@krate/app 0.0.0-stage → 0.5.0-rc.10

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 (132) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +88 -2
  3. package/dist/automation.d.ts +11 -0
  4. package/dist/automation.d.ts.map +1 -0
  5. package/dist/automation.js +27 -0
  6. package/dist/badge.d.ts +13 -0
  7. package/dist/badge.d.ts.map +1 -0
  8. package/dist/badge.js +34 -0
  9. package/dist/chrome.d.ts +90 -0
  10. package/dist/chrome.d.ts.map +1 -0
  11. package/dist/chrome.js +133 -0
  12. package/dist/client.d.ts +26 -0
  13. package/dist/client.d.ts.map +1 -0
  14. package/dist/client.js +545 -0
  15. package/dist/clipboard.d.ts +19 -0
  16. package/dist/clipboard.d.ts.map +1 -0
  17. package/dist/clipboard.js +51 -0
  18. package/dist/cookies.d.ts +44 -0
  19. package/dist/cookies.d.ts.map +1 -0
  20. package/dist/cookies.js +45 -0
  21. package/dist/crash.d.ts +35 -0
  22. package/dist/crash.d.ts.map +1 -0
  23. package/dist/crash.js +28 -0
  24. package/dist/db.d.ts +14 -0
  25. package/dist/db.d.ts.map +1 -0
  26. package/dist/db.js +23 -0
  27. package/dist/dialog.d.ts +36 -0
  28. package/dist/dialog.d.ts.map +1 -0
  29. package/dist/dialog.js +23 -0
  30. package/dist/downloads.d.ts +35 -0
  31. package/dist/downloads.d.ts.map +1 -0
  32. package/dist/downloads.js +30 -0
  33. package/dist/driver.d.ts +190 -0
  34. package/dist/driver.d.ts.map +1 -0
  35. package/dist/driver.js +637 -0
  36. package/dist/errors.d.ts +7 -0
  37. package/dist/errors.d.ts.map +1 -0
  38. package/dist/errors.js +11 -0
  39. package/dist/events.d.ts +6 -0
  40. package/dist/events.d.ts.map +1 -0
  41. package/dist/events.js +47 -0
  42. package/dist/extension.d.ts +10 -0
  43. package/dist/extension.d.ts.map +1 -0
  44. package/dist/extension.js +25 -0
  45. package/dist/fakehost.d.ts +18 -0
  46. package/dist/fakehost.d.ts.map +1 -0
  47. package/dist/fakehost.js +199 -0
  48. package/dist/fs.d.ts +26 -0
  49. package/dist/fs.d.ts.map +1 -0
  50. package/dist/fs.js +38 -0
  51. package/dist/host.d.ts +4 -0
  52. package/dist/host.d.ts.map +1 -0
  53. package/dist/host.js +25 -0
  54. package/dist/index.d.ts +19 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +40 -0
  57. package/dist/kv.d.ts +6 -0
  58. package/dist/kv.d.ts.map +1 -0
  59. package/dist/kv.js +19 -0
  60. package/dist/lifecycle.d.ts +22 -0
  61. package/dist/lifecycle.d.ts.map +1 -0
  62. package/dist/lifecycle.js +85 -0
  63. package/dist/login.d.ts +10 -0
  64. package/dist/login.d.ts.map +1 -0
  65. package/dist/login.js +8 -0
  66. package/dist/media.d.ts +50 -0
  67. package/dist/media.d.ts.map +1 -0
  68. package/dist/media.js +70 -0
  69. package/dist/menu.d.ts +71 -0
  70. package/dist/menu.d.ts.map +1 -0
  71. package/dist/menu.js +114 -0
  72. package/dist/mock.d.ts +14 -0
  73. package/dist/mock.d.ts.map +1 -0
  74. package/dist/mock.js +47 -0
  75. package/dist/notify.d.ts +25 -0
  76. package/dist/notify.d.ts.map +1 -0
  77. package/dist/notify.js +32 -0
  78. package/dist/offscreen.d.ts +24 -0
  79. package/dist/offscreen.d.ts.map +1 -0
  80. package/dist/offscreen.js +27 -0
  81. package/dist/os.d.ts +20 -0
  82. package/dist/os.d.ts.map +1 -0
  83. package/dist/os.js +43 -0
  84. package/dist/page.d.ts +69 -0
  85. package/dist/page.d.ts.map +1 -0
  86. package/dist/page.js +61 -0
  87. package/dist/permission.d.ts +5 -0
  88. package/dist/permission.d.ts.map +1 -0
  89. package/dist/permission.js +18 -0
  90. package/dist/port.d.ts +35 -0
  91. package/dist/port.d.ts.map +1 -0
  92. package/dist/port.js +159 -0
  93. package/dist/power.d.ts +19 -0
  94. package/dist/power.d.ts.map +1 -0
  95. package/dist/power.js +35 -0
  96. package/dist/remote.d.ts +156 -0
  97. package/dist/remote.d.ts.map +1 -0
  98. package/dist/remote.js +115 -0
  99. package/dist/screen.d.ts +25 -0
  100. package/dist/screen.d.ts.map +1 -0
  101. package/dist/screen.js +23 -0
  102. package/dist/shortcut.d.ts +2 -0
  103. package/dist/shortcut.d.ts.map +1 -0
  104. package/dist/shortcut.js +44 -0
  105. package/dist/testing.d.ts +6 -0
  106. package/dist/testing.d.ts.map +1 -0
  107. package/dist/testing.js +9 -0
  108. package/dist/theme.d.ts +12 -0
  109. package/dist/theme.d.ts.map +1 -0
  110. package/dist/theme.js +13 -0
  111. package/dist/tray.d.ts +18 -0
  112. package/dist/tray.d.ts.map +1 -0
  113. package/dist/tray.js +23 -0
  114. package/dist/types.d.ts +16 -0
  115. package/dist/types.d.ts.map +1 -0
  116. package/dist/types.js +1 -0
  117. package/dist/updater.d.ts +36 -0
  118. package/dist/updater.d.ts.map +1 -0
  119. package/dist/updater.js +58 -0
  120. package/dist/window.d.ts +154 -0
  121. package/dist/window.d.ts.map +1 -0
  122. package/dist/window.js +205 -0
  123. package/dist/wire.d.ts +26 -0
  124. package/dist/wire.d.ts.map +1 -0
  125. package/dist/wire.js +328 -0
  126. package/dist/worker-host.d.ts +6 -0
  127. package/dist/worker-host.d.ts.map +1 -0
  128. package/dist/worker-host.js +36 -0
  129. package/dist/worker.d.ts +62 -0
  130. package/dist/worker.d.ts.map +1 -0
  131. package/dist/worker.js +86 -0
  132. package/package.json +188 -3
