Compare commits

...

2 Commits

10 changed files with 1890 additions and 1021 deletions

View File

@@ -1,5 +1,15 @@
# Changelog
## 2025-12-10 - 6.0.0 - 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.
- foldDec now implements TC39 Stage 3 accessor decorators and must be used with the 'accessor' keyword (e.g. '@foldDec() accessor prop: T'). The decorator registers saveable properties via context.addInitializer so properties are tracked per-instance.
- Buffer handling rewritten: replacer/reviver handle Uint8Array and Buffer cross-platform; EncodedBuffer.data now uses a 'base64:' prefix and reviver returns a Uint8Array. This changes the serialized representation of buffers.
- tsconfig updated to remove experimentalDecorators and useDefineForClassFields overrides — project now targets modern TypeScript decorator support (ensure your toolchain supports Stage 3 decorators).
- Documentation (readme and hints) and tests updated to reflect accessor-based decorators and new buffer handling.
- Dependencies bumped: @push.rocks/smartenv -> ^6.0.0, dev deps @git.zone/tsbuild, @git.zone/tsrun, @git.zone/tstest upgraded, and @types/node -> ^24.0.0.
- Removed pnpm-workspace.yaml onlyBuiltDependencies entries.
## 2025-09-12 - 5.2.0 - feat(smartjson)
Implement stableOneWayStringify: deterministic, cycle-safe JSON for hashing/comparisons; update docs and tests

View File

@@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartjson",
"version": "5.2.0",
"version": "6.0.0",
"private": false,
"description": "A library for handling typed JSON data, providing functionalities for parsing, stringifying, and working with JSON objects, including support for encoding and decoding buffers.",
"main": "dist_ts/index.js",
@@ -21,13 +21,13 @@
},
"homepage": "https://code.foss.global/push.rocks/smartjson",
"devDependencies": {
"@git.zone/tsbuild": "^2.6.8",
"@git.zone/tsrun": "^1.3.3",
"@git.zone/tstest": "^2.3.8",
"@types/node": "^22"
"@git.zone/tsbuild": "^3.1.2",
"@git.zone/tsrun": "^2.0.0",
"@git.zone/tstest": "^3.1.3",
"@types/node": "^24.0.0"
},
"dependencies": {
"@push.rocks/smartenv": "^5.0.13",
"@push.rocks/smartenv": "^6.0.0",
"@push.rocks/smartstring": "^4.1.0",
"fast-json-stable-stringify": "^2.1.0",
"lodash.clonedeep": "^4.5.0"

2797
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +0,0 @@
onlyBuiltDependencies:
- esbuild
- puppeteer

View File

@@ -1 +1,11 @@
# Project Hints
## Decorators
- Uses TC39 Stage 3 decorators (not legacy `experimentalDecorators`)
- The `@foldDec()` decorator requires the `accessor` keyword on properties
- Example: `@foldDec() accessor myProp: string = 'value';`
## Dependencies
- Last upgraded: December 2024
- Uses @push.rocks/smartenv v6.x
- Uses @git.zone/tstest v3.x for testing

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
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.

View File

@@ -3,7 +3,7 @@ import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as smartjson from '../ts/index.js';
class SomeClass extends smartjson.Smartjson {
@smartjson.foldDec() thisis: string = 'test';
@smartjson.foldDec() accessor thisis: string = 'test';
constructor() {
super();
console.log(this.saveableProperties);

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartjson',
version: '5.2.0',
version: '6.0.0',
description: 'A library for handling typed JSON data, providing functionalities for parsing, stringifying, and working with JSON objects, including support for encoding and decoding buffers.'
}

View File

@@ -207,14 +207,23 @@ export class Smartjson {
}
/**
* Decorator that marks a property as foldable
* Decorator that marks a property as foldable (TC39 Stage 3 decorator)
* Use with the `accessor` keyword: @foldDec() accessor myProp: string;
*/
export const foldDec = () => {
return (target: any, key: string) => {
if (!target.saveableProperties) {
target.saveableProperties = [];
}
target.saveableProperties.push(key);
return <This extends Smartjson, Value>(
_value: ClassAccessorDecoratorTarget<This, Value>,
context: ClassAccessorDecoratorContext<This, Value>
): ClassAccessorDecoratorResult<This, Value> | void => {
const propertyName = String(context.name);
context.addInitializer(function (this: This) {
if (!this.saveableProperties) {
this.saveableProperties = [];
}
if (!this.saveableProperties.includes(propertyName)) {
this.saveableProperties.push(propertyName);
}
});
};
};

View File

@@ -1,7 +1,5 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",