ac-convert-json-schema-to-mongoose 0.3.4 → 0.3.6

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.
@@ -1,31 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var json_schema_1 = require("./lib/json-schema");
4
- var refs = {
5
- yep: {
6
- type: 'string', pattern: '^\\d{3}$'
7
- }, a: {
8
- type: 'array', items: {
9
- type: 'object', properties: {
10
- num: { type: 'number' }, str: { type: 'string' }
11
- }
12
- }
13
- }, idSpec: {
14
- type: 'object', properties: {
15
- id: { $ref: 'yep' }, arr: { $ref: 'a' }
16
- }
17
- }
18
- };
19
- // noinspection ReservedWordAsName
20
- var valid = {
21
- type: 'object', properties: {
22
- id: { $ref: 'yep' }, arr: { $ref: 'a' }, address: {
23
- type: 'object', properties: {
24
- street: { type: 'integer', default: 44, minimum: 0, maximum: 50 },
25
- houseColor: { type: 'string', default: '[Function=Date.now]', format: 'date-time' }
26
- }
27
- }
28
- }
29
- };
30
- var result = json_schema_1.default(refs, valid);
31
- console.dir(result, { depth: null });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const json_schema_1 = require("./lib/json-schema");
4
+ const refs = {
5
+ yep: {
6
+ type: 'string', pattern: '^\\d{3}$'
7
+ }, a: {
8
+ type: 'array', items: {
9
+ type: 'object', properties: {
10
+ num: { type: 'number' }, str: { type: 'string' }
11
+ }
12
+ }
13
+ }, idSpec: {
14
+ type: 'object', properties: {
15
+ id: { $ref: 'yep' }, arr: { $ref: 'a' }
16
+ }
17
+ }
18
+ };
19
+ // noinspection ReservedWordAsName
20
+ const valid = {
21
+ type: 'object', properties: {
22
+ id: { $ref: 'yep' }, arr: { $ref: 'a' }, address: {
23
+ type: 'object', properties: {
24
+ street: { type: 'integer', default: 44, minimum: 0, maximum: 50 },
25
+ houseColor: { type: 'string', default: '[Function=Date.now]', format: 'date-time' }
26
+ }
27
+ }
28
+ }
29
+ };
30
+ const result = (0, json_schema_1.default)(refs, valid);
31
+ console.dir(result, { depth: null });
32
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1,2 @@
1
+ import createMongooseSchema from './lib/json-schema';
2
+ export { createMongooseSchema };
@@ -1,4 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var json_schema_1 = require("./lib/json-schema");
4
- exports.createMongooseSchema = json_schema_1.default;
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;
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ interface CreateMongooseSchema {
2
+ (refSchemas: any, jsonSchema: any): any;
3
+ (refSchemas: any): (jsonSchema: any) => any;
4
+ }
5
+ declare const _default: CreateMongooseSchema;
6
+ export default _default;
@@ -1,107 +1,108 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var _ = require("lodash");
4
- var mongoose = require("mongoose");
5
- var typeStringToMongooseType = { 'string': String, 'boolean': Boolean, 'number': Number, 'integer': Number };
6
- var typeRefToMongooseType = {
7
- '#/definitions/objectid': mongoose.Schema.Types.ObjectId, '#/definitions/dateOrDatetime': Date
8
- };
9
- var subSchemaTypeV3 = function (parentSchema, subschema, key) {
10
- return (0 <= parentSchema.required.indexOf(key) && !_.isPlainObject(subschema)) ? {
11
- type: subschema, required: true
12
- } : subschema;
13
- };
14
- var subSchemaTypeV4 = function (parentSchema, subschema, key) {
15
- return (0 <= parentSchema.required.indexOf(key)) ? !_.isPlainObject(subschema) ? {
16
- type: subschema, required: true
17
- } : subschema.hasOwnProperty('type') ? _.assign(subschema, { required: true }) : subschema : subschema;
18
- };
19
- // noinspection ReservedWordAsName
20
- var schemaParamsToMongoose = {
21
- /**
22
- * default value
23
- */
24
- default: function (default_) {
25
- var func = (_.last(/^\[Function=(.+)\]$/.exec(default_)) || '')
26
- .replace(/\\_/g, '`underscore`')
27
- .replace(/_/g, ' ')
28
- .replace(/`underscore`/g, '_');
29
- // noinspection ReservedWordAsName,DynamicallyGeneratedCodeJS
30
- return { default: eval(func) || default_ };
31
- },
32
- /**
33
- * Pattern for value to match
34
- */
35
- pattern: function (pattern) { return ({ match: RegExp(pattern) }); },
36
- type: function (type) { return ({ type: typeStringToMongooseType[type] }); },
37
- minLength: function (min) { return ({ minlength: min }); },
38
- maxLength: function (max) { return ({ maxlength: max }); },
39
- minimum: function (min) { return ({ min: min }); },
40
- maximum: function (max) { return ({ max: max }); },
41
- enum: function (members) { return ({ enum: members }); }
42
- };
43
- var toMongooseParams = function (acc, val, key) {
44
- var func;
45
- // noinspection AssignmentResultUsedJS
46
- return (func = schemaParamsToMongoose[key]) ? _.assign(acc, func(val)) : acc;
47
- };
48
- var unsupportedRefValue = function (jsonSchema) {
49
- throw new Error('Unsupported $ref value: ' + jsonSchema.$ref);
50
- };
51
- var unsupportedJsonSchema = function (jsonSchema) {
52
- throw new Error('Unsupported JSON schema type, `' + jsonSchema.type + '`');
53
- };
54
- var convertV = function (version, refSchemas, jsonSchema) {
55
- if (!_.isPlainObject(jsonSchema)) {
56
- unsupportedJsonSchema(jsonSchema);
57
- }
58
- var converted, result, format = jsonSchema.format, isRef = !_.isEmpty(jsonSchema.$ref), isTypeDate = ('string' === jsonSchema.type) && (('date' === format) || ('date-time' === format)), mongooseRef = typeRefToMongooseType[jsonSchema.$ref], isMongooseRef = ('undefined' != typeof (mongooseRef)), subSchema = _.isEmpty(refSchemas) ? false : refSchemas[jsonSchema.$ref], subSchemaType = (4 == version) ? subSchemaTypeV4 : subSchemaTypeV3;
59
- return (result =
60
- isRef ?
61
- isMongooseRef ?
62
- mongooseRef :
63
- subSchema ?
64
- convertV(version, refSchemas, subSchema) :
65
- unsupportedRefValue(jsonSchema)
66
- :
67
- isTypeDate ?
68
- _.reduce(_.omit(jsonSchema, 'type', 'format'), toMongooseParams, { type: typeRefToMongooseType['#/definitions/dateOrDatetime'] })
69
- :
70
- _.has(typeStringToMongooseType, jsonSchema.type) ?
71
- _.reduce(jsonSchema, toMongooseParams, {})
72
- :
73
- (jsonSchema.type === 'object') ?
74
- _.isEmpty(jsonSchema.properties) ?
75
- mongoose.Schema.Types.Mixed :
76
- (converted =
77
- _.mapValues(jsonSchema.properties, convertV.bind(null, version, refSchemas)), jsonSchema.required ?
78
- (_.mapValues(converted, subSchemaType.bind(null, jsonSchema))) :
79
- converted)
80
- :
81
- (jsonSchema.type === 'array') ?
82
- !_.isEmpty(jsonSchema.items) ?
83
- [convertV(version, refSchemas, jsonSchema.items)] :
84
- []
85
- :
86
- !_.has(jsonSchema, 'type') ?
87
- mongoose.Schema.Types.Mixed :
88
- unsupportedJsonSchema(jsonSchema));
89
- };
90
- var convert = function (refSchemas, jsonSchema) {
91
- var version = 3;
92
- switch (jsonSchema.$schema) {
93
- case 'http://json-schema.org/draft-03/schema#':
94
- version = 3;
95
- break;
96
- case 'http://json-schema.org/draft-04/schema#':
97
- version = 4;
98
- break;
99
- // backwards compatibility
100
- default:
101
- version = 3;
102
- break;
103
- }
104
- return convertV(version, refSchemas, jsonSchema);
105
- };
106
- // noinspection JSUnusedGlobalSymbols
107
- exports.default = _.curry(convert);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const _ = require("lodash");
4
+ const mongoose = require("mongoose");
5
+ const typeStringToMongooseType = { 'string': String, 'boolean': Boolean, 'number': Number, 'integer': Number };
6
+ const typeRefToMongooseType = {
7
+ '#/definitions/objectid': mongoose.Schema.Types.ObjectId, '#/definitions/dateOrDatetime': Date
8
+ };
9
+ const subSchemaTypeV3 = (parentSchema, subschema, key) => {
10
+ return (0 <= parentSchema.required.indexOf(key) && !_.isPlainObject(subschema)) ? {
11
+ type: subschema, required: true
12
+ } : subschema;
13
+ };
14
+ const subSchemaTypeV4 = (parentSchema, subschema, key) => {
15
+ return (0 <= parentSchema.required.indexOf(key)) ? !_.isPlainObject(subschema) ? {
16
+ type: subschema, required: true
17
+ } : subschema.hasOwnProperty('type') ? _.assign(subschema, { required: true }) : subschema : subschema;
18
+ };
19
+ // noinspection ReservedWordAsName
20
+ const schemaParamsToMongoose = {
21
+ /**
22
+ * default value
23
+ */
24
+ default: (default_) => {
25
+ const func = (_.last(/^\[Function=(.+)\]$/.exec(default_)) || '')
26
+ .replace(/\\_/g, '`underscore`')
27
+ .replace(/_/g, ' ')
28
+ .replace(/`underscore`/g, '_');
29
+ // noinspection ReservedWordAsName,DynamicallyGeneratedCodeJS
30
+ return { default: eval(func) || default_ };
31
+ },
32
+ /**
33
+ * Pattern for value to match
34
+ */
35
+ pattern: (pattern) => ({ match: RegExp(pattern) }),
36
+ type: (type) => ({ type: typeStringToMongooseType[type] }),
37
+ minLength: (min) => ({ minlength: min }),
38
+ maxLength: (max) => ({ maxlength: max }),
39
+ minimum: (min) => ({ min: min }),
40
+ maximum: (max) => ({ max: max }),
41
+ enum: (members) => ({ enum: members })
42
+ };
43
+ const toMongooseParams = (acc, val, key) => {
44
+ let func;
45
+ // noinspection AssignmentResultUsedJS
46
+ return (func = schemaParamsToMongoose[key]) ? _.assign(acc, func(val)) : acc;
47
+ };
48
+ const unsupportedRefValue = (jsonSchema) => {
49
+ throw new Error('Unsupported $ref value: ' + jsonSchema.$ref);
50
+ };
51
+ const unsupportedJsonSchema = (jsonSchema) => {
52
+ throw new Error('Unsupported JSON schema type, `' + jsonSchema.type + '`');
53
+ };
54
+ const convertV = (version, refSchemas, jsonSchema) => {
55
+ if (!_.isPlainObject(jsonSchema)) {
56
+ unsupportedJsonSchema(jsonSchema);
57
+ }
58
+ let converted, result, format = jsonSchema.format, isRef = !_.isEmpty(jsonSchema.$ref), isTypeDate = ('string' === jsonSchema.type) && (('date' === format) || ('date-time' === format)), mongooseRef = typeRefToMongooseType[jsonSchema.$ref], isMongooseRef = ('undefined' != typeof (mongooseRef)), subSchema = _.isEmpty(refSchemas) ? false : refSchemas[jsonSchema.$ref], subSchemaType = (4 == version) ? subSchemaTypeV4 : subSchemaTypeV3;
59
+ return (result =
60
+ isRef ?
61
+ isMongooseRef ?
62
+ mongooseRef :
63
+ subSchema ?
64
+ convertV(version, refSchemas, subSchema) :
65
+ unsupportedRefValue(jsonSchema)
66
+ :
67
+ isTypeDate ?
68
+ _.reduce(_.omit(jsonSchema, 'type', 'format'), toMongooseParams, { type: typeRefToMongooseType['#/definitions/dateOrDatetime'] })
69
+ :
70
+ _.has(typeStringToMongooseType, jsonSchema.type) ?
71
+ _.reduce(jsonSchema, toMongooseParams, {})
72
+ :
73
+ (jsonSchema.type === 'object') ?
74
+ _.isEmpty(jsonSchema.properties) ?
75
+ mongoose.Schema.Types.Mixed :
76
+ (converted =
77
+ _.mapValues(jsonSchema.properties, convertV.bind(null, version, refSchemas)), jsonSchema.required ?
78
+ (_.mapValues(converted, subSchemaType.bind(null, jsonSchema))) :
79
+ converted)
80
+ :
81
+ (jsonSchema.type === 'array') ?
82
+ !_.isEmpty(jsonSchema.items) ?
83
+ [convertV(version, refSchemas, jsonSchema.items)] :
84
+ []
85
+ :
86
+ !_.has(jsonSchema, 'type') ?
87
+ mongoose.Schema.Types.Mixed :
88
+ unsupportedJsonSchema(jsonSchema));
89
+ };
90
+ const convert = (refSchemas, jsonSchema) => {
91
+ let version = 3;
92
+ switch (jsonSchema.$schema) {
93
+ case 'http://json-schema.org/draft-03/schema#':
94
+ version = 3;
95
+ break;
96
+ case 'http://json-schema.org/draft-04/schema#':
97
+ version = 4;
98
+ break;
99
+ // backwards compatibility
100
+ default:
101
+ version = 3;
102
+ break;
103
+ }
104
+ return convertV(version, refSchemas, jsonSchema);
105
+ };
106
+ // noinspection JSUnusedGlobalSymbols
107
+ exports.default = _.curry(convert);
108
+ //# sourceMappingURL=json-schema.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,82 @@
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 () {
9
+ _.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) {
16
+ 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/);
24
+ });
25
+ });
26
+ _.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/);
39
+ });
40
+ });
41
+ it('should convert a valid json-schema', () => {
42
+ const refs = {
43
+ yep: { type: 'string', pattern: '^\\d{3}$' },
44
+ a: {
45
+ type: 'array', items: { type: 'object', properties: { num: { type: 'number' }, str: { type: 'string' } } }
46
+ },
47
+ anyValue: { description: 'This can be any value.' },
48
+ idSpec: { type: 'object', properties: { id: { $ref: 'yep' }, arr: { $ref: 'a' } } }
49
+ };
50
+ // noinspection ReservedWordAsName
51
+ const valid = {
52
+ type: 'object', properties: {
53
+ id: { $ref: 'yep' }, arr: { $ref: 'a' }, anyValue: { a: 'b' }, address: {
54
+ type: 'object', properties: {
55
+ street: { type: 'integer', default: 44, minimum: 0, maximum: 50 },
56
+ houseColor: { type: 'string', default: '[Function=Date.now]', format: 'date-time' }
57
+ }
58
+ }
59
+ }
60
+ };
61
+ // noinspection ReservedWordAsName
62
+ assert.deepEqual((0, json_schema_1.default)(refs, valid), {
63
+ id: { type: String, match: /^\d{3}$/ },
64
+ arr: [{ num: { type: Number }, str: { type: String } }],
65
+ anyValue: mongoose.Schema.Types.Mixed,
66
+ address: {
67
+ street: { type: Number, default: 44, min: 0, max: 50 }, houseColor: { type: Date, default: Date.now }
68
+ }
69
+ });
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
+ });
80
+ });
81
+ });
82
+ //# sourceMappingURL=json-schema.spec.js.map
package/package.json CHANGED
@@ -1,37 +1,45 @@
1
- {
2
- "name": "ac-convert-json-schema-to-mongoose",
3
- "version": "0.3.4",
4
- "description": "A library for converting JSON schema to mongoose 5 schema",
5
- "keywords": [
6
- "json",
7
- "schema",
8
- "convert",
9
- "mongo",
10
- "mongoose"
11
- ],
12
- "homepage": "https://github.com/kristianmandrup/convert-json-schema-to-mongoose",
13
- "repository": {
14
- "url": "https://github.com/kristianmandrup/convert-json-schema-to-mongoose",
15
- "type": "git"
16
- },
17
- "bugs": {
18
- "url": "https://github.com/kristianmandrup/convert-json-schema-to-mongoose/issues"
19
- },
20
- "private": false,
21
- "license": "MIT",
22
- "dependencies": {
23
- "lodash": "^4.17.21",
24
- "mongoose": "^7.3.0"
25
- },
26
- "devDependencies": {
27
- "@types/jasmine": "^4.3.2",
28
- "@types/lodash": "^4.14.195",
29
- "@types/node": "^20.3.1",
30
- "jasmine-node": "^3.0.0"
31
- },
32
- "scripts": {
33
- "test": "node_modules/.bin/jasmine-node ./test",
34
- "start": "node index.js"
35
- },
36
- "main": "index"
37
- }
1
+ {
2
+ "name": "ac-convert-json-schema-to-mongoose",
3
+ "version": "0.3.6",
4
+ "description": "A library for converting JSON schema to mongoose 5 schema",
5
+ "keywords": [
6
+ "json",
7
+ "schema",
8
+ "convert",
9
+ "mongo",
10
+ "mongoose"
11
+ ],
12
+ "homepage": "https://github.com/kristianmandrup/convert-json-schema-to-mongoose",
13
+ "repository": {
14
+ "url": "https://github.com/kristianmandrup/convert-json-schema-to-mongoose",
15
+ "type": "git"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/kristianmandrup/convert-json-schema-to-mongoose/issues"
19
+ },
20
+ "private": false,
21
+ "license": "MIT",
22
+ "main": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "scripts": {
25
+ "build": "tsc",
26
+ "test": "jasmine ./dist/test/*.js",
27
+ "start": "node dist/index.js"
28
+ },
29
+ "files": [
30
+ "dist/**",
31
+ "!*.map"
32
+ ],
33
+ "dependencies": {
34
+ "lodash": "^4.17.21",
35
+ "mongoose": "^8.9.5"
36
+ },
37
+ "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"
44
+ }
45
+ }
package/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - '5.10.1'
4
- services:
package/app.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["app.ts"],"names":[],"mappings":"AAAA,IAAO,oBAAoB,WAAW,mBAAmB,CAAC,CAAA;AAC1D,IAAO,IAAI,WAAW,MAAM,CAAC,CAAA;AA0C7B,AAxCA,YAAY;AACZ,GAAG;AACH,UAAU;AACV,OAAO;AACP,yBAAyB;AACzB,6BAA6B;AAC7B,QAAQ;AACR,eAAe;AACf,yBAAyB;AACzB,qBAAqB;AACrB,WAAW;AACX,iBAAiB;AACjB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AW,EAAC;aAChG;SAAC;KAAC;CAAC,CAAA;AAEJ,IAAI,MAAM,GAAG,oBAAoB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AAE9C,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA"}
package/app.ts DELETED
@@ -1,32 +0,0 @@
1
- import createMongooseSchema from './lib/json-schema';
2
-
3
- const refs = {
4
- yep: {
5
- type: 'string', pattern: '^\\d{3}$'
6
- }, a: {
7
- type: 'array', items: {
8
- type: 'object', properties: {
9
- num: {type: 'number'}, str: {type: 'string'}
10
- }
11
- }
12
- }, idSpec: {
13
- type: 'object', properties: {
14
- id: {$ref: 'yep'}, arr: {$ref: 'a'}
15
- }
16
- }
17
- };
18
-
19
- // noinspection ReservedWordAsName
20
- const valid = {
21
- type: 'object', properties: {
22
- id: {$ref: 'yep'}, arr: {$ref: 'a'}, address: {
23
- type: 'object', properties: {
24
- street: {type: 'integer', default: 44, minimum: 0, maximum: 50},
25
- houseColor: {type: 'string', default: '[Function=Date.now]', format: 'date-time'}
26
- }
27
- }
28
- }
29
- };
30
-
31
- const result = createMongooseSchema(refs, valid);
32
- console.dir(result, {depth: null});
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAE7C,IAAO,oBAAoB,WAAW,mBAAmB,CAAC,CAAA;AAC7B,AAA7B,iBAAS,oBAAoB,CAAA"}
package/index.ts DELETED
@@ -1,3 +0,0 @@
1
- import createMongooseSchema from './lib/json-schema';
2
-
3
- export {createMongooseSchema};
@@ -1,7 +0,0 @@
1
- declare module 'json-schema-to-mongoose' {
2
- // noinspection JSUnusedGlobalSymbols
3
- function createMongooseSchema(refSchemas : any, jsonSchema : any) : any
4
- function createMongooseSchema(refSchemas : any, jsonSchema : any) : any
5
- function createMongooseSchema(refSchemas : any) : (jsonSchema : any) => any
6
- function createMongooseSchema(refSchemas : any) : (jsonSchema : any) => any
7
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"json-schema.js","sourceRoot":"","sources":["json-schema.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAEhD,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAA;AACrC,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAA;AAE5B,IAAI,wBAAwB,GAAG;IAC3B,QAAQ,EAAE,MAAM;IAChB,SAAS,EAAE,OAAO;IAClB,QAAQ,EAAE,MAAM;IAChB,SAAS,EAAE,MAAM;CACpB,CAAA;AAED,IAAI,qBAAqB,GAAG;IACxB,wBAAwB,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ;IACxD,8BAA8B,EAAE,IAAI;CAEvC,CAAA;AAED,IAAI,aAAa,GAAG,UAAC,YAAY,EAAE,SAAS,EAAE,GAAG;IAE7C,MAAM,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QACxE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE;UACjC,SAAS,CAAA;AACtB,CAAC,CAAA;AAED,IAAI,sBAAsB,GAC1B;IAII,AAHA;;MAEE;IACF,OAAO,EAAE,UAAC,QAAgB;QAEtB,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;aAC1D,OAAO,CAAC,MAAM,EAAE,cAAc,CAAC;aAC/B,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;aAClB,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAA;QAClC,MAAM,CAAC;YACH,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ;SAClC,CAAA;IACL,CAAC;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