@nice-code/util 0.8.0 → 0.9.0

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.
Files changed (41) hide show
  1. package/build/index.d.ts +765 -0
  2. package/build/index.js +966 -1080
  3. package/build/index.js.map +1 -0
  4. package/package.json +6 -18
  5. package/build/types/core/core_valibot_schemas.d.ts +0 -13
  6. package/build/types/core/createDataStringConverter_stringToObject.d.ts +0 -12
  7. package/build/types/crypto/aes_gcm/createAesGcmKeyFromX25519Keys.d.ts +0 -6
  8. package/build/types/crypto/aes_gcm/decryptBytesWithAesGcmKey.d.ts +0 -9
  9. package/build/types/crypto/aes_gcm/decryptTextDataWithAesGcmKey.d.ts +0 -5
  10. package/build/types/crypto/aes_gcm/encryptBytesWithAesGcmKey.d.ts +0 -10
  11. package/build/types/crypto/aes_gcm/encryptTextDataWithAesGcmKey.d.ts +0 -5
  12. package/build/types/crypto/client_key_link/ClientCryptoKeyLink.d.ts +0 -181
  13. package/build/types/crypto/client_key_link/buildVerifyKeyBoundInfoString.d.ts +0 -20
  14. package/build/types/crypto/crypto.converters.d.ts +0 -53
  15. package/build/types/crypto/crypto.schema.d.ts +0 -92
  16. package/build/types/crypto/ed25519/generateEd25519KeyPair.d.ts +0 -1
  17. package/build/types/crypto/ed25519/importEd25519Key.d.ts +0 -35
  18. package/build/types/crypto/ed25519/serializeEd25519Key_Jwk.d.ts +0 -2
  19. package/build/types/crypto/ed25519/serializeEd25519Key_Raw.d.ts +0 -2
  20. package/build/types/crypto/ed25519/signCombinedTextDataWithKeyEd25519.d.ts +0 -2
  21. package/build/types/crypto/ed25519/signTextDataWithKeyEd25519.d.ts +0 -1
  22. package/build/types/crypto/ed25519/verifyWithKeyEd25519.d.ts +0 -5
  23. package/build/types/crypto/index.d.ts +0 -21
  24. package/build/types/crypto/x25519/createSharedBitsFromX25519.d.ts +0 -4
  25. package/build/types/crypto/x25519/generateX25519KeyPair.d.ts +0 -1
  26. package/build/types/crypto/x25519/importX25519Key.d.ts +0 -35
  27. package/build/types/crypto/x25519/serializeX25519Key_Jwk.d.ts +0 -2
  28. package/build/types/crypto/x25519/serializeX25519Key_Raw.d.ts +0 -2
  29. package/build/types/data_type/index.d.ts +0 -1
  30. package/build/types/data_type/string/nullEmpty.d.ts +0 -3
  31. package/build/types/index.d.ts +0 -10
  32. package/build/types/storage_adapter/StorageAdapter.d.ts +0 -23
  33. package/build/types/storage_adapter/specific/browser/browser_storage.d.ts +0 -26
  34. package/build/types/storage_adapter/specific/cloudflare/durable_object/durable_object_storage.d.ts +0 -14
  35. package/build/types/storage_adapter/specific/cloudflare/durable_object/durable_object_storage.types.d.ts +0 -18
  36. package/build/types/storage_adapter/specific/cloudflare/kv/kv_storage.d.ts +0 -18
  37. package/build/types/storage_adapter/specific/cloudflare/kv/kv_storage.types.d.ts +0 -22
  38. package/build/types/storage_adapter/specific/memory/memory_storage.d.ts +0 -28
  39. package/build/types/storage_adapter/storage_adapter.types.d.ts +0 -21
  40. package/build/types/storage_adapter/typed_storage/createTypedStorage.d.ts +0 -16
  41. package/build/types/typescript/special_typescript_types.d.ts +0 -1
