@cripty2001/utils 0.0.67 → 0.0.69

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.
@@ -1,4 +1,3 @@
1
- import { WhisprSetter } from "@cripty2001/whispr";
2
1
  import { Dispatcher } from "../Dispatcher";
3
2
  import { AppserverData } from "./common";
4
3
  export type { AppserverData };
@@ -17,10 +16,11 @@ export declare class ClientValidationError extends ClientError {
17
16
  export declare class Client {
18
17
  private url;
19
18
  private authToken;
20
- setAuthToken: WhisprSetter<string | null>;
19
+ private setAuthToken;
21
20
  loggedIn: Dispatcher<string | null, boolean>;
22
21
  private constructor();
23
22
  static create(url: string): Client;
23
+ login(token: string): Promise<boolean>;
24
24
  exec<I extends AppserverData, O extends AppserverData>(action: string, input: I): Promise<O>;
25
25
  private unsafeExec;
26
26
  }
@@ -41,11 +41,15 @@ class Client {
41
41
  return false;
42
42
  const { user } = await this.unsafeExec('auth/whoami', {});
43
43
  return user !== null;
44
- }, 200);
44
+ }, 0); // Sync execution
45
45
  }
46
46
  static create(url) {
47
47
  return new Client(url);
48
48
  }
49
+ async login(token) {
50
+ this.setAuthToken(token);
51
+ return await this.loggedIn.filtered.load();
52
+ }
49
53
  async exec(action, input) {
50
54
  return this.unsafeExec(`/exec/${action}`, input);
51
55
  }
@@ -54,7 +58,7 @@ class Client {
54
58
  method: "POST",
55
59
  headers: {
56
60
  "Content-Type": "application/vnd.msgpack",
57
- ...(this.authToken !== null ? { "Authorization": `Bearer ${this.authToken}` } : {}),
61
+ ...(this.authToken.value !== null ? { "Authorization": `Bearer ${this.authToken.value}` } : {}),
58
62
  },
59
63
  body: new Blob([new Uint8Array((0, msgpack_1.encode)(input))], { type: 'application/msgpack' }),
60
64
  });
@@ -25,8 +25,9 @@ export declare class Dispatcher<I, O> {
25
25
  * Create a new dispatcher
26
26
  * @param value The whispr value that will trigger f call when changed. Using this pattern instead of exposing a dispatch method allow to return the full dispatcher to anyone, without having to worry about them messing it
27
27
  * @param f The async function to call. It should return a promise that resolves to the data.
28
- * @param DEBOUNCE_INTERVAL
28
+ * @param DEBOUNCE_INTERVAL The debounce interval in milliseconds. Default to 200ms. The function will not be called if this time has not passed since the last call. If another change happens during the wait, the first function call will be aborted.
29
29
  *
30
+ * @remarks If the debounce interval is 0, the function will be called synchronously, as a Whispr listener would do.
30
31
  * @remarks The value is deep checked for equality. The function will be called only if the value changed deeply
31
32
  */
32
33
  constructor(value: Whispr<I>, f: DispatcherFunction<I, O>, DEBOUNCE_INTERVAL?: number);
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Dispatcher = void 0;
4
4
  const whispr_1 = require("@cripty2001/whispr");
5
- const _1 = require(".");
6
5
  const lodash_1 = require("lodash");
6
+ const _1 = require(".");
7
7
  class Dispatcher {
8
8
  state;
9
9
  setState;
@@ -17,8 +17,9 @@ class Dispatcher {
17
17
  * Create a new dispatcher
18
18
  * @param value The whispr value that will trigger f call when changed. Using this pattern instead of exposing a dispatch method allow to return the full dispatcher to anyone, without having to worry about them messing it
19
19
  * @param f The async function to call. It should return a promise that resolves to the data.
20
- * @param DEBOUNCE_INTERVAL
20
+ * @param DEBOUNCE_INTERVAL The debounce interval in milliseconds. Default to 200ms. The function will not be called if this time has not passed since the last call. If another change happens during the wait, the first function call will be aborted.
21
21
  *
22
+ * @remarks If the debounce interval is 0, the function will be called synchronously, as a Whispr listener would do.
22
23
  * @remarks The value is deep checked for equality. The function will be called only if the value changed deeply
23
24
  */
24
25
  constructor(value, f, DEBOUNCE_INTERVAL = 200) {
@@ -104,8 +105,10 @@ class Dispatcher {
104
105
  dispatch(data) {
105
106
  const signals = this.reset();
106
107
  const toReturn = (async () => {
107
- // Debouncing rapid changes
108
- await (0, _1.sleep)(this.DEBOUNCE_INTERVAL);
108
+ // Allow for sync operations
109
+ if (this.DEBOUNCE_INTERVAL > 0) {
110
+ await (0, _1.sleep)(this.DEBOUNCE_INTERVAL);
111
+ }
109
112
  if (signals.controller.signal.aborted)
110
113
  throw new DOMException('Debounced', 'AbortError');
111
114
  // Scheduling function execution
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.67",
3
+ "version": "0.0.69",
4
4
  "description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
5
5
  "homepage": "https://github.com/cripty2001/utils#readme",
6
6
  "bugs": {