@dimina-kit/devtools 0.4.0-dev.20260728110120 → 0.4.0-dev.20260731100034

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.
Files changed (105) hide show
  1. package/README.md +68 -0
  2. package/dist/main/api.d.ts +1 -0
  3. package/dist/main/app/app.d.ts +3 -0
  4. package/dist/main/app/app.js +15 -0
  5. package/dist/main/app/bootstrap.d.ts +8 -5
  6. package/dist/main/app/bootstrap.js +15 -15
  7. package/dist/main/index.bundle.js +2359 -5132
  8. package/dist/main/ipc/app-lifecycle.d.ts +1 -31
  9. package/dist/main/ipc/app-lifecycle.js +1 -53
  10. package/dist/main/ipc/bridge-router.d.ts +19 -152
  11. package/dist/main/ipc/bridge-router.js +28 -2186
  12. package/dist/main/ipc/page-scroll.d.ts +1 -13
  13. package/dist/main/ipc/page-scroll.js +1 -16
  14. package/dist/main/ipc/session-listener-bag.d.ts +1 -40
  15. package/dist/main/ipc/session-listener-bag.js +1 -39
  16. package/dist/main/services/console-forward/index.d.ts +1 -60
  17. package/dist/main/services/console-forward/index.js +1 -225
  18. package/dist/main/services/console-forward/internal-log.d.ts +1 -10
  19. package/dist/main/services/console-forward/internal-log.js +1 -22
  20. package/dist/main/services/diagnostics/index.d.ts +1 -58
  21. package/dist/main/services/diagnostics/index.js +1 -60
  22. package/dist/main/services/dimina-resource-server.d.ts +1 -6
  23. package/dist/main/services/dimina-resource-server.js +1 -98
  24. package/dist/main/services/network-forward/index.d.ts +15 -3
  25. package/dist/main/services/network-forward/index.js +30 -4
  26. package/dist/main/services/network-forward/websocket.d.ts +36 -0
  27. package/dist/main/services/network-forward/websocket.js +120 -0
  28. package/dist/main/services/service-host-pool/pool.d.ts +1 -196
  29. package/dist/main/services/service-host-pool/pool.js +1 -363
  30. package/dist/main/services/simulator/custom-apis.d.ts +1 -42
  31. package/dist/main/services/simulator/custom-apis.js +1 -46
  32. package/dist/main/services/simulator/referer.d.ts +1 -9
  33. package/dist/main/services/simulator/referer.js +1 -19
  34. package/dist/main/services/simulator/ui-extensions.d.ts +13 -0
  35. package/dist/main/services/simulator/ui-extensions.js +166 -0
  36. package/dist/main/services/simulator-storage/service-storage-ops.d.ts +1 -39
  37. package/dist/main/services/simulator-storage/service-storage-ops.js +1 -66
  38. package/dist/main/services/simulator-temp-files/disk.d.ts +1 -54
  39. package/dist/main/services/simulator-temp-files/disk.js +1 -237
  40. package/dist/main/services/simulator-temp-files/fs-channels.d.ts +1 -68
  41. package/dist/main/services/simulator-temp-files/fs-channels.js +1 -107
  42. package/dist/main/services/simulator-temp-files/index.d.ts +1 -32
  43. package/dist/main/services/simulator-temp-files/index.js +1 -181
  44. package/dist/main/services/simulator-temp-files/request-handler.d.ts +1 -29
  45. package/dist/main/services/simulator-temp-files/request-handler.js +1 -177
  46. package/dist/main/services/simulator-temp-files/resolver.d.ts +1 -21
  47. package/dist/main/services/simulator-temp-files/resolver.js +1 -21
  48. package/dist/main/services/simulator-temp-files/store.d.ts +1 -13
  49. package/dist/main/services/simulator-temp-files/store.js +1 -23
  50. package/dist/main/services/views/miniapp-partition.d.ts +1 -89
  51. package/dist/main/services/views/miniapp-partition.js +1 -158
  52. package/dist/main/services/views/native-simulator-view.js +3 -0
  53. package/dist/main/services/views/simulator-session-policy.d.ts +1 -27
  54. package/dist/main/services/views/simulator-session-policy.js +1 -98
  55. package/dist/main/services/views/view-manager.d.ts +5 -0
  56. package/dist/main/services/workbench-context.d.ts +10 -1
  57. package/dist/main/services/workbench-context.js +20 -0
  58. package/dist/main/utils/ipc-registry.d.ts +21 -3
  59. package/dist/main/utils/ipc-registry.js +26 -23
  60. package/dist/main/utils/paths.d.ts +14 -0
  61. package/dist/main/utils/paths.js +14 -0
  62. package/dist/main/windows/service-host-window/create.d.ts +1 -92
  63. package/dist/main/windows/service-host-window/create.js +1 -154
  64. package/dist/native-host/render/render.js +51 -52
  65. package/dist/native-host/service/service.js +2 -2
  66. package/dist/preload/index.d.ts +2 -0
  67. package/dist/preload/index.js +1 -0
  68. package/dist/preload/runtime/clipboard.d.ts +6 -0
  69. package/dist/preload/runtime/clipboard.js +12 -0
  70. package/dist/preload/runtime/native-host.js +4 -10
  71. package/dist/preload/windows/host-toolbar-runtime.cjs.map +2 -2
  72. package/dist/preload/windows/main.cjs +46 -126
  73. package/dist/preload/windows/main.cjs.map +3 -3
  74. package/dist/preload/windows/simulator.cjs +83 -56
  75. package/dist/preload/windows/simulator.cjs.map +4 -4
  76. package/dist/preload/windows/simulator.js +83 -56
  77. package/dist/renderer/assets/{index-BJlFbXHb.js → index-BBg3YI5b.js} +2 -2
  78. package/dist/renderer/entries/main/index.html +1 -1
  79. package/dist/shared/bridge-channels.d.ts +1 -419
  80. package/dist/shared/bridge-channels.js +1 -89
  81. package/dist/shared/dmb-resource-url.d.ts +2 -0
  82. package/dist/shared/dmb-resource-url.js +2 -0
  83. package/dist/shared/ipc-channels.d.ts +2 -32
  84. package/dist/shared/ipc-channels.js +2 -5
  85. package/dist/shared/request-core.d.ts +1 -83
  86. package/dist/shared/request-core.js +1 -167
  87. package/dist/shared/simulator-ui.d.ts +61 -0
  88. package/dist/shared/simulator-ui.js +12 -0
  89. package/dist/shared/types.d.ts +7 -0
  90. package/dist/simulator/assets/device-shell-B03OuytR.js +2 -0
  91. package/dist/simulator/assets/device-shell-DbC5ccs8.css +1 -0
  92. package/dist/simulator/assets/{jsx-runtime-BDTY6fEq.js → jsx-runtime-hBv-rHqQ.js} +2 -2
  93. package/dist/simulator/assets/{simulator-CRyLSz1N.js → simulator-DpdXUf--.js} +5 -5
  94. package/dist/simulator/simulator.html +2 -2
  95. package/dist/simulator/temp-files.d.ts +29 -0
  96. package/dist/simulator/temp-files.js +79 -0
  97. package/dist/simulator/types.d.ts +43 -0
  98. package/dist/simulator/types.js +2 -0
  99. package/package.json +10 -5
  100. package/dist/shared/simulator-api-metadata.d.ts +0 -26
  101. package/dist/shared/simulator-api-metadata.js +0 -59
  102. package/dist/shared/vpath.d.ts +0 -42
  103. package/dist/shared/vpath.js +0 -105
  104. package/dist/simulator/assets/device-shell-DOy53Y0s.css +0 -1
  105. package/dist/simulator/assets/device-shell-Sbkjw8Nb.js +0 -2
