@arcanejs/protocol 0.6.0 → 0.7.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/README.md +1 -1
- package/dist/core.d.mts +23 -29
- package/dist/core.d.ts +23 -29
- package/dist/core.js +3 -1
- package/dist/core.mjs +2 -0
- package/dist/index.d.mts +37 -7
- package/dist/index.d.ts +37 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ and can only be applied to objects that match the type
|
|
|
13
13
|
of the objects being compared.
|
|
14
14
|
|
|
15
15
|
This package is part of the
|
|
16
|
-
[`arcanejs` project](https://github.com/
|
|
16
|
+
[`arcanejs` project](https://github.com/ArcaneWizards/arcanejs#arcanejs),
|
|
17
17
|
and is used to maintain a copy of a JSON tree in downstream clients in real-time
|
|
18
18
|
via websockets.
|
|
19
19
|
|
package/dist/core.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseComponentProto, AnyComponentProto, BaseClientComponentMessage } from './index.mjs';
|
|
1
|
+
import { BaseComponentProto, AnyComponentProto, BaseClientComponentCall, BaseClientComponentMessage } from './index.mjs';
|
|
2
2
|
import { GroupComponentStyle } from './styles.mjs';
|
|
3
3
|
import '@arcanejs/diff';
|
|
4
4
|
|
|
@@ -13,8 +13,7 @@ type Gradient = Array<{
|
|
|
13
13
|
*/
|
|
14
14
|
position: number;
|
|
15
15
|
}>;
|
|
16
|
-
type ButtonComponent = BaseComponentProto<CoreNamespace> & {
|
|
17
|
-
component: 'button';
|
|
16
|
+
type ButtonComponent = BaseComponentProto<CoreNamespace, 'button'> & {
|
|
18
17
|
text: string;
|
|
19
18
|
icon?: string;
|
|
20
19
|
state: {
|
|
@@ -26,12 +25,10 @@ type ButtonComponent = BaseComponentProto<CoreNamespace> & {
|
|
|
26
25
|
};
|
|
27
26
|
type GroupCollapsedState = 'open' | 'closed';
|
|
28
27
|
type DefaultGroupCollapsedState = GroupCollapsedState | 'auto';
|
|
29
|
-
type GroupHeaderComponent = BaseComponentProto<CoreNamespace> & {
|
|
30
|
-
component: 'group-header';
|
|
28
|
+
type GroupHeaderComponent = BaseComponentProto<CoreNamespace, 'group-header'> & {
|
|
31
29
|
children: AnyComponentProto[];
|
|
32
30
|
};
|
|
33
|
-
type GroupComponent = BaseComponentProto<CoreNamespace> & GroupComponentStyle & {
|
|
34
|
-
component: 'group';
|
|
31
|
+
type GroupComponent = BaseComponentProto<CoreNamespace, 'group'> & GroupComponentStyle & {
|
|
35
32
|
title?: string;
|
|
36
33
|
children: AnyComponentProto[];
|
|
37
34
|
headers?: GroupHeaderComponent[];
|
|
@@ -45,21 +42,18 @@ type GroupComponent = BaseComponentProto<CoreNamespace> & GroupComponentStyle &
|
|
|
45
42
|
*/
|
|
46
43
|
defaultCollapsibleState?: DefaultGroupCollapsedState;
|
|
47
44
|
};
|
|
48
|
-
type LabelComponent = BaseComponentProto<CoreNamespace> & {
|
|
49
|
-
component: 'label';
|
|
45
|
+
type LabelComponent = BaseComponentProto<CoreNamespace, 'label'> & {
|
|
50
46
|
bold?: boolean;
|
|
51
47
|
text: string;
|
|
52
48
|
};
|
|
53
|
-
type RectComponent = BaseComponentProto<CoreNamespace> & {
|
|
54
|
-
component: 'rect';
|
|
49
|
+
type RectComponent = BaseComponentProto<CoreNamespace, 'rect'> & {
|
|
55
50
|
color: string;
|
|
56
51
|
/**
|
|
57
52
|
* Set to true if the component should increase its size to fill the available space.
|
|
58
53
|
*/
|
|
59
54
|
grow?: boolean;
|
|
60
55
|
};
|
|
61
|
-
type SliderButtonComponent = BaseComponentProto<CoreNamespace> & {
|
|
62
|
-
component: 'slider_button';
|
|
56
|
+
type SliderButtonComponent = BaseComponentProto<CoreNamespace, 'slider_button'> & {
|
|
63
57
|
min: number;
|
|
64
58
|
max: number;
|
|
65
59
|
step: number;
|
|
@@ -70,21 +64,17 @@ type SliderButtonComponent = BaseComponentProto<CoreNamespace> & {
|
|
|
70
64
|
*/
|
|
71
65
|
grow?: boolean;
|
|
72
66
|
};
|
|
73
|
-
type SwitchComponent = BaseComponentProto<CoreNamespace> & {
|
|
74
|
-
component: 'switch';
|
|
67
|
+
type SwitchComponent = BaseComponentProto<CoreNamespace, 'switch'> & {
|
|
75
68
|
state: 'on' | 'off';
|
|
76
69
|
};
|
|
77
|
-
type TabComponent = BaseComponentProto<CoreNamespace> & {
|
|
78
|
-
component: 'tab';
|
|
70
|
+
type TabComponent = BaseComponentProto<CoreNamespace, 'tab'> & {
|
|
79
71
|
name: string;
|
|
80
72
|
child?: AnyComponentProto;
|
|
81
73
|
};
|
|
82
|
-
type TabsComponent = BaseComponentProto<CoreNamespace> & {
|
|
83
|
-
component: 'tabs';
|
|
74
|
+
type TabsComponent = BaseComponentProto<CoreNamespace, 'tabs'> & {
|
|
84
75
|
tabs: TabComponent[];
|
|
85
76
|
};
|
|
86
|
-
type TextInputComponent = BaseComponentProto<CoreNamespace> & {
|
|
87
|
-
component: 'text-input';
|
|
77
|
+
type TextInputComponent = BaseComponentProto<CoreNamespace, 'text-input'> & {
|
|
88
78
|
value: string;
|
|
89
79
|
};
|
|
90
80
|
type TimelineState = {
|
|
@@ -97,8 +87,7 @@ type TimelineState = {
|
|
|
97
87
|
totalTimeMillis: number;
|
|
98
88
|
currentTimeMillis: number;
|
|
99
89
|
};
|
|
100
|
-
type TimelineComponent = BaseComponentProto<CoreNamespace> & {
|
|
101
|
-
component: 'timeline';
|
|
90
|
+
type TimelineComponent = BaseComponentProto<CoreNamespace, 'timeline'> & {
|
|
102
91
|
state: TimelineState;
|
|
103
92
|
title?: string;
|
|
104
93
|
subtitles?: string[];
|
|
@@ -108,9 +97,7 @@ type TimelineComponent = BaseComponentProto<CoreNamespace> & {
|
|
|
108
97
|
};
|
|
109
98
|
type CoreComponent = ButtonComponent | GroupComponent | GroupHeaderComponent | LabelComponent | RectComponent | SliderButtonComponent | SwitchComponent | TabComponent | TabsComponent | TextInputComponent | TimelineComponent;
|
|
110
99
|
declare const isCoreComponent: (component: AnyComponentProto) => component is CoreComponent;
|
|
111
|
-
type ButtonPressMessage =
|
|
112
|
-
component: 'button';
|
|
113
|
-
};
|
|
100
|
+
type ButtonPressMessage = BaseClientComponentCall<CoreNamespace, 'press'>;
|
|
114
101
|
type GroupTitleChangeMessage = BaseClientComponentMessage<CoreNamespace> & {
|
|
115
102
|
component: 'group';
|
|
116
103
|
title: string;
|
|
@@ -126,9 +113,16 @@ type TextInputUpdateMessage = BaseClientComponentMessage<CoreNamespace> & {
|
|
|
126
113
|
component: 'text-input';
|
|
127
114
|
value: string;
|
|
128
115
|
};
|
|
129
|
-
type CoreComponentMessage =
|
|
130
|
-
|
|
116
|
+
type CoreComponentMessage = GroupTitleChangeMessage | SliderButtonUpdateMessage | SwitchToggleMessage | TextInputUpdateMessage;
|
|
117
|
+
interface CoreComponentCalls {
|
|
118
|
+
press: {
|
|
119
|
+
call: ButtonPressMessage;
|
|
120
|
+
return: true;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
declare const isCoreComponentMessage: <C extends "group" | "slider_button" | "switch" | "text-input">(message: BaseClientComponentMessage<string>, component: C) => message is CoreComponentMessage & {
|
|
131
124
|
component: C;
|
|
132
125
|
};
|
|
126
|
+
declare const isCoreComponentCall: <A extends "press">(call: BaseClientComponentCall<string, string>, action: A) => call is CoreComponentCalls[A]["call"];
|
|
133
127
|
|
|
134
|
-
export { type ButtonComponent, type ButtonPressMessage, type CoreComponent, type CoreComponentMessage, type CoreNamespace, type DefaultGroupCollapsedState, type Gradient, type GroupCollapsedState, type GroupComponent, type GroupHeaderComponent, type GroupTitleChangeMessage, type LabelComponent, type RectComponent, type SliderButtonComponent, type SliderButtonUpdateMessage, type SwitchComponent, type SwitchToggleMessage, type TabComponent, type TabsComponent, type TextInputComponent, type TextInputUpdateMessage, type TimelineComponent, type TimelineState, isCoreComponent, isCoreComponentMessage };
|
|
128
|
+
export { type ButtonComponent, type ButtonPressMessage, type CoreComponent, type CoreComponentCalls, type CoreComponentMessage, type CoreNamespace, type DefaultGroupCollapsedState, type Gradient, type GroupCollapsedState, type GroupComponent, type GroupHeaderComponent, type GroupTitleChangeMessage, type LabelComponent, type RectComponent, type SliderButtonComponent, type SliderButtonUpdateMessage, type SwitchComponent, type SwitchToggleMessage, type TabComponent, type TabsComponent, type TextInputComponent, type TextInputUpdateMessage, type TimelineComponent, type TimelineState, isCoreComponent, isCoreComponentCall, isCoreComponentMessage };
|
package/dist/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseComponentProto, AnyComponentProto, BaseClientComponentMessage } from './index.js';
|
|
1
|
+
import { BaseComponentProto, AnyComponentProto, BaseClientComponentCall, BaseClientComponentMessage } from './index.js';
|
|
2
2
|
import { GroupComponentStyle } from './styles.js';
|
|
3
3
|
import '@arcanejs/diff';
|
|
4
4
|
|
|
@@ -13,8 +13,7 @@ type Gradient = Array<{
|
|
|
13
13
|
*/
|
|
14
14
|
position: number;
|
|
15
15
|
}>;
|
|
16
|
-
type ButtonComponent = BaseComponentProto<CoreNamespace> & {
|
|
17
|
-
component: 'button';
|
|
16
|
+
type ButtonComponent = BaseComponentProto<CoreNamespace, 'button'> & {
|
|
18
17
|
text: string;
|
|
19
18
|
icon?: string;
|
|
20
19
|
state: {
|
|
@@ -26,12 +25,10 @@ type ButtonComponent = BaseComponentProto<CoreNamespace> & {
|
|
|
26
25
|
};
|
|
27
26
|
type GroupCollapsedState = 'open' | 'closed';
|
|
28
27
|
type DefaultGroupCollapsedState = GroupCollapsedState | 'auto';
|
|
29
|
-
type GroupHeaderComponent = BaseComponentProto<CoreNamespace> & {
|
|
30
|
-
component: 'group-header';
|
|
28
|
+
type GroupHeaderComponent = BaseComponentProto<CoreNamespace, 'group-header'> & {
|
|
31
29
|
children: AnyComponentProto[];
|
|
32
30
|
};
|
|
33
|
-
type GroupComponent = BaseComponentProto<CoreNamespace> & GroupComponentStyle & {
|
|
34
|
-
component: 'group';
|
|
31
|
+
type GroupComponent = BaseComponentProto<CoreNamespace, 'group'> & GroupComponentStyle & {
|
|
35
32
|
title?: string;
|
|
36
33
|
children: AnyComponentProto[];
|
|
37
34
|
headers?: GroupHeaderComponent[];
|
|
@@ -45,21 +42,18 @@ type GroupComponent = BaseComponentProto<CoreNamespace> & GroupComponentStyle &
|
|
|
45
42
|
*/
|
|
46
43
|
defaultCollapsibleState?: DefaultGroupCollapsedState;
|
|
47
44
|
};
|
|
48
|
-
type LabelComponent = BaseComponentProto<CoreNamespace> & {
|
|
49
|
-
component: 'label';
|
|
45
|
+
type LabelComponent = BaseComponentProto<CoreNamespace, 'label'> & {
|
|
50
46
|
bold?: boolean;
|
|
51
47
|
text: string;
|
|
52
48
|
};
|
|
53
|
-
type RectComponent = BaseComponentProto<CoreNamespace> & {
|
|
54
|
-
component: 'rect';
|
|
49
|
+
type RectComponent = BaseComponentProto<CoreNamespace, 'rect'> & {
|
|
55
50
|
color: string;
|
|
56
51
|
/**
|
|
57
52
|
* Set to true if the component should increase its size to fill the available space.
|
|
58
53
|
*/
|
|
59
54
|
grow?: boolean;
|
|
60
55
|
};
|
|
61
|
-
type SliderButtonComponent = BaseComponentProto<CoreNamespace> & {
|
|
62
|
-
component: 'slider_button';
|
|
56
|
+
type SliderButtonComponent = BaseComponentProto<CoreNamespace, 'slider_button'> & {
|
|
63
57
|
min: number;
|
|
64
58
|
max: number;
|
|
65
59
|
step: number;
|
|
@@ -70,21 +64,17 @@ type SliderButtonComponent = BaseComponentProto<CoreNamespace> & {
|
|
|
70
64
|
*/
|
|
71
65
|
grow?: boolean;
|
|
72
66
|
};
|
|
73
|
-
type SwitchComponent = BaseComponentProto<CoreNamespace> & {
|
|
74
|
-
component: 'switch';
|
|
67
|
+
type SwitchComponent = BaseComponentProto<CoreNamespace, 'switch'> & {
|
|
75
68
|
state: 'on' | 'off';
|
|
76
69
|
};
|
|
77
|
-
type TabComponent = BaseComponentProto<CoreNamespace> & {
|
|
78
|
-
component: 'tab';
|
|
70
|
+
type TabComponent = BaseComponentProto<CoreNamespace, 'tab'> & {
|
|
79
71
|
name: string;
|
|
80
72
|
child?: AnyComponentProto;
|
|
81
73
|
};
|
|
82
|
-
type TabsComponent = BaseComponentProto<CoreNamespace> & {
|
|
83
|
-
component: 'tabs';
|
|
74
|
+
type TabsComponent = BaseComponentProto<CoreNamespace, 'tabs'> & {
|
|
84
75
|
tabs: TabComponent[];
|
|
85
76
|
};
|
|
86
|
-
type TextInputComponent = BaseComponentProto<CoreNamespace> & {
|
|
87
|
-
component: 'text-input';
|
|
77
|
+
type TextInputComponent = BaseComponentProto<CoreNamespace, 'text-input'> & {
|
|
88
78
|
value: string;
|
|
89
79
|
};
|
|
90
80
|
type TimelineState = {
|
|
@@ -97,8 +87,7 @@ type TimelineState = {
|
|
|
97
87
|
totalTimeMillis: number;
|
|
98
88
|
currentTimeMillis: number;
|
|
99
89
|
};
|
|
100
|
-
type TimelineComponent = BaseComponentProto<CoreNamespace> & {
|
|
101
|
-
component: 'timeline';
|
|
90
|
+
type TimelineComponent = BaseComponentProto<CoreNamespace, 'timeline'> & {
|
|
102
91
|
state: TimelineState;
|
|
103
92
|
title?: string;
|
|
104
93
|
subtitles?: string[];
|
|
@@ -108,9 +97,7 @@ type TimelineComponent = BaseComponentProto<CoreNamespace> & {
|
|
|
108
97
|
};
|
|
109
98
|
type CoreComponent = ButtonComponent | GroupComponent | GroupHeaderComponent | LabelComponent | RectComponent | SliderButtonComponent | SwitchComponent | TabComponent | TabsComponent | TextInputComponent | TimelineComponent;
|
|
110
99
|
declare const isCoreComponent: (component: AnyComponentProto) => component is CoreComponent;
|
|
111
|
-
type ButtonPressMessage =
|
|
112
|
-
component: 'button';
|
|
113
|
-
};
|
|
100
|
+
type ButtonPressMessage = BaseClientComponentCall<CoreNamespace, 'press'>;
|
|
114
101
|
type GroupTitleChangeMessage = BaseClientComponentMessage<CoreNamespace> & {
|
|
115
102
|
component: 'group';
|
|
116
103
|
title: string;
|
|
@@ -126,9 +113,16 @@ type TextInputUpdateMessage = BaseClientComponentMessage<CoreNamespace> & {
|
|
|
126
113
|
component: 'text-input';
|
|
127
114
|
value: string;
|
|
128
115
|
};
|
|
129
|
-
type CoreComponentMessage =
|
|
130
|
-
|
|
116
|
+
type CoreComponentMessage = GroupTitleChangeMessage | SliderButtonUpdateMessage | SwitchToggleMessage | TextInputUpdateMessage;
|
|
117
|
+
interface CoreComponentCalls {
|
|
118
|
+
press: {
|
|
119
|
+
call: ButtonPressMessage;
|
|
120
|
+
return: true;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
declare const isCoreComponentMessage: <C extends "group" | "slider_button" | "switch" | "text-input">(message: BaseClientComponentMessage<string>, component: C) => message is CoreComponentMessage & {
|
|
131
124
|
component: C;
|
|
132
125
|
};
|
|
126
|
+
declare const isCoreComponentCall: <A extends "press">(call: BaseClientComponentCall<string, string>, action: A) => call is CoreComponentCalls[A]["call"];
|
|
133
127
|
|
|
134
|
-
export { type ButtonComponent, type ButtonPressMessage, type CoreComponent, type CoreComponentMessage, type CoreNamespace, type DefaultGroupCollapsedState, type Gradient, type GroupCollapsedState, type GroupComponent, type GroupHeaderComponent, type GroupTitleChangeMessage, type LabelComponent, type RectComponent, type SliderButtonComponent, type SliderButtonUpdateMessage, type SwitchComponent, type SwitchToggleMessage, type TabComponent, type TabsComponent, type TextInputComponent, type TextInputUpdateMessage, type TimelineComponent, type TimelineState, isCoreComponent, isCoreComponentMessage };
|
|
128
|
+
export { type ButtonComponent, type ButtonPressMessage, type CoreComponent, type CoreComponentCalls, type CoreComponentMessage, type CoreNamespace, type DefaultGroupCollapsedState, type Gradient, type GroupCollapsedState, type GroupComponent, type GroupHeaderComponent, type GroupTitleChangeMessage, type LabelComponent, type RectComponent, type SliderButtonComponent, type SliderButtonUpdateMessage, type SwitchComponent, type SwitchToggleMessage, type TabComponent, type TabsComponent, type TextInputComponent, type TextInputUpdateMessage, type TimelineComponent, type TimelineState, isCoreComponent, isCoreComponentCall, isCoreComponentMessage };
|
package/dist/core.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/core.ts
|
|
2
2
|
var isCoreComponent = (component) => component.namespace === "core";
|
|
3
3
|
var isCoreComponentMessage = (message, component) => message.namespace === "core" && message.component === component;
|
|
4
|
+
var isCoreComponentCall = (call, action) => call.namespace === "core" && call.action === action;
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
exports.isCoreComponent = isCoreComponent; exports.isCoreComponentCall = isCoreComponentCall; exports.isCoreComponentMessage = isCoreComponentMessage;
|
package/dist/core.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// src/core.ts
|
|
2
2
|
var isCoreComponent = (component) => component.namespace === "core";
|
|
3
3
|
var isCoreComponentMessage = (message, component) => message.namespace === "core" && message.component === component;
|
|
4
|
+
var isCoreComponentCall = (call, action) => call.namespace === "core" && call.action === action;
|
|
4
5
|
export {
|
|
5
6
|
isCoreComponent,
|
|
7
|
+
isCoreComponentCall,
|
|
6
8
|
isCoreComponentMessage
|
|
7
9
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Diff } from '@arcanejs/diff';
|
|
2
2
|
|
|
3
|
-
type BaseComponentProto<Namespace extends string> = {
|
|
3
|
+
type BaseComponentProto<Namespace extends string, Component extends string> = {
|
|
4
4
|
key: number;
|
|
5
5
|
namespace: Namespace;
|
|
6
|
+
component: Component;
|
|
6
7
|
};
|
|
7
|
-
type AnyComponentProto = BaseComponentProto<string>;
|
|
8
|
+
type AnyComponentProto = BaseComponentProto<string, string>;
|
|
8
9
|
type MetadataMessage = {
|
|
9
10
|
type: 'metadata';
|
|
10
11
|
/**
|
|
@@ -14,19 +15,48 @@ type MetadataMessage = {
|
|
|
14
15
|
};
|
|
15
16
|
type SendTreeMsg = {
|
|
16
17
|
type: 'tree-full';
|
|
17
|
-
root: BaseComponentProto<string>;
|
|
18
|
+
root: BaseComponentProto<string, string>;
|
|
18
19
|
};
|
|
19
20
|
type UpdateTreeMsg = {
|
|
20
21
|
type: 'tree-diff';
|
|
21
|
-
diff: Diff<BaseComponentProto<string>>;
|
|
22
|
+
diff: Diff<BaseComponentProto<string, string>>;
|
|
22
23
|
};
|
|
23
|
-
type
|
|
24
|
+
type CallResponseMsg<Namespace extends string, T> = {
|
|
25
|
+
type: 'call-response';
|
|
26
|
+
namespace: Namespace;
|
|
27
|
+
requestId: number;
|
|
28
|
+
} & ({
|
|
29
|
+
success: true;
|
|
30
|
+
returnValue: T;
|
|
31
|
+
} | {
|
|
32
|
+
success: false;
|
|
33
|
+
errorMessage: string;
|
|
34
|
+
});
|
|
35
|
+
type ServerMessage = MetadataMessage | SendTreeMsg | UpdateTreeMsg | CallResponseMsg<string, unknown>;
|
|
24
36
|
type BaseClientComponentMessage<Namespace extends string> = {
|
|
25
37
|
type: 'component-message';
|
|
26
38
|
namespace: Namespace;
|
|
27
39
|
componentKey: number;
|
|
28
40
|
};
|
|
41
|
+
type BaseClientComponentCall<Namespace extends string, Action extends string> = {
|
|
42
|
+
type: 'component-call';
|
|
43
|
+
namespace: Namespace;
|
|
44
|
+
componentKey: number;
|
|
45
|
+
requestId: number;
|
|
46
|
+
action: Action;
|
|
47
|
+
};
|
|
48
|
+
type BaseClientComponentCallPair<Namespace extends string, Action extends string, Call extends BaseClientComponentCall<Namespace, Action>, Return = unknown> = {
|
|
49
|
+
call: Call;
|
|
50
|
+
return: Return;
|
|
51
|
+
};
|
|
52
|
+
type CallForPair<Namespace extends string, Pairs, Action extends string & keyof Pairs> = Pairs extends Record<Action, {
|
|
53
|
+
call: infer R;
|
|
54
|
+
}> ? Omit<R & BaseClientComponentCall<Namespace, Action>, 'requestId'> : never;
|
|
55
|
+
type ReturnForPair<Pairs, Action extends string & keyof Pairs> = Pairs extends Record<Action, {
|
|
56
|
+
return: infer R;
|
|
57
|
+
}> ? R : never;
|
|
29
58
|
type AnyClientComponentMessage = BaseClientComponentMessage<string>;
|
|
30
|
-
type
|
|
59
|
+
type AnyClientComponentCall = BaseClientComponentCall<string, string>;
|
|
60
|
+
type ClientMessage = AnyClientComponentMessage | AnyClientComponentCall;
|
|
31
61
|
|
|
32
|
-
export type { AnyClientComponentMessage, AnyComponentProto, BaseClientComponentMessage, BaseComponentProto, ClientMessage, MetadataMessage, SendTreeMsg, ServerMessage, UpdateTreeMsg };
|
|
62
|
+
export type { AnyClientComponentCall, AnyClientComponentMessage, AnyComponentProto, BaseClientComponentCall, BaseClientComponentCallPair, BaseClientComponentMessage, BaseComponentProto, CallForPair, CallResponseMsg, ClientMessage, MetadataMessage, ReturnForPair, SendTreeMsg, ServerMessage, UpdateTreeMsg };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Diff } from '@arcanejs/diff';
|
|
2
2
|
|
|
3
|
-
type BaseComponentProto<Namespace extends string> = {
|
|
3
|
+
type BaseComponentProto<Namespace extends string, Component extends string> = {
|
|
4
4
|
key: number;
|
|
5
5
|
namespace: Namespace;
|
|
6
|
+
component: Component;
|
|
6
7
|
};
|
|
7
|
-
type AnyComponentProto = BaseComponentProto<string>;
|
|
8
|
+
type AnyComponentProto = BaseComponentProto<string, string>;
|
|
8
9
|
type MetadataMessage = {
|
|
9
10
|
type: 'metadata';
|
|
10
11
|
/**
|
|
@@ -14,19 +15,48 @@ type MetadataMessage = {
|
|
|
14
15
|
};
|
|
15
16
|
type SendTreeMsg = {
|
|
16
17
|
type: 'tree-full';
|
|
17
|
-
root: BaseComponentProto<string>;
|
|
18
|
+
root: BaseComponentProto<string, string>;
|
|
18
19
|
};
|
|
19
20
|
type UpdateTreeMsg = {
|
|
20
21
|
type: 'tree-diff';
|
|
21
|
-
diff: Diff<BaseComponentProto<string>>;
|
|
22
|
+
diff: Diff<BaseComponentProto<string, string>>;
|
|
22
23
|
};
|
|
23
|
-
type
|
|
24
|
+
type CallResponseMsg<Namespace extends string, T> = {
|
|
25
|
+
type: 'call-response';
|
|
26
|
+
namespace: Namespace;
|
|
27
|
+
requestId: number;
|
|
28
|
+
} & ({
|
|
29
|
+
success: true;
|
|
30
|
+
returnValue: T;
|
|
31
|
+
} | {
|
|
32
|
+
success: false;
|
|
33
|
+
errorMessage: string;
|
|
34
|
+
});
|
|
35
|
+
type ServerMessage = MetadataMessage | SendTreeMsg | UpdateTreeMsg | CallResponseMsg<string, unknown>;
|
|
24
36
|
type BaseClientComponentMessage<Namespace extends string> = {
|
|
25
37
|
type: 'component-message';
|
|
26
38
|
namespace: Namespace;
|
|
27
39
|
componentKey: number;
|
|
28
40
|
};
|
|
41
|
+
type BaseClientComponentCall<Namespace extends string, Action extends string> = {
|
|
42
|
+
type: 'component-call';
|
|
43
|
+
namespace: Namespace;
|
|
44
|
+
componentKey: number;
|
|
45
|
+
requestId: number;
|
|
46
|
+
action: Action;
|
|
47
|
+
};
|
|
48
|
+
type BaseClientComponentCallPair<Namespace extends string, Action extends string, Call extends BaseClientComponentCall<Namespace, Action>, Return = unknown> = {
|
|
49
|
+
call: Call;
|
|
50
|
+
return: Return;
|
|
51
|
+
};
|
|
52
|
+
type CallForPair<Namespace extends string, Pairs, Action extends string & keyof Pairs> = Pairs extends Record<Action, {
|
|
53
|
+
call: infer R;
|
|
54
|
+
}> ? Omit<R & BaseClientComponentCall<Namespace, Action>, 'requestId'> : never;
|
|
55
|
+
type ReturnForPair<Pairs, Action extends string & keyof Pairs> = Pairs extends Record<Action, {
|
|
56
|
+
return: infer R;
|
|
57
|
+
}> ? R : never;
|
|
29
58
|
type AnyClientComponentMessage = BaseClientComponentMessage<string>;
|
|
30
|
-
type
|
|
59
|
+
type AnyClientComponentCall = BaseClientComponentCall<string, string>;
|
|
60
|
+
type ClientMessage = AnyClientComponentMessage | AnyClientComponentCall;
|
|
31
61
|
|
|
32
|
-
export type { AnyClientComponentMessage, AnyComponentProto, BaseClientComponentMessage, BaseComponentProto, ClientMessage, MetadataMessage, SendTreeMsg, ServerMessage, UpdateTreeMsg };
|
|
62
|
+
export type { AnyClientComponentCall, AnyClientComponentMessage, AnyComponentProto, BaseClientComponentCall, BaseClientComponentCallPair, BaseClientComponentMessage, BaseComponentProto, CallForPair, CallResponseMsg, ClientMessage, MetadataMessage, ReturnForPair, SendTreeMsg, ServerMessage, UpdateTreeMsg };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcanejs/protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The JSON protocol types for the @arcanejs Toolkit",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/ArcaneWizards/arcanejs.git"
|
|
14
14
|
},
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|