@audc/convert-json-schema-to-mongoose 0.3.6 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +2 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -5
- package/dist/lib/json-schema.js +3 -5
- package/dist/test/json-schema.spec.js +32 -50
- package/package.json +10 -9
package/dist/app.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const json_schema_1 = require("./lib/json-schema");
|
|
1
|
+
import createMongooseSchema from './lib/json-schema.js';
|
|
4
2
|
const refs = {
|
|
5
3
|
yep: {
|
|
6
4
|
type: 'string', pattern: '^\\d{3}$'
|
|
@@ -27,6 +25,6 @@ const valid = {
|
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
27
|
};
|
|
30
|
-
const result = (
|
|
28
|
+
const result = createMongooseSchema(refs, valid);
|
|
31
29
|
console.dir(result, { depth: null });
|
|
32
30
|
//# sourceMappingURL=app.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import createMongooseSchema from './lib/json-schema';
|
|
1
|
+
import createMongooseSchema from './lib/json-schema.js';
|
|
2
2
|
export { createMongooseSchema };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.createMongooseSchema = void 0;
|
|
4
|
-
const json_schema_1 = require("./lib/json-schema");
|
|
5
|
-
exports.createMongooseSchema = json_schema_1.default;
|
|
1
|
+
import createMongooseSchema from './lib/json-schema.js';
|
|
2
|
+
export { createMongooseSchema };
|
|
6
3
|
//# sourceMappingURL=index.js.map
|
package/dist/lib/json-schema.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const _ = require("lodash");
|
|
4
|
-
const mongoose = require("mongoose");
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import mongoose from 'mongoose';
|
|
5
3
|
const typeStringToMongooseType = { 'string': String, 'boolean': Boolean, 'number': Number, 'integer': Number };
|
|
6
4
|
const typeRefToMongooseType = {
|
|
7
5
|
'#/definitions/objectid': mongoose.Schema.Types.ObjectId, '#/definitions/dateOrDatetime': Date
|
|
@@ -104,5 +102,5 @@ const convert = (refSchemas, jsonSchema) => {
|
|
|
104
102
|
return convertV(version, refSchemas, jsonSchema);
|
|
105
103
|
};
|
|
106
104
|
// noinspection JSUnusedGlobalSymbols
|
|
107
|
-
|
|
105
|
+
export default _.curry(convert);
|
|
108
106
|
//# sourceMappingURL=json-schema.js.map
|
|
@@ -1,81 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
describe('mongoose schema conversion:', function () {
|
|
8
|
-
describe('createMongooseSchema', function () {
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import mongoose from 'mongoose';
|
|
4
|
+
import createMongooseSchema from '../lib/json-schema.js';
|
|
5
|
+
describe('mongoose schema conversion:', () => {
|
|
6
|
+
describe('createMongooseSchema', () => {
|
|
9
7
|
_.each([
|
|
10
|
-
{ type: 'objectttttt' },
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
], function (invalid) {
|
|
8
|
+
{ type: 'objectttttt' },
|
|
9
|
+
{ type: 'object', properties: 'not an object' },
|
|
10
|
+
{ type: 'object', properties: { email: { type: 'not a type' } } }
|
|
11
|
+
], (invalid) => {
|
|
16
12
|
it('throws when the incorrect type is given', () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}, /Unsupported JSON schema/);
|
|
21
|
-
// expect(() => {
|
|
22
|
-
// createMongooseSchema(void 0, invalid);
|
|
23
|
-
// }).toThrowError(/Unsupported JSON schema/);
|
|
13
|
+
expect(() => {
|
|
14
|
+
createMongooseSchema(void 0, invalid);
|
|
15
|
+
}).toThrowError(/Unsupported JSON schema/);
|
|
24
16
|
});
|
|
25
17
|
});
|
|
26
18
|
_.each([
|
|
27
|
-
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// noinspection VoidExpressionJS
|
|
34
|
-
(0, json_schema_1.default)(void 0, invalid);
|
|
35
|
-
}, /Unsupported .ref/);
|
|
36
|
-
// expect(() => {
|
|
37
|
-
// createMongooseSchema(void 0, invalid);
|
|
38
|
-
// }).toThrowError(/Unsupported .ref/);
|
|
19
|
+
{ type: 'object', properties: { id: { $ref: '#/nope/nope/nope' } } }
|
|
20
|
+
], (invalid) => {
|
|
21
|
+
it('throws on unsupported ref, ' + JSON.stringify(invalid), () => {
|
|
22
|
+
expect(() => {
|
|
23
|
+
createMongooseSchema(void 0, invalid);
|
|
24
|
+
}).toThrowError(/Unsupported .ref/);
|
|
39
25
|
});
|
|
40
26
|
});
|
|
41
27
|
it('should convert a valid json-schema', () => {
|
|
42
28
|
const refs = {
|
|
43
29
|
yep: { type: 'string', pattern: '^\\d{3}$' },
|
|
44
30
|
a: {
|
|
45
|
-
type: 'array',
|
|
31
|
+
type: 'array',
|
|
32
|
+
items: { type: 'object', properties: { num: { type: 'number' }, str: { type: 'string' } } }
|
|
46
33
|
},
|
|
47
34
|
anyValue: { description: 'This can be any value.' },
|
|
48
35
|
idSpec: { type: 'object', properties: { id: { $ref: 'yep' }, arr: { $ref: 'a' } } }
|
|
49
36
|
};
|
|
50
|
-
// noinspection ReservedWordAsName
|
|
51
37
|
const valid = {
|
|
52
|
-
type: 'object',
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
id: { $ref: 'yep' },
|
|
41
|
+
arr: { $ref: 'a' },
|
|
42
|
+
anyValue: { a: 'b' },
|
|
43
|
+
address: {
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: {
|
|
55
46
|
street: { type: 'integer', default: 44, minimum: 0, maximum: 50 },
|
|
56
47
|
houseColor: { type: 'string', default: '[Function=Date.now]', format: 'date-time' }
|
|
57
48
|
}
|
|
58
49
|
}
|
|
59
50
|
}
|
|
60
51
|
};
|
|
61
|
-
|
|
62
|
-
assert.deepEqual((0, json_schema_1.default)(refs, valid), {
|
|
52
|
+
expect(createMongooseSchema(refs, valid)).toEqual({
|
|
63
53
|
id: { type: String, match: /^\d{3}$/ },
|
|
64
54
|
arr: [{ num: { type: Number }, str: { type: String } }],
|
|
65
55
|
anyValue: mongoose.Schema.Types.Mixed,
|
|
66
56
|
address: {
|
|
67
|
-
street: { type: Number, default: 44, min: 0, max: 50 },
|
|
57
|
+
street: { type: Number, default: 44, min: 0, max: 50 },
|
|
58
|
+
houseColor: { type: Date, default: Date.now }
|
|
68
59
|
}
|
|
69
60
|
});
|
|
70
|
-
// noinspection ReservedWordAsName
|
|
71
|
-
// expect(createMongooseSchema(refs, valid)).toEqual({
|
|
72
|
-
// id: {type: String, match: /^\d{3}$/},
|
|
73
|
-
// arr: [{num: {type: Number}, str: {type: String}}],
|
|
74
|
-
// anyValue: mongoose.Schema.Types.Mixed,
|
|
75
|
-
// address: {
|
|
76
|
-
// street: {type: Number, default: 44, min: 0, max: 50}, houseColor: {type: Date, default: Date.now}
|
|
77
|
-
// }
|
|
78
|
-
// });
|
|
79
61
|
});
|
|
80
62
|
});
|
|
81
63
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audc/convert-json-schema-to-mongoose",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A library for converting JSON schema to mongoose 5 schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"json",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"mongo",
|
|
10
10
|
"mongoose"
|
|
11
11
|
],
|
|
12
|
+
"type": "module",
|
|
12
13
|
"homepage": "https://github.com/kristianmandrup/convert-json-schema-to-mongoose",
|
|
13
14
|
"repository": {
|
|
14
15
|
"url": "https://github.com/kristianmandrup/convert-json-schema-to-mongoose",
|
|
@@ -23,7 +24,8 @@
|
|
|
23
24
|
"types": "dist/index.d.ts",
|
|
24
25
|
"scripts": {
|
|
25
26
|
"build": "tsc",
|
|
26
|
-
"test": "
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest",
|
|
27
29
|
"start": "node dist/index.js"
|
|
28
30
|
},
|
|
29
31
|
"files": [
|
|
@@ -32,14 +34,13 @@
|
|
|
32
34
|
],
|
|
33
35
|
"dependencies": {
|
|
34
36
|
"lodash": "^4.17.21",
|
|
35
|
-
"mongoose": "^
|
|
37
|
+
"mongoose": "^9.0.0"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
|
-
"@tsconfig/
|
|
39
|
-
"@types/
|
|
40
|
-
"@types/
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"typescript": "^5.7.3"
|
|
40
|
+
"@tsconfig/node22": "^22.0.5",
|
|
41
|
+
"@types/lodash": "^4.17.21",
|
|
42
|
+
"@types/node": "^24.10.1",
|
|
43
|
+
"typescript": "^5.9.3",
|
|
44
|
+
"vitest": "^4.0.14"
|
|
44
45
|
}
|
|
45
46
|
}
|