@@ -1,182 +1,2 @@
1
- /**
2
- * Wires the `difile://_tmp/*` protocol handler on the simulator session
3
- * and bridges renderer-side `setTempFileSink` callbacks to the main-process
4
- * byte store. Returned disposable clears the store, unregisters the protocol
5
- * handler, and tears down its private IPC channels.
6
- *
7
- * SENDER POLICY: The default workbench sender-policy intentionally rejects
8
- * the simulator `<webview>` (see `utils/sender-policy.ts`). The simulator
9
- * is the only legitimate writer for these channels, so this module installs
10
- * its own narrow policy that accepts a sender only when its WebContents
11
- * belongs to the simulator `Session` we were handed. This bypasses the
12
- * default policy without widening trust to any other source.
13
- *
14
- * WRITE-vs-RENDER RACE: `createTempFilePath` is synchronous on the renderer,
15
- * but the bytes travel here through `blob.arrayBuffer().then(ipcRenderer.send)`
16
- * — async. The simulator can race ahead: in `chooseMedia` the renderer
17
- * assigns `img.src = tempFilePath` (via `readImageMetadata`) immediately
18
- * after `createTempFilePath` returns, which fires a `difile://` GET before
19
- * our IPC write arrives. The protocol handler therefore parks a request on
20
- * a per-url waiter for up to PENDING_TIMEOUT_MS; the IPC `write` handler
21
- * drains the waiter on arrival.
22
- *
23
- * QUOTA: A single in-memory store backs all simulator sessions for the
24
- * lifetime of the WorkbenchApp instance. We cap it at MAX_STORE_ENTRIES
25
- * (FIFO eviction). Project switches do NOT clear the store on their own —
26
- * stale entries from a previous project simply age out as new ones land.
27
- * This is the same eviction shape WeChat uses for tmp files (LRU under a
28
- * size cap), simplified for a dev-tools session scope.
29
- */
30
- import { IpcRegistry } from '../../utils/ipc-registry.js';
31
- import { toDisposable } from '@dimina-kit/electron-deck/main';
32
- import { registerTempFile, revokeTempFile, revokeAllTempFiles } from './store.js';
33
- import { handleDifileRequest } from './request-handler.js';
34
- import { registerMiniappSessionConfigurator } from '../views/miniapp-partition.js';
35
- import { handleFsMkdir, handleFsRead, handleFsReaddir, handleFsStat, handleFsUnlink, handleFsWrite, } from './fs-channels.js';
36
- /** Upper bound for in-memory entries; oldest insertion is evicted (FIFO). */
37
- const MAX_STORE_ENTRIES = 200;
38
- /** Max time the protocol handler waits for an in-flight `write` IPC. */
39
- const PENDING_TIMEOUT_MS = 500;
40
- function enforceStoreCap(store) {
41
- while (store.size > MAX_STORE_ENTRIES) {
42
- const next = store.keys().next();
43
- if (next.done)
44
- break;
45
- store.delete(next.value);
46
- }
47
- }
48
- export function setupSimulatorTempFiles(simSession) {
49
- const store = new Map();
50
- const pendingWaiters = new Map();
51
- let disposed = false;
52
- function drainWaiters(path) {
53
- const list = pendingWaiters.get(path);
54
- if (!list)
55
- return;
56
- pendingWaiters.delete(path);
57
- for (const fn of list)
58
- fn();
59
- }
60
- function drainAllWaiters() {
61
- const lists = Array.from(pendingWaiters.values());
62
- pendingWaiters.clear();
63
- for (const list of lists)
64
- for (const fn of list)
65
- fn();
66
- }
67
- // The protocol handler + IPC channels are shared across every per-project
68
- // miniapp partition session (each project's render/service runs the same
69
- // difile:// + temp-file FSM). The base session is always trusted; additional
70
- // per-project partition sessions register themselves via `installOnSession`.
71
- const trustedSessions = new Set([simSession]);
72
- const simulatorOnlyPolicy = sender => !sender.isDestroyed() && trustedSessions.has(sender.session);
73
- const registry = new IpcRegistry(simulatorOnlyPolicy);
74
- registry.on('simulator:temp-file:write', (_event, payload) => {
75
- if (disposed)
76
- return;
77
- const { path, mime, bytes } = payload;
78
- registerTempFile(store, path, mime, bytes);
79
- enforceStoreCap(store);
80
- drainWaiters(path);
81
- });
82
- registry.on('simulator:temp-file:revoke', (_event, payload) => {
83
- if (disposed)
84
- return;
85
- const { path } = payload;
86
- revokeTempFile(store, path);
87
- });
88
- registry.on('simulator:temp-file:revoke-all', () => {
89
- if (disposed)
90
- return;
91
- revokeAllTempFiles(store);
92
- });
93
- const difileHandler = async (req) => {
94
- const url = req.url;
95
- // Forward any HTTP headers Electron parsed (Range / If-None-Match)
96
- // to the pure dispatcher so it can do its own conditional / range
97
- // shaping.
98
- const headers = {};
99
- try {
100
- req.headers.forEach((v, k) => { headers[k] = v; });
101
- }
102
- catch {
103
- // Older Electron headers shape may not be iterable — best effort.
104
- }
105
- const ctx = { tempStore: store };
106
- let res = await handleDifileRequest(ctx, { url, headers });
107
- // Race waiter: the renderer-side `createTempFilePath` is synchronous
108
- // but its `bytes` IPC arrives later. If we miss a `_tmp/*` lookup,
109
- // park briefly and retry once.
110
- if (res.status === 404
111
- && !disposed
112
- && url.startsWith('difile://_tmp/')) {
113
- await new Promise((resolve) => {
114
- let timer = null;
115
- const notify = () => {
116
- if (timer)
117
- clearTimeout(timer);
118
- resolve();
119
- };
120
- const list = pendingWaiters.get(url) ?? new Set();
121
- list.add(notify);
122
- pendingWaiters.set(url, list);
123
- timer = setTimeout(() => {
124
- const cur = pendingWaiters.get(url);
125
- if (cur) {
126
- cur.delete(notify);
127
- if (cur.size === 0)
128
- pendingWaiters.delete(url);
129
- }
130
- resolve();
131
- }, PENDING_TIMEOUT_MS);
132
- });
133
- res = await handleDifileRequest(ctx, { url, headers });
134
- }
135
- return res;
136
- };
137
- // Install the difile:// protocol handler on a session. Idempotent per
138
- // session: a stale handler from a prior setup (e.g. fast app re-init in
139
- // tests) is replaced rather than throwing. Trusts that session's senders for
140
- // the temp-file / fs IPC channels.
141
- const installedSessions = new Set();
142
- function installOnSession(sess) {
143
- trustedSessions.add(sess);
144
- if (installedSessions.has(sess))
145
- return;
146
- installedSessions.add(sess);
147
- try {
148
- sess.protocol.unhandle('difile');
149
- }
150
- catch {
151
- // Not previously registered — fine.
152
- }
153
- sess.protocol.handle('difile', difileHandler);
154
- }
155
- installOnSession(simSession);
156
- // Apply to every per-project miniapp partition session (current + future).
157
- const unregisterConfigurator = registerMiniappSessionConfigurator((sess) => installOnSession(sess));
158
- // Renderer FSM → main fs operations bridge. The same simulator-only sender
159
- // policy applies — registry instance is shared.
160
- registry.handle('simulator:fs:read', (_event, payload) => handleFsRead(payload));
161
- registry.handle('simulator:fs:write', (_event, payload) => handleFsWrite(payload));
162
- registry.handle('simulator:fs:stat', (_event, payload) => handleFsStat(payload));
163
- registry.handle('simulator:fs:readdir', (_event, payload) => handleFsReaddir(payload));
164
- registry.handle('simulator:fs:unlink', (_event, payload) => handleFsUnlink(payload));
165
- registry.handle('simulator:fs:mkdir', (_event, payload) => handleFsMkdir(payload));
166
- return toDisposable(async () => {
167
- disposed = true;
168
- unregisterConfigurator();
169
- drainAllWaiters();
170
- store.clear();
171
- for (const sess of installedSessions) {
172
- try {
173
- sess.protocol.unhandle('difile');
174
- }
175
- catch {
176
- // May already have been unhandled by app shutdown.
177
- }
178
- }
179
- await registry.dispose();
180
- });
181
- }
1
+ export * from '@dimina-kit/electron-runtime/main/temp-files';
182
2
  //# sourceMappingURL=index.js.map
