BREAKING CHANGE(core): renamed Folable to Smartjson and added deterministic stringify
This commit is contained in:
parent
a9ad89d320
commit
5e945ddad6
@ -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
|
||||
@ -33,24 +34,39 @@ snyk:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
sast:
|
||||
stage: security
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
||||
--volume "$PWD:/code"
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
||||
artifacts:
|
||||
reports:
|
||||
sast: gl-sast-report.json
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
# ====================
|
||||
# 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
|
||||
@ -62,6 +78,7 @@ testLTS:
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
@ -118,6 +135,7 @@ pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
tags:
|
||||
@ -130,13 +148,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
|
||||
|
42
README.md
42
README.md
@ -1,24 +1,19 @@
|
||||
# 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/)
|
||||
[![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-standard-brightgreen.svg)](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
@ -30,9 +25,12 @@ 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 +46,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)
|
||||
|
@ -1,5 +1,15 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartjson",
|
||||
"shortDescription": "typed json handlers",
|
||||
"npmPackagename": "@pushrocks/smartjson",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
1024
package-lock.json
generated
1024
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -20,13 +20,15 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartjson#README",
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tsrun": "^1.1.12",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/tapbundle": "^3.0.1",
|
||||
"@types/node": "^10.9.4"
|
||||
"@gitzone/tsbuild": "^2.1.8",
|
||||
"@gitzone/tsrun": "^1.1.17",
|
||||
"@gitzone/tstest": "^1.0.18",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^11.9.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.10"
|
||||
"@types/fast-json-stable-stringify": "^2.0.0",
|
||||
"fast-json-stable-stringify": "^2.0.0",
|
||||
"lodash": "^4.17.11"
|
||||
}
|
||||
}
|
||||
|
28
test/test.ts
28
test/test.ts
@ -1,9 +1,9 @@
|
||||
import { tap, expect } from "@pushrocks/tapbundle";
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
|
||||
import { Foldable, foldDec } from "../ts/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();
|
||||
|
19
ts/index.ts
19
ts/index.ts
@ -1,15 +1,26 @@
|
||||
let lodash = require('lodash');
|
||||
import * as plugins from './smartjson.plugins';
|
||||
|
||||
export class Smartjson {
|
||||
// ======
|
||||
// STATIC
|
||||
// ======
|
||||
static parse = JSON.parse;
|
||||
|
||||
static stringify = plugins.stableJson;
|
||||
|
||||
// ========
|
||||
// INSTANCE
|
||||
// ========
|
||||
|
||||
export class Foldable {
|
||||
saveableProperties: string[];
|
||||
|
||||
/**
|
||||
* folds a class into an object
|
||||
*/
|
||||
foldToObject() {
|
||||
let newFoldedObject = {};
|
||||
let newFoldedObject: {[key: string]: any} = {};
|
||||
for (let keyName of this.saveableProperties) {
|
||||
newFoldedObject[keyName] = lodash.cloneDeep(this[keyName]);
|
||||
newFoldedObject[keyName] = plugins.lodash.cloneDeep(this[keyName]);
|
||||
}
|
||||
return newFoldedObject;
|
||||
}
|
||||
|
7
ts/smartjson.plugins.ts
Normal file
7
ts/smartjson.plugins.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import * as lodash from 'lodash';
|
||||
import * as stableJson from 'fast-json-stable-stringify';
|
||||
|
||||
export {
|
||||
lodash,
|
||||
stableJson
|
||||
}
|
16
tslint.json
16
tslint.json
@ -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"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user