mock-config-server 3.3.3 → 3.3.4

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.
@@ -0,0 +1,4 @@
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
+ };
@@ -0,0 +1,70 @@
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;
@@ -0,0 +1,2 @@
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>>;
@@ -0,0 +1,10 @@
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;
@@ -14,7 +14,7 @@ export type GraphQLTopLevelPlainEntityDescriptor<Check extends CheckMode = Check
14
14
  value: NestedObjectOrArray<GraphQLPlainEntityValue>;
15
15
  } : Check extends CheckActualValueCheckMode ? {
16
16
  checkMode: Check;
17
- value: never;
17
+ value?: never;
18
18
  } : never;
19
19
  type GraphQLPropertyLevelPlainEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? {
20
20
  checkMode: Check;
@@ -24,7 +24,7 @@ type GraphQLPropertyLevelPlainEntityDescriptor<Check extends CheckMode = CheckMo
24
24
  value: GraphQLPlainEntityValue | NestedObjectOrArray<GraphQLPlainEntityValue>;
25
25
  } : Check extends CheckActualValueCheckMode ? {
26
26
  checkMode: Check;
27
- value: never;
27
+ value?: never;
28
28
  } : never;
29
29
  type GraphQLMappedEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? {
30
30
  checkMode: Check;
@@ -37,7 +37,7 @@ type GraphQLMappedEntityDescriptor<Check extends CheckMode = CheckMode> = Check
37
37
  value: GraphQLMappedEntityValue | GraphQLMappedEntityValue[];
38
38
  } : Check extends CheckActualValueCheckMode ? {
39
39
  checkMode: Check;
40
- value: never;
40
+ value?: never;
41
41
  } : never;
42
42
  export type GraphQLEntityDescriptorOrValue<EntityName extends GraphQLEntityName = GraphQLEntityName> = EntityName extends 'variables' ? GraphQLTopLevelPlainEntityDescriptor | Record<string, GraphQLPropertyLevelPlainEntityDescriptor> | NestedObjectOrArray<GraphQLPlainEntityValue> : Record<string, GraphQLMappedEntityDescriptor | GraphQLMappedEntityValue | GraphQLMappedEntityValue[]>;
43
43
  export type GraphQLOperationType = 'query' | 'mutation';
@@ -15,7 +15,7 @@ export type RestTopLevelPlainEntityDescriptor<Check extends CheckMode = CheckMod
15
15
  value: NestedObjectOrArray<RestPlainEntityValue>;
16
16
  } : Check extends CheckActualValueCheckMode ? {
17
17
  checkMode: Check;
18
- value: never;
18
+ value?: never;
19
19
  } : never;
20
20
  type RestPropertyLevelPlainEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? {
21
21
  checkMode: Check;
@@ -25,7 +25,7 @@ type RestPropertyLevelPlainEntityDescriptor<Check extends CheckMode = CheckMode>
25
25
  value: RestPlainEntityValue | NestedObjectOrArray<RestPlainEntityValue>;
26
26
  } : Check extends CheckActualValueCheckMode ? {
27
27
  checkMode: Check;
28
- value: never;
28
+ value?: never;
29
29
  } : never;
30
30
  type RestMappedEntityDescriptor<Check extends CheckMode = CheckMode> = Check extends 'function' ? {
31
31
  checkMode: Check;
@@ -38,7 +38,7 @@ type RestMappedEntityDescriptor<Check extends CheckMode = CheckMode> = Check ext
38
38
  value: RestMappedEntityValue | RestMappedEntityValue[];
39
39
  } : Check extends CheckActualValueCheckMode ? {
40
40
  checkMode: Check;
41
- value: never;
41
+ value?: never;
42
42
  } : never;
43
43
  export type RestEntityDescriptorOrValue<EntityName extends RestEntityName = RestEntityName> = EntityName extends 'body' ? RestTopLevelPlainEntityDescriptor | Record<string, RestPropertyLevelPlainEntityDescriptor> | NestedObjectOrArray<RestPlainEntityValue> : Record<string, RestMappedEntityDescriptor | RestMappedEntityValue | RestMappedEntityValue[]>;
44
44
  export type RestEntityNamesByMethod = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mock-config-server",
3
- "version": "3.3.3",
3
+ "version": "3.3.4",
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 🧊",