Skip to main content

@dataclass

The Dataclass module is designed to facilitate data synchronization between local objects and remote datastores. It provides mechanisms for pushing local changes upstream and pulling remote changes downstream, ensuring data consistency across different environments.

Defining a Dataclass with Upstream

import { dataclass, push, pull, semver } from 'ts-basis'

@dataclass({ classVersion: semver('1.0.0') })
class User {
static index: typeof UserUpstream.index

id: string = '';
name: string = '';

constructor(init?: Partial<User>) {
Object.assign(this, init);
}
}

// Define an index
const UserUpstream = {
index: Upstream.index(User, (addIndex) => ({
byId: addIndex({ unique: true }, { id: true }),
}))
}