diff --git a/redux-persist-transform-compress/index.d.ts b/redux-persist-transform-compress/index.d.ts new file mode 100644 index 0000000000..2f8fb7f366 --- /dev/null +++ b/redux-persist-transform-compress/index.d.ts @@ -0,0 +1,9 @@ +// Type definitions for redux-persist-transform-compress 4.1 +// Project: https://github.com/rt2zz/redux-persist-transform-compress +// Definitions by: Karol Janyst +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { PersistConfig, PersistTransformer } from "redux-persist"; + +export = createCompressor; +declare function createCompressor (config?: PersistConfig): PersistTransformer; diff --git a/redux-persist-transform-compress/package.json b/redux-persist-transform-compress/package.json new file mode 100644 index 0000000000..36ce503807 --- /dev/null +++ b/redux-persist-transform-compress/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "redux": "^3.6.0" + } +} diff --git a/redux-persist-transform-compress/redux-persist-transform-compress-tests.ts b/redux-persist-transform-compress/redux-persist-transform-compress-tests.ts new file mode 100644 index 0000000000..b445171cb9 --- /dev/null +++ b/redux-persist-transform-compress/redux-persist-transform-compress-tests.ts @@ -0,0 +1,11 @@ +import { createStore, Reducer, Store } from "redux" +import { createPersistor, Persistor, PersistTransformer } from "redux-persist" +import createCompressor = require("redux-persist-transform-compress") + +const reducer: Reducer = (state: any, action: any) => ({}) + +const compressor: PersistTransformer = createCompressor({ whitelist : ["foo"] }) + +const store: Store = createStore(reducer) + +const persistor: Persistor = createPersistor(store, { transforms : [compressor] }) diff --git a/redux-persist-transform-compress/tsconfig.json b/redux-persist-transform-compress/tsconfig.json new file mode 100644 index 0000000000..d2d6a9f248 --- /dev/null +++ b/redux-persist-transform-compress/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "redux-persist-transform-compress-tests.ts" + ] +} diff --git a/redux-persist-transform-encrypt/index.d.ts b/redux-persist-transform-encrypt/index.d.ts new file mode 100644 index 0000000000..048f02221f --- /dev/null +++ b/redux-persist-transform-encrypt/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for redux-persist-transform-encrypt 0.1 +// Project: https://github.com/maxdeviant/redux-persist-transform-encrypt#readme +// Definitions by: Karol Janyst +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { PersistTransformer } from "redux-persist"; + +export as namespace ReduxPersistEncryptor; + +export = createEncryptor; + +declare function createEncryptor (config: createEncryptor.EncryptorConfig): PersistTransformer; + +declare namespace createEncryptor { + export interface EncryptorConfig { + secretKey: string; + } +} diff --git a/redux-persist-transform-encrypt/package.json b/redux-persist-transform-encrypt/package.json new file mode 100644 index 0000000000..36ce503807 --- /dev/null +++ b/redux-persist-transform-encrypt/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "redux": "^3.6.0" + } +} diff --git a/redux-persist-transform-encrypt/redux-persist-transform-encrypt-tests.ts b/redux-persist-transform-encrypt/redux-persist-transform-encrypt-tests.ts new file mode 100644 index 0000000000..b3a70dc776 --- /dev/null +++ b/redux-persist-transform-encrypt/redux-persist-transform-encrypt-tests.ts @@ -0,0 +1,13 @@ +import { createStore, Reducer, Store } from "redux" +import { createPersistor, Persistor, PersistTransformer } from "redux-persist" +import { EncryptorConfig } from "redux-persist-transform-encrypt" +import * as createEncryptor from "redux-persist-transform-encrypt" + +const reducer: Reducer = (state: any, action: any) => ({}) + +const config: EncryptorConfig = { secretKey : "foo" } +const encryptor: PersistTransformer = createEncryptor(config) + +const store: Store = createStore(reducer) + +const persistor: Persistor = createPersistor(store, { transforms : [encryptor] }) diff --git a/redux-persist-transform-encrypt/tsconfig.json b/redux-persist-transform-encrypt/tsconfig.json new file mode 100644 index 0000000000..bd7d84ac1d --- /dev/null +++ b/redux-persist-transform-encrypt/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "redux-persist-transform-encrypt-tests.ts" + ] +} diff --git a/redux-persist-transform-filter/index.d.ts b/redux-persist-transform-filter/index.d.ts new file mode 100644 index 0000000000..19e7779bbd --- /dev/null +++ b/redux-persist-transform-filter/index.d.ts @@ -0,0 +1,8 @@ +// Type definitions for redux-persist-transform-filter 0.0 +// Project: https://github.com/edy/redux-persist-transform-filter +// Definitions by: Karol Janyst +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { PersistTransformer } from "redux-persist"; + +export default function createFilter (reducerName: string, inboundPaths?: string[], outboundPaths?: string[]): PersistTransformer; diff --git a/redux-persist-transform-filter/package.json b/redux-persist-transform-filter/package.json new file mode 100644 index 0000000000..36ce503807 --- /dev/null +++ b/redux-persist-transform-filter/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "redux": "^3.6.0" + } +} diff --git a/redux-persist-transform-filter/redux-persist-transform-filter-tests.ts b/redux-persist-transform-filter/redux-persist-transform-filter-tests.ts new file mode 100644 index 0000000000..a19f7610e4 --- /dev/null +++ b/redux-persist-transform-filter/redux-persist-transform-filter-tests.ts @@ -0,0 +1,15 @@ +import { createStore, Reducer, Store } from "redux" +import { createPersistor, Persistor, PersistTransformer } from "redux-persist" +import createFilter from "redux-persist-transform-filter" + +const reducer: Reducer = (state: any, action: any) => ({}) + +const filter: PersistTransformer = createFilter( + "foo", + ["foo.bar"], + ["fizz.buzz"] +) + +const store: Store = createStore(reducer) + +const persistor: Persistor = createPersistor(store, { transforms : [filter] }) diff --git a/redux-persist-transform-filter/tsconfig.json b/redux-persist-transform-filter/tsconfig.json new file mode 100644 index 0000000000..9743fa6b7d --- /dev/null +++ b/redux-persist-transform-filter/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "redux-persist-transform-filter-tests.ts" + ] +} diff --git a/redux-persist/constants.d.ts b/redux-persist/constants.d.ts new file mode 100644 index 0000000000..93d3249dda --- /dev/null +++ b/redux-persist/constants.d.ts @@ -0,0 +1,2 @@ +export const KEY_PREFIX: string; +export const REHYDRATE: string; diff --git a/redux-persist/index.d.ts b/redux-persist/index.d.ts new file mode 100644 index 0000000000..c8d099d5e6 --- /dev/null +++ b/redux-persist/index.d.ts @@ -0,0 +1,66 @@ +// Type definitions for redux-persist 4.0 +// Project: https://github.com/rt2zz/redux-persist +// Definitions by: Karol Janyst +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Action, GenericStoreEnhancer, Store } from "redux"; + +export interface PersistAction extends Action { + payload?: S; + error?: any; +} + +export interface PersistorRehydrateOptions { + serial?: boolean; +} + +export interface Persistor { + purge(keys?: string[]): void; + rehydrate(incoming: A, options?: PersistorRehydrateOptions): A; + pause(): void; + resume(): void; +} + +export type PersistCallback = (err: any, response?: A) => void; + +export interface PersistTransformer { + in(state: any, key: string): any; + out(state: any, key: string): any; +} + +export interface PersistStorage { + setItem(key: string, value: any, callback?: PersistCallback): Promise; + getItem(key: string, callback?: PersistCallback): Promise; + removeItem(key: string, callback?: PersistCallback): Promise; + getAllKeys(callback?: PersistCallback): Promise; + [key: string]: any; +} + +export type PersistStateReconciler = (state: A, inboundState: B, reducedState: C, log?: boolean) => C; + +export interface PersistAutoRehydrateConfig { + stateReconcile?: PersistStateReconciler; +} + +export interface PersistConfig { + whitelist?: string[]; + blacklist?: string[]; + transforms?: PersistTransformer[]; + storage?: PersistStorage; + debounce?: number; + keyPrefix?: string; + serialize?: (data: any) => string; + deserialize?: (data: string) => any; +} + +export function autoRehydrate (config?: PersistAutoRehydrateConfig): GenericStoreEnhancer; + +export function createPersistor (store: Store, config?: PersistConfig): Persistor; + +export function createTransform (inbound: any, outbound: any, config?: PersistConfig): PersistTransformer; + +export function getStoredState(config?: PersistConfig, callback?: PersistCallback): Promise; + +export function persistStore (store: Store, config?: PersistConfig, callback?: PersistCallback): Persistor; + +export function purgeStoredState (config?: PersistConfig, keys?: string[]): Promise; diff --git a/redux-persist/package.json b/redux-persist/package.json new file mode 100644 index 0000000000..36ce503807 --- /dev/null +++ b/redux-persist/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "redux": "^3.6.0" + } +} diff --git a/redux-persist/redux-persist-tests.ts b/redux-persist/redux-persist-tests.ts new file mode 100644 index 0000000000..59885a292a --- /dev/null +++ b/redux-persist/redux-persist-tests.ts @@ -0,0 +1,53 @@ +import { createStore, Store, Reducer } from "redux" +import { + autoRehydrate, + createPersistor, + createTransform, + getStoredState, + persistStore, + purgeStoredState, + PersistConfig, + PersistAutoRehydrateConfig, + PersistCallback, + Persistor, + PersistorRehydrateOptions, + PersistTransformer +} from "redux-persist" +import { KEY_PREFIX, REHYDRATE } from "redux-persist/constants" +import { asyncLocalStorage, asyncSessionStorage } from "redux-persist/storages" + +const reducer: Reducer = (state: any, action: any) => ({}) + +const persistCallback: PersistCallback = (err: any, response: any) => {} + +const transform: PersistTransformer = createTransform({}, {}, { whitelist : ["foo"] }) + +const persistConfig: PersistConfig = { + blacklist : ["foo"], + whitelist : ["bar"], + storage : asyncLocalStorage, + transforms : [transform], + debounce : 1000, + keyPrefix : KEY_PREFIX +} + +const rehydrateOptions: PersistorRehydrateOptions = { serial : true } + +const autoRehydrateConfig: PersistAutoRehydrateConfig = { + stateReconcile: (state: any, inboundState: any, reducedState: any, log: boolean) => ({}) +} + +const store: Store = createStore(reducer, autoRehydrate(autoRehydrateConfig)) +const persistor: Persistor = persistStore(store, persistConfig, persistCallback) + +purgeStoredState({ whitelist : ["foo"] }, ["bar"]) + +getStoredState(persistConfig, (err: any, restoredState: any) => { + const store: Store = createStore(reducer, restoredState) + const persistor: Persistor = createPersistor(store, persistConfig) + const secondaryPersistor: Persistor = createPersistor(store, { storage : asyncSessionStorage }) + persistor.pause() + persistor.resume() + persistor.purge(["foo", "bar"]) + persistor.rehydrate(restoredState, rehydrateOptions) +}) diff --git a/redux-persist/storages.d.ts b/redux-persist/storages.d.ts new file mode 100644 index 0000000000..b798ed2664 --- /dev/null +++ b/redux-persist/storages.d.ts @@ -0,0 +1,4 @@ +import { PersistStorage } from "redux-persist"; + +export const asyncLocalStorage: PersistStorage; +export const asyncSessionStorage: PersistStorage; diff --git a/redux-persist/tsconfig.json b/redux-persist/tsconfig.json new file mode 100644 index 0000000000..f7f8a60693 --- /dev/null +++ b/redux-persist/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "constants.d.ts", + "storages.d.ts", + "redux-persist-tests.ts" + ] +}