@lvce-editor/api 9.35.2 → 9.35.3

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.
@@ -1,22 +1,21 @@
1
- const databasePrefix = 'lvce-editor-extension-output';
1
+ const databaseName = 'lvce-output-channels';
2
2
  const databaseVersion = 1;
3
3
  const objectStoreName = 'chunks';
4
- const channelIdIndexName = 'channelId';
4
+ const extensionPathChannelIdIndexName = 'extensionPath-channelId';
5
5
  let databasePromise;
6
- const getDatabaseName = () => {
7
- const extensionPath = typeof location === 'undefined' ? 'test' : location.pathname;
8
- return `${databasePrefix}:${extensionPath}`;
6
+ const getExtensionPath = () => {
7
+ return typeof location === 'undefined' ? 'test' : location.pathname;
9
8
  };
10
9
  const openDatabase = () => {
11
10
  return new Promise((resolve, reject) => {
12
- const request = indexedDB.open(getDatabaseName(), databaseVersion);
11
+ const request = indexedDB.open(databaseName, databaseVersion);
13
12
  request.onerror = () => reject(request.error);
14
13
  request.onupgradeneeded = () => {
15
14
  const database = request.result;
16
15
  const objectStore = database.createObjectStore(objectStoreName, {
17
16
  autoIncrement: true,
18
17
  });
19
- objectStore.createIndex(channelIdIndexName, 'channelId');
18
+ objectStore.createIndex(extensionPathChannelIdIndexName, ['extensionPath', 'channelId']);
20
19
  };
21
20
  request.onsuccess = () => resolve(request.result);
22
21
  });
@@ -32,9 +31,9 @@ const waitForTransaction = (transaction) => {
32
31
  transaction.oncomplete = () => resolve();
33
32
  });
34
33
  };
35
- const deleteChannelChunks = (objectStore, channelId, onComplete = () => { }) => {
36
- const index = objectStore.index(channelIdIndexName);
37
- const request = index.openKeyCursor(IDBKeyRange.only(channelId));
34
+ const deleteChannelChunks = (objectStore, extensionPath, channelId, onComplete = () => { }) => {
35
+ const index = objectStore.index(extensionPathChannelIdIndexName);
36
+ const request = index.openKeyCursor(IDBKeyRange.only([extensionPath, channelId]));
38
37
  request.onsuccess = () => {
39
38
  const cursor = request.result;
40
39
  if (!cursor) {
@@ -48,19 +47,24 @@ const deleteChannelChunks = (objectStore, channelId, onComplete = () => { }) =>
48
47
  export const append = async (channelId, text) => {
49
48
  const database = await getDatabase();
50
49
  const transaction = database.transaction(objectStoreName, 'readwrite');
51
- transaction.objectStore(objectStoreName).add({ channelId, text });
50
+ const extensionPath = getExtensionPath();
51
+ transaction.objectStore(objectStoreName).add({ channelId, extensionPath, text });
52
52
  await waitForTransaction(transaction);
53
53
  };
54
54
  export const clear = async (channelId) => {
55
55
  const database = await getDatabase();
56
56
  const transaction = database.transaction(objectStoreName, 'readwrite');
57
- deleteChannelChunks(transaction.objectStore(objectStoreName), channelId);
57
+ deleteChannelChunks(transaction.objectStore(objectStoreName), getExtensionPath(), channelId);
58
58
  await waitForTransaction(transaction);
59
59
  };
60
60
  export const getLogs = async (channelId) => {
61
61
  const database = await getDatabase();
62
62
  const transaction = database.transaction(objectStoreName, 'readonly');
63
- const request = transaction.objectStore(objectStoreName).index(channelIdIndexName).getAll(IDBKeyRange.only(channelId));
63
+ const extensionPath = getExtensionPath();
64
+ const request = transaction
65
+ .objectStore(objectStoreName)
66
+ .index(extensionPathChannelIdIndexName)
67
+ .getAll(IDBKeyRange.only([extensionPath, channelId]));
64
68
  const chunks = await new Promise((resolve, reject) => {
65
69
  request.onerror = () => reject(request.error);
66
70
  request.onsuccess = () => resolve(request.result);
@@ -72,8 +76,9 @@ export const replace = async (channelId, text) => {
72
76
  const database = await getDatabase();
73
77
  const transaction = database.transaction(objectStoreName, 'readwrite');
74
78
  const objectStore = transaction.objectStore(objectStoreName);
75
- deleteChannelChunks(objectStore, channelId, () => {
76
- objectStore.add({ channelId, text });
79
+ const extensionPath = getExtensionPath();
80
+ deleteChannelChunks(objectStore, extensionPath, channelId, () => {
81
+ objectStore.add({ channelId, extensionPath, text });
77
82
  });
78
83
  await waitForTransaction(transaction);
79
84
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/api",
3
- "version": "9.35.2",
3
+ "version": "9.35.3",
4
4
  "description": "Tree-shakeable extension API for Lvce Editor extensions.",
5
5
  "keywords": [
6
6
  "lvce-editor",