Compare commits

..

16 Commits

Author SHA1 Message Date
606ff73f58 5.0.2 2022-09-13 21:37:42 +02:00
7ea17c792d fix(core): update 2022-09-13 21:37:42 +02:00
4478b7588a 5.0.1 2022-06-26 11:20:39 +02:00
9bac6e5809 fix(core): update 2022-06-26 11:20:39 +02:00
cbc7e4ebce 5.0.0 2022-06-09 19:55:12 +02:00
097f54a74c BREAKING CHANGE(core): update 2022-06-09 19:55:12 +02:00
807624d157 4.0.7 2022-06-09 19:54:44 +02:00
9d7e2e03d9 fix(core): update 2022-06-09 19:54:43 +02:00
9686caff18 4.0.6 2021-01-28 02:21:24 +00:00
9260d653a1 fix(core): update 2021-01-28 02:21:23 +00:00
28cd849d0d 4.0.5 2020-10-09 09:41:16 +00:00
89a399bf42 fix(core): update 2020-10-09 09:41:15 +00:00
16048fe96d 4.0.4 2020-10-05 16:20:27 +00:00
04d60333a9 fix(core): update 2020-10-05 16:20:27 +00:00
c30f1f4ab9 4.0.3 2020-10-05 15:28:30 +00:00
fc91dd3171 fix(core): update 2020-10-05 15:28:29 +00:00
13 changed files with 10953 additions and 8849 deletions

View File

@ -12,6 +12,9 @@ stages:
- release - release
- metadata - metadata
before_script:
- npm install -g @shipzone/npmci
# ==================== # ====================
# security stage # security stage
# ==================== # ====================
@ -36,6 +39,7 @@ auditProductionDependencies:
- npmci command npm audit --audit-level=high --only=prod --production - npmci command npm audit --audit-level=high --only=prod --production
tags: tags:
- docker - docker
allow_failure: true
auditDevDependencies: auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
@ -96,10 +100,9 @@ codequality:
only: only:
- tags - tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g typescript
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- lossless - lossless
- docker - docker
@ -119,11 +122,10 @@ trigger:
pages: pages:
stage: metadata stage: metadata
script: script:
- npmci node install lts - npmci node install stable
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command npm run buildDocs
tags: tags:
- lossless - lossless
- docker - docker

4
.snyk
View File

@ -1,4 +0,0 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.13.3
ignore: {}
patch: {}

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "current file", "command": "npm test",
"type": "node", "name": "Run npm test",
"request": "launch", "request": "launch",
"args": [ "type": "node-terminal"
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
} }
] ]
} }

View File

@ -8,7 +8,7 @@
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",
"gitrepo": "smartjson", "gitrepo": "smartjson",
"shortDescription": "typed json handlers", "description": "typed json handlers",
"npmPackagename": "@pushrocks/smartjson", "npmPackagename": "@pushrocks/smartjson",
"license": "MIT" "license": "MIT"
} }

19558
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,14 @@
{ {
"name": "@pushrocks/smartjson", "name": "@pushrocks/smartjson",
"version": "4.0.2", "version": "5.0.2",
"private": false, "private": false,
"description": "typed json handlers", "description": "typed json handlers",
"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)" "build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -20,17 +21,17 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartjson#README", "homepage": "https://gitlab.com/pushrocks/smartjson#README",
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.25", "@gitzone/tsbuild": "^2.1.65",
"@gitzone/tsrun": "^1.2.12", "@gitzone/tsrun": "^1.2.37",
"@gitzone/tstest": "^1.0.52", "@gitzone/tstest": "^1.0.73",
"@pushrocks/tapbundle": "^3.2.9", "@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^14.11.2", "@types/node": "^18.7.17"
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@types/buffer-json": "^2.0.0", "@pushrocks/smartstring": "^4.0.5",
"@types/fast-json-stable-stringify": "^2.0.0", "@types/buffer-json": "^2.0.1",
"@types/fast-json-stable-stringify": "^2.1.0",
"@types/lodash.clonedeep": "^4.5.7",
"buffer-json": "^2.0.0", "buffer-json": "^2.0.0",
"fast-json-stable-stringify": "^2.1.0", "fast-json-stable-stringify": "^2.1.0",
"lodash.clonedeep": "^4.5.0" "lodash.clonedeep": "^4.5.0"
@ -49,5 +50,6 @@
], ],
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
] ],
"type": "module"
} }

55
test/test.both.ts Normal file
View File

@ -0,0 +1,55 @@
import { tap, expect } from '@pushrocks/tapbundle';
import * as smartjson from '../ts/index.js';
class SomeClass extends smartjson.Smartjson {
@smartjson.foldDec() thisis: string = 'test';
constructor() {
super();
console.log(this.saveableProperties);
}
}
let mySomeClass: SomeClass;
tap.test('should create a Foldable extended instance', async () => {
mySomeClass = new SomeClass();
expect(mySomeClass).toBeInstanceOf(SomeClass);
expect(mySomeClass).toBeInstanceOf(smartjson.Smartjson);
});
tap.test('should create a folded object', async () => {
let foldedObject = mySomeClass.foldToObject();
expect(foldedObject).property('thisis').toEqual('test');
});
tap.test('should enfold from object', async () => {
const mySomeClass2 = SomeClass.enfoldFromObject({ thisis: 'test2' });
expect(mySomeClass2).property('thisis').toEqual('test2');
});
tap.test('should products stable jsons', async () => {
const jsonString = smartjson.stringify({
a: 1,
f: 6,
b: 3,
c: 3,
e: 5,
d: 4,
});
console.log(jsonString);
});
tap.test('should work with base64', async() => {
const someObject = {
hi: 'there',
thisIs: 'awesome',
};
const base64Json = smartjson.stringifyBase64(someObject);
console.log(base64Json);
const decodedObject = smartjson.parseBase64(base64Json);
expect(decodedObject).toEqual(someObject);
})
tap.start();

