create-harper 0.12.3 → 0.13.0

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 (65) hide show
  1. package/package.json +1 -1
  2. package/template-react/AGENTS.md +5 -2
  3. package/template-react/resources/README.md +1 -1
  4. package/template-react/skills/adding-tables-with-schemas.md +2 -2
  5. package/template-react/skills/automatic-apis.md +53 -0
  6. package/template-react/skills/caching.md +113 -0
  7. package/template-react/skills/checking-authentication.md +100 -5
  8. package/template-react/skills/custom-resources.md +8 -4
  9. package/template-react/skills/defining-relationships.md +3 -3
  10. package/template-react/skills/extending-tables.md +7 -3
  11. package/template-react/skills/handling-binary-data.md +3 -3
  12. package/template-react/skills/programmatic-table-requests.md +3 -3
  13. package/template-react/skills/querying-rest-apis.md +2 -2
  14. package/template-react/skills/real-time-apps.md +8 -4
  15. package/template-react/skills/typescript-type-stripping.md +4 -4
  16. package/template-react/skills/using-blob-datatype.md +131 -0
  17. package/template-react/skills/vector-indexing.md +215 -0
  18. package/template-react-ts/AGENTS.md +5 -2
  19. package/template-react-ts/resources/README.md +1 -1
  20. package/template-react-ts/skills/adding-tables-with-schemas.md +2 -2
  21. package/template-react-ts/skills/automatic-apis.md +53 -0
  22. package/template-react-ts/skills/caching.md +113 -0
  23. package/template-react-ts/skills/checking-authentication.md +100 -5
  24. package/template-react-ts/skills/custom-resources.md +8 -4
  25. package/template-react-ts/skills/defining-relationships.md +3 -3
  26. package/template-react-ts/skills/extending-tables.md +7 -3
  27. package/template-react-ts/skills/handling-binary-data.md +3 -3
  28. package/template-react-ts/skills/programmatic-table-requests.md +3 -3
  29. package/template-react-ts/skills/querying-rest-apis.md +2 -2
  30. package/template-react-ts/skills/real-time-apps.md +8 -4
  31. package/template-react-ts/skills/typescript-type-stripping.md +4 -4
  32. package/template-react-ts/skills/using-blob-datatype.md +131 -0
  33. package/template-react-ts/skills/vector-indexing.md +215 -0
  34. package/template-vanilla/AGENTS.md +5 -2
  35. package/template-vanilla/resources/README.md +1 -1
  36. package/template-vanilla/skills/adding-tables-with-schemas.md +2 -2
  37. package/template-vanilla/skills/automatic-apis.md +53 -0
  38. package/template-vanilla/skills/caching.md +113 -0
  39. package/template-vanilla/skills/checking-authentication.md +100 -5
  40. package/template-vanilla/skills/custom-resources.md +8 -4
  41. package/template-vanilla/skills/defining-relationships.md +3 -3
  42. package/template-vanilla/skills/extending-tables.md +7 -3
  43. package/template-vanilla/skills/handling-binary-data.md +3 -3
  44. package/template-vanilla/skills/programmatic-table-requests.md +3 -3
  45. package/template-vanilla/skills/querying-rest-apis.md +2 -2
  46. package/template-vanilla/skills/real-time-apps.md +8 -4
  47. package/template-vanilla/skills/typescript-type-stripping.md +4 -4
  48. package/template-vanilla/skills/using-blob-datatype.md +131 -0
  49. package/template-vanilla/skills/vector-indexing.md +215 -0
  50. package/template-vanilla-ts/AGENTS.md +5 -2
  51. package/template-vanilla-ts/resources/README.md +1 -1
  52. package/template-vanilla-ts/skills/adding-tables-with-schemas.md +2 -2
  53. package/template-vanilla-ts/skills/automatic-apis.md +53 -0
  54. package/template-vanilla-ts/skills/caching.md +113 -0
  55. package/template-vanilla-ts/skills/checking-authentication.md +100 -5
  56. package/template-vanilla-ts/skills/custom-resources.md +8 -4
  57. package/template-vanilla-ts/skills/defining-relationships.md +3 -3
  58. package/template-vanilla-ts/skills/extending-tables.md +7 -3
  59. package/template-vanilla-ts/skills/handling-binary-data.md +3 -3
  60. package/template-vanilla-ts/skills/programmatic-table-requests.md +3 -3
  61. package/template-vanilla-ts/skills/querying-rest-apis.md +2 -2
  62. package/template-vanilla-ts/skills/real-time-apps.md +8 -4
  63. package/template-vanilla-ts/skills/typescript-type-stripping.md +4 -4
  64. package/template-vanilla-ts/skills/using-blob-datatype.md +131 -0
  65. package/template-vanilla-ts/skills/vector-indexing.md +215 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-harper",
