mock-config-server 3.2.0 → 3.3.1
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 +153 -3
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.d.ts +2 -1
- package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.js +30 -7
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.js +9 -3
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +67 -18
- package/dist/bin/validateMockServerConfig/validateQueue/validateQueue.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateQueue/validateQueue.js +29 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +67 -18
- package/dist/bin/validateMockServerConfig/validateSettings/validateSettings.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateSettings/validateSettings.js +34 -0
- package/dist/src/core/database/createDatabaseRoutes/createDatabaseRoutes.test.ts +112 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/createNewId/createNewId.test.ts +13 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/findIndexById/findIndexById.test.ts +17 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/array/isIndex/isIndex.test.ts +30 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.js +45 -2
- package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.test.ts +399 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/createShallowDatabaseRoutes/createShallowDatabaseRoutes.test.ts +118 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.d.ts +2 -1
- package/dist/src/core/database/createDatabaseRoutes/helpers/operators/operators.d.ts +3 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/operators/operators.js +30 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.d.ts +13 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.js +36 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.d.ts +3 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.js +31 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.d.ts +2 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.js +42 -0
- package/dist/src/core/database/createDatabaseRoutes/helpers/splitDatabaseByNesting/splitDatabaseByNesting.test.ts +25 -0
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileStorage.test.ts +156 -0
- package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.test.ts +48 -0
- package/dist/src/core/database/createDatabaseRoutes/storages/Memory/MemoryStorage.test.ts +96 -0
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.d.ts +7 -1
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +65 -24
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.test.ts +851 -0
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.test.ts +116 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.test.ts +22 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.test.ts +45 -0
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.test.ts +152 -0
- package/dist/src/core/middlewares/corsMiddleware/helpers/getAllowedOrigins/getAllowedOrigins.test.ts +15 -0
- package/dist/src/core/middlewares/errorMiddleware/errorMiddleware.test.ts +29 -0
- package/dist/src/core/middlewares/noCorsMiddleware/noCorsMiddleware.test.ts +49 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.test.ts +27 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getLevenshteinDistance/getLevenshteinDistance.test.ts +12 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.test.ts +54 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.test.ts +12 -0
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.test.ts +10 -0
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +1 -3
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.test.ts +285 -0
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.d.ts +7 -1
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +6 -2
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.d.ts +7 -1
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +55 -12
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.test.ts +648 -0
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.test.ts +154 -0
- package/dist/src/server/createDatabaseMockServer/createDatabaseMockServer.js +4 -1
- package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +11 -4
- package/dist/src/server/createMockServer/createMockServer.js +28 -9
- package/dist/src/server/createRestMockServer/createRestMockServer.js +11 -4
- package/dist/src/server/index.d.ts +3 -3
- package/dist/src/server/index.js +23 -23
- package/dist/src/static/views/features/scheme/index.js +31 -31
- package/dist/src/utils/helpers/config/resolveEntityValues/resolveEntityValues.test.ts +1452 -0
- package/dist/src/utils/helpers/entities/convertToEntityDescriptor/convertToEntityDescriptor.test.ts +27 -0
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.d.ts +2 -1
- package/dist/src/utils/helpers/entities/isEntityDescriptor/isEntityDescriptor.test.ts +15 -0
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.d.ts +7 -2
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.js +6 -4
- package/dist/src/utils/helpers/graphql/getGraphQLInput/getGraphQLInput.test.ts +140 -0
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.d.ts +1 -1
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.js +1 -1
- package/dist/src/utils/helpers/graphql/parseQuery/parseQuery.test.ts +32 -0
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptors.test.ts +53 -0
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +19 -10
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.test.ts +262 -0
- package/dist/src/utils/helpers/isPlainObject/isPlainObject.test.ts +20 -0
- package/dist/src/utils/helpers/isPrimitive/isPrimitive.test.ts +26 -0
- package/dist/src/utils/helpers/isRegExp/isRegExp.test.ts +20 -0
- package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.test.ts +21 -0
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.test.ts +8 -0
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.test.ts +10 -0
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.test.ts +9 -0
- package/dist/src/utils/types/graphql.d.ts +60 -51
- package/dist/src/utils/types/index.d.ts +1 -0
- package/dist/src/utils/types/index.js +11 -0
- package/dist/src/utils/types/interceptors.d.ts +1 -1
- package/dist/src/utils/types/rest.d.ts +47 -40
- package/dist/src/utils/types/utils.d.ts +8 -0
- package/dist/src/utils/types/utils.js +1 -0
- package/dist/src/utils/types/values.d.ts +0 -1
- package/package.json +2 -3
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isPrimitive } from './isPrimitive';
|
|
2
|
+
|
|
3
|
+
describe('isPrimitive', () => {
|
|
4
|
+
test('Object value should return false', () => {
|
|
5
|
+
expect(isPrimitive(Object({}))).toBe(false);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
test('Function value should return false', () => {
|
|
9
|
+
expect(isPrimitive(() => {})).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('Array value should return false', () => {
|
|
13
|
+
expect(isPrimitive(Array([]))).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('All Primitives should return true', () => {
|
|
17
|
+
expect(isPrimitive(Boolean(true))).toBe(true);
|
|
18
|
+
expect(isPrimitive(Number(1))).toBe(true);
|
|
19
|
+
expect(isPrimitive(BigInt(9007199254740991n))).toBe(true);
|
|
20
|
+
expect(isPrimitive(String())).toBe(true);
|
|
21
|
+
expect(isPrimitive(String('test'))).toBe(true);
|
|
22
|
+
expect(isPrimitive(Symbol('test'))).toBe(true);
|
|
23
|
+
expect(isPrimitive(undefined)).toBe(true);
|
|
24
|
+
expect(isPrimitive(null)).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isRegExp } from './isRegExp';
|
|
2
|
+
|
|
3
|
+
describe('isRegExp', () => {
|
|
4
|
+
test('RegExp value should return true', () => {
|
|
5
|
+
expect(isRegExp(/\d/)).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
test('All Primitive, array, object, function values should return false', () => {
|
|
9
|
+
expect(isRegExp(Number(1))).toBe(false);
|
|
10
|
+
expect(isRegExp(BigInt(9007199254740991n))).toBe(false);
|
|
11
|
+
expect(isRegExp(String('test'))).toBe(false);
|
|
12
|
+
expect(isRegExp(Boolean(true))).toBe(false);
|
|
13
|
+
expect(isRegExp(Symbol('test'))).toBe(false);
|
|
14
|
+
expect(isRegExp(Array([]))).toBe(false);
|
|
15
|
+
expect(isRegExp(Object({}))).toBe(false);
|
|
16
|
+
expect(isRegExp(() => {})).toBe(false);
|
|
17
|
+
expect(isRegExp(undefined)).toBe(false);
|
|
18
|
+
expect(isRegExp(null)).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { convertWin32PathToUnix } from './convertWin32PathToUnix';
|
|
2
|
+
|
|
3
|
+
describe('convertWin32PathToUnix', () => {
|
|
4
|
+
test('Should correctly convert Windows-like path to Unix-like', () => {
|
|
5
|
+
expect(convertWin32PathToUnix('C:\\mock-config-server\\dist\\src\\static\\views')).toEqual(
|
|
6
|
+
'C:/mock-config-server/dist/src/static/views'
|
|
7
|
+
);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('Should correctly convert long Windows-like path to Unix-like', () => {
|
|
11
|
+
expect(convertWin32PathToUnix('\\\\?\\mock-config-server\\dist\\src\\static\\views')).toEqual(
|
|
12
|
+
'mock-config-server/dist/src/static/views'
|
|
13
|
+
);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('Should correctly convert Windows-like path with double backslashes to Unix-like', () => {
|
|
17
|
+
expect(convertWin32PathToUnix('C:\\\\mock-config-server\\dist\\src\\static\\views')).toEqual(
|
|
18
|
+
'C:/mock-config-server/dist/src/static/views'
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getUrlParts } from './getUrlParts';
|
|
2
|
+
|
|
3
|
+
describe('getUrlParts', () => {
|
|
4
|
+
test('Should correct parse url parts', () => {
|
|
5
|
+
expect(getUrlParts('/part1/part2/')).toEqual(['part1', 'part2']);
|
|
6
|
+
expect(getUrlParts('//part1/part2///')).toEqual(['part1', 'part2']);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { removeLeadingAndTrailingSlashes } from './removeLeadingAndTrailingSlashes';
|
|
2
|
+
|
|
3
|
+
describe('removeLeadingAndTrailingSlashes', () => {
|
|
4
|
+
test('Should correct remove leading and trailing slashes', () => {
|
|
5
|
+
expect(removeLeadingAndTrailingSlashes('///base/users/1')).toEqual('base/users/1');
|
|
6
|
+
expect(removeLeadingAndTrailingSlashes('//base/users/1///')).toEqual('base/users/1');
|
|
7
|
+
expect(removeLeadingAndTrailingSlashes('base/users/1/')).toEqual('base/users/1');
|
|
8
|
+
expect(removeLeadingAndTrailingSlashes('/base/users/1')).toEqual('base/users/1');
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { urlJoin } from './urlJoin';
|
|
2
|
+
|
|
3
|
+
describe('urlJoin', () => {
|
|
4
|
+
test('Should correctly merge paths', () => {
|
|
5
|
+
expect(urlJoin('/base', '/rest')).toEqual('/base/rest');
|
|
6
|
+
expect(urlJoin('/base', 'rest')).toEqual('/base/rest');
|
|
7
|
+
expect(urlJoin('/base', 'rest', '/users')).toEqual('/base/rest/users');
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -1,74 +1,83 @@
|
|
|
1
1
|
import type { Request } from 'express';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CheckActualValueCheckMode, CheckFunction, CheckMode, CompareWithDescriptorAnyValueCheckMode, CompareWithDescriptorValueCheckMode } from './checkModes';
|
|
3
3
|
import type { Interceptors } from './interceptors';
|
|
4
|
-
import type {
|
|
4
|
+
import type { NestedObjectOrArray } from './utils';
|
|
5
|
+
import type { Data } from './values';
|
|
5
6
|
export type GraphQLEntityName = 'headers' | 'cookies' | 'query' | 'variables';
|
|
6
|
-
|
|
7
|
+
type GraphQLPlainEntityValue = string | number | boolean | null;
|
|
7
8
|
type GraphQLMappedEntityValue = string | number | boolean;
|
|
8
|
-
type
|
|
9
|
-
checkMode
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
checkMode
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
[key: string]: GraphQLPlainEntityInnerValue | Primitive | GraphQLEntityDescriptor;
|
|
20
|
-
};
|
|
21
|
-
export type GraphQLOperationType = 'query' | 'mutation';
|
|
22
|
-
type GraphQLOperationName = string | RegExp;
|
|
23
|
-
interface GraphQLQuery {
|
|
24
|
-
operationType: GraphQLOperationType;
|
|
25
|
-
operationName: GraphQLOperationName;
|
|
26
|
-
}
|
|
27
|
-
type GraphQLVariables = Record<string, any>;
|
|
28
|
-
export interface GraphQLInput {
|
|
29
|
-
query?: string;
|
|
30
|
-
variables: GraphQLVariables;
|
|
31
|
-
}
|
|
32
|
-
type GraphQLEntityValue<EntityName = GraphQLEntityName> = EntityName extends 'variables' ? GraphQLPlainEntityValue : GraphQLMappedEntityValue;
|
|
33
|
-
type GraphQLEntityValueOrValues<EntityName = GraphQLEntityName> = GraphQLEntityValue<EntityName> | GraphQLEntityValue<EntityName>[];
|
|
34
|
-
type GraphQLEntityDescriptor<EntityName extends GraphQLEntityName = GraphQLEntityName, Check extends CheckMode = CheckMode> = EntityName extends 'variables' ? Check extends Extract<CalculateByDescriptorValueCheckMode, 'function'> ? {
|
|
9
|
+
export type GraphQLTopLevelPlainEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? {
|
|
10
|
+
checkMode: Check;
|
|
11
|
+
value: (actualValue: NestedObjectOrArray<GraphQLPlainEntityValue>, checkFunction: CheckFunction) => boolean;
|
|
12
|
+
} : Check extends CompareWithDescriptorAnyValueCheckMode ? {
|
|
13
|
+
checkMode: Check;
|
|
14
|
+
value: NestedObjectOrArray<GraphQLPlainEntityValue>;
|
|
15
|
+
} : Check extends CheckActualValueCheckMode ? {
|
|
16
|
+
checkMode: Check;
|
|
17
|
+
value: never;
|
|
18
|
+
} : never;
|
|
19
|
+
type GraphQLPropertyLevelPlainEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? {
|
|
35
20
|
checkMode: Check;
|
|
36
|
-
value: (actualValue:
|
|
21
|
+
value: (actualValue: GraphQLPlainEntityValue | NestedObjectOrArray<GraphQLPlainEntityValue>, checkFunction: CheckFunction) => boolean;
|
|
37
22
|
} : Check extends CompareWithDescriptorAnyValueCheckMode ? {
|
|
38
23
|
checkMode: Check;
|
|
39
|
-
value:
|
|
24
|
+
value: GraphQLPlainEntityValue | NestedObjectOrArray<GraphQLPlainEntityValue>;
|
|
40
25
|
} : Check extends CheckActualValueCheckMode ? {
|
|
41
26
|
checkMode: Check;
|
|
42
|
-
value
|
|
43
|
-
} : never
|
|
27
|
+
value: never;
|
|
28
|
+
} : never;
|
|
29
|
+
type GraphQLMappedEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? {
|
|
44
30
|
checkMode: Check;
|
|
45
|
-
value: (actualValue:
|
|
46
|
-
} : Check extends
|
|
31
|
+
value: (actualValue: GraphQLMappedEntityValue, checkFunction: CheckFunction) => boolean;
|
|
32
|
+
} : Check extends 'regExp' ? {
|
|
47
33
|
checkMode: Check;
|
|
48
34
|
value: RegExp | RegExp[];
|
|
49
35
|
} : Check extends CompareWithDescriptorValueCheckMode ? {
|
|
50
36
|
checkMode: Check;
|
|
51
|
-
value:
|
|
37
|
+
value: GraphQLMappedEntityValue | GraphQLMappedEntityValue[];
|
|
52
38
|
} : Check extends CheckActualValueCheckMode ? {
|
|
53
39
|
checkMode: Check;
|
|
54
|
-
value
|
|
40
|
+
value: never;
|
|
55
41
|
} : never;
|
|
56
|
-
export type GraphQLEntityDescriptorOrValue<EntityName extends GraphQLEntityName = GraphQLEntityName> = EntityName extends 'variables' ?
|
|
57
|
-
export type
|
|
58
|
-
export
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
type
|
|
63
|
-
[EntityName in
|
|
42
|
+
export type GraphQLEntityDescriptorOrValue<EntityName extends GraphQLEntityName = GraphQLEntityName> = EntityName extends 'variables' ? GraphQLTopLevelPlainEntityDescriptor | Record<string, GraphQLPropertyLevelPlainEntityDescriptor> | NestedObjectOrArray<GraphQLPlainEntityValue> : Record<string, GraphQLMappedEntityDescriptor | GraphQLMappedEntityValue | GraphQLMappedEntityValue[]>;
|
|
43
|
+
export type GraphQLOperationType = 'query' | 'mutation';
|
|
44
|
+
export type GraphQLOperationName = string | RegExp;
|
|
45
|
+
export type GraphQLEntityNamesByOperationType = {
|
|
46
|
+
[operationType in GraphQLOperationType]: GraphQLEntityName;
|
|
47
|
+
};
|
|
48
|
+
export type GraphQLEntitiesByEntityName = {
|
|
49
|
+
[EntityName in GraphQLEntityName]?: GraphQLEntityDescriptorOrValue<EntityName>;
|
|
50
|
+
};
|
|
51
|
+
type GraphQLSettings = {
|
|
52
|
+
readonly polling: boolean;
|
|
64
53
|
};
|
|
65
|
-
export
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
export type GraphQLRouteConfig<Settings extends GraphQLSettings = GraphQLSettings> = ({
|
|
55
|
+
settings: Settings & {
|
|
56
|
+
polling: true;
|
|
57
|
+
};
|
|
58
|
+
queue: Array<{
|
|
59
|
+
time?: number;
|
|
60
|
+
data: ((request: Request, entities: GraphQLEntitiesByEntityName) => Data | Promise<Data>) | Data;
|
|
61
|
+
}>;
|
|
62
|
+
} | {
|
|
63
|
+
settings?: Settings & {
|
|
64
|
+
polling?: false;
|
|
65
|
+
};
|
|
66
|
+
data: ((request: Request, entities: GraphQLEntitiesByEntityName) => Data | Promise<Data>) | Data;
|
|
67
|
+
}) & {
|
|
68
|
+
entities?: GraphQLEntitiesByEntityName;
|
|
68
69
|
interceptors?: Pick<Interceptors, 'response'>;
|
|
69
|
-
}
|
|
70
|
-
|
|
70
|
+
};
|
|
71
|
+
interface BaseGraphQLRequestConfig {
|
|
72
|
+
operationType: GraphQLOperationType;
|
|
71
73
|
routes: GraphQLRouteConfig[];
|
|
72
74
|
interceptors?: Interceptors;
|
|
73
75
|
}
|
|
76
|
+
export interface OperationNameGraphQLRequestConfig extends BaseGraphQLRequestConfig {
|
|
77
|
+
operationName: GraphQLOperationName;
|
|
78
|
+
}
|
|
79
|
+
interface QueryGraphQLRequestConfig extends BaseGraphQLRequestConfig {
|
|
80
|
+
query: string;
|
|
81
|
+
}
|
|
82
|
+
export type GraphQLRequestConfig = OperationNameGraphQLRequestConfig | QueryGraphQLRequestConfig;
|
|
74
83
|
export {};
|
|
@@ -69,6 +69,17 @@ Object.keys(_server).forEach(function (key) {
|
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
|
+
var _utils = require("./utils");
|
|
73
|
+
Object.keys(_utils).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _utils[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _utils[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
72
83
|
var _values = require("./values");
|
|
73
84
|
Object.keys(_values).forEach(function (key) {
|
|
74
85
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -8,7 +8,7 @@ export interface RequestInterceptorParams {
|
|
|
8
8
|
getHeader: (field: string) => RequestInterceptorHeaderValue;
|
|
9
9
|
getHeaders: () => Record<string, RequestInterceptorHeaderValue>;
|
|
10
10
|
}
|
|
11
|
-
export type RequestInterceptor = (params: RequestInterceptorParams) => void
|
|
11
|
+
export type RequestInterceptor = (params: RequestInterceptorParams) => void | Promise<void>;
|
|
12
12
|
export interface ResponseInterceptorParams {
|
|
13
13
|
request: Request;
|
|
14
14
|
response: Response;
|
|
@@ -1,65 +1,72 @@
|
|
|
1
1
|
import type { Request } from 'express';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CheckActualValueCheckMode, CheckFunction, CheckMode, CompareWithDescriptorAnyValueCheckMode, CompareWithDescriptorValueCheckMode } from './checkModes';
|
|
3
3
|
import type { Interceptors } from './interceptors';
|
|
4
|
-
import type {
|
|
4
|
+
import type { NestedObjectOrArray } from './utils';
|
|
5
|
+
import type { Data } from './values';
|
|
5
6
|
export type RestMethod = 'get' | 'post' | 'delete' | 'put' | 'patch' | 'options';
|
|
6
7
|
export type RestEntityName = 'headers' | 'cookies' | 'query' | 'params' | 'body';
|
|
7
|
-
|
|
8
|
+
type RestPlainEntityValue = string | number | boolean | null;
|
|
8
9
|
type RestMappedEntityValue = string | number | boolean;
|
|
9
|
-
type
|
|
10
|
-
checkMode
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
checkMode
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} | (RestPlainEntityInnerValue | Primitive | RestEntityDescriptor)[];
|
|
21
|
-
type RestEntityValue<EntityName = RestEntityName> = EntityName extends 'body' ? RestPlainEntityValue : RestMappedEntityValue;
|
|
22
|
-
type RestEntityValueOrValues<EntityName = RestEntityName> = RestEntityValue<EntityName> | RestEntityValue<EntityName>[];
|
|
23
|
-
type RestEntityDescriptor<EntityName extends RestEntityName = RestEntityName, Check extends CheckMode = CheckMode> = EntityName extends 'body' ? Check extends Extract<CalculateByDescriptorValueCheckMode, 'function'> ? {
|
|
10
|
+
export type RestTopLevelPlainEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? {
|
|
11
|
+
checkMode: Check;
|
|
12
|
+
value: (actualValue: NestedObjectOrArray<RestPlainEntityValue>, checkFunction: CheckFunction) => boolean;
|
|
13
|
+
} : Check extends CompareWithDescriptorAnyValueCheckMode ? {
|
|
14
|
+
checkMode: Check;
|
|
15
|
+
value: NestedObjectOrArray<RestPlainEntityValue>;
|
|
16
|
+
} : Check extends CheckActualValueCheckMode ? {
|
|
17
|
+
checkMode: Check;
|
|
18
|
+
value: never;
|
|
19
|
+
} : never;
|
|
20
|
+
type RestPropertyLevelPlainEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? {
|
|
24
21
|
checkMode: Check;
|
|
25
|
-
value: (actualValue:
|
|
22
|
+
value: (actualValue: RestPlainEntityValue | NestedObjectOrArray<RestPlainEntityValue>, checkFunction: CheckFunction) => boolean;
|
|
26
23
|
} : Check extends CompareWithDescriptorAnyValueCheckMode ? {
|
|
27
24
|
checkMode: Check;
|
|
28
|
-
value:
|
|
25
|
+
value: RestPlainEntityValue | NestedObjectOrArray<RestPlainEntityValue>;
|
|
29
26
|
} : Check extends CheckActualValueCheckMode ? {
|
|
30
27
|
checkMode: Check;
|
|
31
|
-
value
|
|
32
|
-
} : never
|
|
28
|
+
value: never;
|
|
29
|
+
} : never;
|
|
30
|
+
type RestMappedEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? {
|
|
33
31
|
checkMode: Check;
|
|
34
|
-
value: (actualValue:
|
|
35
|
-
} : Check extends
|
|
32
|
+
value: (actualValue: RestMappedEntityValue, checkFunction: CheckFunction) => boolean;
|
|
33
|
+
} : Check extends 'regExp' ? {
|
|
36
34
|
checkMode: Check;
|
|
37
35
|
value: RegExp | RegExp[];
|
|
38
36
|
} : Check extends CompareWithDescriptorValueCheckMode ? {
|
|
39
37
|
checkMode: Check;
|
|
40
|
-
value:
|
|
38
|
+
value: RestMappedEntityValue | RestMappedEntityValue[];
|
|
41
39
|
} : Check extends CheckActualValueCheckMode ? {
|
|
42
40
|
checkMode: Check;
|
|
43
|
-
value
|
|
41
|
+
value: never;
|
|
44
42
|
} : never;
|
|
45
|
-
export type RestEntityDescriptorOrValue<EntityName extends RestEntityName = RestEntityName> = EntityName extends 'body' ?
|
|
46
|
-
export type
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
post: RestEntityName;
|
|
51
|
-
put: RestEntityName;
|
|
52
|
-
patch: RestEntityName;
|
|
53
|
-
options: Exclude<RestEntityName, 'body'>;
|
|
54
|
-
}
|
|
55
|
-
export type RestEntityByEntityName<Method extends RestMethod> = {
|
|
43
|
+
export type RestEntityDescriptorOrValue<EntityName extends RestEntityName = RestEntityName> = EntityName extends 'body' ? RestTopLevelPlainEntityDescriptor | Record<string, RestPropertyLevelPlainEntityDescriptor> | NestedObjectOrArray<RestPlainEntityValue> : Record<string, RestMappedEntityDescriptor | RestMappedEntityValue | RestMappedEntityValue[]>;
|
|
44
|
+
export type RestEntityNamesByMethod = {
|
|
45
|
+
[key in RestMethod]: key extends 'get' | 'delete' | 'options' ? Exclude<RestEntityName, 'body'> : RestEntityName;
|
|
46
|
+
};
|
|
47
|
+
export type RestEntitiesByEntityName<Method extends RestMethod = RestMethod> = {
|
|
56
48
|
[EntityName in RestEntityNamesByMethod[Method]]?: RestEntityDescriptorOrValue<EntityName>;
|
|
57
49
|
};
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
interface RestSettings {
|
|
51
|
+
readonly polling?: boolean;
|
|
52
|
+
}
|
|
53
|
+
export type RestRouteConfig<Method extends RestMethod, Entities extends RestEntitiesByEntityName<Method> = RestEntitiesByEntityName<Method>, Settings extends RestSettings = RestSettings> = ({
|
|
54
|
+
settings: Settings & {
|
|
55
|
+
polling: true;
|
|
56
|
+
};
|
|
57
|
+
queue: Array<{
|
|
58
|
+
time?: number;
|
|
59
|
+
data: ((request: Request, entities: Entities) => Data | Promise<Data>) | Data;
|
|
60
|
+
}>;
|
|
61
|
+
} | {
|
|
62
|
+
settings?: Settings & {
|
|
63
|
+
polling: false;
|
|
64
|
+
};
|
|
60
65
|
data: ((request: Request, entities: Entities) => Data | Promise<Data>) | Data;
|
|
66
|
+
}) & {
|
|
67
|
+
entities?: Entities;
|
|
61
68
|
interceptors?: Pick<Interceptors, 'response'>;
|
|
62
|
-
}
|
|
69
|
+
};
|
|
63
70
|
export type RestPathString = `/${string}`;
|
|
64
71
|
interface BaseRestRequestConfig<Method extends RestMethod> {
|
|
65
72
|
path: RestPathString | RegExp;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PlainObject } from './values';
|
|
2
|
+
export type ValueOf<T extends PlainObject | Array<any>> = T extends Array<any> ? T[number] : T[keyof T];
|
|
3
|
+
export type Entries<T extends PlainObject | Array<any>> = ValueOf<{
|
|
4
|
+
[K in keyof T]-?: [K, T[K]];
|
|
5
|
+
}>[];
|
|
6
|
+
export type NestedObjectOrArray<T> = {
|
|
7
|
+
[key: string]: NestedObjectOrArray<T> | T;
|
|
8
|
+
} | Array<NestedObjectOrArray<T> | T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export type PlainObject = Record<string, any>;
|
|
2
|
-
export type PlainFunction = (...args: any[]) => any;
|
|
3
2
|
export type Primitive = boolean | number | bigint | string | null | undefined | symbol;
|
|
4
3
|
export type Data = boolean | number | string | any[] | Record<any, any> | null | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mock-config-server",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "Tool that easily and quickly imitates server operation, create full fake api in few steps",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SIBERIA CAN CODE 🧊",
|
|
@@ -25,8 +25,7 @@
|
|
|
25
25
|
}
|
|
26
26
|
],
|
|
27
27
|
"license": "MIT",
|
|
28
|
-
"main": "dist/
|
|
29
|
-
"module": "dist/esm/index.js",
|
|
28
|
+
"main": "dist/index.js",
|
|
30
29
|
"types": "./dist/index.d.ts",
|
|
31
30
|
"bin": {
|
|
32
31
|
"mock-config-server": "dist/bin/bin.js",
|