@cocreate/crud-client

中文文档
2.0.1发布于 2026/11/06AGPL-3.0ES Module近 30 天下载 3191

A high-performance, multi-tenant CRUD client for CoCreate. Execute create, read, update, delete, and real-time synchronization operations against one or multiple storage providers using a unified API. Supports parallel persistence across databases such as

原始使用文档
文档目录21 节
  1. Documentation
  2. Table of Contents
  3. Features
  4. Installation
  5. Usage
  6. Initialize the Client
  7. Read Data
  8. Read from a Specific Storage Provider
  9. Create Data in a Single Storage Provider
  10. Create Data in Multiple Storage Providers
  11. Update Data
  12. Delete Data
  13. How it Works
  14. Architecture and Payload Specs
  15. Unified Payload Object Schema
  16. Offline Synchronization
  17. Storage Providers
  18. Announcements
  19. Roadmap
  20. How to Contribute
  21. License

@cocreate/crud-client

A high-performance, database-agnostic client-side CRUD engine for querying, synchronizing, and persisting application data using a single unified payload object. It provides an offline-first architecture, transparent synchronization between local and remote storage providers, and seamless integration with the CoCreate real-time collaboration ecosystem. A single CRUD request can target one or many storage providers simultaneously, allowing applications to maintain synchronized data across distributed databases with minimal application logic.


Documentation

For complete API references, storage adapter configuration, synchronization strategies, and advanced examples, refer to the CoCreate CRUD Client documentation.

Table of Contents


Features

  • Unified CRUD API: Create, read, update, and delete data using a consistent payload structure regardless of the underlying storage provider.
  • Multi-Storage Execution: Execute a single CRUD operation against one or many storage providers simultaneously.
  • Parallel Database Synchronization: When multiple storage providers are specified, operations execute concurrently to keep distributed databases synchronized.
  • Offline-First Architecture: Continue reading and writing data while offline using local storage providers.
  • Real-Time Synchronization: Seamlessly integrates with the CoCreate Socket ecosystem to synchronize data across clients and servers.
  • Database Agnostic: Supports IndexedDB, SQLite, MongoDB, PostgreSQL, MySQL, Firestore, and additional adapters through a unified payload format.
  • Optimistic Updates: Local operations execute immediately while remote synchronization occurs in the background.
  • Stateless Operations: Every CRUD request is completely self-contained, making requests easy to serialize, queue, retry, and replay.

Installation

npm install @cocreate/crud-client

Usage

Initialize the Client

import crud from "@cocreate/crud-client";

await crud.init({
    organization_id: "64b9a32e18f21bc56789abcd",
    host: window.location.host
});

Read Data

const response = await crud.send({
    method: "object.read",
    array: "users"
});

console.log(response);

Read from a Specific Storage Provider

const response = await crud.send({
    method: "object.read",
    array: "users",
    storage: "mongodb"
});

When storage is a string, the operation executes only against the specified storage provider.


Create Data in a Single Storage Provider

await crud.send({
    method: "object.create",
    array: "users",
    storage: "mongodb",
    object: [{
        name: "John Doe",
        email: "[email protected]"
    }]
});

Create Data in Multiple Storage Providers

await crud.send({
    method: "object.create",
    array: "users",
    storage: [
        "mongodb",
        "sqlite"
    ],
    object: [{
        name: "John Doe",
        email: "[email protected]"
    }]
});

When storage is an array, the same payload is executed in parallel across every matching storage provider. This allows applications to synchronize data across multiple databases using a single CRUD request.


Update Data

await crud.send({
    method: "object.update",
    array: "users",
    storage: [
        "mongodb",
        "sqlite"
    ],
    object: [{
        _id: "64b9a32e18f21bc56789abcd",
        status: "active"
    }]
});

Delete Data

await crud.send({
    method: "object.delete",
    array: "users",
    storage: "mongodb",
    object: [{
        _id: "64b9a32e18f21bc56789abcd"
    }]
});

