@flowgram.ai/history-storage 0.1.0
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/dist/esm/index.js +307 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +193 -0
- package/dist/index.d.ts +193 -0
- package/dist/index.js +342 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/create-history-storage-plugin.ts
|
|
13
|
+
import { definePluginCreator } from "@flowgram.ai/core";
|
|
14
|
+
|
|
15
|
+
// src/history-storage-manager.ts
|
|
16
|
+
import { inject, injectable } from "inversify";
|
|
17
|
+
import { DisposableCollection } from "@flowgram.ai/utils";
|
|
18
|
+
import {
|
|
19
|
+
HistoryManager,
|
|
20
|
+
HistoryStackChangeType
|
|
21
|
+
} from "@flowgram.ai/history";
|
|
22
|
+
|
|
23
|
+
// src/history-database.ts
|
|
24
|
+
import Dexie from "dexie";
|
|
25
|
+
var HistoryDatabase = class extends Dexie {
|
|
26
|
+
constructor(databaseName = "ide-history-storage") {
|
|
27
|
+
super(databaseName);
|
|
28
|
+
this.resourceStorageLimit = 100;
|
|
29
|
+
this.version(1).stores({
|
|
30
|
+
history: "++id, &uuid, resourceURI",
|
|
31
|
+
operation: "++id, &uuid, historyId, uri, resourceURI"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 某个uri下所有的history记录
|
|
36
|
+
* @param resourceURI 资源uri
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
allHistoryByResourceURI(resourceURI) {
|
|
40
|
+
return this.history.where({ resourceURI }).toArray();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 根据uuid获取历史
|
|
44
|
+
* @param uuid
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
getHistoryByUUID(uuid) {
|
|
48
|
+
return this.history.get({ uuid });
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 某个uri下所有的operation记录
|
|
52
|
+
* @param resourceURI 资源uri
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
allOperationByResourceURI(resourceURI) {
|
|
56
|
+
return this.operation.where({ resourceURI }).toArray();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 添加历史记录
|
|
60
|
+
* @param history 历史记录
|
|
61
|
+
* @param operations 操作记录
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
addHistoryRecord(history, operations) {
|
|
65
|
+
return this.transaction("rw", this.history, this.operation, async () => {
|
|
66
|
+
const count = await this.history.where({ resourceURI: history.resourceURI }).count();
|
|
67
|
+
if (count >= this.resourceStorageLimit) {
|
|
68
|
+
const limit = count - this.resourceStorageLimit;
|
|
69
|
+
const items = await this.history.where({ resourceURI: history.resourceURI }).limit(limit).toArray();
|
|
70
|
+
const ids = items.map((i) => i.id);
|
|
71
|
+
const uuid = items.map((i) => i.uuid);
|
|
72
|
+
await Promise.all([
|
|
73
|
+
this.history.bulkDelete(ids),
|
|
74
|
+
...uuid.map(async (uuid2) => {
|
|
75
|
+
await this.operation.where({ historyId: uuid2 }).delete();
|
|
76
|
+
})
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
return Promise.all([this.history.add(history), this.operation.bulkAdd(operations)]);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 更新历史记录
|
|
84
|
+
* @param historyRecord
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
async updateHistoryByUUID(uuid, historyRecord) {
|
|
88
|
+
const history = await this.getHistoryByUUID(uuid);
|
|
89
|
+
if (!history) {
|
|
90
|
+
console.warn("no history record found");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
return this.history.update(history.id, historyRecord);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 添加操作记录
|
|
97
|
+
* @param record 操作记录
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
addOperationRecord(record) {
|
|
101
|
+
return this.operation.add(record);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 更新操作记录
|
|
105
|
+
* @param record 操作记录
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
async updateOperationRecord(record) {
|
|
109
|
+
const op = await this.operation.where({ uuid: record.uuid }).first();
|
|
110
|
+
if (!op) {
|
|
111
|
+
console.warn("no operation record found");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
return this.operation.put({
|
|
115
|
+
id: op.id,
|
|
116
|
+
...record
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 重置数据库
|
|
121
|
+
* @returns
|
|
122
|
+
*/
|
|
123
|
+
reset() {
|
|
124
|
+
return this.transaction("rw", this.history, this.operation, async () => {
|
|
125
|
+
await Promise.all(this.tables.map((table) => table.clear()));
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 清空某个资源下所有的数据
|
|
130
|
+
* @param resourceURI
|
|
131
|
+
* @returns
|
|
132
|
+
*/
|
|
133
|
+
resetByResourceURI(resourceURI) {
|
|
134
|
+
return this.transaction("rw", this.history, this.operation, async () => {
|
|
135
|
+
await Promise.all(this.tables.map((table) => table.where({ resourceURI }).delete()));
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// src/history-storage-manager.ts
|
|
141
|
+
var HistoryStorageManager = class {
|
|
142
|
+
constructor() {
|
|
143
|
+
this._toDispose = new DisposableCollection();
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 初始化
|
|
147
|
+
* @param ctx
|
|
148
|
+
*/
|
|
149
|
+
onInit(_ctx, opts) {
|
|
150
|
+
this.db = new HistoryDatabase(opts?.databaseName);
|
|
151
|
+
if (opts?.resourceStorageLimit) {
|
|
152
|
+
this.db.resourceStorageLimit = opts.resourceStorageLimit;
|
|
153
|
+
}
|
|
154
|
+
this._toDispose.push(
|
|
155
|
+
this.historyManager.historyStack.onChange((event) => {
|
|
156
|
+
if (event.type === HistoryStackChangeType.ADD) {
|
|
157
|
+
const [history, operations] = this.historyItemToRecord(event.service, event.value);
|
|
158
|
+
this.db.addHistoryRecord(history, operations).catch(console.error);
|
|
159
|
+
}
|
|
160
|
+
if ([HistoryStackChangeType.ADD_OPERATION, HistoryStackChangeType.UPDATE_OPERATION].includes(
|
|
161
|
+
event.type
|
|
162
|
+
)) {
|
|
163
|
+
const {
|
|
164
|
+
service,
|
|
165
|
+
value: { historyItem }
|
|
166
|
+
} = event;
|
|
167
|
+
this.db.updateHistoryByUUID(historyItem.id, {
|
|
168
|
+
resourceJSON: service.getSnapshot() || ""
|
|
169
|
+
}).catch(console.error);
|
|
170
|
+
}
|
|
171
|
+
if (event.type === HistoryStackChangeType.ADD_OPERATION) {
|
|
172
|
+
const operationRecord = this.historyOperationToRecord(
|
|
173
|
+
event.value.historyItem,
|
|
174
|
+
event.value.operation
|
|
175
|
+
);
|
|
176
|
+
this.db.addOperationRecord(operationRecord).catch(console.error);
|
|
177
|
+
}
|
|
178
|
+
if (event.type === HistoryStackChangeType.UPDATE_OPERATION) {
|
|
179
|
+
const operationRecord = this.historyOperationToRecord(
|
|
180
|
+
event.value.historyItem,
|
|
181
|
+
event.value.operation
|
|
182
|
+
);
|
|
183
|
+
this.db.updateOperationRecord(operationRecord).catch(console.error);
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* 内存历史转数据表记录
|
|
190
|
+
* @param historyItem
|
|
191
|
+
* @returns
|
|
192
|
+
*/
|
|
193
|
+
historyItemToRecord(historyService, historyItem) {
|
|
194
|
+
const operations = historyItem.operations.map(
|
|
195
|
+
(op) => this.historyOperationToRecord(historyItem, op)
|
|
196
|
+
);
|
|
197
|
+
return [
|
|
198
|
+
{
|
|
199
|
+
uuid: historyItem.id,
|
|
200
|
+
timestamp: historyItem.timestamp,
|
|
201
|
+
type: historyItem.type,
|
|
202
|
+
resourceURI: historyItem.uri?.toString() || "",
|
|
203
|
+
resourceJSON: historyService.getSnapshot() || ""
|
|
204
|
+
},
|
|
205
|
+
operations
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 内存操作转数据表操作
|
|
210
|
+
* @param historyItem
|
|
211
|
+
* @param op
|
|
212
|
+
* @returns
|
|
213
|
+
*/
|
|
214
|
+
historyOperationToRecord(historyItem, op) {
|
|
215
|
+
return {
|
|
216
|
+
uuid: op.id,
|
|
217
|
+
type: op.type,
|
|
218
|
+
timestamp: op.timestamp,
|
|
219
|
+
label: op.label || "",
|
|
220
|
+
uri: op?.uri?.toString() || "",
|
|
221
|
+
resourceURI: historyItem.uri?.toString() || "",
|
|
222
|
+
description: op.description || "",
|
|
223
|
+
value: JSON.stringify(op.value),
|
|
224
|
+
historyId: historyItem.id
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* 销毁
|
|
229
|
+
*/
|
|
230
|
+
dispose() {
|
|
231
|
+
this._toDispose.dispose();
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
__decorateClass([
|
|
235
|
+
inject(HistoryManager)
|
|
236
|
+
], HistoryStorageManager.prototype, "historyManager", 2);
|
|
237
|
+
HistoryStorageManager = __decorateClass([
|
|
238
|
+
injectable()
|
|
239
|
+
], HistoryStorageManager);
|
|
240
|
+
|
|
241
|
+
// src/history-storage-container-module.ts
|
|
242
|
+
import { ContainerModule } from "inversify";
|
|
243
|
+
var HistoryStorageContainerModule = new ContainerModule((bind) => {
|
|
244
|
+
bind(HistoryStorageManager).toSelf().inSingletonScope();
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
// src/create-history-storage-plugin.ts
|
|
248
|
+
var createHistoryStoragePlugin = definePluginCreator({
|
|
249
|
+
onBind: ({ bind, rebind }) => {
|
|
250
|
+
},
|
|
251
|
+
onInit(ctx, opts) {
|
|
252
|
+
const historyStorageManager = ctx.get(HistoryStorageManager);
|
|
253
|
+
historyStorageManager.onInit(ctx, opts);
|
|
254
|
+
},
|
|
255
|
+
onDispose(ctx) {
|
|
256
|
+
const historyStorageManager = ctx.get(HistoryStorageManager);
|
|
257
|
+
historyStorageManager.dispose();
|
|
258
|
+
},
|
|
259
|
+
containerModules: [HistoryStorageContainerModule]
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// src/use-storage-hisotry-items.tsx
|
|
263
|
+
import { groupBy } from "lodash";
|
|
264
|
+
import { useLiveQuery } from "dexie-react-hooks";
|
|
265
|
+
import { HistoryStack } from "@flowgram.ai/history";
|
|
266
|
+
function useStorageHistoryItems(historyStorageManager, resourceURI) {
|
|
267
|
+
const items = useLiveQuery(async () => {
|
|
268
|
+
const [historyItems, operations] = await Promise.all([
|
|
269
|
+
historyStorageManager.db.allHistoryByResourceURI(resourceURI),
|
|
270
|
+
historyStorageManager.db.allOperationByResourceURI(resourceURI)
|
|
271
|
+
]);
|
|
272
|
+
const grouped = groupBy(
|
|
273
|
+
operations.map((o) => ({
|
|
274
|
+
id: o.uuid,
|
|
275
|
+
timestamp: o.timestamp,
|
|
276
|
+
type: o.type,
|
|
277
|
+
label: o.label,
|
|
278
|
+
description: o.description,
|
|
279
|
+
value: o.value ? JSON.parse(o.value) : void 0,
|
|
280
|
+
uri: o.uri,
|
|
281
|
+
historyId: o.historyId
|
|
282
|
+
})),
|
|
283
|
+
"historyId"
|
|
284
|
+
);
|
|
285
|
+
return historyItems.sort((a, b) => b.id - a.id).map(
|
|
286
|
+
(historyItem) => ({
|
|
287
|
+
id: historyItem.uuid,
|
|
288
|
+
type: historyItem.type,
|
|
289
|
+
timestamp: historyItem.timestamp,
|
|
290
|
+
operations: grouped[historyItem.uuid] || [],
|
|
291
|
+
time: HistoryStack.dateFormat(historyItem.timestamp),
|
|
292
|
+
uri: historyItem.resourceURI
|
|
293
|
+
})
|
|
294
|
+
);
|
|
295
|
+
}, [resourceURI]) || [];
|
|
296
|
+
return {
|
|
297
|
+
items
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
export {
|
|
301
|
+
HistoryDatabase,
|
|
302
|
+
HistoryStorageContainerModule,
|
|
303
|
+
HistoryStorageManager,
|
|
304
|
+
createHistoryStoragePlugin,
|
|
305
|
+
useStorageHistoryItems
|
|
306
|
+
};
|
|
307
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/create-history-storage-plugin.ts","../../src/history-storage-manager.ts","../../src/history-database.ts","../../src/history-storage-container-module.ts","../../src/use-storage-hisotry-items.tsx"],"sourcesContent":["import { definePluginCreator } from '@flowgram.ai/core';\n\nimport { HistoryStoragePluginOptions } from './types';\nimport { HistoryStorageManager } from './history-storage-manager';\nimport { HistoryStorageContainerModule } from './history-storage-container-module';\n\nexport const createHistoryStoragePlugin = definePluginCreator<HistoryStoragePluginOptions>({\n onBind: ({ bind, rebind }) => {},\n onInit(ctx, opts): void {\n const historyStorageManager = ctx.get<HistoryStorageManager>(HistoryStorageManager);\n historyStorageManager.onInit(ctx, opts);\n },\n onDispose(ctx) {\n const historyStorageManager = ctx.get<HistoryStorageManager>(HistoryStorageManager);\n historyStorageManager.dispose();\n },\n containerModules: [HistoryStorageContainerModule],\n});\n","import { inject, injectable } from 'inversify';\nimport { DisposableCollection } from '@flowgram.ai/utils';\nimport {\n HistoryItem,\n HistoryManager,\n HistoryOperation,\n HistoryStackChangeType,\n HistoryService,\n HistoryStackAddOperationEvent,\n HistoryStackUpdateOperationEvent,\n} from '@flowgram.ai/history';\nimport { PluginContext } from '@flowgram.ai/core';\n\nimport { HistoryOperationRecord, HistoryRecord, HistoryStoragePluginOptions } from './types';\nimport { HistoryDatabase } from './history-database';\n\n/**\n * 历史存储管理\n */\n@injectable()\nexport class HistoryStorageManager {\n private _toDispose = new DisposableCollection();\n\n db: HistoryDatabase;\n\n @inject(HistoryManager)\n protected historyManager: HistoryManager;\n\n /**\n * 初始化\n * @param ctx\n */\n onInit(_ctx: PluginContext, opts: HistoryStoragePluginOptions) {\n this.db = new HistoryDatabase(opts?.databaseName);\n\n if (opts?.resourceStorageLimit) {\n this.db.resourceStorageLimit = opts.resourceStorageLimit;\n }\n\n this._toDispose.push(\n this.historyManager.historyStack.onChange(event => {\n if (event.type === HistoryStackChangeType.ADD) {\n const [history, operations] = this.historyItemToRecord(event.service, event.value);\n this.db.addHistoryRecord(history, operations).catch(console.error);\n }\n\n // operation merge的时候需要更新snapshot\n if (\n [HistoryStackChangeType.ADD_OPERATION, HistoryStackChangeType.UPDATE_OPERATION].includes(\n event.type,\n )\n ) {\n const {\n service,\n value: { historyItem },\n } = event as HistoryStackAddOperationEvent | HistoryStackUpdateOperationEvent;\n // 更新快照\n this.db\n .updateHistoryByUUID(historyItem.id, {\n resourceJSON: service.getSnapshot() || '',\n })\n .catch(console.error);\n }\n\n if (event.type === HistoryStackChangeType.ADD_OPERATION) {\n const operationRecord: HistoryOperationRecord = this.historyOperationToRecord(\n event.value.historyItem,\n event.value.operation,\n );\n this.db.addOperationRecord(operationRecord).catch(console.error);\n }\n if (event.type === HistoryStackChangeType.UPDATE_OPERATION) {\n const operationRecord: HistoryOperationRecord = this.historyOperationToRecord(\n event.value.historyItem,\n event.value.operation,\n );\n this.db.updateOperationRecord(operationRecord).catch(console.error);\n }\n }),\n );\n }\n\n /**\n * 内存历史转数据表记录\n * @param historyItem\n * @returns\n */\n historyItemToRecord(\n historyService: HistoryService,\n historyItem: HistoryItem,\n ): [HistoryRecord, HistoryOperationRecord[]] {\n const operations = historyItem.operations.map(op =>\n this.historyOperationToRecord(historyItem, op),\n );\n\n return [\n {\n uuid: historyItem.id,\n timestamp: historyItem.timestamp,\n type: historyItem.type,\n resourceURI: historyItem.uri?.toString() || '',\n resourceJSON: historyService.getSnapshot() || '',\n },\n operations,\n ];\n }\n\n /**\n * 内存操作转数据表操作\n * @param historyItem\n * @param op\n * @returns\n */\n historyOperationToRecord(historyItem: HistoryItem, op: HistoryOperation): HistoryOperationRecord {\n return {\n uuid: op.id,\n type: op.type,\n timestamp: op.timestamp,\n label: op.label || '',\n uri: op?.uri?.toString() || '',\n resourceURI: historyItem.uri?.toString() || '',\n description: op.description || '',\n value: JSON.stringify(op.value),\n historyId: historyItem.id,\n };\n }\n\n /**\n * 销毁\n */\n dispose() {\n this._toDispose.dispose();\n }\n}\n","import Dexie, { type Table } from 'dexie';\n\nimport { HistoryOperationRecord, HistoryRecord } from './types';\n\n/**\n * 历史数据库\n */\nexport class HistoryDatabase extends Dexie {\n readonly history: Table<HistoryRecord>;\n\n readonly operation: Table<HistoryOperationRecord>;\n\n resourceStorageLimit: number = 100;\n\n constructor(databaseName: string = 'ide-history-storage') {\n super(databaseName);\n this.version(1).stores({\n history: '++id, &uuid, resourceURI',\n operation: '++id, &uuid, historyId, uri, resourceURI',\n });\n }\n\n /**\n * 某个uri下所有的history记录\n * @param resourceURI 资源uri\n * @returns\n */\n allHistoryByResourceURI(resourceURI: string) {\n return this.history.where({ resourceURI }).toArray();\n }\n\n /**\n * 根据uuid获取历史\n * @param uuid\n * @returns\n */\n getHistoryByUUID(uuid: string) {\n return this.history.get({ uuid });\n }\n\n /**\n * 某个uri下所有的operation记录\n * @param resourceURI 资源uri\n * @returns\n */\n allOperationByResourceURI(resourceURI: string) {\n return this.operation.where({ resourceURI }).toArray();\n }\n\n /**\n * 添加历史记录\n * @param history 历史记录\n * @param operations 操作记录\n * @returns\n */\n addHistoryRecord(history: HistoryRecord, operations: HistoryOperationRecord[]) {\n return this.transaction('rw', this.history, this.operation, async () => {\n const count = await this.history.where({ resourceURI: history.resourceURI }).count();\n if (count >= this.resourceStorageLimit) {\n const limit = count - this.resourceStorageLimit;\n const items = await this.history\n .where({ resourceURI: history.resourceURI })\n .limit(limit)\n .toArray();\n const ids = items.map(i => i.id);\n const uuid = items.map(i => i.uuid);\n await Promise.all([\n this.history.bulkDelete(ids),\n ...uuid.map(async uuid => {\n await this.operation.where({ historyId: uuid }).delete();\n }),\n ]);\n }\n\n return Promise.all([this.history.add(history), this.operation.bulkAdd(operations)]);\n });\n }\n\n /**\n * 更新历史记录\n * @param historyRecord\n * @returns\n */\n async updateHistoryByUUID(uuid: string, historyRecord: Partial<HistoryRecord>) {\n const history = await this.getHistoryByUUID(uuid);\n if (!history) {\n console.warn('no history record found');\n return;\n }\n return this.history.update(history.id, historyRecord);\n }\n\n /**\n * 添加操作记录\n * @param record 操作记录\n * @returns\n */\n addOperationRecord(record: HistoryOperationRecord) {\n return this.operation.add(record);\n }\n\n /**\n * 更新操作记录\n * @param record 操作记录\n * @returns\n */\n async updateOperationRecord(record: HistoryOperationRecord) {\n const op = await this.operation.where({ uuid: record.uuid }).first();\n if (!op) {\n console.warn('no operation record found');\n return;\n }\n return this.operation.put({\n id: op.id,\n ...record,\n });\n }\n\n /**\n * 重置数据库\n * @returns\n */\n reset() {\n return this.transaction('rw', this.history, this.operation, async () => {\n await Promise.all(this.tables.map(table => table.clear()));\n });\n }\n\n /**\n * 清空某个资源下所有的数据\n * @param resourceURI\n * @returns\n */\n resetByResourceURI(resourceURI: string) {\n return this.transaction('rw', this.history, this.operation, async () => {\n await Promise.all(this.tables.map(table => table.where({ resourceURI }).delete()));\n });\n }\n}\n","import { ContainerModule } from 'inversify';\n\nimport { HistoryStorageManager } from './history-storage-manager';\n\nexport const HistoryStorageContainerModule = new ContainerModule(bind => {\n bind(HistoryStorageManager).toSelf().inSingletonScope();\n});\n","import { groupBy } from 'lodash';\nimport { useLiveQuery } from 'dexie-react-hooks';\nimport { HistoryItem, HistoryOperation, HistoryStack } from '@flowgram.ai/history';\n\nimport { HistoryStorageManager } from './history-storage-manager';\nexport function useStorageHistoryItems(\n historyStorageManager: HistoryStorageManager,\n resourceURI: string\n): {\n items: HistoryItem[];\n} {\n const items: HistoryItem[] =\n useLiveQuery(async () => {\n const [historyItems, operations] = await Promise.all([\n historyStorageManager.db.allHistoryByResourceURI(resourceURI),\n historyStorageManager.db.allOperationByResourceURI(resourceURI),\n ]);\n\n const grouped = groupBy<HistoryOperation>(\n operations.map((o) => ({\n id: o.uuid,\n timestamp: o.timestamp,\n type: o.type,\n label: o.label,\n description: o.description,\n value: o.value ? JSON.parse(o.value) : undefined,\n uri: o.uri,\n historyId: o.historyId,\n })),\n 'historyId'\n );\n return historyItems\n .sort((a, b) => (b.id as number) - (a.id as number))\n .map(\n (historyItem) =>\n ({\n id: historyItem.uuid,\n type: historyItem.type,\n timestamp: historyItem.timestamp,\n operations: grouped[historyItem.uuid] || [],\n time: HistoryStack.dateFormat(historyItem.timestamp),\n uri: historyItem.resourceURI,\n } as HistoryItem)\n );\n }, [resourceURI]) || [];\n\n return {\n items,\n };\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,2BAA2B;;;ACApC,SAAS,QAAQ,kBAAkB;AACnC,SAAS,4BAA4B;AACrC;AAAA,EAEE;AAAA,EAEA;AAAA,OAIK;;;ACVP,OAAO,WAA2B;AAO3B,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAOzC,YAAY,eAAuB,uBAAuB;AACxD,UAAM,YAAY;AAHpB,gCAA+B;AAI7B,SAAK,QAAQ,CAAC,EAAE,OAAO;AAAA,MACrB,SAAS;AAAA,MACT,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,qBAAqB;AAClF,0BAAsB,QAAQ;AAAA,EAChC;AAAA,EACA,kBAAkB,CAAC,6BAA6B;AAClD,CAAC;;;AIjBD,SAAS,eAAe;AACxB,SAAS,oBAAoB;AAC7B,SAAwC,oBAAoB;AAGrD,SAAS,uBACd,uBACA,aAGA;AACA,QAAM,QACJ,aAAa,YAAY;AACvB,UAAM,CAAC,cAAc,UAAU,IAAI,MAAM,QAAQ,IAAI;AAAA,MACnD,sBAAsB,GAAG,wBAAwB,WAAW;AAAA,MAC5D,sBAAsB,GAAG,0BAA0B,WAAW;AAAA,IAChE,CAAC;AAED,UAAM,UAAU;AAAA,MACd,WAAW,IAAI,CAAC,OAAO;AAAA,QACrB,IAAI,EAAE;AAAA,QACN,WAAW,EAAE;AAAA,QACb,MAAM,EAAE;AAAA,QACR,OAAO,EAAE;AAAA,QACT,aAAa,EAAE;AAAA,QACf,OAAO,EAAE,QAAQ,KAAK,MAAM,EAAE,KAAK,IAAI;AAAA,QACvC,KAAK,EAAE;AAAA,QACP,WAAW,EAAE;AAAA,MACf,EAAE;AAAA,MACF;AAAA,IACF;AACA,WAAO,aACJ,KAAK,CAAC,GAAG,MAAO,EAAE,KAAiB,EAAE,EAAa,EAClD;AAAA,MACC,CAAC,iBACE;AAAA,QACC,IAAI,YAAY;AAAA,QAChB,MAAM,YAAY;AAAA,QAClB,WAAW,YAAY;AAAA,QACvB,YAAY,QAAQ,YAAY,IAAI,KAAK,CAAC;AAAA,QAC1C,MAAM,aAAa,WAAW,YAAY,SAAS;AAAA,QACnD,KAAK,YAAY;AAAA,MACnB;AAAA,IACJ;AAAA,EACJ,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC;AAExB,SAAO;AAAA,IACL;AAAA,EACF;AACF;","names":["uuid"]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
2
|
+
import { PluginContext } from '@flowgram.ai/core';
|
|
3
|
+
import { HistoryManager, HistoryService, HistoryItem, HistoryOperation } from '@flowgram.ai/history';
|
|
4
|
+
import * as dexie from 'dexie';
|
|
5
|
+
import dexie__default, { Table } from 'dexie';
|
|
6
|
+
import { ContainerModule } from 'inversify';
|
|
7
|
+
|
|
8
|
+
interface HistoryRecord {
|
|
9
|
+
/**
|
|
10
|
+
* 自增id
|
|
11
|
+
*/
|
|
12
|
+
id?: number;
|
|
13
|
+
/**
|
|
14
|
+
* 唯一标识
|
|
15
|
+
*/
|
|
16
|
+
uuid: string;
|
|
17
|
+
/**
|
|
18
|
+
* 类型 如 push undo redo
|
|
19
|
+
*/
|
|
20
|
+
type: string;
|
|
21
|
+
/**
|
|
22
|
+
* 时间戳
|
|
23
|
+
*/
|
|
24
|
+
timestamp: number;
|
|
25
|
+
/**
|
|
26
|
+
* 资源uri
|
|
27
|
+
*/
|
|
28
|
+
resourceURI: string;
|
|
29
|
+
/**
|
|
30
|
+
* 资源json
|
|
31
|
+
*/
|
|
32
|
+
resourceJSON: unknown;
|
|
33
|
+
}
|
|
34
|
+
interface HistoryOperationRecord {
|
|
35
|
+
/**
|
|
36
|
+
* 自增id
|
|
37
|
+
*/
|
|
38
|
+
id?: number;
|
|
39
|
+
/**
|
|
40
|
+
* 唯一标识
|
|
41
|
+
*/
|
|
42
|
+
uuid: string;
|
|
43
|
+
/**
|
|
44
|
+
* 历史记录唯一标志,记录的uuid
|
|
45
|
+
*/
|
|
46
|
+
historyId: string;
|
|
47
|
+
/**
|
|
48
|
+
* 类型,如 addFromNode deleteFromNode
|
|
49
|
+
*/
|
|
50
|
+
type: string;
|
|
51
|
+
/**
|
|
52
|
+
* 操作值,不同类型不同,json字符串
|
|
53
|
+
*/
|
|
54
|
+
value: string;
|
|
55
|
+
/**
|
|
56
|
+
* uri操作对象uri,如某个node的uri
|
|
57
|
+
*/
|
|
58
|
+
uri: string;
|
|
59
|
+
/**
|
|
60
|
+
* 操作资源uri,如某个流程的uri
|
|
61
|
+
*/
|
|
62
|
+
resourceURI: string;
|
|
63
|
+
/**
|
|
64
|
+
* 操作显示标题
|
|
65
|
+
*/
|
|
66
|
+
label: string;
|
|
67
|
+
/**
|
|
68
|
+
* 操作显示描述
|
|
69
|
+
*/
|
|
70
|
+
description: string;
|
|
71
|
+
/**
|
|
72
|
+
* 时间戳
|
|
73
|
+
*/
|
|
74
|
+
timestamp: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 插件配置
|
|
78
|
+
*/
|
|
79
|
+
interface HistoryStoragePluginOptions {
|
|
80
|
+
/**
|
|
81
|
+
* 数据库名称
|
|
82
|
+
*/
|
|
83
|
+
databaseName?: string;
|
|
84
|
+
/**
|
|
85
|
+
* 每个资源最大历史记录数量
|
|
86
|
+
*/
|
|
87
|
+
resourceStorageLimit?: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare const createHistoryStoragePlugin: _flowgram_ai_core.PluginCreator<HistoryStoragePluginOptions>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 历史数据库
|
|
94
|
+
*/
|
|
95
|
+
declare class HistoryDatabase extends dexie__default {
|
|
96
|
+
readonly history: Table<HistoryRecord>;
|
|
97
|
+
readonly operation: Table<HistoryOperationRecord>;
|
|
98
|
+
resourceStorageLimit: number;
|
|
99
|
+
constructor(databaseName?: string);
|
|
100
|
+
/**
|
|
101
|
+
* 某个uri下所有的history记录
|
|
102
|
+
* @param resourceURI 资源uri
|
|
103
|
+
* @returns
|
|
104
|
+
*/
|
|
105
|
+
allHistoryByResourceURI(resourceURI: string): dexie.PromiseExtended<HistoryRecord[]>;
|
|
106
|
+
/**
|
|
107
|
+
* 根据uuid获取历史
|
|
108
|
+
* @param uuid
|
|
109
|
+
* @returns
|
|
110
|
+
*/
|
|
111
|
+
getHistoryByUUID(uuid: string): dexie.PromiseExtended<HistoryRecord | undefined>;
|
|
112
|
+
/**
|
|
113
|
+
* 某个uri下所有的operation记录
|
|
114
|
+
* @param resourceURI 资源uri
|
|
115
|
+
* @returns
|
|
116
|
+
*/
|
|
117
|
+
allOperationByResourceURI(resourceURI: string): dexie.PromiseExtended<HistoryOperationRecord[]>;
|
|
118
|
+
/**
|
|
119
|
+
* 添加历史记录
|
|
120
|
+
* @param history 历史记录
|
|
121
|
+
* @param operations 操作记录
|
|
122
|
+
* @returns
|
|
123
|
+
*/
|
|
124
|
+
addHistoryRecord(history: HistoryRecord, operations: HistoryOperationRecord[]): dexie.PromiseExtended<[any, any]>;
|
|
125
|
+
/**
|
|
126
|
+
* 更新历史记录
|
|
127
|
+
* @param historyRecord
|
|
128
|
+
* @returns
|
|
129
|
+
*/
|
|
130
|
+
updateHistoryByUUID(uuid: string, historyRecord: Partial<HistoryRecord>): Promise<number | undefined>;
|
|
131
|
+
/**
|
|
132
|
+
* 添加操作记录
|
|
133
|
+
* @param record 操作记录
|
|
134
|
+
* @returns
|
|
135
|
+
*/
|
|
136
|
+
addOperationRecord(record: HistoryOperationRecord): dexie.PromiseExtended<any>;
|
|
137
|
+
/**
|
|
138
|
+
* 更新操作记录
|
|
139
|
+
* @param record 操作记录
|
|
140
|
+
* @returns
|
|
141
|
+
*/
|
|
142
|
+
updateOperationRecord(record: HistoryOperationRecord): Promise<any>;
|
|
143
|
+
/**
|
|
144
|
+
* 重置数据库
|
|
145
|
+
* @returns
|
|
146
|
+
*/
|
|
147
|
+
reset(): dexie.PromiseExtended<void>;
|
|
148
|
+
/**
|
|
149
|
+
* 清空某个资源下所有的数据
|
|
150
|
+
* @param resourceURI
|
|
151
|
+
* @returns
|
|
152
|
+
*/
|
|
153
|
+
resetByResourceURI(resourceURI: string): dexie.PromiseExtended<void>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 历史存储管理
|
|
158
|
+
*/
|
|
159
|
+
declare class HistoryStorageManager {
|
|
160
|
+
private _toDispose;
|
|
161
|
+
db: HistoryDatabase;
|
|
162
|
+
protected historyManager: HistoryManager;
|
|
163
|
+
/**
|
|
164
|
+
* 初始化
|
|
165
|
+
* @param ctx
|
|
166
|
+
*/
|
|
167
|
+
onInit(_ctx: PluginContext, opts: HistoryStoragePluginOptions): void;
|
|
168
|
+
/**
|
|
169
|
+
* 内存历史转数据表记录
|
|
170
|
+
* @param historyItem
|
|
171
|
+
* @returns
|
|
172
|
+
*/
|
|
173
|
+
historyItemToRecord(historyService: HistoryService, historyItem: HistoryItem): [HistoryRecord, HistoryOperationRecord[]];
|
|
174
|
+
/**
|
|
175
|
+
* 内存操作转数据表操作
|
|
176
|
+
* @param historyItem
|
|
177
|
+
* @param op
|
|
178
|
+
* @returns
|
|
179
|
+
*/
|
|
180
|
+
historyOperationToRecord(historyItem: HistoryItem, op: HistoryOperation): HistoryOperationRecord;
|
|
181
|
+
/**
|
|
182
|
+
* 销毁
|
|
183
|
+
*/
|
|
184
|
+
dispose(): void;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
declare function useStorageHistoryItems(historyStorageManager: HistoryStorageManager, resourceURI: string): {
|
|
188
|
+
items: HistoryItem[];
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
declare const HistoryStorageContainerModule: ContainerModule;
|
|
192
|
+
|
|
193
|
+
export { HistoryDatabase, type HistoryOperationRecord, type HistoryRecord, HistoryStorageContainerModule, HistoryStorageManager, type HistoryStoragePluginOptions, createHistoryStoragePlugin, useStorageHistoryItems };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
2
|
+
import { PluginContext } from '@flowgram.ai/core';
|
|
3
|
+
import { HistoryManager, HistoryService, HistoryItem, HistoryOperation } from '@flowgram.ai/history';
|
|
4
|
+
import * as dexie from 'dexie';
|
|
5
|
+
import dexie__default, { Table } from 'dexie';
|
|
6
|
+
import { ContainerModule } from 'inversify';
|
|
7
|
+
|
|
8
|
+
interface HistoryRecord {
|
|
9
|
+
/**
|
|
10
|
+
* 自增id
|
|
11
|
+
*/
|
|
12
|
+
id?: number;
|
|
13
|
+
/**
|
|
14
|
+
* 唯一标识
|
|
15
|
+
*/
|
|
16
|
+
uuid: string;
|
|
17
|
+
/**
|
|
18
|
+
* 类型 如 push undo redo
|
|
19
|
+
*/
|
|
20
|
+
type: string;
|
|
21
|
+
/**
|
|
22
|
+
* 时间戳
|
|
23
|
+
*/
|
|
24
|
+
timestamp: number;
|
|
25
|
+
/**
|
|
26
|
+
* 资源uri
|
|
27
|
+
*/
|
|
28
|
+
resourceURI: string;
|
|
29
|
+
/**
|
|
30
|
+
* 资源json
|
|
31
|
+
*/
|
|
32
|
+
resourceJSON: unknown;
|
|
33
|
+
}
|
|
34
|
+
interface HistoryOperationRecord {
|
|
35
|
+
/**
|
|
36
|
+
* 自增id
|
|
37
|
+
*/
|
|
38
|
+
id?: number;
|
|
39
|
+
/**
|
|
40
|
+
* 唯一标识
|
|
41
|
+
*/
|
|
42
|
+
uuid: string;
|
|
43
|
+
/**
|
|
44
|
+
* 历史记录唯一标志,记录的uuid
|
|
45
|
+
*/
|
|
46
|
+
historyId: string;
|
|
47
|
+
/**
|
|
48
|
+
* 类型,如 addFromNode deleteFromNode
|
|
49
|
+
*/
|
|
50
|
+
type: string;
|
|
51
|
+
/**
|
|
52
|
+
* 操作值,不同类型不同,json字符串
|
|
53
|
+
*/
|
|
54
|
+
value: string;
|
|
55
|
+
/**
|
|
56
|
+
* uri操作对象uri,如某个node的uri
|
|
57
|
+
*/
|
|
58
|
+
uri: string;
|
|
59
|
+
/**
|
|
60
|
+
* 操作资源uri,如某个流程的uri
|
|
61
|
+
*/
|
|
62
|
+
resourceURI: string;
|
|
63
|
+
/**
|
|
64
|
+
* 操作显示标题
|
|
65
|
+
*/
|
|
66
|
+
label: string;
|
|
67
|
+
/**
|
|
68
|
+
* 操作显示描述
|
|
69
|
+
*/
|
|
70
|
+
description: string;
|
|
71
|
+
/**
|
|
72
|
+
* 时间戳
|
|
73
|
+
*/
|
|
74
|
+
timestamp: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 插件配置
|
|
78
|
+
*/
|
|
79
|
+
interface HistoryStoragePluginOptions {
|
|
80
|
+
/**
|
|
81
|
+
* 数据库名称
|
|
82
|
+
*/
|
|
83
|
+
databaseName?: string;
|
|
84
|
+
/**
|
|
85
|
+
* 每个资源最大历史记录数量
|
|
86
|
+
*/
|
|
87
|
+
resourceStorageLimit?: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare const createHistoryStoragePlugin: _flowgram_ai_core.PluginCreator<HistoryStoragePluginOptions>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 历史数据库
|
|
94
|
+
*/
|
|
95
|
+
declare class HistoryDatabase extends dexie__default {
|
|
96
|
+
readonly history: Table<HistoryRecord>;
|
|
97
|
+
readonly operation: Table<HistoryOperationRecord>;
|
|
98
|
+
resourceStorageLimit: number;
|
|
99
|
+
constructor(databaseName?: string);
|
|
100
|
+
/**
|
|
101
|
+
* 某个uri下所有的history记录
|
|
102
|
+
* @param resourceURI 资源uri
|
|
103
|
+
* @returns
|
|
104
|
+
*/
|
|
105
|
+
allHistoryByResourceURI(resourceURI: string): dexie.PromiseExtended<HistoryRecord[]>;
|
|
106
|
+
/**
|
|
107
|
+
* 根据uuid获取历史
|
|
108
|
+
* @param uuid
|
|
109
|
+
* @returns
|
|
110
|
+
*/
|
|
111
|
+
getHistoryByUUID(uuid: string): dexie.PromiseExtended<HistoryRecord | undefined>;
|
|
112
|
+
/**
|
|
113
|
+
* 某个uri下所有的operation记录
|
|
114
|
+
* @param resourceURI 资源uri
|
|
115
|
+
* @returns
|
|
116
|
+
*/
|
|
117
|
+
allOperationByResourceURI(resourceURI: string): dexie.PromiseExtended<HistoryOperationRecord[]>;
|
|
118
|
+
/**
|
|
119
|
+
* 添加历史记录
|
|
120
|
+
* @param history 历史记录
|
|
121
|
+
* @param operations 操作记录
|
|
122
|
+
* @returns
|
|
123
|
+
*/
|
|
124
|
+
addHistoryRecord(history: HistoryRecord, operations: HistoryOperationRecord[]): dexie.PromiseExtended<[any, any]>;
|
|
125
|
+
/**
|
|
126
|
+
* 更新历史记录
|
|
127
|
+
* @param historyRecord
|
|
128
|
+
* @returns
|
|
129
|
+
*/
|
|
130
|
+
updateHistoryByUUID(uuid: string, historyRecord: Partial<HistoryRecord>): Promise<number | undefined>;
|
|
131
|
+
/**
|
|
132
|
+
* 添加操作记录
|
|
133
|
+
* @param record 操作记录
|
|
134
|
+
* @returns
|
|
135
|
+
*/
|
|
136
|
+
addOperationRecord(record: HistoryOperationRecord): dexie.PromiseExtended<any>;
|
|
137
|
+
/**
|
|
138
|
+
* 更新操作记录
|
|
139
|
+
* @param record 操作记录
|
|
140
|
+
* @returns
|
|
141
|
+
*/
|
|
142
|
+
updateOperationRecord(record: HistoryOperationRecord): Promise<any>;
|
|
143
|
+
/**
|
|
144
|
+
* 重置数据库
|
|
145
|
+
* @returns
|
|
146
|
+
*/
|
|
147
|
+
reset(): dexie.PromiseExtended<void>;
|
|
148
|
+
/**
|
|
149
|
+
* 清空某个资源下所有的数据
|
|
150
|
+
* @param resourceURI
|
|
151
|
+
* @returns
|
|
152
|
+
*/
|
|
153
|
+
resetByResourceURI(resourceURI: string): dexie.PromiseExtended<void>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 历史存储管理
|
|
158
|
+
*/
|
|
159
|
+
declare class HistoryStorageManager {
|
|
160
|
+
private _toDispose;
|
|
161
|
+
db: HistoryDatabase;
|
|
162
|
+
protected historyManager: HistoryManager;
|
|
163
|
+
/**
|
|
164
|
+
* 初始化
|
|
165
|
+
* @param ctx
|
|
166
|
+
*/
|
|
167
|
+
onInit(_ctx: PluginContext, opts: HistoryStoragePluginOptions): void;
|
|
168
|
+
/**
|
|
169
|
+
* 内存历史转数据表记录
|
|
170
|
+
* @param historyItem
|
|
171
|
+
* @returns
|
|
172
|
+
*/
|
|
173
|
+
historyItemToRecord(historyService: HistoryService, historyItem: HistoryItem): [HistoryRecord, HistoryOperationRecord[]];
|
|
174
|
+
/**
|
|
175
|
+
* 内存操作转数据表操作
|
|
176
|
+
* @param historyItem
|
|
177
|
+
* @param op
|
|
178
|
+
* @returns
|
|
179
|
+
*/
|
|
180
|
+
historyOperationToRecord(historyItem: HistoryItem, op: HistoryOperation): HistoryOperationRecord;
|
|
181
|
+
/**
|
|
182
|
+
* 销毁
|
|
183
|
+
*/
|
|
184
|
+
dispose(): void;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
declare function useStorageHistoryItems(historyStorageManager: HistoryStorageManager, resourceURI: string): {
|
|
188
|
+
items: HistoryItem[];
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
declare const HistoryStorageContainerModule: ContainerModule;
|
|
192
|
+
|
|
193
|
+
export { HistoryDatabase, type HistoryOperationRecord, type HistoryRecord, HistoryStorageContainerModule, HistoryStorageManager, type HistoryStoragePluginOptions, createHistoryStoragePlugin, useStorageHistoryItems };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
30
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
31
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
32
|
+
if (decorator = decorators[i])
|
|
33
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
34
|
+
if (kind && result) __defProp(target, key, result);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/index.ts
|
|
39
|
+
var src_exports = {};
|
|
40
|
+
__export(src_exports, {
|
|
41
|
+
HistoryDatabase: () => HistoryDatabase,
|
|
42
|
+
HistoryStorageContainerModule: () => HistoryStorageContainerModule,
|
|
43
|
+
HistoryStorageManager: () => HistoryStorageManager,
|
|
44
|
+
createHistoryStoragePlugin: () => createHistoryStoragePlugin,
|
|
45
|
+
useStorageHistoryItems: () => useStorageHistoryItems
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(src_exports);
|
|
48
|
+
|
|
49
|
+
// src/create-history-storage-plugin.ts
|
|
50
|
+
var import_core = require("@flowgram.ai/core");
|
|
51
|
+
|
|
52
|
+
// src/history-storage-manager.ts
|
|
53
|
+
var import_inversify = require("inversify");
|
|
54
|
+
var import_utils = require("@flowgram.ai/utils");
|
|
55
|
+
var import_history = require("@flowgram.ai/history");
|
|
56
|
+
|
|
57
|
+
// src/history-database.ts
|
|
58
|
+
var import_dexie = __toESM(require("dexie"));
|
|
59
|
+
var HistoryDatabase = class extends import_dexie.default {
|
|
60
|
+
constructor(databaseName = "ide-history-storage") {
|
|
61
|
+
super(databaseName);
|
|
62
|
+
this.resourceStorageLimit = 100;
|
|
63
|
+
this.version(1).stores({
|
|
64
|
+
history: "++id, &uuid, resourceURI",
|
|
65
|
+
operation: "++id, &uuid, historyId, uri, resourceURI"
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 某个uri下所有的history记录
|
|
70
|
+
* @param resourceURI 资源uri
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
allHistoryByResourceURI(resourceURI) {
|
|
74
|
+
return this.history.where({ resourceURI }).toArray();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 根据uuid获取历史
|
|
78
|
+
* @param uuid
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
getHistoryByUUID(uuid) {
|
|
82
|
+
return this.history.get({ uuid });
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 某个uri下所有的operation记录
|
|
86
|
+
* @param resourceURI 资源uri
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
allOperationByResourceURI(resourceURI) {
|
|
90
|
+
return this.operation.where({ resourceURI }).toArray();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 添加历史记录
|
|
94
|
+
* @param history 历史记录
|
|
95
|
+
* @param operations 操作记录
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
addHistoryRecord(history, operations) {
|
|
99
|
+
return this.transaction("rw", this.history, this.operation, async () => {
|
|
100
|
+
const count = await this.history.where({ resourceURI: history.resourceURI }).count();
|
|
101
|
+
if (count >= this.resourceStorageLimit) {
|
|
102
|
+
const limit = count - this.resourceStorageLimit;
|
|
103
|
+
const items = await this.history.where({ resourceURI: history.resourceURI }).limit(limit).toArray();
|
|
104
|
+
const ids = items.map((i) => i.id);
|
|
105
|
+
const uuid = items.map((i) => i.uuid);
|
|
106
|
+
await Promise.all([
|
|
107
|
+
this.history.bulkDelete(ids),
|
|
108
|
+
...uuid.map(async (uuid2) => {
|
|
109
|
+
await this.operation.where({ historyId: uuid2 }).delete();
|
|
110
|
+
})
|
|
111
|
+
]);
|
|
112
|
+
}
|
|
113
|
+
return Promise.all([this.history.add(history), this.operation.bulkAdd(operations)]);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 更新历史记录
|
|
118
|
+
* @param historyRecord
|
|
119
|
+
* @returns
|
|
120
|
+
*/
|
|
121
|
+
async updateHistoryByUUID(uuid, historyRecord) {
|
|
122
|
+
const history = await this.getHistoryByUUID(uuid);
|
|
123
|
+
if (!history) {
|
|
124
|
+
console.warn("no history record found");
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
return this.history.update(history.id, historyRecord);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 添加操作记录
|
|
131
|
+
* @param record 操作记录
|
|
132
|
+
* @returns
|
|
133
|
+
*/
|
|
134
|
+
addOperationRecord(record) {
|
|
135
|
+
return this.operation.add(record);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 更新操作记录
|
|
139
|
+
* @param record 操作记录
|
|
140
|
+
* @returns
|
|
141
|
+
*/
|
|
142
|
+
async updateOperationRecord(record) {
|
|
143
|
+
const op = await this.operation.where({ uuid: record.uuid }).first();
|
|
144
|
+
if (!op) {
|
|
145
|
+
console.warn("no operation record found");
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
return this.operation.put({
|
|
149
|
+
id: op.id,
|
|
150
|
+
...record
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 重置数据库
|
|
155
|
+
* @returns
|
|
156
|
+
*/
|
|
157
|
+
reset() {
|
|
158
|
+
return this.transaction("rw", this.history, this.operation, async () => {
|
|
159
|
+
await Promise.all(this.tables.map((table) => table.clear()));
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 清空某个资源下所有的数据
|
|
164
|
+
* @param resourceURI
|
|
165
|
+
* @returns
|
|
166
|
+
*/
|
|
167
|
+
resetByResourceURI(resourceURI) {
|
|
168
|
+
return this.transaction("rw", this.history, this.operation, async () => {
|
|
169
|
+
await Promise.all(this.tables.map((table) => table.where({ resourceURI }).delete()));
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/history-storage-manager.ts
|
|
175
|
+
var HistoryStorageManager = class {
|
|
176
|
+
constructor() {
|
|
177
|
+
this._toDispose = new import_utils.DisposableCollection();
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* 初始化
|
|
181
|
+
* @param ctx
|
|
182
|
+
*/
|
|
183
|
+
onInit(_ctx, opts) {
|
|
184
|
+
this.db = new HistoryDatabase(opts?.databaseName);
|
|
185
|
+
if (opts?.resourceStorageLimit) {
|
|
186
|
+
this.db.resourceStorageLimit = opts.resourceStorageLimit;
|
|
187
|
+
}
|
|
188
|
+
this._toDispose.push(
|
|
189
|
+
this.historyManager.historyStack.onChange((event) => {
|
|
190
|
+
if (event.type === import_history.HistoryStackChangeType.ADD) {
|
|
191
|
+
const [history, operations] = this.historyItemToRecord(event.service, event.value);
|
|
192
|
+
this.db.addHistoryRecord(history, operations).catch(console.error);
|
|
193
|
+
}
|
|
194
|
+
if ([import_history.HistoryStackChangeType.ADD_OPERATION, import_history.HistoryStackChangeType.UPDATE_OPERATION].includes(
|
|
195
|
+
event.type
|
|
196
|
+
)) {
|
|
197
|
+
const {
|
|
198
|
+
service,
|
|
199
|
+
value: { historyItem }
|
|
200
|
+
} = event;
|
|
201
|
+
this.db.updateHistoryByUUID(historyItem.id, {
|
|
202
|
+
resourceJSON: service.getSnapshot() || ""
|
|
203
|
+
}).catch(console.error);
|
|
204
|
+
}
|
|
205
|
+
if (event.type === import_history.HistoryStackChangeType.ADD_OPERATION) {
|
|
206
|
+
const operationRecord = this.historyOperationToRecord(
|
|
207
|
+
event.value.historyItem,
|
|
208
|
+
event.value.operation
|
|
209
|
+
);
|
|
210
|
+
this.db.addOperationRecord(operationRecord).catch(console.error);
|
|
211
|
+
}
|
|
212
|
+
if (event.type === import_history.HistoryStackChangeType.UPDATE_OPERATION) {
|
|
213
|
+
const operationRecord = this.historyOperationToRecord(
|
|
214
|
+
event.value.historyItem,
|
|
215
|
+
event.value.operation
|
|
216
|
+
);
|
|
217
|
+
this.db.updateOperationRecord(operationRecord).catch(console.error);
|
|
218
|
+
}
|
|
219
|
+
})
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* 内存历史转数据表记录
|
|
224
|
+
* @param historyItem
|
|
225
|
+
* @returns
|
|
226
|
+
*/
|
|
227
|
+
historyItemToRecord(historyService, historyItem) {
|
|
228
|
+
const operations = historyItem.operations.map(
|
|
229
|
+
(op) => this.historyOperationToRecord(historyItem, op)
|
|
230
|
+
);
|
|
231
|
+
return [
|
|
232
|
+
{
|
|
233
|
+
uuid: historyItem.id,
|
|
234
|
+
timestamp: historyItem.timestamp,
|
|
235
|
+
type: historyItem.type,
|
|
236
|
+
resourceURI: historyItem.uri?.toString() || "",
|
|
237
|
+
resourceJSON: historyService.getSnapshot() || ""
|
|
238
|
+
},
|
|
239
|
+
operations
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* 内存操作转数据表操作
|
|
244
|
+
* @param historyItem
|
|
245
|
+
* @param op
|
|
246
|
+
* @returns
|
|
247
|
+
*/
|
|
248
|
+
historyOperationToRecord(historyItem, op) {
|
|
249
|
+
return {
|
|
250
|
+
uuid: op.id,
|
|
251
|
+
type: op.type,
|
|
252
|
+
timestamp: op.timestamp,
|
|
253
|
+
label: op.label || "",
|
|
254
|
+
uri: op?.uri?.toString() || "",
|
|
255
|
+
resourceURI: historyItem.uri?.toString() || "",
|
|
256
|
+
description: op.description || "",
|
|
257
|
+
value: JSON.stringify(op.value),
|
|
258
|
+
historyId: historyItem.id
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* 销毁
|
|
263
|
+
*/
|
|
264
|
+
dispose() {
|
|
265
|
+
this._toDispose.dispose();
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
__decorateClass([
|
|
269
|
+
(0, import_inversify.inject)(import_history.HistoryManager)
|
|
270
|
+
], HistoryStorageManager.prototype, "historyManager", 2);
|
|
271
|
+
HistoryStorageManager = __decorateClass([
|
|
272
|
+
(0, import_inversify.injectable)()
|
|
273
|
+
], HistoryStorageManager);
|
|
274
|
+
|
|
275
|
+
// src/history-storage-container-module.ts
|
|
276
|
+
var import_inversify2 = require("inversify");
|
|
277
|
+
var HistoryStorageContainerModule = new import_inversify2.ContainerModule((bind) => {
|
|
278
|
+
bind(HistoryStorageManager).toSelf().inSingletonScope();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// src/create-history-storage-plugin.ts
|
|
282
|
+
var createHistoryStoragePlugin = (0, import_core.definePluginCreator)({
|
|
283
|
+
onBind: ({ bind, rebind }) => {
|
|
284
|
+
},
|
|
285
|
+
onInit(ctx, opts) {
|
|
286
|
+
const historyStorageManager = ctx.get(HistoryStorageManager);
|
|
287
|
+
historyStorageManager.onInit(ctx, opts);
|
|
288
|
+
},
|
|
289
|
+
onDispose(ctx) {
|
|
290
|
+
const historyStorageManager = ctx.get(HistoryStorageManager);
|
|
291
|
+
historyStorageManager.dispose();
|
|
292
|
+
},
|
|
293
|
+
containerModules: [HistoryStorageContainerModule]
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// src/use-storage-hisotry-items.tsx
|
|
297
|
+
var import_lodash = require("lodash");
|
|
298
|
+
var import_dexie_react_hooks = require("dexie-react-hooks");
|
|
299
|
+
var import_history2 = require("@flowgram.ai/history");
|
|
300
|
+
function useStorageHistoryItems(historyStorageManager, resourceURI) {
|
|
301
|
+
const items = (0, import_dexie_react_hooks.useLiveQuery)(async () => {
|
|
302
|
+
const [historyItems, operations] = await Promise.all([
|
|
303
|
+
historyStorageManager.db.allHistoryByResourceURI(resourceURI),
|
|
304
|
+
historyStorageManager.db.allOperationByResourceURI(resourceURI)
|
|
305
|
+
]);
|
|
306
|
+
const grouped = (0, import_lodash.groupBy)(
|
|
307
|
+
operations.map((o) => ({
|
|
308
|
+
id: o.uuid,
|
|
309
|
+
timestamp: o.timestamp,
|
|
310
|
+
type: o.type,
|
|
311
|
+
label: o.label,
|
|
312
|
+
description: o.description,
|
|
313
|
+
value: o.value ? JSON.parse(o.value) : void 0,
|
|
314
|
+
uri: o.uri,
|
|
315
|
+
historyId: o.historyId
|
|
316
|
+
})),
|
|
317
|
+
"historyId"
|
|
318
|
+
);
|
|
319
|
+
return historyItems.sort((a, b) => b.id - a.id).map(
|
|
320
|
+
(historyItem) => ({
|
|
321
|
+
id: historyItem.uuid,
|
|
322
|
+
type: historyItem.type,
|
|
323
|
+
timestamp: historyItem.timestamp,
|
|
324
|
+
operations: grouped[historyItem.uuid] || [],
|
|
325
|
+
time: import_history2.HistoryStack.dateFormat(historyItem.timestamp),
|
|
326
|
+
uri: historyItem.resourceURI
|
|
327
|
+
})
|
|
328
|
+
);
|
|
329
|
+
}, [resourceURI]) || [];
|
|
330
|
+
return {
|
|
331
|
+
items
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
335
|
+
0 && (module.exports = {
|
|
336
|
+
HistoryDatabase,
|
|
337
|
+
HistoryStorageContainerModule,
|
|
338
|
+
HistoryStorageManager,
|
|
339
|
+
createHistoryStoragePlugin,
|
|
340
|
+
useStorageHistoryItems
|
|
341
|
+
});
|
|
342
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/create-history-storage-plugin.ts","../src/history-storage-manager.ts","../src/history-database.ts","../src/history-storage-container-module.ts","../src/use-storage-hisotry-items.tsx"],"sourcesContent":["export * from './create-history-storage-plugin';\nexport * from './use-storage-hisotry-items';\nexport * from './types';\nexport * from './history-database';\nexport * from './history-storage-container-module';\nexport * from './history-storage-manager';\n","import { definePluginCreator } from '@flowgram.ai/core';\n\nimport { HistoryStoragePluginOptions } from './types';\nimport { HistoryStorageManager } from './history-storage-manager';\nimport { HistoryStorageContainerModule } from './history-storage-container-module';\n\nexport const createHistoryStoragePlugin = definePluginCreator<HistoryStoragePluginOptions>({\n onBind: ({ bind, rebind }) => {},\n onInit(ctx, opts): void {\n const historyStorageManager = ctx.get<HistoryStorageManager>(HistoryStorageManager);\n historyStorageManager.onInit(ctx, opts);\n },\n onDispose(ctx) {\n const historyStorageManager = ctx.get<HistoryStorageManager>(HistoryStorageManager);\n historyStorageManager.dispose();\n },\n containerModules: [HistoryStorageContainerModule],\n});\n","import { inject, injectable } from 'inversify';\nimport { DisposableCollection } from '@flowgram.ai/utils';\nimport {\n HistoryItem,\n HistoryManager,\n HistoryOperation,\n HistoryStackChangeType,\n HistoryService,\n HistoryStackAddOperationEvent,\n HistoryStackUpdateOperationEvent,\n} from '@flowgram.ai/history';\nimport { PluginContext } from '@flowgram.ai/core';\n\nimport { HistoryOperationRecord, HistoryRecord, HistoryStoragePluginOptions } from './types';\nimport { HistoryDatabase } from './history-database';\n\n/**\n * 历史存储管理\n */\n@injectable()\nexport class HistoryStorageManager {\n private _toDispose = new DisposableCollection();\n\n db: HistoryDatabase;\n\n @inject(HistoryManager)\n protected historyManager: HistoryManager;\n\n /**\n * 初始化\n * @param ctx\n */\n onInit(_ctx: PluginContext, opts: HistoryStoragePluginOptions) {\n this.db = new HistoryDatabase(opts?.databaseName);\n\n if (opts?.resourceStorageLimit) {\n this.db.resourceStorageLimit = opts.resourceStorageLimit;\n }\n\n this._toDispose.push(\n this.historyManager.historyStack.onChange(event => {\n if (event.type === HistoryStackChangeType.ADD) {\n const [history, operations] = this.historyItemToRecord(event.service, event.value);\n this.db.addHistoryRecord(history, operations).catch(console.error);\n }\n\n // operation merge的时候需要更新snapshot\n if (\n [HistoryStackChangeType.ADD_OPERATION, HistoryStackChangeType.UPDATE_OPERATION].includes(\n event.type,\n )\n ) {\n const {\n service,\n value: { historyItem },\n } = event as HistoryStackAddOperationEvent | HistoryStackUpdateOperationEvent;\n // 更新快照\n this.db\n .updateHistoryByUUID(historyItem.id, {\n resourceJSON: service.getSnapshot() || '',\n })\n .catch(console.error);\n }\n\n if (event.type === HistoryStackChangeType.ADD_OPERATION) {\n const operationRecord: HistoryOperationRecord = this.historyOperationToRecord(\n event.value.historyItem,\n event.value.operation,\n );\n this.db.addOperationRecord(operationRecord).catch(console.error);\n }\n if (event.type === HistoryStackChangeType.UPDATE_OPERATION) {\n const operationRecord: HistoryOperationRecord = this.historyOperationToRecord(\n event.value.historyItem,\n event.value.operation,\n );\n this.db.updateOperationRecord(operationRecord).catch(console.error);\n }\n }),\n );\n }\n\n /**\n * 内存历史转数据表记录\n * @param historyItem\n * @returns\n */\n historyItemToRecord(\n historyService: HistoryService,\n historyItem: HistoryItem,\n ): [HistoryRecord, HistoryOperationRecord[]] {\n const operations = historyItem.operations.map(op =>\n this.historyOperationToRecord(historyItem, op),\n );\n\n return [\n {\n uuid: historyItem.id,\n timestamp: historyItem.timestamp,\n type: historyItem.type,\n resourceURI: historyItem.uri?.toString() || '',\n resourceJSON: historyService.getSnapshot() || '',\n },\n operations,\n ];\n }\n\n /**\n * 内存操作转数据表操作\n * @param historyItem\n * @param op\n * @returns\n */\n historyOperationToRecord(historyItem: HistoryItem, op: HistoryOperation): HistoryOperationRecord {\n return {\n uuid: op.id,\n type: op.type,\n timestamp: op.timestamp,\n label: op.label || '',\n uri: op?.uri?.toString() || '',\n resourceURI: historyItem.uri?.toString() || '',\n description: op.description || '',\n value: JSON.stringify(op.value),\n historyId: historyItem.id,\n };\n }\n\n /**\n * 销毁\n */\n dispose() {\n this._toDispose.dispose();\n }\n}\n","import Dexie, { type Table } from 'dexie';\n\nimport { HistoryOperationRecord, HistoryRecord } from './types';\n\n/**\n * 历史数据库\n */\nexport class HistoryDatabase extends Dexie {\n readonly history: Table<HistoryRecord>;\n\n readonly operation: Table<HistoryOperationRecord>;\n\n resourceStorageLimit: number = 100;\n\n constructor(databaseName: string = 'ide-history-storage') {\n super(databaseName);\n this.version(1).stores({\n history: '++id, &uuid, resourceURI',\n operation: '++id, &uuid, historyId, uri, resourceURI',\n });\n }\n\n /**\n * 某个uri下所有的history记录\n * @param resourceURI 资源uri\n * @returns\n */\n allHistoryByResourceURI(resourceURI: string) {\n return this.history.where({ resourceURI }).toArray();\n }\n\n /**\n * 根据uuid获取历史\n * @param uuid\n * @returns\n */\n getHistoryByUUID(uuid: string) {\n return this.history.get({ uuid });\n }\n\n /**\n * 某个uri下所有的operation记录\n * @param resourceURI 资源uri\n * @returns\n */\n allOperationByResourceURI(resourceURI: string) {\n return this.operation.where({ resourceURI }).toArray();\n }\n\n /**\n * 添加历史记录\n * @param history 历史记录\n * @param operations 操作记录\n * @returns\n */\n addHistoryRecord(history: HistoryRecord, operations: HistoryOperationRecord[]) {\n return this.transaction('rw', this.history, this.operation, async () => {\n const count = await this.history.where({ resourceURI: history.resourceURI }).count();\n if (count >= this.resourceStorageLimit) {\n const limit = count - this.resourceStorageLimit;\n const items = await this.history\n .where({ resourceURI: history.resourceURI })\n .limit(limit)\n .toArray();\n const ids = items.map(i => i.id);\n const uuid = items.map(i => i.uuid);\n await Promise.all([\n this.history.bulkDelete(ids),\n ...uuid.map(async uuid => {\n await this.operation.where({ historyId: uuid }).delete();\n }),\n ]);\n }\n\n return Promise.all([this.history.add(history), this.operation.bulkAdd(operations)]);\n });\n }\n\n /**\n * 更新历史记录\n * @param historyRecord\n * @returns\n */\n async updateHistoryByUUID(uuid: string, historyRecord: Partial<HistoryRecord>) {\n const history = await this.getHistoryByUUID(uuid);\n if (!history) {\n console.warn('no history record found');\n return;\n }\n return this.history.update(history.id, historyRecord);\n }\n\n /**\n * 添加操作记录\n * @param record 操作记录\n * @returns\n */\n addOperationRecord(record: HistoryOperationRecord) {\n return this.operation.add(record);\n }\n\n /**\n * 更新操作记录\n * @param record 操作记录\n * @returns\n */\n async updateOperationRecord(record: HistoryOperationRecord) {\n const op = await this.operation.where({ uuid: record.uuid }).first();\n if (!op) {\n console.warn('no operation record found');\n return;\n }\n return this.operation.put({\n id: op.id,\n ...record,\n });\n }\n\n /**\n * 重置数据库\n * @returns\n */\n reset() {\n return this.transaction('rw', this.history, this.operation, async () => {\n await Promise.all(this.tables.map(table => table.clear()));\n });\n }\n\n /**\n * 清空某个资源下所有的数据\n * @param resourceURI\n * @returns\n */\n resetByResourceURI(resourceURI: string) {\n return this.transaction('rw', this.history, this.operation, async () => {\n await Promise.all(this.tables.map(table => table.where({ resourceURI }).delete()));\n });\n }\n}\n","import { ContainerModule } from 'inversify';\n\nimport { HistoryStorageManager } from './history-storage-manager';\n\nexport const HistoryStorageContainerModule = new ContainerModule(bind => {\n bind(HistoryStorageManager).toSelf().inSingletonScope();\n});\n","import { groupBy } from 'lodash';\nimport { useLiveQuery } from 'dexie-react-hooks';\nimport { HistoryItem, HistoryOperation, HistoryStack } from '@flowgram.ai/history';\n\nimport { HistoryStorageManager } from './history-storage-manager';\nexport function useStorageHistoryItems(\n historyStorageManager: HistoryStorageManager,\n resourceURI: string\n): {\n items: HistoryItem[];\n} {\n const items: HistoryItem[] =\n useLiveQuery(async () => {\n const [historyItems, operations] = await Promise.all([\n historyStorageManager.db.allHistoryByResourceURI(resourceURI),\n historyStorageManager.db.allOperationByResourceURI(resourceURI),\n ]);\n\n const grouped = groupBy<HistoryOperation>(\n operations.map((o) => ({\n id: o.uuid,\n timestamp: o.timestamp,\n type: o.type,\n label: o.label,\n description: o.description,\n value: o.value ? JSON.parse(o.value) : undefined,\n uri: o.uri,\n historyId: o.historyId,\n })),\n 'historyId'\n );\n return historyItems\n .sort((a, b) => (b.id as number) - (a.id as number))\n .map(\n (historyItem) =>\n ({\n id: historyItem.uuid,\n type: historyItem.type,\n timestamp: historyItem.timestamp,\n operations: grouped[historyItem.uuid] || [],\n time: HistoryStack.dateFormat(historyItem.timestamp),\n uri: historyItem.resourceURI,\n } as HistoryItem)\n );\n }, [resourceURI]) || [];\n\n return {\n items,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAoC;;;ACApC,uBAAmC;AACnC,mBAAqC;AACrC,qBAQO;;;ACVP,mBAAkC;AAO3B,IAAM,kBAAN,cAA8B,aAAAA,QAAM;AAAA,EAOzC,YAAY,eAAuB,uBAAuB;AACxD,UAAM,YAAY;AAHpB,gCAA+B;AAI7B,SAAK,QAAQ,CAAC,EAAE,OAAO;AAAA,MACrB,SAAS;AAAA,MACT,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,wBAAwB,aAAqB;AAC3C,WAAO,KAAK,QAAQ,MAAM,EAAE,YAAY,CAAC,EAAE,QAAQ;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,iBAAiB,MAAc;AAC7B,WAAO,KAAK,QAAQ,IAAI,EAAE,KAAK,CAAC;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,0BAA0B,aAAqB;AAC7C,WAAO,KAAK,UAAU,MAAM,EAAE,YAAY,CAAC,EAAE,QAAQ;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,iBAAiB,SAAwB,YAAsC;AAC7E,WAAO,KAAK,YAAY,MAAM,KAAK,SAAS,KAA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AA,QACf,OAAO,EAAE,QAAQ,KAAK,MAAM,EAAE,KAAK,IAAI;AAAA,QACvC,KAAK,EAAE;AAAA,QACP,WAAW,EAAE;AAAA,MACf,EAAE;AAAA,MACF;AAAA,IACF;AACA,WAAO,aACJ,KAAK,CAAC,GAAG,MAAO,EAAE,KAAiB,EAAE,EAAa,EAClD;AAAA,MACC,CAAC,iBACE;AAAA,QACC,IAAI,YAAY;AAAA,QAChB,MAAM,YAAY;AAAA,QAClB,WAAW,YAAY;AAAA,QACvB,YAAY,QAAQ,YAAY,IAAI,KAAK,CAAC;AAAA,QAC1C,MAAM,6BAAa,WAAW,YAAY,SAAS;AAAA,QACnD,KAAK,YAAY;AAAA,MACnB;AAAA,IACJ;AAAA,EACJ,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC;AAExB,SAAO;AAAA,IACL;AAAA,EACF;AACF;","names":["Dexie","uuid","import_inversify","import_history"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flowgram.ai/history-storage",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"exports": {
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"import": "./dist/esm/index.js",
|
|
8
|
+
"require": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/esm/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"dexie": "4.0.4",
|
|
18
|
+
"dexie-react-hooks": "1.1.7",
|
|
19
|
+
"inversify": "^6.0.1",
|
|
20
|
+
"lodash": "^4.17.21",
|
|
21
|
+
"nanoid": "^4.0.2",
|
|
22
|
+
"@flowgram.ai/core": "0.1.0",
|
|
23
|
+
"@flowgram.ai/history": "0.1.0",
|
|
24
|
+
"@flowgram.ai/utils": "0.1.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/lodash": "^4.14.137",
|
|
28
|
+
"@vitest/coverage-v8": "^0.32.0",
|
|
29
|
+
"eslint": "^8.54.0",
|
|
30
|
+
"fake-indexeddb": "5.0.2",
|
|
31
|
+
"jsdom": "^22.1.0",
|
|
32
|
+
"reflect-metadata": "~0.2.2",
|
|
33
|
+
"tsup": "^8.0.1",
|
|
34
|
+
"typescript": "^5.0.4",
|
|
35
|
+
"vitest": "^0.34.6",
|
|
36
|
+
"@flowgram.ai/ts-config": "0.1.0",
|
|
37
|
+
"@flowgram.ai/eslint-config": "0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"registry": "https://registry.npmjs.org/"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "npm run build:fast -- --dts-resolve",
|
|
45
|
+
"build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
|
|
46
|
+
"build:watch": "npm run build:fast -- --dts-resolve",
|
|
47
|
+
"clean": "rimraf dist",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:cov": "vitest run --coverage",
|
|
50
|
+
"test:update": "vitest run --update",
|
|
51
|
+
"ts-check": "tsc --noEmit",
|
|
52
|
+
"watch": "npm run build:fast -- --dts-resolve --watch --ignore-watch dist"
|
|
53
|
+
}
|
|
54
|
+
}
|