Skip to content

docs: add comprehensive GitHub Copilot onboarding instructions#1135

Merged
Belphemur merged 2 commits into
developfrom
copilot/add-copilot-instructions
Mar 10, 2026
Merged

docs: add comprehensive GitHub Copilot onboarding instructions#1135
Belphemur merged 2 commits into
developfrom
copilot/add-copilot-instructions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 10, 2026

The existing .github/copilot-instructions.md only covered pnpm setup (44 lines). This expands it into a full agent onboarding reference so Copilot coding agents can work effectively without repeated exploration.

Changes to .github/copilot-instructions.md

  • Architecture — annotated directory tree with role of every src/ file; adapter chain (JsonDB → JsonAdapter → CipheredFileAdapter | FileAdapter) made explicit
  • Public API reference — complete method table for JsonDB; Config/ConfigWithAdapter constructor signatures with all parameters and defaults
  • DataPath syntax — reference table covering /, /prop, [0], [], [-1], [0][1], []/prop
  • Error codes — all DataError (ids 3–13, 100, 200) and DatabaseError (ids 1, 2, 7) numeric codes documented
  • Encryption — key requirements (exactly 32 bytes), .enc.json extension behavior, on-disk format (iv/tag/data)
  • TypeScript conventions — strict mode, naming rules (_prefix for private, PascalCase/camelCase), JSDoc requirement for public API
  • Testing conventions — cleanup patterns (afterEach with rmSync/unlinkSync), /tmp/<uuid> pattern for encrypted DB tests, numbered = integration / unnumbered = unit
  • Commit conventions — conventional commits enforced via commitlint; body-max-line-length disabled
  • CI/CD — all three workflows explained (nodejs.yml, release.yml, codeql-analysis.yml); semantic-release flow summarized
  • Adapter pattern — minimal IAdapter<string> implementation guide with ConfigWithAdapter usage
  • Known gotchas — 8 non-obvious behaviors (merge semantics, getObjectDefault error id filtering, file creation timing, ArrayInfo regex caching, lock scope)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Expands .github/copilot-instructions.md from a minimal package manager
note into a full agent onboarding guide covering project purpose,
architecture, API reference, DataPath syntax, error codes, encryption,
testing conventions, commit format, CI/CD pipeline, and known gotchas.

Co-authored-by: Belphemur <197810+Belphemur@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Copilot instructions for optimal repository onboarding docs: add comprehensive GitHub Copilot onboarding instructions Mar 10, 2026
@Belphemur Belphemur marked this pull request as ready for review March 10, 2026 11:24
Copilot AI review requested due to automatic review settings March 10, 2026 11:24
@Belphemur Belphemur merged commit 6632572 into develop Mar 10, 2026
9 checks passed
@Belphemur Belphemur deleted the copilot/add-copilot-instructions branch March 10, 2026 11:25
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.60%. Comparing base (7368006) to head (dcfbe74).
⚠️ Report is 4 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1135   +/-   ##
========================================
  Coverage    99.60%   99.60%           
========================================
  Files           12       12           
  Lines         1531     1531           
  Branches       226      322   +96     
========================================
  Hits          1525     1525           
  Misses           6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Expands .github/copilot-instructions.md from a minimal pnpm note into a comprehensive onboarding/reference guide for Copilot coding agents working on node-json-db.

Changes:

  • Adds a project overview and annotated architecture/directory tree.
  • Documents public API, DataPath syntax, error codes, encryption details, and conventions (TS/testing/commits/CI).
  • Includes adapter implementation guidance and a “known gotchas” section.

Comment on lines +318 to +332
import { IAdapter } from 'node-json-db'

class MyAdapter implements IAdapter<string> {
async readAsync(): Promise<string | null> {
// Return raw string data or null if not found
}
async writeAsync(data: string): Promise<void> {
// Persist raw string data
}
}

