Compare commits
43 Commits
jazz-bette
...
jazz-auth-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c2e60ab51 | ||
|
|
1830171930 | ||
|
|
6574090402 | ||
|
|
a6f65472a7 | ||
|
|
109952aa6a | ||
|
|
556bdf977b | ||
|
|
0213b4e5b9 | ||
|
|
01c195756c | ||
|
|
9c69917d24 | ||
|
|
b4d68f0a32 | ||
|
|
fbc3839777 | ||
|
|
296464b282 | ||
|
|
c463654970 | ||
|
|
debc052bdc | ||
|
|
3c7846153d | ||
|
|
e410fedda7 | ||
|
|
52ea0c7a9b | ||
|
|
b91c93caed | ||
|
|
7586c3bac5 | ||
|
|
9b96cd4a65 | ||
|
|
2e66ea8e56 | ||
|
|
336cc1f0fe | ||
|
|
cc2ca5c23c | ||
|
|
3664385113 | ||
|
|
2b2ecdaf3d | ||
|
|
6dbb05320a | ||
|
|
0160a188fa | ||
|
|
ac3e694f4e | ||
|
|
a7dca75955 | ||
|
|
143156cd6a | ||
|
|
1a182f07de | ||
|
|
7e7e7ebb51 | ||
|
|
0966a90f3d | ||
|
|
76f142b70d | ||
|
|
cd2f0846db | ||
|
|
c2e411d056 | ||
|
|
0167153da2 | ||
|
|
feaa69ebdd | ||
|
|
d5fa172b17 | ||
|
|
96de15593b | ||
|
|
5ba03ebc70 | ||
|
|
d8ae47c4d1 | ||
|
|
92c0048984 |
8
.github/CODEOWNERS
vendored
Normal file
8
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
./packages @garden-co/framework
|
||||
./tests @garden-co/framework
|
||||
./packages/quint-ui @garden-co/ui
|
||||
|
||||
./homepage @garden-co/ui
|
||||
./homepage/homepage/content/docs @garden-co/docs
|
||||
./starters @garden-co/docs
|
||||
./examples @garden-co/docs @garden-co/ui
|
||||
@@ -1,5 +1,27 @@
|
||||
# passkey-svelte
|
||||
|
||||
## 0.0.122
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [52ea0c7]
|
||||
- jazz-tools@0.17.9
|
||||
|
||||
## 0.0.121
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ac3e694]
|
||||
- Updated dependencies [6dbb053]
|
||||
- Updated dependencies [1a182f0]
|
||||
- jazz-tools@0.17.8
|
||||
|
||||
## 0.0.120
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-tools@0.17.7
|
||||
|
||||
## 0.0.119
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-svelte",
|
||||
"version": "0.0.119",
|
||||
"version": "0.0.122",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<div id="root">
|
||||
<p>Loading...</p>
|
||||
</div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -24,6 +24,7 @@ function JazzProvider({ children }: { children: ReactNode }) {
|
||||
sync={{
|
||||
peer: `wss://cloud.jazz.tools/?key=${apiKey}`,
|
||||
}}
|
||||
fallback={<p>Loading...</p>}
|
||||
>
|
||||
{children}
|
||||
</JazzReactProviderWithClerk>
|
||||
|
||||
@@ -25,6 +25,11 @@ export const docNavigationItems = [
|
||||
excludeFromNavigation: true,
|
||||
},
|
||||
{ name: "FAQs", href: "/docs/faq", done: 100 },
|
||||
{
|
||||
name: "Troubleshooting",
|
||||
href: "/docs/troubleshooting",
|
||||
done: 100,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -49,18 +49,20 @@ if (bob) {
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
**Note:** if the account ID is of type `string`, because it comes from a URL parameter or something similar, you need to cast it to `ID<Account>` first:
|
||||
**Note:**
|
||||
- Both `Account.load(id)` and `co.account().load(id)` do the same thing — they load an account from its ID.
|
||||
|
||||
<CodeGroup>
|
||||
```tsx twoslash
|
||||
const bobsID = "co_z123";
|
||||
|
||||
import { Group } from "jazz-tools";
|
||||
const group = Group.create();
|
||||
|
||||
// ---cut---
|
||||
import { co, Group } from "jazz-tools";
|
||||
import { ID, Account, co } from "jazz-tools";
|
||||
|
||||
const bob = await co.account().load(bobsID);
|
||||
const bob = await Account.load(bobsID);
|
||||
// Or: const bob = await co.account().load(bobsID);
|
||||
|
||||
if (bob) {
|
||||
group.addMember(bob, "writer");
|
||||
|
||||
@@ -25,7 +25,10 @@ You can use [`create-jazz-app`](/docs/tools/create-jazz-app) to create a new Jaz
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
<Alert variant="info" className="mt-4 flex gap-2 items-center">Requires at least Node.js v20.</Alert>
|
||||
<Alert variant="info" className="mt-4 flex gap-2 items-center">
|
||||
Requires at least Node.js v20.
|
||||
See our [Troubleshooting Guide](https://jazz.tools/docs/troubleshooting) for quick fixes.
|
||||
</Alert>
|
||||
|
||||
{/* <ContentByFramework framework="react">
|
||||
Or you can follow this [React step-by-step guide](/docs/react/guide) where we walk you through building an issue tracker app.
|
||||
|
||||
@@ -53,6 +53,7 @@ npm i -S jazz-tools
|
||||
<Alert variant="info" className="mt-4" title="Note">
|
||||
- Requires at least Node.js v20.
|
||||
- Hermes has added support for `atob` and `btoa` in React Native 0.74. If you are using earlier versions, you may also need to polyfill `atob` and `btoa` in your `package.json`. Packages to try include `text-encoding` and `base-64`, and you can drop `@bacons/text-decoder`.
|
||||
See our [Troubleshooting Guide](https://jazz.tools/docs/troubleshooting) for quick fixes.
|
||||
</Alert>
|
||||
|
||||
#### Fix incompatible dependencies
|
||||
|
||||
@@ -51,7 +51,6 @@ npm i -S jazz-tools
|
||||
</CodeGroup>
|
||||
|
||||
<Alert variant="info" className="mt-4" title="Note">
|
||||
- Requires at least Node.js v20.
|
||||
- Hermes has added support for `atob` and `btoa` in React Native 0.74. If you are using earlier versions, you may also need to polyfill `atob` and `btoa` in your `package.json`. Packages to try include `text-encoding` and `base-64`, and you can drop `@bacons/text-decoder`.
|
||||
</Alert>
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@ pnpm install jazz-tools
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
<Alert variant="info" className="mt-4 flex gap-2 items-center">Requires at least Node.js v20.</Alert>
|
||||
|
||||
## Write your schema
|
||||
|
||||
Define your data schema using [CoValues](/docs/schemas/covalues) from `jazz-tools`.
|
||||
|
||||
@@ -19,8 +19,6 @@ pnpm install jazz-tools
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
<Alert variant="info" className="mt-4 flex gap-2 items-center">Requires at least Node.js v20.</Alert>
|
||||
|
||||
## Write your schema
|
||||
|
||||
See the [schema docs](/docs/schemas/covalues) for more information.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ContentByFramework, CodeGroup } from '@/components/forMdx'
|
||||
import { Alert } from "@garden-co/design-system/src/components/atoms/Alert";
|
||||
|
||||
export const metadata = {
|
||||
description: "Learn how to sync and persist your data using Jazz Cloud, or run your own sync server."
|
||||
@@ -44,8 +45,14 @@ And then use `ws://localhost:4200` as the sync server URL.
|
||||
You can also run this simple sync server behind a proxy that supports WebSockets, for example to provide TLS.
|
||||
In this case, provide the WebSocket endpoint your proxy exposes as the sync server URL.
|
||||
|
||||
<Alert variant="info" className="mt-4 flex gap-2 items-center">
|
||||
Requires at least Node.js v20.
|
||||
See our [Troubleshooting Guide](https://jazz.tools/docs/troubleshooting) for quick fixes.
|
||||
</Alert>
|
||||
|
||||
### Command line options:
|
||||
|
||||
- `--host` / `-h` - the host to run the sync server on. Defaults to 127.0.0.1.
|
||||
- `--port` / `-p` - the port to run the sync server on. Defaults to 4200.
|
||||
- `--in-memory` - keep CoValues in-memory only and do sync only, no persistence. Persistence is enabled by default.
|
||||
- `--db` - the path to the file where to store the data (SQLite). Defaults to `sync-db/storage.db`.
|
||||
|
||||
133
homepage/homepage/content/docs/troubleshooting.mdx
Normal file
133
homepage/homepage/content/docs/troubleshooting.mdx
Normal file
@@ -0,0 +1,133 @@
|
||||
import { ContentByFramework, CodeGroup } from '@/components/forMdx'
|
||||
import { Alert } from "@garden-co/design-system/src/components/atoms/Alert";
|
||||
|
||||
export const metadata = {
|
||||
title: "Setup troubleshooting",
|
||||
description: "A few reported setup hiccups and how to fix them."
|
||||
};
|
||||
|
||||
# Setup troubleshooting
|
||||
|
||||
A few reported setup hiccups and how to fix them.
|
||||
|
||||
---
|
||||
|
||||
## Node.js version requirements
|
||||
|
||||
Jazz requires **Node.js v20 or later** due to native module dependencies.
|
||||
Check your version:
|
||||
|
||||
<CodeGroup>
|
||||
```sh
|
||||
node -v
|
||||
```
|
||||
</CodeGroup>
|
||||
If you’re on Node 18 or earlier, upgrade via nvm:
|
||||
|
||||
<CodeGroup>
|
||||
```sh
|
||||
nvm install 20
|
||||
nvm use 20
|
||||
```
|
||||
</CodeGroup>
|
||||
---
|
||||
## npx jazz-run: command not found
|
||||
If, when running:
|
||||
<CodeGroup>
|
||||
```sh
|
||||
npx jazz-run sync
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
you encounter:
|
||||
|
||||
<CodeGroup>
|
||||
```sh
|
||||
sh: jazz-run: command not found
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
This is often due to an npx cache quirk. (For most apps using Jazz)
|
||||
|
||||
1. Clear your npx cache:
|
||||
|
||||
<CodeGroup>
|
||||
```sh
|
||||
npx clear-npx-cache
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
2. Rerun the command:
|
||||
|
||||
<CodeGroup>
|
||||
```sh
|
||||
npx jazz-run sync
|
||||
```
|
||||
</CodeGroup>
|
||||
---
|
||||
### Node 18 workaround (rebuilding the native module)
|
||||
|
||||
If you can’t upgrade to Node 20+, you can rebuild the native `better-sqlite3` module for your architecture.
|
||||
|
||||
1. Install `jazz-run` locally in your project:
|
||||
|
||||
<CodeGroup>
|
||||
```sh
|
||||
pnpm add -D jazz-run
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
2. Find the installed version of better-sqlite3 inside node_modules.
|
||||
It should look like this:
|
||||
|
||||
<CodeGroup>
|
||||
```sh
|
||||
./node_modules/.pnpm/better-sqlite3{version}/node_modules/better-sqlite3
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
Replace `{version}` with your installed version and run:
|
||||
|
||||
<CodeGroup>
|
||||
```sh
|
||||
# Navigate to the installed module and rebuild
|
||||
pushd ./node_modules/.pnpm/better-sqlite3{version}/node_modules/better-sqlite3
|
||||
&& pnpm install
|
||||
&& popd
|
||||
```
|
||||
</CodeGroup>
|
||||
If you get ModuleNotFoundError: No module named 'distutils':
|
||||
Linux:
|
||||
|
||||
<CodeGroup>
|
||||
```sh
|
||||
pip install --upgrade setuptools
|
||||
```
|
||||
</CodeGroup>
|
||||
macOS:
|
||||
|
||||
<CodeGroup>
|
||||
```sh
|
||||
brew install python-setuptools
|
||||
```
|
||||
</CodeGroup>
|
||||
<p><i>Workaround originally shared by @aheissenberger on Jun 24, 2025.</i></p>
|
||||
|
||||
---
|
||||
|
||||
### Still having trouble?
|
||||
If none of the above fixes work:
|
||||
|
||||
Make sure dependencies installed without errors (`pnpm install`).
|
||||
|
||||
Double-check your `node -v` output matches the required version.
|
||||
|
||||
Open an issue on GitHub with:
|
||||
|
||||
- Your OS and version
|
||||
|
||||
- Node.js version
|
||||
|
||||
- Steps you ran and full error output
|
||||
|
||||
We're always happy to help! If you're stuck, reachout via [Discord](https://discord.gg/utDMjHYg42)
|
||||
@@ -26,3 +26,4 @@ export const navigationItems: NavItemProps[] = [
|
||||
title: "Status",
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
# cojson-storage-indexeddb
|
||||
|
||||
## 0.17.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7586c3b]
|
||||
- cojson@0.17.9
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.7
|
||||
|
||||
## 0.17.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cojson-storage-indexeddb",
|
||||
"version": "0.17.6",
|
||||
"version": "0.17.9",
|
||||
"main": "dist/index.js",
|
||||
"type": "module",
|
||||
"types": "dist/index.d.ts",
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
# cojson-storage-sqlite
|
||||
|
||||
## 0.17.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7586c3b]
|
||||
- cojson@0.17.9
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.7
|
||||
|
||||
## 0.17.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "cojson-storage-sqlite",
|
||||
"type": "module",
|
||||
"version": "0.17.6",
|
||||
"version": "0.17.9",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
# cojson-transport-nodejs-ws
|
||||
|
||||
## 0.17.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [7586c3b]
|
||||
- cojson@0.17.9
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.7
|
||||
|
||||
## 0.17.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "cojson-transport-ws",
|
||||
"type": "module",
|
||||
"version": "0.17.6",
|
||||
"version": "0.17.9",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
# cojson
|
||||
|
||||
## 0.17.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 7586c3b: Adds disableTransactionVerification() method to SyncManager
|
||||
|
||||
## 0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
## 0.17.6
|
||||
|
||||
## 0.17.5
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
},
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"version": "0.17.6",
|
||||
"version": "0.17.9",
|
||||
"devDependencies": {
|
||||
"@opentelemetry/sdk-metrics": "^2.0.0",
|
||||
"libsql": "^0.5.13",
|
||||
|
||||
@@ -132,6 +132,11 @@ export class SyncManager {
|
||||
peers: { [key: PeerID]: PeerState } = {};
|
||||
local: LocalNode;
|
||||
|
||||
// When true, transactions will not be verified.
|
||||
// This is useful when syncing only for storage purposes, with the expectation that
|
||||
// the transactions have already been verified by the [trusted] peer that sent them.
|
||||
private skipVerify: boolean = false;
|
||||
|
||||
peersCounter = metrics.getMeter("cojson").createUpDownCounter("jazz.peers", {
|
||||
description: "Amount of connected peers",
|
||||
valueType: ValueType.INT,
|
||||
@@ -154,6 +159,10 @@ export class SyncManager {
|
||||
|
||||
syncState: SyncStateManager;
|
||||
|
||||
disableTransactionVerification() {
|
||||
this.skipVerify = true;
|
||||
}
|
||||
|
||||
peersInPriorityOrder(): PeerState[] {
|
||||
return Object.values(this.peers).sort((a, b) => {
|
||||
const aPriority = a.priority || 0;
|
||||
@@ -637,6 +646,7 @@ export class SyncManager {
|
||||
undefined,
|
||||
newContentForSession.lastSignature,
|
||||
"immediate",
|
||||
this.skipVerify,
|
||||
);
|
||||
|
||||
if (result.isErr()) {
|
||||
|
||||
@@ -20,11 +20,13 @@ import {
|
||||
createTestNode,
|
||||
loadCoValueOrFail,
|
||||
nodeWithRandomAgentAndSessionID,
|
||||
randomAgentAndSessionID,
|
||||
setupTestAccount,
|
||||
setupTestNode,
|
||||
tearDownTestMetricReader,
|
||||
waitFor,
|
||||
} from "./testUtils.js";
|
||||
import { stableStringify } from "../jsonStringify.js";
|
||||
|
||||
// We want to simulate a real world communication that happens asynchronously
|
||||
TEST_NODE_CONFIG.withAsyncPeers = true;
|
||||
@@ -160,6 +162,36 @@ test("should delete the peer state when the peer closes if persistent is false",
|
||||
expect(syncManager.peers[peer.id]).toBeUndefined();
|
||||
});
|
||||
|
||||
test("should not verify transactions when SyncManager has verification disabled", async () => {
|
||||
jazzCloud.node.syncManager.disableTransactionVerification();
|
||||
|
||||
const [agent] = randomAgentAndSessionID();
|
||||
const client = await setupTestAccount({ connected: true });
|
||||
|
||||
const group = client.node.createGroup();
|
||||
const map = group.createMap();
|
||||
|
||||
map.core.tryAddTransactions(
|
||||
client.node.currentSessionID,
|
||||
[
|
||||
{
|
||||
privacy: "trusting",
|
||||
changes: stableStringify([{ op: "set", key: "hello", value: "world" }]),
|
||||
madeAt: Date.now(),
|
||||
},
|
||||
],
|
||||
undefined,
|
||||
Crypto.sign(agent.currentSignerSecret(), "hash_z12345678"),
|
||||
"immediate",
|
||||
true,
|
||||
);
|
||||
|
||||
await map.core.waitForSync();
|
||||
|
||||
const loadedMap = await loadCoValueOrFail(jazzCloud.node, map.id);
|
||||
expect(loadedMap.get("hello")).toEqual("world");
|
||||
});
|
||||
|
||||
describe("sync - extra tests", () => {
|
||||
test("Node handles disconnection and reconnection of a peer gracefully", async () => {
|
||||
// Create two nodes
|
||||
|
||||
@@ -1,5 +1,31 @@
|
||||
# jazz-react
|
||||
|
||||
## 0.17.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [52ea0c7]
|
||||
- Updated dependencies [7586c3b]
|
||||
- jazz-tools@0.17.9
|
||||
- cojson@0.17.9
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ac3e694]
|
||||
- Updated dependencies [6dbb053]
|
||||
- Updated dependencies [1a182f0]
|
||||
- jazz-tools@0.17.8
|
||||
- cojson@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.7
|
||||
- jazz-tools@0.17.7
|
||||
|
||||
## 0.17.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "community-jazz-vue",
|
||||
"version": "0.17.6",
|
||||
"version": "0.17.9",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -1,5 +1,34 @@
|
||||
# jazz-auth-betterauth
|
||||
|
||||
## 0.17.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [52ea0c7]
|
||||
- Updated dependencies [7586c3b]
|
||||
- jazz-tools@0.17.9
|
||||
- cojson@0.17.9
|
||||
- jazz-betterauth-client-plugin@0.17.9
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ac3e694]
|
||||
- Updated dependencies [6dbb053]
|
||||
- Updated dependencies [1a182f0]
|
||||
- jazz-tools@0.17.8
|
||||
- jazz-betterauth-client-plugin@0.17.8
|
||||
- cojson@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.7
|
||||
- jazz-betterauth-client-plugin@0.17.7
|
||||
- jazz-tools@0.17.7
|
||||
|
||||
## 0.17.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-auth-betterauth",
|
||||
"version": "0.17.6",
|
||||
"version": "0.17.9",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
# jazz-betterauth-client-plugin
|
||||
|
||||
## 0.17.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-betterauth-server-plugin@0.17.9
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-betterauth-server-plugin@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-betterauth-server-plugin@0.17.7
|
||||
|
||||
## 0.17.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-betterauth-client-plugin",
|
||||
"version": "0.17.6",
|
||||
"version": "0.17.9",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -1,5 +1,31 @@
|
||||
# jazz-betterauth-server-plugin
|
||||
|
||||
## 0.17.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [52ea0c7]
|
||||
- Updated dependencies [7586c3b]
|
||||
- jazz-tools@0.17.9
|
||||
- cojson@0.17.9
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ac3e694]
|
||||
- Updated dependencies [6dbb053]
|
||||
- Updated dependencies [1a182f0]
|
||||
- jazz-tools@0.17.8
|
||||
- cojson@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.7
|
||||
- jazz-tools@0.17.7
|
||||
|
||||
## 0.17.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-betterauth-server-plugin",
|
||||
"version": "0.17.6",
|
||||
"version": "0.17.9",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -1,5 +1,37 @@
|
||||
# jazz-react-auth-betterauth
|
||||
|
||||
## 0.17.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [52ea0c7]
|
||||
- Updated dependencies [7586c3b]
|
||||
- jazz-tools@0.17.9
|
||||
- cojson@0.17.9
|
||||
- jazz-auth-betterauth@0.17.9
|
||||
- jazz-betterauth-client-plugin@0.17.9
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ac3e694]
|
||||
- Updated dependencies [6dbb053]
|
||||
- Updated dependencies [1a182f0]
|
||||
- jazz-tools@0.17.8
|
||||
- jazz-auth-betterauth@0.17.8
|
||||
- jazz-betterauth-client-plugin@0.17.8
|
||||
- cojson@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.7
|
||||
- jazz-auth-betterauth@0.17.7
|
||||
- jazz-betterauth-client-plugin@0.17.7
|
||||
- jazz-tools@0.17.7
|
||||
|
||||
## 0.17.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-react-auth-betterauth",
|
||||
"version": "0.17.6",
|
||||
"version": "0.17.9",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.tsx",
|
||||
|
||||
@@ -1,5 +1,38 @@
|
||||
# jazz-run
|
||||
|
||||
## 0.17.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [52ea0c7]
|
||||
- Updated dependencies [7586c3b]
|
||||
- jazz-tools@0.17.9
|
||||
- cojson@0.17.9
|
||||
- cojson-storage-sqlite@0.17.9
|
||||
- cojson-transport-ws@0.17.9
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ac3e694]
|
||||
- Updated dependencies [6dbb053]
|
||||
- Updated dependencies [1a182f0]
|
||||
- jazz-tools@0.17.8
|
||||
- cojson@0.17.8
|
||||
- cojson-storage-sqlite@0.17.8
|
||||
- cojson-transport-ws@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- feaa69e: Add host option to the jazz-run sync command
|
||||
- cojson@0.17.7
|
||||
- cojson-storage-sqlite@0.17.7
|
||||
- cojson-transport-ws@0.17.7
|
||||
- jazz-tools@0.17.7
|
||||
|
||||
## 0.17.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"bin": "./dist/index.js",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"version": "0.17.6",
|
||||
"version": "0.17.9",
|
||||
"exports": {
|
||||
"./startSyncServer": {
|
||||
"types": "./dist/startSyncServer.d.ts",
|
||||
@@ -28,11 +28,11 @@
|
||||
"@effect/printer-ansi": "^0.34.5",
|
||||
"@effect/schema": "^0.71.1",
|
||||
"@effect/typeclass": "^0.25.5",
|
||||
"cojson": "workspace:0.17.6",
|
||||
"cojson-storage-sqlite": "workspace:0.17.6",
|
||||
"cojson-transport-ws": "workspace:0.17.6",
|
||||
"cojson": "workspace:0.17.9",
|
||||
"cojson-storage-sqlite": "workspace:0.17.9",
|
||||
"cojson-transport-ws": "workspace:0.17.9",
|
||||
"effect": "^3.6.5",
|
||||
"jazz-tools": "workspace:0.17.6",
|
||||
"jazz-tools": "workspace:0.17.9",
|
||||
"ws": "^8.14.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
6
packages/jazz-run/src/config.ts
Normal file
6
packages/jazz-run/src/config.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export const serverDefaults = {
|
||||
host: "127.0.0.1",
|
||||
port: 4200,
|
||||
inMemory: false,
|
||||
db: "sync-db/storage.db",
|
||||
};
|
||||
@@ -5,6 +5,7 @@ import { NodeContext, NodeRuntime } from "@effect/platform-node";
|
||||
import { Console, Effect } from "effect";
|
||||
import { createWorkerAccount } from "./createWorkerAccount.js";
|
||||
import { startSyncServer } from "./startSyncServer.js";
|
||||
import { serverDefaults } from "./config.js";
|
||||
|
||||
const jazzTools = Command.make("jazz-tools");
|
||||
|
||||
@@ -39,36 +40,63 @@ const accountCommand = Command.make("account").pipe(
|
||||
Command.withSubcommands([createAccountCommand]),
|
||||
);
|
||||
|
||||
const hostOption = Options.text("host")
|
||||
.pipe(Options.withAlias("h"))
|
||||
.pipe(
|
||||
Options.withDescription(
|
||||
`The host to listen on. Default is ${serverDefaults.host}`,
|
||||
),
|
||||
)
|
||||
.pipe(Options.withDefault(serverDefaults.host));
|
||||
|
||||
const portOption = Options.text("port")
|
||||
.pipe(Options.withAlias("p"))
|
||||
.pipe(
|
||||
Options.withDescription(
|
||||
"Select a different port for the WebSocket server. Default is 4200",
|
||||
`Select a different port for the WebSocket server. Default is ${serverDefaults.port}`,
|
||||
),
|
||||
)
|
||||
.pipe(Options.withDefault("4200"));
|
||||
.pipe(Options.withDefault(serverDefaults.port.toString()));
|
||||
|
||||
const inMemoryOption = Options.boolean("in-memory").pipe(
|
||||
Options.withDescription("Use an in-memory storage instead of file-based"),
|
||||
Options.withDescription("Use an in-memory storage instead of file-based."),
|
||||
);
|
||||
|
||||
const dbOption = Options.file("db")
|
||||
.pipe(
|
||||
Options.withDescription(
|
||||
"The path to the file where to store the data. Default is 'sync-db/storage.db'",
|
||||
`The path to the file where to store the data. Default is '${serverDefaults.db}'`,
|
||||
),
|
||||
)
|
||||
.pipe(Options.withDefault("sync-db/storage.db"));
|
||||
.pipe(Options.withDefault(serverDefaults.db));
|
||||
|
||||
const startSyncServerCommand = Command.make(
|
||||
"sync",
|
||||
{ port: portOption, inMemory: inMemoryOption, db: dbOption },
|
||||
({ port, inMemory, db }) => {
|
||||
{
|
||||
host: hostOption,
|
||||
port: portOption,
|
||||
inMemory: inMemoryOption,
|
||||
db: dbOption,
|
||||
},
|
||||
({ host, port, inMemory, db }) => {
|
||||
return Effect.gen(function* () {
|
||||
yield* Effect.promise(() => startSyncServer({ port, inMemory, db }));
|
||||
const server = yield* Effect.promise(() =>
|
||||
startSyncServer({ host, port, inMemory, db }),
|
||||
);
|
||||
|
||||
const serverAddress = server.address();
|
||||
|
||||
if (!serverAddress) {
|
||||
return yield* Effect.fail(new Error("Failed to start sync server."));
|
||||
}
|
||||
|
||||
const socketAddress =
|
||||
typeof serverAddress === "object"
|
||||
? `${serverAddress.address}:${serverAddress.port}`
|
||||
: serverAddress;
|
||||
|
||||
yield* Console.log(
|
||||
`COJSON sync server listening on ws://127.0.0.1:${port}`,
|
||||
`COJSON sync server listening on ws://${socketAddress}`,
|
||||
);
|
||||
|
||||
// Keep the server up
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createServer, type Server } from "node:http";
|
||||
import { createServer } from "node:http";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { dirname } from "node:path";
|
||||
import { LocalNode } from "cojson";
|
||||
@@ -6,16 +6,19 @@ import { getBetterSqliteStorage } from "cojson-storage-sqlite";
|
||||
import { createWebSocketPeer } from "cojson-transport-ws";
|
||||
import { WasmCrypto } from "cojson/crypto/WasmCrypto";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { type SyncServer } from "./types.js";
|
||||
|
||||
export const startSyncServer = async ({
|
||||
host,
|
||||
port,
|
||||
inMemory,
|
||||
db,
|
||||
}: {
|
||||
host: string | undefined;
|
||||
port: string | undefined;
|
||||
inMemory: boolean;
|
||||
db: string;
|
||||
}) => {
|
||||
}): Promise<SyncServer> => {
|
||||
const crypto = await WasmCrypto.create();
|
||||
|
||||
const server = createServer((req, res) => {
|
||||
@@ -94,8 +97,6 @@ export const startSyncServer = async ({
|
||||
localNode.gracefulShutdown();
|
||||
});
|
||||
|
||||
server.listen(port ? parseInt(port) : undefined);
|
||||
|
||||
const _close = server.close;
|
||||
|
||||
server.close = () => {
|
||||
@@ -106,5 +107,11 @@ export const startSyncServer = async ({
|
||||
|
||||
Object.defineProperty(server, "localNode", { value: localNode });
|
||||
|
||||
return server as Server & { localNode: LocalNode };
|
||||
server.listen(port ? parseInt(port) : undefined, host);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
server.once("listening", () => {
|
||||
resolve(server as SyncServer);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -5,11 +5,13 @@ import { describe, expect, it, onTestFinished } from "vitest";
|
||||
import { WebSocket } from "ws";
|
||||
import { createWorkerAccount } from "../createWorkerAccount.js";
|
||||
import { startSyncServer } from "../startSyncServer.js";
|
||||
import { serverDefaults } from "../config.js";
|
||||
|
||||
describe("createWorkerAccount - integration tests", () => {
|
||||
it("should create a worker account using the local sync server", async () => {
|
||||
// Pass port: undefined to let the server choose a random port
|
||||
const server = await startSyncServer({
|
||||
host: serverDefaults.host,
|
||||
port: undefined,
|
||||
inMemory: true,
|
||||
db: "",
|
||||
|
||||
@@ -1,24 +1,29 @@
|
||||
import { randomUUID } from "crypto";
|
||||
import { tmpdir } from "os";
|
||||
import { join } from "path";
|
||||
import { LocalNode } from "cojson";
|
||||
import { co, z } from "jazz-tools";
|
||||
import { startWorker } from "jazz-tools/worker";
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { describe, expect, test, afterAll } from "vitest";
|
||||
import { createWorkerAccount } from "../createWorkerAccount.js";
|
||||
import { startSyncServer } from "../startSyncServer.js";
|
||||
import { serverDefaults } from "../config.js";
|
||||
import { unlinkSync } from "node:fs";
|
||||
|
||||
const TestMap = co.map({
|
||||
value: z.string(),
|
||||
});
|
||||
|
||||
const dbPath = join(tmpdir(), `test-${randomUUID()}.db`);
|
||||
|
||||
afterAll(() => {
|
||||
unlinkSync(dbPath);
|
||||
});
|
||||
|
||||
describe("startSyncServer", () => {
|
||||
test("persists values in storage and loads them after restart", async () => {
|
||||
// Create a temporary database file
|
||||
const dbPath = join(tmpdir(), `test-${randomUUID()}.db`);
|
||||
|
||||
// Start first server instance
|
||||
const server1 = await startSyncServer({
|
||||
host: serverDefaults.host,
|
||||
port: "0", // Random available port
|
||||
inMemory: false,
|
||||
db: dbPath,
|
||||
@@ -48,6 +53,7 @@ describe("startSyncServer", () => {
|
||||
|
||||
// Start second server instance with same DB
|
||||
const server2 = await startSyncServer({
|
||||
host: serverDefaults.host,
|
||||
port: "0",
|
||||
inMemory: false,
|
||||
db: dbPath,
|
||||
@@ -74,4 +80,21 @@ describe("startSyncServer", () => {
|
||||
await worker2.done();
|
||||
server2.close();
|
||||
});
|
||||
|
||||
test("starts a sync server with a specific host and port", async () => {
|
||||
const server = await startSyncServer({
|
||||
host: "0.0.0.0",
|
||||
port: "4900",
|
||||
inMemory: false,
|
||||
db: dbPath,
|
||||
});
|
||||
|
||||
expect(server.address()).toEqual({
|
||||
address: "0.0.0.0",
|
||||
port: 4900,
|
||||
family: "IPv4",
|
||||
});
|
||||
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@ import { afterAll, describe, expect, onTestFinished, test } from "vitest";
|
||||
import { createWorkerAccount } from "../createWorkerAccount.js";
|
||||
import { startSyncServer } from "../startSyncServer.js";
|
||||
import { waitFor } from "./utils.js";
|
||||
import { serverDefaults } from "../config.js";
|
||||
|
||||
const dbPath = join(tmpdir(), `test-${randomUUID()}.db`);
|
||||
|
||||
@@ -30,9 +31,9 @@ async function setup<
|
||||
| (AccountClass<Account> & CoValueFromRaw<Account>)
|
||||
| AnyAccountSchema,
|
||||
>(AccountSchema?: S) {
|
||||
const { server, port } = await setupSyncServer();
|
||||
const { server, port, host } = await setupSyncServer();
|
||||
|
||||
const syncServer = `ws://localhost:${port}`;
|
||||
const syncServer = `ws://${host}:${port}`;
|
||||
|
||||
const { worker, done, waitForConnection, subscribeToConnectionChange } =
|
||||
await setupWorker(syncServer, AccountSchema);
|
||||
@@ -43,13 +44,18 @@ async function setup<
|
||||
syncServer,
|
||||
server,
|
||||
port,
|
||||
host,
|
||||
waitForConnection,
|
||||
subscribeToConnectionChange,
|
||||
};
|
||||
}
|
||||
|
||||
async function setupSyncServer(defaultPort = "0") {
|
||||
async function setupSyncServer(
|
||||
defaultHost = serverDefaults.host,
|
||||
defaultPort = "0",
|
||||
) {
|
||||
const server = await startSyncServer({
|
||||
host: defaultHost,
|
||||
port: defaultPort,
|
||||
inMemory: false,
|
||||
db: dbPath,
|
||||
@@ -61,7 +67,7 @@ async function setupSyncServer(defaultPort = "0") {
|
||||
server.close();
|
||||
});
|
||||
|
||||
return { server, port };
|
||||
return { server, port, host: defaultHost };
|
||||
}
|
||||
|
||||
async function setupWorker<
|
||||
@@ -258,6 +264,7 @@ describe("startWorker integration", () => {
|
||||
|
||||
// Start a new sync server on the same port
|
||||
const newServer = await startSyncServer({
|
||||
host: worker1.host,
|
||||
port: worker1.port,
|
||||
inMemory: true,
|
||||
db: "",
|
||||
@@ -290,6 +297,7 @@ describe("startWorker integration", () => {
|
||||
|
||||
// Start a new sync server on the same port
|
||||
const newServer = await startSyncServer({
|
||||
host: worker1.host,
|
||||
port: worker1.port,
|
||||
inMemory: true,
|
||||
db: "",
|
||||
@@ -326,6 +334,7 @@ describe("startWorker integration", () => {
|
||||
|
||||
// Start a new sync server on the same port
|
||||
const newServer = await startSyncServer({
|
||||
host: worker1.host,
|
||||
port: worker1.port,
|
||||
inMemory: true,
|
||||
db: "",
|
||||
|
||||
4
packages/jazz-run/src/types.ts
Normal file
4
packages/jazz-run/src/types.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { type Server } from "node:http";
|
||||
import { type LocalNode } from "cojson";
|
||||
|
||||
export type SyncServer = Server & { localNode: LocalNode };
|
||||
@@ -1,5 +1,34 @@
|
||||
# jazz-tools
|
||||
|
||||
## 0.17.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 52ea0c7: Explicit loadAs in upsertUnique to use it without loaded context
|
||||
- Updated dependencies [7586c3b]
|
||||
- cojson@0.17.9
|
||||
- cojson-storage-indexeddb@0.17.9
|
||||
- cojson-transport-ws@0.17.9
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- ac3e694: Fixed an issue where CoValue schemas could be incorrectly passed to `co.map` and `co.profile` schema definers.
|
||||
- 6dbb053: Prosemirror: fix RangeError triggered when creating invalid HTML
|
||||
- 1a182f0: Add missing BaseProfileShape export
|
||||
- cojson@0.17.8
|
||||
- cojson-storage-indexeddb@0.17.8
|
||||
- cojson-transport-ws@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.7
|
||||
- cojson-storage-indexeddb@0.17.7
|
||||
- cojson-transport-ws@0.17.7
|
||||
|
||||
## 0.17.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
},
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"version": "0.17.6",
|
||||
"version": "0.17.9",
|
||||
"dependencies": {
|
||||
"@manuscripts/prosemirror-recreate-steps": "^0.1.4",
|
||||
"@scure/base": "1.2.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { recreateTransform } from "@manuscripts/prosemirror-recreate-steps";
|
||||
import { CoRichText } from "jazz-tools";
|
||||
import { Transaction } from "prosemirror-state";
|
||||
import { EditorState, Transaction } from "prosemirror-state";
|
||||
import { EditorView } from "prosemirror-view";
|
||||
import { htmlToProseMirror, proseMirrorToHtml } from "./converter.js";
|
||||
|
||||
@@ -34,6 +34,8 @@ export const META_KEY = "fromJazz";
|
||||
export function createSyncHandlers(coRichText: CoRichText | undefined) {
|
||||
// Store the editor view in a closure
|
||||
let view: EditorView | undefined;
|
||||
let localChange = false;
|
||||
let remoteChange = false;
|
||||
|
||||
/**
|
||||
* Handles changes from CoRichText by updating the ProseMirror editor.
|
||||
@@ -47,24 +49,47 @@ export function createSyncHandlers(coRichText: CoRichText | undefined) {
|
||||
* @param newText - The updated CoRichText instance
|
||||
*/
|
||||
function handleCoRichTextChange(newText: CoRichText) {
|
||||
if (!view || !newText) return;
|
||||
if (!view || !newText || localChange || remoteChange) return;
|
||||
|
||||
const pmDoc = htmlToProseMirror(
|
||||
newText.toString(),
|
||||
view.state.doc.type.schema,
|
||||
);
|
||||
const transform = recreateTransform(view.state.doc, pmDoc);
|
||||
const currentView = view;
|
||||
remoteChange = true;
|
||||
|
||||
// Create a new transaction
|
||||
const tr = view.state.tr;
|
||||
// Changes on CoPlainText are emitted word by word, which means that it creates
|
||||
// invalid intermediate states when wrapping a document with HTML tags
|
||||
// To fix the issue, we throttle the changes to the next microtask
|
||||
queueMicrotask(() => {
|
||||
const pmDoc = htmlToProseMirror(
|
||||
newText.toString(),
|
||||
currentView.state.doc.type.schema,
|
||||
);
|
||||
|
||||
// Apply all steps from the transform to the transaction
|
||||
transform.steps.forEach((step) => {
|
||||
tr.step(step);
|
||||
try {
|
||||
const transform = recreateTransform(currentView.state.doc, pmDoc);
|
||||
|
||||
// Create a new transaction
|
||||
const tr = currentView.state.tr;
|
||||
|
||||
// Apply all steps from the transform to the transaction
|
||||
transform.steps.forEach((step) => {
|
||||
tr.step(step);
|
||||
});
|
||||
|
||||
tr.setMeta(META_KEY, true);
|
||||
|
||||
currentView.dispatch(tr);
|
||||
} catch (err) {
|
||||
// Sometimes recreateTransform fails, so we just rebuild the doc from scratch
|
||||
const newState = EditorState.create({
|
||||
schema: currentView.state.schema,
|
||||
doc: pmDoc,
|
||||
plugins: currentView.state.plugins,
|
||||
selection: currentView.state.selection,
|
||||
});
|
||||
currentView.updateState(newState);
|
||||
} finally {
|
||||
remoteChange = false;
|
||||
}
|
||||
});
|
||||
|
||||
tr.setMeta(META_KEY, true);
|
||||
view.dispatch(tr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +107,12 @@ export function createSyncHandlers(coRichText: CoRichText | undefined) {
|
||||
|
||||
if (tr.docChanged) {
|
||||
const str = proseMirrorToHtml(tr.doc);
|
||||
coRichText.applyDiff(str);
|
||||
localChange = true;
|
||||
try {
|
||||
coRichText.applyDiff(str);
|
||||
} finally {
|
||||
localChange = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { Account, CoRichText } from "jazz-tools";
|
||||
import { CoRichText } from "jazz-tools";
|
||||
import { createJazzTestAccount, setupJazzTestSync } from "jazz-tools/testing";
|
||||
import { schema } from "prosemirror-schema-basic";
|
||||
import { EditorState, TextSelection } from "prosemirror-state";
|
||||
import { Plugin } from "prosemirror-state";
|
||||
import { EditorView } from "prosemirror-view";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
afterEach,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
onTestFinished,
|
||||
} from "vitest";
|
||||
import { createJazzPlugin } from "../lib/plugin";
|
||||
import { Schema } from "prosemirror-model";
|
||||
import { schema as basicSchema } from "prosemirror-schema-basic";
|
||||
import { addListNodes } from "prosemirror-schema-list";
|
||||
|
||||
let account: Account;
|
||||
let coRichText: CoRichText;
|
||||
let plugin: Plugin;
|
||||
let state: EditorState;
|
||||
let view: EditorView;
|
||||
|
||||
beforeEach(async () => {
|
||||
await setupJazzTestSync();
|
||||
account = await createJazzTestAccount({ isCurrentActiveAccount: true });
|
||||
const schema = new Schema({
|
||||
nodes: addListNodes(basicSchema.spec.nodes, "paragraph block*", "block"),
|
||||
marks: basicSchema.spec.marks,
|
||||
});
|
||||
|
||||
async function setupTest(initialContent = "<p>Hello</p>") {
|
||||
// Create a real CoRichText with the test account as owner
|
||||
coRichText = CoRichText.create("<p>Hello</p>", account);
|
||||
const coRichText = CoRichText.create(initialContent);
|
||||
|
||||
plugin = createJazzPlugin(coRichText);
|
||||
state = EditorState.create({
|
||||
const plugin = createJazzPlugin(coRichText);
|
||||
const state = EditorState.create({
|
||||
schema,
|
||||
plugins: [plugin],
|
||||
});
|
||||
@@ -33,25 +37,32 @@ beforeEach(async () => {
|
||||
document.body.appendChild(editorElement);
|
||||
|
||||
// Initialize the editor view
|
||||
view = new EditorView(editorElement, {
|
||||
const view = new EditorView(editorElement, {
|
||||
state,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// Clean up the editor view
|
||||
if (view) {
|
||||
onTestFinished(() => {
|
||||
view.destroy();
|
||||
view.dom.remove();
|
||||
}
|
||||
editorElement.remove();
|
||||
});
|
||||
|
||||
return { coRichText, plugin, state, view, editorElement };
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
await setupJazzTestSync();
|
||||
await createJazzTestAccount({ isCurrentActiveAccount: true });
|
||||
});
|
||||
|
||||
describe("createJazzPlugin", () => {
|
||||
it("initializes editor with CoRichText content", () => {
|
||||
it("initializes editor with CoRichText content", async () => {
|
||||
const { state } = await setupTest();
|
||||
expect(state.doc.textContent).toContain("Hello");
|
||||
});
|
||||
|
||||
it("updates editor when CoRichText changes", async () => {
|
||||
const { coRichText, view } = await setupTest();
|
||||
|
||||
// Update CoRichText content
|
||||
coRichText.applyDiff("<p>Updated content</p>");
|
||||
|
||||
@@ -61,7 +72,9 @@ describe("createJazzPlugin", () => {
|
||||
expect(view.state.doc.textContent).toContain("Updated content");
|
||||
});
|
||||
|
||||
it("updates CoRichText when editor content changes", () => {
|
||||
it("updates CoRichText when editor content changes", async () => {
|
||||
const { coRichText, view } = await setupTest();
|
||||
|
||||
// Create a transaction to update the editor content
|
||||
const tr = view.state.tr.insertText(" World", 6);
|
||||
view.dispatch(tr);
|
||||
@@ -70,8 +83,8 @@ describe("createJazzPlugin", () => {
|
||||
expect(coRichText.toString()).toContain("Hello World");
|
||||
});
|
||||
|
||||
it("handles empty CoRichText initialization", () => {
|
||||
const emptyCoRichText = CoRichText.create("", account);
|
||||
it("handles empty CoRichText initialization", async () => {
|
||||
const emptyCoRichText = CoRichText.create("");
|
||||
const emptyPlugin = createJazzPlugin(emptyCoRichText);
|
||||
const emptyState = EditorState.create({
|
||||
schema,
|
||||
@@ -81,7 +94,7 @@ describe("createJazzPlugin", () => {
|
||||
expect(emptyState.doc.textContent).toBe("");
|
||||
});
|
||||
|
||||
it("handles undefined CoRichText", () => {
|
||||
it("handles undefined CoRichText", async () => {
|
||||
const undefinedPlugin = createJazzPlugin(undefined);
|
||||
const undefinedState = EditorState.create({
|
||||
schema,
|
||||
@@ -91,7 +104,9 @@ describe("createJazzPlugin", () => {
|
||||
expect(undefinedState.doc.textContent).toBe("");
|
||||
});
|
||||
|
||||
it("prevents infinite update loops", () => {
|
||||
it("prevents infinite update loops", async () => {
|
||||
const { coRichText, view } = await setupTest();
|
||||
|
||||
// Create a transaction that would normally trigger a CoRichText update
|
||||
const tr = view.state.tr.insertText(" Loop", 6);
|
||||
|
||||
@@ -106,7 +121,9 @@ describe("createJazzPlugin", () => {
|
||||
expect(coRichText.toString()).not.toContain("Loop");
|
||||
});
|
||||
|
||||
it.skip("preserves selection when CoRichText changes", () => {
|
||||
it("preserves selection when CoRichText changes", async () => {
|
||||
const { coRichText, view } = await setupTest();
|
||||
|
||||
// Set a selection in the editor
|
||||
const tr = view.state.tr.setSelection(
|
||||
TextSelection.create(view.state.doc, 2, 5),
|
||||
@@ -118,10 +135,49 @@ describe("createJazzPlugin", () => {
|
||||
expect(view.state.selection.to).toBe(5);
|
||||
|
||||
// Update CoRichText content
|
||||
coRichText.applyDiff("<p>Updated content</p>");
|
||||
coRichText.applyDiff("<p>Hello world</p>");
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
// Verify selection is preserved after content update
|
||||
expect(view.state.selection.from).toBe(2);
|
||||
expect(view.state.selection.to).toBe(5);
|
||||
});
|
||||
|
||||
it("falls back to creating a new EditorState when the transform fails", async () => {
|
||||
const { coRichText, editorElement } = await setupTest(
|
||||
"<p>A <strong>hu<em>man</strong></em>.</p>",
|
||||
);
|
||||
|
||||
// Wait for the next tick to allow the update to propagate
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
// Update CoRichText content
|
||||
coRichText.applyDiff(
|
||||
"<ol><li><p>A <strong>hu</strong><em><strong>man</strong></em>.</p></li></ol>",
|
||||
);
|
||||
|
||||
// Wait for the next tick to allow the update to propagate
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
expect(editorElement.querySelector(".ProseMirror")?.innerHTML).toBe(
|
||||
"<ol><li><p>A <strong>hu</strong><em><strong>man</strong></em>.</p></li></ol>",
|
||||
);
|
||||
});
|
||||
|
||||
it("handles updates with emojis", async () => {
|
||||
const { coRichText, editorElement } = await setupTest(
|
||||
"<p>A <strong>hu</strong><em><strong>man</strong></em>.</p>",
|
||||
);
|
||||
|
||||
// Update CoRichText content
|
||||
coRichText.applyDiff("<p>A human💪</p>");
|
||||
|
||||
// Wait for the next tick to allow the update to propagate
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
expect(editorElement.querySelector(".ProseMirror")?.innerHTML).toBe(
|
||||
"<p>A human💪</p>",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from "jazz-tools";
|
||||
import { LocalStorageKVStore } from "jazz-tools/browser";
|
||||
import { useAuthSecretStorage, useJazzContext } from "jazz-tools/react-core";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { ReactNode, useEffect, useMemo, useState } from "react";
|
||||
import { JazzProviderProps, JazzReactProvider } from "../provider.js";
|
||||
|
||||
function useJazzClerkAuth(clerk: MinimalClerkClient) {
|
||||
@@ -43,7 +43,9 @@ export const JazzReactProviderWithClerk = <
|
||||
| (AccountClass<Account> & CoValueFromRaw<Account>)
|
||||
| AnyAccountSchema,
|
||||
>(
|
||||
props: { clerk: MinimalClerkClient } & JazzProviderProps<S>,
|
||||
props: {
|
||||
clerk: MinimalClerkClient;
|
||||
} & JazzProviderProps<S>,
|
||||
) => {
|
||||
const [isLoaded, setIsLoaded] = useState(false);
|
||||
|
||||
@@ -61,7 +63,7 @@ export const JazzReactProviderWithClerk = <
|
||||
}, []);
|
||||
|
||||
if (!isLoaded) {
|
||||
return null;
|
||||
return props.fallback ?? null;
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -20,6 +20,7 @@ export type JazzProviderProps<
|
||||
> = {
|
||||
children: React.ReactNode;
|
||||
enableSSR?: boolean;
|
||||
fallback?: React.ReactNode | null;
|
||||
} & JazzContextManagerProps<S>;
|
||||
|
||||
/** @category Context & Hooks */
|
||||
@@ -38,6 +39,7 @@ export function JazzReactProvider<
|
||||
logOutReplacement,
|
||||
onAnonymousAccountDiscarded,
|
||||
enableSSR,
|
||||
fallback = null,
|
||||
}: JazzProviderProps<S>) {
|
||||
const [contextManager] = React.useState(
|
||||
() =>
|
||||
@@ -100,7 +102,7 @@ export function JazzReactProvider<
|
||||
return (
|
||||
<JazzContext.Provider value={value}>
|
||||
<JazzContextManagerContext.Provider value={contextManager}>
|
||||
{value && children}
|
||||
{value ? children : fallback}
|
||||
</JazzContextManagerContext.Provider>
|
||||
</JazzContext.Provider>
|
||||
);
|
||||
|
||||
@@ -628,7 +628,11 @@ export class CoMap extends CoValueBase implements CoValue {
|
||||
resolve?: RefsToResolveStrict<M, R>;
|
||||
},
|
||||
): Promise<Resolved<M, R> | null> {
|
||||
let mapId = CoMap._findUnique(options.unique, options.owner.id);
|
||||
const mapId = CoMap._findUnique(
|
||||
options.unique,
|
||||
options.owner.id,
|
||||
options.owner._loadedAs,
|
||||
);
|
||||
let map: Resolved<M, R> | null = await loadCoValueWithoutMe(this, mapId, {
|
||||
...options,
|
||||
loadAs: options.owner._loadedAs,
|
||||
|
||||
@@ -35,6 +35,7 @@ export type {
|
||||
TextPos,
|
||||
AccountClass,
|
||||
AccountCreationProps,
|
||||
BaseProfileShape,
|
||||
} from "./internal.js";
|
||||
|
||||
export {
|
||||
|
||||
@@ -38,9 +38,14 @@ import {
|
||||
// Note: if you're editing this function, edit the `isAnyCoValueSchema`
|
||||
// function in `zodReExport.ts` as well
|
||||
export function isAnyCoValueSchema(
|
||||
schema: AnyZodOrCoValueSchema | CoValueClass,
|
||||
schema: unknown,
|
||||
): schema is AnyCoreCoValueSchema {
|
||||
return "collaborative" in schema && schema.collaborative === true;
|
||||
return (
|
||||
typeof schema === "object" &&
|
||||
schema !== null &&
|
||||
"collaborative" in schema &&
|
||||
schema.collaborative === true
|
||||
);
|
||||
}
|
||||
|
||||
export function isCoValueSchema(
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
createCoreCoPlainTextSchema,
|
||||
createCoreFileStreamSchema,
|
||||
hydrateCoreCoValueSchema,
|
||||
isAnyCoValueSchema,
|
||||
} from "../../internal.js";
|
||||
import {
|
||||
CoDiscriminatedUnionSchema,
|
||||
@@ -36,6 +37,11 @@ import { z } from "./zodReExport.js";
|
||||
export const coMapDefiner = <Shape extends z.core.$ZodLooseShape>(
|
||||
shape: Shape,
|
||||
): CoMapSchema<Shape> => {
|
||||
if (isAnyCoValueSchema(shape as any)) {
|
||||
throw new Error(
|
||||
"co.map() expects an object as its argument, not a CoValue schema",
|
||||
);
|
||||
}
|
||||
const coreSchema = createCoreCoMapSchema(shape);
|
||||
return hydrateCoreCoValueSchema(coreSchema);
|
||||
};
|
||||
@@ -116,6 +122,11 @@ export const coProfileDefiner = <
|
||||
>(
|
||||
shape: Shape & Partial<DefaultProfileShape> = {} as any,
|
||||
): CoProfileSchema<Shape> => {
|
||||
if (isAnyCoValueSchema(shape as any)) {
|
||||
throw new Error(
|
||||
"co.profile() expects an object as its argument, not a CoValue schema",
|
||||
);
|
||||
}
|
||||
const ehnancedShape = Object.assign(shape, {
|
||||
name: z.string(),
|
||||
inbox: z.optional(z.string()),
|
||||
|
||||
@@ -88,6 +88,11 @@ function containsCoValueSchema(shape?: core.$ZodLooseShape): boolean {
|
||||
|
||||
// Note: if you're editing this function, edit the `isAnyCoValueSchema`
|
||||
// function in `zodSchemaToCoSchema.ts` as well
|
||||
function isAnyCoValueSchema(schema: any): boolean {
|
||||
return "collaborative" in schema && schema.collaborative === true;
|
||||
function isAnyCoValueSchema(schema: unknown): boolean {
|
||||
return (
|
||||
typeof schema === "object" &&
|
||||
schema !== null &&
|
||||
"collaborative" in schema &&
|
||||
schema.collaborative === true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -137,6 +137,12 @@ test("loading raw accounts should work", async () => {
|
||||
expect(loadedAccount.profile!.name).toBe("test 1");
|
||||
});
|
||||
|
||||
test("co.profile() should throw an error if passed a CoValue schema", async () => {
|
||||
expect(() => co.profile(co.map({}))).toThrow(
|
||||
"co.profile() expects an object as its argument, not a CoValue schema",
|
||||
);
|
||||
});
|
||||
|
||||
test("should support recursive props on co.profile", async () => {
|
||||
const User = co.profile({
|
||||
name: z.string(),
|
||||
|
||||
@@ -2325,6 +2325,12 @@ describe("co.map schema", () => {
|
||||
expect(draftPerson.extraField).toEqual("extra");
|
||||
});
|
||||
});
|
||||
|
||||
test("co.map() should throw an error if passed a CoValue schema", () => {
|
||||
expect(() => co.map(co.map({}))).toThrow(
|
||||
"co.map() expects an object as its argument, not a CoValue schema",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Updating a nested reference", () => {
|
||||
|
||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@@ -2038,19 +2038,19 @@ importers:
|
||||
specifier: ^0.25.5
|
||||
version: 0.25.8(effect@3.11.9)
|
||||
cojson:
|
||||
specifier: workspace:0.17.6
|
||||
specifier: workspace:0.17.9
|
||||
version: link:../cojson
|
||||
cojson-storage-sqlite:
|
||||
specifier: workspace:0.17.6
|
||||
specifier: workspace:0.17.9
|
||||
version: link:../cojson-storage-sqlite
|
||||
cojson-transport-ws:
|
||||
specifier: workspace:0.17.6
|
||||
specifier: workspace:0.17.9
|
||||
version: link:../cojson-transport-ws
|
||||
effect:
|
||||
specifier: ^3.6.5
|
||||
version: 3.11.9
|
||||
jazz-tools:
|
||||
specifier: workspace:0.17.6
|
||||
specifier: workspace:0.17.9
|
||||
version: link:../jazz-tools
|
||||
ws:
|
||||
specifier: ^8.14.2
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
# jazz-react-tailwind-starter
|
||||
|
||||
## 0.0.153
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [52ea0c7]
|
||||
- jazz-tools@0.17.9
|
||||
|
||||
## 0.0.152
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ac3e694]
|
||||
- Updated dependencies [6dbb053]
|
||||
- Updated dependencies [1a182f0]
|
||||
- jazz-tools@0.17.8
|
||||
|
||||
## 0.0.151
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-tools@0.17.7
|
||||
|
||||
## 0.0.150
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-react-passkey-auth-starter",
|
||||
"private": true,
|
||||
"version": "0.0.150",
|
||||
"version": "0.0.153",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
# svelte-passkey-auth
|
||||
|
||||
## 0.0.127
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [52ea0c7]
|
||||
- jazz-tools@0.17.9
|
||||
|
||||
## 0.0.126
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ac3e694]
|
||||
- Updated dependencies [6dbb053]
|
||||
- Updated dependencies [1a182f0]
|
||||
- jazz-tools@0.17.8
|
||||
|
||||
## 0.0.125
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-tools@0.17.7
|
||||
|
||||
## 0.0.124
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "svelte-passkey-auth",
|
||||
"version": "0.0.124",
|
||||
"version": "0.0.127",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user