How it Works

  1. Every CRUD request is expressed as a standardized payload object.
  2. The client determines which storage providers should process the request.
  3. Local providers execute immediately for fast application responsiveness.
  4. Remote providers transmit requests through the active CoCreate communication layer.
  5. When multiple storage providers are specified, operations execute concurrently.
  6. Responses are normalized into a consistent result regardless of the underlying database technology.
  7. Offline mutations are queued automatically and synchronized once connectivity is restored.

Architecture and Payload Specs

Unified Payload Object Schema

PropertyTypeDescription
methodStringCRUD operation (object.create, object.read, object.update, object.delete, array.read, etc.).
arrayStringCollection, table, or dataset name.
objectArray<Object>Documents to create, update, or delete.
storageString | Array<String>Target storage provider(s). When an array is provided, all matching providers execute the request in parallel.
filterObjectQuery filters, limits, sorting, indexes, projections, and search criteria.
organization_idStringMulti-tenant workspace identifier.

Offline Synchronization

The CRUD Client follows an offline-first execution model.

When connectivity is unavailable:

  • Reads continue using local storage providers.
  • Writes are committed locally.
  • Pending mutations are automatically queued.
  • Queued operations synchronize when connectivity returns.
  • Applications remain responsive without requiring constant network connectivity.

Storage Providers

The storage property determines where CRUD operations execute.

A storage may reference a configured provider such as MongoDB, SQLite, IndexedDB, PostgreSQL, or any custom adapter.

storage: "primary"

Storage names are aliases defined by your application configuration.

Multiple storage providers can be targeted simultaneously.

storage: [
    "primary",
    "backup",
    "analytics"
]

or

storage: [
    "mongodb",
    "sqlite"
]

When an array of storage providers is supplied, the CRUD Client executes the same operation concurrently across every matching provider, allowing applications to maintain synchronized data across multiple databases with a single request.


Announcements

Release notes, new features, breaking changes, and migration guides are published in the project's CHANGELOG and GitHub Releases.


Roadmap

Upcoming enhancements include:

  • CRDT-based conflict resolution
  • Background synchronization workers
  • Delta synchronization
  • Transaction batching
  • Graph query support
  • Pluggable storage adapters
  • Edge synchronization
  • Advanced conflict resolution strategies

How to Contribute

We encourage contributions to our libraries (you might even score some nifty swag). Please see our CONTRIBUTING.md guide for details. We want this library to be community-driven and CoCreate-led.

Help prioritize development by creating issues, submitting pull requests, reviewing existing discussions, or participating in feature requests.


License

This software is dual-licensed under the GNU Affero General Public License version 3 (AGPLv3) and a commercial license.

  • Open Source Use: For open-source projects and non-commercial use, this software is available under the AGPLv3. For the full license text, see the LICENSE file.
  • Commercial Use: Commercial organizations intending to use this software outside the AGPL requirements must obtain a commercial license through CoCreate.

版本与发布记录

@cocreate/crud-client 共发布 337 个版本,首次发布于 2021/04/04;过去 12 个月发布了 12 个版本。

版本发布日期距今
2.0.1latest2026/11/064 天前
2.0.02026/11/037 天前
1.39.02026/10/2120 天前
1.37.02026/08/043 个月前
1.36.12026/08/013 个月前
1.36.02026/07/293 个月前

关于 @cocreate/crud-client 的常见问题

@cocreate/crud-client 是什么?

A high-performance, multi-tenant CRUD client for CoCreate. Execute create, read, update, delete, and real-time synchronization operations against one or multiple storage providers using a unified API. Supports parallel persistence across databases such as

如何安装 @cocreate/crud-client?

在项目目录运行 npm install @cocreate/crud-client,或使用 pnpm add / yarn add / bun add。

@cocreate/crud-client 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cocreate__crud-client 是否存在。

@cocreate/crud-client 支持 ESM 还是 CommonJS?

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

@cocreate/crud-client 可以商用吗?

@cocreate/crud-client 使用 AGPL-3.0 许可。最严格的 Copyleft:除分发外,通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括,不构成法律意见,请以许可原文为准。

@cocreate/crud-client 的下载量有多少?

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

@cocreate/crud-client 还在维护吗?

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