@@ -38,14 +38,14 @@ import { Isotope } from "isotopes"
3838
3939TypeScript typings are provided as part of the package, so no need to install a
4040separate package. However, the [ aws-sdk] [ 3 ] is listed as a peer dependency, so
41- make sure it is installed. Note that when you run * Isotopes* from within AWS
42- Lambda the SDK is already installed.
41+ make sure it is installed. When you run * Isotopes* from within AWS Lambda the
42+ SDK is already installed.
4343
4444 [ 3 ] : https://www.npmjs.com/package/aws-sdk
4545
4646## Usage
4747
48- > Note: the following instructions are intended for usage from TypeScript. You
48+ > Note: the following instructions are intended for usage with TypeScript. You
4949 can also use * Isotopes* from plain JavaScript by omitting all typings from
5050 the examples, but what's the point? [ Learn TypeScript] [ 4 ] , it's awesome!
5151
@@ -63,19 +63,20 @@ export interface Task {
6363 cpus: number /* Number of CPUs */
6464 memory: number /* Reserved memory */
6565 command? : string /* Command override */
66- }
66+ },
67+ tags: string [] /* Tags for categorization */
6768}
6869```
6970
7071Every type that is handled by * Isotopes* must contain a unique identifier which
71- is used for item identification . The identifier * should* be on the first level
72- of the type to be stored, all other variables can be arbitrarily nested. Next,
73- create an isotope for the type, e.g. for a SimpleDB domain named ` tasks ` :
72+ is used as an item name . The item name * should* be on the first level of the
73+ type to be stored, all other variables can be arbitrarily nested. Next, create
74+ an isotope for the type, e.g. for a SimpleDB domain named ` tasks ` :
7475
7576``` ts
7677const tasks = new Isotope <Task >({
77- domain: " tasks" ,
78- key: " id"
78+ domain: " tasks" , /* SimpleDB domain name */
79+ key: " id" /* SimpleDB item name (primary key) */
7980})
8081```
8182
@@ -84,7 +85,7 @@ const tasks = new Isotope<Task>({
8485 or destroy domains by itself. However, [ Terraform] [ 5 ] is an excellent tool
8586 for this.
8687
87- Suppose we have the following item:
88+ Now, suppose we have the following item:
8889
8990``` ts
9091const task: Task = {
@@ -94,13 +95,17 @@ const task: Task = {
9495 image: " busybox" ,
9596 cpus: 2 ,
9697 memory: 2048
97- }
98+ },
99+ tags: [
100+ " TAG_1" ,
101+ " TAG_2"
102+ ]
98103}
99104```
100105
101- We can persist, retrieve and delete items of our defined type from the isotope
102- by using a simple API, cleverly omitting all the boilerplate that is normally
103- necessary for interfacing with SimpleDB. Persist an item:
106+ We can persist, retrieve and delete items from the isotope by using a simple
107+ API, cleverly omitting all the boilerplate that is normally necessary for
108+ interfacing with SimpleDB. Persist an item:
104109
105110``` ts
106111await tasks .put (task ) // => void
@@ -161,21 +166,22 @@ try {
161166### Persistence, retrieval and deletion of partial types
162167
163168By default, * Isotopes* forces only valid entries to be written to SimpleDB which
164- means that all non-optional fields need to be defined in the payload. However,
165- SimpleDB allows reading and writing of partial attribute values, so it might be
166- desirable in some cases to loosen that restriction and allow partial reads and
167- writes. * Isotopes* allows both configurations through simple generic typing.
169+ means that all non-optional fields need to be defined in the payload (otherwise
170+ the TypeScript compiler will moan). However, SimpleDB allows reading and writing
171+ of partial attribute values, so it might be desirable in some cases to loosen
172+ that restriction and allow partial reads and writes. * Isotopes* allows both
173+ configurations through simple generic typing.
168174
169175``` ts
170176class Isotope <
171177 T extends {}, /* Data type */
172178 TPut extends Partial <T > = T , /* Data type expected by PUT operation */
173- TGet extends Partial <T > = TPut /* Data type returned by PUT operation */
179+ TGet extends Partial <T > = TPut /* Data type returned by GET operation */
174180> {}
175181```
176182
177183The first type argument is mandatory and defines the base type. The second
178- and third type arguments can be used to specify what exact types PUT and GET
184+ and third type arguments can be used to specify what exact types ` PUT ` and ` GET `
179185operations return but normally they are equal to the base type.
180186
181187Allow complete values only:
@@ -184,24 +190,24 @@ Allow complete values only:
184190new Isotope <Task >(... )
185191```
186192
187- Allow partial values in PUT and GET operations:
193+ Allow partial values in ` PUT ` and ` GET ` operations:
188194
189195``` ts
190196new Isotope <Task , Partial <Task >>(... )
191197```
192198
193- Allow partial values in GET operations only:
199+ Allow partial values in ` GET ` operations only:
194200
195201``` ts
196202new Isotope <Type , Type , Partial <Type >>(... )
197203```
198204
199- Furthermore, SELECT operations are assumed to return the same type as GET
205+ Furthermore, ` SELECT ` operations are assumed to return the same type as ` GET `
200206operations. Since this may be different on a case-by-case basis (depending on
201- the specific SQL query), it may be overriden on a per-query basis:
207+ the specific SQL query), it may be overridden on a per-query basis:
202208
203209``` ts
204- tasks .select <Partial <Task >>(... )
210+ await tasks .select <Partial <Task >>(... )
205211```
206212
207213### Encoding
@@ -216,7 +222,7 @@ const tasks = new Isotope<Task>({
216222})
217223```
218224
219- #### JSON < small >default, recommended</ small >
225+ #### JSON ( recommended)
220226
221227> ` options.format.encoding: "json" `
222228
@@ -230,13 +236,15 @@ whereas numbers and booleans are written literally:
230236 { "Name" : " active" , "Value" : " true" },
231237 { "Name" : " props.image" , "Value" : " \" busybox\" " },
232238 { "Name" : " props.cpus" , "Value" : " 2" },
233- { "Name" : " props.memory" , "Value" : " 2048" }
239+ { "Name" : " props.memory" , "Value" : " 2048" },
240+ { "Name" : " tags[]" , "Value" : " \" TAG_1\" " },
241+ { "Name" : " tags[]" , "Value" : " \" TAG_2\" " }
234242 ]
235243}
236244```
237245
238- If you don't plan to use the SimpleDB domain from a non-* Isotope* environment,
239- you should always stick with JSON-encoding because it is more safe than text
246+ If you don't plan to use the SimpleDB domain from a non-* Isotope* client, you
247+ should always stick with JSON-encoding because it is more safe than text
240248encoding and comes with no limitations.
241249
242250#### Text
@@ -253,7 +261,9 @@ as literals so they are written without quotes:
253261 { "Name" : " active" , "Value" : " true" },
254262 { "Name" : " props.image" , "Value" : " busybox" },
255263 { "Name" : " props.cpus" , "Value" : " 2" },
256- { "Name" : " props.memory" , "Value" : " 2048" }
264+ { "Name" : " props.memory" , "Value" : " 2048" },
265+ { "Name" : " tags[]" , "Value" : " TAG_1" },
266+ { "Name" : " tags[]" , "Value" : " TAG_2" }
257267 ]
258268}
259269```
0 commit comments