@nemigo/storage 1.7.0 → 1.7.2

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/cookie.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ConstructVeilPrefixStorage } from "./internal/veil-prefix.js";
2
2
  import { VeilPrefixStorage } from "./internal/veil-prefix.js";
3
- import type { IStorage, IStorageValue, IStorageSetOptions } from "./types.js";
3
+ import type { IStorage, IStorageSetOptions, IStorageValue } from "./types.js";
4
4
  import type { SetDocumentCookieOptions } from "@nemigo/helpers/html/cookie";
5
5
  /**
6
6
  * Опции для {@link CookieStorage.set}
@@ -1,5 +1,5 @@
1
+ import type { IStorage } from "../types.js";
1
2
  import type { CanBePromise } from "@nemigo/helpers/types";
2
- import type { IStorage } from "@nemigo/storage/types";
3
3
  export interface VaultItem<PayloadData> {
4
4
  /**
5
5
  * Полезная нагрузка
@@ -28,6 +28,10 @@ export interface VaultTimings {
28
28
  * Если не задано — обновление разрешено в любой момент
29
29
  */
30
30
  upd?: number;
31
+ /**
32
+ * TTL в хранилище (в секундах, дельта от текущего момента)
33
+ */
34
+ ttl?: number;
31
35
  }
32
36
  export interface VaultRunOptions<PayloadData> extends VaultTimings {
33
37
  /**
@@ -38,10 +42,6 @@ export interface VaultRunOptions<PayloadData> extends VaultTimings {
38
42
  * Принудительно перегенерировать, игнорируя тайминги
39
43
  */
40
44
  force?: boolean;
41
- /**
42
- * TTL в хранилище (в секундах, дельта от текущего момента)
43
- */
44
- ttl_seconds?: number;
45
45
  }
46
46
  export interface ConstructVault<PayloadData> extends VaultTimings {
47
47
  /**
@@ -53,6 +53,20 @@ export interface ConstructVault<PayloadData> extends VaultTimings {
53
53
  */
54
54
  equal: (a: PayloadData, b: PayloadData) => CanBePromise<boolean>;
55
55
  }
56
+ /**
57
+ * @example
58
+ * ```typescript
59
+ * export const codeVault = new Vault<string, RedisStorage>(redisStorage, {
60
+ * generate: () => rand(),
61
+ * equal: (a, b) => a === b,
62
+ * exp: 60 * 10,
63
+ * ttl: 60 * 10,
64
+ * upd: 60,
65
+ * });
66
+ *
67
+ * const result = await codeVault.run("some:key")
68
+ * ```
69
+ */
56
70
  export declare class Vault<PayloadData, Storage extends IStorage = IStorage> {
57
71
  storage: Storage;
58
72
  ctx: ConstructVault<PayloadData>;
@@ -1,3 +1,17 @@
1
+ /**
2
+ * @example
3
+ * ```typescript
4
+ * export const codeVault = new Vault<string, RedisStorage>(redisStorage, {
5
+ * generate: () => rand(),
6
+ * equal: (a, b) => a === b,
7
+ * exp: 60 * 10,
8
+ * ttl: 60 * 10,
9
+ * upd: 60,
10
+ * });
11
+ *
12
+ * const result = await codeVault.run("some:key")
13
+ * ```
14
+ */
1
15
  export class Vault {
2
16
  storage;
3
17
  ctx;
@@ -15,7 +29,7 @@ export class Vault {
15
29
  return this.ctx.equal(existed.pld, pld);
16
30
  }
17
31
  async run(key, options = {}) {
18
- const { ttl_seconds, exp = this.ctx.exp, upd = this.ctx.upd, force = false, overload } = options;
32
+ const { ttl = this.ctx.ttl, exp = this.ctx.exp, upd = this.ctx.upd, force = false, overload } = options;
19
33
  // работаем в секундах
20
34
  const nowSec = Math.floor(Date.now() / 1000);
21
35
  const existed = await this.find(key);
@@ -35,7 +49,7 @@ export class Vault {
35
49
  exp: newExp,
36
50
  upd: newUpd,
37
51
  };
38
- await this.storage.set(key, item, { ttl_seconds });
52
+ await this.storage.set(key, item, { ttl_seconds: ttl });
39
53
  return { generate: true, item };
40
54
  }
41
55
  }
package/dist/runtime.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { IStorage, IStorageValue, IStorageSetOptions } from "./types.js";
1
+ import type { IStorage, IStorageSetOptions, IStorageValue } from "./types.js";
2
2
  import type { Timestamp } from "@nemigo/helpers/types";
3
3
  export interface EntryValue {
4
4
  value: IStorageValue;
package/dist/web.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { VeilPrefixStorage } from "./internal/veil-prefix.js";
2
- import type { IStorage, IStorageValue, IStorageSetOptions } from "./types.js";
2
+ import type { IStorage, IStorageSetOptions, IStorageValue } from "./types.js";
3
3
  import type { Timestamp } from "@nemigo/helpers/types";
4
4
  export type WebStorageType = "local" | "session";
5
5
  export interface WebStorageOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/storage",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Vlad Logvin",