package/dist/worker.js ADDED
@@ -0,0 +1,86 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _WorkerHandle_off;
13
+ // Background worker processes (Electron's utilityProcess.fork). Needs the
14
+ // "worker" permission. Workers are declared in native.workers; this module
15
+ // starts them by name and talks to them. See worker-host for the code that
16
+ // runs inside a worker.
17
+ import { call, stream } from "./index.js";
18
+ import { isKrateError } from "./errors.js";
19
+ export function workerSpecs() {
20
+ return call("krate/worker.specs", []);
21
+ }
22
+ export function listWorkers() {
23
+ return call("krate/worker.list", []);
24
+ }
25
+ // onWorkerEvent calls fn for the events of one instance (all when id is
26
+ // omitted) until the returned function is called.
27
+ export function onWorkerEvent(fn, id) {
28
+ const ac = new AbortController();
29
+ void (async () => {
30
+ try {
31
+ for await (const ev of stream("krate/worker.events", id === undefined ? [] : [id], { signal: ac.signal })) {
32
+ try {
33
+ fn(ev);
34
+ }
35
+ catch (e) {
36
+ console.error(e);
37
+ }
38
+ }
39
+ }
40
+ catch (e) {
41
+ if (!ac.signal.aborted && !(isKrateError(e) && e.code === "not_found"))
42
+ console.error(e);
43
+ }
44
+ })();
45
+ return () => ac.abort();
46
+ }
47
+ // A WorkerHandle is one running instance.
48
+ export class WorkerHandle {
49
+ constructor(id, name) {
50
+ this.onmessage = null;
51
+ // onexit runs each time the process ends, with the exit code (-1 for a
52
+ // signal) and whether it crashed. A restart policy may start it again.
53
+ this.onexit = null;
54
+ this.onrestart = null;
55
+ _WorkerHandle_off.set(this, void 0);
56
+ this.id = id;
57
+ this.name = name;
58
+ __classPrivateFieldSet(this, _WorkerHandle_off, onWorkerEvent((ev) => {
59
+ if (ev.kind === "message")
60
+ this.onmessage?.(ev.data);
61
+ else if (ev.kind === "exit" || ev.kind === "crash")
62
+ this.onexit?.({ code: ev.exitCode ?? 0, crashed: ev.kind === "crash", error: ev.error });
63
+ else if (ev.kind === "restarting")
64
+ this.onrestart?.({ attempt: ev.attempt ?? 0, delayMs: ev.delayMs ?? 0 });
65
+ }, id), "f");
66
+ }
67
+ // The id to give transferPort to hand this worker an end of a channel.
68
+ get portOwner() {
69
+ return `worker:${this.id}`;
70
+ }
71
+ postMessage(data) {
72
+ return call("krate/worker.post", [this.id, data]);
73
+ }
74
+ // terminate stops the worker and keeps it from restarting.
75
+ async terminate() {
76
+ __classPrivateFieldGet(this, _WorkerHandle_off, "f").call(this);
77
+ await call("krate/worker.stop", [this.id]);
78
+ }
79
+ }
80
+ _WorkerHandle_off = new WeakMap();
81
+ // startWorker starts an instance of a declared worker and resolves when its
82
+ // process is ready.
83
+ export async function startWorker(name, options) {
84
+ const id = await call("krate/worker.start", options ? [name, options] : [name]);
85
+ return new WorkerHandle(id, name);
86
+ }
package/package.json CHANGED
@@ -1,6 +1,191 @@
1
1
  {
2
2
  "name": "@krate/app",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.5.0-rc.10",
4
+ "description": "Client runtime and host bindings for Krate desktop apps (host calls, streams, signals).",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "homepage": "https://krate.js.org",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/kratejs/krate.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/kratejs/krate/issues"
14
+ },
15
+ "keywords": [
16
+ "krate",
17
+ "desktop",
18
+ "native",
19
+ "webview"
20
+ ],
21
+ "engines": {
22
+ "node": ">=20"
23
+ },
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "./client": {
32
+ "types": "./dist/client.d.ts",
33
+ "default": "./dist/client.js"
34
+ },
35
+ "./host": {
36
+ "types": "./dist/host.d.ts",
37
+ "default": "./dist/host.js"
38
+ },
39
+ "./testing": {
40
+ "types": "./dist/testing.d.ts",
41
+ "default": "./dist/testing.js"
42
+ },
43
+ "./os": {
44
+ "types": "./dist/os.d.ts",
45
+ "default": "./dist/os.js"
46
+ },
47
+ "./db": {
48
+ "types": "./dist/db.d.ts",
49
+ "default": "./dist/db.js"
50
+ },
51
+ "./kv": {
52
+ "types": "./dist/kv.d.ts",
53
+ "default": "./dist/kv.js"
54
+ },
55
+ "./fs": {
56
+ "types": "./dist/fs.d.ts",
57
+ "default": "./dist/fs.js"
58
+ },
59
+ "./permission": {
60
+ "types": "./dist/permission.d.ts",
61
+ "default": "./dist/permission.js"
62
+ },
63
+ "./window": {
64
+ "types": "./dist/window.d.ts",
65
+ "default": "./dist/window.js"
66
+ },
67
+ "./chrome": {
68
+ "types": "./dist/chrome.d.ts",
69
+ "default": "./dist/chrome.js"
70
+ },
71
+ "./dialog": {
72
+ "types": "./dist/dialog.d.ts",
73
+ "default": "./dist/dialog.js"
74
+ },
75
+ "./clipboard": {
76
+ "types": "./dist/clipboard.d.ts",
77
+ "default": "./dist/clipboard.js"
78
+ },
79
+ "./media": {
80
+ "types": "./dist/media.d.ts",
81
+ "default": "./dist/media.js"
82
+ },
83
+ "./notify": {
84
+ "types": "./dist/notify.d.ts",
85
+ "default": "./dist/notify.js"
86
+ },
87
+ "./menu": {
88
+ "types": "./dist/menu.d.ts",
89
+ "default": "./dist/menu.js"
90
+ },
91
+ "./tray": {
92
+ "types": "./dist/tray.d.ts",
93
+ "default": "./dist/tray.js"
94
+ },
95
+ "./shortcut": {
96
+ "types": "./dist/shortcut.d.ts",
97
+ "default": "./dist/shortcut.js"
98
+ },
99
+ "./app": {
100
+ "types": "./dist/lifecycle.d.ts",
101
+ "default": "./dist/lifecycle.js"
102
+ },
103
+ "./updater": {
104
+ "types": "./dist/updater.d.ts",
105
+ "default": "./dist/updater.js"
106
+ },
107
+ "./driver": {
108
+ "types": "./dist/driver.d.ts",
109
+ "default": "./dist/driver.js"
110
+ },
111
+ "./badge": {
112
+ "types": "./dist/badge.d.ts",
113
+ "default": "./dist/badge.js"
114
+ },
115
+ "./screen": {
116
+ "types": "./dist/screen.d.ts",
117
+ "default": "./dist/screen.js"
118
+ },
119
+ "./power": {
120
+ "types": "./dist/power.d.ts",
121
+ "default": "./dist/power.js"
122
+ },
123
+ "./login": {
124
+ "types": "./dist/login.d.ts",
125
+ "default": "./dist/login.js"
126
+ },
127
+ "./theme": {
128
+ "types": "./dist/theme.d.ts",
129
+ "default": "./dist/theme.js"
130
+ },
131
+ "./crash": {
132
+ "types": "./dist/crash.d.ts",
133
+ "default": "./dist/crash.js"
134
+ },
135
+ "./page": {
136
+ "types": "./dist/page.d.ts",
137
+ "default": "./dist/page.js"
138
+ },
139
+ "./downloads": {
140
+ "types": "./dist/downloads.d.ts",
141
+ "default": "./dist/downloads.js"
142
+ },
143
+ "./cookies": {
144
+ "types": "./dist/cookies.d.ts",
145
+ "default": "./dist/cookies.js"
146
+ },
147
+ "./port": {
148
+ "types": "./dist/port.d.ts",
149
+ "default": "./dist/port.js"
150
+ },
151
+ "./worker": {
152
+ "types": "./dist/worker.d.ts",
153
+ "default": "./dist/worker.js"
154
+ },
155
+ "./worker-host": {
156
+ "types": "./dist/worker-host.d.ts",
157
+ "default": "./dist/worker-host.js"
158
+ },
159
+ "./offscreen": {
160
+ "types": "./dist/offscreen.d.ts",
161
+ "default": "./dist/offscreen.js"
162
+ },
163
+ "./automation": {
164
+ "types": "./dist/automation.d.ts",
165
+ "default": "./dist/automation.js"
166
+ },
167
+ "./extension": {
168
+ "types": "./dist/extension.d.ts",
169
+ "default": "./dist/extension.js"
170
+ },
171
+ "./remote": {
172
+ "types": "./dist/remote.d.ts",
173
+ "default": "./dist/remote.js"
174
+ }
175
+ },
176
+ "files": [
177
+ "dist"
178
+ ],
179
+ "devDependencies": {
180
+ "@types/node": "^26.2.0",
181
+ "happy-dom": "^20.14.5",
182
+ "typescript": "^5.5.0",
183
+ "vitest": "^5.0.3"
184
+ },
185
+ "scripts": {
186
+ "build": "tsc",
187
+ "dev": "tsc --watch",
188
+ "test": "vitest run",
189
+ "typecheck": "node ../../node_modules/typescript7/bin/tsc --noEmit && node ../../node_modules/typescript7/bin/tsc --noEmit -p tsconfig.test.json"
190
+ }
6
191
  }