Compare commits

...

15 Commits

Author SHA1 Message Date
a897f01ec6 5.0.13 2024-03-03 10:30:12 +01:00
f951e0e70d fix(core): update 2024-03-03 10:30:11 +01:00
e79a2514ef 5.0.12 2024-03-03 10:29:19 +01:00
d77c104915 fix(core): update 2024-03-03 10:29:18 +01:00
45593168b0 5.0.11 2024-02-25 01:43:07 +01:00
0227f22ca6 fix(core): update 2024-02-25 01:43:07 +01:00
cece00a9b0 5.0.10 2023-08-24 12:01:21 +02:00
e90ae7649f fix(core): update 2023-08-24 12:01:21 +02:00
70e6150708 5.0.9 2023-08-24 10:48:52 +02:00
52928e0b9b fix(core): update 2023-08-24 10:48:51 +02:00
00ae980fa7 5.0.8 2023-08-19 09:45:22 +02:00
2cd2180788 fix(core): update 2023-08-19 09:45:22 +02:00
2a37a42ed0 5.0.7 2023-08-19 09:45:01 +02:00
e88deb1b5f fix(core): update 2023-08-19 09:45:00 +02:00
05f8e6812b switch to new org scheme 2023-07-10 02:56:36 +02:00
13 changed files with 2973 additions and 1441 deletions

View File

@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build

View File

@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true

View File

@ -1,128 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --prod
tags:
- lossless
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --dev
tags:
- lossless
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install stable
- npmci npm install
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

View File

@ -6,10 +6,10 @@
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "push.rocks",
"gitrepo": "smartjson", "gitrepo": "smartjson",
"description": "typed json handlers", "description": "typed json handlers",
"npmPackagename": "@pushrocks/smartjson", "npmPackagename": "@push.rocks/smartjson",
"license": "MIT" "license": "MIT"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartjson", "name": "@push.rocks/smartjson",
"version": "5.0.6", "version": "5.0.13",
"private": false, "private": false,
"description": "typed json handlers", "description": "typed json handlers",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -21,16 +21,16 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartjson#README", "homepage": "https://gitlab.com/pushrocks/smartjson#README",
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.65", "@git.zone/tsbuild": "^2.1.66",
"@gitzone/tsrun": "^1.2.37", "@git.zone/tsrun": "^1.2.44",
"@gitzone/tstest": "^1.0.74", "@git.zone/tstest": "^1.0.77",
"@pushrocks/tapbundle": "^5.0.4", "@push.rocks/tapbundle": "^5.0.8",
"@types/node": "^18.11.9" "@types/node": "^20.11.24"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartstring": "^4.0.5", "@push.rocks/smartbuffer": "^1.0.7",
"@types/buffer-json": "^2.0.1", "@push.rocks/smartenv": "^5.0.12",
"buffer-json": "^2.0.0", "@push.rocks/smartstring": "^4.0.14",
"fast-json-stable-stringify": "^2.1.0", "fast-json-stable-stringify": "^2.1.0",
"lodash.clonedeep": "^4.5.0" "lodash.clonedeep": "^4.5.0"
}, },

