Compare commits

..

16 Commits

Author SHA1 Message Date
a2649b7854 3.0.6 2019-08-09 10:55:17 +02:00
b901f8604b fix(core): update 2019-08-09 10:55:17 +02:00
d70310ce8b 3.0.5 2019-07-04 17:04:24 +02:00
e0e9ceed31 fix(core): update 2019-07-04 17:04:24 +02:00
e3add99efe 3.0.4 2019-07-04 17:03:15 +02:00
91d57c84f4 fix(core): update 2019-07-04 17:03:15 +02:00
37b32d5d5d 3.0.3 2019-05-05 19:10:07 +02:00
f6199740aa fix(core): update 2019-05-05 19:10:07 +02:00
215cf77205 3.0.2 2019-05-05 19:01:19 +02:00
6e2c86dbb4 fix(core): update 2019-05-05 19:01:19 +02:00
a5b9bbd376 3.0.1 2019-02-14 23:21:04 +01:00
f6a9810e71 fix(security): add snyk policy 2019-02-14 23:21:03 +01:00
32423f5475 3.0.0 2019-02-14 23:16:34 +01:00
5e945ddad6 BREAKING CHANGE(core): renamed Folable to Smartjson and added deterministic stringify 2019-02-14 23:16:34 +01:00
a9ad89d320 2.0.2 2018-09-06 00:11:46 +02:00
23e7cbd1f1 fix(core): update 2018-09-06 00:11:46 +02:00
14 changed files with 1388 additions and 501 deletions

20
.gitignore vendored
View File

@ -1,4 +1,22 @@
node_modules/
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,5 +1,5 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
@ -26,6 +26,7 @@ mirror:
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
@ -36,21 +37,11 @@ snyk:
# ====================
# test stage
# ====================
testLEGACY:
stage: test
script:
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
allow_failure: true
testLTS:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
@ -58,22 +49,11 @@ testLTS:
tags:
- docker
- notpriv
testSTABLE:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
release:
stage: release
script:
- npmci node install stable
- npmci node install lts
- npmci npm publish
only:
- tags
@ -86,19 +66,11 @@ release:
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
- npmci command npm install -g tslint typescript
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
@ -117,9 +89,10 @@ pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
- npmci command tsdoc
tags:
- docker
- notpriv
@ -130,13 +103,3 @@ pages:
paths:
- public
allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

4
.snyk Normal file
View File

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

View File

