UNPKG

mongoose-data-seed

Version:

Seed mongodb with data using mongoose models

1,437 lines (1,436 loc) 346 kB
{ "type": "File", "start": 0, "end": 3342, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 149, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 3342, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 149, "column": 0 } }, "sourceType": "module", "body": [ { "type": "Identifier", "start": 860, "end": 3317, "loc": { "start": { "line": 41, "column": 0 }, "end": { "line": 146, "column": 1 } }, "id": { "type": "Identifier", "start": 866, "end": 872, "loc": { "start": { "line": 41, "column": 6 }, "end": { "line": 41, "column": 12 }, "identifierName": "Seeder" }, "name": "Seeder", "leadingComments": null }, "superClass": null, "body": { "type": "ClassBody", "start": 873, "end": 3317, "loc": { "start": { "line": 41, "column": 13 }, "end": { "line": 146, "column": 1 } }, "body": [ { "type": "ClassMethod", "start": 1125, "end": 1372, "loc": { "start": { "line": 49, "column": 2 }, "end": { "line": 56, "column": 3 } }, "static": false, "computed": false, "key": { "type": "Identifier", "start": 1125, "end": 1136, "loc": { "start": { "line": 49, "column": 2 }, "end": { "line": 49, "column": 13 }, "identifierName": "constructor" }, "name": "constructor", "leadingComments": null }, "kind": "constructor", "id": null, "generator": false, "expression": false, "async": false, "params": [], "body": { "type": "BlockStatement", "start": 1139, "end": 1372, "loc": { "start": { "line": 49, "column": 16 }, "end": { "line": 56, "column": 3 } }, "body": [ { "type": "IfStatement", "start": 1145, "end": 1249, "loc": { "start": { "line": 50, "column": 4 }, "end": { "line": 52, "column": 5 } }, "test": { "type": "BinaryExpression", "start": 1149, "end": 1176, "loc": { "start": { "line": 50, "column": 8 }, "end": { "line": 50, "column": 35 } }, "left": { "type": "MemberExpression", "start": 1149, "end": 1165, "loc": { "start": { "line": 50, "column": 8 }, "end": { "line": 50, "column": 24 } }, "object": { "type": "ThisExpression", "start": 1149, "end": 1153, "loc": { "start": { "line": 50, "column": 8 }, "end": { "line": 50, "column": 12 } } }, "property": { "type": "Identifier", "start": 1154, "end": 1165, "loc": { "start": { "line": 50, "column": 13 }, "end": { "line": 50, "column": 24 }, "identifierName": "constructor" }, "name": "constructor" }, "computed": false }, "operator": "===", "right": { "type": "Identifier", "start": 1170, "end": 1176, "loc": { "start": { "line": 50, "column": 29 }, "end": { "line": 50, "column": 35 }, "identifierName": "Seeder" }, "name": "Seeder" } }, "consequent": { "type": "BlockStatement", "start": 1178, "end": 1249, "loc": { "start": { "line": 50, "column": 37 }, "end": { "line": 52, "column": 5 } }, "body": [ { "type": "ThrowStatement", "start": 1186, "end": 1243, "loc": { "start": { "line": 51, "column": 6 }, "end": { "line": 51, "column": 63 } }, "argument": { "type": "NewExpression", "start": 1192, "end": 1242, "loc": { "start": { "line": 51, "column": 12 }, "end": { "line": 51, "column": 62 } }, "callee": { "type": "Identifier", "start": 1196, "end": 1205, "loc": { "start": { "line": 51, "column": 16 }, "end": { "line": 51, "column": 25 }, "identifierName": "TypeError" }, "name": "TypeError" }, "arguments": [ { "type": "StringLiteral", "start": 1206, "end": 1241, "loc": { "start": { "line": 51, "column": 26 }, "end": { "line": 51, "column": 61 } }, "extra": { "rawValue": "Can not construct abstract class.", "raw": "'Can not construct abstract class.'" }, "value": "Can not construct abstract class." } ] } } ], "directives": [] }, "alternate": null }, { "type": "IfStatement", "start": 1254, "end": 1368, "loc": { "start": { "line": 53, "column": 4 }, "end": { "line": 55, "column": 5 } }, "test": { "type": "BinaryExpression", "start": 1258, "end": 1291, "loc": { "start": { "line": 53, "column": 8 }, "end": { "line": 53, "column": 41 } }, "left": { "type": "MemberExpression", "start": 1258, "end": 1266, "loc": { "start": { "line": 53, "column": 8 }, "end": { "line": 53, "column": 16 } }, "object": { "type": "ThisExpression", "start": 1258, "end": 1262, "loc": { "start": { "line": 53, "column": 8 }, "end": { "line": 53, "column": 12 } } }, "property": { "type": "Identifier", "start": 1263, "end": 1266, "loc": { "start": { "line": 53, "column": 13 }, "end": { "line": 53, "column": 16 }, "identifierName": "run" }, "name": "run" }, "computed": false }, "operator": "===", "right": { "type": "MemberExpression", "start": 1271, "end": 1291, "loc": { "start": { "line": 53, "column": 21 }, "end": { "line": 53, "column": 41 } }, "object": { "type": "MemberExpression", "start": 1271, "end": 1287, "loc": { "start": { "line": 53, "column": 21 }, "end": { "line": 53, "column": 37 } }, "object": { "type": "Identifier", "start": 1271, "end": 1277, "loc": { "start": { "line": 53, "column": 21 }, "end": { "line": 53, "column": 27 }, "identifierName": "Seeder" }, "name": "Seeder" }, "property": { "type": "Identifier", "start": 1278, "end": 1287, "loc": { "start": { "line": 53, "column": 28 }, "end": { "line": 53, "column": 37 }, "identifierName": "prototype" }, "name": "prototype" }, "computed": false }, "property": { "type": "Identifier", "start": 1288, "end": 1291, "loc": { "start": { "line": 53, "column": 38 }, "end": { "line": 53, "column": 41 }, "identifierName": "run" }, "name": "run" }, "computed": false } }, "consequent": { "type": "BlockStatement", "start": 1293, "end": 1368, "loc": { "start": { "line": 53, "column": 43 }, "end": { "line": 55, "column": 5 } }, "body": [ { "type": "ThrowStatement", "start": 1301, "end": 1362, "loc": { "start": { "line": 54, "column": 6 }, "end": { "line": 54, "column": 67 } }, "argument": { "type": "NewExpression", "start": 1307, "end": 1361, "loc": { "start": { "line": 54, "column": 12 }, "end": { "line": 54, "column": 66 } }, "callee": { "type": "Identifier", "start": 1311, "end": 1320, "loc": { "start": { "line": 54, "column": 16 }, "end": { "line": 54, "column": 25 }, "identifierName": "TypeError" }, "name": "TypeError" }, "arguments": [ { "type": "StringLiteral", "start": 1321, "end": 1360, "loc": { "start": { "line": 54, "column": 26 }, "end": { "line": 54, "column": 65 } }, "extra": { "rawValue": "Please implement abstract method run.", "raw": "'Please implement abstract method run.'" }, "value": "Please implement abstract method run." } ] } } ], "directives": [] }, "alternate": null } ], "directives": [], "trailingComments": null }, "leadingComments": [ { "type": "CommentBlock", "value": "*\n * Abstract class can not be constructed.\n * Seeder class should be extended.\n * @abstract\n * @throws {TypeError} when creating an instance of the abstract class.\n * @throws {TypeError} when the run method is not implemented.\n ", "start": 877, "end": 1122, "loc": { "start": { "line": 42, "column": 2 }, "end": { "line": 48, "column": 5 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * Seed the data.\n * @return {Promise} Stats about the save.\n ", "start": 1376, "end": 1450, "loc": { "start": { "line": 58, "column": 2 }, "end": { "line": 61, "column": 5 } } } ] }, { "type": "ClassMethod", "start": 1453, "end": 1635, "loc": { "start": { "line": 62, "column": 2 }, "end": { "line": 72, "column": 3 } }, "static": false, "computed": false, "key": { "type": "Identifier", "start": 1459, "end": 1463, "loc": { "start": { "line": 62, "column": 8 }, "end": { "line": 62, "column": 12 }, "identifierName": "seed" }, "name": "seed" }, "kind": "method", "id": null, "generator": false, "expression": false, "async": true, "params": [], "body": { "type": "BlockStatement", "start": 1466, "end": 1635, "loc": { "start": { "line": 62, "column": 15 }, "end": { "line": 72, "column": 3 } }, "body": [ { "type": "ExpressionStatement", "start": 1472, "end": 1495, "loc": { "start": { "line": 63, "column": 4 }, "end": { "line": 63, "column": 27 } }, "expression": { "type": "AwaitExpression", "start": 1472, "end": 1494, "loc": { "start": { "line": 63, "column": 4 }, "end": { "line": 63, "column": 26 } }, "argument": { "type": "CallExpression", "start": 1478, "end": 1494, "loc": { "start": { "line": 63, "column": 10 }, "end": { "line": 63, "column": 26 } }, "callee": { "type": "MemberExpression", "start": 1478, "end": 1492, "loc": { "start": { "line": 63, "column": 10 }, "end": { "line": 63, "column": 24 } }, "object": { "type": "ThisExpression", "start": 1478, "end": 1482, "loc": { "start": { "line": 63, "column": 10 }, "end": { "line": 63, "column": 14 } } }, "property": { "type": "Identifier", "start": 1483, "end": 1492, "loc": { "start": { "line": 63, "column": 15 }, "end": { "line": 63, "column": 24 }, "identifierName": "beforeRun" }, "name": "beforeRun" }, "computed": false }, "arguments": [] } } }, { "type": "VariableDeclaration", "start": 1501, "end": 1520, "loc": { "start": { "line": 65, "column": 4 }, "end": { "line": 65, "column": 23 } }, "declarations": [ { "type": "VariableDeclarator", "start": 1505, "end": 1519, "loc": { "start": { "line": 65, "column": 8 }, "end": { "line": 65, "column": 22 } }, "id": { "type": "Identifier", "start": 1505, "end": 1512, "loc": { "start": { "line": 65, "column": 8 }, "end": { "line": 65, "column": 15 }, "identifierName": "results" }, "name": "results" }, "init": { "type": "NullLiteral", "start": 1515, "end": 1519, "loc": { "start": { "line": 65, "column": 18 }, "end": { "line": 65, "column": 22 } } } } ], "kind": "let" }, { "type": "IfStatement", "start": 1526, "end": 1595, "loc": { "start": { "line": 67, "column": 4 }, "end": { "line": 69, "column": 5 } }, "test": { "type": "AwaitExpression", "start": 1530, "end": 1552, "loc": { "start": { "line": 67, "column": 8 }, "end": { "line": 67, "column": 30 } }, "argument": { "type": "CallExpression", "start": 1536, "end": 1552, "loc": { "start": { "line": 67, "column": 14 }, "end": { "line": 67, "column": 30 } }, "callee": { "type": "MemberExpression", "start": 1536, "end": 1550, "loc": { "start": { "line": 67, "column": 14 }, "end": { "line": 67, "column": 28 } }, "object": { "type": "ThisExpression", "start": 1536, "end": 1540, "loc": { "start": { "line": 67, "column": 14 }, "end": { "line": 67, "column": 18 } } }, "property": { "type": "Identifier", "start": 1541, "end": 1550, "loc": { "start": { "line": 67, "column": 19 }, "end": { "line": 67, "column": 28 }, "identifierName": "shouldRun" }, "name": "shouldRun" }, "computed": false }, "arguments": [] } }, "consequent": { "type": "BlockStatement", "start": 1554, "end": 1595, "loc": { "start": { "line": 67, "column": 32 }, "end": { "line": 69, "column": 5 } }, "body": [ { "type": "ExpressionStatement", "start": 1562, "end": 1589, "loc": { "start": { "line": 68, "column": 6 }, "end": { "line": 68, "column": 33 } }, "expression": { "type": "AssignmentExpression", "start": 1562, "end": 1588, "loc": { "start": { "line": 68, "column": 6 }, "end": { "line": 68, "column": 32 } }, "operator": "=", "left": { "type": "Identifier", "start": 1562, "end": 1569, "loc": { "start": { "line": 68, "column": 6 }, "end": { "line": 68, "column": 13 }, "identifierName": "results" }, "name": "results" }, "right": { "type": "AwaitExpression", "start": 1572, "end": 1588, "loc": { "start": { "line": 68, "column": 16 }, "end": { "line": 68, "column": 32 } }, "argument": { "type": "CallExpression", "start": 1578, "end": 1588, "loc": { "start": { "line": 68, "column": 22 }, "end": { "line": 68, "column": 32 } }, "callee": { "type": "MemberExpression", "start": 1578, "end": 1586, "loc": { "start": { "line": 68, "column": 22 }, "end": { "line": 68, "column": 30 } }, "object": { "type": "ThisExpression", "start": 1578, "end": 1582, "loc": { "start": { "line": 68, "column": 22 }, "end": { "line": 68, "column": 26 } } }, "property": { "type": "Identifier", "start": 1583, "end": 1586, "loc": { "start": { "line": 68, "column": 27 }, "end": { "line": 68, "column": 30 }, "identifierName": "run" }, "name": "run" }, "computed": false }, "arguments": [] } } } } ], "directives": [] }, "alternate": null }, { "type": "ReturnStatement", "start": 1601, "end": 1631, "loc": { "start": { "line": 71, "column": 4 }, "end": { "line": 71, "column": 34 } }, "argument": { "type": "CallExpression", "start": 1608, "end": 1630, "loc": { "start": { "line": 71, "column": 11 }, "end": { "line": 71, "column": 33 } }, "callee": { "type": "MemberExpression", "start": 1608, "end": 1621, "loc": { "start": { "line": 71, "column": 11 }, "end": { "line": 71, "column": 24 } }, "object": { "type": "ThisExpression", "start": 1608, "end": 1612, "loc": { "start": { "line": 71, "column": 11 }, "end": { "line": 71, "column": 15 } } }, "property": { "type": "Identifier", "start": 1613, "end": 1621, "loc": { "start": { "line": 71, "column": 16 }, "end": { "line": 71, "column": 24 }, "identifierName": "getStats" }, "name": "getStats" }, "computed": false }, "arguments": [ { "type": "Identifier", "start": 1622, "end": 1629, "loc": { "start": { "line": 71, "column": 25 }, "end": { "line": 71, "column": 32 }, "identifierName": "results" }, "name": "results" } ] } } ], "directives": [], "trailingComments": null }, "leadingComments": [ { "type": "CommentBlock", "value": "*\n * Seed the data.\n * @return {Promise} Stats about the save.\n ", "start": 1376, "end": 1450, "loc": { "start": { "line": 58, "column": 2 }, "end": { "line": 61, "column": 5 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * Should run\n * @return {Promise<boolean>} Indication if should run\n * @abstract\n ", "start": 1639, "end": 1736, "loc": { "start": { "line": 74, "column": 2 }, "end": { "line": 78, "column": 5 } } } ] }, { "type": "ClassMethod", "start": 1739, "end": 1779, "loc": { "start": { "line": 79, "column": 2 }, "end": { "line": 81, "column": 3 } }, "static": false, "computed": false, "key": { "type": "Identifier", "start": 1745, "end": 1754, "loc": { "start": { "line": 79, "column": 8 }, "end": { "line": 79, "column": 17 }, "identifierName": "shouldRun" }, "name": "shouldRun" }, "kind": "method", "id": null, "generator": false, "expression": false, "async": true, "params": [], "body": { "type": "BlockStatement", "start": 1757, "end": 1779, "loc": { "start": { "line": 79, "column": 20 }, "end": { "line": 81, "column": 3 } }, "body": [ { "type": "ReturnStatement", "start": 1763, "end": 1775, "loc": { "start": { "line": 80, "column": 4 }, "end": { "line": 80, "column": 16 } }, "argument": { "type": "BooleanLiteral", "start": 1770, "end": 1774, "loc": { "start": { "line": 80, "column": 11 }, "end": { "line": 80, "column": 15 } }, "value": true } } ], "directives": [], "trailingComments": null }, "leadingComments": [ { "type": "CommentBlock", "value": "*\n * Should run\n * @return {Promise<boolean>} Indication if should run\n * @abstract\n ", "start": 1639, "end": 1736, "loc": { "start": { "line": 74, "column": 2 }, "end": { "line": 78, "column": 5 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * To perform before run.\n * @return {Promise}\n * @abstract\n ", "start": 1783, "end": 1858, "loc": { "start": { "line": 83, "column": 2 }, "end": { "line": 87, "column": 5 } } } ] }, { "type": "ClassMethod", "start": 1861, "end": 1881, "loc": { "start": { "line": 88, "column": 2 }, "end": { "line": 88, "column": 22 } }, "static": false, "computed": false, "key": { "type": "Identifier", "start": 1867, "end": 1876, "loc": { "start": { "line": 88, "column": 8 }, "end": { "line": 88, "column": 17 }, "identifierName": "beforeRun" }, "name": "beforeRun" }, "kind": "method", "id": null, "generator": false, "expression": false, "async": true, "params": [], "body": { "type": "BlockStatement", "start": 1879, "end": 1881, "loc": { "start": { "line": 88, "column": 20 }, "end": { "line": 88, "column": 22 } }, "body": [], "directives": [], "leadingComments": null, "trailingComments": null }, "leadingComments": [ { "type": "CommentBlock", "value": "*\n * To perform before run.\n * @return {Promise}\n * @abstract\n ", "start": 1783, "end": 1858, "loc": { "start": { "line": 83, "column": 2 }, "end": { "line": 87, "column": 5 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * Run the seeder.\n * @abstract\n ", "start": 1885, "end": 1930, "loc": { "start": { "line": 90, "column": 2 }, "end": { "line": 93, "column": 5 } } } ] }, { "type": "ClassMethod", "start": 1933, "end": 2054, "loc": { "start": { "line": 94, "column": 2 }, "end": { "line": 98, "column": 3 } }, "static": false, "computed": false,