@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 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.0 was built from [fa8bef754122](https://github.com/0xPlayerOne/bun-native/tree/fa8bef754122621d4235eb06e30bb1085b4f7b1e) 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/fa8bef754122621d4235eb06e30bb1085b4f7b1e/docs/getting-started.md); `bun-native host install` fetches the matching release host. The license notice is in LICENSE.
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.
@@ -1,63 +1,67 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "commit": "fa8bef754122621d4235eb06e30bb1085b4f7b1e",
4
- "tree": "f805e2eb19a4e10fc29d1dc827cf5bc617b5773b",
3
+ "commit": "577f6fc5015b6eeef956efcc63f97e2a749d74ff",
4
+ "tree": "c599e781af2ce0749d5e3a6d8700834690e872f4",
5
5
  "files": {
6
6
  "package.json": {
7
- "bytes": 2164,
8
- "sha256": "db50b6f81f25c113a46f8c9b038bc548a92effaeb4ad9562e5e95044baa7b66f"
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": 6435,
16
- "sha256": "52ec565f7423671a13e3bc43d49129496ed9869f22b4fa1b7e3eba79191137b8"
15
+ "bytes": 6010,
16
+ "sha256": "39276bc4307e574263ff34d6e29942ef44734c507c14f82487841795cb5656bb"
17
17
  },
18
18
  "packages/protocol/src/dialogs.ts": {
19
- "bytes": 4896,
20
- "sha256": "c2ea74d7175c75710146c788b261e5566301da5952359b8e50bc69a323cdef00"
19
+ "bytes": 4664,
20
+ "sha256": "637e42c4ef677da419afb9030747341b3f7b7eb0c180f27b399b058d103ffa45"
21
21
  },
22
22
  "packages/protocol/src/drops.ts": {
23
- "bytes": 1968,
24
- "sha256": "478b9952e406853b22e32e8b5c227fdc5936363665d984c628d18581de112191"
23
+ "bytes": 1790,
24
+ "sha256": "8924bd47865072238d5c19f9bc91ee767e99ed123584c0b1c040f01275a10004"
25
25
  },
26
26
  "packages/protocol/src/elements.ts": {
27
- "bytes": 16161,
28
- "sha256": "3529a4f7fefa9d56880a5f32be83b7daea9ad492784478ddc413d2deb85f5283"
27
+ "bytes": 13223,
28
+ "sha256": "ccf94de0d2c13b378d4979244d71ab0c153ae61a851013cca892589a1883b427"
29
29
  },
30
30
  "packages/protocol/src/files.ts": {
31
- "bytes": 10163,
32
- "sha256": "d4d890f22b6abdc713e544a4e3f7b0ed53df4a1d5f44044febea8d8cf9ca96a5"
31
+ "bytes": 10265,
32
+ "sha256": "d3b64ccae0b2f85cefb256e682161aca1d05386e29f3afde6ae6194be5fba79e"
33
33
  },
34
34
  "packages/protocol/src/framing.ts": {
35
- "bytes": 3259,
36
- "sha256": "47d2473785f245d8f85bd1447fba3f7ed47d5ddac170f590df5c83623064158a"
35
+ "bytes": 4043,
36
+ "sha256": "b434a847d174706308ddd30e8dfb6d4283b518257a3314a54800223b5a9abd9b"
37
37
  },
38
38
  "packages/protocol/src/index.ts": {
39
- "bytes": 3388,
40
- "sha256": "7c7fd785b5037bc74ce0594f0ec5c49fca7ef9ae0b4dbab8fbf83d8427f6ead8"
39
+ "bytes": 2970,
40
+ "sha256": "606ea8975cb871eeb1f7a00fd1f2970a1fe4f05ba9d32f77b462639b325a6a4a"
41
41
  },
42
42
  "packages/protocol/src/message-dialogs.ts": {
43
- "bytes": 3997,
44
- "sha256": "551dc23a2fde7771c28e485212d670f37db199da6f2f006344b0dc6b9064ef2b"
43
+ "bytes": 3855,
44
+ "sha256": "ff0c1df4f889ce000d1f42aac9523757b45a6d5b8e078b6e2ff9dc152c5d1d03"
45
45
  },
46
46
  "packages/protocol/src/messages.ts": {
47
- "bytes": 43791,
48
- "sha256": "cef29b0d2fa4b84d73df5c9b8abbf321dafc6a66d688ad00838f0c8aa50a1d03"
47
+ "bytes": 43920,
48
+ "sha256": "1d34f757b7a43a26d77620f0050e6ab353ff2c14c4103ccb63d2b60e3a07d246"
49
49
  },
50
50
  "packages/protocol/src/processes.ts": {
51
- "bytes": 9709,
52
- "sha256": "80f109623ec5f17bc21fb20c4e3093829124839c6c9e5b2457120bff0a45c778"
51
+ "bytes": 9537,
52
+ "sha256": "4b4188862965dead8fd7a0172a533e2b2a975bb96a8ed0071b527e0eef9c690c"
53
53
  },
54
54
  "packages/protocol/src/services.ts": {
55
- "bytes": 7587,
56
- "sha256": "eb128b1ef12d2650acc53b71c2c802f35d3fb983d1f584aa1d81251adfccd37b"
55
+ "bytes": 7302,
56
+ "sha256": "fd94edd7e46c37f5bea665b586f7c7cfec95723e73ec8b63a29daa6fe32b0787"
57
57
  },
58
58
  "packages/protocol/src/values.ts": {
59
- "bytes": 2078,
60
- "sha256": "75d8f7ee9772c1aa2929a9dc4c416f42569795db089d17321398c3cdf482731b"
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": 3012,
69
- "sha256": "00c3f707aae8abe9ca75cd2e162f5e1c7c34362a03675da39afead60d856066a"
72
+ "bytes": 3234,
73
+ "sha256": "9f4d9362cb4cc38c0f4e705295789a0cbfec46ffdd007e0541b9441a7c3003a7"
70
74
  },
71
75
  "dependencyLock": {
72
- "bytes": 28357,
73
- "sha256": "65e3dbd01be4a1889367690faf1a9c3f08fb31d22dbd273d9bb9f39dd6baa6fb"
76
+ "bytes": 28430,
77
+ "sha256": "9d321f65b9224958ec99286628d652232a16e3242ea9536a396bceaf72892460"
74
78
  }
75
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bun-native/protocol",
3
- "version": "0.33.0",
3
+ "version": "0.33.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "files": [
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
- /** Top-level menus in one menu bar. */
5
- export const MAX_APP_MENUS = 16
6
- /** Items, separators and submenus in one menu bar, at every depth. */
7
- export const MAX_APP_MENU_ENTRIES = 128
8
- /** A top-level menu is depth 1; submenus nest at most two levels below it. */
9
- export const MAX_APP_MENU_DEPTH = 3
10
- export const MAX_APP_MENU_LABEL_BYTES = 64
11
- export const MAX_APP_MENU_ITEM_ID_BYTES = 64
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 = /^[A-Za-z0-9._:-]{1,64}$/
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-64 bytes: an application identifier, never a native name. */
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
- "Menu item id must be 1-64 bytes of letters, digits, '.', '_', ':' or '-'"
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, ['key', 'modifiers'])
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, ['control', 'alt', 'shift', 'platform'])
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, ['kind', 'id', 'label', 'shortcut', 'enabled', 'checked'])
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, ['kind'])
138
+ keys(data, PAYLOAD_KEYS.app_menu_entry.separator)
168
139
  return { kind: 'separator' }
