Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
9bc1c4bf93 | |||
5176a34575 | |||
fe9f9299fc | |||
62cf2fd262 | |||
65e581d48b | |||
4ff97294bb | |||
2d5bd6a2f0 | |||
a2649b7854 | |||
b901f8604b | |||
d70310ce8b | |||
e0e9ceed31 | |||
e3add99efe | |||
91d57c84f4 | |||
37b32d5d5d | |||
f6199740aa | |||
215cf77205 | |||
6e2c86dbb4 | |||
a5b9bbd376 | |||
f6a9810e71 | |||
32423f5475 | |||
5e945ddad6 |
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,4 +1,22 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
@ -1,5 +1,7 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
variables:
|
||||||
|
GIT_STRATEGY: clone
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
@ -26,6 +28,7 @@ mirror:
|
|||||||
snyk:
|
snyk:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install -g snyk
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
@ -36,44 +39,35 @@ snyk:
|
|||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# 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:
|
testStable:
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
testBuild:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install lts
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
@ -86,19 +80,11 @@ release:
|
|||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm install
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--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]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
@ -114,12 +100,15 @@ trigger:
|
|||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-dbase:npmci
|
||||||
|
services:
|
||||||
|
- docker:18-dind
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
@ -130,13 +119,3 @@ pages:
|
|||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
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
4
.snyk
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||||
|
version: v1.13.3
|
||||||
|
ignore: {}
|
||||||
|
patch: {}
|
43
README.md
43
README.md
@ -1,25 +1,20 @@
|
|||||||
# smartjson
|
# @pushrocks/smartjson
|
||||||
|
|
||||||
typed json handlers
|
typed json handlers
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartjson)
|
||||||
[](https://www.npmjs.com/package/smartjson)
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartjson)
|
||||||
[](https://GitLab.com/pushrocks/smartjson)
|
* [github.com (source mirror)](https://github.com/pushrocks/smartjson)
|
||||||
[](https://github.com/pushrocks/smartjson)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartjson/)
|
||||||
[](https://pushrocks.gitlab.io/smartjson/)
|
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
[](https://gitlab.com/pushrocks/smartjson/commits/master)
|
||||||
[](https://GitLab.com/pushrocks/smartjson/commits/master)
|
[](https://gitlab.com/pushrocks/smartjson/commits/master)
|
||||||
[](https://GitLab.com/pushrocks/smartjson/commits/master)
|
[](https://www.npmjs.com/package/@pushrocks/smartjson)
|
||||||
[](https://www.npmjs.com/package/smartjson)
|
[](https://snyk.io/test/npm/@pushrocks/smartjson)
|
||||||
[](https://david-dm.org/pushrocks/smartjson)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartjson/master/dependencies/npm)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartjson)
|
[](https://prettier.io/)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
## 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
|
SmartJson makes it easy to fold and enfold classes into and from JSON
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import { Foldable, foldDec } from 'smartjson';
|
import { Smartjson, foldDec } from 'smartjson';
|
||||||
|
|
||||||
|
class AwesomeClass extends Smartjson {
|
||||||
|
static stringify;
|
||||||
|
|
||||||
class AwesomeClass extends Foldable {
|
|
||||||
computedValue: string;
|
computedValue: string;
|
||||||
|
|
||||||
@foldDec() // mark anotherValueToStore as foldable
|
@foldDec() // mark anotherValueToStore as foldable
|
||||||
@ -48,9 +45,9 @@ myAwesomeInstance.enfoldFromObject({ anotherValueToStore: 'hi' });
|
|||||||
foldedObject = myAwesomeInstance.foldToObject(); // will return {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)
|
> 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)
|
||||||
|
|
||||||
[](https://push.rocks)
|
[](https://maintainedby.lossless.com)
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartjson",
|
||||||
|
"shortDescription": "typed json handlers",
|
||||||
|
"npmPackagename": "@pushrocks/smartjson",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
1716
package-lock.json
generated
1716
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartjson",
|
"name": "@pushrocks/smartjson",
|
||||||
"version": "2.0.2",
|
"version": "3.0.10",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "typed json handlers",
|
"description": "typed json handlers",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -20,13 +20,28 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartjson#README",
|
"homepage": "https://gitlab.com/pushrocks/smartjson#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"@gitzone/tsrun": "^1.1.12",
|
"@gitzone/tsrun": "^1.2.8",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.28",
|
||||||
"@pushrocks/tapbundle": "^3.0.1",
|
"@pushrocks/tapbundle": "^3.2.0",
|
||||||
"@types/node": "^10.9.4"
|
"@types/node": "^12.12.17",
|
||||||
|
"tslint": "^5.20.1",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash": "^4.17.10"
|
"@types/fast-json-stable-stringify": "^2.0.0",
|
||||||
}
|
"fast-json-stable-stringify": "^2.1.0",
|
||||||
|
"lodash.clonedeep": "^4.5.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/*",
|
||||||
|
"ts_web/*",
|
||||||
|
"dist/*",
|
||||||
|
"dist_web/*",
|
||||||
|
"dist_ts_web/*",
|
||||||
|
"assets/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
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 {
|
class SomeClass extends Smartjson {
|
||||||
@foldDec() thisis: string = "test";
|
@foldDec() thisis: string = 'test';
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
console.log(this.saveableProperties);
|
console.log(this.saveableProperties);
|
||||||
@ -12,24 +12,24 @@ class SomeClass extends Foldable {
|
|||||||
|
|
||||||
let mySomeClass: SomeClass;
|
let mySomeClass: SomeClass;
|
||||||
|
|
||||||
tap.test("should create a Foldable extended instance", async () => {
|
tap.test('should create a Foldable extended instance', async () => {
|
||||||
mySomeClass = new SomeClass();
|
mySomeClass = new SomeClass();
|
||||||
expect(mySomeClass).to.be.instanceof(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();
|
let foldedObject = mySomeClass.foldToObject();
|
||||||
expect(foldedObject)
|
expect(foldedObject)
|
||||||
.property("thisis")
|
.property('thisis')
|
||||||
.to.equal("test");
|
.to.equal('test');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test("should enfold from object", async () => {
|
tap.test('should enfold from object', async () => {
|
||||||
mySomeClass.enfoldFromObject({ thisis: "test2" });
|
mySomeClass.enfoldFromObject({ thisis: 'test2' });
|
||||||
expect(mySomeClass)
|
expect(mySomeClass)
|
||||||
.property("thisis")
|
.property('thisis')
|
||||||
.to.equal("test2");
|
.to.equal('test2');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start()
|
tap.start();
|
||||||
|
31
ts/index.ts
31
ts/index.ts
@ -1,15 +1,28 @@
|
|||||||
let lodash = require('lodash');
|
import * as plugins from './smartjson.plugins';
|
||||||
|
|
||||||
export class Foldable {
|
export class Smartjson {
|
||||||
saveableProperties: string[];
|
// ======
|
||||||
|
// STATIC
|
||||||
|
// ======
|
||||||
|
public static parse = JSON.parse;
|
||||||
|
|
||||||
|
public static stringify = (objArg: any, optionsArg: plugins.IStableJsonTypes['Options']) => {
|
||||||
|
return plugins.stableJson(objArg, optionsArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========
|
||||||
|
// INSTANCE
|
||||||
|
// ========
|
||||||
|
|
||||||
|
public saveableProperties: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* folds a class into an object
|
* folds a class into an object
|
||||||
*/
|
*/
|
||||||
foldToObject() {
|
public foldToObject() {
|
||||||
let newFoldedObject = {};
|
const newFoldedObject: { [key: string]: any } = {};
|
||||||
for (let keyName of this.saveableProperties) {
|
for (const keyName of this.saveableProperties) {
|
||||||
newFoldedObject[keyName] = lodash.cloneDeep(this[keyName]);
|
newFoldedObject[keyName] = plugins.lodashCloneDeep(this[keyName]);
|
||||||
}
|
}
|
||||||
return newFoldedObject;
|
return newFoldedObject;
|
||||||
}
|
}
|
||||||
@ -17,8 +30,8 @@ export class Foldable {
|
|||||||
/**
|
/**
|
||||||
* enfolds data from an object
|
* enfolds data from an object
|
||||||
*/
|
*/
|
||||||
enfoldFromObject(objectArg) {
|
public enfoldFromObject(objectArg) {
|
||||||
for (let keyName in objectArg) {
|
for (const keyName in objectArg) {
|
||||||
if (this.saveableProperties.indexOf(keyName) !== -1) {
|
if (this.saveableProperties.indexOf(keyName) !== -1) {
|
||||||
this[keyName] = objectArg[keyName];
|
this[keyName] = objectArg[keyName];
|
||||||
}
|
}
|
||||||
|
18
ts/smartjson.plugins.ts
Normal file
18
ts/smartjson.plugins.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import lodashCloneDeep from 'lodash.clonedeep';
|
||||||
|
import stableJson2 from 'fast-json-stable-stringify';
|
||||||
|
|
||||||
|
const stableJson = stableJson2 as any;
|
||||||
|
|
||||||
|
export { lodashCloneDeep, stableJson };
|
||||||
|
|
||||||
|
export interface IStableJsonTypes {
|
||||||
|
Comparator: (a: IStableJsonTypes['CompareDescriptor'], b: IStableJsonTypes['CompareDescriptor']) => number;
|
||||||
|
CompareDescriptor: {
|
||||||
|
key: string;
|
||||||
|
value: any;
|
||||||
|
};
|
||||||
|
Options: {
|
||||||
|
cmp?: (a: IStableJsonTypes['CompareDescriptor'], b: IStableJsonTypes['CompareDescriptor']) => number;
|
||||||
|
cycles?: boolean;
|
||||||
|
};
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"target": "es2016",
|
"esModuleInterop": true,
|
||||||
|
"target": "es2017",
|
||||||
"module": "commonjs"
|
"module": "commonjs"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user