Skip to content

Commit 7ea5a74

Browse files
committed
Signature updates
1 parent 405707f commit 7ea5a74

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

docs/reference/resources/index.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class MyExternalData extends Resource {
3434
let response = await this.fetch(target.id);
3535
// do something with the response
3636
}
37-
static put(target, data) {
37+
static put(target, promisedData) {
3838
// send the data into the external source
3939
}
4040
static delete(target) {
@@ -53,20 +53,22 @@ You can also extend table classes in the same way, overriding the instance metho
5353

5454
```javascript
5555
export class MyTable extends tables.MyTable {
56-
static get(target) {
56+
static async get(target) {
5757
// we can add properties or change properties before returning data:
58-
return { ...super.get(target), newProperty: 'newValue', existingProperty: 42 }; // returns the record, with additional properties
58+
return { ...(await super.get(target)), newProperty: 'newValue', existingProperty: 42 }; // returns the record, with additional properties
5959
}
60-
static put(target, data) {
60+
static async put(target, promisedData) {
61+
let data = await promisedData;
6162
// can change data any way we want
6263
super.put(target, data);
6364
}
64-
static delete(target) {
65-
super.delete(target);
65+
static async delete(target) {
66+
return super.delete(target);
6667
}
67-
static post(target, data) {
68+
static async post(target, promisedData) {
6869
// providing a post handler (for HTTP POST requests) is a common way to create additional
6970
// actions that aren't well described with just PUT or DELETE
71+
let data = await promisedData;
7072
}
7173
}
7274
```
@@ -201,8 +203,9 @@ You can also override `get` to collect data from other tables:
201203
const { MyTable, Comment } = tables;
202204
...
203205
// in class:
204-
static async get() {
205-
for (let commentId of this.commentIds) {
206+
static async get(target) {
207+
let record = await super.get(target);
208+
for (let commentId of record.commentIds) {
206209
let comment = await Comment.get(commentId, this);
207210
// now you can do something with the comment record
208211
}
@@ -213,13 +216,13 @@ const { MyTable, Comment } = tables;
213216
214217
This performs a query on this resource or table. By default, this is called by `get(query)` from a collection resource. When this is called for the root resource (like `/Table/`) it searches through all records in the table. You can define or override this method to define how records should be queried. The default `search` method on tables (`super.search(query)`) will perform a query and return an `AsyncIterable` of results. The `query` object can be used to specify the desired query.
215218
216-
### `static put(target: RequestTarget | Id, data: object): void|Response`
219+
### `static put(target: RequestTarget | Id, data: Promise<object> | object): void|Response`
217220
218221
This will assign the provided record or data to this resource, and is called for HTTP PUT requests. You can define or override this method to define how records should be updated. The default `put` method on tables (`super.put(target, data)`) writes the record to the table (updating or inserting depending on if the record previously existed) as part of the current transaction for the resource instance.
219222
220223
The `target` object represents the target of a request and can be used to access the path, coerced id, and any query parameters that were included in the URL.
221224
222-
### `static patch(target: RequestTarget | Id, data: object): void|Response`
225+
### `static patch(target: RequestTarget | Id, data: Promise<object> | object): void|Response`
223226
224227
This will update the existing record with the provided data's properties, and is called for HTTP PATCH requests. You can define or override this method to define how records should be updated. The default `patch` method on tables (`super.patch(target, data)`) updates the record. The properties will be applied to the existing record, overwriting the existing records properties, and preserving any properties in the record that are not specified in the `data` object. This is performed as part of the current transaction for the resource instance. The `target` object represents the target of a request and can be used to access the path, coerced id, and any query parameters that were included in the URL.
225228
@@ -267,11 +270,11 @@ Return the expiration time of the record.
267270
268271
This will delete this record or resource identified by the target, and is called for HTTP DELETE requests. You can define or override this method to define how records should be deleted. The default `delete` method on tables (`super.delete(target)`) deletes the record identified by target from the table as part of the current transaction. The `target` object represents the target of a request and can be used to access the path, coerced id, and any query parameters that were included in the URL.
269272
270-
### `static publish(target: RequestTarget, message): void|Response`
273+
### `static publish(target: RequestTarget, message: Promise<object> | object): void|Response`
271274
272275
This will publish a message to this resource, and is called for MQTT publish commands. You can define or override this method to define how messages should be published. The default `publish` method on tables (`super.publish(target, message)`) records the published message as part of the current transaction; this will not change the data in the record but will notify any subscribers to the record/topic. The `target` object represents the target of a request and can be used to access the path, coerced id, and any query parameters that were included in the URL.
273276
274-
### `static post(target: RequestTarget, data: object): void|Response`
277+
### `static post(target: RequestTarget, data: Promise<object> | object): void|Response`
275278
276279
This is called for HTTP POST requests. You can define this method to provide your own implementation of how POST requests should be handled. Generally `POST` provides a generic mechanism for various types of data updates, and is a good place to define custom functionality for updating records. The default behavior is to create a new record/resource. The `target` object represents the target of a request and can be used to access the path, coerced id, and any query parameters that were included in the URL.
277280

0 commit comments

Comments
 (0)