@bun-native/protocol 0.33.0 → 0.33.2
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/README.md +1 -1
- package/bun-native-source.json +36 -32
- package/package.json +1 -1
- package/src/app-menu.ts +19 -48
- package/src/dialogs.ts +17 -18
- package/src/drops.ts +2 -8
- package/src/elements.ts +91 -166
- package/src/files.ts +26 -21
- package/src/framing.ts +28 -9
- package/src/index.ts +57 -79
- package/src/message-dialogs.ts +14 -22
- package/src/messages.ts +315 -283
- package/src/processes.ts +23 -22
- package/src/services.ts +17 -30
- package/src/values.ts +12 -4
- package/src/wire-schema.ts +789 -0
package/README.md
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
The private native protocol shared by Bun Native packages and hosts.
|
|
4
4
|
|
|
5
|
-
Part of [Bun Native](https://github.com/0xPlayerOne/bun-native), an experimental developer preview. Version 0.33.
|
|
5
|
+
Part of [Bun Native](https://github.com/0xPlayerOne/bun-native), an experimental developer preview. Version 0.33.2 was built from [577f6fc5015b](https://github.com/0xPlayerOne/bun-native/tree/577f6fc5015b6eeef956efcc63f97e2a749d74ff) and published from GitHub Actions with npm provenance. Use the Bun revision pinned in that commit's toolchain.json. Start with the [getting-started guide](https://github.com/0xPlayerOne/bun-native/blob/577f6fc5015b6eeef956efcc63f97e2a749d74ff/docs/getting-started.md); `bun-native host install` fetches the matching release host. The license notice is in LICENSE.
|
package/bun-native-source.json
CHANGED
|
@@ -1,63 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"commit": "
|
|
4
|
-
"tree": "
|
|
3
|
+
"commit": "577f6fc5015b6eeef956efcc63f97e2a749d74ff",
|
|
4
|
+
"tree": "c599e781af2ce0749d5e3a6d8700834690e872f4",
|
|
5
5
|
"files": {
|
|
6
6
|
"package.json": {
|
|
7
|
-
"bytes":
|
|
8
|
-
"sha256": "
|
|
7
|
+
"bytes": 2258,
|
|
8
|
+
"sha256": "38e2f0f89b5f6c4ba80b3baefcdf0806dd73c684294153df74ab470fda6bf3f9"
|
|
9
9
|
},
|
|
10
10
|
"packages/protocol/package.json": {
|
|
11
11
|
"bytes": 129,
|
|
12
12
|
"sha256": "668f52c10a6db801c2d0c68c59998c489b50c0bb79cb7f60298dfbb83923b0ba"
|
|
13
13
|
},
|
|
14
14
|
"packages/protocol/src/app-menu.ts": {
|
|
15
|
-
"bytes":
|
|
16
|
-
"sha256": "
|
|
15
|
+
"bytes": 6010,
|
|
16
|
+
"sha256": "39276bc4307e574263ff34d6e29942ef44734c507c14f82487841795cb5656bb"
|
|
17
17
|
},
|
|
18
18
|
"packages/protocol/src/dialogs.ts": {
|
|
19
|
-
"bytes":
|
|
20
|
-
"sha256": "
|
|
19
|
+
"bytes": 4664,
|
|
20
|
+
"sha256": "637e42c4ef677da419afb9030747341b3f7b7eb0c180f27b399b058d103ffa45"
|
|
21
21
|
},
|
|
22
22
|
"packages/protocol/src/drops.ts": {
|
|
23
|
-
"bytes":
|
|
24
|
-
"sha256": "
|
|
23
|
+
"bytes": 1790,
|
|
24
|
+
"sha256": "8924bd47865072238d5c19f9bc91ee767e99ed123584c0b1c040f01275a10004"
|
|
25
25
|
},
|
|
26
26
|
"packages/protocol/src/elements.ts": {
|
|
27
|
-
"bytes":
|
|
28
|
-
"sha256": "
|
|
27
|
+
"bytes": 13223,
|
|
28
|
+
"sha256": "ccf94de0d2c13b378d4979244d71ab0c153ae61a851013cca892589a1883b427"
|
|
29
29
|
},
|
|
30
30
|
"packages/protocol/src/files.ts": {
|
|
31
|
-
"bytes":
|
|
32
|
-
"sha256": "
|
|
31
|
+
"bytes": 10265,
|
|
32
|
+
"sha256": "d3b64ccae0b2f85cefb256e682161aca1d05386e29f3afde6ae6194be5fba79e"
|
|
33
33
|
},
|
|
34
34
|
"packages/protocol/src/framing.ts": {
|
|
35
|
-
"bytes":
|
|
36
|
-
"sha256": "
|
|
35
|
+
"bytes": 4043,
|
|
36
|
+
"sha256": "b434a847d174706308ddd30e8dfb6d4283b518257a3314a54800223b5a9abd9b"
|
|
37
37
|
},
|
|
38
38
|
"packages/protocol/src/index.ts": {
|
|
39
|
-
"bytes":
|
|
40
|
-
"sha256": "
|
|
39
|
+
"bytes": 2970,
|
|
40
|
+
"sha256": "606ea8975cb871eeb1f7a00fd1f2970a1fe4f05ba9d32f77b462639b325a6a4a"
|
|
41
41
|
},
|
|
42
42
|
"packages/protocol/src/message-dialogs.ts": {
|
|
43
|
-
"bytes":
|
|
44
|
-
"sha256": "
|
|
43
|
+
"bytes": 3855,
|
|
44
|
+
"sha256": "ff0c1df4f889ce000d1f42aac9523757b45a6d5b8e078b6e2ff9dc152c5d1d03"
|
|
45
45
|
},
|
|
46
46
|
"packages/protocol/src/messages.ts": {
|
|
47
|
-
"bytes":
|
|
48
|
-
"sha256": "
|
|
47
|
+
"bytes": 43920,
|
|
48
|
+
"sha256": "1d34f757b7a43a26d77620f0050e6ab353ff2c14c4103ccb63d2b60e3a07d246"
|
|
49
49
|
},
|
|
50
50
|
"packages/protocol/src/processes.ts": {
|
|
51
|
-
"bytes":
|
|
52
|
-
"sha256": "
|
|
51
|
+
"bytes": 9537,
|
|
52
|
+
"sha256": "4b4188862965dead8fd7a0172a533e2b2a975bb96a8ed0071b527e0eef9c690c"
|
|
53
53
|
},
|
|
54
54
|
"packages/protocol/src/services.ts": {
|
|
55
|
-
"bytes":
|
|
56
|
-
"sha256": "
|
|
55
|
+
"bytes": 7302,
|
|
56
|
+
"sha256": "fd94edd7e46c37f5bea665b586f7c7cfec95723e73ec8b63a29daa6fe32b0787"
|
|
57
57
|
},
|
|
58
58
|
"packages/protocol/src/values.ts": {
|
|
59
|
-
"bytes":
|
|
60
|
-
"sha256": "
|
|
59
|
+
"bytes": 2608,
|
|
60
|
+
"sha256": "30ff1758f56cb4d439ddce36a236c8cc1c90ce8427710307946710299636df7a"
|
|
61
|
+
},
|
|
62
|
+
"packages/protocol/src/wire-schema.ts": {
|
|
63
|
+
"bytes": 28705,
|
|
64
|
+
"sha256": "21c589221792fb6d55aef5422a67b7c40f0b0ed280d3925d25d099d1573b2367"
|
|
61
65
|
},
|
|
62
66
|
"LICENSE": {
|
|
63
67
|
"bytes": 1075,
|
|
@@ -65,11 +69,11 @@
|
|
|
65
69
|
}
|
|
66
70
|
},
|
|
67
71
|
"toolchain": {
|
|
68
|
-
"bytes":
|
|
69
|
-
"sha256": "
|
|
72
|
+
"bytes": 3234,
|
|
73
|
+
"sha256": "9f4d9362cb4cc38c0f4e705295789a0cbfec46ffdd007e0541b9441a7c3003a7"
|
|
70
74
|
},
|
|
71
75
|
"dependencyLock": {
|
|
72
|
-
"bytes":
|
|
73
|
-
"sha256": "
|
|
76
|
+
"bytes": 28430,
|
|
77
|
+
"sha256": "9d321f65b9224958ec99286628d652232a16e3242ea9536a396bceaf72892460"
|
|
74
78
|
}
|
|
75
79
|
}
|
package/package.json
CHANGED
package/src/app-menu.ts
CHANGED
|
@@ -1,44 +1,15 @@
|
|
|
1
1
|
import { ProtocolError } from './framing.ts'
|
|
2
2
|
import { keys, object, string } from './values.ts'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export const APP_MENU_NAMED_KEYS = Object.freeze([
|
|
14
|
-
'enter',
|
|
15
|
-
'escape',
|
|
16
|
-
'tab',
|
|
17
|
-
'space',
|
|
18
|
-
'backspace',
|
|
19
|
-
'delete',
|
|
20
|
-
'up',
|
|
21
|
-
'down',
|
|
22
|
-
'left',
|
|
23
|
-
'right',
|
|
24
|
-
'home',
|
|
25
|
-
'end',
|
|
26
|
-
'pageup',
|
|
27
|
-
'pagedown',
|
|
28
|
-
] as const)
|
|
29
|
-
export const APP_MENU_PUNCTUATION_KEYS = Object.freeze([
|
|
30
|
-
',',
|
|
31
|
-
'.',
|
|
32
|
-
'/',
|
|
33
|
-
';',
|
|
34
|
-
"'",
|
|
35
|
-
'[',
|
|
36
|
-
']',
|
|
37
|
-
'-',
|
|
38
|
-
'=',
|
|
39
|
-
'`',
|
|
40
|
-
'\\',
|
|
41
|
-
] as const)
|
|
3
|
+
import {
|
|
4
|
+
APP_MENU_NAMED_KEYS,
|
|
5
|
+
APP_MENU_PUNCTUATION_KEYS,
|
|
6
|
+
MAX_APP_MENUS,
|
|
7
|
+
MAX_APP_MENU_DEPTH,
|
|
8
|
+
MAX_APP_MENU_ENTRIES,
|
|
9
|
+
MAX_APP_MENU_ITEM_ID_BYTES,
|
|
10
|
+
MAX_APP_MENU_LABEL_BYTES,
|
|
11
|
+
PAYLOAD_KEYS,
|
|
12
|
+
} from './wire-schema.ts'
|
|
42
13
|
|
|
43
14
|
/** The closed key set of a menu shortcut. */
|
|
44
15
|
export const APP_MENU_KEYS = Object.freeze([
|
|
@@ -78,13 +49,13 @@ export interface AppMenu {
|
|
|
78
49
|
items: AppMenuEntry[]
|
|
79
50
|
}
|
|
80
51
|
|
|
81
|
-
const ITEM_ID =
|
|
52
|
+
const ITEM_ID = new RegExp(`^[A-Za-z0-9._:-]{1,${MAX_APP_MENU_ITEM_ID_BYTES}}$`)
|
|
82
53
|
|
|
83
|
-
/** `[A-Za-z0-9._:-]`, 1
|
|
54
|
+
/** `[A-Za-z0-9._:-]`, 1 to `MAX_APP_MENU_ITEM_ID_BYTES` bytes: an application identifier, never a native name. */
|
|
84
55
|
export function parseAppMenuItemId(value: unknown): string {
|
|
85
56
|
if (typeof value !== 'string' || !ITEM_ID.test(value))
|
|
86
57
|
throw new ProtocolError(
|
|
87
|
-
|
|
58
|
+
`Menu item id must be 1-${MAX_APP_MENU_ITEM_ID_BYTES} bytes of letters, digits, '.', '_', ':' or '-'`
|
|
88
59
|
)
|
|
89
60
|
return value
|
|
90
61
|
}
|
|
@@ -106,12 +77,12 @@ const isFunctionKey = (key: string) => /^f([1-9]|1[0-2])$/.test(key)
|
|
|
106
77
|
|
|
107
78
|
function parseMenuShortcut(value: unknown): MenuShortcut {
|
|
108
79
|
const data = object(value)
|
|
109
|
-
keys(data,
|
|
80
|
+
keys(data, PAYLOAD_KEYS.menu_shortcut)
|
|
110
81
|
const key = data['key']
|
|
111
82
|
if (typeof key !== 'string' || !APP_MENU_KEYS.includes(key))
|
|
112
83
|
throw new ProtocolError('Menu shortcut key is not in the closed key set')
|
|
113
84
|
const raw = object(data['modifiers'])
|
|
114
|
-
keys(raw,
|
|
85
|
+
keys(raw, PAYLOAD_KEYS.menu_shortcut_modifiers)
|
|
115
86
|
const modifiers = {
|
|
116
87
|
control: flag(raw, 'control'),
|
|
117
88
|
alt: flag(raw, 'alt'),
|
|
@@ -141,7 +112,7 @@ function entries(value: unknown, depth: number, census: Census): AppMenuEntry[]
|
|
|
141
112
|
const data = object(raw)
|
|
142
113
|
switch (data['kind']) {
|
|
143
114
|
case 'item': {
|
|
144
|
-
keys(data,
|
|
115
|
+
keys(data, PAYLOAD_KEYS.app_menu_entry.item)
|
|
145
116
|
const id = parseAppMenuItemId(data['id'])
|
|
146
117
|
if (census.ids.has(id))
|
|
147
118
|
throw new ProtocolError('Menu item ids must be unique in a menu bar')
|
|
@@ -164,10 +135,10 @@ function entries(value: unknown, depth: number, census: Census): AppMenuEntry[]
|
|
|
164
135
|
return entry
|
|
165
136
|
}
|
|
166
137
|
case 'separator':
|
|
167
|
-
keys(data,
|
|
138
|
+
keys(data, PAYLOAD_KEYS.app_menu_entry.separator)
|
|
168
139
|
return { kind: 'separator' }
|
|
169
140
|
case 'submenu': {
|
|
170
|
-
keys(data,
|
|
141
|
+
keys(data, PAYLOAD_KEYS.app_menu_entry.submenu)
|
|
171
142
|
const text = label(data['label'], 'menu label')
|
|
172
143
|
const enabled = flag(data, 'enabled')
|
|
173
144
|
if (depth >= MAX_APP_MENU_DEPTH)
|
|
@@ -200,7 +171,7 @@ export function parseAppMenus(value: unknown): AppMenu[] {
|
|
|
200
171
|
const census: Census = { entries: 0, ids: new Set(), shortcuts: new Set() }
|
|
201
172
|
return value.map((raw) => {
|
|
202
173
|
const data = object(raw)
|
|
203
|
-
keys(data,
|
|
174
|
+
keys(data, PAYLOAD_KEYS.app_menu)
|
|
204
175
|
return {
|
|
205
176
|
title: label(data['title'], 'menu title'),
|
|
206
177
|
items: entries(data['items'], 1, census),
|
package/src/dialogs.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { ProtocolError } from './framing.ts'
|
|
2
2
|
import { keys, object, string } from './values.ts'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export const MAX_DIALOG_PATHS = 256
|
|
3
|
+
import {
|
|
4
|
+
MAX_DIALOG_FILTERS,
|
|
5
|
+
MAX_DIALOG_FILTER_NAME_BYTES,
|
|
6
|
+
MAX_DIALOG_FILTER_PATTERNS,
|
|
7
|
+
MAX_DIALOG_LABEL_BYTES,
|
|
8
|
+
MAX_DIALOG_NAME_BYTES,
|
|
9
|
+
MAX_DIALOG_PATHS,
|
|
10
|
+
MAX_DIALOG_PATH_BYTES,
|
|
11
|
+
MAX_DIALOG_PATTERN_BYTES,
|
|
12
|
+
MAX_DIALOG_TITLE_BYTES,
|
|
13
|
+
PAYLOAD_KEYS,
|
|
14
|
+
} from './wire-schema.ts'
|
|
16
15
|
|
|
17
16
|
export const FILE_DIALOG_MODES = Object.freeze([
|
|
18
17
|
'open_file',
|
|
@@ -58,7 +57,7 @@ function parseDialogPath(value: unknown, field = 'dialog path'): string {
|
|
|
58
57
|
|
|
59
58
|
function filter(value: unknown): FileFilter {
|
|
60
59
|
const data = object(value)
|
|
61
|
-
keys(data,
|
|
60
|
+
keys(data, PAYLOAD_KEYS.file_filter)
|
|
62
61
|
const patterns = data['patterns']
|
|
63
62
|
if (
|
|
64
63
|
!Array.isArray(patterns) ||
|
|
@@ -76,7 +75,7 @@ function filter(value: unknown): FileFilter {
|
|
|
76
75
|
|
|
77
76
|
export function parseFileDialogOptions(value: unknown): FileDialogOptions {
|
|
78
77
|
const data = object(value)
|
|
79
|
-
keys(data,
|
|
78
|
+
keys(data, PAYLOAD_KEYS.file_dialog_options)
|
|
80
79
|
const mode = FILE_DIALOG_MODES.find((candidate) => candidate === data['mode'])
|
|
81
80
|
if (!mode) throw new ProtocolError('Unknown file dialog mode')
|
|
82
81
|
const options: FileDialogOptions = {
|
|
@@ -108,17 +107,17 @@ export function parseFileDialogResult(value: unknown): FileDialogResult {
|
|
|
108
107
|
const data = object(value)
|
|
109
108
|
switch (data['kind']) {
|
|
110
109
|
case 'selected': {
|
|
111
|
-
keys(data,
|
|
110
|
+
keys(data, PAYLOAD_KEYS.file_dialog_result.selected)
|
|
112
111
|
const paths = data['paths']
|
|
113
112
|
if (!Array.isArray(paths) || paths.length < 1 || paths.length > MAX_DIALOG_PATHS)
|
|
114
113
|
throw new ProtocolError('A dialog selection holds between 1 and 256 paths')
|
|
115
114
|
return { kind: 'selected', paths: paths.map((path) => parseDialogPath(path)) }
|
|
116
115
|
}
|
|
117
116
|
case 'cancelled':
|
|
118
|
-
keys(data,
|
|
117
|
+
keys(data, PAYLOAD_KEYS.file_dialog_result.cancelled)
|
|
119
118
|
return { kind: 'cancelled' }
|
|
120
119
|
case 'failed': {
|
|
121
|
-
keys(data,
|
|
120
|
+
keys(data, PAYLOAD_KEYS.file_dialog_result.failed)
|
|
122
121
|
const code = (['native_failure', 'payload_too_large'] as const).find(
|
|
123
122
|
(candidate) => candidate === data['code']
|
|
124
123
|
)
|
package/src/drops.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { ProtocolError } from './framing.ts'
|
|
2
2
|
import { integer, keys, object, string } from './values.ts'
|
|
3
|
-
|
|
4
|
-
/** Live drop targets across a session. */
|
|
5
|
-
export const MAX_DROP_TARGETS = 32
|
|
6
|
-
/** Items one drop may deliver. A larger drop is rejected, never truncated. */
|
|
7
|
-
export const MAX_DROP_ITEMS = 64
|
|
8
|
-
/** UTF-8 bytes of one untrusted display name. */
|
|
9
|
-
export const MAX_DROP_NAME_BYTES = 255
|
|
3
|
+
import { MAX_DROP_ITEMS, MAX_DROP_NAME_BYTES, PAYLOAD_KEYS } from './wire-schema.ts'
|
|
10
4
|
|
|
11
5
|
export const DRAG_STATES = Object.freeze(['entered', 'left'] as const)
|
|
12
6
|
export type DragState = (typeof DRAG_STATES)[number]
|
|
@@ -38,7 +32,7 @@ export function parseDroppedItems(value: unknown): DroppedItem[] {
|
|
|
38
32
|
throw new ProtocolError('A drop must deliver between 1 and ' + MAX_DROP_ITEMS + ' items')
|
|
39
33
|
return value.map((entry) => {
|
|
40
34
|
const data = object(entry)
|
|
41
|
-
keys(data,
|
|
35
|
+
keys(data, PAYLOAD_KEYS.dropped_item)
|
|
42
36
|
const name = string(data['name'], 'Dropped item name', MAX_DROP_NAME_BYTES)
|
|
43
37
|
if (!name || /\p{Cc}/u.test(name))
|
|
44
38
|
throw new ProtocolError('Dropped item name must be nonempty without control characters')
|