3877
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,26 @@
# @pushrocks/smartjson # @push.rocks/smartjson
typed json handlers typed json handlers
## Availabililty and Links ## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartjson) * [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartjson)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartjson) * [gitlab.com (source)](https://gitlab.com/push.rocks/smartjson)
* [github.com (source mirror)](https://github.com/pushrocks/smartjson) * [github.com (source mirror)](https://github.com/push.rocks/smartjson)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartjson/) * [docs (typedoc)](https://push.rocks.gitlab.io/smartjson/)
## Status for master ## Status for master
Status Category | Status Badge Status Category | Status Badge
-- | -- -- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartjson/badges/master/pipeline.svg)](https://lossless.cloud) GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/smartjson/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartjson/badges/master/coverage.svg)](https://lossless.cloud) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/smartjson/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartjson)](https://lossless.cloud) npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartjson)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartjson)](https://lossless.cloud) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smartjson)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud) Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartjson)](https://lossless.cloud) PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartjson)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartjson)](https://lossless.cloud) PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartjson)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartjson)](https://lossless.cloud) BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartjson)](https://lossless.cloud)
## Usage ## Usage

View File

@ -1,4 +1,4 @@
import { tap, expect } from '@pushrocks/tapbundle'; import { tap, expect } from '@push.rocks/tapbundle';
import * as smartjson from '../ts/index.js'; import * as smartjson from '../ts/index.js';
@ -59,4 +59,17 @@ tap.test('stringify should handle plain string', async () => {
expect(smartjson.parse(stringifiedString)).toEqual('hello'); expect(smartjson.parse(stringifiedString)).toEqual('hello');
}); });
tap.test('should work with buffers', async () => {
const someObject = {
myBuffer: new TextEncoder().encode('hello')
};
console.log(someObject.myBuffer);
const stringified = smartjson.stringify(someObject);
console.log(stringified);
const decoded = smartjson.parse(stringified);
console.log(decoded.myBuffer);
let text = new TextDecoder().decode(decoded.myBuffer);
expect(text).toEqual('hello');
});
tap.start(); tap.start();

View File

@ -2,7 +2,7 @@
* autocreated commitinfo by @pushrocks/commitinfo * autocreated commitinfo by @pushrocks/commitinfo
*/ */
export const commitinfo = { export const commitinfo = {
name: '@pushrocks/smartjson', name: '@push.rocks/smartjson',
version: '5.0.6', version: '5.0.13',
description: 'typed json handlers' description: 'typed json handlers'
} }

121
ts/bufferhandling.ts Normal file
View File

@ -0,0 +1,121 @@
import * as plugins from './smartjson.plugins.js';
// Define interfaces and types for better type checking and readability
interface IBufferLike {
type: 'Buffer';
data: string | any[]; // `any[]` for array data representation
}
interface IEncodedBuffer {
type: 'EncodedBuffer',
data: string;
}
type TParseReviver = (this: any, key: string, value: any) => any;
type TParseReplacer = (this: any, key: string, value: any) => any;
// Utility functions to handle base64 encoding/decoding in a cross-platform way
function base64Encode(data: Uint8Array): string {
return btoa(String.fromCharCode(...data));
}
function base64Decode(str: string): Uint8Array {
return new Uint8Array(Array.from(atob(str)).map((char) => char.charCodeAt(0)));
}
// Main functionality with cross-platform support
function stringify(value: any, space?: string | number): string {
return JSON.stringify(value, replacer, space);
}
function parse(text: string): any {
return JSON.parse(text, reviver);
}
const replacer: TParseReplacer = (key, value) => {
// Check if value is IBufferLike
if (isBufferLike(value)) {
let bufferData: Uint8Array;
// Handle IBufferLike objects with a .data property
if ('data' in value && isArray(value.data)) {
if (value.data.length > 0) {
bufferData = new Uint8Array(value.data);
} else {
return ''; // Return empty string for empty data arrays
}
}
// Handle Uint8Array directly
else if (value instanceof Uint8Array) {
bufferData = value;
} else {
// If not a recognized format, return value as is
return value;
}
// Encode the bufferData (Uint8Array) to base64
const base64Data = 'base64:' + base64Encode(bufferData);
return {
type: 'EncodedBuffer',
data: base64Data,
};
}
// Return value unchanged if not buffer-like
return value;
};
const reviver: TParseReviver = (key, value) => {
if (isEncodedBuffer(value)) {
if (isString(value.data) && value.data.startsWith('base64:')) {
// Correctly slice the 'base64:' prefix before decoding
const base64Data = value.data.slice(7); // Skip 'base64:' prefix
const buffer = base64Decode(base64Data);
// Assuming the rest of your application can work directly with Uint8Array,
// otherwise, you might need to convert it to another format
return buffer;
}
}
return value;
};
function isEncodedBuffer(x: any): x is IEncodedBuffer {
return isObject(x) && (x as any).type === 'EncodedBuffer' && isString((x as any).data);
}
function isBufferLike(x: any): x is IBufferLike | Uint8Array {
return (
(isObject(x) &&
((x as any).type === 'Buffer' &&
(isArray((x as any).data) || isString((x as any).data)))) ||
x instanceof Uint8Array
);
}
/**
* We use this function to check if a value is an array
* @param x
* @returns
*/
function isArray(x: any): x is any[] {
return Array.isArray(x);
}
/**
* We use this function to check if a value is a string
* @param x
* @returns
*/
function isString(x: any): x is string {
return typeof x === 'string';
}
/**
* We use this function to check if a value is an object
* @param x
*/
function isObject(x: any): x is object {
return typeof x === 'object' && x !== null;
}
export { stringify, parse, replacer, reviver };