@@ -1,92 +0,0 @@
1
- import * as v from "valibot";
2
- export declare enum ECryptoKeyAlgo {
3
- ed25519 = "ed25519",
4
- x25519 = "x25519"
5
- }
6
- export declare enum ECryptoKeyFormat {
7
- raw_base64 = "raw_base64",
8
- jwk = "jwk"
9
- }
10
- export declare const vSerializedCryptoKeyDataEd25519_Raw: v.SchemaWithPipe<readonly [v.CustomSchema<`ed25519::raw_base64::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
11
- export declare const vSerializedCryptoKeyDataEd25519_Jwk: v.SchemaWithPipe<readonly [v.CustomSchema<`ed25519::jwk::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
12
- export type TSerializedCryptoKeyData_Ed25519_Raw = v.InferInput<typeof vSerializedCryptoKeyDataEd25519_Raw>;
13
- export type TSerializedCryptoKeyData_Ed25519_Raw_Transformed = {
14
- formattedString: `${ECryptoKeyAlgo.ed25519}::${ECryptoKeyFormat.raw_base64}::${string}`;
15
- type: ECryptoKeyAlgo.ed25519;
16
- format: ECryptoKeyFormat.raw_base64;
17
- data: string;
18
- };
19
- export type TSerializedCryptoKeyData_Ed25519_Jwk = v.InferInput<typeof vSerializedCryptoKeyDataEd25519_Jwk>;
20
- export type TSerializedCryptoKeyData_Ed25519_Jwk_Transformed = {
21
- formattedString: `${ECryptoKeyAlgo.ed25519}::${ECryptoKeyFormat.jwk}::${string}`;
22
- type: ECryptoKeyAlgo.ed25519;
23
- format: ECryptoKeyFormat.jwk;
24
- data: JsonWebKey;
25
- };
26
- export declare const vSerializedCryptoKeyDataX25519_Raw: v.SchemaWithPipe<readonly [v.CustomSchema<`x25519::raw_base64::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
27
- export declare const vSerializedCryptoKeyDataX25519_Jwk: v.SchemaWithPipe<readonly [v.CustomSchema<`x25519::jwk::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
28
- export declare const vCryptoKeyPairDataX25519: v.ObjectSchema<{
29
- readonly publicKey: v.SchemaWithPipe<readonly [v.CustomSchema<`x25519::raw_base64::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
30
- readonly privateKey: v.SchemaWithPipe<readonly [v.CustomSchema<`x25519::jwk::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
31
- }, undefined>;
32
- export type TSerializedCryptoKeyPairDataX25519 = v.InferInput<typeof vCryptoKeyPairDataX25519>;
33
- export declare const vCryptoKeyPairDataEd25519: v.ObjectSchema<{
34
- readonly publicKey: v.SchemaWithPipe<readonly [v.CustomSchema<`ed25519::raw_base64::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
35
- readonly privateKey: v.SchemaWithPipe<readonly [v.CustomSchema<`ed25519::jwk::${string}`, v.ErrorMessage<v.CustomIssue> | undefined>]>;
36
- }, undefined>;
37
- export type TSerializedCryptoKeyPairDataEd25519 = v.InferInput<typeof vCryptoKeyPairDataEd25519>;
38
- export type TSerializedCryptoKeyData_X25519_Raw = v.InferInput<typeof vSerializedCryptoKeyDataX25519_Raw>;
39
- export type TSerializedCryptoKeyData_X25519_Raw_Transformed = {
40
- formattedString: `${ECryptoKeyAlgo.x25519}::${ECryptoKeyFormat.raw_base64}::${string}`;
41
- type: ECryptoKeyAlgo.x25519;
42
- format: ECryptoKeyFormat.raw_base64;
43
- data: string;
44
- };
45
- export type TSerializedCryptoKeyData_X25519_Jwk = v.InferInput<typeof vSerializedCryptoKeyDataX25519_Jwk>;
46
- export type TSerializedCryptoKeyData_X25519_Jwk_Transformed = {
47
- formattedString: `${ECryptoKeyAlgo.x25519}::${ECryptoKeyFormat.jwk}::${string}`;
48
- type: ECryptoKeyAlgo.x25519;
49
- format: ECryptoKeyFormat.jwk;
50
- data: JsonWebKey;
51
- };
52
- export declare const vVerifyChallengeWithSignature_Input: v.ObjectSchema<{
53
- readonly challenge: v.StringSchema<undefined>;
54
- readonly signatureBase64: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
55
- }, undefined>;
56
- export declare const vVerifyChallengeWithSignature_WithThrow_Input: v.IntersectSchema<[v.ObjectSchema<{
57
- readonly challenge: v.StringSchema<undefined>;
58
- readonly signatureBase64: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
59
- }, undefined>, v.ObjectSchema<{
60
- readonly throwOnInvalid: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
61
- }, undefined>], undefined>;
62
- export type TVerifyChallengeWithSignature_Input = v.InferInput<typeof vVerifyChallengeWithSignature_Input>;
63
- export type TVerifyChallengeWithSignature_WithThrow_Input = v.InferInput<typeof vVerifyChallengeWithSignature_WithThrow_Input>;
64
- export declare const vEncryptedAesGcmPayload: v.ObjectSchema<{
65
- readonly nonce: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
66
- readonly ciphertext: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
67
- }, undefined>;
68
- export type TEncryptedAesGcmPayload = v.InferInput<typeof vEncryptedAesGcmPayload>;
69
- export type TEncryptedAesGcmPayload_Transformed = v.InferOutput<typeof vEncryptedAesGcmPayload>;
70
- /**
71
- * Raw-bytes counterpart of {@link TEncryptedAesGcmPayload} — keeps `nonce`/`ciphertext` as binary
72
- * instead of base64 strings. For binary channels (e.g. msgpack WebSocket frames) this avoids the
73
- * ~33% base64 inflation the text payload incurs.
74
- */
75
- export type TEncryptedAesGcmBytes = {
76
- nonce: Uint8Array;
77
- ciphertext: Uint8Array;
78
- };
79
- interface ISerializedKeyData<T, P> {
80
- transformed: T;
81
- prefixed: P;
82
- }
83
- export interface ISerializedKeyData_Ed25519_Raw extends ISerializedKeyData<TSerializedCryptoKeyData_Ed25519_Raw_Transformed, TSerializedCryptoKeyData_Ed25519_Raw> {
84
- }
85
- export interface ISerializedKeyData_Ed25519_Jwk extends ISerializedKeyData<TSerializedCryptoKeyData_Ed25519_Jwk_Transformed, TSerializedCryptoKeyData_Ed25519_Jwk> {
86
- }
87
- export interface ISerializedKeyData_X25519_Raw extends ISerializedKeyData<TSerializedCryptoKeyData_X25519_Raw_Transformed, TSerializedCryptoKeyData_X25519_Raw> {
88
- }
89
- export interface ISerializedKeyData_X25519_Jwk extends ISerializedKeyData<TSerializedCryptoKeyData_X25519_Jwk_Transformed, TSerializedCryptoKeyData_X25519_Jwk> {
90
- }
91
- export type TSerializedKeyData = ISerializedKeyData_Ed25519_Raw | ISerializedKeyData_Ed25519_Jwk | ISerializedKeyData_X25519_Raw | ISerializedKeyData_X25519_Jwk;
92
- export {};
@@ -1 +0,0 @@
1
- export declare const generateEd25519KeyPair: () => Promise<CryptoKeyPair>;
@@ -1,35 +0,0 @@
1
- import { type TSerializedCryptoKeyData_Ed25519_Jwk_Transformed, type TSerializedCryptoKeyData_Ed25519_Raw_Transformed } from "../crypto.schema";
2
- export declare const importEd25519Key: {
3
- private: {
4
- fromFormattedString: {
5
- readonly extractable: (input: `ed25519::jwk::${string}`) => Promise<CryptoKey>;
6
- readonly nonExtractable: (input: `ed25519::jwk::${string}`) => Promise<CryptoKey>;
7
- };
8
- fromSerializedObject: {
9
- readonly extractable: (input: TSerializedCryptoKeyData_Ed25519_Jwk_Transformed) => Promise<CryptoKey>;
10
- readonly nonExtractable: (input: TSerializedCryptoKeyData_Ed25519_Jwk_Transformed) => Promise<CryptoKey>;
11
- };
12
- fromJwk: {
13
- readonly extractable: (input: JsonWebKey) => Promise<CryptoKey>;
14
- readonly nonExtractable: (input: JsonWebKey) => Promise<CryptoKey>;
15
- };
16
- };
17
- public: {
18
- fromBase64: {
19
- readonly extractable: (input: string) => Promise<CryptoKey>;
20
- readonly nonExtractable: (input: string) => Promise<CryptoKey>;
21
- };
22
- fromFormattedString: {
23
- readonly extractable: (input: `ed25519::raw_base64::${string}` | `ed25519::jwk::${string}`) => Promise<CryptoKey>;
24
- readonly nonExtractable: (input: `ed25519::raw_base64::${string}` | `ed25519::jwk::${string}`) => Promise<CryptoKey>;
25
- };
26
- fromSerializedObject: {
27
- readonly extractable: (input: TSerializedCryptoKeyData_Ed25519_Raw_Transformed | TSerializedCryptoKeyData_Ed25519_Jwk_Transformed) => Promise<CryptoKey>;
28
- readonly nonExtractable: (input: TSerializedCryptoKeyData_Ed25519_Raw_Transformed | TSerializedCryptoKeyData_Ed25519_Jwk_Transformed) => Promise<CryptoKey>;
29
- };
30
- fromJwk: {
31
- readonly extractable: (input: JsonWebKey) => Promise<CryptoKey>;
32
- readonly nonExtractable: (input: JsonWebKey) => Promise<CryptoKey>;
33
- };
34
- };
35
- };
@@ -1,2 +0,0 @@
1
- import { type ISerializedKeyData_Ed25519_Jwk } from "../crypto.schema";
2
- export declare const serializeEd25519Key_Jwk: (key: CryptoKey) => Promise<ISerializedKeyData_Ed25519_Jwk>;
@@ -1,2 +0,0 @@
1
- import { type ISerializedKeyData_Ed25519_Raw } from "../crypto.schema";
2
- export declare const serializeEd25519Key_Raw: (publicKey: CryptoKey) => Promise<ISerializedKeyData_Ed25519_Raw>;
@@ -1,2 +0,0 @@
1
- export declare const DEFAULT_COMBINED_TEXT_DATA_SEPARATOR = "::";
2
- export declare const signCombinedTextDataWithKeyEd25519: (data: string[], cryptoKey: CryptoKey, separator?: string) => Promise<Uint8Array>;
@@ -1 +0,0 @@
1
- export declare const signTextDataWithKeyEd25519: (data: string, cryptoKey: CryptoKey) => Promise<Uint8Array>;
@@ -1,5 +0,0 @@
1
- export declare const verifyWithKeyEd25519: ({ challenge, signatureBase64, publicKey, }: {
2
- challenge: string;
3
- signatureBase64: string;
4
- publicKey: CryptoKey;
5
- }) => Promise<boolean>;
@@ -1,21 +0,0 @@
1
- export * from "./aes_gcm/createAesGcmKeyFromX25519Keys";
2
- export * from "./aes_gcm/decryptBytesWithAesGcmKey";
3
- export * from "./aes_gcm/decryptTextDataWithAesGcmKey";
4
- export * from "./aes_gcm/encryptBytesWithAesGcmKey";
5
- export * from "./aes_gcm/encryptTextDataWithAesGcmKey";
6
- export * from "./client_key_link/buildVerifyKeyBoundInfoString";
7
- export * from "./client_key_link/ClientCryptoKeyLink";
8
- export * from "./crypto.converters";
9
- export * from "./crypto.schema";
10
- export * from "./ed25519/generateEd25519KeyPair";
11
- export * from "./ed25519/importEd25519Key";
12
- export * from "./ed25519/serializeEd25519Key_Jwk";
13
- export * from "./ed25519/serializeEd25519Key_Raw";
14
- export * from "./ed25519/signCombinedTextDataWithKeyEd25519";
15
- export * from "./ed25519/signTextDataWithKeyEd25519";
16
- export * from "./ed25519/verifyWithKeyEd25519";
17
- export * from "./x25519/createSharedBitsFromX25519";
18
- export * from "./x25519/generateX25519KeyPair";
19
- export * from "./x25519/importX25519Key";
20
- export * from "./x25519/serializeX25519Key_Jwk";
21
- export * from "./x25519/serializeX25519Key_Raw";
@@ -1,4 +0,0 @@
1
- export declare const createSharedBitsFromX25519: ({ privateKey, publicKey, }: {
2
- privateKey: CryptoKey;
3
- publicKey: CryptoKey;
4
- }) => Promise<Uint8Array>;
@@ -1 +0,0 @@
1
- export declare const generateX25519KeyPair: () => Promise<CryptoKeyPair>;
@@ -1,35 +0,0 @@
1
- import { type TSerializedCryptoKeyData_X25519_Jwk_Transformed, type TSerializedCryptoKeyData_X25519_Raw_Transformed } from "../crypto.schema";
2
- export declare const importX25519Key: {
3
- private: {
4
- fromFormattedString: {
5
- readonly extractable: (input: `x25519::jwk::${string}`) => Promise<CryptoKey>;
6
- readonly nonExtractable: (input: `x25519::jwk::${string}`) => Promise<CryptoKey>;
7
- };
8
- fromSerializedObject: {
9
- readonly extractable: (input: TSerializedCryptoKeyData_X25519_Jwk_Transformed) => Promise<CryptoKey>;
10
- readonly nonExtractable: (input: TSerializedCryptoKeyData_X25519_Jwk_Transformed) => Promise<CryptoKey>;
11
- };
12
- fromJwk: {
13
- readonly extractable: (input: JsonWebKey) => Promise<CryptoKey>;
14
- readonly nonExtractable: (input: JsonWebKey) => Promise<CryptoKey>;
15
- };
16
- };
17
- public: {
18
- fromBase64: {
19
- readonly extractable: (input: string) => Promise<CryptoKey>;
20
- readonly nonExtractable: (input: string) => Promise<CryptoKey>;
21
- };
22
- fromFormattedString: {
23
- readonly extractable: (input: `x25519::raw_base64::${string}` | `x25519::jwk::${string}`) => Promise<CryptoKey>;
24
- readonly nonExtractable: (input: `x25519::raw_base64::${string}` | `x25519::jwk::${string}`) => Promise<CryptoKey>;
25
- };
26
- fromSerializedObject: {
27
- readonly extractable: (input: TSerializedCryptoKeyData_X25519_Raw_Transformed | TSerializedCryptoKeyData_X25519_Jwk_Transformed) => Promise<CryptoKey>;
28
- readonly nonExtractable: (input: TSerializedCryptoKeyData_X25519_Raw_Transformed | TSerializedCryptoKeyData_X25519_Jwk_Transformed) => Promise<CryptoKey>;
29
- };
30
- fromJwk: {
31
- readonly extractable: (input: JsonWebKey) => Promise<CryptoKey>;
32
- readonly nonExtractable: (input: JsonWebKey) => Promise<CryptoKey>;
33
- };
34
- };
35
- };
@@ -1,2 +0,0 @@
1
- import { type ISerializedKeyData_X25519_Jwk } from "../crypto.schema";
2
- export declare const serializeX25519Key_Jwk: (key: CryptoKey) => Promise<ISerializedKeyData_X25519_Jwk>;
@@ -1,2 +0,0 @@
1
- import { type ISerializedKeyData_X25519_Raw } from "../crypto.schema";
2
- export declare const serializeX25519Key_Raw: (key: CryptoKey) => Promise<ISerializedKeyData_X25519_Raw>;
@@ -1 +0,0 @@
1
- export * from "./string/nullEmpty";
@@ -1,3 +0,0 @@
1
- export declare const notNullEmpty: (str: string | null | undefined) => str is string;
2
- export declare const nullEmpty: (str: string | null | undefined) => str is null | undefined | "";
3
- export declare const firstNotNullEmpty: (...strItems: (string | null | undefined)[]) => string | undefined;
@@ -1,10 +0,0 @@
1
- export type { TTypeAndId } from "./core/core_valibot_schemas";
2
- export * from "./crypto";
3
- export * from "./storage_adapter/StorageAdapter";
4
- export * from "./storage_adapter/specific/browser/browser_storage";
5
- export * from "./storage_adapter/specific/cloudflare/durable_object/durable_object_storage";
6
- export * from "./storage_adapter/specific/cloudflare/kv/kv_storage";
7
- export * from "./storage_adapter/specific/memory/memory_storage";
8
- export * from "./storage_adapter/storage_adapter.types";
9
- export * from "./storage_adapter/typed_storage/createTypedStorage";
10
- export * from "./typescript/special_typescript_types";
@@ -1,23 +0,0 @@
1
- import { type IStorageKeyGetterAndSetter, type TStorageAdapterMethods } from "./storage_adapter.types";
2
- export interface IStorageAdapterConstructor {
3
- methods: TStorageAdapterMethods;
4
- trackKeysForClearing?: boolean;
5
- keyPrefix?: string;
6
- }
7
- export declare class StorageAdapter {
8
- private implementation;
9
- readonly keyPrefix: string;
10
- private readonly adapterStorage?;
11
- constructor({ methods, keyPrefix, trackKeysForClearing: trackKeys }: IStorageAdapterConstructor);
12
- private getPrefixedKey;
13
- private trackUsedKey;
14
- private untrackUsedKey;
15
- clearAll(): Promise<void>;
16
- removeItem(rawKey: string): Promise<void>;
17
- setJson(rawKey: string, value: any): Promise<void>;
18
- getJson<T>(rawKey: string): Promise<T | undefined>;
19
- getJsonOrDef<T>(rawKey: string, defVal: T): Promise<T>;
20
- updateJson<T>(rawKey: string, updater: (currentVal: T | undefined) => T): Promise<T>;
21
- updateJsonOrDef<T>(rawKey: string, defVal: T, updater: (currentVal: T) => T): Promise<T>;
22
- createJsonGetterSetter<T>(rawKey: string): IStorageKeyGetterAndSetter<T>;
23
- }
@@ -1,26 +0,0 @@
1
- import { type IStorageAdapterConstructor, StorageAdapter } from "../../StorageAdapter";
2
- import { type IStorageAdapterMethods_String } from "../../storage_adapter.types";
3
- import { type ITypedStorage } from "../../typed_storage/createTypedStorage";
4
- /**
5
- *
6
- * Web Storage [LOCAL STORAGE]
7
- *
8
- */
9
- type TCreateWebLocalStorageOptions = Omit<IStorageAdapterConstructor, "methods"> & {
10
- localStorage: typeof localStorage;
11
- };
12
- export declare function createWebLocalStorageMethods(_localStorage: typeof localStorage): IStorageAdapterMethods_String;
13
- export declare const createWebLocalStorageAdapter: ({ localStorage: _localStorage, ...options }: TCreateWebLocalStorageOptions) => StorageAdapter;
14
- export declare function createTypedWebLocalStorage<T extends Record<string, any>>(options: TCreateWebLocalStorageOptions): ITypedStorage<T>;
15
- /**
16
- *
17
- * Web Storage [SESSION STORAGE]
18
- *
19
- */
20
- type TCreateWebSessionStorageOptions = Omit<IStorageAdapterConstructor, "methods"> & {
21
- sessionStorage: typeof sessionStorage;
22
- };
23
- export declare function createWebSessionStorageMethods(_sessionStorage: typeof sessionStorage): IStorageAdapterMethods_String;
24
- export declare const createWebSessionStorageAdapter: ({ sessionStorage: _sessionStorage, ...options }: TCreateWebSessionStorageOptions) => StorageAdapter;
25
- export declare function createTypedWebSessionStorage<T extends Record<string, any>>(options: TCreateWebSessionStorageOptions): ITypedStorage<T>;
26
- export {};
@@ -1,14 +0,0 @@
1
- import { type IStorageAdapterConstructor, StorageAdapter } from "../../../StorageAdapter";
2
- import { type IStorageAdapterMethods_Json } from "../../../storage_adapter.types";
3
- import { type ITypedStorage } from "../../../typed_storage/createTypedStorage";
4
- import type { IDurableObjectStorage } from "./durable_object_storage.types";
5
- export declare function createDurableObjectStorageMethods(durableObjectStorage: IDurableObjectStorage): IStorageAdapterMethods_Json;
6
- export type TCreateDurableObjectStorageOptions = Omit<IStorageAdapterConstructor, "methods"> & {
7
- durableObjectStorage: IDurableObjectStorage;
8
- };
9
- /**
10
- * Wraps a Durable Object's storage in the generic StorageAdapter interface, e.g. for handing to a
11
- * ClientCryptoKeyLink so it can persist its keys inside the DO's own storage.
12
- */
13
- export declare const createDurableObjectStorageAdapter: ({ durableObjectStorage, ...options }: TCreateDurableObjectStorageOptions) => StorageAdapter;
14
- export declare function createDurableObjectTypedStorage<T extends Record<string, any>>(options: TCreateDurableObjectStorageOptions): ITypedStorage<T>;
@@ -1,18 +0,0 @@
1
- interface DurableObjectGetOptions {
2
- allowConcurrency?: boolean;
3
- noCache?: boolean;
4
- }
5
- interface DurableObjectPutOptions {
6
- allowConcurrency?: boolean;
7
- allowUnconfirmed?: boolean;
8
- noCache?: boolean;
9
- }
10
- export interface IDurableObjectStorage {
11
- get<T = unknown>(key: string, options?: DurableObjectGetOptions): Promise<T | undefined>;
12
- get<T = unknown>(keys: string[], options?: DurableObjectGetOptions): Promise<Map<string, T>>;
13
- put<T>(key: string, value: T, options?: DurableObjectPutOptions): Promise<void>;
14
- put<T>(entries: Record<string, T>, options?: DurableObjectPutOptions): Promise<void>;
15
- delete(key: string, options?: DurableObjectPutOptions): Promise<boolean>;
16
- delete(keys: string[], options?: DurableObjectPutOptions): Promise<number>;
17
- }
18
- export {};
@@ -1,18 +0,0 @@
1
- import { type IStorageAdapterConstructor, StorageAdapter } from "../../../StorageAdapter";
2
- import { type IStorageAdapterMethods_String } from "../../../storage_adapter.types";
3
- import { type ITypedStorage } from "../../../typed_storage/createTypedStorage";
4
- import type { IKVNamespace, IKVNamespacePutOptions } from "./kv_storage.types";
5
- export interface ICreateKVStorageMethodsOptions {
6
- /** The `KVNamespace` binding, e.g. accessed off `env.MY_KV` inside a worker. */
7
- kvNamespace: IKVNamespace;
8
- /** Default options applied to every `put`, e.g. `{ expirationTtl }` for TTL-based eviction. */
9
- defaultPutOptions?: IKVNamespacePutOptions;
10
- }
11
- export declare function createKVStorageMethods({ kvNamespace, defaultPutOptions, }: ICreateKVStorageMethodsOptions): IStorageAdapterMethods_String;
12
- export type TCreateKVStorageOptions = Omit<IStorageAdapterConstructor, "methods"> & ICreateKVStorageMethodsOptions;
13
- /**
14
- * Wraps a Cloudflare KV namespace binding in the generic StorageAdapter interface, e.g. for handing
15
- * to a ClientCryptoKeyLink so it can persist its keys inside KV.
16
- */
17
- export declare const createKVStorageAdapter: ({ kvNamespace, defaultPutOptions, ...options }: TCreateKVStorageOptions) => StorageAdapter;
18
- export declare function createKVTypedStorage<T extends Record<string, any>>(options: TCreateKVStorageOptions): ITypedStorage<T>;
@@ -1,22 +0,0 @@
1
- interface IKVNamespaceGetOptions {
2
- cacheTtl?: number;
3
- }
4
- interface IKVNamespacePutOptions {
5
- /** Absolute time (seconds since epoch) at which the key should expire. */
6
- expiration?: number;
7
- /** Relative TTL (in seconds) from now, after which the key should expire. */
8
- expirationTtl?: number;
9
- metadata?: unknown;
10
- }
11
- /**
12
- * Minimal subset of Cloudflare's `KVNamespace` binding that our storage adapter relies on. Values
13
- * are always written/read as strings (KV's `put` only accepts string/stream/buffer values), so the
14
- * adapter is a {@link EStorageAdapterType.string} adapter and JSON (de)serialization happens in the
15
- * generic `StorageAdapter`.
16
- */
17
- export interface IKVNamespace {
18
- get(key: string, options?: IKVNamespaceGetOptions): Promise<string | null>;
19
- put(key: string, value: string, options?: IKVNamespacePutOptions): Promise<void>;
20
- delete(key: string): Promise<void>;
21
- }
22
- export type { IKVNamespaceGetOptions, IKVNamespacePutOptions };
@@ -1,28 +0,0 @@
1
- import { type IStorageAdapterConstructor, StorageAdapter } from "../../StorageAdapter";
2
- import { type IStorageAdapterMethods_Json, type IStorageAdapterMethods_String } from "../../storage_adapter.types";
3
- import { type ITypedStorage } from "../../typed_storage/createTypedStorage";
4
- export type TMemoryStorage_string = Map<string, string>;
5
- export type TMemoryStorage_json = Map<string, any>;
6
- /**
7
- *
8
- * Memory Storage [STRING]
9
- *
10
- */
11
- type TCreateMemoryStorageOptions_string = Omit<IStorageAdapterConstructor, "methods"> & {
12
- memoryStorageMap?: TMemoryStorage_string;
13
- };
14
- export declare function createMemoryStorageMethods_string(memoryStorageMap?: TMemoryStorage_string): IStorageAdapterMethods_String;
15
- export declare const createMemoryStorageAdapter_string: (options?: TCreateMemoryStorageOptions_string) => StorageAdapter;
16
- export declare function createTypedMemoryStorage_string<T extends Record<string, any>>(options?: TCreateMemoryStorageOptions_string): ITypedStorage<T>;
17
- /**
18
- *
19
- * Memory Storage [JSON]
20
- *
21
- */
22
- type TCreateMemoryStorageOptions_json = Omit<IStorageAdapterConstructor, "methods"> & {
23
- memoryStorageMap?: TMemoryStorage_json;
24
- };
25
- export declare function createMemoryStorageMethods_json(memoryStorageMap?: TMemoryStorage_json): IStorageAdapterMethods_Json;
26
- export declare const createMemoryStorageAdapter_json: (options?: TCreateMemoryStorageOptions_json) => StorageAdapter;
27
- export declare function createTypedMemoryStorage_json<T extends Record<string, any>>(options?: TCreateMemoryStorageOptions_json): ITypedStorage<T>;
28
- export {};
@@ -1,21 +0,0 @@
1
- export declare enum EStorageAdapterType {
2
- string = "string",
3
- json = "json"
4
- }
5
- export interface IStorageAdapterMethods_String {
6
- type: EStorageAdapterType.string;
7
- setItem: (key: string, value: string) => Promise<void>;
8
- getItem: (key: string) => Promise<string | null | undefined>;
9
- removeItem: (key: string) => Promise<void>;
10
- }
11
- export interface IStorageAdapterMethods_Json {
12
- type: EStorageAdapterType.json;
13
- setItem: <T>(key: string, value: T) => Promise<void>;
14
- getItem: <T>(key: string) => Promise<T | null | undefined>;
15
- removeItem: (key: string) => Promise<void>;
16
- }
17
- export type TStorageAdapterMethods = IStorageAdapterMethods_String | IStorageAdapterMethods_Json;
18
- export interface IStorageKeyGetterAndSetter<T> {
19
- get: () => Promise<T | undefined>;
20
- set: (value: T) => Promise<void>;
21
- }
@@ -1,16 +0,0 @@
1
- import type { StringKeys } from "../../typescript/special_typescript_types";
2
- import type { StorageAdapter } from "../StorageAdapter";
3
- export interface ITypedStorage<T extends Record<string, any>> {
4
- getJson<K extends StringKeys<T>>(key: K): Promise<T[K] | undefined>;
5
- getJsonOrDef<K extends StringKeys<T>>(key: K, defVal: T[K]): Promise<T[K]>;
6
- setJson<K extends StringKeys<T>>(key: K, val: T[K]): Promise<void>;
7
- removeItem<K extends StringKeys<T>>(key: K): Promise<void>;
8
- updateJson<K extends StringKeys<T>>(key: K, updater: (currentVal: T[K] | undefined) => T[K]): Promise<void>;
9
- updateJsonWithDef<K extends StringKeys<T>>(key: K, defaultVal: T[K], updater: (currentVal: T[K]) => T[K]): Promise<void>;
10
- clearAll(): Promise<void>;
11
- }
12
- interface ITypedStorage_Create_Input {
13
- storageAdapter: StorageAdapter;
14
- }
15
- export declare function createTypedStorage<T extends Record<string, any>>({ storageAdapter, }: ITypedStorage_Create_Input): ITypedStorage<T>;
16
- export {};
@@ -1 +0,0 @@
1
- export type StringKeys<T> = keyof T & string;