@harperfast/skills 1.2.1 → 1.3.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/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ export const ruleNames = [
|
|
|
16
16
|
"programmatic-table-requests",
|
|
17
17
|
"querying-rest-apis",
|
|
18
18
|
"real-time-apps",
|
|
19
|
+
"schema-design-tooling",
|
|
19
20
|
"serving-web-content",
|
|
20
21
|
"typescript-type-stripping",
|
|
21
22
|
"using-blob-datatype",
|
|
@@ -40,6 +41,7 @@ export const rules = {
|
|
|
40
41
|
"programmatic-table-requests": "---\nname: programmatic-table-requests\ndescription: How to interact with Harper tables programmatically using the `tables` object.\n---\n\n# Programmatic Table Requests\n\nInstructions for the agent to follow when interacting with Harper tables via code.\n\n## When to Use\n\nUse this skill when you need to perform database operations (CRUD, search, subscribe) from within Harper Resources or scripts.\n\n## How It Works\n\n1. **Access the Table**: Use the global `tables` object followed by your table name (e.g., `tables.MyTable`).\n2. **Perform CRUD Operations**:\n - **Get**: `await tables.MyTable.get(id)` for a single record or `await tables.MyTable.get({ conditions: [...] })` for multiple.\n - **Create**: `await tables.MyTable.post(record)` (auto-generates ID) or `await tables.MyTable.put(id, record)`.\n - **Update**: `await tables.MyTable.patch(id, partialRecord)` for partial updates.\n - **Delete**: `await tables.MyTable.delete(id)`.\n3. **Use Updatable Records for Atomic Ops**: Call `update(id)` to get a reference, then use `addTo` or `subtractFrom` for atomic increments/decrements:\n ```typescript\n const stats = await tables.Stats.update('daily');\n stats.addTo('viewCount', 1);\n ```\n4. **Search and Stream**: Use `search(query)` for efficient streaming of large result sets:\n ```typescript\n for await (const record of tables.MyTable.search({ conditions: [...] })) {\n // process record\n }\n ```\n5. **Real-time Subscriptions**: Use `subscribe(query)` to listen for changes:\n ```typescript\n for await (const event of tables.MyTable.subscribe(query)) {\n \t// handle event\n }\n ```\n6. **Publish Events**: Use `publish(id, message)` to trigger subscriptions without necessarily persisting data.\n",
|
|
41
42
|
"querying-rest-apis": "---\nname: querying-rest-apis\ndescription: How to use query parameters to filter, sort, and paginate Harper REST APIs.\n---\n\n# Querying REST APIs\n\nInstructions for the agent to follow when querying Harper's REST APIs.\n\n## When to Use\n\nUse this skill when you need to perform advanced data retrieval (filtering, sorting, pagination, joins) using Harper's automatic REST endpoints.\n\n## How It Works\n\n1. **Basic Filtering**: Use attribute names as query parameters: `GET /Table/?key=value`.\n2. **Use Comparison Operators**: Append operators like `gt`, `ge`, `lt`, `le`, `ne` using FIQL-style syntax: `GET /Table/?price=gt=100`.\n3. **Apply Logic and Grouping**: Use `&` for AND, `|` for OR, and `()` for grouping: `GET /Table/?(rating=5|featured=true)&price=lt=50`.\n4. **Select Specific Fields**: Use `select()` to limit returned attributes: `GET /Table/?select(name,price)`.\n5. **Paginate Results**: Use `limit(count)` or `limit(offset, count)`: `GET /Table/?limit(20, 10)`.\n6. **Sort Results**: Use `sort()` with `+` (asc) or `-` (desc): `GET /Table/?sort(-price,+name)`.\n7. **Query Relationships**: Use dot syntax for tables linked with `@relationship`: `GET /Book/?author.name=Harper`.\n",
|
|
42
43
|
"real-time-apps": "---\nname: real-time-apps\ndescription: How to build real-time features in Harper using WebSockets and Pub/Sub.\n---\n\n# Real-time Applications\n\nInstructions for the agent to follow when building real-time applications in Harper.\n\n## When to Use\n\nUse this skill when you need to stream live updates to clients, implement chat features, or provide real-time data synchronization between the database and a frontend.\n\n## How It Works\n\n1. **Check Automatic WebSockets**: If you only need to stream table changes, use [Automatic APIs](automatic-apis.md) which provide a WebSocket endpoint for every `@export`ed table.\n2. **Implement `connect` in a Resource**: For custom bi-directional logic, implement the `connect` method.\n3. **Use Pub/Sub**: Use `tables.TableName.subscribe(query)` to listen for specific data changes and stream them to the client.\n4. **Handle SSE**: Ensure your `connect` method gracefully handles cases where `incomingMessages` is null (Server-Sent Events).\n5. **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).\n\n## Examples\n\n### Bi-directional WebSocket Resource\n\n```typescript\nimport { Resource, tables } from 'harperdb';\n\nexport class MySocket extends Resource {\n\tasync *connect(target, incomingMessages) {\n\t\t// Subscribe to table changes\n\t\tconst subscription = await tables.MyTable.subscribe(target);\n\t\tif (!incomingMessages) {\n\t\t\treturn subscription; // SSE mode\n\t\t}\n\n\t\t// Handle incoming client messages\n\t\tfor await (let message of incomingMessages) {\n\t\t\tyield { received: message };\n\t\t}\n\t}\n}\n```\n",
|
|
44
|
+
"schema-design-tooling": "---\nname: schema-design-tooling\ndescription: Best practices for Harper schema design, including core directives and GraphQL tooling configuration.\n---\n\n# Schema Design & Tooling\n\nHarper 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.\n\n## Core Harper Directives\n\nHarper 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:\n\n### Table Definition\n\n- `@table`: Marks a GraphQL type as a Harper database table.\n- `@export`: Automatically generates REST and WebSocket APIs for the table.\n- `@table(expiration: Int)`: Configures a time-to-expire for records in the table (useful for caching).\n\n### Attribute Constraints & Indexing\n\n- `@primaryKey`: Specifies the unique identifier for the table.\n- `@indexed`: Creates a standard index on the field for faster lookups.\n- `@indexed(type: \"HNSW\", distance: \"cosine\" | \"euclidean\" | \"dot\")`: Creates a vector index for similarity search.\n\n### Relationships\n\n- `@relationship(from: String)`: Defines a relationship to another table. `from` specifies the local field holding the foreign key.\n\n### Authentication & Authorization\n\n- `@auth(role: String)`: Restricts access to a table or field based on user roles.\n\n## Configuring GraphQL Tooling\n\nTo 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.\n\nThis file tells GraphQL tools where to find Harper's built-in types and directives alongside your own schema files.\n\n### Creating `graphql.config.yml`\n\nCreate a file named `graphql.config.yml` in your project root with the following content:\n\n```yaml\nschema:\n - 'node_modules/harperdb/schema.graphql'\n - 'schema.graphql'\n - 'schemas/*.graphql'\n```\n\n### Why this is important:\n\n1. **Shared Directives**: It includes `@table`, `@primaryKey`, etc., so they aren't marked as \"unknown directives\".\n2. **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.\n3. **Consistency**: The `npm create harper@latest` command includes this by default. Manually adding it to existing projects ensures they follow the same standards.\n\n## Example Project Structure\n\nA typical Harper project with proper schema tooling:\n\n```text\nmy-harper-app/\n├── config.yaml\n├── graphql.config.yml\n├── package.json\n├── schema.graphql\n└── resources.js\n```\n",
|
|
43
45
|
"serving-web-content": "---\nname: serving-web-content\ndescription: How to serve static files and integrated Vite/React applications in Harper.\n---\n\n# Serving Web Content\n\nInstructions for the agent to follow when serving web content from Harper.\n\n## When to Use\n\nUse this skill when you need to serve a frontend (HTML, CSS, JS, or a React app) directly from your Harper instance.\n\n## How It Works\n\n1. **Choose a Method**: Decide between the simple Static Plugin or the integrated Vite Plugin.\n2. **Option A: Static Plugin (Simple)**:\n - Add to `config.yaml`:\n ```yaml\n static:\n files: 'web/*'\n ```\n - Place files in a `web/` folder in the project root.\n - Files are served at the root URL (e.g., `http://localhost:9926/index.html`).\n3. **Option B: Vite Plugin (Advanced/Development)**:\n - Add to `config.yaml`:\n ```yaml\n '@harperfast/vite-plugin':\n package: '@harperfast/vite-plugin'\n ```\n - Ensure `vite.config.ts` and `index.html` are in the project root.\n\n ```javascript\n import vue from '@vitejs/plugin-vue';\n import path from 'node:path';\n import { defineConfig } from 'vite';\n\n // https://vite.dev/config/\n export default defineConfig({\n \tplugins: [vue()],\n \tresolve: {\n \t\talias: {\n \t\t\t'@': path.resolve(import.meta.dirname, './src'),\n \t\t},\n \t},\n \tbuild: {\n \t\toutDir: 'web',\n \t\temptyOutDir: true,\n \t\trolldownOptions: {\n \t\t\texternal: ['**/*.test.*', '**/*.spec.*'],\n \t\t},\n \t},\n });\n ```\n\n - Install dependencies: `npm install --save-dev vite @harperfast/vite-plugin`.\n - Then `harper run .` will start up Harper and Vite with HMR. Vite does _not_ need to be executed separately.\n\n4. **Deploy for Production**: For Vite apps, use a build script to generate static files into a `web/` folder and deploy them using the static handler pattern. For example, these scripts in a package.json can perform the necessary steps:\n ```json\n \"build\": \"vite build\",\n \"deploy\": \"rm -Rf deploy && npm run build && mkdir deploy && mv web deploy/ && cp -R deploy-template/* deploy/ && cp -R schemas resources deploy/ && dotenv -- npm run deploy:component && rm -Rf deploy\",\n \"deploy:component\": \"(cd deploy && harper deploy_component . project=web restart=rolling replicated=true)\"\n ```\n Then in production, the \"Static Plugin\" option will performantly and securely serve your assets. `npm create harper@latest` scaffolds all of this for you.\n",
|
|
44
46
|
"typescript-type-stripping": "---\nname: typescript-type-stripping\ndescription: How to run TypeScript files directly in Harper without a build step.\n---\n\n# TypeScript Type Stripping\n\nInstructions for the agent to follow when using TypeScript in Harper.\n\n## When to Use\n\nUse this skill when you want to write Harper Resources in TypeScript and have them execute directly in Node.js without an intermediate build or compilation step.\n\n## How It Works\n\n1. **Verify Node.js Version**: Ensure you are using Node.js v22.6.0 or higher.\n2. **Name Files with `.ts`**: Create your resource files in the `resources/` directory with a `.ts` extension.\n3. **Use TypeScript Syntax**: Write your resource classes using standard TypeScript (interfaces, types, etc.).\n ```typescript\n import { Resource } from 'harperdb';\n export class MyResource extends Resource {\n \tasync get(): Promise<{ message: string }> {\n \t\treturn { message: 'Running TS directly!' };\n \t}\n }\n ```\n4. **Use Explicit Extensions in Imports**: When importing other local modules, include the `.ts` extension: `import { helper } from './helper.ts'`.\n5. **Configure `config.yaml`**: Ensure `jsResource` points to your `.ts` files:\n ```yaml\n jsResource:\n files: 'resources/*.ts'\n ```\n",
|
|
45
47
|
"using-blob-datatype": "---\nname: using-blob-datatype\ndescription: How to use the Blob data type for efficient binary storage in Harper.\n---\n\n# Using Blob Datatype\n\nInstructions for the agent to follow when working with the Blob data type in Harper.\n\n## When to Use\n\nUse this skill when you need to store unstructured or large binary data (media, documents) that is too large for standard JSON fields. Blobs provide efficient storage and integrated streaming support.\n\n## How It Works\n\n1. **Define Blob Fields**: In your GraphQL schema, use the `Blob` type:\n ```graphql\n type MyTable @table {\n \tid: ID @primaryKey\n \tdata: Blob\n }\n ```\n2. **Create and Store Blobs**: Use `createBlob()` from Harper's globals to wrap Buffers or Streams:\n ```javascript\n import { tables } from 'harperdb';\n const blob = createBlob(largeBuffer);\n await tables.MyTable.put('my-id', { data: blob });\n ```\n3. **Use Streaming (Optional)**: For very large files, pass a stream to `createBlob()` to avoid loading the entire file into memory.\n4. **Read Blob Data**: Retrieve the record and use `.bytes()` or streaming interfaces on the blob field:\n ```javascript\n const record = await tables.MyTable.get('my-id');\n const buffer = await record.data.bytes();\n ```\n5. **Ensure Write Completion**: Use `saveBeforeCommit: true` in `createBlob` options if you need the blob fully written before the record is committed.\n6. **Handle Errors**: Attach error listeners to the blob object to handle streaming failures.\n",
|
|
@@ -49,4 +51,4 @@ export const rules = {
|
|
|
49
51
|
/**
|
|
50
52
|
* The content of the Harper Best Practices SKILL.md.
|
|
51
53
|
*/
|
|
52
|
-
export const skillSummary = "---\nname: harper-best-practices\ndescription: Best practices for building Harper applications, covering schema definition,\n automatic APIs, authentication, custom resources, and data handling.\n Triggers on tasks involving Harper database design, API implementation,\n and deployment.\nlicense: Apache-2.0\nmetadata:\n author: harper\n version: '1.0.0'\n---\n\n# Harper Best Practices\n\nGuidelines for building scalable, secure, and performant applications on Harper. These practices cover everything from initial schema design to advanced deployment strategies.\n\n## When to Use\n\nReference these guidelines when:\n\n- Defining or modifying database schemas\n- Implementing or extending REST/WebSocket APIs\n- Handling authentication and session management\n- Working with custom resources and extensions\n- Optimizing data storage and retrieval (Blobs, Vector Indexing)\n- Deploying applications to Harper Fabric\n\n## How It Works\n\n1. Review the requirements for the task (schema design, API needs, or infrastructure setup).\n2. Consult the relevant category under \"Rule Categories by Priority\" to understand the impact of your decisions.\n3. Apply specific rules from the \"Quick Reference\" section below by reading their detailed rule files.\n4. If you're building a new table, prioritize the `schema-` rules.\n5. If you're extending functionality, consult the `logic-` and `api-` rules.\n6. Validate your implementation against the `ops-` rules before deployment.\n\n## Examples\n\nSee the concrete examples embedded in each rule subsection below (GraphQL schemas, REST query patterns, and deployment workflow snippets).\n\n## Rule Categories by Priority\n\n| Priority | Category | Impact | Prefix |\n| -------- | -------------------- | ------ | --------- |\n| 1 | Schema & Data Design | HIGH | `schema-` |\n| 2 | API & Communication | HIGH | `api-` |\n| 3 | Logic & Extension | MEDIUM | `logic-` |\n| 4 | Infrastructure & Ops | MEDIUM | `ops-` |\n\n## Quick Reference\n\n### 1. Schema & Data Design (HIGH)\n\n- `adding-tables-with-schemas` - Define tables using GraphQL schemas and directives\n- `defining-relationships` - Link tables using the `@relationship` directive\n- `vector-indexing` - Efficient similarity search with vector indexes\n- `using-blob-datatype` - Store and retrieve large data (Blobs)\n- `handling-binary-data` - Manage binary data like images or MP3s\n\n### 2. API & Communication (HIGH)\n\n- `automatic-apis` - Leverage automatically generated CRUD endpoints\n- `querying-rest-apis` - Filters, sorting, and pagination in REST requests\n- `real-time-apps` - WebSockets and Pub/Sub for Real-Time Apps\n- `checking-authentication` - Secure apps with session-based identity verification\n\n### 3. Logic & Extension (MEDIUM)\n\n- `custom-resources` - Define custom REST endpoints using JS/TS\n- `extending-tables` - Add custom logic to generated table resources\n- `programmatic-table-requests` - Advanced filtering and sorting in code\n- `typescript-type-stripping` - Use TypeScript without build tools\n- `caching` - Implement and define caching for performance\n\n### 4. Infrastructure & Ops (MEDIUM)\n\n- `deploying-to-harper-fabric` - Scale globally with Harper Fabric\n- `creating-a-fabric-account-and-cluster` - Setting up your Harper Fabric cloud infrastructure\n- `creating-harper-apps` - Quickstart with `npm create harper@latest`\n- `serving-web-content` - Ways to serve web content from Harper\n\n## How to Use\n\nRead individual rule files for detailed explanations and code examples:\n\n```\nrules/adding-tables-with-schemas.md\nrules/automatic-apis.md\nrules/creating-harper-apps.md\n```\n\n## Full Compiled Document\n\nFor the complete guide with all rules expanded: `AGENTS.md`\n";
|
|
54
|
+
export const skillSummary = "---\nname: harper-best-practices\ndescription: Best practices for building Harper applications, covering schema definition,\n automatic APIs, authentication, custom resources, and data handling.\n Triggers on tasks involving Harper database design, API implementation,\n and deployment.\nlicense: Apache-2.0\nmetadata:\n author: harper\n version: '1.0.0'\n---\n\n# Harper Best Practices\n\nGuidelines for building scalable, secure, and performant applications on Harper. These practices cover everything from initial schema design to advanced deployment strategies.\n\n## When to Use\n\nReference these guidelines when:\n\n- Defining or modifying database schemas\n- Implementing or extending REST/WebSocket APIs\n- Handling authentication and session management\n- Working with custom resources and extensions\n- Optimizing data storage and retrieval (Blobs, Vector Indexing)\n- Deploying applications to Harper Fabric\n\n## How It Works\n\n1. Review the requirements for the task (schema design, API needs, or infrastructure setup).\n2. Consult the relevant category under \"Rule Categories by Priority\" to understand the impact of your decisions.\n3. Apply specific rules from the \"Quick Reference\" section below by reading their detailed rule files.\n4. If you're building a new table, prioritize the `schema-` rules.\n5. If you're extending functionality, consult the `logic-` and `api-` rules.\n6. Validate your implementation against the `ops-` rules before deployment.\n\n## Examples\n\nSee the concrete examples embedded in each rule subsection below (GraphQL schemas, REST query patterns, and deployment workflow snippets).\n\n## Rule Categories by Priority\n\n| Priority | Category | Impact | Prefix |\n| -------- | -------------------- | ------ | --------- |\n| 1 | Schema & Data Design | HIGH | `schema-` |\n| 2 | API & Communication | HIGH | `api-` |\n| 3 | Logic & Extension | MEDIUM | `logic-` |\n| 4 | Infrastructure & Ops | MEDIUM | `ops-` |\n\n## Quick Reference\n\n### 1. Schema & Data Design (HIGH)\n\n- `adding-tables-with-schemas` - Define tables using GraphQL schemas and directives\n- `schema-design-tooling` - Core directives and GraphQL IDE/agent configuration\n- `defining-relationships` - Link tables using the `@relationship` directive\n- `vector-indexing` - Efficient similarity search with vector indexes\n- `using-blob-datatype` - Store and retrieve large data (Blobs)\n- `handling-binary-data` - Manage binary data like images or MP3s\n\n### 2. API & Communication (HIGH)\n\n- `automatic-apis` - Leverage automatically generated CRUD endpoints\n- `querying-rest-apis` - Filters, sorting, and pagination in REST requests\n- `real-time-apps` - WebSockets and Pub/Sub for Real-Time Apps\n- `checking-authentication` - Secure apps with session-based identity verification\n\n### 3. Logic & Extension (MEDIUM)\n\n- `custom-resources` - Define custom REST endpoints using JS/TS\n- `extending-tables` - Add custom logic to generated table resources\n- `programmatic-table-requests` - Advanced filtering and sorting in code\n- `typescript-type-stripping` - Use TypeScript without build tools\n- `caching` - Implement and define caching for performance\n\n### 4. Infrastructure & Ops (MEDIUM)\n\n- `deploying-to-harper-fabric` - Scale globally with Harper Fabric\n- `creating-a-fabric-account-and-cluster` - Setting up your Harper Fabric cloud infrastructure\n- `creating-harper-apps` - Quickstart with `npm create harper@latest`\n- `serving-web-content` - Ways to serve web content from Harper\n\n## How to Use\n\nRead individual rule files for detailed explanations and code examples:\n\n```\nrules/adding-tables-with-schemas.md\nrules/schema-design-tooling.md\nrules/automatic-apis.md\nrules/creating-harper-apps.md\n```\n\n## Full Compiled Document\n\nFor the complete guide with all rules expanded: `AGENTS.md`\n";
|
|
@@ -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,71 @@ 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
|
+
|
|
75
|
+
- `@table`: Marks a GraphQL type as a Harper database table.
|
|
76
|
+
- `@export`: Automatically generates REST and WebSocket APIs for the table.
|
|
77
|
+
- `@table(expiration: Int)`: Configures a time-to-expire for records in the table (useful for caching).
|
|
78
|
+
|
|
79
|
+
##### Attribute Constraints & Indexing
|
|
80
|
+
|
|
81
|
+
- `@primaryKey`: Specifies the unique identifier for the table.
|
|
82
|
+
- `@indexed`: Creates a standard index on the field for faster lookups.
|
|
83
|
+
- `@indexed(type: "HNSW", distance: "cosine" | "euclidean" | "dot")`: Creates a vector index for similarity search.
|
|
84
|
+
|
|
85
|
+
##### Relationships
|
|
86
|
+
|
|
87
|
+
- `@relationship(from: String)`: Defines a relationship to another table. `from` specifies the local field holding the foreign key.
|
|
88
|
+
|
|
89
|
+
##### Authentication & Authorization
|
|
90
|
+
|
|
91
|
+
- `@auth(role: String)`: Restricts access to a table or field based on user roles.
|
|
92
|
+
|
|
93
|
+
#### Configuring GraphQL Tooling
|
|
94
|
+
|
|
95
|
+
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.
|
|
96
|
+
|
|
97
|
+
This file tells GraphQL tools where to find Harper's built-in types and directives alongside your own schema files.
|
|
98
|
+
|
|
99
|
+
##### Creating `graphql.config.yml`
|
|
100
|
+
|
|
101
|
+
Create a file named `graphql.config.yml` in your project root with the following content:
|
|
102
|
+
|
|
103
|
+
```yaml
|
|
104
|
+
schema:
|
|
105
|
+
- 'node_modules/harperdb/schema.graphql'
|
|
106
|
+
- 'schema.graphql'
|
|
107
|
+
- 'schemas/*.graphql'
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
##### Why this is important:
|
|
111
|
+
|
|
112
|
+
1. **Shared Directives**: It includes `@table`, `@primaryKey`, etc., so they aren't marked as "unknown directives".
|
|
113
|
+
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.
|
|
114
|
+
3. **Consistency**: The `npm create harper@latest` command includes this by default. Manually adding it to existing projects ensures they follow the same standards.
|
|
115
|
+
|
|
116
|
+
#### Example Project Structure
|
|
117
|
+
|
|
118
|
+
A typical Harper project with proper schema tooling:
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
my-harper-app/
|
|
122
|
+
├── config.yaml
|
|
123
|
+
├── graphql.config.yml
|
|
124
|
+
├── package.json
|
|
125
|
+
├── schema.graphql
|
|
126
|
+
└── resources.js
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 1.3 Defining Relationships
|
|
65
130
|
|
|
66
131
|
Using the `@relationship` directive to link tables.
|
|
67
132
|
|
|
@@ -105,7 +170,7 @@ type Category @table @export {
|
|
|
105
170
|
}
|
|
106
171
|
```
|
|
107
172
|
|
|
108
|
-
### 1.
|
|
173
|
+
### 1.4 Vector Indexing
|
|
109
174
|
|
|
110
175
|
How to define and use vector indexes for efficient similarity search.
|
|
111
176
|
|
|
@@ -130,7 +195,7 @@ type Document @table @export {
|
|
|
130
195
|
}
|
|
131
196
|
```
|
|
132
197
|
|
|
133
|
-
### 1.
|
|
198
|
+
### 1.5 Using Blobs
|
|
134
199
|
|
|
135
200
|
How to store and retrieve large data in Harper.
|
|
136
201
|
|
|
@@ -144,7 +209,7 @@ Use this when you need to store large, unstructured data such as files, images,
|
|
|
144
209
|
2. **Storing Data**: Send the data as a buffer or a stream when creating or updating a record.
|
|
145
210
|
3. **Retrieving Data**: Access the blob field, which will return the data as a stream or buffer.
|
|
146
211
|
|
|
147
|
-
### 1.
|
|
212
|
+
### 1.6 Handling Binary Data
|
|
148
213
|
|
|
149
214
|
How to store and serve binary data like images or MP3s.
|
|
150
215
|
|
|
@@ -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
|
```
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
|
|
16
|
+
- `@table`: Marks a GraphQL type as a Harper database table.
|
|
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).
|
|
19
|
+
|
|
20
|
+
### Attribute Constraints & Indexing
|
|
21
|
+
|
|
22
|
+
- `@primaryKey`: Specifies the unique identifier for the table.
|
|
23
|
+
- `@indexed`: Creates a standard index on the field for faster lookups.
|
|
24
|
+
- `@indexed(type: "HNSW", distance: "cosine" | "euclidean" | "dot")`: Creates a vector index for similarity search.
|
|
25
|
+
|
|
26
|
+
### Relationships
|
|
27
|
+
|
|
28
|
+
- `@relationship(from: String)`: Defines a relationship to another table. `from` specifies the local field holding the foreign key.
|
|
29
|
+
|
|
30
|
+
### Authentication & Authorization
|
|
31
|
+
|
|
32
|
+
- `@auth(role: String)`: Restricts access to a table or field based on user roles.
|
|
33
|
+
|
|
34
|
+
## Configuring GraphQL Tooling
|
|
35
|
+
|
|
36
|
+
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.
|
|
37
|
+
|
|
38
|
+
This file tells GraphQL tools where to find Harper's built-in types and directives alongside your own schema files.
|
|
39
|
+
|
|
40
|
+
### Creating `graphql.config.yml`
|
|
41
|
+
|
|
42
|
+
Create a file named `graphql.config.yml` in your project root with the following content:
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
schema:
|
|
46
|
+
- 'node_modules/harperdb/schema.graphql'
|
|
47
|
+
- 'schema.graphql'
|
|
48
|
+
- 'schemas/*.graphql'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Why this is important:
|
|
52
|
+
|
|
53
|
+
1. **Shared Directives**: It includes `@table`, `@primaryKey`, etc., so they aren't marked as "unknown directives".
|
|
54
|
+
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.
|
|
55
|
+
3. **Consistency**: The `npm create harper@latest` command includes this by default. Manually adding it to existing projects ensures they follow the same standards.
|
|
56
|
+
|
|
57
|
+
## Example Project Structure
|
|
58
|
+
|
|
59
|
+
A typical Harper project with proper schema tooling:
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
my-harper-app/
|
|
63
|
+
├── config.yaml
|
|
64
|
+
├── graphql.config.yml
|
|
65
|
+
├── package.json
|
|
66
|
+
├── schema.graphql
|
|
67
|
+
└── resources.js
|
|
68
|
+
```
|