@desmat/redis-store 1.1.0 → 1.2.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/dist/index.js CHANGED
@@ -132,10 +132,20 @@ class RedisStore {
132
132
  if (query.scan) {
133
133
  return this.scan(query);
134
134
  }
135
- const min = query.offset || 0;
136
- const max = min + (query.count || 0) - 1;
137
- delete query.offset;
135
+ let count = query.count;
138
136
  delete query.count;
137
+ if (typeof (count) != "undefined" && typeof (count) != "number") {
138
+ console.warn(`RedisStore.RedisStore<${this.key}>.id WARNING: query.count is not a number`);
139
+ count = undefined;
140
+ }
141
+ let offset = query.offset;
142
+ delete query.offset;
143
+ if (typeof (offset) != "undefined" && typeof (offset) != "number") {
144
+ console.warn(`RedisStore.RedisStore<${this.key}>.id WARNING: query.offset must be a number`);
145
+ offset = undefined;
146
+ }
147
+ const min = offset || 0;
148
+ const max = min + (count || 0) - 1;
139
149
  const queryEntries = query && Object.entries(query);
140
150
  // .ids() or .ids({})
141
151
  if (!(queryEntries === null || queryEntries === void 0 ? void 0 : queryEntries.length)) {
@@ -22,7 +22,7 @@ const store = {
22
22
  setKey: "ViceCategories",
23
23
  options: {
24
24
  lookups: {
25
- vice: "viceId",
25
+ vice: "vice",
26
26
  }
27
27
  },
28
28
  debug,
@@ -31,7 +31,19 @@ const store = {
31
31
  key: "ViceType",
32
32
  options: {
33
33
  lookups: {
34
+ vice: "vice",
35
+ category: "categoryId",
36
+ }
37
+ },
38
+ debug,
39
+ }),
40
+ customTypes: new index_1.default({
41
+ key: "ViceCustomType",
42
+ options: {
43
+ lookups: {
44
+ vice: "vice",
34
45
  category: "categoryId",
46
+ user: "userId",
35
47
  }
36
48
  },
37
49
  debug,
@@ -60,16 +72,30 @@ const store = {
60
72
  // options: Options,
61
73
  debug,
62
74
  }),
75
+ journalEntries: new index_1.default({
76
+ key: "ViceJournalEntry",
77
+ setKey: "ViceJournalEntries",
78
+ // options: JournalEntryOptions,
79
+ debug,
80
+ }),
81
+ insights: new index_1.default({
82
+ key: "ViceInsight",
83
+ // options: InsightOptions,
84
+ debug,
85
+ }),
63
86
  };
64
87
  async function cleanup() {
65
88
  // cleanup all from previous session
66
- let [vices, categories, types, entries, hourlySummaries, dailySummaries,] = await Promise.all([
89
+ let [vices, categories, types, customTypes, entries, hourlySummaries, dailySummaries, journalEntries, insights,] = await Promise.all([
67
90
  store.vices.ids({ scan: "*" }),
68
91
  store.categories.ids({ scan: "*" }),
69
92
  store.types.ids({ scan: "*" }),
93
+ store.customTypes.ids({ scan: "*" }),
70
94
  store.entries.ids({ scan: "*" }),
71
95
  store.hourlySummaries.ids({ scan: "*" }),
72
96
  store.dailySummaries.ids({ scan: "*" }),
97
+ store.journalEntries.ids({ scan: "*" }),
98
+ store.insights.ids({ scan: "*" }),
73
99
  ]);
74
100
  // console.log("users to delete", { usersToDelete, postsToDelete, userPostsToDelete });
75
101
  return Promise.all([
@@ -80,56 +106,219 @@ async function cleanup() {
80
106
  // @ts-ignore
81
107
  ...Array.from(types).map((id) => store.types.delete(id, { hardDelete: true })),
82
108
  // @ts-ignore
109
+ ...Array.from(customTypes).map((id) => store.customTypes.delete(id, { hardDelete: true })),
110
+ // @ts-ignore
83
111
  ...Array.from(entries).map((id) => store.entries.delete(id, { hardDelete: true })),
84
112
  // @ts-ignore
85
113
  ...Array.from(hourlySummaries).map((id) => store.hourlySummaries.delete(id, { hardDelete: true })),
86
114
  // @ts-ignore
87
115
  ...Array.from(dailySummaries).map((id) => store.dailySummaries.delete(id, { hardDelete: true })),
116
+ // @ts-ignore
117
+ ...Array.from(journalEntries).map((id) => store.journalEntries.delete(id, { hardDelete: true })),
118
+ // @ts-ignore
119
+ ...Array.from(insights).map((id) => store.insights.delete(id, { hardDelete: true })),
88
120
  ]);
89
121
  }
90
122
  (async function () {
91
123
  await cleanup();
124
+ return;
92
125
  const userId = "user_2nnoSDL2mdJD8XiQpYKqBT3pEK5";
93
126
  const vices = await Promise.all([
127
+ // store.vices.create({
128
+ // name: "alcohol",
129
+ // unit: "standard drink (14g)",
130
+ // }),
94
131
  store.vices.create({
95
- name: "alcohol",
96
- unit: "standard drink (14g)",
132
+ name: "sugar",
133
+ unit: "grams of net sugar",
97
134
  }),
98
135
  ]);
99
136
  console.log("created", { vices });
100
137
  const categories = await Promise.all([
138
+ // store.categories.create({
139
+ // vice: vices[0].name,
140
+ // viceId: vices[0].id,
141
+ // name: "beer/cider",
142
+ // }),
143
+ // store.categories.create({
144
+ // vice: vices[0].name,
145
+ // viceId: vices[0].id,
146
+ // name: "wine",
147
+ // }),
148
+ // store.categories.create({
149
+ // vice: vices[0].name,
150
+ // viceId: vices[0].id,
151
+ // name: "spirits/cocktails",
152
+ // }),
101
153
  store.categories.create({
102
154
  vice: vices[0].name,
103
155
  viceId: vices[0].id,
104
- name: "beer/cider",
156
+ name: "sugar",
105
157
  }),
106
158
  store.categories.create({
107
159
  vice: vices[0].name,
108
160
  viceId: vices[0].id,
109
- name: "wine",
161
+ name: "candy",
110
162
  }),
111
163
  store.categories.create({
112
164
  vice: vices[0].name,
113
165
  viceId: vices[0].id,
114
- name: "spirits/cocktails",
166
+ id: "custom",
167
+ name: "custom",
115
168
  }),
116
169
  ]);
117
170
  console.log("created", { categories });
118
171
  const types = await Promise.all([
172
+ // store.types.create({
173
+ // vice: vices[0].id,
174
+ // viceId: vices[0].id,
175
+ // category: categories[0].name,
176
+ // categoryId: categories[0].id,
177
+ // name: "beer (small)",
178
+ // units: 0.75,
179
+ // }),
180
+ // store.types.create({
181
+ // vice: vices[0].name,
182
+ // viceId: vices[0].id,
183
+ // category: categories[0].name,
184
+ // categoryId: categories[0].id,
185
+ // name: "beer",
186
+ // units: 1,
187
+ // }),
188
+ // store.types.create({
189
+ // vice: vices[0].name,
190
+ // viceId: vices[0].id,
191
+ // category: categories[0].name,
192
+ // categoryId: categories[0].id,
193
+ // name: "beer (strong)",
194
+ // units: 1.25,
195
+ // }),
196
+ // store.types.create({
197
+ // vice: vices[0].name,
198
+ // viceId: vices[0].id,
199
+ // category: categories[0].name,
200
+ // categoryId: categories[0].id,
201
+ // name: "beer (large)",
202
+ // units: 1.25,
203
+ // }),
204
+ // store.types.create({
205
+ // vice: vices[0].name,
206
+ // viceId: vices[0].id,
207
+ // category: categories[0].name,
208
+ // categoryId: categories[0].id,
209
+ // name: "beer (xlarge/xstrong/large-strong)",
210
+ // units: 1.5,
211
+ // }),
212
+ // store.types.create({
213
+ // vice: vices[0].name,
214
+ // viceId: vices[0].id,
215
+ // category: categories[1].name,
216
+ // categoryId: categories[1].id,
217
+ // name: "wine (2.5oz)",
218
+ // units: 0.5,
219
+ // }),
220
+ // store.types.create({
221
+ // vice: vices[0].name,
222
+ // viceId: vices[0].id,
223
+ // category: categories[1].name,
224
+ // categoryId: categories[1].id,
225
+ // name: "wine (3.5oz)",
226
+ // units: 0.75,
227
+ // }),
228
+ // store.types.create({
229
+ // vice: vices[0].name,
230
+ // viceId: vices[0].id,
231
+ // category: categories[1].name,
232
+ // categoryId: categories[1].id,
233
+ // name: "wine (5oz)",
234
+ // units: 1,
235
+ // }),
236
+ // store.types.create({
237
+ // vice: vices[0].name,
238
+ // viceId: vices[0].id,
239
+ // category: categories[1].name,
240
+ // categoryId: categories[1].id,
241
+ // name: "wine (6.5oz)",
242
+ // units: 1.25,
243
+ // }),
244
+ // store.types.create({
245
+ // vice: vices[0].name,
246
+ // viceId: vices[0].id,
247
+ // category: categories[1].name,
248
+ // categoryId: categories[1].id,
249
+ // name: "wine (7.5oz)",
250
+ // units: 1.5,
251
+ // }),
252
+ // store.types.create({
253
+ // vice: vices[0].name,
254
+ // viceId: vices[0].id,
255
+ // category: categories[1].name,
256
+ // categoryId: categories[1].id,
257
+ // name: "wine (9oz)",
258
+ // units: 1.75,
259
+ // }),
260
+ // store.types.create({
261
+ // vice: vices[0].name,
262
+ // viceId: vices[0].id,
263
+ // category: categories[1].name,
264
+ // categoryId: categories[1].id,
265
+ // name: "wine (500ml bottle)",
266
+ // units: 3.5,
267
+ // }),
268
+ // store.types.create({
269
+ // vice: vices[0].name,
270
+ // viceId: vices[0].id,
271
+ // category: categories[1].name,
272
+ // categoryId: categories[1].id,
273
+ // name: "wine (750ml bottle)",
274
+ // units: 5,
275
+ // }),
276
+ // store.types.create({
277
+ // vice: vices[0].name,
278
+ // viceId: vices[0].id,
279
+ // category: categories[2].name,
280
+ // categoryId: categories[2].id,
281
+ // name: "spirit (1oz)",
282
+ // units: 0.75,
283
+ // }),
284
+ // store.types.create({
285
+ // vice: vices[0].name,
286
+ // viceId: vices[0].id,
287
+ // category: categories[2].name,
288
+ // categoryId: categories[2].id,
289
+ // name: "spirit (1.5oz)",
290
+ // units: 1,
291
+ // }),
292
+ // store.types.create({
293
+ // vice: vices[0].name,
294
+ // viceId: vices[0].id,
295
+ // category: categories[2].name,
296
+ // categoryId: categories[2].id,
297
+ // name: "spirit (2oz)",
298
+ // units: 1.25,
299
+ // }),
300
+ // store.types.create({
301
+ // vice: vices[0].name,
302
+ // viceId: vices[0].id,
303
+ // category: categories[2].name,
304
+ // categoryId: categories[2].id,
305
+ // name: "cocktail",
306
+ // units: 1.5,
307
+ // }),
119
308
  store.types.create({
120
- vice: vices[0].id,
309
+ vice: vices[0].name,
121
310
  viceId: vices[0].id,
122
311
  category: categories[0].name,
123
312
  categoryId: categories[0].id,
124
- name: "beer (small)",
125
- units: 0.75,
313
+ name: "teaspoon/packet of sugar (4g)",
314
+ units: 4,
126
315
  }),
127
316
  store.types.create({
128
317
  vice: vices[0].name,
129
318
  viceId: vices[0].id,
130
319
  category: categories[0].name,
131
320
  categoryId: categories[0].id,
132
- name: "beer",
321
+ name: "1g of sugar",
133
322
  units: 1,
134
323
  }),
135
324
  store.types.create({
@@ -137,120 +326,48 @@ async function cleanup() {
137
326
  viceId: vices[0].id,
138
327
  category: categories[0].name,
139
328
  categoryId: categories[0].id,
140
- name: "beer (strong)",
141
- units: 1.25,
329
+ name: "2g of sugar",
330
+ units: 2,
142
331
  }),
143
332
  store.types.create({
144
333
  vice: vices[0].name,
145
334
  viceId: vices[0].id,
146
335
  category: categories[0].name,
147
336
  categoryId: categories[0].id,
148
- name: "beer (large)",
149
- units: 1.25,
337
+ name: "5g of sugar",
338
+ units: 5,
150
339
  }),
151
340
  store.types.create({
152
341
  vice: vices[0].name,
153
342
  viceId: vices[0].id,
154
343
  category: categories[0].name,
155
344
  categoryId: categories[0].id,
156
- name: "beer (xlarge/xstrong/large-strong)",
157
- units: 1.5,
158
- }),
159
- store.types.create({
160
- vice: vices[0].name,
161
- viceId: vices[0].id,
162
- category: categories[1].name,
163
- categoryId: categories[1].id,
164
- name: "wine (2.5oz)",
165
- units: 0.5,
166
- }),
167
- store.types.create({
168
- vice: vices[0].name,
169
- viceId: vices[0].id,
170
- category: categories[1].name,
171
- categoryId: categories[1].id,
172
- name: "wine (3.5oz)",
173
- units: 0.75,
174
- }),
175
- store.types.create({
176
- vice: vices[0].name,
177
- viceId: vices[0].id,
178
- category: categories[1].name,
179
- categoryId: categories[1].id,
180
- name: "wine (5oz)",
181
- units: 1,
182
- }),
183
- store.types.create({
184
- vice: vices[0].name,
185
- viceId: vices[0].id,
186
- category: categories[1].name,
187
- categoryId: categories[1].id,
188
- name: "wine (6.5oz)",
189
- units: 1.25,
345
+ name: "10g of sugar",
346
+ units: 10,
190
347
  }),
191
348
  store.types.create({
192
349
  vice: vices[0].name,
193
350
  viceId: vices[0].id,
194
- category: categories[1].name,
195
- categoryId: categories[1].id,
196
- name: "wine (7.5oz)",
197
- units: 1.5,
198
- }),
199
- store.types.create({
200
- vice: vices[0].name,
201
- viceId: vices[0].id,
202
- category: categories[1].name,
203
- categoryId: categories[1].id,
204
- name: "wine (9oz)",
205
- units: 1.75,
351
+ category: categories[0].name,
352
+ categoryId: categories[0].id,
353
+ name: "20g of sugar",
354
+ units: 20,
206
355
  }),
207
356
  store.types.create({
208
357
  vice: vices[0].name,
209
358
  viceId: vices[0].id,
210
- category: categories[1].name,
211
- categoryId: categories[1].id,
212
- name: "wine (500ml bottle)",
213
- units: 3.5,
359
+ category: categories[0].name,
360
+ categoryId: categories[0].id,
361
+ name: "50g of sugar",
362
+ units: 50,
214
363
  }),
215
364
  store.types.create({
216
365
  vice: vices[0].name,
217
366
  viceId: vices[0].id,
218
367
  category: categories[1].name,
219
368
  categoryId: categories[1].id,
220
- name: "wine (750ml bottle)",
221
- units: 5,
222
- }),
223
- store.types.create({
224
- vice: vices[0].name,
225
- viceId: vices[0].id,
226
- category: categories[2].name,
227
- categoryId: categories[2].id,
228
- name: "spirit (1oz)",
229
- units: 0.75,
230
- }),
231
- store.types.create({
232
- vice: vices[0].name,
233
- viceId: vices[0].id,
234
- category: categories[2].name,
235
- categoryId: categories[2].id,
236
- name: "spirit (1.5oz)",
237
- units: 1,
238
- }),
239
- store.types.create({
240
- vice: vices[0].name,
241
- viceId: vices[0].id,
242
- category: categories[2].name,
243
- categoryId: categories[2].id,
244
- name: "spirit (2oz)",
245
- units: 1.25,
246
- }),
247
- store.types.create({
248
- vice: vices[0].name,
249
- viceId: vices[0].id,
250
- category: categories[2].name,
251
- categoryId: categories[2].id,
252
- name: "cocktail",
253
- units: 1.5,
369
+ name: "typical candy bar",
370
+ units: 25,
254
371
  }),
255
372
  ]);
256
373
  // console.log("created", { types });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@desmat/redis-store",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {