You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/developers/applications/index.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,16 +86,16 @@ This guide is going to walk you through building a basic Harper application usin
86
86
To define custom (JavaScript) resources as endpoints, we need to create a `resources.js` module (this goes in the root of your application folder). And then endpoints can be defined with Resource classes that `export`ed. This can be done in addition to, or in lieu of the `@export`ed types in the schema.graphql. If you are exporting and extending a table you defined in the schema make sure you remove the `@export` from the schema so that don't export the original table or resource to the same endpoint/path you are exporting with a class. Resource classes have methods that correspond to standard HTTP/REST methods, like `get`, `post`, `patch`, and `put` to implement specific handling for any of these methods (for tables they all have default implementations). To do this, we get the `Dog` class from the defined tables, extend it, and export it:
87
87
88
88
```javascript
89
-
/resources.js:
90
-
const { Dog } = tables; / get the Dog table from the Harper provided set oftables (in the default database)
89
+
// resources.js:
90
+
const { Dog } = tables; // get the Dog table from the Harper provided set of tables (in the default database)
91
91
92
92
exportclassDogWithHumanAgeextendsDog {
93
93
static loadAsInstance =false;
94
94
asyncget(target) {
95
95
constrecord=awaitsuper.get(target);
96
96
return {
97
-
...record, / include all properties from the record
98
-
humanAge:15+record.age*5, / silly calculation of human age equivalent
97
+
...record, // include all properties from the record
98
+
humanAge:15+record.age*5, // silly calculation of human age equivalent
99
99
};
100
100
}
101
101
}
@@ -123,14 +123,14 @@ We use the new table's (static) `get()` method to retrieve a breed by id. Harper
@@ -168,10 +168,10 @@ export class CustomDog extends Dog {
168
168
asyncpost(target, data) {
169
169
if (data.action==='add-trick') {
170
170
constcontext=this.getContext();
171
-
/if we want to skip the default permission checks, we can turn off checkPermissions:
171
+
// if we want to skip the default permission checks, we can turn off checkPermissions:
172
172
target.checkPermissions=false;
173
173
constrecord=this.update(target);
174
-
/ and do our own/custom permission check:
174
+
// and do our own/custom permission check:
175
175
if (record.owner!==context.user?.username) {
176
176
thrownewError('Can not update this record');
177
177
}
@@ -186,7 +186,7 @@ Any methods that are not defined will fall back to Harper's default authorizatio
186
186
You can also use the `default` export to define the root path resource handler. For example:
187
187
188
188
```javascript
189
-
/resources.json
189
+
// resources.json
190
190
exportdefaultclassCustomDogextendsDog {
191
191
...
192
192
```
@@ -198,14 +198,14 @@ This will allow requests to url like / to be directly resolved to this resource.
198
198
We can also directly implement the Resource class and use it to create new data sources from scratch that can be used as endpoints. Custom resources can also be used as caching sources. Let's say that we defined a `Breed` table that was a cache of information about breeds from another source. We could implement a caching table like:
Copy file name to clipboardExpand all lines: docs/technical-details/reference/blob.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ export class MyEndpoint extends MyTable {
34
34
return {
35
35
status:200,
36
36
headers: {},
37
-
body:this.data, /this.data is a blob
37
+
body:this.data, // this.data is a blob
38
38
});
39
39
}
40
40
}
@@ -44,11 +44,11 @@ One of the important characteristics of blobs is they natively support asynchron
44
44
45
45
```javascript
46
46
let blob =awaitcreateBlob(stream);
47
-
/ at this point the blob exists, but the data is still being written to storage
47
+
// at this point the blob exists, but the data is still being written to storage
48
48
awaitMyTable.put({ id:'my-record', data: blob });
49
-
/ we now have written a record that references the blob
49
+
// we now have written a record that references the blob
50
50
let record =awaitMyTable.get('my-record');
51
-
/ we now have a record that gives us access to the blob. We can asynchronously access the blob's data or stream the data, and it will be available as blob the stream is written to the blob.
51
+
// we now have a record that gives us access to the blob. We can asynchronously access the blob's data or stream the data, and it will be available as blob the stream is written to the blob.
52
52
let stream =record.data.stream();
53
53
```
54
54
@@ -57,9 +57,9 @@ Alternately, we can also wait for the blob to be fully written to storage before
57
57
58
58
```javascript
59
59
let blob =awaitcreateBlob(stream);
60
-
/ at this point the blob exists, but the data is was not been written to storage
60
+
// at this point the blob exists, but the data is was not been written to storage
61
61
awaitblob.save(MyTable);
62
-
/ we now know the blob is fully written to storage
62
+
// we now know the blob is fully written to storage
63
63
awaitMyTable.put({ id:'my-record', data: blob });
64
64
```
65
65
@@ -73,7 +73,7 @@ Because blobs can be streamed and referenced prior to their completion, there is
73
73
exportclassMyEndpointextendsMyTable {
74
74
let blob =this.data;
75
75
blob.on('error', () => {
76
-
/ if this was a caching table, we may want to invalidate or delete this record:
76
+
// if this was a caching table, we may want to invalidate or delete this record:
77
77
this.invalidate();
78
78
});
79
79
asyncget() {
@@ -93,11 +93,11 @@ Blobs that are created from streams may not have the standard `size` property av
93
93
```javascript
94
94
let record =awaitMyTable.get('my-record');
95
95
let blob =record.data;
96
-
blob.size / will be available if it was saved with a known size
97
-
let stream blob.stream(); / start streaming the data
96
+
blob.size// will be available if it was saved with a known size
97
+
let stream blob.stream(); // start streaming the data
Copy file name to clipboardExpand all lines: docs/technical-details/reference/components/extensions.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,11 +86,11 @@ test-component:
86
86
In order for an extension to be classified as a Resource Extension it must implement at least one of the `handleFile()`, `handleDirectory()`, `setupFile()`, or `setupDirectory()` methods. As a standalone extension, these methods should be named and exported directly. For example:
0 commit comments