mock-config-server 3.4.0 → 3.5.0
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/bin/bin.js +5 -8
- package/dist/bin/build.js +52 -50
- package/dist/bin/cli.js +50 -43
- package/dist/bin/helpers/createTemplate.js +29 -21
- package/dist/bin/helpers/getMostSpecificPathFromError.js +34 -30
- package/dist/bin/helpers/getValidationMessageFromPath.js +11 -8
- package/dist/bin/helpers/index.js +21 -79
- package/dist/bin/helpers/isOnlyRequestedDataResolvingPropertyExists.js +13 -6
- package/dist/bin/helpers/resolveConfigFile.js +22 -19
- package/dist/bin/helpers/resolveConfigFilePath.js +19 -12
- package/dist/bin/helpers/resolveExportsFromSourceCode.js +13 -10
- package/dist/bin/init.js +114 -97
- package/dist/bin/run.js +42 -37
- package/dist/bin/templates/js/full/mock-server.config.js +16 -16
- package/dist/bin/templates/js/graphql/mock-server.config.js +9 -9
- package/dist/bin/templates/js/rest/mock-server.config.js +9 -9
- package/dist/bin/templates/ts/full/mock-requests/graphql/index.ts +2 -2
- package/dist/bin/templates/ts/full/mock-requests/graphql/user.ts +37 -37
- package/dist/bin/templates/ts/full/mock-requests/graphql/users.ts +14 -14
- package/dist/bin/templates/ts/full/mock-requests/rest/index.ts +2 -2
- package/dist/bin/templates/ts/full/mock-requests/rest/user.ts +37 -37
- package/dist/bin/templates/ts/full/mock-requests/rest/users.ts +14 -14
- package/dist/bin/templates/ts/full/mock-server.config.ts +18 -18
- package/dist/bin/templates/ts/graphql/mock-requests/index.ts +2 -2
- package/dist/bin/templates/ts/graphql/mock-requests/user.ts +37 -37
- package/dist/bin/templates/ts/graphql/mock-requests/users.ts +14 -14
- package/dist/bin/templates/ts/graphql/mock-server.config.ts +11 -11
- package/dist/bin/templates/ts/rest/mock-requests/index.ts +2 -2
- package/dist/bin/templates/ts/rest/mock-requests/user.ts +37 -37
- package/dist/bin/templates/ts/rest/mock-requests/users.ts +14 -14
- package/dist/bin/templates/ts/rest/mock-server.config.ts +11 -11
- package/dist/bin/validateMockServerConfig/baseUrlSchema/baseUrlSchema.js +9 -5
- package/dist/bin/validateMockServerConfig/corsSchema/corsSchema.js +32 -14
- package/dist/bin/validateMockServerConfig/databaseConfigSchema/databaseConfigSchema.js +19 -9
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.js +38 -22
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.js +38 -28
- package/dist/bin/validateMockServerConfig/interceptorsSchema/interceptorsSchema.js +12 -8
- package/dist/bin/validateMockServerConfig/portSchema/portSchema.js +9 -5
- package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.js +18 -9
- package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.js +33 -19
- package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.js +62 -48
- package/dist/bin/validateMockServerConfig/settingsSchema/settingsSchema.js +13 -9
- package/dist/bin/validateMockServerConfig/staticPathSchema/staticPathSchema.js +19 -9
- package/dist/bin/validateMockServerConfig/utils/checkModeSchema/checkModeSchema.js +27 -9
- package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.js +117 -60
- package/dist/bin/validateMockServerConfig/utils/index.js +20 -68
- package/dist/bin/validateMockServerConfig/utils/jsonSchema/jsonSchema.js +30 -10
- package/dist/bin/validateMockServerConfig/utils/plainObjectSchema/plainObjectSchema.js +9 -8
- package/dist/bin/validateMockServerConfig/utils/requiredPropertiesSchema/requiredPropertiesSchema.js +10 -7
- package/dist/bin/validateMockServerConfig/utils/sharedSchema/sharedSchema.js +18 -6
- package/dist/bin/validateMockServerConfig/validateApiMockServerConfig.js +43 -40
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +38 -35
- package/dist/index.js +15 -13
- package/dist/src/core/database/createDatabaseRoutes/createDatabaseRoutes.js +25 -28
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.js +14 -11
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/findIndexById/findIndexById.js +8 -5
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/index.js +17 -35
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/isIndex/isIndex.js +8 -5
- package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.js +157 -143
- package/dist/src/core/database/createDatabaseRoutes/helpers/createRewrittenDatabaseRoutes/createRewrittenDatabaseRoutes.js +15 -8
- package/dist/src/core/database/createDatabaseRoutes/helpers/createShallowDatabaseRoutes/createShallowDatabaseRoutes.js +88 -94
- package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.js +44 -47
- package/dist/src/core/database/createDatabaseRoutes/helpers/index.js +19 -57
- package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.js +32 -31
- package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.js +34 -24
- package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.js +38 -34
- package/dist/src/core/database/createDatabaseRoutes/helpers/splitDatabaseByNesting/splitDatabaseByNesting.js +26 -25
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.js +65 -50
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.js +55 -48
- package/dist/src/core/database/createDatabaseRoutes/storages/Memory/MemoryStorage.js +51 -41
- package/dist/src/core/database/createDatabaseRoutes/storages/index.js +16 -24
- package/dist/src/core/database/index.js +15 -13
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +126 -140
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/index.js +15 -13
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +36 -41
- package/dist/src/core/graphql/index.js +15 -13
- package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.js +16 -13
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/index.js +15 -13
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.js +18 -15
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.js +50 -47
- package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.js +17 -12
- package/dist/src/core/middlewares/corsMiddleware/helpers/index.js +15 -13
- package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.js +23 -20
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.js +23 -17
- package/dist/src/core/middlewares/index.js +23 -91
- package/dist/src/core/middlewares/noCorsMiddleware/noCorsMiddleware.js +22 -19
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +21 -23
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.js +80 -80
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.js +34 -34
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.js +8 -5
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.js +8 -5
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/index.js +16 -24
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/index.js +17 -35
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +58 -60
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +16 -17
- package/dist/src/core/middlewares/staticMiddleware/staticMiddleware.js +32 -25
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +120 -130
- package/dist/src/core/rest/createRestRoutes/helpers/index.js +15 -13
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +37 -43
- package/dist/src/core/rest/index.js +15 -13
- package/dist/src/index.js +16 -24
- package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.js +56 -53
- package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +64 -62
- package/dist/src/server/createMockServer/createMockServer.js +94 -91
- package/dist/src/server/createRestMockServer/createRestMockServer.js +64 -62
- package/dist/src/server/index.js +23 -91
- package/dist/src/server/startDatabaseMockServer/startDatabaseMockServer.js +25 -19
- package/dist/src/server/startGraphQLMockServer/startGraphQLMockServer.js +25 -19
- package/dist/src/server/startMockServer/startMockServer.js +25 -19
- package/dist/src/server/startRestMockServer/startRestMockServer.js +25 -19
- package/dist/src/utils/constants/appPath.js +8 -4
- package/dist/src/utils/constants/checkModes.js +74 -11
- package/dist/src/utils/constants/default.js +18 -14
- package/dist/src/utils/constants/index.js +17 -35
- package/dist/src/utils/helpers/asyncHandler.js +8 -5
- package/dist/src/utils/helpers/config/index.js +15 -13
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.js +103 -110
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.js +12 -9
- package/dist/src/utils/helpers/entities/index.js +16 -24
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.js +9 -6
- package/dist/src/utils/helpers/files/index.js +15 -13
- package/dist/src/utils/helpers/files/isFilePathValid/isFilePathValid.js +22 -15
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.js +25 -29
- package/dist/src/utils/helpers/graphql/index.js +17 -35
- package/dist/src/utils/helpers/graphql/parseGraphQLRequest/parseGraphQLRequest.js +13 -10
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.js +23 -19
- package/dist/src/utils/helpers/index.js +26 -124
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.js +21 -21
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +62 -64
- package/dist/src/utils/helpers/interceptors/helpers/setDelay.js +10 -7
- package/dist/src/utils/helpers/interceptors/index.js +16 -24
- package/dist/src/utils/helpers/isPlainObject/isPlainObject.js +8 -5
- package/dist/src/utils/helpers/isPrimitive/isPrimitive.js +8 -5
- package/dist/src/utils/helpers/isRegExp/isRegExp.js +8 -5
- package/dist/src/utils/helpers/sleep.js +9 -6
- package/dist/src/utils/helpers/tests/createTmpDir.js +16 -9
- package/dist/src/utils/helpers/tests/index.js +15 -13
- package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.js +8 -5
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +9 -6
- package/dist/src/utils/helpers/url/index.js +18 -46
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +8 -5
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +18 -11
- package/dist/src/utils/types/checkModes.js +4 -1
- package/dist/src/utils/types/database.js +4 -1
- package/dist/src/utils/types/entities.js +4 -1
- package/dist/src/utils/types/graphql.js +4 -1
- package/dist/src/utils/types/index.js +24 -102
- package/dist/src/utils/types/interceptors.js +4 -1
- package/dist/src/utils/types/rest.js +4 -1
- package/dist/src/utils/types/server.js +4 -1
- package/dist/src/utils/types/utils.js +4 -1
- package/dist/src/utils/types/values.js +4 -1
- package/package.json +8 -9
- package/dist/bin/templates/.eslintrc.js +0 -14
- package/dist/bin/templates/tsconfig.json +0 -11
|
@@ -1,44 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
5
|
+
Object.defineProperty(exports, "validateApiMockServerConfig", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return validateApiMockServerConfig;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _zod = require("zod");
|
|
12
|
+
const _helpers = require("../helpers");
|
|
13
|
+
const _baseUrlSchema = require("./baseUrlSchema/baseUrlSchema");
|
|
14
|
+
const _corsSchema = require("./corsSchema/corsSchema");
|
|
15
|
+
const _databaseConfigSchema = require("./databaseConfigSchema/databaseConfigSchema");
|
|
16
|
+
const _graphqlConfigSchema = require("./graphqlConfigSchema/graphqlConfigSchema");
|
|
17
|
+
const _interceptorsSchema = require("./interceptorsSchema/interceptorsSchema");
|
|
18
|
+
const _portSchema = require("./portSchema/portSchema");
|
|
19
|
+
const _restConfigSchema = require("./restConfigSchema/restConfigSchema");
|
|
20
|
+
const _staticPathSchema = require("./staticPathSchema/staticPathSchema");
|
|
21
|
+
const _utils = require("./utils");
|
|
22
|
+
const validateApiMockServerConfig = (mockServerConfig, api)=>{
|
|
23
|
+
if (!mockServerConfig.configs && !mockServerConfig.database && !mockServerConfig.staticPath) {
|
|
24
|
+
throw new Error("Configuration should contain at least one of these configs: configs | database | staticPath; see our doc (https://github.com/siberiacancode/mock-config-server) for more information");
|
|
25
|
+
}
|
|
26
|
+
const isConfigsContainAtLeastOneElement = Array.isArray(mockServerConfig.configs) && !!mockServerConfig.configs.length;
|
|
27
|
+
const mockServerConfigSchema = _zod.z.strictObject({
|
|
28
|
+
baseUrl: _baseUrlSchema.baseUrlSchema.optional(),
|
|
29
|
+
port: _portSchema.portSchema.optional(),
|
|
30
|
+
staticPath: _staticPathSchema.staticPathSchema.optional(),
|
|
31
|
+
interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional(),
|
|
32
|
+
cors: _corsSchema.corsSchema.optional(),
|
|
33
|
+
database: _databaseConfigSchema.databaseConfigSchema.optional(),
|
|
34
|
+
...isConfigsContainAtLeastOneElement && api === "graphql" && {
|
|
35
|
+
configs: _graphqlConfigSchema.graphqlConfigSchema.shape.configs
|
|
36
|
+
},
|
|
37
|
+
...isConfigsContainAtLeastOneElement && api === "rest" && {
|
|
38
|
+
configs: _restConfigSchema.restConfigSchema.shape.configs
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const validationResult = mockServerConfigSchema.safeParse(mockServerConfig);
|
|
42
|
+
if (!validationResult.success) {
|
|
43
|
+
const path = (0, _helpers.getMostSpecificPathFromError)(validationResult.error);
|
|
44
|
+
const validationMessage = (0, _helpers.getValidationMessageFromPath)(path);
|
|
45
|
+
throw new Error(`Validation Error: configuration${validationMessage} does not match the API schema. Click here to see correct type: https://github.com/siberiacancode/mock-config-server`);
|
|
46
|
+
}
|
|
43
47
|
};
|
|
44
|
-
exports.validateApiMockServerConfig = validateApiMockServerConfig;
|
|
@@ -1,39 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
5
|
+
Object.defineProperty(exports, "validateMockServerConfig", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return validateMockServerConfig;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _zod = require("zod");
|
|
12
|
+
const _helpers = require("../helpers");
|
|
13
|
+
const _baseUrlSchema = require("./baseUrlSchema/baseUrlSchema");
|
|
14
|
+
const _corsSchema = require("./corsSchema/corsSchema");
|
|
15
|
+
const _databaseConfigSchema = require("./databaseConfigSchema/databaseConfigSchema");
|
|
16
|
+
const _graphqlConfigSchema = require("./graphqlConfigSchema/graphqlConfigSchema");
|
|
17
|
+
const _interceptorsSchema = require("./interceptorsSchema/interceptorsSchema");
|
|
18
|
+
const _portSchema = require("./portSchema/portSchema");
|
|
19
|
+
const _restConfigSchema = require("./restConfigSchema/restConfigSchema");
|
|
20
|
+
const _staticPathSchema = require("./staticPathSchema/staticPathSchema");
|
|
21
|
+
const _utils = require("./utils");
|
|
22
|
+
const validateMockServerConfig = (mockServerConfig)=>{
|
|
23
|
+
if (!mockServerConfig.rest && !mockServerConfig.graphql && !mockServerConfig.database && !mockServerConfig.staticPath) {
|
|
24
|
+
throw new Error("Configuration should contain at least one of these configs: rest | graphql | database | staticPath; see our doc (https://github.com/siberiacancode/mock-config-server) for more information");
|
|
25
|
+
}
|
|
26
|
+
const mockServerConfigSchema = _zod.z.strictObject({
|
|
27
|
+
baseUrl: _baseUrlSchema.baseUrlSchema.optional(),
|
|
28
|
+
port: _portSchema.portSchema.optional(),
|
|
29
|
+
staticPath: _staticPathSchema.staticPathSchema.optional(),
|
|
30
|
+
interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional(),
|
|
31
|
+
cors: _corsSchema.corsSchema.optional(),
|
|
32
|
+
rest: _restConfigSchema.restConfigSchema.optional(),
|
|
33
|
+
graphql: _graphqlConfigSchema.graphqlConfigSchema.optional(),
|
|
34
|
+
database: _databaseConfigSchema.databaseConfigSchema.optional()
|
|
35
|
+
});
|
|
36
|
+
const validationResult = mockServerConfigSchema.safeParse(mockServerConfig);
|
|
37
|
+
if (!validationResult.success) {
|
|
38
|
+
const path = (0, _helpers.getMostSpecificPathFromError)(validationResult.error);
|
|
39
|
+
const validationMessage = (0, _helpers.getValidationMessageFromPath)(path);
|
|
40
|
+
throw new Error(`Validation Error: configuration${validationMessage} does not match the API schema. Click here to see correct type: https://github.com/siberiacancode/mock-config-server`);
|
|
41
|
+
}
|
|
38
42
|
};
|
|
39
|
-
exports.validateMockServerConfig = validateMockServerConfig;
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
5
|
+
_export_star(require("./src"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return from;
|
|
18
|
+
}
|
|
@@ -1,33 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
(
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
Object.defineProperty(exports, "createDatabaseRoutes", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createDatabaseRoutes;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _helpers = require("./helpers");
|
|
12
|
+
const _storages = require("./storages");
|
|
13
|
+
const isVariableJsonFile = (variable)=>typeof variable === "string" && variable.endsWith(".json");
|
|
14
|
+
const createDatabaseRoutes = (router, { data, routes })=>{
|
|
15
|
+
if (routes) {
|
|
16
|
+
const storage = isVariableJsonFile(routes) ? new _storages.FileStorage(routes) : new _storages.MemoryStorage(routes);
|
|
17
|
+
(0, _helpers.createRewrittenDatabaseRoutes)(router, storage.read());
|
|
18
|
+
router.route("/__routes").get((_request, response)=>{
|
|
19
|
+
response.json(storage.read());
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const storage = isVariableJsonFile(data) ? new _storages.FileStorage(data) : new _storages.MemoryStorage(data);
|
|
23
|
+
const { shallowDatabase, nestedDatabase } = (0, _helpers.splitDatabaseByNesting)(storage.read());
|
|
24
|
+
(0, _helpers.createShallowDatabaseRoutes)(router, shallowDatabase, storage);
|
|
25
|
+
(0, _helpers.createNestedDatabaseRoutes)(router, nestedDatabase, storage);
|
|
26
|
+
router.route("/__db").get((_request, response)=>{
|
|
27
|
+
response.json(storage.read());
|
|
19
28
|
});
|
|
20
|
-
|
|
21
|
-
const storage = isVariableJsonFile(data) ? new _storages.FileStorage(data) : new _storages.MemoryStorage(data);
|
|
22
|
-
const {
|
|
23
|
-
shallowDatabase,
|
|
24
|
-
nestedDatabase
|
|
25
|
-
} = (0, _helpers.splitDatabaseByNesting)(storage.read());
|
|
26
|
-
(0, _helpers.createShallowDatabaseRoutes)(router, shallowDatabase, storage);
|
|
27
|
-
(0, _helpers.createNestedDatabaseRoutes)(router, nestedDatabase, storage);
|
|
28
|
-
router.route('/__db').get((_request, response) => {
|
|
29
|
-
response.json(storage.read());
|
|
30
|
-
});
|
|
31
|
-
return router;
|
|
29
|
+
return router;
|
|
32
30
|
};
|
|
33
|
-
exports.createDatabaseRoutes = createDatabaseRoutes;
|
package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (typeof array[i].id === 'number' && array[i].id > maxId) {
|
|
11
|
-
maxId = array[i].id;
|
|
5
|
+
Object.defineProperty(exports, "createNewId", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createNewId;
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
});
|
|
11
|
+
const createNewId = (array)=>{
|
|
12
|
+
let maxId = -1;
|
|
13
|
+
for(let i = 0; i < array.length; i += 1){
|
|
14
|
+
if (typeof array[i].id === "number" && array[i].id > maxId) {
|
|
15
|
+
maxId = array[i].id;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return maxId + 1;
|
|
15
19
|
};
|
|
16
|
-
exports.createNewId = createNewId;
|
package/dist/src/core/database/createDatabaseRoutes/helpers/array/findIndexById/findIndexById.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Object.defineProperty(exports, "findIndexById", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return findIndexById;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const findIndexById = (array, id)=>array.findIndex((item)=>item.id.toString() === id.toString());
|
|
@@ -1,38 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _findIndexById[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _isIndex = require("./isIndex/isIndex");
|
|
29
|
-
Object.keys(_isIndex).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _isIndex[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _isIndex[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
5
|
+
_export_star(require("./createNewId/createNewId"), exports);
|
|
6
|
+
_export_star(require("./findIndexById/findIndexById"), exports);
|
|
7
|
+
_export_star(require("./isIndex/isIndex"), exports);
|
|
8
|
+
function _export_star(from, to) {
|
|
9
|
+
Object.keys(from).forEach(function(k) {
|
|
10
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
11
|
+
Object.defineProperty(to, k, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function() {
|
|
14
|
+
return from[k];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return from;
|
|
20
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Object.defineProperty(exports, "isIndex", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return isIndex;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const isIndex = (value)=>Number.isInteger(value) && value >= 0;
|