mock-config-server 3.5.0 → 3.6.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/README.md +2 -0
- package/dist/bin/bin.js +3 -3
- package/dist/bin/build.js +5 -5
- package/dist/bin/cli.js +18 -18
- package/dist/bin/helpers/createTemplate.js +4 -4
- package/dist/bin/helpers/getValidationMessageFromPath.js +2 -2
- package/dist/bin/helpers/isOnlyRequestedDataResolvingPropertyExists.js +3 -3
- package/dist/bin/helpers/resolveConfigFile.js +3 -3
- package/dist/bin/helpers/resolveExportsFromSourceCode.js +1 -1
- package/dist/bin/init.js +36 -36
- package/dist/bin/run.js +6 -6
- package/dist/bin/validateMockServerConfig/corsSchema/corsSchema.d.ts +2 -2
- package/dist/bin/validateMockServerConfig/corsSchema/corsSchema.js +6 -6
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.d.ts +82 -72
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.js +4 -4
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +25 -21
- package/dist/bin/validateMockServerConfig/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.js +3 -5
- package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.d.ts +2 -2
- package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.js +1 -1
- package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.d.ts +270 -240
- package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.js +6 -6
- package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +33 -28
- package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.js +7 -9
- package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.d.ts +4 -8
- package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.js +11 -11
- package/dist/bin/validateMockServerConfig/utils/requiredPropertiesSchema/requiredPropertiesSchema.d.ts +1 -1
- package/dist/bin/validateMockServerConfig/utils/sharedSchema/sharedSchema.js +2 -2
- package/dist/bin/validateMockServerConfig/validateApiMockServerConfig.js +3 -3
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +1 -1
- package/dist/src/core/database/createDatabaseRoutes/createDatabaseRoutes.js +3 -3
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.js +1 -1
- package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.js +15 -13
- package/dist/src/core/database/createDatabaseRoutes/helpers/createShallowDatabaseRoutes/createShallowDatabaseRoutes.js +15 -13
- package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.js +19 -13
- package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.js +3 -3
- package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.js +5 -5
- package/dist/src/core/database/createDatabaseRoutes/helpers/splitDatabaseByNesting/splitDatabaseByNesting.js +1 -1
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.js +1 -1
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.js +1 -1
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +24 -19
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +1 -1
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.js +3 -3
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.js +8 -8
- package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.js +2 -2
- package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.js +2 -2
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.js +1 -1
- package/dist/src/core/middlewares/noCorsMiddleware/noCorsMiddleware.js +7 -7
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +1 -1
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.js +2 -2
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.js +1 -1
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.js +1 -1
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +7 -7
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +1 -1
- package/dist/src/core/middlewares/staticMiddleware/staticMiddleware.js +2 -2
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +19 -14
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +1 -1
- package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.js +6 -6
- package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +6 -6
- package/dist/src/server/createMockServer/createMockServer.js +8 -8
- package/dist/src/server/createRestMockServer/createRestMockServer.js +6 -6
- package/dist/src/utils/constants/checkModes.js +18 -18
- package/dist/src/utils/constants/default.js +4 -4
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.js +20 -20
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.js +1 -1
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.js +1 -1
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.js +3 -3
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.js +1 -1
- package/dist/src/utils/helpers/isPlainObject/isPlainObject.js +1 -1
- package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.js +1 -1
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +1 -1
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +1 -1
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +1 -1
- package/dist/src/utils/types/graphql.d.ts +1 -1
- package/dist/src/utils/types/rest.d.ts +1 -1
- package/package.json +21 -23
|
@@ -23,12 +23,12 @@ const baseRequestConfigSchema = (method)=>_zod.z.strictObject({
|
|
|
23
23
|
interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional()
|
|
24
24
|
});
|
|
25
25
|
const requestConfigSchema = _zod.z.union([
|
|
26
|
-
baseRequestConfigSchema(
|
|
27
|
-
baseRequestConfigSchema(
|
|
28
|
-
baseRequestConfigSchema(
|
|
29
|
-
baseRequestConfigSchema(
|
|
30
|
-
baseRequestConfigSchema(
|
|
31
|
-
baseRequestConfigSchema(
|
|
26
|
+
baseRequestConfigSchema('get'),
|
|
27
|
+
baseRequestConfigSchema('post'),
|
|
28
|
+
baseRequestConfigSchema('put'),
|
|
29
|
+
baseRequestConfigSchema('delete'),
|
|
30
|
+
baseRequestConfigSchema('patch'),
|
|
31
|
+
baseRequestConfigSchema('options')
|
|
32
32
|
]);
|
|
33
33
|
const restConfigSchema = _zod.z.strictObject({
|
|
34
34
|
baseUrl: _baseUrlSchema.baseUrlSchema.optional(),
|
package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.d.ts
CHANGED
|
@@ -1,48 +1,45 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { RestMethod } from '../../../../src/utils/types';
|
|
3
|
-
export declare const routeConfigSchema: (method: RestMethod) => z.ZodUnion<[z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodObject<{
|
|
4
|
-
data: z.ZodUnion<[z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>, z.ZodAny]>;
|
|
3
|
+
export declare const routeConfigSchema: (method: RestMethod) => z.ZodUnion<[z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodObject<z.objectUtil.extendShape<{
|
|
5
4
|
settings: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
|
|
5
|
+
data: z.ZodUnion<[z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>, z.ZodAny]>;
|
|
6
|
+
}, {
|
|
6
7
|
entities: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
|
|
7
8
|
interceptors: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
|
|
8
|
-
}
|
|
9
|
+
}>, "strict", z.ZodTypeAny, {
|
|
9
10
|
data?: any;
|
|
10
|
-
settings?: any;
|
|
11
|
-
entities?: any;
|
|
12
11
|
interceptors?: any;
|
|
12
|
+
entities?: any;
|
|
13
|
+
settings?: any;
|
|
13
14
|
}, {
|
|
14
15
|
data?: any;
|
|
15
|
-
settings?: unknown;
|
|
16
|
-
entities?: unknown;
|
|
17
16
|
interceptors?: unknown;
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
entities?: unknown;
|
|
18
|
+
settings?: unknown;
|
|
19
|
+
}>>, z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodObject<z.objectUtil.extendShape<{
|
|
20
20
|
settings: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
|
|
21
|
+
file: z.ZodString;
|
|
22
|
+
}, {
|
|
21
23
|
entities: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
|
|
22
24
|
interceptors: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
|
|
23
|
-
}
|
|
25
|
+
}>, "strict", z.ZodTypeAny, {
|
|
24
26
|
file: string;
|
|
25
|
-
settings?: any;
|
|
26
|
-
entities?: any;
|
|
27
27
|
interceptors?: any;
|
|
28
|
+
entities?: any;
|
|
29
|
+
settings?: any;
|
|
28
30
|
}, {
|
|
29
31
|
file: string;
|
|
30
|
-
settings?: unknown;
|
|
31
|
-
entities?: unknown;
|
|
32
32
|
interceptors?: unknown;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
time?: number | undefined;
|
|
39
|
-
data?: any;
|
|
40
|
-
}>>, "many">;
|
|
41
|
-
settings: z.ZodObject<{
|
|
33
|
+
entities?: unknown;
|
|
34
|
+
settings?: unknown;
|
|
35
|
+
}>>, z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodObject<z.objectUtil.extendShape<{
|
|
36
|
+
settings: z.ZodObject<z.objectUtil.extendShape<{
|
|
37
|
+
polling: z.ZodOptional<z.ZodBoolean>;
|
|
42
38
|
status: z.ZodOptional<z.ZodNumber>;
|
|
43
39
|
delay: z.ZodOptional<z.ZodNumber>;
|
|
40
|
+
}, {
|
|
44
41
|
polling: z.ZodLiteral<true>;
|
|
45
|
-
}
|
|
42
|
+
}>, "strict", z.ZodTypeAny, {
|
|
46
43
|
polling: true;
|
|
47
44
|
status?: number | undefined;
|
|
48
45
|
delay?: number | undefined;
|
|
@@ -51,20 +48,28 @@ export declare const routeConfigSchema: (method: RestMethod) => z.ZodUnion<[z.Zo
|
|
|
51
48
|
status?: number | undefined;
|
|
52
49
|
delay?: number | undefined;
|
|
53
50
|
}>;
|
|
51
|
+
queue: z.ZodArray<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodType<{
|
|
52
|
+
data?: any;
|
|
53
|
+
time?: number | undefined;
|
|
54
|
+
}, z.ZodTypeDef, {
|
|
55
|
+
data?: any;
|
|
56
|
+
time?: number | undefined;
|
|
57
|
+
}>>, "many">;
|
|
58
|
+
}, {
|
|
54
59
|
entities: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
|
|
55
60
|
interceptors: z.ZodOptional<z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>>;
|
|
56
|
-
}
|
|
61
|
+
}>, "strict", z.ZodTypeAny, {
|
|
57
62
|
queue: {
|
|
58
|
-
time?: number | undefined;
|
|
59
63
|
data?: any;
|
|
64
|
+
time?: number | undefined;
|
|
60
65
|
}[];
|
|
61
66
|
settings: {
|
|
62
67
|
polling: true;
|
|
63
68
|
status?: number | undefined;
|
|
64
69
|
delay?: number | undefined;
|
|
65
70
|
};
|
|
66
|
-
entities?: any;
|
|
67
71
|
interceptors?: any;
|
|
72
|
+
entities?: any;
|
|
68
73
|
}, {
|
|
69
74
|
queue: unknown[];
|
|
70
75
|
settings: {
|
|
@@ -72,6 +77,6 @@ export declare const routeConfigSchema: (method: RestMethod) => z.ZodUnion<[z.Zo
|
|
|
72
77
|
status?: number | undefined;
|
|
73
78
|
delay?: number | undefined;
|
|
74
79
|
};
|
|
75
|
-
entities?: unknown;
|
|
76
80
|
interceptors?: unknown;
|
|
81
|
+
entities?: unknown;
|
|
77
82
|
}>>]>;
|
package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.js
CHANGED
|
@@ -16,9 +16,9 @@ const _queueSchema = require("../../queueSchema/queueSchema");
|
|
|
16
16
|
const _settingsSchema = require("../../settingsSchema/settingsSchema");
|
|
17
17
|
const _utils = require("../../utils");
|
|
18
18
|
const METHODS_WITH_BODY = [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
'post',
|
|
20
|
+
'put',
|
|
21
|
+
'patch'
|
|
22
22
|
];
|
|
23
23
|
const entitiesByEntityNameSchema = (method)=>{
|
|
24
24
|
const isMethodWithBody = METHODS_WITH_BODY.includes(method);
|
|
@@ -34,9 +34,7 @@ const entitiesByEntityNameSchema = (method)=>{
|
|
|
34
34
|
};
|
|
35
35
|
const baseRouteConfigSchema = (method)=>_zod.z.strictObject({
|
|
36
36
|
entities: entitiesByEntityNameSchema(method).optional(),
|
|
37
|
-
interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema.
|
|
38
|
-
response: true
|
|
39
|
-
})).optional()
|
|
37
|
+
interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional()
|
|
40
38
|
});
|
|
41
39
|
const dataRouteConfigSchema = (method)=>_zod.z.strictObject({
|
|
42
40
|
settings: (0, _utils.plainObjectSchema)(_settingsSchema.settingsSchema.extend({
|
|
@@ -60,7 +58,7 @@ const queueRouteConfigSchema = (method)=>_zod.z.strictObject({
|
|
|
60
58
|
queue: _queueSchema.queueSchema
|
|
61
59
|
}).merge(baseRouteConfigSchema(method));
|
|
62
60
|
const routeConfigSchema = (method)=>_zod.z.union([
|
|
63
|
-
_zod.z.custom((value)=>(0, _helpers.isPlainObject)(value) && (0, _helpers1.isOnlyRequestedDataResolvingPropertyExists)(value,
|
|
64
|
-
_zod.z.custom((value)=>(0, _helpers.isPlainObject)(value) && (0, _helpers1.isOnlyRequestedDataResolvingPropertyExists)(value,
|
|
65
|
-
_zod.z.custom((value)=>(0, _helpers.isPlainObject)(value) && (0, _helpers1.isOnlyRequestedDataResolvingPropertyExists)(value,
|
|
61
|
+
_zod.z.custom((value)=>(0, _helpers.isPlainObject)(value) && (0, _helpers1.isOnlyRequestedDataResolvingPropertyExists)(value, 'data')).pipe(dataRouteConfigSchema(method)),
|
|
62
|
+
_zod.z.custom((value)=>(0, _helpers.isPlainObject)(value) && (0, _helpers1.isOnlyRequestedDataResolvingPropertyExists)(value, 'file')).pipe(fileRouteConfigSchema(method)),
|
|
63
|
+
_zod.z.custom((value)=>(0, _helpers.isPlainObject)(value) && (0, _helpers1.isOnlyRequestedDataResolvingPropertyExists)(value, 'queue')).pipe(queueRouteConfigSchema(method))
|
|
66
64
|
]);
|
|
@@ -4,11 +4,9 @@ export declare const plainEntitySchema: z.ZodUnion<[z.ZodPipeline<z.ZodType<unkn
|
|
|
4
4
|
value: (...args: unknown[]) => unknown;
|
|
5
5
|
} | {
|
|
6
6
|
checkMode: "equals" | "notEquals";
|
|
7
|
-
value:
|
|
7
|
+
value: string | number | boolean | {
|
|
8
8
|
[key: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
|
|
9
|
-
} | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[]
|
|
10
|
-
[key: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
|
|
11
|
-
} | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | undefined)) | null;
|
|
9
|
+
} | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
|
|
12
10
|
} | {
|
|
13
11
|
checkMode: "exists" | "notExists";
|
|
14
12
|
}, z.ZodTypeDef, {
|
|
@@ -16,11 +14,9 @@ export declare const plainEntitySchema: z.ZodUnion<[z.ZodPipeline<z.ZodType<unkn
|
|
|
16
14
|
value: (...args: unknown[]) => unknown;
|
|
17
15
|
} | {
|
|
18
16
|
checkMode: "equals" | "notEquals";
|
|
19
|
-
value:
|
|
20
|
-
[key: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
|
|
21
|
-
} | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[]) & (string | number | boolean | {
|
|
17
|
+
value: string | number | boolean | {
|
|
22
18
|
[key: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
|
|
23
|
-
} | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] |
|
|
19
|
+
} | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
|
|
24
20
|
} | {
|
|
25
21
|
checkMode: "exists" | "notExists";
|
|
26
22
|
}>>, z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodTypeAny>, z.ZodArray<z.ZodIntersection<z.ZodType<string | number | boolean | {
|
|
@@ -21,9 +21,9 @@ const _checkModeSchema = require("../checkModeSchema/checkModeSchema");
|
|
|
21
21
|
const _jsonSchema = require("../jsonSchema/jsonSchema");
|
|
22
22
|
const _plainObjectSchema = require("../plainObjectSchema/plainObjectSchema");
|
|
23
23
|
const _requiredPropertiesSchema = require("../requiredPropertiesSchema/requiredPropertiesSchema");
|
|
24
|
-
/* ----- Plain entity schema ----- */ const topLevelPlainEntityDescriptorSchema = (0, _requiredPropertiesSchema.requiredPropertiesSchema)(_zod.z.discriminatedUnion(
|
|
24
|
+
/* ----- Plain entity schema ----- */ const topLevelPlainEntityDescriptorSchema = (0, _requiredPropertiesSchema.requiredPropertiesSchema)(_zod.z.discriminatedUnion('checkMode', [
|
|
25
25
|
_zod.z.strictObject({
|
|
26
|
-
checkMode: _zod.z.literal(
|
|
26
|
+
checkMode: _zod.z.literal('function'),
|
|
27
27
|
value: _zod.z.function()
|
|
28
28
|
}),
|
|
29
29
|
_zod.z.strictObject({
|
|
@@ -34,11 +34,11 @@ const _requiredPropertiesSchema = require("../requiredPropertiesSchema/requiredP
|
|
|
34
34
|
checkMode: _checkModeSchema.checkActualValueCheckModeSchema
|
|
35
35
|
})
|
|
36
36
|
]), [
|
|
37
|
-
|
|
37
|
+
'checkMode'
|
|
38
38
|
]);
|
|
39
|
-
const propertyLevelPlainEntityDescriptorSchema = (0, _requiredPropertiesSchema.requiredPropertiesSchema)(_zod.z.discriminatedUnion(
|
|
39
|
+
const propertyLevelPlainEntityDescriptorSchema = (0, _requiredPropertiesSchema.requiredPropertiesSchema)(_zod.z.discriminatedUnion('checkMode', [
|
|
40
40
|
_zod.z.strictObject({
|
|
41
|
-
checkMode: _zod.z.literal(
|
|
41
|
+
checkMode: _zod.z.literal('function'),
|
|
42
42
|
value: _zod.z.function()
|
|
43
43
|
}),
|
|
44
44
|
_zod.z.strictObject({
|
|
@@ -46,7 +46,7 @@ const propertyLevelPlainEntityDescriptorSchema = (0, _requiredPropertiesSchema.r
|
|
|
46
46
|
value: _jsonSchema.jsonSchema
|
|
47
47
|
}),
|
|
48
48
|
_zod.z.strictObject({
|
|
49
|
-
checkMode: _zod.z.literal(
|
|
49
|
+
checkMode: _zod.z.literal('regExp'),
|
|
50
50
|
value: _zod.z.union([
|
|
51
51
|
_zod.z.instanceof(RegExp),
|
|
52
52
|
_zod.z.array(_zod.z.instanceof(RegExp))
|
|
@@ -63,7 +63,7 @@ const propertyLevelPlainEntityDescriptorSchema = (0, _requiredPropertiesSchema.r
|
|
|
63
63
|
checkMode: _checkModeSchema.checkActualValueCheckModeSchema
|
|
64
64
|
})
|
|
65
65
|
]), [
|
|
66
|
-
|
|
66
|
+
'checkMode'
|
|
67
67
|
]);
|
|
68
68
|
const nonCheckModeRecordSchema = (recordSchema)=>(0, _plainObjectSchema.plainObjectSchema)(recordSchema.and(_zod.z.object({
|
|
69
69
|
checkMode: _zod.z.never().optional()
|
|
@@ -92,13 +92,13 @@ const plainEntitySchema = _zod.z.union([
|
|
|
92
92
|
_zod.z.number(),
|
|
93
93
|
_zod.z.boolean()
|
|
94
94
|
]);
|
|
95
|
-
const mappedEntityDescriptorSchema = (0, _requiredPropertiesSchema.requiredPropertiesSchema)(_zod.z.discriminatedUnion(
|
|
95
|
+
const mappedEntityDescriptorSchema = (0, _requiredPropertiesSchema.requiredPropertiesSchema)(_zod.z.discriminatedUnion('checkMode', [
|
|
96
96
|
_zod.z.strictObject({
|
|
97
|
-
checkMode: _zod.z.literal(
|
|
97
|
+
checkMode: _zod.z.literal('function'),
|
|
98
98
|
value: _zod.z.function()
|
|
99
99
|
}),
|
|
100
100
|
_zod.z.strictObject({
|
|
101
|
-
checkMode: _zod.z.literal(
|
|
101
|
+
checkMode: _zod.z.literal('regExp'),
|
|
102
102
|
value: _zod.z.union([
|
|
103
103
|
_zod.z.instanceof(RegExp),
|
|
104
104
|
_zod.z.array(_zod.z.instanceof(RegExp))
|
|
@@ -115,7 +115,7 @@ const mappedEntityDescriptorSchema = (0, _requiredPropertiesSchema.requiredPrope
|
|
|
115
115
|
checkMode: _checkModeSchema.checkActualValueCheckModeSchema
|
|
116
116
|
})
|
|
117
117
|
]), [
|
|
118
|
-
|
|
118
|
+
'checkMode'
|
|
119
119
|
]);
|
|
120
120
|
const mappedEntitySchema = (0, _plainObjectSchema.plainObjectSchema)(_zod.z.record(_zod.z.union([
|
|
121
121
|
mappedEntityValueSchema,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { PlainObject } from '../../../../src/utils/types';
|
|
3
|
-
export declare const requiredPropertiesSchema: <T extends PlainObject>(schema: z.ZodType<T
|
|
3
|
+
export declare const requiredPropertiesSchema: <T extends PlainObject>(schema: z.ZodType<T>, requiredProperties: (keyof T)[]) => z.ZodPipeline<z.ZodType<unknown, z.ZodTypeDef, unknown>, z.ZodType<T, z.ZodTypeDef, T>>;
|
|
@@ -17,5 +17,5 @@ _export(exports, {
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
const _zod = require("zod");
|
|
20
|
-
const stringForwardSlashSchema = _zod.z.string().startsWith(
|
|
21
|
-
const stringJsonFilenameSchema = _zod.z.string().endsWith(
|
|
20
|
+
const stringForwardSlashSchema = _zod.z.string().startsWith('/');
|
|
21
|
+
const stringJsonFilenameSchema = _zod.z.string().endsWith('.json');
|
|
@@ -21,7 +21,7 @@ const _staticPathSchema = require("./staticPathSchema/staticPathSchema");
|
|
|
21
21
|
const _utils = require("./utils");
|
|
22
22
|
const validateApiMockServerConfig = (mockServerConfig, api)=>{
|
|
23
23
|
if (!mockServerConfig.configs && !mockServerConfig.database && !mockServerConfig.staticPath) {
|
|
24
|
-
throw new Error(
|
|
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
25
|
}
|
|
26
26
|
const isConfigsContainAtLeastOneElement = Array.isArray(mockServerConfig.configs) && !!mockServerConfig.configs.length;
|
|
27
27
|
const mockServerConfigSchema = _zod.z.strictObject({
|
|
@@ -31,10 +31,10 @@ const validateApiMockServerConfig = (mockServerConfig, api)=>{
|
|
|
31
31
|
interceptors: (0, _utils.plainObjectSchema)(_interceptorsSchema.interceptorsSchema).optional(),
|
|
32
32
|
cors: _corsSchema.corsSchema.optional(),
|
|
33
33
|
database: _databaseConfigSchema.databaseConfigSchema.optional(),
|
|
34
|
-
...isConfigsContainAtLeastOneElement && api ===
|
|
34
|
+
...isConfigsContainAtLeastOneElement && api === 'graphql' && {
|
|
35
35
|
configs: _graphqlConfigSchema.graphqlConfigSchema.shape.configs
|
|
36
36
|
},
|
|
37
|
-
...isConfigsContainAtLeastOneElement && api ===
|
|
37
|
+
...isConfigsContainAtLeastOneElement && api === 'rest' && {
|
|
38
38
|
configs: _restConfigSchema.restConfigSchema.shape.configs
|
|
39
39
|
}
|
|
40
40
|
});
|
|
@@ -21,7 +21,7 @@ const _staticPathSchema = require("./staticPathSchema/staticPathSchema");
|
|
|
21
21
|
const _utils = require("./utils");
|
|
22
22
|
const validateMockServerConfig = (mockServerConfig)=>{
|
|
23
23
|
if (!mockServerConfig.rest && !mockServerConfig.graphql && !mockServerConfig.database && !mockServerConfig.staticPath) {
|
|
24
|
-
throw new Error(
|
|
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
25
|
}
|
|
26
26
|
const mockServerConfigSchema = _zod.z.strictObject({
|
|
27
27
|
baseUrl: _baseUrlSchema.baseUrlSchema.optional(),
|
|
@@ -10,12 +10,12 @@ Object.defineProperty(exports, "createDatabaseRoutes", {
|
|
|
10
10
|
});
|
|
11
11
|
const _helpers = require("./helpers");
|
|
12
12
|
const _storages = require("./storages");
|
|
13
|
-
const isVariableJsonFile = (variable)=>typeof variable ===
|
|
13
|
+
const isVariableJsonFile = (variable)=>typeof variable === 'string' && variable.endsWith('.json');
|
|
14
14
|
const createDatabaseRoutes = (router, { data, routes })=>{
|
|
15
15
|
if (routes) {
|
|
16
16
|
const storage = isVariableJsonFile(routes) ? new _storages.FileStorage(routes) : new _storages.MemoryStorage(routes);
|
|
17
17
|
(0, _helpers.createRewrittenDatabaseRoutes)(router, storage.read());
|
|
18
|
-
router.route(
|
|
18
|
+
router.route('/__routes').get((_request, response)=>{
|
|
19
19
|
response.json(storage.read());
|
|
20
20
|
});
|
|
21
21
|
}
|
|
@@ -23,7 +23,7 @@ const createDatabaseRoutes = (router, { data, routes })=>{
|
|
|
23
23
|
const { shallowDatabase, nestedDatabase } = (0, _helpers.splitDatabaseByNesting)(storage.read());
|
|
24
24
|
(0, _helpers.createShallowDatabaseRoutes)(router, shallowDatabase, storage);
|
|
25
25
|
(0, _helpers.createNestedDatabaseRoutes)(router, nestedDatabase, storage);
|
|
26
|
-
router.route(
|
|
26
|
+
router.route('/__db').get((_request, response)=>{
|
|
27
27
|
response.json(storage.read());
|
|
28
28
|
});
|
|
29
29
|
return router;
|
package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.js
CHANGED
|
@@ -11,7 +11,7 @@ Object.defineProperty(exports, "createNewId", {
|
|
|
11
11
|
const createNewId = (array)=>{
|
|
12
12
|
let maxId = -1;
|
|
13
13
|
for(let i = 0; i < array.length; i += 1){
|
|
14
|
-
if (typeof array[i].id ===
|
|
14
|
+
if (typeof array[i].id === 'number' && array[i].id > maxId) {
|
|
15
15
|
maxId = array[i].id;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -23,7 +23,7 @@ const createNestedDatabaseRoutes = (router, database, storage)=>{
|
|
|
23
23
|
// ✅ important:
|
|
24
24
|
// set 'Cache-Control' header for explicit browsers response revalidate
|
|
25
25
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
|
26
|
-
response.set(
|
|
26
|
+
response.set('Cache-control', 'max-age=0, must-revalidate');
|
|
27
27
|
return response.json(data);
|
|
28
28
|
}
|
|
29
29
|
const { _page, _limit, _begin, _end, _sort: _sort1, _order, _q, ...filters } = request.query;
|
|
@@ -33,11 +33,21 @@ const createNestedDatabaseRoutes = (router, database, storage)=>{
|
|
|
33
33
|
if (_q) {
|
|
34
34
|
data = (0, _search.search)(data, request.query._q);
|
|
35
35
|
}
|
|
36
|
+
if (_sort1) {
|
|
37
|
+
data = (0, _sort.sort)(data, request.query);
|
|
38
|
+
}
|
|
39
|
+
if (_begin || _end) {
|
|
40
|
+
var _request_query__begin;
|
|
41
|
+
data = data.slice((_request_query__begin = request.query._begin) !== null && _request_query__begin !== void 0 ? _request_query__begin : 0, request.query._end);
|
|
42
|
+
response.set('X-Total-Count', data.length);
|
|
43
|
+
}
|
|
44
|
+
// ✅ important:
|
|
45
|
+
// The pagination should be last because it changes the form of the response
|
|
36
46
|
if (_page) {
|
|
37
47
|
data = (0, _pagination.pagination)(data, request.query);
|
|
38
48
|
if (data._link) {
|
|
39
49
|
const links = {};
|
|
40
|
-
const fullUrl = `${request.protocol}://${request.get(
|
|
50
|
+
const fullUrl = `${request.protocol}://${request.get('host')}${request.originalUrl}`;
|
|
41
51
|
if (data._link.first) {
|
|
42
52
|
links.first = fullUrl.replace(`page=${data._link.current}`, `page=${data._link.first}`);
|
|
43
53
|
}
|
|
@@ -57,18 +67,10 @@ const createNestedDatabaseRoutes = (router, database, storage)=>{
|
|
|
57
67
|
response.links(links);
|
|
58
68
|
}
|
|
59
69
|
}
|
|
60
|
-
if (_sort1) {
|
|
61
|
-
data = (0, _sort.sort)(data, request.query);
|
|
62
|
-
}
|
|
63
|
-
if (_begin || _end) {
|
|
64
|
-
var _request_query__begin;
|
|
65
|
-
data = data.slice((_request_query__begin = request.query._begin) !== null && _request_query__begin !== void 0 ? _request_query__begin : 0, request.query._end);
|
|
66
|
-
response.set("X-Total-Count", data.length);
|
|
67
|
-
}
|
|
68
70
|
// ✅ important:
|
|
69
71
|
// set 'Cache-Control' header for explicit browsers response revalidate
|
|
70
72
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
|
71
|
-
response.set(
|
|
73
|
+
response.set('Cache-control', 'no-cache');
|
|
72
74
|
response.json(data);
|
|
73
75
|
});
|
|
74
76
|
router.route(collectionPath).post((request, response)=>{
|
|
@@ -82,7 +84,7 @@ const createNestedDatabaseRoutes = (router, database, storage)=>{
|
|
|
82
84
|
key,
|
|
83
85
|
collection.length
|
|
84
86
|
], newResource);
|
|
85
|
-
response.set(
|
|
87
|
+
response.set('Location', `${request.url}/${newResourceId}`);
|
|
86
88
|
response.status(201).json(newResource);
|
|
87
89
|
});
|
|
88
90
|
router.route(itemPath).get((request, response)=>{
|
|
@@ -95,7 +97,7 @@ const createNestedDatabaseRoutes = (router, database, storage)=>{
|
|
|
95
97
|
// ✅ important:
|
|
96
98
|
// set 'Cache-Control' header for explicit browsers response revalidate
|
|
97
99
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
|
98
|
-
response.set(
|
|
100
|
+
response.set('Cache-control', 'no-cache');
|
|
99
101
|
response.json(storage.read([
|
|
100
102
|
key,
|
|
101
103
|
currentResourceIndex
|
|
@@ -21,10 +21,10 @@ const createShallowDatabaseRoutes = (router, database, storage)=>{
|
|
|
21
21
|
// ✅ important:
|
|
22
22
|
// set 'Cache-Control' header for explicit browsers response revalidate
|
|
23
23
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
|
24
|
-
response.set(
|
|
24
|
+
response.set('Cache-control', 'no-cache');
|
|
25
25
|
return response.json(data);
|
|
26
26
|
}
|
|
27
|
-
data = data.filter((element)=>typeof element ===
|
|
27
|
+
data = data.filter((element)=>typeof element === 'object' && element !== null);
|
|
28
28
|
const { _page, _limit, _begin, _end, _sort: _sort1, _order, _q, ...filters } = request.query;
|
|
29
29
|
if (Object.keys(filters).length) {
|
|
30
30
|
data = (0, _filter.filter)(data, filters);
|
|
@@ -32,11 +32,21 @@ const createShallowDatabaseRoutes = (router, database, storage)=>{
|
|
|
32
32
|
if (_q) {
|
|
33
33
|
data = (0, _search.search)(data, request.query._q);
|
|
34
34
|
}
|
|
35
|
+
if (_sort1) {
|
|
36
|
+
data = (0, _sort.sort)(data, request.query);
|
|
37
|
+
}
|
|
38
|
+
if (_begin || _end) {
|
|
39
|
+
var _request_query__begin;
|
|
40
|
+
data = data.slice((_request_query__begin = request.query._begin) !== null && _request_query__begin !== void 0 ? _request_query__begin : 0, request.query._end);
|
|
41
|
+
response.set('X-Total-Count', data.length);
|
|
42
|
+
}
|
|
43
|
+
// ✅ important:
|
|
44
|
+
// The pagination should be last because it changes the form of the response
|
|
35
45
|
if (_page) {
|
|
36
46
|
data = (0, _pagination.pagination)(data, request.query);
|
|
37
47
|
if (data._link) {
|
|
38
48
|
const links = {};
|
|
39
|
-
const fullUrl = `${request.protocol}://${request.get(
|
|
49
|
+
const fullUrl = `${request.protocol}://${request.get('host')}${request.originalUrl}`;
|
|
40
50
|
if (data._link.first) {
|
|
41
51
|
links.first = fullUrl.replace(`page=${data._link.current}`, `page=${data._link.first}`);
|
|
42
52
|
}
|
|
@@ -56,23 +66,15 @@ const createShallowDatabaseRoutes = (router, database, storage)=>{
|
|
|
56
66
|
response.links(links);
|
|
57
67
|
}
|
|
58
68
|
}
|
|
59
|
-
if (_sort1) {
|
|
60
|
-
data = (0, _sort.sort)(data, request.query);
|
|
61
|
-
}
|
|
62
|
-
if (_begin || _end) {
|
|
63
|
-
var _request_query__begin;
|
|
64
|
-
data = data.slice((_request_query__begin = request.query._begin) !== null && _request_query__begin !== void 0 ? _request_query__begin : 0, request.query._end);
|
|
65
|
-
response.set("X-Total-Count", data.length);
|
|
66
|
-
}
|
|
67
69
|
// ✅ important:
|
|
68
70
|
// set 'Cache-Control' header for explicit browsers response revalidate
|
|
69
71
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
|
70
|
-
response.set(
|
|
72
|
+
response.set('Cache-control', 'no-cache');
|
|
71
73
|
response.json(data);
|
|
72
74
|
});
|
|
73
75
|
router.route(path).post((request, response)=>{
|
|
74
76
|
storage.write(key, request.body);
|
|
75
|
-
response.set(
|
|
77
|
+
response.set('Location', request.url);
|
|
76
78
|
response.status(201).json(request.body);
|
|
77
79
|
});
|
|
78
80
|
router.route(path).put((request, response)=>{
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "filter", {
|
|
|
10
10
|
});
|
|
11
11
|
const _flat = require("flat");
|
|
12
12
|
const OPERATORS = {
|
|
13
|
+
eq: (a, b)=>`${a}` === `${b}`,
|
|
13
14
|
neq: (a, b)=>`${a}` !== `${b}`,
|
|
14
15
|
gt: (a, b)=>+a > +b,
|
|
15
16
|
gte: (a, b)=>+a >= +b,
|
|
@@ -20,35 +21,40 @@ const OPERATORS = {
|
|
|
20
21
|
sw: (a, b)=>a.startsWith(b),
|
|
21
22
|
nsw: (a, b)=>!a.startsWith(b),
|
|
22
23
|
ew: (a, b)=>a.endsWith(b),
|
|
23
|
-
new: (a, b)=>!a.endsWith(b)
|
|
24
|
+
new: (a, b)=>!a.endsWith(b),
|
|
25
|
+
some: (a, b)=>a.some((element)=>`${element}` === `${b}`)
|
|
24
26
|
};
|
|
25
27
|
const OPERATORS_KEYS = Object.keys(OPERATORS);
|
|
26
|
-
const OPERATOR_REGEXP = new RegExp(`^(.+)_(${OPERATORS_KEYS.join(
|
|
28
|
+
const OPERATOR_REGEXP = new RegExp(`^(.+)_(${OPERATORS_KEYS.join('|')})$`);
|
|
27
29
|
const getEntities = (object, key)=>{
|
|
28
30
|
const parts = key.match(OPERATOR_REGEXP);
|
|
29
|
-
if (parts) {
|
|
30
|
-
const [, element, operator] = parts;
|
|
31
|
+
if (!parts) {
|
|
31
32
|
return {
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
operator: 'eq',
|
|
34
|
+
element: object[key]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const [, element, operator] = parts;
|
|
38
|
+
if (operator === 'some') {
|
|
39
|
+
const array = Object.entries(object).filter(([objectKey])=>new RegExp(`^${element}.\\d$`).test(objectKey));
|
|
40
|
+
return {
|
|
41
|
+
operator,
|
|
42
|
+
element: array.map(([, value])=>value)
|
|
34
43
|
};
|
|
35
44
|
}
|
|
36
45
|
return {
|
|
37
|
-
element: object[
|
|
46
|
+
element: object[element],
|
|
47
|
+
operator: operator
|
|
38
48
|
};
|
|
39
49
|
};
|
|
40
|
-
const filtered = (element, value, operator)=>{
|
|
41
|
-
if (!operator) return `${element}` === value;
|
|
42
|
-
return OPERATORS[operator](element, value);
|
|
43
|
-
};
|
|
44
50
|
const filter = (array, filters)=>array.filter((arrayElement)=>{
|
|
45
51
|
const flattenedArrayElement = (0, _flat.flatten)(arrayElement);
|
|
46
52
|
return Object.entries(filters).every(([key, filter])=>{
|
|
47
53
|
if (Array.isArray(filter)) {
|
|
48
54
|
const { element, operator } = getEntities(flattenedArrayElement, key);
|
|
49
|
-
return filter.some((value)=>
|
|
55
|
+
return filter.some((value)=>OPERATORS[operator](element, value));
|
|
50
56
|
}
|
|
51
57
|
const { element, operator } = getEntities(flattenedArrayElement, key);
|
|
52
|
-
return
|
|
58
|
+
return OPERATORS[operator](element, filter);
|
|
53
59
|
});
|
|
54
60
|
});
|
|
@@ -18,7 +18,7 @@ _export(exports, {
|
|
|
18
18
|
});
|
|
19
19
|
const searchInNestedObjects = (obj, searchText)=>{
|
|
20
20
|
for(const key in obj){
|
|
21
|
-
if (typeof obj[key] ===
|
|
21
|
+
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
22
22
|
if (searchInNestedObjects(obj[key], searchText)) {
|
|
23
23
|
return true;
|
|
24
24
|
}
|
|
@@ -29,11 +29,11 @@ const searchInNestedObjects = (obj, searchText)=>{
|
|
|
29
29
|
return false;
|
|
30
30
|
};
|
|
31
31
|
const search = (array, searchText)=>array.filter((element)=>{
|
|
32
|
-
if (typeof searchText ===
|
|
32
|
+
if (typeof searchText === 'string') {
|
|
33
33
|
return searchInNestedObjects(element, searchText);
|
|
34
34
|
}
|
|
35
35
|
if (Array.isArray(searchText)) {
|
|
36
36
|
return searchText.some((text)=>searchInNestedObjects(element, text));
|
|
37
37
|
}
|
|
38
|
-
throw new Error(
|
|
38
|
+
throw new Error('search technical error');
|
|
39
39
|
});
|
|
@@ -9,19 +9,19 @@ Object.defineProperty(exports, "sort", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _flat = require("flat");
|
|
12
|
-
const DEFAULT_ORDER =
|
|
12
|
+
const DEFAULT_ORDER = 'asc';
|
|
13
13
|
const getOrder = (order)=>{
|
|
14
|
-
if (order ===
|
|
14
|
+
if (order === 'asc' || order === 'desc') return order;
|
|
15
15
|
return DEFAULT_ORDER;
|
|
16
16
|
};
|
|
17
17
|
const sortArray = (array, key, order)=>array.sort((a, b)=>{
|
|
18
18
|
const flattenedA = (0, _flat.flatten)(a);
|
|
19
19
|
const flattenedB = (0, _flat.flatten)(b);
|
|
20
20
|
if (!flattenedA[key] || !flattenedB[key]) return 0;
|
|
21
|
-
if (typeof flattenedA[key] ===
|
|
22
|
-
return order ===
|
|
21
|
+
if (typeof flattenedA[key] === 'string' && typeof flattenedB[key] === 'string') {
|
|
22
|
+
return order === 'asc' ? flattenedA[key].localeCompare(flattenedB[key]) : flattenedB[key].localeCompare(flattenedA[key]);
|
|
23
23
|
}
|
|
24
|
-
return order ===
|
|
24
|
+
return order === 'asc' ? Number(flattenedA[key]) - Number(flattenedB[key]) : Number(flattenedB[key]) - Number(flattenedA[key]);
|
|
25
25
|
});
|
|
26
26
|
const sort = (array, queries)=>{
|
|
27
27
|
const { _sort, _order = DEFAULT_ORDER } = queries;
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "splitDatabaseByNesting", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _helpers = require("../../../../../utils/helpers");
|
|
12
|
-
const isAllArrayElementsHaveValidTypeId = (array)=>array.every((element)=>(0, _helpers.isPlainObject)(element) && (typeof element.id ===
|
|
12
|
+
const isAllArrayElementsHaveValidTypeId = (array)=>array.every((element)=>(0, _helpers.isPlainObject)(element) && (typeof element.id === 'number' || typeof element.id === 'string'));
|
|
13
13
|
const isAllArrayElementsHaveUniqueId = (array)=>{
|
|
14
14
|
const uniqueIdsCount = new Set(array.map(({ id })=>id)).size;
|
|
15
15
|
return array.length === uniqueIdsCount;
|
|
@@ -24,7 +24,7 @@ class FileStorage {
|
|
|
24
24
|
constructor(fileName){
|
|
25
25
|
const filePath = _path.default.resolve(_constants.APP_PATH, fileName);
|
|
26
26
|
this.fileWriter = new _FileWriter.FileWriter(filePath);
|
|
27
|
-
this.data = JSON.parse(_fs.default.readFileSync(filePath,
|
|
27
|
+
this.data = JSON.parse(_fs.default.readFileSync(filePath, 'utf-8'));
|
|
28
28
|
}
|
|
29
29
|
read(key) {
|
|
30
30
|
if (!key) return this.data;
|
|
@@ -38,7 +38,7 @@ class FileWriter {
|
|
|
38
38
|
}
|
|
39
39
|
async unlockedWrite(data, recursionLevel = 0) {
|
|
40
40
|
this.writeIsLocked = true;
|
|
41
|
-
await _fs.default.promises.writeFile(this.filePath, data,
|
|
41
|
+
await _fs.default.promises.writeFile(this.filePath, data, 'utf-8');
|
|
42
42
|
this.writeIsLocked = false;
|
|
43
43
|
// ✅ important:
|
|
44
44
|
// copy content of this.nextData into new variable
|