presidium 4.11.0 → 4.11.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.
Files changed (2) hide show
  1. package/README.md +34 -167
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -101,178 +101,45 @@ websocket.on("message", message => {
101
101
  })
102
102
  ```
103
103
 
104
- ## [Create, read, update, delete, and query with AWS DynamoDB](https://presidium.services/docs/DynamoDBTable)
104
+ ## [Validate data](https://presidium.services/docs/Validator)
105
105
  ```javascript
106
- const DynamoDBTable = require("presidium/DynamoDBTable")
107
- const DynamoDBGlobalSecondaryIndex = require("presidium/DynamoDBGlobalSecondaryIndex")
108
- const AwsCredentials = require("presidium/AwsCredentials")
109
-
110
- const awsCreds = await AwsCredentials("default")
111
- awsCreds.region = "us-east-1"
112
-
113
- const myTable = new DynamoDBTable({
114
- name: "my-table",
115
- key: [{ id: "string" }],
116
- ...awsCreds,
106
+ const Validator = require("presidium/Validator")
107
+
108
+ const {
109
+ Object, Array, Number, String, Email, Boolean, OneOf, Optional,
110
+ } = Validator
111
+
112
+ const validator = Object({
113
+ Name: String,
114
+ Email: Email,
115
+ Password: String,
116
+ Preferences: Object({
117
+ Gender: OneOf("Male", "Female"),
118
+ }),
119
+ Gender: OneOf("Male", "Female"),
120
+ IsReturning: Boolean,
121
+ Time: Optional(Number),
122
+ Media: Array(Object({
123
+ MediaUrl: String,
124
+ Description: String,
125
+ })),
117
126
  })
118
- await myTable.ready
119
-
120
- const myTypeAgeIndex = new DynamoDBGlobalSecondaryIndex({
121
- table: "my-table",
122
- key: [{ type: "string" }, { age: "number" }],
123
- ...awsCreds,
124
- })
125
- await myTypeAgeIndex.ready
126
-
127
- await myTable.putItem({ id: { S: "1" }, name: { S: "John" }, type: { S: "person" } })
128
- await myTable.updateItem({ id: { S: "1" } }, { age: { N: "32" } })
129
-
130
- await myTable.putItemJSON({ id: "2", name: "Joe", age: 19, type: "person" })
131
- await myTable.putItemJSON({ id: "3", name: "Jane", age: 33, type: "person" })
132
-
133
- {
134
- const data = await myTable.getItem({ id: { S: "1" } }),
135
- console.log(data)
136
- // { Item: { id: { S: "1" }, name: { S: "John" }, age: { N: "32" } } }
137
- }
138
-
139
- {
140
- const data = await myTable.getItemJSON({ id: "1" })
141
- console.log(data)
142
- // { item: { id: "1", name: "John", age: 32 } }
143
- }
144
127
 
145
- {
146
- const data = await myTypeAgeIndex.query(
147
- "type = :type AND age < :age",
148
- { type: { S: "person" }, age: { N: "100" } },
149
- { Limit: 2, ScanIndexForward: true },
150
- )
151
- console.log(data)
152
- // {
153
- // Items: [
154
- // { id: { S: "1" }, name: { S: "John" }, age: { N: "32" }, type: { S: "person" } },
155
- // { id: { S: "2" }, name: { S: "Joe" }, age: { N: "19" }, type: { S: "person" } },
156
- // ],
157
- // Count: 2,
158
- // ScannedCount: 2,
159
- // }
160
- }
161
-
162
- {
163
- const data = await myTypeAgeIndex.queryJSON(
164
- "type = :type AND age < :age",
165
- { type: "person", age: 100 },
166
- { Limit: 2, ScanIndexForward: true },
167
- )
168
- console.log(data)
169
- // {
170
- // ItemsJSON: [
171
- // { id: "1", name: "John", age: 32, type: "person" },
172
- // { id: "2", name: "Joe", age: 19, type: "person" },
173
- // ],
174
- // Count: 2,
175
- // ScannedCount: 2,
176
- // }
177
- }
178
-
179
- {
180
- const ItemIterator = myTypeAgeIndex.queryItemsIterator(
181
- "type = :type AND age < :age",
182
- { type: { S: "person" }, age: { N: "100" } },
183
- { ScanIndexForward: true },
184
- )
185
- for await (const Item of ItemIterator) {
186
- console.log(Item)
187
- // { id: { S: "2" }, name: { S: "Joe" }, age: { N: "19" }, type: { S: "person" } },
188
- // { id: { S: "1" }, name: { S: "John" }, age: { N: "32" }, type: { S: "person" } },
189
- // { id: { S: "3" }, name: { S: "Jane" }, age: { N: "33" }, type: { S: "person" } },
190
- }
191
- }
192
-
193
- {
194
- const itemsIterator = myTypeAgeIndex.queryItemsIteratorJSON(
195
- "type = :type AND age < :age",
196
- { type: "person", age: 100 },
197
- { ScanIndexForward: true },
198
- )
199
- for await (const item of itemsIterator) {
200
- console.log(item)
201
- // { id: "2", name: "Joe", age: 19, type: "person" }
202
- // { id: "1", name: "John", age: 32, type: "person" }
203
- // { id: "3", name: "Jane", age: 33, type: "person" }
204
- }
205
- }
206
- ```
207
-
208
- ## [Consume AWS DynamoDB Streams](https://presidium.services/docs/DynamoDBStream)
209
- ```javascript
210
- const DynamoDBTable = require("presidium/DynamoDBTable")
211
- const DynamoDBStream = require("presidium/DynamoDBStream")
212
- const AwsCredentials = require("presidium/AwsCredentials")
213
-
214
- const awsCreds = await AwsCredentials("default")
215
- awsCreds.region = "us-east-1"
216
-
217
- const myTable = new DynamoDBTable({
218
- name: "my-table",
219
- key: [{ id: "string" }],
220
- ...awsCreds,
221
- })
222
- await myTable.ready
223
-
224
- const myStream = new DynamoDBStream({
225
- table: "my-table",
226
- ...awsCreds,
227
- })
228
- await myStream.ready
229
-
230
- for await (const record of myStream) {
231
- console.log(record)
232
- // { dynamodb: { Keys: {...}, NewImage: {...}, OldImage: {...} } }
233
- // { dynamodb: { Keys: {...}, NewImage: {...}, OldImage: {...} } }
234
- // { dynamodb: { Keys: {...}, NewImage: {...}, OldImage: {...} } }
235
- }
236
-
237
- const myStreamJSON = new DynamoDBStream({
238
- table: "my-table",
239
- ...awsCreds,
240
- JSON: true,
241
- })
242
- await myStream.ready
243
-
244
- for await (const record of myStreamJSON) {
245
- console.log(record)
246
- // { dynamodb: { KeysJSON: {...}, NewImageJSON: {...}, OldImageJSON: {...} } }
247
- // { dynamodb: { KeysJSON: {...}, NewImageJSON: {...}, OldImageJSON: {...} } }
248
- // { dynamodb: { KeysJSON: {...}, NewImageJSON: {...}, OldImageJSON: {...} } }
128
+ const data = {
129
+ Name: "Example Name",
130
+ Email: "email@domain.com",
131
+ Password: "************",
132
+ Preferences: {
133
+ Gender: "Male",
134
+ },
135
+ IsReturning: false,
136
+ Media: [{
137
+ MediaUrl: "https://cdn.my-website.com/assets/1.mp4",
138
+ Description: "Example description.",
139
+ }],
249
140
  }
250
- ```
251
-
252
- ## [Download and upload with AWS S3](https://presidium.services/docs/S3Bucket)
253
- ```javascript
254
- const S3Bucket = require("presidium/S3Bucket")
255
- const AwsCredentials = require("presidium/AwsCredentials")
256
-
257
- const awsCreds = await AwsCredentials("default")
258
- awsCreds.region = "us-east-1"
259
-
260
- const myBucket = new S3Bucket({
261
- name: "my-bucket",
262
- ...awsCreds,
263
- })
264
- await myBucket.ready
265
-
266
- await myBucket.putObject("some-key", "{"hello":"world"}", {
267
- ContentType: "application/json",
268
- })
269
-
270
- const data = await myBucket.getObject("some-key")
271
- console.log(data)
272
- // { Etag: "...", Body: <Buffer 7b 22 68 ...>, ContentType: "application/json" }
273
141
 
274
- await myBucket.deleteAllObjects()
275
- await myBucket.delete()
142
+ validator(data)
276
143
  ```
277
144
 
278
145
  ## [Build and push Docker images](https://presidium.services/docs/Docker)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "4.11.0",
3
+ "version": "4.11.1",
4
4
  "description": "The Presidium library.",
5
5
  "author": "Richard Tong",
6
6
  "license": "CFOSS",