wtfai 1.6.4 → 1.6.5

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
@@ -506,28 +506,28 @@ const url = await IframeBridge.uploadFile(file, {
506
506
  > - `saveData/loadData` 存储在工作流 state 中(适合简单 key-value)
507
507
  > - Session Data API 存储在独立数据表中(适合结构化数据、列表数据)
508
508
 
509
- #### `IframeBridge.createRecord(collection, data)`
509
+ #### `IframeBridge.createRecord(collection, data, options?)`
510
510
 
511
- 在指定集合中创建一条记录。
511
+ 在指定集合中创建一条记录。可以通过 `options.entityId` 字段进行二级分类归属(如老师 ID、学生 ID),后续查询时利用此字段能大幅提升检索性能。
512
512
 
513
513
  ```javascript
514
514
  const id = await IframeBridge.createRecord('notes', {
515
515
  title: 'My Note',
516
516
  content: 'Hello World',
517
517
  createdAt: Date.now()
518
- });
518
+ }, { entityId: 'user_123' }); // 可选的 entityId
519
519
  console.log('创建成功, ID:', id);
520
520
  ```
521
521
 
522
- #### `IframeBridge.createRecords(collection, dataList)`
522
+ #### `IframeBridge.createRecords(collection, dataList, options?)`
523
523
 
524
- 批量在指定集合中创建多条记录。
524
+ 批量在指定集合中创建多条记录。支持传入可选的配置项如 `entityId`。
525
525
 
526
526
  ```javascript
527
527
  const ids = await IframeBridge.createRecords('logs', [
528
528
  { level: 'info', message: 'Task started' },
529
529
  { level: 'success', message: 'Task finished' }
530
- ]);
530
+ ], { entityId: 'user_123' });
531
531
  console.log('创建成功, IDs:', ids);
532
532
  ```
533
533
 
@@ -566,13 +566,14 @@ await IframeBridge.deleteRecord('notes', id);
566
566
 
567
567
  #### `IframeBridge.listRecords(collection, options?)`
568
568
 
569
- 分页查询集合中的记录。
569
+ 分页查询集合中的记录。可以通过传入 `entityId` 来极速筛选归属于特定实体的数据。
570
570
 
571
571
  ```javascript
572
572
  const result = await IframeBridge.listRecords('notes', {
573
573
  page: 1,
574
574
  pageSize: 10,
575
- order: 'DESC'
575
+ order: 'DESC',
576
+ entityId: 'user_123' // 可选,利用组合索引极速过滤
576
577
  });
577
578
  console.log(`共 ${result.total} 条记录`);
578
579
  result.records.forEach(r => {
@@ -56,11 +56,11 @@ class IframeBridgeHost {
56
56
  const [options] = params;
57
57
  result = await this.session.uploadFileFromIframe(options);
58
58
  } else if ('createRecord' === method) {
59
- const [collection, data] = params;
60
- result = await this.session.createRecord(collection, data);
59
+ const [collection, data, options] = params;
60
+ result = await this.session.createRecord(collection, data, options);
61
61
  } else if ('createRecords' === method) {
62
- const [collection, dataList] = params;
63
- result = await this.session.createRecords(collection, dataList);
62
+ const [collection, dataList, options] = params;
63
+ result = await this.session.createRecords(collection, dataList, options);
64
64
  } else if ('getRecord' === method) {
65
65
  const [collection, id] = params;
66
66
  result = await this.session.getRecord(collection, id);
package/dist/session.d.ts CHANGED
@@ -82,14 +82,18 @@ export declare class WorkflowSession {
82
82
  * @param data 数据内容
83
83
  * @returns 新创建记录的 ID
84
84
  */
85
- createRecord(collection: string, data: Record<string, unknown>): Promise<string>;
85
+ createRecord(collection: string, data: Record<string, unknown>, options?: {
86
+ entityId?: string;
87
+ }): Promise<string>;
86
88
  /**
87
89
  * 批量创建数据记录
88
90
  * @param collection 集合名称
89
91
  * @param dataList 数据列表
90
92
  * @returns 新创建记录的 ID 列表
91
93
  */
92
- createRecords(collection: string, dataList: Array<Record<string, unknown>>): Promise<string[]>;
94
+ createRecords(collection: string, dataList: Array<Record<string, unknown>>, options?: {
95
+ entityId?: string;
96
+ }): Promise<string[]>;
93
97
  /**
94
98
  * 获取数据记录
95
99
  * @param collection 集合名称
@@ -110,15 +114,11 @@ export declare class WorkflowSession {
110
114
  * @param id 记录 ID
111
115
  */
112
116
  deleteRecord(collection: string, id: string): Promise<void>;
113
- /**
114
- * 列表查询数据记录
115
- * @param collection 集合名称
116
- * @param options 分页选项
117
- */
118
117
  listRecords(collection: string, options?: {
119
118
  page?: number;
120
119
  pageSize?: number;
121
120
  order?: 'ASC' | 'DESC';
121
+ entityId?: string;
122
122
  }): Promise<{
123
123
  records: Array<{
124
124
  id: string;
package/dist/session.js CHANGED
@@ -161,7 +161,7 @@ class WorkflowSession {
161
161
  }, this.headers).catch(reject);
162
162
  });
163
163
  }
164
- async createRecord(collection, data) {
164
+ async createRecord(collection, data, options = {}) {
165
165
  this.assertNotDisposed();
166
166
  if (!this.state.threadId) throw new Error('No active session (missing threadId)');
167
167
  const response = await fetch(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}`, {
@@ -172,14 +172,15 @@ class WorkflowSession {
172
172
  },
173
173
  body: JSON.stringify({
174
174
  threadId: this.state.threadId,
175
- data
175
+ data,
176
+ entityId: options.entityId
176
177
  })
177
178
  });
178
179
  if (!response.ok) throw new Error('Failed to create record');
179
180
  const result = await response.json();
180
181
  return result.id;
181
182
  }
182
- async createRecords(collection, dataList) {
183
+ async createRecords(collection, dataList, options = {}) {
183
184
  this.assertNotDisposed();
184
185
  if (!this.state.threadId) throw new Error('No active session (missing threadId)');
185
186
  const response = await fetch(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}/batch`, {
@@ -190,7 +191,8 @@ class WorkflowSession {
190
191
  },
191
192
  body: JSON.stringify({
192
193
  threadId: this.state.threadId,
193
- dataList
194
+ dataList,
195
+ entityId: options.entityId
194
196
  })
195
197
  });
196
198
  if (!response.ok) throw new Error('Failed to create records');
@@ -242,9 +244,9 @@ class WorkflowSession {
242
244
  if (!this.state.threadId) throw new Error('No active session (missing threadId)');
243
245
  const url = new URL(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}`);
244
246
  url.searchParams.set('threadId', this.state.threadId);
245
- if (null == options ? void 0 : options.page) url.searchParams.set('page', String(options.page));
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);
247
+ Object.entries(options || {}).forEach(([key, value])=>{
248
+ if (void 0 !== value) url.searchParams.set(key, String(value));
249
+ });
248
250
  const response = await fetch(url.toString(), {
249
251
  headers: this.headers
250
252
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wtfai",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {