Skip to content

Commit

Permalink
feat: add TypeScript schema
Browse files Browse the repository at this point in the history
  • Loading branch information
moretti committed Sep 5, 2023
1 parent 75fea7c commit 5480d31
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 0 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
"dependencies": {
"ajv": "^6.9.1",
"flakeid": "^0.3.1"
},
"devDependencies": {
"prettier": "^3.0.3"
},
"prettier": {
"singleQuote": true
}
}
184 changes: 184 additions & 0 deletions schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
type Animation =
| 'fade'
| 'push-left'
| 'push-right'
| 'slide-up'
| 'slide-down'
| 'slide-left'
| 'slide-right'
| 'pop'
| 'flip'
| 'flow'
| 'slide-fade'
| null;

/**
* Globally unique ID for the test
*/
type EventId = string;

export interface RootSchema {
trigger: Trigger;
object: Object;
outcome: Outcome;
id: EventId;
prevId: EventId | null;
/**
* Timestamp of the event relative to the start of the prototype-viewer session, in ms
*/
timestamp: number;
[k: string]: unknown;
}

/**
* The object that was used in triggering this event, such as a hotspot or a screen
*/
export type Object =
| {
type: 'hotspot' | 'overlay' | 'scrollContainer';
id: number;
}
| {
type: 'player';
}
| {
type: 'screen';
id: number;
width: number;
height: number;
};
/**
* An action that has happened as a result of this event occuring
*/
export type Outcome =
| {
type: 'goalReached' | 'miss' | 'startRecording' | 'stopRecording';
}
| {
type: 'openUrl';
url: string;
newWindow: boolean;
}
| {
type: 'overlayTransition';
/**
* The PK of the screen that is being overlain onto the currently active screen
*/
screen: number;
/**
* The top left of the overlain screen
*/
position: Coordinates;
/**
* The x,y coordinates of the scroll position
*/
scrollPosition: Coordinates;
/**
* The animation used for the transition
*/
animation: Animation;
/**
* Whether to reverse the animation or not
*/
reverseAnimation: boolean;
}
| {
type: 'removeOverlay';
/**
* The PK of the screen that is under the currently active overlay
*/
screen: number;
/**
* The animation used for the transition
*/
animation: Animation;
/**
* Whether to reverse the animation or not
*/
reverseAnimation: boolean;
}
| {
type: 'screenTransition';
/**
* The PK of the screen that transitioned to
*/
screen: number;
/**
* The x,y coordinates of the scroll position
*/
scrollosition: Coordinates;
/**
* The animation used for the transition
*/
animation: Animation;
/**
* Whether to reverse the animation or not
*/
reverseAnimation: boolean;
}
| {
type: 'resize';
width: number;
height: number;
}
| {
type: 'scroll';
/**
* The PK of the screen that scrolled
*/
screen: number | null;
/**
* The PK of the overlay that scrolled
*/
overlay: number | null;
/**
* The x,y coordinates of the final scroll position
*/
coords: Coordinates;
/**
* Whether to scroll smoothly or not
*/
smooth: boolean;
};

/**
* The x,y coordinates of the interaction
*/
type Coordinates = [number, number];

/**
* What caused the event to happen, such as user interaction or an elapsed timer
*/
type Trigger =
| {
type: 'tap' | 'doubletap' | 'mousemove';
coords: Coordinates;
}
| {
type: 'navigation' | 'player' | 'timer' | 'user';
}
| {
type: 'pinch';
/**
* The direction of the pinch, either in or out
*/
direction: 'in' | 'out';
coords: Coordinates;
duration: number;
}
| {
type: 'swipe';
/**
* The general direction of the swipe
*/
direction: 'left' | 'right' | 'up' | 'down';
/**
* The x,y coordinate of the starting position for the swipe
*/
startCoords: Coordinates;
/**
* The x,y coordinate of the ending position for the swipe
*/
endCoords: Coordinates;
duration: number;
};
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ json-schema-traverse@^0.4.1:
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==

prettier@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.3.tgz#432a51f7ba422d1469096c0fdc28e235db8f9643"
integrity sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==

punycode@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
Expand Down

0 comments on commit 5480d31

Please sign in to comment.