diff --git a/.gitignore b/.gitignore
index 00f6d3c..30f2690 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,52 @@
+# -*- mode: gitignore; -*-
+*~
+\#*\#
+/.emacs.desktop
+/.emacs.desktop.lock
+*.elc
+auto-save-list
+tramp
+.\#*
+
+# Org-mode
+.org-id-locations
+*_archive
+
+# flymake-mode
+*_flymake.*
+
+# eshell files
+/eshell/history
+/eshell/lastdir
+
+# elpa packages
+/elpa/
+
+# reftex files
+*.rel
+
+# AUCTeX auto folder
+/auto/
+
+# cask packages
+.cask/
+dist/
+
+# Flycheck
+flycheck_*.el
+
+# server auth directory
+/server/
+
+# projectiles files
+.projectile
+
+# directory configuration
+.dir-locals.el
+
+# The rest...
node_modules
dist/
*log
-.DS_Store
\ No newline at end of file
+.DS_Store
+coverage
diff --git a/.travis.yml b/.travis.yml
index 2c59434..c23bf9f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,8 +2,7 @@ language: node_js
install:
- yarn
- - yarn build:source
- - yarn build:docs
+ - yarn build
jobs:
include:
@@ -14,6 +13,7 @@ jobs:
script:
- yarn lint
- yarn test
+ - yarn test:dist
- stage: benchmark
node_js:
- "6"
@@ -28,6 +28,6 @@ jobs:
provider: script
skip_cleanup: true
script:
- - npm publish
+ - ./scripts/release
on:
tags: true
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 288f92c..39f38de 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Re-factored code to typescript.
- use `isPointer` internally now.
- Now exports an optimized `npm pack` with minimal file system foot-print.
+- Refactor `typings.d.ts` to `./types/index.ts`, we now compile and package our types.
+- Improved package scripts, now cleaner and more verbose.
+- Simplify package scripts without losing any functionality.
### Remove
- Object manipulation functionality has been dropped from JST (the `merge`,
@@ -30,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `dereference` circular schema dereferencing.
- fixed linting
- `lodash` imports, build size reduced.
+- benchmark messages returning out of sync with test run.
## [1.0.0] - 2017-06-25
diff --git a/benchmarks/benchmark.ts b/benchmarks/benchmark.ts
deleted file mode 100644
index d7ca24d..0000000
--- a/benchmarks/benchmark.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-import { Suite } from 'benchmark';
-import * as chalk from 'chalk';
-
-type Test = {
- id: string,
- deferred: boolean,
- exec: any,
-};
-
-const benchmark = (title: string, description: string, tests: Test[]) => {
- const suite = new Suite();
- const h1 = chalk.bgBlack.white;
- const h2 = chalk.white;
-
- tests.forEach((t) => {
- if (!t.deferred) {
- suite.add(t.id, t.exec);
- } else {
- suite.add(t.id, {
- defer: true,
- fn: function(deferred) {
- t.exec(deferred);
- }
- });
- }
- });
-
- suite.on('cycle', function(event) {
- console.log(String(event.target));
- }).on('complete', function() {
- const fastest = this.filter('fastest').map('name');
- console.log('\n', chalk.white(`Fastest: ${chalk.green(fastest)}`), '\n');
- });
-
- console.log(h1('\n', `Benchmark: ${title}`), '\n');
- console.log(h2(description), '\n', '\n', chalk.blue.bold('-------'), '\n');
-
- return suite.run({
- async: false,
- });
-};
-
-export default benchmark;
diff --git a/benchmarks/dereference-address-schema.benchmark.ts b/benchmarks/dereference-address-schema.benchmark.ts
deleted file mode 100755
index 2dfcdfe..0000000
--- a/benchmarks/dereference-address-schema.benchmark.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import * as derefSync from 'json-schema-deref-sync';
-import { dereference } from './../dist/index';
-import resolve from './../tests/mockResolve';
-import benchmark from './benchmark';
-
-const title = 'jst/dereference comparision: http://footown.com/generic/address#';
-const description =
- 'This benchmark tests the performance of the jst/dereference function using ' +
- 'a basic schema of our own invention and a variety of other similar open source ' +
- 'tools.';
-const tests = [
- {
- id: 'jst/dereference',
- deferred: false,
- exec: () => {
- dereference(resolve('http://footown.com/generic/address#'), resolve);
- },
- },
- {
- id: 'json-schema-deref-sync',
- deferred: false,
- exec: () => {
- derefSync(resolve('http://footown.com/generic/address#'));
- }
- }
-];
-
-benchmark(title, description, tests);
diff --git a/benchmarks/dereference-petstore-swagger.benchmark.ts b/benchmarks/dereference-petstore-swagger.benchmark.ts
deleted file mode 100755
index 15532bb..0000000
--- a/benchmarks/dereference-petstore-swagger.benchmark.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import * as derefSync from 'json-schema-deref-sync';
-import * as $RefParser from 'json-schema-ref-parser';
-import { dereference } from './../dist/index';
-import resolve from './../tests/mockResolve';
-import benchmark from './benchmark';
-
-const title = 'jst/dereference comparision - petstore.swagger.json';
-const description =
- 'This benchmark tests the performance of the jst/dereference function using ' +
- 'the demo Petstore API swagger from the open api homepage. This is a medium ' +
- 'sized json payload.';
-const refParser = new $RefParser();
-const tests = [
- {
- id: 'jst/dereference',
- deferred: false,
- exec: () => {
- dereference(require('./../resources/petstore.swagger.json'), resolve)
- },
- },
- {
- id: 'json-schema-deref-sync',
- deferred: false,
- exec: () => {
- derefSync(require('./../resources/petstore.swagger.json'));
- }
- },
- {
- id: 'json-schmea-ref-parser',
- deferred: true,
- exec: (defer) => {
- refParser.dereference(
- require('./../resources/petstore.swagger.json'),
- (err, x) => {
- defer.resolve();
- }
- );
- },
- },
-];
-
-benchmark(title, description, tests);
diff --git a/benchmarks/dereference-temando-swagger.benchmark.ts b/benchmarks/dereference-temando-swagger.benchmark.ts
deleted file mode 100755
index bb7da5f..0000000
--- a/benchmarks/dereference-temando-swagger.benchmark.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import * as derefSync from 'json-schema-deref-sync';
-import * as $RefParser from 'json-schema-ref-parser';
-import { dereference } from './../dist/index';
-import resolve from './../tests/mockResolve';
-import benchmark from './benchmark';
-
-const title = 'jst/dereference comparision - temando.swagger.json';
-const description =
- 'This benchmark tests the performance of the jst/dereference function using ' +
- 'the Temando Phoenix API swagger payload. This is a large json payload.';
-const refParser = new $RefParser();
-const tests = [
- {
- id: 'jst/dereference',
- deferred: false,
- exec: () => {
- dereference(require('./../resources/temando.swagger.json'), resolve)
- },
- },
- {
- id: 'json-schema-deref-sync',
- deferred: false,
- exec: () => {
- derefSync(require('./../resources/temando.swagger.json'));
- }
- },
- {
- id: 'json-schmea-ref-parser',
- deferred: true,
- exec: (defer) => {
- refParser.dereference(
- require('./../resources/temando.swagger.json'),
- (err, x) => {
- defer.resolve();
- }
- );
- },
- },
-];
-
-benchmark(title, description, tests);
diff --git a/benchmarks/index.benchmark.ts b/benchmarks/index.benchmark.ts
deleted file mode 100644
index 1103bbc..0000000
--- a/benchmarks/index.benchmark.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-require('./traversal-shallow-benchmark');
-require('./dereference-address-schema.benchmark');
-require('./dereference-petstore-swagger.benchmark');
-require('./dereference-temando-swagger.benchmark');
diff --git a/docs/CNAME b/docs/CNAME
index df3e90d..63c891a 100644
--- a/docs/CNAME
+++ b/docs/CNAME
@@ -1 +1 @@
-www.jwije.com
\ No newline at end of file
+www.jwije.com
diff --git a/docs/dereference.html b/docs/dereference.html
index ed3c05d..7cf98cd 100644
--- a/docs/dereference.html
+++ b/docs/dereference.html
@@ -56,13 +56,6 @@
Table of Contents
-
-
-
- typings.d.ts
-
-
-
@@ -88,7 +81,7 @@ Usage
Arguments
subject: Object|number|string|boolean|null
A json value.
-resolve: Jst.Resolver
A function to resolve a schema by its id.
+resolve:
Resolver` A function to resolve a schema by its id.
Returns
@@ -105,7 +98,8 @@ Dependencies
import * as forIn from 'lodash.forin' ;
import * as isObject from 'lodash.isobject' ;
import * as merge from 'lodash.merge' ;
-import { get , isPointer, set } from './index' ;
+import { get , isPointer, set } from './index' ;
+import { Dereferencer, Resolver } from './types' ;
@@ -131,7 +125,7 @@ Implementation
const isHttp: RegExp = /^http/ ;
const isRemoteRef = (ref: string ): boolean => isHttp.test(ref);
-export const dereference: Jst.dereference = (root, resolver ) => {
+export const dereference: Dereferencer = (root, resolver ) => {
@@ -160,7 +154,7 @@ JSON In, JSON Out
}
const circularRefs = {};
- const walk = (schema: any , resolve: Jst.resolve = null , path: string = '#' ): any => {
+ const walk = (schema: any , resolve: Resolver = null , path: string = '#' ): any => {
diff --git a/docs/get.html b/docs/get.html
index 8357b98..cdf1418 100644
--- a/docs/get.html
+++ b/docs/get.html
@@ -56,13 +56,6 @@ Table of Contents
-
-
-
- typings.d.ts
-
-
-
@@ -98,7 +91,8 @@ Dependencies
import * as has from 'lodash.has' ;
-import { isPointer } from './isPointer' ;
+import { isPointer } from './isPointer' ;
+import { GetPointer } from './types' ;
@@ -111,7 +105,7 @@ Implementation
typings.d.ts .
- export const get : Jst.getPointer = (schema, pointer ) => {
+ export const get : GetPointer = (schema, pointer ) => {
diff --git a/docs/index.html b/docs/index.html
index 0337693..ffdc761 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -59,13 +59,6 @@ Table of Contents
-
-
-
- typings.d.ts
-
-
-
diff --git a/docs/isPointer.html b/docs/isPointer.html
index 6287c39..2836e0b 100644
--- a/docs/isPointer.html
+++ b/docs/isPointer.html
@@ -56,13 +56,6 @@ Table of Contents
-
-
-
- typings.d.ts
-
-
-
@@ -70,10 +63,47 @@ Table of Contents
- A JSON pointer
must begin with the symbols ‘#’, ‘/‘ or be an empty string ‘’.
+ The isPointer
function determines if its argument is a valid json pointer
+or not returning a boolean indicating the result of the operation.
+
+
+
+
+ Usage
- export const isPointer = (input: string ): boolean => {
+
+
+ import { isPointer } from '@jdw/jst' ;
+
+isPointer('#/foo' );
+isPointer({})
+
+
+
+
+
+ Dependencies
+
+
+
+import { IsPointer } from './types' ;
+
+
+
+ Implementation
+
+
+
+export const isPointer: IsPointer = (input ) => {
+
+
+
+ A JSON pointer
must begin with the symbols ‘#’, ‘/‘ or be an empty string
+‘’.
+
+
+
if (typeof input !== 'string' ) {
return false ;
}
@@ -84,9 +114,14 @@ Table of Contents
if (/^#|^\// .test(input)) {
return true ;
- }
+ }
+
+
+
+ If it is not one of these values then input
is not a json pointer.
- return false ;
+
+
diff --git a/docs/set.html b/docs/set.html
index 4fd5bef..d420ca2 100644
--- a/docs/set.html
+++ b/docs/set.html
@@ -56,13 +56,6 @@ Table of Contents
-
-
-
- typings.d.ts
-
-
-
@@ -74,8 +67,9 @@ Table of Contents
import * as has from 'lodash.has' ;
import { isPointer } from './isPointer' ;
+import { SetPointer } from './types' ;
-export const set : Jst.setPointer = (obj, pointer, value ) => {
+export const set : SetPointer = (obj, pointer, value ) => {
diff --git a/docs/typings.d.html b/docs/typings.d.html
deleted file mode 100644
index 29d9938..0000000
--- a/docs/typings.d.html
+++ /dev/null
@@ -1,125 +0,0 @@
-
-
-
-
- typings.d.ts
-
-
-
-
-
-
-
-
-
-
-
-
-
JST Type Definitions
-
-
-
-
-
JST is a library for working with JSON Schema. It aims to be both simple and
-performant. We begin by covering JST internal data-structures and interfaces.
-
-
-
-
-
-
-
Interfaces
-
-
-
-
-
A Resolver function takes a schema ID as its argument and looks it
-up, returning them schema as an Object
if found or undefined
if not.
-
-
-
export type resolve = (schemaId: string ) => Object | undefined ;
-
-
-
-
A Dereferencer function takes a schema
and a resolver
function
-and then dereferences schema
in accordance with the IETF JSON
-Reference Draft v3
-Specification .
-
-
-
export type dereference =
- (schema: Object | Array <any >, resolver: resolve ) => Object | Array <any >;
-
-
-
-
A Getter function dereferences a JSON pointer in accordance with the
-IETF RFC6901 specification
-returning its value if path
is found in schema
or throw an error
-otherwise.
-
-
-
export type getPointer = (schema: Object , path: string ) => any ;
- export type setPointer = (schema: Object , path: string , value: any ) => void ;
-}
-
-
-
h
-
-
-
-
diff --git a/jest.config.js b/jest.config.js
index da091f8..09c9fff 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -1,10 +1,22 @@
module.exports = {
- verbose: true,
- transform: { '.(ts|tsx)': '/node_modules/ts-jest/preprocessor.js' },
- moduleFileExtensions: [ 'ts', 'tsx', 'js'],
- testMatch: ["**/*.test.ts"],
- testPathIgnorePatterns: [
- '/node_modules/',
- 'd.ts',
+ "verbose": true,
+ "transform": {
+ ".(ts|tsx)": "/node_modules/ts-jest/preprocessor.js"
+ },
+ "testMatch": [
+ "**/*.(spec|test).(t|j)s?(x)"
+ ],
+ "testEnvironment": "node",
+ "moduleFileExtensions": [
+ "ts",
+ "tsx",
+ "js"
+ ],
+ "coverageReporters": ['text', 'text-summary'],
+ "coverageThreshold": {
+ "global": { statements: 76, lines: 80, functions: 72 }
+ },
+ "testPathIgnorePatterns": [
+ "/node_modules/"
]
};
diff --git a/package.json b/package.json
index 57afa8f..6a71252 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@jdw/jst",
- "version": "2.0.0-beta.9",
+ "version": "2.0.0-beta.13",
"engines": {
"node": ">=4"
},
@@ -13,16 +13,16 @@
"contributors": [
"Brendan Abbott "
],
- "main": "dist/index.js",
+ "main": "index.js",
"scripts": {
"benchmark": "./scripts/benchmark",
- "build": "npm run build:source && npm run build:docs",
- "build:source": "./scripts/package",
- "build:docs": "docco --layout linear src/*.ts",
- "clean": "rm -rf dist",
+ "build": "./scripts/build",
"lint": "tslint -p tsconfig.json --type-check",
- "test": "jest --verbose",
- "test:watch": "yarn run test -- -o --watch"
+ "release": "./scripts/release",
+ "test": "jest src --verbose --coverage",
+ "test:dist": "jest dist --verbose",
+ "test:watch": "yarn run test -- -o --watch",
+ "trash": "rm -rf dist docs coverage"
},
"repository": {
"type": "git",
@@ -51,12 +51,14 @@
"ts-node": "^3.1.0",
"tslint": "^5.4.3",
"tslint-config-temando": "^1.1.4",
+ "tslint-strict-null-checks": "^1.0.0",
"typescript": "^2.3.3"
},
"dependencies": {
"lodash.forin": "^4.4.0",
"lodash.has": "^4.5.2",
"lodash.isobject": "^3.0.2",
- "lodash.merge": "^4.6.0"
+ "lodash.merge": "^4.6.0",
+ "self": "^1.0.0"
}
}
diff --git a/scripts/benchmark b/scripts/benchmark
index 7553f07..4aab282 100755
--- a/scripts/benchmark
+++ b/scripts/benchmark
@@ -1,4 +1,12 @@
#!/bin/bash
-node_modules/.bin/ts-node benchmarks/index.benchmark.ts
+# This script runs jst's internal benchmarks.
+. ./scripts/constants
+
+printf "${BLUE}@jdw/jst benchmarks${NC}\n\n"
+sleep 1
+
+for file in src/__benchmarks__/*benchmark.ts; do
+ yarn ts-node "${file}" # evaluate entry point
+done
diff --git a/scripts/build b/scripts/build
new file mode 100755
index 0000000..75afd12
--- /dev/null
+++ b/scripts/build
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# This script builds the jst package.
+
+. ./scripts/constants
+
+printf "${BLUE}@jdw/jst build script${NC}\n\n"
+sleep 1
+
+## build the package
+
+printf "\n${CYAN}COMPILE${NC}\n"
+
+
+mkdir -p ./dist/__tests__/fixture # create directory structure
+yarn trash # remove build artifacts
+yarn tsc # compile source code
+cp -rv ./src/__tests__/fixture ./dist/__tests__ # copy test fixture
+yarn docco --layout linear src/*.ts # compile documentation
+touch ./docs/CNAME \
+ && echo www.jwije.com > ./docs/CNAME # add CNAME to docs output
+## copy copy distributable material
+printf "\n${CYAN}COPY ARTIFACTS${NC}\n"
+
+declare -a filemap
+
+filemap=( "./README.md"
+ "./LICENSE.md"
+ "./CHANGELOG.md"
+ "./docs"
+ "./package.json" )
+
+for file in "${!filemap[@]}"; do
+ cp -rv "${filemap[$file]}" ./dist/
+done
+
+
+
+
+
+
+
+
+
diff --git a/scripts/constants b/scripts/constants
new file mode 100755
index 0000000..c4caaaa
--- /dev/null
+++ b/scripts/constants
@@ -0,0 +1,4 @@
+## Constants
+export BLUE='\033[0;34m'
+export CYAN='\033[0;36m'
+export NC='\033[0m' # No Color
diff --git a/scripts/package b/scripts/package
deleted file mode 100755
index 2de4fda..0000000
--- a/scripts/package
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/bash
-
-# Clean
-rm -rf dist
-mkdir dist
-
-# Copy latent files into ./dist
-#cp * dist 2>&1 | grep -v 'omitting directory'
-#cp .* dist 2>&1 | grep -v 'omitting directory'
-
-# Build typescript
-yarn tsc
-
-# Copy latent files from source, recursively
-# cp -rp src/__tests__/schema dist/__tests__/schema
diff --git a/scripts/release b/scripts/release
new file mode 100755
index 0000000..d5afacd
--- /dev/null
+++ b/scripts/release
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+# This script is used to release the package
+
+. ./scripts/constants
+
+printf "${BLUE}@jdw/jst release script${NC}\n"
+sleep 1
+
+printf "\n${CYAN}PUBLISHING${NC}\n"
+cd dist
+npm publish
+
+
+
+
+
diff --git a/src/__benchmarks__/benchmark.ts b/src/__benchmarks__/benchmark.ts
new file mode 100644
index 0000000..5c97acb
--- /dev/null
+++ b/src/__benchmarks__/benchmark.ts
@@ -0,0 +1,40 @@
+import { Suite } from 'benchmark';
+
+// tslint:disable
+export interface ITest {
+ id: string;
+ deferred: boolean;
+ exec: any;
+}
+
+const benchmark = (title: string, description: string, tests: ITest[]) => {
+ const suite = new Suite();
+ tests.forEach((t) => {
+ if (!t.deferred) {
+ suite.add(t.id, t.exec);
+ } else {
+ suite.add(t.id, {
+ defer: true,
+ fn(deferred) {
+ t.exec(deferred);
+ },
+ });
+ }
+ });
+
+ suite.on('cycle', function(event) {
+ console.log(String(event.target));
+ }).on('complete', function() {
+ const fastest = this.filter('fastest').map('name');
+ console.log('\n', `Fastest: ${fastest}`, '\n');
+ });
+
+ console.log('\n', `Benchmark: ${title}`, '\n');
+ console.log(description, '\n', '\n', '-------', '\n');
+
+ return suite.run({
+ async: false,
+ });
+};
+
+export { benchmark };
diff --git a/src/__benchmarks__/dereference-address-schema.benchmark.ts b/src/__benchmarks__/dereference-address-schema.benchmark.ts
new file mode 100755
index 0000000..4cf9c8e
--- /dev/null
+++ b/src/__benchmarks__/dereference-address-schema.benchmark.ts
@@ -0,0 +1,28 @@
+import * as derefSync from 'json-schema-deref-sync';
+import { dereference } from './../index';
+import { resolve } from './../__tests__/lib/';
+import { benchmark } from './benchmark';
+
+const title = 'jst/dereference comparision: http://footown.com/generic/address#';
+const description =
+ 'This benchmark tests the performance of the jst/dereference function using ' +
+ 'a basic schema of our own invention and a variety of other similar open source ' +
+ 'tools.';
+const tests = [
+ {
+ id: 'jst/dereference',
+ deferred: false,
+ exec: () => {
+ dereference(resolve('http://footown.com/generic/address#'), resolve);
+ },
+ },
+ {
+ id: 'json-schema-deref-sync',
+ deferred: false,
+ exec: () => {
+ derefSync(resolve('http://footown.com/generic/address#'));
+ },
+ },
+];
+
+benchmark(title, description, tests);
diff --git a/src/__benchmarks__/dereference-petstore-swagger.benchmark.ts b/src/__benchmarks__/dereference-petstore-swagger.benchmark.ts
new file mode 100755
index 0000000..b211521
--- /dev/null
+++ b/src/__benchmarks__/dereference-petstore-swagger.benchmark.ts
@@ -0,0 +1,47 @@
+import * as derefSync from 'json-schema-deref-sync';
+import * as $RefParser from 'json-schema-ref-parser';
+import { dereference } from './../index';
+import { resolve } from './../__tests__/lib/';
+import { benchmark } from './benchmark';
+
+const title = 'jst/dereference comparision - petstore.swagger.json';
+const description =
+ 'This benchmark tests the performance of the jst/dereference function using ' +
+ 'the demo Petstore API swagger from the open api homepage. This is a medium ' +
+ 'sized json payload.';
+const refParser = new $RefParser();
+const tests = [
+ {
+ id: 'jst/dereference',
+ deferred: false,
+ exec: () => {
+ dereference(require('./../__tests__/fixture/petstore.swagger.json'), resolve);
+ },
+ },
+ {
+ id: 'json-schema-deref-sync',
+ deferred: false,
+ exec: () => {
+ derefSync(require('./../__tests__/fixture/petstore.swagger.json'));
+ },
+ },
+ {
+ id: 'json-schmea-ref-parser',
+ deferred: true,
+ exec: (defer) => {
+ refParser.dereference(
+ require('./../__tests__/fixture/petstore.swagger.json'),
+ (err, x) => {
+ if (err) {
+ throw err;
+ }
+ defer.resolve();
+ },
+ ).catch((reason) => {
+ defer.reject(reason);
+ });
+ },
+ },
+];
+
+benchmark(title, description, tests);
diff --git a/src/__benchmarks__/dereference-temando-swagger.benchmark.ts b/src/__benchmarks__/dereference-temando-swagger.benchmark.ts
new file mode 100755
index 0000000..87ce7bc
--- /dev/null
+++ b/src/__benchmarks__/dereference-temando-swagger.benchmark.ts
@@ -0,0 +1,46 @@
+import * as $RefParser from 'json-schema-ref-parser';
+import * as derefSync from 'json-schema-deref-sync';
+import { benchmark } from './benchmark';
+import { dereference } from './../index';
+import { resolve } from './../__tests__/lib/';
+
+const title = 'jst/dereference comparision - temando.swagger.json';
+const description =
+ 'This benchmark tests the performance of the jst/dereference function using ' +
+ 'the Temando Phoenix API swagger payload. This is a large json payload.';
+const refParser = new $RefParser();
+const tests = [
+ {
+ id: 'jst/dereference',
+ deferred: false,
+ exec: () => {
+ dereference(require('./../__tests__/fixture/temando.swagger.json'), resolve);
+ },
+ },
+ {
+ id: 'json-schema-deref-sync',
+ deferred: false,
+ exec: () => {
+ derefSync(require('./../__tests__/fixture/temando.swagger.json'));
+ },
+ },
+ {
+ id: 'json-schmea-ref-parser',
+ deferred: true,
+ exec: (defer) => {
+ refParser.dereference(
+ require('./../__tests__/fixture/temando.swagger.json'),
+ (err, x) => {
+ if (err) {
+ throw err;
+ }
+ defer.resolve();
+ },
+ ).catch((reason) => {
+ defer.reject(reason);
+ });
+ },
+ },
+];
+
+benchmark(title, description, tests);
diff --git a/benchmarks/traversal-shallow-benchmark.ts b/src/__benchmarks__/traversal-shallow.benchmark.ts
similarity index 90%
rename from benchmarks/traversal-shallow-benchmark.ts
rename to src/__benchmarks__/traversal-shallow.benchmark.ts
index 023d7b0..23887d2 100755
--- a/benchmarks/traversal-shallow-benchmark.ts
+++ b/src/__benchmarks__/traversal-shallow.benchmark.ts
@@ -1,7 +1,7 @@
import * as forIn from 'lodash.forin';
-import benchmark from './benchmark';
+import { benchmark } from './benchmark';
-const schema = require('./../resources/temando.swagger.json');
+const schema = require('./../__tests__/fixture/temando.swagger.json');
const title = 'jst/experimental: Basic object traversal';
const description =
'This benchmark tests various methods for iterating and walking an objects top level properties.';
diff --git a/tests/dereference.test.ts b/src/__tests__/dereference.test.ts
similarity index 81%
rename from tests/dereference.test.ts
rename to src/__tests__/dereference.test.ts
index 80d8139..d5292fc 100644
--- a/tests/dereference.test.ts
+++ b/src/__tests__/dereference.test.ts
@@ -1,10 +1,10 @@
import { expect } from 'chai';
-import { dereference } from './../src/index';
-import resolve from './mockResolve';
+import { dereference } from './../index';
+import { resolve } from './lib';
describe('dereference schema utility function', () => {
it('dereferences referenced schema correctly', () => {
- const ast = dereference(resolve('http://footown.com/generic/address#'), resolve);
+ const ast: any = dereference(resolve('http://footown.com/generic/address#'), resolve);
expect(ast.properties).to.have.property('addressLines');
expect(ast.properties).to.have.property('contact');
expect(ast.properties.contact).to.have.property('properties');
@@ -18,8 +18,7 @@ describe('dereference schema utility function', () => {
resolve('http://footown.com/generic/address#'),
resolve('http://footown.com/generic/address-override#'),
];
- const ast = dereference(schema, resolve);
-
+ const ast: any = dereference(schema, resolve);
expect(ast.properties).to.have.property('addressLines');
expect(ast.properties).to.have.property('country');
expect(ast.properties.country).to.have.property('enum');
@@ -33,7 +32,7 @@ describe('dereference schema utility function', () => {
it('can dereference circular schema references', () => {
const schema = resolve('http://footown.com/generic/edit-person+v1#');
- const ast = dereference(schema, resolve);
+ const ast: any = dereference(schema, resolve);
expect(ast).to.have.property('allOf');
expect(ast.allOf.length).to.eq(1);
@@ -42,43 +41,43 @@ describe('dereference schema utility function', () => {
it('dereferences null values correctly', () => {
const schema = resolve('http://footown.com/generic/edit-person+v1#');
- const ast = dereference(schema, resolve);
+ const ast: any = dereference(schema, resolve);
expect(ast.foo).to.eq(null);
});
it('dereferences circular references correctly', () => {
const schema = resolve('http://footown.com/generic/circular#');
- const ast = dereference(schema, resolve);
+ const ast: any = dereference(schema, resolve);
expect(ast).to.be.an('object');
});
it('dereferences conditional allOf references correctly', () => {
const schema = resolve('http://footown.com/generic/conditional#');
- const ast = dereference(schema, resolve);
+ const ast: any = dereference(schema, resolve);
expect(ast).to.be.an('object');
expect(ast.allOf[0]).deep.eq({
type: 'object',
properties: {
foobar: {
type: 'string',
- minLength: 1
- }
- }
+ minLength: 1,
+ },
+ },
});
expect(ast.allOf[1]).deep.eq({
type: 'object',
properties: {
barfoo: {
type: 'number',
- }
- }
+ },
+ },
});
});
it('can dereference referenced circular schema correctly', () => {
- const schema = require('./../resources/circular-referenced.schema.json');
+ const schema = require('./fixture/circular-referenced.schema.json');
- const ast = dereference(schema, resolve);
+ const ast: any = dereference(schema, resolve);
expect(ast).to.be.an('object');
expect(ast.properties.circular.properties.circle.id).to.eq('http://footown.com/generic/circular#');
diff --git a/resources/address+v1.schema.json b/src/__tests__/fixture/address+v1.schema.json
similarity index 100%
rename from resources/address+v1.schema.json
rename to src/__tests__/fixture/address+v1.schema.json
diff --git a/resources/address-override+v1.schema.json b/src/__tests__/fixture/address-override+v1.schema.json
similarity index 100%
rename from resources/address-override+v1.schema.json
rename to src/__tests__/fixture/address-override+v1.schema.json
diff --git a/resources/circular-referenced.schema.json b/src/__tests__/fixture/circular-referenced.schema.json
similarity index 100%
rename from resources/circular-referenced.schema.json
rename to src/__tests__/fixture/circular-referenced.schema.json
diff --git a/resources/circular.schema.json b/src/__tests__/fixture/circular.schema.json
similarity index 100%
rename from resources/circular.schema.json
rename to src/__tests__/fixture/circular.schema.json
diff --git a/resources/conditional.schema.json b/src/__tests__/fixture/conditional.schema.json
similarity index 100%
rename from resources/conditional.schema.json
rename to src/__tests__/fixture/conditional.schema.json
diff --git a/resources/credentials+v1.schema.json b/src/__tests__/fixture/credentials+v1.schema.json
similarity index 100%
rename from resources/credentials+v1.schema.json
rename to src/__tests__/fixture/credentials+v1.schema.json
diff --git a/resources/edit-person+v1.schema.json b/src/__tests__/fixture/edit-person+v1.schema.json
similarity index 100%
rename from resources/edit-person+v1.schema.json
rename to src/__tests__/fixture/edit-person+v1.schema.json
diff --git a/resources/person+v1.schema.json b/src/__tests__/fixture/person+v1.schema.json
similarity index 100%
rename from resources/person+v1.schema.json
rename to src/__tests__/fixture/person+v1.schema.json
diff --git a/resources/petstore.swagger.json b/src/__tests__/fixture/petstore.swagger.json
similarity index 100%
rename from resources/petstore.swagger.json
rename to src/__tests__/fixture/petstore.swagger.json
diff --git a/resources/profile+v1.schema.json b/src/__tests__/fixture/profile+v1.schema.json
similarity index 100%
rename from resources/profile+v1.schema.json
rename to src/__tests__/fixture/profile+v1.schema.json
diff --git a/resources/temando.swagger.json b/src/__tests__/fixture/temando.swagger.json
similarity index 100%
rename from resources/temando.swagger.json
rename to src/__tests__/fixture/temando.swagger.json
diff --git a/tests/get.test.ts b/src/__tests__/get.test.ts
similarity index 77%
rename from tests/get.test.ts
rename to src/__tests__/get.test.ts
index a9290bf..e971e29 100644
--- a/tests/get.test.ts
+++ b/src/__tests__/get.test.ts
@@ -1,22 +1,22 @@
import { expect } from 'chai';
-import { get } from './../src/index';
+import { get } from './../index';
describe('@jdw/jst/get', () => {
const fixture = {
- foo: {
+ 'foo': {
bar: 20,
},
'/': {
'~': 400,
- bar: {
- '~': 10
- }
+ 'bar': {
+ '~': 10,
+ },
},
- arr: [{
+ 'arr': [{
arr: [{
foo: 100,
- }]
- }, 30]
+ }],
+ }, 30],
};
it('should resolve valid JSON pointers', () => {
@@ -26,7 +26,7 @@ describe('@jdw/jst/get', () => {
['', fixture],
];
cases.forEach((t) => {
- expect(get(fixture, t[0])).to.eq(t[1]);
+ expect(get(fixture, t[0].toString())).to.eq(t[1]);
});
});
@@ -36,7 +36,7 @@ describe('@jdw/jst/get', () => {
['#/~1/bar/~0', 10],
];
cases.forEach((t) => {
- expect(get(fixture, t[0])).to.eq(t[1]);
+ expect(get(fixture, t[0].toString())).to.eq(t[1]);
});
});
@@ -46,7 +46,7 @@ describe('@jdw/jst/get', () => {
['#/arr/1', 30],
];
cases.forEach((t) => {
- expect(get(fixture, t[0])).to.eq(t[1]);
+ expect(get(fixture, t[0].toString())).to.eq(t[1]);
});
});
diff --git a/src/__tests__/isPointer.test.ts b/src/__tests__/isPointer.test.ts
new file mode 100644
index 0000000..67e9408
--- /dev/null
+++ b/src/__tests__/isPointer.test.ts
@@ -0,0 +1,21 @@
+import { expect } from 'chai';
+import { isPointer } from './../index';
+
+describe('@jdw/jst/isPointer', () => {
+ const cases = {
+ success: ['#', '/', '', '#/foo/bar/baz', '/bar/baz'],
+ failure: ['yolo', 123, {}, false, true, null, undefined], // '#adasd']
+ };
+
+ cases.success.forEach((testCase) => {
+ it(`can recognize ${JSON.stringify(testCase)} as a pointer`, () => {
+ expect(isPointer(testCase)).to.eq(true);
+ });
+ });
+
+ cases.failure.forEach((testCase) => {
+ it(`can recognize ${JSON.stringify(testCase)} is NOT a pointer`, () => {
+ expect(isPointer(testCase)).to.eq(false);
+ });
+ });
+});
diff --git a/src/__tests__/lib/Validator.ts b/src/__tests__/lib/Validator.ts
new file mode 100644
index 0000000..f7ca76b
--- /dev/null
+++ b/src/__tests__/lib/Validator.ts
@@ -0,0 +1,53 @@
+import * as Ajv from 'ajv';
+
+import * as address from './../fixture/address+v1.schema.json';
+import * as addressOverride from './../fixture/address-override+v1.schema.json';
+import * as circular from './../fixture/circular.schema.json';
+import * as conditional from './../fixture/conditional.schema.json';
+import * as credentials from './../fixture/credentials+v1.schema.json';
+import * as editPerson from './../fixture/edit-person+v1.schema.json';
+import * as person from './../fixture/person+v1.schema.json';
+import * as profile from './../fixture/profile+v1.schema.json';
+
+/**
+ * A validation helper for our test schema.
+ */
+export class Validator {
+ public schema: object[] = [];
+ private ajv;
+
+ constructor(config: object = {}) {
+ const schema = [
+ address,
+ addressOverride,
+ circular,
+ conditional,
+ credentials,
+ editPerson,
+ person,
+ profile,
+ ];
+ const cnf = {
+ extendRefs: true,
+ allErrors: true,
+ ...config,
+ };
+ this.ajv = new Ajv(cnf);
+ this.load(schema);
+ }
+
+ load(schema: object[]) {
+ schema.map((scm) => {
+ this.ajv.addSchema(scm);
+ this.schema.push(scm);
+ });
+
+ return this;
+ }
+
+ getSchema(id: string): object | undefined {
+ const lookup = this.ajv.getSchema(id);
+
+ return !lookup ? undefined : lookup.schema;
+ }
+}
diff --git a/src/__tests__/lib/index.ts b/src/__tests__/lib/index.ts
new file mode 100644
index 0000000..c3f99db
--- /dev/null
+++ b/src/__tests__/lib/index.ts
@@ -0,0 +1,7 @@
+import { Validator } from './Validator';
+import { resolve } from './resolve';
+
+export {
+ Validator,
+ resolve,
+};
diff --git a/src/__tests__/lib/resolve.ts b/src/__tests__/lib/resolve.ts
new file mode 100644
index 0000000..2155c6d
--- /dev/null
+++ b/src/__tests__/lib/resolve.ts
@@ -0,0 +1,19 @@
+import { Validator } from './index';
+
+const validator = new Validator();
+
+/**
+ * A resolve function must simply take a schema id as an argument and return
+ * that schema as an object literal or throw an error if it can't find it.
+ */
+const resolve = (id) => {
+ const result = validator.getSchema(id);
+
+ if (!result) {
+ throw new Error(`could not resolve schema with id: ${id}`);
+ }
+
+ return result;
+};
+
+export { resolve };
diff --git a/tests/set.test.ts b/src/__tests__/set.test.ts
similarity index 92%
rename from tests/set.test.ts
rename to src/__tests__/set.test.ts
index 379593b..57658af 100644
--- a/tests/set.test.ts
+++ b/src/__tests__/set.test.ts
@@ -1,12 +1,12 @@
import { expect } from 'chai';
-import { set } from './../src/index';
+import { set } from './../index';
describe('@jdw/jst/set', () => {
const fixture = {
array: [1, 2, null],
object: {
foo: null,
- array: [{ foo: null }, null]
+ array: [{ foo: null }, null],
},
foo: null,
};
diff --git a/src/dereference.ts b/src/dereference.ts
index c444406..3db973a 100644
--- a/src/dereference.ts
+++ b/src/dereference.ts
@@ -19,7 +19,7 @@
//
// **Arguments**
// - `subject: Object|number|string|boolean|null` A json value.
-// - `resolve: Jst.Resolver` A function to resolve a schema by its id.
+// - `resolve: `Resolver` A function to resolve a schema by its id.
//
// **Returns**
// - `any`: The dereferenced object.
@@ -33,7 +33,7 @@ import * as forIn from 'lodash.forin';
import * as isObject from 'lodash.isobject';
import * as merge from 'lodash.merge';
import { get, isPointer, set } from './index';
-
+import { Dereferencer, Resolver } from './types';
// ## Implementation
// Here begins the implementation of the `dereference` function. This being
@@ -51,7 +51,7 @@ import { get, isPointer, set } from './index';
const isHttp: RegExp = /^http/;
const isRemoteRef = (ref: string): boolean => isHttp.test(ref);
-export const dereference: Jst.dereference = (root, resolver) => {
+export const dereference: Dereferencer = (root, resolver) => {
// ### JSON In, JSON Out
//
// The [json specification](http://www.ietf.org/rfc/rfc4627.txt) section 2.1
@@ -68,7 +68,7 @@ export const dereference: Jst.dereference = (root, resolver) => {
}
const circularRefs = {};
- const walk = (schema: any, resolve: Jst.resolve = null, path: string = '#'): any => {
+ const walk = (schema: any, resolve: Resolver = null, path: string = '#'): any => {
// If schema is an array we dereference each schema and then merge them from
// right-to-left.
if (Array.isArray(schema)) {
@@ -85,11 +85,12 @@ export const dereference: Jst.dereference = (root, resolver) => {
.map((scm, index) => walk(scm, resolve, `${path}/${index}`))
.reduce((acc, scm) => merge(acc, scm), {});
- // If schema is not an array of json objects we expect a singlular json schema
- // be provided
+ // If schema is not an array of json objects we expect a singlular json schema
+ // be provided
} else if (isObject(schema)) {
const schemaId = schema.id || undefined;
let isCircular = false;
+
// traverse is an internal recursive function that we bind to this lexical
// scope in order to easily resolve to schema definitions whilst traversing
// an objects nested properties. This is primarily for efficiency concerns.
@@ -119,8 +120,8 @@ export const dereference: Jst.dereference = (root, resolver) => {
if (typeof value !== 'object' && key !== '$ref') {
resolution[key] = value;
- // If we have a schema reference we must fetch it, dereference it, then merge
- // it into the base schema object.
+ // If we have a schema reference we must fetch it, dereference it, then merge
+ // it into the base schema object.
} else if (key === '$ref') {
// We have two types of references - definitions which are defined
// within the current schema and external schema references which we
@@ -155,7 +156,7 @@ export const dereference: Jst.dereference = (root, resolver) => {
isCircular = true;
}
- // de-reference a json pointer
+ // de-reference a json pointer
} else if (isPointer(value)) {
reference = get(schema, value);
resolution = merge(
@@ -172,8 +173,8 @@ export const dereference: Jst.dereference = (root, resolver) => {
throw new ReferenceError(`could not find a reference to ${value}`);
}
- // Otherwise the value is an array or object and we need to traverse it
- // and dereference it's properties.
+ // Otherwise the value is an array or object and we need to traverse it
+ // and dereference it's properties.
} else {
resolution[key] = traverse(value, `${nodePath}/${key}`);
}
@@ -184,7 +185,7 @@ export const dereference: Jst.dereference = (root, resolver) => {
return traverse(schema, path);
- // if any other combination of arguments is provided we throw
+ // if any other combination of arguments is provided we throw
} else {
throw new TypeError(`expected first parameter to be object or array: ${schema}`);
}
diff --git a/src/get.ts b/src/get.ts
index 131918c..d2ce713 100644
--- a/src/get.ts
+++ b/src/get.ts
@@ -27,12 +27,13 @@
import * as has from 'lodash.has';
import { isPointer } from './isPointer';
+import { GetPointer } from './types';
// #### Implementation
// The `get` function implements the `Jst.Getter` signature as described in
// [typings.d.ts](typings.d.html).
-export const get: Jst.getPointer = (schema, pointer) => {
+export const get: GetPointer = (schema, pointer) => {
// A JSON `pointer` must begin with the symbols '#', '/' or be an empty
// string ''. So as a first step, we check that this assumption is true and
// bail if not.
@@ -70,8 +71,8 @@ export const get: Jst.getPointer = (schema, pointer) => {
}
reference = object[index];
- // Otherwise if `object` *is not* an Array we expect `object` to be of
- // type Object and that `token` references a valid path in `object`.
+ // Otherwise if `object` *is not* an Array we expect `object` to be of
+ // type Object and that `token` references a valid path in `object`.
} else {
if (!has(object, token)) {
throw new Error(
diff --git a/src/isPointer.ts b/src/isPointer.ts
index b926c7d..3f0b7ed 100644
--- a/src/isPointer.ts
+++ b/src/isPointer.ts
@@ -1,5 +1,25 @@
-// A JSON `pointer` must begin with the symbols '#', '/' or be an empty string ''.
-export const isPointer = (input: string): boolean => {
+// The `isPointer` function determines if its argument is a valid json pointer
+// or not returning a boolean indicating the result of the operation.
+
+// ## Usage
+
+// ```javascript
+// import { isPointer } from '@jdw/jst';
+//
+// isPointer('#/foo'); // true
+// isPointer({}) // false
+// ```
+
+// ## Dependencies
+
+import { IsPointer } from './types';
+
+// ## Implementation
+
+export const isPointer: IsPointer = (input) => {
+ // A JSON `pointer` must begin with the symbols '#', '/' or be an empty string
+ // ''.
+
if (typeof input !== 'string') {
return false;
}
@@ -11,6 +31,6 @@ export const isPointer = (input: string): boolean => {
if (/^#|^\//.test(input)) {
return true;
}
-
+ // If it is not one of these values then `input` is not a json pointer.
return false;
};
diff --git a/src/set.ts b/src/set.ts
index bb7996d..c0af7eb 100644
--- a/src/set.ts
+++ b/src/set.ts
@@ -1,7 +1,8 @@
import * as has from 'lodash.has';
import { isPointer } from './isPointer';
+import { SetPointer } from './types';
-export const set: Jst.setPointer = (obj, pointer, value) => {
+export const set: SetPointer = (obj, pointer, value) => {
// A JSON `pointer` must begin with the symbols '#', '/' or be an empty
// string ''. So as a first step, we check that this assumption is true and
@@ -45,8 +46,8 @@ export const set: Jst.setPointer = (obj, pointer, value) => {
}
ref = ref[i];
- // Otherwise if `object` *is not* an Array we expect `object` to be of
- // type Object and that `token` references a valid path in `object`.
+ // Otherwise if `object` *is not* an Array we expect `object` to be of
+ // type Object and that `token` references a valid path in `object`.
} else {
if (!has(ref, token)) {
throw new Error(
diff --git a/src/types/index.ts b/src/types/index.ts
new file mode 100644
index 0000000..cfe8ab1
--- /dev/null
+++ b/src/types/index.ts
@@ -0,0 +1,25 @@
+// ## JST Type Definitions
+
+// JST is a library for working with JSON Schema. It aims to be both simple and
+// performant. We begin by covering JST internal data-structures and interfaces.
+
+// ### Interfaces
+
+// A **Resolver** function takes a schema ID as its argument and looks it
+// up, returning them schema as an `Object` if found or `undefined` if not.
+export type Resolver = (schemaId: string) => object | undefined;
+
+// A **Dereferencer** function takes a `schema` and a `resolver` function
+// and then dereferences `schema` in accordance with the [IETF JSON
+// Reference Draft v3
+// Specification](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03).
+export type Dereferencer =
+ (schema: object | any[], resolve: Resolver) => object | any[];
+
+// A **Getter** function dereferences a JSON pointer in accordance with the
+// [IETF RFC6901 specification](https://tools.ietf.org/html/rfc6901)
+// returning its value if `path` is found in `schema` or throw an error
+// otherwise.
+export type GetPointer = (schema: object, path: string) => any;
+export type SetPointer = (schema: object, path: string, value: any) => void;
+export type IsPointer = (input: any) => boolean;
diff --git a/src/types/json.d.ts b/src/types/json.d.ts
new file mode 100644
index 0000000..f3f5966
--- /dev/null
+++ b/src/types/json.d.ts
@@ -0,0 +1,4 @@
+declare module "*.json" {
+ const value: any;
+ export default value;
+}
diff --git a/src/typings.d.ts b/src/typings.d.ts
deleted file mode 100644
index 9ec293d..0000000
--- a/src/typings.d.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-// ## JST Type Definitions
-
-// JST is a library for working with JSON Schema. It aims to be both simple and
-// performant. We begin by covering JST internal data-structures and interfaces.
-declare module Jst {
- // ### Interfaces
-
- // A **Resolver** function takes a schema ID as its argument and looks it
- // up, returning them schema as an `Object` if found or `undefined` if not.
- export type resolve = (schemaId: string) => Object | undefined;
-
- // A **Dereferencer** function takes a `schema` and a `resolver` function
- // and then dereferences `schema` in accordance with the [IETF JSON
- // Reference Draft v3
- // Specification](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03).
- export type dereference =
- (schema: Object | Array, resolver: resolve) => Object | Array;
-
- // A **Getter** function dereferences a JSON pointer in accordance with the
- // [IETF RFC6901 specification](https://tools.ietf.org/html/rfc6901)
- // returning its value if `path` is found in `schema` or throw an error
- // otherwise.
- export type getPointer = (schema: Object, path: string) => any;
- export type setPointer = (schema: Object, path: string, value: any) => void;
-}
diff --git a/tests/MockValidator.ts b/tests/MockValidator.ts
deleted file mode 100644
index ba94f8a..0000000
--- a/tests/MockValidator.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-import * as Ajv from 'ajv';
-
-const address = require('./../resources/address+v1.schema.json');
-const addressOverride = require('./../resources/address-override+v1.schema.json');
-const circular = require('./../resources/circular.schema.json');
-const conditional = require('./../resources/conditional.schema.json');
-const credentials = require('./../resources/credentials+v1.schema.json');
-const editPerson = require('./../resources/edit-person+v1.schema.json');
-const person = require('./../resources/person+v1.schema.json');
-const profile = require('./../resources/profile+v1.schema.json');
-
-/**
- * A validation helper for our test schema.
- */
-export default class MockValidator {
- public schema: Array = [];
- private ajv;
-
- constructor(config: Object = {}) {
- const schema = [
- address,
- addressOverride,
- circular,
- conditional,
- credentials,
- editPerson,
- person,
- profile,
- ];
- const cnf = {
- extendRefs: true,
- allErrors: true,
- ...config
- };
- this.ajv = new Ajv(cnf);
- this.load(schema);
- }
-
- load(schema: Array) {
- schema.map((scm) => {
- this.ajv.addSchema(scm)
- this.schema.push(scm);
- });
-
- return this;
- }
-
- getSchema(id: string): Object | undefined {
- const lookup = this.ajv.getSchema(id);
-
- return !lookup ? undefined : lookup.schema;
- }
-}
diff --git a/tests/isPointer.test.ts b/tests/isPointer.test.ts
deleted file mode 100644
index 5cbe7e2..0000000
--- a/tests/isPointer.test.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { expect } from 'chai';
-import { isPointer } from './../src/index';
-
-describe('@jdw/jst/isPointer', () => {
- const cases = {
- success: ['#', '/', '', '#/foo/bar/baz', '/bar/baz'],
- failure: ['yolo', 123, {}, false, true, null, undefined], // '#adasd']
- };
-
- cases.success.forEach((testCase) => {
- it(`can recognize ${JSON.stringify(testCase)} as a pointer`, () => {
- expect(isPointer(testCase)).to.eq(true);
- });
- });
-
- cases.failure.forEach((testCase) => {
- it(`can recognize ${JSON.stringify(testCase)} is NOT a pointer`, () => {
- expect(isPointer(testCase)).to.eq(false);
- });
- });
-});
diff --git a/tests/mockResolve.ts b/tests/mockResolve.ts
deleted file mode 100644
index 47a639a..0000000
--- a/tests/mockResolve.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import Validator from './MockValidator';
-
-const validator = new Validator();
-
-/**
- * A resolve function must simply take a schema id as an argument and return
- * that schema as an object literal or throw an error if it can't find it.
- */
-const mockResolve = (id) => {
- const result = validator.getSchema(id);
-
- if (!result) throw new Error(`could not resolve schema with id: ${id}`);
-
- return result;
-};
-
-export default mockResolve;
diff --git a/tsconfig.json b/tsconfig.json
index 79b487c..efabd5f 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -6,6 +6,7 @@
"outDir": "./dist",
"declaration": true,
"sourceMap": true,
+ "listFiles": true,
"allowSyntheticDefaultImports": false,
"noUnusedLocals": true,
"lib": [
diff --git a/tslint.json b/tslint.json
index 7835ed1..ad5f32b 100644
--- a/tslint.json
+++ b/tslint.json
@@ -2,7 +2,15 @@
"extends":[
"tslint-config-temando"
],
+ "rulesDirectory": [
+ "node_modules/tslint-strict-null-checks/rules"
+ ],
"rules": {
- "no-console": [false]
+ "space-before-function-paren": false,
+ "no-console": [false],
+ "strict-type-predicates": false,
+ "no-uninitialized": true,
+ "no-var-requires": false,
+ "ordered-imports": false
}
}
diff --git a/yarn.lock b/yarn.lock
index 4454dac..0637faa 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2202,6 +2202,10 @@ sax@^1.2.1:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
+self@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/self/-/self-1.0.0.tgz#6355f6f6502507cfc788811e0cc1c6d6269e16b8"
+
"semver@2 || 3 || 4 || 5", semver@^5.3.0:
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"
@@ -2496,6 +2500,10 @@ tslint-eslint-rules@^4.0.0, tslint-eslint-rules@^4.1.1:
tslib "^1.0.0"
tsutils "^1.4.0"
+tslint-strict-null-checks@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/tslint-strict-null-checks/-/tslint-strict-null-checks-1.0.0.tgz#6563ba646abe76236ad4266657de48aa49ff8842"
+
tslint@^5.4.3:
version "5.6.0"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.6.0.tgz#088aa6c6026623338650b2900828ab3edf59f6cf"