Skip to content

Commit 8d236ab

Browse files
Fix up all the broken code comments (#228)
* beep boop fix everything and im faster than the AI haha * revert mistake
1 parent 20ed7ac commit 8d236ab

File tree

63 files changed

+805
-815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+805
-815
lines changed

docs/developers/applications/caching.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ class ThirdPartyAPI extends Resource {
8686
async get() {
8787
const context = this.getContext();
8888
let headers = new Headers();
89-
if (context.replacingVersion) / this is the existing cached record
89+
if (context.replacingVersion) // this is the existing cached record
9090
headers.set('If-Modified-Since', new Date(context.replacingVersion).toUTCString());
9191
let response = await fetch(`https://some-api.com/${this.getId()}`, { headers });
9292
let cacheInfo = response.headers.get('Cache-Control');
9393
let maxAge = cacheInfo?.match(/max-age=(\d)/)?.[1];
94-
if (maxAge) / we can set a specific expiration time by setting context.expiresAt
95-
context.expiresAt = Date.now() + maxAge * 1000; / convert from seconds to milliseconds and add to current time
96-
/ we can just revalidate and return the record if the origin has confirmed that it has the same version:
94+
if (maxAge) // we can set a specific expiration time by setting context.expiresAt
95+
context.expiresAt = Date.now() + maxAge * 1000; // convert from seconds to milliseconds and add to current time
96+
// we can just revalidate and return the record if the origin has confirmed that it has the same version:
9797
if (response.status === 304) return context.replacingRecord;
9898
...
9999
```
@@ -111,7 +111,7 @@ const { MyTable } = tables;
111111
export class MyTableEndpoint extends MyTable {
112112
async post(data) {
113113
if (data.invalidate)
114-
/ use this flag as a marker
114+
// use this flag as a marker
115115
this.invalidate();
116116
}
117117
}
@@ -126,16 +126,16 @@ We can provide more control of an active cache with subscriptions. If there is a
126126
```javascript
127127
class ThirdPartyAPI extends Resource {
128128
async *subscribe() {
129-
setInterval(() => { / every second retrieve more data
130-
/ get the next data change event from the source
129+
setInterval(() => { // every second retrieve more data
130+
// get the next data change event from the source
131131
let update = (await fetch(`https://some-api.com/latest-update`)).json();
132-
const event = { / define the change event (which will update the cache)
133-
type: 'put', / this would indicate that the event includes the new data value
134-
id: / the primary key of the record that updated
135-
value: / the new value of the record that updated
136-
timestamp: / the timestamp of when the data change occurred
132+
const event = { // define the change event (which will update the cache)
133+
type: 'put', // this would indicate that the event includes the new data value
134+
id: // the primary key of the record that updated
135+
value: // the new value of the record that updated
136+
timestamp: // the timestamp of when the data change occurred
137137
};
138-
yield event; / this returns this event, notifying the cache of the change
138+
yield event; // this returns this event, notifying the cache of the change
139139
}, 1000);
140140
}
141141
async get() {
@@ -166,7 +166,7 @@ By default, Harper will only run the subscribe method on one thread. Harper is m
166166
```javascript
167167
class ThirdPartyAPI extends Resource {
168168
static subscribeOnThisThread(threadIndex) {
169-
return threadIndex < 2; / run on two threads (the first two threads)
169+
return threadIndex < 2; // run on two threads (the first two threads)
170170
}
171171
async *subscribe() {
172172
....
@@ -219,9 +219,9 @@ When you are using a caching table, it is important to remember that any resourc
219219
```javascript
220220
class MyCache extends tables.MyCache {
221221
async post(data) {
222-
/ if the data is not cached locally, retrieves from source:
222+
// if the data is not cached locally, retrieves from source:
223223
await this.ensuredLoaded();
224-
/ now we can be sure that the data is loaded, and can access properties
224+
// now we can be sure that the data is loaded, and can access properties
225225
this.quantity = this.quantity - data.purchases;
226226
}
227227
}
@@ -241,7 +241,7 @@ class BlogSource extends Resource {
241241
get() {
242242
const post = await (await fetch(`https://my-blog-server/${this.getId()}`).json());
243243
for (let comment of post.comments) {
244-
await Comment.put(comment, this); / save this comment as part of our current context and transaction
244+
await Comment.put(comment, this); // save this comment as part of our current context and transaction
245245
}
246246
return post;
247247
}

docs/developers/applications/defining-schemas.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ HNSW indexing finds the nearest neighbors to a search vector. To use this, you c
195195
```javascript
196196
let results = Product.search({
197197
sort: { attribute: 'textEmbeddings', target: searchVector },
198-
limit: 5, / get the five nearest neighbors
198+
limit: 5, // get the five nearest neighbors
199199
});
200200
```
201201

@@ -205,7 +205,7 @@ This can be used in combination with other conditions as well, for example:
205205
let results = Product.search({
206206
conditions: [{ attribute: 'price', comparator: 'lt', value: 50 }],
207207
sort: { attribute: 'textEmbeddings', target: searchVector },
208-
limit: 5, / get the five nearest neighbors
208+
limit: 5, // get the five nearest neighbors
209209
});
210210
```
211211

docs/developers/applications/index.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,16 @@ This guide is going to walk you through building a basic Harper application usin
8686
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:
8787

8888
```javascript
89-
/ resources.js:
90-
const { Dog } = tables; / get the Dog table from the Harper provided set of tables (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)
9191

9292
export class DogWithHumanAge extends Dog {
9393
static loadAsInstance = false;
9494
async get(target) {
9595
const record = await super.get(target);
9696
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
9999
};
100100
}
101101
}
@@ -123,14 +123,14 @@ We use the new table's (static) `get()` method to retrieve a breed by id. Harper
123123
The resource methods are automatically wrapped with a transaction and will automatically commit the changes when the method finishes. This allows us to fully utilize multiple resources in our current transaction. With our own snapshot of the database for the Dog and Breed table we can then access data like this:
124124

125125
```javascript
126-
/resource.js:
127-
const { Dog, Breed } = tables; / get the Breed table too
126+
//resource.js:
127+
const { Dog, Breed } = tables; // get the Breed table too
128128
export class DogWithBreed extends Dog {
129129
static loadAsInstance = false;
130130
async get(target) {
131-
/ get the Dog record
131+
// get the Dog record
132132
const record = await super.get(target);
133-
/ get the Breed record
133+
// get the Breed record
134134
let breedDescription = await Breed.get(record.breed);
135135
return {
136136
...record,
@@ -168,10 +168,10 @@ export class CustomDog extends Dog {
168168
async post(target, data) {
169169
if (data.action === 'add-trick') {
170170
const context = 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:
172172
target.checkPermissions = false;
173173
const record = this.update(target);
174-
/ and do our own/custom permission check:
174+
// and do our own/custom permission check:
175175
if (record.owner !== context.user?.username) {
176176
throw new Error('Can not update this record');
177177
}
@@ -186,7 +186,7 @@ Any methods that are not defined will fall back to Harper's default authorizatio
186186
You can also use the `default` export to define the root path resource handler. For example:
187187
188188
```javascript
189-
/ resources.json
189+
// resources.json
190190
export default class CustomDog extends Dog {
191191
...
192192
```
@@ -198,14 +198,14 @@ This will allow requests to url like / to be directly resolved to this resource.
198198
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:
199199
200200
```javascript
201-
const { Breed } = tables; / our Breed table
201+
const { Breed } = tables; // our Breed table
202202
class BreedSource extends Resource {
203-
/ define a data source
203+
// define a data source
204204
async get(target) {
205205
return (await fetch(`https://best-dog-site.com/${target}`)).json();
206206
}
207207
}
208-
/ define that our breed table is a cache of data from the data source above, with a specified expiration
208+
// define that our breed table is a cache of data from the data source above, with a specified expiration
209209
Breed.sourcedFrom(BreedSource, { expiration: 3600 });
210210
```
211211

docs/developers/real-time.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ WebSockets are supported through the REST interface and go through the `connect(
9696
```javascript
9797
let ws = new WebSocket('wss://server/my-resource/341');
9898
ws.onmessage = (event) => {
99-
/ received a notification from the server
99+
// received a notification from the server
100100
let data = JSON.parse(event.data);
101101
};
102102
```
@@ -106,8 +106,8 @@ By default, the resources will make a subscription to that resource, monitoring
106106
```javascript
107107
export class Echo extends Resource {
108108
async *connect(incomingMessages) {
109-
for await (let message of incomingMessages) { / wait for each incoming message from the client
110-
/ and send the message back to the client
109+
for await (let message of incomingMessages) { // wait for each incoming message from the client
110+
// and send the message back to the client
111111
yield message;
112112
}
113113
}
@@ -121,13 +121,13 @@ export class Example extends Resource {
121121
let outgoingMessages = super.connect();
122122
let timer = setInterval(() => {
123123
outgoingMessages.send({greeting: 'hi again!'});
124-
}, 1000); / send a message once a second
124+
}, 1000); // send a message once a second
125125
incomingMessages.on('data', (message) => {
126-
/ another way of echo-ing the data back to the client
126+
// another way of echo-ing the data back to the client
127127
outgoingMessages.send(message);
128128
});
129129
outgoingMessages.on('close', () => {
130-
/ make sure we end the timer once the connection is closed
130+
// make sure we end the timer once the connection is closed
131131
clearInterval(timer);
132132
});
133133
return outgoingMessages;
@@ -141,7 +141,7 @@ Server Sent Events (SSE) are also supported through the REST server interface, a
141141
```javascript
142142
let eventSource = new EventSource('https://server/my-resource/341', { withCredentials: true });
143143
eventSource.onmessage = (event) => {
144-
/ received a notification from the server
144+
// received a notification from the server
145145
let data = JSON.parse(event.data);
146146
};
147147
```

docs/developers/replication/sharding.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Additionally, you can specify `replicateTo` and `replicatedConfirmation` paramet
7575
class MyTable extends tables.MyTable {
7676
put(record) {
7777
const context = this.getContext();
78-
context.replicateTo = 2; / or an array of node names
78+
context.replicateTo = 2; // or an array of node names
7979
context.replicatedConfirmation = 1;
8080
return super.put(record);
8181
}
@@ -132,15 +132,15 @@ Alternately you can define a custom sharding strategy based on the primary key a
132132

133133
```javascript
134134
MyTable.setResidencyById((id) => {
135-
return id % 2 === 0 ? 1 : 2; / return shard number
135+
return id % 2 === 0 ? 1 : 2; // return shard number
136136
});
137137
```
138138

139139
or
140140

141141
```javascript
142142
MyTable.setResidencyById((id) => {
143-
return id % 2 === 0 ? ['node1'] : ['node2']; / return array of node hostnames
143+
return id % 2 === 0 ? ['node1'] : ['node2']; // return array of node hostnames
144144
});
145145
```
146146

docs/developers/security/users-and-roles.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@ Each table that a role should be given some level of CRUD permissions to must be
100100

101101
```json
102102
{
103-
"table_name": { / the name of the table to define CRUD perms for
104-
"read": boolean, / access to read from this table
105-
"insert": boolean, / access to insert data to table
106-
"update": boolean, / access to update data in table
107-
"delete": boolean, / access to delete row data in table
108-
"attribute_permissions": [ / permissions for specific table attributes
103+
"table_name": { // the name of the table to define CRUD perms for
104+
"read": boolean, // access to read from this table
105+
"insert": boolean, // access to insert data to table
106+
"update": boolean, // access to update data in table
107+
"delete": boolean, // access to delete row data in table
108+
"attribute_permissions": [ // permissions for specific table attributes
109109
{
110-
"attribute_name": "attribute_name", / attribute to assign permissions to
111-
"read": boolean, / access to read this attribute from table
112-
"insert": boolean, / access to insert this attribute into the table
113-
"update": boolean / access to update this attribute in the table
110+
"attribute_name": "attribute_name", // attribute to assign permissions to
111+
"read": boolean, // access to read this attribute from table
112+
"insert": boolean, // access to insert this attribute into the table
113+
"update": boolean // access to update this attribute in the table
114114
}
115115
]
116116
}

docs/technical-details/reference/blob.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class MyEndpoint extends MyTable {
3434
return {
3535
status: 200,
3636
headers: {},
37-
body: this.data, / this.data is a blob
37+
body: this.data, // this.data is a blob
3838
});
3939
}
4040
}
@@ -44,11 +44,11 @@ One of the important characteristics of blobs is they natively support asynchron
4444

4545
```javascript
4646
let blob = await createBlob(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
4848
await MyTable.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
5050
let record = await MyTable.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.
5252
let stream = record.data.stream();
5353
```
5454

@@ -57,9 +57,9 @@ Alternately, we can also wait for the blob to be fully written to storage before
5757

5858
```javascript
5959
let blob = await createBlob(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
6161
await blob.save(MyTable);
62-
/ we now know the blob is fully written to storage
62+
// we now know the blob is fully written to storage
6363
await MyTable.put({ id: 'my-record', data: blob });
6464
```
6565

@@ -73,7 +73,7 @@ Because blobs can be streamed and referenced prior to their completion, there is
7373
export class MyEndpoint extends MyTable {
7474
let blob = this.data;
7575
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:
7777
this.invalidate();
7878
});
7979
async get() {
@@ -93,11 +93,11 @@ Blobs that are created from streams may not have the standard `size` property av
9393
```javascript
9494
let record = await MyTable.get('my-record');
9595
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
9898
if (blob.size === undefined) {
9999
blob.on('size', (size) => {
100-
/ will be called once the size is available
100+
// will be called once the size is available
101101
})
102102
}
103103

docs/technical-details/reference/components/extensions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ test-component:
8686
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:
8787

8888
```js
89-
/ ESM
89+
// ESM
9090
export function handleFile() {}
9191
export function setupDirectory() {}
9292
93-
/ or CJS
93+
// or CJS
9494
function handleDirectory() {}
9595
function setupFile() {}
9696

0 commit comments

Comments
 (0)