@harperfast/skills 1.0.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.md ADDED
@@ -0,0 +1,7 @@
1
+ # Harper Agent Skills
2
+
3
+ This repository contains "skills" that guide AI agents in developing Harper applications.
4
+
5
+ ## Available Skills
6
+
7
+ - [Harper Best Practices](harper-best-practices/SKILL.md): Comprehensive guidelines for building, extending, and deploying Harper applications.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 HarperDB, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # Harper Agent Skills
2
+
3
+ This repository provides specialized "skills" for AI agents (like Cursor, Windsurf, or Junie) to build better applications on [Harper](https://harper.fast/).
4
+
5
+ ## Installation
6
+
7
+ Add these skills to your local project using the [skills](https://skills.sh/) CLI:
8
+
9
+ ```bash
10
+ npx skills add harperfast/skills
11
+ ```
12
+
13
+ Re-run this command later if you want to get the latest updates from us.
14
+
15
+ ## Available Skills
16
+
17
+ ### [Harper Best Practices](harper-best-practices/SKILL.md)
18
+ Comprehensive guidelines for building, extending, and deploying Harper applications. Covers:
19
+ - Schema design and relationships.
20
+ - Automatic REST and WebSocket APIs.
21
+ - Custom resources and table extensions.
22
+ - Advanced features like Vector Indexing and Caching.
23
+
24
+ ## How it Works
25
+
26
+ These skills are structured to be easily consumed by Large Language Models (LLMs) and AI agents. For a technical overview of how agents use these files, see [AGENTS.md](AGENTS.md).
@@ -0,0 +1,258 @@
1
+ # Harper Best Practices
2
+
3
+ Guidelines for building scalable, secure, and performant applications on Harper. These practices cover everything from initial schema design to advanced deployment strategies.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [Schema & Data Design](#1-schema--data-design) — **HIGH**
10
+ - 1.1 [Adding Tables with Schemas](#11-adding-tables-with-schemas)
11
+ - 1.2 [Defining Relationships](#12-defining-relationships)
12
+ - 1.3 [Vector Indexing](#13-vector-indexing)
13
+ - 1.4 [Using Blobs](#14-using-blobs)
14
+ - 1.5 [Handling Binary Data](#15-handling-binary-data)
15
+ 2. [API & Communication](#2-api--communication) — **HIGH**
16
+ - 2.1 [Automatic REST APIs](#21-automatic-rest-apis)
17
+ - 2.2 [Querying REST APIs](#22-querying-rest-apis)
18
+ - 2.3 [Real-time Applications](#23-real-time-applications)
19
+ - 2.4 [Checking Authentication](#24-checking-authentication)
20
+ 3. [Logic & Extension](#3-logic--extension) — **MEDIUM**
21
+ - 3.1 [Custom Resources](#31-custom-resources)
22
+ - 3.2 [Extending Table Resources](#32-extending-table-resources)
23
+ - 3.3 [Programmatic Table Requests](#33-programmatic-table-requests)
24
+ - 3.4 [TypeScript Type Stripping](#34-typescript-type-stripping)
25
+ - 3.5 [Caching](#35-caching)
26
+ 4. [Infrastructure & Ops](#4-infrastructure--ops) — **MEDIUM**
27
+ - 4.1 [Deploying to Harper Fabric](#41-deploying-to-harper-fabric)
28
+ - 4.2 [Serving Web Content](#42-serving-web-content)
29
+
30
+ ---
31
+
32
+ ## 1. Schema & Data Design
33
+
34
+ **Impact: HIGH**
35
+
36
+ ### 1.1 Adding Tables with Schemas
37
+
38
+ Instructions for the agent to follow when adding tables to a Harper database.
39
+
40
+ #### When to Use
41
+ Use this skill when you need to define new data structures or modify existing ones in a Harper database.
42
+
43
+ #### Steps
44
+ 1. **Create Dedicated Schema Files**: Prefer having a dedicated schema `.graphql` file for each table. Check the `config.yaml` file under `graphqlSchema.files` to see how it's configured. It typically accepts wildcards (e.g., `schemas/*.graphql`), but may be configured to point at a single file.
45
+ 2. **Use Directives**: All available directives for defining your schema are defined in `node_modules/harperdb/schema.graphql`. Common directives include `@table`, `@export`, `@primaryKey`, `@indexed`, and `@relationship`.
46
+ 3. **Define Relationships**: Link tables together using the `@relationship` directive.
47
+ 4. **Enable Automatic APIs**: If you add `@table @export` to a schema type, Harper automatically sets up REST and WebSocket APIs for basic CRUD operations against that table.
48
+ 5. **Consider Table Extensions**: If you are going to extend the table in your resources, then do not `@export` the table from the schema.
49
+
50
+ #### Example
51
+ ```graphql
52
+ type ExamplePerson @table @export {
53
+ id: ID @primaryKey
54
+ name: String
55
+ tag: String @indexed
56
+ }
57
+ ```
58
+
59
+ ### 1.2 Defining Relationships
60
+
61
+ Using the `@relationship` directive to link tables.
62
+
63
+ #### When to Use
64
+ Use this when you have two or more tables that need to be logically linked (e.g., a "Product" table and a "Category" table).
65
+
66
+ #### Steps
67
+ 1. **Identify the Relationship**: Determine which table should "own" the relationship. This is typically the table that will hold the foreign key.
68
+ 2. **Apply the `@relationship` Directive**: In your GraphQL schema, use the `@relationship` directive on the field that links to another table.
69
+ 3. **Specify the `name` and `path` Arguments**:
70
+ - `name`: A unique name for the relationship.
71
+ - `path`: The field name in the current table that holds the value to match in the related table.
72
+ 4. **Define the Inverse Relationship (Optional but Recommended)**: For better queryability, define the relationship in the related table as well.
73
+
74
+ #### Example
75
+ ```graphql
76
+ type Product @table @export {
77
+ id: ID @primaryKey
78
+ name: String
79
+ category: Category @relationship(name: "product_category", path: "category_id")
80
+ category_id: ID
81
+ }
82
+
83
+ type Category @table @export {
84
+ id: ID @primaryKey
85
+ name: String
86
+ products: [Product] @relationship(name: "product_category", path: "id")
87
+ }
88
+ ```
89
+
90
+ ### 1.3 Vector Indexing
91
+
92
+ How to define and use vector indexes for efficient similarity search.
93
+
94
+ #### When to Use
95
+ Use this when you need to perform similarity searches on high-dimensional data, such as image embeddings, text embeddings, or any other numeric vectors.
96
+
97
+ #### Steps
98
+ 1. **Define the Vector Field**: In your GraphQL schema, define a field with a list of floats (e.g., `[Float]`).
99
+ 2. **Apply the `@indexed` Directive**: Use the `@indexed` directive on the vector field and specify the index type as `vector`.
100
+ 3. **Configure the Index (Optional)**: You can provide additional configuration for the vector index, such as the distance metric (e.g., `cosine`, `euclidean`).
101
+ 4. **Querying**: Use the `vector` operator in your REST or programmatic requests to perform similarity searches.
102
+
103
+ #### Example
104
+ ```graphql
105
+ type Document @table @export {
106
+ id: ID @primaryKey
107
+ content: String
108
+ embedding: [Float] @indexed(type: "vector", options: { dims: 1536, metric: "cosine" })
109
+ }
110
+ ```
111
+
112
+ ### 1.4 Using Blobs
113
+
114
+ How to store and retrieve large data in HarperDB.
115
+
116
+ #### When to Use
117
+ Use this when you need to store large, unstructured data such as files, images, or large text documents that exceed the typical size of a standard database field.
118
+
119
+ #### Steps
120
+ 1. **Define the Blob Field**: Use the `Blob` scalar type in your GraphQL schema.
121
+ 2. **Storing Data**: Send the data as a buffer or a stream when creating or updating a record.
122
+ 3. **Retrieving Data**: Access the blob field, which will return the data as a stream or buffer.
123
+
124
+ ### 1.5 Handling Binary Data
125
+
126
+ How to store and serve binary data like images or MP3s.
127
+
128
+ #### When to Use
129
+ Use this when your application needs to handle binary files, particularly for storage and retrieval.
130
+
131
+ #### Steps
132
+ 1. **Use the `Blob` type**: As with general large data, the `Blob` type is best for binary files.
133
+ 2. **Streaming**: For large files, use streaming to minimize memory usage during upload and download.
134
+ 3. **MIME Types**: Store the MIME type alongside the binary data to ensure it is served correctly by your application logic.
135
+
136
+ ---
137
+
138
+ ## 2. API & Communication
139
+
140
+ **Impact: HIGH**
141
+
142
+ ### 2.1 Automatic REST APIs
143
+
144
+ Details on the CRUD endpoints automatically generated for exported tables.
145
+
146
+ #### Endpoints
147
+ - `GET /{TableName}`: Describes the schema.
148
+ - `GET /{TableName}/`: Lists records (supports filtering/sorting).
149
+ - `GET /{TableName}/{id}`: Gets a record by ID.
150
+ - `POST /{TableName}/`: Creates a record.
151
+ - `PUT /{TableName}/{id}`: Updates a record.
152
+ - `PATCH /{TableName}/{id}`: Partial update.
153
+ - `DELETE /{TableName}/`: Deletes records.
154
+ - `DELETE /{TableName}/{id}`: Deletes by ID.
155
+
156
+ ### 2.2 Querying REST APIs
157
+
158
+ How to use filters, operators, sorting, and pagination in REST requests.
159
+
160
+ #### Query Parameters
161
+ - `limit`: Number of records to return.
162
+ - `offset`: Number of records to skip.
163
+ - `sort`: Field to sort by.
164
+ - `order`: `asc` or `desc`.
165
+ - `filter`: JSON object for filtering.
166
+
167
+ ### 2.3 Real-time Applications
168
+
169
+ Implementing WebSockets and Pub/Sub for live data updates.
170
+
171
+ #### When to Use
172
+ Use this for applications that require live updates, such as chat apps, live dashboards, or collaborative tools.
173
+
174
+ #### Steps
175
+ 1. **WebSocket Connection**: Connect to the Harper WebSocket endpoint.
176
+ 2. **Subscribing**: Subscribe to table updates or specific records.
177
+ 3. **Pub/Sub**: Use the internal bus to publish and subscribe to custom events.
178
+
179
+ ### 2.4 Checking Authentication
180
+
181
+ How to use sessions to verify user identity and roles.
182
+
183
+ #### When to Use
184
+ Use this to secure your application by ensuring that only authorized users can access certain resources or perform specific actions.
185
+
186
+ #### Steps
187
+ 1. **Session Handling**: Access the session object from the request context.
188
+ 2. **Identity Verification**: Check for the presence of a user ID or token.
189
+ 3. **Role Checks**: Verify if the user has the required roles for the action.
190
+
191
+ ---
192
+
193
+ ## 3. Logic & Extension
194
+
195
+ **Impact: MEDIUM**
196
+
197
+ ### 3.1 Custom Resources
198
+
199
+ How to define custom REST endpoints using JavaScript or TypeScript.
200
+
201
+ #### Steps
202
+ 1. **Create Resource File**: Define your logic in a JS or TS file.
203
+ 2. **Export Handlers**: Export functions like `GET`, `POST`, etc.
204
+ 3. **Registration**: Ensure the resource is correctly registered in your application configuration.
205
+
206
+ ### 3.2 Extending Table Resources
207
+
208
+ Adding custom logic to automatically generated table resources.
209
+
210
+ #### Steps
211
+ 1. **Define Extension**: Create a resource file that targets an existing table.
212
+ 2. **Intercept Requests**: Use handlers to add custom validation or data transformation.
213
+ 3. **No `@export`**: If extending, remember not to `@export` the table in the schema.
214
+
215
+ ### 3.3 Programmatic Table Requests
216
+
217
+ How to use filters, operators, sorting, and pagination in programmatic table requests.
218
+
219
+ #### Usage
220
+ When writing custom resources, use the internal API to query tables with full support for advanced filtering and sorting.
221
+
222
+ ### 3.4 TypeScript Type Stripping
223
+
224
+ Using TypeScript directly without build tools via Node.js Type Stripping.
225
+
226
+ #### Configuration
227
+ Harper supports native TypeScript type stripping, allowing you to run `.ts` files directly. Ensure your environment is configured to take advantage of this for faster development cycles.
228
+
229
+ ### 3.5 Caching
230
+
231
+ How caching is defined and implemented in Harper applications.
232
+
233
+ #### Strategies
234
+ - **In-memory**: For fast access to frequently used data.
235
+ - **Distributed**: For scaling across multiple nodes in Harper Fabric.
236
+
237
+ ---
238
+
239
+ ## 4. Infrastructure & Ops
240
+
241
+ **Impact: MEDIUM**
242
+
243
+ ### 4.1 Deploying to Harper Fabric
244
+
245
+ Globally scaling your Harper application.
246
+
247
+ #### Benefits
248
+ - **Global Distribution**: Low latency for users everywhere.
249
+ - **Automatic Sync**: Data is synced across the fabric automatically.
250
+ - **Free Tier**: Start for free and scale as you grow.
251
+
252
+ ### 4.2 Serving Web Content
253
+
254
+ Two ways to serve web content from a Harper application.
255
+
256
+ #### Methods
257
+ 1. **Static Serving**: Serve HTML, CSS, and JS files directly.
258
+ 2. **Dynamic Rendering**: Use custom resources to render content on the fly.
@@ -0,0 +1,88 @@
1
+ ---
2
+ name: harper-best-practices
3
+ description:
4
+ Best practices for building Harper applications, covering schema definition,
5
+ automatic APIs, authentication, custom resources, and data handling.
6
+ Triggers on tasks involving Harper database design, API implementation,
7
+ and deployment.
8
+ license: MIT
9
+ metadata:
10
+ author: harper
11
+ version: '1.0.0'
12
+ ---
13
+
14
+ # Harper Best Practices
15
+
16
+ Guidelines for building scalable, secure, and performant applications on Harper. These practices cover everything from initial schema design to advanced deployment strategies.
17
+
18
+ ## When to Use
19
+
20
+ Reference these guidelines when:
21
+
22
+ - Defining or modifying database schemas
23
+ - Implementing or extending REST/WebSocket APIs
24
+ - Handling authentication and session management
25
+ - Working with custom resources and extensions
26
+ - Optimizing data storage and retrieval (Blobs, Vector Indexing)
27
+ - Deploying applications to Harper Fabric
28
+
29
+ ## Steps
30
+
31
+ 1. Review the requirements for the task (schema design, API needs, or infrastructure setup).
32
+ 2. Consult the relevant category under "Rule Categories by Priority" to understand the impact of your decisions.
33
+ 3. Apply specific rules from the "Quick Reference" section below by reading their detailed rule files.
34
+ 4. If you're building a new table, prioritize the `schema-` rules.
35
+ 5. If you're extending functionality, consult the `logic-` and `api-` rules.
36
+ 6. Validate your implementation against the `ops-` rules before deployment.
37
+
38
+ ## Rule Categories by Priority
39
+
40
+ | Priority | Category | Impact | Prefix |
41
+ | -------- | ----------------------- | ------ | --------------- |
42
+ | 1 | Schema & Data Design | HIGH | `schema-` |
43
+ | 2 | API & Communication | HIGH | `api-` |
44
+ | 3 | Logic & Extension | MEDIUM | `logic-` |
45
+ | 4 | Infrastructure & Ops | MEDIUM | `ops-` |
46
+
47
+ ## Quick Reference
48
+
49
+ ### 1. Schema & Data Design (HIGH)
50
+
51
+ - `adding-tables-with-schemas` - Define tables using GraphQL schemas and directives
52
+ - `defining-relationships` - Link tables using the `@relationship` directive
53
+ - `vector-indexing` - Efficient similarity search with vector indexes
54
+ - `using-blob-datatype` - Store and retrieve large data (Blobs)
55
+ - `handling-binary-data` - Manage binary data like images or MP3s
56
+
57
+ ### 2. API & Communication (HIGH)
58
+
59
+ - `automatic-apis` - Leverage automatically generated CRUD endpoints
60
+ - `querying-rest-apis` - Filters, sorting, and pagination in REST requests
61
+ - `real-time-apps` - WebSockets and Pub/Sub for live data updates
62
+ - `checking-authentication` - Secure apps with session-based identity verification
63
+
64
+ ### 3. Logic & Extension (MEDIUM)
65
+
66
+ - `custom-resources` - Define custom REST endpoints using JS/TS
67
+ - `extending-tables` - Add custom logic to generated table resources
68
+ - `programmatic-table-requests` - Advanced filtering and sorting in code
69
+ - `typescript-type-stripping` - Use TypeScript without build tools
70
+ - `caching` - Implement and define caching for performance
71
+
72
+ ### 4. Infrastructure & Ops (MEDIUM)
73
+
74
+ - `deploying-to-harper-fabric` - Scale globally with Harper Fabric
75
+ - `serving-web-content` - Ways to serve web content from Harper
76
+
77
+ ## How to Use
78
+
79
+ Read individual rule files for detailed explanations and code examples:
80
+
81
+ ```
82
+ rules/adding-tables-with-schemas.md
83
+ rules/automatic-apis.md
84
+ ```
85
+
86
+ ## Full Compiled Document
87
+
88
+ For the complete guide with all rules expanded: `AGENTS.md`
@@ -0,0 +1,40 @@
1
+ ---
2
+ name: adding-tables-with-schemas
3
+ description: Guidelines for adding tables to a Harper database using GraphQL schemas.
4
+ ---
5
+
6
+ # Adding Tables with Schemas
7
+
8
+ Instructions for the agent to follow when adding tables to a Harper database.
9
+
10
+ ## When to Use
11
+
12
+ Use this skill when you need to define new data structures or modify existing ones in a Harper database.
13
+
14
+ ## Steps
15
+
16
+ 1. **Create Dedicated Schema Files**: Prefer having a dedicated schema `.graphql` file for each table. Check the `config.yaml` file under `graphqlSchema.files` to see how it's configured. It typically accepts wildcards (e.g., `schemas/*.graphql`), but may be configured to point at a single file.
17
+ 2. **Use Directives**: All available directives for defining your schema are defined in `node_modules/harperdb/schema.graphql`. Common directives include `@table`, `@export`, `@primaryKey`, `@indexed`, and `@relationship`.
18
+ 3. **Define Relationships**: Link tables together using the `@relationship` directive. For more details, see the [Defining Relationships](defining-relationships.md) skill.
19
+ 4. **Enable Automatic APIs**: If you add `@table @export` to a schema type, Harper automatically sets up REST and WebSocket APIs for basic CRUD operations against that table. For a detailed list of available endpoints and how to use them, see the [Automatic REST APIs](automatic-apis.md) skill.
20
+ - `GET /{TableName}`: Describes the schema itself.
21
+ - `GET /{TableName}/`: Lists all records (supports filtering, sorting, and pagination via query parameters). See the [Querying REST APIs](querying-rest-apis.md) skill for details.
22
+ - `GET /{TableName}/{id}`: Retrieves a single record by its ID.
23
+ - `POST /{TableName}/`: Creates a new record.
24
+ - `PUT /{TableName}/{id}`: Updates an existing record.
25
+ - `PATCH /{TableName}/{id}`: Performs a partial update on a record.
26
+ - `DELETE /{TableName}/`: Deletes all records or filtered records.
27
+ - `DELETE /{TableName}/{id}`: Deletes a single record by its ID.
28
+ 5. **Consider Table Extensions**: If you are going to [extend the table](./extending-tables.md) in your resources, then do not `@export` the table from the schema.
29
+
30
+ ### Example
31
+
32
+ In a hypothetical `schemas/ExamplePerson.graphql`:
33
+
34
+ ```graphql
35
+ type ExamplePerson @table @export {
36
+ id: ID @primaryKey
37
+ name: String
38
+ tag: String @indexed
39
+ }
40
+ ```
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: automatic-apis
3
+ description: How to use Harper's automatically generated REST and WebSocket APIs.
4
+ ---
5
+
6
+ # Automatic APIs
7
+
8
+ Instructions for the agent to follow when utilizing Harper's automatic APIs.
9
+
10
+ ## When to Use
11
+
12
+ Use this skill when you want to interact with Harper tables via REST or WebSockets without writing custom resource logic. This is ideal for basic CRUD operations and real-time updates.
13
+
14
+ ## Steps
15
+
16
+ 1. **Enable Automatic APIs**: Ensure your GraphQL schema includes the `@export` directive for the table:
17
+ ```graphql
18
+ type MyTable @table @export {
19
+ id: ID @primaryKey
20
+ # ... other fields
21
+ }
22
+ ```
23
+ 2. **Access REST Endpoints**: Use the following endpoints for a table named `TableName` (Note: Paths are **case-sensitive**):
24
+ - **Describe Schema**: `GET /{TableName}`
25
+ - **List Records**: `GET /{TableName}/` (Supports filtering, sorting, and pagination. See [Querying REST APIs](querying-rest-apis.md)).
26
+ - **Get Single Record**: `GET /{TableName}/{id}`
27
+ - **Create Record**: `POST /{TableName}/` (Request body should be JSON).
28
+ - **Update Record (Full)**: `PUT /{TableName}/{id}`
29
+ - **Update Record (Partial)**: `PATCH /{TableName}/{id}`
30
+ - **Delete All/Filtered Records**: `DELETE /{TableName}/`
31
+ - **Delete Single Record**: `DELETE /{TableName}/{id}`
32
+ 3. **Use Automatic WebSockets**: Connect to `ws://your-harper-instance/{TableName}` to receive events whenever updates are made to that table. This is the easiest way to add real-time capabilities. For more complex needs, see [Real-time Applications](real-time-apps.md).
33
+ 4. **Apply Filtering and Querying**: Use query parameters with `GET /{TableName}/` and `DELETE /{TableName}/`. See the [Querying REST APIs](querying-rest-apis.md) skill for advanced details.
34
+ 5. **Customize if Needed**: If the automatic APIs don't meet your requirements, [customize the resources](./custom-resources.md).