@@ -1,30 +1,2 @@
1
- /**
2
- * Pure dispatcher for `difile://` URL requests.
3
- *
4
- * Spec: `packages/devtools/docs/file-system.md`.
5
- *
6
- * The shipping implementation in `index.ts` registers a thin
7
- * `simSession.protocol.handle('difile')` wrapper that delegates here; the race
8
- * waiter on `_tmp/*` lives in `index.ts` because it owns the IPC lifecycle.
9
- * For unit tests we assume the bytes are already in the store.
10
- *
11
- * Response shape:
12
- * - 200: full body, with Content-Type, Cache-Control (immutable), ETag
13
- * - 206: range slice, plus Content-Range
14
- * - 304: empty body when `If-None-Match` matches the on-disk ETag. Per RFC
15
- * 9110 §13.1.2 If-None-Match wins over Range.
16
- * - 404: anything `resolveVPath` rejects, plus disk-side ENOENT and any
17
- * other I/O error. The protocol handler in `index.ts` translates this
18
- * into the renderer's network failure surface; we deliberately do not
19
- * leak errno strings.
20
- */
21
- import type { TempFileStore } from './resolver.js';
22
- export interface HandleDifileContext {
23
- tempStore: TempFileStore;
24
- }
25
- export interface HandleDifileRequest {
26
- url: string;
27
- headers?: Record<string, string>;
28
- }
29
- export declare function handleDifileRequest(ctx: HandleDifileContext, req: HandleDifileRequest): Promise<Response>;
1
+ export * from '@dimina-kit/electron-runtime/main/temp-files/request-handler';
30
2
  //# sourceMappingURL=request-handler.d.ts.map
