Compare commits

...

18 Commits

Author SHA1 Message Date
Guido D'Orsi
14f52dbc4e Merge pull request #2365 from garden-co/changeset-release/main
Version Packages
2025-05-26 12:48:04 +02:00
github-actions[bot]
82e4256e26 Version Packages 2025-05-26 10:07:42 +00:00
Guido D'Orsi
5e253cc717 chore: version bump 2025-05-26 11:12:59 +02:00
Guido D'Orsi
0c1663505c Merge pull request #2363 from garden-co/changeset-release/main
Version Packages
2025-05-26 11:07:20 +02:00
github-actions[bot]
ad85703373 Version Packages 2025-05-25 15:01:21 +00:00
Guido D'Orsi
3a6ec3791c Merge pull request #2364 from garden-co/fix/storage-group-deps
feat(react): API for SSR and Server Components
2025-05-25 16:58:34 +02:00
Guido D'Orsi
f9590f9120 feat(react): API for SSR and Server Components 2025-05-25 16:54:29 +02:00
Guido D'Orsi
706ebf87da Merge pull request #2357 from balazshevesi/main
Fix docs
2025-05-25 16:24:47 +02:00
Guido D'Orsi
00dd317a5d Merge pull request #2362 from garden-co/fix/storage-group-deps
fix(storage): align groups dependencies calculation to LocalNode
2025-05-25 16:24:04 +02:00
Guido D'Orsi
5ced45fb90 test: cover the group dependency loading with a test (temporary) 2025-05-25 15:35:00 +02:00
Guido D'Orsi
23daa7cdde fix(storage): align groups dependencies calculation to LocalNode 2025-05-25 14:34:50 +02:00
Guido D'Orsi
c018752c0c Merge pull request #2361 from garden-co/changeset-release/main
Version Packages
2025-05-24 22:54:04 +02:00
github-actions[bot]
ba3bdcc268 Version Packages 2025-05-24 20:31:26 +00:00
Guido D'Orsi
4177f6f92c Merge pull request #2360 from garden-co/feat/ssr
feat(react): add experimental_enableSSR
2025-05-24 22:28:20 +02:00
Guido D'Orsi
e32a1f7392 feat(react): add experimental_enableSSR 2025-05-24 19:11:23 +02:00
Guido D'Orsi
7c43fd37ae Merge pull request #2358 from garden-co/feat/improve-music-player-mobile
feat(music-player): make the ui usable on mobile
2025-05-24 18:37:59 +02:00
Guido D'Orsi
48168d619b feat(music-player): make the ui usable on mobile 2025-05-24 18:37:15 +02:00
Balazs Hevesi
1b9b9273e5 Update 0-14-0.mdx 2025-05-23 22:18:05 +02:00
161 changed files with 3543 additions and 416 deletions

View File

@@ -1,5 +1,40 @@
# betterauth
## 0.1.19
### Patch Changes
- jazz-betterauth-server-plugin@0.14.16
- jazz-inspector@0.14.16
- jazz-react@0.14.16
- jazz-react-auth-betterauth@0.14.16
- jazz-tools@0.14.16
- jazz-betterauth-client-plugin@0.14.16
## 0.1.18
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-betterauth-server-plugin@0.14.15
- jazz-inspector@0.14.15
- jazz-react-auth-betterauth@0.14.15
- jazz-tools@0.14.15
- jazz-betterauth-client-plugin@0.14.15
## 0.1.17
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-betterauth-server-plugin@0.14.14
- jazz-inspector@0.14.14
- jazz-react@0.14.14
- jazz-react-auth-betterauth@0.14.14
- jazz-betterauth-client-plugin@0.14.14
## 0.1.16
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "betterauth",
"version": "0.1.16",
"version": "0.1.19",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,5 +1,30 @@
# chat-rn-expo-clerk
## 1.0.139
### Patch Changes
- jazz-expo@0.14.16
- jazz-tools@0.14.16
- jazz-react-native-media-images@0.14.16
## 1.0.138
### Patch Changes
- jazz-expo@0.14.15
- jazz-tools@0.14.15
- jazz-react-native-media-images@0.14.15
## 1.0.137
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-expo@0.14.14
- jazz-react-native-media-images@0.14.14
## 1.0.136
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "chat-rn-expo-clerk",
"main": "index.js",
"version": "1.0.136",
"version": "1.0.139",
"scripts": {
"build": "expo export -p ios",
"start": "expo start",

View File

@@ -1,5 +1,27 @@
# chat-rn-expo
## 1.0.7
### Patch Changes
- jazz-expo@0.14.16
- jazz-tools@0.14.16
## 1.0.6
### Patch Changes
- jazz-expo@0.14.15
- jazz-tools@0.14.15
## 1.0.5
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-expo@0.14.14
## 1.0.4
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "chat-rn-expo",
"version": "1.0.4",
"version": "1.0.7",
"main": "index.ts",
"scripts": {
"build": "expo prebuild",

View File

@@ -1,5 +1,33 @@
# chat-rn
## 1.0.134
### Patch Changes
- Updated dependencies [5e253cc]
- cojson@0.14.16
- cojson-transport-ws@0.14.16
- jazz-react-native@0.14.16
- jazz-tools@0.14.16
## 1.0.133
### Patch Changes
- Updated dependencies [23daa7c]
- cojson@0.14.15
- jazz-react-native@0.14.15
- cojson-transport-ws@0.14.15
- jazz-tools@0.14.15
## 1.0.132
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react-native@0.14.14
## 1.0.131
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "chat-rn",
"version": "1.0.131",
"version": "1.0.134",
"main": "index.js",
"scripts": {
"android": "react-native run-android",

View File

@@ -1,5 +1,30 @@
# chat-vue
## 0.0.114
### Patch Changes
- jazz-browser@0.14.16
- jazz-tools@0.14.16
- jazz-vue@0.14.16
## 0.0.113
### Patch Changes
- jazz-browser@0.14.15
- jazz-tools@0.14.15
- jazz-vue@0.14.15
## 0.0.112
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-browser@0.14.14
- jazz-vue@0.14.14
## 0.0.111
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "chat-vue",
"version": "0.0.111",
"version": "0.0.114",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,5 +1,31 @@
# jazz-example-chat
## 0.0.214
### Patch Changes
- jazz-inspector@0.14.16
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.213
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-inspector@0.14.15
- jazz-tools@0.14.15
## 0.0.212
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-inspector@0.14.14
- jazz-react@0.14.14
## 0.0.211
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-chat",
"private": true,
"version": "0.0.211",
"version": "0.0.214",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,31 @@
# minimal-auth-clerk
## 0.0.113
### Patch Changes
- jazz-react@0.14.16
- jazz-react-auth-clerk@0.14.16
- jazz-tools@0.14.16
## 0.0.112
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-react-auth-clerk@0.14.15
- jazz-tools@0.14.15
## 0.0.111
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
- jazz-react-auth-clerk@0.14.14
## 0.0.110
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "clerk",
"private": true,
"version": "0.0.110",
"version": "0.0.113",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,30 @@
# file-share-svelte
## 0.0.98
### Patch Changes
- jazz-svelte@0.14.16
- jazz-tools@0.14.16
- jazz-inspector-element@0.14.16
## 0.0.97
### Patch Changes
- jazz-svelte@0.14.15
- jazz-tools@0.14.15
- jazz-inspector-element@0.14.15
## 0.0.96
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-inspector-element@0.14.14
- jazz-svelte@0.14.14
## 0.0.95
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "file-share-svelte",
"version": "0.0.95",
"version": "0.0.98",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,5 +1,31 @@
# jazz-tailwind-demo-auth-starter
## 0.0.53
### Patch Changes
- jazz-inspector@0.14.16
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.52
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-inspector@0.14.15
- jazz-tools@0.14.15
## 0.0.51
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-inspector@0.14.14
- jazz-react@0.14.14
## 0.0.50
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "filestream",
"private": true,
"version": "0.0.50",
"version": "0.0.53",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,28 @@
# form
## 0.1.54
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.1.53
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
## 0.1.52
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
## 0.1.51
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "form",
"private": true,
"version": "0.1.51",
"version": "0.1.54",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,28 @@
# image-upload
## 0.0.110
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.109
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
## 0.0.108
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
## 0.0.107
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "image-upload",
"private": true,
"version": "0.0.107",
"version": "0.0.110",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,29 @@
# jazz-example-inspector
## 0.0.163
### Patch Changes
- Updated dependencies [5e253cc]
- cojson@0.14.16
- cojson-transport-ws@0.14.16
- jazz-inspector@0.14.16
## 0.0.162
### Patch Changes
- Updated dependencies [23daa7c]
- cojson@0.14.15
- cojson-transport-ws@0.14.15
- jazz-inspector@0.14.15
## 0.0.161
### Patch Changes
- jazz-inspector@0.14.14
## 0.0.160
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-inspector-app",
"private": true,
"version": "0.0.160",
"version": "0.0.163",
"type": "module",
"scripts": {
"dev": "vite",

41
examples/jazz-nextjs/.gitignore vendored Normal file
View File

@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# env files (can opt-in for committing if needed)
.env*
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts

View File

@@ -0,0 +1,24 @@
# jazz-nextjs
## 0.1.3
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.1.2
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
## 0.1.1
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14

View File

@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

View File

@@ -0,0 +1,7 @@
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
};
export default nextConfig;

View File

@@ -0,0 +1,26 @@
{
"name": "jazz-nextjs",
"version": "0.1.3",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0",
"next": "15.3.2",
"jazz-react": "workspace:*",
"jazz-tools": "workspace:*"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"@tailwindcss/postcss": "^4",
"tailwindcss": "^4"
}
}

View File

@@ -0,0 +1,5 @@
const config = {
plugins: ["@tailwindcss/postcss"],
};
export default config;

View File

@@ -0,0 +1,26 @@
@import "tailwindcss";
:root {
--background: #ffffff;
--foreground: #171717;
}
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-geist-sans);
--font-mono: var(--font-geist-mono);
}
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
body {
background: var(--background);
color: var(--foreground);
font-family: Arial, Helvetica, sans-serif;
}

