mnfst 0.5.276 → 0.5.278
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 +280 -47
- package/lib/manifest.data.js +193 -46
- package/lib/manifest.integrity.json +3 -3
- package/lib/manifest.schema.json +15 -0
- package/lib/manifest.sw.js +1 -1
- package/package.json +2 -1
package/lib/manifest.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
/** Appwrite-style query expression returned by helper builders. */
|
|
18
18
|
export type ManifestQueryExpr = string;
|
|
19
19
|
|
|
20
|
-
/** Appwrite-style query helpers
|
|
20
|
+
/** Appwrite-style query helpers. */
|
|
21
21
|
export interface ManifestQuery {
|
|
22
22
|
equal(field: string, value: unknown): ManifestQueryExpr;
|
|
23
23
|
notEqual(field: string, value: unknown): ManifestQueryExpr;
|
|
@@ -41,81 +41,211 @@ export interface ManifestQuery {
|
|
|
41
41
|
cursorBefore(id: string): ManifestQueryExpr;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/** A column of row type `T` (or a dot path into a relationship). Any string when `T` is loose. */
|
|
45
|
+
export type ManifestColumn<T> = string extends keyof T ? string : (keyof T & string) | `${keyof T & string}.${string}`;
|
|
46
|
+
|
|
47
|
+
type ManifestCompare = 'equal' | 'notEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'greaterThanEqual'
|
|
48
|
+
| 'lessThan' | 'lessThanOrEqual' | 'lessThanEqual' | 'contains' | 'startsWith' | 'endsWith' | 'search';
|
|
49
|
+
|
|
50
|
+
/** One `$query` expression: `[method, column, ...values]`. Column names are checked against the row type. */
|
|
51
|
+
export type ManifestQueryTuple<T = any> =
|
|
52
|
+
| [ManifestCompare, ManifestColumn<T>, ...unknown[]]
|
|
53
|
+
| ['between', ManifestColumn<T>, unknown, unknown]
|
|
54
|
+
| ['isNull' | 'isNotNull' | 'orderAsc' | 'orderDesc', ManifestColumn<T>]
|
|
55
|
+
| ['orderRandom']
|
|
56
|
+
| ['limit' | 'offset', number]
|
|
57
|
+
| ['cursorAfter' | 'cursorBefore', string]
|
|
58
|
+
| ['or', ManifestQueryTuple<T>[]];
|
|
59
|
+
|
|
44
60
|
/** State flags exposed on every data source (array or object). */
|
|
45
61
|
export interface ManifestSourceState {
|
|
46
|
-
/** True
|
|
62
|
+
/** True during a fetch or mutation. */
|
|
47
63
|
readonly $loading: boolean;
|
|
48
64
|
/** Last error from a load or mutation, or null. */
|
|
49
|
-
readonly $error:
|
|
50
|
-
/** True once
|
|
65
|
+
readonly $error: string | null;
|
|
66
|
+
/** True once the source has settled (loaded, or resolved empty because its scope can't apply). */
|
|
51
67
|
readonly $ready: boolean;
|
|
52
|
-
|
|
68
|
+
/** True while cached rows show and fresh data is still loading. */
|
|
69
|
+
readonly $stale: boolean;
|
|
70
|
+
/** Resolves once fresh data has landed. */
|
|
71
|
+
readonly $fresh: Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Fields Appwrite adds to every row. */
|
|
75
|
+
export interface ManifestRowSystem {
|
|
76
|
+
$id: string;
|
|
77
|
+
$createdAt: string;
|
|
78
|
+
$updatedAt: string;
|
|
79
|
+
$sequence?: number;
|
|
80
|
+
$permissions?: string[];
|
|
81
|
+
$tableId?: string;
|
|
82
|
+
$databaseId?: string;
|
|
83
|
+
/** Files linked to the row when the source configures `storage`. */
|
|
84
|
+
$files?: ManifestFile[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A file row from an Appwrite bucket source. */
|
|
88
|
+
export interface ManifestFile {
|
|
89
|
+
$id: string;
|
|
90
|
+
name: string;
|
|
91
|
+
mimeType: string;
|
|
92
|
+
sizeOriginal: number;
|
|
93
|
+
$createdAt: string;
|
|
94
|
+
$updatedAt: string;
|
|
95
|
+
readonly $url?: string;
|
|
96
|
+
readonly $isImage?: boolean;
|
|
97
|
+
readonly $isPdf?: boolean;
|
|
98
|
+
readonly $formattedSize?: string | null;
|
|
99
|
+
readonly $thumbnailUrl?: string | null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Search weights: `{ title: 3, body: 1 }`. */
|
|
103
|
+
export type ManifestSearchWeights<T> = Partial<Record<ManifestColumn<T>, number>>;
|
|
53
104
|
|
|
54
105
|
/** Operators available on array-shaped sources (CSV tabular, JSON arrays, Appwrite tables). */
|
|
55
106
|
export interface ManifestArrayOps<T> {
|
|
56
|
-
/** Substring match across the given fields
|
|
57
|
-
$search(term: string, ...fields:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
$
|
|
63
|
-
/** Look up a single row whose `id` matches the current route param, if any. */
|
|
64
|
-
$route(path?: string): T | undefined;
|
|
107
|
+
/** Substring match across the given fields, or a ranked search with field weights. */
|
|
108
|
+
$search(term: string, ...fields: ManifestColumn<T>[]): ManifestArraySource<T>;
|
|
109
|
+
$search(term: string, weights: ManifestSearchWeights<T>): ManifestArraySource<T>;
|
|
110
|
+
/** Local sources: filter synchronously (chainable with `$search`). */
|
|
111
|
+
$query(queries: ManifestQueryTuple<T>[]): ManifestArraySource<T>;
|
|
112
|
+
/** The row whose `field` matches a segment of the current URL. */
|
|
113
|
+
$route(field?: ManifestColumn<T>): T | undefined;
|
|
65
114
|
}
|
|
66
115
|
|
|
67
|
-
/**
|
|
116
|
+
/** A cursor page from `$first`, `$next` and `$prev`. */
|
|
117
|
+
export interface ManifestCursorPage<T> {
|
|
118
|
+
items: T[];
|
|
119
|
+
cursor: string | null;
|
|
120
|
+
total: number;
|
|
121
|
+
hasMore: boolean;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** An offset page from `$page`. */
|
|
125
|
+
export interface ManifestOffsetPage<T> {
|
|
126
|
+
items: T[];
|
|
127
|
+
page: number;
|
|
128
|
+
total: number;
|
|
129
|
+
totalPages: number;
|
|
130
|
+
hasMore: boolean;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** `$update` list form: one entry per row. */
|
|
134
|
+
export type ManifestUpdateList<T> = Array<{ id?: string; $id?: string; data: Partial<T> }>;
|
|
135
|
+
|
|
136
|
+
/** Options for `$duplicate` on table rows: field overrides plus copy controls. */
|
|
137
|
+
export type ManifestDuplicateOptions<T> = Partial<T> & { newRowId?: string; files?: 'duplicate' | 'same' | 'none' };
|
|
138
|
+
|
|
139
|
+
/** Reads, mutations and paging on Appwrite-table sources. */
|
|
68
140
|
export interface ManifestAppwriteTableOps<T> {
|
|
69
|
-
|
|
70
|
-
$
|
|
71
|
-
$
|
|
72
|
-
|
|
141
|
+
/** Server-side query with expressions or a named query from manifest.json; replaces the source's rows. */
|
|
142
|
+
$query(queriesOrName: ManifestQueryTuple<T>[] | string): Promise<T[]>;
|
|
143
|
+
$create(values: Partial<T>, rowId?: string): Promise<T>;
|
|
144
|
+
/** One row by id, several by ids, or a list of `{ id, data }` (no second argument). */
|
|
145
|
+
$update<I extends string | string[] | ManifestUpdateList<T>>(
|
|
146
|
+
target: I,
|
|
147
|
+
...values: 0 extends (1 & I) ? [values?: Partial<T>] : I extends ManifestUpdateList<T> ? [] : [values: Partial<T>]
|
|
148
|
+
): Promise<0 extends (1 & I) ? T : I extends string ? T : T[]>;
|
|
149
|
+
$delete(id: string): Promise<T>;
|
|
150
|
+
$delete(ids: string[]): Promise<T[]>;
|
|
151
|
+
$duplicate(id: string, options?: ManifestDuplicateOptions<T>): Promise<T>;
|
|
152
|
+
$first(limit?: number): Promise<ManifestCursorPage<T>>;
|
|
153
|
+
$next(cursor: string, limit?: number): Promise<ManifestCursorPage<T>>;
|
|
154
|
+
$prev(cursor: string, limit?: number): Promise<ManifestCursorPage<T>>;
|
|
155
|
+
$page(page: number, limit?: number): Promise<ManifestOffsetPage<T>>;
|
|
156
|
+
$reload(): Promise<void>;
|
|
157
|
+
/** Realtime events skipped by the growth cap since the last load. */
|
|
158
|
+
readonly $realtimeOverflow: number;
|
|
159
|
+
/** Loads the next page into the source (`paging` sources only); resolves with the rows added. */
|
|
160
|
+
$more(): Promise<number>;
|
|
161
|
+
/** Whether `$more()` can load another page; false at the end or at `max`. */
|
|
162
|
+
readonly $hasMore: boolean;
|
|
163
|
+
/** Appwrite's count for the current filters, or null when not requested. */
|
|
164
|
+
readonly $total: number | null;
|
|
165
|
+
/** True when `$total` hit Appwrite's counting ceiling. */
|
|
166
|
+
readonly $totalCapped: boolean;
|
|
167
|
+
/** Whether a write to row `id` is still unconfirmed. */
|
|
168
|
+
$saving(id: string): boolean;
|
|
169
|
+
/** Rows with an unconfirmed write. */
|
|
170
|
+
readonly $pending: number;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Detail of `manifest:data-mutation-success` / `manifest:data-mutation-error` on window. */
|
|
174
|
+
export interface ManifestMutationDetail {
|
|
175
|
+
mutationId: string;
|
|
176
|
+
type: 'create' | 'update' | 'delete';
|
|
177
|
+
dataSourceName: string;
|
|
178
|
+
entryId?: string;
|
|
179
|
+
result?: unknown;
|
|
180
|
+
error?: unknown;
|
|
73
181
|
}
|
|
74
182
|
|
|
75
183
|
/** Operations available on Appwrite-bucket (storage) sources. */
|
|
76
184
|
export interface ManifestAppwriteBucketOps {
|
|
77
|
-
$url(fileId: string): string;
|
|
78
|
-
$preview(fileId: string,
|
|
79
|
-
$download(fileId: string): string;
|
|
80
|
-
$openUrl(fileId: string): void;
|
|
81
|
-
$openPreview(fileId: string): void;
|
|
82
|
-
$openDownload(fileId: string): void;
|
|
83
|
-
$
|
|
185
|
+
$url(fileId: string, token?: string): string;
|
|
186
|
+
$preview(fileId: string, options?: Record<string, unknown>, token?: string): string;
|
|
187
|
+
$download(fileId: string, token?: string): string;
|
|
188
|
+
$openUrl(fileId: string, token?: string): void;
|
|
189
|
+
$openPreview(fileId: string, options?: Record<string, unknown>, token?: string): void;
|
|
190
|
+
$openDownload(fileId: string, filename?: string, token?: string): void;
|
|
191
|
+
$create(file: File | Blob, fileId?: string, permissions?: string[], onProgress?: (progress: unknown) => void): Promise<ManifestFile>;
|
|
192
|
+
$upload(file: File | Blob, opts?: Record<string, unknown>): Promise<ManifestFile>;
|
|
84
193
|
$remove(fileId: string): Promise<void>;
|
|
85
|
-
$
|
|
194
|
+
$delete(fileId: string | string[]): Promise<unknown>;
|
|
195
|
+
$duplicate(fileId: string, options?: { newName?: string; newFileId?: string }): Promise<ManifestFile>;
|
|
196
|
+
$filesFor(parentId: string, fieldName?: string): ManifestFile[];
|
|
197
|
+
$first(limit?: number): Promise<ManifestCursorPage<ManifestFile>>;
|
|
198
|
+
$next(cursor: string, limit?: number): Promise<ManifestCursorPage<ManifestFile>>;
|
|
199
|
+
$prev(cursor: string, limit?: number): Promise<ManifestCursorPage<ManifestFile>>;
|
|
200
|
+
$page(page: number, limit?: number): Promise<ManifestOffsetPage<ManifestFile>>;
|
|
86
201
|
$unlinkFrom(parentId: string, fileId: string): Promise<void>;
|
|
87
202
|
$removeFrom(parentId: string, fileId: string): Promise<void>;
|
|
88
203
|
}
|
|
89
204
|
|
|
90
205
|
/**
|
|
91
|
-
*
|
|
92
|
-
* Behaves as a regular `T[]`
|
|
93
|
-
* Manifest operators and state flags.
|
|
206
|
+
* `$x.<source>` for an array-of-rows source (CSV tabular, JSON arrays).
|
|
207
|
+
* Behaves as a regular `T[]` plus Manifest operators and state flags.
|
|
94
208
|
*/
|
|
95
209
|
export type ManifestArraySource<T> =
|
|
96
210
|
& ReadonlyArray<T>
|
|
97
211
|
& ManifestSourceState
|
|
98
|
-
& ManifestArrayOps<T
|
|
99
|
-
& Partial<ManifestAppwriteTableOps<T>>;
|
|
212
|
+
& ManifestArrayOps<T>;
|
|
100
213
|
|
|
101
|
-
/**
|
|
214
|
+
/** `$x.<source>` for an Appwrite table: rows plus server-side queries, mutations and paging. */
|
|
215
|
+
export type ManifestTableSource<T> =
|
|
216
|
+
& ReadonlyArray<T>
|
|
217
|
+
& ManifestSourceState
|
|
218
|
+
& Omit<ManifestArrayOps<T>, '$query'>
|
|
219
|
+
& ManifestAppwriteTableOps<T>;
|
|
220
|
+
|
|
221
|
+
/** `$x.<source>` for an object-shaped source (CSV key-value, JSON object, YAML map). */
|
|
102
222
|
export type ManifestObjectSource<T> = T & ManifestSourceState;
|
|
103
223
|
|
|
104
|
-
/**
|
|
105
|
-
export type ManifestBucketSource = ManifestSourceState & ManifestAppwriteBucketOps;
|
|
224
|
+
/** `$x.<source>` for an Appwrite storage bucket. */
|
|
225
|
+
export type ManifestBucketSource = ReadonlyArray<ManifestFile> & ManifestSourceState & ManifestAppwriteBucketOps;
|
|
106
226
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Precise row types, keyed by data source name. Declare them to override the
|
|
229
|
+
* column names `npx mnfst-types` reads from the contract:
|
|
230
|
+
*
|
|
231
|
+
* declare module 'mnfst' { interface ManifestRows { tasks: Task } }
|
|
232
|
+
*/
|
|
233
|
+
export interface ManifestRows { }
|
|
234
|
+
|
|
235
|
+
/** The row type for source `K`: a declared `ManifestRows` entry, else `Fallback`. */
|
|
236
|
+
export type ManifestRowFor<K extends string, Fallback> = K extends keyof ManifestRows ? ManifestRows[K] & ManifestRowSystem : Fallback;
|
|
110
237
|
|
|
111
238
|
/**
|
|
112
|
-
* Project
|
|
113
|
-
* `
|
|
114
|
-
* data (declarations appended below the AUGMENTATION marker).
|
|
239
|
+
* Project data sources, keyed by the names in `manifest.json`'s `data`.
|
|
240
|
+
* `npx mnfst-types` fills this in below the AUGMENTATION marker.
|
|
115
241
|
*/
|
|
116
|
-
export interface ManifestSources {
|
|
117
|
-
|
|
118
|
-
|
|
242
|
+
export interface ManifestSources { }
|
|
243
|
+
|
|
244
|
+
/** `$x` itself: the sources plus runtime registration and persistence controls. */
|
|
245
|
+
export type ManifestData = ManifestSources & {
|
|
246
|
+
$register(name: string, data: unknown[] | Record<string, unknown>): void;
|
|
247
|
+
$wipe(target?: string | { all: true }): Promise<void>;
|
|
248
|
+
};
|
|
119
249
|
|
|
120
250
|
/** `$auth` from the Appwrite auth plugin. Loose by design — auth API is broad. */
|
|
121
251
|
export interface ManifestAuth {
|
|
@@ -194,7 +324,7 @@ export type ManifestRoute = string;
|
|
|
194
324
|
export type ManifestModify = (attr: string) => string | undefined;
|
|
195
325
|
|
|
196
326
|
/** `$try(fn)` — run a callback and swallow any thrown error, returning undefined on failure. */
|
|
197
|
-
export type ManifestTry = <T>(fn: () => T) => T | undefined
|
|
327
|
+
export type ManifestTry = <T>(fn: () => T | Promise<T>, errorVar?: string) => Promise<T | undefined>;
|
|
198
328
|
|
|
199
329
|
/** `$pay` from the payments plugin: callable to start checkout, plus portal/state helpers. */
|
|
200
330
|
export interface ManifestPay {
|
|
@@ -587,13 +717,105 @@ export interface ManifestSubmitDetail {
|
|
|
587
717
|
message: string;
|
|
588
718
|
}
|
|
589
719
|
|
|
720
|
+
// ---------------------------------------------------------------------------
|
|
721
|
+
// App modules: components, stores and magics on `this`
|
|
722
|
+
// ---------------------------------------------------------------------------
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Alpine stores, keyed by name. Declare them so `$store.<name>` is checked:
|
|
726
|
+
*
|
|
727
|
+
* declare module 'mnfst' { interface ManifestStores { session: Session } }
|
|
728
|
+
*/
|
|
729
|
+
export interface ManifestStores { [name: string]: any }
|
|
730
|
+
|
|
731
|
+
/** Declared stores keep their types; any other name is `any` until it's declared. */
|
|
732
|
+
export type ManifestStoreMap = ManifestStores;
|
|
733
|
+
|
|
734
|
+
/** Magics available on `this` inside an Alpine component (Alpine's own plus Manifest's). */
|
|
735
|
+
export interface ManifestMagics {
|
|
736
|
+
$el: HTMLElement;
|
|
737
|
+
$root: HTMLElement;
|
|
738
|
+
$refs: Record<string, any>;
|
|
739
|
+
$store: ManifestStoreMap;
|
|
740
|
+
$data: Record<string, any>;
|
|
741
|
+
$watch(property: string, callback: (value: any, oldValue: any) => void): void;
|
|
742
|
+
$dispatch(event: string, detail?: unknown): void;
|
|
743
|
+
$nextTick(callback?: () => void): Promise<void>;
|
|
744
|
+
$id(name: string, key?: string | number): string;
|
|
745
|
+
$x: ManifestData;
|
|
746
|
+
$route: ManifestRoute;
|
|
747
|
+
$modify: ManifestModify;
|
|
748
|
+
$try: ManifestTry;
|
|
749
|
+
$computed<T>(fn: (scope: any) => T): T;
|
|
750
|
+
$auth: ManifestAuth;
|
|
751
|
+
$locale: ManifestLocale;
|
|
752
|
+
$toast: ManifestToast;
|
|
753
|
+
$color: ManifestColor;
|
|
754
|
+
$colorpicker: ManifestColorpicker;
|
|
755
|
+
$url: ManifestUrl;
|
|
756
|
+
$pay: ManifestPay;
|
|
757
|
+
$chat: ManifestChat;
|
|
758
|
+
$status: ManifestStatus;
|
|
759
|
+
$presence: ManifestPresence;
|
|
760
|
+
$date: ManifestDate;
|
|
761
|
+
$chart: ManifestChart;
|
|
762
|
+
$export: ManifestExport;
|
|
763
|
+
$import: ManifestImport;
|
|
764
|
+
$edit: ManifestEdit;
|
|
765
|
+
$rich: ManifestRichText;
|
|
766
|
+
$device: ManifestDevice;
|
|
767
|
+
$share: ManifestShare;
|
|
768
|
+
$push: ManifestPush;
|
|
769
|
+
$secure: ManifestSecure;
|
|
770
|
+
$links: ManifestLinks;
|
|
771
|
+
$app: ManifestApp;
|
|
772
|
+
$haptics: ManifestHaptics;
|
|
773
|
+
$biometric: ManifestBiometric;
|
|
774
|
+
$camera: ManifestCamera;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/** Lifecycle hooks Alpine calls on a component. */
|
|
778
|
+
export interface ManifestComponentHooks {
|
|
779
|
+
init?(): void | Promise<void>;
|
|
780
|
+
destroy?(): void;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* A component's state with `this` typed as that state plus every magic.
|
|
785
|
+
* Pair with an identity helper so `T` is inferred from the returned object:
|
|
786
|
+
*
|
|
787
|
+
* /** @template T @param {() => import('mnfst').ManifestComponent<T>} fn *\/
|
|
788
|
+
* export const component = (fn) => fn
|
|
789
|
+
*/
|
|
790
|
+
export type ManifestComponent<T> = T & ManifestComponentHooks & ThisType<T & ManifestMagics>;
|
|
791
|
+
|
|
792
|
+
/** The `Alpine` global, as app modules use it. */
|
|
793
|
+
export interface ManifestAlpine {
|
|
794
|
+
data<T>(name: string, factory: (...args: any[]) => T): void;
|
|
795
|
+
store<T>(name: string, value: T & ThisType<T>): void;
|
|
796
|
+
store<K extends string>(name: K): ManifestStores[K];
|
|
797
|
+
magic(name: string, callback: (el: HTMLElement, options: unknown) => unknown): void;
|
|
798
|
+
directive(name: string, callback: (...args: any[]) => unknown): unknown;
|
|
799
|
+
nextTick(callback?: () => void): Promise<void>;
|
|
800
|
+
effect(callback: () => void): unknown;
|
|
801
|
+
reactive<T extends object>(value: T): T;
|
|
802
|
+
raw<T>(value: T): T;
|
|
803
|
+
evaluate(el: Element, expression: string): unknown;
|
|
804
|
+
initTree(el: Element): void;
|
|
805
|
+
$data(el: Element): Record<string, any>;
|
|
806
|
+
}
|
|
807
|
+
|
|
590
808
|
// ---------------------------------------------------------------------------
|
|
591
809
|
// Global declarations (what Alpine exposes inside `x-data`, `x-show`, etc.)
|
|
592
810
|
// ---------------------------------------------------------------------------
|
|
593
811
|
|
|
594
812
|
declare global {
|
|
595
813
|
/** Project data sources registered in manifest.json. */
|
|
596
|
-
const $x:
|
|
814
|
+
const $x: ManifestData;
|
|
815
|
+
/** Alpine stores. */
|
|
816
|
+
const $store: ManifestStoreMap;
|
|
817
|
+
/** Alpine, loaded by Manifest; reach it inside `alpine:init`. */
|
|
818
|
+
const Alpine: ManifestAlpine;
|
|
597
819
|
/** The current route path (compare or .startsWith against it). */
|
|
598
820
|
const $route: ManifestRoute;
|
|
599
821
|
/** Read a parent component attribute (Manifest's prop mechanism). */
|
|
@@ -669,7 +891,7 @@ declare global {
|
|
|
669
891
|
/** The two-line same-origin /sw.js stub pinned to a framework version. */
|
|
670
892
|
swStub?(version?: string): string;
|
|
671
893
|
};
|
|
672
|
-
Alpine?:
|
|
894
|
+
Alpine?: ManifestAlpine;
|
|
673
895
|
__manifestLoaded?: unknown;
|
|
674
896
|
/** Pending work that will still change the page; mnfst-render's auto settle won't snapshot early while count > 0. */
|
|
675
897
|
ManifestPending?: {
|
|
@@ -700,6 +922,16 @@ declare global {
|
|
|
700
922
|
'submit:error': CustomEvent<ManifestSubmitDetail>;
|
|
701
923
|
}
|
|
702
924
|
|
|
925
|
+
interface WindowEventMap {
|
|
926
|
+
'manifest:data-mutation-success': CustomEvent<ManifestMutationDetail>;
|
|
927
|
+
'manifest:data-mutation-error': CustomEvent<ManifestMutationDetail>;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/** x-virtual: the last rendered row neared the end of the list (bubbles). */
|
|
931
|
+
interface HTMLElementEventMap {
|
|
932
|
+
'virtual-end': CustomEvent<{ length: number }>;
|
|
933
|
+
}
|
|
934
|
+
|
|
703
935
|
/**
|
|
704
936
|
* Fired when the utilities runtime sees a class the baked sheet (and
|
|
705
937
|
* `manifest.json`'s `utilities.safelist`/`patterns`) doesn't cover, after
|
|
@@ -720,6 +952,7 @@ declare global {
|
|
|
720
952
|
// ---------------------------------------------------------------------------
|
|
721
953
|
|
|
722
954
|
// (No project augmentations yet — run `npx mnfst-types` to generate.)
|
|
955
|
+
export interface ManifestSources { [sourceName: string]: any }
|
|
723
956
|
|
|
724
957
|
// ---------------------------------------------------------------------------
|
|
725
958
|
// AUGMENTATION:end
|
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.278';
|
|
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-cVP8/j1hDbYLj+EugdI/S15lvavKOqM8Hw5I7CV2WUhp33nLyzipjgR90REGD43f",
|
|
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-eEwDOCsUPZyJ+MXk0dRmLV1O+I1fMDb5vtmGNnBcxic2LWbF/vY2IDukPsnol+9s",
|
|
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-j96v7U8po0Jwk5UjnsPdJTOydgilWGDsF2s9w/YAaPyL5JeVlbVCxXnL8gotSYU4",
|
|
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,21 @@
|
|
|
275
275
|
}
|
|
276
276
|
]
|
|
277
277
|
},
|
|
278
|
+
"paging": {
|
|
279
|
+
"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
|
+
"oneOf": [
|
|
281
|
+
{ "type": "string", "enum": ["all", "window"] },
|
|
282
|
+
{
|
|
283
|
+
"type": "object",
|
|
284
|
+
"properties": {
|
|
285
|
+
"mode": { "type": "string", "enum": ["all", "window"] },
|
|
286
|
+
"size": { "type": "integer", "minimum": 1, "maximum": 4999 },
|
|
287
|
+
"max": { "type": "integer", "minimum": 1 }
|
|
288
|
+
},
|
|
289
|
+
"additionalProperties": false
|
|
290
|
+
}
|
|
291
|
+
]
|
|
292
|
+
},
|
|
278
293
|
"realtime": {
|
|
279
294
|
"description": "Realtime subscription config. false disables the subscription. { mode, maxRows } bounds growth: 'append' (default) stops appending at maxRows and counts skipped events in $realtimeOverflow; 'window' keeps the initial window size by evicting the oldest realtime-appended rows. maxRows defaults to max(500, 2x the initially loaded rows); 0 opts into legacy unbounded growth. serverFilter picks which filters ride the Appwrite realtime subscription server-side: 'scope' (default) sends only scope-column filters; 'all' (alias true) sends every expressible filter — rows that stop matching then drop on the next load instead of instantly; false sends none.",
|
|
280
295
|
"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.278';
|
|
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)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mnfst",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.278",
|
|
4
4
|
"private": false,
|
|
5
5
|
"workspaces": [
|
|
6
6
|
"templates/starter",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"rimraf": "^5.0.0",
|
|
76
76
|
"rollup": "^4.24.2",
|
|
77
77
|
"terser": "^5.47.1",
|
|
78
|
+
"typescript": "^7.0.2",
|
|
78
79
|
"vitest": "^4.1.2"
|
|
79
80
|
},
|
|
80
81
|
"keywords": [
|