@@ -1,178 +1,2 @@
1
- /**
2
- * Pure dispatcher for `difile://` URL requests.
3
- *
4
- * Spec: `packages/devtools/docs/file-system.md`.
5
- *
6
- * The shipping implementation in `index.ts` registers a thin
7
- * `simSession.protocol.handle('difile')` wrapper that delegates here; the race
8
- * waiter on `_tmp/*` lives in `index.ts` because it owns the IPC lifecycle.
9
- * For unit tests we assume the bytes are already in the store.
10
- *
11
- * Response shape:
12
- * - 200: full body, with Content-Type, Cache-Control (immutable), ETag
13
- * - 206: range slice, plus Content-Range
14
- * - 304: empty body when `If-None-Match` matches the on-disk ETag. Per RFC
15
- * 9110 §13.1.2 If-None-Match wins over Range.
16
- * - 404: anything `resolveVPath` rejects, plus disk-side ENOENT and any
17
- * other I/O error. The protocol handler in `index.ts` translates this
18
- * into the renderer's network failure surface; we deliberately do not
19
- * leak errno strings.
20
- */
21
- import { resolveVPath } from '../../../shared/vpath.js';
22
- import { readDiskFile } from './disk.js';
23
- const CACHE_CONTROL = 'public, max-age=31536000, immutable';
24
- function getHeader(headers, name) {
25
- if (!headers)
26
- return undefined;
27
- const lc = name.toLowerCase();
28
- for (const k of Object.keys(headers)) {
29
- if (k.toLowerCase() === lc)
30
- return headers[k];
31
- }
32
- return undefined;
33
- }
34
- /**
35
- * Weak ETag comparison per RFC 9110 §8.8.3.2: strip the optional `W/` prefix
36
- * from each side before comparing. Both our generated ETags and conditional
37
- * headers may or may not include the weak prefix; the comparison must accept
38
- * `W/"abc"` and `"abc"` as equivalent.
39
- */
40
- function etagsMatch(a, b) {
41
- if (!a)
42
- return false;
43
- const stripped = (s) => (s.startsWith('W/') ? s.slice(2) : s);
44
- return stripped(a.trim()) === stripped(b);
45
- }
46
- /**
47
- * Parse a `Range: bytes=<start>-<end>` header into an inclusive `{start,end}`.
48
- * Returns `null` if absent or malformed (callers should treat that as "no
49
- * range" — a full 200 response, not a 416). `totalSize` clamps the end.
50
- */
51
- function parseRange(header, totalSize) {
52
- if (!header)
53
- return null;
54
- const m = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
55
- if (!m)
56
- return null;
57
- const startStr = m[1];
58
- const endStr = m[2];
59
- if (startStr === '' && endStr === '')
60
- return null;
61
- if (startStr === '') {
62
- // Suffix range: last N bytes.
63
- const n = Number(endStr);
64
- if (!Number.isFinite(n) || n <= 0)
65
- return null;
66
- const start = Math.max(0, totalSize - n);
67
- return { start, end: totalSize - 1 };
68
- }
69
- const start = Number(startStr);
70
- if (!Number.isFinite(start) || start < 0)
71
- return null;
72
- const end = endStr === '' ? totalSize - 1 : Number(endStr);
73
- if (!Number.isFinite(end))
74
- return null;
75
- return { start, end };
76
- }
77
- function notFound() {
78
- return new Response(null, { status: 404 });
79
- }
80
- function notModified(etag) {
81
- return new Response(null, {
82
- status: 304,
83
- headers: {
84
- ETag: etag,
85
- 'Cache-Control': CACHE_CONTROL,
86
- 'Access-Control-Allow-Origin': '*',
87
- },
88
- });
89
- }
90
- function bufferToBody(bytes) {
91
- // Copy into a fresh ArrayBuffer so the result is definitely typed as
92
- // `ArrayBuffer` (not `ArrayBufferLike` / `SharedArrayBuffer`) and is
93
- // safe to hand to Response without aliasing the Node Buffer pool.
94
- const out = new ArrayBuffer(bytes.byteLength);
95
- new Uint8Array(out).set(bytes);
96
- return out;
97
- }
98
- function tempBody(bytes, mime) {
99
- return new Response(bufferToBody(bytes), {
100
- status: 200,
101
- headers: {
102
- 'Content-Type': mime,
103
- 'Cache-Control': CACHE_CONTROL,
104
- 'Access-Control-Allow-Origin': '*',
105
- },
106
- });
107
- }
108
- export async function handleDifileRequest(ctx, req) {
109
- const v = resolveVPath(req.url);
110
- if (!v)
111
- return notFound();
112
- if (v.kind === 'tmp') {
113
- const record = ctx.tempStore.get(req.url);
114
- if (!record)
115
- return notFound();
116
- return tempBody(record.bytes, record.mime || 'application/octet-stream');
117
- }
118
- if (!v.realPath)
119
- return notFound();
120
- // Disk-backed: _store or usr.
121
- try {
122
- // Probe first to learn the ETag/size so If-None-Match can short-circuit
123
- // without reading the body. The probe also doubles as our existence /
124
- // permission check, so anything that throws here (ENOENT, EACCES, ...)
125
- // surfaces as a 404.
126
- const probe = await readDiskFile(v.realPath);
127
- const etag = probe.etag;
128
- const totalSize = probe.totalSize;
129
- const mime = probe.mime;
130
- const ifNoneMatch = getHeader(req.headers, 'If-None-Match');
131
- if (etagsMatch(ifNoneMatch, etag)) {
132
- return notModified(etag);
133
- }
134
- const rangeHeader = getHeader(req.headers, 'Range');
135
- const range = parseRange(rangeHeader, totalSize);
136
- if (range) {
137
- // Range out of bounds → 416 (Range Not Satisfiable) per RFC 9110 §15.4.
138
- // Distinct from 404 so callers can tell "wrong file" from "wrong slice".
139
- if (range.start < 0 || range.start >= totalSize || range.end < range.start) {
140
- return new Response(null, {
141
- status: 416,
142
- headers: {
143
- 'Content-Range': `bytes */${totalSize}`,
144
- 'Access-Control-Allow-Origin': '*',
145
- },
146
- });
147
- }
148
- const clampedEnd = Math.min(range.end, totalSize - 1);
149
- const sliced = await readDiskFile(v.realPath, { range: { start: range.start, end: clampedEnd } });
150
- const { bytes } = sliced;
151
- const lastByte = range.start + bytes.length - 1;
152
- return new Response(bufferToBody(bytes), {
153
- status: 206,
154
- headers: {
155
- 'Content-Type': mime,
156
- 'Content-Length': String(bytes.length),
157
- 'Content-Range': `bytes ${range.start}-${lastByte}/${totalSize}`,
158
- 'Cache-Control': CACHE_CONTROL,
159
- ETag: etag,
160
- 'Access-Control-Allow-Origin': '*',
161
- },
162
- });
163
- }
164
- return new Response(bufferToBody(probe.bytes), {
165
- status: 200,
166
- headers: {
167
- 'Content-Type': mime,
168
- 'Cache-Control': CACHE_CONTROL,
169
- ETag: etag,
170
- 'Access-Control-Allow-Origin': '*',
171
- },
172
- });
173
- }
174
- catch {
175
- return notFound();
176
- }
177
- }
1
+ export * from '@dimina-kit/electron-runtime/main/temp-files/request-handler';
178
2
  //# sourceMappingURL=request-handler.js.map
