amplifyquery 1.0.20 → 2.0.1
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/README.md +11 -0
- package/dist/config.d.ts +8 -1
- package/dist/config.js +36 -6
- package/dist/index.d.ts +0 -62
- package/dist/index.js +6 -4
- package/dist/query.js +60 -29
- package/dist/service.js +336 -112
- package/dist/singleton.js +85 -95
- package/dist/types.d.ts +23 -0
- package/dist/utils.d.ts +0 -72
- package/dist/utils.js +20 -262
- package/package.json +14 -17
package/dist/utils.js
CHANGED
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -53,19 +20,28 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
53
20
|
return t;
|
|
54
21
|
};
|
|
55
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
|
-
exports.AuthService = exports.
|
|
23
|
+
exports.AuthService = exports.Utils = void 0;
|
|
57
24
|
exports.setAppUrl = setAppUrl;
|
|
58
25
|
exports.getAppUrl = getAppUrl;
|
|
59
26
|
exports.createRelationalHook = createRelationalHook;
|
|
60
27
|
const react_query_1 = require("@tanstack/react-query");
|
|
61
28
|
const auth_1 = require("aws-amplify/auth");
|
|
62
|
-
const storage_1 = require("aws-amplify/storage");
|
|
63
|
-
const expo_crypto_1 = require("expo-crypto");
|
|
64
|
-
const FileSystem = __importStar(require("expo-file-system"));
|
|
65
29
|
const react_1 = require("react");
|
|
66
|
-
const
|
|
30
|
+
const config_1 = require("./config");
|
|
31
|
+
function createMmkvStorage(id) {
|
|
32
|
+
// Support both react-native-mmkv v3 (class MMKV) and v4 (createMMKV factory)
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
34
|
+
const mmkv = require("react-native-mmkv");
|
|
35
|
+
if (typeof mmkv.createMMKV === "function") {
|
|
36
|
+
return mmkv.createMMKV({ id });
|
|
37
|
+
}
|
|
38
|
+
if (typeof mmkv.MMKV === "function") {
|
|
39
|
+
return new mmkv.MMKV({ id });
|
|
40
|
+
}
|
|
41
|
+
throw new Error("react-native-mmkv is not available in this runtime");
|
|
42
|
+
}
|
|
67
43
|
// Create MMKV storage instance
|
|
68
|
-
const storage =
|
|
44
|
+
const storage = createMmkvStorage("mmkv.amplify-query");
|
|
69
45
|
// Key for managing app URL
|
|
70
46
|
const APP_URL_KEY = "amplify_query_app_url";
|
|
71
47
|
/**
|
|
@@ -122,230 +98,11 @@ exports.Utils = {
|
|
|
122
98
|
removeOwnerField: (data, operation) => {
|
|
123
99
|
const { owner } = data, dataWithoutOwner = __rest(data, ["owner"]);
|
|
124
100
|
if (owner) {
|
|
125
|
-
|
|
101
|
+
(0, config_1.debugWarn)(`The owner field exists. This field is added automatically and will be excluded from the ${operation} operation.`);
|
|
126
102
|
}
|
|
127
103
|
return dataWithoutOwner;
|
|
128
104
|
},
|
|
129
105
|
};
|
|
130
|
-
/**
|
|
131
|
-
* Storage related utilities
|
|
132
|
-
*/
|
|
133
|
-
exports.StorageService = {
|
|
134
|
-
// URL cache internal type definition
|
|
135
|
-
_types: {
|
|
136
|
-
// URL cache interface (used internally only)
|
|
137
|
-
Item: {},
|
|
138
|
-
// Cache data structure (stored as key-value)
|
|
139
|
-
CacheData: {},
|
|
140
|
-
},
|
|
141
|
-
// Memory cache (for fast access)
|
|
142
|
-
_urlCache: new Map(),
|
|
143
|
-
// MMKV cache storage key
|
|
144
|
-
_CACHE_KEY: "storage_url_cache",
|
|
145
|
-
// Initialization status
|
|
146
|
-
_initialized: false,
|
|
147
|
-
/**
|
|
148
|
-
* Initialize the memory cache.
|
|
149
|
-
* Loads URL cache from MMKV storage.
|
|
150
|
-
*/
|
|
151
|
-
_initCache: () => {
|
|
152
|
-
if (exports.StorageService._initialized)
|
|
153
|
-
return;
|
|
154
|
-
try {
|
|
155
|
-
// Retrieve URL cache data from MMKV
|
|
156
|
-
const cachedData = storage.getString(exports.StorageService._CACHE_KEY);
|
|
157
|
-
// Restore to memory cache
|
|
158
|
-
if (cachedData && cachedData.length > 0) {
|
|
159
|
-
const parsedData = JSON.parse(cachedData);
|
|
160
|
-
const now = Date.now();
|
|
161
|
-
// Add only non-expired items to memory cache
|
|
162
|
-
Object.entries(parsedData).forEach(([key, item]) => {
|
|
163
|
-
if (item.expiresAt > now) {
|
|
164
|
-
exports.StorageService._urlCache.set(key, {
|
|
165
|
-
url: item.url,
|
|
166
|
-
expiresAt: item.expiresAt,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
exports.StorageService._initialized = true;
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
console.error("URL cache initialization error:", error);
|
|
175
|
-
// Clear cache on error
|
|
176
|
-
exports.StorageService.clearUrlCache();
|
|
177
|
-
exports.StorageService._initialized = true;
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
/**
|
|
181
|
-
* Save cache to MMKV storage.
|
|
182
|
-
*/
|
|
183
|
-
_saveCache: () => {
|
|
184
|
-
try {
|
|
185
|
-
const cacheData = {};
|
|
186
|
-
// Convert memory cache to persistent storage format
|
|
187
|
-
exports.StorageService._urlCache.forEach((item, key) => {
|
|
188
|
-
cacheData[key] = {
|
|
189
|
-
url: item.url,
|
|
190
|
-
expiresAt: item.expiresAt,
|
|
191
|
-
};
|
|
192
|
-
});
|
|
193
|
-
// Save to MMKV
|
|
194
|
-
storage.set(exports.StorageService._CACHE_KEY, JSON.stringify(cacheData));
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
console.error("URL cache save error:", error);
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
/**
|
|
201
|
-
* Upload an image file to Storage.
|
|
202
|
-
* @param file File to upload (Blob or File object)
|
|
203
|
-
* @param key Path and filename to save as (auto-generated if not specified)
|
|
204
|
-
* @returns Key of the uploaded file
|
|
205
|
-
*/
|
|
206
|
-
uploadImage: (file, key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
207
|
-
try {
|
|
208
|
-
const fileKey = key || `images/${(0, expo_crypto_1.randomUUID)()}.${file.type.split("/")[1] || "jpg"}`;
|
|
209
|
-
const result = yield (0, storage_1.uploadData)({
|
|
210
|
-
path: fileKey,
|
|
211
|
-
data: file,
|
|
212
|
-
options: {
|
|
213
|
-
contentType: file.type,
|
|
214
|
-
},
|
|
215
|
-
}).result;
|
|
216
|
-
return result.path;
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
console.error("File upload failed:", error);
|
|
220
|
-
throw error;
|
|
221
|
-
}
|
|
222
|
-
}),
|
|
223
|
-
/**
|
|
224
|
-
* Get the URL of a stored file. (Auto-caching)
|
|
225
|
-
* @param key File key
|
|
226
|
-
* @param options Caching options (forceRefresh: ignore cache and fetch new URL)
|
|
227
|
-
* @returns File URL
|
|
228
|
-
*/
|
|
229
|
-
getFileUrl: (key, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
230
|
-
try {
|
|
231
|
-
// Initialize cache (only runs on first call)
|
|
232
|
-
if (!exports.StorageService._initialized) {
|
|
233
|
-
exports.StorageService._initCache();
|
|
234
|
-
}
|
|
235
|
-
// If not ignoring cache and URL is in cache, return from cache
|
|
236
|
-
const cachedItem = exports.StorageService._urlCache.get(key);
|
|
237
|
-
const now = Date.now();
|
|
238
|
-
// If cached URL exists, is not expired, and not forced refresh
|
|
239
|
-
if (cachedItem && cachedItem.expiresAt > now && !(options === null || options === void 0 ? void 0 : options.forceRefresh)) {
|
|
240
|
-
return cachedItem.url;
|
|
241
|
-
}
|
|
242
|
-
// If not in cache, expired, or forced refresh, get new URL
|
|
243
|
-
// Number of seconds till the URL expires.
|
|
244
|
-
// The expiration time of the presigned url is dependent on the session and will max out at 1 hour.
|
|
245
|
-
const result = yield (0, storage_1.getUrl)({
|
|
246
|
-
path: key,
|
|
247
|
-
options: {
|
|
248
|
-
// Default 1 hour expiration, adjustable if needed
|
|
249
|
-
expiresIn: 60 * 60, // 1 hour
|
|
250
|
-
},
|
|
251
|
-
});
|
|
252
|
-
const url = result.url.toString();
|
|
253
|
-
// Convert expiration time to timestamp
|
|
254
|
-
const expiresAt = result.expiresAt.getTime();
|
|
255
|
-
// Save to cache
|
|
256
|
-
exports.StorageService._urlCache.set(key, {
|
|
257
|
-
url,
|
|
258
|
-
expiresAt,
|
|
259
|
-
});
|
|
260
|
-
// Also save to persistent storage
|
|
261
|
-
exports.StorageService._saveCache();
|
|
262
|
-
return url;
|
|
263
|
-
}
|
|
264
|
-
catch (error) {
|
|
265
|
-
console.error("Failed to get file URL:", error);
|
|
266
|
-
throw error;
|
|
267
|
-
}
|
|
268
|
-
}),
|
|
269
|
-
/**
|
|
270
|
-
* Delete a stored file.
|
|
271
|
-
* @param key Key of the file to delete
|
|
272
|
-
*/
|
|
273
|
-
deleteFile: (key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
274
|
-
try {
|
|
275
|
-
yield (0, storage_1.remove)({ path: key });
|
|
276
|
-
// Remove from cache on file deletion
|
|
277
|
-
exports.StorageService._urlCache.delete(key);
|
|
278
|
-
// Update persistent storage
|
|
279
|
-
exports.StorageService._saveCache();
|
|
280
|
-
}
|
|
281
|
-
catch (error) {
|
|
282
|
-
console.error("File deletion failed:", error);
|
|
283
|
-
throw error;
|
|
284
|
-
}
|
|
285
|
-
}),
|
|
286
|
-
/**
|
|
287
|
-
* Clear the URL cache.
|
|
288
|
-
*/
|
|
289
|
-
clearUrlCache: () => {
|
|
290
|
-
exports.StorageService._urlCache.clear();
|
|
291
|
-
storage.delete(exports.StorageService._CACHE_KEY);
|
|
292
|
-
},
|
|
293
|
-
/**
|
|
294
|
-
* Remove a specific key's URL cache.
|
|
295
|
-
* @param key Key of the URL to remove
|
|
296
|
-
*/
|
|
297
|
-
clearUrlCacheForKey: (key) => {
|
|
298
|
-
exports.StorageService._urlCache.delete(key);
|
|
299
|
-
// Update persistent storage
|
|
300
|
-
exports.StorageService._saveCache();
|
|
301
|
-
},
|
|
302
|
-
/**
|
|
303
|
-
* Remove only expired URL caches.
|
|
304
|
-
*/
|
|
305
|
-
clearExpiredUrlCache: () => {
|
|
306
|
-
const now = Date.now();
|
|
307
|
-
for (const [key, item] of exports.StorageService._urlCache.entries()) {
|
|
308
|
-
if (item.expiresAt <= now) {
|
|
309
|
-
exports.StorageService._urlCache.delete(key);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
// Update persistent storage
|
|
313
|
-
exports.StorageService._saveCache();
|
|
314
|
-
},
|
|
315
|
-
/**
|
|
316
|
-
* Download an audio file.
|
|
317
|
-
* @param audioKey Key of the audio file to download
|
|
318
|
-
* @returns Local file system path of the downloaded file
|
|
319
|
-
*/
|
|
320
|
-
downloadAudioFile: (audioKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
321
|
-
try {
|
|
322
|
-
// Create directory path where the file will be saved
|
|
323
|
-
const audioDir = `${FileSystem.cacheDirectory}sounds/`;
|
|
324
|
-
const localFilePath = `${audioDir}${audioKey}`;
|
|
325
|
-
// Check if directory exists, create if not
|
|
326
|
-
const dirInfo = yield FileSystem.getInfoAsync(audioDir);
|
|
327
|
-
if (!dirInfo.exists) {
|
|
328
|
-
yield FileSystem.makeDirectoryAsync(audioDir, { intermediates: true });
|
|
329
|
-
}
|
|
330
|
-
// Check if file already exists
|
|
331
|
-
const fileInfo = yield FileSystem.getInfoAsync(localFilePath);
|
|
332
|
-
if (fileInfo.exists) {
|
|
333
|
-
console.log("Audio file already exists locally:", localFilePath);
|
|
334
|
-
return localFilePath;
|
|
335
|
-
}
|
|
336
|
-
// Get file URL from S3
|
|
337
|
-
const s3Url = yield (0, storage_1.getUrl)({ path: `public/sound/${audioKey}` });
|
|
338
|
-
// Download file
|
|
339
|
-
const downloadResult = yield FileSystem.downloadAsync(s3Url.url.toString(), localFilePath);
|
|
340
|
-
console.log("Audio file downloaded successfully:", downloadResult.uri);
|
|
341
|
-
return downloadResult.uri;
|
|
342
|
-
}
|
|
343
|
-
catch (error) {
|
|
344
|
-
console.error("Audio file download failed:", error);
|
|
345
|
-
throw error;
|
|
346
|
-
}
|
|
347
|
-
}),
|
|
348
|
-
};
|
|
349
106
|
/**
|
|
350
107
|
* Authentication related utilities
|
|
351
108
|
*/
|
|
@@ -424,9 +181,10 @@ function createRelationalHook(service, relationName, queryName, idParamName = `$
|
|
|
424
181
|
error,
|
|
425
182
|
getItem: baseHook.getItem,
|
|
426
183
|
refresh: () => __awaiter(this, void 0, void 0, function* () {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
184
|
+
(0, config_1.debugLog)(`🍬 ${service.modelName} relational refresh called`, id);
|
|
185
|
+
// Always fetch from server (no cache) for refresh
|
|
186
|
+
const result = yield service.customList(queryName, { [idParamName]: id }, { forceRefresh: true, throwOnError: true });
|
|
187
|
+
return result || [];
|
|
430
188
|
}),
|
|
431
189
|
create: createItem, // ID-specific method
|
|
432
190
|
update: baseHook.update,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "amplifyquery",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Amplify+Query",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Amplify",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "expo-module build",
|
|
27
|
+
"build": "CI=1 expo-module build",
|
|
28
28
|
"clean": "expo-module clean",
|
|
29
29
|
"dev": "expo-module build --watch",
|
|
30
30
|
"lint": "expo-module lint",
|
|
@@ -34,34 +34,31 @@
|
|
|
34
34
|
"test": "expo-module test"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@aws-amplify/api": "^6.3.11",
|
|
38
|
-
"@aws-amplify/core": "^6.11.4",
|
|
39
|
-
"@aws-amplify/datastore": "^5.0.82",
|
|
40
37
|
"@babel/core": "^7.27.1",
|
|
41
38
|
"@react-native-async-storage/async-storage": "^2.1.2",
|
|
42
39
|
"@semantic-release/changelog": "^6.0.3",
|
|
43
40
|
"@semantic-release/git": "^10.0.1",
|
|
44
|
-
"@tanstack/react-query": "^5.76.1",
|
|
45
|
-
"@tanstack/react-query-persist-client": "^5.76.1",
|
|
46
41
|
"@types/react": "^19.1.4",
|
|
47
42
|
"amplify": "^0.0.11",
|
|
48
|
-
"aws-amplify": "^6.14.4",
|
|
49
43
|
"expo": "^53.0.9",
|
|
50
|
-
"expo-crypto": "^14.1.4",
|
|
51
|
-
"expo-file-system": "^18.1.10",
|
|
52
44
|
"expo-module-scripts": "^4.1.7",
|
|
53
|
-
"react": "^19.1.0",
|
|
54
|
-
"react-native": "^0.79.2",
|
|
55
|
-
"react-native-mmkv": "^3.2.0",
|
|
56
45
|
"semantic-release": "^24.2.5",
|
|
57
|
-
"
|
|
58
|
-
"zustand": "
|
|
46
|
+
"react-native-mmkv": "3.3.1",
|
|
47
|
+
"zustand": "*",
|
|
48
|
+
"@tanstack/react-query": "*",
|
|
49
|
+
"@tanstack/react-query-persist-client": "*",
|
|
50
|
+
"aws-amplify": "*",
|
|
51
|
+
"typescript": "^5.8.3"
|
|
59
52
|
},
|
|
60
53
|
"peerDependencies": {
|
|
61
54
|
"expo": ">=49",
|
|
62
55
|
"react": ">=19.1.0",
|
|
63
56
|
"react-native": ">=0.79.2",
|
|
64
|
-
"react-native-mmkv": "
|
|
65
|
-
"zustand": "
|
|
57
|
+
"react-native-mmkv": ">=3.3.1",
|
|
58
|
+
"zustand": ">=5.0.8",
|
|
59
|
+
"@tanstack/react-query": ">=5.90.10",
|
|
60
|
+
"@tanstack/react-query-persist-client": ">=5.90.12",
|
|
61
|
+
"aws-amplify": ">=6.15.8",
|
|
62
|
+
"expo-crypto": ">=14"
|
|
66
63
|
}
|
|
67
64
|
}
|