View File

@ -1,31 +0,0 @@
import { tap, expect } from '@pushrocks/tapbundle';
import { Smartjson, foldDec } from '../ts/index';
class SomeClass extends Smartjson {
@foldDec() thisis: string = 'test';
constructor() {
super();
console.log(this.saveableProperties);
}
}
let mySomeClass: SomeClass;
tap.test('should create a Foldable extended instance', async () => {
mySomeClass = new SomeClass();
expect(mySomeClass).to.be.instanceof(SomeClass);
expect(mySomeClass).to.be.instanceof(Smartjson);
});
tap.test('should create a folded object', async () => {
let foldedObject = mySomeClass.foldToObject();
expect(foldedObject).property('thisis').to.equal('test');
});
tap.test('should enfold from object', async () => {
const mySomeClass2 = SomeClass.enfoldFromObject({ thisis: 'test2' });
expect(mySomeClass2).property('thisis').to.equal('test2');
});
tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartjson',
version: '5.0.2',
description: 'typed json handlers'
}

View File

@ -1,4 +1,4 @@
import * as plugins from './smartjson.plugins'; import * as plugins from './smartjson.plugins.js';
/** /**
* allows you to parse a json * allows you to parse a json
@ -10,12 +10,29 @@ export const parse = plugins.bufferJson.parse;
* @param objArg * @param objArg
* @param optionsArg * @param optionsArg
*/ */
export const stringify = (objArg: any, optionsArg: plugins.IStableJsonTypes['Options'] = {}) => { export const stringify = (
objArg: any,
simpleOrderArray?: string[],
optionsArg: plugins.IStableJsonTypes['Options'] = {}
): string => {
const bufferedJson = plugins.bufferJson.stringify(objArg); const bufferedJson = plugins.bufferJson.stringify(objArg);
objArg = JSON.parse(bufferedJson); objArg = JSON.parse(bufferedJson);
return plugins.stableJson(objArg, optionsArg); let returnJson = plugins.stableJson(objArg, optionsArg);
return returnJson;
}; };
export const stringifyBase64 = (...args: Parameters<typeof stringify>): string => {
const stringifiedResult = stringify(...args);
return plugins.smartstring.base64.encodeUri(stringifiedResult);
}
export const parseBase64 = (base64JsonStringArg: string) => {
const simpleStringified = plugins.smartstring.base64.decode(base64JsonStringArg);
return parse(simpleStringified);
}
parse
export class Smartjson { export class Smartjson {
/** /**
* enfolds data from an object * enfolds data from an object
@ -49,8 +66,17 @@ export class Smartjson {
*/ */
public foldToObject() { public foldToObject() {
const newFoldedObject: { [key: string]: any } = {}; const newFoldedObject: { [key: string]: any } = {};
const trackMap = [];
for (const keyName of this.saveableProperties) { for (const keyName of this.saveableProperties) {
newFoldedObject[keyName] = plugins.lodashCloneDeep(this[keyName]); let value = this[keyName];
if (value instanceof Smartjson) {
if (trackMap.includes(value)) {
throw new Error('cycle detected');
}
trackMap.push(value);
value = value.foldToObject();
}
newFoldedObject[keyName] = plugins.lodashCloneDeep(value);
} }
return newFoldedObject; return newFoldedObject;
} }
@ -60,14 +86,14 @@ export class Smartjson {
*/ */
public foldToJson() { public foldToJson() {
const foldedObject = this.foldToObject(); const foldedObject = this.foldToObject();
return stringify(foldedObject, {}); return stringify(foldedObject);
} }
} }
/** /**
* Decorator that marks a property as foldable * Decorator that marks a property as foldable
*/ */
export let foldDec = () => { export const foldDec = () => {
return (target: any, key: string) => { return (target: any, key: string) => {
if (!target.saveableProperties) { if (!target.saveableProperties) {
target.saveableProperties = []; target.saveableProperties = [];
@ -75,3 +101,9 @@ export let foldDec = () => {
target.saveableProperties.push(key); target.saveableProperties.push(key);
}; };
}; };
export const deepEqualObjects = (object1: any, object2: any): boolean => {
const object1String = stringify(object1);
const object2String = stringify(object2);
return object1String === object2String;
};

View File

@ -1,3 +1,10 @@
// @pushrocks scope
import * as smartstring from '@pushrocks/smartstring';
export {
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';

View File

@ -1,8 +1,10 @@
{ {
"compilerOptions": { "compilerOptions": {
"experimentalDecorators": true, "experimentalDecorators": true,
"esModuleInterop": true, "useDefineForClassFields": false,
"target": "es2017", "target": "ES2022",
"module": "commonjs" "module": "ES2022",
} "moduleResolution": "nodenext",
"esModuleInterop": true
}
} }

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}