@@ -1,22 +1,2 @@
1
- /**
2
- * Pure lookup helper backing the main-process `difile://_tmp/*` protocol
3
- * handler. Receives the shared {@link TempFileStore} that the
4
- * `simulator:temp-file:*` IPC channels populate from the renderer.
5
- *
6
- * The full URL (including scheme + host) is used as the Map key — the resolver
7
- * never re-parses or normalises it, so any URL with a wrong scheme or host
8
- * misses regardless of suffix similarity.
9
- */
10
- export interface TempFileRecord {
11
- bytes: Buffer;
12
- mime: string;
13
- }
14
- export type TempFileStore = Map<string, TempFileRecord>;
15
- export declare function resolveTempFile(store: TempFileStore, url: string): {
16
- status: 200;
17
- bytes: Buffer;
18
- mime: string;
19
- } | {
20
- status: 404;
21
- };
1
+ export * from '@dimina-kit/electron-runtime/main/temp-files/resolver';
22
2
  //# sourceMappingURL=resolver.d.ts.map
@@ -1,22 +1,2 @@
1
- /**
2
- * Pure lookup helper backing the main-process `difile://_tmp/*` protocol
3
- * handler. Receives the shared {@link TempFileStore} that the
4
- * `simulator:temp-file:*` IPC channels populate from the renderer.
5
- *
6
- * The full URL (including scheme + host) is used as the Map key — the resolver
7
- * never re-parses or normalises it, so any URL with a wrong scheme or host
8
- * misses regardless of suffix similarity.
9
- */
10
- export function resolveTempFile(store, url) {
11
- if (!url.startsWith('difile://_tmp/'))
12
- return { status: 404 };
13
- const record = store.get(url);
14
- if (!record)
15
- return { status: 404 };
16
- return {
17
- status: 200,
18
- bytes: record.bytes,
19
- mime: record.mime || 'application/octet-stream',
20
- };
21
- }
1
+ export * from '@dimina-kit/electron-runtime/main/temp-files/resolver';
22
2
  //# sourceMappingURL=resolver.js.map
