rads-db 3.0.19 → 3.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -133,20 +133,37 @@ const operatorFns = {
133
133
  }
134
134
  };
135
135
  const memory = (options) => (schema, entity) => {
136
- let itemsById = {};
136
+ const itemsById = {};
137
137
  function getItemById(id) {
138
138
  return itemsById[id] ?? null;
139
139
  }
140
140
  function getItemByIds(ids) {
141
141
  return ids.map((id) => itemsById[id]);
142
142
  }
143
+ function getMany(args) {
144
+ args = args || {};
145
+ const where = args.where || {};
146
+ const whereKeys = ___default.keys(where);
147
+ if (whereKeys.length === 1) {
148
+ if (whereKeys[0] === "id")
149
+ return { nodes: ___default.cloneDeep([getItemById(where.id)].filter((x) => x)), cursor: null };
150
+ if (whereKeys[0] === "id_in")
151
+ return { nodes: ___default.cloneDeep(getItemByIds(where.id_in).filter((x) => x)), cursor: null };
152
+ }
153
+ return queryArray(Object.values(itemsById), args);
154
+ }
143
155
  const instance = {
144
156
  driverName: "memory",
145
157
  get itemsById() {
146
158
  return itemsById;
147
159
  },
148
- clear() {
149
- itemsById = {};
160
+ getMany,
161
+ deleteMany(args) {
162
+ const { nodes, cursor } = getMany(args);
163
+ for (const node of nodes) {
164
+ delete itemsById[node.id];
165
+ }
166
+ return { nodes, cursor };
150
167
  },
151
168
  putMany(items) {
152
169
  for (const item of items) {
@@ -154,18 +171,6 @@ const memory = (options) => (schema, entity) => {
154
171
  throw new Error(`You must provide an id`);
155
172
  itemsById[item.id] = item;
156
173
  }
157
- },
158
- getMany(args) {
159
- args = args || {};
160
- const where = args.where || {};
161
- const whereKeys = ___default.keys(where);
162
- if (whereKeys.length === 1) {
163
- if (whereKeys[0] === "id")
164
- return { nodes: ___default.cloneDeep([getItemById(where.id)].filter((x) => x)), cursor: null };
165
- if (whereKeys[0] === "id_in")
166
- return { nodes: ___default.cloneDeep(getItemByIds(where.id_in).filter((x) => x)), cursor: null };
167
- }
168
- return queryArray(Object.values(itemsById), args);
169
174
  }
170
175
  };
171
176
  return instance;
@@ -760,6 +765,7 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
760
765
  return docsToSave;
761
766
  }
762
767
  const result = {
768
+ // No deleteMany / deleteAll on purpose - it's a dangerous operation, let them use driver instead
763
769
  createObject() {
764
770
  throw new Error("Not implemented");
765
771
  },
@@ -887,10 +893,6 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
887
893
  await handleEffectsAfterPut(computedContext, docArgsToSave, beforePutResults, ctx);
888
894
  await afterPut(docArgsToSave, ctx, computedContext);
889
895
  return { _logs, cursor, correctCount, incorrectCount, incorrectDocs };
890
- },
891
- clear: (ctx) => {
892
- ctx = { ...options.context, ...ctx };
893
- return driverInstance.clear(ctx);
894
896
  }
895
897
  };
896
898
  for (const f of options.features) {
@@ -1044,7 +1046,7 @@ function getDriverInstance(schema, key, driverConstructor, driverInstances) {
1044
1046
  function getDriverInstanceInner(schema, key, driverConstructor) {
1045
1047
  const driverInstance = driverConstructor(schema, key);
1046
1048
  addDryRunSupport(driverInstance, key);
1047
- async function getAll(args, ctx) {
1049
+ async function followCursors(callback, args, ctx) {
1048
1050
  const result = [];
1049
1051
  args = args || {};
1050
1052
  let cursor = args.cursor;
@@ -1052,7 +1054,7 @@ function getDriverInstanceInner(schema, key, driverConstructor) {
1052
1054
  if (maxItemCount < 1e3)
1053
1055
  maxItemCount = 1e3;
1054
1056
  for (let i = 0; i < 1e3; i++) {
1055
- const response = await driverInstance.getMany({ ...args, cursor, maxItemCount }, ctx);
1057
+ const response = await callback({ ...args, cursor, maxItemCount }, ctx);
1056
1058
  result.push(...response.nodes);
1057
1059
  if (cursor && cursor === response.cursor) {
1058
1060
  throw new Error(
@@ -1065,12 +1067,21 @@ function getDriverInstanceInner(schema, key, driverConstructor) {
1065
1067
  }
1066
1068
  return result;
1067
1069
  }
1070
+ async function getAll(args, ctx) {
1071
+ const result = await followCursors(driverInstance.getMany, args, ctx);
1072
+ return result;
1073
+ }
1074
+ async function deleteAll(args, ctx) {
1075
+ const result = await followCursors(driverInstance.deleteMany, args, ctx);
1076
+ return result;
1077
+ }
1068
1078
  return {
1079
+ getAll,
1080
+ deleteAll,
1069
1081
  async getAgg(args, ctx) {
1070
1082
  const result = await getAll(args, ctx);
1071
1083
  return getAggFromArray(result, args);
1072
1084
  },
1073
- getAll,
1074
1085
  async get(args, ctx) {
1075
1086
  args = { ...args, maxItemCount: 1 };
1076
1087
  const result = (await driverInstance.getMany(args, ctx))?.nodes[0];
@@ -1081,45 +1092,28 @@ function getDriverInstanceInner(schema, key, driverConstructor) {
1081
1092
  throw new Error("Data is required");
1082
1093
  await driverInstance.putMany([data], ctx);
1083
1094
  },
1084
- async clear() {
1085
- console.error(`"clear" not supported for driver "${driverInstance.driverName}"`);
1095
+ deleteMany(args, ctx) {
1096
+ throw new Error(`"deleteMany" not supported for driver "${driverInstance.driverName}"`);
1086
1097
  },
1087
1098
  ...driverInstance
1088
1099
  };
1089
1100
  }
1090
1101
  function addDryRunSupport(driverInstance, entity) {
1091
- const { clear, put, putMany } = driverInstance;
1092
- if (clear) {
1093
- driverInstance.clear = (ctx) => {
1094
- if (ctx?.dryRun) {
1095
- if (!ctx._logs)
1096
- ctx._logs = [];
1097
- ctx._logs.push({ method: "clear", entity });
1098
- return;
1099
- }
1100
- return clear(ctx);
1101
- };
1102
- }
1103
- if (put) {
1104
- driverInstance.put = (data, ctx) => {
1105
- if (ctx?.dryRun) {
1106
- if (!ctx._logs)
1107
- ctx._logs = [];
1108
- ctx._logs.push({ method: "put", entity, data });
1109
- return;
1110
- }
1111
- return put(data, ctx);
1112
- };
1113
- }
1114
- driverInstance.putMany = (data, ctx) => {
1115
- if (ctx?.dryRun) {
1116
- if (!ctx._logs)
1117
- ctx._logs = [];
1118
- ctx._logs.push({ method: "putMany", entity, data });
1119
- return;
1102
+ const methods = ["deleteMany", "deleteAll", "put", "putMany"];
1103
+ for (const method of methods) {
1104
+ const originalMethod = driverInstance[method];
1105
+ if (originalMethod) {
1106
+ driverInstance[method] = (args, ctx) => {
1107
+ if (ctx?.dryRun) {
1108
+ if (!ctx._logs)
1109
+ ctx._logs = [];
1110
+ ctx._logs.push({ method, entity, args });
1111
+ return;
1112
+ }
1113
+ return originalMethod(args, ctx);
1114
+ };
1120
1115
  }
1121
- return putMany(data, ctx);
1122
- };
1116
+ }
1123
1117
  }
1124
1118
  function getRadsUiSlots(features) {
1125
1119
  const result = {};
package/dist/index.d.ts CHANGED
@@ -206,6 +206,7 @@ interface TypeDefinition {
206
206
  enumValues?: Record<string, EnumDefinition>;
207
207
  handle?: string;
208
208
  handlePlural?: string;
209
+ isExtending?: string;
209
210
  }
210
211
  interface FileUploadResult {
211
212
  url: string;
@@ -247,7 +248,11 @@ interface MinimalDriver {
247
248
  get?: (args: GetArgsAny, ctx?: RadsRequestContext) => MaybePromise<Record<string, any> | null>;
248
249
  getAll?: (args: GetManyArgsAny, ctx?: RadsRequestContext) => MaybePromise<Record<string, any>[]>;
249
250
  getAgg?: (args: GetAggArgsAny, ctx?: RadsRequestContext) => MaybePromise<Record<string, any>>;
250
- clear?: (ctx?: RadsRequestContext) => MaybePromise<void>;
251
+ deleteMany?: (args: GetManyArgsAny, ctx?: RadsRequestContext) => MaybePromise<{
252
+ nodes: Record<string, any>[];
253
+ cursor: string | null;
254
+ }>;
255
+ deleteAll?: (args: GetManyArgsAny, ctx?: RadsRequestContext) => MaybePromise<Record<string, any>[]>;
251
256
  put?: (data: Record<string, any>, ctx?: RadsRequestContext) => MaybePromise<void>;
252
257
  verifyMany?: (args?: VerifyManyArgsAny, ctx?: RadsRequestContext) => MaybePromise<VerifyManyResponse>;
253
258
  }
@@ -256,6 +261,7 @@ interface FieldDefinition {
256
261
  name: string;
257
262
  type: string;
258
263
  defaultValue?: any;
264
+ defaultValueClass?: string;
259
265
  defaultValueCopyFrom?: string;
260
266
  isRequired?: boolean;
261
267
  isArray?: boolean;
package/dist/index.mjs CHANGED
@@ -125,20 +125,37 @@ const operatorFns = {
125
125
  }
126
126
  };
127
127
  const memory = (options) => (schema, entity) => {
128
- let itemsById = {};
128
+ const itemsById = {};
129
129
  function getItemById(id) {
130
130
  return itemsById[id] ?? null;
131
131
  }
132
132
  function getItemByIds(ids) {
133
133
  return ids.map((id) => itemsById[id]);
134
134
  }
135
+ function getMany(args) {
136
+ args = args || {};
137
+ const where = args.where || {};
138
+ const whereKeys = _.keys(where);
139
+ if (whereKeys.length === 1) {
140
+ if (whereKeys[0] === "id")
141
+ return { nodes: _.cloneDeep([getItemById(where.id)].filter((x) => x)), cursor: null };
142
+ if (whereKeys[0] === "id_in")
143
+ return { nodes: _.cloneDeep(getItemByIds(where.id_in).filter((x) => x)), cursor: null };
144
+ }
145
+ return queryArray(Object.values(itemsById), args);
146
+ }
135
147
  const instance = {
136
148
  driverName: "memory",
137
149
  get itemsById() {
138
150
  return itemsById;
139
151
  },
140
- clear() {
141
- itemsById = {};
152
+ getMany,
153
+ deleteMany(args) {
154
+ const { nodes, cursor } = getMany(args);
155
+ for (const node of nodes) {
156
+ delete itemsById[node.id];
157
+ }
158
+ return { nodes, cursor };
142
159
  },
143
160
  putMany(items) {
144
161
  for (const item of items) {
@@ -146,18 +163,6 @@ const memory = (options) => (schema, entity) => {
146
163
  throw new Error(`You must provide an id`);
147
164
  itemsById[item.id] = item;
148
165
  }
149
- },
150
- getMany(args) {
151
- args = args || {};
152
- const where = args.where || {};
153
- const whereKeys = _.keys(where);
154
- if (whereKeys.length === 1) {
155
- if (whereKeys[0] === "id")
156
- return { nodes: _.cloneDeep([getItemById(where.id)].filter((x) => x)), cursor: null };
157
- if (whereKeys[0] === "id_in")
158
- return { nodes: _.cloneDeep(getItemByIds(where.id_in).filter((x) => x)), cursor: null };
159
- }
160
- return queryArray(Object.values(itemsById), args);
161
166
  }
162
167
  };
163
168
  return instance;
@@ -752,6 +757,7 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
752
757
  return docsToSave;
753
758
  }
754
759
  const result = {
760
+ // No deleteMany / deleteAll on purpose - it's a dangerous operation, let them use driver instead
755
761
  createObject() {
756
762
  throw new Error("Not implemented");
757
763
  },
@@ -879,10 +885,6 @@ function getRadsDbMethods(key, computedContext, driverInstance) {
879
885
  await handleEffectsAfterPut(computedContext, docArgsToSave, beforePutResults, ctx);
880
886
  await afterPut(docArgsToSave, ctx, computedContext);
881
887
  return { _logs, cursor, correctCount, incorrectCount, incorrectDocs };
882
- },
883
- clear: (ctx) => {
884
- ctx = { ...options.context, ...ctx };
885
- return driverInstance.clear(ctx);
886
888
  }
887
889
  };
888
890
  for (const f of options.features) {
@@ -1036,7 +1038,7 @@ function getDriverInstance(schema, key, driverConstructor, driverInstances) {
1036
1038
  function getDriverInstanceInner(schema, key, driverConstructor) {
1037
1039
  const driverInstance = driverConstructor(schema, key);
1038
1040
  addDryRunSupport(driverInstance, key);
1039
- async function getAll(args, ctx) {
1041
+ async function followCursors(callback, args, ctx) {
1040
1042
  const result = [];
1041
1043
  args = args || {};
1042
1044
  let cursor = args.cursor;
@@ -1044,7 +1046,7 @@ function getDriverInstanceInner(schema, key, driverConstructor) {
1044
1046
  if (maxItemCount < 1e3)
1045
1047
  maxItemCount = 1e3;
1046
1048
  for (let i = 0; i < 1e3; i++) {
1047
- const response = await driverInstance.getMany({ ...args, cursor, maxItemCount }, ctx);
1049
+ const response = await callback({ ...args, cursor, maxItemCount }, ctx);
1048
1050
  result.push(...response.nodes);
1049
1051
  if (cursor && cursor === response.cursor) {
1050
1052
  throw new Error(
@@ -1057,12 +1059,21 @@ function getDriverInstanceInner(schema, key, driverConstructor) {
1057
1059
  }
1058
1060
  return result;
1059
1061
  }
1062
+ async function getAll(args, ctx) {
1063
+ const result = await followCursors(driverInstance.getMany, args, ctx);
1064
+ return result;
1065
+ }
1066
+ async function deleteAll(args, ctx) {
1067
+ const result = await followCursors(driverInstance.deleteMany, args, ctx);
1068
+ return result;
1069
+ }
1060
1070
  return {
1071
+ getAll,
1072
+ deleteAll,
1061
1073
  async getAgg(args, ctx) {
1062
1074
  const result = await getAll(args, ctx);
1063
1075
  return getAggFromArray(result, args);
1064
1076
  },
1065
- getAll,
1066
1077
  async get(args, ctx) {
1067
1078
  args = { ...args, maxItemCount: 1 };
1068
1079
  const result = (await driverInstance.getMany(args, ctx))?.nodes[0];
@@ -1073,45 +1084,28 @@ function getDriverInstanceInner(schema, key, driverConstructor) {
1073
1084
  throw new Error("Data is required");
1074
1085
  await driverInstance.putMany([data], ctx);
1075
1086
  },
1076
- async clear() {
1077
- console.error(`"clear" not supported for driver "${driverInstance.driverName}"`);
1087
+ deleteMany(args, ctx) {
1088
+ throw new Error(`"deleteMany" not supported for driver "${driverInstance.driverName}"`);
1078
1089
  },
1079
1090
  ...driverInstance
1080
1091
  };
1081
1092
  }
1082
1093
  function addDryRunSupport(driverInstance, entity) {
1083
- const { clear, put, putMany } = driverInstance;
1084
- if (clear) {
1085
- driverInstance.clear = (ctx) => {
1086
- if (ctx?.dryRun) {
1087
- if (!ctx._logs)
1088
- ctx._logs = [];
1089
- ctx._logs.push({ method: "clear", entity });
1090
- return;
1091
- }
1092
- return clear(ctx);
1093
- };
1094
- }
1095
- if (put) {
1096
- driverInstance.put = (data, ctx) => {
1097
- if (ctx?.dryRun) {
1098
- if (!ctx._logs)
1099
- ctx._logs = [];
1100
- ctx._logs.push({ method: "put", entity, data });
1101
- return;
1102
- }
1103
- return put(data, ctx);
1104
- };
1105
- }
1106
- driverInstance.putMany = (data, ctx) => {
1107
- if (ctx?.dryRun) {
1108
- if (!ctx._logs)
1109
- ctx._logs = [];
1110
- ctx._logs.push({ method: "putMany", entity, data });
1111
- return;
1094
+ const methods = ["deleteMany", "deleteAll", "put", "putMany"];
1095
+ for (const method of methods) {
1096
+ const originalMethod = driverInstance[method];
1097
+ if (originalMethod) {
1098
+ driverInstance[method] = (args, ctx) => {
1099
+ if (ctx?.dryRun) {
1100
+ if (!ctx._logs)
1101
+ ctx._logs = [];
1102
+ ctx._logs.push({ method, entity, args });
1103
+ return;
1104
+ }
1105
+ return originalMethod(args, ctx);
1106
+ };
1112
1107
  }
1113
- return putMany(data, ctx);
1114
- };
1108
+ }
1115
1109
  }
1116
1110
  function getRadsUiSlots(features) {
1117
1111
  const result = {};
@@ -95,24 +95,22 @@ var _default = options => (schema, entity) => {
95
95
  driverName: "azureCosmos",
96
96
  client,
97
97
  getMany,
98
- async clear(ctx) {
99
- let currentCursor = null;
100
- do {
101
- const {
102
- nodes,
103
- cursor
104
- } = await getMany({
105
- cursor: currentCursor
98
+ async deleteMany(args, ctx) {
99
+ const {
100
+ nodes,
101
+ cursor
102
+ } = await getMany(args, ctx);
103
+ for (const r of nodes) {
104
+ const resp = await client.item(r.id, r._partition).delete();
105
+ ctx?.log?.({
106
+ charge: resp.requestCharge,
107
+ request: `delete#${r._partition}|${r.id}`
106
108
  });
107
- for (const r of nodes) {
108
- const resp = await client.item(r.id, r._partition).delete();
109
- ctx?.log?.({
110
- charge: resp.requestCharge,
111
- request: `delete#${r._partition}|${r.id}`
112
- });
113
- }
114
- currentCursor = cursor;
115
- } while (currentCursor);
109
+ }
110
+ return {
111
+ nodes,
112
+ cursor
113
+ };
116
114
  },
117
115
  async putMany(items, ctx) {
118
116
  for (const item of items) {
@@ -63,16 +63,13 @@ export default (options) => (schema, entity) => {
63
63
  driverName: "azureCosmos",
64
64
  client,
65
65
  getMany,
66
- async clear(ctx) {
67
- let currentCursor = null;
68
- do {
69
- const { nodes, cursor } = await getMany({ cursor: currentCursor });
70
- for (const r of nodes) {
71
- const resp = await client.item(r.id, r._partition).delete();
72
- ctx?.log?.({ charge: resp.requestCharge, request: `delete#${r._partition}|${r.id}` });
73
- }
74
- currentCursor = cursor;
75
- } while (currentCursor);
66
+ async deleteMany(args, ctx) {
67
+ const { nodes, cursor } = await getMany(args, ctx);
68
+ for (const r of nodes) {
69
+ const resp = await client.item(r.id, r._partition).delete();
70
+ ctx?.log?.({ charge: resp.requestCharge, request: `delete#${r._partition}|${r.id}` });
71
+ }
72
+ return { nodes, cursor };
76
73
  },
77
74
  async putMany(items, ctx) {
78
75
  for (const item of items) {
@@ -81,32 +81,27 @@ var _default = options => (schema, entity) => {
81
81
  driverName: "azureStorageBlob",
82
82
  client: containerClient,
83
83
  getMany,
84
- async clear(ctx) {
85
- let currentCursor = null;
86
- const iterator = containerClient.listBlobsFlat({}).byPage({
87
- maxPageSize: 100,
88
- continuationToken: currentCursor || void 0
84
+ async deleteMany(args, ctx) {
85
+ const {
86
+ nodes,
87
+ cursor
88
+ } = await getMany(args, ctx);
89
+ const responses = await Promise.all(nodes.map(x => containerClient.getBlobClient(getBlobName(entity, x)).delete()));
90
+ ctx?.log?.({
91
+ requestId: responses.map(x => x.requestId || "").join(";"),
92
+ charge: responses.length,
93
+ request: `deleteBlobs ${entity}`
89
94
  });
90
- for await (const page of iterator) {
91
- ctx?.log?.({
92
- requestId: page.requestId,
93
- charge: page.segment.blobItems.length,
94
- request: `listBlobsFlat ${entity}`
95
- });
96
- const responses = await Promise.all(page.segment.blobItems.map(x => containerClient.getBlobClient(x.name).delete()));
97
- ctx?.log?.({
98
- requestId: responses.map(x => x.requestId || "").join(";"),
99
- charge: responses.length,
100
- request: `deleteBlobs ${entity}`
101
- });
102
- currentCursor = page.continuationToken || null;
103
- }
95
+ return {
96
+ nodes,
97
+ cursor
98
+ };
104
99
  },
105
100
  async putMany(items, ctx) {
106
101
  for (const item of items) {
107
102
  const id = item?.id;
108
103
  if (!id) throw new Error(`You must provide an id`);
109
- const blobName = `${entity}/${id}.json`;
104
+ const blobName = getBlobName(entity, item);
110
105
  const itemToPut = item;
111
106
  const blobClient = containerClient.getBlockBlobClient(blobName);
112
107
  const str = JSON.stringify(itemToPut);
@@ -122,6 +117,10 @@ var _default = options => (schema, entity) => {
122
117
  return instance;
123
118
  };
124
119
  module.exports = _default;
120
+ function getBlobName(entity, item) {
121
+ if (!item.id) throw new Error("Item must have an id");
122
+ return `${entity}/${item.id}.json`;
123
+ }
125
124
  async function blobOrStreamToString(response) {
126
125
  if (response.blobBody) {
127
126
  return await (await response.blobBody).text();
@@ -66,32 +66,24 @@ export default (options) => (schema, entity) => {
66
66
  driverName: "azureStorageBlob",
67
67
  client: containerClient,
68
68
  getMany,
69
- async clear(ctx) {
70
- let currentCursor = null;
71
- const iterator = containerClient.listBlobsFlat({}).byPage({ maxPageSize: 100, continuationToken: currentCursor || void 0 });
72
- for await (const page of iterator) {
73
- ctx?.log?.({
74
- requestId: page.requestId,
75
- charge: page.segment.blobItems.length,
76
- request: `listBlobsFlat ${entity}`
77
- });
78
- const responses = await Promise.all(
79
- page.segment.blobItems.map((x) => containerClient.getBlobClient(x.name).delete())
80
- );
81
- ctx?.log?.({
82
- requestId: responses.map((x) => x.requestId || "").join(";"),
83
- charge: responses.length,
84
- request: `deleteBlobs ${entity}`
85
- });
86
- currentCursor = page.continuationToken || null;
87
- }
69
+ async deleteMany(args, ctx) {
70
+ const { nodes, cursor } = await getMany(args, ctx);
71
+ const responses = await Promise.all(
72
+ nodes.map((x) => containerClient.getBlobClient(getBlobName(entity, x)).delete())
73
+ );
74
+ ctx?.log?.({
75
+ requestId: responses.map((x) => x.requestId || "").join(";"),
76
+ charge: responses.length,
77
+ request: `deleteBlobs ${entity}`
78
+ });
79
+ return { nodes, cursor };
88
80
  },
89
81
  async putMany(items, ctx) {
90
82
  for (const item of items) {
91
83
  const id = item?.id;
92
84
  if (!id)
93
85
  throw new Error(`You must provide an id`);
94
- const blobName = `${entity}/${id}.json`;
86
+ const blobName = getBlobName(entity, item);
95
87
  const itemToPut = item;
96
88
  const blobClient = containerClient.getBlockBlobClient(blobName);
97
89
  const str = JSON.stringify(itemToPut);
@@ -102,6 +94,11 @@ export default (options) => (schema, entity) => {
102
94
  };
103
95
  return instance;
104
96
  };
97
+ function getBlobName(entity, item) {
98
+ if (!item.id)
99
+ throw new Error("Item must have an id");
100
+ return `${entity}/${item.id}.json`;
101
+ }
105
102
  async function blobOrStreamToString(response) {
106
103
  if (response.blobBody) {
107
104
  return await (await response.blobBody).text();
@@ -40,42 +40,53 @@ const operatorFns = {
40
40
  }
41
41
  };
42
42
  var _default = options => (schema, entity) => {
43
- let itemsById = {};
43
+ const itemsById = {};
44
44
  function getItemById(id) {
45
45
  return itemsById[id] ?? null;
46
46
  }
47
47
  function getItemByIds(ids) {
48
48
  return ids.map(id => itemsById[id]);
49
49
  }
50
+ function getMany(args) {
51
+ args = args || {};
52
+ const where = args.where || {};
53
+ const whereKeys = _lodash.default.keys(where);
54
+ if (whereKeys.length === 1) {
55
+ if (whereKeys[0] === "id") return {
56
+ nodes: _lodash.default.cloneDeep([getItemById(where.id)].filter(x => x)),
57
+ cursor: null
58
+ };
59
+ if (whereKeys[0] === "id_in") return {
60
+ nodes: _lodash.default.cloneDeep(getItemByIds(where.id_in).filter(x => x)),
61
+ cursor: null
62
+ };
63
+ }
64
+ return queryArray(Object.values(itemsById), args);
65
+ }
50
66
  const instance = {
51
67
  driverName: "memory",
52
68
  get itemsById() {
53
69
  return itemsById;
54
70
  },
55
- clear() {
56
- itemsById = {};
71
+ getMany,
72
+ deleteMany(args) {
73
+ const {
74
+ nodes,
75
+ cursor
76
+ } = getMany(args);
77
+ for (const node of nodes) {
78
+ delete itemsById[node.id];
79
+ }
80
+ return {
81
+ nodes,
82
+ cursor
83
+ };
57
84
  },
58
85
  putMany(items) {
59
86
  for (const item of items) {
60
87
  if (!item?.id) throw new Error(`You must provide an id`);
61
88
  itemsById[item.id] = item;
62
89
  }
63
- },
64
- getMany(args) {
65
- args = args || {};
66
- const where = args.where || {};
67
- const whereKeys = _lodash.default.keys(where);
68
- if (whereKeys.length === 1) {
69
- if (whereKeys[0] === "id") return {
70
- nodes: _lodash.default.cloneDeep([getItemById(where.id)].filter(x => x)),
71
- cursor: null
72
- };
73
- if (whereKeys[0] === "id_in") return {
74
- nodes: _lodash.default.cloneDeep(getItemByIds(where.id_in).filter(x => x)),
75
- cursor: null
76
- };
77
- }
78
- return queryArray(Object.values(itemsById), args);
79
90
  }
80
91
  };
81
92
  return instance;