Skip to content

Commit dd1b497

Browse files
committed
feat: support ES modules, use c8 instead of nyc
BREAKING CHANGE: ESM support is required
1 parent c26a60a commit dd1b497

32 files changed

+479
-490
lines changed

package.json

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "arrest",
33
"version": "0.0.0-development",
44
"description": "OpenAPI v3 compliant REST framework for Node.js, with support for MongoDB and JSON-Schema",
5+
"type": "module",
56
"main": "dist/index.js",
67
"typings": "dist/index.d.ts",
78
"directories": {
@@ -19,10 +20,9 @@
1920
"build:tests": "tsc -p test",
2021
"clean": "rimraf dist coverage .nyc_output test-results && find ./test/ts -type f -name '*.js' -delete && rimraf test/tsconfig.tsbuildinfo",
2122
"clean:all": "npm run clean && rimraf node_modules",
22-
"cover": "nyc --reporter=lcov --reporter=text npm t",
23+
"cover": "c8 --reporter=lcov --reporter=text npm t",
2324
"report-coverage": "cat ./coverage/lcov.info | coveralls",
24-
"commit": "git-cz",
25-
"check-coverage": "nyc check-coverage",
25+
"check-coverage": "c8 check-coverage",
2626
"watch:test": "npm t -- -w",
2727
"test": "npm run build && tsc -p test && mocha --exit --no-timeouts --recursive --reporter mochawesome --reporter-options reportDir=test-results test/**/*.test.js",
2828
"test:debug": "find ./test/ts -type f -name '*.js' -delete && npm run build && npm run build:tests && mocha --exit --no-timeouts --inspect-brk --recursive test/**/*.test.js",
@@ -77,74 +77,57 @@
7777
},
7878
"homepage": "https://github.com/vivocha/arrest",
7979
"devDependencies": {
80-
"@commitlint/cli": "^16.2.3",
81-
"@commitlint/config-conventional": "^16.2.1",
8280
"@types/body-parser": "^1.19.2",
83-
"@types/chai": "^4.3.0",
81+
"@types/chai": "^4.3.1",
8482
"@types/chai-as-promised": "^7.1.5",
8583
"@types/chai-spies": "^1.0.3",
8684
"@types/debug": "^4.1.7",
8785
"@types/express": "^4.17.13",
88-
"@types/lodash": "^4.14.181",
89-
"@types/luxon": "^2.3.1",
90-
"@types/mocha": "^9.1.0",
86+
"@types/lodash": "^4.14.182",
87+
"@types/luxon": "^2.3.2",
88+
"@types/mocha": "^9.1.1",
9189
"@types/needle": "^2.5.3",
9290
"@types/node": "^16.11.1",
9391
"@types/semver": "^7.3.9",
92+
"c8": "^7.11.3",
9493
"chai": "^4.3.6",
9594
"chai-as-promised": "^7.1.1",
9695
"chai-spies": "^1.0.0",
97-
"commitizen": "^4.2.4",
98-
"commitlint": "^16.2.3",
9996
"coveralls": "^3.1.1",
100-
"cz-conventional-changelog": "^3.3.0",
101-
"husky": "^7.0.4",
102-
"mocha": "^9.2.2",
97+
"mocha": "^10.0.0",
10398
"mochawesome": "^7.1.3",
10499
"mongodoki": "^5.0.0",
105-
"nyc": "^15.1.0",
106100
"pem": "^1.14.6",
107101
"rimraf": "^3.0.2",
108102
"semantic-release": "^19.0.2",
109-
"supertest": "^6.2.2",
110-
"typescript": "^4.6.3"
103+
"supertest": "^6.2.3",
104+
"typescript": "^4.7.3"
111105
},
112106
"dependencies": {
113-
"@casl/ability": "^5.4.3",
107+
"@casl/ability": "^5.4.4",
114108
"@vivocha/scopes": "^1.0.0",
115109
"body-parser": "^1.20.0",
116-
"camelcase": "^6.3.0",
110+
"camelcase": "^7.0.0",
117111
"cookie-parser": "^1.4.6",
118112
"debug": "^4.3.4",
119113
"debuggo": "^1.4.1",
120-
"decamelize": "^5.0.0",
121-
"dot-prop": "^6.0.1",
114+
"decamelize": "^6.0.0",
115+
"dot-prop": "^7.2.0",
122116
"eredita": "^1.2.1",
123-
"express": "^4.17.3",
124-
"jsonref": "^7.0.0",
117+
"express": "^4.18.1",
118+
"jsonref": "^8.0.4",
125119
"lodash": "^4.17.21",
126-
"luxon": "^2.3.1",
127-
"mongodb": "^4.5.0",
120+
"luxon": "^2.4.0",
121+
"mongodb": "^4.7.0",
128122
"needle": "^3.1.0",
129-
"openapi-police": "^3.0.1",
123+
"openapi-police": "^4.0.0",
130124
"rql": "^0.3.3",
131-
"semver": "^7.3.6"
125+
"semver": "^7.3.7"
132126
},
133127
"engines": {
134128
"node": ">=16.14.0"
135129
},
136-
"config": {
137-
"commitizen": {
138-
"path": "./node_modules/cz-conventional-changelog"
139-
}
140-
},
141-
"husky": {
142-
"hooks": {
143-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
144-
"pre-commit": "npm run build && npm run cover && npm run check-coverage"
145-
}
146-
},
147-
"nyc": {
130+
"c8": {
148131
"lines": 100,
149132
"statements": 100,
150133
"functions": 100,

src/api.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ import { Scopes } from '@vivocha/scopes';
22
import { getLogger, Logger } from 'debuggo';
33
import { Eredita } from 'eredita';
44
import express, { NextFunction, Request, Response, Router, RouterOptions } from 'express';
5-
import * as http from 'http';
6-
import * as https from 'https';
7-
import * as refs from 'jsonref'; // TODO include everything from openapi-police
8-
import * as _ from 'lodash';
5+
import http from 'http';
6+
import https from 'https';
7+
import _ from 'lodash';
98
import needle from 'needle';
10-
import { OpenAPIV3, SchemaObject, ValidationError } from 'openapi-police';
11-
import * as semver from 'semver';
9+
import { OpenAPIV3, parse, ParseOptions, rebase, SchemaObject, ValidationError } from 'openapi-police';
10+
import semver from 'semver';
1211
import { deprecate } from 'util';
13-
import { DEFAULT_DOCUMENT } from './defaults';
14-
import { RESTError } from './error';
15-
import { Resource } from './resource';
16-
import { SchemaResource } from './schema';
17-
import { APIRequest, APIResponse } from './types';
18-
import { rebaseOASDefinitions, refsRebaser, removeSchemaDeclaration, removeUnusedSchemas } from './util';
12+
import { DEFAULT_DOCUMENT } from './defaults.js';
13+
import { RESTError } from './error.js';
14+
import { Resource } from './resource.js';
15+
import { SchemaResource } from './schema.js';
16+
import { APIRequest, APIResponse } from './types.js';
17+
import { rebaseOASDefinitions, refsRebaser, removeSchemaDeclaration, removeUnusedSchemas } from './util.js';
1918

2019
let reqId: number = 0;
2120

@@ -31,7 +30,7 @@ export class API {
3130
[name: string]: SchemaObject;
3231
} = {};
3332
protected internalRouter: Promise<Router>;
34-
protected parseOptions: refs.ParseOptions;
33+
protected parseOptions: ParseOptions;
3534

3635
constructor(info?: OpenAPIV3.InfoObject) {
3736
this.document = Eredita.deepExtend(_.cloneDeep(DEFAULT_DOCUMENT), { info: info || {} });
@@ -74,7 +73,7 @@ export class API {
7473
if (!this.document.components.schemas) {
7574
this.document.components.schemas = {};
7675
}
77-
this.document.components.schemas[name] = removeSchemaDeclaration(refs.rebase(name, _.cloneDeep(schema), refsRebaser));
76+
this.document.components.schemas[name] = removeSchemaDeclaration(rebase(name, _.cloneDeep(schema), refsRebaser));
7877
}
7978
registerDynamicSchema(name: string, schema: SchemaObject) {
8079
this.dynamicSchemas[name] = schema;
@@ -215,7 +214,7 @@ export class API {
215214
}
216215
});
217216

218-
this.document = await refs.parse(this.document, this.parseOptions);
217+
this.document = await parse(this.document, this.parseOptions);
219218
for (let resource of this.resources) {
220219
await resource.router(router, options);
221220
}

src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export * from '@casl/ability';
22
export * from '@vivocha/scopes';
33
export * from 'openapi-police';
4-
export * from './api';
5-
export * from './error';
6-
export * from './mongo';
7-
export * from './operation';
8-
export * from './resource';
9-
export * from './rpc';
10-
export * from './types';
4+
export * from './api.js';
5+
export * from './error.js';
6+
export * from './mongo/index.js';
7+
export * from './operation.js';
8+
export * from './resource.js';
9+
export * from './rpc.js';
10+
export * from './types.js';

src/mongo/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './operation';
2-
export * from './resource';
1+
export * from './operation/index.js';
2+
export * from './resource.js';

src/mongo/operation/base.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Ability } from '@casl/ability';
2-
import * as _ from 'lodash';
2+
import _ from 'lodash';
33
import { Collection, CollectionOptions, ObjectId } from 'mongodb';
4-
import { API } from '../../api';
5-
import { Job, PipelineOperation } from '../../pipeline';
6-
import { APIRequest, APIResponse, Method } from '../../types';
7-
import { MongoResource } from '../resource';
8-
import { addConstraint, toMongoQuery, unescapeMongoObject } from '../util';
4+
import { API } from '../../api.js';
5+
import { Job, PipelineOperation } from '../../pipeline.js';
6+
import { APIRequest, APIResponse, Method } from '../../types.js';
7+
import { MongoResource } from '../resource.js';
8+
import { addConstraint, toMongoQuery, unescapeMongoObject } from '../util.js';
99

1010
export interface MongoJob extends Job {
1111
coll: Collection;

src/mongo/operation/create.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as _ from 'lodash';
1+
import _ from 'lodash';
22
import { InsertOneOptions, ObjectId } from 'mongodb';
33
import { OpenAPIV3 } from 'openapi-police';
4-
import { API } from '../../api';
5-
import { Method } from '../../types';
6-
import { MongoResource } from '../resource';
7-
import { escapeMongoObject } from '../util';
8-
import { MongoJob, MongoOperation } from './base';
4+
import { API } from '../../api.js';
5+
import { Method } from '../../types.js';
6+
import { MongoResource } from '../resource.js';
7+
import { escapeMongoObject } from '../util.js';
8+
import { MongoJob, MongoOperation } from './base.js';
99

1010
export class CreateMongoOperation extends MongoOperation {
1111
constructor(resource: MongoResource, path: string, method: Method, id: string = 'create') {

src/mongo/operation/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export * from './base';
2-
export { CreateMongoOperation } from './create';
3-
export { PatchMongoOperation } from './patch';
4-
export { QueryMongoOperation } from './query';
5-
export { ReadMongoOperation } from './read';
6-
export { RemoveMongoOperation } from './remove';
7-
export { UpdateMongoOperation } from './update';
1+
export * from './base.js';
2+
export { CreateMongoOperation } from './create.js';
3+
export { PatchMongoOperation } from './patch.js';
4+
export { QueryMongoOperation } from './query.js';
5+
export { ReadMongoOperation } from './read.js';
6+
export { RemoveMongoOperation } from './remove.js';
7+
export { UpdateMongoOperation } from './update.js';

src/mongo/operation/patch.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { FindOneAndUpdateOptions } from 'mongodb';
22
import { JSONPatch, OpenAPIV3 } from 'openapi-police';
3-
import { API } from '../../api';
4-
import { Method } from '../../types';
5-
import { MongoResource } from '../resource';
6-
import { addConstraint, patchToMongo } from '../util';
7-
import { MongoJob, MongoOperation } from './base';
3+
import { API } from '../../api.js';
4+
import { Method } from '../../types.js';
5+
import { MongoResource } from '../resource.js';
6+
import { addConstraint, patchToMongo } from '../util.js';
7+
import { MongoJob, MongoOperation } from './base.js';
88

99
export class PatchMongoOperation extends MongoOperation {
1010
constructor(resource: MongoResource, path: string, method: Method, id: string = 'patch') {

src/mongo/operation/query.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as _ from 'lodash';
1+
import _ from 'lodash';
22
import { AggregateOptions } from 'mongodb';
33
import { OpenAPIV3 } from 'openapi-police';
4-
import { Method } from '../../types';
5-
import { MongoResource } from '../resource';
6-
import rql from '../rql';
7-
import { addConstraint } from '../util';
8-
import { MongoJob, MongoOperation } from './base';
4+
import { Method } from '../../types.js';
5+
import { MongoResource } from '../resource.js';
6+
import rql from '../rql.js';
7+
import { addConstraint } from '../util.js';
8+
import { MongoJob, MongoOperation } from './base.js';
99

1010
export class QueryMongoOperation extends MongoOperation {
1111
constructor(resource: MongoResource, path: string, method: Method, id: string = 'query') {

src/mongo/operation/read.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { FindOptions } from 'mongodb';
22
import { OpenAPIV3 } from 'openapi-police';
3-
import { API } from '../../api';
4-
import { Method } from '../../types';
5-
import { MongoResource } from '../resource';
6-
import { addConstraint } from '../util';
7-
import { MongoJob, MongoOperation } from './base';
3+
import { API } from '../../api.js';
4+
import { Method } from '../../types.js';
5+
import { MongoResource } from '../resource.js';
6+
import { addConstraint } from '../util.js';
7+
import { MongoJob, MongoOperation } from './base.js';
88

99
export class ReadMongoOperation extends MongoOperation {
1010
constructor(resource: MongoResource, path: string, method: Method, id: string = 'read') {

0 commit comments

Comments
 (0)