@tldraw/tlsync-client
Advanced tools
Comparing version 2.0.0-canary.091081ee to 2.0.0-canary.0bc397c94624
@@ -0,1 +1,33 @@ | ||
# v2.0.0-alpha.12 (Mon Apr 03 2023) | ||
#### 🐛 Bug Fix | ||
- Make sure all types and build stuff get run in CI [#1548](https://github.com/tldraw/tldraw-lite/pull/1548) ([@SomeHats](https://github.com/SomeHats)) | ||
- add pre-commit api report generation [#1517](https://github.com/tldraw/tldraw-lite/pull/1517) ([@SomeHats](https://github.com/SomeHats)) | ||
- [chore] restore api extractor [#1500](https://github.com/tldraw/tldraw-lite/pull/1500) ([@steveruizok](https://github.com/steveruizok)) | ||
- Remove initial data parameter as it is not being used. [#1480](https://github.com/tldraw/tldraw-lite/pull/1480) ([@MitjaBezensek](https://github.com/MitjaBezensek)) | ||
- David/publish good [#1488](https://github.com/tldraw/tldraw-lite/pull/1488) ([@ds300](https://github.com/ds300)) | ||
- [chore] alpha 10 [#1486](https://github.com/tldraw/tldraw-lite/pull/1486) ([@ds300](https://github.com/ds300)) | ||
- [chore] package build improvements [#1484](https://github.com/tldraw/tldraw-lite/pull/1484) ([@ds300](https://github.com/ds300)) | ||
- [chore] bump for alpha 8 [#1485](https://github.com/tldraw/tldraw-lite/pull/1485) ([@steveruizok](https://github.com/steveruizok)) | ||
- stop using broken-af turbo for publishing [#1476](https://github.com/tldraw/tldraw-lite/pull/1476) ([@ds300](https://github.com/ds300)) | ||
- [chore] add canary release script [#1423](https://github.com/tldraw/tldraw-lite/pull/1423) ([@ds300](https://github.com/ds300) [@steveruizok](https://github.com/steveruizok)) | ||
- [chore] upgrade yarn [#1430](https://github.com/tldraw/tldraw-lite/pull/1430) ([@ds300](https://github.com/ds300)) | ||
- [update] docs [#1448](https://github.com/tldraw/tldraw-lite/pull/1448) ([@steveruizok](https://github.com/steveruizok)) | ||
- [fix] dev version number for tldraw/tldraw [#1434](https://github.com/tldraw/tldraw-lite/pull/1434) ([@steveruizok](https://github.com/steveruizok)) | ||
- repo cleanup [#1426](https://github.com/tldraw/tldraw-lite/pull/1426) ([@steveruizok](https://github.com/steveruizok)) | ||
- Vscode extension [#1253](https://github.com/tldraw/tldraw-lite/pull/1253) ([@steveruizok](https://github.com/steveruizok) [@MitjaBezensek](https://github.com/MitjaBezensek) [@orangemug](https://github.com/orangemug)) | ||
- Run all the tests. Fix linting for tests. [#1389](https://github.com/tldraw/tldraw-lite/pull/1389) ([@MitjaBezensek](https://github.com/MitjaBezensek)) | ||
- add beta-redirect app [#1415](https://github.com/tldraw/tldraw-lite/pull/1415) ([@SomeHats](https://github.com/SomeHats)) | ||
#### Authors: 5 | ||
- alex ([@SomeHats](https://github.com/SomeHats)) | ||
- David Sheldrick ([@ds300](https://github.com/ds300)) | ||
- Mitja Bezenšek ([@MitjaBezensek](https://github.com/MitjaBezensek)) | ||
- Orange Mug ([@orangemug](https://github.com/orangemug)) | ||
- Steve Ruiz ([@steveruizok](https://github.com/steveruizok)) | ||
--- | ||
# @tldraw/tlsync-client | ||
@@ -2,0 +34,0 @@ |
@@ -1,43 +0,12 @@ | ||
import { RecordsDiff } from '@tldraw/tlstore'; | ||
import { SerializedSchema } from '@tldraw/tlstore'; | ||
import { Store } from '@tldraw/tlstore'; | ||
import { StoreSnapshot } from '@tldraw/tlstore'; | ||
import { SyncedStore } from '@tldraw/editor'; | ||
import { TldrawEditorConfig } from '@tldraw/editor'; | ||
import { TLInstanceId } from '@tldraw/editor'; | ||
import { TLRecord } from '@tldraw/editor'; | ||
import { TLStore } from '@tldraw/editor'; | ||
import { TLStoreSchema } from '@tldraw/editor'; | ||
import { TLUser } from '@tldraw/editor'; | ||
import { TLUserId } from '@tldraw/editor'; | ||
/** @public */ | ||
export declare function addDbName(name: string): void; | ||
declare type AnnounceMessage = { | ||
type: 'announce'; | ||
schema: SerializedSchema; | ||
}; | ||
/** @public */ | ||
export declare class BroadcastChannelMock { | ||
onmessage?: (e: MessageEvent) => void; | ||
constructor(_name: string); | ||
postMessage(_msg: Message): void; | ||
close(): void; | ||
} | ||
/** @public */ | ||
export declare function clearDb(universalPersistenceKey: string): void; | ||
/** @public */ | ||
export declare const DEFAULT_DOCUMENT_NAME: any; | ||
/** @public */ | ||
export declare function getAllIndexDbNames(): string[]; | ||
/** @public */ | ||
export declare function getUserData(): TLUser; | ||
/** @public */ | ||
/** | ||
* Clear the database of all data associated with tldraw. | ||
* | ||
* @public */ | ||
export declare function hardReset({ shouldReload }?: { | ||
@@ -48,86 +17,18 @@ shouldReload?: boolean | undefined; | ||
/** @public */ | ||
export declare function loadDataFromStore(universalPersistenceKey: string, opts?: { | ||
didCancel?: () => boolean; | ||
}): Promise<undefined | { | ||
records: TLRecord[]; | ||
schema?: SerializedSchema; | ||
}>; | ||
declare type Message = SyncMessage | AnnounceMessage; | ||
/** @public */ | ||
export declare const STORE_PREFIX = "TLDRAW_DOCUMENT_v2"; | ||
/** @public */ | ||
export declare function storeChangesInIndexedDb(universalPersistenceKey: string, schema: TLStoreSchema, changes: RecordsDiff<any>, opts?: { | ||
didCancel?: () => boolean; | ||
}): Promise<void>; | ||
export declare const TAB_ID: TLInstanceId; | ||
/** @public */ | ||
export declare function storeSnapshotInIndexedDb(universalPersistenceKey: string, schema: TLStoreSchema, snapshot: StoreSnapshot<any>, opts?: { | ||
didCancel?: () => boolean; | ||
}): Promise<void>; | ||
/** @public */ | ||
export declare function subscribeToUserData(store: Store<any>): () => void; | ||
/** | ||
* IMPORTANT!!! | ||
* Use a client that persists to indexedDB and syncs to other stores with the same instance id, e.g. other tabs running the same instance of tldraw. | ||
* | ||
* This is just a quick-n-dirty temporary solution that will be replaced with the remote sync client once it has the db integrated | ||
*/ | ||
declare type SyncMessage = { | ||
type: 'diff'; | ||
instanceId: TLInstanceId; | ||
changes: RecordsDiff<any>; | ||
schema: SerializedSchema; | ||
}; | ||
/** @public */ | ||
export declare const TAB_ID: TLInstanceId; | ||
/** @public */ | ||
export declare class TLLocalSyncClient { | ||
readonly store: TLStore; | ||
readonly channel: BroadcastChannelMock | BroadcastChannel; | ||
private disposables; | ||
private diffQueue; | ||
private didDispose; | ||
private shouldDoFullDBWrite; | ||
private isReloading; | ||
readonly universalPersistenceKey: string; | ||
readonly serializedSchema: SerializedSchema; | ||
private isDebugging; | ||
initTime: number; | ||
private debug; | ||
constructor(store: TLStore, { universalPersistenceKey, onLoad, onLoadError, }: { | ||
universalPersistenceKey: string; | ||
onLoad: (self: TLLocalSyncClient) => void; | ||
onLoadError: (error: Error) => void; | ||
}, channel?: BroadcastChannelMock | BroadcastChannel); | ||
private connect; | ||
close(): void; | ||
private isPersisting; | ||
private didLastWriteError; | ||
private scheduledPersistTimeout; | ||
/* Excluded from this release type: schedulePersist */ | ||
/* Excluded from this release type: persistIfNeeded */ | ||
/** | ||
* Actually persist to indexeddb. If the write fails, then we'll | ||
* retry with a full db write after a short delay. | ||
*/ | ||
private doPersist; | ||
} | ||
/** | ||
* This is a temporary solution that will be replaced with the remote sync client once it has the db integrated | ||
* @public | ||
*/ | ||
export declare function useLocalSyncClient({ universalPersistenceKey, instanceId, userId, config, }: { | ||
export declare function useLocalSyncClient({ universalPersistenceKey, instanceId, config, }: { | ||
universalPersistenceKey: string; | ||
instanceId: TLInstanceId; | ||
userId: TLUserId; | ||
config?: TldrawEditorConfig; | ||
config: TldrawEditorConfig; | ||
}): SyncedStore; | ||
export { } |
@@ -18,14 +18,15 @@ "use strict"; | ||
}; | ||
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
hardReset: () => import_hardReset.hardReset | ||
DEFAULT_DOCUMENT_NAME: () => import_persistence_constants.DEFAULT_DOCUMENT_NAME, | ||
STORE_PREFIX: () => import_persistence_constants.STORE_PREFIX, | ||
TAB_ID: () => import_persistence_constants.TAB_ID, | ||
hardReset: () => import_hardReset.hardReset, | ||
useLocalSyncClient: () => import_useLocalSyncClient.useLocalSyncClient | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
__reExport(src_exports, require("./lib/TLLocalSyncClient"), module.exports); | ||
var import_hardReset = require("./lib/hardReset"); | ||
__reExport(src_exports, require("./lib/hooks/useLocalSyncClient"), module.exports); | ||
__reExport(src_exports, require("./lib/indexedDb"), module.exports); | ||
__reExport(src_exports, require("./lib/persistence-constants"), module.exports); | ||
var import_useLocalSyncClient = require("./lib/hooks/useLocalSyncClient"); | ||
var import_persistence_constants = require("./lib/persistence-constants"); | ||
//# sourceMappingURL=index.js.map |
@@ -27,3 +27,2 @@ "use strict"; | ||
var import_hardReset = require("../hardReset"); | ||
var import_persistence_constants = require("../persistence-constants"); | ||
var import_TLLocalSyncClient = require("../TLLocalSyncClient"); | ||
@@ -33,4 +32,3 @@ function useLocalSyncClient({ | ||
instanceId, | ||
userId, | ||
config = import_editor.TldrawEditorConfig.default | ||
config | ||
}) { | ||
@@ -52,3 +50,3 @@ const [state, setState] = (0, import_react.useState)(null); | ||
}; | ||
const store = config.createStore({ userId, instanceId }); | ||
const store = config.createStore({ instanceId }); | ||
const client = new import_TLLocalSyncClient.TLLocalSyncClient(store, { | ||
@@ -63,11 +61,9 @@ universalPersistenceKey, | ||
}); | ||
const userDataUnsubcribe = (0, import_persistence_constants.subscribeToUserData)(store); | ||
return () => { | ||
setState((prevState) => prevState?.id === id ? null : prevState); | ||
userDataUnsubcribe(); | ||
client.close(); | ||
}; | ||
}, [instanceId, universalPersistenceKey, config, userId]); | ||
}, [instanceId, universalPersistenceKey, config]); | ||
return state?.syncedStore ?? { status: "loading" }; | ||
} | ||
//# sourceMappingURL=useLocalSyncClient.js.map |
@@ -25,9 +25,6 @@ "use strict"; | ||
addDbName: () => addDbName, | ||
getAllIndexDbNames: () => getAllIndexDbNames, | ||
getUserData: () => getUserData, | ||
subscribeToUserData: () => subscribeToUserData | ||
getAllIndexDbNames: () => getAllIndexDbNames | ||
}); | ||
module.exports = __toCommonJS(persistence_constants_exports); | ||
var import_editor = require("@tldraw/editor"); | ||
var import_signia = require("signia"); | ||
const tabIdKey = "TLDRAW_TAB_ID_v2"; | ||
@@ -43,30 +40,2 @@ const window = globalThis.window; | ||
} | ||
const USER_DATA_KEY = "TLDRAW_USER_DATA_v2"; | ||
const globalUserData = (0, import_signia.atom)( | ||
"globalUserData", | ||
JSON.parse(window?.localStorage.getItem(USER_DATA_KEY) || "null") ?? import_editor.TLUser.create({}) | ||
); | ||
(0, import_signia.react)("set global user data", () => { | ||
if (window) { | ||
window.localStorage.setItem(USER_DATA_KEY, JSON.stringify(globalUserData.value)); | ||
} | ||
}); | ||
function getUserData() { | ||
return globalUserData.value; | ||
} | ||
function subscribeToUserData(store) { | ||
const userId = globalUserData.value.id; | ||
return store.listen(({ changes }) => { | ||
for (const record of Object.values(changes.added)) { | ||
if (record.typeName === "user" && userId === record.id) { | ||
globalUserData.set(record); | ||
} | ||
} | ||
for (const [_, record] of Object.values(changes.updated)) { | ||
if (record.typeName === "user" && userId === record.id) { | ||
globalUserData.set(record); | ||
} | ||
} | ||
}); | ||
} | ||
const defaultDocumentKey = "TLDRAW_DEFAULT_DOCUMENT_NAME_v2"; | ||
@@ -76,3 +45,3 @@ const DEFAULT_DOCUMENT_NAME = window?.localStorage.getItem(defaultDocumentKey) ?? (0, import_editor.uniqueId)(); | ||
const STORE_PREFIX = "TLDRAW_DOCUMENT_v2"; | ||
const TAB_ID = window?.[tabIdKey] ?? window?.sessionStorage[tabIdKey] ?? import_editor.TLInstance.createId(); | ||
const TAB_ID = window?.[tabIdKey] ?? window?.sessionStorage[tabIdKey] ?? import_editor.InstanceRecordType.createId(); | ||
if (window) { | ||
@@ -79,0 +48,0 @@ window[tabIdKey] = TAB_ID; |
@@ -123,3 +123,8 @@ "use strict"; | ||
this.store.mergeRemoteChanges(() => { | ||
this.store.put(Object.values(migrationResult.value), "initialize"); | ||
this.store.put( | ||
Object.values(migrationResult.value).filter( | ||
(r) => this.store.schema.types[r.typeName].scope !== "presence" | ||
), | ||
"initialize" | ||
); | ||
}); | ||
@@ -189,4 +194,5 @@ } | ||
/** | ||
* Schedule a persist. Persists don't happen immediately: they are throttled to | ||
* avoid writing too often, and will retry if failed. | ||
* Schedule a persist. Persists don't happen immediately: they are throttled to avoid writing too | ||
* often, and will retry if failed. | ||
* | ||
* @internal | ||
@@ -208,6 +214,7 @@ */ | ||
* Persist to indexeddb only under certain circumstances: | ||
* - if we're not already persisting | ||
* - if we're not reloading the page | ||
* - and we have something to persist (a full db write scheduled or changes in the diff queue) | ||
* | ||
* - If we're not already persisting | ||
* - If we're not reloading the page | ||
* - And we have something to persist (a full db write scheduled or changes in the diff queue) | ||
* | ||
* @internal | ||
@@ -238,4 +245,4 @@ */ | ||
/** | ||
* Actually persist to indexeddb. If the write fails, then we'll | ||
* retry with a full db write after a short delay. | ||
* Actually persist to indexeddb. If the write fails, then we'll retry with a full db write after | ||
* a short delay. | ||
*/ | ||
@@ -242,0 +249,0 @@ async doPersist() { |
{ | ||
"name": "@tldraw/tlsync-client", | ||
"description": "A tiny little drawing app (multiplayer sync).", | ||
"version": "2.0.0-canary.091081ee", | ||
"version": "2.0.0-canary.0bc397c94624", | ||
"packageManager": "yarn@3.5.0", | ||
"author": { | ||
@@ -29,15 +30,14 @@ "name": "tldraw GB Ltd.", | ||
"files": [ | ||
"dist-esm/**/*", | ||
"dist-cjs/**/*" | ||
"dist-esm", | ||
"dist-cjs", | ||
"src" | ||
], | ||
"scripts": { | ||
"test": "yarn run -T jest", | ||
"test:coverage": "yarn run -T jest --coverage", | ||
"typecheck": "yarn run -T tsc --build", | ||
"build": "echo 'build should be run by turbo'", | ||
"build:package": "yarn run -T tsx ../../scripts/build-package.ts", | ||
"build:types": "yarn run -T tsx ../../scripts/build-types.ts", | ||
"build:api": "yarn run -T tsx ../../scripts/build-api.ts", | ||
"test": "lazy inherit", | ||
"test-coverage": "lazy inherit", | ||
"build": "yarn run -T tsx ../../scripts/build-package.ts", | ||
"build-api": "yarn run -T tsx ../../scripts/build-api.ts", | ||
"prepack": "yarn run -T tsx ../../scripts/prepack.ts", | ||
"postpack": "../../scripts/postpack.sh", | ||
"pack-tarball": "yarn pack", | ||
"lint": "yarn run -T tsx ../../scripts/lint.ts" | ||
@@ -48,2 +48,3 @@ }, | ||
"@types/react-dom": "*", | ||
"lazyrepo": "0.0.0-alpha.26", | ||
"ws": "^8.10.0" | ||
@@ -72,4 +73,5 @@ }, | ||
"dependencies": { | ||
"@tldraw/editor": "2.0.0-canary.091081ee", | ||
"@tldraw/tlstore": "2.0.0-canary.091081ee", | ||
"@tldraw/editor": "2.0.0-canary.0bc397c94624", | ||
"@tldraw/tlstore": "2.0.0-canary.0bc397c94624", | ||
"@tldraw/utils": "2.0.0-canary.0bc397c94624", | ||
"idb": "^7.1.0" | ||
@@ -76,0 +78,0 @@ }, |
# @tldraw/tlsync-client | ||
## License | ||
The source code in this repository (as well as our 2.0+ distributions and releases) are currently licensed under Apache-2.0. These licenses are subject to change in our upcoming 2.0 release. If you are planning to use tldraw in a commercial product, please reach out at [hello@tldraw.com](mailto://hello@tldraw.com). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
145870
42
1868
6
0
7
4
+ Added@tldraw/editor@2.0.0-canary.0bc397c94624(transitive)
+ Added@tldraw/indices@2.0.0-canary.0bc397c94624(transitive)
+ Added@tldraw/primitives@2.0.0-canary.0bc397c94624(transitive)
+ Added@tldraw/tlschema@2.0.0-canary.0bc397c94624(transitive)
+ Added@tldraw/tlstore@2.0.0-canary.0bc397c94624(transitive)
+ Added@tldraw/tlvalidate@2.0.0-canary.0bc397c94624(transitive)
+ Added@tldraw/utils@2.0.0-canary.0bc397c94624(transitive)
+ Addedcrc@4.3.2(transitive)
+ Addednanoid@4.0.2(transitive)
- Removed@tldraw/editor@2.0.0-canary.091081ee(transitive)
- Removed@tldraw/primitives@2.0.0-canary.091081ee(transitive)
- Removed@tldraw/tlschema@2.0.0-canary.091081ee(transitive)
- Removed@tldraw/tlstore@2.0.0-canary.091081ee(transitive)
- Removed@tldraw/tlvalidate@2.0.0-canary.091081ee(transitive)
- Removed@tldraw/utils@2.0.0-canary.091081ee(transitive)
- Removednanoid@3.3.8(transitive)