wtfai 1.6.1 → 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 +12 -0
- package/dist/iframe-bridge.js +4 -0
- package/dist/session.d.ts +7 -0
- package/dist/session.js +18 -0
- package/package.json +1 -1
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
|
获取单条记录。
|
package/dist/iframe-bridge.js
CHANGED
|
@@ -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 集合名称
|
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)');
|