View File

@@ -0,0 +1,35 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import { Jazz } from "../jazz";
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
<Jazz>{children}</Jazz>
</body>
</html>
);
}

View File

@@ -0,0 +1,46 @@
"use client";
import { useAccount } from "jazz-react";
import { Account } from "jazz-tools";
import Link from "next/link";
export default function Home() {
const { me } = useAccount(Account, {
resolve: {
profile: true,
},
});
return (
<div className="flex flex-col items-center justify-center h-screen gap-4">
<h1 className="text-2xl font-bold">SSR rendering example with Jazz</h1>
<div className="text-sm text-gray-500 w-1/2 text-center">
Data is still loaded only on the client, the components are rendered on
the server with all the CoValues as null
</div>
<label>
<div className="text-sm">
Your profile name{" "}
<span className="text-xs">(only loaded on the client)</span>
</div>
<input
className="border-2 border-gray-300 rounded-md p-2 w-full"
value={me?.profile.name ?? ""}
onChange={(e) => {
if (!me) {
return;
}
me.profile.name = e.target.value;
}}
/>
</label>
<Link
href={`/profile/${me?.profile.id}`}
className="bg-blue-500 text-white px-4 py-2 rounded-md"
>
Your profile name in a Server Component
</Link>
</div>
);
}

View File

@@ -0,0 +1,23 @@
import { jazzSSR } from "@/jazzSSR";
import { Profile } from "jazz-tools";
export default async function ServerSidePage(props: {
params: Promise<{ profileId: string }>;
}) {
const { profileId } = await props.params;
const profile = await Profile.load(profileId, {
loadAs: jazzSSR,
});
return (
<div className="flex flex-col items-center justify-center h-screen gap-4">
<h1 className="text-2xl font-bold">SSR rendering example with Jazz</h1>
<div className="text-sm text-gray-500 w-1/2 text-center">
This is a server component!
</div>
<label>
<div className="text-sm">Your profile name "{profile?.name}"</div>
</label>
</div>
);
}

View File

@@ -0,0 +1,16 @@
"use client";
import { JazzProvider } from "jazz-react";
export function Jazz({ children }: { children: React.ReactNode }) {
return (
<JazzProvider
experimental_enableSSR
sync={{
peer: `wss://cloud.jazz.tools/`,
}}
>
{children}
</JazzProvider>
);
}

View File

@@ -0,0 +1,5 @@
import { createSSRJazzAgent } from "jazz-react/ssr";
export const jazzSSR = createSSRJazzAgent({
peer: "wss://cloud.jazz.tools/",
});

View File

@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -1,5 +1,28 @@
# multi-cursors
## 0.0.106
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.105
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
## 0.0.104
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
## 0.0.103
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "multi-cursors",
"private": true,
"version": "0.0.103",
"version": "0.0.106",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,31 @@
# multiauth
## 0.0.54
### Patch Changes
- jazz-react@0.14.16
- jazz-react-auth-clerk@0.14.16
- jazz-tools@0.14.16
## 0.0.53
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-react-auth-clerk@0.14.15
- jazz-tools@0.14.15
## 0.0.52
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
- jazz-react-auth-clerk@0.14.14
## 0.0.51
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "multiauth",
"private": true,
"version": "0.0.51",
"version": "0.0.54",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,31 @@
# jazz-example-musicplayer
## 0.0.135
### Patch Changes
- jazz-inspector@0.14.16
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.134
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-inspector@0.14.15
- jazz-tools@0.14.15
## 0.0.133
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-inspector@0.14.14
- jazz-react@0.14.14
## 0.0.132
### Patch Changes

View File

@@ -4,7 +4,7 @@
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"config": "tailwind.config.ts",
"css": "src/index.css",
"baseColor": "stone",
"cssVariables": true

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-music-player",
"private": true,
"version": "0.0.132",
"version": "0.0.135",
"type": "module",
"scripts": {
"dev": "vite",
@@ -16,10 +16,11 @@
"@radix-ui/react-dialog": "^1.1.4",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-label": "^2.1.1",
"@radix-ui/react-separator": "^1.1.2",
"@radix-ui/react-slot": "^1.1.1",
"@radix-ui/react-toast": "^1.1.4",
"@radix-ui/react-tooltip": "^1.1.6",
"class-variance-authority": "^0.7.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.0.0",
"jazz-inspector": "workspace:*",
"jazz-react": "workspace:*",

View File

@@ -7,11 +7,11 @@ import { RouterProvider, createHashRouter } from "react-router-dom";
import { HomePage } from "./3_HomePage";
import { useMediaPlayer } from "./5_useMediaPlayer";
import { InvitePage } from "./6_InvitePage";
import { PlayerControls } from "./components/PlayerControls";
import "./index.css";
import { MusicaAccount } from "@/1_schema";
import { apiKey } from "@/apiKey.ts";
import { SidebarProvider } from "@/components/ui/sidebar";
import { JazzProvider } from "jazz-react";
import { onAnonymousAccountDiscarded } from "./4_actions";
import { useUploadExampleData } from "./lib/useUploadExampleData";
@@ -50,7 +50,7 @@ function Main() {
return (
<>
<RouterProvider router={router} />
<PlayerControls mediaPlayer={mediaPlayer} />
{/* <PlayerControls mediaPlayer={mediaPlayer} /> */}
<Toaster />
</>
);
@@ -72,8 +72,10 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
defaultProfileName="Anonymous unicorn"
onAnonymousAccountDiscarded={onAnonymousAccountDiscarded}
>
<Main />
<JazzInspector />
<SidebarProvider>
<Main />
<JazzInspector />
</SidebarProvider>
</JazzProvider>
</React.StrictMode>,
);

View File

@@ -5,16 +5,16 @@ import {
useCoState,
useIsAuthenticated,
} from "jazz-react";
import { useNavigate, useParams } from "react-router";
import { useParams } from "react-router";
import { MusicaAccount, Playlist } from "./1_schema";
import { createNewPlaylist, uploadMusicTracks } from "./4_actions";
import { uploadMusicTracks } from "./4_actions";
import { MediaPlayer } from "./5_useMediaPlayer";
import { AuthButton } from "./components/AuthButton";
import { FileUploadButton } from "./components/FileUploadButton";
import { MusicTrackRow } from "./components/MusicTrackRow";
import { PlaylistTitleInput } from "./components/PlaylistTitleInput";
import { SidePanel } from "./components/SidePanel";
import { Button } from "./components/ui/button";
import { SidebarInset, SidebarTrigger } from "./components/ui/sidebar";
import { usePlayState } from "./lib/audio/usePlayState";
export function HomePage({ mediaPlayer }: { mediaPlayer: MediaPlayer }) {
@@ -26,7 +26,6 @@ export function HomePage({ mediaPlayer }: { mediaPlayer: MediaPlayer }) {
resolve: { root: { rootPlaylist: true, playlists: true } },
});
const navigate = useNavigate();
const playState = usePlayState();
const isPlaying = playState.value === "play";
const { toast } = useToast();
@@ -39,12 +38,6 @@ export function HomePage({ mediaPlayer }: { mediaPlayer: MediaPlayer }) {
await uploadMusicTracks(files);
}
async function handleCreatePlaylist() {
const playlist = await createNewPlaylist();
navigate(`/playlist/${playlist.id}`);
}
const params = useParams<{ playlistId: string }>();
const playlistId = params.playlistId ?? me?.root._refs.rootPlaylist.id;
@@ -71,10 +64,11 @@ export function HomePage({ mediaPlayer }: { mediaPlayer: MediaPlayer }) {
const isAuthenticated = useIsAuthenticated();
return (
<div className="flex flex-col h-screen text-gray-800 bg-blue-50">
<SidebarInset className="flex flex-col h-screen text-gray-800 bg-blue-50">
<div className="flex flex-1 overflow-hidden">
<SidePanel />
<SidePanel mediaPlayer={mediaPlayer} />
<main className="flex-1 p-6 overflow-y-auto">
<SidebarTrigger />
<div className="flex items-center justify-between mb-6">
{isRootPlaylist ? (
<h1 className="text-2xl font-bold text-blue-800">All tracks</h1>
@@ -87,7 +81,6 @@ export function HomePage({ mediaPlayer }: { mediaPlayer: MediaPlayer }) {
<FileUploadButton onFileLoad={handleFileLoad}>
Add file
</FileUploadButton>
<Button onClick={handleCreatePlaylist}>New playlist</Button>
</>
)}
{!isRootPlaylist && isAuthenticated && (
@@ -95,7 +88,6 @@ export function HomePage({ mediaPlayer }: { mediaPlayer: MediaPlayer }) {
Share playlist
</Button>
)}
<AuthButton />
</div>
</div>
<ul className="flex flex-col">
@@ -121,6 +113,6 @@ export function HomePage({ mediaPlayer }: { mediaPlayer: MediaPlayer }) {
</ul>
</main>
</div>
</div>
</SidebarInset>
);
}

View File

@@ -20,7 +20,7 @@ export function AuthButton() {
if (isAuthenticated) {
return (
<Button variant="outline" onClick={handleSignOut}>
<Button variant="ghost" onClick={handleSignOut}>
Sign out
</Button>
);
@@ -28,10 +28,7 @@ export function AuthButton() {
return (
<>
<Button
onClick={() => setOpen(true)}
className="bg-white text-black hover:bg-gray-100"
>
<Button onClick={() => setOpen(true)} variant="ghost">
Sign up
</Button>
<AuthModal open={open} onOpenChange={setOpen} />

View File

@@ -1,27 +1,40 @@
import { MusicaAccount } from "@/1_schema";
import { deletePlaylist } from "@/4_actions";
import { useAccount } from "jazz-react";
import { Trash2 } from "lucide-react";
import { MusicTrack, MusicaAccount } from "@/1_schema";
import { createNewPlaylist, deletePlaylist } from "@/4_actions";
import { MediaPlayer } from "@/5_useMediaPlayer";
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarHeader,
SidebarMenu,
SidebarMenuAction,
SidebarMenuButton,
SidebarMenuItem,
} from "@/components/ui/sidebar";
import { usePlayState } from "@/lib/audio/usePlayState";
import { useAccount, useCoState } from "jazz-react";
import { Home, Music, Pause, Play, Plus, Trash2 } from "lucide-react";
import { useNavigate, useParams } from "react-router";
import { LocalOnlyTag } from "./LocalOnlyTag";
import { AuthButton } from "./AuthButton";
export function SidePanel() {
export function SidePanel({ mediaPlayer }: { mediaPlayer: MediaPlayer }) {
const { playlistId } = useParams();
const navigate = useNavigate();
const { me } = useAccount(MusicaAccount, {
resolve: { root: { playlists: { $each: true } } },
});
function handleAllTracksClick(evt: React.MouseEvent<HTMLAnchorElement>) {
evt.preventDefault();
const playState = usePlayState();
const isPlaying = playState.value === "play";
function handleAllTracksClick() {
navigate(`/`);
}
function handlePlaylistClick(
evt: React.MouseEvent<HTMLAnchorElement>,
playlistId: string,
) {
evt.preventDefault();
function handlePlaylistClick(playlistId: string) {
navigate(`/playlist/${playlistId}`);
}
@@ -32,73 +45,121 @@ export function SidePanel() {
}
}
async function handleCreatePlaylist() {
const playlist = await createNewPlaylist();
navigate(`/playlist/${playlist.id}`);
}
const activeTrack = useCoState(MusicTrack, mediaPlayer.activeTrackId, {
resolve: { waveform: true },
});
const activeTrackTitle = activeTrack?.title;
return (
<aside className="w-64 p-6 bg-white overflow-y-auto">
<div className="flex items-center mb-1">
<svg
className="w-8 h-8 mr-2"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M9 18V5l12-2v13"
stroke="#3b82f6"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M6 15H3c-1.1 0-2 .9-2 2v4c0 1.1.9 2 2 2h3c1.1 0 2-.9 2-2v-4c0-1.1-.9-2-2-2zM18 13h-3c-1.1 0-2 .9-2 2v4c0 1.1.9 2 2 2h3c1.1 0 2-.9 2-2v-4c0-1.1-.9-2-2-2z"
fill="#3b82f6"
/>
</svg>
<span className="text-xl font-bold text-blue-600">Music Player</span>
</div>
<div className="mb-6">
<LocalOnlyTag />
</div>
<nav>
<h2 className="mb-2 text-sm font-semibold text-gray-600">Playlists</h2>
<ul className="space-y-1">
<li>
<a
href="#"
className={`block px-2 py-1 text-sm rounded ${
!playlistId ? "bg-blue-100 text-blue-600" : "hover:bg-blue-100"
}`}
onClick={handleAllTracksClick}
>
All tracks
</a>
</li>
{me?.root.playlists.map((playlist, index) => (
<li
key={index}
className={`px-2 py-1 flex transition-all duration-300 rounded items-center justify-between ${
playlist.id === playlistId ? "bg-blue-100" : ""
}`}
>
<a
href="#"
className={`w-full text-sm`}
onClick={(evt) => handlePlaylistClick(evt, playlist.id)}
<Sidebar>
<SidebarHeader>
<SidebarMenu>
<SidebarMenuItem className="flex items-center gap-2">
<div className="flex aspect-square size-8 items-center justify-center rounded-lg bg-blue-600 text-white">
<svg
className="size-4"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
{playlist.title}
</a>
{playlist.id === playlistId && (
<button
onClick={() => handleDeletePlaylist(playlist.id)}
className="ml-2 text-red-600 hover:text-red-800 animate-in fade-in scale-in duration-200"
aria-label={`Delete ${playlist.title}`}
>
<Trash2 size={16} />
</button>
)}
</li>
))}
</ul>
</nav>
</aside>
<path
d="M9 18V5l12-2v13"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M6 15H3c-1.1 0-2 .9-2 2v4c0 1.1.9 2 2 2h3c1.1 0 2-.9 2-2v-4c0-1.1-.9-2-2-2zM18 13h-3c-1.1 0-2 .9-2 2v4c0 1.1.9 2 2 2h3c1.1 0 2-.9 2-2v-4c0-1.1-.9-2-2-2z"
fill="currentColor"
/>
</svg>
</div>
<div className="grid flex-1 text-left text-sm leading-tight">
<span className="truncate font-semibold">Music Player</span>
</div>
<AuthButton />
</SidebarMenuItem>
</SidebarMenu>
</SidebarHeader>
<SidebarContent>
<SidebarGroup>
<SidebarGroupContent>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton onClick={handleAllTracksClick}>
<Home className="size-4" />
<span>Go to all tracks</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
<SidebarGroup>
<SidebarGroupLabel>Playlists</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton onClick={handleCreatePlaylist}>
<Plus className="size-4" />
<span>Add a new playlist</span>
</SidebarMenuButton>
</SidebarMenuItem>
{me?.root.playlists.map((playlist) => (
<SidebarMenuItem key={playlist.id}>
<SidebarMenuButton
onClick={() => handlePlaylistClick(playlist.id)}
isActive={playlist.id === playlistId}
>
<div className="flex items-center gap-2">
<Music className="size-4" />
<span>{playlist.title}</span>
</div>
</SidebarMenuButton>
{playlist.id === playlistId && (
<SidebarMenuAction
onClick={() => handleDeletePlaylist(playlist.id)}
className="text-red-600 hover:text-red-800"
>
<Trash2 className="size-4" />
<span className="sr-only">Delete {playlist.title}</span>
</SidebarMenuAction>
)}
</SidebarMenuItem>
))}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
{activeTrack && (
<SidebarFooter>
<SidebarMenu>
<SidebarMenuItem className="flex justify-end">
<SidebarMenuButton
onClick={playState.toggle}
aria-label={
isPlaying ? "Pause active track" : "Play active track"
}
>
<div className="w-[28px] h-[28px] flex items-center justify-center bg-blue-600 rounded-full text-white hover:bg-blue-700">
{isPlaying ? (
<Pause size={16} fill="currentColor" />
) : (
<Play size={16} fill="currentColor" />
)}
</div>
<span>{activeTrackTitle}</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarFooter>
)}
</Sidebar>
);
}

View File

@@ -5,7 +5,7 @@ import * as React from "react";
import { cn } from "@/lib/utils";
const buttonVariants = cva(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
{
variants: {
variant: {
@@ -53,5 +53,4 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
);
Button.displayName = "Button";
// eslint-disable-next-line react-refresh/only-export-components
export { Button, buttonVariants };

View File

@@ -0,0 +1,29 @@
import * as SeparatorPrimitive from "@radix-ui/react-separator";
import * as React from "react";
import { cn } from "@/lib/utils";
const Separator = React.forwardRef<
React.ElementRef<typeof SeparatorPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
>(
(
{ className, orientation = "horizontal", decorative = true, ...props },
ref,
) => (
<SeparatorPrimitive.Root
ref={ref}
decorative={decorative}
orientation={orientation}
className={cn(
"shrink-0 bg-border",
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
className,
)}
{...props}
/>
),
);
Separator.displayName = SeparatorPrimitive.Root.displayName;
export { Separator };

View File

@@ -0,0 +1,140 @@
"use client";
import * as SheetPrimitive from "@radix-ui/react-dialog";
import { type VariantProps, cva } from "class-variance-authority";
import { X } from "lucide-react";
import * as React from "react";
import { cn } from "@/lib/utils";
const Sheet = SheetPrimitive.Root;
const SheetTrigger = SheetPrimitive.Trigger;
const SheetClose = SheetPrimitive.Close;
const SheetPortal = SheetPrimitive.Portal;
const SheetOverlay = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Overlay
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className,
)}
{...props}
ref={ref}
/>
));
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;
const sheetVariants = cva(
"fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
{
variants: {
side: {
top: "inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
bottom:
"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
left: "inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",
right:
"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",
},
},
defaultVariants: {
side: "right",
},
},
);
interface SheetContentProps
extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
VariantProps<typeof sheetVariants> {}
const SheetContent = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Content>,
SheetContentProps
>(({ side = "right", className, children, ...props }, ref) => (
<SheetPortal>
<SheetOverlay />
<SheetPrimitive.Content
ref={ref}
className={cn(sheetVariants({ side }), className)}
{...props}
>
{children}
<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</SheetPrimitive.Close>
</SheetPrimitive.Content>
</SheetPortal>
));
SheetContent.displayName = SheetPrimitive.Content.displayName;
const SheetHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-2 text-center sm:text-left",
className,
)}
{...props}
/>
);
SheetHeader.displayName = "SheetHeader";
const SheetFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className,
)}
{...props}
/>
);
SheetFooter.displayName = "SheetFooter";
const SheetTitle = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Title
ref={ref}
className={cn("text-lg font-semibold text-foreground", className)}
{...props}
/>
));
SheetTitle.displayName = SheetPrimitive.Title.displayName;
const SheetDescription = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
));
SheetDescription.displayName = SheetPrimitive.Description.displayName;
export {
Sheet,
SheetPortal,
SheetOverlay,
SheetTrigger,
SheetClose,
SheetContent,
SheetHeader,
SheetFooter,
SheetTitle,
SheetDescription,
};

