@g9tm/syncdata

中文文档
1.5.23发布于 2026/11/15MITTypeScriptES Module零依赖近 30 天下载 4255

TypeScript twin of the G9SyncData .NET client for Lynx, Node and browsers: the sync engine, the G9RowBatch protocol, the SQLite client store (same schema as the .NET store) and the SignalR transport.

原始使用文档
文档目录4 节
  1. Install
  2. Use (Node)
  3. Lynx
  4. License

@g9tm/syncdata

The TypeScript twin of the G9SyncData .NET client: offline-first sync between a device's SQLite database and a PostgreSQL server, for Lynx apps (with @g9tm/syncdata-lynx), Node and browsers. Same protocol, same engine behaviour, and the same local database as the .NET client — a database the MAUI app wrote opens in the Lynx app and keeps syncing.

Entry pointWhat
@g9tm/syncdatathe engine (G9SyncEngine), the client model, the protocol (DTOs, G9RowBatch frames), errors, digests
@g9tm/syncdata/sqlitethe SQLite client store (G9SqliteSyncStore) over any G9SqliteDriver
@g9tm/syncdata/signalrthe SignalR transport (G9SignalRSyncTransport), JSON and MessagePack with exact 64-bit values
@g9tm/syncdata/nodenode:sqlite driver (nodeSqliteDriver), Brotli through node:zlib (useNodeBrotli)
@g9tm/syncdata/testingfault injection over any transport (G9FaultInjectingTransport)
@g9tm/syncdata/brotli-jsa pure-JavaScript Brotli decoder for runtimes without a native one

Version 1.2.2 — always equal to the .NET packages' version. What maps to what, and every deliberate difference: PARITY.md.

Install

npm install @g9tm/syncdata @g9tm/signalr-supernetcore-client @microsoft/signalr @microsoft/signalr-protocol-msgpack @msgpack/msgpack

The SignalR packages are optional peers: only @g9tm/syncdata/signalr needs them.

Use (Node)

import { G9ESyncColumnType as T, G9SyncClientModelBuilder, G9SyncEngine, G9SyncParameters } from '@g9tm/syncdata';
import { G9SqliteSyncStore } from '@g9tm/syncdata/sqlite';
import { G9SignalRSyncTransport } from '@g9tm/syncdata/signalr';
import { nodeSqliteDriver, useNodeBrotli } from '@g9tm/syncdata/node';

useNodeBrotli(); // the server compresses frames with Brotli

// Tables in the order the .NET source generator emits them (entity type name), so both clients number them alike.
const model = new G9SyncClientModelBuilder()
  .table('farm.Pot', 'Pot', (t) =>
    t.key('Id').column('SiteId', T.Guid, false).column('Code', T.String, false).column('Weight', T.Decimal).index(null, false, 'SiteId'))
  .table('farm.Site', 'Site', (t) => t.key('Id').column('Name', T.String, false))
  .build();

const store = new G9SqliteSyncStore({ driver: nodeSqliteDriver(), databasePath: './device.db' });
const transport = new G9SignalRSyncTransport({ url: 'https://sync.example.com/g9sync', accessTokenFactory: () => token });
const engine = new G9SyncEngine(store, transport, model, { appVersion: '1.0.0' });

await engine.initialize();
await engine.subscribe('sites');
await engine.subscribe('site-pots', new G9SyncParameters().setGuid('SiteId', siteId));
const run = engine.run({ subscriptions: ['site-pots'] });
run.onProgress((p) => console.log(p.phase, Math.round(p.overall * 100) + '%'));
const result = await run.completion;
if (!result.isSuccess) console.error(result.error?.code, result.error?.message);

Local edits are ordinary SQL on the app's own connection: the store's triggers capture them and the next run pushes them. Commands (engine.executeCommand), the change feed (readChangeFeed), rejections, quarantine and the run reports work as on .NET (07-Client-Engine, 08-Client-Sqlite).

Lynx

On Lynx's background thread use @g9tm/syncdata-lynx: useLynxBrotli() and createLynxSyncTransport({ url }) (MessagePack over the G9 native WebSocket — release Lynx builds have none of their own), and G9LynxControls' native SQLite driver for the store. The code ships as ES2019 and uses no API the background thread lacks (no BigInt, TextEncoder, URL, btoa, globalThis timers) — the build fails otherwise.

License

MIT. The Brotli decoder in brotli-js is Google's (MIT): THIRD-PARTY-NOTICES.md.

版本与发布记录

@g9tm/syncdata 共发布 29 个版本,首次发布于 2026/10/06;过去 12 个月发布了 29 个版本。

版本发布日期距今
1.5.23latest2026/11/15今天
1.5.222026/11/15今天
1.5.212026/11/132 天前
1.5.202026/11/115 天前
1.5.192026/11/106 天前
1.5.182026/11/106 天前

关于 @g9tm/syncdata 的常见问题

@g9tm/syncdata 是什么?

TypeScript twin of the G9SyncData .NET client for Lynx, Node and browsers: the sync engine, the G9RowBatch protocol, the SQLite client store (same schema as the .NET store) and the SignalR transport.

如何安装 @g9tm/syncdata?

在项目目录运行 npm install @g9tm/syncdata,或使用 pnpm add / yarn add / bun add。

@g9tm/syncdata 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@g9tm/syncdata 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@g9tm/syncdata 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@g9tm/syncdata 可以商用吗?

@g9tm/syncdata 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@g9tm/syncdata 的下载量有多少?

根据 npm 官方下载统计,@g9tm/syncdata 在 2026/10/16 – 2026/11/14 这 30 天内被下载 4,255 次,日均约 142 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@g9tm/syncdata 还在维护吗?

最新版本 1.5.23 发布于 2026/11/15(今天);至今共发布 29 个版本,其中过去 12 个月发布了 29 个;首次发布于 2026/10/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。