@bun-native/protocol 0.33.1 → 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.1 was built from [c56fdd675365](https://github.com/0xPlayerOne/bun-native/tree/c56fdd6753653a10144a4167c1d3dfb3c38a0647) 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/c56fdd6753653a10144a4167c1d3dfb3c38a0647/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": "c56fdd6753653a10144a4167c1d3dfb3c38a0647",
4
- "tree": "c6e81b3f9d041e11dd0413b5fdd7a50910383854",
3
+ "commit": "577f6fc5015b6eeef956efcc63f97e2a749d74ff",
4
+ "tree": "c599e781af2ce0749d5e3a6d8700834690e872f4",
5
5
  "files": {
6
6
  "package.json": {
7
- "bytes": 2115,
8
- "sha256": "caf866d56f3cd7530d5735ecbf62512e9e22526bc44c75a4b48a18c26352c0b8"
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": 6687,
16
- "sha256": "a0346cff0bfe26a1b2d1eaf1470521d5602d59dd54f831b3353be56499a5efc3"
15
+ "bytes": 6010,
16
+ "sha256": "39276bc4307e574263ff34d6e29942ef44734c507c14f82487841795cb5656bb"
17
17
  },
18
18
  "packages/protocol/src/dialogs.ts": {
19
- "bytes": 5261,
20
- "sha256": "c26aab88e0e6ca9838b8c7dd471165e03f967694576a257dec88cff8343e4175"
19
+ "bytes": 4664,
20
+ "sha256": "637e42c4ef677da419afb9030747341b3f7b7eb0c180f27b399b058d103ffa45"
21
21
  },
22
22
  "packages/protocol/src/drops.ts": {
23
- "bytes": 2029,
24
- "sha256": "03894f9b2b40f7645e74824de630bebc4d7d7145eafade79739248126826a42b"
23
+ "bytes": 1790,
24
+ "sha256": "8924bd47865072238d5c19f9bc91ee767e99ed123584c0b1c040f01275a10004"
25
25
  },
26
26
  "packages/protocol/src/elements.ts": {
27
- "bytes": 17017,
28
- "sha256": "b831c4906806cd8b46aab29983481c85617b84b4bcc6cde515c3c2d8f5f4dfb1"
27
+ "bytes": 13223,
28
+ "sha256": "ccf94de0d2c13b378d4979244d71ab0c153ae61a851013cca892589a1883b427"
29
29
  },
30
30
  "packages/protocol/src/files.ts": {
31
- "bytes": 10818,
32
- "sha256": "4fda4c2ebcc489f330b52ff042fe3b005b7b09718799f4b684d06c7728b86730"
31
+ "bytes": 10265,
32
+ "sha256": "d3b64ccae0b2f85cefb256e682161aca1d05386e29f3afde6ae6194be5fba79e"
33
33
  },
34
34
  "packages/protocol/src/framing.ts": {
35
- "bytes": 4321,
36
- "sha256": "63148dfde50d4e98dafd8e1923db43d290565453a28113cf356ed3e33c4a5d70"
35
+ "bytes": 4043,
36
+ "sha256": "b434a847d174706308ddd30e8dfb6d4283b518257a3314a54800223b5a9abd9b"
37
37
  },
38
38
  "packages/protocol/src/index.ts": {
39
- "bytes": 2940,
40
- "sha256": "3aa7a5bb90bbcb4c58fa999a6179fcca860b53913984efb857505d90438e79ae"
39
+ "bytes": 2970,
40
+ "sha256": "606ea8975cb871eeb1f7a00fd1f2970a1fe4f05ba9d32f77b462639b325a6a4a"
41
41
  },
42
42
  "packages/protocol/src/message-dialogs.ts": {
43
- "bytes": 4229,
44
- "sha256": "3fe42b3c42ff255761a867c87d0ea69f0404ee9dd64ba57cda9f9573588db210"
43
+ "bytes": 3855,
44
+ "sha256": "ff0c1df4f889ce000d1f42aac9523757b45a6d5b8e078b6e2ff9dc152c5d1d03"
45
45
  },
46
46
  "packages/protocol/src/messages.ts": {
47
- "bytes": 48950,
48
- "sha256": "17d92d1b5f08fb04f1dc9e6269291ffc7ff39f3c6ace3c9a6b7b216c6a63c2d3"
47
+ "bytes": 43920,
48
+ "sha256": "1d34f757b7a43a26d77620f0050e6ab353ff2c14c4103ccb63d2b60e3a07d246"
49
49
  },
50
50
  "packages/protocol/src/processes.ts": {
51
- "bytes": 10019,
52
- "sha256": "b64ee81b209a4e6ccf0965409c355a1bc3bfa8d813668aec385b50050be4f2b6"
51
+ "bytes": 9537,
52
+ "sha256": "4b4188862965dead8fd7a0172a533e2b2a975bb96a8ed0071b527e0eef9c690c"
53
53
  },
54
54
  "packages/protocol/src/services.ts": {
55
- "bytes": 7933,
56
- "sha256": "4906b13929e96382fe55c8f94316e5b6629c74a6482ce25c55c621bc449a45e9"
55
+ "bytes": 7302,
56
+ "sha256": "fd94edd7e46c37f5bea665b586f7c7cfec95723e73ec8b63a29daa6fe32b0787"
57
57
  },
58
58
  "packages/protocol/src/values.ts": {
59
- "bytes": 2365,
60
- "sha256": "cca3d96f72dde820f154b6e492ea1a94ee33d8af8da44aca6fd1039912de63c1"
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,
@@ -69,7 +73,7 @@
69
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.1",
3
+ "version": "0.33.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "files": [
package/src/app-menu.ts CHANGED
@@ -1,43 +1,15 @@
1
1
  import { ProtocolError } from './framing.ts'
2
- import { fields, keys, object, string } from './values.ts'
3
-
4
- /** Top-level menus in one menu bar. */
5
- 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
- const MAX_APP_MENU_LABEL_BYTES = 64
11
-
12
- const APP_MENU_NAMED_KEYS = Object.freeze([
13
- 'enter',
14
- 'escape',
15
- 'tab',
16
- 'space',
17
- 'backspace',
18
- 'delete',
19
- 'up',
20
- 'down',
21
- 'left',
22
- 'right',
23
- 'home',
24
- 'end',
25
- 'pageup',
26
- 'pagedown',
27
- ] as const)
28
- const APP_MENU_PUNCTUATION_KEYS = Object.freeze([
29
- ',',
30
- '.',
31
- '/',
32
- ';',
33
- "'",
34
- '[',
35
- ']',
36
- '-',
37
- '=',
38
- '`',
39
- '\\',
40
- ] as const)
2
+ import { keys, object, string } from './values.ts'
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'
41
13
 
42
14
  /** The closed key set of a menu shortcut. */
43
15
  export const APP_MENU_KEYS = Object.freeze([
@@ -77,13 +49,13 @@ export interface AppMenu {
77
49
  items: AppMenuEntry[]
78
50
  }
79
51
 
80
- 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}}$`)
81
53
 
82
- /** `[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. */
83
55
  export function parseAppMenuItemId(value: unknown): string {
84
56
  if (typeof value !== 'string' || !ITEM_ID.test(value))
85
57
  throw new ProtocolError(
86
- "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 '-'`
87
59
  )
88
60
  return value
89
61
  }
@@ -103,17 +75,14 @@ function flag(data: Record<string, unknown>, key: string): boolean {
103
75
 
104
76
  const isFunctionKey = (key: string) => /^f([1-9]|1[0-2])$/.test(key)
105
77
 
106
- const MENU_SHORTCUT_KEYS = fields('key', 'modifiers')
107
- const MENU_MODIFIER_KEYS = fields('control', 'alt', 'shift', 'platform')
108
-
109
78
  function parseMenuShortcut(value: unknown): MenuShortcut {
110
79
  const data = object(value)
111
- keys(data, MENU_SHORTCUT_KEYS)
80
+ keys(data, PAYLOAD_KEYS.menu_shortcut)
112
81
  const key = data['key']
113
82
  if (typeof key !== 'string' || !APP_MENU_KEYS.includes(key))
114
83
  throw new ProtocolError('Menu shortcut key is not in the closed key set')
115
84
  const raw = object(data['modifiers'])
116
- keys(raw, MENU_MODIFIER_KEYS)
85
+ keys(raw, PAYLOAD_KEYS.menu_shortcut_modifiers)
117
86
  const modifiers = {
118
87
  control: flag(raw, 'control'),
119
88
  alt: flag(raw, 'alt'),
@@ -134,10 +103,6 @@ interface Census {
134
103
  shortcuts: Set<string>
135
104
  }
136
105
 
137
- const ENTRIES_ITEM_KEYS = fields('kind', 'id', 'label', 'shortcut', 'enabled', 'checked')
138
- const ENTRIES_SEPARATOR_KEYS = fields('kind')
139
- const ENTRIES_SUBMENU_KEYS = fields('kind', 'label', 'enabled', 'items')
140
-
141
106
  function entries(value: unknown, depth: number, census: Census): AppMenuEntry[] {
142
107
  if (!Array.isArray(value) || !value.length)
143
108
  throw new ProtocolError('A menu or submenu needs at least one entry')
@@ -147,7 +112,7 @@ function entries(value: unknown, depth: number, census: Census): AppMenuEntry[]
147
112
  const data = object(raw)
148
113
  switch (data['kind']) {
149
114
  case 'item': {
150
- keys(data, ENTRIES_ITEM_KEYS)
115
+ keys(data, PAYLOAD_KEYS.app_menu_entry.item)
151
116
  const id = parseAppMenuItemId(data['id'])
152
117
  if (census.ids.has(id))
153
118
  throw new ProtocolError('Menu item ids must be unique in a menu bar')
@@ -170,10 +135,10 @@ function entries(value: unknown, depth: number, census: Census): AppMenuEntry[]
170
135
  return entry
171
136
  }
172
137
  case 'separator':
173
- keys(data, ENTRIES_SEPARATOR_KEYS)
138
+ keys(data, PAYLOAD_KEYS.app_menu_entry.separator)
174
139
  return { kind: 'separator' }
175
140
  case 'submenu': {
176
- keys(data, ENTRIES_SUBMENU_KEYS)
141
+ keys(data, PAYLOAD_KEYS.app_menu_entry.submenu)
177
142
  const text = label(data['label'], 'menu label')
178
143
  const enabled = flag(data, 'enabled')
179
144
  if (depth >= MAX_APP_MENU_DEPTH)
@@ -199,8 +164,6 @@ export function parseContextMenuItems(value: unknown): AppMenuEntry[] {
199
164
  return entries(value, 1, { entries: 0, ids: new Set(), shortcuts: new Set() })
200
165
  }
201
166
 
202
- const APP_MENUS_KEYS = fields('title', 'items')
203
-
204
167
  /** An empty bar is valid: it removes the application's menus. */
205
168
  export function parseAppMenus(value: unknown): AppMenu[] {
206
169
  if (!Array.isArray(value) || value.length > MAX_APP_MENUS)
@@ -208,7 +171,7 @@ export function parseAppMenus(value: unknown): AppMenu[] {
208
171
  const census: Census = { entries: 0, ids: new Set(), shortcuts: new Set() }
209
172
  return value.map((raw) => {
210
173
  const data = object(raw)
211
- keys(data, APP_MENUS_KEYS)
174
+ keys(data, PAYLOAD_KEYS.app_menu)
212
175
  return {
213
176
  title: label(data['title'], 'menu title'),
214
177
  items: entries(data['items'], 1, census),
package/src/dialogs.ts CHANGED
@@ -1,18 +1,17 @@
1
1
  import { ProtocolError } from './framing.ts'
2
- import { fields, 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
2
+ import { keys, object, string } from './values.ts'
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',
@@ -56,11 +55,9 @@ function parseDialogPath(value: unknown, field = 'dialog path'): string {
56
55
  return path
57
56
  }
58
57
 
59
- const FILTER_KEYS = fields('name', 'patterns')
60
-
61
58
  function filter(value: unknown): FileFilter {
62
59
  const data = object(value)
63
- keys(data, FILTER_KEYS)
60
+ keys(data, PAYLOAD_KEYS.file_filter)
64
61
  const patterns = data['patterns']
65
62
  if (
66
63
  !Array.isArray(patterns) ||
@@ -76,18 +73,9 @@ function filter(value: unknown): FileFilter {
76
73
  }
77
74
  }
78
75
 
79
- const FILE_DIALOG_OPTIONS_KEYS = fields(
80
- 'mode',
81
- 'title',
82
- 'accept_label',
83
- 'folder',
84
- 'name',
85
- 'filters'
86
- )
87
-
88
76
  export function parseFileDialogOptions(value: unknown): FileDialogOptions {
89
77
  const data = object(value)
90
- keys(data, FILE_DIALOG_OPTIONS_KEYS)
78
+ keys(data, PAYLOAD_KEYS.file_dialog_options)
91
79
  const mode = FILE_DIALOG_MODES.find((candidate) => candidate === data['mode'])
92
80
  if (!mode) throw new ProtocolError('Unknown file dialog mode')
93
81
  const options: FileDialogOptions = {
@@ -115,25 +103,21 @@ export function parseFileDialogOptions(value: unknown): FileDialogOptions {
115
103
  return options
116
104
  }
117
105
 
118
- const FILE_DIALOG_RESULT_SELECTED_KEYS = fields('kind', 'paths')
119
- const FILE_DIALOG_RESULT_CANCELLED_KEYS = fields('kind')
120
- const FILE_DIALOG_RESULT_FAILED_KEYS = fields('kind', 'code')
121
-
122
106
  export function parseFileDialogResult(value: unknown): FileDialogResult {
123
107
  const data = object(value)
124
108
  switch (data['kind']) {
125
109
  case 'selected': {
126
- keys(data, FILE_DIALOG_RESULT_SELECTED_KEYS)
110
+ keys(data, PAYLOAD_KEYS.file_dialog_result.selected)
127
111
  const paths = data['paths']
128
112
  if (!Array.isArray(paths) || paths.length < 1 || paths.length > MAX_DIALOG_PATHS)
129
113
  throw new ProtocolError('A dialog selection holds between 1 and 256 paths')
130
114
  return { kind: 'selected', paths: paths.map((path) => parseDialogPath(path)) }
131
115
  }
132
116
  case 'cancelled':
133
- keys(data, FILE_DIALOG_RESULT_CANCELLED_KEYS)
117
+ keys(data, PAYLOAD_KEYS.file_dialog_result.cancelled)
134
118
  return { kind: 'cancelled' }
135
119
  case 'failed': {
136
- keys(data, FILE_DIALOG_RESULT_FAILED_KEYS)
120
+ keys(data, PAYLOAD_KEYS.file_dialog_result.failed)
137
121
  const code = (['native_failure', 'payload_too_large'] as const).find(
138
122
  (candidate) => candidate === data['code']
139
123
  )
package/src/drops.ts CHANGED
@@ -1,12 +1,6 @@
1
1
  import { ProtocolError } from './framing.ts'
2
- import { fields, 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
2
+ import { integer, keys, object, string } from './values.ts'
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]
@@ -33,14 +27,12 @@ export function parseDropItemIndex(value: unknown): number {
33
27
  return integer(value, 'Dropped item index', 0, MAX_DROP_ITEMS - 1)
34
28
  }
35
29
 
36
- const DROPPED_ITEMS_KEYS = fields('name')
37
-
38
30
  export function parseDroppedItems(value: unknown): DroppedItem[] {
39
31
  if (!Array.isArray(value) || value.length < 1 || value.length > MAX_DROP_ITEMS)
40
32
  throw new ProtocolError('A drop must deliver between 1 and ' + MAX_DROP_ITEMS + ' items')
41
33
  return value.map((entry) => {
42
34
  const data = object(entry)
43
- keys(data, DROPPED_ITEMS_KEYS)
35
+ keys(data, PAYLOAD_KEYS.dropped_item)
44
36
  const name = string(data['name'], 'Dropped item name', MAX_DROP_NAME_BYTES)
45
37
  if (!name || /\p{Cc}/u.test(name))
46
38
  throw new ProtocolError('Dropped item name must be nonempty without control characters')