UNPKG

mongoose-data-seed

Version:

Seed mongodb with data using mongoose models

1,691 lines (1,690 loc) 286 kB
{ "type": "File", "start": 0, "end": 2197, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 81, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 2197, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 81, "column": 0 } }, "sourceType": "module", "body": [ { "type": "ImportDeclaration", "start": 0, "end": 64, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 64 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 9, "end": 13, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 13 } }, "imported": { "type": "Identifier", "start": 9, "end": 13, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 13 }, "identifierName": "trim" }, "name": "trim" }, "local": { "type": "Identifier", "start": 9, "end": 13, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 13 }, "identifierName": "trim" }, "name": "trim" } }, { "type": "ImportSpecifier", "start": 15, "end": 25, "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 25 } }, "imported": { "type": "Identifier", "start": 15, "end": 25, "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 25 }, "identifierName": "upperFirst" }, "name": "upperFirst" }, "local": { "type": "Identifier", "start": 15, "end": 25, "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 25 }, "identifierName": "upperFirst" }, "name": "upperFirst" } }, { "type": "ImportSpecifier", "start": 27, "end": 36, "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 36 } }, "imported": { "type": "Identifier", "start": 27, "end": 36, "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 36 }, "identifierName": "camelCase" }, "name": "camelCase" }, "local": { "type": "Identifier", "start": 27, "end": 36, "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 36 }, "identifierName": "camelCase" }, "name": "camelCase" } }, { "type": "ImportSpecifier", "start": 38, "end": 47, "loc": { "start": { "line": 1, "column": 38 }, "end": { "line": 1, "column": 47 } }, "imported": { "type": "Identifier", "start": 38, "end": 47, "loc": { "start": { "line": 1, "column": 38 }, "end": { "line": 1, "column": 47 }, "identifierName": "kebabCase" }, "name": "kebabCase" }, "local": { "type": "Identifier", "start": 38, "end": 47, "loc": { "start": { "line": 1, "column": 38 }, "end": { "line": 1, "column": 47 }, "identifierName": "kebabCase" }, "name": "kebabCase" } } ], "source": { "type": "StringLiteral", "start": 55, "end": 63, "loc": { "start": { "line": 1, "column": 55 }, "end": { "line": 1, "column": 63 } }, "extra": { "rawValue": "lodash", "raw": "'lodash'" }, "value": "lodash" } }, { "type": "ImportDeclaration", "start": 66, "end": 97, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 3, "column": 31 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", "start": 73, "end": 79, "loc": { "start": { "line": 3, "column": 7 }, "end": { "line": 3, "column": 13 } }, "local": { "type": "Identifier", "start": 73, "end": 79, "loc": { "start": { "line": 3, "column": 7 }, "end": { "line": 3, "column": 13 }, "identifierName": "config" }, "name": "config" } } ], "source": { "type": "StringLiteral", "start": 85, "end": 96, "loc": { "start": { "line": 3, "column": 19 }, "end": { "line": 3, "column": 30 } }, "extra": { "rawValue": "../config", "raw": "'../config'" }, "value": "../config" } }, { "type": "ImportDeclaration", "start": 98, "end": 138, "loc": { "start": { "line": 4, "column": 0 }, "end": { "line": 4, "column": 40 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 107, "end": 116, "loc": { "start": { "line": 4, "column": 9 }, "end": { "line": 4, "column": 18 } }, "imported": { "type": "Identifier", "start": 107, "end": 116, "loc": { "start": { "line": 4, "column": 9 }, "end": { "line": 4, "column": 18 }, "identifierName": "ExitCodes" }, "name": "ExitCodes" }, "local": { "type": "Identifier", "start": 107, "end": 116, "loc": { "start": { "line": 4, "column": 9 }, "end": { "line": 4, "column": 18 }, "identifierName": "ExitCodes" }, "name": "ExitCodes" } } ], "source": { "type": "StringLiteral", "start": 124, "end": 137, "loc": { "start": { "line": 4, "column": 26 }, "end": { "line": 4, "column": 39 } }, "extra": { "rawValue": "./constants", "raw": "'./constants'" }, "value": "./constants" }, "trailingComments": [ { "type": "CommentBlock", "value": "*\n * Normalize seeder name.\n * @param {string} name seeder name\n * @return {string} normalized seeder name\n ", "start": 140, "end": 258, "loc": { "start": { "line": 6, "column": 0 }, "end": { "line": 10, "column": 3 } } } ] }, { "type": "ExportNamedDeclaration", "start": 259, "end": 330, "loc": { "start": { "line": 11, "column": 0 }, "end": { "line": 11, "column": 71 } }, "specifiers": [], "source": null, "declaration": { "type": "VariableDeclaration", "start": 266, "end": 330, "loc": { "start": { "line": 11, "column": 7 }, "end": { "line": 11, "column": 71 } }, "declarations": [ { "type": "VariableDeclarator", "start": 272, "end": 329, "loc": { "start": { "line": 11, "column": 13 }, "end": { "line": 11, "column": 70 } }, "id": { "type": "Identifier", "start": 272, "end": 291, "loc": { "start": { "line": 11, "column": 13 }, "end": { "line": 11, "column": 32 }, "identifierName": "normalizeSeederName" }, "name": "normalizeSeederName", "leadingComments": null }, "init": { "type": "ArrowFunctionExpression", "start": 294, "end": 329, "loc": { "start": { "line": 11, "column": 35 }, "end": { "line": 11, "column": 70 } }, "id": { "type": "Identifier", "start": 272, "end": 291, "loc": { "start": { "line": 11, "column": 13 }, "end": { "line": 11, "column": 32 }, "identifierName": "normalizeSeederName" }, "name": "normalizeSeederName", "leadingComments": null }, "generator": false, "expression": true, "async": false, "params": [ { "type": "Identifier", "start": 294, "end": 298, "loc": { "start": { "line": 11, "column": 35 }, "end": { "line": 11, "column": 39 }, "identifierName": "name" }, "name": "name" } ], "body": { "type": "CallExpression", "start": 302, "end": 329, "loc": { "start": { "line": 11, "column": 43 }, "end": { "line": 11, "column": 70 } }, "callee": { "type": "Identifier", "start": 302, "end": 312, "loc": { "start": { "line": 11, "column": 43 }, "end": { "line": 11, "column": 53 }, "identifierName": "upperFirst" }, "name": "upperFirst" }, "arguments": [ { "type": "CallExpression", "start": 313, "end": 328, "loc": { "start": { "line": 11, "column": 54 }, "end": { "line": 11, "column": 69 } }, "callee": { "type": "Identifier", "start": 313, "end": 322, "loc": { "start": { "line": 11, "column": 54 }, "end": { "line": 11, "column": 63 }, "identifierName": "camelCase" }, "name": "camelCase" }, "arguments": [ { "type": "Identifier", "start": 323, "end": 327, "loc": { "start": { "line": 11, "column": 64 }, "end": { "line": 11, "column": 68 }, "identifierName": "name" }, "name": "name" } ] } ] } }, "leadingComments": null } ], "kind": "const", "leadingComments": [ { "type": "CommentBlock", "value": "*\n * Normalize seeder name.\n * @param {string} name seeder name\n * @return {string} normalized seeder name\n ", "start": 140, "end": 258, "loc": { "start": { "line": 6, "column": 0 }, "end": { "line": 10, "column": 3 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * Normalize seeder filename.\n * @param {string} name seeder name\n * @return {string} normalized seeder filename\n ", "start": 331, "end": 457, "loc": { "start": { "line": 12, "column": 0 }, "end": { "line": 16, "column": 3 } } } ] }, "leadingComments": [ { "type": "CommentBlock", "value": "*\n * Normalize seeder name.\n * @param {string} name seeder name\n * @return {string} normalized seeder name\n ", "start": 140, "end": 258, "loc": { "start": { "line": 6, "column": 0 }, "end": { "line": 10, "column": 3 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * Normalize seeder filename.\n * @param {string} name seeder name\n * @return {string} normalized seeder filename\n ", "start": 331, "end": 457, "loc": { "start": { "line": 12, "column": 0 }, "end": { "line": 16, "column": 3 } } } ] }, { "type": "ExportNamedDeclaration", "start": 458, "end": 536, "loc": { "start": { "line": 17, "column": 0 }, "end": { "line": 17, "column": 78 } }, "specifiers": [], "source": null, "declaration": { "type": "VariableDeclaration", "start": 465, "end": 536, "loc": { "start": { "line": 17, "column": 7 }, "end": { "line": 17, "column": 78 } }, "declarations": [ { "type": "VariableDeclarator", "start": 471, "end": 535, "loc": { "start": { "line": 17, "column": 13 }, "end": { "line": 17, "column": 77 } }, "id": { "type": "Identifier", "start": 471, "end": 494, "loc": { "start": { "line": 17, "column": 13 }, "end": { "line": 17, "column": 36 }, "identifierName": "normalizeSeederFileName" }, "name": "normalizeSeederFileName", "leadingComments": null }, "init": { "type": "ArrowFunctionExpression", "start": 497, "end": 535, "loc": { "start": { "line": 17, "column": 39 }, "end": { "line": 17, "column": 77 } }, "id": { "type": "Identifier", "start": 471, "end": 494, "loc": { "start": { "line": 17, "column": 13 }, "end": { "line": 17, "column": 36 }, "identifierName": "normalizeSeederFileName" }, "name": "normalizeSeederFileName", "leadingComments": null }, "generator": false, "expression": true, "async": false, "params": [ { "type": "Identifier", "start": 497, "end": 501, "loc": { "start": { "line": 17, "column": 39 }, "end": { "line": 17, "column": 43 }, "identifierName": "name" }, "name": "name" } ], "body": { "type": "TemplateLiteral", "start": 505, "end": 535, "loc": { "start": { "line": 17, "column": 47 }, "end": { "line": 17, "column": 77 } }, "expressions": [ { "type": "CallExpression", "start": 508, "end": 523, "loc": { "start": { "line": 17, "column": 50 }, "end": { "line": 17, "column": 65 } }, "callee": { "type": "Identifier", "start": 508, "end": 517, "loc": { "start": { "line": 17, "column": 50 }, "end": { "line": 17, "column": 59 }, "identifierName": "kebabCase" }, "name": "kebabCase" }, "arguments": [ { "type": "Identifier", "start": 518, "end": 522, "loc": { "start": { "line": 17, "column": 60 }, "end": { "line": 17, "column": 64 }, "identifierName": "name" }, "name": "name" } ] } ], "quasis": [ { "type": "TemplateElement", "start": 506, "end": 506, "loc": { "start": { "line": 17, "column": 48 }, "end": { "line": 17, "column": 48 } }, "value": { "raw": "", "cooked": "" }, "tail": false }, { "type": "TemplateElement", "start": 524, "end": 534, "loc": { "start": { "line": 17, "column": 66 }, "end": { "line": 17, "column": 76 } }, "value": { "raw": ".seeder.js", "cooked": ".seeder.js" }, "tail": true } ] } }, "leadingComments": null } ], "kind": "const", "leadingComments": [ { "type": "CommentBlock", "value": "*\n * Normalize seeder filename.\n * @param {string} name seeder name\n * @return {string} normalized seeder filename\n ", "start": 331, "end": 457, "loc": { "start": { "line": 12, "column": 0 }, "end": { "line": 16, "column": 3 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * Get folder name from given path.\n * @param {string} path path\n * @return {string} folder name\n ", "start": 537, "end": 647, "loc": { "start": { "line": 18, "column": 0 }, "end": { "line": 22, "column": 3 } } } ] }, "leadingComments": [ { "type": "CommentBlock", "value": "*\n * Normalize seeder filename.\n * @param {string} name seeder name\n * @return {string} normalized seeder filename\n ", "start": 331, "end": 457, "loc": { "start": { "line": 12, "column": 0 }, "end": { "line": 16, "column": 3 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * Get folder name from given path.\n * @param {string} path path\n * @return {string} folder name\n ", "start": 537, "end": 647, "loc": { "start": { "line": 18, "column": 0 }, "end": { "line": 22, "column": 3 } } } ] }, { "type": "ExportNamedDeclaration", "start": 648, "end": 737, "loc": { "start": { "line": 23, "column": 0 }, "end": { "line": 24, "column": 44 } }, "specifiers": [], "source": null, "declaration": { "type": "VariableDeclaration", "start": 655, "end": 737, "loc": { "start": { "line": 23, "column": 7 }, "end": { "line": 24, "column": 44 } }, "declarations": [ { "type": "VariableDeclarator", "start": 661, "end": 736, "loc": { "start": { "line": 23, "column": 13 }, "end": { "line": 24, "column": 43 } }, "id": { "type": "Identifier", "start": 661, "end": 682, "loc": { "start": { "line": 23, "column": 13 }, "end": { "line": 23, "column": 34 }, "identifierName": "getFolderNameFromPath" }, "name": "getFolderNameFromPath", "leadingComments": null }, "init": { "type": "ArrowFunctionExpression", "start": 685, "end": 736, "loc": { "start": { "line": 23, "column": 37 }, "end": { "line": 24, "column": 43 } }, "id": { "type": "Identifier", "start": 661, "end": 682, "loc": { "start": { "line": 23, "column": 13 }, "end": { "line": 23, "column": 34 }, "identifierName": "getFolderNameFromPath" }, "name": "getFolderNameFromPath", "leadingComments": null }, "generator": false, "expression": true, "async": false, "params": [ { "type": "Identifier", "start": 685, "end": 689, "loc": { "start": { "line": 23, "column": 37 }, "end": { "line": 23, "column": 41 }, "identifierName": "path" }, "name": "path" } ], "body": { "type": "CallExpression", "start": 695, "end": 736, "loc": { "start": { "line": 24, "column": 2 }, "end": { "line": 24, "column": 43 } }, "callee": { "type": "MemberExpression", "start": 695, "end": 709, "loc": { "start": { "line": 24, "column": 2 }, "end": { "line": 24, "column": 16 } }, "object": { "type": "Identifier", "start": 695, "end": 699, "loc": { "start": { "line": 24, "column": 2 }, "end": { "line": 24, "column": 6 }, "identifierName": "path" }, "name": "path" }, "property": { "type": "Identifier", "start": 700, "end": 709, "loc": { "start": { "line": 24, "column": 7 }, "end": { "line": 24, "column": 16 }, "identifierName": "substring" }, "name": "substring" }, "computed": false }, "arguments": [ { "type": "BinaryExpression", "start": 710, "end": 735, "loc": { "start": { "line": 24, "column": 17 }, "end": { "line": 24, "column": 42 } }, "left": { "type": "CallExpression", "start": 710, "end": 731, "loc": { "start": { "line": 24, "column": 17 }, "end": { "line": 24, "column": 38 } }, "callee": { "type": "MemberExpression", "start": 710, "end": 726, "loc": { "start": { "line": 24, "column": 17 }, "end": { "line": 24, "column": 33 } }, "object": { "type": "Identifier", "start": 710, "end": 714, "loc": { "start": { "line": 24, "column": 17 }, "end": { "line": 24, "column": 21 }, "identifierName": "path" }, "name": "path" }, "property": { "type": "Identifier", "start": 715, "end": 726, "loc": { "start": { "line": 24, "column": 22 }, "end": { "line": 24, "column": 33 }, "identifierName": "lastIndexOf" }, "name": "lastIndexOf" }, "computed": false }, "arguments": [ { "type": "StringLiteral", "start": 727, "end": 730, "loc": { "start": { "line": 24, "column": 34 }, "end": { "line": 24, "column": 37 } }, "extra": { "rawValue": "/", "raw": "'/'" }, "value": "/" } ] }, "operator": "+", "right": { "type": "NumericLiteral", "start": 734, "end": 735, "loc": { "start": { "line": 24, "column": 41 }, "end": { "line": 24, "column": 42 } }, "extra": { "rawValue": 1, "raw": "1" }, "value": 1 } } ] } }, "leadingComments": null } ], "kind": "const", "leadingComments": [ { "type": "CommentBlock", "value": "*\n * Get folder name from given path.\n * @param {string} path path\n * @return {string} folder name\n ", "start": 537, "end": 647, "loc": { "start": { "line": 18, "column": 0 }, "end": { "line": 22, "column": 3 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * Get object with selected keys from a given object.\n * @param {Object} obj Object\n * @param {string[]} keys Keys to get from the given object.\n * @return {Object} new object with the selected keys.\n ", "start": 738, "end": 950, "loc": { "start": { "line": 25, "column": 0 }, "end": { "line": 30, "column": 3 } } } ] }, "leadingComments": [ { "type": "CommentBlock", "value": "*\n * Get folder name from given path.\n * @param {string} path path\n * @return {string} folder name\n ", "start": 537, "end": 647, "loc": { "start": { "line": 18, "column": 0 }, "end": { "line": 22, "column": 3 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * Get object with selected keys from a given object.\n * @param {Object} obj Object\n * @param {string[]} keys Keys to get from the given object.\n * @return {Object} new object with the selected keys.\n ", "start": 738, "end": 950, "loc": { "start": { "line": 25, "column": 0 }, "end": { "line": 30, "column": 3 } } } ] }, { "type": "ExportNamedDeclaration", "start": 951, "end": 1151, "loc": { "start": { "line": 31, "column": 0 }, "end": { "line": 41, "column": 2 } }, "specifiers": [], "source": null, "declaration": { "type": "VariableDeclaration", "start": 958, "end": 1151, "loc": { "start": { "line": 31, "column": 7 }, "end": { "line": 41, "column": 2 } }, "declarations": [ { "type": "VariableDeclarator", "start": 964, "end": 1150, "loc": { "start": { "line": 31, "column": 13 }, "end": { "line": 41, "column": 1 } }, "id": { "type": "Identifier", "start": 964, "end": 989, "loc": { "start": { "line": 31, "column": 13 }, "end": { "line": 31, "column": 38 }, "identifierName": "getObjectWithSelectedKeys" }, "name": "getObjectWithSelectedKeys", "leadingComments": null }, "init": { "type": "ArrowFunctionExpression", "start": 992, "end": 1150, "loc": { "start": { "line": 31, "column": 41 }, "end": { "line": 41, "column": 1 } }, "id": { "type": "Identifier", "start": 964, "end": 989, "loc": { "start": { "line": 31, "column": 13 }, "end": { "line": 31, "column": 38 }, "identifierName": "getObjectWithSelectedKeys" }, "name": "getObjectWithSelectedKeys", "leadingComments": null }, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 993, "end": 996, "loc": { "start": { "line": 31, "column": 42 }, "end": { "line": 31, "column": 45 }, "identifierName": "obj" }, "name": "obj" }, { "type": "Identifier", "start": 998, "end": 1002, "loc": { "start": { "line": 31, "column": 47 }, "end": { "line": 31, "column": 51 }, "identifierName": "keys" }, "name": "keys" } ], "body": { "type": "BlockStatement", "start": 1007, "end": 1150, "loc": { "start": { "line": 31, "column": 56 }, "end": { "line": 41, "column": 1 } }, "body": [ { "type": "VariableDeclaration", "start": 1011, "end": 1029, "loc": { "start": { "line": 32, "column": 2 }, "end": { "line": 32, "column": 20 } }, "declarations": [ { "type": "VariableDeclarator", "start": 1017, "end": 1028, "loc": { "start": { "line": 32, "column": 8 }, "end": { "line": 32, "column": 19 } }, "id": { "type": "Identifier", "start": 1017, "end": 1023, "loc": { "start": { "line": 32, "column": 8 }, "end": { "line": 32, "column": 14 }, "identifierName": "newObj" }, "name": "newObj" }, "init": { "type": "ObjectExpression", "start": 1026, "end": 1028, "loc": { "start": { "line": 32, "column": 17 }, "end": { "line": 32, "column": 19 } }, "properties": [] } } ], "kind": "const" }, { "type": "ExpressionStatement", "start": 1033, "end": 1130, "loc": { "start": { "line": 34, "column": 2 }, "end": { "line": 38, "column": 5 } }, "expression": { "type": "CallExpression", "start": 1033, "end": 1129, "loc": { "start": { "line": 34, "column": 2 }, "end": { "line": 38, "column": 4 } }, "callee": { "type": "MemberExpression", "start": 1033, "end": 1057, "loc": { "start": { "line": 34, "column": 2 }, "end": { "line": 34, "column": 26 } }, "object": { "type": "CallExpression", "start": 1033, "end": 1049, "loc": { "start": { "line": 34, "column": 2 }, "end": { "line": 34, "column": 18 } }, "callee": { "type": "MemberExpression", "start": 1033, "end": 1044, "loc": { "start": { "line": 34, "column": 2 }, "end": {