https://github.com/marvelapp/prototype-event-schema
Prototype player event schema files distributed via yarn & pip.
https://github.com/marvelapp/prototype-event-schema
Last synced: 8 months ago
JSON representation
Prototype player event schema files distributed via yarn & pip.
- Host: GitHub
- URL: https://github.com/marvelapp/prototype-event-schema
- Owner: marvelapp
- Created: 2019-02-13T14:24:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-02-10T12:14:03.000Z (over 1 year ago)
- Last Synced: 2025-02-17T15:58:52.160Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://circleci.com/gh/marvelapp/workflows/prototype-event-schema
- Size: 50.8 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Proto-Viewer Event Schema [](https://circleci.com/gh/marvelapp/prototype-event-schema)
This repo defines a set of [json-schema](https://json-schema.org/) (draft v7) files we can use across multiple codebases to validate our prototype-viewer's event schema.
## How to validate event structure
When you receive an event, you should first validate the entire event against the schema in `event.json`. That schema will ensure the basic event structure is correct, and that it has all required top level keys with correct `type` values if appropriate.
If that's valid, you need to take object in the `trigger` key and validate it against the schema in `triggers/:type.json`, where `:type` is the value of the trigger's `type` key. Then you should do the same for the `object` and `outcome` keys.
For example, if you have an event that looks like the following:
```json
{
"trigger": {
"type": "timer",
},
"object": {
"type": "screen",
"id": 1,
"height": 100,
"width": 100
},
"outcome": {
"type": "screenTransition",
"fromScreen": 1,
"toScreen": 2,
"animation": "fade"
},
"timestamp": 2500,
"id": "6503601444799647744",
"prevId": "6503601444803842048"
}
```
After validating the entire event using `event.json`, you'd need to take the `trigger` object and validate against `triggers/timer.json`, use `objects/screen.json` to validate the `object` value and validate the `outcome` with `outcomes/screenTransition.json`
## How to add a new `trigger`, `object` or `outcome`
ProTip: [jsonschema.net](https://www.jsonschema.net/) is a useful tool for creating and updating the schema files
1. Update `event.json` to accept your new `type` value for the `trigger`, `object` or `outcome` keys as appropriate
2. Add a schema file to the `triggers/`, `objects/` or `outcomes/` directory, with the same name as your `type` value. So a `timer` type becomes `timer.json`
3. Add or update at least a basic test in `validate.js`
## How to publish changes
- Alter package.json version and increment depending on whether it is a patch, minor or major change
- run `npm publish` to update the published npm package
- update `setup.py` and alter the `version`
- To publish the python package, run a git tag. `git tag v3.x.x` to the specific version you want to tag. Alter the referenced python package in requirements.txt as required. (e.g. git+https://github.com/marvelapp/prototype-event-schema.git@v3.0.7#egg=marvel-proto-events)