-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from nfhipona/release/4.1.0
Generate typescript *.d.ts files
- Loading branch information
Showing
9 changed files
with
216 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CryptorOption, KeyOption, ReturnOption, CryptorModel, VectorIV } from './interface'; | ||
export declare const CryptorDefaults: CryptorOption; | ||
export declare class Cryptor implements CryptorModel { | ||
#private; | ||
constructor(options?: CryptorOption, ivHex?: VectorIV); | ||
get settings(): CryptorOption; | ||
get key(): KeyOption; | ||
get ivHex(): KeyOption; | ||
encrypt(subject: string): ReturnOption; | ||
decrypt(encrypted: string): ReturnOption; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { KeyPath, StorageValue, Storage } from './interface'; | ||
import { WebStore } from "./storage"; | ||
export declare class EncodedWebStore extends WebStore { | ||
#private; | ||
/** | ||
* | ||
* @param storage Storage interface to be used and initialized. | ||
*/ | ||
constructor(storage: Storage, delimiter?: string); | ||
getItem(key: KeyPath): StorageValue; | ||
setItem(key: KeyPath, value: StorageValue): boolean | Error; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { KeyPath, StorageValue, Storage, EncryptedWebStorage } from './interface'; | ||
import { WebStore } from "./storage"; | ||
import { Cryptor } from "./cryptor"; | ||
export declare class EncryptedWebStore extends WebStore implements EncryptedWebStorage { | ||
#private; | ||
/** | ||
* | ||
* @param storage Storage interface to be used and initialized. | ||
*/ | ||
constructor(storage: Storage, cryptor: Cryptor, delimiter?: string); | ||
getItem(key: KeyPath): StorageValue; | ||
setItem(key: KeyPath, value: StorageValue): boolean | Error; | ||
getEncryptedRawItem(key: string): any; | ||
setEncryptedRawItem(key: string, value: any): boolean | Error; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/// <reference types="node" /> | ||
export type KeyPath = string; | ||
export type StorageValue = any; | ||
export type StorageItem = { | ||
key: KeyPath; | ||
value: StorageValue; | ||
}; | ||
/** | ||
* Attribute compare will work for a collection of items where values match or will replace a value of the matched key for data objects. | ||
*/ | ||
export type AttributeCompare = { | ||
name: string; | ||
value: string | number; | ||
}; | ||
export interface Storage { | ||
/** | ||
* keypath delimeter. defaults to '.'. | ||
*/ | ||
delimiter: string; | ||
/** | ||
* Returns an integer representing the number of data items stored in the Storage object. | ||
*/ | ||
get length(): number; | ||
/** | ||
* Returns an integer representing the number of data items stored in the Storage object. | ||
* @param n When passed a number n, this method will return the name of the nth key in the storage. | ||
*/ | ||
key(n: number): number; | ||
/** | ||
* When passed a key name, will return that key's value. | ||
* @param {KeyPath} key key name. | ||
*/ | ||
getItem(key: KeyPath): StorageValue; | ||
/** | ||
* When passed a key name and value, will add that key to the storage, or update that key's value if it already exists. | ||
* @param {KeyPath} key A string containing the name of the key you want to create/update. | ||
* @param {StorageValue} value A string containing the value you want to give the key you are creating/updating. | ||
*/ | ||
setItem(key: KeyPath, value: StorageValue): boolean | Error; | ||
/** | ||
* When passed a key name, will remove that key from the storage. | ||
* @param {KeyPath} key A string containing the name of the key you want to remove. | ||
*/ | ||
removeItem(key: KeyPath): void; | ||
/** | ||
* When invoked, will empty all keys out of the storage. | ||
*/ | ||
clear(): void; | ||
} | ||
export interface WebStorage extends Storage { | ||
/** | ||
* Add multiple entries of key value pairs to the storage. | ||
* @param {StorageItem[]} items Items to add individually in the storage. | ||
*/ | ||
setMultipleItems(items: StorageItem[]): boolean | Error; | ||
/** | ||
* Remove multiple entries found in the specified keypaths. | ||
* Will only work on top level keypaths and will not utilize an `AttributeCompare`. | ||
* Use `removeItemInItem` to utilize an `AttributeCompare`. | ||
* @param {KeyPath[]} keys | ||
*/ | ||
removeMultipleItems(keys: KeyPath[]): void; | ||
/** | ||
* Returns multiple entries found in the specified keypaths. | ||
* Will only work on top level keypaths and will not utilize an `AttributeCompare`. | ||
* Use `getItemInItem` to utilize an `AttributeCompare`. | ||
* @param {KeyPath[]} keys | ||
*/ | ||
getMultipleItems(keys: KeyPath[]): StorageValue[]; | ||
/** | ||
* Append item to an existing item on the storage. Works for object and array type data. | ||
* @param {KeyPath} key keypath of the data you want to append to. | ||
* @param {StorageValue} value data value you want to append to. | ||
*/ | ||
appendItemInItem(key: KeyPath, value: StorageValue): boolean | Error; | ||
/** | ||
* Updates an item in the specified keypath. | ||
* @param {KeyPath} key keypath of the data. | ||
* @param {AttributeCompare} attrCompare data key attribute to be updated. | ||
*/ | ||
updateItemInItem(key: KeyPath, attrCompare: AttributeCompare | null, newValue: StorageValue): boolean | Error; | ||
/** | ||
* Removes an item in the specified keypath. | ||
* @param {KeyPath} key keypath of the data. | ||
* @param {AttributeCompare} attrCompare data key attribute to be updated. | ||
*/ | ||
removeItemInItem(key: KeyPath, attrCompare?: AttributeCompare): boolean | Error; | ||
/** | ||
* Returns data found in the specified keypath. | ||
* @param {KeyPath} key keypath of the data. | ||
* @param {AttributeCompare} attrCompare data key attribute to be updated. | ||
*/ | ||
getItemInItem(key: KeyPath, attrCompare?: AttributeCompare): StorageValue; | ||
} | ||
export interface EncryptedWebStorage extends Storage { | ||
/** | ||
* When passed a key name, will return that key's value. | ||
* @param {KeyPath} key key name. | ||
*/ | ||
getEncryptedRawItem(key: KeyPath): StorageValue; | ||
/** | ||
* When passed a key name and value, will add that key to the storage, or update that key's value if it already exists. | ||
* @param {KeyPath} key A string containing the name of the key you want to create/update. | ||
* @param {StorageValue} value A string containing the value you want to give the key you are creating/updating. | ||
*/ | ||
setEncryptedRawItem(key: KeyPath, value: StorageValue): boolean | Error; | ||
} | ||
/** | ||
* Cryptor interface | ||
*/ | ||
export interface CryptorOption { | ||
salt: string | Buffer; | ||
keyLength: number; | ||
algorithm: string; | ||
password: string | Buffer; | ||
byteLength: number; | ||
} | ||
export type KeyOption = string | null; | ||
export type ReturnOption = string | null; | ||
export type VectorIV = string | null; | ||
export interface CryptorModel { | ||
/** | ||
* Returns the cryptor's configs | ||
*/ | ||
get settings(): CryptorOption; | ||
/** | ||
* Returns the cryptor's generated encryption key | ||
*/ | ||
get key(): KeyOption; | ||
/** | ||
* Returns the cryptor's initialization vector. | ||
* NOTE: This is important for decryption. Make sure you store it somewhere for reuse. | ||
*/ | ||
get ivHex(): KeyOption; | ||
/** | ||
* Encrypt the data and save to storage. | ||
*/ | ||
encrypt(subject: string): ReturnOption; | ||
/** | ||
* Returns the decrypted data from storage. | ||
*/ | ||
decrypt(encrypted: string): ReturnOption; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { AttributeCompare, KeyPath, Storage, StorageItem, StorageValue, WebStorage } from './interface'; | ||
export declare class WebStore implements WebStorage { | ||
#private; | ||
delimiter: string; | ||
/** | ||
* | ||
* @param storage Storage interface to be used and initialized. | ||
*/ | ||
constructor(storage: Storage, delimiter?: string); | ||
get length(): number; | ||
key(n: number): number; | ||
getItem(key: KeyPath): StorageValue; | ||
setItem(key: KeyPath, value: StorageValue): boolean | Error; | ||
removeItem(key: KeyPath): void; | ||
clear(): void; | ||
setMultipleItems(items: StorageItem[]): boolean | Error; | ||
removeMultipleItems(keys: KeyPath[]): void; | ||
getMultipleItems(keys: KeyPath[]): StorageValue[]; | ||
appendItemInItem(key: KeyPath, value: any): boolean | Error; | ||
updateItemInItem(key: KeyPath, attrCompare: AttributeCompare | null, newValue: StorageValue): boolean | Error; | ||
removeItemInItem(key: KeyPath, attrCompare?: AttributeCompare): boolean | Error; | ||
getItemInItem(key: KeyPath, attrCompare?: AttributeCompare): StorageValue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface Options { | ||
delimiter?: string; | ||
isEncoded: boolean; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters