tinybase 4.4.0-beta.0 → 4.4.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/cjs/checkpoints.cjs +1 -1
- package/lib/cjs/checkpoints.cjs.gz +0 -0
- package/lib/cjs/indexes.cjs +1 -1
- package/lib/cjs/indexes.cjs.gz +0 -0
- package/lib/cjs/metrics.cjs +1 -1
- package/lib/cjs/metrics.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-automerge.cjs +1 -1
- package/lib/cjs/persisters/persister-automerge.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-browser.cjs +1 -1
- package/lib/cjs/persisters/persister-browser.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-cr-sqlite-wasm.cjs +1 -1
- package/lib/cjs/persisters/persister-cr-sqlite-wasm.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-expo-sqlite.cjs +1 -1
- package/lib/cjs/persisters/persister-expo-sqlite.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-file.cjs +1 -1
- package/lib/cjs/persisters/persister-file.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-indexed-db.cjs +1 -1
- package/lib/cjs/persisters/persister-indexed-db.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-partykit-client.cjs +1 -1
- package/lib/cjs/persisters/persister-partykit-client.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-partykit-server.cjs +1 -1
- package/lib/cjs/persisters/persister-partykit-server.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-remote.cjs +1 -1
- package/lib/cjs/persisters/persister-remote.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-sqlite-wasm.cjs +1 -1
- package/lib/cjs/persisters/persister-sqlite-wasm.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-sqlite3.cjs +1 -1
- package/lib/cjs/persisters/persister-sqlite3.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-yjs.cjs +1 -1
- package/lib/cjs/persisters/persister-yjs.cjs.gz +0 -0
- package/lib/cjs/persisters.cjs +1 -1
- package/lib/cjs/persisters.cjs.gz +0 -0
- package/lib/cjs/queries.cjs +1 -1
- package/lib/cjs/queries.cjs.gz +0 -0
- package/lib/cjs/relationships.cjs +1 -1
- package/lib/cjs/relationships.cjs.gz +0 -0
- package/lib/cjs/store.cjs +1 -1
- package/lib/cjs/store.cjs.gz +0 -0
- package/lib/cjs/tinybase.cjs +1 -1
- package/lib/cjs/tinybase.cjs.gz +0 -0
- package/lib/cjs/tools.cjs +1 -1
- package/lib/cjs/tools.cjs.gz +0 -0
- package/lib/cjs/ui-react-dom-debug.cjs +1 -1
- package/lib/cjs/ui-react-dom-debug.cjs.gz +0 -0
- package/lib/cjs/ui-react-dom.cjs +1 -1
- package/lib/cjs/ui-react-dom.cjs.gz +0 -0
- package/lib/cjs/ui-react.cjs +1 -1
- package/lib/cjs/ui-react.cjs.gz +0 -0
- package/lib/cjs-es6/checkpoints.cjs +1 -1
- package/lib/cjs-es6/checkpoints.cjs.gz +0 -0
- package/lib/cjs-es6/indexes.cjs +1 -1
- package/lib/cjs-es6/indexes.cjs.gz +0 -0
- package/lib/cjs-es6/metrics.cjs +1 -1
- package/lib/cjs-es6/metrics.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-automerge.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-automerge.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-browser.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-browser.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-cr-sqlite-wasm.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-cr-sqlite-wasm.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-expo-sqlite.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-expo-sqlite.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-file.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-file.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-indexed-db.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-indexed-db.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-partykit-client.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-partykit-client.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-partykit-server.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-partykit-server.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-remote.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-remote.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-sqlite-wasm.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-sqlite-wasm.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-sqlite3.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-sqlite3.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-yjs.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-yjs.cjs.gz +0 -0
- package/lib/cjs-es6/persisters.cjs +1 -1
- package/lib/cjs-es6/persisters.cjs.gz +0 -0
- package/lib/cjs-es6/queries.cjs +1 -1
- package/lib/cjs-es6/queries.cjs.gz +0 -0
- package/lib/cjs-es6/relationships.cjs +1 -1
- package/lib/cjs-es6/relationships.cjs.gz +0 -0
- package/lib/cjs-es6/store.cjs +1 -1
- package/lib/cjs-es6/store.cjs.gz +0 -0
- package/lib/cjs-es6/tinybase.cjs +1 -1
- package/lib/cjs-es6/tinybase.cjs.gz +0 -0
- package/lib/cjs-es6/tools.cjs +1 -1
- package/lib/cjs-es6/tools.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react-dom-debug.cjs +1 -1
- package/lib/cjs-es6/ui-react-dom-debug.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react-dom.cjs +1 -1
- package/lib/cjs-es6/ui-react-dom.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react.cjs +1 -1
- package/lib/cjs-es6/ui-react.cjs.gz +0 -0
- package/lib/debug/checkpoints.js +12 -12
- package/lib/debug/indexes.js +9 -9
- package/lib/debug/metrics.js +9 -9
- package/lib/debug/persisters/persister-automerge.js +21 -8
- package/lib/debug/persisters/persister-browser.js +17 -3
- package/lib/debug/persisters/persister-cr-sqlite-wasm.js +27 -12
- package/lib/debug/persisters/persister-expo-sqlite.js +27 -12
- package/lib/debug/persisters/persister-file.js +17 -3
- package/lib/debug/persisters/persister-indexed-db.js +21 -8
- package/lib/debug/persisters/persister-partykit-client.js +54 -20
- package/lib/debug/persisters/persister-partykit-server.js +173 -77
- package/lib/debug/persisters/persister-remote.js +17 -3
- package/lib/debug/persisters/persister-sqlite-wasm.js +27 -12
- package/lib/debug/persisters/persister-sqlite3.js +28 -13
- package/lib/debug/persisters/persister-yjs.js +23 -10
- package/lib/debug/persisters.js +16 -4
- package/lib/debug/queries.js +16 -15
- package/lib/debug/relationships.js +9 -9
- package/lib/debug/store.js +130 -35
- package/lib/debug/tinybase.js +142 -41
- package/lib/debug/tools.js +17 -9
- package/lib/debug/ui-react-dom.js +262 -150
- package/lib/debug/ui-react.js +288 -67
- package/lib/es6/checkpoints.js +1 -1
- package/lib/es6/checkpoints.js.gz +0 -0
- package/lib/es6/indexes.js +1 -1
- package/lib/es6/indexes.js.gz +0 -0
- package/lib/es6/metrics.js +1 -1
- package/lib/es6/metrics.js.gz +0 -0
- package/lib/es6/persisters/persister-automerge.js +1 -1
- package/lib/es6/persisters/persister-automerge.js.gz +0 -0
- package/lib/es6/persisters/persister-browser.js +1 -1
- package/lib/es6/persisters/persister-browser.js.gz +0 -0
- package/lib/es6/persisters/persister-cr-sqlite-wasm.js +1 -1
- package/lib/es6/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
- package/lib/es6/persisters/persister-expo-sqlite.js +1 -1
- package/lib/es6/persisters/persister-expo-sqlite.js.gz +0 -0
- package/lib/es6/persisters/persister-file.js +1 -1
- package/lib/es6/persisters/persister-file.js.gz +0 -0
- package/lib/es6/persisters/persister-indexed-db.js +1 -1
- package/lib/es6/persisters/persister-indexed-db.js.gz +0 -0
- package/lib/es6/persisters/persister-partykit-client.js +1 -1
- package/lib/es6/persisters/persister-partykit-client.js.gz +0 -0
- package/lib/es6/persisters/persister-partykit-server.js +1 -1
- package/lib/es6/persisters/persister-partykit-server.js.gz +0 -0
- package/lib/es6/persisters/persister-remote.js +1 -1
- package/lib/es6/persisters/persister-remote.js.gz +0 -0
- package/lib/es6/persisters/persister-sqlite-wasm.js +1 -1
- package/lib/es6/persisters/persister-sqlite-wasm.js.gz +0 -0
- package/lib/es6/persisters/persister-sqlite3.js +1 -1
- package/lib/es6/persisters/persister-sqlite3.js.gz +0 -0
- package/lib/es6/persisters/persister-yjs.js +1 -1
- package/lib/es6/persisters/persister-yjs.js.gz +0 -0
- package/lib/es6/persisters.js +1 -1
- package/lib/es6/persisters.js.gz +0 -0
- package/lib/es6/queries.js +1 -1
- package/lib/es6/queries.js.gz +0 -0
- package/lib/es6/relationships.js +1 -1
- package/lib/es6/relationships.js.gz +0 -0
- package/lib/es6/store.js +1 -1
- package/lib/es6/store.js.gz +0 -0
- package/lib/es6/tinybase.js +1 -1
- package/lib/es6/tinybase.js.gz +0 -0
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/es6/ui-react-dom-debug.js +1 -1
- package/lib/es6/ui-react-dom-debug.js.gz +0 -0
- package/lib/es6/ui-react-dom.js +1 -1
- package/lib/es6/ui-react-dom.js.gz +0 -0
- package/lib/es6/ui-react.js +1 -1
- package/lib/es6/ui-react.js.gz +0 -0
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters/persister-automerge.js +1 -1
- package/lib/persisters/persister-automerge.js.gz +0 -0
- package/lib/persisters/persister-browser.js +1 -1
- package/lib/persisters/persister-browser.js.gz +0 -0
- package/lib/persisters/persister-cr-sqlite-wasm.js +1 -1
- package/lib/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
- package/lib/persisters/persister-expo-sqlite.js +1 -1
- package/lib/persisters/persister-expo-sqlite.js.gz +0 -0
- package/lib/persisters/persister-file.js +1 -1
- package/lib/persisters/persister-file.js.gz +0 -0
- package/lib/persisters/persister-indexed-db.js +1 -1
- package/lib/persisters/persister-indexed-db.js.gz +0 -0
- package/lib/persisters/persister-partykit-client.js +1 -1
- package/lib/persisters/persister-partykit-client.js.gz +0 -0
- package/lib/persisters/persister-partykit-server.js +1 -1
- package/lib/persisters/persister-partykit-server.js.gz +0 -0
- package/lib/persisters/persister-remote.js +1 -1
- package/lib/persisters/persister-remote.js.gz +0 -0
- package/lib/persisters/persister-sqlite-wasm.js +1 -1
- package/lib/persisters/persister-sqlite-wasm.js.gz +0 -0
- package/lib/persisters/persister-sqlite3.js +1 -1
- package/lib/persisters/persister-sqlite3.js.gz +0 -0
- package/lib/persisters/persister-yjs.js +1 -1
- package/lib/persisters/persister-yjs.js.gz +0 -0
- package/lib/persisters.js +1 -1
- package/lib/persisters.js.gz +0 -0
- package/lib/queries.js +1 -1
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/types/persisters/persister-automerge.d.ts +36 -3
- package/lib/types/persisters/persister-browser.d.ts +71 -8
- package/lib/types/persisters/persister-cr-sqlite-wasm.d.ts +42 -8
- package/lib/types/persisters/persister-expo-sqlite.d.ts +40 -7
- package/lib/types/persisters/persister-file.d.ts +34 -3
- package/lib/types/persisters/persister-indexed-db.d.ts +40 -9
- package/lib/types/persisters/persister-partykit-client.d.ts +99 -13
- package/lib/types/persisters/persister-partykit-server.d.ts +414 -9
- package/lib/types/persisters/persister-remote.d.ts +40 -4
- package/lib/types/persisters/persister-sqlite-wasm.d.ts +46 -7
- package/lib/types/persisters/persister-sqlite3.d.ts +40 -7
- package/lib/types/persisters/persister-yjs.d.ts +37 -5
- package/lib/types/persisters.d.ts +10 -10
- package/lib/types/queries.d.ts +24 -0
- package/lib/types/store.d.ts +912 -32
- package/lib/types/tools.d.ts +4 -6
- package/lib/types/ui-react-dom.d.ts +13 -2
- package/lib/types/ui-react.d.ts +1176 -44
- package/lib/types/with-schemas/persisters/persister-automerge.d.ts +38 -4
- package/lib/types/with-schemas/persisters/persister-browser.d.ts +75 -10
- package/lib/types/with-schemas/persisters/persister-cr-sqlite-wasm.d.ts +44 -9
- package/lib/types/with-schemas/persisters/persister-expo-sqlite.d.ts +42 -8
- package/lib/types/with-schemas/persisters/persister-file.d.ts +36 -4
- package/lib/types/with-schemas/persisters/persister-indexed-db.d.ts +42 -10
- package/lib/types/with-schemas/persisters/persister-partykit-client.d.ts +102 -15
- package/lib/types/with-schemas/persisters/persister-partykit-server.d.ts +447 -9
- package/lib/types/with-schemas/persisters/persister-remote.d.ts +42 -5
- package/lib/types/with-schemas/persisters/persister-sqlite-wasm.d.ts +48 -8
- package/lib/types/with-schemas/persisters/persister-sqlite3.d.ts +41 -7
- package/lib/types/with-schemas/persisters/persister-yjs.d.ts +39 -6
- package/lib/types/with-schemas/persisters.d.ts +10 -10
- package/lib/types/with-schemas/queries.d.ts +24 -0
- package/lib/types/with-schemas/store.d.ts +1180 -36
- package/lib/types/with-schemas/tools.d.ts +4 -6
- package/lib/types/with-schemas/ui-react-dom.d.ts +21 -4
- package/lib/types/with-schemas/ui-react.d.ts +1382 -71
- package/lib/ui-react-dom.js +1 -1
- package/lib/ui-react-dom.js.gz +0 -0
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/persisters/persister-automerge.js +1 -1
- package/lib/umd/persisters/persister-automerge.js.gz +0 -0
- package/lib/umd/persisters/persister-browser.js +1 -1
- package/lib/umd/persisters/persister-browser.js.gz +0 -0
- package/lib/umd/persisters/persister-cr-sqlite-wasm.js +1 -1
- package/lib/umd/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
- package/lib/umd/persisters/persister-expo-sqlite.js +1 -1
- package/lib/umd/persisters/persister-expo-sqlite.js.gz +0 -0
- package/lib/umd/persisters/persister-file.js +1 -1
- package/lib/umd/persisters/persister-file.js.gz +0 -0
- package/lib/umd/persisters/persister-indexed-db.js +1 -1
- package/lib/umd/persisters/persister-indexed-db.js.gz +0 -0
- package/lib/umd/persisters/persister-partykit-client.js +1 -1
- package/lib/umd/persisters/persister-partykit-client.js.gz +0 -0
- package/lib/umd/persisters/persister-partykit-server.js +1 -1
- package/lib/umd/persisters/persister-partykit-server.js.gz +0 -0
- package/lib/umd/persisters/persister-remote.js +1 -1
- package/lib/umd/persisters/persister-remote.js.gz +0 -0
- package/lib/umd/persisters/persister-sqlite-wasm.js +1 -1
- package/lib/umd/persisters/persister-sqlite-wasm.js.gz +0 -0
- package/lib/umd/persisters/persister-sqlite3.js +1 -1
- package/lib/umd/persisters/persister-sqlite3.js.gz +0 -0
- package/lib/umd/persisters/persister-yjs.js +1 -1
- package/lib/umd/persisters/persister-yjs.js.gz +0 -0
- package/lib/umd/persisters.js +1 -1
- package/lib/umd/persisters.js.gz +0 -0
- package/lib/umd/queries.js +1 -1
- package/lib/umd/queries.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd/ui-react-dom-debug.js +1 -1
- package/lib/umd/ui-react-dom-debug.js.gz +0 -0
- package/lib/umd/ui-react-dom.js +1 -1
- package/lib/umd/ui-react-dom.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/lib/umd-es6/checkpoints.js +1 -1
- package/lib/umd-es6/checkpoints.js.gz +0 -0
- package/lib/umd-es6/indexes.js +1 -1
- package/lib/umd-es6/indexes.js.gz +0 -0
- package/lib/umd-es6/metrics.js +1 -1
- package/lib/umd-es6/metrics.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-automerge.js +1 -1
- package/lib/umd-es6/persisters/persister-automerge.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-browser.js +1 -1
- package/lib/umd-es6/persisters/persister-browser.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-cr-sqlite-wasm.js +1 -1
- package/lib/umd-es6/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-expo-sqlite.js +1 -1
- package/lib/umd-es6/persisters/persister-expo-sqlite.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-file.js +1 -1
- package/lib/umd-es6/persisters/persister-file.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-indexed-db.js +1 -1
- package/lib/umd-es6/persisters/persister-indexed-db.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-partykit-client.js +1 -1
- package/lib/umd-es6/persisters/persister-partykit-client.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-partykit-server.js +1 -1
- package/lib/umd-es6/persisters/persister-partykit-server.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-remote.js +1 -1
- package/lib/umd-es6/persisters/persister-remote.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-sqlite-wasm.js +1 -1
- package/lib/umd-es6/persisters/persister-sqlite-wasm.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-sqlite3.js +1 -1
- package/lib/umd-es6/persisters/persister-sqlite3.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-yjs.js +1 -1
- package/lib/umd-es6/persisters/persister-yjs.js.gz +0 -0
- package/lib/umd-es6/persisters.js +1 -1
- package/lib/umd-es6/persisters.js.gz +0 -0
- package/lib/umd-es6/queries.js +1 -1
- package/lib/umd-es6/queries.js.gz +0 -0
- package/lib/umd-es6/relationships.js +1 -1
- package/lib/umd-es6/relationships.js.gz +0 -0
- package/lib/umd-es6/store.js +1 -1
- package/lib/umd-es6/store.js.gz +0 -0
- package/lib/umd-es6/tinybase.js +1 -1
- package/lib/umd-es6/tinybase.js.gz +0 -0
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/lib/umd-es6/ui-react-dom-debug.js +1 -1
- package/lib/umd-es6/ui-react-dom-debug.js.gz +0 -0
- package/lib/umd-es6/ui-react-dom.js +1 -1
- package/lib/umd-es6/ui-react-dom.js.gz +0 -0
- package/lib/umd-es6/ui-react.js +1 -1
- package/lib/umd-es6/ui-react.js.gz +0 -0
- package/package.json +42 -40
- package/readme.md +2 -2
|
@@ -23,6 +23,90 @@ import PartySocket from 'partysocket';
|
|
|
23
23
|
import {Persister} from '../persisters';
|
|
24
24
|
import {Store} from '../store';
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* The PartyKitPersister interface is a minor extension to the Persister
|
|
28
|
+
* interface.
|
|
29
|
+
*
|
|
30
|
+
* It simply provides an extra getConnection method for accessing the
|
|
31
|
+
* PartySocket the Store is being persisted to.
|
|
32
|
+
* @since v4.3.14
|
|
33
|
+
*/
|
|
34
|
+
export interface PartyKitPersister extends Persister {
|
|
35
|
+
/**
|
|
36
|
+
* The getConnection method returns the PartySocket the Store is being
|
|
37
|
+
* persisted to.
|
|
38
|
+
* @returns The PartySocket.
|
|
39
|
+
* @example
|
|
40
|
+
* This example creates a Persister object against a newly-created Store and
|
|
41
|
+
* then gets the PartySocket back out again.
|
|
42
|
+
*
|
|
43
|
+
* ```js yolo
|
|
44
|
+
* const partySocket = new PartySocket({
|
|
45
|
+
* host: PARTYKIT_HOST,
|
|
46
|
+
* room: 'my_room',
|
|
47
|
+
* });
|
|
48
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
49
|
+
* const persister = createPartyKitPersister(store, partySocket);
|
|
50
|
+
*
|
|
51
|
+
* console.log(persister.getConnection() == partySocket);
|
|
52
|
+
* // -> true
|
|
53
|
+
*
|
|
54
|
+
* persister.destroy();
|
|
55
|
+
* ```
|
|
56
|
+
* @category Getter
|
|
57
|
+
* @since v4.3.14
|
|
58
|
+
*/
|
|
59
|
+
getConnection: () => PartySocket;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The PartyKitPersisterConfig type describes the configuration of a PartyKit
|
|
64
|
+
* Persister on the client side.
|
|
65
|
+
*
|
|
66
|
+
* The defaults (if used on both the server and client) will work fine, but if
|
|
67
|
+
* you are building more complex PartyKit apps and you need to configure path
|
|
68
|
+
* names, for example, then this is the thing to use.
|
|
69
|
+
* @example
|
|
70
|
+
* When applied to a PartyKit Persister, this PartyKitPersisterConfig will load
|
|
71
|
+
* and save a JSON serialization from and to an end point in your room called
|
|
72
|
+
* `/my_tinybase`, and use HTTP (rather than the default HTTPS) as the protocol.
|
|
73
|
+
*
|
|
74
|
+
* Note that this would require you to also add the matching storePath setting
|
|
75
|
+
* to the TinyBasePartyKitServerConfig on the server side.
|
|
76
|
+
*
|
|
77
|
+
* ```js
|
|
78
|
+
* const partyKitPersisterConfig = {
|
|
79
|
+
* storeProtocol: 'http',
|
|
80
|
+
* storePath: '/my_tinybase',
|
|
81
|
+
* };
|
|
82
|
+
* ```
|
|
83
|
+
* @category Configuration
|
|
84
|
+
* @since v4.3.9
|
|
85
|
+
*/
|
|
86
|
+
export type PartyKitPersisterConfig = {
|
|
87
|
+
/**
|
|
88
|
+
* The HTTP protocol to use (in addition to the websocket channel). This
|
|
89
|
+
* defaults to 'https' but you may wish to use 'http' for local PartyKit
|
|
90
|
+
* development.
|
|
91
|
+
*/
|
|
92
|
+
storeProtocol?: 'http' | 'https';
|
|
93
|
+
/**
|
|
94
|
+
* The path used to set and get the whole Store over HTTP(S) on the server.
|
|
95
|
+
* This must match the storePath property of the TinyBasePartyKitServerConfig
|
|
96
|
+
* object used on the server. Both default to '/store'.
|
|
97
|
+
*/
|
|
98
|
+
storePath?: string;
|
|
99
|
+
/**
|
|
100
|
+
* The prefix at the beginning of the web socket messages sent between the
|
|
101
|
+
* client and the server when synchronizing the Store. Use this to make sure
|
|
102
|
+
* they do not collide with any other message syntax that your room is using.
|
|
103
|
+
* This must match the messagePrefix property of the
|
|
104
|
+
* TinyBasePartyKitServerConfig object used on the server. Both default to an
|
|
105
|
+
* empty string.
|
|
106
|
+
*/
|
|
107
|
+
messagePrefix?: string;
|
|
108
|
+
};
|
|
109
|
+
|
|
26
110
|
/**
|
|
27
111
|
* The createPartyKitPersister function creates a Persister object that can
|
|
28
112
|
* persist the Store to durable PartyKit storage, enabling synchronization of
|
|
@@ -52,24 +136,26 @@ import {Store} from '../store';
|
|
|
52
136
|
* @param store The Store to persist.
|
|
53
137
|
* @param connection The PartySocket to use for participating in the PartyKit
|
|
54
138
|
* room.
|
|
55
|
-
* @param
|
|
56
|
-
*
|
|
57
|
-
*
|
|
139
|
+
* @param configOrStoreProtocol The PartyKitPersisterConfig configuration for
|
|
140
|
+
* the Persister, (or a string to specify a HTTP protocol to use, defaulting to
|
|
141
|
+
* 'https').
|
|
58
142
|
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
59
143
|
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
60
144
|
* debugging persistence issues in a development environment.
|
|
61
|
-
* @returns A reference to the new
|
|
145
|
+
* @returns A reference to the new PartyKitPersister object.
|
|
62
146
|
* @example
|
|
63
|
-
* This example creates a
|
|
147
|
+
* This example creates a PartyKitPersister object and persists the Store to the
|
|
64
148
|
* browser's IndexedDB storage.
|
|
65
149
|
*
|
|
66
150
|
* ```js yolo
|
|
67
|
-
* const store =
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
151
|
+
* const store = createStore()
|
|
152
|
+
* .setTable('pets', {fido: {species: 'dog'}})
|
|
153
|
+
* .setTable('species', {dog: {price: 5}})
|
|
154
|
+
* .setValues({open: true});
|
|
155
|
+
* const partySocket = new PartySocket({
|
|
156
|
+
* host: PARTYKIT_HOST,
|
|
157
|
+
* room: 'my_room',
|
|
158
|
+
* });
|
|
73
159
|
* const persister = createPartyKitPersister(store, partySocket);
|
|
74
160
|
* await persister.startAutoLoad();
|
|
75
161
|
* await persister.startAutoSave();
|
|
@@ -83,6 +169,6 @@ import {Store} from '../store';
|
|
|
83
169
|
export function createPartyKitPersister(
|
|
84
170
|
store: Store,
|
|
85
171
|
connection: PartySocket,
|
|
86
|
-
|
|
172
|
+
configOrStoreProtocol?: PartyKitPersisterConfig | 'http' | 'https',
|
|
87
173
|
onIgnoredError?: (error: any) => void,
|
|
88
|
-
):
|
|
174
|
+
): PartyKitPersister;
|
|
@@ -18,7 +18,76 @@
|
|
|
18
18
|
* @since 4.3.0
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import {Cell, CellOrUndefined, Value, ValueOrUndefined} from '../store';
|
|
22
|
+
import {Connection, Party, Request, Server} from 'partykit/server';
|
|
23
|
+
import {Id} from '../common';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The TinyBasePartyKitServerConfig type describes the configuration of a
|
|
27
|
+
* PartyKit Persister on the server side.
|
|
28
|
+
*
|
|
29
|
+
* The defaults (if used on both the server and client) will work fine, but if
|
|
30
|
+
* you are building more complex PartyKit apps and you need to configure path
|
|
31
|
+
* names, for example, then this is the type to use.
|
|
32
|
+
* @example
|
|
33
|
+
* When set as the config in a TinyBasePartyKitServer, this
|
|
34
|
+
* TinyBasePartyKitServerConfig will expect clients to load and save their JSON
|
|
35
|
+
* serialization from and to an end point in the room called `/my_tinybase`.
|
|
36
|
+
* Note that this would require you to also add the matching storePath setting
|
|
37
|
+
* to the PartyKitPersisterConfig on the client side.
|
|
38
|
+
*
|
|
39
|
+
* It will also store the data in the durable storage with a prefix of
|
|
40
|
+
* 'tinybase_' in case you are worried about colliding with other data stored
|
|
41
|
+
* in the room.
|
|
42
|
+
*
|
|
43
|
+
* ```js
|
|
44
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
45
|
+
* readonly config = {
|
|
46
|
+
* storePath: '/my_tinybase',
|
|
47
|
+
* storagePrefix: 'tinybase_',
|
|
48
|
+
* };
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
* @category Configuration
|
|
52
|
+
* @since v4.3.9
|
|
53
|
+
*/
|
|
54
|
+
export type TinyBasePartyKitServerConfig = {
|
|
55
|
+
/**
|
|
56
|
+
* The path used to set and get the whole Store over HTTP(S) on the server.
|
|
57
|
+
* This must match the storePath property of the PartyKitPersisterConfig used
|
|
58
|
+
* on the client. Both default to '/store'.
|
|
59
|
+
*/
|
|
60
|
+
storePath?: string;
|
|
61
|
+
/**
|
|
62
|
+
* The prefix at the beginning of the web socket messages between the client
|
|
63
|
+
* and the server when synchronizing the Store. Use this to make sure they do
|
|
64
|
+
* not collide with any other message syntax that your room is using. This
|
|
65
|
+
* must match the messagePrefix property of the PartyKitPersisterConfig object
|
|
66
|
+
* used on the client. Both default to an empty string.
|
|
67
|
+
*/
|
|
68
|
+
messagePrefix?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The prefix used before all the keys in the server's durable storage. Use
|
|
71
|
+
* this in case you are worried about the Store data colliding with other data
|
|
72
|
+
* stored in the room. Defaults to an empty string.
|
|
73
|
+
*/
|
|
74
|
+
storagePrefix?: string;
|
|
75
|
+
/**
|
|
76
|
+
* An object containing the extra HTTP(S) headers returned to the client from
|
|
77
|
+
* this server. This defaults to the following three headers to allow CORS:
|
|
78
|
+
*
|
|
79
|
+
* ```
|
|
80
|
+
* Access-Control-Allow-Origin: *
|
|
81
|
+
* Access-Control-Allow-Methods: *
|
|
82
|
+
* Access-Control-Allow-Headers: *
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* If you set this field, it will override the default completely. So, for
|
|
86
|
+
* example, if you add another header but still want the CORS defaults, you
|
|
87
|
+
* will need to explicitly set the Access-Control-Allow headers above again.
|
|
88
|
+
*/
|
|
89
|
+
responseHeaders?: HeadersInit;
|
|
90
|
+
};
|
|
22
91
|
|
|
23
92
|
/**
|
|
24
93
|
* A TinyBasePartyKitServer is the server component for persisting the Store to
|
|
@@ -39,7 +108,7 @@ import {Connection, Request, Server} from 'partykit/server';
|
|
|
39
108
|
* ```js
|
|
40
109
|
* // This is your PartyKit server entry point.
|
|
41
110
|
*
|
|
42
|
-
*
|
|
111
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
43
112
|
* constructor(party) {
|
|
44
113
|
* super(party);
|
|
45
114
|
* // custom constructor code
|
|
@@ -50,8 +119,8 @@ import {Connection, Request, Server} from 'partykit/server';
|
|
|
50
119
|
* console.log('Server started');
|
|
51
120
|
* }
|
|
52
121
|
*
|
|
53
|
-
* async onMessage(message,
|
|
54
|
-
* await super.onMessage(message,
|
|
122
|
+
* async onMessage(message, connection) {
|
|
123
|
+
* await super.onMessage(message, connection);
|
|
55
124
|
* // custom onMessage code
|
|
56
125
|
* }
|
|
57
126
|
*
|
|
@@ -65,8 +134,20 @@ import {Connection, Request, Server} from 'partykit/server';
|
|
|
65
134
|
* See the [PartyKit server API
|
|
66
135
|
* documentation](https://docs.partykit.io/reference/partyserver-api/) for
|
|
67
136
|
* more details.
|
|
137
|
+
* @category Creation
|
|
138
|
+
* @since v4.3.0
|
|
68
139
|
*/
|
|
69
140
|
export class TinyBasePartyKitServer implements Server {
|
|
141
|
+
constructor(party: Party);
|
|
142
|
+
/**
|
|
143
|
+
* The config property is used to optionally configure the server, using an
|
|
144
|
+
* object of the TinyBasePartyKitServerConfig type.
|
|
145
|
+
*
|
|
146
|
+
* See the documentation for that type for more details.
|
|
147
|
+
* @category Configuration
|
|
148
|
+
* @since v4.3.9
|
|
149
|
+
*/
|
|
150
|
+
readonly config: TinyBasePartyKitServerConfig;
|
|
70
151
|
/**
|
|
71
152
|
* The onRequest method is called when a HTTP request is made to the party
|
|
72
153
|
* URL.
|
|
@@ -76,7 +157,7 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
76
157
|
* synchronization stays supported:
|
|
77
158
|
*
|
|
78
159
|
* ```js
|
|
79
|
-
*
|
|
160
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
80
161
|
* async onRequest(request) {
|
|
81
162
|
* // custom onRequest code, else:
|
|
82
163
|
* return await super.onRequest(request);
|
|
@@ -87,6 +168,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
87
168
|
* See the [PartyKit server API
|
|
88
169
|
* documentation](https://docs.partykit.io/reference/partyserver-api/) for
|
|
89
170
|
* more details.
|
|
171
|
+
* @category Connection
|
|
172
|
+
* @since v4.3.0
|
|
90
173
|
*/
|
|
91
174
|
onRequest(request: Request): Promise<Response>;
|
|
92
175
|
/**
|
|
@@ -98,9 +181,9 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
98
181
|
* synchronization stays supported:
|
|
99
182
|
*
|
|
100
183
|
* ```js
|
|
101
|
-
*
|
|
102
|
-
* async onMessage(message,
|
|
103
|
-
* await super.onMessage(message,
|
|
184
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
185
|
+
* async onMessage(message, connection) {
|
|
186
|
+
* await super.onMessage(message, connection);
|
|
104
187
|
* // custom onMessage code
|
|
105
188
|
* }
|
|
106
189
|
* }
|
|
@@ -109,6 +192,328 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
109
192
|
* See the [PartyKit server API
|
|
110
193
|
* documentation](https://docs.partykit.io/reference/partyserver-api/) for
|
|
111
194
|
* more details.
|
|
195
|
+
* @category Connection
|
|
196
|
+
* @since v4.3.0
|
|
197
|
+
*/
|
|
198
|
+
onMessage(message: string, connection: Connection): Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* The canSetTable method lets you allow or disallow any changes to a Table
|
|
201
|
+
* stored on the server, as sent from a client.
|
|
202
|
+
*
|
|
203
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
204
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
205
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
206
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
207
|
+
* the server considers valid or safe.
|
|
208
|
+
*
|
|
209
|
+
* This method is passed the Table Id that the client is trying to change. The
|
|
210
|
+
* `initialSave` parameter distinguishes between the first bulk save of the
|
|
211
|
+
* Store to the PartyKit room over HTTP (`true`), and subsequent incremental
|
|
212
|
+
* updates over a web sockets (`false`).
|
|
213
|
+
*
|
|
214
|
+
* The `requestOrConnection` parameter will either be the HTTP(S) request or
|
|
215
|
+
* the web socket connection, in those two cases respectively. You can, for
|
|
216
|
+
* instance, use this to distinguish between different users.
|
|
217
|
+
*
|
|
218
|
+
* Since v4.3.13, the final parameter is the Cell previously stored on the
|
|
219
|
+
* server, if any. Use this to distinguish between the addition of a new Cell
|
|
220
|
+
* (in which case it will be undefined) and the updating of an existing one.
|
|
221
|
+
*
|
|
222
|
+
* Return `false` from this method to disallow changes to this Table on the
|
|
223
|
+
* server, or `true` to allow them (subject to subsequent canSetRow method,
|
|
224
|
+
* canDelRow method, canSetCell method, and canSetCell method checks). The
|
|
225
|
+
* default implementation returns `true` to allow all changes.
|
|
226
|
+
* @example
|
|
227
|
+
* The following implementation will strip out any attempts by the client to
|
|
228
|
+
* update any 'user' tabular data after the initial save:
|
|
229
|
+
*
|
|
230
|
+
* ```js
|
|
231
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
232
|
+
* canSetTable(tableId, initialSave) {
|
|
233
|
+
* return initialSave || tableId != 'user';
|
|
234
|
+
* }
|
|
235
|
+
* }
|
|
236
|
+
* ```
|
|
237
|
+
* @category Sanitization
|
|
238
|
+
* @since v4.3.12
|
|
239
|
+
*/
|
|
240
|
+
canSetTable(
|
|
241
|
+
tableId: Id,
|
|
242
|
+
initialSave: boolean,
|
|
243
|
+
requestOrConnection: Request | Connection,
|
|
244
|
+
): boolean;
|
|
245
|
+
/**
|
|
246
|
+
* The canDelTable method lets you allow or disallow deletions of a Table
|
|
247
|
+
* stored on the server, as sent from a client.
|
|
248
|
+
*
|
|
249
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
250
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
251
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
252
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
253
|
+
* the server considers valid or safe.
|
|
254
|
+
*
|
|
255
|
+
* This method is passed the Table Id that the client is trying to delete. The
|
|
256
|
+
* `connection` parameter will be the web socket connection of that client.
|
|
257
|
+
* You can, for instance, use this to distinguish between different users.
|
|
258
|
+
*
|
|
259
|
+
* Return `false` from this method to disallow this Table from being deleted
|
|
260
|
+
* on the server, or `true` to allow it. The default implementation returns
|
|
261
|
+
* `true` to allow deletion.
|
|
262
|
+
* @example
|
|
263
|
+
* The following implementation will strip out any attempts by the client to
|
|
264
|
+
* delete the 'user' Table:
|
|
265
|
+
*
|
|
266
|
+
* ```js
|
|
267
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
268
|
+
* canDelTable(tableId) {
|
|
269
|
+
* return tableId != 'user';
|
|
270
|
+
* }
|
|
271
|
+
* }
|
|
272
|
+
* ```
|
|
273
|
+
* @category Sanitization
|
|
274
|
+
* @since v4.3.12
|
|
275
|
+
*/
|
|
276
|
+
canDelTable(tableId: Id, connection: Connection): boolean;
|
|
277
|
+
/**
|
|
278
|
+
* The canSetRow method lets you allow or disallow any changes to a Row stored
|
|
279
|
+
* on the server, as sent from a client.
|
|
280
|
+
*
|
|
281
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
282
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
283
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
284
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
285
|
+
* the server considers valid or safe.
|
|
286
|
+
*
|
|
287
|
+
* This method is passed the Table Id and Row Id that the client is trying to
|
|
288
|
+
* change. The `initialSave` parameter distinguishes between the first bulk
|
|
289
|
+
* save of the Store to the PartyKit room over HTTP (`true`), and subsequent
|
|
290
|
+
* incremental updates over a web sockets (`false`).
|
|
291
|
+
*
|
|
292
|
+
* The final `requestOrConnection` parameter will either be the HTTP(S)
|
|
293
|
+
* request or the web socket connection, in those two cases respectively. You
|
|
294
|
+
* can, for instance, use this to distinguish between different users.
|
|
295
|
+
*
|
|
296
|
+
* Return `false` from this method to disallow changes to this Row on the
|
|
297
|
+
* server, or `true` to allow them (subject to subsequent canSetCell method
|
|
298
|
+
* and canSetCell method checks). The default implementation returns `true` to
|
|
299
|
+
* allow all changes.
|
|
300
|
+
* @example
|
|
301
|
+
* The following implementation will strip out any attempts by the client to
|
|
302
|
+
* update the 'me' Row of the 'user' Table after the initial save:
|
|
303
|
+
*
|
|
304
|
+
* ```js
|
|
305
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
306
|
+
* canSetRow(tableId, rowId, initialSave) {
|
|
307
|
+
* return initialSave || tableId != 'user' || rowId != 'me';
|
|
308
|
+
* }
|
|
309
|
+
* }
|
|
310
|
+
* ```
|
|
311
|
+
* @category Sanitization
|
|
312
|
+
* @since v4.3.12
|
|
313
|
+
*/
|
|
314
|
+
canSetRow(
|
|
315
|
+
tableId: Id,
|
|
316
|
+
rowId: Id,
|
|
317
|
+
initialSave: boolean,
|
|
318
|
+
requestOrConnection: Request | Connection,
|
|
319
|
+
): boolean;
|
|
320
|
+
/**
|
|
321
|
+
* The canDelRow method lets you allow or disallow deletions of a Row stored
|
|
322
|
+
* on the server, as sent from a client.
|
|
323
|
+
*
|
|
324
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
325
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
326
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
327
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
328
|
+
* the server considers valid or safe.
|
|
329
|
+
*
|
|
330
|
+
* This method is passed the Table Id and Row Id that the client is trying to
|
|
331
|
+
* delete. The `connection` parameter will be the web socket connection of
|
|
332
|
+
* that client. You can, for instance, use this to distinguish between
|
|
333
|
+
* different users.
|
|
334
|
+
*
|
|
335
|
+
* Return `false` from this method to disallow this Row from being deleted
|
|
336
|
+
* on the server, or `true` to allow it. The default implementation returns
|
|
337
|
+
* `true` to allow deletion.
|
|
338
|
+
* @example
|
|
339
|
+
* The following implementation will strip out any attempts by the client to
|
|
340
|
+
* delete the 'me' Row of the 'user' Table:
|
|
341
|
+
*
|
|
342
|
+
* ```js
|
|
343
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
344
|
+
* canDelRow(tableId, rowId) {
|
|
345
|
+
* return tableId != 'user' || rowId != 'me';
|
|
346
|
+
* }
|
|
347
|
+
* }
|
|
348
|
+
* ```
|
|
349
|
+
* @category Sanitization
|
|
350
|
+
* @since v4.3.12
|
|
351
|
+
*/
|
|
352
|
+
canDelRow(tableId: Id, rowId: Id, connection: Connection): boolean;
|
|
353
|
+
/**
|
|
354
|
+
* The canSetCell method lets you allow or disallow any changes to a Cell
|
|
355
|
+
* stored on the server, as sent from a client.
|
|
356
|
+
*
|
|
357
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
358
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
359
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
360
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
361
|
+
* the server considers valid or safe.
|
|
362
|
+
*
|
|
363
|
+
* This method is passed the Table Id, Row Id, and Cell Id that the client is
|
|
364
|
+
* trying to change - as well as the Cell value itself. The `initialSave`
|
|
365
|
+
* parameter distinguishes between the first bulk save of the Store to the
|
|
366
|
+
* PartyKit room over HTTP (`true`), and subsequent incremental updates over a
|
|
367
|
+
* web sockets (`false`).
|
|
368
|
+
*
|
|
369
|
+
* The final `requestOrConnection` parameter will either be the HTTP(S)
|
|
370
|
+
* request or the web socket connection, in those two cases respectively. You
|
|
371
|
+
* can, for instance, use this to distinguish between different users.
|
|
372
|
+
*
|
|
373
|
+
* Return `false` from this method to disallow changes to this Cell on the
|
|
374
|
+
* server, or `true` to allow them. The default implementation returns `true`
|
|
375
|
+
* to allow all changes.
|
|
376
|
+
* @example
|
|
377
|
+
* The following implementation will strip out any attempts by the client to
|
|
378
|
+
* update the 'name' Cell of the 'me' Row of the 'user' Table after the
|
|
379
|
+
* initial save:
|
|
380
|
+
*
|
|
381
|
+
* ```js
|
|
382
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
383
|
+
* canSetCell(tableId, rowId, cellId, cell, initialSave) {
|
|
384
|
+
* return (
|
|
385
|
+
* initialSave || tableId != 'user' || rowId != 'me' || cellId != 'name'
|
|
386
|
+
* );
|
|
387
|
+
* }
|
|
388
|
+
* }
|
|
389
|
+
* ```
|
|
390
|
+
* @category Sanitization
|
|
391
|
+
* @since v4.3.12
|
|
392
|
+
*/
|
|
393
|
+
canSetCell(
|
|
394
|
+
tableId: Id,
|
|
395
|
+
rowId: Id,
|
|
396
|
+
cellId: Id,
|
|
397
|
+
cell: Cell,
|
|
398
|
+
initialSave: boolean,
|
|
399
|
+
requestOrConnection: Request | Connection,
|
|
400
|
+
oldCell: CellOrUndefined,
|
|
401
|
+
): boolean;
|
|
402
|
+
/**
|
|
403
|
+
* The canDelCell method lets you allow or disallow deletions of a Cell stored
|
|
404
|
+
* on the server, as sent from a client.
|
|
405
|
+
*
|
|
406
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
407
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
408
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
409
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
410
|
+
* the server considers valid or safe.
|
|
411
|
+
*
|
|
412
|
+
* This method is passed the Table Id, Row Id, and Cell Id that the client is
|
|
413
|
+
* trying to delete. The `connection` parameter will be the web socket
|
|
414
|
+
* connection of that client. You can, for instance, use this to distinguish
|
|
415
|
+
* between different users.
|
|
416
|
+
*
|
|
417
|
+
* Return `false` from this method to disallow this Cell from being deleted on
|
|
418
|
+
* the server, or `true` to allow it. The default implementation returns
|
|
419
|
+
* `true` to allow deletion.
|
|
420
|
+
* @example
|
|
421
|
+
* The following implementation will strip out any attempts by the client to
|
|
422
|
+
* delete the 'name' Cell of the 'me' Row of the 'user' Table:
|
|
423
|
+
*
|
|
424
|
+
* ```js
|
|
425
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
426
|
+
* canDelCell(tableId, rowId, cellId) {
|
|
427
|
+
* return tableId != 'user' || rowId != 'me' || cellId != 'name';
|
|
428
|
+
* }
|
|
429
|
+
* }
|
|
430
|
+
* ```
|
|
431
|
+
* @category Sanitization
|
|
432
|
+
* @since v4.3.12
|
|
433
|
+
*/
|
|
434
|
+
canDelCell(
|
|
435
|
+
tableId: Id,
|
|
436
|
+
rowId: Id,
|
|
437
|
+
cellId: Id,
|
|
438
|
+
connection: Connection,
|
|
439
|
+
): boolean;
|
|
440
|
+
/**
|
|
441
|
+
* The canSetValue method lets you allow or disallow any changes to a Value
|
|
442
|
+
* stored on the server, as sent from a client.
|
|
443
|
+
*
|
|
444
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
445
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
446
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
447
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
448
|
+
* the server considers valid or safe.
|
|
449
|
+
*
|
|
450
|
+
* This method is passed the Value Id that the client is trying to change - as
|
|
451
|
+
* well as the Value itself. The `initialSave` parameter distinguishes between
|
|
452
|
+
* the first bulk save of the Store to the PartyKit room over HTTP (`true`),
|
|
453
|
+
* and subsequent incremental updates over a web sockets (`false`).
|
|
454
|
+
*
|
|
455
|
+
* The `requestOrConnection` parameter will either be the HTTP(S) request or
|
|
456
|
+
* the web socket connection, in those two cases respectively. You can, for
|
|
457
|
+
* instance, use this to distinguish between different users.
|
|
458
|
+
*
|
|
459
|
+
* Since v4.3.13, the final parameter is the Value previously stored on the
|
|
460
|
+
* server, if any. Use this to distinguish between the addition of a new Value
|
|
461
|
+
* (in which case it will be undefined) and the updating of an existing one.
|
|
462
|
+
*
|
|
463
|
+
* Return `false` from this method to disallow changes to this Value on the
|
|
464
|
+
* server, or `true` to allow them. The default implementation returns `true`
|
|
465
|
+
* to allow all changes.
|
|
466
|
+
* @example
|
|
467
|
+
* The following implementation will strip out any attempts by the client to
|
|
468
|
+
* update the 'userId' Value after the initial save:
|
|
469
|
+
*
|
|
470
|
+
* ```js
|
|
471
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
472
|
+
* canSetValue(valueId, value, initialSave) {
|
|
473
|
+
* return initialSave || userId != 'userId';
|
|
474
|
+
* }
|
|
475
|
+
* }
|
|
476
|
+
* ```
|
|
477
|
+
* @category Sanitization
|
|
478
|
+
* @since v4.3.12
|
|
479
|
+
*/
|
|
480
|
+
canSetValue(
|
|
481
|
+
valueId: Id,
|
|
482
|
+
value: Value,
|
|
483
|
+
initialSave: boolean,
|
|
484
|
+
requestOrConnection: Request | Connection,
|
|
485
|
+
oldValue: ValueOrUndefined,
|
|
486
|
+
): boolean;
|
|
487
|
+
/**
|
|
488
|
+
* The canDelValue method lets you allow or disallow deletions of a Value
|
|
489
|
+
* stored on the server, as sent from a client.
|
|
490
|
+
*
|
|
491
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
492
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
493
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
494
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
495
|
+
* the server considers valid or safe.
|
|
496
|
+
*
|
|
497
|
+
* This method is passed the Value Id that the client is trying to delete. The
|
|
498
|
+
* `connection` parameter will be the web socket connection of that client.
|
|
499
|
+
* You can, for instance, use this to distinguish between different users.
|
|
500
|
+
*
|
|
501
|
+
* Return `false` from this method to disallow this Value from being deleted
|
|
502
|
+
* on the server, or `true` to allow it. The default implementation returns
|
|
503
|
+
* `true` to allow deletion.
|
|
504
|
+
* @example
|
|
505
|
+
* The following implementation will strip out any attempts by the client to
|
|
506
|
+
* delete the 'userId' Value:
|
|
507
|
+
*
|
|
508
|
+
* ```js
|
|
509
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
510
|
+
* canDelValue(valueId) {
|
|
511
|
+
* return valueId != 'userId';
|
|
512
|
+
* }
|
|
513
|
+
* }
|
|
514
|
+
* ```
|
|
515
|
+
* @category Sanitization
|
|
516
|
+
* @since v4.3.12
|
|
112
517
|
*/
|
|
113
|
-
|
|
518
|
+
canDelValue(valueId: Id, connection: Connection): boolean;
|
|
114
519
|
}
|
|
@@ -9,6 +9,42 @@
|
|
|
9
9
|
import {Persister} from '../persisters';
|
|
10
10
|
import {Store} from '../store';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* The RemotePersister interface is a minor extension to the Persister
|
|
14
|
+
* interface.
|
|
15
|
+
*
|
|
16
|
+
* It simply provides an extra getUrls method for accessing the URLs the Store
|
|
17
|
+
* is being persisted to.
|
|
18
|
+
* @since v4.3.14
|
|
19
|
+
*/
|
|
20
|
+
export interface RemotePersister extends Persister {
|
|
21
|
+
/**
|
|
22
|
+
* The getUrls method returns the URLs the Store is being persisted to.
|
|
23
|
+
* @returns The load and save URLs as a two-item array.
|
|
24
|
+
* @example
|
|
25
|
+
* This example creates a RemotePersister object against a newly-created Store
|
|
26
|
+
* and then gets the URLs back out again.
|
|
27
|
+
*
|
|
28
|
+
* ```js
|
|
29
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
30
|
+
* const persister = createRemotePersister(
|
|
31
|
+
* store,
|
|
32
|
+
* 'https://example.com/load',
|
|
33
|
+
* 'https://example.com/save',
|
|
34
|
+
* 5,
|
|
35
|
+
* );
|
|
36
|
+
*
|
|
37
|
+
* console.log(persister.getUrls());
|
|
38
|
+
* // -> ['https://example.com/load', 'https://example.com/save']
|
|
39
|
+
*
|
|
40
|
+
* persister.destroy();
|
|
41
|
+
* ```
|
|
42
|
+
* @category Getter
|
|
43
|
+
* @since v4.3.14
|
|
44
|
+
*/
|
|
45
|
+
getUrls: () => [string, string];
|
|
46
|
+
}
|
|
47
|
+
|
|
12
48
|
/**
|
|
13
49
|
* The createRemotePersister function creates a Persister object that can
|
|
14
50
|
* persist the Store to a remote server.
|
|
@@ -29,10 +65,10 @@ import {Store} from '../store';
|
|
|
29
65
|
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
30
66
|
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
31
67
|
* debugging persistence issues in a development environment, since v4.0.4.
|
|
32
|
-
* @returns A reference to the new
|
|
68
|
+
* @returns A reference to the new RemotePersister object.
|
|
33
69
|
* @example
|
|
34
|
-
* This example creates a
|
|
35
|
-
* server.
|
|
70
|
+
* This example creates a RemotePersister object and persists the Store to a
|
|
71
|
+
* remote server.
|
|
36
72
|
*
|
|
37
73
|
* ```js yolo
|
|
38
74
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
@@ -59,4 +95,4 @@ export function createRemotePersister(
|
|
|
59
95
|
saveUrl: string,
|
|
60
96
|
autoLoadIntervalSeconds?: number,
|
|
61
97
|
onIgnoredError?: (error: any) => void,
|
|
62
|
-
):
|
|
98
|
+
): RemotePersister;
|