mnfst 0.5.280 → 0.5.282

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.280';
5
+ const MANIFEST_BUILD_VERSION = '0.5.282';
6
6
 
7
7
  /* Manifest Data Sources - Appwrite Integration */
8
8
 
@@ -1749,124 +1749,4 @@ window.ManifestDataPagination = {
1749
1749
  };
1750
1750
 
1751
1751
 
1752
- /* Manifest Data Sources - Contract checks */
1753
-
1754
- // Rows of Appwrite sources whose table the contract declares throw when app code
1755
- // reads a column that is undeclared and never seen on a row. Dev hosts by default.
1756
- (function () {
1757
- const proxies = new WeakMap();
1758
- const targets = new WeakMap();
1759
- const warned = new Set();
1760
- // Read by the framework on every row; storage columns are added per source
1761
- const ALLOWED = new Set(['then', 'catch', 'finally', 'toJSON', 'length', 'contentType', 'fileIds']);
1762
- let enabled;
1763
- let tables = null;
1764
- const tableBySource = new Map();
1765
- const seenBySource = new Map();
1766
- let appwriteSources = null;
1767
-
1768
- function devHost(h) {
1769
- return h === 'localhost' || h === '127.0.0.1' || h === '[::1]' || h === '::1' || h === '0.0.0.0' ||
1770
- h.endsWith('.localhost') || h.endsWith('.local') || h.endsWith('.test');
1771
- }
1772
-
1773
- function hostMatches(pattern, host) {
1774
- const re = new RegExp('^' + String(pattern).toLowerCase().replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^.]*') + '$');
1775
- return re.test(host);
1776
- }
1777
-
1778
- function config(manifest) {
1779
- const c = manifest && manifest.contract;
1780
- if (typeof c === 'string') return { module: c, checks: 'dev' };
1781
- if (c && typeof c === 'object' && typeof c.module === 'string') return { module: c.module, checks: c.checks === undefined ? 'dev' : c.checks };
1782
- return null;
1783
- }
1784
-
1785
- function decide(manifest) {
1786
- const cfg = config(manifest);
1787
- if (!cfg || cfg.checks === false) return false;
1788
- const host = String(location.hostname || '').toLowerCase();
1789
- if (cfg.checks === true) return cfg;
1790
- if (devHost(host)) return cfg;
1791
- return Array.isArray(cfg.checks) && cfg.checks.some(p => hostMatches(p, host)) ? cfg : false;
1792
- }
1793
-
1794
- function load(manifest, cfg) {
1795
- import(new URL(cfg.module, location.origin + '/').href).then(mod => {
1796
- tables = mod && mod.tables && typeof mod.tables === 'object' ? mod.tables : {};
1797
- const defaultDb = manifest.appwrite && (manifest.appwrite.databaseId || manifest.appwrite.database);
1798
- for (const [source, src] of Object.entries(manifest.data || {})) {
1799
- if (!src || typeof src.appwriteTableId !== 'string') continue;
1800
- const db = src.appwriteDatabaseId || defaultDb;
1801
- const hit = Object.entries(tables).find(([key, t]) => t && (t.id || key) === src.appwriteTableId && (!t.database || !db || t.database === db));
1802
- if (!hit || !Array.isArray(hit[1].columns)) continue;
1803
- const columns = new Set(hit[1].columns);
1804
- for (const c of Object.values(src.storage || {})) columns.add(typeof c === 'string' ? c : (c && c.column) || 'fileIds');
1805
- tableBySource.set(source, { key: hit[0], columns });
1806
- }
1807
- }).catch(e => {
1808
- console.warn(`[Manifest] contract ${cfg.module} failed to load; column checks are off`, e);
1809
- tables = {};
1810
- });
1811
- }
1812
-
1813
- function isEnabled() {
1814
- if (enabled !== undefined) return enabled;
1815
- const manifest = window.__manifestLoaded;
1816
- if (!manifest) return false;
1817
- const cfg = decide(manifest);
1818
- enabled = !!cfg;
1819
- if (cfg) {
1820
- appwriteSources = new Set(Object.entries(manifest.data || {}).filter(([, s]) => s && typeof s.appwriteTableId === 'string').map(([k]) => k));
1821
- load(manifest, cfg);
1822
- }
1823
- return enabled;
1824
- }
1825
-
1826
- const known = (key, table) => key[0] === '$' || key[0] === '_' || ALLOWED.has(key) || table.columns.has(key);
1827
-
1828
- function drift(source, table, row) {
1829
- for (const key of Object.keys(row)) {
1830
- if (known(key, table) || warned.has(source + '\0' + key)) continue;
1831
- warned.add(source + '\0' + key);
1832
- console.warn(`[Manifest] data source "${source}" has column "${key}", which the contract does not declare for "${table.key}"`);
1833
- }
1834
- }
1835
-
1836
- function guard(source, row) {
1837
- if (!row || typeof row !== 'object' || Array.isArray(row) || !isEnabled() || !appwriteSources.has(source)) return row;
1838
- const existing = proxies.get(row);
1839
- if (existing) return existing;
1840
- let seen = seenBySource.get(source);
1841
- if (!seen) seenBySource.set(source, seen = new Set());
1842
- for (const key of Object.keys(row)) seen.add(key);
1843
- let checked = false;
1844
- const proxy = new Proxy(row, {
1845
- // App reads arrive through Alpine's reactive proxy; its own old-value reads use this one
1846
- get(target, key, receiver) {
1847
- if (typeof key === 'string' && tables && receiver !== proxy) {
1848
- const table = tableBySource.get(source);
1849
- if (table) {
1850
- if (!checked) { checked = true; drift(source, table, target); }
1851
- if (!known(key, table) && !(key in target) && !seen.has(key)) {
1852
- throw new Error(`[Manifest] "${key}" is not a column of "${table.key}" in the contract (data source "${source}")`);
1853
- }
1854
- }
1855
- }
1856
- return Reflect.get(target, key, receiver);
1857
- }
1858
- });
1859
- proxies.set(row, proxy);
1860
- proxies.set(proxy, proxy);
1861
- targets.set(proxy, row);
1862
- return proxy;
1863
- }
1864
-
1865
- // Framework reads go through the unchecked row
1866
- const raw = (obj) => (obj && targets.get(obj)) || obj;
1867
-
1868
- window.ManifestDataContract = { guard, raw };
1869
- })();
1870
-
1871
-
1872
1752
  })();
