Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add TypeScript schema #15

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
*/
scrollPosition: 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