Skip to content

Releases: tinyplex/tinybase

v5.2.1

Choose a tag to compare

@jamesgpearce jamesgpearce released this 04 Sep 04:39

This release updates dependencies, fixes some new lint issues, and updates the type definitions to reflect the removal of the persisters and synchronizers module from the master tinybase module.

v5.2.0

Choose a tag to compare

@jamesgpearce jamesgpearce released this 03 Sep 15:40

This release introduces new Persisters for... PostgreSQL! TinyBase now has two new Persister modules:

Conceptually, things behave in the same way as they do for the various SQLite persisters. Simply use the createPostgresPersister function (or the similar createPglitePersister function) to persist your TinyBase data:

import postgres from 'postgres';
import {createPostgresPersister} from 'tinybase/persisters/persister-postgres';
import {createStore} from 'tinybase';

// Create a TinyBase Store.
const store = createStore().setTables({pets: {fido: {species: 'dog'}}});

// Create a postgres connection and Persister.
const sql = postgres('postgres://localhost:5432/tinybase');
const pgPersister = await createPostgresPersister(store, sql, 'my_tinybase');

// Save Store to the database.
await pgPersister.save();

console.log(await sql`SELECT * FROM my_tinybase;`);
// -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]

And, as per usual, you can update the database and have TinyBase automatically reflect those changes:

// If separately the database gets updated...
const json = '[{"pets":{"felix":{"species":"cat"}}},{}]';
await sql`UPDATE my_tinybase SET store = ${json} WHERE _id = '_';`;

// ... then changes are loaded back. Reactive auto-load is also supported!
await pgPersister.load();
console.log(store.getTables());
// -> {pets: {felix: {species: 'cat'}}}

// As always, don't forget to tidy up.
pgPersister.destroy();
await sql.end();

Note that these two Persister objects support both the json and tabular modes for saving TinyBase data into the database. See the DatabasePersisterConfig type for more details. (Note however that, like the SQLite Persisters, only the json mode is supported for MergeableStore instances, due to their additional CRDT metadata.)

Please provide feedback on this new release on GitHub!

v5.1.5

Choose a tag to compare

@jamesgpearce jamesgpearce released this 18 Aug 21:57

Updates peer dependencies, fixes resulting lints, and resolves #171.

v5.1.4

Choose a tag to compare

@jamesgpearce jamesgpearce released this 12 Aug 16:43

Updates peer dependencies and fixes #170.

v5.1.3

Choose a tag to compare

@jamesgpearce jamesgpearce released this 09 Aug 04:05

Updates peer dependencies

v5.1.2

Choose a tag to compare

@jamesgpearce jamesgpearce released this 01 Aug 16:08

Updates peer dependencies

v5.1.1

Choose a tag to compare

@jamesgpearce jamesgpearce released this 25 Jul 21:30

Updates peer dependencies, and lets you return a callback in the createPersisterForPath argument of the createWsServer function so that you can manipulate data on the server just after clients connect.

v5.1.0

Choose a tag to compare

@jamesgpearce jamesgpearce released this 19 Jul 22:31

This release lets you persist data on a server using the createWsServer function. This makes it possible for all clients to disconnect from a path, but, when they reconnect, for the data to still be present for them to sync with.

This is done by passing in a second argument to the createWsServer function that creates a Persister instance (for which also need to create or provide a MergeableStore) for a given path:

import {WebSocketServer} from 'ws';
import {createFilePersister} from 'tinybase/persisters/persister-file';
import {createMergeableStore} from 'tinybase';
import {createWsServer} from 'tinybase/synchronizers/synchronizer-ws-server';

const persistingServer = createWsServer(
  new WebSocketServer({port: 8051}),
  (pathId) => createFilePersister(createMergeableStore(), pathId + '.json'),
);

This is a very crude (and not production-safe!) example, but demonstrates a server that will create a file, based on any path that clients connect to, and persist data to it. See the createWsServer function documentation for more details.

This implementation is still experimental so please kick the tires!

There is one small breaking change in this release: the functions for creating Synchronizer objects can now take optional onSend and onReceive callbacks that will fire whenever messages pass through the Synchronizer. See, for example, the createWsSynchronizer function. These are suitable for debugging synchronization issues in a development environment.

v5.0.5

Choose a tag to compare

@jamesgpearce jamesgpearce released this 17 Jul 23:13

Addresses #161 and updates dependencies.

v5.1.0-beta.1

v5.1.0-beta.1 Pre-release
Pre-release

Choose a tag to compare

@jamesgpearce jamesgpearce released this 16 Jul 19:33

This release lets you persist data on a server using the createWsServer function. This makes it possible for all clients to disconnect from a path, but, when they reconnect, for the data to still be present for them to sync with.

This is done by passing in a second argument to the createWsServer function that creates a Persister instance (for which also need to create or provide a MergeableStore) for a given path:

import {WebSocketServer} from 'ws';
import {createFilePersister} from 'tinybase/persisters/persister-file';
import {createMergeableStore} from 'tinybase';
import {createWsServer} from 'tinybase/synchronizers/synchronizer-ws-server';

const persistingServer = createWsServer(
  new WebSocketServer({port: 8051}),
  (pathId) => createFilePersister(createMergeableStore(), pathId + '.json'),
);

This is a very crude (and not production-safe!) example, but demonstrates a server that will create a file, based on any path that clients connect to, and persist data to it. See the createWsServer function documentation for more details.

This implementation is still experimental so please kick the tires!