@@ -1,14 +1,2 @@
1
- /**
2
- * Mutators for the shared {@link TempFileStore}. The renderer-side bridge
3
- * forwards every `createTempFilePath` / `registerTempFilePath` /
4
- * `revokeTempFilePath` / `revokeAllTempFilePaths` call over IPC, and these
5
- * helpers translate the payloads into Map writes.
6
- *
7
- * ArrayBuffer inputs are normalised to Buffer at the boundary so the
8
- * resolver hot path can return the bytes directly without re-wrapping.
9
- */
10
- import type { TempFileStore } from './resolver.js';
11
- export declare function registerTempFile(store: TempFileStore, path: string, mime: string, bytes: ArrayBuffer | Buffer): void;
12
- export declare function revokeTempFile(store: TempFileStore, path: string): void;
13
- export declare function revokeAllTempFiles(store: TempFileStore): void;
1
+ export * from '@dimina-kit/electron-runtime/main/temp-files/store';
14
2
  //# sourceMappingURL=store.d.ts.map
@@ -1,24 +1,2 @@
1
- /**
2
- * Mutators for the shared {@link TempFileStore}. The renderer-side bridge
3
- * forwards every `createTempFilePath` / `registerTempFilePath` /
4
- * `revokeTempFilePath` / `revokeAllTempFilePaths` call over IPC, and these
5
- * helpers translate the payloads into Map writes.
6
- *
7
- * ArrayBuffer inputs are normalised to Buffer at the boundary so the
8
- * resolver hot path can return the bytes directly without re-wrapping.
9
- */
10
- export function registerTempFile(store, path, mime, bytes) {
11
- const buf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(new Uint8Array(bytes));
12
- // delete-then-set so an existing entry's insertion order is refreshed.
13
- // Without this, a FIFO cap eviction over `store.keys()` could drop a
14
- // recently re-written path.
15
- store.delete(path);
16
- store.set(path, { bytes: buf, mime });
17
- }
18
- export function revokeTempFile(store, path) {
19
- store.delete(path);
20
- }
21
- export function revokeAllTempFiles(store) {
22
- store.clear();
23
- }
1
+ export * from '@dimina-kit/electron-runtime/main/temp-files/store';
24
2
  //# sourceMappingURL=store.js.map