View File

@ -1,9 +1,10 @@
import * as plugins from './smartjson.plugins.js'; import * as plugins from './smartjson.plugins.js';
import * as bufferhandling from './bufferhandling.js';
/** /**
* allows you to parse a json * allows you to parse a json
*/ */
export const parse = plugins.bufferJson.parse; export const parse = bufferhandling.parse;
/** /**
* *
@ -15,12 +16,18 @@ export const stringify = (
simpleOrderArray?: string[], simpleOrderArray?: string[],
optionsArg: plugins.IStableJsonTypes['Options'] = {} optionsArg: plugins.IStableJsonTypes['Options'] = {}
): string => { ): string => {
const bufferedJson = plugins.bufferJson.stringify(objArg); const bufferedJson = bufferhandling.stringify(objArg);
objArg = JSON.parse(bufferedJson); objArg = JSON.parse(bufferedJson);
let returnJson = plugins.stableJson(objArg, optionsArg); let returnJson = plugins.stableJson(objArg, optionsArg);
return returnJson; return returnJson;
}; };
export const stringifyPretty = (objectArg: any) => {
const stringified = stringify(objectArg);
const object = JSON.parse(stringified);
return JSON.stringify(object, null, 2);
}
export const stringifyBase64 = (...args: Parameters<typeof stringify>): string => { export const stringifyBase64 = (...args: Parameters<typeof stringify>): string => {
const stringifiedResult = stringify(...args); const stringifiedResult = stringify(...args);
return plugins.smartstring.base64.encodeUri(stringifiedResult); return plugins.smartstring.base64.encodeUri(stringifiedResult);

View File

@ -1,16 +1,16 @@
// @pushrocks scope // @pushrocks scope
import * as smartstring from '@pushrocks/smartstring'; import * as smartenv from '@push.rocks/smartenv';
import * as smartstring from '@push.rocks/smartstring';
export { smartstring }; export { smartenv, smartstring };
// third party scope // third party scope
import lodashCloneDeep from 'lodash.clonedeep'; import lodashCloneDeep from 'lodash.clonedeep';
import stableJson2 from 'fast-json-stable-stringify'; import stableJson2 from 'fast-json-stable-stringify';
import bufferJson from 'buffer-json';
const stableJson = stableJson2 as any; const stableJson = stableJson2 as any;
export { bufferJson, lodashCloneDeep, stableJson }; export { lodashCloneDeep, stableJson };
export interface IStableJsonTypes { export interface IStableJsonTypes {
Comparator: ( Comparator: (

View File

@ -3,8 +3,12 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"useDefineForClassFields": false, "useDefineForClassFields": false,
"target": "ES2022", "target": "ES2022",
"module": "ES2022", "module": "NodeNext",
"moduleResolution": "nodenext", "moduleResolution": "NodeNext",
"esModuleInterop": true "esModuleInterop": true,
} "verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
} }