3
3
  "description": "Scaffold a new Harper project in JavaScript or TypeScript.",
4
- "version": "0.12.3",
4
+ "version": "0.13.0",
5
5
  "type": "module",
6
6
  "author": {
7
7
  "name": "HarperDB",
@@ -1,11 +1,11 @@
1
- # HarperDB Agent Skills
1
+ # Harper Agent Skills
2
2
 
3
3
  This repository contains "skills" that guide AI agents in developing Harper applications.
4
4
 
5
5
  ## Available Skills
6
6
 
7
7
  - [Adding Tables with Schemas](skills/adding-tables-with-schemas.md): Learn how to define schemas and enable automatic REST APIs for your database tables with schema .graphql files in Harper.
8
- - [Automatic REST APIs](skills/automatic-rest-apis.md): Details on the CRUD endpoints automatically generated for exported tables.
8
+ - [Automatic APIs](skills/automatic-apis.md): Details on the CRUD endpoints automatically generated for exported tables with REST and WebSockets.
9
9
  - [Querying REST APIs](skills/querying-rest-apis.md): How to use filters, operators, sorting, and pagination in REST requests.
10
10
  - [Programmatic Table Requests](skills/programmatic-table-requests.md): How to use filters, operators, sorting, and pagination in programmatic table requests.
11
11
  - [Custom Resources](skills/custom-resources.md): How to define custom REST endpoints using JavaScript or TypeScript (Note: Paths are case-sensitive).
@@ -16,3 +16,6 @@ This repository contains "skills" that guide AI agents in developing Harper appl
16
16
  - [Handling Binary Data](skills/handling-binary-data.md): How to store and serve binary data like images or MP3s.
17
17
  - [Serving Web Content](skills/serving-web-content): Two ways to serve web content from a Harper application.
18
18
  - [Checking Authentication](skills/checking-authentication.md): How to use sessions to verify user identity and roles.
19
+ - [Caching](skills/caching.md): How caching is defined and implemented in Harper applications.
20
+ - [Using Blobs](skills/using-blob-datatype.md): How to store and retrieve large data in HarperDB.
21
+ - [Vector Indexing](skills/vector-indexing.md): How to define and use vector indexes for efficient similarity search.
@@ -1,6 +1,6 @@
1
1
  # Resources
2
2
 
3
- The [schemas you define in .GraphQL files](../skills/adding-tables-with-schemas.md) will [automatically stand-up REST APIs](../skills/automatic-rest-apis.md).
3
+ The [schemas you define in .GraphQL files](../skills/adding-tables-with-schemas.md) will [automatically stand-up REST APIs](../skills/automatic-apis.md).
4
4
 
5
5
  But you can [extend your tables with custom logic](../skills/extending-tables.md) and [create your own resources](../skills/custom-resources.md) in this directory.
6
6
 
@@ -1,4 +1,4 @@
1
- # Adding Tables to HarperDB
1
+ # Adding Tables to Harper
2
2
 
3
3
  To add tables to a Harper database, follow these guidelines:
4
4
 
@@ -8,7 +8,7 @@ To add tables to a Harper database, follow these guidelines:
8
8
 
9
9
  3. **Defining Relationships**: You can link tables together using the `@relationship` directive. For more details, see the [Defining Relationships](defining-relationships.md) skill.
10
10
 
11
- 4. **Automatic REST APIs**: If you add `@table @export` to a schema type, HarperDB automatically sets up REST APIs for basic CRUD operations against that table. For a detailed list of available endpoints and how to use them, see the [Automatic REST APIs](automatic-rest-apis.md) skill.
11
+ 4. **Automatic APIs**: If you add `@table @export` to a schema type, Harper automatically sets up REST and WebSocket APIs for basic CRUD operations against that table. For a detailed list of available endpoints and how to use them, see the [Automatic REST APIs](automatic-apis.md) skill.
12
12
 
13
13
  - `GET /{TableName}`: Describes the schema itself.
14
14
  - `GET /{TableName}/`: Lists all records (supports filtering, sorting, and pagination via query parameters). See the [Querying REST APIs](querying-rest-apis.md) skill for details.
@@ -0,0 +1,53 @@
1
+ # Automatic APIs in Harper
2
+
3
+ When you define a GraphQL type with the `@table` and `@export` directives, Harper automatically generates a fully-functional REST API and WebSocket interface for that table. This allows for immediate CRUD (Create, Read, Update, Delete) operations and real-time updates without writing any additional code.
4
+
5
+ ## Enabling Automatic APIs
6
+
7
+ To enable the automatic REST and WebSocket APIs for a table, ensure your GraphQL schema includes the `@export` directive:
8
+
9
+ ```graphql
10
+ type MyTable @table @export {
11
+ id: ID @primaryKey
12
+ # ... other fields
13
+ }
14
+ ```
15
+
16
+ ## Available REST Endpoints
17
+
18
+ The following endpoints are automatically created for a table named `TableName` (Note: Paths are **case-sensitive**, so `GET /TableName/` is valid while `GET /tablename/` is not):
19
+
20
+ - **Describe Schema**: `GET /{TableName}`
21
+ Returns the schema definition and metadata for the table.
22
+ - **List Records**: `GET /{TableName}/`
23
+ Lists all records in the table. This endpoint supports advanced filtering, sorting, and pagination. For more details, see the [Querying REST APIs](querying-rest-apis.md) skill.
24
+ - **Get Single Record**: `GET /{TableName}/{id}`
25
+ Retrieves a single record by its primary key (`id`).
26
+ - **Create Record**: `POST /{TableName}/`
27
+ Creates a new record. The request body should be a JSON object containing the record data.
28
+ - **Update Record (Full)**: `PUT /{TableName}/{id}`
29
+ Replaces the entire record at the specified `id` with the provided JSON data.
30
+ - **Update Record (Partial)**: `PATCH /{TableName}/{id}`
31
+ Updates only the specified fields of the record at the given `id`.
32
+ - **Delete All/Filtered Records**: `DELETE /{TableName}/`
33
+ Deletes all records in the table, or a subset of records if filtering parameters are provided.
34
+ - **Delete Single Record**: `DELETE /{TableName}/{id}`
35
+ Deletes the record with the specified `id`.
36
+
37
+ ## Automatic WebSockets
38
+
39
+ In addition to REST endpoints, Harper also stands up WebSocket interfaces for exported tables. When you connect to the table's endpoint via WebSocket, you will automatically receive events whenever updates are made to that table.
40
+
41
+ - **WebSocket Endpoint**: `ws://your-harper-instance/{TableName}`
42
+
43
+ This is the easiest way to add real-time capabilities to your application. For more complex real-time needs, see the [Real-time Applications](real-time-apps.md) skill.
44
+
45
+ ## Filtering and Querying
46
+
47
+ The `GET /{TableName}/` and `DELETE /{TableName}/` endpoints can be filtered using query parameters. While basic equality filters are straightforward, Harper supports a rich set of operators, sorting, and pagination.
48
+
49
+ For a comprehensive guide on advanced querying, see the [Querying REST APIs](querying-rest-apis.md) skill.
50
+
51
+ ## Customizing Resources
52
+
53
+ If the automatic APIs don't behave how you need, then you can look to [customize the resources](./custom-resources.md).
@@ -0,0 +1,113 @@
1
+ # Harper Caching
2
+
3
+ Harper includes integrated support for **caching data from external sources**, enabling high-performance, low-latency cache storage that is fully queryable and interoperable with your applications. With built-in caching capabilities and distributed responsiveness, Harper makes an ideal **data caching server** for both edge and centralized use cases.
4
+
5
+ ---
6
+
7
+ ## What is Harper Caching?
8
+
9
+ Harper caching lets you store **cached content** in standard tables, enabling you to:
10
+
11
+ - Expose cached entries as **queryable structured data** (e.g., JSON or CSV)
12
+ - Serve data to clients with **flexible formats and custom querying**
13
+ - Manage cache control with **timestamps and ETags** for downstream caching layers
14
+ - Implement **active or passive caching** patterns depending on your source and invalidation strategy
15
+
16
+ ---
17
+
18
+ ## Configuring a Cache Table
19
+
20
+ Define a cache table in your `schema.graphql`:
21
+
22
+ ```graphql
23
+ type MyCache @table(expiration: 3600) @export {
24
+ id: ID @primaryKey
25
+ }
26
+ ```
27
+
28
+ - `expiration` is defined in seconds
29
+ - Expired records are refreshed on access
30
+ - Evicted records are removed after expiration
31
+
32
+ ---
33
+
34
+ ## Connecting an External Source
35
+
36
+ Create a resource:
37
+
38
+ ```js
39
+ import { Resource } from 'harperdb';
40
+
41
+ export class ThirdPartyAPI extends Resource {
42
+ async get() {
43
+ const id = this.getId();
44
+ const response = await fetch(`https://api.example.com/items/${id}`);
45
+ if (!response.ok) {
46
+ throw new Error('Source fetch failed');
47
+ }
48
+ return await response.json();
49
+ }
50
+ }
51
+ ```
52
+
53
+ Attach it to your table:
54
+
55
+ ```js
56
+ import { tables } from 'harperdb';
57
+ import { ThirdPartyAPI } from './ThirdPartyAPI.js';
58
+
59
+ const { MyCache } = tables;
60
+ MyCache.sourcedFrom(ThirdPartyAPI);
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Cache Behavior
66
+
67
+ 1. Fresh data is returned immediately
68
+ 2. Missing or stale data triggers a fetch
69
+ 3. Concurrent misses are deduplicated
70
+
71
+ ---
72
+
73
+ ## Active Caching
74
+
75
+ Use `subscribe()` to proactively update or invalidate cache entries:
76
+
77
+ ```js
78
+ class MyAPI extends Resource {
79
+ async *subscribe() {
80
+ // stream updates
81
+ }
82
+ }
83
+ ```
84
+
85
+ See [Real Time Apps](real-time-apps.md) for more details.
86
+
87
+ ---
88
+
89
+ ## Write-Through Caching
90
+
91
+ Propagate updates upstream:
92
+
93
+ ```js
94
+ class ThirdPartyAPI extends Resource {
95
+ async put(data) {
96
+ await fetch(`https://some-api.com/${this.getId()}`, {
97
+ method: 'PUT',
98
+ body: JSON.stringify(data),
99
+ });
100
+ }
101
+ }
102
+ ```
103
+
104
+ ---
105
+
106
+ ## Summary
107
+
108
+ Harper Caching allows you to:
109
+
110
+ - Cache external APIs efficiently
111
+ - Query cached data like native tables
112
+ - Prevent cache stampedes
113
+ - Build real-time or write-through caches
@@ -1,8 +1,8 @@
1
- # Checking Authentication and Sessions in this app (HarperDB Resources)
1
+ # Checking Authentication and Sessions in this app (Harper Resources)
2
2
 
3
- This project uses HarperDB Resource classes with cookie-backed sessions to enforce authentication and authorization. Below are the concrete patterns used across resources like `resources/me.ts`, `resources/signIn.ts`, `resources/signOut.ts`, and protected endpoints such as `resources/downloadAlbumArtwork.ts`.
3
+ This project uses Harper Resource classes with cookie-backed sessions to enforce authentication and authorization. Below are the concrete patterns used across resources like `resources/me.ts`, `resources/signIn.ts`, `resources/signOut.ts`, and protected endpoints such as `resources/downloadAlbumArtwork.ts`.
4
4
 
5
- Important: To actually enforce sessions (even on localhost), HarperDB must not auto-authorize the local loopback as the superuser. Ensure the following in your HarperDB config (see `~/hdb/harperdb-config.yaml`):
5
+ Important: To actually enforce sessions (even on localhost), Harper must not auto-authorize the local loopback as the superuser. Ensure the following in your Harper config (see `~/hdb/harperdb-config.yaml`):
6
6
 
7
7
  ```yaml
