wtfai 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -519,6 +519,18 @@ const id = await IframeBridge.createRecord('notes', {
519
519
  console.log('创建成功, ID:', id);
520
520
  ```
521
521
 
522
+ #### `IframeBridge.createRecords(collection, dataList)`
523
+
524
+ 批量在指定集合中创建多条记录。
525
+
526
+ ```javascript
527
+ const ids = await IframeBridge.createRecords('logs', [
528
+ { level: 'info', message: 'Task started' },
529
+ { level: 'success', message: 'Task finished' }
530
+ ]);
531
+ console.log('创建成功, IDs:', ids);
532
+ ```
533
+
522
534
  #### `IframeBridge.getRecord(collection, id)`
523
535
 
524
536
  获取单条记录。
@@ -559,7 +571,8 @@ await IframeBridge.deleteRecord('notes', id);
559
571
  ```javascript
560
572
  const result = await IframeBridge.listRecords('notes', {
561
573
  page: 1,
562
- pageSize: 10
574
+ pageSize: 10,
575
+ order: 'DESC'
563
576
  });
564
577
  console.log(`共 ${result.total} 条记录`);
565
578
  result.records.forEach(r => {
@@ -58,6 +58,9 @@ class IframeBridgeHost {
58
58
  } else if ('createRecord' === method) {
59
59
  const [collection, data] = params;
60
60
  result = await this.session.createRecord(collection, data);
61
+ } else if ('createRecords' === method) {
62
+ const [collection, dataList] = params;
63
+ result = await this.session.createRecords(collection, dataList);
61
64
  } else if ('getRecord' === method) {
62
65
  const [collection, id] = params;
63
66
  result = await this.session.getRecord(collection, id);
@@ -99,6 +102,7 @@ class IframeBridgeHost {
99
102
  'updateSessionTitle',
100
103
  'getSessionId',
101
104
  'createRecord',
105
+ 'createRecords',
102
106
  'getRecord',
103
107
  'updateRecord',
104
108
  'deleteRecord',
package/dist/session.d.ts CHANGED
@@ -83,6 +83,13 @@ export declare class WorkflowSession {
83
83
  * @returns 新创建记录的 ID
84
84
  */
85
85
  createRecord(collection: string, data: Record<string, unknown>): Promise<string>;
86
+ /**
87
+ * 批量创建数据记录
88
+ * @param collection 集合名称
89
+ * @param dataList 数据列表
90
+ * @returns 新创建记录的 ID 列表
91
+ */
92
+ createRecords(collection: string, dataList: Array<Record<string, unknown>>): Promise<string[]>;
86
93
  /**
87
94
  * 获取数据记录
88
95
  * @param collection 集合名称
@@ -111,6 +118,7 @@ export declare class WorkflowSession {
111
118
  listRecords(collection: string, options?: {
112
119
  page?: number;
113
120
  pageSize?: number;
121
+ order?: 'ASC' | 'DESC';
114
122
  }): Promise<{
115
123
  records: Array<{
116
124
  id: string;
package/dist/session.js CHANGED
@@ -179,6 +179,24 @@ class WorkflowSession {
179
179
  const result = await response.json();
180
180
  return result.id;
181
181
  }
182
+ async createRecords(collection, dataList) {
183
+ this.assertNotDisposed();
184
+ if (!this.state.threadId) throw new Error('No active session (missing threadId)');
185
+ const response = await fetch(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}/batch`, {
186
+ method: 'POST',
187
+ headers: {
188
+ 'Content-Type': 'application/json',
189
+ ...this.headers
190
+ },
191
+ body: JSON.stringify({
192
+ threadId: this.state.threadId,
193
+ dataList
194
+ })
195
+ });
196
+ if (!response.ok) throw new Error('Failed to create records');
197
+ const result = await response.json();
198
+ return result.ids;
199
+ }
182
200
  async getRecord(collection, id) {
183
201
  this.assertNotDisposed();
184
202
  if (!this.state.threadId) throw new Error('No active session (missing threadId)');
@@ -226,6 +244,7 @@ class WorkflowSession {
226
244
  url.searchParams.set('threadId', this.state.threadId);
227
245
  if (null == options ? void 0 : options.page) url.searchParams.set('page', String(options.page));
228
246
  if (null == options ? void 0 : options.pageSize) url.searchParams.set('pageSize', String(options.pageSize));
247
+ if (null == options ? void 0 : options.order) url.searchParams.set('order', options.order);
229
248
  const response = await fetch(url.toString(), {
230
249
  headers: this.headers
231
250
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wtfai",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {