This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$id": "https://example.com/person.schema.json", | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"title": "Person", | |
"type": "object", | |
"properties": { | |
"firstName": { | |
"type": "string", | |
"description": "The person's first name." | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$ref": "#/definitions/MyObject", | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"definitions": { | |
"MyBaseObject": { | |
"additionalProperties": false, | |
"properties": { | |
"number": { | |
"description": "This is a number. We can set the max and min like so", | |
"maximum": 9, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface MyBaseObject { | |
/** | |
* This is a number. We can set the max and min like so | |
* @minimum 3 | |
* @maximum 9 | |
*/ | |
number: number; | |
/** | |
* This is a string. We can set the maxLength like so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// where you might have something like this and check a single property exists | |
isMyType(toCheck: any): toCheck is MyType { | |
return !!toCheck.propertyOfMyType | |
} | |
/** | |
Now we can have a generic function that takes type, and we can verify | |
that the whole object validates against a schema, rather than just checking | |
a property or two | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Receive notification of update of property 'b' for system_id: 123 | |
const notification_b = { | |
system_id: 123, | |
b: 4 | |
} | |
// Retrieve state of system_id: 123 from MongoDB | |
const current_state_before_b_change = { | |
system_id: 123, | |
a: 1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE system_states | |
SET a = 4 | |
WHERE system_id = 123; | |
UPDATE system_states | |
SET b = 5 | |
WHERE system_id = 123; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** create connection pool to system DB in MongoDB | |
* assume we are using https://www.npmjs.com/package/mongodb | |
* assume we begin with: | |
{ | |
system_id: 123, | |
a: 1, | |
b: 2, | |
c: 3 | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** create connection pool to system DB in MongoDB | |
* assume we are using https://www.npmjs.com/package/mongodb | |
* assume we start with no document with property matching 'system_id: 123' | |
*/ | |
system_states_collection.update( | |
{ system_id: 123 }, | |
{ | |
$set: { a: 4 }, | |
$setOnInsert: { created_at: new Date() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** create connection pool to system DB in MongoDB | |
* assume we are using https://www.npmjs.com/package/mongodb | |
* assume we begin with: | |
{ | |
system_id: 123, | |
a: 1, | |
b: 2, | |
c: 3 | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** create connection pool to system DB in MongoDB | |
* assume we are using https://www.npmjs.com/package/mongodb | |
* assume we begin with: | |
{ | |
system_id: 123, | |
a: 1, | |
b: 2, | |
c: 3, | |
watcher_emails: ['somebody@emailaddress.com'] | |
} |
OlderNewer