Skip to content

Commit

Permalink
Merge pull request #26 from nfhipona/release/4.1.0
Browse files Browse the repository at this point in the history
Generate typescript *.d.ts files
  • Loading branch information
nfhipona committed Sep 27, 2023
2 parents c8d4522 + 0d24068 commit 9a9eef8
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 7 deletions.
11 changes: 11 additions & 0 deletions lib/class/cryptor.d.ts
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;
}
12 changes: 12 additions & 0 deletions lib/class/encoded-storage.d.ts
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;
}
15 changes: 15 additions & 0 deletions lib/class/encrypted-storage.d.ts
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;
}
143 changes: 143 additions & 0 deletions lib/class/interface.d.ts
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;
}
23 changes: 23 additions & 0 deletions lib/class/storage.d.ts
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;
}
4 changes: 4 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Options {
delimiter?: string;
isEncoded: boolean;
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"name": "web-storage-manager",
"version": "4.0.4",
"version": "4.1.0",
"description": "Web utility storage manager for handling data encryption, save and persist, update and data purge in your local and session storage",
"main": "lib/index.js",
"type": "commonjs",
"types": "lib/index.d.ts",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "jest",
"test:build": "rm -rf lib && npm run build:js && jest",
"test:silent-build": "rm -rf lib && npm run build:js && jest --verbose false",
"build": "rm -rf lib && npm run build:js",
"test:build": "rm -rf lib && npm run build && jest",
"test:silent-build": "rm -rf lib && npm run build && jest --verbose false",
"build": "rm -rf lib && npm run build:js && npm run build:types",
"build:types": "tsc --emitDeclarationOnly",
"build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline",
"publish": "npm run build && npm publish"
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"noEmit": true,
"noEmit": false,
"allowJs": true,
"alwaysStrict": true,
"module": "ESNext",
Expand Down

0 comments on commit 9a9eef8

Please sign in to comment.