169
140
  case 'submenu': {
170
- keys(data, ['kind', 'label', 'enabled', 'items'])
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, ['title', 'items'])
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
- /** Live file dialogs per session. Each window owns at most one at a time. */
5
- export const MAX_FILE_DIALOGS = 16
6
- export const MAX_DIALOG_TITLE_BYTES = 256
7
- export const MAX_DIALOG_LABEL_BYTES = 64
8
- export const MAX_DIALOG_PATH_BYTES = 4_096
9
- export const MAX_DIALOG_NAME_BYTES = 255
10
- export const MAX_DIALOG_FILTERS = 16
11
- export const MAX_DIALOG_FILTER_PATTERNS = 16
12
- export const MAX_DIALOG_FILTER_NAME_BYTES = 128
13
- export const MAX_DIALOG_PATTERN_BYTES = 64
14
- /** Selected paths in one result. The whole result must also fit one frame. */
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, ['name', 'patterns'])
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, ['mode', 'title', 'accept_label', 'folder', 'name', 'filters'])
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, ['kind', 'paths'])
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, ['kind'])
117
+ keys(data, PAYLOAD_KEYS.file_dialog_result.cancelled)
119
118
  return { kind: 'cancelled' }
120
119
  case 'failed': {
121
- keys(data, ['kind', 'code'])
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, ['name'])
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')