@ahmetskilinc/sync-core
v0.3.0
Published
Schema builder and wire protocol for the sync-engine realtime sync toolkit
Maintainers
Readme
@ahmetskilinc/sync-core
Schema builder and wire protocol shared by @ahmetskilinc/sync-client and @ahmetskilinc/sync-server.
You rarely install this alone — it comes in as a dependency of the other two — but you do import from it to declare your schema.
npm install @ahmetskilinc/sync-coreimport { defineModel, defineSchema, p } from "@ahmetskilinc/sync-core";
const Team = defineModel("Team", {
name: p.string(),
});
const Issue = defineModel("Issue", {
title: p.string(),
status: p.string(),
teamId: p.reference(() => Team),
description: p.string().nullable(),
});
export const schema = defineSchema([Team, Issue]);Records are fully typed via inference. InferRecord<typeof Issue> is:
{
id: string;
title: string;
status: string;
teamId: string;
description?: string | null;
}Nullable properties are optional keys, so you can omit them on create.
What's in here
defineModel/defineSchema/p— the schema builderInferRecord/InferCreateInput/InferPatch— type inference helpersvalidateData— runtime validation, used server-side before accepting a transactionencodeMessage/decodeMessageand theClientMessage/ServerMessage/SyncAction/Transactionwire typesgenerateId
Zero runtime dependencies.
Full documentation: github.com/ahmetskilinc/sync-engine · Upgrading? See MIGRATION.md
MIT
