bb-relay 0.0.24 → 0.0.25
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/api.d.mts +3 -53
- package/dist/api.d.ts +3 -53
- package/dist/editor.d.mts +2 -2
- package/dist/editor.d.ts +2 -2
- package/dist/{FolderStat-CC_Sg9M2.d.mts → fetch-BFabLq7k.d.mts} +19 -1
- package/dist/{FolderStat-CC_Sg9M2.d.ts → fetch-BFabLq7k.d.ts} +19 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +0 -60
- package/dist/index.mjs +0 -60
- package/package.json +1 -1
- package/src/editor.ts +2 -0
- package/src/relay/index.ts +0 -2
- package/src/types/api/BBRequest.ts +3 -3
- package/src/types/editor/WatchFSEvent.ts +1 -1
- package/src/types/requests/fetch.ts +15 -0
- package/src/types/requests/file/index.ts +1 -1
- package/src/relay/storage-bridge.ts +0 -71
- package/src/types/requests/storage.ts +0 -34
package/dist/api.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as FileContent, b as FileStat, C as CopyArg, F as FolderContent, c as FolderStat, G as GitFileStatus } from './
|
|
1
|
+
import { a as FileContent, b as FileStat, C as CopyArg, F as FolderContent, c as FolderStat, G as GitFileStatus, d as FetchRequest } from './fetch-BFabLq7k.mjs';
|
|
2
2
|
import { P as Project } from './Project-B7IjpqOJ.mjs';
|
|
3
3
|
import { C as Commit } from './Commit-PdsjrKSG.mjs';
|
|
4
4
|
import './PROJECT_CATEGORY-BivLHtB6.mjs';
|
|
@@ -86,7 +86,7 @@ type FileRequests = {
|
|
|
86
86
|
arg: {
|
|
87
87
|
glob?: string;
|
|
88
88
|
path?: string;
|
|
89
|
-
};
|
|
89
|
+
} | null;
|
|
90
90
|
response: string[];
|
|
91
91
|
};
|
|
92
92
|
"file:stat": {
|
|
@@ -144,56 +144,6 @@ type FolderRequest = {
|
|
|
144
144
|
};
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
type StorageRequests = {
|
|
148
|
-
"storage:set-item": {
|
|
149
|
-
arg: {
|
|
150
|
-
key: string;
|
|
151
|
-
value: string;
|
|
152
|
-
};
|
|
153
|
-
response: null;
|
|
154
|
-
};
|
|
155
|
-
"storage:get-item": {
|
|
156
|
-
arg: {
|
|
157
|
-
key: string;
|
|
158
|
-
};
|
|
159
|
-
response: string;
|
|
160
|
-
};
|
|
161
|
-
"storage:remove-item": {
|
|
162
|
-
arg: {
|
|
163
|
-
key: string;
|
|
164
|
-
};
|
|
165
|
-
response: null;
|
|
166
|
-
};
|
|
167
|
-
"storage:clear": {
|
|
168
|
-
arg: null;
|
|
169
|
-
response: null;
|
|
170
|
-
};
|
|
171
|
-
"storage:key": {
|
|
172
|
-
arg: {
|
|
173
|
-
index: number;
|
|
174
|
-
};
|
|
175
|
-
response: string[];
|
|
176
|
-
};
|
|
177
|
-
"storage:length": {
|
|
178
|
-
arg: null;
|
|
179
|
-
response: string[];
|
|
180
|
-
};
|
|
181
|
-
"storage:sync": {
|
|
182
|
-
arg: {
|
|
183
|
-
[key: string]: string;
|
|
184
|
-
};
|
|
185
|
-
response: {
|
|
186
|
-
[key: string]: string;
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
"storage:load": {
|
|
190
|
-
arg: null;
|
|
191
|
-
response: {
|
|
192
|
-
[key: string]: string;
|
|
193
|
-
};
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
|
|
197
147
|
type ProjectRequest = {
|
|
198
148
|
"project:update": {
|
|
199
149
|
arg: Project["update"];
|
|
@@ -318,7 +268,7 @@ type GitRequests = {
|
|
|
318
268
|
};
|
|
319
269
|
};
|
|
320
270
|
|
|
321
|
-
type BBRequest = FileRequests & FolderRequest &
|
|
271
|
+
type BBRequest = FileRequests & FolderRequest & ProjectRequest & AppRequest & GitRequests & FetchRequest;
|
|
322
272
|
|
|
323
273
|
type EventParam<K extends keyof BBEvent> = {
|
|
324
274
|
id: string;
|
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as FileContent, b as FileStat, C as CopyArg, F as FolderContent, c as FolderStat, G as GitFileStatus } from './
|
|
1
|
+
import { a as FileContent, b as FileStat, C as CopyArg, F as FolderContent, c as FolderStat, G as GitFileStatus, d as FetchRequest } from './fetch-BFabLq7k.js';
|
|
2
2
|
import { P as Project } from './Project-B_Vppjgw.js';
|
|
3
3
|
import { C as Commit } from './Commit-PdsjrKSG.js';
|
|
4
4
|
import './PROJECT_CATEGORY-BivLHtB6.js';
|
|
@@ -86,7 +86,7 @@ type FileRequests = {
|
|
|
86
86
|
arg: {
|
|
87
87
|
glob?: string;
|
|
88
88
|
path?: string;
|
|
89
|
-
};
|
|
89
|
+
} | null;
|
|
90
90
|
response: string[];
|
|
91
91
|
};
|
|
92
92
|
"file:stat": {
|
|
@@ -144,56 +144,6 @@ type FolderRequest = {
|
|
|
144
144
|
};
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
type StorageRequests = {
|
|
148
|
-
"storage:set-item": {
|
|
149
|
-
arg: {
|
|
150
|
-
key: string;
|
|
151
|
-
value: string;
|
|
152
|
-
};
|
|
153
|
-
response: null;
|
|
154
|
-
};
|
|
155
|
-
"storage:get-item": {
|
|
156
|
-
arg: {
|
|
157
|
-
key: string;
|
|
158
|
-
};
|
|
159
|
-
response: string;
|
|
160
|
-
};
|
|
161
|
-
"storage:remove-item": {
|
|
162
|
-
arg: {
|
|
163
|
-
key: string;
|
|
164
|
-
};
|
|
165
|
-
response: null;
|
|
166
|
-
};
|
|
167
|
-
"storage:clear": {
|
|
168
|
-
arg: null;
|
|
169
|
-
response: null;
|
|
170
|
-
};
|
|
171
|
-
"storage:key": {
|
|
172
|
-
arg: {
|
|
173
|
-
index: number;
|
|
174
|
-
};
|
|
175
|
-
response: string[];
|
|
176
|
-
};
|
|
177
|
-
"storage:length": {
|
|
178
|
-
arg: null;
|
|
179
|
-
response: string[];
|
|
180
|
-
};
|
|
181
|
-
"storage:sync": {
|
|
182
|
-
arg: {
|
|
183
|
-
[key: string]: string;
|
|
184
|
-
};
|
|
185
|
-
response: {
|
|
186
|
-
[key: string]: string;
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
"storage:load": {
|
|
190
|
-
arg: null;
|
|
191
|
-
response: {
|
|
192
|
-
[key: string]: string;
|
|
193
|
-
};
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
|
|
197
147
|
type ProjectRequest = {
|
|
198
148
|
"project:update": {
|
|
199
149
|
arg: Project["update"];
|
|
@@ -318,7 +268,7 @@ type GitRequests = {
|
|
|
318
268
|
};
|
|
319
269
|
};
|
|
320
270
|
|
|
321
|
-
type BBRequest = FileRequests & FolderRequest &
|
|
271
|
+
type BBRequest = FileRequests & FolderRequest & ProjectRequest & AppRequest & GitRequests & FetchRequest;
|
|
322
272
|
|
|
323
273
|
type EventParam<K extends keyof BBEvent> = {
|
|
324
274
|
id: string;
|
package/dist/editor.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { C as Commit } from './Commit-PdsjrKSG.mjs';
|
|
2
|
-
export { C as CopyArg, a as FileContent, b as FileStat, F as FolderContent, c as FolderStat, G as GitFileStatus } from './
|
|
2
|
+
export { C as CopyArg, a as FileContent, b as FileStat, F as FolderContent, c as FolderStat, G as GitFileStatus, I as IPCResponse } from './fetch-BFabLq7k.mjs';
|
|
3
3
|
import { L as Language, a as Locale } from './Locale-WvQQn-Rm.mjs';
|
|
4
4
|
export { R as Result } from './Result-BLbZLEgX.mjs';
|
|
5
5
|
|
|
@@ -38,6 +38,6 @@ interface TutorialHeader {
|
|
|
38
38
|
body: string;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
type WatchFSEvent = "updated" | "deleted";
|
|
41
|
+
type WatchFSEvent = "updated" | "deleted" | "updated" | "add";
|
|
42
42
|
|
|
43
43
|
export type { IconArg, MenuContent, Nav, Route, Settings, TutorialHeader, WatchFSEvent };
|
package/dist/editor.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { C as Commit } from './Commit-PdsjrKSG.js';
|
|
2
|
-
export { C as CopyArg, a as FileContent, b as FileStat, F as FolderContent, c as FolderStat, G as GitFileStatus } from './
|
|
2
|
+
export { C as CopyArg, a as FileContent, b as FileStat, F as FolderContent, c as FolderStat, G as GitFileStatus, I as IPCResponse } from './fetch-BFabLq7k.js';
|
|
3
3
|
import { L as Language, a as Locale } from './Locale-WvQQn-Rm.js';
|
|
4
4
|
export { R as Result } from './Result-BLbZLEgX.js';
|
|
5
5
|
|
|
@@ -38,6 +38,6 @@ interface TutorialHeader {
|
|
|
38
38
|
body: string;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
type WatchFSEvent = "updated" | "deleted";
|
|
41
|
+
type WatchFSEvent = "updated" | "deleted" | "updated" | "add";
|
|
42
42
|
|
|
43
43
|
export type { IconArg, MenuContent, Nav, Route, Settings, TutorialHeader, WatchFSEvent };
|
|
@@ -37,4 +37,22 @@ type FolderStat = {
|
|
|
37
37
|
folderCount: number;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
type IPCResponse<T = unknown> = {
|
|
41
|
+
ok: boolean;
|
|
42
|
+
status: number;
|
|
43
|
+
statusText: string;
|
|
44
|
+
url: string;
|
|
45
|
+
headers: Record<string, string>;
|
|
46
|
+
data: T | string;
|
|
47
|
+
};
|
|
48
|
+
type FetchRequest = {
|
|
49
|
+
fetch: {
|
|
50
|
+
arg: {
|
|
51
|
+
input: string | URL | Request;
|
|
52
|
+
init?: RequestInit;
|
|
53
|
+
};
|
|
54
|
+
response: IPCResponse;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type { CopyArg as C, FolderContent as F, GitFileStatus as G, IPCResponse as I, FileContent as a, FileStat as b, FolderStat as c, FetchRequest as d };
|
|
@@ -37,4 +37,22 @@ type FolderStat = {
|
|
|
37
37
|
folderCount: number;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
type IPCResponse<T = unknown> = {
|
|
41
|
+
ok: boolean;
|
|
42
|
+
status: number;
|
|
43
|
+
statusText: string;
|
|
44
|
+
url: string;
|
|
45
|
+
headers: Record<string, string>;
|
|
46
|
+
data: T | string;
|
|
47
|
+
};
|
|
48
|
+
type FetchRequest = {
|
|
49
|
+
fetch: {
|
|
50
|
+
arg: {
|
|
51
|
+
input: string | URL | Request;
|
|
52
|
+
init?: RequestInit;
|
|
53
|
+
};
|
|
54
|
+
response: IPCResponse;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type { CopyArg as C, FolderContent as F, GitFileStatus as G, IPCResponse as I, FileContent as a, FileStat as b, FolderStat as c, FetchRequest as d };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BBRequest, RequestReturn, BBEvent, EventReturn, EventParam, RequestParam } from './api.mjs';
|
|
2
|
-
import { a as FileContent } from './
|
|
2
|
+
import { a as FileContent } from './fetch-BFabLq7k.mjs';
|
|
3
3
|
export { R as Result } from './Result-BLbZLEgX.mjs';
|
|
4
4
|
import { P as Plugin } from './Plugin-BMoQ48uq.mjs';
|
|
5
5
|
import './Project-B7IjpqOJ.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BBRequest, RequestReturn, BBEvent, EventReturn, EventParam, RequestParam } from './api.js';
|
|
2
|
-
import { a as FileContent } from './
|
|
2
|
+
import { a as FileContent } from './fetch-BFabLq7k.js';
|
|
3
3
|
export { R as Result } from './Result-BLbZLEgX.js';
|
|
4
4
|
import { P as Plugin } from './Plugin-BojCB5ZJ.js';
|
|
5
5
|
import './Project-B_Vppjgw.js';
|
package/dist/index.js
CHANGED
|
@@ -5,65 +5,6 @@ function registerRequest(request) {
|
|
|
5
5
|
window.parent.postMessage(request, "*");
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
// src/relay/storage-bridge.ts
|
|
9
|
-
function storageBridge() {
|
|
10
|
-
let loaded = false;
|
|
11
|
-
const proto = Storage.prototype;
|
|
12
|
-
const _setItem = proto.setItem;
|
|
13
|
-
const _removeItem = proto.removeItem;
|
|
14
|
-
const _clear = proto.clear;
|
|
15
|
-
function snapshot(storage) {
|
|
16
|
-
const obj = {};
|
|
17
|
-
for (let i = 0; i < storage.length; i++) {
|
|
18
|
-
const key = storage.key(i);
|
|
19
|
-
if (key !== null) {
|
|
20
|
-
obj[key] = storage.getItem(key);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return obj;
|
|
24
|
-
}
|
|
25
|
-
function notify() {
|
|
26
|
-
registerRequest({
|
|
27
|
-
type: "storage:sync",
|
|
28
|
-
id: crypto.randomUUID(),
|
|
29
|
-
arg: snapshot(localStorage),
|
|
30
|
-
source: "request"
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
proto.setItem = function(key, value) {
|
|
34
|
-
const result = _setItem.apply(this, [key, value]);
|
|
35
|
-
notify();
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
proto.removeItem = function(key) {
|
|
39
|
-
const result = _removeItem.apply(this, [key]);
|
|
40
|
-
notify();
|
|
41
|
-
return result;
|
|
42
|
-
};
|
|
43
|
-
proto.clear = function() {
|
|
44
|
-
const result = _clear.apply(this);
|
|
45
|
-
notify();
|
|
46
|
-
return result;
|
|
47
|
-
};
|
|
48
|
-
registerRequest({
|
|
49
|
-
type: "storage:load",
|
|
50
|
-
id: crypto.randomUUID(),
|
|
51
|
-
arg: null,
|
|
52
|
-
source: "request"
|
|
53
|
-
});
|
|
54
|
-
window.addEventListener("message", (event) => {
|
|
55
|
-
const data = event.data;
|
|
56
|
-
if (data.type === "storage:load") {
|
|
57
|
-
if (!loaded && data.response) {
|
|
58
|
-
loaded = true;
|
|
59
|
-
for (const key in data.response) {
|
|
60
|
-
localStorage.setItem(key, data.response[key]);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
8
|
// src/relay/registerEvent.ts
|
|
68
9
|
function registerEvent(event) {
|
|
69
10
|
if (!window) throw new Error("Window not found");
|
|
@@ -77,7 +18,6 @@ var BBRelay = class {
|
|
|
77
18
|
this.requestCallbacks = /* @__PURE__ */ new Map();
|
|
78
19
|
this.eventCallbacks = /* @__PURE__ */ new Map();
|
|
79
20
|
this.responseIds = [];
|
|
80
|
-
storageBridge();
|
|
81
21
|
window.addEventListener("message", (event) => {
|
|
82
22
|
const data = event.data;
|
|
83
23
|
if (!_optionalChain([data, 'optionalAccess', _ => _.type])) return;
|
package/dist/index.mjs
CHANGED
|
@@ -5,65 +5,6 @@ function registerRequest(request) {
|
|
|
5
5
|
window.parent.postMessage(request, "*");
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
// src/relay/storage-bridge.ts
|
|
9
|
-
function storageBridge() {
|
|
10
|
-
let loaded = false;
|
|
11
|
-
const proto = Storage.prototype;
|
|
12
|
-
const _setItem = proto.setItem;
|
|
13
|
-
const _removeItem = proto.removeItem;
|
|
14
|
-
const _clear = proto.clear;
|
|
15
|
-
function snapshot(storage) {
|
|
16
|
-
const obj = {};
|
|
17
|
-
for (let i = 0; i < storage.length; i++) {
|
|
18
|
-
const key = storage.key(i);
|
|
19
|
-
if (key !== null) {
|
|
20
|
-
obj[key] = storage.getItem(key);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return obj;
|
|
24
|
-
}
|
|
25
|
-
function notify() {
|
|
26
|
-
registerRequest({
|
|
27
|
-
type: "storage:sync",
|
|
28
|
-
id: crypto.randomUUID(),
|
|
29
|
-
arg: snapshot(localStorage),
|
|
30
|
-
source: "request"
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
proto.setItem = function(key, value) {
|
|
34
|
-
const result = _setItem.apply(this, [key, value]);
|
|
35
|
-
notify();
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
proto.removeItem = function(key) {
|
|
39
|
-
const result = _removeItem.apply(this, [key]);
|
|
40
|
-
notify();
|
|
41
|
-
return result;
|
|
42
|
-
};
|
|
43
|
-
proto.clear = function() {
|
|
44
|
-
const result = _clear.apply(this);
|
|
45
|
-
notify();
|
|
46
|
-
return result;
|
|
47
|
-
};
|
|
48
|
-
registerRequest({
|
|
49
|
-
type: "storage:load",
|
|
50
|
-
id: crypto.randomUUID(),
|
|
51
|
-
arg: null,
|
|
52
|
-
source: "request"
|
|
53
|
-
});
|
|
54
|
-
window.addEventListener("message", (event) => {
|
|
55
|
-
const data = event.data;
|
|
56
|
-
if (data.type === "storage:load") {
|
|
57
|
-
if (!loaded && data.response) {
|
|
58
|
-
loaded = true;
|
|
59
|
-
for (const key in data.response) {
|
|
60
|
-
localStorage.setItem(key, data.response[key]);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
8
|
// src/relay/registerEvent.ts
|
|
68
9
|
function registerEvent(event) {
|
|
69
10
|
if (!window) throw new Error("Window not found");
|
|
@@ -77,7 +18,6 @@ var BBRelay = class {
|
|
|
77
18
|
this.requestCallbacks = /* @__PURE__ */ new Map();
|
|
78
19
|
this.eventCallbacks = /* @__PURE__ */ new Map();
|
|
79
20
|
this.responseIds = [];
|
|
80
|
-
storageBridge();
|
|
81
21
|
window.addEventListener("message", (event) => {
|
|
82
22
|
const data = event.data;
|
|
83
23
|
if (!data?.type) return;
|
package/package.json
CHANGED
package/src/editor.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { WatchFSEvent } from "./types/editor/WatchFSEvent";
|
|
|
13
13
|
import FileStat from "./types/requests/file/FileStat";
|
|
14
14
|
import Result from "./types/editor/Result";
|
|
15
15
|
import { FolderStat } from "./types/requests/folder/FolderStat";
|
|
16
|
+
import { IPCResponse } from "./types/requests/fetch";
|
|
16
17
|
|
|
17
18
|
export type {
|
|
18
19
|
Commit,
|
|
@@ -30,4 +31,5 @@ export type {
|
|
|
30
31
|
FileStat,
|
|
31
32
|
FolderStat,
|
|
32
33
|
Result,
|
|
34
|
+
IPCResponse,
|
|
33
35
|
};
|
package/src/relay/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import registerRequest from "./registerRequest";
|
|
2
2
|
import BBRequest from "../types/api/BBRequest";
|
|
3
|
-
import storageBridge from "./storage-bridge";
|
|
4
3
|
import RequestReturn from "../types/api/RequestReturn";
|
|
5
4
|
import BBEvent from "../types/api/BBEvent";
|
|
6
5
|
import EventReturn from "../types/api/EventReturn";
|
|
@@ -32,7 +31,6 @@ export default class BBRelay {
|
|
|
32
31
|
private responseIds: string[] = [];
|
|
33
32
|
|
|
34
33
|
constructor() {
|
|
35
|
-
storageBridge();
|
|
36
34
|
window.addEventListener("message", (event: MessageEvent) => {
|
|
37
35
|
const data = event.data as RequestReturn<any> | EventReturn<any>;
|
|
38
36
|
if (!data?.type) return;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { FileRequests } from "../requests/file";
|
|
2
2
|
import { FolderRequest } from "../requests/folder";
|
|
3
|
-
import { StorageRequests } from "../requests/storage";
|
|
4
3
|
import ProjectRequest from "../requests/project";
|
|
5
4
|
import { AppRequest } from "../requests/app";
|
|
6
5
|
import { GitRequests } from "../requests/git";
|
|
6
|
+
import { FetchRequest } from "../requests/fetch";
|
|
7
7
|
|
|
8
8
|
type BBRequest = FileRequests &
|
|
9
9
|
FolderRequest &
|
|
10
|
-
StorageRequests &
|
|
11
10
|
ProjectRequest &
|
|
12
11
|
AppRequest &
|
|
13
|
-
GitRequests
|
|
12
|
+
GitRequests &
|
|
13
|
+
FetchRequest;
|
|
14
14
|
|
|
15
15
|
export default BBRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type WatchFSEvent = "updated" | "deleted"
|
|
1
|
+
export type WatchFSEvent = "updated" | "deleted" | "updated" | "add";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type IPCResponse<T = unknown> = {
|
|
2
|
+
ok: boolean;
|
|
3
|
+
status: number;
|
|
4
|
+
statusText: string;
|
|
5
|
+
url: string;
|
|
6
|
+
headers: Record<string, string>;
|
|
7
|
+
data: T | string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type FetchRequest = {
|
|
11
|
+
fetch: {
|
|
12
|
+
arg: { input: string | URL | Request; init?: RequestInit };
|
|
13
|
+
response: IPCResponse;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import registerRequest from "./registerRequest";
|
|
2
|
-
import RequestReturn from "../types/api/RequestReturn";
|
|
3
|
-
|
|
4
|
-
export default function storageBridge() {
|
|
5
|
-
let loaded = false;
|
|
6
|
-
const proto = Storage.prototype;
|
|
7
|
-
|
|
8
|
-
// Keep original references
|
|
9
|
-
const _setItem = proto.setItem;
|
|
10
|
-
const _removeItem = proto.removeItem;
|
|
11
|
-
const _clear = proto.clear;
|
|
12
|
-
|
|
13
|
-
function snapshot(storage: Storage) {
|
|
14
|
-
const obj: Record<string, string> = {};
|
|
15
|
-
for (let i = 0; i < storage.length; i++) {
|
|
16
|
-
const key = storage.key(i);
|
|
17
|
-
if (key !== null) {
|
|
18
|
-
obj[key] = storage.getItem(key)!;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return obj;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function notify() {
|
|
25
|
-
registerRequest({
|
|
26
|
-
type: "storage:sync",
|
|
27
|
-
id: crypto.randomUUID(),
|
|
28
|
-
arg: snapshot(localStorage),
|
|
29
|
-
source: "request",
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Patch setItem
|
|
34
|
-
proto.setItem = function (key: string, value: string): void {
|
|
35
|
-
const result = _setItem.apply(this, [key, value]);
|
|
36
|
-
notify();
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// Patch removeItem
|
|
41
|
-
proto.removeItem = function (key: string): void {
|
|
42
|
-
const result = _removeItem.apply(this, [key]);
|
|
43
|
-
notify();
|
|
44
|
-
return result;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// Patch clear
|
|
48
|
-
proto.clear = function (): void {
|
|
49
|
-
const result = _clear.apply(this);
|
|
50
|
-
notify();
|
|
51
|
-
return result;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
registerRequest({
|
|
55
|
-
type: "storage:load",
|
|
56
|
-
id: crypto.randomUUID(),
|
|
57
|
-
arg: null,
|
|
58
|
-
source: "request",
|
|
59
|
-
});
|
|
60
|
-
window.addEventListener("message", (event) => {
|
|
61
|
-
const data = event.data as RequestReturn<"storage:load">;
|
|
62
|
-
if (data.type === "storage:load") {
|
|
63
|
-
if (!loaded && data.response) {
|
|
64
|
-
loaded = true;
|
|
65
|
-
for (const key in data.response) {
|
|
66
|
-
localStorage.setItem(key, data.response[key]);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export type StorageRequests = {
|
|
2
|
-
"storage:set-item": {
|
|
3
|
-
arg: { key: string; value: string };
|
|
4
|
-
response: null;
|
|
5
|
-
};
|
|
6
|
-
"storage:get-item": {
|
|
7
|
-
arg: { key: string };
|
|
8
|
-
response: string;
|
|
9
|
-
};
|
|
10
|
-
"storage:remove-item": {
|
|
11
|
-
arg: { key: string };
|
|
12
|
-
response: null;
|
|
13
|
-
};
|
|
14
|
-
"storage:clear": {
|
|
15
|
-
arg: null;
|
|
16
|
-
response: null;
|
|
17
|
-
};
|
|
18
|
-
"storage:key": {
|
|
19
|
-
arg: { index: number };
|
|
20
|
-
response: string[];
|
|
21
|
-
};
|
|
22
|
-
"storage:length": {
|
|
23
|
-
arg: null;
|
|
24
|
-
response: string[];
|
|
25
|
-
};
|
|
26
|
-
"storage:sync": {
|
|
27
|
-
arg: { [key: string]: string };
|
|
28
|
-
response: { [key: string]: string };
|
|
29
|
-
};
|
|
30
|
-
"storage:load": {
|
|
31
|
-
arg: null;
|
|
32
|
-
response: { [key: string]: string };
|
|
33
|
-
};
|
|
34
|
-
};
|