Compare commits

...

4 Commits

14 changed files with 3254 additions and 3126 deletions
+12 -5
View File
@@ -1,8 +1,5 @@
{ {
"npmci": { "@git.zone/cli": {
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "code.foss.global", "githost": "code.foss.global",
@@ -24,9 +21,19 @@
"data encoding", "data encoding",
"data decoding" "data decoding"
] ]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
} }
}, },
"tsdoc": { "@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis 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. \n\n**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.\n\n### Trademarks\n\nThis 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.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy 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.\n" "legal": "\n## License and Legal Information\n\nThis 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. \n\n**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.\n\n### Trademarks\n\nThis 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.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy 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.\n"
},
"@ship.zone/szci": {
"npmGlobalTools": []
} }
} }
+18
View File
@@ -1,5 +1,23 @@
# Changelog # Changelog
## 2026-04-30 - 6.0.1 - fix(build,json)
replace lodash.clonedeep with structuredClone and migrate package metadata to smartconfig
- removes the lodash.clonedeep dependency by using structuredClone when folding saveable properties
- improves cross-platform buffer handling by resolving Buffer from globalThis instead of relying on ts-ignore checks
- migrates project metadata from npmextra.json to .smartconfig.json and updates packaged files accordingly
- updates build tooling versions and drops the allowimplicitany build flag
## 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) ## 2025-09-12 - 5.2.0 - feat(smartjson)
Implement stableOneWayStringify: deterministic, cycle-safe JSON for hashing/comparisons; update docs and tests Implement stableOneWayStringify: deterministic, cycle-safe JSON for hashing/comparisons; update docs and tests
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2026 Task Venture Capital GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+12 -13
View File
@@ -1,36 +1,35 @@
{ {
"name": "@push.rocks/smartjson", "name": "@push.rocks/smartjson",
"version": "5.2.0", "version": "6.0.1",
"private": false, "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.", "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", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"scripts": { "scripts": {
"test": "(tstest test/ --web)", "test": "(tstest test/ --web)",
"build": "(tsbuild --web --allowimplicitany)", "build": "(tsbuild --web)",
"buildDocs": "tsdoc" "buildDocs": "tsdoc"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://code.foss.global/push.rocks/smartjson.git" "url": "https://code.foss.global/push.rocks/smartjson.git"
}, },
"author": "Lossless GmbH", "author": "Task Venture Capital GmbH",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://gitlab.com/pushrocks/smartjson/issues" "url": "https://code.foss.global/push.rocks/smartjson/issues"
}, },
"homepage": "https://code.foss.global/push.rocks/smartjson", "homepage": "https://code.foss.global/push.rocks/smartjson",
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.6.8", "@git.zone/tsbuild": "^4.4.0",
"@git.zone/tsrun": "^1.3.3", "@git.zone/tsrun": "^2.0.2",
"@git.zone/tstest": "^2.3.8", "@git.zone/tstest": "^3.6.3",
"@types/node": "^22" "@types/node": "^25.6.0"
}, },
"dependencies": { "dependencies": {
"@push.rocks/smartenv": "^5.0.13", "@push.rocks/smartenv": "^6.0.0",
"@push.rocks/smartstring": "^4.1.0", "@push.rocks/smartstring": "^4.1.0",
"fast-json-stable-stringify": "^2.1.0", "fast-json-stable-stringify": "^2.1.0"
"lodash.clonedeep": "^4.5.0"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@@ -41,7 +40,7 @@
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
"npmextra.json", ".smartconfig.json",
"readme.md" "readme.md"
], ],
"browserslist": [ "browserslist": [
@@ -61,5 +60,5 @@
"data encoding", "data encoding",
"data decoding" "data decoding"
], ],
"packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748" "packageManager": "pnpm@10.28.2"
} }
+3110 -3058
View File
File diff suppressed because it is too large Load Diff
-3
View File
@@ -1,3 +0,0 @@
onlyBuiltDependencies:
- esbuild
- puppeteer
+10
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
+27 -21
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. 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 ## Installation
```bash ```bash
@@ -157,9 +161,9 @@ Transform class instances to JSON and back while preserving type safety:
import { Smartjson, foldDec } from '@push.rocks/smartjson'; import { Smartjson, foldDec } from '@push.rocks/smartjson';
class User extends Smartjson { class User extends Smartjson {
@foldDec() public username: string; @foldDec() accessor username: string;
@foldDec() public email: string; @foldDec() accessor email: string;
@foldDec() public settings: UserSettings; @foldDec() accessor settings: UserSettings;
// Properties without @foldDec won't be serialized // Properties without @foldDec won't be serialized
private internalId: string; private internalId: string;
@@ -174,8 +178,8 @@ class User extends Smartjson {
} }
class UserSettings extends Smartjson { class UserSettings extends Smartjson {
@foldDec() public theme: 'light' | 'dark' = 'light'; @foldDec() accessor theme: 'light' | 'dark' = 'light';
@foldDec() public notifications: boolean = true; @foldDec() accessor notifications: boolean = true;
} }
// Create and serialize // Create and serialize
@@ -197,8 +201,8 @@ console.log(restoredUser.settings instanceof UserSettings); // true
```typescript ```typescript
class Company extends Smartjson { class Company extends Smartjson {
@foldDec() public name: string; @foldDec() accessor name: string;
@foldDec() public employees: Employee[] = []; @foldDec() accessor employees: Employee[] = [];
addEmployee(employee: Employee) { addEmployee(employee: Employee) {
this.employees.push(employee); this.employees.push(employee);
@@ -206,9 +210,9 @@ class Company extends Smartjson {
} }
class Employee extends Smartjson { class Employee extends Smartjson {
@foldDec() public name: string; @foldDec() accessor name: string;
@foldDec() public role: string; @foldDec() accessor role: string;
@foldDec() public salary: number; @foldDec() accessor salary: number;
constructor(name: string, role: string, salary: number) { constructor(name: string, role: string, salary: number) {
super(); super();
@@ -282,9 +286,9 @@ const isEqual = smartjson.deepEqualObjects(obj1, obj2); // true
```typescript ```typescript
class CachedAPIResponse extends Smartjson { class CachedAPIResponse extends Smartjson {
@foldDec() public data: any; @foldDec() accessor data: any;
@foldDec() public timestamp: number; @foldDec() accessor timestamp: number;
@foldDec() public endpoint: string; @foldDec() accessor endpoint: string;
isExpired(maxAge: number = 3600000): boolean { isExpired(maxAge: number = 3600000): boolean {
return Date.now() - this.timestamp > maxAge; return Date.now() - this.timestamp > maxAge;
@@ -318,9 +322,9 @@ if (stored) {
```typescript ```typescript
class AppConfig extends Smartjson { class AppConfig extends Smartjson {
@foldDec() public apiUrl: string; @foldDec() accessor apiUrl: string;
@foldDec() public features: Map<string, boolean> = new Map(); @foldDec() accessor features: Map<string, boolean> = new Map();
@foldDec() public limits: { @foldDec() accessor limits: {
maxUploadSize: number; maxUploadSize: number;
maxConcurrentRequests: number; maxConcurrentRequests: number;
}; };
@@ -364,7 +368,7 @@ class AppConfig extends Smartjson {
### Decorators ### Decorators
- `@foldDec()` - Mark class property for serialization - `@foldDec()` - Mark class property for serialization (use with `accessor` keyword)
## Performance Tips ## Performance Tips
@@ -395,19 +399,21 @@ This library supports modern browsers and Node.js environments. For older browse
## License and Legal Information ## 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. **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 ### 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 ### Company Information
Task Venture Capital GmbH 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. 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.
+1 -1
View File
@@ -3,7 +3,7 @@ import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as smartjson from '../ts/index.js'; import * as smartjson from '../ts/index.js';
class SomeClass extends smartjson.Smartjson { class SomeClass extends smartjson.Smartjson {
@smartjson.foldDec() thisis: string = 'test'; @smartjson.foldDec() accessor thisis: string = 'test';
constructor() { constructor() {
super(); super();
console.log(this.saveableProperties); console.log(this.saveableProperties);
+1 -1
View File
@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartjson', name: '@push.rocks/smartjson',
version: '5.2.0', version: '6.0.1',
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.' 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.'
} }
+20 -8
View File
@@ -14,22 +14,34 @@ interface IEncodedBuffer {
type TParseReviver = (this: any, key: string, value: any) => any; type TParseReviver = (this: any, key: string, value: any) => any;
type TParseReplacer = (this: any, key: string, value: any) => any; type TParseReplacer = (this: any, key: string, value: any) => any;
interface INodeBufferLike extends Uint8Array {
toString(): string;
toString(encoding: 'base64'): string;
}
interface INodeBufferConstructor {
from(data: Uint8Array): INodeBufferLike;
from(data: string, encoding: 'base64'): INodeBufferLike;
}
const getNodeBuffer = (): INodeBufferConstructor | undefined => {
return (globalThis as typeof globalThis & { Buffer?: INodeBufferConstructor }).Buffer;
};
// Utility functions to handle base64 encoding/decoding in a cross-platform way // Utility functions to handle base64 encoding/decoding in a cross-platform way
function base64Encode(data: Uint8Array): string { function base64Encode(data: Uint8Array): string {
// Prefer Node's Buffer when available const NodeBuffer = getNodeBuffer();
if (typeof Buffer !== 'undefined') { if (NodeBuffer) {
// @ts-ignore Buffer might not exist in browser builds return NodeBuffer.from(data).toString('base64');
return Buffer.from(data).toString('base64');
} }
// Fallback for browsers // Fallback for browsers
return btoa(String.fromCharCode(...data)); return btoa(String.fromCharCode(...data));
} }
function base64Decode(str: string): Uint8Array { function base64Decode(str: string): Uint8Array {
// Prefer Node's Buffer when available const NodeBuffer = getNodeBuffer();
if (typeof Buffer !== 'undefined') { if (NodeBuffer) {
// @ts-ignore Buffer might not exist in browser builds const buf = NodeBuffer.from(str, 'base64');
const buf = Buffer.from(str, 'base64');
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength); return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
} }
// Fallback for browsers // Fallback for browsers
+18 -9
View File
@@ -163,7 +163,7 @@ export class Smartjson {
// INSTANCE // INSTANCE
// ======== // ========
public saveableProperties: string[]; public saveableProperties: string[] = [];
/** /**
* folds a class into an object * folds a class into an object
@@ -187,11 +187,11 @@ export class Smartjson {
if (Array.isArray(val)) { if (Array.isArray(val)) {
return val.map((item) => foldValue(item)); return val.map((item) => foldValue(item));
} }
return plugins.lodashCloneDeep(val); return structuredClone(val);
}; };
const props: string[] = (this as any).saveableProperties || []; const props: string[] = (this as any).saveableProperties || [];
for (const keyName of props) { for (const keyName of props) {
const value = this[keyName]; const value = (this as unknown as Record<string, unknown>)[keyName];
result[keyName] = foldValue(value); result[keyName] = foldValue(value);
} }
return result; return result;
@@ -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 = () => { export const foldDec = () => {
return (target: any, key: string) => { return <This extends Smartjson, Value>(
if (!target.saveableProperties) { _value: ClassAccessorDecoratorTarget<This, Value>,
target.saveableProperties = []; context: ClassAccessorDecoratorContext<This, Value>
} ): ClassAccessorDecoratorResult<This, Value> | void => {
target.saveableProperties.push(key); const propertyName = String(context.name);
context.addInitializer(function (this: This) {
if (!this.saveableProperties) {
this.saveableProperties = [];
}
if (!this.saveableProperties.includes(propertyName)) {
this.saveableProperties.push(propertyName);
}
});
}; };
}; };
+1 -2
View File
@@ -5,12 +5,11 @@ import * as smartstring from '@push.rocks/smartstring';
export { smartenv, smartstring }; export { smartenv, smartstring };
// third party scope // third party scope
import lodashCloneDeep from 'lodash.clonedeep';
import stableJson2 from 'fast-json-stable-stringify'; import stableJson2 from 'fast-json-stable-stringify';
const stableJson = stableJson2 as any; const stableJson = stableJson2 as any;
export { lodashCloneDeep, stableJson }; export { stableJson };
export interface IStableJsonTypes { export interface IStableJsonTypes {
Comparator: ( Comparator: (
-2
View File
@@ -1,7 +1,5 @@
{ {
"compilerOptions": { "compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022", "target": "ES2022",
"module": "NodeNext", "module": "NodeNext",
"moduleResolution": "NodeNext", "moduleResolution": "NodeNext",