@aegis-framework/artemis 0.3.28 → 0.4.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.
- package/LICENSE +1 -1
- package/dist/artemis.browser.js +4 -0
- package/dist/artemis.browser.js.map +24 -0
- package/dist/artemis.js +3 -1
- package/dist/artemis.js.map +23 -1
- package/dist/types/DOM.d.ts +383 -0
- package/dist/types/DOM.d.ts.map +1 -0
- package/dist/types/Debug.d.ts +118 -0
- package/dist/types/Debug.d.ts.map +1 -0
- package/dist/types/FileSystem.d.ts +69 -0
- package/dist/types/FileSystem.d.ts.map +1 -0
- package/dist/types/Form.d.ts +32 -0
- package/dist/types/Form.d.ts.map +1 -0
- package/dist/types/Platform.d.ts +93 -0
- package/dist/types/Platform.d.ts.map +1 -0
- package/dist/types/Preload.d.ts +26 -0
- package/dist/types/Preload.d.ts.map +1 -0
- package/dist/types/Request.d.ts +86 -0
- package/dist/types/Request.d.ts.map +1 -0
- package/dist/types/Space.d.ts +205 -0
- package/dist/types/Space.d.ts.map +1 -0
- package/dist/types/SpaceAdapter/IndexedDB.d.ts +130 -0
- package/dist/types/SpaceAdapter/IndexedDB.d.ts.map +1 -0
- package/dist/types/SpaceAdapter/LocalStorage.d.ts +125 -0
- package/dist/types/SpaceAdapter/LocalStorage.d.ts.map +1 -0
- package/dist/types/SpaceAdapter/RemoteStorage.d.ts +122 -0
- package/dist/types/SpaceAdapter/RemoteStorage.d.ts.map +1 -0
- package/dist/types/SpaceAdapter/SessionStorage.d.ts +30 -0
- package/dist/types/SpaceAdapter/SessionStorage.d.ts.map +1 -0
- package/dist/types/SpaceAdapter/types.d.ts +76 -0
- package/dist/types/SpaceAdapter/types.d.ts.map +1 -0
- package/dist/types/Text.d.ts +47 -0
- package/dist/types/Text.d.ts.map +1 -0
- package/dist/types/Util.d.ts +31 -0
- package/dist/types/Util.d.ts.map +1 -0
- package/dist/types/browser.d.ts +7 -0
- package/dist/types/browser.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +42 -53
- package/dist/artemis.min.js +0 -2
- package/dist/artemis.min.js.map +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/index.js +0 -10
- package/src/DOM.js +0 -993
- package/src/Debug.js +0 -233
- package/src/FileSystem.js +0 -109
- package/src/Form.js +0 -73
- package/src/Platform.js +0 -166
- package/src/Preload.js +0 -48
- package/src/Request.js +0 -163
- package/src/Space.js +0 -334
- package/src/SpaceAdapter/IndexedDB.js +0 -345
- package/src/SpaceAdapter/LocalStorage.js +0 -395
- package/src/SpaceAdapter/RemoteStorage.js +0 -219
- package/src/SpaceAdapter/SessionStorage.js +0 -46
- package/src/Text.js +0 -133
- package/src/Util.js +0 -55
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ==============================
|
|
3
|
+
* Platform
|
|
4
|
+
* ==============================
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Desktop platform types
|
|
8
|
+
*/
|
|
9
|
+
export type DesktopPlatform = 'Windows' | 'macOS' | 'Linux' | 'FreeBSD' | 'webOS' | 'Any';
|
|
10
|
+
/**
|
|
11
|
+
* Mobile platform types
|
|
12
|
+
*/
|
|
13
|
+
export type MobilePlatform = 'Android' | 'iOS' | 'Opera' | 'Windows' | 'BlackBerry' | 'Any';
|
|
14
|
+
/**
|
|
15
|
+
* Orientation types
|
|
16
|
+
*/
|
|
17
|
+
export type Orientation = 'portrait' | 'landscape';
|
|
18
|
+
/**
|
|
19
|
+
* Extended Navigator interface for userAgentData
|
|
20
|
+
*/
|
|
21
|
+
interface NavigatorUAData {
|
|
22
|
+
platform?: string;
|
|
23
|
+
brands?: {
|
|
24
|
+
brand: string;
|
|
25
|
+
version: string;
|
|
26
|
+
}[];
|
|
27
|
+
mobile?: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare global {
|
|
30
|
+
interface Navigator {
|
|
31
|
+
userAgentData?: NavigatorUAData;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* General checks for what kind of platform is being used to run the app.
|
|
36
|
+
*/
|
|
37
|
+
export declare class Platform {
|
|
38
|
+
/**
|
|
39
|
+
* Check if the screen has a retina pixel ratio
|
|
40
|
+
* @returns Whether the screen is retina
|
|
41
|
+
*/
|
|
42
|
+
static retina(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Check if the device is on portrait orientation
|
|
45
|
+
* @returns Whether device is in portrait mode
|
|
46
|
+
*/
|
|
47
|
+
static portrait(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Check if the device is on landscape orientation
|
|
50
|
+
* @returns Whether device is in landscape mode
|
|
51
|
+
*/
|
|
52
|
+
static landscape(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Get device Orientation
|
|
55
|
+
* @returns 'portrait' or 'landscape'
|
|
56
|
+
*/
|
|
57
|
+
static orientation(): Orientation;
|
|
58
|
+
/**
|
|
59
|
+
* Check if the app is running over Electron
|
|
60
|
+
* @returns Whether running in Electron
|
|
61
|
+
*/
|
|
62
|
+
static electron(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Check if the app is running over Cordova
|
|
65
|
+
* @returns Whether running in Cordova
|
|
66
|
+
*/
|
|
67
|
+
static cordova(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Get the platform string using modern userAgentData API with fallback
|
|
70
|
+
* @returns Platform string
|
|
71
|
+
*/
|
|
72
|
+
private static getPlatformString;
|
|
73
|
+
/**
|
|
74
|
+
* Check if the app is running in a desktop platform
|
|
75
|
+
* @param platform - Check for a specific desktop platform
|
|
76
|
+
* @returns Whether running on specified desktop platform
|
|
77
|
+
*/
|
|
78
|
+
static desktop(platform?: DesktopPlatform): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Check if the app is running in a mobile platform
|
|
81
|
+
* @param platform - Check for a specific mobile platform
|
|
82
|
+
* @returns Whether running on specified mobile platform
|
|
83
|
+
*/
|
|
84
|
+
static mobile(platform?: MobilePlatform): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Check if the platform allows the use of service workers
|
|
87
|
+
*
|
|
88
|
+
* @returns Whether service workers are supported
|
|
89
|
+
*/
|
|
90
|
+
static serviceWorkers(): boolean;
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
93
|
+
//# sourceMappingURL=Platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../src/Platform.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,KAAK,CAAC;AAE1F;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,KAAK,GAAG,OAAO,GAAG,SAAS,GAAG,YAAY,GAAG,KAAK,CAAC;AAE5F;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;AAEnD;;GAEG;AACH,UAAU,eAAe;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC9C,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,SAAS;QAClB,aAAa,CAAC,EAAE,eAAe,CAAC;KAChC;CACD;AAeD;;GAEG;AACH,qBAAa,QAAQ;IACpB;;;OAGG;IACH,MAAM,CAAC,MAAM,IAAI,OAAO;IAIxB;;;OAGG;IACH,MAAM,CAAC,QAAQ,IAAI,OAAO;IAI1B;;;OAGG;IACH,MAAM,CAAC,SAAS,IAAI,OAAO;IAI3B;;;OAGG;IACH,MAAM,CAAC,WAAW,IAAI,WAAW;IAIjC;;;OAGG;IACH,MAAM,CAAC,QAAQ,IAAI,OAAO;IAsB1B;;;OAGG;IACH,MAAM,CAAC,OAAO,IAAI,OAAO;IAIzB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAehC;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,QAAQ,GAAE,eAAuB,GAAG,OAAO;IA2B1D;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,QAAQ,GAAE,cAAsB,GAAG,OAAO;IA+BxD;;;;OAIG;IACH,MAAM,CAAC,cAAc,IAAI,OAAO;CAQhC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ==============================
|
|
3
|
+
* Preload
|
|
4
|
+
* ==============================
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A simple class for asset preloading. This class assumes you have a service
|
|
8
|
+
* worker set up that will be caching all requests.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Preload {
|
|
11
|
+
/**
|
|
12
|
+
* Preload an image file
|
|
13
|
+
*
|
|
14
|
+
* @param route - Route to the image
|
|
15
|
+
* @returns Resolves to the image object or gets rejected with the rejection event
|
|
16
|
+
*/
|
|
17
|
+
static image(route: string): Promise<HTMLImageElement>;
|
|
18
|
+
/**
|
|
19
|
+
* Preload any kind of file
|
|
20
|
+
*
|
|
21
|
+
* @param route - Route to the file
|
|
22
|
+
* @returns Resolves or rejects depending on request success
|
|
23
|
+
*/
|
|
24
|
+
static file(route: string): Promise<Blob>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=Preload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Preload.d.ts","sourceRoot":"","sources":["../../src/Preload.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;GAGG;AACH,qBAAa,OAAO;IACnB;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAgBtD;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGzC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ==============================
|
|
3
|
+
* Request
|
|
4
|
+
* ==============================
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Type for request data object
|
|
8
|
+
*/
|
|
9
|
+
export type RequestData = Record<string, string | number | boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Type for request options
|
|
12
|
+
*/
|
|
13
|
+
export interface RequestOptions extends Omit<RequestInit, 'headers'> {
|
|
14
|
+
headers?: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Simple Wrapper for the fetch API, providing simple functions to handle requests
|
|
18
|
+
*/
|
|
19
|
+
export declare class Request {
|
|
20
|
+
/**
|
|
21
|
+
* Serialize an object of data into a URI encoded format
|
|
22
|
+
*
|
|
23
|
+
* @param data - Key-value object of data to serialize
|
|
24
|
+
* @returns Serialized Data
|
|
25
|
+
*/
|
|
26
|
+
static serialize(data: RequestData): string;
|
|
27
|
+
/**
|
|
28
|
+
* Make a GET request to a given URL with the provided data parameters
|
|
29
|
+
* and an optional configuration object for the request.
|
|
30
|
+
*
|
|
31
|
+
* @param url - URL to make the request to
|
|
32
|
+
* @param data - Parameters to send in the URL, represented as a JSON object
|
|
33
|
+
* @param options - Options object for configurations you want to use in the fetch request
|
|
34
|
+
* @returns Resolves to the response of the request
|
|
35
|
+
*/
|
|
36
|
+
static get(url: string, data?: RequestData, options?: RequestOptions): Promise<Response>;
|
|
37
|
+
/**
|
|
38
|
+
* Make a POST request to a given URL with the provided data and an optional
|
|
39
|
+
* configuration object for the request.
|
|
40
|
+
*
|
|
41
|
+
* @param url - URL to make the request
|
|
42
|
+
* @param data - Set of data to send in the URL, represented as a JSON object
|
|
43
|
+
* @param options - Options object for configurations you want to use in the fetch request
|
|
44
|
+
* @returns Resolves to the response of the request
|
|
45
|
+
*/
|
|
46
|
+
static post(url: string, data: RequestData, options?: RequestOptions): Promise<Response>;
|
|
47
|
+
/**
|
|
48
|
+
* Make a PUT request to a given URL with the provided data and an optional
|
|
49
|
+
* configuration object for the request.
|
|
50
|
+
*
|
|
51
|
+
* @param url - URL to make the request
|
|
52
|
+
* @param data - Set of data to send in the URL, represented as a JSON object
|
|
53
|
+
* @param options - Options object for configurations you want to use in the fetch request
|
|
54
|
+
* @returns Resolves to the response of the request
|
|
55
|
+
*/
|
|
56
|
+
static put(url: string, data: RequestData, options?: RequestOptions): Promise<Response>;
|
|
57
|
+
/**
|
|
58
|
+
* Make a DELETE request to a given URL with the provided data and an optional
|
|
59
|
+
* configuration object for the request.
|
|
60
|
+
*
|
|
61
|
+
* @param url - URL to make the request
|
|
62
|
+
* @param data - Parameters to send in the URL, represented as a JSON object
|
|
63
|
+
* @param options - Options object for configurations you want to use in the fetch request
|
|
64
|
+
* @returns Resolves to the response of the request
|
|
65
|
+
*/
|
|
66
|
+
static delete(url: string, data: RequestData, options?: RequestOptions): Promise<Response>;
|
|
67
|
+
/**
|
|
68
|
+
* Request a JSON object from a given URL through a GET request
|
|
69
|
+
*
|
|
70
|
+
* @param url - URL to make the request to
|
|
71
|
+
* @param data - Parameters to send in the URL, represented as a JSON object
|
|
72
|
+
* @param options - Options object for configurations you want to use in the fetch request
|
|
73
|
+
* @returns Resolves to the json object obtained from the request response
|
|
74
|
+
*/
|
|
75
|
+
static json<T = unknown>(url: string, data?: RequestData, options?: RequestOptions): Promise<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Request a Blob from a given URL through a GET request
|
|
78
|
+
*
|
|
79
|
+
* @param url - URL to make the request to
|
|
80
|
+
* @param data - Parameters to send in the URL, represented as a JSON object
|
|
81
|
+
* @param options - Options object for configurations you want to use in the fetch request
|
|
82
|
+
* @returns Resolves to the blob obtained from the request response
|
|
83
|
+
*/
|
|
84
|
+
static blob(url: string, data?: RequestData, options?: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,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,CAAC,CAAC;IAMvG;;;;;;;OAOG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;CAK7F"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ==============================
|
|
3
|
+
* Space
|
|
4
|
+
* ==============================
|
|
5
|
+
*/
|
|
6
|
+
import { LocalStorage } from './SpaceAdapter/LocalStorage';
|
|
7
|
+
import { SessionStorage } from './SpaceAdapter/SessionStorage';
|
|
8
|
+
import { IndexedDB } from './SpaceAdapter/IndexedDB';
|
|
9
|
+
import { RemoteStorage } from './SpaceAdapter/RemoteStorage';
|
|
10
|
+
import type { SpaceConfiguration, StorageValue, KeyValueResult, UpgradeCallback } from './SpaceAdapter/types';
|
|
11
|
+
/**
|
|
12
|
+
* List of Adapters Available
|
|
13
|
+
*/
|
|
14
|
+
export declare const SpaceAdapter: {
|
|
15
|
+
LocalStorage: typeof LocalStorage;
|
|
16
|
+
SessionStorage: typeof SessionStorage;
|
|
17
|
+
IndexedDB: typeof IndexedDB;
|
|
18
|
+
RemoteStorage: typeof RemoteStorage;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Space adapter type (any of the available adapters)
|
|
22
|
+
*/
|
|
23
|
+
export type SpaceAdapterType = LocalStorage | SessionStorage | IndexedDB | RemoteStorage;
|
|
24
|
+
/**
|
|
25
|
+
* Space adapter constructor type
|
|
26
|
+
*/
|
|
27
|
+
export type SpaceAdapterConstructor = typeof LocalStorage | typeof SessionStorage | typeof IndexedDB | typeof RemoteStorage;
|
|
28
|
+
/**
|
|
29
|
+
* Callback function type for space events
|
|
30
|
+
*/
|
|
31
|
+
export type SpaceCallback = (key: string, value: StorageValue) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Transformation function type
|
|
34
|
+
*/
|
|
35
|
+
export type TransformationFunction = (key: string, value: StorageValue) => StorageValue;
|
|
36
|
+
/**
|
|
37
|
+
* Transformation configuration
|
|
38
|
+
*/
|
|
39
|
+
export interface Transformation {
|
|
40
|
+
id: string;
|
|
41
|
+
get?: TransformationFunction | null;
|
|
42
|
+
set?: TransformationFunction | null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Space provides a simple wrapper for different Storage APIs. It aims to
|
|
46
|
+
* provide data independence through storage namespaces and versioning, allowing
|
|
47
|
+
* transparent data formatting and content modifications through versions.
|
|
48
|
+
*/
|
|
49
|
+
export declare class Space {
|
|
50
|
+
private _configuration;
|
|
51
|
+
adapter: SpaceAdapterType;
|
|
52
|
+
callbacks: {
|
|
53
|
+
create: SpaceCallback[];
|
|
54
|
+
update: SpaceCallback[];
|
|
55
|
+
delete: SpaceCallback[];
|
|
56
|
+
};
|
|
57
|
+
transformations: Record<string, Transformation>;
|
|
58
|
+
/**
|
|
59
|
+
* Create a new Space Object. If no name and version is defined, the global
|
|
60
|
+
* LocalSpace space is used.
|
|
61
|
+
*
|
|
62
|
+
* @param adapter - Space Adapter to use
|
|
63
|
+
* @param configuration - Configuration object for the space
|
|
64
|
+
*/
|
|
65
|
+
constructor(adapter?: SpaceAdapterConstructor, configuration?: SpaceConfiguration);
|
|
66
|
+
/**
|
|
67
|
+
* Modify the space configuration, it will also be passed down to the adapter
|
|
68
|
+
* using its configuration() function.
|
|
69
|
+
*
|
|
70
|
+
* @param object - Configuration object to set up
|
|
71
|
+
* @returns Configuration object if no param was passed
|
|
72
|
+
*/
|
|
73
|
+
configuration(object?: SpaceConfiguration | null): SpaceConfiguration | void;
|
|
74
|
+
/**
|
|
75
|
+
* Open the Storage Object to be used depending on the SpaceAdapter
|
|
76
|
+
*
|
|
77
|
+
* @returns Promise resolving to this Space
|
|
78
|
+
*/
|
|
79
|
+
open(): Promise<this>;
|
|
80
|
+
/**
|
|
81
|
+
* Store a key-value pair
|
|
82
|
+
*
|
|
83
|
+
* @param key - Key with which this value will be saved
|
|
84
|
+
* @param value - Value to save
|
|
85
|
+
* @returns Promise with key and value
|
|
86
|
+
*/
|
|
87
|
+
set(key: string, value: StorageValue): Promise<KeyValueResult>;
|
|
88
|
+
/**
|
|
89
|
+
* Update a key-value pair. In difference with the set() method, the update
|
|
90
|
+
* method will use Object.assign() in the case of objects so no value is lost.
|
|
91
|
+
*
|
|
92
|
+
* @param key - Key with which this value will be saved
|
|
93
|
+
* @param value - Value to save
|
|
94
|
+
* @returns Promise with key and value
|
|
95
|
+
*/
|
|
96
|
+
update(key: string, value: StorageValue): Promise<KeyValueResult>;
|
|
97
|
+
/**
|
|
98
|
+
* Retrieves a value from storage given its key
|
|
99
|
+
*
|
|
100
|
+
* @param key - Key with which the value was saved
|
|
101
|
+
* @returns Promise resolving to the retrieved value
|
|
102
|
+
*/
|
|
103
|
+
get(key: string): Promise<StorageValue>;
|
|
104
|
+
/**
|
|
105
|
+
* Retrieves all the values in the space in a key-value JSON object
|
|
106
|
+
*
|
|
107
|
+
* @returns Promise resolving to all values
|
|
108
|
+
*/
|
|
109
|
+
getAll(): Promise<Record<string, StorageValue>>;
|
|
110
|
+
/**
|
|
111
|
+
* Iterate over every value in the space
|
|
112
|
+
*
|
|
113
|
+
* @param callback - A callback function receiving the key and value
|
|
114
|
+
* @returns Promise resolving when all callbacks have been resolved
|
|
115
|
+
*/
|
|
116
|
+
each(callback: (key: string, value: StorageValue) => unknown): Promise<unknown[]>;
|
|
117
|
+
/**
|
|
118
|
+
* Check if a space contains a given key. Not all adapters may give this information
|
|
119
|
+
*
|
|
120
|
+
* @param key - Key to look for
|
|
121
|
+
* @returns Promise that resolves if key exists
|
|
122
|
+
*/
|
|
123
|
+
contains(key: string): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Upgrade a Space Version. Not all adapters may provide this functionality
|
|
126
|
+
*
|
|
127
|
+
* @param oldVersion - The version of the storage to be upgraded
|
|
128
|
+
* @param newVersion - The version to be upgraded to
|
|
129
|
+
* @param callback - Function to transform the old stored values
|
|
130
|
+
* @returns Promise for the upgrade operation
|
|
131
|
+
*/
|
|
132
|
+
upgrade(oldVersion: string, newVersion: string, callback: UpgradeCallback): Promise<this>;
|
|
133
|
+
/**
|
|
134
|
+
* Rename a Space. Not all adapters may provide this functionality
|
|
135
|
+
*
|
|
136
|
+
* @param name - New name to be used
|
|
137
|
+
* @returns Promise for the rename operation
|
|
138
|
+
*/
|
|
139
|
+
rename(name: string): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Add a callback function to be run every time a value is created.
|
|
142
|
+
*
|
|
143
|
+
* @param callback - Callback Function. Key and Value pair will be sent as parameters.
|
|
144
|
+
*/
|
|
145
|
+
onCreate(callback: SpaceCallback): void;
|
|
146
|
+
/**
|
|
147
|
+
* Add a callback function to be run every time a value is updated.
|
|
148
|
+
*
|
|
149
|
+
* @param callback - Callback Function. Key and Value pair will be sent as parameters.
|
|
150
|
+
*/
|
|
151
|
+
onUpdate(callback: SpaceCallback): void;
|
|
152
|
+
/**
|
|
153
|
+
* Add a callback function to be run every time a value is deleted.
|
|
154
|
+
*
|
|
155
|
+
* @param callback - Callback Function. Key and Value pair will be sent as parameters.
|
|
156
|
+
*/
|
|
157
|
+
onDelete(callback: SpaceCallback): void;
|
|
158
|
+
/**
|
|
159
|
+
* Add a transformation function to the space.
|
|
160
|
+
*
|
|
161
|
+
* @param transformation - Transformation configuration with id, get, and set functions
|
|
162
|
+
*/
|
|
163
|
+
addTransformation({ id, get, set }: Transformation): void;
|
|
164
|
+
/**
|
|
165
|
+
* Remove a transformation function given its id
|
|
166
|
+
*
|
|
167
|
+
* @param id - Name or identifier of the transformation to remove
|
|
168
|
+
*/
|
|
169
|
+
removeTransformation(id: string): void;
|
|
170
|
+
/**
|
|
171
|
+
* Get the key that corresponds to a given index in the storage.
|
|
172
|
+
* Not all adapters may provide this functionality
|
|
173
|
+
*
|
|
174
|
+
* @param index - Index to get the key from
|
|
175
|
+
* @param full - Whether to return the full key name including space id
|
|
176
|
+
* @returns Promise resolving to the key's name
|
|
177
|
+
*/
|
|
178
|
+
key(index: number, full?: boolean): Promise<string>;
|
|
179
|
+
/**
|
|
180
|
+
* Return all keys stored in the space. Not all adapters may provide this functionality
|
|
181
|
+
*
|
|
182
|
+
* @param full - Whether to return the full key name including space id
|
|
183
|
+
* @returns Promise resolving to array of keys
|
|
184
|
+
*/
|
|
185
|
+
keys(full?: boolean): Promise<string[]>;
|
|
186
|
+
/**
|
|
187
|
+
* Delete a value from the space given its key
|
|
188
|
+
*
|
|
189
|
+
* @param key - Key of the item to delete
|
|
190
|
+
* @returns Promise that resolves after deletion
|
|
191
|
+
*/
|
|
192
|
+
remove(key: string): Promise<void>;
|
|
193
|
+
/**
|
|
194
|
+
* Clear the entire space
|
|
195
|
+
*
|
|
196
|
+
* @returns Promise for the clear operation
|
|
197
|
+
*/
|
|
198
|
+
clear(): Promise<void>;
|
|
199
|
+
}
|
|
200
|
+
export { LocalStorage } from './SpaceAdapter/LocalStorage';
|
|
201
|
+
export { SessionStorage } from './SpaceAdapter/SessionStorage';
|
|
202
|
+
export { IndexedDB } from './SpaceAdapter/IndexedDB';
|
|
203
|
+
export { RemoteStorage } from './SpaceAdapter/RemoteStorage';
|
|
204
|
+
export type { SpaceConfiguration, StorageValue, KeyValueResult, UpgradeCallback } from './SpaceAdapter/types';
|
|
205
|
+
//# sourceMappingURL=Space.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Space.d.ts","sourceRoot":"","sources":["../../src/Space.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,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,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAItC;;;;;;;OAOG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,OAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAI1D;;;;;OAKG;IACH,IAAI,CAAC,IAAI,GAAE,OAAe,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAI9C;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASlC;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGtB;AAGD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ==============================
|
|
3
|
+
* IndexedDB Adapter
|
|
4
|
+
* ==============================
|
|
5
|
+
*/
|
|
6
|
+
import type { IndexedDBConfiguration, StorageValue, KeyValueResult, UpgradeCallback } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* The IndexedDB Adapter provides the Space Class the ability to interact
|
|
9
|
+
* with the IndexedDB API found in most modern browsers.
|
|
10
|
+
*/
|
|
11
|
+
export declare class IndexedDB {
|
|
12
|
+
name: string;
|
|
13
|
+
version: string;
|
|
14
|
+
store: string;
|
|
15
|
+
props: IDBObjectStoreParameters;
|
|
16
|
+
index: Record<string, {
|
|
17
|
+
name: string;
|
|
18
|
+
field: string;
|
|
19
|
+
props?: IDBIndexParameters;
|
|
20
|
+
}>;
|
|
21
|
+
keyPath: string;
|
|
22
|
+
numericVersion: number;
|
|
23
|
+
upgrades: Record<string, UpgradeCallback<IndexedDB>>;
|
|
24
|
+
storage: IDBDatabase | Promise<IDBDatabase> | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Create a new IndexedDB. Differently from Local and Session Storages, the
|
|
27
|
+
* IndexedDB Adapter requires a mandatory name, version and store name.
|
|
28
|
+
*
|
|
29
|
+
* @param configuration - Configuration Object for the Adapter
|
|
30
|
+
*/
|
|
31
|
+
constructor({ name, version, store, props, index }: IndexedDBConfiguration);
|
|
32
|
+
/**
|
|
33
|
+
* Modify the configuration
|
|
34
|
+
*
|
|
35
|
+
* @param config - Configuration object to set up
|
|
36
|
+
*/
|
|
37
|
+
configuration(config: IndexedDBConfiguration): void;
|
|
38
|
+
/**
|
|
39
|
+
* Open the Storage Object
|
|
40
|
+
*
|
|
41
|
+
* @returns Promise resolving to this adapter
|
|
42
|
+
*/
|
|
43
|
+
open(): Promise<this>;
|
|
44
|
+
/**
|
|
45
|
+
* Store a key-value pair. Because of the nature of IndexedDB,
|
|
46
|
+
* stored values must be JSON objects.
|
|
47
|
+
*
|
|
48
|
+
* @param key - Key with which this value will be saved
|
|
49
|
+
* @param value - Value to save
|
|
50
|
+
* @returns Promise with key and value
|
|
51
|
+
*/
|
|
52
|
+
set(key: string | null | undefined, value: StorageValue): Promise<KeyValueResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Update a key-value pair. The update method will use Object.assign()
|
|
55
|
+
* in the case of objects so no value is lost.
|
|
56
|
+
*
|
|
57
|
+
* @param key - Key with which this value will be saved
|
|
58
|
+
* @param value - Value to save
|
|
59
|
+
* @returns Promise with key and value
|
|
60
|
+
*/
|
|
61
|
+
update(key: string, value: StorageValue): Promise<KeyValueResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves a value from storage given its key
|
|
64
|
+
*
|
|
65
|
+
* @param key - Key with which the value was saved
|
|
66
|
+
* @returns Promise resolving to the retrieved value
|
|
67
|
+
*/
|
|
68
|
+
get(key: string): Promise<StorageValue>;
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves all the values in the space in a key-value JSON object
|
|
71
|
+
*
|
|
72
|
+
* @returns Promise resolving to all values
|
|
73
|
+
*/
|
|
74
|
+
getAll(): Promise<Record<string, StorageValue>>;
|
|
75
|
+
/**
|
|
76
|
+
* Check if the space contains a given key.
|
|
77
|
+
*
|
|
78
|
+
* @param key - Key to look for
|
|
79
|
+
* @returns Promise that resolves if key exists
|
|
80
|
+
*/
|
|
81
|
+
contains(key: string): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Upgrade a Space Version. Upgrades must be declared before the open()
|
|
84
|
+
* method is executed.
|
|
85
|
+
*
|
|
86
|
+
* @param oldVersion - The version to be upgraded
|
|
87
|
+
* @param newVersion - The version to be upgraded to
|
|
88
|
+
* @param callback - Function to transform the old stored values
|
|
89
|
+
* @returns Promise
|
|
90
|
+
*/
|
|
91
|
+
upgrade(oldVersion: string, newVersion: string, callback: UpgradeCallback<IndexedDB>): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Helper for the upgrade progress by executing callbacks in order
|
|
94
|
+
*/
|
|
95
|
+
private _upgrade;
|
|
96
|
+
/**
|
|
97
|
+
* Renaming the space is not possible with the IndexedDB adapter therefore
|
|
98
|
+
* this function always gets rejected.
|
|
99
|
+
*
|
|
100
|
+
* @returns Promise rejection
|
|
101
|
+
*/
|
|
102
|
+
rename(): Promise<never>;
|
|
103
|
+
/**
|
|
104
|
+
* Getting a key by its index is not possible in this adapter, therefore this
|
|
105
|
+
* function always gets rejected.
|
|
106
|
+
*
|
|
107
|
+
* @returns Promise rejection
|
|
108
|
+
*/
|
|
109
|
+
key(): Promise<never>;
|
|
110
|
+
/**
|
|
111
|
+
* Return all keys stored in the space.
|
|
112
|
+
*
|
|
113
|
+
* @returns Promise resolving to array of keys
|
|
114
|
+
*/
|
|
115
|
+
keys(): Promise<string[]>;
|
|
116
|
+
/**
|
|
117
|
+
* Delete a value from the space given its key
|
|
118
|
+
*
|
|
119
|
+
* @param key - Key of the item to delete
|
|
120
|
+
* @returns Promise resolving to the value of the deleted object
|
|
121
|
+
*/
|
|
122
|
+
remove(key: string): Promise<StorageValue>;
|
|
123
|
+
/**
|
|
124
|
+
* Clear the entire space
|
|
125
|
+
*
|
|
126
|
+
* @returns Promise for the clear operation
|
|
127
|
+
*/
|
|
128
|
+
clear(): Promise<void>;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=IndexedDB.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndexedDB.d.ts","sourceRoot":"","sources":["../../../src/SpaceAdapter/IndexedDB.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAErG;;;GAGG;AACH,qBAAa,SAAS;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,wBAAwB,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,kBAAkB,CAAA;KAAE,CAAC,CAAC;IACnF,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;IACrD,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC;IAE/D;;;;;OAKG;gBACS,EAAE,IAAS,EAAE,OAAY,EAAE,KAAU,EAAE,KAAU,EAAE,KAAU,EAAE,EAAE,sBAAsB;IAiBnG;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI;IAMnD;;;;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