@aventoapp/framework 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/README.md +260 -0
  2. package/dist/index.js.map +1 -1
  3. package/dist/native/index.js.map +1 -1
  4. package/dist/offline/index.js.map +1 -1
  5. package/dist/server/index.js.map +1 -1
  6. package/dist/server/workflow/index.js.map +1 -1
  7. package/dist/shared/index.js.map +1 -1
  8. package/dist/web/index.js.map +1 -1
  9. package/package.json +84 -79
  10. package/schemas/Workflow.json +14 -14
  11. package/schemas/WorkflowHistory.json +22 -22
  12. package/schemas/WorkflowInstance.json +16 -16
  13. package/schemas/WorkflowState.json +18 -18
  14. package/schemas/WorkflowTransition.json +27 -27
  15. package/src/index.js +8 -8
  16. package/src/native/components/NativeAuthProvider.jsx +249 -249
  17. package/src/native/components/NativeDetail.jsx +270 -270
  18. package/src/native/components/NativeForm.jsx +543 -543
  19. package/src/native/components/NativeGrid.jsx +90 -90
  20. package/src/native/components/NativeJsonGrid.jsx +213 -213
  21. package/src/native/components/NativeJsonView.jsx +454 -454
  22. package/src/native/components/NativeJsonViewContext.js +17 -17
  23. package/src/native/components/NativeShell.jsx +68 -68
  24. package/src/native/components/NativeViewComponent.jsx +351 -351
  25. package/src/native/extensions/NativeExtensionRegistry.js +81 -81
  26. package/src/native/hooks/useNativeStore.js +72 -72
  27. package/src/native/index.js +15 -15
  28. package/src/native/layouts/NativeStackLayout.jsx +30 -30
  29. package/src/native/layouts/NativeTabLayout.jsx +96 -96
  30. package/src/native/storage.js +13 -13
  31. package/src/native/stores/NativeBaseStore.js +348 -348
  32. package/src/native/stores/NativeStoreContext.jsx +53 -53
  33. package/src/offline/index.js +1 -1
  34. package/src/server/ai/capabilities-routes.js +106 -106
  35. package/src/server/ai/index.js +1 -1
  36. package/src/server/cache/MemoryCache.js +153 -153
  37. package/src/server/cache/index.js +2 -2
  38. package/src/server/cache/middleware.js +12 -12
  39. package/src/server/db/index.js +14 -14
  40. package/src/server/db/mongo.js +137 -137
  41. package/src/server/db/postgres.js +144 -144
  42. package/src/server/index.js +42 -42
  43. package/src/server/middleware/auth.js +682 -682
  44. package/src/server/middleware/can-flags.js +132 -132
  45. package/src/server/middleware/entityRoles.js +105 -105
  46. package/src/server/middleware/index.js +58 -58
  47. package/src/server/middleware/permissions.js +240 -240
  48. package/src/server/middleware/tenant.js +203 -203
  49. package/src/server/realtime/EventBus.js +45 -45
  50. package/src/server/realtime/WebSocketServer.js +105 -105
  51. package/src/server/realtime/index.js +3 -3
  52. package/src/server/realtime/middleware.js +18 -18
  53. package/src/server/services/email-templates.js +157 -157
  54. package/src/server/services/email.js +78 -78
  55. package/src/server/services/index.js +15 -15
  56. package/src/server/services/storage.js +119 -119
  57. package/src/server/utils/index.js +16 -16
  58. package/src/server/utils/paginate.js +65 -65
  59. package/src/server/utils/query-builder.js +293 -293
  60. package/src/server/utils/route-loader.js +61 -61
  61. package/src/server/workflow/WorkflowEngine.js +494 -494
  62. package/src/server/workflow/index.js +2 -2
  63. package/src/server/workflow/workflow-routes.js +174 -174
  64. package/src/shared/index.js +10 -10
  65. package/src/shared/utils/field-accessor.js +108 -108
  66. package/src/shared/utils/index.js +7 -7
  67. package/src/shared/utils/validation-utils.js +83 -83
  68. package/src/web/components/AppRouter/AppRouter.jsx +130 -130
  69. package/src/web/components/AppRouter/index.js +1 -1
  70. package/src/web/components/AppShell/AppShell.jsx +101 -101
  71. package/src/web/components/AppShell/DefaultUserMenu.jsx +54 -54
  72. package/src/web/components/AppShell/ShellConfig.js +53 -53
  73. package/src/web/components/AppShell/index.js +3 -3
  74. package/src/web/components/AuthProvider.jsx +426 -426
  75. package/src/web/components/CardList/CardList.jsx +272 -272
  76. package/src/web/components/CardList/index.js +2 -2
  77. package/src/web/components/DetailView/DetailView.jsx +281 -281
  78. package/src/web/components/DetailView/index.js +2 -2
  79. package/src/web/components/Form/Form.jsx +300 -300
  80. package/src/web/components/Form/FormField.jsx +226 -226
  81. package/src/web/components/Form/index.js +3 -3
  82. package/src/web/components/Grid/Grid.jsx +304 -304
  83. package/src/web/components/Grid/index.js +2 -2
  84. package/src/web/components/IconRegistry/IconRegistry.jsx +127 -127
  85. package/src/web/components/IconRegistry/index.js +1 -1
  86. package/src/web/components/JsonView/JsonView.jsx +647 -647
  87. package/src/web/components/JsonView/ViewComponent.jsx +1045 -1045
  88. package/src/web/components/JsonView/ViewToolbar.jsx +141 -141
  89. package/src/web/components/JsonView/index.js +14 -14
  90. package/src/web/components/JsonView/layouts/SingleLayout.jsx +41 -41
  91. package/src/web/components/JsonView/layouts/SplitLayout.jsx +122 -122
  92. package/src/web/components/JsonView/layouts/TabLayout.jsx +112 -112
  93. package/src/web/components/JsonView/layouts/index.js +8 -8
  94. package/src/web/components/Layout.jsx +265 -265
  95. package/src/web/components/MobileLayout/MobileLayout.jsx +385 -385
  96. package/src/web/components/MobileLayout/index.js +1 -1
  97. package/src/web/components/Navigation/Navigation.jsx +248 -248
  98. package/src/web/components/Navigation/index.js +1 -1
  99. package/src/web/components/NotificationProvider.jsx +55 -55
  100. package/src/web/components/Pagination/InfiniteScroll.jsx +82 -82
  101. package/src/web/components/Pagination/Pagination.jsx +73 -73
  102. package/src/web/components/Pagination/index.js +8 -8
  103. package/src/web/components/SimpleList/SimpleList.jsx +177 -177
  104. package/src/web/components/SimpleList/index.js +2 -2
  105. package/src/web/components/TenantProvider.jsx +121 -121
  106. package/src/web/components/WorkflowActions/WorkflowActions.jsx +71 -71
  107. package/src/web/components/WorkflowActions/index.js +1 -1
  108. package/src/web/components/WorkflowField/WorkflowField.jsx +176 -176
  109. package/src/web/components/WorkflowField/index.js +2 -2
  110. package/src/web/components/WorkflowField/workflowColors.js +32 -32
  111. package/src/web/components/auth/DevTenantSelector.jsx +90 -90
  112. package/src/web/components/auth/ForgotPasswordForm.jsx +94 -94
  113. package/src/web/components/auth/RegisterForm.jsx +168 -168
  114. package/src/web/components/auth/ResetPasswordForm.jsx +121 -121
  115. package/src/web/components/auth/VerifyEmailView.jsx +85 -85
  116. package/src/web/components/auth/index.js +5 -5
  117. package/src/web/components/index.js +39 -39
  118. package/src/web/components/layouts/CardListLayout.jsx +68 -68
  119. package/src/web/components/layouts/FullscreenLayout.jsx +30 -30
  120. package/src/web/components/layouts/MobileStackLayout.jsx +28 -28
  121. package/src/web/components/layouts/WizardLayout.jsx +86 -86
  122. package/src/web/components/layouts/index.js +4 -4
  123. package/src/web/components/mobile/Badge.jsx +105 -105
  124. package/src/web/components/mobile/BadgeThemeEditor.jsx +104 -104
  125. package/src/web/components/mobile/EmptyState.jsx +30 -30
  126. package/src/web/components/mobile/QuickActionButton.jsx +77 -77
  127. package/src/web/components/mobile/ServerAutocomplete.jsx +123 -123
  128. package/src/web/components/mobile/StarRating.jsx +42 -42
  129. package/src/web/components/mobile/StatCard.jsx +65 -65
  130. package/src/web/components/mobile/index.js +7 -7
  131. package/src/web/extensions/ExtensionRegistry.js +79 -79
  132. package/src/web/extensions/index.js +7 -7
  133. package/src/web/hooks/index.js +15 -15
  134. package/src/web/hooks/useApi.js +76 -76
  135. package/src/web/hooks/useAuth.js +37 -37
  136. package/src/web/hooks/useDebouncedSave.js +158 -158
  137. package/src/web/hooks/useIsMobile.js +14 -14
  138. package/src/web/hooks/useOfflineQueue.js +99 -99
  139. package/src/web/hooks/useSelectionModel.js +143 -143
  140. package/src/web/hooks/useServerAutocomplete.js +146 -146
  141. package/src/web/hooks/useStore.js +107 -107
  142. package/src/web/hooks/useSubscription.js +130 -130
  143. package/src/web/hooks/useTenant.js +39 -39
  144. package/src/web/hooks/useTenantResolver.js +65 -65
  145. package/src/web/hooks/useUndoRedo.js +77 -77
  146. package/src/web/hooks/useViews.js +113 -113
  147. package/src/web/hooks/useWorkflow.js +190 -190
  148. package/src/web/index.js +117 -117
  149. package/src/web/stores/BaseStore.js +439 -439
  150. package/src/web/stores/StoreContext.jsx +93 -93
  151. package/src/web/stores/index.js +3 -3
  152. package/src/web/theme/index.js +3 -3
  153. package/src/web/theme/mui-theme.js +228 -228
  154. package/src/web/utils/formatTimeAgo.js +22 -22
  155. package/src/web/utils/index.js +1 -1
  156. package/src/web/views/ViewRegistry.js +235 -235
  157. package/src/web/views/index.js +2 -2
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/offline/diff.js", "../../src/offline/clock.js", "../../src/offline/coalesce.js", "../../src/offline/idb.js", "../../src/offline/store.js", "../../src/offline/outbox.js", "../../src/offline/syncer.js", "../../src/offline/kit.js", "../../src/offline/index.js"],
4
- "sourcesContent": ["// Shallow field diff: only keys present in `next` whose value differs from `prev`.\n// Never includes keys absent from `next` \u2014 so untouched fields are never sent.\nexport function diffFields(prev, next) {\n const base = prev && typeof prev === 'object' ? prev : {};\n const out = {};\n for (const key of Object.keys(next || {})) {\n if (!sameValue(base[key], next[key])) out[key] = next[key];\n }\n return out;\n}\n\nfunction sameValue(a, b) {\n if (a === b) return true;\n // NaN === NaN\n if (typeof a === 'number' && typeof b === 'number' && Number.isNaN(a) && Number.isNaN(b)) return true;\n return false;\n}\n", "// A monotonic-ish wall clock that can be calibrated against server time so a\n// wrong device clock doesn't poison cross-client timestamp ordering.\nexport function createClock({ nowFn = () => Date.now() } = {}) {\n let offset = 0;\n return {\n now() { return nowFn() + offset; },\n setOffsetFromServer(serverEpochMs, localAtMs = nowFn()) {\n offset = serverEpochMs - localAtMs;\n },\n getOffsetMs() { return offset; },\n };\n}\n", "// Collapse repeated offline edits so the outbox holds one entry per\n// (resource, recordId), keeping the latest value per field by client timestamp.\nexport function coalescePatch(queue, entry) {\n const idx = queue.findIndex(\n (e) => e.resource === entry.resource && e.recordId === entry.recordId,\n );\n if (idx === -1) {\n return [...queue, cloneEntry(entry)];\n }\n const existing = queue[idx];\n const merged = cloneEntry(existing);\n for (const field of Object.keys(entry.fields)) {\n // Always store a numeric ts \u2014 a field with no incoming timestamp defaults to\n // 0 so `undefined` never lands in fieldTimes (it would break the LWW compare).\n const incomingTs = tsOf(entry.fieldTimes, field);\n const currentTs = merged.fieldTimes[field];\n if (currentTs === undefined || incomingTs >= currentTs) {\n merged.fields[field] = entry.fields[field];\n merged.fieldTimes[field] = incomingTs;\n }\n }\n const out = queue.slice();\n out[idx] = merged;\n return out;\n}\n\nfunction cloneEntry(e) {\n // Normalize: every field carries a numeric ts (default 0), never undefined.\n const fieldTimes = {};\n for (const field of Object.keys(e.fields)) fieldTimes[field] = tsOf(e.fieldTimes, field);\n for (const field of Object.keys(e.fieldTimes || {})) {\n if (fieldTimes[field] === undefined) fieldTimes[field] = tsOf(e.fieldTimes, field);\n }\n return {\n resource: e.resource,\n recordId: e.recordId,\n fields: { ...e.fields },\n fieldTimes,\n };\n}\n\nfunction tsOf(fieldTimes, field) {\n const t = fieldTimes ? fieldTimes[field] : undefined;\n return t === undefined || t === null ? 0 : t;\n}\n", "// Minimal promisified IndexedDB wrapper over three fixed stores.\n// `indexedDB` is injected so this runs under fake-indexeddb in tests and\n// window.indexedDB in the browser. No external dependency.\n\nconst STORES = ['cache', 'outbox', 'meta'];\nconst DB_VERSION = 1;\n\nexport function createIdb({ name = 'avento-offline', indexedDB } = {}) {\n if (!indexedDB) throw new Error('createIdb requires an indexedDB implementation');\n let dbPromise = null;\n\n function open() {\n if (dbPromise) return dbPromise;\n dbPromise = new Promise((resolve, reject) => {\n const req = indexedDB.open(name, DB_VERSION);\n req.onupgradeneeded = () => {\n const db = req.result;\n for (const s of STORES) {\n if (!db.objectStoreNames.contains(s)) db.createObjectStore(s);\n }\n };\n req.onsuccess = () => resolve(req.result);\n req.onerror = () => reject(req.error);\n }).catch((err) => {\n // Don't cache a transient open failure forever \u2014 clear so the next call retries.\n dbPromise = null;\n throw err;\n });\n return dbPromise;\n }\n\n function tx(store, mode, fn) {\n return open().then((db) => new Promise((resolve, reject) => {\n const t = db.transaction(store, mode);\n const os = t.objectStore(store);\n let result;\n const r = fn(os);\n if (r) r.onsuccess = () => { result = r.result; };\n t.oncomplete = () => resolve(result);\n t.onerror = () => reject(t.error);\n t.onabort = () => reject(t.error);\n }));\n }\n\n return {\n get: (store, key) => tx(store, 'readonly', (os) => os.get(key)),\n set: (store, key, value) => tx(store, 'readwrite', (os) => os.put(value, key)),\n del: (store, key) => tx(store, 'readwrite', (os) => os.delete(key)),\n clear: (store) => tx(store, 'readwrite', (os) => os.clear()),\n all: (store) => tx(store, 'readonly', (os) => os.getAll()),\n };\n}\n", "// Read-through cache: serve fresh when online, fall back to the last snapshot\n// when offline. Backed by the idb 'cache' store.\nexport function createStore({ idb, clock }) {\n async function getEntry(key) {\n return (await idb.get('cache', key)) || null;\n }\n return {\n async readThrough(key, fetcher) {\n const res = await fetcher();\n if (res && res.ok) {\n await idb.set('cache', key, { data: res.data, fetchedAt: clock.now() });\n return { data: res.data, fromCache: false };\n }\n const entry = await getEntry(key);\n if (entry) return { data: entry.data, fromCache: true, fetchedAt: entry.fetchedAt };\n return { data: null, fromCache: true };\n },\n async getCached(key) {\n const entry = await getEntry(key);\n return entry ? entry.data : null;\n },\n async putCached(key, data) {\n await idb.set('cache', key, { data, fetchedAt: clock.now() });\n },\n };\n}\n", "import { coalescePatch } from './coalesce.js';\n\nconst KEY = 'queue';\n\nexport function createOutbox({ idb }) {\n async function read() {\n return (await idb.get('outbox', KEY)) || { patches: [], blobs: [] };\n }\n async function write(state) {\n await idb.set('outbox', KEY, state);\n }\n\n // Single-tab mutex: every mutation is a non-atomic read-modify-write across two\n // IDB transactions, so concurrent un-awaited mutations would race and clobber\n // each other (lost edit). Serialize them through a promise chain. `list()` is a\n // single `idb.get` (one transaction = consistent snapshot) so it stays lock-free.\n let chain = Promise.resolve();\n function withLock(fn) {\n const run = chain.then(() => fn());\n chain = run.then(() => {}, () => {});\n return run;\n }\n\n return {\n enqueuePatch(entry) {\n return withLock(async () => {\n const state = await read();\n // coalescePatch keys on resource+recordId; carry an id on the surviving entry.\n const before = state.patches.find((p) => p.resource === entry.resource && p.recordId === entry.recordId);\n const patches = coalescePatch(state.patches, entry);\n const survivor = patches.find((p) => p.resource === entry.resource && p.recordId === entry.recordId);\n if (survivor && !survivor.id) survivor.id = before ? before.id : entry.id;\n state.patches = patches;\n await write(state);\n });\n },\n enqueueBlob(rec) {\n return withLock(async () => {\n const state = await read();\n state.blobs.push({ kind: 'blob', ...rec });\n await write(state);\n });\n },\n async list() {\n return read();\n },\n remove(id) {\n return withLock(async () => {\n const state = await read();\n state.patches = state.patches.filter((p) => p.id !== id);\n state.blobs = state.blobs.filter((b) => b.id !== id);\n await write(state);\n });\n },\n // Field-scoped acknowledgement of a sent patch snapshot. Removes only the\n // fields that were actually sent (ts still matches the snapshot); a field\n // that coalesced in during the send has a newer ts and is retained so it\n // still gets flushed. Drops the entry entirely when no fields remain.\n ackPatch(sentEntry) {\n return withLock(async () => {\n const state = await read();\n const idx = state.patches.findIndex(\n (p) => p.resource === sentEntry.resource && p.recordId === sentEntry.recordId,\n );\n if (idx === -1) return;\n const cur = state.patches[idx];\n const sentTimes = sentEntry.fieldTimes || {};\n for (const field of Object.keys(sentTimes)) {\n if (cur.fieldTimes[field] === sentTimes[field]) {\n delete cur.fields[field];\n delete cur.fieldTimes[field];\n }\n }\n if (Object.keys(cur.fields).length === 0) {\n state.patches.splice(idx, 1);\n } else {\n state.patches[idx] = cur;\n }\n await write(state);\n });\n },\n };\n}\n", "// Drains the outbox in order: all patches first, then blobs. A failed send in a\n// category leaves that item queued and stops that category (FIFO, no reorder).\nexport function createSyncer({ outbox, transport, isOnline }) {\n let flushing = false;\n // Work enqueued while a flush is in flight would otherwise be stranded until an\n // unrelated future trigger; this latch makes the active flush re-run once more.\n let pendingFlush = false;\n\n async function flush() {\n if (flushing) { pendingFlush = true; return { sentPatches: 0, sentBlobs: 0, remaining: await remaining() }; }\n if (!isOnline()) return { sentPatches: 0, sentBlobs: 0, remaining: await remaining() };\n flushing = true;\n let sentPatches = 0; let sentBlobs = 0;\n try {\n let { patches, blobs } = await outbox.list();\n for (const p of patches) {\n const r = await transport.sendPatch(p);\n if (!r || !r.ok) break;\n // Field-scoped ack: remove only the fields we actually sent. A field that\n // coalesced into this record during the send has a newer ts and is kept.\n await outbox.ackPatch(p);\n sentPatches++;\n }\n // A failed patch above breaks only the patch loop \u2014 blobs are append-only and\n // independent of preceding patches, so the blob drain always runs.\n for (const b of blobs) {\n const r = await transport.sendBlob(b);\n if (!r || !r.ok) break;\n await outbox.remove(b.id);\n sentBlobs++;\n }\n } finally {\n flushing = false;\n }\n // Drain anything enqueued mid-flush. Loop until a flush completes with no\n // pending work (each recursion re-checks the latch in its own finally).\n if (pendingFlush) {\n pendingFlush = false;\n const again = await flush();\n return {\n sentPatches: sentPatches + again.sentPatches,\n sentBlobs: sentBlobs + again.sentBlobs,\n remaining: again.remaining,\n };\n }\n return { sentPatches, sentBlobs, remaining: await remaining() };\n }\n\n async function remaining() {\n const { patches, blobs } = await outbox.list();\n return patches.length + blobs.length;\n }\n\n return { flush, running: () => flushing };\n}\n", "import { diffFields } from './diff.js';\nimport { createStore } from './store.js';\nimport { createOutbox } from './outbox.js';\nimport { createSyncer } from './syncer.js';\n\n/**\n * Create an offline-first sync kit.\n *\n * @param {object} opts\n * @param {object} opts.idb - IndexedDB-compatible handle used for the local\n * cache store and the outbox (e.g. `indexedDB` / `fake-indexeddb`).\n * @param {{ now: () => number }} opts.clock - Clock used to timestamp field\n * edits and `lastSyncedAt`. Injected for testability.\n * @param {boolean | (() => boolean)} opts.isOnline - Initial online state, or\n * a function returning it. **`isOnline` is consulted only once at\n * construction to seed the initial online state. After construction,\n * connectivity changes MUST be pushed via `setOnline(true|false)` (e.g.\n * from window 'online'/'offline' listeners); the kit does not re-poll\n * `isOnline`.**\n * @param {(req: object) => Promise<{ ok: boolean, body?: any }>} opts.request\n * Transport function used for reads, patch sends, and blob sends.\n * @returns {object} The offline kit instance (defineSyncedResource, read/edit,\n * queueBlob, flushNow, setOnline, getStatus, subscribe).\n */\nexport function createOfflineKit({ idb, clock, isOnline, request }) {\n const kitNonce = Math.random().toString(36).slice(2, 8);\n let seq = 0;\n const nextId = () => `${kitNonce}-${++seq}`;\n\n const resources = new Map();\n const store = createStore({ idb, clock });\n const outbox = createOutbox({ idb });\n // `isOnline` seeds the initial state; after creation, `online` is the sole\n // source of truth so `setOnline()` (e.g. wired to window online/offline\n // events) can always override it \u2014 re-invoking `isOnline()` on every read\n // would make setOnline() a no-op whenever the consumer passed a function.\n let online = typeof isOnline === 'function' ? isOnline() : !!isOnline;\n const onlineNow = () => online;\n\n const transport = {\n async sendPatch(entry) {\n const def = resources.get(entry.resource);\n const { url, method } = def.patch(entry.recordId);\n const body = { ...entry.fields, _fieldTimes: entry.fieldTimes };\n const res = await request({ url, method, body });\n return { ok: !!res && res.ok };\n },\n async sendBlob(rec) {\n const res = await request({ url: rec.url, method: rec.method, body: rec.blob, headers: rec.headers, isBlob: true, idemKey: rec.idemKey, meta: rec.meta });\n return { ok: !!res && res.ok };\n },\n };\n const syncer = createSyncer({ outbox, transport, isOnline: onlineNow });\n\n let lastSyncedAt = null;\n const subscribers = new Set();\n function emit() {\n const s = getStatusSync();\n for (const fn of subscribers) fn(s);\n }\n let pendingCache = 0;\n async function refreshPending() {\n const { patches, blobs } = await outbox.list();\n pendingCache = patches.length + blobs.length;\n emit();\n }\n function getStatusSync() {\n return { online: onlineNow(), pendingCount: pendingCache, lastSyncedAt, flushing: syncer.running() };\n }\n\n const kit = {\n defineSyncedResource(def) { resources.set(def.name, def); },\n\n async readSynced(name, id) {\n const def = resources.get(name);\n const key = `${name}/${id}`;\n const res = await store.readThrough(key, async () => {\n if (!onlineNow()) return { ok: false };\n const r = await request({ url: def.load(id), method: 'GET' });\n return r && r.ok ? { ok: true, data: r.body } : { ok: false };\n });\n return res;\n },\n\n async primeCache(name, id, data) {\n await store.putCached(`${name}/${id}`, data);\n },\n\n async editSynced(name, id, partialFields) {\n const key = `${name}/${id}`;\n const cached = (await store.getCached(key)) || {};\n const changed = diffFields(cached, partialFields);\n if (Object.keys(changed).length === 0) return;\n const ts = clock.now();\n const fieldTimes = {};\n for (const k of Object.keys(changed)) fieldTimes[k] = ts;\n await store.putCached(key, { ...cached, ...changed }); // optimistic\n await outbox.enqueuePatch({ id: nextId(), resource: name, recordId: String(id), fields: changed, fieldTimes });\n await refreshPending();\n if (onlineNow()) await kit.flushNow();\n },\n\n async queueBlob(name, { url, idemKey, blob, meta = {}, method = 'POST', headers }) {\n await outbox.enqueueBlob({ id: nextId(), resource: name, url, method, idemKey, blob, meta, headers });\n await refreshPending();\n if (onlineNow()) await kit.flushNow();\n },\n\n async flushNow() {\n const res = await syncer.flush();\n if (res.sentPatches > 0 || res.sentBlobs > 0) lastSyncedAt = clock.now();\n await refreshPending();\n return res;\n },\n\n setOnline(v) { online = v; emit(); },\n getStatus: getStatusSync,\n subscribe(fn) { subscribers.add(fn); fn(getStatusSync()); return () => subscribers.delete(fn); },\n };\n return kit;\n}\n", "// @avento/framework/offline\n// Framework-agnostic offline read-cache + write-outbox + sync engine.\n// MUST stay React-free and DOM-optional (browser globals only behind injection).\n\nexport const OFFLINE_KIT_VERSION = '0.1.0';\nexport { diffFields } from './diff.js';\nexport { createClock } from './clock.js';\nexport { coalescePatch } from './coalesce.js';\nexport { createIdb } from './idb.js';\nexport { createStore } from './store.js';\nexport { createOutbox } from './outbox.js';\nexport { createSyncer } from './syncer.js';\nexport { createOfflineKit } from './kit.js';\n"],
4
+ "sourcesContent": ["// Shallow field diff: only keys present in `next` whose value differs from `prev`.\n// Never includes keys absent from `next` \u2014 so untouched fields are never sent.\nexport function diffFields(prev, next) {\n const base = prev && typeof prev === 'object' ? prev : {};\n const out = {};\n for (const key of Object.keys(next || {})) {\n if (!sameValue(base[key], next[key])) out[key] = next[key];\n }\n return out;\n}\n\nfunction sameValue(a, b) {\n if (a === b) return true;\n // NaN === NaN\n if (typeof a === 'number' && typeof b === 'number' && Number.isNaN(a) && Number.isNaN(b)) return true;\n return false;\n}\n", "// A monotonic-ish wall clock that can be calibrated against server time so a\n// wrong device clock doesn't poison cross-client timestamp ordering.\nexport function createClock({ nowFn = () => Date.now() } = {}) {\n let offset = 0;\n return {\n now() { return nowFn() + offset; },\n setOffsetFromServer(serverEpochMs, localAtMs = nowFn()) {\n offset = serverEpochMs - localAtMs;\n },\n getOffsetMs() { return offset; },\n };\n}\n", "// Collapse repeated offline edits so the outbox holds one entry per\n// (resource, recordId), keeping the latest value per field by client timestamp.\nexport function coalescePatch(queue, entry) {\n const idx = queue.findIndex(\n (e) => e.resource === entry.resource && e.recordId === entry.recordId,\n );\n if (idx === -1) {\n return [...queue, cloneEntry(entry)];\n }\n const existing = queue[idx];\n const merged = cloneEntry(existing);\n for (const field of Object.keys(entry.fields)) {\n // Always store a numeric ts \u2014 a field with no incoming timestamp defaults to\n // 0 so `undefined` never lands in fieldTimes (it would break the LWW compare).\n const incomingTs = tsOf(entry.fieldTimes, field);\n const currentTs = merged.fieldTimes[field];\n if (currentTs === undefined || incomingTs >= currentTs) {\n merged.fields[field] = entry.fields[field];\n merged.fieldTimes[field] = incomingTs;\n }\n }\n const out = queue.slice();\n out[idx] = merged;\n return out;\n}\n\nfunction cloneEntry(e) {\n // Normalize: every field carries a numeric ts (default 0), never undefined.\n const fieldTimes = {};\n for (const field of Object.keys(e.fields)) fieldTimes[field] = tsOf(e.fieldTimes, field);\n for (const field of Object.keys(e.fieldTimes || {})) {\n if (fieldTimes[field] === undefined) fieldTimes[field] = tsOf(e.fieldTimes, field);\n }\n return {\n resource: e.resource,\n recordId: e.recordId,\n fields: { ...e.fields },\n fieldTimes,\n };\n}\n\nfunction tsOf(fieldTimes, field) {\n const t = fieldTimes ? fieldTimes[field] : undefined;\n return t === undefined || t === null ? 0 : t;\n}\n", "// Minimal promisified IndexedDB wrapper over three fixed stores.\n// `indexedDB` is injected so this runs under fake-indexeddb in tests and\n// window.indexedDB in the browser. No external dependency.\n\nconst STORES = ['cache', 'outbox', 'meta'];\nconst DB_VERSION = 1;\n\nexport function createIdb({ name = 'avento-offline', indexedDB } = {}) {\n if (!indexedDB) throw new Error('createIdb requires an indexedDB implementation');\n let dbPromise = null;\n\n function open() {\n if (dbPromise) return dbPromise;\n dbPromise = new Promise((resolve, reject) => {\n const req = indexedDB.open(name, DB_VERSION);\n req.onupgradeneeded = () => {\n const db = req.result;\n for (const s of STORES) {\n if (!db.objectStoreNames.contains(s)) db.createObjectStore(s);\n }\n };\n req.onsuccess = () => resolve(req.result);\n req.onerror = () => reject(req.error);\n }).catch((err) => {\n // Don't cache a transient open failure forever \u2014 clear so the next call retries.\n dbPromise = null;\n throw err;\n });\n return dbPromise;\n }\n\n function tx(store, mode, fn) {\n return open().then((db) => new Promise((resolve, reject) => {\n const t = db.transaction(store, mode);\n const os = t.objectStore(store);\n let result;\n const r = fn(os);\n if (r) r.onsuccess = () => { result = r.result; };\n t.oncomplete = () => resolve(result);\n t.onerror = () => reject(t.error);\n t.onabort = () => reject(t.error);\n }));\n }\n\n return {\n get: (store, key) => tx(store, 'readonly', (os) => os.get(key)),\n set: (store, key, value) => tx(store, 'readwrite', (os) => os.put(value, key)),\n del: (store, key) => tx(store, 'readwrite', (os) => os.delete(key)),\n clear: (store) => tx(store, 'readwrite', (os) => os.clear()),\n all: (store) => tx(store, 'readonly', (os) => os.getAll()),\n };\n}\n", "// Read-through cache: serve fresh when online, fall back to the last snapshot\n// when offline. Backed by the idb 'cache' store.\nexport function createStore({ idb, clock }) {\n async function getEntry(key) {\n return (await idb.get('cache', key)) || null;\n }\n return {\n async readThrough(key, fetcher) {\n const res = await fetcher();\n if (res && res.ok) {\n await idb.set('cache', key, { data: res.data, fetchedAt: clock.now() });\n return { data: res.data, fromCache: false };\n }\n const entry = await getEntry(key);\n if (entry) return { data: entry.data, fromCache: true, fetchedAt: entry.fetchedAt };\n return { data: null, fromCache: true };\n },\n async getCached(key) {\n const entry = await getEntry(key);\n return entry ? entry.data : null;\n },\n async putCached(key, data) {\n await idb.set('cache', key, { data, fetchedAt: clock.now() });\n },\n };\n}\n", "import { coalescePatch } from './coalesce.js';\n\nconst KEY = 'queue';\n\nexport function createOutbox({ idb }) {\n async function read() {\n return (await idb.get('outbox', KEY)) || { patches: [], blobs: [] };\n }\n async function write(state) {\n await idb.set('outbox', KEY, state);\n }\n\n // Single-tab mutex: every mutation is a non-atomic read-modify-write across two\n // IDB transactions, so concurrent un-awaited mutations would race and clobber\n // each other (lost edit). Serialize them through a promise chain. `list()` is a\n // single `idb.get` (one transaction = consistent snapshot) so it stays lock-free.\n let chain = Promise.resolve();\n function withLock(fn) {\n const run = chain.then(() => fn());\n chain = run.then(() => {}, () => {});\n return run;\n }\n\n return {\n enqueuePatch(entry) {\n return withLock(async () => {\n const state = await read();\n // coalescePatch keys on resource+recordId; carry an id on the surviving entry.\n const before = state.patches.find((p) => p.resource === entry.resource && p.recordId === entry.recordId);\n const patches = coalescePatch(state.patches, entry);\n const survivor = patches.find((p) => p.resource === entry.resource && p.recordId === entry.recordId);\n if (survivor && !survivor.id) survivor.id = before ? before.id : entry.id;\n state.patches = patches;\n await write(state);\n });\n },\n enqueueBlob(rec) {\n return withLock(async () => {\n const state = await read();\n state.blobs.push({ kind: 'blob', ...rec });\n await write(state);\n });\n },\n async list() {\n return read();\n },\n remove(id) {\n return withLock(async () => {\n const state = await read();\n state.patches = state.patches.filter((p) => p.id !== id);\n state.blobs = state.blobs.filter((b) => b.id !== id);\n await write(state);\n });\n },\n // Field-scoped acknowledgement of a sent patch snapshot. Removes only the\n // fields that were actually sent (ts still matches the snapshot); a field\n // that coalesced in during the send has a newer ts and is retained so it\n // still gets flushed. Drops the entry entirely when no fields remain.\n ackPatch(sentEntry) {\n return withLock(async () => {\n const state = await read();\n const idx = state.patches.findIndex(\n (p) => p.resource === sentEntry.resource && p.recordId === sentEntry.recordId,\n );\n if (idx === -1) return;\n const cur = state.patches[idx];\n const sentTimes = sentEntry.fieldTimes || {};\n for (const field of Object.keys(sentTimes)) {\n if (cur.fieldTimes[field] === sentTimes[field]) {\n delete cur.fields[field];\n delete cur.fieldTimes[field];\n }\n }\n if (Object.keys(cur.fields).length === 0) {\n state.patches.splice(idx, 1);\n } else {\n state.patches[idx] = cur;\n }\n await write(state);\n });\n },\n };\n}\n", "// Drains the outbox in order: all patches first, then blobs. A failed send in a\n// category leaves that item queued and stops that category (FIFO, no reorder).\nexport function createSyncer({ outbox, transport, isOnline }) {\n let flushing = false;\n // Work enqueued while a flush is in flight would otherwise be stranded until an\n // unrelated future trigger; this latch makes the active flush re-run once more.\n let pendingFlush = false;\n\n async function flush() {\n if (flushing) { pendingFlush = true; return { sentPatches: 0, sentBlobs: 0, remaining: await remaining() }; }\n if (!isOnline()) return { sentPatches: 0, sentBlobs: 0, remaining: await remaining() };\n flushing = true;\n let sentPatches = 0; let sentBlobs = 0;\n try {\n let { patches, blobs } = await outbox.list();\n for (const p of patches) {\n const r = await transport.sendPatch(p);\n if (!r || !r.ok) break;\n // Field-scoped ack: remove only the fields we actually sent. A field that\n // coalesced into this record during the send has a newer ts and is kept.\n await outbox.ackPatch(p);\n sentPatches++;\n }\n // A failed patch above breaks only the patch loop \u2014 blobs are append-only and\n // independent of preceding patches, so the blob drain always runs.\n for (const b of blobs) {\n const r = await transport.sendBlob(b);\n if (!r || !r.ok) break;\n await outbox.remove(b.id);\n sentBlobs++;\n }\n } finally {\n flushing = false;\n }\n // Drain anything enqueued mid-flush. Loop until a flush completes with no\n // pending work (each recursion re-checks the latch in its own finally).\n if (pendingFlush) {\n pendingFlush = false;\n const again = await flush();\n return {\n sentPatches: sentPatches + again.sentPatches,\n sentBlobs: sentBlobs + again.sentBlobs,\n remaining: again.remaining,\n };\n }\n return { sentPatches, sentBlobs, remaining: await remaining() };\n }\n\n async function remaining() {\n const { patches, blobs } = await outbox.list();\n return patches.length + blobs.length;\n }\n\n return { flush, running: () => flushing };\n}\n", "import { diffFields } from './diff.js';\nimport { createStore } from './store.js';\nimport { createOutbox } from './outbox.js';\nimport { createSyncer } from './syncer.js';\n\n/**\n * Create an offline-first sync kit.\n *\n * @param {object} opts\n * @param {object} opts.idb - IndexedDB-compatible handle used for the local\n * cache store and the outbox (e.g. `indexedDB` / `fake-indexeddb`).\n * @param {{ now: () => number }} opts.clock - Clock used to timestamp field\n * edits and `lastSyncedAt`. Injected for testability.\n * @param {boolean | (() => boolean)} opts.isOnline - Initial online state, or\n * a function returning it. **`isOnline` is consulted only once at\n * construction to seed the initial online state. After construction,\n * connectivity changes MUST be pushed via `setOnline(true|false)` (e.g.\n * from window 'online'/'offline' listeners); the kit does not re-poll\n * `isOnline`.**\n * @param {(req: object) => Promise<{ ok: boolean, body?: any }>} opts.request\n * Transport function used for reads, patch sends, and blob sends.\n * @returns {object} The offline kit instance (defineSyncedResource, read/edit,\n * queueBlob, flushNow, setOnline, getStatus, subscribe).\n */\nexport function createOfflineKit({ idb, clock, isOnline, request }) {\n const kitNonce = Math.random().toString(36).slice(2, 8);\n let seq = 0;\n const nextId = () => `${kitNonce}-${++seq}`;\n\n const resources = new Map();\n const store = createStore({ idb, clock });\n const outbox = createOutbox({ idb });\n // `isOnline` seeds the initial state; after creation, `online` is the sole\n // source of truth so `setOnline()` (e.g. wired to window online/offline\n // events) can always override it \u2014 re-invoking `isOnline()` on every read\n // would make setOnline() a no-op whenever the consumer passed a function.\n let online = typeof isOnline === 'function' ? isOnline() : !!isOnline;\n const onlineNow = () => online;\n\n const transport = {\n async sendPatch(entry) {\n const def = resources.get(entry.resource);\n const { url, method } = def.patch(entry.recordId);\n const body = { ...entry.fields, _fieldTimes: entry.fieldTimes };\n const res = await request({ url, method, body });\n return { ok: !!res && res.ok };\n },\n async sendBlob(rec) {\n const res = await request({ url: rec.url, method: rec.method, body: rec.blob, headers: rec.headers, isBlob: true, idemKey: rec.idemKey, meta: rec.meta });\n return { ok: !!res && res.ok };\n },\n };\n const syncer = createSyncer({ outbox, transport, isOnline: onlineNow });\n\n let lastSyncedAt = null;\n const subscribers = new Set();\n function emit() {\n const s = getStatusSync();\n for (const fn of subscribers) fn(s);\n }\n let pendingCache = 0;\n async function refreshPending() {\n const { patches, blobs } = await outbox.list();\n pendingCache = patches.length + blobs.length;\n emit();\n }\n function getStatusSync() {\n return { online: onlineNow(), pendingCount: pendingCache, lastSyncedAt, flushing: syncer.running() };\n }\n\n const kit = {\n defineSyncedResource(def) { resources.set(def.name, def); },\n\n async readSynced(name, id) {\n const def = resources.get(name);\n const key = `${name}/${id}`;\n const res = await store.readThrough(key, async () => {\n if (!onlineNow()) return { ok: false };\n const r = await request({ url: def.load(id), method: 'GET' });\n return r && r.ok ? { ok: true, data: r.body } : { ok: false };\n });\n return res;\n },\n\n async primeCache(name, id, data) {\n await store.putCached(`${name}/${id}`, data);\n },\n\n async editSynced(name, id, partialFields) {\n const key = `${name}/${id}`;\n const cached = (await store.getCached(key)) || {};\n const changed = diffFields(cached, partialFields);\n if (Object.keys(changed).length === 0) return;\n const ts = clock.now();\n const fieldTimes = {};\n for (const k of Object.keys(changed)) fieldTimes[k] = ts;\n await store.putCached(key, { ...cached, ...changed }); // optimistic\n await outbox.enqueuePatch({ id: nextId(), resource: name, recordId: String(id), fields: changed, fieldTimes });\n await refreshPending();\n if (onlineNow()) await kit.flushNow();\n },\n\n async queueBlob(name, { url, idemKey, blob, meta = {}, method = 'POST', headers }) {\n await outbox.enqueueBlob({ id: nextId(), resource: name, url, method, idemKey, blob, meta, headers });\n await refreshPending();\n if (onlineNow()) await kit.flushNow();\n },\n\n async flushNow() {\n const res = await syncer.flush();\n if (res.sentPatches > 0 || res.sentBlobs > 0) lastSyncedAt = clock.now();\n await refreshPending();\n return res;\n },\n\n setOnline(v) { online = v; emit(); },\n getStatus: getStatusSync,\n subscribe(fn) { subscribers.add(fn); fn(getStatusSync()); return () => subscribers.delete(fn); },\n };\n return kit;\n}\n", "// @aventoapp/framework/offline\n// Framework-agnostic offline read-cache + write-outbox + sync engine.\n// MUST stay React-free and DOM-optional (browser globals only behind injection).\n\nexport const OFFLINE_KIT_VERSION = '0.1.0';\nexport { diffFields } from './diff.js';\nexport { createClock } from './clock.js';\nexport { coalescePatch } from './coalesce.js';\nexport { createIdb } from './idb.js';\nexport { createStore } from './store.js';\nexport { createOutbox } from './outbox.js';\nexport { createSyncer } from './syncer.js';\nexport { createOfflineKit } from './kit.js';\n"],
5
5
  "mappings": ";AAEO,SAAS,WAAW,MAAM,MAAM;AACrC,QAAM,OAAO,QAAQ,OAAO,SAAS,WAAW,OAAO,CAAC;AACxD,QAAM,MAAM,CAAC;AACb,aAAW,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,GAAG;AACzC,QAAI,CAAC,UAAU,KAAK,GAAG,GAAG,KAAK,GAAG,CAAC;AAAG,UAAI,GAAG,IAAI,KAAK,GAAG;AAAA,EAC3D;AACA,SAAO;AACT;AAEA,SAAS,UAAU,GAAG,GAAG;AACvB,MAAI,MAAM;AAAG,WAAO;AAEpB,MAAI,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,OAAO,MAAM,CAAC,KAAK,OAAO,MAAM,CAAC;AAAG,WAAO;AACjG,SAAO;AACT;;;ACdO,SAAS,YAAY,EAAE,QAAQ,MAAM,KAAK,IAAI,EAAE,IAAI,CAAC,GAAG;AAC7D,MAAI,SAAS;AACb,SAAO;AAAA,IACL,MAAM;AAAE,aAAO,MAAM,IAAI;AAAA,IAAQ;AAAA,IACjC,oBAAoB,eAAe,YAAY,MAAM,GAAG;AACtD,eAAS,gBAAgB;AAAA,IAC3B;AAAA,IACA,cAAc;AAAE,aAAO;AAAA,IAAQ;AAAA,EACjC;AACF;;;ACTO,SAAS,cAAc,OAAO,OAAO;AAC1C,QAAM,MAAM,MAAM;AAAA,IAChB,CAAC,MAAM,EAAE,aAAa,MAAM,YAAY,EAAE,aAAa,MAAM;AAAA,EAC/D;AACA,MAAI,QAAQ,IAAI;AACd,WAAO,CAAC,GAAG,OAAO,WAAW,KAAK,CAAC;AAAA,EACrC;AACA,QAAM,WAAW,MAAM,GAAG;AAC1B,QAAM,SAAS,WAAW,QAAQ;AAClC,aAAW,SAAS,OAAO,KAAK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