wecom-smartsheet-orm
v0.1.0
Published
A orm like wrapper for WeCom SmartSheet
Downloads
9
Maintainers
Readme
WeCom Smartsheet ORM
A lightweight, TypeScript-based ORM for WeChat Work (WeCom) Smartsheets, providing an intuitive interface for querying data with built-in metadata caching.
Installation
npm install wecom-smartsheet-orm
Quick Start
import { WeComSheetOrm } from "wecom-smartsheet-orm";
const orm = new WeComSheetOrm({
corpId: process.env.CORPID!,
agentId: process.env.AGENTID!,
secret: process.env.WX_SECRET!,
docId: process.env.DOCID!,
});
async function run() {
// 1. Get available table titles
const tables = await orm.getTables();
const tableName = tables[0];
if (tableName) {
// 2. Get field names for a specific table
const fields = await orm.getFields(tableName);
// 3. Query records with sorting and limits
const records = await orm.query(tableName, {
fieldNames: fields,
sortBy: { field_title: "name", desc: true },
limit: 5
});
console.log(records);
}
}
API Reference
WeComSheetOrm
constructor(credentials: WeComOrmCredentials)
Initializes the database instance.
corpId: WeCom Corporation ID.agentId: WeCom Application Agent ID.secret: Application Secret.docId: The unique ID of the Smartsheet document.
query(tableName: string, params: QueryParams): Promise<any[]>
Fetches and maps records from the specified table.
QueryParams:
| Property | Type | Description |
| :--- | :--- | :--- |
| fieldNames | string[] | Optional. Specific fields to retrieve. |
| sortBy | { field_title: string, desc: boolean } | Optional. Sorting configuration. |
| limit | number | Optional. Maximum number of records to return. |
Internal Behavior
- Metadata Caching: The library caches
sheet_idandfield_idmappings automatically to reduce API overhead during repetitive queries. - Data Mapping: Records are automatically transformed from the WeCom internal format into standard JavaScript objects using the field titles as keys.
