@nustackdev/ui-core 0.1.0
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/package.json +28 -0
- package/src/index.ts +4 -0
- package/src/protocol.ts +61 -0
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nustackdev/ui-core",
|
|
3
|
+
"description": "Wire protocol for the Nu.",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"types": "./src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.ts",
|
|
11
|
+
"import": "./src/index.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"src"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"check": "biome check ."
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@msgpack/msgpack": "^3.1.3"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "~5.9.3",
|
|
26
|
+
"@biomejs/biome": "^2.3.15"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/index.ts
ADDED
package/src/protocol.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Wire protocol mirror of api/src/nudle/protocol.py.
|
|
2
|
+
// See projects/nu/stack/nudle/protocol.md in the Go space for the spec.
|
|
3
|
+
|
|
4
|
+
import { decode as mpDecode, encode as mpEncode } from "@msgpack/msgpack";
|
|
5
|
+
|
|
6
|
+
export const OP_MOUNT = "mount";
|
|
7
|
+
export const OP_UNMOUNT = "unmount";
|
|
8
|
+
export const OP_ERROR = "error";
|
|
9
|
+
export const OP_NOTIFY = "notify";
|
|
10
|
+
export const OP_READ = "read";
|
|
11
|
+
|
|
12
|
+
export type Frame = {
|
|
13
|
+
op: string;
|
|
14
|
+
ref: string;
|
|
15
|
+
payload: unknown;
|
|
16
|
+
id?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type MountField = {
|
|
20
|
+
path: string;
|
|
21
|
+
type: string;
|
|
22
|
+
// Optional class-level defaults for the Ref or Section. When present,
|
|
23
|
+
// the slice factory seeds its state from these values.
|
|
24
|
+
props?: Record<string, unknown>;
|
|
25
|
+
// Optional nested fields. Layout entries (Row, Column, Container) carry
|
|
26
|
+
// their child entries here. Leaf Ref entries omit this key. The browser
|
|
27
|
+
// walks the tree recursively to register slices for every leaf.
|
|
28
|
+
fields?: MountField[];
|
|
29
|
+
};
|
|
30
|
+
export type MountPage = { route: string; name: string; fields: MountField[] };
|
|
31
|
+
// `name` is the Index class name; `fields` are Index-level structural
|
|
32
|
+
// slots (TitleRef, NavRef, ...); `pages` lists Page subtrees by route.
|
|
33
|
+
export type MountPayload = {
|
|
34
|
+
name: string;
|
|
35
|
+
fields: MountField[];
|
|
36
|
+
pages?: MountPage[];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type ErrorCode =
|
|
40
|
+
| "ref_not_found"
|
|
41
|
+
| "op_not_allowed"
|
|
42
|
+
| "payload_invalid"
|
|
43
|
+
| "not_mounted"
|
|
44
|
+
| "internal";
|
|
45
|
+
|
|
46
|
+
export type ErrorPayload = { code: ErrorCode; message: string };
|
|
47
|
+
|
|
48
|
+
export function encode(frame: Frame): Uint8Array {
|
|
49
|
+
return mpEncode(frame);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function decode(raw: ArrayBuffer | Uint8Array): Frame {
|
|
53
|
+
const bytes = raw instanceof Uint8Array ? raw : new Uint8Array(raw);
|
|
54
|
+
const d = mpDecode(bytes) as Partial<Frame> & { op: string };
|
|
55
|
+
return {
|
|
56
|
+
op: d.op,
|
|
57
|
+
ref: d.ref ?? "",
|
|
58
|
+
payload: d.payload,
|
|
59
|
+
id: d.id,
|
|
60
|
+
};
|
|
61
|
+
}
|