Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/core/src/core/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import {
LoroTreeSchema,
RootSchemaType,
SchemaType,
} from "../schema";
import { ChangeKinds, InferContainerOptions, type Change } from "./mirror";
import { CID_KEY } from "../constants";
} from "../schema/index.js";
import { ChangeKinds, InferContainerOptions, type Change } from "./mirror.js";
import { CID_KEY } from "../constants.js";

import {
containerIdToContainerType,
Expand All @@ -42,7 +42,7 @@ import {
isArrayLike,
isTreeID,
defineCidProperty,
} from "./utils";
} from "./utils.js";

/**
* Finds the longest increasing subsequence of a sequence of numbers
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Core mirroring functionality for syncing application state with Loro CRDT
*/

export { Mirror, SyncDirection, toNormalizedJson } from "./mirror";
export { Mirror, SyncDirection, toNormalizedJson } from "./mirror.js";
export type {
InferContainerOptions,
MirrorOptions,
SetStateOptions,
SubscriberCallback,
UpdateMetadata,
} from "./mirror";
} from "./mirror.js";
2 changes: 1 addition & 1 deletion packages/core/src/core/loroEventApply.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable unicorn/consistent-function-scoping */
import { describe, it, expect } from "vitest";
import { LoroDoc, LoroText, LoroList, LoroMap, LoroCounter } from "loro-crdt";
import { applyEventBatchToState } from "./loroEventApply";
import { applyEventBatchToState } from "./loroEventApply.js";

const commitAndAssert = (doc: LoroDoc, getState: () => unknown) => {
doc.commit();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/loroEventApply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
LoroEventBatch,
TreeID,
} from "loro-crdt";
import { defineCidProperty, isTreeID } from "./utils";
import { defineCidProperty, isTreeID } from "./utils.js";

// Plain JSON-like value held in Mirror state (no `any`)
type JSONPrimitive = string | number | boolean | null | undefined;
Expand Down
17 changes: 7 additions & 10 deletions packages/core/src/core/mirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
TreeID,
} from "loro-crdt";

import { applyEventBatchToState } from "./loroEventApply";
import { applyEventBatchToState } from "./loroEventApply.js";
import {
ContainerSchemaType,
getDefaultValue,
Expand All @@ -36,7 +36,7 @@ import {
RootSchemaType,
SchemaType,
validateSchema,
} from "../schema";
} from "../schema/index.js";
import {
deepEqual,
inferContainerTypeFromValue,
Expand All @@ -46,9 +46,9 @@ import {
tryInferContainerType,
getRootContainerByType,
defineCidProperty,
} from "./utils";
import { diffContainer, diffTree } from "./diff";
import { CID_KEY } from "../constants";
} from "./utils.js";
import { diffContainer, diffTree } from "./diff.js";
import { CID_KEY } from "../constants.js";

