Compare commits
9 Commits
jazz-react
...
jazz-bette
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
336cc1f0fe | ||
|
|
cc2ca5c23c | ||
|
|
3664385113 | ||
|
|
2b2ecdaf3d | ||
|
|
6dbb05320a | ||
|
|
ac3e694f4e | ||
|
|
143156cd6a | ||
|
|
1a182f07de | ||
|
|
7e7e7ebb51 |
@@ -1,5 +1,14 @@
|
||||
# passkey-svelte
|
||||
|
||||
## 0.0.121
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ac3e694]
|
||||
- Updated dependencies [6dbb053]
|
||||
- Updated dependencies [1a182f0]
|
||||
- jazz-tools@0.17.8
|
||||
|
||||
## 0.0.120
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-svelte",
|
||||
"version": "0.0.120",
|
||||
"version": "0.0.121",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# cojson-storage-indexeddb
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cojson-storage-indexeddb",
|
||||
"version": "0.17.7",
|
||||
"version": "0.17.8",
|
||||
"main": "dist/index.js",
|
||||
"type": "module",
|
||||
"types": "dist/index.d.ts",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# cojson-storage-sqlite
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "cojson-storage-sqlite",
|
||||
"type": "module",
|
||||
"version": "0.17.7",
|
||||
"version": "0.17.8",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# cojson-transport-nodejs-ws
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cojson@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "cojson-transport-ws",
|
||||
"type": "module",
|
||||
"version": "0.17.7",
|
||||
"version": "0.17.8",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# cojson
|
||||
|
||||
## 0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
## 0.17.6
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
},
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"version": "0.17.7",
|
||||
"version": "0.17.8",
|
||||
"devDependencies": {
|
||||
"@opentelemetry/sdk-metrics": "^2.0.0",
|
||||
"libsql": "^0.5.13",
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
# jazz-react
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "community-jazz-vue",
|
||||
"version": "0.17.7",
|
||||
"version": "0.17.8",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
# jazz-auth-betterauth
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-auth-betterauth",
|
||||
"version": "0.17.7",
|
||||
"version": "0.17.8",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# jazz-betterauth-client-plugin
|
||||
|
||||
## 0.17.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- jazz-betterauth-server-plugin@0.17.8
|
||||
|
||||
## 0.17.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-betterauth-client-plugin",
|
||||
"version": "0.17.7",
|
||||
"version": "0.17.8",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
# jazz-betterauth-server-plugin
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-betterauth-server-plugin",
|
||||
"version": "0.17.7",
|
||||
"version": "0.17.8",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
# jazz-react-auth-betterauth
|
||||
|
||||
## 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jazz-react-auth-betterauth",
|
||||
"version": "0.17.7",
|
||||
"version": "0.17.8",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/index.tsx",
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
# jazz-run
|
||||
|
||||
## 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
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"bin": "./dist/index.js",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"version": "0.17.7",
|
||||
"version": "0.17.8",
|
||||
"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.7",
|
||||
"cojson-storage-sqlite": "workspace:0.17.7",
|
||||
"cojson-transport-ws": "workspace:0.17.7",
|
||||
"cojson": "workspace:0.17.8",
|
||||
"cojson-storage-sqlite": "workspace:0.17.8",
|
||||
"cojson-transport-ws": "workspace:0.17.8",
|
||||
"effect": "^3.6.5",
|
||||
"jazz-tools": "workspace:0.17.7",
|
||||
"jazz-tools": "workspace:0.17.8",
|
||||
"ws": "^8.14.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
# jazz-tools
|
||||
|
||||
## 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
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
},
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"version": "0.17.7",
|
||||
"version": "0.17.8",
|
||||
"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>",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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.7
|
||||
specifier: workspace:0.17.8
|
||||
version: link:../cojson
|
||||
cojson-storage-sqlite:
|
||||
specifier: workspace:0.17.7
|
||||
specifier: workspace:0.17.8
|
||||
version: link:../cojson-storage-sqlite
|
||||
cojson-transport-ws:
|
||||
specifier: workspace:0.17.7
|
||||
specifier: workspace:0.17.8
|
||||
version: link:../cojson-transport-ws
|
||||
effect:
|
||||
specifier: ^3.6.5
|
||||
version: 3.11.9
|
||||
jazz-tools:
|
||||
specifier: workspace:0.17.7
|
||||
specifier: workspace:0.17.8
|
||||
version: link:../jazz-tools
|
||||
ws:
|
||||
specifier: ^8.14.2
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
# jazz-react-tailwind-starter
|
||||
|
||||
## 0.0.152
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ac3e694]
|
||||
- Updated dependencies [6dbb053]
|
||||
- Updated dependencies [1a182f0]
|
||||
- jazz-tools@0.17.8
|
||||
|
||||
## 0.0.151
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jazz-react-passkey-auth-starter",
|
||||
"private": true,
|
||||
"version": "0.0.151",
|
||||
"version": "0.0.152",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
# svelte-passkey-auth
|
||||
|
||||
## 0.0.126
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [ac3e694]
|
||||
- Updated dependencies [6dbb053]
|
||||
- Updated dependencies [1a182f0]
|
||||
- jazz-tools@0.17.8
|
||||
|
||||
## 0.0.125
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "svelte-passkey-auth",
|
||||
"version": "0.0.125",
|
||||
"version": "0.0.126",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user