@player-ui/types 0.0.1-next.1
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/dist/index.cjs.js +3 -0
- package/dist/index.d.ts +330 -0
- package/dist/index.esm.js +2 -0
- package/package.json +15 -0
- package/src/index.ts +426 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An asset is the smallest unit of user interaction in a player view
|
|
3
|
+
*/
|
|
4
|
+
interface Asset<T extends string = string> {
|
|
5
|
+
/** Each asset requires a unique id per view */
|
|
6
|
+
id: string;
|
|
7
|
+
/** The asset type determines the semantics of how a user interacts with a page */
|
|
8
|
+
type: T;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* An asset that contains a Binding.
|
|
13
|
+
*/
|
|
14
|
+
interface AssetBinding extends Asset {
|
|
15
|
+
/** A binding that points to somewhere in the data model */
|
|
16
|
+
binding: Binding;
|
|
17
|
+
}
|
|
18
|
+
/** A single case statement to use in a switch */
|
|
19
|
+
interface SwitchCase<T extends Asset = Asset> {
|
|
20
|
+
/** The Asset to use if this case is applicable */
|
|
21
|
+
asset: T;
|
|
22
|
+
/** An expression to execute to determine if this case applies */
|
|
23
|
+
case: Expression | true;
|
|
24
|
+
}
|
|
25
|
+
/** A switch can replace an asset with the applicable case on first render */
|
|
26
|
+
declare type Switch<T extends Asset = Asset> = SwitchCase<T>[];
|
|
27
|
+
/** An object that contains an asset */
|
|
28
|
+
declare type AssetWrapper<T extends Asset = Asset> = {
|
|
29
|
+
/** An asset instance */
|
|
30
|
+
asset: T;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
};
|
|
33
|
+
declare type AssetWrapperOrSwitch<T extends Asset = Asset> = (AssetWrapper<T> & {
|
|
34
|
+
/** The dynamicSwitch property can't exist at the same time as 'asset' */
|
|
35
|
+
dynamicSwitch?: never;
|
|
36
|
+
/** The staticSwitch property can't exist at the same time as 'asset' */
|
|
37
|
+
staticSwitch?: never;
|
|
38
|
+
}) | (StaticSwitch<T> & {
|
|
39
|
+
/** The staticSwitch property can't exist at the same time as 'asset' */
|
|
40
|
+
asset?: never;
|
|
41
|
+
/** The staticSwitch property can't exist at the same time as 'dynamicSwitch' */
|
|
42
|
+
dynamicSwitch?: never;
|
|
43
|
+
}) | (DynamicSwitch<T> & {
|
|
44
|
+
/** The dynamicSwitch property can't exist at the same time as 'asset' */
|
|
45
|
+
asset?: never;
|
|
46
|
+
/** The dynamicSwitch property can't exist at the same time as 'staticSwitch' */
|
|
47
|
+
staticSwitch?: never;
|
|
48
|
+
});
|
|
49
|
+
declare type AssetSwitch<T extends Asset = Asset> = StaticSwitch<T> | DynamicSwitch<T>;
|
|
50
|
+
interface StaticSwitch<T extends Asset = Asset> {
|
|
51
|
+
/** A static switch only evaluates the applicable base on first render of the view */
|
|
52
|
+
staticSwitch: Switch<T>;
|
|
53
|
+
}
|
|
54
|
+
interface DynamicSwitch<T extends Asset = Asset> {
|
|
55
|
+
/** A dynamic switch re-evaluates the applicable case as data changes */
|
|
56
|
+
dynamicSwitch: Switch<T>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Expressions are a specialized way of executing code.
|
|
60
|
+
* If the expression is a composite, the last expression executed is the return value
|
|
61
|
+
*/
|
|
62
|
+
declare type Expression = string | string[];
|
|
63
|
+
declare type ExpressionRef = `@[${string}]@`;
|
|
64
|
+
/**
|
|
65
|
+
* Bindings describe locations in the data model.
|
|
66
|
+
*/
|
|
67
|
+
declare type Binding = string;
|
|
68
|
+
declare type BindingRef = `{{${Binding}}}`;
|
|
69
|
+
/**
|
|
70
|
+
* The data-model is the location that all user data is stored
|
|
71
|
+
*/
|
|
72
|
+
declare type DataModel = Record<any, unknown>;
|
|
73
|
+
/** The navigation section of the flow describes a State Machine for the user. */
|
|
74
|
+
declare type Navigation = {
|
|
75
|
+
/** The name of the Flow to begin on */
|
|
76
|
+
BEGIN: string;
|
|
77
|
+
} & Record<string, string | NavigationFlow>;
|
|
78
|
+
/** An object with an expression in it */
|
|
79
|
+
interface ExpressionObject {
|
|
80
|
+
/** The expression to run */
|
|
81
|
+
exp?: Expression;
|
|
82
|
+
}
|
|
83
|
+
/** A state machine in the navigation */
|
|
84
|
+
interface NavigationFlow {
|
|
85
|
+
/** The first state to kick off the state machine */
|
|
86
|
+
startState: string;
|
|
87
|
+
/** An optional expression to run when this Flow starts */
|
|
88
|
+
onStart?: Expression | ExpressionObject;
|
|
89
|
+
/** An optional expression to run when this Flow ends */
|
|
90
|
+
onEnd?: Expression | ExpressionObject;
|
|
91
|
+
[key: string]: undefined | string | Expression | ExpressionObject | NavigationFlowState;
|
|
92
|
+
}
|
|
93
|
+
declare type NavigationFlowTransition = Record<string, string>;
|
|
94
|
+
interface CommentBase {
|
|
95
|
+
/** Add comments that will not be processing, but are useful for code explanation */
|
|
96
|
+
_comment?: string;
|
|
97
|
+
}
|
|
98
|
+
/** The base representation of a state within a Flow */
|
|
99
|
+
interface NavigationBaseState<T extends string> extends CommentBase {
|
|
100
|
+
/** A property to determine the type of state this is */
|
|
101
|
+
state_type: T;
|
|
102
|
+
/** An optional expression to run when this view renders */
|
|
103
|
+
onStart?: Expression | ExpressionObject;
|
|
104
|
+
/** An optional expression to run before view transition */
|
|
105
|
+
onEnd?: Expression | ExpressionObject;
|
|
106
|
+
/**
|
|
107
|
+
* TS gets really confused with both the ActionState and the onStart state both declaring the `exp` property
|
|
108
|
+
* So this explicity says there should never be an exp prop on a state node that's not of type 'ACTION'
|
|
109
|
+
*/
|
|
110
|
+
exp?: T extends 'ACTION' ? Expression : never;
|
|
111
|
+
}
|
|
112
|
+
/** A generic state that can transition to another state */
|
|
113
|
+
interface NavigationFlowTransitionableState<T extends string> extends NavigationBaseState<T> {
|
|
114
|
+
/** A mapping of transition-name to FlowState name */
|
|
115
|
+
transitions: NavigationFlowTransition;
|
|
116
|
+
}
|
|
117
|
+
/** A state representing a view */
|
|
118
|
+
interface NavigationFlowViewState extends NavigationFlowTransitionableState<'VIEW'> {
|
|
119
|
+
/** An id corresponding to a view from the 'views' array */
|
|
120
|
+
ref: string;
|
|
121
|
+
/** View meta-properties */
|
|
122
|
+
attributes?: {
|
|
123
|
+
[key: string]: any;
|
|
124
|
+
};
|
|
125
|
+
/** Any additional properties are forwarded as options, like param */
|
|
126
|
+
[key: string]: unknown;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* An END state of the flow.
|
|
130
|
+
*/
|
|
131
|
+
interface NavigationFlowEndState extends NavigationBaseState<'END'> {
|
|
132
|
+
/**
|
|
133
|
+
* A description of _how_ the flow ended.
|
|
134
|
+
* If this is a flow started from another flow, the outcome determines the flow transition
|
|
135
|
+
*/
|
|
136
|
+
outcome: string;
|
|
137
|
+
/** Any additional properties are forwarded as options, like param */
|
|
138
|
+
[key: string]: unknown;
|
|
139
|
+
}
|
|
140
|
+
/** Action states execute an expression to determine the next state to transition to */
|
|
141
|
+
interface NavigationFlowActionState extends NavigationFlowTransitionableState<'ACTION'> {
|
|
142
|
+
/**
|
|
143
|
+
* An expression to execute.
|
|
144
|
+
* The return value determines the transition to take
|
|
145
|
+
*/
|
|
146
|
+
exp: Expression;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* External Flow states represent states in the FSM that can't be resolved internally in Player.
|
|
150
|
+
* The flow will wait for the embedded application to manage moving to the next state via a transition
|
|
151
|
+
*/
|
|
152
|
+
interface NavigationFlowExternalState extends NavigationFlowTransitionableState<'EXTERNAL'> {
|
|
153
|
+
/** A reference for this external state */
|
|
154
|
+
ref: string;
|
|
155
|
+
/** Any additional properties are forwarded as options */
|
|
156
|
+
[key: string]: unknown;
|
|
157
|
+
}
|
|
158
|
+
interface NavigationFlowFlowState extends NavigationFlowTransitionableState<'FLOW'> {
|
|
159
|
+
/** A reference to a FLOW id state to run */
|
|
160
|
+
ref: string;
|
|
161
|
+
}
|
|
162
|
+
declare type NavigationFlowState = NavigationFlowViewState | NavigationFlowEndState | NavigationFlowFlowState | NavigationFlowActionState | NavigationFlowExternalState;
|
|
163
|
+
/** The data at the end of a flow */
|
|
164
|
+
interface FlowResult {
|
|
165
|
+
/** The outcome describes _how_ the flow ended (forwards, backwards, etc) */
|
|
166
|
+
endState: NavigationFlowEndState;
|
|
167
|
+
/** The serialized data-model */
|
|
168
|
+
data?: any;
|
|
169
|
+
}
|
|
170
|
+
/** Any object that contains 1 or more templates */
|
|
171
|
+
interface Templatable {
|
|
172
|
+
/** A list of templates to process for this node */
|
|
173
|
+
template?: Template[];
|
|
174
|
+
}
|
|
175
|
+
/** A template describes a mapping from a data array -> array of objects */
|
|
176
|
+
interface Template<ValueType = unknown, Key extends string = string> {
|
|
177
|
+
/** A pointer to the data-model containing an array of elements to map over */
|
|
178
|
+
data: Binding;
|
|
179
|
+
/**
|
|
180
|
+
* The template to iterate over using each value in the supplied template data.
|
|
181
|
+
* Any reference to _index_ is replaced with the current iteration index.
|
|
182
|
+
*/
|
|
183
|
+
value: ValueType;
|
|
184
|
+
/**
|
|
185
|
+
* A property on the parent object to store the new map under.
|
|
186
|
+
* If it already exists, values are appended to the end.
|
|
187
|
+
*/
|
|
188
|
+
output: Key;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The Schema organizes all content related to Data and it's types
|
|
192
|
+
*/
|
|
193
|
+
declare namespace Schema {
|
|
194
|
+
/** The authored schema object in the JSON payload */
|
|
195
|
+
interface Schema {
|
|
196
|
+
/** The ROOT object is the top level object to use */
|
|
197
|
+
ROOT: Node;
|
|
198
|
+
/** Any additional keys are properties of the ROOT object */
|
|
199
|
+
[key: string]: Node;
|
|
200
|
+
}
|
|
201
|
+
/** A Node describes a specific object in the tree */
|
|
202
|
+
interface Node {
|
|
203
|
+
/** Each property describes a property of the object */
|
|
204
|
+
[key: string]: DataType;
|
|
205
|
+
}
|
|
206
|
+
/** Each prop in the object can have a specific DataType */
|
|
207
|
+
interface DataType<T = unknown> {
|
|
208
|
+
/** The reference of the base type to use */
|
|
209
|
+
type: string;
|
|
210
|
+
/** The referenced object represents an array rather than an object */
|
|
211
|
+
isArray?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Any additional validations that are associated with this property
|
|
214
|
+
* These will add to any base validations associated with the "type"
|
|
215
|
+
*/
|
|
216
|
+
validation?: Validation.Reference[];
|
|
217
|
+
/**
|
|
218
|
+
* A reference to a specific data format to use.
|
|
219
|
+
* If none is specified, will fallback to that of the base type
|
|
220
|
+
*/
|
|
221
|
+
format?: Formatting.Reference;
|
|
222
|
+
/**
|
|
223
|
+
* A default value for this property.
|
|
224
|
+
* Any reads for this property will result in this default value being written to the model.
|
|
225
|
+
*/
|
|
226
|
+
default?: T;
|
|
227
|
+
/** Any additional options */
|
|
228
|
+
[key: string]: unknown;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/** Namespace to wrap up core functionality to be used by the Language Service */
|
|
232
|
+
declare namespace Language {
|
|
233
|
+
/**
|
|
234
|
+
* Helper to compliment `Schema.DataType` to provide a way to export a reference to a data type instead of the whole object
|
|
235
|
+
*/
|
|
236
|
+
interface DataTypeRef {
|
|
237
|
+
/** Name of the type in Player Core */
|
|
238
|
+
type: string;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/** A spot for formatting */
|
|
242
|
+
declare namespace Formatting {
|
|
243
|
+
/** A reference to a specific formatter */
|
|
244
|
+
interface Reference {
|
|
245
|
+
/** The name of the formatter (and de-formatter) to use */
|
|
246
|
+
type: string;
|
|
247
|
+
/** Any additional properties will be passed as options to the formatter function */
|
|
248
|
+
[key: string]: unknown;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/** A space for all thing validation */
|
|
252
|
+
declare namespace Validation {
|
|
253
|
+
/**
|
|
254
|
+
* How serious are you about this error?
|
|
255
|
+
* Warning validations are reserved for errors that could be ignored by the user without consequence
|
|
256
|
+
* Errors must be fixed before proceeding
|
|
257
|
+
*/
|
|
258
|
+
type Severity = 'error' | 'warning';
|
|
259
|
+
/**
|
|
260
|
+
* When to _first_ start caring about a validation of a data-val.
|
|
261
|
+
*
|
|
262
|
+
* load - only check once the first time the binding appears on screen
|
|
263
|
+
* change - check anytime the data changes
|
|
264
|
+
* navigation - check once the user attempts to navigate away from a view
|
|
265
|
+
*/
|
|
266
|
+
type Trigger = 'navigation' | 'change' | 'load';
|
|
267
|
+
/**
|
|
268
|
+
* Where the error/warning should be displayed.
|
|
269
|
+
* - `field` is the default display target. This renders the error/warning directly underneath the field.
|
|
270
|
+
* - `section` is used to display a message at a parent node that is designated as a "section"
|
|
271
|
+
* - `page` a special section used to display a message at the top of the page.
|
|
272
|
+
*/
|
|
273
|
+
type DisplayTarget = 'page' | 'section' | 'field';
|
|
274
|
+
/** A reference to a validation object */
|
|
275
|
+
interface Reference {
|
|
276
|
+
/**
|
|
277
|
+
* The name of the referenced validation type
|
|
278
|
+
* This will be used to lookup the proper handler
|
|
279
|
+
*/
|
|
280
|
+
type: string;
|
|
281
|
+
/** An optional means of overriding the default message if the validation is triggered */
|
|
282
|
+
message?: string;
|
|
283
|
+
/** An optional means of overriding the default severity of the validation if triggered */
|
|
284
|
+
severity?: Severity;
|
|
285
|
+
/** When to run this particular validation */
|
|
286
|
+
trigger?: Trigger;
|
|
287
|
+
/**
|
|
288
|
+
* Each validation is passed the value of the data to run it's validation against.
|
|
289
|
+
* By default, this is the value stored in the data-model (deformatted).
|
|
290
|
+
* In the off chance you'd like this validator to run against the formatted value (the one the user sees), set this option
|
|
291
|
+
*/
|
|
292
|
+
dataTarget?: 'formatted' | 'deformatted';
|
|
293
|
+
/** Where the error should be displayed */
|
|
294
|
+
displayTarget?: DisplayTarget;
|
|
295
|
+
/** Additional props to send down to a Validator */
|
|
296
|
+
[key: string]: unknown;
|
|
297
|
+
}
|
|
298
|
+
interface CrossfieldReference extends Reference {
|
|
299
|
+
/** The binding to associate this validation with */
|
|
300
|
+
ref?: Binding;
|
|
301
|
+
/** Cross-field references and validation must run against the default (deformatted) value */
|
|
302
|
+
dataTarget?: never;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
declare type View<T extends Asset = Asset> = unknown extends T['validation'] ? T & {
|
|
306
|
+
/** Each view can optionally supply a list of validations to run against a particular view */
|
|
307
|
+
validation?: Array<Validation.CrossfieldReference>;
|
|
308
|
+
} : T;
|
|
309
|
+
/**
|
|
310
|
+
* The JSON payload for running Player
|
|
311
|
+
*/
|
|
312
|
+
interface Flow<T extends Asset = Asset> {
|
|
313
|
+
/** A unique identifier for the flow */
|
|
314
|
+
id: string;
|
|
315
|
+
/** A list of views (each with an ID) that can be shown to a user */
|
|
316
|
+
views?: Array<View<T>>;
|
|
317
|
+
/**
|
|
318
|
+
* The schema for the supplied (or referenced data).
|
|
319
|
+
* This is used for validation, formatting, etc
|
|
320
|
+
*/
|
|
321
|
+
schema?: Schema.Schema;
|
|
322
|
+
/** Any initial data that the flow can use */
|
|
323
|
+
data?: DataModel;
|
|
324
|
+
/** A state machine to drive a user through the experience */
|
|
325
|
+
navigation: Navigation;
|
|
326
|
+
/** Other keys can be present. We just don't know what they are */
|
|
327
|
+
[key: string]: unknown;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export { Asset, AssetBinding, AssetSwitch, AssetWrapper, AssetWrapperOrSwitch, Binding, BindingRef, DataModel, DynamicSwitch, Expression, ExpressionObject, ExpressionRef, Flow, FlowResult, Formatting, Language, Navigation, NavigationBaseState, NavigationFlow, NavigationFlowActionState, NavigationFlowEndState, NavigationFlowExternalState, NavigationFlowFlowState, NavigationFlowState, NavigationFlowTransition, NavigationFlowTransitionableState, NavigationFlowViewState, Schema, StaticSwitch, Switch, SwitchCase, Templatable, Template, Validation, View };
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@player-ui/types",
|
|
3
|
+
"version": "0.0.1-next.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"registry": "https://registry.npmjs.org"
|
|
7
|
+
},
|
|
8
|
+
"peerDependencies": {},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@babel/runtime": "7.15.4"
|
|
11
|
+
},
|
|
12
|
+
"main": "dist/index.cjs.js",
|
|
13
|
+
"module": "dist/index.esm.js",
|
|
14
|
+
"typings": "dist/index.d.ts"
|
|
15
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An asset is the smallest unit of user interaction in a player view
|
|
3
|
+
*/
|
|
4
|
+
export interface Asset<T extends string = string> {
|
|
5
|
+
/** Each asset requires a unique id per view */
|
|
6
|
+
id: string;
|
|
7
|
+
|
|
8
|
+
/** The asset type determines the semantics of how a user interacts with a page */
|
|
9
|
+
type: T;
|
|
10
|
+
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* An asset that contains a Binding.
|
|
15
|
+
*/
|
|
16
|
+
export interface AssetBinding extends Asset {
|
|
17
|
+
/** A binding that points to somewhere in the data model */
|
|
18
|
+
binding: Binding;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A single case statement to use in a switch */
|
|
22
|
+
export interface SwitchCase<T extends Asset = Asset> {
|
|
23
|
+
/** The Asset to use if this case is applicable */
|
|
24
|
+
asset: T;
|
|
25
|
+
|
|
26
|
+
/** An expression to execute to determine if this case applies */
|
|
27
|
+
case: Expression | true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A switch can replace an asset with the applicable case on first render */
|
|
31
|
+
export type Switch<T extends Asset = Asset> = SwitchCase<T>[];
|
|
32
|
+
|
|
33
|
+
/** An object that contains an asset */
|
|
34
|
+
export type AssetWrapper<T extends Asset = Asset> = {
|
|
35
|
+
/** An asset instance */
|
|
36
|
+
asset: T;
|
|
37
|
+
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type AssetWrapperOrSwitch<T extends Asset = Asset> =
|
|
42
|
+
| (AssetWrapper<T> & {
|
|
43
|
+
/** The dynamicSwitch property can't exist at the same time as 'asset' */
|
|
44
|
+
dynamicSwitch?: never;
|
|
45
|
+
|
|
46
|
+
/** The staticSwitch property can't exist at the same time as 'asset' */
|
|
47
|
+
staticSwitch?: never;
|
|
48
|
+
})
|
|
49
|
+
| (StaticSwitch<T> & {
|
|
50
|
+
/** The staticSwitch property can't exist at the same time as 'asset' */
|
|
51
|
+
asset?: never;
|
|
52
|
+
|
|
53
|
+
/** The staticSwitch property can't exist at the same time as 'dynamicSwitch' */
|
|
54
|
+
dynamicSwitch?: never;
|
|
55
|
+
})
|
|
56
|
+
| (DynamicSwitch<T> & {
|
|
57
|
+
/** The dynamicSwitch property can't exist at the same time as 'asset' */
|
|
58
|
+
asset?: never;
|
|
59
|
+
|
|
60
|
+
/** The dynamicSwitch property can't exist at the same time as 'staticSwitch' */
|
|
61
|
+
staticSwitch?: never;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export type AssetSwitch<T extends Asset = Asset> =
|
|
65
|
+
| StaticSwitch<T>
|
|
66
|
+
| DynamicSwitch<T>;
|
|
67
|
+
|
|
68
|
+
export interface StaticSwitch<T extends Asset = Asset> {
|
|
69
|
+
/** A static switch only evaluates the applicable base on first render of the view */
|
|
70
|
+
staticSwitch: Switch<T>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface DynamicSwitch<T extends Asset = Asset> {
|
|
74
|
+
/** A dynamic switch re-evaluates the applicable case as data changes */
|
|
75
|
+
dynamicSwitch: Switch<T>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Expressions are a specialized way of executing code.
|
|
80
|
+
* If the expression is a composite, the last expression executed is the return value
|
|
81
|
+
*/
|
|
82
|
+
export type Expression = string | string[];
|
|
83
|
+
export type ExpressionRef = `@[${string}]@`;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Bindings describe locations in the data model.
|
|
87
|
+
*/
|
|
88
|
+
export type Binding = string;
|
|
89
|
+
export type BindingRef = `{{${Binding}}}`;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The data-model is the location that all user data is stored
|
|
93
|
+
*/
|
|
94
|
+
export type DataModel = Record<any, unknown>;
|
|
95
|
+
|
|
96
|
+
/** The navigation section of the flow describes a State Machine for the user. */
|
|
97
|
+
export type Navigation = {
|
|
98
|
+
/** The name of the Flow to begin on */
|
|
99
|
+
BEGIN: string;
|
|
100
|
+
} & Record<string, string | NavigationFlow>;
|
|
101
|
+
|
|
102
|
+
/** An object with an expression in it */
|
|
103
|
+
export interface ExpressionObject {
|
|
104
|
+
/** The expression to run */
|
|
105
|
+
exp?: Expression;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** A state machine in the navigation */
|
|
109
|
+
export interface NavigationFlow {
|
|
110
|
+
/** The first state to kick off the state machine */
|
|
111
|
+
startState: string;
|
|
112
|
+
|
|
113
|
+
/** An optional expression to run when this Flow starts */
|
|
114
|
+
onStart?: Expression | ExpressionObject;
|
|
115
|
+
|
|
116
|
+
/** An optional expression to run when this Flow ends */
|
|
117
|
+
onEnd?: Expression | ExpressionObject;
|
|
118
|
+
|
|
119
|
+
[key: string]:
|
|
120
|
+
| undefined
|
|
121
|
+
| string
|
|
122
|
+
| Expression
|
|
123
|
+
| ExpressionObject
|
|
124
|
+
| NavigationFlowState;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export type NavigationFlowTransition = Record<string, string>;
|
|
128
|
+
|
|
129
|
+
interface CommentBase {
|
|
130
|
+
/** Add comments that will not be processing, but are useful for code explanation */
|
|
131
|
+
_comment?: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The base representation of a state within a Flow */
|
|
135
|
+
export interface NavigationBaseState<T extends string> extends CommentBase {
|
|
136
|
+
/** A property to determine the type of state this is */
|
|
137
|
+
state_type: T;
|
|
138
|
+
|
|
139
|
+
/** An optional expression to run when this view renders */
|
|
140
|
+
onStart?: Expression | ExpressionObject;
|
|
141
|
+
|
|
142
|
+
/** An optional expression to run before view transition */
|
|
143
|
+
onEnd?: Expression | ExpressionObject;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* TS gets really confused with both the ActionState and the onStart state both declaring the `exp` property
|
|
147
|
+
* So this explicity says there should never be an exp prop on a state node that's not of type 'ACTION'
|
|
148
|
+
*/
|
|
149
|
+
exp?: T extends 'ACTION' ? Expression : never;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** A generic state that can transition to another state */
|
|
153
|
+
export interface NavigationFlowTransitionableState<T extends string>
|
|
154
|
+
extends NavigationBaseState<T> {
|
|
155
|
+
/** A mapping of transition-name to FlowState name */
|
|
156
|
+
transitions: NavigationFlowTransition;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** A state representing a view */
|
|
160
|
+
export interface NavigationFlowViewState
|
|
161
|
+
extends NavigationFlowTransitionableState<'VIEW'> {
|
|
162
|
+
/** An id corresponding to a view from the 'views' array */
|
|
163
|
+
ref: string;
|
|
164
|
+
|
|
165
|
+
/** View meta-properties */
|
|
166
|
+
attributes?: {
|
|
167
|
+
[key: string]: any;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/** Any additional properties are forwarded as options, like param */
|
|
171
|
+
[key: string]: unknown;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* An END state of the flow.
|
|
176
|
+
*/
|
|
177
|
+
export interface NavigationFlowEndState extends NavigationBaseState<'END'> {
|
|
178
|
+
/**
|
|
179
|
+
* A description of _how_ the flow ended.
|
|
180
|
+
* If this is a flow started from another flow, the outcome determines the flow transition
|
|
181
|
+
*/
|
|
182
|
+
outcome: string;
|
|
183
|
+
|
|
184
|
+
/** Any additional properties are forwarded as options, like param */
|
|
185
|
+
[key: string]: unknown;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Action states execute an expression to determine the next state to transition to */
|
|
189
|
+
export interface NavigationFlowActionState
|
|
190
|
+
extends NavigationFlowTransitionableState<'ACTION'> {
|
|
191
|
+
/**
|
|
192
|
+
* An expression to execute.
|
|
193
|
+
* The return value determines the transition to take
|
|
194
|
+
*/
|
|
195
|
+
exp: Expression;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* External Flow states represent states in the FSM that can't be resolved internally in Player.
|
|
200
|
+
* The flow will wait for the embedded application to manage moving to the next state via a transition
|
|
201
|
+
*/
|
|
202
|
+
export interface NavigationFlowExternalState
|
|
203
|
+
extends NavigationFlowTransitionableState<'EXTERNAL'> {
|
|
204
|
+
/** A reference for this external state */
|
|
205
|
+
ref: string;
|
|
206
|
+
/** Any additional properties are forwarded as options */
|
|
207
|
+
[key: string]: unknown;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface NavigationFlowFlowState
|
|
211
|
+
extends NavigationFlowTransitionableState<'FLOW'> {
|
|
212
|
+
/** A reference to a FLOW id state to run */
|
|
213
|
+
ref: string;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export type NavigationFlowState =
|
|
217
|
+
| NavigationFlowViewState
|
|
218
|
+
| NavigationFlowEndState
|
|
219
|
+
| NavigationFlowFlowState
|
|
220
|
+
| NavigationFlowActionState
|
|
221
|
+
| NavigationFlowExternalState;
|
|
222
|
+
|
|
223
|
+
/** The data at the end of a flow */
|
|
224
|
+
export interface FlowResult {
|
|
225
|
+
/** The outcome describes _how_ the flow ended (forwards, backwards, etc) */
|
|
226
|
+
endState: NavigationFlowEndState;
|
|
227
|
+
|
|
228
|
+
/** The serialized data-model */
|
|
229
|
+
data?: any;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Any object that contains 1 or more templates */
|
|
233
|
+
export interface Templatable {
|
|
234
|
+
/** A list of templates to process for this node */
|
|
235
|
+
template?: Template[];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** A template describes a mapping from a data array -> array of objects */
|
|
239
|
+
export interface Template<ValueType = unknown, Key extends string = string> {
|
|
240
|
+
/** A pointer to the data-model containing an array of elements to map over */
|
|
241
|
+
data: Binding;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The template to iterate over using each value in the supplied template data.
|
|
245
|
+
* Any reference to _index_ is replaced with the current iteration index.
|
|
246
|
+
*/
|
|
247
|
+
value: ValueType;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* A property on the parent object to store the new map under.
|
|
251
|
+
* If it already exists, values are appended to the end.
|
|
252
|
+
*/
|
|
253
|
+
output: Key;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The Schema organizes all content related to Data and it's types
|
|
258
|
+
*/
|
|
259
|
+
export declare namespace Schema {
|
|
260
|
+
/** The authored schema object in the JSON payload */
|
|
261
|
+
export interface Schema {
|
|
262
|
+
/** The ROOT object is the top level object to use */
|
|
263
|
+
ROOT: Node;
|
|
264
|
+
|
|
265
|
+
/** Any additional keys are properties of the ROOT object */
|
|
266
|
+
[key: string]: Node;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** A Node describes a specific object in the tree */
|
|
270
|
+
export interface Node {
|
|
271
|
+
/** Each property describes a property of the object */
|
|
272
|
+
[key: string]: DataType;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Each prop in the object can have a specific DataType */
|
|
276
|
+
export interface DataType<T = unknown> {
|
|
277
|
+
/** The reference of the base type to use */
|
|
278
|
+
type: string;
|
|
279
|
+
|
|
280
|
+
/** The referenced object represents an array rather than an object */
|
|
281
|
+
isArray?: boolean;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Any additional validations that are associated with this property
|
|
285
|
+
* These will add to any base validations associated with the "type"
|
|
286
|
+
*/
|
|
287
|
+
validation?: Validation.Reference[];
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* A reference to a specific data format to use.
|
|
291
|
+
* If none is specified, will fallback to that of the base type
|
|
292
|
+
*/
|
|
293
|
+
format?: Formatting.Reference;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* A default value for this property.
|
|
297
|
+
* Any reads for this property will result in this default value being written to the model.
|
|
298
|
+
*/
|
|
299
|
+
default?: T;
|
|
300
|
+
|
|
301
|
+
/** Any additional options */
|
|
302
|
+
[key: string]: unknown;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Namespace to wrap up core functionality to be used by the Language Service */
|
|
307
|
+
export declare namespace Language {
|
|
308
|
+
/**
|
|
309
|
+
* Helper to compliment `Schema.DataType` to provide a way to export a reference to a data type instead of the whole object
|
|
310
|
+
*/
|
|
311
|
+
export interface DataTypeRef {
|
|
312
|
+
/** Name of the type in Player Core */
|
|
313
|
+
type: string;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** A spot for formatting */
|
|
318
|
+
export declare namespace Formatting {
|
|
319
|
+
/** A reference to a specific formatter */
|
|
320
|
+
export interface Reference {
|
|
321
|
+
/** The name of the formatter (and de-formatter) to use */
|
|
322
|
+
type: string;
|
|
323
|
+
|
|
324
|
+
/** Any additional properties will be passed as options to the formatter function */
|
|
325
|
+
[key: string]: unknown;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** A space for all thing validation */
|
|
330
|
+
export declare namespace Validation {
|
|
331
|
+
/**
|
|
332
|
+
* How serious are you about this error?
|
|
333
|
+
* Warning validations are reserved for errors that could be ignored by the user without consequence
|
|
334
|
+
* Errors must be fixed before proceeding
|
|
335
|
+
*/
|
|
336
|
+
export type Severity = 'error' | 'warning';
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* When to _first_ start caring about a validation of a data-val.
|
|
340
|
+
*
|
|
341
|
+
* load - only check once the first time the binding appears on screen
|
|
342
|
+
* change - check anytime the data changes
|
|
343
|
+
* navigation - check once the user attempts to navigate away from a view
|
|
344
|
+
*/
|
|
345
|
+
export type Trigger = 'navigation' | 'change' | 'load';
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Where the error/warning should be displayed.
|
|
349
|
+
* - `field` is the default display target. This renders the error/warning directly underneath the field.
|
|
350
|
+
* - `section` is used to display a message at a parent node that is designated as a "section"
|
|
351
|
+
* - `page` a special section used to display a message at the top of the page.
|
|
352
|
+
*/
|
|
353
|
+
export type DisplayTarget = 'page' | 'section' | 'field';
|
|
354
|
+
|
|
355
|
+
/** A reference to a validation object */
|
|
356
|
+
export interface Reference {
|
|
357
|
+
/**
|
|
358
|
+
* The name of the referenced validation type
|
|
359
|
+
* This will be used to lookup the proper handler
|
|
360
|
+
*/
|
|
361
|
+
type: string;
|
|
362
|
+
|
|
363
|
+
/** An optional means of overriding the default message if the validation is triggered */
|
|
364
|
+
message?: string;
|
|
365
|
+
|
|
366
|
+
/** An optional means of overriding the default severity of the validation if triggered */
|
|
367
|
+
severity?: Severity;
|
|
368
|
+
|
|
369
|
+
/** When to run this particular validation */
|
|
370
|
+
trigger?: Trigger;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Each validation is passed the value of the data to run it's validation against.
|
|
374
|
+
* By default, this is the value stored in the data-model (deformatted).
|
|
375
|
+
* In the off chance you'd like this validator to run against the formatted value (the one the user sees), set this option
|
|
376
|
+
*/
|
|
377
|
+
dataTarget?: 'formatted' | 'deformatted';
|
|
378
|
+
|
|
379
|
+
/** Where the error should be displayed */
|
|
380
|
+
displayTarget?: DisplayTarget;
|
|
381
|
+
|
|
382
|
+
/** Additional props to send down to a Validator */
|
|
383
|
+
[key: string]: unknown;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export interface CrossfieldReference extends Reference {
|
|
387
|
+
/** The binding to associate this validation with */
|
|
388
|
+
ref?: Binding;
|
|
389
|
+
|
|
390
|
+
/** Cross-field references and validation must run against the default (deformatted) value */
|
|
391
|
+
dataTarget?: never;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export type View<T extends Asset = Asset> = unknown extends T['validation']
|
|
396
|
+
? T & {
|
|
397
|
+
/** Each view can optionally supply a list of validations to run against a particular view */
|
|
398
|
+
validation?: Array<Validation.CrossfieldReference>;
|
|
399
|
+
}
|
|
400
|
+
: T;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* The JSON payload for running Player
|
|
404
|
+
*/
|
|
405
|
+
export interface Flow<T extends Asset = Asset> {
|
|
406
|
+
/** A unique identifier for the flow */
|
|
407
|
+
id: string;
|
|
408
|
+
|
|
409
|
+
/** A list of views (each with an ID) that can be shown to a user */
|
|
410
|
+
views?: Array<View<T>>;
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* The schema for the supplied (or referenced data).
|
|
414
|
+
* This is used for validation, formatting, etc
|
|
415
|
+
*/
|
|
416
|
+
schema?: Schema.Schema;
|
|
417
|
+
|
|
418
|
+
/** Any initial data that the flow can use */
|
|
419
|
+
data?: DataModel;
|
|
420
|
+
|
|
421
|
+
/** A state machine to drive a user through the experience */
|
|
422
|
+
navigation: Navigation;
|
|
423
|
+
|
|
424
|
+
/** Other keys can be present. We just don't know what they are */
|
|
425
|
+
[key: string]: unknown;
|
|
426
|
+
}
|