mnfst 0.5.277 → 0.5.279
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/lib/manifest.appwrite.data.js +1 -1
- package/lib/manifest.d.ts +2 -1
- package/lib/manifest.data.js +193 -46
- package/lib/manifest.integrity.json +3 -3
- package/lib/manifest.schema.json +14 -0
- package/lib/manifest.sw.js +1 -1
- package/package.json +1 -1
package/lib/manifest.d.ts
CHANGED
|
@@ -69,6 +69,8 @@ export interface ManifestSourceState {
|
|
|
69
69
|
readonly $stale: boolean;
|
|
70
70
|
/** Resolves once fresh data has landed. */
|
|
71
71
|
readonly $fresh: Promise<void>;
|
|
72
|
+
/** Fetch again; Appwrite tables keep the active `$query` and paged rows. */
|
|
73
|
+
$reload(): Promise<unknown>;
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
/** Fields Appwrite adds to every row. */
|
|
@@ -153,7 +155,6 @@ export interface ManifestAppwriteTableOps<T> {
|
|
|
153
155
|
$next(cursor: string, limit?: number): Promise<ManifestCursorPage<T>>;
|
|
154
156
|
$prev(cursor: string, limit?: number): Promise<ManifestCursorPage<T>>;
|
|
155
157
|
$page(page: number, limit?: number): Promise<ManifestOffsetPage<T>>;
|
|
156
|
-
$reload(): Promise<void>;
|
|
157
158
|
/** Realtime events skipped by the growth cap since the last load. */
|
|
158
159
|
readonly $realtimeOverflow: number;
|
|
159
160
|
/** Loads the next page into the source (`paging` sources only); resolves with the rows added. */
|
package/lib/manifest.data.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
(function () {
|
|
4
4
|
|
|
5
|
-
const MANIFEST_BUILD_VERSION = '0.5.
|
|
5
|
+
const MANIFEST_BUILD_VERSION = '0.5.279';
|
|
6
6
|
|
|
7
7
|
/* Manifest Data Sources - Configuration */
|
|
8
8
|
|
|
@@ -620,6 +620,7 @@ function endRead(dataSourceName, token) {
|
|
|
620
620
|
}
|
|
621
621
|
function readsInFlight(dataSourceName) { return inflightReads.has(dataSourceName); }
|
|
622
622
|
function currentRead(dataSourceName) { return latestRead.get(dataSourceName); }
|
|
623
|
+
function readSeqNow() { return readSeq; }
|
|
623
624
|
function adoptRead(dataSourceName, token) { if (token !== undefined) latestRead.set(dataSourceName, token); }
|
|
624
625
|
// A reset clears the record: generation stamps already drop the older reads
|
|
625
626
|
function isLatestRead(dataSourceName, token) { return token === undefined || !latestRead.has(dataSourceName) || latestRead.get(dataSourceName) === token; }
|
|
@@ -1766,6 +1767,7 @@ window.ManifestDataStore = {
|
|
|
1766
1767
|
readsInFlight,
|
|
1767
1768
|
adoptRead,
|
|
1768
1769
|
currentRead,
|
|
1770
|
+
readSeqNow,
|
|
1769
1771
|
compareBy,
|
|
1770
1772
|
loadReadTokens,
|
|
1771
1773
|
isLatestRead,
|
|
@@ -3135,7 +3137,7 @@ async function loadFromAPI(dataSource) {
|
|
|
3135
3137
|
});
|
|
3136
3138
|
|
|
3137
3139
|
if (!response.ok) {
|
|
3138
|
-
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
|
|
3140
|
+
throw Object.assign(new Error(`API request failed: ${response.status} ${response.statusText}`), { status: response.status });
|
|
3139
3141
|
}
|
|
3140
3142
|
|
|
3141
3143
|
let data = await response.json();
|
|
@@ -4566,6 +4568,12 @@ function attachArrayMethods(array, dataSourceName, reloadDataSource) {
|
|
|
4566
4568
|
writable: false,
|
|
4567
4569
|
value: () => window.ManifestDataMain.loadMore(dataSourceName)
|
|
4568
4570
|
});
|
|
4571
|
+
Object.defineProperty(array, '$reload', {
|
|
4572
|
+
enumerable: false,
|
|
4573
|
+
configurable: true,
|
|
4574
|
+
writable: false,
|
|
4575
|
+
value: () => window.ManifestDataMain.reloadSource(dataSourceName)
|
|
4576
|
+
});
|
|
4569
4577
|
Object.defineProperty(array, '$saving', {
|
|
4570
4578
|
enumerable: false,
|
|
4571
4579
|
configurable: true,
|
|
@@ -5250,6 +5258,9 @@ function createArrayProxyWithRoute(arrayTarget, dataSourceName = null, reloadDat
|
|
|
5250
5258
|
if (key === '$saving') {
|
|
5251
5259
|
return window.ManifestDataProxiesMagic.createSavingMethod(dataSourceName);
|
|
5252
5260
|
}
|
|
5261
|
+
if (key === '$reload') {
|
|
5262
|
+
return () => window.ManifestDataMain.reloadSource(dataSourceName);
|
|
5263
|
+
}
|
|
5253
5264
|
|
|
5254
5265
|
// Handle pagination methods
|
|
5255
5266
|
if (key === '$first' || key === '$next' || key === '$prev' || key === '$page') {
|
|
@@ -7958,7 +7969,8 @@ function createAppwriteMethodsHandler(dataSourceName, reloadDataSource) {
|
|
|
7958
7969
|
const sourceUnloaded = args[3]?.sourceUnloaded === true;
|
|
7959
7970
|
if (!sourceUnloaded) clearErrorState();
|
|
7960
7971
|
// Reads are ordered by call, not by network start: the last-issued one lands
|
|
7961
|
-
|
|
7972
|
+
let readToken = method === '$query' ? window.ManifestDataStore?.beginRead?.(dataSourceName) : undefined;
|
|
7973
|
+
let queryIntentRef = null;
|
|
7962
7974
|
|
|
7963
7975
|
try {
|
|
7964
7976
|
const manifest = await window.ManifestDataConfig?.ensureManifest?.();
|
|
@@ -8331,13 +8343,29 @@ function createAppwriteMethodsHandler(dataSourceName, reloadDataSource) {
|
|
|
8331
8343
|
}
|
|
8332
8344
|
queries = named;
|
|
8333
8345
|
}
|
|
8334
|
-
|
|
8335
|
-
|
|
8336
|
-
|
|
8337
|
-
|
|
8338
|
-
);
|
|
8346
|
+
window.ManifestDataStore?.setSourceState?.(dataSourceName, { loading: true });
|
|
8347
|
+
queryIntentRef = [...(queries || [])]; // own copy: a named query's array is shared
|
|
8348
|
+
window.ManifestDataMain?.noteQueryIntent?.(dataSourceName, queryIntentRef);
|
|
8349
|
+
// A $auth. value or scope not resolved yet: wait for auth once, then run
|
|
8350
|
+
const build = () => window.ManifestDataQueries.buildAppwriteQueries(queries || [], scope, scopeColumns);
|
|
8351
|
+
let appwriteQueries = await build();
|
|
8339
8352
|
if (appwriteQueries === null) {
|
|
8340
|
-
|
|
8353
|
+
const waiting = window.ManifestDataMain?.awaitingQueries;
|
|
8354
|
+
waiting?.add(dataSourceName);
|
|
8355
|
+
try {
|
|
8356
|
+
await window.ManifestDataMain?.waitForAuthChange?.();
|
|
8357
|
+
// Let any reload of this source already running finish, then run as the newest read
|
|
8358
|
+
window.ManifestDataStore?.endRead?.(dataSourceName, readToken);
|
|
8359
|
+
await window.ManifestDataMain?.settledReads?.(dataSourceName);
|
|
8360
|
+
} finally {
|
|
8361
|
+
waiting?.delete(dataSourceName);
|
|
8362
|
+
}
|
|
8363
|
+
readToken = window.ManifestDataStore?.beginRead?.(dataSourceName);
|
|
8364
|
+
window.ManifestDataStore?.setSourceState?.(dataSourceName, { loading: true });
|
|
8365
|
+
appwriteQueries = await build();
|
|
8366
|
+
}
|
|
8367
|
+
if (appwriteQueries === null) {
|
|
8368
|
+
throw new Error(`[Manifest Data] "${dataSourceName}" $query: auth not ready — sign in, or check the $auth. values in its queries`);
|
|
8341
8369
|
}
|
|
8342
8370
|
// Dedupe key: source + serialized queries (never across different queries)
|
|
8343
8371
|
const key = `${dataSourceName}:$query:${JSON.stringify(appwriteQueries.map(q => String(q)))}`;
|
|
@@ -8351,19 +8379,21 @@ function createAppwriteMethodsHandler(dataSourceName, reloadDataSource) {
|
|
|
8351
8379
|
let paged = null;
|
|
8352
8380
|
const run = spec
|
|
8353
8381
|
? async () => {
|
|
8354
|
-
|
|
8382
|
+
const fetchPaged = () => main.fetchPagedRows(dataSourceName, queries || [], {
|
|
8355
8383
|
want,
|
|
8356
8384
|
isCurrent: () => !isLatestRead || isLatestRead(dataSourceName, readToken)
|
|
8357
8385
|
});
|
|
8386
|
+
paged = await fetchPaged();
|
|
8387
|
+
if (paged === null) { await main.waitForAuthChange(); paged = await fetchPaged(); }
|
|
8358
8388
|
if (paged === null) throw new Error(`[Manifest Data] "${dataSourceName}" $query: auth not ready yet — retry after auth settles`);
|
|
8359
8389
|
return paged.rows;
|
|
8360
8390
|
}
|
|
8361
|
-
: () => window.ManifestDataAppwrite.loadTableRows(
|
|
8391
|
+
: () => (main?.withRetry || ((_, fn) => fn()))(dataSource, () => window.ManifestDataAppwrite.loadTableRows(
|
|
8362
8392
|
appwriteConfig.databaseId,
|
|
8363
8393
|
tableId,
|
|
8364
8394
|
appwriteQueries,
|
|
8365
8395
|
{ requireAuth }
|
|
8366
|
-
);
|
|
8396
|
+
), () => sourceGeneration?.(dataSourceName) === generation); // shared by identical calls: stop only on a reset
|
|
8367
8397
|
const result = (runDeduped && !spec) ? await runDeduped(key, run) : await run();
|
|
8368
8398
|
// Network landing: query result replaces the source (coalesced, identity-preserving);
|
|
8369
8399
|
// only the last-issued read of this source lands
|
|
@@ -9131,12 +9161,18 @@ function createAppwriteMethodsHandler(dataSourceName, reloadDataSource) {
|
|
|
9131
9161
|
|
|
9132
9162
|
throw new Error(`[Manifest Data] Method "${method}" not supported for this data source`);
|
|
9133
9163
|
} catch (error) {
|
|
9164
|
+
// A $query that failed is not what the source shows: a sign-in doesn't re-run it
|
|
9165
|
+
if (method === '$query') window.ManifestDataMain?.dropQueryIntent?.(dataSourceName, queryIntentRef);
|
|
9134
9166
|
// Automatically set error state - no need for inline .catch() in HTML
|
|
9135
9167
|
setErrorState(error);
|
|
9136
9168
|
// Re-throw so promise chain still works if caller wants to handle it
|
|
9137
9169
|
throw error;
|
|
9138
9170
|
} finally {
|
|
9139
|
-
if (readToken !== undefined)
|
|
9171
|
+
if (readToken !== undefined) {
|
|
9172
|
+
const ds = window.ManifestDataStore;
|
|
9173
|
+
ds?.endRead?.(dataSourceName, readToken);
|
|
9174
|
+
if (!ds?.readsInFlight?.(dataSourceName)) ds?.setSourceState?.(dataSourceName, { loading: false });
|
|
9175
|
+
}
|
|
9140
9176
|
}
|
|
9141
9177
|
};
|
|
9142
9178
|
|
|
@@ -9523,10 +9559,14 @@ function createPaginationMethod(methodName, dataSourceName) {
|
|
|
9523
9559
|
const active = window.ManifestDataMain?.getActiveQuery?.(dataSourceName);
|
|
9524
9560
|
const filters = (Array.isArray(active) ? active : (Array.isArray(defaults) ? defaults : []))
|
|
9525
9561
|
.filter(q => !(Array.isArray(q) && PAGE_WINDOW_METHODS.has(q[0])));
|
|
9526
|
-
|
|
9527
|
-
|
|
9562
|
+
let baseQueries = await window.ManifestDataQueries.buildAppwriteQueries(filters, scope, scopeColumns);
|
|
9563
|
+
if (baseQueries === null) {
|
|
9564
|
+
// A $auth. value or scope not resolved yet: wait for auth once
|
|
9565
|
+
await window.ManifestDataMain?.waitForAuthChange?.();
|
|
9566
|
+
baseQueries = await window.ManifestDataQueries.buildAppwriteQueries(filters, scope, scopeColumns);
|
|
9567
|
+
}
|
|
9528
9568
|
if (baseQueries === null) {
|
|
9529
|
-
throw new Error(`[Manifest Data] "${dataSourceName}" pagination: auth not ready
|
|
9569
|
+
throw new Error(`[Manifest Data] "${dataSourceName}" pagination: auth not ready — sign in, or check the $auth. values in its queries`);
|
|
9530
9570
|
}
|
|
9531
9571
|
|
|
9532
9572
|
if (methodName === '$first') {
|
|
@@ -9613,6 +9653,20 @@ if (typeof window !== 'undefined') {
|
|
|
9613
9653
|
}
|
|
9614
9654
|
}
|
|
9615
9655
|
|
|
9656
|
+
// $x.<source> hands back the same array until the source's next landing, so
|
|
9657
|
+
// identity-keyed memos and Alpine comparisons hold between reads
|
|
9658
|
+
const sourceArrayViews = new WeakMap(); // array -> { version, view }
|
|
9659
|
+
function sourceArrayView(dataSourceName, array, build) {
|
|
9660
|
+
const store = typeof Alpine !== 'undefined' ? Alpine.store('data') : null;
|
|
9661
|
+
const raw = store ? (window.ManifestDataStore?.rawOf?.(store) || store) : null;
|
|
9662
|
+
const version = raw?._v?.[dataSourceName];
|
|
9663
|
+
const cached = sourceArrayViews.get(array);
|
|
9664
|
+
if (cached && cached.version === version) return cached.view;
|
|
9665
|
+
const view = build();
|
|
9666
|
+
sourceArrayViews.set(array, { version, view });
|
|
9667
|
+
return view;
|
|
9668
|
+
}
|
|
9669
|
+
|
|
9616
9670
|
// Loading proxy for Appwrite sources (CRUD + state/files/upload/pagination methods)
|
|
9617
9671
|
function createAppwriteLoadingProxy(dataSourceName, reloadDataSource) {
|
|
9618
9672
|
const createLoadingProxy = window.ManifestDataProxiesCore?.createLoadingProxy;
|
|
@@ -9660,6 +9714,9 @@ function createAppwriteLoadingProxy(dataSourceName, reloadDataSource) {
|
|
|
9660
9714
|
if (key === '$saving') {
|
|
9661
9715
|
return window.ManifestDataProxiesMagic.createSavingMethod(dataSourceName);
|
|
9662
9716
|
}
|
|
9717
|
+
if (key === '$reload') {
|
|
9718
|
+
return () => window.ManifestDataMain.reloadSource(dataSourceName);
|
|
9719
|
+
}
|
|
9663
9720
|
|
|
9664
9721
|
// Appwrite CRUD
|
|
9665
9722
|
if (key === '$create' || key === '$update' || key === '$delete' || key === '$query' ||
|
|
@@ -9700,6 +9757,9 @@ function createBasicLoadingProxy(dataSourceName) {
|
|
|
9700
9757
|
if (key === '$files' && filesMethod) {
|
|
9701
9758
|
return filesMethod;
|
|
9702
9759
|
}
|
|
9760
|
+
if (key === '$reload') {
|
|
9761
|
+
return () => window.ManifestDataMain.reloadSource(dataSourceName);
|
|
9762
|
+
}
|
|
9703
9763
|
|
|
9704
9764
|
return target[key];
|
|
9705
9765
|
}
|
|
@@ -9868,6 +9928,7 @@ function registerXMagicMethod(loadDataSource) {
|
|
|
9868
9928
|
}
|
|
9869
9929
|
if (key === '$saving') return window.ManifestDataProxiesMagic.createSavingMethod(prop);
|
|
9870
9930
|
if (key === '$more') return () => window.ManifestDataMain.loadMore(prop);
|
|
9931
|
+
if (key === '$reload') return () => window.ManifestDataMain.reloadSource(prop);
|
|
9871
9932
|
return target[key];
|
|
9872
9933
|
}
|
|
9873
9934
|
}));
|
|
@@ -9982,7 +10043,7 @@ function registerXMagicMethod(loadDataSource) {
|
|
|
9982
10043
|
if (attachArrayMethods) {
|
|
9983
10044
|
const arrayWithMethods = attachArrayMethods(arrayForMethods, prop, reloadDataSource);
|
|
9984
10045
|
// has() trap so Alpine sees $search/$query/etc. before accessing
|
|
9985
|
-
return new Proxy(arrayWithMethods, {
|
|
10046
|
+
return sourceArrayView(prop, arrayWithMethods, () => new Proxy(arrayWithMethods, {
|
|
9986
10047
|
get(target, key) {
|
|
9987
10048
|
if (key === '$search' || key === '$query' || key === '$route') {
|
|
9988
10049
|
if (key in target && typeof target[key] === 'function') {
|
|
@@ -10043,7 +10104,7 @@ function registerXMagicMethod(loadDataSource) {
|
|
|
10043
10104
|
}
|
|
10044
10105
|
return undefined;
|
|
10045
10106
|
}
|
|
10046
|
-
});
|
|
10107
|
+
}));
|
|
10047
10108
|
} else {
|
|
10048
10109
|
return arrayForMethods;
|
|
10049
10110
|
}
|
|
@@ -10206,7 +10267,7 @@ function registerXMagicMethod(loadDataSource) {
|
|
|
10206
10267
|
if (attachArrayMethods) {
|
|
10207
10268
|
const arrayWithMethods = attachArrayMethods(emptyArray, prop, reloadDataSource);
|
|
10208
10269
|
// has() trap so Alpine sees $search/$query/etc.
|
|
10209
|
-
return new Proxy(arrayWithMethods, {
|
|
10270
|
+
return sourceArrayView(prop, arrayWithMethods, () => new Proxy(arrayWithMethods, {
|
|
10210
10271
|
get(target, key) {
|
|
10211
10272
|
if (key === '$search' || key === '$query' || key === '$route') {
|
|
10212
10273
|
if (key in target && typeof target[key] === 'function') {
|
|
@@ -10244,7 +10305,7 @@ function registerXMagicMethod(loadDataSource) {
|
|
|
10244
10305
|
}
|
|
10245
10306
|
return undefined;
|
|
10246
10307
|
}
|
|
10247
|
-
});
|
|
10308
|
+
}));
|
|
10248
10309
|
}
|
|
10249
10310
|
return emptyArray;
|
|
10250
10311
|
}
|
|
@@ -10294,7 +10355,7 @@ function registerXMagicMethod(loadDataSource) {
|
|
|
10294
10355
|
if (attachArrayMethods) {
|
|
10295
10356
|
const arrayWithMethods = attachArrayMethods(value, prop, loadDataSource);
|
|
10296
10357
|
// has() trap so Alpine sees $search/$query/etc.
|
|
10297
|
-
return new Proxy(arrayWithMethods, {
|
|
10358
|
+
return sourceArrayView(prop, arrayWithMethods, () => new Proxy(arrayWithMethods, {
|
|
10298
10359
|
get(target, key) {
|
|
10299
10360
|
if (key === '$search' || key === '$query') {
|
|
10300
10361
|
if (target && typeof target === 'object' && key in target && typeof target[key] === 'function') {
|
|
@@ -10370,7 +10431,7 @@ function registerXMagicMethod(loadDataSource) {
|
|
|
10370
10431
|
}
|
|
10371
10432
|
return undefined;
|
|
10372
10433
|
}
|
|
10373
|
-
});
|
|
10434
|
+
}));
|
|
10374
10435
|
}
|
|
10375
10436
|
return value;
|
|
10376
10437
|
|
|
@@ -10525,7 +10586,7 @@ function registerXMagicMethod(loadDataSource) {
|
|
|
10525
10586
|
const appwriteMethodNames = ['$create', '$update', '$delete', '$query', '$url', '$download', '$preview', '$openUrl', '$openPreview', '$openDownload', '$filesFor', '$unlinkFrom', '$removeFrom', '$remove'];
|
|
10526
10587
|
const baseMethodNames = ['$search', '$route', '$query']; // Base plugin methods available for all data sources
|
|
10527
10588
|
|
|
10528
|
-
return new Proxy(arrayWithMethods, {
|
|
10589
|
+
return sourceArrayView(prop, arrayWithMethods, () => new Proxy(arrayWithMethods, {
|
|
10529
10590
|
get(target, prop) {
|
|
10530
10591
|
// Handle base plugin methods ($search, $route, $query)
|
|
10531
10592
|
if (prop === '$route' || prop === '$search' || prop === '$query') {
|
|
@@ -10658,7 +10719,7 @@ function registerXMagicMethod(loadDataSource) {
|
|
|
10658
10719
|
}
|
|
10659
10720
|
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
10660
10721
|
}
|
|
10661
|
-
});
|
|
10722
|
+
}));
|
|
10662
10723
|
}
|
|
10663
10724
|
// Only create proxy for objects, return primitives directly
|
|
10664
10725
|
if (typeof nestedValue === 'object' && nestedValue !== null) {
|
|
@@ -11946,7 +12007,10 @@ function setupAuthResetListener() {
|
|
|
11946
12007
|
let bound = (currentAuth() ? confirmedIdentity() : null) ?? lastKnownIdentity();
|
|
11947
12008
|
// Reads under an unverified session failed or came from the snapshot: confirming the same identity still reloads
|
|
11948
12009
|
let unverified = currentAuth()?._sessionUnverified === true;
|
|
11949
|
-
|
|
12010
|
+
// keepQuery: someone is signed in, so a source showing a $query shows it again under them
|
|
12011
|
+
const reset = async (clear, keepQuery = false) => {
|
|
12012
|
+
// Reads issued after this auth change already see the new identity: they stand
|
|
12013
|
+
const readAtEvent = window.ManifestDataStore?.readSeqNow?.();
|
|
11950
12014
|
const manifest = await window.ManifestDataConfig?.ensureManifest?.();
|
|
11951
12015
|
const ds = window.ManifestDataStore;
|
|
11952
12016
|
const store = typeof Alpine !== 'undefined' ? Alpine.store('data') : null;
|
|
@@ -11956,11 +12020,16 @@ function setupAuthResetListener() {
|
|
|
11956
12020
|
const locale = liveLocale();
|
|
11957
12021
|
for (const [name, config] of Object.entries(configs)) {
|
|
11958
12022
|
if (!isIdentityBound(config) || raw[`_${name}_state`] === undefined) continue;
|
|
12023
|
+
if (!clear && keepQuery && awaitingQueries.has(name)) continue; // a $query waiting on this sign-in runs it
|
|
12024
|
+
if (!clear && readAtEvent !== undefined && (ds.currentRead?.(name) ?? 0) > readAtEvent) continue;
|
|
12025
|
+
const active = keepQuery ? (queryIntents.get(name) || activeQueries.get(name)) : null;
|
|
11959
12026
|
if (clear) {
|
|
11960
12027
|
window.ManifestDataRealtime?.unsubscribeFromDataSource?.(name);
|
|
11961
12028
|
ds.resetSource(name);
|
|
11962
12029
|
}
|
|
11963
|
-
|
|
12030
|
+
const handler = active && window.ManifestDataProxiesAppwrite?.createAppwriteMethodsHandler?.(name, reloadDataSource);
|
|
12031
|
+
if (handler) Promise.resolve(handler('$query', active)).catch(() => { /* $error carries it */ });
|
|
12032
|
+
else loadDataSource(name, locale, { reload: true });
|
|
11964
12033
|
}
|
|
11965
12034
|
};
|
|
11966
12035
|
const onAuth = (type) => {
|
|
@@ -11974,10 +12043,11 @@ function setupAuthResetListener() {
|
|
|
11974
12043
|
// Same identity, or unknown before (rows so far were read under this same session; a sign-out still drops them):
|
|
11975
12044
|
// no reset, but an unverified boot's reads are redone with the rows kept live
|
|
11976
12045
|
if (prev === next || (prev === null && !ended)) {
|
|
11977
|
-
if (recovered) reset(false);
|
|
12046
|
+
if (recovered) reset(false, next !== '');
|
|
11978
12047
|
return;
|
|
11979
12048
|
}
|
|
11980
|
-
|
|
12049
|
+
// An identity switch (A to B) starts clean with the defaults; a first sign-in keeps the $query
|
|
12050
|
+
reset(prev !== '', prev === '' && next !== '');
|
|
11981
12051
|
};
|
|
11982
12052
|
['manifest:auth:logout', 'manifest:auth:session-cleared', 'manifest:auth:login', 'manifest:auth:anonymous', 'manifest:auth:initialized']
|
|
11983
12053
|
.forEach(type => window.addEventListener(type, () => onAuth(type)));
|
|
@@ -12229,6 +12299,8 @@ function configureRealtimeMeta(dataSourceName, config, initialCount, limitQuery)
|
|
|
12229
12299
|
// Active $query per source (manifest-format): realtime matches, orders and
|
|
12230
12300
|
// server-filters by it until the next default load replaces the rows
|
|
12231
12301
|
const activeQueries = new Map();
|
|
12302
|
+
const awaitingQueries = new Set(); // sources with a $query waiting for auth to settle
|
|
12303
|
+
const queryIntents = new Map(); // the latest $query asked of a source (cleared by a default load)
|
|
12232
12304
|
const realtimeBinds = new Map(); // Map<name, { config, mode, rebind }>
|
|
12233
12305
|
|
|
12234
12306
|
function realtimeQueriesFor(dataSourceName, defaults) {
|
|
@@ -12294,11 +12366,53 @@ function rowFitsSource(dataSourceName, row) {
|
|
|
12294
12366
|
// Source reset (identity/scope) or torn down: nothing of the old binding carries over
|
|
12295
12367
|
function forgetLiveSource(dataSourceName) {
|
|
12296
12368
|
activeQueries.delete(dataSourceName);
|
|
12369
|
+
queryIntents.delete(dataSourceName);
|
|
12297
12370
|
pagingState.delete(dataSourceName);
|
|
12298
12371
|
catchUpTargets.delete(dataSourceName);
|
|
12299
12372
|
realtimeBinds.delete(dataSourceName);
|
|
12300
12373
|
}
|
|
12301
12374
|
|
|
12375
|
+
// Load retry: transient failures (network, 5xx, 408/429, an SDK call that dies mid-blip)
|
|
12376
|
+
// retry with backoff before $error shows. `retry: false` | `{ attempts, delay }` per source
|
|
12377
|
+
const RETRY_DEFAULT = { attempts: 3, delay: 500 };
|
|
12378
|
+
|
|
12379
|
+
function retryPolicy(dataSource) {
|
|
12380
|
+
const r = dataSource && typeof dataSource === 'object' ? dataSource.retry : undefined;
|
|
12381
|
+
if (r === false || r === 0) return { attempts: 0, delay: 0 };
|
|
12382
|
+
if (r && typeof r === 'object') {
|
|
12383
|
+
return {
|
|
12384
|
+
attempts: Number.isFinite(r.attempts) && r.attempts >= 0 ? Math.floor(r.attempts) : RETRY_DEFAULT.attempts,
|
|
12385
|
+
delay: Number.isFinite(r.delay) && r.delay >= 0 ? r.delay : RETRY_DEFAULT.delay
|
|
12386
|
+
};
|
|
12387
|
+
}
|
|
12388
|
+
return RETRY_DEFAULT;
|
|
12389
|
+
}
|
|
12390
|
+
|
|
12391
|
+
function isTransient(error) {
|
|
12392
|
+
// Offline: the `online` catch-up refetches, so retrying now only delays $error
|
|
12393
|
+
if (typeof navigator !== 'undefined' && navigator.onLine === false) return false;
|
|
12394
|
+
const code = error?.code ?? error?.status ?? error?.response?.code;
|
|
12395
|
+
if (typeof code === 'number' && code > 0) return code >= 500 || code === 408 || code === 429;
|
|
12396
|
+
// fetch network failure, or the SDK reading a response that never came — not config mistakes
|
|
12397
|
+
return error?.name === 'TypeError' && /fetch|network|load failed|headers/i.test(String(error.message || ''));
|
|
12398
|
+
}
|
|
12399
|
+
|
|
12400
|
+
// Run a read, retrying transient failures with exponential backoff (delay, 2×, 4×…, jittered);
|
|
12401
|
+
// stops early once isCurrent() is false (a newer read or identity took over)
|
|
12402
|
+
async function withRetry(dataSource, fn, isCurrent = () => true) {
|
|
12403
|
+
const { attempts, delay } = retryPolicy(dataSource);
|
|
12404
|
+
for (let attempt = 0; ; attempt++) {
|
|
12405
|
+
try {
|
|
12406
|
+
return await fn();
|
|
12407
|
+
} catch (error) {
|
|
12408
|
+
if (attempt >= attempts || !isTransient(error) || !isCurrent()) throw error;
|
|
12409
|
+
const wait = delay * 2 ** attempt * (0.75 + Math.random() * 0.5);
|
|
12410
|
+
await new Promise(resolve => setTimeout(resolve, wait));
|
|
12411
|
+
if (!isCurrent()) throw error;
|
|
12412
|
+
}
|
|
12413
|
+
}
|
|
12414
|
+
}
|
|
12415
|
+
|
|
12302
12416
|
// Paged sources: `paging: "all" | "window" | { mode, size, max }`
|
|
12303
12417
|
// all: every page up to `max` rows; window: `size` rows, `$more()` appends the next page.
|
|
12304
12418
|
// The cursor is the last row the server sent (never a local or moved row), with its
|
|
@@ -12353,11 +12467,10 @@ async function fetchPagedRows(dataSourceName, filters, { want, after = null, isC
|
|
|
12353
12467
|
let cursor = after;
|
|
12354
12468
|
while (rows.length < limit) {
|
|
12355
12469
|
const n = Math.min(spec.size, limit - rows.length);
|
|
12356
|
-
const
|
|
12357
|
-
|
|
12358
|
-
|
|
12359
|
-
|
|
12360
|
-
);
|
|
12470
|
+
const pageQueries = [...base, ...(cursor ? [Query.cursorAfter(cursor)] : []), Query.limit(n + 1)];
|
|
12471
|
+
const page = await withRetry(dataSource, () => window.ManifestDataAppwrite.loadTablePage(
|
|
12472
|
+
appwriteConfig.databaseId, tableId, pageQueries, { requireAuth }
|
|
12473
|
+
), isCurrent);
|
|
12361
12474
|
if (total === null) total = page.total;
|
|
12362
12475
|
const got = page.rows.slice(0, n);
|
|
12363
12476
|
rows.push(...got);
|
|
@@ -12839,6 +12952,7 @@ async function loadDataSource(dataSourceName, locale = 'en', options = {}) {
|
|
|
12839
12952
|
|
|
12840
12953
|
// Reads are ordered by call: a $query issued after this load wins over it
|
|
12841
12954
|
const readToken = window.ManifestDataStore.beginRead?.(dataSourceName);
|
|
12955
|
+
queryIntents.delete(dataSourceName);
|
|
12842
12956
|
let pagedResult = null;
|
|
12843
12957
|
window.ManifestDataStore.loadReadTokens?.set(cacheKey, readToken);
|
|
12844
12958
|
|
|
@@ -12932,7 +13046,7 @@ async function loadDataSource(dataSourceName, locale = 'en', options = {}) {
|
|
|
12932
13046
|
// Cloud API - load from HTTP endpoint (read-only)
|
|
12933
13047
|
// NOTE: Basic API support is in core for localization compatibility.
|
|
12934
13048
|
// Full CRUD operations will be available via manifest.api.data.js plugin (planned).
|
|
12935
|
-
data = await window.ManifestDataAPI.loadFromAPI(dataSource);
|
|
13049
|
+
data = await withRetry(dataSource, () => window.ManifestDataAPI.loadFromAPI(dataSource), () => !superseded());
|
|
12936
13050
|
} else if (window.ManifestDataConfig.isAppwriteCollection(dataSource)) {
|
|
12937
13051
|
// Appwrite collection or bucket
|
|
12938
13052
|
const appwriteConfig = await window.ManifestDataConfig.getAppwriteConfig(dataSource);
|
|
@@ -12972,12 +13086,12 @@ async function loadDataSource(dataSourceName, locale = 'en', options = {}) {
|
|
|
12972
13086
|
const authStore = typeof Alpine !== 'undefined' ? Alpine.store('auth') : null;
|
|
12973
13087
|
const teamIds = authStore?.teams?.map(t => t.$id || t.id) || [];
|
|
12974
13088
|
|
|
12975
|
-
data = paged ? paged.rows : await window.ManifestDataAppwrite.loadTableRows(
|
|
13089
|
+
data = paged ? paged.rows : await withRetry(dataSource, () => window.ManifestDataAppwrite.loadTableRows(
|
|
12976
13090
|
appwriteConfig.databaseId,
|
|
12977
13091
|
tableId,
|
|
12978
13092
|
queries,
|
|
12979
13093
|
{ requireAuth: requiresIdentity(dataSource) }
|
|
12980
|
-
);
|
|
13094
|
+
), () => !superseded());
|
|
12981
13095
|
if (superseded()) { landed = true; return null; }
|
|
12982
13096
|
|
|
12983
13097
|
// Subscribe to real-time updates for this table (events from a
|
|
@@ -13026,7 +13140,7 @@ async function loadDataSource(dataSourceName, locale = 'en', options = {}) {
|
|
|
13026
13140
|
return null;
|
|
13027
13141
|
}
|
|
13028
13142
|
|
|
13029
|
-
let files = await window.ManifestDataAppwrite.listBucketFiles(bucketId, queries);
|
|
13143
|
+
let files = await withRetry(dataSource, () => window.ManifestDataAppwrite.listBucketFiles(bucketId, queries), () => !superseded());
|
|
13030
13144
|
|
|
13031
13145
|
// Ensure files is always an array
|
|
13032
13146
|
if (!Array.isArray(files)) {
|
|
@@ -13083,7 +13197,7 @@ async function loadDataSource(dataSourceName, locale = 'en', options = {}) {
|
|
|
13083
13197
|
currentLocaleData = await window.ManifestDataLoaders.loadLocalFile(localizedDataSource);
|
|
13084
13198
|
} else if (localizedDataSource.url) {
|
|
13085
13199
|
// Localized cloud API
|
|
13086
|
-
currentLocaleData = await window.ManifestDataAPI.loadFromAPI(localizedDataSource);
|
|
13200
|
+
currentLocaleData = await withRetry(dataSource, () => window.ManifestDataAPI.loadFromAPI(localizedDataSource), () => !superseded());
|
|
13087
13201
|
} else {
|
|
13088
13202
|
console.warn(`[Manifest Data] No valid source found for dataSource "${dataSourceName}" in locale "${locale}"`);
|
|
13089
13203
|
return null;
|
|
@@ -13105,7 +13219,7 @@ async function loadDataSource(dataSourceName, locale = 'en', options = {}) {
|
|
|
13105
13219
|
// For CSV in localized structure, don't pass locale - each file is already locale-specific
|
|
13106
13220
|
fallbackData = await window.ManifestDataLoaders.loadLocalFile(defaultLocaleDataSource);
|
|
13107
13221
|
} else if (defaultLocaleDataSource?.url) {
|
|
13108
|
-
fallbackData = await window.ManifestDataAPI.loadFromAPI(defaultLocaleDataSource);
|
|
13222
|
+
fallbackData = await withRetry(dataSource, () => window.ManifestDataAPI.loadFromAPI(defaultLocaleDataSource), () => !superseded());
|
|
13109
13223
|
}
|
|
13110
13224
|
|
|
13111
13225
|
// Merge fallback data with current locale data (current takes precedence if it exists)
|
|
@@ -13253,6 +13367,38 @@ async function loadDataSource(dataSourceName, locale = 'en', options = {}) {
|
|
|
13253
13367
|
return run;
|
|
13254
13368
|
}
|
|
13255
13369
|
|
|
13370
|
+
// $reload(): fetch again what the source shows — its active $query, else its default
|
|
13371
|
+
// load; a paged source keeps as many rows as it holds
|
|
13372
|
+
function reloadSource(dataSourceName) {
|
|
13373
|
+
if (pagingState.has(dataSourceName)) {
|
|
13374
|
+
const held = window.ManifestDataStore.rawOf(Alpine.store('data'))?.[dataSourceName];
|
|
13375
|
+
catchUpTargets.set(dataSourceName, Array.isArray(held) ? held.length : 0);
|
|
13376
|
+
}
|
|
13377
|
+
const active = activeQueries.get(dataSourceName);
|
|
13378
|
+
const handler = active && window.ManifestDataProxiesAppwrite?.createAppwriteMethodsHandler?.(dataSourceName, reloadDataSource);
|
|
13379
|
+
return handler ? handler('$query', active) : reloadDataSource(dataSourceName);
|
|
13380
|
+
}
|
|
13381
|
+
|
|
13382
|
+
// Resolves at the next auth change (sign-in settles, team switch) or after timeoutMs
|
|
13383
|
+
function waitForAuthChange(timeoutMs = 10000) {
|
|
13384
|
+
const events = ['manifest:auth:login', 'manifest:auth:initialized', 'manifest:auth:anonymous', 'manifest:auth:teams-loaded', 'manifest:auth:logout', 'manifest:auth:session-cleared'];
|
|
13385
|
+
return new Promise(resolve => {
|
|
13386
|
+
const done = () => { clearTimeout(timer); events.forEach(type => window.removeEventListener(type, done)); resolve(); };
|
|
13387
|
+
const timer = setTimeout(done, timeoutMs);
|
|
13388
|
+
events.forEach(type => window.addEventListener(type, done));
|
|
13389
|
+
});
|
|
13390
|
+
}
|
|
13391
|
+
|
|
13392
|
+
// Resolves once no read of this source is in flight (bounded); starts after a tick so
|
|
13393
|
+
// reloads that an event just kicked off are counted
|
|
13394
|
+
async function settledReads(dataSourceName, timeoutMs = 5000) {
|
|
13395
|
+
const until = Date.now() + timeoutMs;
|
|
13396
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
13397
|
+
while (window.ManifestDataStore.readsInFlight(dataSourceName) && Date.now() < until) {
|
|
13398
|
+
await new Promise(resolve => setTimeout(resolve, 20));
|
|
13399
|
+
}
|
|
13400
|
+
}
|
|
13401
|
+
|
|
13256
13402
|
// Reload: refetch past the memory cache; rows stay live and merge by $id
|
|
13257
13403
|
function reloadDataSource(dataSourceName, locale) {
|
|
13258
13404
|
return loadDataSource(dataSourceName, locale || liveLocale(), { reload: true });
|
|
@@ -13389,13 +13535,7 @@ async function initializeDataSourcesPlugin() {
|
|
|
13389
13535
|
clearTimeout(catchUpTimer);
|
|
13390
13536
|
catchUpTimer = setTimeout(() => {
|
|
13391
13537
|
for (const name of realtimeBinds.keys()) {
|
|
13392
|
-
|
|
13393
|
-
if (pagingState.has(name)) {
|
|
13394
|
-
const held = window.ManifestDataStore.rawOf(Alpine.store('data'))?.[name];
|
|
13395
|
-
catchUpTargets.set(name, Array.isArray(held) ? held.length : 0);
|
|
13396
|
-
}
|
|
13397
|
-
const handler = active && window.ManifestDataProxiesAppwrite?.createAppwriteMethodsHandler?.(name, reloadDataSource);
|
|
13398
|
-
Promise.resolve(handler ? handler('$query', active) : reloadDataSource(name)).catch(() => { /* $error carries it */ });
|
|
13538
|
+
Promise.resolve(reloadSource(name)).catch(() => { /* $error carries it */ });
|
|
13399
13539
|
}
|
|
13400
13540
|
}, 250);
|
|
13401
13541
|
};
|
|
@@ -13415,6 +13555,13 @@ async function initializeDataSourcesPlugin() {
|
|
|
13415
13555
|
requiresIdentity,
|
|
13416
13556
|
setActiveQuery,
|
|
13417
13557
|
forgetLiveSource,
|
|
13558
|
+
reloadSource,
|
|
13559
|
+
waitForAuthChange,
|
|
13560
|
+
settledReads,
|
|
13561
|
+
awaitingQueries,
|
|
13562
|
+
noteQueryIntent: (dataSourceName, queries) => queryIntents.set(dataSourceName, queries),
|
|
13563
|
+
dropQueryIntent: (dataSourceName, queries) => { if (queryIntents.get(dataSourceName) === queries) queryIntents.delete(dataSourceName); },
|
|
13564
|
+
withRetry,
|
|
13418
13565
|
pagingSpec,
|
|
13419
13566
|
fetchPagedRows,
|
|
13420
13567
|
pagedWant,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest.appwrite.auth.js": "sha384-gWLSeVPqCLMiUZB8MU7GqMg3x2yULFUsp8nTTZrPp/9Dlkix42rBn9yIimvwrHqZ",
|
|
3
|
-
"manifest.appwrite.data.js": "sha384-
|
|
3
|
+
"manifest.appwrite.data.js": "sha384-HGDENGMqr2x0MJ0hdMJKu8u76g8P8ilZF7m0lewPVyzPb3z8Hn2hAQBIps7HnNgI",
|
|
4
4
|
"manifest.appwrite.presences.js": "sha384-LINPhIPTCK+rA8zd+HPUzMSEgH6Sl2vQMEyItT97bnEE2FYGYKqjXX+CWdt6nl9z",
|
|
5
5
|
"manifest.bindings.js": "sha384-lPtMf8Ykaic9gNVZKq8Scia1881ZeMAyxer3WCIkUNwwrgzGBWto1OXADUwjvORF",
|
|
6
6
|
"manifest.charts.js": "sha384-AFbP7mQnigy7DU1s+YE30yKTeQAKfgNazhbfSNbfd9ZpLgeulZKaPi/fAq3gJHDO",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"manifest.combobox.js": "sha384-/lJo6vaxKjgnBSRs/dzkhK1dzGk3GBw8FISoNJZB70mwAVwu1k5veZyBXjOb4keS",
|
|
12
12
|
"manifest.components.js": "sha384-1el5WMdgmzu/2ocaYN21OjLi/lfjllvA8aju1J3knYuOizw+XFfJU1+rvGqYW7qk",
|
|
13
13
|
"manifest.computed.js": "sha384-GYML/e81gQfN+iDbqhPUgny8bINCyL+SrbTofoGk4hlCnLLjv51mCv42JMqq+ku5",
|
|
14
|
-
"manifest.data.js": "sha384
|
|
14
|
+
"manifest.data.js": "sha384-/80Rkio+kmm/A+lH4jjD5uK0WJ1uSXda7K2JXEc93AK8x1o40OJizq7NFBKpfnN+",
|
|
15
15
|
"manifest.datepicker.js": "sha384-EzlMwvIxlla/0BuyhAEqxN0M8TGcWIWgEIg840V0akKQQK1uY648wPWMkobvtq/o",
|
|
16
16
|
"manifest.defer.js": "sha384-PRp7+dCZHnnl55rX2xrHutLrQnszHo7o5o9Tq28M/yjLZPuXDzcwQNxCdvbtCYSz",
|
|
17
17
|
"manifest.device.js": "sha384-YeQaS56L8IILqrQNBSeAOLwIh5DuAOrE60cYLK1+46qJtUrXlAvqGe2j5mbV4Vq7",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"manifest.status.js": "sha384-ofu7nBnVIGZ1U1o2R9d2H3V8aEMPUCVbl5FO3gIToXqi0oa36fTviEdh5UU7Kitw",
|
|
30
30
|
"manifest.submissions.js": "sha384-v9eS47ytAfTGIKAyVnbd0QWegucVS7yduvigqfsxxoqXmbaEoy0M2y+BiI4xeZBd",
|
|
31
31
|
"manifest.svg.js": "sha384-qr/8H9+2cIhSXNbRWRtIdrDlTOxKlNJqwEefHvCYoiBNW/kKhPTFa109Orv/EBnb",
|
|
32
|
-
"manifest.sw.js": "sha384-
|
|
32
|
+
"manifest.sw.js": "sha384-tfQWEMCzu3Bzs87VuM+LrBLqf8ZbuW0D14siQaUO5V4LPQmMETzc3eKs4PuLRPGC",
|
|
33
33
|
"manifest.tabs.js": "sha384-otU09H7jnawVKQdLAYpMCd3jx00tgyPVr42D2hLIBzN5dG4se505YesavdnMqEi1",
|
|
34
34
|
"manifest.tailwind.js": "sha384-yuP3LEvWU+QVjxjkZ0YhErtC9RrGmhOmHjjFjhS9obqZbp5/KTIEnSR0CXDvHE0B",
|
|
35
35
|
"manifest.toasts.js": "sha384-UpOz9fAdGeGUhL0NamBg5iPepEfIy73p9HYdcxfOQC5b7CVsl7Our0skdZzaLNcC",
|
package/lib/manifest.schema.json
CHANGED
|
@@ -275,6 +275,20 @@
|
|
|
275
275
|
}
|
|
276
276
|
]
|
|
277
277
|
},
|
|
278
|
+
"retry": {
|
|
279
|
+
"description": "Retries for transient load failures (network, timeouts, 5xx, 429) before $error shows, on API, Appwrite table and bucket sources. false turns them off; default { attempts: 3, delay: 500 } (ms, backing off).",
|
|
280
|
+
"oneOf": [
|
|
281
|
+
{ "type": "boolean", "enum": [false] },
|
|
282
|
+
{
|
|
283
|
+
"type": "object",
|
|
284
|
+
"properties": {
|
|
285
|
+
"attempts": { "type": "integer", "minimum": 0 },
|
|
286
|
+
"delay": { "type": "number", "minimum": 0 }
|
|
287
|
+
},
|
|
288
|
+
"additionalProperties": false
|
|
289
|
+
}
|
|
290
|
+
]
|
|
291
|
+
},
|
|
278
292
|
"paging": {
|
|
279
293
|
"description": "Load an Appwrite table in pages that stay live. 'all' walks every page (up to max, default 5000); 'window' loads the first page (size, default 100, at most 4999) and $more() appends the next.",
|
|
280
294
|
"oneOf": [
|
package/lib/manifest.sw.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
// Build stamps the published version here; unstamped (dev) falls back to the
|
|
18
18
|
// registration URL's `v`, then 'dev'.
|
|
19
|
-
const BUILD_VERSION = '0.5.
|
|
19
|
+
const BUILD_VERSION = '0.5.279';
|
|
20
20
|
const CACHE_PREFIX = 'mnfst-sw:';
|
|
21
21
|
const META_CACHE = CACHE_PREFIX + 'meta';
|
|
22
22
|
// Sized to hold a full precache.json warm-up (PRECACHE_MAX_ENTRIES server-side)
|