View File

@@ -0,0 +1,779 @@
import { Slot } from "@radix-ui/react-slot";
import { VariantProps, cva } from "class-variance-authority";
import { PanelLeft } from "lucide-react";
import * as React from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Separator } from "@/components/ui/separator";
import {
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
} from "@/components/ui/sheet";
import { Skeleton } from "@/components/ui/skeleton";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { useIsMobile } from "@/hooks/use-mobile";
import { cn } from "@/lib/utils";
const SIDEBAR_COOKIE_NAME = "sidebar_state";
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
const SIDEBAR_WIDTH = "16rem";
const SIDEBAR_WIDTH_MOBILE = "18rem";
const SIDEBAR_WIDTH_ICON = "3rem";
const SIDEBAR_KEYBOARD_SHORTCUT = "b";
type SidebarContextProps = {
state: "expanded" | "collapsed";
open: boolean;
setOpen: (open: boolean) => void;
openMobile: boolean;
setOpenMobile: (open: boolean) => void;
isMobile: boolean;
toggleSidebar: () => void;
};
const SidebarContext = React.createContext<SidebarContextProps | null>(null);
function useSidebar() {
const context = React.useContext(SidebarContext);
if (!context) {
throw new Error("useSidebar must be used within a SidebarProvider.");
}
return context;
}
const SidebarProvider = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div"> & {
defaultOpen?: boolean;
open?: boolean;
onOpenChange?: (open: boolean) => void;
}
>(
(
{
defaultOpen = true,
open: openProp,
onOpenChange: setOpenProp,
className,
style,
children,
...props
},
ref,
) => {
const isMobile = useIsMobile();
const [openMobile, setOpenMobile] = React.useState(false);
// This is the internal state of the sidebar.
// We use openProp and setOpenProp for control from outside the component.
const [_open, _setOpen] = React.useState(defaultOpen);
const open = openProp ?? _open;
const setOpen = React.useCallback(
(value: boolean | ((value: boolean) => boolean)) => {
const openState = typeof value === "function" ? value(open) : value;
if (setOpenProp) {
setOpenProp(openState);
} else {
_setOpen(openState);
}
// This sets the cookie to keep the sidebar state.
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
},
[setOpenProp, open],
);
// Helper to toggle the sidebar.
const toggleSidebar = React.useCallback(() => {
return isMobile
? setOpenMobile((open) => !open)
: setOpen((open) => !open);
}, [isMobile, setOpen, setOpenMobile]);
// Adds a keyboard shortcut to toggle the sidebar.
React.useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (
event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
(event.metaKey || event.ctrlKey)
) {
event.preventDefault();
toggleSidebar();
}
};
window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
}, [toggleSidebar]);
// We add a state so that we can do data-state="expanded" or "collapsed".
// This makes it easier to style the sidebar with Tailwind classes.
const state = open ? "expanded" : "collapsed";
const contextValue = React.useMemo<SidebarContextProps>(
() => ({
state,
open,
setOpen,
isMobile,
openMobile,
setOpenMobile,
toggleSidebar,
}),
[
state,
open,
setOpen,
isMobile,
openMobile,
setOpenMobile,
toggleSidebar,
],
);
return (
<SidebarContext.Provider value={contextValue}>
<TooltipProvider delayDuration={0}>
<div
style={
{
"--sidebar-width": SIDEBAR_WIDTH,
"--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
...style,
} as React.CSSProperties
}
className={cn(
"group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",
className,
)}
ref={ref}
{...props}
>
{children}
</div>
</TooltipProvider>
</SidebarContext.Provider>
);
},
);
SidebarProvider.displayName = "SidebarProvider";
const Sidebar = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div"> & {
side?: "left" | "right";
variant?: "sidebar" | "floating" | "inset";
collapsible?: "offcanvas" | "icon" | "none";
}
>(
(
{
side = "left",
variant = "sidebar",
collapsible = "offcanvas",
className,
children,
...props
},
ref,
) => {
const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
if (collapsible === "none") {
return (
<div
className={cn(
"flex h-full w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",
className,
)}
ref={ref}
{...props}
>
{children}
</div>
);
}
if (isMobile) {
return (
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
<SheetContent
data-sidebar="sidebar"
data-mobile="true"
className="w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
style={
{
"--sidebar-width": SIDEBAR_WIDTH_MOBILE,
} as React.CSSProperties
}
side={side}
>
<SheetHeader className="sr-only">
<SheetTitle>Sidebar</SheetTitle>
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
</SheetHeader>
<div className="flex h-full w-full flex-col">{children}</div>
</SheetContent>
</Sheet>
);
}
return (
<div
ref={ref}
className="group peer hidden text-sidebar-foreground md:block"
data-state={state}
data-collapsible={state === "collapsed" ? collapsible : ""}
data-variant={variant}
data-side={side}
>
{/* This is what handles the sidebar gap on desktop */}
<div
className={cn(
"relative w-[--sidebar-width] bg-transparent transition-[width] duration-200 ease-linear",
"group-data-[collapsible=offcanvas]:w-0",
"group-data-[side=right]:rotate-180",
variant === "floating" || variant === "inset"
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]"
: "group-data-[collapsible=icon]:w-[--sidebar-width-icon]",
)}
/>
<div
className={cn(
"fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] duration-200 ease-linear md:flex",
side === "left"
? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
: "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
// Adjust the padding for floating and inset variants.
variant === "floating" || variant === "inset"
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]"
: "group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",
className,
)}
{...props}
>
<div
data-sidebar="sidebar"
className="flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow"
>
{children}
</div>
</div>
</div>
);
},
);
Sidebar.displayName = "Sidebar";
const SidebarTrigger = React.forwardRef<
React.ElementRef<typeof Button>,
React.ComponentProps<typeof Button>
>(({ className, onClick, ...props }, ref) => {
const { toggleSidebar } = useSidebar();
return (
<Button
ref={ref}
data-sidebar="trigger"
variant="ghost"
size="icon"
className={cn("h-7 w-7", className)}
onClick={(event) => {
onClick?.(event);
toggleSidebar();
}}
{...props}
>
<PanelLeft />
<span className="sr-only">Toggle Sidebar</span>
</Button>
);
});
SidebarTrigger.displayName = "SidebarTrigger";
const SidebarRail = React.forwardRef<
HTMLButtonElement,
React.ComponentProps<"button">
>(({ className, ...props }, ref) => {
const { toggleSidebar } = useSidebar();
return (
<button
ref={ref}
data-sidebar="rail"
aria-label="Toggle Sidebar"
tabIndex={-1}
onClick={toggleSidebar}
title="Toggle Sidebar"
className={cn(
"absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex",
"[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize",
"[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
"group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar",
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
className,
)}
{...props}
/>
);
});
SidebarRail.displayName = "SidebarRail";
const SidebarInset = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"main">
>(({ className, ...props }, ref) => {
return (
<main
ref={ref}
className={cn(
"relative flex w-full flex-1 flex-col bg-background",
"md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow",
className,
)}
{...props}
/>
);
});
SidebarInset.displayName = "SidebarInset";
const SidebarInput = React.forwardRef<
React.ElementRef<typeof Input>,
React.ComponentProps<typeof Input>
>(({ className, ...props }, ref) => {
return (
<Input
ref={ref}
data-sidebar="input"
className={cn(
"h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",
className,
)}
{...props}
/>
);
});
SidebarInput.displayName = "SidebarInput";
const SidebarHeader = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div">
>(({ className, ...props }, ref) => {
return (
<div
ref={ref}
data-sidebar="header"
className={cn("flex flex-col gap-2 p-2", className)}
{...props}
/>
);
});
SidebarHeader.displayName = "SidebarHeader";
const SidebarFooter = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div">
>(({ className, ...props }, ref) => {
return (
<div
ref={ref}
data-sidebar="footer"
className={cn("flex flex-col gap-2 p-2", className)}
{...props}
/>
);
});
SidebarFooter.displayName = "SidebarFooter";
const SidebarSeparator = React.forwardRef<
React.ElementRef<typeof Separator>,
React.ComponentProps<typeof Separator>
>(({ className, ...props }, ref) => {
return (
<Separator
ref={ref}
data-sidebar="separator"
className={cn("mx-2 w-auto bg-sidebar-border", className)}
{...props}
/>
);
});
SidebarSeparator.displayName = "SidebarSeparator";
const SidebarContent = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div">
>(({ className, ...props }, ref) => {
return (
<div
ref={ref}
data-sidebar="content"
className={cn(
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
className,
)}
{...props}
/>
);
});
SidebarContent.displayName = "SidebarContent";
const SidebarGroup = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div">
>(({ className, ...props }, ref) => {
return (
<div
ref={ref}
data-sidebar="group"
className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
{...props}
/>
);
});
SidebarGroup.displayName = "SidebarGroup";
const SidebarGroupLabel = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div"> & { asChild?: boolean }
>(({ className, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "div";
return (
<Comp
ref={ref}
data-sidebar="group-label"
className={cn(
"flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-none ring-sidebar-ring transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
"group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
className,
)}
{...props}
/>
);
});
SidebarGroupLabel.displayName = "SidebarGroupLabel";
const SidebarGroupAction = React.forwardRef<
HTMLButtonElement,
React.ComponentProps<"button"> & { asChild?: boolean }
>(({ className, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button";
return (
<Comp
ref={ref}
data-sidebar="group-action"
className={cn(
"absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
// Increases the hit area of the button on mobile.
"after:absolute after:-inset-2 after:md:hidden",
"group-data-[collapsible=icon]:hidden",
className,
)}
{...props}
/>
);
});
SidebarGroupAction.displayName = "SidebarGroupAction";
const SidebarGroupContent = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div">
>(({ className, ...props }, ref) => (
<div
ref={ref}
data-sidebar="group-content"
className={cn("w-full text-sm", className)}
{...props}
/>
));
SidebarGroupContent.displayName = "SidebarGroupContent";
const SidebarMenu = React.forwardRef<
HTMLUListElement,
React.ComponentProps<"ul">
>(({ className, ...props }, ref) => (
<ul
ref={ref}
data-sidebar="menu"
className={cn("flex w-full min-w-0 flex-col gap-1", className)}
{...props}
/>
));
SidebarMenu.displayName = "SidebarMenu";
const SidebarMenuItem = React.forwardRef<
HTMLLIElement,
React.ComponentProps<"li">
>(({ className, ...props }, ref) => (
<li
ref={ref}
data-sidebar="menu-item"
className={cn("group/menu-item relative", className)}
{...props}
/>
));
SidebarMenuItem.displayName = "SidebarMenuItem";
const sidebarMenuButtonVariants = cva(
"peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
{
variants: {
variant: {
default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
outline:
"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
},
size: {
default: "h-8 text-sm",
sm: "h-7 text-xs",
lg: "h-12 text-sm group-data-[collapsible=icon]:!p-0",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
},
);
const SidebarMenuButton = React.forwardRef<
HTMLButtonElement,
React.ComponentProps<"button"> & {
asChild?: boolean;
isActive?: boolean;
tooltip?: string | React.ComponentProps<typeof TooltipContent>;
} & VariantProps<typeof sidebarMenuButtonVariants>
>(
(
{
asChild = false,
isActive = false,
variant = "default",
size = "default",
tooltip,
className,
...props
},
ref,
) => {
const Comp = asChild ? Slot : "button";
const { isMobile, state } = useSidebar();
const button = (
<Comp
ref={ref}
data-sidebar="menu-button"
data-size={size}
data-active={isActive}
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
{...props}
/>
);
if (!tooltip) {
return button;
}
if (typeof tooltip === "string") {
tooltip = {
children: tooltip,
};
}
return (
<Tooltip>
<TooltipTrigger asChild>{button}</TooltipTrigger>
<TooltipContent
side="right"
align="center"
hidden={state !== "collapsed" || isMobile}
{...tooltip}
/>
</Tooltip>
);
},
);
SidebarMenuButton.displayName = "SidebarMenuButton";
const SidebarMenuAction = React.forwardRef<
HTMLButtonElement,
React.ComponentProps<"button"> & {
asChild?: boolean;
showOnHover?: boolean;
}
>(({ className, asChild = false, showOnHover = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button";
return (
<Comp
ref={ref}
data-sidebar="menu-action"
className={cn(
"absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0",
// Increases the hit area of the button on mobile.
"after:absolute after:-inset-2 after:md:hidden",
"peer-data-[size=sm]/menu-button:top-1",
"peer-data-[size=default]/menu-button:top-1.5",
"peer-data-[size=lg]/menu-button:top-2.5",
"group-data-[collapsible=icon]:hidden",
showOnHover &&
"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",
className,
)}
{...props}
/>
);
});
SidebarMenuAction.displayName = "SidebarMenuAction";
const SidebarMenuBadge = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div">
>(({ className, ...props }, ref) => (
<div
ref={ref}
data-sidebar="menu-badge"
className={cn(
"pointer-events-none absolute right-1 flex h-5 min-w-5 select-none items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground",
"peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
"peer-data-[size=sm]/menu-button:top-1",
"peer-data-[size=default]/menu-button:top-1.5",
"peer-data-[size=lg]/menu-button:top-2.5",
"group-data-[collapsible=icon]:hidden",
className,
)}
{...props}
/>
));
SidebarMenuBadge.displayName = "SidebarMenuBadge";
const SidebarMenuSkeleton = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div"> & {
showIcon?: boolean;
}
>(({ className, showIcon = false, ...props }, ref) => {
// Random width between 50 to 90%.
const width = React.useMemo(() => {
return `${Math.floor(Math.random() * 40) + 50}%`;
}, []);
return (
<div
ref={ref}
data-sidebar="menu-skeleton"
className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
{...props}
>
{showIcon && (
<Skeleton
className="size-4 rounded-md"
data-sidebar="menu-skeleton-icon"
/>
)}
<Skeleton
className="h-4 max-w-[--skeleton-width] flex-1"
data-sidebar="menu-skeleton-text"
style={
{
"--skeleton-width": width,
} as React.CSSProperties
}
/>
</div>
);
});
SidebarMenuSkeleton.displayName = "SidebarMenuSkeleton";
const SidebarMenuSub = React.forwardRef<
HTMLUListElement,
React.ComponentProps<"ul">
>(({ className, ...props }, ref) => (
<ul
ref={ref}
data-sidebar="menu-sub"
className={cn(
"mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5",
"group-data-[collapsible=icon]:hidden",
className,
)}
{...props}
/>
));
SidebarMenuSub.displayName = "SidebarMenuSub";
const SidebarMenuSubItem = React.forwardRef<
HTMLLIElement,
React.ComponentProps<"li">
>(({ ...props }, ref) => <li ref={ref} {...props} />);
SidebarMenuSubItem.displayName = "SidebarMenuSubItem";
const SidebarMenuSubButton = React.forwardRef<
HTMLAnchorElement,
React.ComponentProps<"a"> & {
asChild?: boolean;
size?: "sm" | "md";
isActive?: boolean;
}
>(({ asChild = false, size = "md", isActive, className, ...props }, ref) => {
const Comp = asChild ? Slot : "a";
return (
<Comp
ref={ref}
data-sidebar="menu-sub-button"
data-size={size}
data-active={isActive}
className={cn(
"flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground",
"data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
size === "sm" && "text-xs",
size === "md" && "text-sm",
"group-data-[collapsible=icon]:hidden",
className,
)}
{...props}
/>
);
});
SidebarMenuSubButton.displayName = "SidebarMenuSubButton";
export {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupAction,
SidebarGroupContent,
SidebarGroupLabel,
SidebarHeader,
SidebarInput,
SidebarInset,
SidebarMenu,
SidebarMenuAction,
SidebarMenuBadge,
SidebarMenuButton,
SidebarMenuItem,
SidebarMenuSkeleton,
SidebarMenuSub,
SidebarMenuSubButton,
SidebarMenuSubItem,
SidebarProvider,
SidebarRail,
SidebarSeparator,
SidebarTrigger,
useSidebar,
};

View File

@@ -0,0 +1,15 @@
import { cn } from "@/lib/utils";
function Skeleton({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) {
return (
<div
className={cn("animate-pulse rounded-md bg-muted", className)}
{...props}
/>
);
}
export { Skeleton };

View File

@@ -1,5 +1,3 @@
"use client";
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
import * as React from "react";
@@ -19,7 +17,7 @@ const TooltipContent = React.forwardRef<
ref={ref}
sideOffset={sideOffset}
className={cn(
"z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
"z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",
className,
)}
{...props}

View File

@@ -0,0 +1,21 @@
import * as React from "react";
const MOBILE_BREAKPOINT = 768;
export function useIsMobile() {
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
undefined,
);
React.useEffect(() => {
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
const onChange = () => {
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
};
mql.addEventListener("change", onChange);
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
return () => mql.removeEventListener("change", onChange);
}, []);
return !!isMobile;
}

View File

@@ -33,6 +33,22 @@
--ring: 20 14.3% 4.1%;
--radius: 0.5rem;
--sidebar-background: 0 0% 98%;
--sidebar-foreground: 240 5.3% 26.1%;
--sidebar-primary: 240 5.9% 10%;
--sidebar-primary-foreground: 0 0% 98%;
--sidebar-accent: 240 4.8% 95.9%;
--sidebar-accent-foreground: 240 5.9% 10%;
--sidebar-border: 220 13% 91%;
--sidebar-ring: 217.2 91.2% 59.8%;
}
.dark {
@@ -63,6 +79,14 @@
--border: 12 6.5% 15.1%;
--input: 12 6.5% 15.1%;
--ring: 24 5.7% 82.9%;
--sidebar-background: 240 5.9% 10%;
--sidebar-foreground: 240 4.8% 95.9%;
--sidebar-primary: 224.3 76.3% 48%;
--sidebar-primary-foreground: 0 0% 100%;
--sidebar-accent: 240 3.7% 15.9%;
--sidebar-accent-foreground: 240 4.8% 95.9%;
--sidebar-border: 240 3.7% 15.9%;
--sidebar-ring: 217.2 91.2% 59.8%;
}
}

View File

@@ -52,6 +52,16 @@ const config: Config = {
DEFAULT: "hsl(var(--card))",
foreground: "hsl(var(--card-foreground))",
},
sidebar: {
DEFAULT: "hsl(var(--sidebar-background))",
foreground: "hsl(var(--sidebar-foreground))",
primary: "hsl(var(--sidebar-primary))",
"primary-foreground": "hsl(var(--sidebar-primary-foreground))",
accent: "hsl(var(--sidebar-accent))",
"accent-foreground": "hsl(var(--sidebar-accent-foreground))",
border: "hsl(var(--sidebar-border))",
ring: "hsl(var(--sidebar-ring))",
},
},
borderRadius: {
lg: "var(--radius)",
@@ -60,12 +70,20 @@ const config: Config = {
},
keyframes: {
"accordion-down": {
from: { height: "0" },
to: { height: "var(--radix-accordion-content-height)" },
from: {
height: "0",
},
to: {
height: "var(--radix-accordion-content-height)",
},
},
"accordion-up": {
from: { height: "var(--radix-accordion-content-height)" },
to: { height: "0" },
from: {
height: "var(--radix-accordion-content-height)",
},
to: {
height: "0",
},
},
},
animation: {

View File

@@ -71,7 +71,7 @@ export class HomePage {
async navigateToPlaylist(playlistTitle: string) {
await this.page
.getByRole("link", {
.getByRole("button", {
name: playlistTitle,
})
.click();
@@ -79,7 +79,7 @@ export class HomePage {
async navigateToHome() {
await this.page
.getByRole("link", {
.getByRole("button", {
name: "All tracks",
})
.click();

View File

@@ -1,5 +1,28 @@
# organization
## 0.0.106
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.105
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
## 0.0.104
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
## 0.0.103
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "organization",
"private": true,
"version": "0.0.103",
"version": "0.0.106",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,27 @@
# passkey-svelte
## 0.0.100
### Patch Changes
- jazz-svelte@0.14.16
- jazz-tools@0.14.16
## 0.0.99
### Patch Changes
- jazz-svelte@0.14.15
- jazz-tools@0.14.15
## 0.0.98
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-svelte@0.14.14
## 0.0.97
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "passkey-svelte",
"version": "0.0.97",
"version": "0.0.100",
"type": "module",
"private": true,
"scripts": {

View File

@@ -1,5 +1,28 @@
# minimal-auth-passkey
## 0.0.111
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.110
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
## 0.0.109
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
## 0.0.108
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "passkey",
"private": true,
"version": "0.0.108",
"version": "0.0.111",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,28 @@
# passphrase
## 0.0.108
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.107
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
## 0.0.106
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
## 0.0.105
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "passphrase",
"private": true,
"version": "0.0.105",
"version": "0.0.108",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,28 @@
# jazz-password-manager
## 0.0.132
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.131
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
## 0.0.130
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
## 0.0.129
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-password-manager",
"private": true,
"version": "0.0.129",
"version": "0.0.132",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,28 @@
# jazz-example-pets
## 0.0.230
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.229
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
## 0.0.228
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
## 0.0.227
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-pets",
"private": true,
"version": "0.0.227",
"version": "0.0.230",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,28 @@
# reactions
## 0.0.110
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.109
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
## 0.0.108
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
## 0.0.107
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "reactions",
"private": true,
"version": "0.0.107",
"version": "0.0.110",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,31 @@
# richtext-tiptap
## 0.1.23
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
- jazz-richtext-tiptap@0.1.21
## 0.1.22
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
- jazz-richtext-tiptap@0.1.20
## 0.1.21
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
- jazz-richtext-tiptap@0.1.19
## 0.1.20
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "richtext-tiptap",
"private": true,
"version": "0.1.20",
"version": "0.1.23",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,31 @@
# richtext
## 0.0.100
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
- jazz-richtext-prosemirror@0.1.32
## 0.0.99
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
- jazz-richtext-prosemirror@0.1.31
## 0.0.98
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
- jazz-richtext-prosemirror@0.1.30
## 0.0.97
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "richtext",
"private": true,
"version": "0.0.97",
"version": "0.0.100",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,30 @@
# todo-vue
## 0.0.112
### Patch Changes
- jazz-browser@0.14.16
- jazz-tools@0.14.16
- jazz-vue@0.14.16
## 0.0.111
### Patch Changes
- jazz-browser@0.14.15
- jazz-tools@0.14.15
- jazz-vue@0.14.15
## 0.0.110
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-browser@0.14.14
- jazz-vue@0.14.14
## 0.0.109
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "todo-vue",
"version": "0.0.109",
"version": "0.0.112",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,5 +1,28 @@
# jazz-example-todo
## 0.0.229
### Patch Changes
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.228
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-tools@0.14.15
## 0.0.227
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-react@0.14.14
## 0.0.226
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-todo",
"private": true,
"version": "0.0.226",
"version": "0.0.229",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,31 @@
# version-history
## 0.0.108
### Patch Changes
- jazz-inspector@0.14.16
- jazz-react@0.14.16
- jazz-tools@0.14.16
## 0.0.107
### Patch Changes
- Updated dependencies [f9590f9]
- jazz-react@0.14.15
- jazz-inspector@0.14.15
- jazz-tools@0.14.15
## 0.0.106
### Patch Changes
- Updated dependencies [e32a1f7]
- jazz-tools@0.14.14
- jazz-inspector@0.14.14
- jazz-react@0.14.14
## 0.0.105
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "version-history",
"private": true,
"version": "0.0.105",
"version": "0.0.108",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -15,8 +15,6 @@ We're still in the process of:
- completing all the details of this upgrade guide
</small>
**Note: React Native is currently broken based on an [underlying Zod v4 issue](https://github.com/colinhacks/zod/issues/4148).**
If you see something broken, please let us know on [Discord](https://discord.gg/utDMjHYg42) and check back in a couple hours.
Thanks for your patience!

View File

@@ -1,5 +1,21 @@
# cojson-storage-indexeddb
## 0.14.16
### Patch Changes
- Updated dependencies [5e253cc]
- cojson@0.14.16
- cojson-storage@0.14.16
## 0.14.15
### Patch Changes
- Updated dependencies [23daa7c]
- cojson-storage@0.14.15
- cojson@0.14.15
## 0.14.1
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "cojson-storage-indexeddb",
"version": "0.14.1",
"version": "0.14.16",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",

View File

@@ -1,12 +1,21 @@
import { LocalNode } from "cojson";
import { StorageManagerAsync } from "cojson-storage";
import { WasmCrypto } from "cojson/crypto/WasmCrypto";
import { expect, test, vi } from "vitest";
import { afterEach, beforeEach, expect, test, vi } from "vitest";
import { IDBStorage } from "../index.js";
import { toSimplifiedMessages } from "./messagesTestUtils.js";
import { trackMessages, waitFor } from "./testUtils.js";
const Crypto = await WasmCrypto.create();
let syncMessages: ReturnType<typeof trackMessages>;
beforeEach(() => {
syncMessages = trackMessages();
});
afterEach(() => {
syncMessages.restore();
});
test("Should be able to initialize and load from empty DB", async () => {
const agentSecret = Crypto.newRandomAgentSecret();
@@ -33,8 +42,6 @@ test("should sync and load data from storage", async () => {
Crypto,
);
const node1Sync = trackMessages(node1);
const peer = await IDBStorage.asPeer();
node1.syncManager.addPeer(peer);
@@ -53,7 +60,7 @@ test("should sync and load data from storage", async () => {
Map: map.core,
Group: group.core,
},
node1Sync.messages,
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
@@ -64,7 +71,8 @@ test("should sync and load data from storage", async () => {
]
`);
node1Sync.restore();
node1.gracefulShutdown();
syncMessages.clear();
const node2 = new LocalNode(
agentSecret,
@@ -72,8 +80,6 @@ test("should sync and load data from storage", async () => {
Crypto,
);
const node2Sync = trackMessages(node2);
const peer2 = await IDBStorage.asPeer();
node2.syncManager.addPeer(peer2);
@@ -91,7 +97,7 @@ test("should sync and load data from storage", async () => {
Map: map.core,
Group: group.core,
},
node2Sync.messages,
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
@@ -100,8 +106,6 @@ test("should sync and load data from storage", async () => {
"storage -> CONTENT Map header: true new: After: 0 New: 1",
]
`);
node2Sync.restore();
});
test("should send an empty content message if there is no content", async () => {
@@ -113,8 +117,6 @@ test("should send an empty content message if there is no content", async () =>
Crypto,
);
const node1Sync = trackMessages(node1);
const peer = await IDBStorage.asPeer();
node1.syncManager.addPeer(peer);
@@ -131,7 +133,7 @@ test("should send an empty content message if there is no content", async () =>
Map: map.core,
Group: group.core,
},
node1Sync.messages,
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
@@ -142,7 +144,8 @@ test("should send an empty content message if there is no content", async () =>
]
`);
node1Sync.restore();
syncMessages.clear();
node1.gracefulShutdown();
const node2 = new LocalNode(
agentSecret,
@@ -150,8 +153,6 @@ test("should send an empty content message if there is no content", async () =>
Crypto,
);
const node2Sync = trackMessages(node2);
const peer2 = await IDBStorage.asPeer();
node2.syncManager.addPeer(peer2);
@@ -167,7 +168,7 @@ test("should send an empty content message if there is no content", async () =>
Map: map.core,
Group: group.core,
},
node2Sync.messages,
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
@@ -176,8 +177,6 @@ test("should send an empty content message if there is no content", async () =>
"storage -> CONTENT Map header: true new: ",
]
`);
node2Sync.restore();
});
test("should load dependencies correctly (group inheritance)", async () => {
@@ -189,8 +188,6 @@ test("should load dependencies correctly (group inheritance)", async () => {
Crypto,
);
const node1Sync = trackMessages(node1);
const peer = await IDBStorage.asPeer();
node1.syncManager.addPeer(peer);
@@ -213,7 +210,7 @@ test("should load dependencies correctly (group inheritance)", async () => {
Group: group.core,
ParentGroup: parentGroup.core,
},
node1Sync.messages,
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
@@ -226,7 +223,8 @@ test("should load dependencies correctly (group inheritance)", async () => {
]
`);
node1Sync.restore();
syncMessages.clear();
node1.gracefulShutdown();
const node2 = new LocalNode(
agentSecret,
@@ -234,8 +232,6 @@ test("should load dependencies correctly (group inheritance)", async () => {
Crypto,
);
const node2Sync = trackMessages(node2);
const peer2 = await IDBStorage.asPeer();
node2.syncManager.addPeer(peer2);
@@ -253,7 +249,7 @@ test("should load dependencies correctly (group inheritance)", async () => {
Group: group.core,
ParentGroup: parentGroup.core,
},
node2Sync.messages,
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
@@ -274,8 +270,6 @@ test("should not send the same dependency value twice", async () => {
Crypto,
);
const node1Sync = trackMessages(node1);
const peer = await IDBStorage.asPeer();
node1.syncManager.addPeer(peer);
@@ -293,7 +287,8 @@ test("should not send the same dependency value twice", async () => {
await new Promise((resolve) => setTimeout(resolve, 200));
node1Sync.restore();
syncMessages.clear();
node1.gracefulShutdown();
const node2 = new LocalNode(
agentSecret,
@@ -301,8 +296,6 @@ test("should not send the same dependency value twice", async () => {
Crypto,
);
const node2Sync = trackMessages(node2);
const peer2 = await IDBStorage.asPeer();
node2.syncManager.addPeer(peer2);
@@ -323,7 +316,7 @@ test("should not send the same dependency value twice", async () => {
ParentGroup: parentGroup.core,
MapFromParent: mapFromParent.core,
},
node2Sync.messages,
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
@@ -349,8 +342,6 @@ test("should recover from data loss", async () => {
Crypto,
);
const node1Sync = trackMessages(node1);
const peer = await IDBStorage.asPeer();
node1.syncManager.addPeer(peer);
@@ -384,7 +375,7 @@ test("should recover from data loss", async () => {
Map: map.core,
Group: group.core,
},
node1Sync.messages,
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
@@ -399,7 +390,8 @@ test("should recover from data loss", async () => {
]
`);
node1Sync.restore();
syncMessages.clear();
node1.gracefulShutdown();
const node2 = new LocalNode(
agentSecret,
@@ -407,8 +399,6 @@ test("should recover from data loss", async () => {
Crypto,
);
const node2Sync = trackMessages(node2);
const peer2 = await IDBStorage.asPeer();
node2.syncManager.addPeer(peer2);
@@ -432,7 +422,7 @@ test("should recover from data loss", async () => {
Map: map.core,
Group: group.core,
},
node2Sync.messages,
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
@@ -491,7 +481,7 @@ test("should sync multiple sessions in a single content message", async () => {
Crypto,
);
const node3Sync = trackMessages(node3);
syncMessages.clear();
node3.syncManager.addPeer(await IDBStorage.asPeer());
@@ -508,7 +498,7 @@ test("should sync multiple sessions in a single content message", async () => {
Map: map.core,
Group: group.core,
},
node3Sync.messages,
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
@@ -517,8 +507,6 @@ test("should sync multiple sessions in a single content message", async () => {
"storage -> CONTENT Map header: true new: After: 0 New: 1 | After: 0 New: 1",
]
`);
node3Sync.restore();
});
test("large coValue upload streaming", async () => {
@@ -559,7 +547,7 @@ test("large coValue upload streaming", async () => {
Crypto,
);
const node2Sync = trackMessages(node2);
syncMessages.clear();
node2.syncManager.addPeer(await IDBStorage.asPeer());
@@ -581,7 +569,7 @@ test("large coValue upload streaming", async () => {
Map: largeMap.core,
Group: group.core,
},
node2Sync.messages,
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
@@ -598,3 +586,80 @@ test("large coValue upload streaming", async () => {
]
`);
});
test("should sync and load accounts from storage", async () => {
const agentSecret = Crypto.newRandomAgentSecret();
const { node: node1, accountID } = await LocalNode.withNewlyCreatedAccount({
crypto: Crypto,
initialAgentSecret: agentSecret,
peersToLoadFrom: [await IDBStorage.asPeer()],
creationProps: {
name: "test",
},
});
const account1 = node1.getCoValue(accountID);
const profile = node1.expectProfileLoaded(accountID);
const profileGroup = profile.group;
await new Promise((resolve) => setTimeout(resolve, 200));
expect(
toSimplifiedMessages(
{
Account: account1,
Profile: profile.core,
ProfileGroup: profileGroup.core,
},
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
"client -> CONTENT Account header: true new: After: 0 New: 4",
"storage -> KNOWN Account sessions: header/4",
"client -> CONTENT ProfileGroup header: true new: After: 0 New: 5",
"storage -> KNOWN ProfileGroup sessions: header/5",
"client -> CONTENT Profile header: true new: After: 0 New: 1",
"storage -> KNOWN Profile sessions: header/1",
]
`);
node1.gracefulShutdown();
syncMessages.restore();
syncMessages = trackMessages();
const node2 = await LocalNode.withLoadedAccount({
crypto: Crypto,
accountSecret: agentSecret,
accountID,
peersToLoadFrom: [await IDBStorage.asPeer()],
sessionID: Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)),
});
await new Promise((resolve) => setTimeout(resolve, 200));
expect(
toSimplifiedMessages(
{
Account: account1,
Profile: profile.core,
ProfileGroup: profileGroup.core,
},
syncMessages.messages,
),
).toMatchInlineSnapshot(`
[
"client -> LOAD Account sessions: empty",
"storage -> CONTENT Account header: true new: After: 0 New: 4",
"client -> KNOWN Account sessions: header/4",
"client -> LOAD Profile sessions: empty",
"storage -> CONTENT ProfileGroup header: true new: After: 0 New: 5",
"storage -> CONTENT Profile header: true new: After: 0 New: 1",
"client -> KNOWN ProfileGroup sessions: header/5",
"client -> KNOWN Profile sessions: header/1",
]
`);
expect(node2.getCoValue(accountID).isAvailable()).toBeTruthy();
});

View File

@@ -1,8 +1,11 @@
import type { LocalNode, SyncMessage } from "cojson";
import { cojsonInternals } from "cojson";
import { StorageManagerAsync } from "cojson-storage";
import { onTestFinished } from "vitest";
export function trackMessages(node: LocalNode) {
const { SyncManager } = cojsonInternals;
export function trackMessages() {
const messages: {
from: "client" | "server" | "storage";
msg: SyncMessage;
@@ -10,7 +13,7 @@ export function trackMessages(node: LocalNode) {
const originalHandleSyncMessage =
StorageManagerAsync.prototype.handleSyncMessage;
const originalNodeSyncMessage = node.syncManager.handleSyncMessage;
const originalNodeSyncMessage = SyncManager.prototype.handleSyncMessage;
StorageManagerAsync.prototype.handleSyncMessage = async function (msg) {
messages.push({
@@ -20,7 +23,7 @@ export function trackMessages(node: LocalNode) {
return originalHandleSyncMessage.call(this, msg);
};
node.syncManager.handleSyncMessage = async function (msg, peer) {
SyncManager.prototype.handleSyncMessage = async function (msg, peer) {
messages.push({
from: "storage",
msg,
@@ -30,7 +33,12 @@ export function trackMessages(node: LocalNode) {
const restore = () => {
StorageManagerAsync.prototype.handleSyncMessage = originalHandleSyncMessage;
node.syncManager.handleSyncMessage = originalNodeSyncMessage;
SyncManager.prototype.handleSyncMessage = originalNodeSyncMessage;
messages.length = 0;
};
const clear = () => {
messages.length = 0;
};
onTestFinished(() => {
@@ -40,6 +48,7 @@ export function trackMessages(node: LocalNode) {
return {
messages,
restore,
clear,
};
}

View File

@@ -1,5 +1,21 @@
# cojson-storage-sqlite
## 0.14.16
### Patch Changes
- Updated dependencies [5e253cc]
- cojson@0.14.16
- cojson-storage@0.14.16
## 0.14.15
### Patch Changes
- Updated dependencies [23daa7c]
- cojson-storage@0.14.15
- cojson@0.14.15
## 0.14.1
### Patch Changes

View File

@@ -1,13 +1,13 @@
{
"name": "cojson-storage-sqlite",
"type": "module",
"version": "0.14.1",
"version": "0.14.16",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"dependencies": {
"better-sqlite3": "^11.7.0",
"cojson": "workspace:0.14.1",
"cojson": "workspace:0.14.16",
"cojson-storage": "workspace:*"
},
"devDependencies": {

View File

@@ -1,5 +1,20 @@
# cojson-storage
## 0.14.16
### Patch Changes
- Updated dependencies [5e253cc]
- cojson@0.14.16
## 0.14.15
### Patch Changes
- 23daa7c: Align the processing of the group dependencies between LocalNode and Storage.
- Updated dependencies [23daa7c]
- cojson@0.14.15
## 0.14.1
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "cojson-storage",
"version": "0.14.1",
"version": "0.14.16",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",

View File

@@ -15,15 +15,9 @@ import type {
StoredCoValueRow,
StoredSessionRow,
} from "./types.js";
import NewContentMessage = CojsonInternalTypes.NewContentMessage;
import KnownStateMessage = CojsonInternalTypes.KnownStateMessage;
import RawCoID = CojsonInternalTypes.RawCoID;
type OutputMessageMap = Record<
RawCoID,
{ knownMessage: KnownStateMessage; contentMessages?: NewContentMessage[] }
>;
export class StorageManagerAsync {
private readonly toLocalNode: OutgoingSyncQueue;
private readonly dbClient: DBClientInterfaceAsync;
@@ -179,10 +173,10 @@ export class StorageManagerAsync {
coValueRow: StoredCoValueRow,
contentMessage: CojsonInternalTypes.NewContentMessage,
) {
const dependedOnCoValuesList = getDependedOnCoValues({
coValueRow,
newContentMessages: [contentMessage],
});
const dependedOnCoValuesList = getDependedOnCoValues(
coValueRow.header,
contentMessage,
);
for (const dependedOnCoValue of dependedOnCoValuesList) {
if (this.loadedCoValues.has(dependedOnCoValue)) {

View File

@@ -180,10 +180,10 @@ export class StorageManagerSync {
coValueRow: StoredCoValueRow,
contentMessage: CojsonInternalTypes.NewContentMessage,
) {
const dependedOnCoValuesList = getDependedOnCoValues({
coValueRow,
newContentMessages: [contentMessage],
});
const dependedOnCoValuesList = getDependedOnCoValues(
coValueRow.header,
contentMessage,
);
for (const dependedOnCoValue of dependedOnCoValuesList) {
if (this.loadedCoValues.has(dependedOnCoValue)) {

View File

@@ -5,6 +5,7 @@ import {
type Stringified,
cojsonInternals,
} from "cojson";
import type { RawCoID } from "cojson";
import type {
StoredCoValueRow,
StoredSessionRow,
@@ -42,31 +43,29 @@ export function collectNewTxs({
sessionEntry.lastSignature = signature;
}
export function getDependedOnCoValues({
coValueRow,
newContentMessages,
}: {
coValueRow: StoredCoValueRow;
newContentMessages: CojsonInternalTypes.NewContentMessage[];
}) {
return coValueRow.header.ruleset.type === "group"
? getGroupDependedOnCoValues(newContentMessages)
: coValueRow.header.ruleset.type === "ownedByGroup"
? getOwnedByGroupDependedOnCoValues(coValueRow, newContentMessages)
: [];
}
function getGroupDependedOnCoValues(
newContentMessages: CojsonInternalTypes.NewContentMessage[],
export function getDependedOnCoValues(
header: CojsonInternalTypes.CoValueHeader,
contentMessage: CojsonInternalTypes.NewContentMessage,
) {
const keys: CojsonInternalTypes.RawCoID[] = [];
const deps = new Set<RawCoID>();
/**
* Collect all the signing keys inside the transactions to list all the
* dependencies required to correctly access the CoValue.
*/
for (const piece of newContentMessages) {
for (const sessionEntry of Object.values(piece.new)) {
for (const sessionID of Object.keys(contentMessage.new) as SessionID[]) {
const accountId = cojsonInternals.accountOrAgentIDfromSessionID(sessionID);
if (
cojsonInternals.isAccountID(accountId) &&
accountId !== contentMessage.id
) {
deps.add(accountId);
}
}
if (header.ruleset.type === "group") {
/**
* Collect all the signing keys inside the transactions to list all the
* dependencies required to correctly access the CoValue.
*/
for (const sessionEntry of Object.values(contentMessage.new)) {
for (const tx of sessionEntry.newTransactions) {
if (tx.privacy !== "trusting") continue;
@@ -83,7 +82,7 @@ function getGroupDependedOnCoValues(
const key = cojsonInternals.getGroupDependentKey(change.key);
if (key) {
keys.push(key);
deps.add(key);
}
}
}
@@ -91,36 +90,11 @@ function getGroupDependedOnCoValues(
}
}
return keys;
}
function getOwnedByGroupDependedOnCoValues(
coValueRow: StoredCoValueRow,
newContentMessages: CojsonInternalTypes.NewContentMessage[],
) {
if (coValueRow.header.ruleset.type !== "ownedByGroup") return [];
const keys: CojsonInternalTypes.RawCoID[] = [coValueRow.header.ruleset.group];
/**
* Collect all the signing keys inside the transactions to list all the
* dependencies required to correctly access the CoValue.
*/
for (const piece of newContentMessages) {
for (const sessionID of Object.keys(piece.new) as SessionID[]) {
const accountId =
cojsonInternals.accountOrAgentIDfromSessionID(sessionID);
if (
cojsonInternals.isAccountID(accountId) &&
accountId !== coValueRow.id
) {
keys.push(accountId);
}
}
if (header.ruleset.type === "ownedByGroup") {
deps.add(header.ruleset.group);
}
return keys;
return deps;
}
function safeParseChanges(changes: Stringified<JsonValue[]>) {

View File

@@ -13,7 +13,7 @@ function getMockedCoValueId() {
function generateNewContentMessage(
privacy: "trusting" | "private",
changes: any[],
accountId?: `co_z${string}`,
accountId: `co_z${string}`,
) {
return {
action: "content",
@@ -46,18 +46,21 @@ describe("getDependedOnCoValues", () => {
},
} as any;
const result = getDependedOnCoValues({
coValueRow,
newContentMessages: [
generateNewContentMessage("trusting", [
const accountId = getMockedCoValueId();
const result = getDependedOnCoValues(
coValueRow.header,
generateNewContentMessage(
"trusting",
[
{ op: "set", key: "co_zabc123", value: "test" },
{ op: "set", key: "parent_co_zdef456", value: "test" },
{ op: "set", key: "normal_key", value: "test" },
]),
],
});
],
accountId,
),
);
expect(result).toEqual(["co_zabc123", "co_zdef456"]);
expect(result).toEqual(new Set([accountId, "co_zabc123", "co_zdef456"]));
});
it("should not throw on malformed JSON", () => {
@@ -70,9 +73,12 @@ describe("getDependedOnCoValues", () => {
},
} as any;
const message = generateNewContentMessage("trusting", [
{ op: "set", key: "co_zabc123", value: "test" },
]);
const accountId = getMockedCoValueId();
const message = generateNewContentMessage(
"trusting",
[{ op: "set", key: "co_zabc123", value: "test" }],
accountId,
);
message.new["invalid_session" as SessionID] = {
after: 0,
@@ -86,12 +92,9 @@ describe("getDependedOnCoValues", () => {
],
};
const result = getDependedOnCoValues({
coValueRow,
newContentMessages: [message],
});
const result = getDependedOnCoValues(coValueRow.header, message);
expect(result).toEqual(["co_zabc123"]);
expect(result).toEqual(new Set([accountId, "co_zabc123"]));
});
it("should return dependencies for ownedByGroup ruleset", () => {
@@ -123,12 +126,9 @@ describe("getDependedOnCoValues", () => {
newTransactions: [],
};
const result = getDependedOnCoValues({
coValueRow,
newContentMessages: [message],
});
const result = getDependedOnCoValues(coValueRow.header, message);
expect(result).toEqual([groupId, accountId]);
expect(result).toEqual(new Set([groupId, accountId]));
});
it("should return empty array for other ruleset types", () => {
@@ -141,18 +141,21 @@ describe("getDependedOnCoValues", () => {
},
} as any;
const result = getDependedOnCoValues({
coValueRow,
newContentMessages: [
generateNewContentMessage("trusting", [
const accountId = getMockedCoValueId();
const result = getDependedOnCoValues(
coValueRow.header,
generateNewContentMessage(
"trusting",
[
{ op: "set", key: "co_zabc123", value: "test" },
{ op: "set", key: "parent_co_zdef456", value: "test" },
{ op: "set", key: "normal_key", value: "test" },
]),
],
});
],
accountId,
),
);
expect(result).toEqual([]);
expect(result).toEqual(new Set([accountId]));
});
it("should ignore non-trusting transactions in group ruleset", () => {
@@ -165,15 +168,17 @@ describe("getDependedOnCoValues", () => {
},
} as any;
const result = getDependedOnCoValues({
coValueRow,
newContentMessages: [
generateNewContentMessage("private", [
{ op: "set", key: "co_zabc123", value: "test" },
]),
],
});
const accountId = getMockedCoValueId();
expect(result).toEqual([]);
const result = getDependedOnCoValues(
coValueRow.header,
generateNewContentMessage(
"private",
[{ op: "set", key: "co_zabc123", value: "test" }],
accountId,
),
);
expect(result).toEqual(new Set([accountId]));
});
});

View File

@@ -21,7 +21,6 @@ import { fixtures } from "./fixtureMessages.js";
type RawCoID = CojsonInternalTypes.RawCoID;
type NewContentMessage = CojsonInternalTypes.NewContentMessage;
type Transaction = CojsonInternalTypes.Transaction;
vi.mock("../syncUtils");
const coValueIdToLoad = "co_zKwG8NyfZ8GXqcjDHY4NS3SbU2m";
@@ -58,7 +57,7 @@ describe("DB sync manager", () => {
syncManager.sendStateMessage = vi.fn();
// No dependencies found
vi.mocked(getDependedOnCoValues).mockReturnValue([]);
vi.mocked(getDependedOnCoValues).mockReturnValue(new Set());
});
afterEach(() => {
@@ -135,7 +134,7 @@ describe("DB sync manager", () => {
// Fetch dependencies of the current dependency for the future recursion iterations
vi.mocked(getDependedOnCoValues).mockImplementation(
({ coValueRow }) => dependenciesTreeWithLoop[coValueRow.id] || [],
(_, msg) => new Set(dependenciesTreeWithLoop[msg.id] || []),
);
await syncManager.handleSyncMessage(loadMsg);

View File

@@ -1,5 +1,19 @@
# cojson-transport-nodejs-ws
## 0.14.16
### Patch Changes
- Updated dependencies [5e253cc]
- cojson@0.14.16
## 0.14.15
### Patch Changes
- Updated dependencies [23daa7c]
- cojson@0.14.15
## 0.14.1
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "cojson-transport-ws",
"type": "module",
"version": "0.14.1",
"version": "0.14.16",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",

View File

@@ -1,5 +1,17 @@
# cojson
## 0.14.16
### Patch Changes
- 5e253cc: Version bump
## 0.14.15
### Patch Changes
- 23daa7c: Align the processing of the group dependencies between LocalNode and Storage.
## 0.14.1
### Patch Changes

View File

@@ -25,7 +25,7 @@
},
"type": "module",
"license": "MIT",
"version": "0.14.1",
"version": "0.14.16",
"devDependencies": {
"@opentelemetry/sdk-metrics": "^2.0.0",
"typescript": "catalog:"

Some files were not shown because too many files have changed in this diff Show More