@scenar/sdk 0.1.19 → 0.1.20-rc.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/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/proto/load-scenario.d.ts +4 -4
- package/proto/load-scenario.d.ts.map +1 -1
- package/proto/load-scenario.js +7 -7
- package/proto/load-scenario.js.map +1 -1
- package/proto/proto-types.d.ts +2 -2
- package/proto/proto-types.d.ts.map +1 -1
- package/src/__tests__/load-scenario.test.ts +11 -8
- package/src/index.ts +1 -1
- package/src/proto/load-scenario.ts +8 -8
- package/src/proto/proto-types.ts +2 -2
package/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { loadScenarioFromProto } from "./proto/load-scenario.js";
|
|
|
4
4
|
export type { LoadScenarioOptions } from "./proto/load-scenario.js";
|
|
5
5
|
export { InvalidScenarioError } from "./proto/errors.js";
|
|
6
6
|
export { PROTO_ACTION_TYPE } from "./proto/proto-types.js";
|
|
7
|
-
export type { ProtoActionTypeValue,
|
|
7
|
+
export type { ProtoActionTypeValue, ProtoScenarioSpec, ProtoStep, ProtoStepAction, ProtoStepActionConfig, ProtoViewportConfig, } from "./proto/proto-types.js";
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,YAAY,EACV,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,SAAS,EACT,aAAa,EACb,OAAO,GACR,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EACV,oBAAoB,EACpB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,YAAY,EACV,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,SAAS,EACT,aAAa,EACb,OAAO,GACR,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EACV,oBAAoB,EACpB,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scenar/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20-rc.1",
|
|
4
4
|
"description": "Typed authoring surface for Scenar scenarios — createScenario() builder and proto adapter.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@scenar/core": "0.1.
|
|
31
|
+
"@scenar/core": "0.1.20-rc.1"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/proto/load-scenario.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AuthoredScenario, ViewRegistry } from "../author/types.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ProtoScenarioSpec } from "./proto-types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Options for {@link loadScenarioFromProto}.
|
|
5
5
|
*/
|
|
@@ -8,10 +8,10 @@ export interface LoadScenarioOptions<Views extends ViewRegistry> {
|
|
|
8
8
|
readonly views: Views;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Convert a proto `
|
|
11
|
+
* Convert a proto `ScenarioSpec` message into an `AuthoredScenario`
|
|
12
12
|
* ready for `<ScenarioPlayer>`.
|
|
13
13
|
*
|
|
14
|
-
* This is the YAML ingestion path: a scenario parsed from protobuf
|
|
14
|
+
* This is the YAML ingestion path: a scenario spec parsed from protobuf
|
|
15
15
|
* (or proto-JSON) enters here and comes out as the same shape that
|
|
16
16
|
* `createScenario()` produces.
|
|
17
17
|
*
|
|
@@ -21,5 +21,5 @@ export interface LoadScenarioOptions<Views extends ViewRegistry> {
|
|
|
21
21
|
* @throws {InvalidScenarioError} with a path and reason on any
|
|
22
22
|
* structural or semantic validation failure.
|
|
23
23
|
*/
|
|
24
|
-
export declare function loadScenarioFromProto<Views extends ViewRegistry>(
|
|
24
|
+
export declare function loadScenarioFromProto<Views extends ViewRegistry>(spec: ProtoScenarioSpec, options: LoadScenarioOptions<Views>): AuthoredScenario<Views>;
|
|
25
25
|
//# sourceMappingURL=load-scenario.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-scenario.d.ts","sourceRoot":"","sources":["../../src/proto/load-scenario.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAEhB,YAAY,EACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"load-scenario.d.ts","sourceRoot":"","sources":["../../src/proto/load-scenario.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAEhB,YAAY,EACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,KAAK,SAAS,YAAY;IAC7D,yDAAyD;IACzD,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACvB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,SAAS,YAAY,EAC9D,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,mBAAmB,CAAC,KAAK,CAAC,GAClC,gBAAgB,CAAC,KAAK,CAAC,CA6CzB"}
|
package/proto/load-scenario.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { InvalidScenarioError } from "./errors.js";
|
|
2
2
|
import { mapProtoAction } from "./action-mapper.js";
|
|
3
3
|
/**
|
|
4
|
-
* Convert a proto `
|
|
4
|
+
* Convert a proto `ScenarioSpec` message into an `AuthoredScenario`
|
|
5
5
|
* ready for `<ScenarioPlayer>`.
|
|
6
6
|
*
|
|
7
|
-
* This is the YAML ingestion path: a scenario parsed from protobuf
|
|
7
|
+
* This is the YAML ingestion path: a scenario spec parsed from protobuf
|
|
8
8
|
* (or proto-JSON) enters here and comes out as the same shape that
|
|
9
9
|
* `createScenario()` produces.
|
|
10
10
|
*
|
|
@@ -14,14 +14,14 @@ import { mapProtoAction } from "./action-mapper.js";
|
|
|
14
14
|
* @throws {InvalidScenarioError} with a path and reason on any
|
|
15
15
|
* structural or semantic validation failure.
|
|
16
16
|
*/
|
|
17
|
-
export function loadScenarioFromProto(
|
|
18
|
-
if (
|
|
17
|
+
export function loadScenarioFromProto(spec, options) {
|
|
18
|
+
if (spec.steps.length === 0) {
|
|
19
19
|
throw new InvalidScenarioError("steps", "steps array must not be empty.");
|
|
20
20
|
}
|
|
21
21
|
const viewNames = new Set(Object.keys(options.views));
|
|
22
22
|
const steps = [];
|
|
23
|
-
for (let i = 0; i <
|
|
24
|
-
const protoStep =
|
|
23
|
+
for (let i = 0; i < spec.steps.length; i++) {
|
|
24
|
+
const protoStep = spec.steps[i];
|
|
25
25
|
const stepPath = `steps[${i}]`;
|
|
26
26
|
if (!protoStep.view) {
|
|
27
27
|
throw new InvalidScenarioError(`${stepPath}.view`, "view is required.");
|
|
@@ -43,7 +43,7 @@ export function loadScenarioFromProto(scenario, options) {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
return {
|
|
46
|
-
viewport:
|
|
46
|
+
viewport: spec.viewport ? { width: spec.viewport.width, height: spec.viewport.height } : undefined,
|
|
47
47
|
views: options.views,
|
|
48
48
|
steps,
|
|
49
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-scenario.js","sourceRoot":"","sources":["../../src/proto/load-scenario.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAUpD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,qBAAqB,CACnC,
|
|
1
|
+
{"version":3,"file":"load-scenario.js","sourceRoot":"","sources":["../../src/proto/load-scenario.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAUpD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,qBAAqB,CACnC,IAAuB,EACvB,OAAmC;IAEnC,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,oBAAoB,CAAC,OAAO,EAAE,gCAAgC,CAAC,CAAC;IAC5E,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IACtD,MAAM,KAAK,GAA4C,EAAE,CAAC;IAE1D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,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AAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS;QAClG,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,KAAK;KACN,CAAC;AACJ,CAAC"}
|
package/proto/proto-types.d.ts
CHANGED
|
@@ -89,8 +89,8 @@ export interface ProtoStep {
|
|
|
89
89
|
readonly props?: Record<string, unknown>;
|
|
90
90
|
readonly interactions: readonly ProtoStepAction[];
|
|
91
91
|
}
|
|
92
|
-
/** Structural shape of the proto `
|
|
93
|
-
export interface
|
|
92
|
+
/** Structural shape of the proto `ScenarioSpec` message. */
|
|
93
|
+
export interface ProtoScenarioSpec {
|
|
94
94
|
readonly viewport?: ProtoViewportConfig;
|
|
95
95
|
readonly steps: readonly ProtoStep[];
|
|
96
96
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proto-types.d.ts","sourceRoot":"","sources":["../../src/proto/proto-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,kDAAkD;AAClD,eAAO,MAAM,iBAAiB;;;;;;;;;;CAUpB,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE9F,4DAA4D;AAC5D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,wDAAwD;AACxD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,yDAAyD;AACzD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAED,wD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,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,0BAA0B,CAAC;IAAC,KAAK,EAAE,6BAA6B,CAAA;CAAE,GAC1E;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAE3C,wDAAwD;AACxD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;CACxC;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,QAAQ,CAAC,YAAY,EAAE,SAAS,eAAe,EAAE,CAAC;CACnD;AAED,4DAA4D;AAC5D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAC;CACtC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { loadScenarioFromProto } from "../proto/load-scenario.js";
|
|
3
3
|
import { InvalidScenarioError } from "../proto/errors.js";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
PROTO_ACTION_TYPE,
|
|
6
|
+
type ProtoScenarioSpec,
|
|
7
|
+
} from "../proto/proto-types.js";
|
|
5
8
|
|
|
6
9
|
interface SettingsProps {
|
|
7
10
|
readonly org: string;
|
|
@@ -21,7 +24,7 @@ function FormView(_props: FormProps): unknown {
|
|
|
21
24
|
|
|
22
25
|
const views = { settings: SettingsView, form: FormView };
|
|
23
26
|
|
|
24
|
-
function makeValidScenario():
|
|
27
|
+
function makeValidScenario(): ProtoScenarioSpec {
|
|
25
28
|
return {
|
|
26
29
|
viewport: { width: 896, height: 540 },
|
|
27
30
|
steps: [
|
|
@@ -86,7 +89,7 @@ describe("loadScenarioFromProto", () => {
|
|
|
86
89
|
it("defaults props to empty object when proto props is undefined", () => {
|
|
87
90
|
const proto = makeValidScenario();
|
|
88
91
|
const step = { ...proto.steps[0]!, props: undefined };
|
|
89
|
-
const modified:
|
|
92
|
+
const modified: ProtoScenarioSpec = {
|
|
90
93
|
...proto,
|
|
91
94
|
steps: [step],
|
|
92
95
|
};
|
|
@@ -97,7 +100,7 @@ describe("loadScenarioFromProto", () => {
|
|
|
97
100
|
|
|
98
101
|
it("handles scenario with no viewport", () => {
|
|
99
102
|
const proto = makeValidScenario();
|
|
100
|
-
const modified:
|
|
103
|
+
const modified: ProtoScenarioSpec = {
|
|
101
104
|
...proto,
|
|
102
105
|
viewport: undefined,
|
|
103
106
|
};
|
|
@@ -107,7 +110,7 @@ describe("loadScenarioFromProto", () => {
|
|
|
107
110
|
});
|
|
108
111
|
|
|
109
112
|
it("throws when steps array is empty", () => {
|
|
110
|
-
const proto:
|
|
113
|
+
const proto: ProtoScenarioSpec = { steps: [] };
|
|
111
114
|
|
|
112
115
|
expect(() => loadScenarioFromProto(proto, { views })).toThrow(
|
|
113
116
|
/steps array must not be empty/,
|
|
@@ -115,7 +118,7 @@ describe("loadScenarioFromProto", () => {
|
|
|
115
118
|
});
|
|
116
119
|
|
|
117
120
|
it("throws when a step references an unregistered view", () => {
|
|
118
|
-
const modified:
|
|
121
|
+
const modified: ProtoScenarioSpec = {
|
|
119
122
|
steps: [
|
|
120
123
|
{
|
|
121
124
|
view: "unknown-view",
|
|
@@ -141,7 +144,7 @@ describe("loadScenarioFromProto", () => {
|
|
|
141
144
|
|
|
142
145
|
it("throws when an action has unspecified type", () => {
|
|
143
146
|
const proto = makeValidScenario();
|
|
144
|
-
const modified:
|
|
147
|
+
const modified: ProtoScenarioSpec = {
|
|
145
148
|
...proto,
|
|
146
149
|
steps: [
|
|
147
150
|
{
|
|
@@ -168,7 +171,7 @@ describe("loadScenarioFromProto", () => {
|
|
|
168
171
|
});
|
|
169
172
|
|
|
170
173
|
it("omits empty narration and caption strings", () => {
|
|
171
|
-
const modified:
|
|
174
|
+
const modified: ProtoScenarioSpec = {
|
|
172
175
|
steps: [
|
|
173
176
|
{
|
|
174
177
|
view: "settings",
|
package/src/index.ts
CHANGED
|
@@ -22,7 +22,7 @@ export { InvalidScenarioError } from "./proto/errors.js";
|
|
|
22
22
|
export { PROTO_ACTION_TYPE } from "./proto/proto-types.js";
|
|
23
23
|
export type {
|
|
24
24
|
ProtoActionTypeValue,
|
|
25
|
-
|
|
25
|
+
ProtoScenarioSpec,
|
|
26
26
|
ProtoStep,
|
|
27
27
|
ProtoStepAction,
|
|
28
28
|
ProtoStepActionConfig,
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
ViewRegistry,
|
|
6
6
|
} from "../author/types.js";
|
|
7
7
|
import { InvalidScenarioError } from "./errors.js";
|
|
8
|
-
import type {
|
|
8
|
+
import type { ProtoScenarioSpec } from "./proto-types.js";
|
|
9
9
|
import { mapProtoAction } from "./action-mapper.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -17,10 +17,10 @@ export interface LoadScenarioOptions<Views extends ViewRegistry> {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Convert a proto `
|
|
20
|
+
* Convert a proto `ScenarioSpec` message into an `AuthoredScenario`
|
|
21
21
|
* ready for `<ScenarioPlayer>`.
|
|
22
22
|
*
|
|
23
|
-
* This is the YAML ingestion path: a scenario parsed from protobuf
|
|
23
|
+
* This is the YAML ingestion path: a scenario spec parsed from protobuf
|
|
24
24
|
* (or proto-JSON) enters here and comes out as the same shape that
|
|
25
25
|
* `createScenario()` produces.
|
|
26
26
|
*
|
|
@@ -31,18 +31,18 @@ export interface LoadScenarioOptions<Views extends ViewRegistry> {
|
|
|
31
31
|
* structural or semantic validation failure.
|
|
32
32
|
*/
|
|
33
33
|
export function loadScenarioFromProto<Views extends ViewRegistry>(
|
|
34
|
-
|
|
34
|
+
spec: ProtoScenarioSpec,
|
|
35
35
|
options: LoadScenarioOptions<Views>,
|
|
36
36
|
): AuthoredScenario<Views> {
|
|
37
|
-
if (
|
|
37
|
+
if (spec.steps.length === 0) {
|
|
38
38
|
throw new InvalidScenarioError("steps", "steps array must not be empty.");
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const viewNames = new Set(Object.keys(options.views));
|
|
42
42
|
const steps: ScenarioStep<AuthoredStepData<Views>>[] = [];
|
|
43
43
|
|
|
44
|
-
for (let i = 0; i <
|
|
45
|
-
const protoStep =
|
|
44
|
+
for (let i = 0; i < spec.steps.length; i++) {
|
|
45
|
+
const protoStep = spec.steps[i]!;
|
|
46
46
|
const stepPath = `steps[${i}]`;
|
|
47
47
|
|
|
48
48
|
if (!protoStep.view) {
|
|
@@ -74,7 +74,7 @@ export function loadScenarioFromProto<Views extends ViewRegistry>(
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
return {
|
|
77
|
-
viewport:
|
|
77
|
+
viewport: spec.viewport ? { width: spec.viewport.width, height: spec.viewport.height } : undefined,
|
|
78
78
|
views: options.views,
|
|
79
79
|
steps,
|
|
80
80
|
};
|
package/src/proto/proto-types.ts
CHANGED
|
@@ -86,8 +86,8 @@ export interface ProtoStep {
|
|
|
86
86
|
readonly interactions: readonly ProtoStepAction[];
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
/** Structural shape of the proto `
|
|
90
|
-
export interface
|
|
89
|
+
/** Structural shape of the proto `ScenarioSpec` message. */
|
|
90
|
+
export interface ProtoScenarioSpec {
|
|
91
91
|
readonly viewport?: ProtoViewportConfig;
|
|
92
92
|
readonly steps: readonly ProtoStep[];
|
|
93
93
|
}
|