@capacitor/preferences 4.0.0-beta.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/CHANGELOG.md +299 -0
- package/CapacitorPreferences.podspec +17 -0
- package/LICENSE +23 -0
- package/README.md +259 -0
- package/android/build.gradle +57 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/capacitorjs/plugins/preferences/Preferences.java +45 -0
- package/android/src/main/java/com/capacitorjs/plugins/preferences/PreferencesConfiguration.java +18 -0
- package/android/src/main/java/com/capacitorjs/plugins/preferences/PreferencesPlugin.java +129 -0
- package/dist/docs.json +348 -0
- package/dist/esm/definitions.d.ts +135 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +17 -0
- package/dist/esm/web.js +71 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +87 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +90 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Preferences.swift +64 -0
- package/ios/Plugin/PreferencesPlugin.h +10 -0
- package/ios/Plugin/PreferencesPlugin.m +15 -0
- package/ios/Plugin/PreferencesPlugin.swift +106 -0
- package/package.json +83 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
package com.capacitorjs.plugins.preferences;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.SharedPreferences;
|
|
6
|
+
import java.util.Set;
|
|
7
|
+
|
|
8
|
+
public class Preferences {
|
|
9
|
+
|
|
10
|
+
private SharedPreferences preferences;
|
|
11
|
+
|
|
12
|
+
private interface PreferencesOperation {
|
|
13
|
+
void execute(SharedPreferences.Editor editor);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
Preferences(Context context, PreferencesConfiguration configuration) {
|
|
17
|
+
this.preferences = context.getSharedPreferences(configuration.group, Activity.MODE_PRIVATE);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public String get(String key) {
|
|
21
|
+
return preferences.getString(key, null);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public void set(String key, String value) {
|
|
25
|
+
executeOperation(editor -> editor.putString(key, value));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public void remove(String key) {
|
|
29
|
+
executeOperation(editor -> editor.remove(key));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public Set<String> keys() {
|
|
33
|
+
return preferences.getAll().keySet();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public void clear() {
|
|
37
|
+
executeOperation(SharedPreferences.Editor::clear);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private void executeOperation(PreferencesOperation op) {
|
|
41
|
+
SharedPreferences.Editor editor = preferences.edit();
|
|
42
|
+
op.execute(editor);
|
|
43
|
+
editor.apply();
|
|
44
|
+
}
|
|
45
|
+
}
|
package/android/src/main/java/com/capacitorjs/plugins/preferences/PreferencesConfiguration.java
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package com.capacitorjs.plugins.preferences;
|
|
2
|
+
|
|
3
|
+
public class PreferencesConfiguration implements Cloneable {
|
|
4
|
+
|
|
5
|
+
static final PreferencesConfiguration DEFAULTS;
|
|
6
|
+
|
|
7
|
+
static {
|
|
8
|
+
DEFAULTS = new PreferencesConfiguration();
|
|
9
|
+
DEFAULTS.group = "CapacitorStorage";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
String group;
|
|
13
|
+
|
|
14
|
+
@Override
|
|
15
|
+
public PreferencesConfiguration clone() throws CloneNotSupportedException {
|
|
16
|
+
return (PreferencesConfiguration) super.clone();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
package com.capacitorjs.plugins.preferences;
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSArray;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import com.getcapacitor.Plugin;
|
|
6
|
+
import com.getcapacitor.PluginCall;
|
|
7
|
+
import com.getcapacitor.PluginMethod;
|
|
8
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
9
|
+
import java.util.ArrayList;
|
|
10
|
+
import java.util.List;
|
|
11
|
+
import java.util.Set;
|
|
12
|
+
import org.json.JSONException;
|
|
13
|
+
|
|
14
|
+
@CapacitorPlugin(name = "Preferences")
|
|
15
|
+
public class PreferencesPlugin extends Plugin {
|
|
16
|
+
|
|
17
|
+
private Preferences preferences;
|
|
18
|
+
|
|
19
|
+
@Override
|
|
20
|
+
public void load() {
|
|
21
|
+
preferences = new Preferences(getContext(), PreferencesConfiguration.DEFAULTS);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@PluginMethod
|
|
25
|
+
public void configure(PluginCall call) {
|
|
26
|
+
try {
|
|
27
|
+
PreferencesConfiguration configuration = PreferencesConfiguration.DEFAULTS.clone();
|
|
28
|
+
configuration.group = call.getString("group", PreferencesConfiguration.DEFAULTS.group);
|
|
29
|
+
|
|
30
|
+
preferences = new Preferences(getContext(), configuration);
|
|
31
|
+
} catch (CloneNotSupportedException e) {
|
|
32
|
+
call.reject("Error while configuring", e);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
call.resolve();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@PluginMethod
|
|
39
|
+
public void get(PluginCall call) {
|
|
40
|
+
String key = call.getString("key");
|
|
41
|
+
if (key == null) {
|
|
42
|
+
call.reject("Must provide key");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
String value = preferences.get(key);
|
|
47
|
+
|
|
48
|
+
JSObject ret = new JSObject();
|
|
49
|
+
ret.put("value", value == null ? JSObject.NULL : value);
|
|
50
|
+
call.resolve(ret);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@PluginMethod
|
|
54
|
+
public void set(PluginCall call) {
|
|
55
|
+
String key = call.getString("key");
|
|
56
|
+
if (key == null) {
|
|
57
|
+
call.reject("Must provide key");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
String value = call.getString("value");
|
|
62
|
+
preferences.set(key, value);
|
|
63
|
+
|
|
64
|
+
call.resolve();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@PluginMethod
|
|
68
|
+
public void remove(PluginCall call) {
|
|
69
|
+
String key = call.getString("key");
|
|
70
|
+
if (key == null) {
|
|
71
|
+
call.reject("Must provide key");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
preferences.remove(key);
|
|
76
|
+
|
|
77
|
+
call.resolve();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@PluginMethod
|
|
81
|
+
public void keys(PluginCall call) {
|
|
82
|
+
Set<String> keySet = preferences.keys();
|
|
83
|
+
String[] keys = keySet.toArray(new String[0]);
|
|
84
|
+
|
|
85
|
+
JSObject ret = new JSObject();
|
|
86
|
+
try {
|
|
87
|
+
ret.put("keys", new JSArray(keys));
|
|
88
|
+
} catch (JSONException ex) {
|
|
89
|
+
call.reject("Unable to serialize response.", ex);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
call.resolve(ret);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@PluginMethod
|
|
96
|
+
public void clear(PluginCall call) {
|
|
97
|
+
preferences.clear();
|
|
98
|
+
call.resolve();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@PluginMethod
|
|
102
|
+
public void migrate(PluginCall call) {
|
|
103
|
+
List<String> migrated = new ArrayList<>();
|
|
104
|
+
List<String> existing = new ArrayList<>();
|
|
105
|
+
Preferences oldPreferences = new Preferences(getContext(), PreferencesConfiguration.DEFAULTS);
|
|
106
|
+
|
|
107
|
+
for (String key : oldPreferences.keys()) {
|
|
108
|
+
String value = oldPreferences.get(key);
|
|
109
|
+
String currentValue = preferences.get(key);
|
|
110
|
+
|
|
111
|
+
if (currentValue == null) {
|
|
112
|
+
preferences.set(key, value);
|
|
113
|
+
migrated.add(key);
|
|
114
|
+
} else {
|
|
115
|
+
existing.add(key);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
JSObject ret = new JSObject();
|
|
120
|
+
ret.put("migrated", new JSArray(migrated));
|
|
121
|
+
ret.put("existing", new JSArray(existing));
|
|
122
|
+
call.resolve(ret);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@PluginMethod
|
|
126
|
+
public void removeOld(PluginCall call) {
|
|
127
|
+
call.resolve();
|
|
128
|
+
}
|
|
129
|
+
}
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "PreferencesPlugin",
|
|
4
|
+
"slug": "preferencesplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "configure",
|
|
10
|
+
"signature": "(options: ConfigureOptions) => Promise<void>",
|
|
11
|
+
"parameters": [
|
|
12
|
+
{
|
|
13
|
+
"name": "options",
|
|
14
|
+
"docs": "",
|
|
15
|
+
"type": "ConfigureOptions"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"returns": "Promise<void>",
|
|
19
|
+
"tags": [
|
|
20
|
+
{
|
|
21
|
+
"name": "since",
|
|
22
|
+
"text": "1.0.0"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"docs": "Configure the preferences plugin at runtime.\n\nOptions that are `undefined` will not be used.",
|
|
26
|
+
"complexTypes": [
|
|
27
|
+
"ConfigureOptions"
|
|
28
|
+
],
|
|
29
|
+
"slug": "configure"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "get",
|
|
33
|
+
"signature": "(options: GetOptions) => Promise<GetResult>",
|
|
34
|
+
"parameters": [
|
|
35
|
+
{
|
|
36
|
+
"name": "options",
|
|
37
|
+
"docs": "",
|
|
38
|
+
"type": "GetOptions"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"returns": "Promise<GetResult>",
|
|
42
|
+
"tags": [
|
|
43
|
+
{
|
|
44
|
+
"name": "since",
|
|
45
|
+
"text": "1.0.0"
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
"docs": "Get the value from preferences of a given key.",
|
|
49
|
+
"complexTypes": [
|
|
50
|
+
"GetResult",
|
|
51
|
+
"GetOptions"
|
|
52
|
+
],
|
|
53
|
+
"slug": "get"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "set",
|
|
57
|
+
"signature": "(options: SetOptions) => Promise<void>",
|
|
58
|
+
"parameters": [
|
|
59
|
+
{
|
|
60
|
+
"name": "options",
|
|
61
|
+
"docs": "",
|
|
62
|
+
"type": "SetOptions"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"returns": "Promise<void>",
|
|
66
|
+
"tags": [
|
|
67
|
+
{
|
|
68
|
+
"name": "since",
|
|
69
|
+
"text": "1.0.0"
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"docs": "Set the value in preferences for a given key.",
|
|
73
|
+
"complexTypes": [
|
|
74
|
+
"SetOptions"
|
|
75
|
+
],
|
|
76
|
+
"slug": "set"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"name": "remove",
|
|
80
|
+
"signature": "(options: RemoveOptions) => Promise<void>",
|
|
81
|
+
"parameters": [
|
|
82
|
+
{
|
|
83
|
+
"name": "options",
|
|
84
|
+
"docs": "",
|
|
85
|
+
"type": "RemoveOptions"
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
"returns": "Promise<void>",
|
|
89
|
+
"tags": [
|
|
90
|
+
{
|
|
91
|
+
"name": "since",
|
|
92
|
+
"text": "1.0.0"
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"docs": "Remove the value from preferences for a given key, if any.",
|
|
96
|
+
"complexTypes": [
|
|
97
|
+
"RemoveOptions"
|
|
98
|
+
],
|
|
99
|
+
"slug": "remove"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "clear",
|
|
103
|
+
"signature": "() => Promise<void>",
|
|
104
|
+
"parameters": [],
|
|
105
|
+
"returns": "Promise<void>",
|
|
106
|
+
"tags": [
|
|
107
|
+
{
|
|
108
|
+
"name": "since",
|
|
109
|
+
"text": "1.0.0"
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"docs": "Clear keys and values from preferences.",
|
|
113
|
+
"complexTypes": [],
|
|
114
|
+
"slug": "clear"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"name": "keys",
|
|
118
|
+
"signature": "() => Promise<KeysResult>",
|
|
119
|
+
"parameters": [],
|
|
120
|
+
"returns": "Promise<KeysResult>",
|
|
121
|
+
"tags": [
|
|
122
|
+
{
|
|
123
|
+
"name": "since",
|
|
124
|
+
"text": "1.0.0"
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
"docs": "Return the list of known keys in preferences.",
|
|
128
|
+
"complexTypes": [
|
|
129
|
+
"KeysResult"
|
|
130
|
+
],
|
|
131
|
+
"slug": "keys"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"name": "migrate",
|
|
135
|
+
"signature": "() => Promise<MigrateResult>",
|
|
136
|
+
"parameters": [],
|
|
137
|
+
"returns": "Promise<MigrateResult>",
|
|
138
|
+
"tags": [
|
|
139
|
+
{
|
|
140
|
+
"name": "since",
|
|
141
|
+
"text": "1.0.0"
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
"docs": "Migrate data from the Capacitor 2 Storage plugin.\n\nThis action is non-destructive. It will not remove old data and will only\nwrite new data if they key was not already set.\nTo remove the old data after being migrated, call removeOld().",
|
|
145
|
+
"complexTypes": [
|
|
146
|
+
"MigrateResult"
|
|
147
|
+
],
|
|
148
|
+
"slug": "migrate"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "removeOld",
|
|
152
|
+
"signature": "() => Promise<void>",
|
|
153
|
+
"parameters": [],
|
|
154
|
+
"returns": "Promise<void>",
|
|
155
|
+
"tags": [
|
|
156
|
+
{
|
|
157
|
+
"name": "since",
|
|
158
|
+
"text": "1.1.0"
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
"docs": "Removes old data with `_cap_` prefix from the Capacitor 2 Storage plugin.",
|
|
162
|
+
"complexTypes": [],
|
|
163
|
+
"slug": "removeold"
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
"properties": []
|
|
167
|
+
},
|
|
168
|
+
"interfaces": [
|
|
169
|
+
{
|
|
170
|
+
"name": "ConfigureOptions",
|
|
171
|
+
"slug": "configureoptions",
|
|
172
|
+
"docs": "",
|
|
173
|
+
"tags": [],
|
|
174
|
+
"methods": [],
|
|
175
|
+
"properties": [
|
|
176
|
+
{
|
|
177
|
+
"name": "group",
|
|
178
|
+
"tags": [
|
|
179
|
+
{
|
|
180
|
+
"text": "CapacitorStorage",
|
|
181
|
+
"name": "default"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"text": "1.0.0",
|
|
185
|
+
"name": "since"
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
"docs": "Set the preferences group.\n\nPreferences groups are used to organize key/value pairs.\n\nUsing the value 'NativeStorage' provides backwards-compatibility with\n[`cordova-plugin-nativestorage`](https://www.npmjs.com/package/cordova-plugin-nativestorage).\nWARNING: The `clear()` method can delete unintended values when using the\n'NativeStorage' group.",
|
|
189
|
+
"complexTypes": [],
|
|
190
|
+
"type": "string | undefined"
|
|
191
|
+
}
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"name": "GetResult",
|
|
196
|
+
"slug": "getresult",
|
|
197
|
+
"docs": "",
|
|
198
|
+
"tags": [],
|
|
199
|
+
"methods": [],
|
|
200
|
+
"properties": [
|
|
201
|
+
{
|
|
202
|
+
"name": "value",
|
|
203
|
+
"tags": [
|
|
204
|
+
{
|
|
205
|
+
"text": "1.0.0",
|
|
206
|
+
"name": "since"
|
|
207
|
+
}
|
|
208
|
+
],
|
|
209
|
+
"docs": "The value from preferences associated with the given key.\n\nIf a value was not previously set or was removed, value will be `null`.",
|
|
210
|
+
"complexTypes": [],
|
|
211
|
+
"type": "string | null"
|
|
212
|
+
}
|
|
213
|
+
]
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"name": "GetOptions",
|
|
217
|
+
"slug": "getoptions",
|
|
218
|
+
"docs": "",
|
|
219
|
+
"tags": [],
|
|
220
|
+
"methods": [],
|
|
221
|
+
"properties": [
|
|
222
|
+
{
|
|
223
|
+
"name": "key",
|
|
224
|
+
"tags": [
|
|
225
|
+
{
|
|
226
|
+
"text": "1.0.0",
|
|
227
|
+
"name": "since"
|
|
228
|
+
}
|
|
229
|
+
],
|
|
230
|
+
"docs": "The key whose value to retrieve from preferences.",
|
|
231
|
+
"complexTypes": [],
|
|
232
|
+
"type": "string"
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"name": "SetOptions",
|
|
238
|
+
"slug": "setoptions",
|
|
239
|
+
"docs": "",
|
|
240
|
+
"tags": [],
|
|
241
|
+
"methods": [],
|
|
242
|
+
"properties": [
|
|
243
|
+
{
|
|
244
|
+
"name": "key",
|
|
245
|
+
"tags": [
|
|
246
|
+
{
|
|
247
|
+
"text": "1.0.0",
|
|
248
|
+
"name": "since"
|
|
249
|
+
}
|
|
250
|
+
],
|
|
251
|
+
"docs": "The key to associate with the value being set in preferences.",
|
|
252
|
+
"complexTypes": [],
|
|
253
|
+
"type": "string"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
"name": "value",
|
|
257
|
+
"tags": [
|
|
258
|
+
{
|
|
259
|
+
"text": "1.0.0",
|
|
260
|
+
"name": "since"
|
|
261
|
+
}
|
|
262
|
+
],
|
|
263
|
+
"docs": "The value to set in preferences with the associated key.",
|
|
264
|
+
"complexTypes": [],
|
|
265
|
+
"type": "string"
|
|
266
|
+
}
|
|
267
|
+
]
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"name": "RemoveOptions",
|
|
271
|
+
"slug": "removeoptions",
|
|
272
|
+
"docs": "",
|
|
273
|
+
"tags": [],
|
|
274
|
+
"methods": [],
|
|
275
|
+
"properties": [
|
|
276
|
+
{
|
|
277
|
+
"name": "key",
|
|
278
|
+
"tags": [
|
|
279
|
+
{
|
|
280
|
+
"text": "1.0.0",
|
|
281
|
+
"name": "since"
|
|
282
|
+
}
|
|
283
|
+
],
|
|
284
|
+
"docs": "The key whose value to remove from preferences.",
|
|
285
|
+
"complexTypes": [],
|
|
286
|
+
"type": "string"
|
|
287
|
+
}
|
|
288
|
+
]
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
"name": "KeysResult",
|
|
292
|
+
"slug": "keysresult",
|
|
293
|
+
"docs": "",
|
|
294
|
+
"tags": [],
|
|
295
|
+
"methods": [],
|
|
296
|
+
"properties": [
|
|
297
|
+
{
|
|
298
|
+
"name": "keys",
|
|
299
|
+
"tags": [
|
|
300
|
+
{
|
|
301
|
+
"text": "1.0.0",
|
|
302
|
+
"name": "since"
|
|
303
|
+
}
|
|
304
|
+
],
|
|
305
|
+
"docs": "The known keys in preferences.",
|
|
306
|
+
"complexTypes": [],
|
|
307
|
+
"type": "string[]"
|
|
308
|
+
}
|
|
309
|
+
]
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
"name": "MigrateResult",
|
|
313
|
+
"slug": "migrateresult",
|
|
314
|
+
"docs": "",
|
|
315
|
+
"tags": [],
|
|
316
|
+
"methods": [],
|
|
317
|
+
"properties": [
|
|
318
|
+
{
|
|
319
|
+
"name": "migrated",
|
|
320
|
+
"tags": [
|
|
321
|
+
{
|
|
322
|
+
"text": "1.0.0",
|
|
323
|
+
"name": "since"
|
|
324
|
+
}
|
|
325
|
+
],
|
|
326
|
+
"docs": "An array of keys that were migrated.",
|
|
327
|
+
"complexTypes": [],
|
|
328
|
+
"type": "string[]"
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
"name": "existing",
|
|
332
|
+
"tags": [
|
|
333
|
+
{
|
|
334
|
+
"text": "1.0.0",
|
|
335
|
+
"name": "since"
|
|
336
|
+
}
|
|
337
|
+
],
|
|
338
|
+
"docs": "An array of keys that were already migrated or otherwise exist in preferences\nthat had a value in the Capacitor 2 Preferences plugin.",
|
|
339
|
+
"complexTypes": [],
|
|
340
|
+
"type": "string[]"
|
|
341
|
+
}
|
|
342
|
+
]
|
|
343
|
+
}
|
|
344
|
+
],
|
|
345
|
+
"enums": [],
|
|
346
|
+
"typeAliases": [],
|
|
347
|
+
"pluginConfigs": []
|
|
348
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
export interface ConfigureOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Set the preferences group.
|
|
4
|
+
*
|
|
5
|
+
* Preferences groups are used to organize key/value pairs.
|
|
6
|
+
*
|
|
7
|
+
* Using the value 'NativeStorage' provides backwards-compatibility with
|
|
8
|
+
* [`cordova-plugin-nativestorage`](https://www.npmjs.com/package/cordova-plugin-nativestorage).
|
|
9
|
+
* WARNING: The `clear()` method can delete unintended values when using the
|
|
10
|
+
* 'NativeStorage' group.
|
|
11
|
+
*
|
|
12
|
+
* @default CapacitorStorage
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
group?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface GetOptions {
|
|
18
|
+
/**
|
|
19
|
+
* The key whose value to retrieve from preferences.
|
|
20
|
+
*
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
*/
|
|
23
|
+
key: string;
|
|
24
|
+
}
|
|
25
|
+
export interface GetResult {
|
|
26
|
+
/**
|
|
27
|
+
* The value from preferences associated with the given key.
|
|
28
|
+
*
|
|
29
|
+
* If a value was not previously set or was removed, value will be `null`.
|
|
30
|
+
*
|
|
31
|
+
* @since 1.0.0
|
|
32
|
+
*/
|
|
33
|
+
value: string | null;
|
|
34
|
+
}
|
|
35
|
+
export interface SetOptions {
|
|
36
|
+
/**
|
|
37
|
+
* The key to associate with the value being set in preferences.
|
|
38
|
+
*
|
|
39
|
+
* @since 1.0.0
|
|
40
|
+
*/
|
|
41
|
+
key: string;
|
|
42
|
+
/**
|
|
43
|
+
* The value to set in preferences with the associated key.
|
|
44
|
+
*
|
|
45
|
+
* @since 1.0.0
|
|
46
|
+
*/
|
|
47
|
+
value: string;
|
|
48
|
+
}
|
|
49
|
+
export interface RemoveOptions {
|
|
50
|
+
/**
|
|
51
|
+
* The key whose value to remove from preferences.
|
|
52
|
+
*
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
*/
|
|
55
|
+
key: string;
|
|
56
|
+
}
|
|
57
|
+
export interface KeysResult {
|
|
58
|
+
/**
|
|
59
|
+
* The known keys in preferences.
|
|
60
|
+
*
|
|
61
|
+
* @since 1.0.0
|
|
62
|
+
*/
|
|
63
|
+
keys: string[];
|
|
64
|
+
}
|
|
65
|
+
export interface MigrateResult {
|
|
66
|
+
/**
|
|
67
|
+
* An array of keys that were migrated.
|
|
68
|
+
*
|
|
69
|
+
* @since 1.0.0
|
|
70
|
+
*/
|
|
71
|
+
migrated: string[];
|
|
72
|
+
/**
|
|
73
|
+
* An array of keys that were already migrated or otherwise exist in preferences
|
|
74
|
+
* that had a value in the Capacitor 2 Preferences plugin.
|
|
75
|
+
*
|
|
76
|
+
* @since 1.0.0
|
|
77
|
+
*/
|
|
78
|
+
existing: string[];
|
|
79
|
+
}
|
|
80
|
+
export interface PreferencesPlugin {
|
|
81
|
+
/**
|
|
82
|
+
* Configure the preferences plugin at runtime.
|
|
83
|
+
*
|
|
84
|
+
* Options that are `undefined` will not be used.
|
|
85
|
+
*
|
|
86
|
+
* @since 1.0.0
|
|
87
|
+
*/
|
|
88
|
+
configure(options: ConfigureOptions): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Get the value from preferences of a given key.
|
|
91
|
+
*
|
|
92
|
+
* @since 1.0.0
|
|
93
|
+
*/
|
|
94
|
+
get(options: GetOptions): Promise<GetResult>;
|
|
95
|
+
/**
|
|
96
|
+
* Set the value in preferences for a given key.
|
|
97
|
+
*
|
|
98
|
+
* @since 1.0.0
|
|
99
|
+
*/
|
|
100
|
+
set(options: SetOptions): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Remove the value from preferences for a given key, if any.
|
|
103
|
+
*
|
|
104
|
+
* @since 1.0.0
|
|
105
|
+
*/
|
|
106
|
+
remove(options: RemoveOptions): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Clear keys and values from preferences.
|
|
109
|
+
*
|
|
110
|
+
* @since 1.0.0
|
|
111
|
+
*/
|
|
112
|
+
clear(): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Return the list of known keys in preferences.
|
|
115
|
+
*
|
|
116
|
+
* @since 1.0.0
|
|
117
|
+
*/
|
|
118
|
+
keys(): Promise<KeysResult>;
|
|
119
|
+
/**
|
|
120
|
+
* Migrate data from the Capacitor 2 Storage plugin.
|
|
121
|
+
*
|
|
122
|
+
* This action is non-destructive. It will not remove old data and will only
|
|
123
|
+
* write new data if they key was not already set.
|
|
124
|
+
* To remove the old data after being migrated, call removeOld().
|
|
125
|
+
*
|
|
126
|
+
* @since 1.0.0
|
|
127
|
+
*/
|
|
128
|
+
migrate(): Promise<MigrateResult>;
|
|
129
|
+
/**
|
|
130
|
+
* Removes old data with `_cap_` prefix from the Capacitor 2 Storage plugin.
|
|
131
|
+
*
|
|
132
|
+
* @since 1.1.0
|
|
133
|
+
*/
|
|
134
|
+
removeOld(): Promise<void>;
|
|
135
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface ConfigureOptions {\n /**\n * Set the preferences group.\n *\n * Preferences groups are used to organize key/value pairs.\n *\n * Using the value 'NativeStorage' provides backwards-compatibility with\n * [`cordova-plugin-nativestorage`](https://www.npmjs.com/package/cordova-plugin-nativestorage).\n * WARNING: The `clear()` method can delete unintended values when using the\n * 'NativeStorage' group.\n *\n * @default CapacitorStorage\n * @since 1.0.0\n */\n group?: string;\n}\n\nexport interface GetOptions {\n /**\n * The key whose value to retrieve from preferences.\n *\n * @since 1.0.0\n */\n key: string;\n}\n\nexport interface GetResult {\n /**\n * The value from preferences associated with the given key.\n *\n * If a value was not previously set or was removed, value will be `null`.\n *\n * @since 1.0.0\n */\n value: string | null;\n}\n\nexport interface SetOptions {\n /**\n * The key to associate with the value being set in preferences.\n *\n * @since 1.0.0\n */\n key: string;\n\n /**\n * The value to set in preferences with the associated key.\n *\n * @since 1.0.0\n */\n value: string;\n}\n\nexport interface RemoveOptions {\n /**\n * The key whose value to remove from preferences.\n *\n * @since 1.0.0\n */\n key: string;\n}\n\nexport interface KeysResult {\n /**\n * The known keys in preferences.\n *\n * @since 1.0.0\n */\n keys: string[];\n}\n\nexport interface MigrateResult {\n /**\n * An array of keys that were migrated.\n *\n * @since 1.0.0\n */\n migrated: string[];\n\n /**\n * An array of keys that were already migrated or otherwise exist in preferences\n * that had a value in the Capacitor 2 Preferences plugin.\n *\n * @since 1.0.0\n */\n existing: string[];\n}\n\nexport interface PreferencesPlugin {\n /**\n * Configure the preferences plugin at runtime.\n *\n * Options that are `undefined` will not be used.\n *\n * @since 1.0.0\n */\n configure(options: ConfigureOptions): Promise<void>;\n\n /**\n * Get the value from preferences of a given key.\n *\n * @since 1.0.0\n */\n get(options: GetOptions): Promise<GetResult>;\n\n /**\n * Set the value in preferences for a given key.\n *\n * @since 1.0.0\n */\n set(options: SetOptions): Promise<void>;\n\n /**\n * Remove the value from preferences for a given key, if any.\n *\n * @since 1.0.0\n */\n remove(options: RemoveOptions): Promise<void>;\n\n /**\n * Clear keys and values from preferences.\n *\n * @since 1.0.0\n */\n clear(): Promise<void>;\n\n /**\n * Return the list of known keys in preferences.\n *\n * @since 1.0.0\n */\n keys(): Promise<KeysResult>;\n\n /**\n * Migrate data from the Capacitor 2 Storage plugin.\n *\n * This action is non-destructive. It will not remove old data and will only\n * write new data if they key was not already set.\n * To remove the old data after being migrated, call removeOld().\n *\n * @since 1.0.0\n */\n migrate(): Promise<MigrateResult>;\n\n /**\n * Removes old data with `_cap_` prefix from the Capacitor 2 Storage plugin.\n *\n * @since 1.1.0\n */\n removeOld(): Promise<void>;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const Preferences = registerPlugin('Preferences', {
|
|
3
|
+
web: () => import('./web').then(m => new m.PreferencesWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { Preferences };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|