Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
37b32d5d5d | |||
f6199740aa | |||
215cf77205 | |||
6e2c86dbb4 | |||
a5b9bbd376 | |||
f6a9810e71 | |||
32423f5475 | |||
5e945ddad6 | |||
a9ad89d320 | |||
23e7cbd1f1 |
@ -26,6 +26,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
|
||||||
@ -33,24 +34,39 @@ snyk:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- 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
|
# 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:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install lts
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -62,6 +78,7 @@ testLTS:
|
|||||||
testSTABLE:
|
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
|
||||||
@ -118,6 +135,7 @@ pages:
|
|||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci command npm install -g typedoc typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
tags:
|
tags:
|
||||||
@ -130,13 +148,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: {}
|
42
README.md
42
README.md
@ -1,24 +1,19 @@
|
|||||||
# 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://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
## Usage
|
## 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
|
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 +46,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.html)
|
||||||
|
|
||||||
[](https://push.rocks)
|
[](https://maintainedby.lossless.com)
|
||||||
|
16
dist/index.d.ts
vendored
16
dist/index.d.ts
vendored
@ -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
39
dist/index.js
vendored
@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QixJQUFJLE1BQU0sR0FBRyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUE7QUFFOUI7SUFHRT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Q0FBQSJ9
|
|
15
npmextra.json
Normal file
15
npmextra.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1280
package-lock.json
generated
1280
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartjson",
|
"name": "@pushrocks/smartjson",
|
||||||
"version": "2.0.1",
|
"version": "3.0.3",
|
||||||
"private": true,
|
"private": false,
|
||||||
"description": "typed json handlers",
|
"description": "typed json handlers",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tsrun test/test.ts)",
|
"test": "(tstest test/)",
|
||||||
"build": "(npmts)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -20,10 +20,15 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartjson#README",
|
"homepage": "https://gitlab.com/pushrocks/smartjson#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsrun": "^1.1.9",
|
"@gitzone/tsbuild": "^2.1.11",
|
||||||
"@pushrocks/tapbundle": "^3.0.1"
|
"@gitzone/tsrun": "^1.2.6",
|
||||||
|
"@gitzone/tstest": "^1.0.20",
|
||||||
|
"@pushrocks/tapbundle": "^3.0.9",
|
||||||
|
"@types/node": "^12.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"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 "../dist/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();
|
||||||
|
21
ts/index.ts
21
ts/index.ts
@ -1,15 +1,28 @@
|
|||||||
let lodash = require('lodash');
|
import * as plugins from './smartjson.plugins';
|
||||||
|
|
||||||
|
export class Smartjson {
|
||||||
|
// ======
|
||||||
|
// STATIC
|
||||||
|
// ======
|
||||||
|
static parse = JSON.parse;
|
||||||
|
|
||||||
|
static stringify = (objArg: any, optionsArg: plugins.stableJson.Options) => {
|
||||||
|
return plugins.stableJson(objArg, optionsArg)
|
||||||
|
};
|
||||||
|
|
||||||
|
// ========
|
||||||
|
// INSTANCE
|
||||||
|
// ========
|
||||||
|
|
||||||
export class Foldable {
|
|
||||||
saveableProperties: string[];
|
saveableProperties: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* folds a class into an object
|
* folds a class into an object
|
||||||
*/
|
*/
|
||||||
foldToObject() {
|
foldToObject() {
|
||||||
let newFoldedObject = {};
|
let newFoldedObject: {[key: string]: any} = {};
|
||||||
for (let keyName of this.saveableProperties) {
|
for (let keyName of this.saveableProperties) {
|
||||||
newFoldedObject[keyName] = lodash.cloneDeep(this[keyName]);
|
newFoldedObject[keyName] = plugins.lodash.cloneDeep(this[keyName]);
|
||||||
}
|
}
|
||||||
return newFoldedObject;
|
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 stableJson from 'fast-json-stable-stringify';
|
||||||
|
|
||||||
|
export {
|
||||||
|
lodash,
|
||||||
|
stableJson
|
||||||
|
}
|
@ -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