package/lib/manifest.d.ts CHANGED
@@ -226,8 +226,8 @@ export type ManifestObjectSource<T> = T & ManifestSourceState;
226
226
  export type ManifestBucketSource = ReadonlyArray<ManifestFile> & ManifestSourceState & ManifestAppwriteBucketOps;
227
227
 
228
228
  /**
229
- * Precise row types, keyed by data source name. Declare them to override the
230
- * column names `npx mnfst-types` reads from the contract:
229
+ * Precise row types, keyed by data source name. Appwrite rows accept any
230
+ * field until declared here:
231
231
  *
232
232
  * declare module 'mnfst' { interface ManifestRows { tasks: Task } }
233
233
  */
@@ -2,7 +2,7 @@
2
2
 
3
3
  (function () {
4
4
 
5
- const MANIFEST_BUILD_VERSION = '0.5.280';
5
+ const MANIFEST_BUILD_VERSION = '0.5.282';
6
6
 
7
7
  /* Manifest Data Sources - Configuration */
8
8
 
@@ -397,7 +397,7 @@ function mergeRowFields(target, fields, dataSourceName) {
397
397
  if (key === '$files') continue;
398
398
  const value = fields[key];
399
399
  if (sameScalarOrList(raw[key], value)) continue;
400
- target[key] = createReactiveReferences(value, dataSourceName, true);
400
+ target[key] = createReactiveReferences(value, dataSourceName);
401
401
  }
402
402
  }
403
403
 
@@ -955,25 +955,24 @@ function getRawData(dataSourceName) {
955
955
  }
956
956
 
957
957
  // New object/array references (incl. nested arrays like fileIds) so Alpine tracks changes
958
- function createReactiveReferences(data, dataSourceName = null, nested = false) {
958
+ function createReactiveReferences(data, dataSourceName = null) {
959
959
  if (data === null || data === undefined) {
960
960
  return data;
961
961
  }
962
962
 
963
963
  if (Array.isArray(data)) {
964
964
  // Create new array with new references for each item
965
- return data.map(item => createReactiveReferences(item, dataSourceName, nested));
965
+ return data.map(item => createReactiveReferences(item, dataSourceName));
966
966
  }
967
967
 
968
968
  if (typeof data === 'object') {
969
969
  // Object.keys, not for…in + .hasOwnProperty (see deepSeal). Hot path for
970
970
  // every Appwrite mutation result and realtime event.
971
971
  const newObj = {};
972
- let self = newObj;
973
972
  for (const key of Object.keys(data)) {
974
973
  const value = data[key];
975
974
  // Recursively create new references for nested objects/arrays
976
- newObj[key] = createReactiveReferences(value, dataSourceName, true);
975
+ newObj[key] = createReactiveReferences(value, dataSourceName);
977
976
  }
978
977
 
979
978
  // Detect file objects (have mimeType or sizeOriginal)
@@ -1012,7 +1011,7 @@ function createReactiveReferences(data, dataSourceName = null, nested = false) {
1012
1011
  data.$id,
1013
1012
  bucketName,
1014
1013
  columnName,
1015
- { owner: self }
1014
+ { owner: newObj }
1016
1015
  );
1017
1016
 
1018
1017
  // Assign computed array to entry
@@ -1199,11 +1198,7 @@ function createReactiveReferences(data, dataSourceName = null, nested = false) {
1199
1198
  });
1200
1199
  }
1201
1200
 
1202
- // Contract checks wrap top-level Appwrite rows (dev and opted-in hosts)
1203
- if (!nested && isDatabaseEntry && dataSourceName && window.ManifestDataContract) {
1204
- self = window.ManifestDataContract.guard(dataSourceName, newObj);
1205
- }
1206
- return self;
1201
+ return newObj;
1207
1202
  }
1208
1203
 
1209
1204
  // Primitives can be returned as-is
@@ -3387,7 +3382,9 @@ async function executeMutation(mutationConfig) {
3387
3382
  if (type === 'create') {
3388
3383
  // Generate temporary ID if not provided
3389
3384
  const tempId = data.$id || `temp_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
3390
- optimisticData = { ...data, $id: tempId };
3385
+ // Provisional timestamps so the placeholder sorts as the newest row; the server's replace them
3386
+ const now = new Date().toISOString();
3387
+ optimisticData = { $createdAt: now, $updatedAt: now, ...data, $id: tempId };
3391
3388
  resolvedEntryId = tempId;
3392
3389
 
3393
3390
  // Set creating state
@@ -3475,8 +3472,15 @@ async function executeMutation(mutationConfig) {
3475
3472
  clearSourceCaches(dataSourceName);
3476
3473
  } else if (store && arr) {
3477
3474
  if (index !== -1) {
3475
+ // The server row takes its own sort position (its values may differ from the placeholder's)
3478
3476
  const ds = window.ManifestDataStore;
3479
- store[dataSourceName].splice(index, 1, ds.createReactiveReferences(result, dataSourceName));
3477
+ const created = ds.createReactiveReferences(result, dataSourceName);
3478
+ if (window.ManifestDataMain?.orderFor?.(dataSourceName)) {
3479
+ store[dataSourceName].splice(index, 1);
3480
+ ds.insertRow(store, dataSourceName, created);
3481
+ } else {
3482
+ store[dataSourceName].splice(index, 1, created); // unsorted: keeps its place
3483
+ }
3480
3484
  ds.touchSource(dataSourceName);
3481
3485
  clearSourceCaches(dataSourceName);
3482
3486
  } else {
@@ -9667,6 +9671,8 @@ function sourceArrayView(dataSourceName, array, build) {
9667
9671
  return view;
9668
9672
  }
9669
9673
 
9674
+ const APPWRITE_EARLY_METHODS = new Set(['$query', '$create', '$update', '$delete', '$duplicate']);
9675
+
9670
9676
  // Loading proxy for Appwrite sources (CRUD + state/files/upload/pagination methods)
9671
9677
  function createAppwriteLoadingProxy(dataSourceName, reloadDataSource) {
9672
9678
  const createLoadingProxy = window.ManifestDataProxiesCore?.createLoadingProxy;
@@ -9929,6 +9935,18 @@ function registerXMagicMethod(loadDataSource) {
9929
9935
  if (key === '$saving') return window.ManifestDataProxiesMagic.createSavingMethod(prop);
9930
9936
  if (key === '$more') return () => window.ManifestDataMain.loadMore(prop);
9931
9937
  if (key === '$reload') return () => window.ManifestDataMain.reloadSource(prop);
9938
+ if (key === '$first' || key === '$next' || key === '$prev' || key === '$page') {
9939
+ return window.ManifestDataProxiesMagic.createPaginationMethod(key, prop);
9940
+ }
9941
+ // Appwrite methods work before the first load ($query on open)
9942
+ if (APPWRITE_EARLY_METHODS.has(key)) {
9943
+ const manifest = window.ManifestComponentsRegistry?.manifest || window.__manifestLoaded;
9944
+ const config = manifest?.data?.[prop];
9945
+ // Manifest not loaded yet: route anyway (the handler awaits it and refuses non-Appwrite sources)
9946
+ const handler = (!manifest || (config && window.ManifestDataConfig?.isAppwriteCollection?.(config)))
9947
+ && window.ManifestDataProxiesAppwrite?.createAppwriteMethodsHandler?.(prop, window.ManifestDataMain?.reloadDataSource);
9948
+ if (handler) return handler.bind(null, key);
9949
+ }
9932
9950
  return target[key];
9933
9951
  }
9934
9952
  }));
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "manifest.appwrite.auth.js": "sha384-gWLSeVPqCLMiUZB8MU7GqMg3x2yULFUsp8nTTZrPp/9Dlkix42rBn9yIimvwrHqZ",
3
- "manifest.appwrite.data.js": "sha384-0EGUWEr42z0dZpjupRpAESbafLNh8EM0qSLkOSFiHQ/Hsmxd9iTLjujJ0ikRkWBJ",
3
+ "manifest.appwrite.data.js": "sha384-GWMQqxFSIrenZpip0UPl52ryWKoBXNsQdXij2EiuyAN1dQWP/6nue114JNeDKbxM",
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-aNfAjA6DMSGz5FwvlI6/9Q3osRBfEEcCAXB1VYZDO/Ftuzo0Vuq3SkvJ4WLTuGEk",
14
+ "manifest.data.js": "sha384-LFG+IQqJye5+ccjj2xefyvsSvqnsLS7rgm2zAcCIEC41wopKzPNXmd2dB35zqrlt",
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-qb/Yr73VTXtWXo055Ff4oKPsdbz+nSwF66KAGxSIlu9hlNYCfOOOkm6ychI9qWaG",
32
+ "manifest.sw.js": "sha384-VawgDkXO4cfbM93u/jxsqW9f1tBIbZKy5W8KcirjltPLIzB8cDSUNOe5Ijaj/RdV",
33
33
  "manifest.tabs.js": "sha384-otU09H7jnawVKQdLAYpMCd3jx00tgyPVr42D2hLIBzN5dG4se505YesavdnMqEi1",
34
34
  "manifest.tailwind.js": "sha384-yuP3LEvWU+QVjxjkZ0YhErtC9RrGmhOmHjjFjhS9obqZbp5/KTIEnSR0CXDvHE0B",
35
35
  "manifest.toasts.js": "sha384-UpOz9fAdGeGUhL0NamBg5iPepEfIy73p9HYdcxfOQC5b7CVsl7Our0skdZzaLNcC",
@@ -137,28 +137,6 @@
137
137
  "type": "string"
138
138
  }
139
139
  },
140
- "contract": {
141
- "description": "Shared contract module, a path from the project root (e.g. /shared/contract.js), whose `tables` export declares Appwrite tables and columns. mnfst-test checks data sources against it; on dev hosts (or hosts listed in `checks`) app code reading a column of an Appwrite row that is undeclared and absent from every row of the source throws.",
142
- "oneOf": [
143
- { "type": "string" },
144
- {
145
- "type": "object",
146
- "properties": {
147
- "module": { "type": "string" },
148
- "checks": {
149
- "description": "Where column checks run: 'dev' (default, local hosts), true (everywhere), false (nowhere), or host patterns such as '*-staging.example.com' (dev hosts included).",
150
- "oneOf": [
151
- { "type": "boolean" },
152
- { "type": "string", "enum": ["dev"] },
153
- { "type": "array", "items": { "type": "string" } }
154
- ]
155
- }
156
- },
157
- "required": ["module"],
158
- "additionalProperties": false
159
- }
160
- ]
161
- },
162
140
  "data": {
163
141
  "type": "object",
164
142
  "description": "Named data sources made available via $x.<sourceName>. Each value is either a string path/URL or a config object.",
@@ -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.280';
19
+ const BUILD_VERSION = '0.5.282';
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.280",
3
+ "version": "0.5.282",
4
4
  "private": false,
5
5
  "workspaces": [
6
6
  "templates/starter",
@@ -54,7 +54,6 @@
54
54
  "test:e2e:submissions": "node tests/e2e/submissions.e2e.mjs",
55
55
  "test:e2e:data-paging": "node tests/e2e/data-paging.e2e.mjs",
56
56
  "test:e2e:modules": "node tests/e2e/modules.e2e.mjs",
57
- "test:e2e:contract": "node tests/e2e/contract.e2e.mjs && node tests/e2e/contract-checks.e2e.mjs",
58
57
  "lint": "echo 'No linting configured'",
59
58
  "release:docs": "node scripts/release-bump.mjs packages/docs && cd packages/docs && npm publish --auth-type=web",
60
59
  "release:check": "node scripts/release-check.mjs"