// Use with ConfigWithAdapter:
import { JsonDB, ConfigWithAdapter } from 'node-json-db'
const db = new JsonDB(new ConfigWithAdapter(new JsonAdapter(new MyAdapter())))
```
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Adapter Pattern example uses new JsonAdapter(...) but the snippet doesn’t import JsonAdapter, so it won’t compile as written. Either add JsonAdapter to the import list or show an example where the custom adapter already reads/writes JSON and can be passed directly to ConfigWithAdapter.

Copilot uses AI. Check for mistakes.
Comment on lines +340 to +341
1. **`push()` with `override=false`** merges recursively for objects, concatenates for arrays, and skips `null` values
2. **`getObjectDefault<T>()`** catches only `DataError` with `id === 5` (path not found); other errors still propagate
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha #1 says push() merge “skips null values”, but the merge() implementation in src/lib/Utils.ts does not skip nulls—source[prop] can overwrite with null, and only the special-case is when the destination is null. Please adjust this description to match the actual merge semantics (arrays concat; objects recurse; primitives including null overwrite).

Copilot uses AI. Check for mistakes.
Comment on lines +344 to +345
5. **Concurrency**: `readLockAsync`/`writeLockAsync` from `src/lock/Lock.ts` wrap all public read/write operations; custom adapter implementations do not need to add their own locking
6. **Date parsing**: Enabled by default (`parseDates: true`); ISO 8601 strings are automatically revived as `Date` objects
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha #5 claims readLockAsync/writeLockAsync wrap all public read/write operations, but load(), save(), reload(), fromPath(), and resetData() are not lock-wrapped in src/JsonDB.ts. Consider narrowing this statement to the specific methods that are locked (getData/push/delete, and methods that call getData).

Copilot uses AI. Check for mistakes.
Comment on lines +128 to +129
All methods are async and protected by reader-writer locks internally.

Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The statement “All methods are async and protected by reader-writer locks internally” isn’t accurate for the current JsonDB API: resetData() is synchronous, and load(), save(), reload(), and fromPath() are not wrapped in readLockAsync/writeLockAsync. Please adjust this wording to reflect which methods are actually lock-protected/async to avoid misleading API consumers and agents.

Copilot uses AI. Check for mistakes.
Comment on lines +208 to +212
// id 12: filter/find on non-array/non-object
// id 13: fromPath value not found
// id 100: Can't get/delete appended data
// id 200: Non-numeric array index

Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataError id mappings here don’t match the implementation in a few places: id 100 is specifically “Can’t get data when appending” (not delete), and id 10 is also used for “Can’t delete an appended data” in ArrayInfo.delete(). Please align these descriptions with the actual throw sites to keep the error-code reference reliable.

Copilot uses AI. Check for mistakes.
Comment on lines +346 to +347
7. **File auto-created**: The JSON file is only created on the first `save()` (triggered by `push()`/`delete()` with `saveOnPush: true`); the file does NOT exist after a bare `new JsonDB(config)` call
8. **`fromPath()`**: Converts Express-style routes (e.g., `/users/123`) to DataPaths using `getIndex()` internally
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha #7 says the JSON file is created only on the first save() (via push/delete), but the default file-based adapter path will also create the file during the first load()/getData() when it doesn’t exist (because JsonAdapter.readAsync() writes {} on empty/missing data). Please update this to reflect that the first read can create the file.

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +8
- **DataPath navigation**: XPath-like syntax (`/users/0/name`, `/items[]`, `/data[-1]`) to navigate nested JSON data
- **Async-first API**: All database operations return Promises (async/await)
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DataPath examples use /users/0/name, but the project’s documented/featured array syntax uses bracket notation (e.g. /users[0]/name) to support [] append and [-1] semantics consistently (see README array examples). Consider updating this example to bracket form to avoid implying /0 is the recommended array access pattern.

Copilot uses AI. Check for mistakes.
Comment on lines +185 to +187
| `/users` | `users` property of root |
| `/users/0/name` | `name` of first user |
| `/items[0]` | First element of `items` array |
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This table entry uses /users/0/name, which is inconsistent with the library’s standard array indexing syntax (/users[0]/name) used throughout the README and tests. Using bracket notation here will better match how ArrayInfo parses arrays (and avoids confusion with object property names that happen to be numeric strings).

Copilot uses AI. Check for mistakes.
Comment on lines +202 to +206
// DataError — problems with path or data (ids 3–13, 100, 200)
// id 3: Can't merge another type with Array
// id 4: Can't merge Array with Object
// id 5: Path not found (used by getObjectDefault to return default)
// id 10: Can't find array index
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section says it documents all DataError ids 3–13, 100, 200, but it currently omits id 6 (The Data Path can't be empty). Also, ids 7–9 aren’t used in the codebase, so the “3–13” range wording is misleading—consider listing only the ids that actually exist.

Copilot uses AI. Check for mistakes.
Comment on lines +306 to +308
### `codeql-analysis.yml` — Security Scanning
- Runs CodeQL analysis on pushes/PRs to master/develop

Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CodeQL workflow description says it runs on PRs to both master and develop, but .github/workflows/codeql-analysis.yml is configured to run on pull requests targeting develop only. Please update this line to match the actual triggers so agents don’t assume CodeQL runs on every PR to master.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants