@harperfast/template-vue-ts-studio 1.6.3 → 1.7.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.
- package/.agents/skills/harper-best-practices/AGENTS.md +1686 -361
- package/.agents/skills/harper-best-practices/SKILL.md +25 -20
- package/.agents/skills/harper-best-practices/rules/adding-tables-with-schemas.md +2 -0
- package/.agents/skills/harper-best-practices/rules/automatic-apis.md +141 -18
- package/.agents/skills/harper-best-practices/rules/caching.md +134 -21
- package/.agents/skills/harper-best-practices/rules/checking-authentication.md +139 -148
- package/.agents/skills/harper-best-practices/rules/creating-a-fabric-account-and-cluster.md +2 -0
- package/.agents/skills/harper-best-practices/rules/creating-harper-apps.md +7 -2
- package/.agents/skills/harper-best-practices/rules/custom-resources.md +2 -0
- package/.agents/skills/harper-best-practices/rules/defining-relationships.md +2 -0
- package/.agents/skills/harper-best-practices/rules/deploying-to-harper-fabric.md +97 -77
- package/.agents/skills/harper-best-practices/rules/extending-tables.md +2 -0
- package/.agents/skills/harper-best-practices/rules/handling-binary-data.md +2 -0
- package/.agents/skills/harper-best-practices/rules/load-env.md +100 -0
- package/.agents/skills/harper-best-practices/rules/logging.md +154 -77
- package/.agents/skills/harper-best-practices/rules/programmatic-table-requests.md +32 -26
- package/.agents/skills/harper-best-practices/rules/querying-rest-apis.md +190 -15
- package/.agents/skills/harper-best-practices/rules/real-time-apps.md +80 -21
- package/.agents/skills/harper-best-practices/rules/schema-design-tooling.md +133 -40
- package/.agents/skills/harper-best-practices/rules/serving-web-content.md +2 -0
- package/.agents/skills/harper-best-practices/rules/typescript-type-stripping.md +48 -16
- package/.agents/skills/harper-best-practices/rules/using-blob-datatype.md +2 -0
- package/.agents/skills/harper-best-practices/rules/vector-indexing.md +85 -120
- package/.agents/skills/harper-best-practices/rules.manifest.yaml +302 -0
- package/package.json +1 -1
- package/skills-lock.json +1 -1
|
@@ -1,43 +1,102 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: real-time-apps
|
|
3
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
|
|
4
10
|
---
|
|
5
11
|
|
|
6
|
-
# Real-
|
|
12
|
+
# Real-Time Apps with WebSockets and Pub/Sub
|
|
7
13
|
|
|
8
|
-
Instructions for the agent to follow when building real-time
|
|
14
|
+
Instructions for the agent to follow when building real-time features in Harper using WebSockets and Pub/Sub.
|
|
9
15
|
|
|
10
16
|
## When to Use
|
|
11
17
|
|
|
12
|
-
|
|
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.
|
|
13
19
|
|
|
14
20
|
## How It Works
|
|
15
21
|
|
|
16
|
-
1. **
|
|
17
|
-
2. **Implement `connect` in a Resource**: For custom bi-directional logic, implement the `connect` method.
|
|
18
|
-
3. **Use Pub/Sub**: Use `tables.TableName.subscribe(query)` to listen for specific data changes and stream them to the client.
|
|
19
|
-
4. **Handle SSE**: Ensure your `connect` method gracefully handles cases where `incomingMessages` is null (Server-Sent Events).
|
|
20
|
-
5. **Connect from Client**: Use standard WebSockets (`new WebSocket('wss://...')`) to connect to your resource endpoint. Ensure you use the appropriate scheme (`ws://` for HTTP, `wss://` for HTTPS).
|
|
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:
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
```yaml
|
|
25
|
+
rest:
|
|
26
|
+
webSocket: false
|
|
27
|
+
```
|
|
23
28
|
|
|
24
|
-
|
|
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.
|
|
25
30
|
|
|
26
|
-
```
|
|
27
|
-
|
|
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
|
+
```
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 |
|
|
36
52
|
|
|
37
|
-
|
|
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) {
|
|
38
65
|
for await (let message of incomingMessages) {
|
|
39
|
-
yield
|
|
66
|
+
yield message; // echo each message back
|
|
40
67
|
}
|
|
41
68
|
}
|
|
42
69
|
}
|
|
43
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.
|
|
@@ -1,68 +1,161 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: schema-design-tooling
|
|
3
|
-
description:
|
|
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
|
|
4
14
|
---
|
|
5
15
|
|
|
6
|
-
# Schema Design
|
|
16
|
+
# Schema Design and Tooling
|
|
7
17
|
|
|
8
|
-
|
|
18
|
+
Instructions for the agent to follow when designing Harper schemas, applying core directives, and configuring GraphQL tooling.
|
|
9
19
|
|
|
10
|
-
##
|
|
20
|
+
## When to Use
|
|
11
21
|
|
|
12
|
-
|
|
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.
|
|
13
23
|
|
|
14
|
-
|
|
24
|
+
## How It Works
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
- `@export`: Automatically generates REST and WebSocket APIs for the table.
|
|
18
|
-
- `@table(expiration: Int)`: Configures a time-to-expire for records in the table (useful for caching).
|
|
26
|
+
1. **Create a GraphQL schema file** with Harper-specific directives. Name it (e.g., `schema.graphql`) and place it in your component directory.
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
```graphql
|
|
29
|
+
type Dog @table {
|
|
30
|
+
id: Long @primaryKey
|
|
31
|
+
name: String
|
|
32
|
+
breed: String
|
|
33
|
+
age: Int
|
|
34
|
+
}
|
|
21
35
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
type Breed @table {
|
|
37
|
+
id: Long @primaryKey
|
|
38
|
+
name: String @indexed
|
|
39
|
+
}
|
|
40
|
+
```
|
|
25
41
|
|
|
26
|
-
|
|
42
|
+
2. **Register the schema in `config.yaml`** using the `graphqlSchema` plugin key:
|
|
27
43
|
|
|
28
|
-
|
|
44
|
+
```yaml
|
|
45
|
+
graphqlSchema:
|
|
46
|
+
files: 'schema.graphql'
|
|
47
|
+
```
|
|
29
48
|
|
|
30
|
-
|
|
49
|
+
Both plugins and applications can specify schemas this way.
|
|
31
50
|
|
|
32
|
-
|
|
51
|
+
3. **Mark every table type with `@table`**. The type name becomes the table name by default. Use optional arguments to override behavior:
|
|
33
52
|
|
|
34
|
-
|
|
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 |
|
|
35
61
|
|
|
36
|
-
|
|
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
|
|
37
65
|
|
|
38
|
-
|
|
66
|
+
Prefer `Long` or `Any` for auto-generated numeric keys; `Int` is 32-bit and may be insufficient for large tables.
|
|
39
67
|
|
|
40
|
-
|
|
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.
|
|
41
69
|
|
|
42
|
-
|
|
70
|
+
```graphql
|
|
71
|
+
type Product @table {
|
|
72
|
+
id: Long @primaryKey
|
|
73
|
+
category: String @indexed
|
|
74
|
+
price: Float @indexed
|
|
75
|
+
}
|
|
76
|
+
```
|
|
43
77
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
}
|
|
49
128
|
```
|
|
50
129
|
|
|
51
|
-
|
|
130
|
+
**Table with audit timestamps:**
|
|
52
131
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
```
|
|
56
140
|
|
|
57
|
-
|
|
141
|
+
**Overriding the table name and disabling replication:**
|
|
58
142
|
|
|
59
|
-
|
|
143
|
+
```graphql
|
|
144
|
+
type Product @table(table: "products") {
|
|
145
|
+
id: Long @primaryKey
|
|
146
|
+
name: String
|
|
147
|
+
}
|
|
60
148
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
├── package.json
|
|
66
|
-
├── schema.graphql
|
|
67
|
-
└── resources.js
|
|
149
|
+
type LocalRecord @table(replicate: false) {
|
|
150
|
+
id: Long @primaryKey
|
|
151
|
+
value: String
|
|
152
|
+
}
|
|
68
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`.
|
|
@@ -1,32 +1,64 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: typescript-type-stripping
|
|
3
3
|
description: How to run TypeScript files directly in Harper without a build step.
|
|
4
|
+
metadata:
|
|
5
|
+
mode: generate
|
|
6
|
+
sources:
|
|
7
|
+
- reference/v5/components/javascript-environment.md#TypeScript Support
|
|
8
|
+
sourceCommit: b7fbddadd42eb4487190b650a9abc4bcfeef5819
|
|
9
|
+
inputHash: 4e6bd8b610edd595
|
|
4
10
|
---
|
|
5
11
|
|
|
6
|
-
# TypeScript Type Stripping
|
|
12
|
+
# TypeScript Type Stripping in Harper
|
|
7
13
|
|
|
8
|
-
Instructions for the agent to
|
|
14
|
+
Instructions for the agent to run `.ts` files directly in Harper without a build step using Node.js's built-in type stripping.
|
|
9
15
|
|
|
10
16
|
## When to Use
|
|
11
17
|
|
|
12
|
-
|
|
18
|
+
Apply this rule when writing Harper resource files in TypeScript. Use it any time you need to reference `.ts` source files from `config.yaml` or import between local TypeScript modules in a Harper project.
|
|
13
19
|
|
|
14
20
|
## How It Works
|
|
15
21
|
|
|
16
|
-
1. **
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import { Resource } from 'harper';
|
|
21
|
-
export class MyResource extends Resource {
|
|
22
|
-
async get(): Promise<{ message: string }> {
|
|
23
|
-
return { message: 'Running TS directly!' };
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
```
|
|
27
|
-
4. **Use Explicit Extensions in Imports**: When importing other local modules, include the `.ts` extension: `import { helper } from './helper.ts'`.
|
|
28
|
-
5. **Configure `config.yaml`**: Ensure `jsResource` points to your `.ts` files:
|
|
22
|
+
1. **Ensure Node.js version**: Require Node.js 22.6 or later. Type stripping is unavailable on earlier versions.
|
|
23
|
+
|
|
24
|
+
2. **Point `jsResource` at `.ts` files**: The `jsResource` plugin loads both `.js` and `.ts` files. Set its `files` glob in `config.yaml` to target your `.ts` source files:
|
|
25
|
+
|
|
29
26
|
```yaml
|
|
30
27
|
jsResource:
|
|
31
28
|
files: 'resources/*.ts'
|
|
32
29
|
```
|
|
30
|
+
|
|
31
|
+
3. **Use explicit `.ts` extensions in local imports**: Node's loader does not resolve `'./helper'` to `'./helper.ts'`, so always include the full extension:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { helper } from './helper.ts';
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
4. **Stay within type-stripping limits**: Only type annotations and declarations are removed. Do not use enums with runtime values, namespaces with runtime semantics, or any other features that require code transformation beyond type stripping.
|
|
38
|
+
|
|
39
|
+
## Examples
|
|
40
|
+
|
|
41
|
+
A complete Harper resource written in TypeScript, using imports from the `harper` package:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { type RequestTargetOrId, Resource, tables } from 'harper';
|
|
45
|
+
|
|
46
|
+
export class MyResource extends Resource {
|
|
47
|
+
async get(target?: RequestTargetOrId): Promise<{ message: string }> {
|
|
48
|
+
return { message: 'Hello from TS' };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Paired `config.yaml` entry loading the file via `jsResource`:
|
|
54
|
+
|
|
55
|
+
```yaml
|
|
56
|
+
jsResource:
|
|
57
|
+
files: 'resources/*.ts'
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Notes
|
|
61
|
+
|
|
62
|
+
- No build step or transpiler is required — Harper runs `.ts` files directly.
|
|
63
|
+
- Type imports (e.g., `import { type RequestTargetOrId }`) from the `harper` package work as usual.
|
|
64
|
+
- Unsupported TypeScript features include: enums with runtime values, namespaces with runtime semantics, and anything requiring code transformation beyond simple type stripping.
|