@ -1,25 +1,20 @@
# smartjson
# @pushrocks/smartjson
typed json handlers
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartjson)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartjson)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartjson)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartjson/)
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartjson)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartjson)
* [github.com (source mirror)](https://github.com/pushrocks/smartjson)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartjson/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartjson/badges/master/build.svg)](https://GitLab.com/pushrocks/smartjson/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartjson/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartjson/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartjson.svg)](https://www.npmjs.com/package/smartjson)
[![Dependency Status](https://david-dm.org/pushrocks/smartjson.svg)](https://david-dm.org/pushrocks/smartjson)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartjson/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartjson/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartjson/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartjson)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![build status](https://gitlab.com/pushrocks/smartjson/badges/master/build.svg)](https://gitlab.com/pushrocks/smartjson/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartjson/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartjson/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartjson.svg)](https://www.npmjs.com/package/@pushrocks/smartjson)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartjson/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartjson)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
## Usage
@ -30,9 +25,11 @@ Use TypeScript for best in class instellisense.
SmartJson makes it easy to fold and enfold classes into and from JSON
```javascript
import { Foldable, foldDec } from 'smartjson';
import { Smartjson, foldDec } from 'smartjson';
class AwesomeClass extends Smartjson {
static stringify;
class AwesomeClass extends Foldable {
computedValue: string;
@foldDec() // mark anotherValueToStore as foldable
@ -48,9 +45,9 @@ myAwesomeInstance.enfoldFromObject({ anotherValueToStore: 'hi' });
foldedObject = myAwesomeInstance.foldToObject(); // will return {anotherValueToStore: 'hi'}
```
For further information read the linked docs at the top of this README.
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)

16
dist/index.d.ts vendored
View File

@ -1,16 +0,0 @@
import 'typings-global';
export declare class Foldable {
saveableProperties: string[];
/**
* folds a class into an object
*/
foldToObject(): {};
/**
* enfolds data from an object
*/
enfoldFromObject(objectArg: any): void;
}
/**
* Decorator that marks a property as foldable
*/
export declare let foldDec: () => (target: any, key: string) => void;

39
dist/index.js vendored
View File

@ -1,39 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
let lodash = require('lodash');
class Foldable {
/**
* folds a class into an object
*/
foldToObject() {
let newFoldedObject = {};
for (let keyName of this.saveableProperties) {
newFoldedObject[keyName] = lodash.cloneDeep(this[keyName]);
}
return newFoldedObject;
}
/**
* enfolds data from an object
*/
enfoldFromObject(objectArg) {
for (let keyName in objectArg) {
if (this.saveableProperties.indexOf(keyName) !== -1) {
this[keyName] = objectArg[keyName];
}
}
}
}
exports.Foldable = Foldable;
/**
* Decorator that marks a property as foldable
*/
exports.foldDec = () => {
return (target, key) => {
if (!target.saveableProperties) {
target.saveableProperties = [];
}
target.saveableProperties.push(key);
};
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QixJQUFJLE1BQU0sR0FBRyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUE7QUFFOUI7SUFHRTs7T0FFRztJQUNILFlBQVk7UUFDVixJQUFJLGVBQWUsR0FBRyxFQUFFLENBQUE7UUFDeEIsR0FBRyxDQUFDLENBQUMsSUFBSSxPQUFPLElBQUksSUFBSSxDQUFDLGtCQUFrQixDQUFDLENBQUMsQ0FBQztZQUM1QyxlQUFlLENBQUUsT0FBTyxDQUFFLEdBQUcsTUFBTSxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUUsT0FBTyxDQUFFLENBQUMsQ0FBQTtRQUNoRSxDQUFDO1FBQ0QsTUFBTSxDQUFDLGVBQWUsQ0FBQTtJQUN4QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxnQkFBZ0IsQ0FBQyxTQUFTO1FBQ3hCLEdBQUcsQ0FBQyxDQUFDLElBQUksT0FBTyxJQUFJLFNBQVMsQ0FBQyxDQUFDLENBQUM7WUFDOUIsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLGtCQUFrQixDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7Z0JBQ3BELElBQUksQ0FBRSxPQUFPLENBQUUsR0FBRyxTQUFTLENBQUUsT0FBTyxDQUFFLENBQUE7WUFDeEMsQ0FBQztRQUNILENBQUM7SUFDSCxDQUFDO0NBQ0Y7QUF4QkQsNEJBd0JDO0FBRUQ7O0dBRUc7QUFDUSxRQUFBLE9BQU8sR0FBRztJQUNuQixNQUFNLENBQUMsQ0FBQyxNQUFXLEVBQUUsR0FBVztRQUM5QixFQUFFLENBQUMsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDLENBQUM7WUFBQyxNQUFNLENBQUMsa0JBQWtCLEdBQUcsRUFBRSxDQUFBO1FBQUMsQ0FBQztRQUNsRSxNQUFNLENBQUMsa0JBQWtCLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFBO0lBQ3JDLENBQUMsQ0FBQTtBQUNILENBQUMsQ0FBQSJ9

15
npmextra.json Normal file
View File

@ -0,0 +1,15 @@
{
"npmci": {
"npmAccessLevel": "public"
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartjson",
"shortDescription": "typed json handlers",
"npmPackagename": "@pushrocks/smartjson",
"license": "MIT"
}
}
}

1578
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
{
"name": "@pushrocks/smartjson",
"version": "2.0.1",
"private": true,
"version": "3.0.6",
"private": false,
"description": "typed json handlers",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(tsrun test/test.ts)",
"build": "(npmts)"
"test": "(tstest test/)",
"build": "(tsbuild)"
},
"repository": {
"type": "git",
@ -20,10 +20,27 @@
},
"homepage": "https://gitlab.com/pushrocks/smartjson#README",
"devDependencies": {
"@gitzone/tsrun": "^1.1.9",
"@pushrocks/tapbundle": "^3.0.1"
"@gitzone/tsbuild": "^2.1.11",
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.11",
"@types/node": "^12.7.1",
"tslint": "^5.18.0",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"lodash": "^4.17.10"
}
"@types/fast-json-stable-stringify": "^2.0.0",
"fast-json-stable-stringify": "^2.0.0",
"lodash.clonedeep": "^4.5.0"
},
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

View File

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

View File

@ -1,15 +1,28 @@
let lodash = require('lodash');
import * as plugins from './smartjson.plugins';
export class Foldable {
saveableProperties: string[];
export class Smartjson {
// ======
// STATIC
// ======
public static parse = JSON.parse;
public static stringify = (objArg: any, optionsArg: plugins.stableJson.Options) => {
return plugins.stableJson(objArg, optionsArg);
};
// ========
// INSTANCE
// ========
public saveableProperties: string[];
/**
* folds a class into an object
*/
foldToObject() {
let newFoldedObject = {};
for (let keyName of this.saveableProperties) {
newFoldedObject[keyName] = lodash.cloneDeep(this[keyName]);
public foldToObject() {
const newFoldedObject: { [key: string]: any } = {};
for (const keyName of this.saveableProperties) {
newFoldedObject[keyName] = plugins.lodashCloneDeep(this[keyName]);
}
return newFoldedObject;
}
@ -17,8 +30,8 @@ export class Foldable {
/**
* enfolds data from an object
*/
enfoldFromObject(objectArg) {
for (let keyName in objectArg) {
public enfoldFromObject(objectArg) {
for (const keyName in objectArg) {
if (this.saveableProperties.indexOf(keyName) !== -1) {
this[keyName] = objectArg[keyName];
}

4
ts/smartjson.plugins.ts Normal file
View File

@ -0,0 +1,4 @@
import lodashCloneDeep from 'lodash.clonedeep';
import stableJson from 'fast-json-stable-stringify';
export { lodashCloneDeep, stableJson };

View File

@ -1,7 +1,8 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"target": "es2016",
"esModuleInterop": true,
"target": "es2017",
"module": "commonjs"
}
}

View File

@ -1,3 +1,17 @@
{
"extends": "tslint-config-standard"
"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"
}