@@ -1,90 +1,2 @@
1
- /**
2
- * Per-project session partition for the native-host miniapp runtime (P0 debt).
3
- *
4
- * Historically every project's miniapp webContents — the simulator content
5
- * WebContentsView, its nested render-host `<webview>` guests, AND the
6
- * service-host window — shared ONE hard-coded `persist:simulator` Electron
7
- * session. Cookies / localStorage / cache / IndexedDB written by project A were
8
- * visible to (and clobbered by) project B; two projects open at once cross-
9
- * contaminate and "clear storage" on one nukes the other.
10
- *
11
- * The fix derives a STABLE per-project partition from the project identity:
12
- * the miniapp `appId` (which flows in via the simulator URL `?appId=` and the
13
- * spawn path's `appId`) PLUS the project path. appId alone is insufficient —
14
- * it comes from the project manifest, so two DIFFERENT project paths can declare
15
- * the SAME appId and would otherwise share a partition; folding the path in
16
- * isolates them. Same project (same appId + path) → same partition (storage
17
- * survives a relaunch); different projects → different partitions (no cross-
18
- * contamination). The shape mirrors the IDE state of the art (WeChat's static
19
- * partition, ByteDance's `persist:miniapp-<id>` dynamic partition).
20
- *
21
- * The protocol handlers (`difile://`, `dmb-resource`) and webRequest policies
22
- * (referer / CORS) that the simulator runtime needs were installed once on the
23
- * single `persist:simulator` session. With per-project partitions those have to
24
- * be (re)applied to EACH project session the first time it is used. The setup
25
- * sites register a partition-agnostic configurator here; `configureMiniappSession`
26
- * runs every registered configurator exactly once per partition.
27
- *
28
- * Partition CLEANUP (reclaiming on-disk `persist:` data) is intentionally NOT
29
- * done here — leaving the data on disk is the whole point of a `persist:`
30
- * partition (cache/storage survives a relaunch). That is a separate concern.
31
- *
32
- * MIGRATION (intentional one-time reset): folding the project path into the key
33
- * means a project that previously ran on the appId-only `persist:miniapp-<appId>`
34
- * now runs on `persist:miniapp-<appId>-p<hash>` and starts with empty
35
- * cookies/localStorage/cache. Old data is NOT migrated — a best-effort copy
36
- * could carry already-cross-contaminated state into the newly isolated space,
37
- * which defeats the isolation. The reset is accepted as a one-time cost.
38
- */
39
- import type { Session } from 'electron';
40
- /** The legacy single-session partition. Still used by the pre-warm pool (which
41
- * is intentionally NOT isolation-aware — see `serviceHostSpec`) and as the
42
- * fallback when a project key cannot be derived. */
43
- export declare const SHARED_MINIAPP_PARTITION = "persist:simulator";
44
- /**
45
- * Derive a stable, filesystem-safe partition key from a project `appId`.
46
- *
47
- * `appId` is the project identity (e.g. a `wxapp…` id). We pass through the
48
- * characters Electron is happy to put in a session partition / on-disk folder
49
- * name (`[A-Za-z0-9_-]`) verbatim so the common case is human-legible, and fold
50
- * anything else into a short deterministic hash suffix so two appIds that differ
51
- * only in stripped characters never collide. The same `appId` always yields the
52
- * same key (so storage survives a relaunch); different `appId`s yield different
53
- * keys.
54
- */
55
- export declare function miniappPartitionKey(appId: string, projectPath?: string | null): string;
56
- /**
57
- * The Electron session partition for a project. Returns the SHARED partition
58
- * when `appId` is empty/unknown (so the runtime still has a session to load on,
59
- * matching the legacy behavior) and a `persist:miniapp-<key>` partition
60
- * otherwise.
61
- */
62
- export declare function miniappPartition(appId: string | null | undefined, projectPath?: string | null): string;
63
- type SessionConfigurator = (sess: Session, partition: string) => void;
64
- /**
65
- * Register a configurator that runs against every miniapp partition session.
66
- * Already-configured partitions are (re)configured immediately so registration
67
- * order does not matter. Returns a disposer that unregisters the configurator
68
- * (it does not undo work already applied to live sessions).
69
- */
70
- export declare function registerMiniappSessionConfigurator(fn: SessionConfigurator): () => void;
71
- /**
72
- * Ensure a partition's session has every registered configurator applied. Safe
73
- * to call repeatedly per partition (idempotent — each partition is configured
74
- * once). Call this before loading project content on `partition`.
75
- *
76
- * Returns `null` when there is nothing to configure (no configurator registered)
77
- * so the partition derivation stays independent of any live Electron session —
78
- * the partition is a constructor-time fact, not a side effect of touching the
79
- * session API. Setup sites register configurators at app boot; in unit tests
80
- * that mock `electron` without a `session` export this short-circuits cleanly.
81
- */
82
- export declare function configureMiniappSession(partition: string): Session | null;
83
- /**
84
- * Test-only: drop the configurator + configured-partition bookkeeping so each
85
- * test starts from a clean slate. (Module-level state otherwise leaks across
86
- * unit tests that mock `electron`.)
87
- */
88
- export declare function __resetMiniappSessionConfigForTests(): void;
89
- export {};
1
+ export * from '@dimina-kit/electron-runtime/main/miniapp-partition';
90
2
  //# sourceMappingURL=miniapp-partition.d.ts.map