@harperfast/template-vue-studio 1.5.21 → 1.5.23
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 +81 -15
- package/.agents/skills/harper-best-practices/SKILL.md +2 -0
- package/.agents/skills/harper-best-practices/rules/custom-resources.md +7 -3
- package/.agents/skills/harper-best-practices/rules/querying-rest-apis.md +7 -2
- package/.agents/skills/harper-best-practices/rules/schema-design-tooling.md +63 -0
- package/package.json +1 -1
- package/skills-lock.json +1 -1
|
@@ -8,10 +8,11 @@ Guidelines for building scalable, secure, and performant applications on Harper.
|
|
|
8
8
|
|
|
9
9
|
1. [Schema & Data Design](#1-schema--data-design) — **HIGH**
|
|
10
10
|
- 1.1 [Adding Tables with Schemas](#11-adding-tables-with-schemas)
|
|
11
|
-
- 1.2 [
|
|
12
|
-
- 1.3 [
|
|
13
|
-
- 1.4 [
|
|
14
|
-
- 1.5 [
|
|
11
|
+
- 1.2 [Schema Design & Tooling](#12-schema-design--tooling)
|
|
12
|
+
- 1.3 [Defining Relationships](#13-defining-relationships)
|
|
13
|
+
- 1.4 [Vector Indexing](#14-vector-indexing)
|
|
14
|
+
- 1.5 [Using Blobs](#15-using-blobs)
|
|
15
|
+
- 1.6 [Handling Binary Data](#16-handling-binary-data)
|
|
15
16
|
2. [API & Communication](#2-api--communication) — **HIGH**
|
|
16
17
|
- 2.1 [Automatic REST APIs](#21-automatic-rest-apis)
|
|
17
18
|
- 2.2 [Querying REST APIs](#22-querying-rest-apis)
|
|
@@ -61,7 +62,66 @@ type ExamplePerson @table @export {
|
|
|
61
62
|
}
|
|
62
63
|
```
|
|
63
64
|
|
|
64
|
-
### 1.2
|
|
65
|
+
### 1.2 Schema Design & Tooling
|
|
66
|
+
|
|
67
|
+
Harper uses GraphQL schemas to define database tables, relationships, and APIs. To ensure the best development experience for both humans and AI agents, it's important to understand the core directives and configure your project tooling correctly.
|
|
68
|
+
|
|
69
|
+
#### Core Harper Directives
|
|
70
|
+
|
|
71
|
+
Harper extends GraphQL with custom directives that define database behavior. These are typically defined in `node_modules/harperdb/schema.graphql`. If you don't have access to that file, here is a reference of the most important ones:
|
|
72
|
+
|
|
73
|
+
##### Table Definition
|
|
74
|
+
- `@table`: Marks a GraphQL type as a Harper database table.
|
|
75
|
+
- `@export`: Automatically generates REST and WebSocket APIs for the table.
|
|
76
|
+
- `@table(expiration: Int)`: Configures a time-to-expire for records in the table (useful for caching).
|
|
77
|
+
|
|
78
|
+
##### Attribute Constraints & Indexing
|
|
79
|
+
- `@primaryKey`: Specifies the unique identifier for the table.
|
|
80
|
+
- `@indexed`: Creates a standard index on the field for faster lookups.
|
|
81
|
+
- `@indexed(type: "HNSW", distance: "cosine" | "euclidean" | "dot")`: Creates a vector index for similarity search.
|
|
82
|
+
|
|
83
|
+
##### Relationships
|
|
84
|
+
- `@relationship(from: String)`: Defines a relationship to another table. `from` specifies the local field holding the foreign key.
|
|
85
|
+
|
|
86
|
+
##### Authentication & Authorization
|
|
87
|
+
- `@auth(role: String)`: Restricts access to a table or field based on user roles.
|
|
88
|
+
|
|
89
|
+
#### Configuring GraphQL Tooling
|
|
90
|
+
|
|
91
|
+
To get the best IDE support (autocompletion, validation) and to help AI agents understand your schema context, you should create a `graphql.config.yml` file in your project root.
|
|
92
|
+
|
|
93
|
+
This file tells GraphQL tools where to find Harper's built-in types and directives alongside your own schema files.
|
|
94
|
+
|
|
95
|
+
##### Creating `graphql.config.yml`
|
|
96
|
+
|
|
97
|
+
Create a file named `graphql.config.yml` in your project root with the following content:
|
|
98
|
+
|
|
99
|
+
```yaml
|
|
100
|
+
schema:
|
|
101
|
+
- "node_modules/harperdb/schema.graphql"
|
|
102
|
+
- "schema.graphql"
|
|
103
|
+
- "schemas/*.graphql"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
##### Why this is important:
|
|
107
|
+
1. **Shared Directives**: It includes `@table`, `@primaryKey`, etc., so they aren't marked as "unknown directives".
|
|
108
|
+
2. **Context for Agents**: When an agent reads your project, seeing this config helps it locate the core Harper definitions, leading to more accurate code generation.
|
|
109
|
+
3. **Consistency**: The `npm create harper@latest` command includes this by default. Manually adding it to existing projects ensures they follow the same standards.
|
|
110
|
+
|
|
111
|
+
#### Example Project Structure
|
|
112
|
+
|
|
113
|
+
A typical Harper project with proper schema tooling:
|
|
114
|
+
|
|
115
|
+
```text
|
|
116
|
+
my-harper-app/
|
|
117
|
+
├── config.yaml
|
|
118
|
+
├── graphql.config.yml
|
|
119
|
+
├── package.json
|
|
120
|
+
├── schema.graphql
|
|
121
|
+
└── resources.js
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 1.3 Defining Relationships
|
|
65
125
|
|
|
66
126
|
Using the `@relationship` directive to link tables.
|
|
67
127
|
|
|
@@ -105,7 +165,7 @@ type Category @table @export {
|
|
|
105
165
|
}
|
|
106
166
|
```
|
|
107
167
|
|
|
108
|
-
### 1.
|
|
168
|
+
### 1.4 Vector Indexing
|
|
109
169
|
|
|
110
170
|
How to define and use vector indexes for efficient similarity search.
|
|
111
171
|
|
|
@@ -130,7 +190,7 @@ type Document @table @export {
|
|
|
130
190
|
}
|
|
131
191
|
```
|
|
132
192
|
|
|
133
|
-
### 1.
|
|
193
|
+
### 1.5 Using Blobs
|
|
134
194
|
|
|
135
195
|
How to store and retrieve large data in Harper.
|
|
136
196
|
|
|
@@ -144,7 +204,7 @@ Use this when you need to store large, unstructured data such as files, images,
|
|
|
144
204
|
2. **Storing Data**: Send the data as a buffer or a stream when creating or updating a record.
|
|
145
205
|
3. **Retrieving Data**: Access the blob field, which will return the data as a stream or buffer.
|
|
146
206
|
|
|
147
|
-
### 1.
|
|
207
|
+
### 1.6 Handling Binary Data
|
|
148
208
|
|
|
149
209
|
How to store and serve binary data like images or MP3s.
|
|
150
210
|
|
|
@@ -185,11 +245,12 @@ How to use filters, operators, sorting, and pagination in REST requests.
|
|
|
185
245
|
|
|
186
246
|
#### Query Parameters
|
|
187
247
|
|
|
188
|
-
- `limit`: Number of records to return.
|
|
189
|
-
- `
|
|
190
|
-
- `
|
|
191
|
-
- `
|
|
192
|
-
- `
|
|
248
|
+
- `limit(count)` or `limit(offset, count)`: Number of records to return and optional skip. Example: `?limit(10)`, `?limit(10, 20)`.
|
|
249
|
+
- `sort(+field1, -field2)`: Fields to sort by. Use `+` for ascending and `-` for descending. Example: `?sort(+name)`, `?sort(-price, +name)`.
|
|
250
|
+
- `select(field1, field2)`: Specific fields to return. Example: `?select(id, name)`.
|
|
251
|
+
- `filter`: Advanced filtering using comparison operators and logic.
|
|
252
|
+
- Operators: `gt`, `ge`, `lt`, `le`, `ne`. Example: `?price=gt=100`.
|
|
253
|
+
- Logic: `&` (AND), `|` (OR), `()` (grouping). Example: `?(category=electronics|category=books)&price=lt=500`.
|
|
193
254
|
|
|
194
255
|
### 2.3 Real-time Applications
|
|
195
256
|
|
|
@@ -232,8 +293,13 @@ How to define custom REST endpoints using JavaScript or TypeScript.
|
|
|
232
293
|
#### How It Works
|
|
233
294
|
|
|
234
295
|
1. **Create Resource File**: Define your logic in a JS or TS file.
|
|
235
|
-
2. **
|
|
236
|
-
3. **
|
|
296
|
+
2. **Define Resource Class**: Export a class extending `Resource` from `harperdb`.
|
|
297
|
+
3. **Implement HTTP Methods**: Add methods like `get`, `post`, `put`, `patch`, or `delete` to handle corresponding requests.
|
|
298
|
+
4. **Route Nesting and Naming**: You can control the URL structure by how you export your resources:
|
|
299
|
+
- **Direct Class Export**: `export class Foo extends Resource` creates endpoints at `/Foo/`. Class names are case-sensitive in the URL.
|
|
300
|
+
- **Nested Objects**: `export const Bar = { Foo };` creates endpoints at `/Bar/Foo/`.
|
|
301
|
+
- **Lowercase and Hyphens**: Use object keys to define custom paths: `export const bar = { 'foo-baz': Foo };` exposes endpoints at `/bar/foo-baz/`.
|
|
302
|
+
5. **Registration**: Ensure the resource is correctly registered in your application configuration.
|
|
237
303
|
|
|
238
304
|
### 3.2 Extending Table Resources
|
|
239
305
|
|
|
@@ -52,6 +52,7 @@ See the concrete examples embedded in each rule subsection below (GraphQL schema
|
|
|
52
52
|
### 1. Schema & Data Design (HIGH)
|
|
53
53
|
|
|
54
54
|
- `adding-tables-with-schemas` - Define tables using GraphQL schemas and directives
|
|
55
|
+
- `schema-design-tooling` - Core directives and GraphQL IDE/agent configuration
|
|
55
56
|
- `defining-relationships` - Link tables using the `@relationship` directive
|
|
56
57
|
- `vector-indexing` - Efficient similarity search with vector indexes
|
|
57
58
|
- `using-blob-datatype` - Store and retrieve large data (Blobs)
|
|
@@ -85,6 +86,7 @@ Read individual rule files for detailed explanations and code examples:
|
|
|
85
86
|
|
|
86
87
|
```
|
|
87
88
|
rules/adding-tables-with-schemas.md
|
|
89
|
+
rules/schema-design-tooling.md
|
|
88
90
|
rules/automatic-apis.md
|
|
89
91
|
rules/creating-harper-apps.md
|
|
90
92
|
```
|
|
@@ -27,11 +27,15 @@ Use this skill when the automatic CRUD operations provided by `@table @export` a
|
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
4. **Implement HTTP Methods**: Add methods like `get`, `post`, `put`, `patch`, or `delete` to handle corresponding requests.
|
|
31
|
-
5. **
|
|
30
|
+
4. **Implement HTTP Methods**: Add methods like `get`, `post`, `put`, `patch`, or `delete` to handle corresponding requests.
|
|
31
|
+
5. **Route Nesting and Naming**: You can control the URL structure by how you export your resources:
|
|
32
|
+
- **Direct Class Export**: `export class Foo extends Resource` creates endpoints at `/Foo/`. Class names are case-sensitive in the URL.
|
|
33
|
+
- **Nested Objects**: `export const Bar = { Foo };` creates endpoints at `/Bar/Foo/`.
|
|
34
|
+
- **Lowercase and Hyphens**: Use object keys to define custom paths: `export const bar = { 'foo-baz': Foo };` exposes endpoints at `/bar/foo-baz/`.
|
|
35
|
+
6. **Access Tables (Optional)**: Import and use the `tables` object to interact with your data:
|
|
32
36
|
```typescript
|
|
33
37
|
import { tables } from 'harperdb';
|
|
34
38
|
// ... inside a method
|
|
35
39
|
const results = await tables.MyTable.list();
|
|
36
40
|
```
|
|
37
|
-
|
|
41
|
+
7. **Configure Loading**: Ensure `config.yaml` points to your resource files (e.g., `jsResource: { files: 'resources/*.ts' }`).
|
|
@@ -17,6 +17,11 @@ Use this skill when you need to perform advanced data retrieval (filtering, sort
|
|
|
17
17
|
2. **Use Comparison Operators**: Append operators like `gt`, `ge`, `lt`, `le`, `ne` using FIQL-style syntax: `GET /Table/?price=gt=100`.
|
|
18
18
|
3. **Apply Logic and Grouping**: Use `&` for AND, `|` for OR, and `()` for grouping: `GET /Table/?(rating=5|featured=true)&price=lt=50`.
|
|
19
19
|
4. **Select Specific Fields**: Use `select()` to limit returned attributes: `GET /Table/?select(name,price)`.
|
|
20
|
-
5. **Paginate Results**: Use `limit(count)` or `limit(offset, count)
|
|
21
|
-
|
|
20
|
+
5. **Paginate Results**: Use `limit(count)` or `limit(offset, count)` to set the number of records to return and skip.
|
|
21
|
+
- Example (first 10): `GET /Table/?limit(10)`
|
|
22
|
+
- Example (skip 20, return 10): `GET /Table/?limit(20, 10)`
|
|
23
|
+
6. **Sort Results**: Use `sort()` with `+` (asc) or `-` (desc) before the field name. Avoid `sort=field` format.
|
|
24
|
+
- Example (asc): `GET /Table/?sort(+name)`
|
|
25
|
+
- Example (desc): `GET /Table/?sort(-price)`
|
|
26
|
+
- Example (combined): `GET /Table/?sort(-price,+name)`
|
|
22
27
|
7. **Query Relationships**: Use dot syntax for tables linked with `@relationship`: `GET /Book/?author.name=Harper`.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: schema-design-tooling
|
|
3
|
+
description: Best practices for Harper schema design, including core directives and GraphQL tooling configuration.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Schema Design & Tooling
|
|
7
|
+
|
|
8
|
+
Harper uses GraphQL schemas to define database tables, relationships, and APIs. To ensure the best development experience for both humans and AI agents, it's important to understand the core directives and configure your project tooling correctly.
|
|
9
|
+
|
|
10
|
+
## Core Harper Directives
|
|
11
|
+
|
|
12
|
+
Harper extends GraphQL with custom directives that define database behavior. These are typically defined in `node_modules/harperdb/schema.graphql`. If you don't have access to that file, here is a reference of the most important ones:
|
|
13
|
+
|
|
14
|
+
### Table Definition
|
|
15
|
+
- `@table`: Marks a GraphQL type as a Harper database table.
|
|
16
|
+
- `@export`: Automatically generates REST and WebSocket APIs for the table.
|
|
17
|
+
- `@table(expiration: Int)`: Configures a time-to-expire for records in the table (useful for caching).
|
|
18
|
+
|
|
19
|
+
### Attribute Constraints & Indexing
|
|
20
|
+
- `@primaryKey`: Specifies the unique identifier for the table.
|
|
21
|
+
- `@indexed`: Creates a standard index on the field for faster lookups.
|
|
22
|
+
- `@indexed(type: "HNSW", distance: "cosine" | "euclidean" | "dot")`: Creates a vector index for similarity search.
|
|
23
|
+
|
|
24
|
+
### Relationships
|
|
25
|
+
- `@relationship(from: String)`: Defines a relationship to another table. `from` specifies the local field holding the foreign key.
|
|
26
|
+
|
|
27
|
+
### Authentication & Authorization
|
|
28
|
+
- `@auth(role: String)`: Restricts access to a table or field based on user roles.
|
|
29
|
+
|
|
30
|
+
## Configuring GraphQL Tooling
|
|
31
|
+
|
|
32
|
+
To get the best IDE support (autocompletion, validation) and to help AI agents understand your schema context, you should create a `graphql.config.yml` file in your project root.
|
|
33
|
+
|
|
34
|
+
This file tells GraphQL tools where to find Harper's built-in types and directives alongside your own schema files.
|
|
35
|
+
|
|
36
|
+
### Creating `graphql.config.yml`
|
|
37
|
+
|
|
38
|
+
Create a file named `graphql.config.yml` in your project root with the following content:
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
schema:
|
|
42
|
+
- "node_modules/harperdb/schema.graphql"
|
|
43
|
+
- "schema.graphql"
|
|
44
|
+
- "schemas/*.graphql"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Why this is important:
|
|
48
|
+
1. **Shared Directives**: It includes `@table`, `@primaryKey`, etc., so they aren't marked as "unknown directives".
|
|
49
|
+
2. **Context for Agents**: When an agent reads your project, seeing this config helps it locate the core Harper definitions, leading to more accurate code generation.
|
|
50
|
+
3. **Consistency**: The `npm create harper@latest` command includes this by default. Manually adding it to existing projects ensures they follow the same standards.
|
|
51
|
+
|
|
52
|
+
## Example Project Structure
|
|
53
|
+
|
|
54
|
+
A typical Harper project with proper schema tooling:
|
|
55
|
+
|
|
56
|
+
```text
|
|
57
|
+
my-harper-app/
|
|
58
|
+
├── config.yaml
|
|
59
|
+
├── graphql.config.yml
|
|
60
|
+
├── package.json
|
|
61
|
+
├── schema.graphql
|
|
62
|
+
└── resources.js
|
|
63
|
+
```
|
package/package.json
CHANGED
package/skills-lock.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"harper-best-practices": {
|
|
5
5
|
"source": "harperfast/skills",
|
|
6
6
|
"sourceType": "github",
|
|
7
|
-
"computedHash": "
|
|
7
|
+
"computedHash": "dc6edafe30ac9800fb009d9ac48b73206e9ba9efc6b9a49268aeb1bb7e8c1b8c"
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|