mock-config-server 3.3.4 → 3.4.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.
Files changed (171) hide show
  1. package/README.md +107 -3
  2. package/dist/bin/build.js +1 -1
  3. package/dist/bin/cli.d.ts +1 -1
  4. package/dist/bin/cli.js +25 -16
  5. package/dist/bin/helpers/createTemplate.d.ts +9 -0
  6. package/dist/bin/helpers/createTemplate.js +25 -0
  7. package/dist/bin/helpers/getMostSpecificPathFromError.d.ts +2 -0
  8. package/dist/bin/helpers/getMostSpecificPathFromError.js +36 -0
  9. package/dist/bin/helpers/getValidationMessageFromPath.d.ts +1 -0
  10. package/dist/bin/helpers/getValidationMessageFromPath.js +11 -0
  11. package/dist/bin/helpers/index.d.ts +4 -0
  12. package/dist/bin/helpers/index.js +44 -0
  13. package/dist/bin/helpers/isOnlyRequestedDataResolvingPropertyExists.d.ts +4 -0
  14. package/dist/bin/helpers/isOnlyRequestedDataResolvingPropertyExists.js +9 -0
  15. package/dist/bin/init.d.ts +2 -0
  16. package/dist/bin/init.js +101 -0
  17. package/dist/bin/run.d.ts +1 -1
  18. package/dist/bin/run.js +29 -2
  19. package/dist/bin/templates/.eslintrc.js +14 -0
  20. package/dist/bin/templates/js/full/mock-requests/graphql/index.js +2 -0
  21. package/dist/bin/templates/js/full/mock-requests/graphql/user.js +35 -0
  22. package/dist/bin/templates/js/full/mock-requests/graphql/users.js +12 -0
  23. package/dist/bin/templates/js/full/mock-requests/rest/index.js +2 -0
  24. package/dist/bin/templates/js/full/mock-requests/rest/user.js +35 -0
  25. package/dist/bin/templates/js/full/mock-requests/rest/users.js +12 -0
  26. package/dist/bin/templates/js/full/mock-server.config.js +16 -0
  27. package/dist/bin/templates/js/graphql/mock-requests/index.js +2 -0
  28. package/dist/bin/templates/js/graphql/mock-requests/user.js +35 -0
  29. package/dist/bin/templates/js/graphql/mock-requests/users.js +12 -0
  30. package/dist/bin/templates/js/graphql/mock-server.config.js +9 -0
  31. package/dist/bin/templates/js/rest/mock-requests/index.js +2 -0
  32. package/dist/bin/templates/js/rest/mock-requests/user.js +35 -0
  33. package/dist/bin/templates/js/rest/mock-requests/users.js +12 -0
  34. package/dist/bin/templates/js/rest/mock-server.config.js +9 -0
  35. package/dist/bin/templates/ts/full/mock-requests/graphql/index.ts +2 -0
  36. package/dist/bin/templates/ts/full/mock-requests/graphql/user.ts +37 -0
  37. package/dist/bin/templates/ts/full/mock-requests/graphql/users.ts +14 -0
  38. package/dist/bin/templates/ts/full/mock-requests/rest/index.ts +2 -0
  39. package/dist/bin/templates/ts/full/mock-requests/rest/user.ts +37 -0
  40. package/dist/bin/templates/ts/full/mock-requests/rest/users.ts +14 -0
  41. package/dist/bin/templates/ts/full/mock-server.config.ts +18 -0
  42. package/dist/bin/templates/ts/graphql/mock-requests/index.ts +2 -0
  43. package/dist/bin/templates/ts/graphql/mock-requests/user.ts +37 -0
  44. package/dist/bin/templates/ts/graphql/mock-requests/users.ts +14 -0
  45. package/dist/bin/templates/ts/graphql/mock-server.config.ts +11 -0
  46. package/dist/bin/templates/ts/rest/mock-requests/index.ts +2 -0
  47. package/dist/bin/templates/ts/rest/mock-requests/user.ts +37 -0
  48. package/dist/bin/templates/ts/rest/mock-requests/users.ts +14 -0
  49. package/dist/bin/templates/ts/rest/mock-server.config.ts +11 -0
  50. package/dist/bin/templates/tsconfig.json +11 -0
  51. package/dist/bin/validateMockServerConfig/baseUrlSchema/baseUrlSchema.d.ts +1 -0
  52. package/dist/bin/validateMockServerConfig/baseUrlSchema/baseUrlSchema.js +8 -0
  53. package/dist/bin/validateMockServerConfig/corsSchema/corsSchema.d.ts +23 -0
  54. package/dist/bin/validateMockServerConfig/corsSchema/corsSchema.js +17 -0
  55. package/dist/bin/validateMockServerConfig/databaseConfigSchema/databaseConfigSchema.d.ts +11 -0
  56. package/dist/bin/validateMockServerConfig/databaseConfigSchema/databaseConfigSchema.js +12 -0
  57. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.d.ts +248 -0
  58. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/graphqlConfigSchema.js +31 -0
  59. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +61 -0
  60. package/dist/bin/validateMockServerConfig/graphqlConfigSchema/routeConfigSchema/routeConfigSchema.js +37 -0
  61. package/dist/bin/validateMockServerConfig/interceptorsSchema/interceptorsSchema.d.ts +11 -0
  62. package/dist/bin/validateMockServerConfig/interceptorsSchema/interceptorsSchema.js +11 -0
  63. package/dist/bin/validateMockServerConfig/portSchema/portSchema.d.ts +2 -0
  64. package/dist/bin/validateMockServerConfig/portSchema/portSchema.js +9 -0
  65. package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.d.ts +8 -0
  66. package/dist/bin/validateMockServerConfig/queueSchema/queueSchema.js +12 -0
  67. package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.d.ts +713 -0
  68. package/dist/bin/validateMockServerConfig/restConfigSchema/restConfigSchema.js +23 -0
  69. package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.d.ts +77 -0
  70. package/dist/bin/validateMockServerConfig/restConfigSchema/routeConfigSchema/routeConfigSchema.js +52 -0
  71. package/dist/bin/validateMockServerConfig/settingsSchema/settingsSchema.d.ts +14 -0
  72. package/dist/bin/validateMockServerConfig/settingsSchema/settingsSchema.js +12 -0
  73. package/dist/bin/validateMockServerConfig/staticPathSchema/staticPathSchema.d.ts +20 -0
  74. package/dist/bin/validateMockServerConfig/staticPathSchema/staticPathSchema.js +14 -0
  75. package/dist/bin/validateMockServerConfig/utils/checkModeSchema/checkModeSchema.d.ts +5 -0
  76. package/dist/bin/validateMockServerConfig/utils/checkModeSchema/checkModeSchema.js +12 -0
  77. package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.d.ts +75 -0
  78. package/dist/bin/validateMockServerConfig/utils/entitiesSchema/entitiesSchema.js +67 -0
  79. package/dist/bin/validateMockServerConfig/utils/index.d.ts +6 -0
  80. package/dist/bin/validateMockServerConfig/utils/index.js +71 -0
  81. package/dist/bin/validateMockServerConfig/utils/jsonSchema/jsonSchema.d.ts +8 -0
  82. package/dist/bin/validateMockServerConfig/utils/jsonSchema/jsonSchema.js +13 -0
  83. package/dist/bin/validateMockServerConfig/utils/plainObjectSchema/plainObjectSchema.d.ts +2 -0
  84. package/dist/bin/validateMockServerConfig/utils/plainObjectSchema/plainObjectSchema.js +11 -0
  85. package/dist/bin/validateMockServerConfig/utils/requiredPropertiesSchema/requiredPropertiesSchema.d.ts +3 -0
  86. package/dist/bin/validateMockServerConfig/utils/requiredPropertiesSchema/requiredPropertiesSchema.js +10 -0
  87. package/dist/bin/validateMockServerConfig/utils/sharedSchema/sharedSchema.d.ts +3 -0
  88. package/dist/bin/validateMockServerConfig/utils/sharedSchema/sharedSchema.js +9 -0
  89. package/dist/bin/validateMockServerConfig/validateApiMockServerConfig.d.ts +2 -0
  90. package/dist/bin/validateMockServerConfig/validateApiMockServerConfig.js +44 -0
  91. package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +27 -20
  92. package/dist/src/core/database/createDatabaseRoutes/helpers/createNestedDatabaseRoutes/createNestedDatabaseRoutes.js +27 -16
  93. package/dist/src/core/database/createDatabaseRoutes/helpers/createShallowDatabaseRoutes/createShallowDatabaseRoutes.js +64 -3
  94. package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.d.ts +1 -0
  95. package/dist/src/core/database/createDatabaseRoutes/helpers/filter/filter.js +46 -6
  96. package/dist/src/core/database/createDatabaseRoutes/helpers/pagination/pagination.d.ts +1 -0
  97. package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.d.ts +4 -0
  98. package/dist/src/core/database/createDatabaseRoutes/helpers/search/search.js +29 -0
  99. package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.d.ts +1 -0
  100. package/dist/src/core/database/createDatabaseRoutes/helpers/sort/sort.js +3 -4
  101. package/dist/src/core/database/createDatabaseRoutes/storages/File/FileWriter.js +2 -2
  102. package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +13 -7
  103. package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +7 -1
  104. package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +27 -10
  105. package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +6 -0
  106. package/dist/src/server/createGraphQLMockServer/createGraphQLMockServer.js +1 -1
  107. package/dist/src/server/createRestMockServer/createRestMockServer.js +1 -1
  108. package/dist/src/static/views/components/header/index.js +1 -1
  109. package/dist/src/static/views/features/scheme/index.js +31 -31
  110. package/dist/src/static/views/features/tab/index.js +12 -12
  111. package/dist/src/utils/constants/appPath.js +1 -2
  112. package/dist/src/utils/constants/checkModes.d.ts +8 -9
  113. package/dist/src/utils/constants/checkModes.js +8 -16
  114. package/dist/src/utils/constants/default.js +2 -3
  115. package/dist/src/utils/helpers/files/index.d.ts +1 -0
  116. package/dist/src/utils/helpers/files/index.js +16 -0
  117. package/dist/src/utils/helpers/files/isFilePathValid/isFilePathValid.d.ts +1 -0
  118. package/dist/src/utils/helpers/files/isFilePathValid/isFilePathValid.js +19 -0
  119. package/dist/src/utils/helpers/index.d.ts +1 -0
  120. package/dist/src/utils/helpers/index.js +11 -0
  121. package/dist/src/utils/helpers/tests/createTmpDir.d.ts +1 -0
  122. package/dist/src/utils/helpers/tests/createTmpDir.js +12 -0
  123. package/dist/src/utils/helpers/tests/index.d.ts +1 -0
  124. package/dist/{bin/validateMockServerConfig/helpers/isCheckModeValid → src/utils/helpers/tests}/index.js +4 -4
  125. package/dist/src/utils/types/entities.d.ts +48 -0
  126. package/dist/src/utils/types/entities.js +1 -0
  127. package/dist/src/utils/types/graphql.d.ts +11 -45
  128. package/dist/src/utils/types/index.d.ts +1 -0
  129. package/dist/src/utils/types/index.js +11 -0
  130. package/dist/src/utils/types/rest.d.ts +17 -46
  131. package/dist/src/utils/types/server.d.ts +5 -4
  132. package/package.json +35 -27
  133. package/dist/bin/resolveConfigFilePath/resolveConfigFilePath.d.ts +0 -1
  134. package/dist/bin/resolveConfigFilePath/resolveConfigFilePath.js +0 -16
  135. package/dist/bin/validateMockServerConfig/helpers/index.d.ts +0 -2
  136. package/dist/bin/validateMockServerConfig/helpers/index.js +0 -27
  137. package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/index.d.ts +0 -1
  138. package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/isCheckModeValid.d.ts +0 -1
  139. package/dist/bin/validateMockServerConfig/helpers/isCheckModeValid/isCheckModeValid.js +0 -12
  140. package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/index.d.ts +0 -1
  141. package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/index.js +0 -16
  142. package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.d.ts +0 -2
  143. package/dist/bin/validateMockServerConfig/helpers/isDescriptorValueValid/isDescriptorValueValid.js +0 -43
  144. package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.d.ts +0 -1
  145. package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.js +0 -15
  146. package/dist/bin/validateMockServerConfig/validateCors/validateCors.d.ts +0 -1
  147. package/dist/bin/validateMockServerConfig/validateCors/validateCors.js +0 -84
  148. package/dist/bin/validateMockServerConfig/validateDatabaseConfig/validateDatabaseConfig.d.ts +0 -1
  149. package/dist/bin/validateMockServerConfig/validateDatabaseConfig/validateDatabaseConfig.js +0 -45
  150. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.d.ts +0 -1
  151. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.js +0 -58
  152. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.d.ts +0 -2
  153. package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +0 -153
  154. package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.d.ts +0 -1
  155. package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.js +0 -27
  156. package/dist/bin/validateMockServerConfig/validatePort/validatePort.d.ts +0 -1
  157. package/dist/bin/validateMockServerConfig/validatePort/validatePort.js +0 -12
  158. package/dist/bin/validateMockServerConfig/validateQueue/validateQueue.d.ts +0 -1
  159. package/dist/bin/validateMockServerConfig/validateQueue/validateQueue.js +0 -29
  160. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.d.ts +0 -1
  161. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.js +0 -57
  162. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.d.ts +0 -2
  163. package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +0 -157
  164. package/dist/bin/validateMockServerConfig/validateSettings/validateSettings.d.ts +0 -1
  165. package/dist/bin/validateMockServerConfig/validateSettings/validateSettings.js +0 -34
  166. package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.d.ts +0 -1
  167. package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.js +0 -53
  168. package/dist/src/core/database/createOrm/createOrm.d.ts +0 -4
  169. package/dist/src/core/database/createOrm/createOrm.js +0 -70
  170. package/dist/src/core/database/createStorage/createStorage.d.ts +0 -2
  171. package/dist/src/core/database/createStorage/createStorage.js +0 -10
@@ -1,157 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validateRoutes = void 0;
7
- var _helpers = require("../../../../src/utils/helpers");
8
- var _helpers2 = require("../../helpers");
9
- var _validateInterceptors = require("../../validateInterceptors/validateInterceptors");
10
- var _validateQueue = require("../../validateQueue/validateQueue");
11
- var _validateSettings = require("../../validateSettings/validateSettings");
12
- const ALLOWED_ENTITIES_BY_METHOD = {
13
- get: ['headers', 'cookies', 'query', 'params'],
14
- delete: ['headers', 'cookies', 'query', 'params'],
15
- post: ['headers', 'cookies', 'query', 'params', 'body'],
16
- put: ['headers', 'cookies', 'query', 'params', 'body'],
17
- patch: ['headers', 'cookies', 'query', 'params', 'body'],
18
- options: ['headers', 'cookies', 'query', 'params']
19
- };
20
- const validateEntity = (entity, entityName) => {
21
- const isBody = entityName === 'body';
22
- const isEntityTopLevelDescriptor = (0, _helpers.isEntityDescriptor)(entity);
23
- if (isEntityTopLevelDescriptor) {
24
- if (!isBody) {
25
- throw new Error(entityName);
26
- }
27
- if (!(0, _helpers2.isCheckModeValid)(entity.checkMode, 'body')) {
28
- throw new Error('body.checkMode');
29
- }
30
- const isDescriptorValueObjectOrArray = (0, _helpers.isPlainObject)(entity.value) || Array.isArray(entity.value);
31
- if (!isDescriptorValueObjectOrArray || !(0, _helpers2.isDescriptorValueValid)(entity.checkMode, entity.value)) {
32
- throw new Error('body.value');
33
- }
34
- return;
35
- }
36
- const isEntityArray = Array.isArray(entity);
37
- if (isEntityArray) {
38
- if (!isBody) {
39
- throw new Error(entityName);
40
- }
41
- entity.forEach((entityElement, index) => {
42
- const isEntityElementObjectOrArray = (0, _helpers.isPlainObject)(entityElement) || Array.isArray(entityElement);
43
- if (!isEntityElementObjectOrArray || !(0, _helpers2.isDescriptorValueValid)('equals', entityElement)) {
44
- throw new Error(`${entityName}[${index}]`);
45
- }
46
- });
47
- return;
48
- }
49
- const isEntityObject = (0, _helpers.isPlainObject)(entity);
50
- if (isEntityObject) {
51
- Object.entries(entity).forEach(([key, valueOrDescriptor]) => {
52
- const {
53
- checkMode,
54
- value
55
- } = (0, _helpers.convertToEntityDescriptor)(valueOrDescriptor);
56
- if (!(0, _helpers2.isCheckModeValid)(checkMode)) {
57
- throw new Error(`${entityName}.${key}.checkMode`);
58
- }
59
- const isDescriptor = (0, _helpers.isEntityDescriptor)(valueOrDescriptor);
60
- const errorMessage = `${entityName}.${key}${isDescriptor ? '.value' : ''}`;
61
- const isValueArray = Array.isArray(value);
62
- if (isValueArray) {
63
- value.forEach((element, index) => {
64
- if (isBody) {
65
- if ((0, _helpers2.isDescriptorValueValid)(checkMode, element)) return;
66
- throw new Error(`${errorMessage}[${index}]`);
67
- }
68
- const isElementObjectOrArray = (0, _helpers.isPlainObject)(element) || Array.isArray(element);
69
- if (isElementObjectOrArray || !(0, _helpers2.isDescriptorValueValid)(checkMode, element)) {
70
- throw new Error(`${errorMessage}[${index}]`);
71
- }
72
- });
73
- return;
74
- }
75
- if (isBody) {
76
- if ((0, _helpers2.isDescriptorValueValid)(checkMode, value)) return;
77
- throw new Error(errorMessage);
78
- }
79
- const isValueObject = (0, _helpers.isPlainObject)(value);
80
- if (isValueObject || !(0, _helpers2.isDescriptorValueValid)(checkMode, value)) {
81
- throw new Error(errorMessage);
82
- }
83
- });
84
- return;
85
- }
86
- throw new Error(entityName);
87
- };
88
- const validateEntities = (entities, method) => {
89
- const isEntitiesObject = (0, _helpers.isPlainObject)(entities);
90
- if (isEntitiesObject) {
91
- Object.keys(entities).forEach(entityName => {
92
- const isEntityAllowed = ALLOWED_ENTITIES_BY_METHOD[method].includes(entityName);
93
- if (!isEntityAllowed) {
94
- throw new Error(`entities.${entityName}`);
95
- }
96
- try {
97
- validateEntity(entities[entityName], entityName);
98
- } catch (error) {
99
- throw new Error(`entities.${error.message}`);
100
- }
101
- });
102
- return;
103
- }
104
- if (typeof entities !== 'undefined') {
105
- throw new Error('entities');
106
- }
107
- };
108
- const validateRoutes = (routes, method) => {
109
- const isRoutesArray = Array.isArray(routes);
110
- if (isRoutesArray) {
111
- routes.forEach((route, index) => {
112
- const isRouteObject = (0, _helpers.isPlainObject)(route);
113
- if (isRouteObject) {
114
- const isRouteHasDataProperty = ('data' in route);
115
- const isRouteHasQueueProperty = ('queue' in route);
116
- if (!isRouteHasDataProperty && !isRouteHasQueueProperty) {
117
- throw new Error(`routes[${index}]`);
118
- }
119
- if (isRouteHasDataProperty && isRouteHasQueueProperty) {
120
- throw new Error(`routes[${index}]`);
121
- }
122
- const {
123
- settings
124
- } = route;
125
- const isRouteSettingsObject = (0, _helpers.isPlainObject)(settings);
126
- if (isRouteHasQueueProperty) {
127
- try {
128
- (0, _validateQueue.validateQueue)(route.queue);
129
- if (!isRouteSettingsObject) {
130
- throw new Error('settings');
131
- }
132
- if (!(isRouteSettingsObject && settings !== null && settings !== void 0 && settings.polling)) {
133
- throw new Error('settings.polling');
134
- }
135
- } catch (error) {
136
- throw new Error(`routes[${index}].${error.message}`);
137
- }
138
- }
139
- if (isRouteHasDataProperty && isRouteSettingsObject && settings !== null && settings !== void 0 && settings.polling) {
140
- throw new Error(`routes[${index}].settings.polling`);
141
- }
142
- try {
143
- (0, _validateSettings.validateSettings)(route.settings);
144
- validateEntities(route.entities, method);
145
- (0, _validateInterceptors.validateInterceptors)(route.interceptors);
146
- } catch (error) {
147
- throw new Error(`routes[${index}].${error.message}`);
148
- }
149
- return;
150
- }
151
- throw new Error(`routes[${index}]`);
152
- });
153
- return;
154
- }
155
- throw new Error('routes');
156
- };
157
- exports.validateRoutes = validateRoutes;
@@ -1 +0,0 @@
1
- export declare const validateSettings: (settings: unknown) => void;
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validateSettings = void 0;
7
- var _helpers = require("../../../src/utils/helpers");
8
- const ALLOWED_SETTINGS = ['polling'];
9
- const validateSetting = (setting, settingName) => {
10
- if (settingName === 'polling' && typeof setting !== 'boolean') {
11
- throw new Error('polling');
12
- }
13
- };
14
- const validateSettings = settings => {
15
- const isSettingsObject = (0, _helpers.isPlainObject)(settings);
16
- if (isSettingsObject) {
17
- Object.keys(settings).forEach(settingName => {
18
- const isSettingAllowed = ALLOWED_SETTINGS.includes(settingName);
19
- if (!isSettingAllowed) {
20
- throw new Error(`settings.${settingName}`);
21
- }
22
- try {
23
- validateSetting(settings[settingName], settingName);
24
- } catch (error) {
25
- throw new Error(`settings.${error.message}`);
26
- }
27
- });
28
- return;
29
- }
30
- if (typeof settings !== 'undefined') {
31
- throw new Error('settings');
32
- }
33
- };
34
- exports.validateSettings = validateSettings;
@@ -1 +0,0 @@
1
- export declare const validateStaticPath: (staticPath: unknown) => void;
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validateStaticPath = void 0;
7
- var _helpers = require("../../../src/utils/helpers");
8
- const validateStaticPath = staticPath => {
9
- const isStaticPathArray = Array.isArray(staticPath);
10
- if (isStaticPathArray) {
11
- staticPath.forEach((staticPathElement, index) => {
12
- const isStaticPathElementObject = (0, _helpers.isPlainObject)(staticPathElement);
13
- if (isStaticPathElementObject) {
14
- const {
15
- prefix,
16
- path
17
- } = staticPathElement;
18
- if (typeof prefix !== 'string' || !prefix.startsWith('/')) {
19
- throw new Error(`staticPath[${index}].prefix`);
20
- }
21
- if (typeof path !== 'string' || !path.startsWith('/')) {
22
- throw new Error(`staticPath[${index}].path`);
23
- }
24
- return;
25
- }
26
- if (typeof staticPathElement !== 'string' || !staticPathElement.startsWith('/')) {
27
- throw new Error(`staticPath[${index}]`);
28
- }
29
- });
30
- return;
31
- }
32
- const isStaticPathObject = (0, _helpers.isPlainObject)(staticPath);
33
- if (isStaticPathObject) {
34
- const {
35
- prefix,
36
- path
37
- } = staticPath;
38
- if (typeof prefix !== 'string' || !prefix.startsWith('/')) {
39
- throw new Error('staticPath.prefix');
40
- }
41
- if (typeof path !== 'string' || !path.startsWith('/')) {
42
- throw new Error('staticPath.path');
43
- }
44
- return;
45
- }
46
- if (typeof staticPath !== 'string' && typeof staticPath !== 'undefined') {
47
- throw new Error('staticPath');
48
- }
49
- if (typeof staticPath === 'string' && !staticPath.startsWith('/')) {
50
- throw new Error('staticPath');
51
- }
52
- };
53
- exports.validateStaticPath = validateStaticPath;
@@ -1,4 +0,0 @@
1
- import type { NestedOrm, ShallowOrm, Storage } from '../../../utils/types';
2
- export declare const createOrm: (storage: Storage) => {
3
- [x: string]: NestedOrm<Record<string, unknown>> | ShallowOrm<unknown>;
4
- };
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createOrm = void 0;
7
- var _helpers = require("../createDatabaseRoutes/helpers");
8
- const createOrm = storage => {
9
- const {
10
- shallowDatabase,
11
- nestedDatabase
12
- } = (0, _helpers.splitDatabaseByNesting)(storage.read());
13
- const nestedOrm = Object.entries(nestedDatabase).reduce((orm, [key, value]) => {
14
- orm[key] = {
15
- get: () => value,
16
- count: () => value.length,
17
- delete: id => storage.delete([key, id]),
18
- update: (id, data) => {
19
- const currentResource = storage.read([key, id]);
20
- const updatedResource = {
21
- ...data,
22
- id: currentResource.id
23
- };
24
- storage.write([key, id], updatedResource);
25
- },
26
- create: data => {
27
- const collection = storage.read(key);
28
- const newResourceId = (0, _helpers.createNewId)(collection);
29
- const newResource = {
30
- ...data,
31
- id: newResourceId
32
- };
33
- storage.write([key, value.length], newResource);
34
- },
35
- createMany: data => data.forEach(element => {
36
- const collection = storage.read(key);
37
- const newResourceId = (0, _helpers.createNewId)(collection);
38
- const newResource = {
39
- ...element,
40
- id: newResourceId
41
- };
42
- storage.write([key, value.length], newResource);
43
- }),
44
- deleteMany: ids => ids.forEach(id => {
45
- storage.delete([key, id]);
46
- }),
47
- updateMany: (ids, data) => ids.forEach(id => {
48
- const currentResource = storage.read([key, id]);
49
- const updatedResource = {
50
- ...data,
51
- id: currentResource.id
52
- };
53
- storage.write([key, id], updatedResource);
54
- })
55
- };
56
- return orm;
57
- }, {});
58
- const shallowOrm = Object.entries(shallowDatabase).reduce((orm, [key, value]) => {
59
- orm[key] = {
60
- get: () => value,
61
- update: data => storage.write([key], data)
62
- };
63
- return orm;
64
- }, {});
65
- return {
66
- ...nestedOrm,
67
- ...shallowOrm
68
- };
69
- };
70
- exports.createOrm = createOrm;
@@ -1,2 +0,0 @@
1
- import { FileStorage, MemoryStorage } from '../createDatabaseRoutes/storages';
2
- export declare const createStorage: <Data extends Record<string, unknown> | `${string}.json`>(data: Data) => FileStorage<Record<import("../../..").StorageIndex, any>> | MemoryStorage<Record<import("../../..").StorageIndex, any>>;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createStorage = void 0;
7
- var _storages = require("../createDatabaseRoutes/storages");
8
- const isVariableJsonFile = variable => typeof variable === 'string' && variable.endsWith('.json');
9
- const createStorage = data => isVariableJsonFile(data) ? new _storages.FileStorage(data) : new _storages.MemoryStorage(data);
10
- exports.createStorage = createStorage;