corebasic 1.0.232 → 1.0.234

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.
@@ -78,7 +78,7 @@ export const send = async (meta, feature, data, params) => {
78
78
  // return (await axios[method](`${service}${url}`, payload, {headers: {jwt: SERVICE_ACCESS_TOKEN, service: true}, timeout: 1000 })).data // Worked Earlier, but issue spotted
79
79
  if (baseFeature) { // Local call
80
80
  let response;
81
- let req = { body: payload, params: params ?? {}, method, path: url, url: '' };
81
+ let req = { body: payload, params: params ?? {}, method, path: url, url: '', headers: {}, query: {}, on: (_event, _callback) => { } };
82
82
  req = JSON.parse(JSON.stringify(req));
83
83
  const callback = (payload) => { response = payload; };
84
84
  const res = {
@@ -109,7 +109,7 @@ async function announce() {
109
109
  let exp_features = {};
110
110
  for (let [key, { api, subscribe }] of Object.entries(features))
111
111
  exp_features[key] = { api, service: SERVICE_ADDRESS, subscribe, topic: "" };
112
- await Messaging.subscribe(`${process.env.REDIS_CHANNEL_PREFIX}_SLYP_FEATURES_LIST`, async (message, channel) => {
112
+ await Messaging.subscribe(`${process.env.REDIS_CHANNEL_PREFIX}_SLYP_FEATURES_LIST`, async (message, _channel) => {
113
113
  let { uid, ...msg } = JSON.parse(message);
114
114
  if (uid !== appId && !appids[uid]) {
115
115
  appids[uid] = true;
@@ -129,6 +129,7 @@ function getFeaturelessFeature(req) {
129
129
  }
130
130
  }
131
131
  }
132
+ return undefined;
132
133
  }
133
134
  const apiHandler = async (req, res) => {
134
135
  let method = req.method.toLowerCase();
@@ -266,7 +267,7 @@ export const start = async (app, url, file) => {
266
267
  PROJECT_ROOT_URL = url;
267
268
  features = await Utils.fileToJson(url, file);
268
269
  await announce();
269
- app.get('/features', async (req, res) => {
270
+ app.get('/features', async (_req, res) => {
270
271
  let exp_features = {};
271
272
  for (let [key, { api }] of Object.entries(features))
272
273
  exp_features[key] = { api, service: `${SERVICE_ADDRESS}`, subscribe: '', topic: '' };
@@ -411,7 +412,7 @@ async function subscribe() {
411
412
  kafka_consumer_promise
412
413
  .then(kafka_consumer => {
413
414
  subscribed_consumers[consumer] = kafka_consumer;
414
- }).catch(err => {
415
+ }).catch(() => {
415
416
  throw new Error("Error: Remote service to service kafka Feature subscription.");
416
417
  });
417
418
  }
@@ -42,12 +42,11 @@ const start_consumer = async function (topic, groupId, callback) {
42
42
  autoCommit: false,
43
43
  eachMessage: async ({ topic, partition, message }) => {
44
44
  // callback(topic, message.value.toString(), partition) // toString() returns array so won't parse if json.
45
- let success;
46
45
  try {
47
- success = await callback(topic, JSON.parse(message.value), partition);
46
+ await callback(topic, JSON.parse(message.value), partition);
48
47
  }
49
48
  catch (ex) {
50
- success = await callback(topic, message.value, partition); // NOTE: Beware: Ensure Kafka.receive<T> can handle raw message type that is not json parseable
49
+ await callback(topic, message.value, partition); // NOTE: Beware: Ensure Kafka.receive<T> can handle raw message type that is not json parseable
51
50
  }
52
51
  await consumer.commitOffsets([{ topic, partition, offset: (Number(message.offset) + 1).toString() }]);
53
52
  },
@@ -34,7 +34,7 @@ async function connect({ user, req, res, uid }) {
34
34
  message = JSON.parse(message);
35
35
  }
36
36
  catch { }
37
- for (let { req, res } of users_pool[user].reqres) {
37
+ for (let { res } of users_pool[user].reqres) {
38
38
  res.write(JSON.stringify({ message, channel }) + "\n");
39
39
  if (res.flush) // If compression enabled
40
40
  res.flush();
@@ -53,7 +53,7 @@ export async function start(app) {
53
53
  await consumer.connect();
54
54
  publisher = createClient({ url });
55
55
  await publisher.connect();
56
- consumer.on('error', err => console.log('Redis Client Error', err));
56
+ consumer.on('error', (err) => console.log('Redis Client Error', err));
57
57
  app.get('/messages/:user', async (req, res) => {
58
58
  let uid = req.body.client;
59
59
  await connect({ user: req.params.user, req, res, uid });
@@ -26,7 +26,7 @@ export function isEmpty(str) {
26
26
  }
27
27
  export let GLOBAL_META = { company: "GLOBAL", outlet: "GLOBAL" };
28
28
  export function isEmptyJson(json) {
29
- for (let i in json)
29
+ for (let _i in json)
30
30
  return false;
31
31
  return true;
32
32
  }
package/libs/auth.ts CHANGED
@@ -47,7 +47,7 @@ type SuccessCallback = (
47
47
  let validateFn: ValidateFunction | undefined
48
48
  let validateErrMessage: string | undefined
49
49
 
50
- export const validate = (callback: ValidateFunction, errMessage?: string) => {
50
+ export const validate = (callback: ValidateFunction, _errMessage?: string) => {
51
51
  validateFn = callback
52
52
  }
53
53
 
@@ -58,7 +58,7 @@ export const start = (app: AuthApp, successCallback?: SuccessCallback) => {
58
58
  return
59
59
  }
60
60
  try {
61
- let login = await attemptLogin(req, res)
61
+ let login = await attemptLogin(req)
62
62
  if (login.mode === 'verify' && login.success) {
63
63
  let tokens = Session.generateAccessToken(login.userId, req.body.clientId ?? '')
64
64
  let response = {...login, tokens}
@@ -74,7 +74,7 @@ export const start = (app: AuthApp, successCallback?: SuccessCallback) => {
74
74
  })
75
75
  }
76
76
 
77
- async function attemptLogin(req: AuthRequest, res: AuthResponse) {
77
+ async function attemptLogin(req: AuthRequest) {
78
78
  let meta = {company: "GLOBAL", outlet: "GLOBAL"}
79
79
 
80
80
  let expiry = 300000
@@ -89,7 +89,7 @@ function flatten_value(target_key: string, value: unknown, flattened: unknown[],
89
89
  }
90
90
 
91
91
 
92
- export function entries(target_key: string, query: unknown, binary_slice?: Buffer): unknown[] {
92
+ export function entries(target_key: string, query: unknown, _binary_slice?: Buffer): unknown[] {
93
93
  let result = flatten_id_values(target_key, query); // extract all valid _id
94
94
 
95
95
  // let cows = result.map(v => extract_direct_id(v, binary_slice))
@@ -140,7 +140,7 @@ type SuffixItem = { key?: string; value?: string; type: string; ls_threshold?: n
140
140
  type CollectionsJsonType = Record<string, {policy?: {when: object, suffix: SuffixItem[]}[]}>
141
141
  type Arg = { db: string; collection: string[]; }
142
142
 
143
- export async function applySuffixPolicy(COLLECTIONS_JSON: CollectionsJsonType, cols: string | string[], query: Record<string, any>, insertMode?: boolean, arg?: Arg) {
143
+ export async function applySuffixPolicy(COLLECTIONS_JSON: CollectionsJsonType, cols: string | string[], query: Record<string, any>, insertMode: boolean, arg: Arg) {
144
144
  const collections = Array.isArray(cols) ? cols : [cols]
145
145
  let suffixes: string[] = []
146
146
 
@@ -6,7 +6,7 @@ type SuffixItem = { key?: string; value?: string; type: string; ls_threshold?: n
6
6
  type Arg = { db: string; collection: string[]; }
7
7
 
8
8
  const EXPLICIT_SUFFIX_POLICY_TYPES = new Set([ "string", "date", "number" ]);
9
- export async function suffix(doc: Record<string, any>, policies: SuffixItem[], insertMode?: boolean, arg?: Arg) {
9
+ export async function suffix(doc: Record<string, any>, policies: SuffixItem[], insertMode: boolean, arg: Arg) {
10
10
  let suffixes = [""]
11
11
  for (const policy of policies) {
12
12
 
@@ -92,9 +92,8 @@ export async function suffix(doc: Record<string, any>, policies: SuffixItem[], i
92
92
  if (!keys.length && !insertMode) {
93
93
  ls = true
94
94
  for (const suffix of suffixes) {
95
- const collections = arg?.collection ?? []
96
- for (const collection of collections) {
97
- const dirs = (await Dip.operation("ls", { db: arg?.db, collection: collection, suffix })).filter((dir: string) => !dir.startsWith('chunk-'))
95
+ for (const collection of arg.collection) {
96
+ const dirs = (await Dip.operation("ls", { db: arg.db, collection: collection, suffix })).filter((dir: string) => !dir.startsWith('chunk-'))
98
97
  suffixAssociatedKeys[suffix] = suffixAssociatedKeys[suffix] ?? []
99
98
  suffixAssociatedKeys[suffix].push(...dirs)
100
99
  }
@@ -2,6 +2,8 @@ import { describe, test } from "node:test";
2
2
  import assert from "node:assert/strict";
3
3
  import {applySuffixPolicy} from "../policy.ts";
4
4
 
5
+ let insertMode = false
6
+ const arg = {db: "test-db", collection: ["test-collection"]}
5
7
  // -----------------------------------------------------------------------------
6
8
  // applySuffixPolicy()
7
9
  // -----------------------------------------------------------------------------
@@ -10,7 +12,7 @@ describe("applySuffixPolicy()", () => {
10
12
  test("no collection", async () => {
11
13
  const collections = {};
12
14
 
13
- const result = await applySuffixPolicy(collections, "missing", {});
15
+ const result = await applySuffixPolicy(collections, "missing", {}, insertMode, arg);
14
16
 
15
17
  assert.deepEqual(result, []);
16
18
  });
@@ -20,7 +22,7 @@ describe("applySuffixPolicy()", () => {
20
22
  invoices: {}
21
23
  };
22
24
 
23
- const result = await applySuffixPolicy(collections, "invoices", {});
25
+ const result = await applySuffixPolicy(collections, "invoices", {}, insertMode, arg);
24
26
 
25
27
  assert.deepEqual(result, []);
26
28
  });
@@ -32,7 +34,7 @@ describe("applySuffixPolicy()", () => {
32
34
  }
33
35
  };
34
36
 
35
- const result = await applySuffixPolicy(collections, "invoices", {});
37
+ const result = await applySuffixPolicy(collections, "invoices", {}, insertMode, arg);
36
38
 
37
39
  assert.deepEqual(result, []);
38
40
  });
@@ -48,13 +50,7 @@ describe("applySuffixPolicy()", () => {
48
50
  }
49
51
  };
50
52
 
51
- const result = await applySuffixPolicy(
52
- collections as any,
53
- "invoices",
54
- {
55
- type: "Sales"
56
- }
57
- );
53
+ const result = await applySuffixPolicy(collections as any, "invoices", {type: "Sales"}, insertMode, arg);
58
54
 
59
55
  assert.deepEqual(result, [
60
56
  "/Sales"
@@ -74,17 +70,8 @@ describe("applySuffixPolicy()", () => {
74
70
  }
75
71
  };
76
72
 
77
- const result = await applySuffixPolicy(
78
- collections as any,
79
- "invoices",
80
- {
81
- type: "Sales"
82
- }
83
- );
84
-
85
- assert.deepEqual(result, [
86
- "/Sales"
87
- ]);
73
+ const result = await applySuffixPolicy(collections as any, "invoices", { type: "Sales" }, insertMode, arg);
74
+ assert.deepEqual(result, ["/Sales"]);
88
75
  });
89
76
 
90
77
  test("unconditional policy", async () => {
@@ -99,13 +86,7 @@ describe("applySuffixPolicy()", () => {
99
86
  }
100
87
  };
101
88
 
102
- const result = await applySuffixPolicy(
103
- collections as any,
104
- "invoices",
105
- {
106
- type: "Sales"
107
- }
108
- );
89
+ const result = await applySuffixPolicy(collections as any, "invoices", {type: "Sales"}, insertMode, arg);
109
90
 
110
91
  assert.deepEqual(result, [
111
92
  "/Sales"
@@ -126,14 +107,7 @@ describe("applySuffixPolicy()", () => {
126
107
  }
127
108
  };
128
109
 
129
- const result = await applySuffixPolicy(
130
- collections as any,
131
- "invoices",
132
- {
133
- status: "Active",
134
- type: "Sales"
135
- }
136
- );
110
+ const result = await applySuffixPolicy(collections as any, "invoices", {status: "Active", type: "Sales"}, insertMode, arg);
137
111
 
138
112
  assert.deepEqual(result, [
139
113
  "/Sales"
@@ -154,14 +128,7 @@ describe("applySuffixPolicy()", () => {
154
128
  }
155
129
  };
156
130
 
157
- const result = await applySuffixPolicy(
158
- collections as any,
159
- "invoices",
160
- {
161
- status: "Deleted",
162
- type: "Sales"
163
- }
164
- );
131
+ const result = await applySuffixPolicy(collections as any, "invoices", {status: "Deleted", type: "Sales"}, insertMode, arg);
165
132
 
166
133
  assert.deepEqual(result, []);
167
134
  });
@@ -180,14 +147,7 @@ describe("applySuffixPolicy()", () => {
180
147
  }
181
148
  };
182
149
 
183
- const result = await applySuffixPolicy(
184
- collections as any,
185
- "invoices",
186
- {
187
- status: {$in: ["Active", "Pending"]},
188
- type: "Sales"
189
- }
190
- );
150
+ const result = await applySuffixPolicy(collections as any, "invoices", {status: {$in: ["Active", "Pending"]}, type: "Sales"}, insertMode, arg);
191
151
 
192
152
  assert.deepEqual(result, [
193
153
  "/Sales"
@@ -218,15 +178,7 @@ describe("applySuffixPolicy()", () => {
218
178
  }
219
179
  };
220
180
 
221
- const result = await applySuffixPolicy(
222
- collections as any,
223
- "invoices",
224
- {
225
- status: "Active",
226
- type: "Sales",
227
- region: "IN"
228
- }
229
- );
181
+ const result = await applySuffixPolicy(collections as any, "invoices", {status: "Active", type: "Sales", region: "IN"}, insertMode, arg);
230
182
 
231
183
  assert.deepEqual(
232
184
  result.sort(),
@@ -261,15 +213,7 @@ describe("applySuffixPolicy()", () => {
261
213
  }
262
214
  };
263
215
 
264
- const result = await applySuffixPolicy(
265
- collections as any,
266
- "invoices",
267
- {
268
- status: "Active",
269
- type: "Sales",
270
- region: "IN"
271
- }
272
- );
216
+ const result = await applySuffixPolicy(collections as any, "invoices", {status: "Active", type: "Sales", region: "IN"}, insertMode, arg);
273
217
 
274
218
  assert.deepEqual(result, [
275
219
  "/Sales"
@@ -294,13 +238,7 @@ describe("applySuffixPolicy()", () => {
294
238
  }
295
239
  };
296
240
 
297
- const result = await applySuffixPolicy(
298
- collections as any,
299
- "invoices",
300
- {
301
- type: "Sales"
302
- }
303
- );
241
+ const result = await applySuffixPolicy(collections as any, "invoices", {type: "Sales"}, insertMode, arg);
304
242
 
305
243
  assert.deepEqual(result, [
306
244
  "/Sales"
@@ -321,13 +259,7 @@ describe("applySuffixPolicy()", () => {
321
259
  }
322
260
  };
323
261
 
324
- const result = await applySuffixPolicy(
325
- collections as any,
326
- "invoices",
327
- {
328
- date: new Date(2026, 4, 3).getTime()
329
- }
330
- );
262
+ const result = await applySuffixPolicy(collections as any, "invoices", {date: new Date(2026, 4, 3).getTime()}, insertMode, arg);
331
263
 
332
264
  assert.deepEqual(result, [
333
265
  "/2026"
@@ -349,14 +281,7 @@ describe("applySuffixPolicy()", () => {
349
281
  }
350
282
  };
351
283
 
352
- const result = await applySuffixPolicy(
353
- collections as any,
354
- "invoices",
355
- {
356
- type: "Sales",
357
- date: new Date(2026, 4, 3).getTime()
358
- }
359
- );
284
+ const result = await applySuffixPolicy(collections as any, "invoices", {type: "Sales", date: new Date(2026, 4, 3).getTime()}, insertMode, arg);
360
285
 
361
286
  assert.deepEqual(result, [
362
287
  "/Sales/2026"
@@ -379,16 +304,7 @@ describe("applySuffixPolicy()", () => {
379
304
  }
380
305
  };
381
306
 
382
- const result = await applySuffixPolicy(
383
- collections as any,
384
- "invoices",
385
- {
386
- age: {
387
- $gt: 20
388
- },
389
- type: "Sales"
390
- }
391
- );
307
+ const result = await applySuffixPolicy(collections as any, "invoices", {age: {$gt: 20}, type: "Sales"}, insertMode, arg);
392
308
 
393
309
  assert.deepEqual(result, [
394
310
  "/Sales"
@@ -411,16 +327,7 @@ describe("applySuffixPolicy()", () => {
411
327
  }
412
328
  };
413
329
 
414
- const result = await applySuffixPolicy(
415
- collections as any,
416
- "invoices",
417
- {
418
- age: {
419
- $lt: 10
420
- },
421
- type: "Sales"
422
- }
423
- );
330
+ const result = await applySuffixPolicy(collections as any, "invoices", {age: {$lt: 10}, type: "Sales"}, insertMode, arg);
424
331
 
425
332
  assert.deepEqual(result, []);
426
333
  });
@@ -442,14 +349,7 @@ describe("applySuffixPolicy()", () => {
442
349
  };
443
350
 
444
351
  await assert.rejects(async () => {
445
- await applySuffixPolicy(
446
- collections as any,
447
- "invoices",
448
- {
449
- status: "Active",
450
- type: "Sales"
451
- }
452
- );
352
+ await applySuffixPolicy(collections as any, "invoices", {status: "Active", type: "Sales"}, insertMode, arg);
453
353
  });
454
354
  });
455
355
 
@@ -467,17 +367,7 @@ describe("applySuffixPolicy()", () => {
467
367
  }
468
368
  };
469
369
 
470
- const result = await applySuffixPolicy(
471
- collections as any,
472
- "invoices",
473
- {
474
- age: {
475
- $gt: 5,
476
- $lt: 15
477
- },
478
- type: "Sales"
479
- }
480
- );
370
+ const result = await applySuffixPolicy(collections as any, "invoices", {age: {$gt: 5, $lt: 15}, type: "Sales"}, insertMode, arg);
481
371
 
482
372
  assert.deepEqual(result, [
483
373
  "/Sales"
@@ -498,17 +388,7 @@ describe("applySuffixPolicy()", () => {
498
388
  }
499
389
  };
500
390
 
501
- const result = await applySuffixPolicy(
502
- collections as any,
503
- "invoices",
504
- {
505
- age: {
506
- $gt: 5,
507
- $lt: 15
508
- },
509
- type: "Sales"
510
- }
511
- );
391
+ const result = await applySuffixPolicy(collections as any, "invoices", {age: {$gt: 5,$lt: 15}, type: "Sales"}, insertMode, arg);
512
392
 
513
393
  assert.deepEqual(result, []);
514
394
  });
@@ -530,14 +410,7 @@ describe("applySuffixPolicy()", () => {
530
410
  }
531
411
  };
532
412
 
533
- const result = await applySuffixPolicy(
534
- collections as any,
535
- "invoices",
536
- {
537
- age: { $in: [10] },
538
- type: "Sales"
539
- }
540
- );
413
+ const result = await applySuffixPolicy(collections as any, "invoices", {age: { $in: [10] }, type: "Sales"}, insertMode, arg);
541
414
 
542
415
  assert.deepEqual(result, [
543
416
  "/Sales"
@@ -561,14 +434,7 @@ describe("applySuffixPolicy()", () => {
561
434
  }
562
435
  };
563
436
 
564
- const result = await applySuffixPolicy(
565
- collections as any,
566
- "invoices",
567
- {
568
- age: { $in: [10] },
569
- type: "Sales"
570
- }
571
- );
437
+ const result = await applySuffixPolicy(collections as any, "invoices", {age: { $in: [10] }, type: "Sales"}, insertMode, arg);
572
438
 
573
439
  assert.deepEqual(result, []);
574
440
  });
@@ -590,17 +456,7 @@ describe("applySuffixPolicy()", () => {
590
456
  }
591
457
  };
592
458
 
593
- const result = await applySuffixPolicy(
594
- collections as any,
595
- "invoices",
596
- {
597
- age: {
598
- $gt: 20,
599
- $lt: 40
600
- },
601
- type: "Sales"
602
- }
603
- );
459
+ const result = await applySuffixPolicy(collections as any, "invoices",{age: {$gt: 20, $lt: 40}, type: "Sales"}, insertMode, arg);
604
460
 
605
461
  assert.deepEqual(result, [
606
462
  "/Sales"
@@ -624,17 +480,7 @@ describe("applySuffixPolicy()", () => {
624
480
  }
625
481
  };
626
482
 
627
- const result = await applySuffixPolicy(
628
- collections as any,
629
- "invoices",
630
- {
631
- age: {
632
- $gt: 10,
633
- $lt: 20
634
- },
635
- type: "Sales"
636
- }
637
- );
483
+ const result = await applySuffixPolicy(collections as any, "invoices", {age: {$gt: 10, $lt: 20}, type: "Sales"}, insertMode, arg);
638
484
 
639
485
  assert.deepEqual(result, []);
640
486
  });
@@ -1,6 +1,6 @@
1
1
  import { describe, test } from "node:test";
2
2
  import assert from "node:assert/strict";
3
- import {matchPolicy, overlaps, contains, intersects, applySuffixPolicy} from "../policy.ts";
3
+ import {matchPolicy, overlaps, contains, intersects} from "../policy.ts";
4
4
 
5
5
  const defaultBounds = {values: [], from: -Infinity, to: Infinity, fromOp: "$gte", toOp: "$lte"}
6
6
 
package/libs/dip.ts CHANGED
@@ -64,14 +64,14 @@ export const IdempotentDip = (): IdempotentDip => {
64
64
  }
65
65
 
66
66
  idip.insert = async function (collection, query, data) {
67
- await Elabase.update(state.meta, collection, query, { $setOnInsert: data }, {upsert: true})
67
+ await Elabase.update(state.meta!, collection, query, { $setOnInsert: data }, {upsert: true})
68
68
  }
69
69
 
70
70
  idip.update = async function (collection, query, data, rollback) {
71
71
  let token = { [state.txn]: true }
72
72
  let idempotent = { [state.txn]: { $exists: rollback ?? false } }
73
- let result = await Elabase.update(state.meta, collection, {...query, ...idempotent}, {...data, $setOnInsert: undefined, $set: {...(data.$set ?? {}), ...token} })
74
- return result.count ? true : (await Elabase.query(state.meta, collection, {...query, ...idempotent})).length
73
+ let result = await Elabase.update(state.meta!, collection, {...query, ...idempotent}, {...data, $setOnInsert: undefined, $set: {...(data.$set ?? {}), ...token} })
74
+ return result.count ? true : (await Elabase.query(state.meta!, collection, {...query, ...idempotent})).length
75
75
  }
76
76
 
77
77
  idip.upsert = async function (collection, query, data, rollback) {
@@ -80,11 +80,11 @@ export const IdempotentDip = (): IdempotentDip => {
80
80
  }
81
81
 
82
82
  idip.cleanup = async function (collection, query) {
83
- await Elabase.update(state.meta, collection, query, { $unset: { [state.txn]: true } })
83
+ await Elabase.update(state.meta!, collection, query, { $unset: { [state.txn]: true } })
84
84
  }
85
85
 
86
86
  idip.finish = async function () {
87
- return await Elabase.update(state.meta, "txns",{_id: state.txn}, {}, {upsert: true})
87
+ return await Elabase.update(state.meta!, "txns",{_id: state.txn}, {}, {upsert: true})
88
88
  }
89
89
 
90
90
  return idip
package/libs/dipper.ts CHANGED
@@ -6,7 +6,6 @@ import axios from 'axios'
6
6
  type DipperIdQuery = string | string[] | { $in: string[] }
7
7
 
8
8
  type DipperArg = {
9
- mode: string
10
9
  query?: {
11
10
  _id?: DipperIdQuery
12
11
  }
@@ -25,16 +24,16 @@ function hashStr(str: string) {
25
24
  return hash;
26
25
  }
27
26
 
28
- function hash(string: string, digits: number) {
29
- digits = digits || 6;
30
- var m = Math.pow(10, digits+1) - 1;
31
- var phi = Math.pow(10, digits) / 2 - 1;
32
- var n = 0;
33
- for (var i = 0; i < string.length; i++) {
34
- n = (n + phi * string.charCodeAt(i)) % m;
35
- }
36
- return n.toString();
37
- }
27
+ // function hash(string: string, digits: number) {
28
+ // digits = digits || 6;
29
+ // var m = Math.pow(10, digits+1) - 1;
30
+ // var phi = Math.pow(10, digits) / 2 - 1;
31
+ // var n = 0;
32
+ // for (var i = 0; i < string.length; i++) {
33
+ // n = (n + phi * string.charCodeAt(i)) % m;
34
+ // }
35
+ // return n.toString();
36
+ // }
38
37
  let shards: string[] = []
39
38
  let shardCount = 20
40
39
 
@@ -52,7 +51,7 @@ function shard(key: string) {
52
51
  export let shard_hits: Record<string, number> = {}
53
52
 
54
53
  async function postDip(url: string | URL, arg: unknown) {
55
- return (await axios.post(url, arg)).data
54
+ return (await axios.post(String(url), arg)).data
56
55
  // curl
57
56
  // -----
58
57
  // const { data } = await curly.post(url, {
@@ -67,6 +66,8 @@ async function postDip(url: string | URL, arg: unknown) {
67
66
 
68
67
  export default async function dipper(arg: DipperArg) {
69
68
 
69
+ const mode: string = arg.insert || arg.update || arg.delete ? "query" : "command" // TODO: batch
70
+
70
71
  let result = []
71
72
 
72
73
  let _id = arg.query?._id ?? arg.insert?._id ?? undefined
@@ -90,12 +91,12 @@ export default async function dipper(arg: DipperArg) {
90
91
  }
91
92
  }
92
93
 
93
- if (arg.mode === "query")
94
+ if (mode === "query")
94
95
  result = result.reduce( (partial, item) => partial.concat(item), [])
95
96
 
96
97
 
97
98
 
98
- return arg.mode === "query" ? result : result[0]
99
+ return mode === "query" ? result : result[0]
99
100
  }
100
101
 
101
102