@mblaney/holster 2.3.2 → 2.3.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mblaney/holster",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "description": "Holster is a service that allows synchronising data between devices using Node, Deno, Bun or the browser.",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/holster.js CHANGED
@@ -416,10 +416,10 @@ const Holster = opt => {
416
416
  return
417
417
  }
418
418
 
419
- // lex requires a callback as it's not included in the chain below.
419
+ // lex isn't part of the chain below, so without a callback the
420
+ // result is returned as a promise instead.
420
421
  if (lex && typeof cb !== "function") {
421
- console.log("error lex requires a callback function")
422
- return
422
+ return new Promise(resolve => api(ctxid).get(key, lex, resolve, _opt))
423
423
  }
424
424
 
425
425
  // Top level keys are added to a root node so their values don't need
@@ -462,10 +462,12 @@ const Holster = opt => {
462
462
  return
463
463
  }
464
464
 
465
- // lex requires a callback as it's not included in the chain below.
465
+ // lex isn't part of the chain below, so without a callback the
466
+ // result is returned as a promise instead.
466
467
  if (lex && typeof cb !== "function") {
467
- console.log("error lex requires a callback function")
468
- return
468
+ return new Promise(resolve =>
469
+ api(ctxid).next(key, lex, resolve, _opt),
470
+ )
469
471
  }
470
472
 
471
473
  const ctx = allctx.get(ctxid)
@@ -982,10 +984,10 @@ const Holster = opt => {
982
984
  return
983
985
  }
984
986
 
985
- // lex requires a callback as it's not included in the chain below.
987
+ // lex isn't part of the chain below, so without a callback the
988
+ // result is returned as a promise instead.
986
989
  if (lex && !cb) {
987
- console.log("error lex requires a callback function")
988
- return
990
+ return new Promise(resolve => user.get(keys, lex, resolve, _opt))
989
991
  }
990
992
 
991
993
  ctxid = utils.text.random()
package/ts/src/holster.ts CHANGED
@@ -37,11 +37,8 @@ export interface HolsterAPI {
37
37
  cb: (data: unknown) => void,
38
38
  _opt?: WireOptions,
39
39
  ): HolsterAPI
40
- (
41
- key: string | null,
42
- lex?: LexWithDot,
43
- _opt?: WireOptions,
44
- ): AwaitableHolsterAPI
40
+ (key: string | null, lex: LexWithDot, _opt?: WireOptions): Promise<unknown>
41
+ (key: string | null, lex?: null, _opt?: WireOptions): AwaitableHolsterAPI
45
42
  }
46
43
  next: {
47
44
  (
@@ -55,11 +52,8 @@ export interface HolsterAPI {
55
52
  cb: (data: unknown) => void,
56
53
  _opt?: WireOptions,
57
54
  ): HolsterAPI
58
- (
59
- key: string | null,
60
- lex?: LexWithDot,
61
- _opt?: WireOptions,
62
- ): AwaitableHolsterAPI
55
+ (key: string | null, lex: LexWithDot, _opt?: WireOptions): Promise<unknown>
56
+ (key: string | null, lex?: null, _opt?: WireOptions): AwaitableHolsterAPI
63
57
  }
64
58
  put: {
65
59
  (
@@ -601,9 +595,12 @@ const Holster = (opt?: HolsterOptions | string | string[]): HolsterAPI => {
601
595
  return this
602
596
  }
603
597
 
598
+ // lex isn't part of the chain below, so without a callback the
599
+ // result is returned as a promise instead.
604
600
  if (lexFilter && typeof callback !== "function") {
605
- console.log("error lex requires a callback function")
606
- return this
601
+ return new Promise(resolve =>
602
+ api(ctxid).get(key, lexFilter, resolve, opts),
603
+ ) as never
607
604
  }
608
605
 
609
606
  ctxid = utils.text.random()
@@ -662,9 +659,12 @@ const Holster = (opt?: HolsterOptions | string | string[]): HolsterAPI => {
662
659
  return this
663
660
  }
664
661
 
662
+ // lex isn't part of the chain below, so without a callback the
663
+ // result is returned as a promise instead.
665
664
  if (lexFilter && typeof callback !== "function") {
666
- console.log("error lex requires a callback function")
667
- return this
665
+ return new Promise(resolve =>
666
+ api(ctxid).next(key, lexFilter, resolve, opts),
667
+ ) as never
668
668
  }
669
669
 
670
670
  const ctx = allctx.get(ctxid)
@@ -1266,9 +1266,12 @@ const Holster = (opt?: HolsterOptions | string | string[]): HolsterAPI => {
1266
1266
  return this
1267
1267
  }
1268
1268
 
1269
+ // lex isn't part of the chain below, so without a callback the
1270
+ // result is returned as a promise instead.
1269
1271
  if (lexFilter && !callback) {
1270
- console.log("error lex requires a callback function")
1271
- return this
1272
+ return new Promise(resolve =>
1273
+ user.get!(keys, lexFilter, resolve, opts),
1274
+ ) as never
1272
1275
  }
1273
1276
 
1274
1277
  ctxid = utils.text.random()
package/ts/src/user.ts CHANGED
@@ -9,7 +9,7 @@ import SEA from "./sea.ts"
9
9
  import type {
10
10
  UserIdentity,
11
11
  HolsterOptions,
12
- LexFilter,
12
+ LexWithDot,
13
13
  WireOptions,
14
14
  } from "./schemas.ts"
15
15
  import type {HolsterAPI, AwaitableHolsterAPI} from "./holster.ts"
@@ -45,7 +45,7 @@ export interface UserInterface {
45
45
  get?: {
46
46
  (
47
47
  keys: string | string[],
48
- lex: LexFilter,
48
+ lex: LexWithDot,
49
49
  cb: (data: unknown) => void,
50
50
  _opt?: WireOptions,
51
51
  ): HolsterAPI
@@ -56,7 +56,12 @@ export interface UserInterface {
56
56
  ): HolsterAPI
57
57
  (
58
58
  keys: string | string[],
59
- lex?: LexFilter,
59
+ lex: LexWithDot,
60
+ _opt?: WireOptions,
61
+ ): Promise<unknown>
62
+ (
63
+ keys: string | string[],
64
+ lex?: null,
60
65
  _opt?: WireOptions,
61
66
  ): AwaitableHolsterAPI
62
67
  }