mnfst 0.5.295 → 0.5.297

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  (function () {
4
4
 
5
- const MANIFEST_BUILD_VERSION = '0.5.295';
5
+ const MANIFEST_BUILD_VERSION = '0.5.297';
6
6
 
7
7
  /* Manifest Data Sources - Appwrite Integration */
8
8
 
package/lib/manifest.d.ts CHANGED
@@ -194,13 +194,13 @@ export interface ManifestAppwriteBucketOps {
194
194
  $remove(fileId: string): Promise<void>;
195
195
  $delete(fileId: string | string[]): Promise<unknown>;
196
196
  $duplicate(fileId: string, options?: { newName?: string; newFileId?: string }): Promise<ManifestFile>;
197
- $filesFor(parentId: string, fieldName?: string): ManifestFile[];
197
+ $filesFor(tableName: string, entryId: string, fileIdsColumn?: string): Promise<ManifestFile[]>;
198
198
  $first(limit?: number): Promise<ManifestCursorPage<ManifestFile>>;
199
199
  $next(cursor: string, limit?: number): Promise<ManifestCursorPage<ManifestFile>>;
200
200
  $prev(cursor: string, limit?: number): Promise<ManifestCursorPage<ManifestFile>>;
201
201
  $page(page: number, limit?: number): Promise<ManifestOffsetPage<ManifestFile>>;
202
- $unlinkFrom(parentId: string, fileId: string): Promise<void>;
203
- $removeFrom(parentId: string, fileId: string): Promise<void>;
202
+ $unlinkFrom(tableName: string, entryId: string, file: string | { $id: string }, fileIdsColumn?: string): Promise<void>;
203
+ $removeFrom(tableName: string, entryId: string, file: string | { $id: string }, fileIdsColumn?: string): Promise<ManifestFile[] | null>;
204
204
  }
205
205
 
206
206
  /**
@@ -2,7 +2,7 @@
2
2
 
3
3
  (function () {
4
4
 
5
- const MANIFEST_BUILD_VERSION = '0.5.295';
5
+ const MANIFEST_BUILD_VERSION = '0.5.297';
6
6
 
7
7
  /* Manifest Data Sources - Configuration */
8
8
 
@@ -11,25 +11,36 @@ const MANIFEST_BUILD_VERSION = '0.5.295';
11
11
  // doing `window.__manifestLoaded.foo = …` before the loader populates it (or in a
12
12
  // no-loader setup) can leave a stub without `data`/`components`, which would otherwise
13
13
  // mask every data source. Fall through to fetching the real manifest in that case.
14
- async function ensureManifest() {
15
- const looksComplete = (m) => m && typeof m === 'object' &&
16
- (m.data || m.components || m.preloadedComponents || m.appwrite || m.render);
14
+ const looksComplete = (m) => m && typeof m === 'object' &&
15
+ (m.data || m.components || m.preloadedComponents || m.appwrite || m.render);
16
+ let resolvedManifest = null;
17
+
18
+ // Synchronous accessor: the manifest if already loaded, else null
19
+ function getManifest() {
17
20
  if (looksComplete(window.ManifestComponentsRegistry?.manifest)) {
18
21
  return window.ManifestComponentsRegistry.manifest;
19
22
  }
20
23
  if (looksComplete(window.__manifestLoaded)) {
21
24
  return window.__manifestLoaded;
22
25
  }
26
+ return resolvedManifest;
27
+ }
28
+
29
+ async function ensureManifest() {
30
+ const loaded = getManifest();
31
+ if (loaded) return loaded;
23
32
 
24
33
  // One request per boot, shared with the loader and the other plugins (window.__manifestPromise)
25
34
  if (window.__manifestPromise) {
26
35
  const shared = await window.__manifestPromise.catch(() => null);
27
- if (looksComplete(shared)) return shared;
36
+ if (looksComplete(shared)) return (resolvedManifest = shared);
28
37
  }
29
38
  try {
30
39
  const manifestUrl = (document.querySelector('link[rel="manifest"]')?.getAttribute('href')) || '/manifest.json';
31
40
  window.__manifestPromise = fetch(manifestUrl).then(r => r.json()).then(m => { interpolateManifest(m); return m; });
32
- return await window.__manifestPromise;
41
+ const fetched = await window.__manifestPromise;
42
+ if (looksComplete(fetched)) resolvedManifest = fetched;
43
+ return fetched;
33
44
  } catch (error) {
34
45
  console.error('[Manifest Data] Failed to load manifest:', error);
35
46
  return null;
@@ -259,6 +270,7 @@ function getQueries(dataSource) {
259
270
  // Export functions to window for use by other subscripts
260
271
  window.ManifestDataConfig = {
261
272
  ensureManifest,
273
+ getManifest,
262
274
  interpolateEnvVars,
263
275
  interpolateManifest,
264
276
  getNestedValue,
@@ -7074,7 +7086,6 @@ function createReactiveFileManager(tableName, entryId, bucketName, columnName) {
7074
7086
  throw new Error(`[Manifest Data] Table "${tableName}" not found`);
7075
7087
  }
7076
7088
 
7077
- // Parse storage config directly; parseStorageConfig's getManifest() may be null here
7078
7089
  const storageConfigObj = tableDataSource?.storage;
7079
7090
  if (!storageConfigObj || typeof storageConfigObj !== 'object') {
7080
7091
  throw new Error(`[Manifest Data] Storage bucket "${bucketName}" not configured for table "${tableName}"`);
@@ -7518,11 +7529,16 @@ function queueEntryFileWrite(tableName, entryId, fileIdsColumn, write) {
7518
7529
 
7519
7530
  // Link a file to a table entry by adding the file ID to the entry's fileIds array
7520
7531
  // Generic function - works with any table and any scope
7521
- function linkFileToEntry(tableName, entryId, fileId, fileIdsColumn = 'fileIds') {
7522
- return queueEntryFileWrite(tableName, entryId, fileIdsColumn, () => writeFileLink(tableName, entryId, fileId, fileIdsColumn));
7532
+ // The table's generation is captured at the call, so a queued write never lands for a later identity
7533
+ function linkFileToEntry(tableName, entryId, fileId, fileIdsColumn = 'fileIds', options = {}) {
7534
+ const isCurrent = identityGuard(tableName, options.isCurrent);
7535
+ return queueEntryFileWrite(tableName, entryId, fileIdsColumn, () => writeFileLink(tableName, entryId, fileId, fileIdsColumn, { ...options, isCurrent }));
7523
7536
  }
7524
7537
 
7525
- async function writeFileLink(tableName, entryId, fileId, fileIdsColumn) {
7538
+ // options.isCurrent: false once the identity that started the write is gone
7539
+ async function writeFileLink(tableName, entryId, fileId, fileIdsColumn, options = {}) {
7540
+ const stale = () => !!options.isCurrent && !options.isCurrent();
7541
+ if (stale()) return false;
7526
7542
  const manifest = await window.ManifestDataConfig.ensureManifest();
7527
7543
  const tableDataSource = manifest?.data?.[tableName];
7528
7544
 
@@ -7544,6 +7560,8 @@ async function writeFileLink(tableName, entryId, fileId, fileIdsColumn) {
7544
7560
  entryId
7545
7561
  );
7546
7562
 
7563
+ if (stale()) return false;
7564
+
7547
7565
  if (!entry) {
7548
7566
  throw new Error(`[Manifest Data] Entry "${entryId}" not found in table "${tableName}"`);
7549
7567
  }
@@ -7748,10 +7766,13 @@ function fileIdOf(id) {
7748
7766
  return id && typeof id === 'object' ? id.$id : id;
7749
7767
  }
7750
7768
 
7751
- // True while the source's generation (bumped on sign-out / account switch) and the caller's guard hold
7769
+ // True while the identity epoch and the source's generation (both bumped on sign-out / account switch) and the caller's guard hold
7752
7770
  function identityGuard(dataSourceName, outer) {
7771
+ const epoch = window.ManifestDataMain?.identityEpoch?.() ?? 0;
7753
7772
  const generation = window.ManifestDataStore?.sourceGeneration?.(dataSourceName);
7754
- return () => (!outer || outer()) && window.ManifestDataStore?.sourceGeneration?.(dataSourceName) === generation;
7773
+ return () => (!outer || outer())
7774
+ && (window.ManifestDataMain?.identityEpoch?.() ?? 0) === epoch
7775
+ && window.ManifestDataStore?.sourceGeneration?.(dataSourceName) === generation;
7755
7776
  }
7756
7777
 
7757
7778
  // options.isCurrent: false once the identity that started the write is gone
@@ -8315,6 +8336,11 @@ function createAppwriteMethodsHandler(dataSourceName, reloadDataSource) {
8315
8336
  } else if (method === '$duplicate') {
8316
8337
  const [entryId, options = {}] = args;
8317
8338
  const { files = 'same', newRowId, ...overrides } = options;
8339
+ // The copy (and its file links) lands only for the identity that read the original
8340
+ const isCurrent = window.ManifestDataProxiesFiles?.identityGuard?.(dataSourceName) || (() => true);
8341
+ const stopIfStale = () => {
8342
+ if (!isCurrent()) throw new Error('[Manifest Data] $duplicate stopped: the signed-in user changed');
8343
+ };
8318
8344
 
8319
8345
  // Get the original entry
8320
8346
  const originalEntry = await window.ManifestDataAppwrite.getTableRow(
@@ -8384,6 +8410,7 @@ function createAppwriteMethodsHandler(dataSourceName, reloadDataSource) {
8384
8410
  // Duplicate each file
8385
8411
  const newFileIds = [];
8386
8412
  for (const file of originalFiles) {
8413
+ stopIfStale();
8387
8414
  try {
8388
8415
  // Download file content
8389
8416
  const fileBlob = await window.ManifestDataAppwrite.getFileContentAsBlob(bucketId, file.$id);
@@ -8423,6 +8450,7 @@ function createAppwriteMethodsHandler(dataSourceName, reloadDataSource) {
8423
8450
  }
8424
8451
 
8425
8452
  // Create the duplicate entry using existing $create logic
8453
+ stopIfStale();
8426
8454
  return await handleMethod('$create', duplicateData, newRowId);
8427
8455
  } else if (method === '$query') {
8428
8456
  let [queries] = args;
@@ -8566,6 +8594,8 @@ function createAppwriteMethodsHandler(dataSourceName, reloadDataSource) {
8566
8594
 
8567
8595
  if (method === '$create') {
8568
8596
  let [fileId, file, permissions, onProgress] = args;
8597
+ // The entry link lands only for the identity that started the upload
8598
+ const linkCurrent = window.ManifestDataProxiesFiles?.identityGuard?.(dataSourceName, onProgress?.isCurrent) || (() => true);
8569
8599
 
8570
8600
  // Appwrite requires fileId to be provided - it doesn't auto-generate
8571
8601
  // If fileId is not provided or is a File object (first arg is file), generate one
@@ -8847,7 +8877,7 @@ function createAppwriteMethodsHandler(dataSourceName, reloadDataSource) {
8847
8877
  try {
8848
8878
  const linkFileToEntry = window.ManifestDataProxiesFiles?.linkFileToEntry;
8849
8879
  if (linkFileToEntry) {
8850
- await linkFileToEntry(tableName, entryId, result.$id, fileIdsColumn);
8880
+ await linkFileToEntry(tableName, entryId, result.$id, fileIdsColumn, { isCurrent: linkCurrent });
8851
8881
  }
8852
8882
  } catch (linkError) {
8853
8883
  // Check if error is about missing column
@@ -9387,6 +9417,8 @@ window.ManifestDataProxiesMagic.createFilesMethod = createFilesMethod;
9387
9417
 
9388
9418
  function createUploadMethod(dataSourceName, reloadDataSource) {
9389
9419
  return async function (entryId, fileOrEvent, bucketName) {
9420
+ // Links land only for the identity that started the upload
9421
+ const isCurrent = window.ManifestDataProxiesFiles?.identityGuard?.(dataSourceName);
9390
9422
  const manifest = await window.ManifestDataConfig.ensureManifest();
9391
9423
  if (!manifest?.data) {
9392
9424
  throw new Error('[Manifest Data] Manifest not available');
@@ -9490,7 +9522,8 @@ function createUploadMethod(dataSourceName, reloadDataSource) {
9490
9522
  entryId: entryId,
9491
9523
  table: dataSourceName,
9492
9524
  fileIdsColumn: resolvedColumnName,
9493
- sourceUnloaded
9525
+ sourceUnloaded,
9526
+ isCurrent
9494
9527
  }).then(result => {
9495
9528
  // Clear uploading state for this file
9496
9529
  if (clearUploadingFile) {
@@ -11434,6 +11467,8 @@ function registerFilesDirective() {
11434
11467
 
11435
11468
  // Set new timeout for debouncing
11436
11469
  loadTimeout = setTimeout(async () => {
11470
+ // The fileIds sync writes only for the identity that read them
11471
+ const isCurrent = window.ManifestDataProxiesFiles?.identityGuard?.('projects') || (() => true);
11437
11472
  // Double-check project still exists before making API call using projectId
11438
11473
  const store = Alpine.store('data');
11439
11474
  const projects = store?.projects;
@@ -11586,7 +11621,7 @@ function registerFilesDirective() {
11586
11621
  const databaseFileIdsJson = JSON.stringify(databaseFileIdsArray);
11587
11622
  const databaseIsStale = databaseFileIds && databaseFileIdsJson !== lastFileIds;
11588
11623
 
11589
- if (storeIsStale || databaseIsStale) {
11624
+ if ((storeIsStale || databaseIsStale) && isCurrent()) {
11590
11625
  console.warn('[Manifest Data] Store/Database fileIds is STALE - cleaning up:', {
11591
11626
  directiveInstanceId,
11592
11627
  projectId: currentProjectId,
@@ -11617,7 +11652,7 @@ function registerFilesDirective() {
11617
11652
  const tableId = window.ManifestDataConfig.getAppwriteTableId(tableDataSource);
11618
11653
  const appwriteConfig = await window.ManifestDataConfig.getAppwriteConfig(tableDataSource);
11619
11654
 
11620
- if (appwriteConfig && window.ManifestDataAppwrite?.updateRow) {
11655
+ if (appwriteConfig && window.ManifestDataAppwrite?.updateRow && isCurrent()) {
11621
11656
  await window.ManifestDataAppwrite.updateRow(
11622
11657
  appwriteConfig.databaseId,
11623
11658
  tableId,
@@ -12012,6 +12047,9 @@ function confirmedIdentity() {
12012
12047
  return auth.isAuthenticated === true ? (authUserId(auth) || '') : '';
12013
12048
  }
12014
12049
 
12050
+ // Bumped synchronously when an identity ends (sign-out, account switch), before any source reset; covers never-loaded sources
12051
+ let identityEpoch = 0;
12052
+
12015
12053
  // Identity change (sign-in, sign-out, account switch): identity-bound sources reload for the new identity.
12016
12054
  // A previous user's rows drop at once; rows read signed out stay live until the reload lands.
12017
12055
  function setupAuthResetListener() {
@@ -12058,6 +12096,7 @@ function setupAuthResetListener() {
12058
12096
  return;
12059
12097
  }
12060
12098
  // An identity switch (A to B) starts clean with the defaults; a first sign-in keeps the $query
12099
+ if (prev !== '') identityEpoch++;
12061
12100
  reset(prev !== '', prev === '' && next !== '');
12062
12101
  };
12063
12102
  ['manifest:auth:logout', 'manifest:auth:session-cleared', 'manifest:auth:login', 'manifest:auth:anonymous', 'manifest:auth:initialized']
@@ -13594,6 +13633,7 @@ async function initializeDataSourcesPlugin() {
13594
13633
  noteQueryIntent: (dataSourceName, queries) => queryIntents.set(dataSourceName, queries),
13595
13634
  dropQueryIntent: (dataSourceName, queries) => { if (queryIntents.get(dataSourceName) === queries) queryIntents.delete(dataSourceName); },
13596
13635
  withRetry,
13636
+ identityEpoch: () => identityEpoch,
13597
13637
  pagingSpec,
13598
13638
  fetchPagedRows,
13599
13639
  pagedWant,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "manifest.appwrite.auth.js": "sha384-gWLSeVPqCLMiUZB8MU7GqMg3x2yULFUsp8nTTZrPp/9Dlkix42rBn9yIimvwrHqZ",
3
- "manifest.appwrite.data.js": "sha384-vpsdC1jM27OXG1o/Lqvy8VG1mHxTuTDM/Gid5eQ0sUYpurdugM/tV1TOQlcsq/cp",
3
+ "manifest.appwrite.data.js": "sha384-+C9+NUQGnYQqXCYt+fb97/J0b13Vx7eLsBlBlYsG+6/Q8bfHUR2TBtOsG7+s/4OD",
4
4
  "manifest.appwrite.presences.js": "sha384-LINPhIPTCK+rA8zd+HPUzMSEgH6Sl2vQMEyItT97bnEE2FYGYKqjXX+CWdt6nl9z",
5
5
  "manifest.bindings.js": "sha384-lPtMf8Ykaic9gNVZKq8Scia1881ZeMAyxer3WCIkUNwwrgzGBWto1OXADUwjvORF",
6
6
  "manifest.charts.js": "sha384-cf1N+ssSR5IL2qufv8noB5QOJrSvL7J0sLKgbJmyTDl1HodQ/Bkyf/QntO6Iynvi",
@@ -11,7 +11,7 @@
11
11
  "manifest.combobox.js": "sha384-/lJo6vaxKjgnBSRs/dzkhK1dzGk3GBw8FISoNJZB70mwAVwu1k5veZyBXjOb4keS",
12
12
  "manifest.components.js": "sha384-7lu4Nw2GqpAUn63c3gYEvgfM58PYsdoPv3wzqPQfZ5bravqOY/lfE8HFKHsKflQj",
13
13
  "manifest.computed.js": "sha384-GYML/e81gQfN+iDbqhPUgny8bINCyL+SrbTofoGk4hlCnLLjv51mCv42JMqq+ku5",
14
- "manifest.data.js": "sha384-MY08UMqVNj9XO7Lwlu5amMRPzjFWrjEKRN5cryNUn8NW5BrjfW67WAc2a9theuJd",
14
+ "manifest.data.js": "sha384-a94NfFVv/07ZCMAbhGEuftFHrYqSP/VcI/2LUrtp17kRTQm4diiM4Fazu0iMG6M6",
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-bhlRTHccsPyrkKyzpejm386tYIklNr3ZQrMqCkZiVnv576W/kzqtAh8BMyBrSVnr",
32
+ "manifest.sw.js": "sha384-ZE4beB999SQ8tMqo9NrmqYs1sAynIYThfc6qv8JxQG2gCJavrYLa4xITK6npUgah",
33
33
  "manifest.tabs.js": "sha384-otU09H7jnawVKQdLAYpMCd3jx00tgyPVr42D2hLIBzN5dG4se505YesavdnMqEi1",
34
34
  "manifest.tailwind.js": "sha384-yuP3LEvWU+QVjxjkZ0YhErtC9RrGmhOmHjjFjhS9obqZbp5/KTIEnSR0CXDvHE0B",
35
35
  "manifest.toasts.js": "sha384-UpOz9fAdGeGUhL0NamBg5iPepEfIy73p9HYdcxfOQC5b7CVsl7Our0skdZzaLNcC",
@@ -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.295';
19
+ const BUILD_VERSION = '0.5.297';
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.295",
3
+ "version": "0.5.297",
4
4
  "private": false,
5
5
  "workspaces": [
6
6
  "templates/starter",