@harperfast/template-vue-ts-studio 1.9.0 → 1.9.2
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.
- package/.agents/skills/harper-best-practices/AGENTS.md +16 -12
- package/.agents/skills/harper-best-practices/rules/custom-resources.md +5 -4
- package/.agents/skills/harper-best-practices/rules/extending-tables.md +11 -8
- package/agent/skills/harper-best-practices/AGENTS.md +1950 -0
- package/agent/skills/harper-best-practices/SKILL.md +96 -0
- package/agent/skills/harper-best-practices/rules/adding-tables-with-schemas.md +42 -0
- package/agent/skills/harper-best-practices/rules/automatic-apis.md +165 -0
- package/agent/skills/harper-best-practices/rules/caching.md +163 -0
- package/agent/skills/harper-best-practices/rules/checking-authentication.md +190 -0
- package/agent/skills/harper-best-practices/rules/creating-a-fabric-account-and-cluster.md +30 -0
- package/agent/skills/harper-best-practices/rules/creating-harper-apps.md +54 -0
- package/agent/skills/harper-best-practices/rules/custom-resources.md +44 -0
- package/agent/skills/harper-best-practices/rules/defining-relationships.md +35 -0
- package/agent/skills/harper-best-practices/rules/deploying-to-harper-fabric.md +122 -0
- package/agent/skills/harper-best-practices/rules/extending-tables.md +46 -0
- package/agent/skills/harper-best-practices/rules/handling-binary-data.md +45 -0
- package/agent/skills/harper-best-practices/rules/load-env.md +111 -0
- package/agent/skills/harper-best-practices/rules/logging.md +169 -0
- package/agent/skills/harper-best-practices/rules/programmatic-table-requests.md +134 -0
- package/agent/skills/harper-best-practices/rules/querying-rest-apis.md +202 -0
- package/agent/skills/harper-best-practices/rules/real-time-apps.md +102 -0
- package/agent/skills/harper-best-practices/rules/schema-design-tooling.md +161 -0
- package/agent/skills/harper-best-practices/rules/serving-web-content.md +85 -0
- package/agent/skills/harper-best-practices/rules/typescript-type-stripping.md +64 -0
- package/agent/skills/harper-best-practices/rules/using-blob-datatype.md +38 -0
- package/agent/skills/harper-best-practices/rules/vector-indexing.md +124 -0
- package/agent/skills/harper-best-practices/rules.manifest.yaml +302 -0
- package/package.json +1 -1
- package/skills-lock.json +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: programmatic-table-requests
|
|
3
|
+
description: How to interact with Harper tables programmatically using the `tables` object.
|
|
4
|
+
metadata:
|
|
5
|
+
mode: synthesized
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Programmatic Table Requests
|
|
9
|
+
|
|
10
|
+
Instructions for the agent to follow when interacting with Harper tables via code.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
Use this skill when you need to perform database operations (CRUD, search, subscribe) from within Harper Resources or scripts.
|
|
15
|
+
|
|
16
|
+
## How It Works
|
|
17
|
+
|
|
18
|
+
1. **Access the Table**: Use the global `tables` object followed by your table name (e.g., `tables.MyTable`).
|
|
19
|
+
2. **Perform CRUD Operations**:
|
|
20
|
+
- **Get**: `await tables.MyTable.get(id)` for a single record or `await tables.MyTable.get({ conditions: [...] })` for multiple.
|
|
21
|
+
- **Create**: `await tables.MyTable.post(record)` (auto-generates ID) or `await tables.MyTable.put(id, record)`.
|
|
22
|
+
- **Update**: `await tables.MyTable.patch(id, partialRecord)` for partial updates.
|
|
23
|
+
- **Delete**: `await tables.MyTable.delete(id)`.
|
|
24
|
+
3. **Use Updatable Records for Atomic Ops**: Call `update(id)` to get a reference, then use `addTo` or `subtractFrom` for atomic increments/decrements:
|
|
25
|
+
```typescript
|
|
26
|
+
const stats = await tables.Stats.update('daily');
|
|
27
|
+
stats.addTo('viewCount', 1);
|
|
28
|
+
```
|
|
29
|
+
4. **Search and Stream**: Use `search(query)` for efficient streaming of large result sets:
|
|
30
|
+
```typescript
|
|
31
|
+
for await (const record of tables.MyTable.search({ conditions: [...] })) {
|
|
32
|
+
// process record
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
See the [Query Conditions](#query-conditions) section below for the full query object reference.
|
|
36
|
+
5. **Real-time Subscriptions**: Use `subscribe(query)` to listen for changes:
|
|
37
|
+
```typescript
|
|
38
|
+
for await (const event of tables.MyTable.subscribe(query)) {
|
|
39
|
+
// handle event
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
6. **Publish Events**: Use `publish(id, message)` to trigger subscriptions without necessarily persisting data.
|
|
43
|
+
|
|
44
|
+
## Query Conditions
|
|
45
|
+
|
|
46
|
+
When passing a query to `search()`, `get()`, or `subscribe()`, use a query object with a `conditions` array.
|
|
47
|
+
|
|
48
|
+
### Condition Object Shape
|
|
49
|
+
|
|
50
|
+
| Property | Description |
|
|
51
|
+
| ------------ | ------------------------------------------------------------------------------------------ |
|
|
52
|
+
| `attribute` | Field name, or array of field names to traverse a relationship (e.g., `['brand', 'name']`) |
|
|
53
|
+
| `value` | The value to compare against |
|
|
54
|
+
| `comparator` | One of the comparator strings below (default: `equals`) |
|
|
55
|
+
| `operator` | `and` (default) or `or` — applies to a nested `conditions` block |
|
|
56
|
+
| `conditions` | Nested array of condition objects for complex AND/OR logic |
|
|
57
|
+
|
|
58
|
+
### Comparator Values
|
|
59
|
+
|
|
60
|
+
Use these exact strings — incorrect comparator names will silently fail or error:
|
|
61
|
+
|
|
62
|
+
| Comparator | Meaning |
|
|
63
|
+
| -------------------- | ---------------------------------------------------------- |
|
|
64
|
+
| `equals` | Exact match (default) |
|
|
65
|
+
| `not_equal` | Not equal |
|
|
66
|
+
| `greater_than` | `>` |
|
|
67
|
+
| `greater_than_equal` | `>=` |
|
|
68
|
+
| `less_than` | `<` |
|
|
69
|
+
| `less_than_equal` | `<=` |
|
|
70
|
+
| `starts_with` | String starts with value |
|
|
71
|
+
| `contains` | String contains value |
|
|
72
|
+
| `ends_with` | String ends with value |
|
|
73
|
+
| `between` | Value is between two bounds (pass `value` as `[min, max]`) |
|
|
74
|
+
|
|
75
|
+
### Query Object Parameters
|
|
76
|
+
|
|
77
|
+
| Property | Description |
|
|
78
|
+
| ------------ | ------------------------------------------------------------------------------------ |
|
|
79
|
+
| `conditions` | Array of condition objects |
|
|
80
|
+
| `limit` | Maximum number of records to return |
|
|
81
|
+
| `offset` | Number of records to skip (for pagination) |
|
|
82
|
+
| `select` | Array of attribute names to return; supports `$id` and `$updatedtime` |
|
|
83
|
+
| `sort` | Object with `attribute`, `descending` (bool), and optional `next` for secondary sort |
|
|
84
|
+
|
|
85
|
+
### Examples
|
|
86
|
+
|
|
87
|
+
**Simple filter:**
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
for await (const record of tables.Product.search({
|
|
91
|
+
conditions: [{ attribute: 'price', comparator: 'less_than', value: 100 }],
|
|
92
|
+
limit: 20,
|
|
93
|
+
})) { ... }
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**AND + nested OR:**
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
for await (const record of tables.Product.search({
|
|
100
|
+
conditions: [
|
|
101
|
+
{ attribute: 'price', comparator: 'less_than', value: 100 },
|
|
102
|
+
{
|
|
103
|
+
operator: 'or',
|
|
104
|
+
conditions: [
|
|
105
|
+
{ attribute: 'rating', comparator: 'greater_than', value: 4 },
|
|
106
|
+
{ attribute: 'featured', value: true },
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
})) { ... }
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Relationship traversal:**
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
for await (const record of tables.Book.search({
|
|
117
|
+
conditions: [{ attribute: ['brand', 'name'], comparator: 'equals', value: 'Harper' }],
|
|
118
|
+
})) { ... }
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Sort and paginate:**
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
for await (const record of tables.Product.search({
|
|
125
|
+
conditions: [{ attribute: 'inStock', value: true }],
|
|
126
|
+
sort: { attribute: 'price', descending: false },
|
|
127
|
+
limit: 10,
|
|
128
|
+
offset: 20,
|
|
129
|
+
})) { ... }
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Cautions
|
|
133
|
+
|
|
134
|
+
Be very careful when performing updates and deletions! You may be dealing with live production data. The wrong request to delete, without approval from a human, could be devastating to a business. Always use the proper approval process.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: querying-rest-apis
|
|
3
|
+
description: 'How to use query parameters to filter, sort, and paginate Harper REST APIs.'
|
|
4
|
+
metadata:
|
|
5
|
+
mode: generate
|
|
6
|
+
sources:
|
|
7
|
+
- reference/v5/rest/querying.md
|
|
8
|
+
sourceCommit: b7fbddadd42eb4487190b650a9abc4bcfeef5819
|
|
9
|
+
inputHash: 9f8c981a629ef606
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Querying REST APIs
|
|
13
|
+
|
|
14
|
+
Instructions for the agent to filter, sort, select, and paginate Harper REST API collections using URL query parameters.
|
|
15
|
+
|
|
16
|
+
## When to Use
|
|
17
|
+
|
|
18
|
+
Apply this rule when building or modifying code that queries Harper REST endpoints with filtering, sorting, field selection, or pagination. Use it whenever constructing URLs against collection paths exposed by Harper's automatic REST interface (see [automatic-apis.md](automatic-apis.md)).
|
|
19
|
+
|
|
20
|
+
## How It Works
|
|
21
|
+
|
|
22
|
+
1. **Filter by attribute**: Add query parameters matching attribute names and values. The queried attribute must be indexed.
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
GET /Product/?category=software
|
|
26
|
+
GET /Product/?category=software&inStock=true
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
2. **Apply comparison operators (FIQL syntax)**: Use FIQL operators directly in query parameter values.
|
|
30
|
+
|
|
31
|
+
| Operator | Meaning |
|
|
32
|
+
| ------------ | -------------------------------------- |
|
|
33
|
+
| `==` | Equal |
|
|
34
|
+
| `=lt=` | Less than |
|
|
35
|
+
| `=le=` | Less than or equal |
|
|
36
|
+
| `=gt=` | Greater than |
|
|
37
|
+
| `=ge=` | Greater than or equal |
|
|
38
|
+
| `=ne=`, `!=` | Not equal |
|
|
39
|
+
| `=ct=` | Contains (strings) |
|
|
40
|
+
| `=sw=` | Starts with (strings) |
|
|
41
|
+
| `=ew=` | Ends with (strings) |
|
|
42
|
+
| `=`, `===` | Strict equality (no type conversion) |
|
|
43
|
+
| `!==` | Strict inequality (no type conversion) |
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
GET /Product/?price=gt=100
|
|
47
|
+
GET /Product/?price=le=20
|
|
48
|
+
GET /Product/?name==Keyboard*
|
|
49
|
+
GET /Product/?category=software&price=gt=100&price=lt=200
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
For date fields, URL-encode colons as `%3A`:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
GET /Product/?listDate=gt=2017-03-08T09%3A30%3A00.000Z
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
3. **Chain conditions for range queries**: Omit the attribute name on the second condition to apply it to the same attribute. Only `gt`/`ge` combined with `lt`/`le` is supported.
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
GET /Product/?price=gt=100<=200
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
4. **Combine conditions with OR logic**: Use `|` instead of `&`.
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
GET /Product/?rating=5|featured=true
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
5. **Group conditions**: Use parentheses or square brackets to control order of operations. Prefer square brackets when constructing queries from user input, since standard URI encoding safely encodes `[` and `]`.
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
GET /Product/?rating=5|(price=gt=100&price=lt=200)
|
|
74
|
+
GET /Product/?rating=5&[tag=fast|tag=scalable|tag=efficient]
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Construct grouped queries from JavaScript:
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
let url = `/Product/?rating=5&[${tags.map(encodeURIComponent).join('|')}]`;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
6. **Select specific properties with `select(`**: Use `select()` to control which fields are returned.
|
|
84
|
+
|
|
85
|
+
| Syntax | Returns |
|
|
86
|
+
| -------------------------------------- | ------------------------------------------- |
|
|
87
|
+
| `?select(property)` | Values of a single property directly |
|
|
88
|
+
| `?select(property1,property2)` | Objects with only the specified properties |
|
|
89
|
+
| `?select([property1,property2])` | Arrays of property values |
|
|
90
|
+
| `?select(property1,)` | Objects with a single specified property |
|
|
91
|
+
| `?select(property{subProp1,subProp2})` | Nested objects with specific sub-properties |
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
GET /Product/?category=software&select(name)
|
|
95
|
+
GET /Product/?brand.name=Microsoft&select(name,brand{name})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
7. **Limit results with `limit(`**: Use `limit(end)` or `limit(start,end)` to paginate.
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
GET /Product/?rating=gt=3&inStock=true&select(rating,name)&limit(20)
|
|
102
|
+
GET /Product/?rating=gt=3&limit(10,30)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
8. **Sort results with `sort(`**: Use `sort(property)` or `sort(+property,-property,...)`. Prefix `+` or no prefix = ascending; `-` = descending.
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
GET /Product/?rating=gt=3&sort(+name)
|
|
109
|
+
GET /Product/?sort(+rating,-price)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
9. **Query across relationships**: Use dot-syntax to filter by related table attributes. Relationships must be defined in the schema using `@relation`.
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
GET /Product/?brand.name=Microsoft
|
|
116
|
+
GET /Brand/?products.name=Keyboard
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Use `select()` to include relationship attributes in the response (they are not included by default):
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
GET /Product/?brand.name=Microsoft&select(name,brand{name})
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
10. **Access a specific property by URL**: Append the property name with dot syntax to the record ID. Only works for properties declared in the schema.
|
|
126
|
+
```
|
|
127
|
+
GET /MyTable/123.propertyName
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Examples
|
|
131
|
+
|
|
132
|
+
**Range filter with select and limit:**
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
GET /Product/?category=software&price=gt=100&price=lt=200&select(name,price)&limit(20)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**Sort descending with multiple fields:**
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
GET /Product/?sort(+rating,-price)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**OR logic with grouping:**
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
GET /Product/?price=lt=100|[rating=5&[tag=fast|tag=scalable|tag=efficient]&inStock=true]
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Relationship join with nested select:**
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
GET /Product/?brand.name=Microsoft&select(name,brand{name,id})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Schema defining a relationship for join queries:**
|
|
157
|
+
|
|
158
|
+
```graphql
|
|
159
|
+
type Product @table @export {
|
|
160
|
+
id: Long @primaryKey
|
|
161
|
+
name: String
|
|
162
|
+
brandId: Long @indexed
|
|
163
|
+
brand: Brand @relation(from: "brandId")
|
|
164
|
+
}
|
|
165
|
+
type Brand @table @export {
|
|
166
|
+
id: Long @primaryKey
|
|
167
|
+
name: String
|
|
168
|
+
products: [Product] @relation(to: "brandId")
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Many-to-many relationship query:**
|
|
173
|
+
|
|
174
|
+
```graphql
|
|
175
|
+
type Product @table @export {
|
|
176
|
+
id: Long @primaryKey
|
|
177
|
+
name: String
|
|
178
|
+
resellerIds: [Long] @indexed
|
|
179
|
+
resellers: [Reseller] @relation(from: "resellerId")
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
GET /Product/?resellers.name=Cool Shop&select(id,name,resellers{name,id})
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**Type conversion with explicit prefix:**
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
GET /Product/?price==number:123
|
|
191
|
+
GET /Product/?active==boolean:true
|
|
192
|
+
GET /Product/?listDate==date:2024-01-05T20%3A07%3A27.955Z
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Notes
|
|
196
|
+
|
|
197
|
+
- Only indexed attributes can be used as the primary filter; additional unindexed attributes can be combined with `&` once at least one indexed attribute is present.
|
|
198
|
+
- For null value queries, use `?attribute=null`. Indexes must have been created with null indexing support; existing indexes must be removed and re-added to support null queries.
|
|
199
|
+
- FIQL comparators (`==`, `!=`, `=gt=`, etc.) apply automatic type conversion based on value syntax or schema-declared type. Strict operators (`=`, `===`, `!==`) skip automatic type conversion.
|
|
200
|
+
- Filtering by a related attribute produces INNER JOIN behavior (only records with a matching related record are returned). Using `select()` on a relationship without a filter produces LEFT JOIN behavior.
|
|
201
|
+
- The array order of foreign key values in many-to-many relationships is preserved when resolving the relationship.
|
|
202
|
+
- See [automatic-apis.md](automatic-apis.md) for how Harper tables are automatically exposed as REST endpoints.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: real-time-apps
|
|
3
|
+
description: How to build real-time features in Harper using WebSockets and Pub/Sub.
|
|
4
|
+
metadata:
|
|
5
|
+
mode: generate
|
|
6
|
+
sources:
|
|
7
|
+
- reference/v5/rest/websockets.md
|
|
8
|
+
sourceCommit: b7fbddadd42eb4487190b650a9abc4bcfeef5819
|
|
9
|
+
inputHash: a8afd4d3a52f77ba
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Real-Time Apps with WebSockets and Pub/Sub
|
|
13
|
+
|
|
14
|
+
Instructions for the agent to follow when building real-time features in Harper using WebSockets and Pub/Sub.
|
|
15
|
+
|
|
16
|
+
## When to Use
|
|
17
|
+
|
|
18
|
+
Apply this rule when implementing any feature that requires real-time bidirectional communication, live data streaming, or push-based updates in a Harper application. This includes chat, live dashboards, sensor feeds, and any scenario where clients must receive resource changes as they happen.
|
|
19
|
+
|
|
20
|
+
## How It Works
|
|
21
|
+
|
|
22
|
+
1. **Enable WebSocket support**: WebSocket support is enabled automatically when the `rest` plugin is enabled. To explicitly disable it, set the following in your config:
|
|
23
|
+
|
|
24
|
+
```yaml
|
|
25
|
+
rest:
|
|
26
|
+
webSocket: false
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
2. **Connect a client to a resource**: A WebSocket connection to a resource URL automatically subscribes to that resource. When the record changes or a message is published to it, the connection receives the update.
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
let ws = new WebSocket('wss://server/my-resource/341');
|
|
33
|
+
ws.onmessage = (event) => {
|
|
34
|
+
let data = JSON.parse(event.data);
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`new WebSocket('wss://server/my-resource/341')` accesses the resource defined for `my-resource` with record id `341` and subscribes to it.
|
|
39
|
+
|
|
40
|
+
3. **Implement a custom `connect()` handler**: Override the `connect(incomingMessages)` method on a resource class to control WebSocket behavior. The method must return an async iterable (or generator) that produces messages to send to the client. See [automatic-apis.md](automatic-apis.md) for more on defining resource classes.
|
|
41
|
+
|
|
42
|
+
4. **Use the default `connect()` for event-style access**: Call `super.connect()` to get a streaming iterable that provides:
|
|
43
|
+
- A `send(message)` method for pushing outgoing messages
|
|
44
|
+
- A `close` event for cleanup on disconnect
|
|
45
|
+
|
|
46
|
+
5. **Handle message ordering in distributed environments**: Harper delivers messages to local subscribers immediately without inter-node coordination delay.
|
|
47
|
+
|
|
48
|
+
| Message Type | Behavior |
|
|
49
|
+
| -------------------------------------------------------- | ----------------------------------------------------------------------- |
|
|
50
|
+
| Non-retained (no `retain` flag) | Every message delivered in order received; suitable for chat |
|
|
51
|
+
| Retained (published with `retain`, or PUT/updated in DB) | Only the latest-timestamp message is kept; suitable for sensor readings |
|
|
52
|
+
|
|
53
|
+
6. **Use MQTT over WebSockets** when needed by setting the sub-protocol header:
|
|
54
|
+
```
|
|
55
|
+
Sec-WebSocket-Protocol: mqtt
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Examples
|
|
59
|
+
|
|
60
|
+
**Simple echo server** — override `connect(incomingMessages)` to yield each incoming message back to the client:
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
export class Echo extends Resource {
|
|
64
|
+
async *connect(incomingMessages) {
|
|
65
|
+
for await (let message of incomingMessages) {
|
|
66
|
+
yield message; // echo each message back
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Custom connect with timer and event-style access** — use `super.connect()` to get the outgoing stream, push periodic messages, echo incoming messages, and clean up on disconnect:
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
export class Example extends Resource {
|
|
76
|
+
connect(incomingMessages) {
|
|
77
|
+
let outgoingMessages = super.connect();
|
|
78
|
+
|
|
79
|
+
let timer = setInterval(() => {
|
|
80
|
+
outgoingMessages.send({ greeting: 'hi again!' });
|
|
81
|
+
}, 1000);
|
|
82
|
+
|
|
83
|
+
incomingMessages.on('data', (message) => {
|
|
84
|
+
outgoingMessages.send(message); // echo incoming messages
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
outgoingMessages.on('close', () => {
|
|
88
|
+
clearInterval(timer);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return outgoingMessages;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Notes
|
|
97
|
+
|
|
98
|
+
- WebSocket connections target a resource URL path. By default, connecting to a resource subscribes to changes for that resource.
|
|
99
|
+
- The `connect(incomingMessages)` method **must** return an async iterable or generator; returning a plain value will not work.
|
|
100
|
+
- `super.connect()` returns a streaming iterable with `send(message)` and a `close` event — use this when you need to push messages outside of the incoming message loop.
|
|
101
|
+
- For one-way real-time streaming without bidirectional communication, consider Server-Sent Events instead.
|
|
102
|
+
- For full pub/sub capabilities, Harper also supports MQTT; set `Sec-WebSocket-Protocol: mqtt` to use MQTT over WebSockets.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: schema-design-tooling
|
|
3
|
+
description: >-
|
|
4
|
+
Best practices for Harper schema design, including core directives and GraphQL
|
|
5
|
+
tooling configuration.
|
|
6
|
+
metadata:
|
|
7
|
+
mode: generate
|
|
8
|
+
sources:
|
|
9
|
+
- reference/v5/database/schema.md#Overview
|
|
10
|
+
- reference/v5/database/schema.md#Type Directives
|
|
11
|
+
- reference/v5/database/schema.md#Field Directives
|
|
12
|
+
sourceCommit: b7fbddadd42eb4487190b650a9abc4bcfeef5819
|
|
13
|
+
inputHash: 4faa3baed7cfa854
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# Schema Design and Tooling
|
|
17
|
+
|
|
18
|
+
Instructions for the agent to follow when designing Harper schemas, applying core directives, and configuring GraphQL tooling.
|
|
19
|
+
|
|
20
|
+
## When to Use
|
|
21
|
+
|
|
22
|
+
Apply this rule when creating or modifying Harper schema files, configuring `graphqlSchema` in `config.yaml`, or deciding which directives to apply to tables and fields. Use it any time a component needs tables, indexes, primary keys, or exported endpoints defined.
|
|
23
|
+
|
|
24
|
+
## How It Works
|
|
25
|
+
|
|
26
|
+
1. **Create a GraphQL schema file** with Harper-specific directives. Name it (e.g., `schema.graphql`) and place it in your component directory.
|
|
27
|
+
|
|
28
|
+
```graphql
|
|
29
|
+
type Dog @table {
|
|
30
|
+
id: Long @primaryKey
|
|
31
|
+
name: String
|
|
32
|
+
breed: String
|
|
33
|
+
age: Int
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type Breed @table {
|
|
37
|
+
id: Long @primaryKey
|
|
38
|
+
name: String @indexed
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
2. **Register the schema in `config.yaml`** using the `graphqlSchema` plugin key:
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
graphqlSchema:
|
|
46
|
+
files: 'schema.graphql'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Both plugins and applications can specify schemas this way.
|
|
50
|
+
|
|
51
|
+
3. **Mark every table type with `@table`**. The type name becomes the table name by default. Use optional arguments to override behavior:
|
|
52
|
+
|
|
53
|
+
| Argument | Type | Default | Description |
|
|
54
|
+
| -------------- | --------- | ----------------------------- | ------------------------------------------------------------- |
|
|
55
|
+
| `table` | `String` | type name | Override the table name |
|
|
56
|
+
| `database` | `String` | `"data"` | Database to place the table in |
|
|
57
|
+
| `expiration` | `Int` | — | Seconds until a record goes stale |
|
|
58
|
+
| `eviction` | `Int` | `0` | Additional seconds after `expiration` before physical removal |
|
|
59
|
+
| `scanInterval` | `Int` | `(expiration + eviction) / 4` | Seconds between eviction scans |
|
|
60
|
+
| `replicate` | `Boolean` | `true` | Enable replication of this table |
|
|
61
|
+
|
|
62
|
+
4. **Designate a primary key on every table** using `@primaryKey`. Primary keys must be unique; duplicate-key inserts are rejected. If no key is provided on insert, Harper auto-generates one:
|
|
63
|
+
- `String` or `ID` → UUID string
|
|
64
|
+
- `Int`, `Long`, or `Any` → auto-incrementing integer
|
|
65
|
+
|
|
66
|
+
Prefer `Long` or `Any` for auto-generated numeric keys; `Int` is 32-bit and may be insufficient for large tables.
|
|
67
|
+
|
|
68
|
+
5. **Index fields that need fast querying** with `@indexed`. This is required for filtering by that attribute in REST queries, SQL, or NoSQL operations. If the field value is an array, each element is individually indexed.
|
|
69
|
+
|
|
70
|
+
```graphql
|
|
71
|
+
type Product @table {
|
|
72
|
+
id: Long @primaryKey
|
|
73
|
+
category: String @indexed
|
|
74
|
+
price: Float @indexed
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
6. **Expose a table as an external resource endpoint** with `@export`. This makes the table accessible via REST, MQTT, and other interfaces. The optional `name` parameter sets the URL path segment; without it, the type name is used.
|
|
79
|
+
|
|
80
|
+
```graphql
|
|
81
|
+
type MyTable @table @export(name: "my-table") {
|
|
82
|
+
id: Long @primaryKey
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
7. **Restrict extra properties** with `@sealed` when records must not include attributes beyond those declared. By default, Harper allows additional properties.
|
|
87
|
+
|
|
88
|
+
```graphql
|
|
89
|
+
type StrictRecord @table @sealed {
|
|
90
|
+
id: Long @primaryKey
|
|
91
|
+
name: String
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
8. **Configure expiration, eviction, and scan behavior** together when building caching tables. These three arguments control the full record lifecycle:
|
|
96
|
+
- `expiration` — record becomes stale; next request triggers a source fetch
|
|
97
|
+
- `eviction` — additional time after `expiration` before physical removal
|
|
98
|
+
- `scanInterval` — how often Harper scans for records to evict; clock-aligned, not startup-aligned
|
|
99
|
+
|
|
100
|
+
## Examples
|
|
101
|
+
|
|
102
|
+
**Caching table with tuned expiration:**
|
|
103
|
+
|
|
104
|
+
```graphql
|
|
105
|
+
# Expire after 5 minutes, evict after 1 hour, scan every 10 minutes
|
|
106
|
+
type WeatherCache @table(expiration: 300, eviction: 3300, scanInterval: 600) {
|
|
107
|
+
id: ID @primaryKey
|
|
108
|
+
temperature: Float
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Table in a named database with expiration and an indexed field:**
|
|
113
|
+
|
|
114
|
+
```graphql
|
|
115
|
+
type Event @table(database: "analytics", expiration: 86400) {
|
|
116
|
+
id: Long @primaryKey
|
|
117
|
+
name: String @indexed
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Session cache with auto-expiry:**
|
|
122
|
+
|
|
123
|
+
```graphql
|
|
124
|
+
type Session @table(expiration: 3600) {
|
|
125
|
+
id: Long @primaryKey
|
|
126
|
+
userId: String
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Table with audit timestamps:**
|
|
131
|
+
|
|
132
|
+
```graphql
|
|
133
|
+
type Order @table @export(name: "orders") {
|
|
134
|
+
id: Long @primaryKey
|
|
135
|
+
createdAt: Long @createdTime
|
|
136
|
+
updatedAt: Long @updatedTime
|
|
137
|
+
status: String @indexed
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Overriding the table name and disabling replication:**
|
|
142
|
+
|
|
143
|
+
```graphql
|
|
144
|
+
type Product @table(table: "products") {
|
|
145
|
+
id: Long @primaryKey
|
|
146
|
+
name: String
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
type LocalRecord @table(replicate: false) {
|
|
150
|
+
id: Long @primaryKey
|
|
151
|
+
value: String
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Notes
|
|
156
|
+
|
|
157
|
+
- Use unique `database` names in plugins and applications to avoid table naming collisions, since all tables default to the `"data"` database.
|
|
158
|
+
- Eviction removes non-indexed record data but does **not** remove a record from its secondary indexes. Indexes remain functional for evicted records; Harper fetches the full record from the source on demand when a query matches an evicted record.
|
|
159
|
+
- `scanInterval` is clock-aligned to the server's local timezone. The server's startup time does not affect when eviction runs.
|
|
160
|
+
- If replication is disabled on a table and later re-enabled, it will not catch up on writes made while replication was disabled.
|
|
161
|
+
- Null values are indexed by `@indexed` fields, enabling queries such as `GET /Product/?category=null`.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: serving-web-content
|
|
3
|
+
description: How to serve static files and integrated Vite/React applications in Harper.
|
|
4
|
+
metadata:
|
|
5
|
+
mode: synthesized
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Serving Web Content
|
|
9
|
+
|
|
10
|
+
Instructions for the agent to follow when serving web content from Harper.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
Use this skill when you need to serve a frontend (HTML, CSS, JS, or a React/Vue app) directly from your Harper instance — either plain static files or an integrated Vite app with hot module replacement (HMR) in development and a real production build when deployed.
|
|
15
|
+
|
|
16
|
+
## How It Works
|
|
17
|
+
|
|
18
|
+
There are two building blocks. Harper's built-in `static` plugin **serves** files; the `@harperfast/vite` plugin **builds** (and, for SSR, **renders**) a Vite app. For a Vite app they work **together** — the plugin builds into a directory and `static` serves that same directory.
|
|
19
|
+
|
|
20
|
+
### Option A: Static plugin only (simple, pre-built assets)
|
|
21
|
+
|
|
22
|
+
For a plain static site or already-built assets, use `static` on its own:
|
|
23
|
+
|
|
24
|
+
```yaml
|
|
25
|
+
static:
|
|
26
|
+
files: 'web/*'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- Place files in a `web/` folder in the project root; they are served from the root URL (e.g. `http://localhost:9926/index.html`).
|
|
30
|
+
- Static files are matched first; if none matches, Harper falls through to your resource and table APIs.
|
|
31
|
+
|
|
32
|
+
### Option B: Vite plugin + static plugin (integrated Vite app)
|
|
33
|
+
|
|
34
|
+
> **Renamed in v1:** the plugin was previously `@harperfast/vite-plugin`. From `1.0.0` on it is **`@harperfast/vite`** (same key and `package`). It now pairs with the `static` plugin instead of building into `web/` itself.
|
|
35
|
+
|
|
36
|
+
`@harperfast/vite` **builds** your app — in `harper dev` it runs Vite in middleware mode with HMR; in `harper run` it runs `vite build` and rebuilds when watched files change (and renders HTML for SSR). The `static` plugin **serves** the built output. Point both at the same directory (`output`, default `dist`) — that shared directory is the only contract between them.
|
|
37
|
+
|
|
38
|
+
**SPA `config.yaml`** — list the plugin first so its dev server wins in `harper dev`; `notFound` + `fallthrough: false` makes client-side routing work:
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
'@harperfast/vite':
|
|
42
|
+
package: '@harperfast/vite'
|
|
43
|
+
files: 'src/**/*'
|
|
44
|
+
output: 'dist'
|
|
45
|
+
|
|
46
|
+
static:
|
|
47
|
+
files: 'dist/**'
|
|
48
|
+
notFound:
|
|
49
|
+
file: 'index.html'
|
|
50
|
+
statusCode: 200
|
|
51
|
+
fallthrough: false
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**SSR `config.yaml`** — add an `ssr` entry so the plugin renders `index.html`, and set `index: false` on `static` so it serves assets only:
|
|
55
|
+
|
|
56
|
+
```yaml
|
|
57
|
+
'@harperfast/vite':
|
|
58
|
+
package: '@harperfast/vite'
|
|
59
|
+
files: 'src/**/*'
|
|
60
|
+
output: 'dist'
|
|
61
|
+
ssr: 'src/entry-server.tsx'
|
|
62
|
+
|
|
63
|
+
static:
|
|
64
|
+
files: 'dist/**'
|
|
65
|
+
index: false
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- Install dependencies: `npm install --save-dev vite @harperfast/vite @vitejs/plugin-react` (swap in your framework's Vite plugin, e.g. `@vitejs/plugin-vue`).
|
|
69
|
+
- Then `harper dev .` runs the app with HMR and `harper run .` runs the production build. Vite does _not_ need to be executed separately.
|
|
70
|
+
|
|
71
|
+
## Deploying to Production
|
|
72
|
+
|
|
73
|
+
Because `@harperfast/vite` builds on the node and `static` serves the output, deploy the component as-is — no manual build-and-move step is needed:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"scripts": {
|
|
78
|
+
"dev": "harper dev .",
|
|
79
|
+
"start": "harper run .",
|
|
80
|
+
"deploy": "harper deploy_component . restart=true replicated=true"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
On deploy the plugin runs `vite build` at startup (and rebuilds when `files` change) while `static` serves the result. If you prefer to build in CI, commit the build output, point `static` at it, and omit `files` so the plugin stays idle while `static` serves the prebuilt assets. Either way, `npm create harper@latest` scaffolds a working setup for you.
|