8
8
  authentication:
@@ -174,13 +174,108 @@ export function ensureSuperUser(user: User | undefined) {
174
174
 
175
175
  ## Client considerations
176
176
 
177
- - Sessions are cookie-based; the server handles setting and reading the cookie via HarperDB. If you make cross-origin requests, ensure the appropriate `credentials` mode and CORS settings.
177
+ - Sessions are cookie-based; the server handles setting and reading the cookie via Harper. If you make cross-origin requests, ensure the appropriate `credentials` mode and CORS settings.
178
178
  - If developing locally, double-check the server config still has `authentication.authorizeLocal: false` to avoid accidental superuser bypass.
179
179
 
180
+ ## Token-based auth (JWT + refresh token) for non-browser clients
181
+
182
+ Cookie-backed sessions are great for browser flows. For CLI tools, mobile apps, or other non-browser clients, it’s often easier to use **explicit tokens**:
183
+
184
+ - **JWT (`operation_token`)**: short-lived bearer token used to authorize API requests.
185
+ - **Refresh token (`refresh_token`)**: longer-lived token used to mint a new JWT when it expires.
186
+
187
+ This project includes two Resource patterns for that flow:
188
+
189
+ ### Issuing tokens: `IssueTokens`
190
+
191
+ **Description / use case:** Generate `{ refreshToken, jwt }` either:
192
+
193
+ - with an existing Authorization token (either Basic Auth or a JWT) and you want to issue new tokens, or
194
+ - from an explicit `{ username, password }` payload (useful for direct “login” from a CLI/mobile client).
195
+
196
+ ```
197
+ js
198
+ export class IssueTokens extends Resource {
199
+ static loadAsInstance = false;
200
+
201
+ async get(target) {
202
+ const { refresh_token: refreshToken, operation_token: jwt } =
203
+ await databases.system.hdb_user.operation(
204
+ { operation: 'create_authentication_tokens' },
205
+ this.getContext(),
206
+ );
207
+ return { refreshToken, jwt };
208
+ }
209
+
210
+ async post(target, data) {
211
+ if (!data.username || !data.password) {
212
+ throw new Error('username and password are required');
213
+ }
214
+
215
+ const { refresh_token: refreshToken, operation_token: jwt } =
216
+ await databases.system.hdb_user.operation({
217
+ operation: 'create_authentication_tokens',
218
+ username: data.username,
219
+ password: data.password,
220
+ });
221
+ return { refreshToken, jwt };
222
+ }
223
+ }
224
+ ```
225
+
226
+ **Recommended documentation notes to include:**
227
+
228
+ - `GET` variant: intended for “I already have an Authorization token, give me new tokens”.
229
+ - `POST` variant: intended for “I have credentials, give me tokens”.
230
+ - Response shape:
231
+ - `refreshToken`: store securely (long-lived).
232
+ - `jwt`: attach to requests (short-lived).
233
+
234
+ ### Refreshing a JWT: `RefreshJWT`
235
+
236
+ **Description / use case:** When the JWT expires, the client uses the refresh token to get a new JWT without re-supplying username/password.
237
+
238
+ ```
239
+ js
240
+ export class RefreshJWT extends Resource {
241
+ static loadAsInstance = false;
242
+
243
+ async post(target, data) {
244
+ if (!data.refreshToken) {
245
+ throw new Error('refreshToken is required');
246
+ }
247
+
248
+ const { operation_token: jwt } = await databases.system.hdb_user.operation({
249
+ operation: 'refresh_operation_token',
250
+ refresh_token: data.refreshToken,
251
+ });
252
+ return { jwt };
253
+ }
254
+ }
255
+ ```
256
+
257
+ **Recommended documentation notes to include:**
258
+
259
+ - Requires `refreshToken` in the request body.
260
+ - Returns a new `{ jwt }`.
261
+ - If refresh fails (expired/revoked), client must re-authenticate (e.g., call `IssueTokens.post` again).
262
+
263
+ ### Suggested client flow (high-level)
264
+
265
+ 1. **Sign in (token flow)**
266
+ - POST /IssueTokens/ with a body of `{ "username": "your username", "password": "your password" }` or GET /IssueTokens/ with an existing Authorization token.
267
+ - Receive `{ jwt, refreshToken }` in the response
268
+ 2. **Call protected APIs**
269
+ - Send the JWT with each request in the Authorization header (as your auth mechanism expects)
270
+ 3. **JWT expires**
271
+ - POST /RefreshJWT/ with a body of `{ "refreshToken": "your refresh token" }`.
272
+ - Receive `{ jwt }` in the response and continue
273
+
180
274
  ## Quick checklist
181
275
 
182
276
  - [ ] Public endpoints explicitly `allowRead`/`allowCreate` as needed.
183
277
  - [ ] Sign-in uses `context.login` and handles 400/403 correctly.
184
278
  - [ ] Protected routes call `ensureSuperUser(this.getCurrentUser())` (or another role check) before doing work.
185
279
  - [ ] Sign-out verifies a session and deletes it.
186
- - [ ] `authentication.authorizeLocal` is `false` and `enableSessions` is `true` in HarperDB config.
280
+ - [ ] `authentication.authorizeLocal` is `false` and `enableSessions` is `true` in Harper config.
281
+ - [ ] If using tokens: `IssueTokens` issues `{ jwt, refreshToken }`, `RefreshJWT` refreshes `{ jwt }` with a `refreshToken`.
@@ -1,8 +1,12 @@
1
- # Custom Resources in HarperDB
1
+ # Custom Resources in Harper
2
2
 
3
3
  Custom Resources allow you to define your own REST endpoints with custom logic by writing JavaScript or TypeScript code. This is useful when the automatic CRUD operations provided by `@table @export` are not enough.
4
4
 
5
- HarperDB supports [TypeScript Type Stripping](typescript-type-stripping.md), allowing you to use TypeScript directly without additional build tools on supported Node.js versions.
5
+ Harper supports [TypeScript Type Stripping](typescript-type-stripping.md), allowing you to use TypeScript directly without additional build tools on supported Node.js versions.
6
+
7
+ ## Do you need a custom resource?
8
+
9
+ Exported tables have [automatic APIs](./automatic-apis.md) as a part of them. These APIs may be enough for what you need. Take a look at [extendings tables](./extending-tables.md) to learn more about resources with a backing table.
6
10
 
7
11
  ## Defining a Custom Resource
8
12
 
@@ -21,7 +25,7 @@ interface GreetingRecord {
21
25
  }
22
26
 
23
27
  export class Greeting extends Resource<GreetingRecord> {
24
- // Set to false if you want HarperDB to manage the instance lifecycle
28
+ // Set to false if you want Harper to manage the instance lifecycle
25
29
  static loadAsInstance = false;
26
30
 
27
31
  async get(target?: RequestTargetOrId): Promise<GreetingRecord> {
@@ -79,4 +83,4 @@ Once defined and configured, your resource will be available at a REST endpoint
79
83
 
80
84
  ### Case Sensitivity
81
85
 
82
- Paths in HarperDB are **case-sensitive**. A resource class named `MyResource` will be accessible only at `/MyResource/`, not `/myresource/`.
86
+ Paths in Harper are **case-sensitive**. A resource class named `MyResource` will be accessible only at `/MyResource/`, not `/myresource/`.
@@ -1,6 +1,6 @@
1
- # Defining Relationships in HarperDB
1
+ # Defining Relationships in Harper
2
2
 
3
- HarperDB allows you to define relationships between tables using the `@relationship` directive in your GraphQL schema. This enables powerful features like automatic joins when querying through REST APIs.
3
+ Harper allows you to define relationships between tables using the `@relationship` directive in your GraphQL schema. This enables powerful features like automatic joins when querying through REST APIs.
4
4
 
5
5
  ## The `@relationship` Directive
6
6
 
@@ -67,5 +67,5 @@ This returns authors with their names and a list of their books (only the titles
67
67
  ## Benefits of `@relationship`
68
68
 
69
69
  - **Simplified Queries**: No need for complex manual joins in your code.
70
- - **Efficient Data Fetching**: HarperDB optimizes relationship lookups.
70
+ - **Efficient Data Fetching**: Harper optimizes relationship lookups.
71
71
  - **Improved API Discoverability**: Related data structures are clearly defined in your schema.
@@ -1,6 +1,10 @@
1
- # Extending Table Resources in HarperDB
1
+ # Extending Table Resources in Harper
2
2
 
3
- In HarperDB, when you define a table in GraphQL and export it, you can extend the automatically generated resource class to add custom logic, validation, or hooks to standard CRUD operations.
3
+ In Harper, when you define a table in GraphQL and export it, you can extend the automatically generated resource class to add custom logic, validation, or hooks to standard CRUD operations.
4
+
5
+ ## Do you need to extend tables?
6
+
7
+ Exported tables have [automatic APIs](./automatic-apis.md) as a part of them. These APIs may be sufficient for what you need.
4
8
 
5
9
  ## How to Extend a Table Resource
6
10
 
@@ -53,7 +57,7 @@ export class ExamplePeople extends tables.ExamplePeople<ExamplePerson> {
53
57
 
54
58
  ## Important Note
55
59
 
56
- When you extend a table resource, HarperDB uses your custom class for all REST API interactions with that table. Make sure to call `super[method]` if you still want the default behavior to occur after your custom logic.
60
+ When you extend a table resource, Harper uses your custom class for all REST API interactions with that table. Make sure to call `super[method]` if you still want the default behavior to occur after your custom logic.
57
61
 
58
62
  Extended tables do not need to be `@export`ed in their schema .graphql.
59
63
 
@@ -1,6 +1,6 @@
1
- # Handling Binary Data in HarperDB
1
+ # Handling Binary Data in Harper
2
2
 
3
- When working with binary data (such as images or audio files) in HarperDB, you often receive this data as base64-encoded strings through JSON REST APIs. To store this data efficiently in a `Blob` field, you should convert it to a `Buffer`.
3
+ When working with binary data (such as images or audio files) in Harper, you often receive this data as base64-encoded strings through JSON REST APIs. To store this data efficiently in a `Blob` field, you should convert it to a `Buffer`.
4
4
 
5
5
  ## Storing Base64 Strings as Buffers
6
6
 
@@ -63,5 +63,5 @@ export class TrackResource extends Resource {
63
63
  ## Why Use Blobs?
64
64
 
65
65
  - **Efficiency**: `Blob` fields are optimized for storing binary data. Buffers are the standard way to handle binary data in Node.js.
66
- - **Compatibility**: Many HarperDB features and external libraries expect binary data to be in `Buffer` or `Uint8Array` format.
66
+ - **Compatibility**: Many Harper features and external libraries expect binary data to be in `Buffer` or `Uint8Array` format.
67
67
  - **Storage**: Storing data as binary is more compact than storing it as a base64-encoded string.
@@ -1,10 +1,10 @@
1
- # Programmatic Requests with HarperDB Tables
1
+ # Programmatic Requests with Harper Tables
2
2
 
3
- In HarperDB, you can interact with your database tables programmatically using the global `tables` object. Each table defined in your schema is available as a property on this object.
3
+ In Harper, you can interact with your database tables programmatically using the global `tables` object. Each table defined in your schema is available as a property on this object.
4
4
 
5
5
  ## Basic Usage
6
6
 
7
- The `tables` object provides a direct way to perform CRUD operations from within your HarperDB resources or scripts.
7
+ The `tables` object provides a direct way to perform CRUD operations from within your Harper resources or scripts.
8
8
 
9
9
  ```typescript
10
10
  const track = await tables.ExamplePeople.get(id) as ExamplePerson;
@@ -1,6 +1,6 @@
1
- # Querying through REST APIs in HarperDB
1
+ # Querying through REST APIs in Harper
2
2
 
3
- HarperDB's automatic REST APIs support powerful querying capabilities directly through URL query parameters. This allows you to filter, sort, paginate, and join data without writing complex queries.
3
+ Harper's automatic REST APIs support powerful querying capabilities directly through URL query parameters. This allows you to filter, sort, paginate, and join data without writing complex queries.
4
4
 
5
5
  ## Basic Filtering
6
6
 
@@ -1,10 +1,14 @@
1
- # Real-time Applications in HarperDB
1
+ # Real-time Applications in Harper
2
2
 
3
- HarperDB provides built-in support for real-time data synchronization using WebSockets and a Pub/Sub mechanism. This allows clients to receive immediate updates when data changes in the database.
3
+ Harper provides built-in support for real-time data synchronization using WebSockets and a Pub/Sub mechanism. This allows clients to receive immediate updates when data changes in the database.
4
+
5
+ ## Automatic WebSockets
6
+
7
+ For many use cases, the [Automatic APIs](automatic-apis.md) provided by Harper are more than enough. When you `@export` a table, Harper automatically provides a WebSocket endpoint that publishes events whenever data in that table is updated.
4
8
 
5
9
  ## Implementing a WebSocket Resource
6
10
 
7
- To handle WebSocket connections, implement the `connect` method in your custom resource class.
11
+ Customizing resources by implementing a `connect` method is only necessary when you want to come up with a more specific back-and-forth or custom message handling. To handle WebSocket connections, implement the `connect` method in your custom resource class.
8
12
 
9
13
  ### Example: `resources/exampleSocket.ts`
10
14
 
@@ -68,4 +72,4 @@ socket.send(JSON.stringify({ type: 'ping' }));
68
72
 
69
73
  - **Automatic Table Subscriptions**: Easily stream changes from any database table.
70
74
  - **Bi-directional Communication**: Send and receive messages in real-time.
71
- - **Scalable Pub/Sub**: HarperDB handles the efficient distribution of messages to subscribers.
75
+ - **Scalable Pub/Sub**: Harper handles the efficient distribution of messages to subscribers.
@@ -1,16 +1,16 @@
1
1
  # TypeScript Type Stripping
2
2
 
3
- HarperDB supports using TypeScript directly without any additional build tools (like `tsc` or `esbuild`) by leveraging Node.js's native Type Stripping capability. This allows you to write `.ts` files for your Custom Resources and have them run directly in HarperDB.
3
+ Harper supports using TypeScript directly without any additional build tools (like `tsc` or `esbuild`) by leveraging Node.js's native Type Stripping capability. This allows you to write `.ts` files for your Custom Resources and have them run directly in Harper.
4
4
 
5
5
  ## Requirements
6
6
 
7
7
  - **Node.js Version**: You must be running a version of Node.js that supports type stripping (Node.js v22.6.0 or higher).
8
- - **No Experimental Flags**: When running on supported Node.js versions, HarperDB can automatically handle type stripping for your resource files.
8
+ - **No Experimental Flags**: When running on supported Node.js versions, Harper can automatically handle type stripping for your resource files.
9
9
 
10
10
  ## Benefits
11
11
 
12
12
  - **Faster Development**: No need to wait for a build step or manage complex build pipelines.
13
- - **Simplified Tooling**: You don't need to install or configure `ts-node`, `tsx`, or other TypeScript execution engines for your HarperDB resources.
13
+ - **Simplified Tooling**: You don't need to install or configure `ts-node`, `tsx`, or other TypeScript execution engines for your Harper resources.
14
14
  - **Native Performance**: Leverages Node.js's built-in support for stripping types, which is highly efficient.
15
15
 
16
16
  ## Usage
@@ -44,4 +44,4 @@ jsResource:
44
44
  files: 'resources/*.ts'
45
45
  ```
46
46
 
47
- When HarperDB starts, it will detect the `.ts` files and, if running on a compatible Node.js version, will execute them using type stripping.
47
+ When Harper starts, it will detect the `.ts` files and, if running on a compatible Node.js version, will execute them using type stripping.
@@ -0,0 +1,131 @@
1
+ # Blob (Binary Large Objects)
2
+
3
+ Harper supports **Blobs** — binary large objects for storing unstructured or large binary data — with integrated streaming support and efficient storage. Blobs are ideal for media files, documents, and any data where size or throughput makes standard JSON fields impractical.
4
+
5
+ ---
6
+
7
+ ## What Are Blobs
8
+
9
+ Blobs extend the native JavaScript `Blob` type and allow you to store **binary or arbitrary data** inside Harper tables. The blob reference is stored in the record, while the blob’s contents are streamed to and from storage.
10
+
11
+ - Designed for binary data such as images, audio, and documents
12
+ - Supports streaming reads and writes
13
+ - Blob data is stored separately from record attributes
14
+ - Optimized for large payloads
15
+
16
+ ---
17
+
18
+ ## Defining Blob Fields
19
+
20
+ Declare a blob field using the `Blob` type in your schema:
21
+
22
+ ```graphql
23
+ type MyTable @table {
24
+ id: ID @primaryKey
25
+ data: Blob
26
+ }
27
+ ```
28
+
29
+ Any record written to this field will store a reference to the blob’s contents.
30
+
31
+ ---
32
+
33
+ ## Creating and Storing Blobs
34
+
35
+ ### Creating a Blob from a Buffer
36
+
37
+ ```js
38
+ const blob = createBlob(largeBuffer);
39
+ await MyTable.put({ id: 'my-record', data: blob });
40
+ ```
41
+
42
+ - `createBlob()` returns a blob reference
43
+ - Data is streamed to storage asynchronously
44
+ - Records may be committed before the blob finishes writing
45
+
46
+ ---
47
+
48
+ ### Creating a Blob from a Stream
49
+
50
+ ```js
51
+ const blob = createBlob(stream);
52
+ await MyTable.put({ id: 'streamed-record', data: blob });
53
+ ```
54
+
55
+ Streaming allows large data to be written without loading it fully into memory.
56
+
57
+ ---
58
+
59
+ ## Reading Blob Data
60
+
61
+ Retrieve a record and read its blob contents:
62
+
63
+ ```js
64
+ const record = await MyTable.get('my-record');
65
+ const buffer = await record.data.bytes();
66
+ ```
67
+
68
+ Blob objects also support streaming interfaces for large reads.
69
+
70
+ ---
71
+
72
+ ## Blob Attributes and Events
73
+
74
+ ### Size
75
+
76
+ The blob size may not be immediately available when streaming:
77
+
78
+ ```js
79
+ if (blob.size === undefined) {
80
+ blob.on('size', size => {
81
+ console.log('Blob size:', size);
82
+ });
83
+ }
84
+ ```
85
+
86
+ ---
87
+
88
+ ### saveBeforeCommit
89
+
90
+ Blobs are not atomic while streaming. To ensure the blob is fully written before committing the record:
91
+
92
+ ```js
93
+ const blob = createBlob(stream, { saveBeforeCommit: true });
94
+ await MyTable.put({ id: 'safe-record', data: blob });
95
+ ```
96
+
97
+ ---
98
+
99
+ ## Error Handling
100
+
101
+ Handle streaming errors by attaching an error listener:
102
+
103
+ ```js
104
+ blob.on('error', () => {
105
+ MyTable.invalidate('my-record');
106
+ });
107
+ ```
108
+
109
+ This prevents partially written blobs from being used.
110
+
111
+ ---
112
+
113
+ ## Automatic Coercion
114
+
115
+ When a field is defined as `Blob`, assigning a string or buffer automatically converts it into a blob when using `put`, `patch`, or `publish`.
116
+
117
+ ---
118
+
119
+ ## Related Skill
120
+
121
+ - [Handling Binary Data with Blobs](handling-binary-data.md) How to store and serve binary data like images or MP3s using the Blob data type.
122
+
123
+ ---
124
+
125
+ ## Summary
126
+
127
+ - Blobs store large or binary data efficiently
128
+ - Blob fields reference streamed content
129
+ - Supports buffered and streamed writes
130
+ - Optional write-before-commit behavior
131
+ - Integrates seamlessly with Harper tables