BREAKING CHANGE(Smartjson): Require TC39 Stage 3 decorators for @foldDec (use accessor), switch foldDec to initializer-based implementation, improve buffer encode/decode handling, bump dependencies and update docs/tests.

This commit is contained in:
2025-12-10 00:16:00 +00:00
parent acf8cea099
commit 6fe5112bfb
10 changed files with 1889 additions and 1020 deletions

View File

@@ -3,6 +3,10 @@
A powerful library for working with JSON in TypeScript, providing type-safe serialization, advanced buffer handling, deep object comparison, and support for complex class instances. Perfect for applications that need reliable JSON manipulation with full TypeScript support.
## Issue Reporting and Security
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
## Installation
```bash
@@ -157,9 +161,9 @@ Transform class instances to JSON and back while preserving type safety:
import { Smartjson, foldDec } from '@push.rocks/smartjson';
class User extends Smartjson {
@foldDec() public username: string;
@foldDec() public email: string;
@foldDec() public settings: UserSettings;
@foldDec() accessor username: string;
@foldDec() accessor email: string;
@foldDec() accessor settings: UserSettings;
// Properties without @foldDec won't be serialized
private internalId: string;
@@ -174,8 +178,8 @@ class User extends Smartjson {
}
class UserSettings extends Smartjson {
@foldDec() public theme: 'light' | 'dark' = 'light';
@foldDec() public notifications: boolean = true;
@foldDec() accessor theme: 'light' | 'dark' = 'light';
@foldDec() accessor notifications: boolean = true;
}
// Create and serialize
@@ -197,8 +201,8 @@ console.log(restoredUser.settings instanceof UserSettings); // true
```typescript
class Company extends Smartjson {
@foldDec() public name: string;
@foldDec() public employees: Employee[] = [];
@foldDec() accessor name: string;
@foldDec() accessor employees: Employee[] = [];
addEmployee(employee: Employee) {
this.employees.push(employee);
@@ -206,9 +210,9 @@ class Company extends Smartjson {
}
class Employee extends Smartjson {
@foldDec() public name: string;
@foldDec() public role: string;
@foldDec() public salary: number;
@foldDec() accessor name: string;
@foldDec() accessor role: string;
@foldDec() accessor salary: number;
constructor(name: string, role: string, salary: number) {
super();
@@ -282,9 +286,9 @@ const isEqual = smartjson.deepEqualObjects(obj1, obj2); // true
```typescript
class CachedAPIResponse extends Smartjson {
@foldDec() public data: any;
@foldDec() public timestamp: number;
@foldDec() public endpoint: string;
@foldDec() accessor data: any;
@foldDec() accessor timestamp: number;
@foldDec() accessor endpoint: string;
isExpired(maxAge: number = 3600000): boolean {
return Date.now() - this.timestamp > maxAge;
@@ -318,9 +322,9 @@ if (stored) {
```typescript
class AppConfig extends Smartjson {
@foldDec() public apiUrl: string;
@foldDec() public features: Map<string, boolean> = new Map();
@foldDec() public limits: {
@foldDec() accessor apiUrl: string;
@foldDec() accessor features: Map<string, boolean> = new Map();
@foldDec() accessor limits: {
maxUploadSize: number;
maxConcurrentRequests: number;
};
@@ -364,7 +368,7 @@ class AppConfig extends Smartjson {
### Decorators
- `@foldDec()` - Mark class property for serialization
- `@foldDec()` - Mark class property for serialization (use with `accessor` keyword)
## Performance Tips
@@ -395,19 +399,21 @@ This library supports modern browsers and Node.js environments. For older browse
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
For any legal inquiries or further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.