Skip to content

Commit 7242fa1

Browse files
authored
Merge pull request #10 from InonGuetta/master
Add ts support
2 parents 505cd7a + c3ad50e commit 7242fa1

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
56
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
67
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
78

9+
## [1.2.0] - 2025-07-08
10+
11+
### Added
12+
- **TypeScript Definitions** - Bundled `lib/json-file-crud.d.ts` for IDE support
13+
14+
815
## [1.1.0] - 2025-07-07
916

1017
### Added
@@ -92,7 +99,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9299
## [Unreleased]
93100

94101
### Future Improvements
95-
- TypeScript support with .d.ts files
96102
- Promise-based API (async/await)
97103
- Batch operations (createMany, updateMany, deleteMany)
98104
- File locking for multi-process safety

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ node examples/basic-usage.js
329329

330330
## TypeScript Support
331331

332-
While this library is written in JavaScript, you can use it in TypeScript projects. Type definitions may be added in future versions.
332+
Type definitions are provided via `lib/json-file-crud.d.ts` so the library can be used comfortably in TypeScript projects with autocompletion and compile-time checks.
333333

334334
## File Format
335335

lib/json-file-crud.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export interface CrudOptions {
2+
idField?: string;
3+
autoId?: boolean;
4+
uniqueFields?: string[];
5+
}
6+
7+
export type Callback<T> = (err: Error | null, result: T) => void;
8+
9+
export default class JsonFileCRUD<T = any> {
10+
constructor(filePath: string, options?: CrudOptions);
11+
12+
readonly filePath: string;
13+
readonly idField: string;
14+
readonly autoId: boolean;
15+
readonly uniqueFields: string[];
16+
17+
create(item: T, callback: Callback<T>): void;
18+
readAll(callback: Callback<T[]>): void;
19+
findById(id: any, callback: Callback<T>): void;
20+
findBy(filterFn: (item: T) => boolean, callback: Callback<T[]>): void;
21+
count(callback: Callback<number>): void;
22+
update(id: any, data: Partial<T>, callback: Callback<T>): void;
23+
delete(id: any, callback: Callback<T>): void;
24+
deleteAll(callback: (err: Error | null) => void): void;
25+
writeAll(items: T[], callback: (err: Error | null) => void): void;
26+
processWriteQueue(): void;
27+
}
28+
29+
export function createCrud<T = any>(filePath: string, options?: CrudOptions): JsonFileCRUD<T>;

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "@r-el/json-file-crud",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"title": "JsonFileCRUD",
55
"description": "A simple, robust, and thread-safe CRUD library for managing JSON objects in files with unique fields, auto-ID, and advanced features",
66
"main": "./lib/json-file-crud.js",
7+
"types": "./lib/json-file-crud.d.ts",
78
"type": "module",
89
"publishConfig": {
910
"registry": "https://npm.pkg.github.com"

0 commit comments

Comments
 (0)