@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 CHANGED
@@ -1,6 +1,4 @@
1
- "use strict";
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 = (0, json_schema_1.default)(refs, valid);
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
@@ -1,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- exports.default = _.curry(convert);
105
+ export default _.curry(convert);
108
106
  //# sourceMappingURL=json-schema.js.map
@@ -1,81 +1,63 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const _ = require("lodash");
5
- const mongoose = require("mongoose");
6
- const json_schema_1 = require("../lib/json-schema");
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
- type: 'object', properties: 'not an object'
12
- }, {
13
- type: 'object', properties: { email: { type: 'not a type' } }
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
- assert.throws(() => {
18
- // noinspection VoidExpressionJS
19
- (0, json_schema_1.default)(void 0, invalid);
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
- type: 'object', properties: { id: { $ref: '#/nope/nope/nope' } }
29
- }
30
- ], function (invalid) {
31
- it('throws on unsupported ref, ' + invalid, () => {
32
- assert.throws(() => {
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', items: { type: 'object', properties: { num: { type: 'number' }, str: { type: 'string' } } }
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', properties: {
53
- id: { $ref: 'yep' }, arr: { $ref: 'a' }, anyValue: { a: 'b' }, address: {
54
- type: 'object', properties: {
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
- // noinspection ReservedWordAsName
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 }, houseColor: { type: Date, default: Date.now }
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.6",
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": "jasmine ./dist/test/*.js",
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": "^8.9.5"
37
+ "mongoose": "^9.0.0"
36
38
  },
37
39
  "devDependencies": {
38
- "@tsconfig/node20": "^20.1.4",
39
- "@types/jasmine": "^5.1.5",
40
- "@types/lodash": "^4.17.14",
41
- "@types/node": "^22.10.7",
42
- "jasmine": "^5.5.0",
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
  }