// Plain JSON-like value used for state snapshots
type JSONPrimitive = string | number | boolean | null | undefined;
Expand Down Expand Up @@ -98,7 +98,7 @@ export interface MirrorOptions<S extends SchemaType> {
/**
* Initial state (optional)
*/
initialState?: Partial<import("../schema").InferInputType<S>>;
initialState?: Partial<import("../schema/index.js").InferInputType<S>>;

/**
* Whether to validate state updates against the schema
Expand Down Expand Up @@ -726,10 +726,7 @@ export class Mirror<S extends SchemaType> {
/**
* Update Loro based on state changes
*/
private updateLoro(
newState: InferType<S>,
options?: SetStateOptions,
) {
private updateLoro(newState: InferType<S>, options?: SetStateOptions) {
if (this.syncing) return;

this.syncing = true;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/

import { Container, ContainerID, ContainerType, LoroDoc } from "loro-crdt";
import { SchemaType } from "../schema";
import { Change, InferContainerOptions } from "./mirror";
import { CID_KEY } from "../constants";
import { SchemaType } from "../schema/index.js";
import { Change, InferContainerOptions } from "./mirror.js";
import { CID_KEY } from "../constants.js";

export function defineCidProperty(target: unknown, cid: ContainerID) {
if (
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

// Re-export all public APIs
export * from "./schema";
export * from "./schema/index.js";
export {
Mirror,
toNormalizedJson,
Expand All @@ -14,11 +14,11 @@ export {
type SubscriberCallback,
type InferContainerOptions,
SyncDirection,
} from "./core";
} from "./core/index.js";

// Default export
import * as schema from "./schema";
import * as core from "./core";
import * as schema from "./schema/index.js";
import * as core from "./core/index.js";

type Combined = typeof schema & typeof core;
const loroMirror: Combined = Object.assign({}, schema, core);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import {
SchemaType,
StringSchemaType,
InferType,
} from "./types";
} from "./types.js";

export * from "./types";
export * from "./validators";
export * from "./types.js";
export * from "./validators.js";

/**
* Create a schema definition
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/schema/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
LoroTreeSchema,
RootSchemaType,
SchemaType,
} from "./types";
import { isObject } from "../core/utils";
} from "./types.js";
import { isObject } from "../core/utils.js";

const schemaValidationCache = new WeakMap<object, WeakSet<object>>();

Expand Down
10 changes: 5 additions & 5 deletions packages/core/tests/cid.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describe, it, expect, expectTypeOf } from "vitest";
import { LoroDoc, LoroMap } from "loro-crdt";
import { Mirror } from "../src/core/mirror";
import { schema } from "../src/schema";
import { InferType } from "../src";
import { CID_KEY } from "../src/constants";
import { diffMap } from "../src/core/diff";
import { Mirror } from "../src/core/mirror.js";
import { schema } from "../src/schema/index.js";
import { InferType } from "../src/index.js";
import { CID_KEY } from "../src/constants.js";
import { diffMap } from "../src/core/diff.js";

describe("$cid: state injection and write ignoring (always-on for LoroMap)", () => {
it("types: LoroMap includes $cid by default", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/diff-equality.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect } from "vitest";
import { LoroDoc } from "loro-crdt";
import { diffContainer } from "../src/core/diff";
import { schema } from "../src/schema";
import { diffContainer } from "../src/core/diff.js";
import { schema } from "../src/schema/index.js";

describe("diffMap equality for falsy primitives", () => {
it("does not emit changes when string field stays ''", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/inferType.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expectTypeOf, describe } from "vitest";
import { InferType, schema } from "../src";
import { InferType, schema } from "../src/index.js";

describe("infer type", () => {
test("catchall", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/issue.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { it, expect } from "vitest";
import { LoroDoc, LoroMap } from "loro-crdt";
import { Mirror, schema } from "../src/";
import { Mirror, schema } from "../src/index.js";

it("Applying remote event then calling setState immediately may cause an event apply order issue", async () => {
const docA = new LoroDoc();
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/list.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from "vitest";
import { longestIncreasingSubsequence } from "../src/core/diff";
import { Mirror, schema } from "../src";
import { longestIncreasingSubsequence } from "../src/core/diff.js";
import { Mirror, schema } from "../src/index.js";
import { LoroDoc } from "loro-crdt";

describe("longestIncreasingSubsequence", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/mirror-list-updates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* based on whether an idSelector is provided
*/

import { Mirror } from "../src/core/mirror";
import { Mirror } from "../src/core/mirror.js";
import { LoroDoc, LoroMap } from "loro-crdt";
import { schema } from "../src/schema";
import { schema } from "../src/schema/index.js";
import { describe, expect, it } from "vitest";

// Utility function to wait for sync to complete (three microtasks for better reliability)
Expand Down
6 changes: 3 additions & 3 deletions packages/core/tests/mirror-movable-list.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable unicorn/consistent-function-scoping */
import { Mirror } from "../src/core/mirror";
import { Mirror } from "../src/core/mirror.js";
import { LoroDoc } from "loro-crdt";
import { schema } from "../src/schema";
import { schema } from "../src/schema/index.js";
import { describe, expect, it } from "vitest";
import { valueIsContainerOfType } from "../src/core/utils";
import { valueIsContainerOfType } from "../src/core/utils.js";

// Utility function to wait for sync to complete (three microtasks for better reliability)
const waitForSync = async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/mirror-tags.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Mirror, SyncDirection, UpdateMetadata } from "../src/core/mirror";
import { schema } from "../src/schema";
import { Mirror, SyncDirection, UpdateMetadata } from "../src/core/mirror.js";
import { schema } from "../src/schema/index.js";
import { LoroDoc } from "loro-crdt";
import { describe, expect, it } from "vitest";

Expand Down
6 changes: 3 additions & 3 deletions packages/core/tests/mirror-text.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Mirror } from "../src/core/mirror";
import { Mirror } from "../src/core/mirror.js";
import { LoroDoc, LoroText } from "loro-crdt";
import { schema } from "../src/schema";
import { schema } from "../src/schema/index.js";
import { describe, expect, it } from "vitest";
import { valueIsContainer, valueIsContainerOfType } from "../src/core/utils";
import { valueIsContainer, valueIsContainerOfType } from "../src/core/utils.js";

// Utility function to wait for sync to complete (three microtasks for better reliability)
const waitForSync = async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/tests/mirror-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/* eslint-disable unicorn/consistent-function-scoping */
import { describe, it, expect } from "vitest";
import { LoroDoc, LoroText, type LoroEventBatch } from "loro-crdt";
import { Mirror } from "../src/core/mirror";
import { applyEventBatchToState } from "../src/core/loroEventApply";
import { schema } from "../src/schema";
import { Mirror } from "../src/core/mirror.js";
import { applyEventBatchToState } from "../src/core/loroEventApply.js";
import { schema } from "../src/schema/index.js";

// Small helper to wait for microtasks (mirror commits async)
const tick = async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/mirror.human.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Mirror } from "../src/core/mirror";
import { schema } from "../src/schema";
import { Mirror } from "../src/core/mirror.js";
import { schema } from "../src/schema/index.js";
import { isContainer, LoroDoc, LoroMap } from "loro-crdt";
import { expect, it } from "vitest";

Expand Down
6 changes: 3 additions & 3 deletions packages/core/tests/mirror.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Mirror, SyncDirection } from "../src/core/mirror";
import { valueIsContainer, valueIsContainerOfType } from "../src/core/utils";
import { schema } from "../src/schema";
import { Mirror, SyncDirection } from "../src/core/mirror.js";
import { valueIsContainer, valueIsContainerOfType } from "../src/core/utils.js";
import { schema } from "../src/schema/index.js";
import { LoroDoc, LoroList, LoroMap } from "loro-crdt";
import { beforeEach, describe, expect, it, vi } from "vitest";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/null-in-map-consistency.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from "vitest";
import { LoroDoc, LoroMap, LoroList } from "loro-crdt";
import { Mirror, schema, toNormalizedJson } from "../src";
import { Mirror, schema, toNormalizedJson } from "../src/index.js";

function stripCid(value: unknown): unknown {
if (Array.isArray(value)) return value.map(stripCid);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/readme.quickstart.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from "vitest";
import { LoroDoc } from "loro-crdt";
import { Mirror, schema, validateSchema } from "../src";
import { Mirror, schema, validateSchema } from "../src/index.js";

describe("README Quick Start examples", () => {
it("creates a store, updates immutably and via draft, and injects cid", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/schema-catchall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Test for schema catchall functionality
*/
import { describe, it, expect } from "vitest";
import { schema } from "../src/schema";
import { schema } from "../src/schema/index.js";

describe("Schema Catchall Functionality", () => {
it("should create a schema with catchall support", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
RootSchemaType,
schema,
StringSchemaType,
} from "../src/schema";
import { Mirror, SyncDirection } from "../src/core/mirror";
} from "../src/schema/index.js";
import { Mirror, SyncDirection } from "../src/core/mirror.js";
import { LoroDoc } from "loro-crdt";

// Utility to wait for sync to complete (three microtasks for reliable sync)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getPathValue,
setPathValue,
isObject,
} from "../src/core/utils";
} from "../src/core/utils.js";

describe("Utility Functions", () => {
describe("isObject", () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/tests/validator.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { LoroDoc } from "loro-crdt";
import { Mirror } from "../src/core/mirror";
import { schema, validateSchema } from "../src/schema";
import * as schemaModule from "../src/schema";
import { Mirror } from "../src/core/mirror.js";
import { schema, validateSchema } from "../src/schema/index.js";
import * as schemaModule from "../src/schema/index.js";

describe("schema validator caching", () => {
let doc: LoroDoc;
Expand Down
2 changes: 1 addition & 1 deletion packages/jotai/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAtom } from "jotai";
import { LoroDoc } from "loro-crdt";
import { schema } from "loro-mirror";
import { afterEach, describe, expect, it } from "vitest";
import { loroMirrorAtom } from "../src";
import { loroMirrorAtom } from "../src/index.js";

// Helper to wait for Jotai state propagation
const waitFor = (ms: number) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/jotai/tests/readme.jotai.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
import { act, renderHook } from "@testing-library/react";
import { LoroDoc } from "loro-crdt";
import { InferInputType, schema } from "loro-mirror";
import { loroMirrorAtom } from "../src";
import { loroMirrorAtom } from "../src/index.js";
import { atom, useAtomValue, useSetAtom } from "jotai";

describe("Jotai README example", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
* React integration for Loro Mirror
*/

export * from "./hooks";
export * from "./hooks.js";
2 changes: 1 addition & 1 deletion packages/react/tests/readme.react.context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
useLoroStore,
useLoroValue,
useLoroCallback,
} from "../src";
} from "../src/index.js";

describe("React README examples", () => {
it("createLoroContext returns provider and hooks for given schema", () => {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
Expand Down