@undefineds.co/xpod 0.4.10 → 0.4.12

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 (402) hide show
  1. package/config/components-ignore.json +5 -1
  2. package/config/notifications.json +68 -0
  3. package/config/xpod.base.json +9 -11
  4. package/dist/ai/service/AiCredentialSecret.d.ts +30 -0
  5. package/dist/ai/service/AiCredentialSecret.js +120 -0
  6. package/dist/ai/service/CredentialReaderImpl.d.ts +18 -0
  7. package/dist/ai/service/CredentialReaderImpl.js +81 -5
  8. package/dist/ai/service/CredentialReaderImpl.jsonld +42 -2
  9. package/dist/ai/service/EmbeddingModelPolicy.d.ts +79 -0
  10. package/dist/ai/service/EmbeddingModelPolicy.js +134 -0
  11. package/dist/ai/service/EmbeddingProviderError.js +6 -0
  12. package/dist/ai/service/EmbeddingServiceImpl.d.ts +13 -1
  13. package/dist/ai/service/EmbeddingServiceImpl.js +18 -5
  14. package/dist/ai/service/EmbeddingServiceImpl.jsonld +35 -0
  15. package/dist/ai/service/index.d.ts +2 -0
  16. package/dist/ai/service/index.js +2 -0
  17. package/dist/api/ai-gateway/connect/index.d.ts +20 -2
  18. package/dist/api/ai-gateway/connect/index.js +162 -16
  19. package/dist/api/ai-gateway/credentials/AiCredentialSecretDecoder.d.ts +12 -0
  20. package/dist/api/ai-gateway/credentials/AiCredentialSecretDecoder.js +30 -0
  21. package/dist/api/ai-gateway/errors.d.ts +1 -1
  22. package/dist/api/ai-gateway/models/GatewayEmbeddingModelCatalog.d.ts +11 -0
  23. package/dist/api/ai-gateway/models/GatewayEmbeddingModelCatalog.js +31 -0
  24. package/dist/api/ai-gateway/models/PodModelSelectionRepository.js +7 -3
  25. package/dist/api/ai-gateway/models/ProviderCustomModelsService.d.ts +18 -0
  26. package/dist/api/ai-gateway/models/ProviderCustomModelsService.js +23 -0
  27. package/dist/api/ai-gateway/models/ProviderModelDiscoveryAdapters.d.ts +3 -1
  28. package/dist/api/ai-gateway/models/ProviderModelDiscoveryAdapters.js +2 -45
  29. package/dist/api/ai-gateway/models/ProviderModelSelectionService.d.ts +10 -0
  30. package/dist/api/ai-gateway/models/ProviderModelSelectionService.js +57 -20
  31. package/dist/api/ai-gateway/models/ProviderModelType.d.ts +28 -0
  32. package/dist/api/ai-gateway/models/ProviderModelType.js +34 -0
  33. package/dist/api/ai-gateway/models/ProviderModelsAdapter.d.ts +10 -0
  34. package/dist/api/ai-gateway/models/ProviderModelsAdapter.js +3 -4
  35. package/dist/api/ai-gateway/models/index.d.ts +1 -0
  36. package/dist/api/ai-gateway/models/index.js +3 -1
  37. package/dist/api/ai-gateway/providers/CustomRuntimeAdapter.d.ts +7 -0
  38. package/dist/api/ai-gateway/providers/CustomRuntimeAdapter.js +9 -2
  39. package/dist/api/ai-gateway/providers/ModelsDevCatalog.d.ts +7 -1
  40. package/dist/api/ai-gateway/providers/ModelsDevCatalog.js +4 -10
  41. package/dist/api/ai-gateway/providers/ProviderRegistry.d.ts +107 -0
  42. package/dist/api/ai-gateway/providers/ProviderRegistry.js +244 -21
  43. package/dist/api/ai-gateway/providers/ProviderRuntimeRegistry.d.ts +5 -0
  44. package/dist/api/ai-gateway/providers/ProviderRuntimeRegistry.js +5 -1
  45. package/dist/api/ai-gateway/quota/SubscriptionQuotaAdapters.d.ts +12 -4
  46. package/dist/api/ai-gateway/quota/SubscriptionQuotaAdapters.js +11 -11
  47. package/dist/api/ai-gateway/routing/ModelRouter.d.ts +14 -0
  48. package/dist/api/ai-gateway/routing/ModelRouter.js +43 -4
  49. package/dist/api/ai-gateway/service-access/AiConnectionsServiceAccess.d.ts +9 -1
  50. package/dist/api/ai-gateway/service-access/AiConnectionsServiceAccess.js +3 -27
  51. package/dist/api/auth/ClientCredentialsAuthenticator.d.ts +0 -1
  52. package/dist/api/auth/ClientCredentialsAuthenticator.js +0 -3
  53. package/dist/api/auth/index.d.ts +1 -0
  54. package/dist/api/auth/index.js +1 -1
  55. package/dist/api/chatkit/pod-store.d.ts +31 -0
  56. package/dist/api/chatkit/pod-store.js +132 -8
  57. package/dist/api/container/common.js +24 -4
  58. package/dist/api/container/routes.js +17 -2
  59. package/dist/api/container/types.d.ts +3 -1
  60. package/dist/api/handlers/AdminHandler.d.ts +13 -0
  61. package/dist/api/handlers/AdminHandler.js +47 -18
  62. package/dist/api/handlers/AiConfigHandler.d.ts +6 -0
  63. package/dist/api/handlers/AiConfigHandler.js +28 -0
  64. package/dist/api/handlers/AiGatewayManagementHandler.js +36 -0
  65. package/dist/api/runs/RdfRunContextRetriever.d.ts +14 -0
  66. package/dist/api/runs/RdfRunContextRetriever.js +41 -5
  67. package/dist/api/runtime.js +2 -1
  68. package/dist/cli/commands/secret.d.ts +1 -0
  69. package/dist/cli/commands/secret.js +25 -7
  70. package/dist/components/components.jsonld +3 -1
  71. package/dist/components/context.jsonld +53 -1
  72. package/dist/http/SubgraphSparqlHttpHandler.d.ts +59 -2
  73. package/dist/http/SubgraphSparqlHttpHandler.js +145 -13
  74. package/dist/http/SubgraphSparqlHttpHandler.jsonld +37 -0
  75. package/dist/identity/drizzle/AccountRoleRepository.d.ts +30 -2
  76. package/dist/identity/drizzle/AccountRoleRepository.js +163 -15
  77. package/dist/identity/drizzle/EdgeNodeRepository.d.ts +0 -12
  78. package/dist/identity/drizzle/EdgeNodeRepository.js +5 -13
  79. package/dist/identity/drizzle/PodLookupRepository.d.ts +58 -4
  80. package/dist/identity/drizzle/PodLookupRepository.js +248 -105
  81. package/dist/identity/drizzle/db.d.ts +19 -0
  82. package/dist/identity/drizzle/db.js +39 -4
  83. package/dist/index.d.ts +2 -1
  84. package/dist/index.js +7 -3
  85. package/dist/logging/log-file.d.ts +17 -0
  86. package/dist/logging/log-file.js +69 -0
  87. package/dist/main.js +2 -1
  88. package/dist/notifications/NotificationChannelSweeper.d.ts +50 -0
  89. package/dist/notifications/NotificationChannelSweeper.js +131 -0
  90. package/dist/notifications/NotificationChannelSweeper.jsonld +136 -0
  91. package/dist/notifications/ReclaimingWebSocket2023Storer.d.ts +25 -0
  92. package/dist/notifications/ReclaimingWebSocket2023Storer.js +56 -0
  93. package/dist/notifications/ReclaimingWebSocket2023Storer.jsonld +77 -0
  94. package/dist/notifications/index.d.ts +2 -0
  95. package/dist/notifications/index.js +2 -0
  96. package/dist/runtime/Proxy.d.ts +37 -0
  97. package/dist/runtime/Proxy.js +88 -16
  98. package/dist/runtime/bootstrap.js +2 -1
  99. package/dist/runtime/upgrade/BunNativeUpgradeRelay.d.ts +116 -0
  100. package/dist/runtime/upgrade/BunNativeUpgradeRelay.js +423 -0
  101. package/dist/runtime/upgrade/UpgradeHandshake.d.ts +63 -0
  102. package/dist/runtime/upgrade/UpgradeHandshake.js +199 -0
  103. package/dist/runtime/upgrade/WebSocketFrames.d.ts +67 -0
  104. package/dist/runtime/upgrade/WebSocketFrames.js +224 -0
  105. package/node_modules/@undefineds.co/ai-connections/dist/AiApiKeyPool.js +8 -1
  106. package/node_modules/@undefineds.co/ai-connections/dist/AiAuthorizationActions.d.ts +11 -2
  107. package/node_modules/@undefineds.co/ai-connections/dist/AiAuthorizationActions.js +27 -10
  108. package/node_modules/@undefineds.co/ai-connections/dist/AiClientConfigurationSection.d.ts +7 -0
  109. package/node_modules/@undefineds.co/ai-connections/dist/AiClientConfigurationSection.js +13 -11
  110. package/node_modules/@undefineds.co/ai-connections/dist/AiConnectDialog.js +1 -1
  111. package/node_modules/@undefineds.co/ai-connections/dist/AiConnectionsList.js +10 -6
  112. package/node_modules/@undefineds.co/ai-connections/dist/AiConnectionsMain.d.ts +15 -0
  113. package/node_modules/@undefineds.co/ai-connections/dist/AiConnectionsMain.js +29 -3
  114. package/node_modules/@undefineds.co/ai-connections/dist/AiConnectionsMainHeader.js +18 -3
  115. package/node_modules/@undefineds.co/ai-connections/dist/AiConnectionsPanel.d.ts +16 -1
  116. package/node_modules/@undefineds.co/ai-connections/dist/AiConnectionsPanel.js +92 -20
  117. package/node_modules/@undefineds.co/ai-connections/dist/AiCopyButton.d.ts +35 -0
  118. package/node_modules/@undefineds.co/ai-connections/dist/AiCopyButton.js +45 -0
  119. package/node_modules/@undefineds.co/ai-connections/dist/AiCredentialPoolSection.js +71 -11
  120. package/node_modules/@undefineds.co/ai-connections/dist/AiCredentialRow.js +9 -7
  121. package/node_modules/@undefineds.co/ai-connections/dist/AiEndpointList.d.ts +23 -0
  122. package/node_modules/@undefineds.co/ai-connections/dist/AiEndpointList.js +24 -0
  123. package/node_modules/@undefineds.co/ai-connections/dist/AiGatewayKeysSection.d.ts +13 -4
  124. package/node_modules/@undefineds.co/ai-connections/dist/AiGatewayKeysSection.js +35 -38
  125. package/node_modules/@undefineds.co/ai-connections/dist/AiGatewayModelsSection.d.ts +21 -0
  126. package/node_modules/@undefineds.co/ai-connections/dist/AiGatewayModelsSection.js +51 -0
  127. package/node_modules/@undefineds.co/ai-connections/dist/AiInfoTooltip.d.ts +15 -0
  128. package/node_modules/@undefineds.co/ai-connections/dist/AiInfoTooltip.js +16 -0
  129. package/node_modules/@undefineds.co/ai-connections/dist/AiModelCatalog.d.ts +175 -0
  130. package/node_modules/@undefineds.co/ai-connections/dist/AiModelCatalog.js +133 -0
  131. package/node_modules/@undefineds.co/ai-connections/dist/AiOfferingDetails.js +2 -2
  132. package/node_modules/@undefineds.co/ai-connections/dist/AiProviderCard.js +13 -64
  133. package/node_modules/@undefineds.co/ai-connections/dist/AiProviderHeader.d.ts +21 -0
  134. package/node_modules/@undefineds.co/ai-connections/dist/AiProviderHeader.js +12 -0
  135. package/node_modules/@undefineds.co/ai-connections/dist/AiRowAction.d.ts +15 -0
  136. package/node_modules/@undefineds.co/ai-connections/dist/AiRowAction.js +12 -0
  137. package/node_modules/@undefineds.co/ai-connections/dist/AiSortableCredentialList.js +2 -1
  138. package/node_modules/@undefineds.co/ai-connections/dist/ai-connections-client.d.ts +7 -0
  139. package/node_modules/@undefineds.co/ai-connections/dist/ai-connections-client.js +6 -0
  140. package/node_modules/@undefineds.co/ai-connections/dist/authorization-methods.d.ts +36 -5
  141. package/node_modules/@undefineds.co/ai-connections/dist/authorization-methods.js +52 -9
  142. package/node_modules/@undefineds.co/ai-connections/dist/client/normalize.js +30 -3
  143. package/node_modules/@undefineds.co/ai-connections/dist/client/types.d.ts +21 -1
  144. package/node_modules/@undefineds.co/ai-connections/dist/client-config/base-adapter.d.ts +1 -3
  145. package/node_modules/@undefineds.co/ai-connections/dist/client-config/base-adapter.js +3 -7
  146. package/node_modules/@undefineds.co/ai-connections/dist/client-config/index.cjs +9 -7
  147. package/node_modules/@undefineds.co/ai-connections/dist/collection-runtime.d.ts +46 -0
  148. package/node_modules/@undefineds.co/ai-connections/dist/collection-runtime.js +231 -0
  149. package/node_modules/@undefineds.co/ai-connections/dist/collections.d.ts +119 -0
  150. package/node_modules/@undefineds.co/ai-connections/dist/collections.js +173 -0
  151. package/node_modules/@undefineds.co/ai-connections/dist/controller.d.ts +71 -5
  152. package/node_modules/@undefineds.co/ai-connections/dist/controller.js +285 -16
  153. package/node_modules/@undefineds.co/ai-connections/dist/credential-labels.d.ts +5 -0
  154. package/node_modules/@undefineds.co/ai-connections/dist/credential-labels.js +8 -3
  155. package/node_modules/@undefineds.co/ai-connections/dist/credential-storage.d.ts +59 -0
  156. package/node_modules/@undefineds.co/ai-connections/dist/credential-storage.js +131 -0
  157. package/node_modules/@undefineds.co/ai-connections/dist/endpoint-urls.d.ts +15 -0
  158. package/node_modules/@undefineds.co/ai-connections/dist/endpoint-urls.js +20 -0
  159. package/node_modules/@undefineds.co/ai-connections/dist/gateway-endpoints.d.ts +14 -0
  160. package/node_modules/@undefineds.co/ai-connections/dist/gateway-endpoints.js +20 -0
  161. package/node_modules/@undefineds.co/ai-connections/dist/index.d.ts +8 -0
  162. package/node_modules/@undefineds.co/ai-connections/dist/index.js +8 -0
  163. package/node_modules/@undefineds.co/ai-connections/dist/manifest.js +1 -1
  164. package/node_modules/@undefineds.co/ai-connections/dist/offering-endpoints.d.ts +14 -0
  165. package/node_modules/@undefineds.co/ai-connections/dist/offering-endpoints.js +17 -0
  166. package/node_modules/@undefineds.co/ai-connections/dist/provider-catalog.cjs +68 -1
  167. package/node_modules/@undefineds.co/ai-connections/dist/provider-catalog.d.ts +75 -1
  168. package/node_modules/@undefineds.co/ai-connections/dist/provider-catalog.js +119 -0
  169. package/node_modules/@undefineds.co/ai-connections/dist/provider-visuals.d.ts +5 -0
  170. package/node_modules/@undefineds.co/ai-connections/dist/provider-visuals.js +5 -0
  171. package/node_modules/@undefineds.co/ai-connections/dist/service-access.js +2 -27
  172. package/node_modules/@undefineds.co/ai-connections/package.json +1 -0
  173. package/node_modules/@undefineds.co/extension-sdk/dist/manifest.d.ts +1 -1
  174. package/node_modules/@undefineds.co/extension-sdk/dist/manifest.js +2 -0
  175. package/node_modules/@undefineds.co/extension-sdk/dist/web.d.ts +150 -0
  176. package/node_modules/@undefineds.co/extension-sdk/package.json +2 -1
  177. package/node_modules/@undefineds.co/models/README.md +1 -1
  178. package/node_modules/@undefineds.co/models/dist/ai-config/index.d.ts +3 -3
  179. package/node_modules/@undefineds.co/models/dist/ai-gateway.schema.d.ts +5 -0
  180. package/node_modules/@undefineds.co/models/dist/ai-gateway.schema.js +9 -0
  181. package/node_modules/@undefineds.co/models/dist/ai-runtime.repository.d.ts +1 -1
  182. package/node_modules/@undefineds.co/models/dist/approval.repository.d.ts +2 -2
  183. package/node_modules/@undefineds.co/models/dist/audit.presentation.d.ts +2 -2
  184. package/node_modules/@undefineds.co/models/dist/capture.repository.d.ts +1 -1
  185. package/node_modules/@undefineds.co/models/dist/chat-project.repository.d.ts +1 -1
  186. package/node_modules/@undefineds.co/models/dist/chat.repository.d.ts +2 -2
  187. package/node_modules/@undefineds.co/models/dist/control-request.repository.d.ts +2 -2
  188. package/node_modules/@undefineds.co/models/dist/conversation-share.repository.d.ts +1 -1
  189. package/node_modules/@undefineds.co/models/dist/credential.schema.d.ts +12 -0
  190. package/node_modules/@undefineds.co/models/dist/credential.schema.js +15 -1
  191. package/node_modules/@undefineds.co/models/dist/discovery/index.d.ts +2 -2
  192. package/node_modules/@undefineds.co/models/dist/discovery/providers.json +248 -7
  193. package/node_modules/@undefineds.co/models/dist/discovery/types.d.ts +31 -0
  194. package/node_modules/@undefineds.co/models/dist/extension/index.d.ts +1 -1
  195. package/node_modules/@undefineds.co/models/dist/favorite/index.d.ts +2 -2
  196. package/node_modules/@undefineds.co/models/dist/fixtures/contracts-chat-contact.d.ts +5 -5
  197. package/node_modules/@undefineds.co/models/dist/import/index.d.ts +1 -1
  198. package/node_modules/@undefineds.co/models/dist/index.d.ts +73 -73
  199. package/node_modules/@undefineds.co/models/dist/index.js +1 -1
  200. package/node_modules/@undefineds.co/models/dist/input-request.repository.d.ts +2 -2
  201. package/node_modules/@undefineds.co/models/dist/knowledge/index.d.ts +1 -1
  202. package/node_modules/@undefineds.co/models/dist/message.repository.d.ts +1 -1
  203. package/node_modules/@undefineds.co/models/dist/namespaces.js +5 -0
  204. package/node_modules/@undefineds.co/models/dist/pod-storage-descriptor.d.ts +4815 -26
  205. package/node_modules/@undefineds.co/models/dist/pod-storage-descriptor.js +482 -132
  206. package/node_modules/@undefineds.co/models/dist/schema.d.ts +4 -0
  207. package/node_modules/@undefineds.co/models/dist/session/index.d.ts +1 -1
  208. package/node_modules/@undefineds.co/models/dist/settings/index.d.ts +1 -1
  209. package/node_modules/@undefineds.co/models/dist/sidecar/persistence-mapping.d.ts +5 -5
  210. package/node_modules/@undefineds.co/models/dist/thread.repository.d.ts +2 -2
  211. package/node_modules/@undefineds.co/models/dist/types/message-block.d.ts +1 -1
  212. package/node_modules/@undefineds.co/models/dist/vocab/_namespaces.d.ts +1 -1
  213. package/node_modules/@undefineds.co/models/dist/vocab/index.d.ts +10 -10
  214. package/node_modules/@undefineds.co/models/dist/vocab/sidecar.vocab.d.ts +1 -0
  215. package/node_modules/@undefineds.co/models/dist/vocab/sidecar.vocab.js +1 -0
  216. package/node_modules/@undefineds.co/models/package.json +4 -2
  217. package/node_modules/@undefineds.co/pod-collections/README.md +71 -0
  218. package/node_modules/@undefineds.co/pod-collections/dist/diff.d.ts +85 -0
  219. package/node_modules/@undefineds.co/pod-collections/dist/diff.js +166 -0
  220. package/node_modules/@undefineds.co/pod-collections/dist/feed.d.ts +17 -0
  221. package/node_modules/@undefineds.co/pod-collections/dist/feed.js +27 -0
  222. package/node_modules/@undefineds.co/pod-collections/dist/index.cjs +1042 -0
  223. package/node_modules/@undefineds.co/pod-collections/dist/index.d.ts +37 -0
  224. package/node_modules/@undefineds.co/pod-collections/dist/index.js +89 -0
  225. package/node_modules/@undefineds.co/pod-collections/dist/layout.d.ts +75 -0
  226. package/node_modules/@undefineds.co/pod-collections/dist/layout.js +173 -0
  227. package/node_modules/@undefineds.co/pod-collections/dist/mapping.d.ts +78 -0
  228. package/node_modules/@undefineds.co/pod-collections/dist/mapping.js +287 -0
  229. package/node_modules/@undefineds.co/pod-collections/dist/mutations.d.ts +83 -0
  230. package/node_modules/@undefineds.co/pod-collections/dist/mutations.js +273 -0
  231. package/node_modules/@undefineds.co/pod-collections/dist/react.d.ts +21 -0
  232. package/node_modules/@undefineds.co/pod-collections/dist/react.js +22 -0
  233. package/node_modules/@undefineds.co/pod-collections/dist/read.d.ts +65 -0
  234. package/node_modules/@undefineds.co/pod-collections/dist/read.js +31 -0
  235. package/node_modules/@undefineds.co/pod-collections/dist/sync.d.ts +66 -0
  236. package/node_modules/@undefineds.co/pod-collections/dist/sync.js +260 -0
  237. package/node_modules/@undefineds.co/pod-collections/dist/types.d.ts +155 -0
  238. package/node_modules/@undefineds.co/pod-collections/dist/types.js +9 -0
  239. package/node_modules/@undefineds.co/pod-collections/package.json +42 -0
  240. package/node_modules/@undefineds.co/shared-ui/dist/index.d.ts +0 -1
  241. package/node_modules/@undefineds.co/shared-ui/dist/index.js +0 -1
  242. package/package.json +15 -7
  243. package/static/app/assets/main.css +1 -1
  244. package/static/app/assets/main.js +12 -13
  245. package/static/auth-callback/assets/AiConfigContext-DnQs1ZpW.js +1 -0
  246. package/static/auth-callback/assets/AiConfigPage-DOtvlxH0.js +1 -0
  247. package/static/auth-callback/assets/DocumentProcessingPanel-BS2voQgL.js +1 -0
  248. package/static/auth-callback/assets/IndexLifecyclePanel-Cvt0cJtN.js +1 -0
  249. package/static/auth-callback/assets/{IndexSubjectPanel-C4YG0whI.js → IndexSubjectPanel-Dhf01GqF.js} +1 -1
  250. package/static/auth-callback/assets/ModelAssignmentsPanel-BJutWaAF.js +1 -0
  251. package/static/auth-callback/assets/ModelsPage-BRS0sje3.js +11 -0
  252. package/static/auth-callback/assets/{NetworkPage-Cbdn_P1e.js → NetworkPage-B3qBfANA.js} +2 -2
  253. package/static/auth-callback/assets/{PaneListHeader-jy70Q00L.js → PaneListHeader-QQeJGTp4.js} +1 -1
  254. package/static/auth-callback/assets/SearchIndexingPanel-MyNUSEwT.js +1 -0
  255. package/static/auth-callback/assets/{StatusSubjectPanel-hfjoB5aS.js → StatusSubjectPanel-DQkEVsFs.js} +1 -1
  256. package/static/{settings/assets/StatusWorkspace-CKD_Rzdr.js → auth-callback/assets/StatusWorkspace-Dkv63Uwk.js} +1 -1
  257. package/static/auth-callback/assets/SystemSettingsPage-TIsUfX5d.js +1 -0
  258. package/static/auth-callback/assets/SystemSettingsSubjectPanel-BJWEt2-7.js +33 -0
  259. package/static/auth-callback/assets/XpodAiConnectionsPodStore-BJiXm-PF.js +3 -0
  260. package/static/auth-callback/assets/{activity-BcsZZxxw.js → activity-5hNeNKnL.js} +1 -1
  261. package/static/auth-callback/assets/admin-C6qCRFiY.js +1 -0
  262. package/static/auth-callback/assets/ai-connections-CryuHGKW.js +1 -0
  263. package/static/auth-callback/assets/{auth-callback-atKg_oig.js → auth-callback-CAFZ3R0B.js} +80 -84
  264. package/static/auth-callback/assets/auth-callback-rk080mvG.css +1 -0
  265. package/static/auth-callback/assets/{badge-BWbRHThQ.js → badge-CAIPI0CB.js} +1 -1
  266. package/static/auth-callback/assets/collection-runtime-D9s7h9YA.js +1 -0
  267. package/static/auth-callback/assets/dialog-BjA109aX.js +1 -0
  268. package/static/auth-callback/assets/{download-BmvG1Vya.js → download-B3Up5W2G.js} +1 -1
  269. package/static/auth-callback/assets/{external-link-DZ34d3g3.js → external-link-BTXgSPzB.js} +1 -1
  270. package/static/auth-callback/assets/index-BppXlxcp.js +41 -0
  271. package/static/auth-callback/assets/index-CirW4CJf.js +1 -0
  272. package/static/auth-callback/assets/index-DlLYWOhw.js +4 -0
  273. package/static/auth-callback/assets/{index-browser-B9Z7GU-T.js → index-browser-DtU38ni3.js} +1 -1
  274. package/static/auth-callback/assets/{key-round-tjP76Se-.js → key-round-CQCOrZ7x.js} +1 -1
  275. package/static/auth-callback/assets/layout-DB3pMyTl.js +1 -0
  276. package/static/auth-callback/assets/pod-collections-host-KnnGFZHL.js +8 -0
  277. package/static/auth-callback/assets/{rotate-ccw-C_L5ZLx1.js → rotate-ccw-C1zM2KtS.js} +1 -1
  278. package/static/auth-callback/assets/settings-projection-CUkyprDQ.js +1 -0
  279. package/static/auth-callback/assets/{skeleton-C7tGDQIs.js → skeleton-Cqp7_M9-.js} +1 -1
  280. package/static/auth-callback/assets/{waypoints-VMNQlWdU.js → waypoints-Bj6gAUSQ.js} +1 -1
  281. package/static/auth-callback/assets/{workspace-layout-SAp6BtYK.js → workspace-layout-DK8mDzrY.js} +1 -1
  282. package/static/auth-callback/auth-callback.html +2 -2
  283. package/static/dashboard/assets/AiConfigContext-BsE7MqX8.js +1 -0
  284. package/static/dashboard/assets/AiConfigPage-DvM-lRXa.js +1 -0
  285. package/static/dashboard/assets/DocumentProcessingPanel-BPfdlfuf.js +1 -0
  286. package/static/dashboard/assets/IndexLifecyclePanel--m0AGxvh.js +1 -0
  287. package/static/dashboard/assets/{IndexSubjectPanel-DQFPP6-p.js → IndexSubjectPanel-Bb7m1k3d.js} +1 -1
  288. package/static/dashboard/assets/ModelAssignmentsPanel-BLi_zbMa.js +1 -0
  289. package/static/dashboard/assets/ModelsPage-CxdpgnfR.js +11 -0
  290. package/static/dashboard/assets/{NetworkPage-CHQ3YxIB.js → NetworkPage-BAIPw-D_.js} +2 -2
  291. package/static/dashboard/assets/{PaneListHeader-DsXemAdR.js → PaneListHeader-BBCMei0r.js} +1 -1
  292. package/static/dashboard/assets/SearchIndexingPanel-Ck4Y-xjR.js +1 -0
  293. package/static/dashboard/assets/{StatusSubjectPanel-D3PGEYT4.js → StatusSubjectPanel-D1KWfAXE.js} +1 -1
  294. package/static/dashboard/assets/{StatusWorkspace-BcpePYUW.js → StatusWorkspace-JbA5gzXx.js} +1 -1
  295. package/static/dashboard/assets/SystemSettingsPage-BbwQWsSR.js +1 -0
  296. package/static/dashboard/assets/SystemSettingsSubjectPanel-N117nMt5.js +33 -0
  297. package/static/dashboard/assets/XpodAiConnectionsPodStore-CdDOb4SV.js +18 -0
  298. package/static/dashboard/assets/{activity-j5zrznu-.js → activity-DX1I96o_.js} +1 -1
  299. package/static/dashboard/assets/admin-C6qCRFiY.js +1 -0
  300. package/static/dashboard/assets/ai-connections-DwCRqOQa.js +1 -0
  301. package/static/dashboard/assets/{badge-CzeBdG7h.js → badge-k2vhtDqH.js} +1 -1
  302. package/static/dashboard/assets/collection-runtime-BFQ8teQJ.js +1 -0
  303. package/static/dashboard/assets/{dashboard-D-xANHk1.js → dashboard-DWZ-fmCT.js} +105 -109
  304. package/static/dashboard/assets/dashboard-rk080mvG.css +1 -0
  305. package/static/dashboard/assets/dialog-1CCw-iHT.js +1 -0
  306. package/static/dashboard/assets/{download-IcNdEZWi.js → download-C6-SNY1q.js} +1 -1
  307. package/static/dashboard/assets/{external-link-DxBxK8Vu.js → external-link-BgPcZ_j2.js} +1 -1
  308. package/static/dashboard/assets/index-6LcIUIYO.js +1 -0
  309. package/static/dashboard/assets/index-D7A8U6Pt.js +41 -0
  310. package/static/dashboard/assets/index-UD6QOE7H.js +4 -0
  311. package/static/dashboard/assets/{key-round-D1K7warM.js → key-round-BOd7Jo0Q.js} +1 -1
  312. package/static/dashboard/assets/layout-DB3pMyTl.js +1 -0
  313. package/static/dashboard/assets/pod-collections-host-KnnGFZHL.js +8 -0
  314. package/static/dashboard/assets/{rotate-ccw-CcN1N6p9.js → rotate-ccw-CCgJqsvx.js} +1 -1
  315. package/static/dashboard/assets/settings-projection-CUkyprDQ.js +1 -0
  316. package/static/dashboard/assets/{skeleton-CKnmJMUH.js → skeleton-Bc7abAn5.js} +1 -1
  317. package/static/dashboard/assets/{waypoints-DuZPO_wu.js → waypoints-s-opmJxx.js} +1 -1
  318. package/static/dashboard/assets/{workspace-layout-BUj3wZ_m.js → workspace-layout-DqIQeTBV.js} +1 -1
  319. package/static/dashboard/dashboard.html +2 -2
  320. package/static/settings/assets/AiConfigContext-BB9KZySa.js +1 -0
  321. package/static/settings/assets/AiConfigPage-DGSXUkLs.js +1 -0
  322. package/static/settings/assets/DocumentProcessingPanel-Da2Re6Rg.js +1 -0
  323. package/static/settings/assets/IndexLifecyclePanel-BSZuIzgr.js +1 -0
  324. package/static/settings/assets/{IndexSubjectPanel-73sM16Ma.js → IndexSubjectPanel-CFd0ay-r.js} +1 -1
  325. package/static/settings/assets/ModelAssignmentsPanel-CSAryvWJ.js +1 -0
  326. package/static/settings/assets/ModelsPage-BQwCwLHU.js +11 -0
  327. package/static/settings/assets/{NetworkPage-i6j-M2RY.js → NetworkPage-BKymvsQc.js} +2 -2
  328. package/static/settings/assets/{PaneListHeader-DpqC0jd5.js → PaneListHeader-Bjh3hRdQ.js} +1 -1
  329. package/static/settings/assets/SearchIndexingPanel-MjKL5QLU.js +1 -0
  330. package/static/settings/assets/{StatusSubjectPanel-Dv4q3PGh.js → StatusSubjectPanel-Bvl6K4mx.js} +1 -1
  331. package/static/settings/assets/StatusWorkspace-B0NzrP--.js +1 -0
  332. package/static/settings/assets/SystemSettingsPage-D2z6Z4FE.js +1 -0
  333. package/static/settings/assets/SystemSettingsSubjectPanel-4sxma4X4.js +33 -0
  334. package/static/settings/assets/XpodAiConnectionsPodStore-BkNQ8fZx.js +3 -0
  335. package/static/settings/assets/{activity-DaFkk8f3.js → activity-CgJJGpjx.js} +1 -1
  336. package/static/settings/assets/admin-C6qCRFiY.js +1 -0
  337. package/static/settings/assets/ai-connections-CryuHGKW.js +1 -0
  338. package/static/settings/assets/{badge-d5SHdc-x.js → badge-C4NypVyT.js} +1 -1
  339. package/static/settings/assets/collection-runtime-CTLCDxAi.js +1 -0
  340. package/static/settings/assets/dialog-Csq0vWUi.js +1 -0
  341. package/static/settings/assets/{download-CpkwomDr.js → download-DaLJJ-Wp.js} +1 -1
  342. package/static/settings/assets/{external-link-_4YT42Mf.js → external-link--w_iW5Au.js} +1 -1
  343. package/static/settings/assets/index-B0mQa59b.js +4 -0
  344. package/static/settings/assets/index-BukHiu4y.js +1 -0
  345. package/static/settings/assets/index-COmVnZi2.js +41 -0
  346. package/static/settings/assets/{index-browser-B06xjBdZ.js → index-browser-BGpvHwD0.js} +1 -1
  347. package/static/settings/assets/{key-round-Dlqmp1Kq.js → key-round-Bk4YRjBu.js} +1 -1
  348. package/static/settings/assets/layout-DB3pMyTl.js +1 -0
  349. package/static/settings/assets/pod-collections-host-KnnGFZHL.js +8 -0
  350. package/static/settings/assets/{rotate-ccw-TAY65xWT.js → rotate-ccw-TCabbqsr.js} +1 -1
  351. package/static/settings/assets/{settings-ExBXGgbj.js → settings-CJWpdbNC.js} +105 -109
  352. package/static/settings/assets/settings-projection-CUkyprDQ.js +1 -0
  353. package/static/settings/assets/settings-rk080mvG.css +1 -0
  354. package/static/settings/assets/{skeleton-DKIWjNr9.js → skeleton-JDHYVe7t.js} +1 -1
  355. package/static/settings/assets/{waypoints-9erLIxyR.js → waypoints-DDvEl-MU.js} +1 -1
  356. package/static/settings/assets/{workspace-layout-CYXfYIa3.js → workspace-layout-DV5QU30U.js} +1 -1
  357. package/static/settings/settings.html +2 -2
  358. package/node_modules/@undefineds.co/shared-ui/dist/oidc-consent.d.ts +0 -54
  359. package/node_modules/@undefineds.co/shared-ui/dist/oidc-consent.js +0 -21
  360. package/static/auth-callback/assets/AiConfigContext-C81deMM9.js +0 -1
  361. package/static/auth-callback/assets/AiConfigPage-evWI8T56.js +0 -1
  362. package/static/auth-callback/assets/DocumentProcessingPanel-B9GrDEMe.js +0 -1
  363. package/static/auth-callback/assets/IndexLifecyclePanel-qCo8ABQZ.js +0 -1
  364. package/static/auth-callback/assets/ModelAssignmentsPanel-DG7Lxh3t.js +0 -1
  365. package/static/auth-callback/assets/ModelsPage-CgEuqE6p.js +0 -10
  366. package/static/auth-callback/assets/SearchIndexingPanel-ByU3u7kp.js +0 -1
  367. package/static/auth-callback/assets/StatusWorkspace-BZd617sV.js +0 -1
  368. package/static/auth-callback/assets/SystemSettingsPage-BirzWAQM.js +0 -1
  369. package/static/auth-callback/assets/SystemSettingsSubjectPanel-CmsVWNCx.js +0 -31
  370. package/static/auth-callback/assets/admin-BU4m6Ko2.js +0 -1
  371. package/static/auth-callback/assets/ai-connections-CHNTKemd.js +0 -1
  372. package/static/auth-callback/assets/auth-callback-C_7MUXJb.css +0 -1
  373. package/static/auth-callback/assets/index-BpV1hsqs.js +0 -4
  374. package/static/auth-callback/assets/index-D9oE6FXK.js +0 -41
  375. package/static/dashboard/assets/AiConfigContext-De-OtAWo.js +0 -1
  376. package/static/dashboard/assets/AiConfigPage-macP4Mop.js +0 -1
  377. package/static/dashboard/assets/DocumentProcessingPanel-C5ObvCCl.js +0 -1
  378. package/static/dashboard/assets/IndexLifecyclePanel-xVNa2l40.js +0 -1
  379. package/static/dashboard/assets/ModelAssignmentsPanel-DMOATFpQ.js +0 -1
  380. package/static/dashboard/assets/ModelsPage-91UbnETA.js +0 -25
  381. package/static/dashboard/assets/SearchIndexingPanel-Dh70PNFZ.js +0 -1
  382. package/static/dashboard/assets/SystemSettingsPage-BiN5GcKx.js +0 -1
  383. package/static/dashboard/assets/SystemSettingsSubjectPanel-B9QrSiFp.js +0 -31
  384. package/static/dashboard/assets/admin-BU4m6Ko2.js +0 -1
  385. package/static/dashboard/assets/ai-connections-CHNTKemd.js +0 -1
  386. package/static/dashboard/assets/dashboard-C_7MUXJb.css +0 -1
  387. package/static/dashboard/assets/index-FWZ-s52O.js +0 -41
  388. package/static/dashboard/assets/index-ZiQZ96oC.js +0 -4
  389. package/static/settings/assets/AiConfigContext-C0cQMPfG.js +0 -1
  390. package/static/settings/assets/AiConfigPage-CPhB4iFb.js +0 -1
  391. package/static/settings/assets/DocumentProcessingPanel-sYI7OpuH.js +0 -1
  392. package/static/settings/assets/IndexLifecyclePanel-yj8iyiT8.js +0 -1
  393. package/static/settings/assets/ModelAssignmentsPanel-BFIgUX5v.js +0 -1
  394. package/static/settings/assets/ModelsPage-BdppXl7E.js +0 -10
  395. package/static/settings/assets/SearchIndexingPanel-BlPnrkT3.js +0 -1
  396. package/static/settings/assets/SystemSettingsPage-CiOm2NzV.js +0 -1
  397. package/static/settings/assets/SystemSettingsSubjectPanel-Cd-GECon.js +0 -31
  398. package/static/settings/assets/admin-BU4m6Ko2.js +0 -1
  399. package/static/settings/assets/ai-connections-CHNTKemd.js +0 -1
  400. package/static/settings/assets/index-BFi9yn7_.js +0 -41
  401. package/static/settings/assets/index-BGgEhIUy.js +0 -4
  402. package/static/settings/assets/settings-C_7MUXJb.css +0 -1
@@ -0,0 +1,1042 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ function __accessProp(key) {
6
+ return this[key];
7
+ }
8
+ var __toCommonJS = (from) => {
9
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
+ if (entry)
11
+ return entry;
12
+ entry = __defProp({}, "__esModule", { value: true });
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (var key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(entry, key))
16
+ __defProp(entry, key, {
17
+ get: __accessProp.bind(from, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ __moduleCache.set(from, entry);
22
+ return entry;
23
+ };
24
+ var __moduleCache;
25
+ var __returnValue = (v) => v;
26
+ function __exportSetter(name, newValue) {
27
+ this[name] = __returnValue.bind(null, newValue);
28
+ }
29
+ var __export = (target, all) => {
30
+ for (var name in all)
31
+ __defProp(target, name, {
32
+ get: all[name],
33
+ enumerable: true,
34
+ configurable: true,
35
+ set: __exportSetter.bind(all, name)
36
+ });
37
+ };
38
+
39
+ // src/index.ts
40
+ var exports_src = {};
41
+ __export(exports_src, {
42
+ writeOnlyFields: () => writeOnlyFields,
43
+ valueToTerm: () => valueToTerm,
44
+ tableColumnsWithoutDescriptorField: () => tableColumnsWithoutDescriptorField,
45
+ subjectIriForRow: () => subjectIriForRow,
46
+ stripVirtualProps: () => stripVirtualProps,
47
+ sessionFetchOf: () => sessionFetchOf,
48
+ rowKeyOf: () => rowKeyOf,
49
+ resourceIdForRow: () => resourceIdForRow,
50
+ resolveTableDocument: () => resolveTableDocument,
51
+ projectionHash: () => projectionHash,
52
+ projectionFieldOrder: () => projectionFieldOrder,
53
+ podCollectionInternals: () => podCollectionInternals,
54
+ mapSubjectRows: () => mapSubjectRows,
55
+ fieldBindings: () => fieldBindings,
56
+ descriptorFieldsWithoutColumn: () => descriptorFieldsWithoutColumn,
57
+ definePodCollection: () => definePodCollection,
58
+ conditionalDocumentRead: () => conditionalDocumentRead,
59
+ computeDocumentDiff: () => computeDocumentDiff,
60
+ coerceFieldValue: () => coerceFieldValue,
61
+ PodCollectionError: () => PodCollectionError,
62
+ DEFAULT_CONFIRM_RETRIES: () => DEFAULT_CONFIRM_RETRIES,
63
+ DEFAULT_COALESCE_MS: () => DEFAULT_COALESCE_MS
64
+ });
65
+ module.exports = __toCommonJS(exports_src);
66
+ var import_db = require("@tanstack/db");
67
+
68
+ // src/types.ts
69
+ class PodCollectionError extends Error {
70
+ code;
71
+ cause;
72
+ constructor(code, message, options) {
73
+ super(message);
74
+ this.name = "PodCollectionError";
75
+ this.code = code;
76
+ this.cause = options?.cause;
77
+ }
78
+ }
79
+
80
+ // src/layout.ts
81
+ var TEMPLATE_VARIABLE = /\{([^{}]+)\}/gu;
82
+ function escapeRegExp(value) {
83
+ return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
84
+ }
85
+ function normalizePodUrl(podUrl) {
86
+ return podUrl.endsWith("/") ? podUrl : `${podUrl}/`;
87
+ }
88
+ function resolvePodUrl(podUrl, value) {
89
+ if (/^[a-z][a-z0-9+.-]*:/iu.test(value))
90
+ return value;
91
+ return new URL(value.replace(/^\/+/u, ""), normalizePodUrl(podUrl)).toString();
92
+ }
93
+ function templateVariables(pattern) {
94
+ return [...pattern.matchAll(TEMPLATE_VARIABLE)].map((match) => match[1]);
95
+ }
96
+ function rowKeyVariable(pattern) {
97
+ const last = templateVariables(pattern).at(-1);
98
+ if (!last) {
99
+ throw new PodCollectionError("layout_pattern_without_key", `resourceIdPattern "${pattern}" has no {…} key slot`);
100
+ }
101
+ return last;
102
+ }
103
+ function splitOnKeySlot(pattern) {
104
+ const slot = `{${rowKeyVariable(pattern)}}`;
105
+ const index = pattern.lastIndexOf(slot);
106
+ return { head: pattern.slice(0, index), tail: pattern.slice(index + slot.length), slot };
107
+ }
108
+ function isDocumentBase(base) {
109
+ const lastSegment = base.replace(/\/+$/u, "").split("/").pop() ?? "";
110
+ return lastSegment.includes(".");
111
+ }
112
+ function baseDirectory(base) {
113
+ if (base.endsWith("/"))
114
+ return base;
115
+ const slash = base.lastIndexOf("/");
116
+ return slash < 0 ? "/" : base.slice(0, slash + 1);
117
+ }
118
+ function resolveTableDocument(descriptor, input) {
119
+ const podUrl = normalizePodUrl(input.podUrl);
120
+ if (input.document)
121
+ return resolvePodUrl(podUrl, input.document);
122
+ const base = descriptor.storage.base;
123
+ const pattern = descriptor.storage.resourceIdPattern;
124
+ if (!base || !pattern) {
125
+ throw new PodCollectionError("layout_missing_storage", `descriptor ${descriptor.uri} has no storage.base / resourceIdPattern`);
126
+ }
127
+ if (isDocumentBase(base))
128
+ return resolvePodUrl(podUrl, base);
129
+ const { head, tail } = splitOnKeySlot(pattern);
130
+ if (!pattern.includes("#") && templateVariables(head).length === 0) {
131
+ const key = input.scope?.instanceId ?? input.scope?.provider;
132
+ if (!key) {
133
+ throw new PodCollectionError("layout_document_required", `descriptor ${descriptor.uri} stores one document per row key (${pattern}); pass document or scope`);
134
+ }
135
+ return resolvePodUrl(podUrl, `${base}${head}${key}${tail}`);
136
+ }
137
+ throw new PodCollectionError("layout_document_required", `descriptor ${descriptor.uri} stores rows across documents (${base}${pattern}); pass document explicitly`);
138
+ }
139
+ function documentResourceId(documentUrl, podUrl) {
140
+ const root = normalizePodUrl(podUrl);
141
+ if (documentUrl.startsWith(root))
142
+ return documentUrl.slice(root.length);
143
+ return documentUrl.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/]*/iu, "").replace(/^\/+/u, "");
144
+ }
145
+ function documentKeyOf(descriptor, documentUrl, podUrl) {
146
+ const relative = documentResourceId(documentUrl, podUrl);
147
+ const baseDir = baseDirectory(descriptor.storage.base).replace(/^\/+/u, "");
148
+ const key = relative.startsWith(baseDir) ? relative.slice(baseDir.length) : relative;
149
+ if (!key) {
150
+ throw new PodCollectionError("layout_document_outside_base", `document ${documentUrl} is not under ${descriptor.storage.base}`);
151
+ }
152
+ return key;
153
+ }
154
+ function resourceIdForRow(descriptor, documentUrl, podUrl, key) {
155
+ const pattern = descriptor.storage.resourceIdPattern;
156
+ const documentKey = documentKeyOf(descriptor, documentUrl, podUrl);
157
+ const { head, tail, slot } = splitOnKeySlot(pattern);
158
+ if (templateVariables(pattern).length > 1) {
159
+ throw new PodCollectionError("layout_document_required", `resourceIdPattern "${pattern}" has template variables this layer cannot fill`);
160
+ }
161
+ if (pattern.startsWith("#"))
162
+ return `${documentKey}${pattern.replace(slot, key)}`;
163
+ return `${head}${key}${tail}`;
164
+ }
165
+ function subjectIriForRow(descriptor, documentUrl, key) {
166
+ return descriptor.storage.resourceIdPattern.includes("#") ? `${documentUrl}#${key}` : documentUrl;
167
+ }
168
+ function documentOfIri(iri) {
169
+ const hash = iri.indexOf("#");
170
+ return hash < 0 ? iri : iri.slice(0, hash);
171
+ }
172
+ function rowSubjectIriOf(row) {
173
+ for (const candidate of [row["@id"], row.uri, row.subject]) {
174
+ if (typeof candidate === "string" && candidate.length > 0)
175
+ return candidate;
176
+ }
177
+ return;
178
+ }
179
+ function rowResourceIdOf(row) {
180
+ return typeof row.id === "string" && row.id.length > 0 ? row.id : undefined;
181
+ }
182
+ function rowKeyOf(descriptor, row) {
183
+ const resourceId = rowResourceIdOf(row);
184
+ if (!resourceId)
185
+ return;
186
+ return compileRowKeyPattern(descriptor.storage.resourceIdPattern).exec(resourceId)?.[1];
187
+ }
188
+ function compileRowKeyPattern(pattern) {
189
+ const matches = [...pattern.matchAll(TEMPLATE_VARIABLE)];
190
+ const last = matches.at(-1);
191
+ if (!last) {
192
+ throw new PodCollectionError("layout_pattern_without_key", `resourceIdPattern "${pattern}" has no {…} key slot`);
193
+ }
194
+ let source = "^[\\s\\S]*?";
195
+ let cursor = 0;
196
+ for (const match of matches) {
197
+ const index = match.index ?? 0;
198
+ source += escapeRegExp(pattern.slice(cursor, index));
199
+ source += match === last ? "([\\s\\S]+)" : "[\\s\\S]*?";
200
+ cursor = index + match[0].length;
201
+ }
202
+ source += `${escapeRegExp(pattern.slice(cursor))}$`;
203
+ return new RegExp(source, "u");
204
+ }
205
+ function rowBelongsToDocument(descriptor, documentUrl, podUrl, row) {
206
+ const document = documentOfIri(documentUrl);
207
+ const subject = rowSubjectIriOf(row);
208
+ if (subject)
209
+ return documentOfIri(subject) === document;
210
+ const resourceId = rowResourceIdOf(row);
211
+ if (!resourceId)
212
+ return false;
213
+ const documentKey = documentKeyOf(descriptor, documentUrl, podUrl);
214
+ return documentOfIri(resourceId).endsWith(documentKey);
215
+ }
216
+
217
+ // src/mapping.ts
218
+ var XSD = "http://www.w3.org/2001/XMLSchema#";
219
+ function tableColumnPredicates(table) {
220
+ const mapping = table.getMapping();
221
+ const predicates = new Map;
222
+ for (const [column, entry] of Object.entries(mapping.columns)) {
223
+ if (entry.predicate === "@id")
224
+ continue;
225
+ predicates.set(column, entry.predicate);
226
+ }
227
+ return predicates;
228
+ }
229
+ function fieldBindings(descriptor, table) {
230
+ const byPredicate = new Map;
231
+ for (const [column, predicate] of tableColumnPredicates(table)) {
232
+ byPredicate.set(predicate, column);
233
+ }
234
+ const bindings = new Map;
235
+ for (const [field, fieldDescriptor] of Object.entries(descriptor.fields)) {
236
+ bindings.set(field, { field, descriptor: fieldDescriptor, column: byPredicate.get(fieldDescriptor.predicate) });
237
+ }
238
+ return bindings;
239
+ }
240
+ function identityFieldOf(descriptor) {
241
+ return rowKeyVariable(descriptor.storage.resourceIdPattern);
242
+ }
243
+ function descriptorFieldsWithoutColumn(descriptor, table) {
244
+ const identity = identityFieldOf(descriptor);
245
+ return [...fieldBindings(descriptor, table).values()].filter((binding) => binding.column === undefined && binding.field !== identity).map((binding) => binding.field).sort();
246
+ }
247
+ function tableColumnsWithoutDescriptorField(descriptor, table) {
248
+ const declaredPredicates = new Set(Object.values(descriptor.fields).map((field) => field.predicate));
249
+ return [...tableColumnPredicates(table)].filter(([, predicate]) => !declaredPredicates.has(predicate)).map(([column]) => column).sort();
250
+ }
251
+ function assertDescriptorTableAlignment(descriptor, table) {
252
+ const tableClass = table.getType();
253
+ if (descriptor.class !== tableClass) {
254
+ throw new PodCollectionError("mapping_class_mismatch", `descriptor ${descriptor.uri} declares class ${descriptor.class} but table ${table.config.name} reads ${tableClass}`);
255
+ }
256
+ }
257
+ function writeOnlyFields(descriptor) {
258
+ return new Set(Object.entries(descriptor.fields).filter(([, field]) => field.secret === true).map(([name]) => name));
259
+ }
260
+ function projectionFieldOrder(descriptor) {
261
+ const writeOnly = writeOnlyFields(descriptor);
262
+ return Object.entries(descriptor.fields).filter(([field]) => !writeOnly.has(field)).sort(([, left], [, right]) => left.predicate < right.predicate ? -1 : left.predicate > right.predicate ? 1 : 0).map(([field]) => field);
263
+ }
264
+ function isRdfTerm(value) {
265
+ return typeof value === "object" && value !== null && typeof value.termType === "string" && typeof value.value === "string";
266
+ }
267
+ function termDatatypeOf(value) {
268
+ const datatype = value.datatype;
269
+ if (!datatype)
270
+ return;
271
+ return typeof datatype === "string" ? datatype : datatype.value;
272
+ }
273
+ function coerceScalar(field, input) {
274
+ if (input === null || input === undefined || input === "")
275
+ return;
276
+ const term = isRdfTerm(input) ? input : undefined;
277
+ const raw = term ? term.value : input;
278
+ const datatype = term ? termDatatypeOf(term) : undefined;
279
+ switch (field.type) {
280
+ case "uri":
281
+ return term && term.termType !== "NamedNode" ? String(raw) : String(raw);
282
+ case "string":
283
+ case "text":
284
+ return typeof raw === "boolean" || typeof raw === "number" ? String(raw) : String(raw);
285
+ case "number": {
286
+ if (typeof raw === "number")
287
+ return raw;
288
+ const parsed = Number(raw);
289
+ return Number.isFinite(parsed) ? parsed : undefined;
290
+ }
291
+ case "boolean":
292
+ if (typeof raw === "boolean")
293
+ return raw;
294
+ if (raw === "true")
295
+ return true;
296
+ if (raw === "false")
297
+ return false;
298
+ return Boolean(raw);
299
+ case "timestamp": {
300
+ const date = raw instanceof Date ? raw : new Date(String(raw));
301
+ return Number.isNaN(date.getTime()) ? undefined : date;
302
+ }
303
+ case "json": {
304
+ if (!term)
305
+ return input;
306
+ if (datatype && !/#json(Array)?$/u.test(datatype) && raw === "")
307
+ return;
308
+ try {
309
+ return JSON.parse(String(raw));
310
+ } catch {
311
+ return raw;
312
+ }
313
+ }
314
+ default:
315
+ return raw;
316
+ }
317
+ }
318
+ function coerceFieldValue(field, input) {
319
+ if (field.array) {
320
+ if (input === undefined || input === null)
321
+ return;
322
+ const list = Array.isArray(input) ? input : [input];
323
+ const values = list.map((item) => coerceScalar(field, item)).filter((item) => item !== undefined);
324
+ return values.length > 0 ? values : undefined;
325
+ }
326
+ return coerceScalar(field, input);
327
+ }
328
+ function valueToTerm(field, value) {
329
+ if (value === undefined || value === null)
330
+ return;
331
+ if (field.type === "uri")
332
+ return { termType: "NamedNode", value: String(value) };
333
+ if (field.type === "number") {
334
+ const numeric = typeof value === "number" ? value : Number(value);
335
+ if (!Number.isFinite(numeric))
336
+ return;
337
+ return {
338
+ termType: "Literal",
339
+ value: String(numeric),
340
+ datatype: Number.isInteger(numeric) ? `${XSD}integer` : `${XSD}decimal`
341
+ };
342
+ }
343
+ if (field.type === "boolean") {
344
+ return { termType: "Literal", value: value ? "true" : "false", datatype: `${XSD}boolean` };
345
+ }
346
+ if (field.type === "timestamp") {
347
+ const date = value instanceof Date ? value : new Date(String(value));
348
+ if (Number.isNaN(date.getTime()))
349
+ return;
350
+ return { termType: "Literal", value: date.toISOString(), datatype: `${XSD}dateTime` };
351
+ }
352
+ if (field.type === "json") {
353
+ return { termType: "Literal", value: typeof value === "string" ? value : JSON.stringify(value) };
354
+ }
355
+ const text = String(value);
356
+ if (/^https?:\/\//u.test(text))
357
+ return { termType: "NamedNode", value: text };
358
+ return { termType: "Literal", value: text };
359
+ }
360
+ function mapSubjectRows(descriptor, table, subjects) {
361
+ const bindings = fieldBindings(descriptor, table);
362
+ const identityField = identityFieldOf(descriptor);
363
+ const writeOnly = writeOnlyFields(descriptor);
364
+ const rows = [];
365
+ for (const subject of subjects) {
366
+ const key = rowKeyOf(descriptor, subject);
367
+ if (key === undefined)
368
+ continue;
369
+ const row = { id: key };
370
+ if (identityField !== "id")
371
+ row[identityField] = key;
372
+ const subjectIri = subject["@id"] ?? subject.uri ?? subject.subject;
373
+ if (typeof subjectIri === "string")
374
+ row["@id"] = subjectIri;
375
+ for (const binding of bindings.values()) {
376
+ if (writeOnly.has(binding.field))
377
+ continue;
378
+ if (binding.column === undefined)
379
+ continue;
380
+ const value = coerceFieldValue(binding.descriptor, subject[binding.column]);
381
+ if (value !== undefined)
382
+ row[binding.field] = value;
383
+ }
384
+ rows.push(row);
385
+ }
386
+ return rows;
387
+ }
388
+ function descriptorRowToColumnValues(descriptor, table, row, options) {
389
+ const bindings = fieldBindings(descriptor, table);
390
+ const values = { id: options.resourceId };
391
+ for (const [field, value] of Object.entries(row)) {
392
+ if (field === "id" || field === "@id")
393
+ continue;
394
+ const binding = bindings.get(field);
395
+ if (!binding || binding.column === undefined)
396
+ continue;
397
+ if (options.includeField && !options.includeField(field))
398
+ continue;
399
+ values[binding.column] = value;
400
+ }
401
+ return values;
402
+ }
403
+ function isUriArrayField(field) {
404
+ return field.array === true && field.type === "uri";
405
+ }
406
+
407
+ // src/read.ts
408
+ async function selectSubjectRows(table, database) {
409
+ const initialized = typeof table.isInitialized === "function" ? table.isInitialized() : true;
410
+ if (!initialized)
411
+ await database.init?.(table);
412
+ const rows = await database.select().from(table).execute();
413
+ return rows;
414
+ }
415
+ async function conditionalDocumentRead(source, _request = {}) {
416
+ const subjects = await selectSubjectRows(source.table, source.database);
417
+ return {
418
+ etag: undefined,
419
+ subjects: subjects.filter((subject) => rowBelongsToDocument(source.descriptor, source.document, source.podUrl, subject))
420
+ };
421
+ }
422
+ function sessionFetchOf(database) {
423
+ const dialect = database.getDialect?.();
424
+ const candidate = dialect?.config?.session?.fetch;
425
+ return typeof candidate === "function" ? candidate : undefined;
426
+ }
427
+
428
+ // src/diff.ts
429
+ var EMPTY_FIELDS = new Set;
430
+ function stripVirtualProps(row) {
431
+ const source = row;
432
+ const stripped = {};
433
+ for (const [key, value] of Object.entries(source)) {
434
+ if (key.startsWith("$"))
435
+ continue;
436
+ stripped[key] = value;
437
+ }
438
+ return stripped;
439
+ }
440
+ function canonicalValue(value) {
441
+ if (value instanceof Date)
442
+ return value.toISOString();
443
+ if (Array.isArray(value))
444
+ return value.map((item) => canonicalValue(item));
445
+ if (value && typeof value === "object") {
446
+ if (value instanceof Set)
447
+ return [...value].map((item) => canonicalValue(item));
448
+ const entries = Object.entries(value).filter(([, item]) => item !== undefined).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0);
449
+ return Object.fromEntries(entries.map(([key, item]) => [key, canonicalValue(item)]));
450
+ }
451
+ return value;
452
+ }
453
+ function projectionHash(row, fieldOrder) {
454
+ const source = stripVirtualProps(row);
455
+ const ordered = {};
456
+ if (source.id !== undefined)
457
+ ordered.id = canonicalValue(source.id);
458
+ for (const field of fieldOrder) {
459
+ if (source[field] !== undefined)
460
+ ordered[field] = canonicalValue(source[field]);
461
+ }
462
+ return JSON.stringify(ordered);
463
+ }
464
+ function canonicalEquals(left, right) {
465
+ if (left === undefined || right === undefined)
466
+ return left === right;
467
+ return JSON.stringify(canonicalValue(left)) === JSON.stringify(canonicalValue(right));
468
+ }
469
+ function projectionCovers(row, intent, writeOnly = EMPTY_FIELDS) {
470
+ if (row === undefined)
471
+ return false;
472
+ const source = stripVirtualProps(row);
473
+ const target = stripVirtualProps(intent);
474
+ for (const [key, value] of Object.entries(target)) {
475
+ if (key === "@id" || value === undefined)
476
+ continue;
477
+ if (writeOnly.has(key))
478
+ continue;
479
+ if (!canonicalEquals(source[key], value))
480
+ return false;
481
+ }
482
+ return true;
483
+ }
484
+ function computeDocumentDiff(input) {
485
+ const present = new Set(input.presentKeys);
486
+ const inserts = [];
487
+ const updates = [];
488
+ const deletes = [];
489
+ const baselineHash = (key) => {
490
+ const known = input.knownHash(key);
491
+ if (known !== undefined)
492
+ return known;
493
+ const held = input.presentRow?.(key);
494
+ return held === undefined ? undefined : input.hashOf(held);
495
+ };
496
+ for (const [key, row] of input.next) {
497
+ if (input.pendingKeys.has(key)) {
498
+ if (present.has(key) && baselineHash(key) !== input.hashOf(row)) {
499
+ updates.push({ key, row });
500
+ }
501
+ continue;
502
+ }
503
+ if (!present.has(key)) {
504
+ inserts.push({ key, row });
505
+ continue;
506
+ }
507
+ if (baselineHash(key) !== input.hashOf(row))
508
+ updates.push({ key, row });
509
+ }
510
+ for (const key of present) {
511
+ if (input.next.has(key))
512
+ continue;
513
+ if (input.pendingKeys.has(key))
514
+ continue;
515
+ const row = input.presentRow?.(key);
516
+ if (row === undefined)
517
+ continue;
518
+ deletes.push({ key, row });
519
+ }
520
+ return { inserts, updates, deletes };
521
+ }
522
+
523
+ // src/mutations.ts
524
+ function createDeferred() {
525
+ let resolve;
526
+ const promise = new Promise((settle) => {
527
+ resolve = () => settle();
528
+ });
529
+ return { promise, resolve };
530
+ }
531
+ function createPendingWrites(onConflict) {
532
+ const keys = new Set;
533
+ const entries = new Map;
534
+ const conflicts = [];
535
+ const clear = (key) => {
536
+ keys.delete(key);
537
+ entries.delete(key);
538
+ };
539
+ const settle = (entry, error) => {
540
+ if (entry.settled)
541
+ return;
542
+ entry.error = error;
543
+ entry.settled = true;
544
+ entry.resolveSettled();
545
+ };
546
+ const register = (input) => {
547
+ clear(input.key);
548
+ const deferred = createDeferred();
549
+ const entry = {
550
+ ...input,
551
+ settled: false,
552
+ error: undefined,
553
+ settledPromise: deferred.promise,
554
+ resolveSettled: deferred.resolve
555
+ };
556
+ entries.set(input.key, entry);
557
+ keys.add(input.key);
558
+ return entry;
559
+ };
560
+ return {
561
+ keys,
562
+ entries,
563
+ conflicts,
564
+ register,
565
+ clear,
566
+ settle,
567
+ isConfirmed: (key) => entries.get(key)?.settled === true && entries.get(key)?.error === undefined,
568
+ recordConflict: (conflict) => {
569
+ conflicts.push(conflict);
570
+ onConflict?.(conflict);
571
+ }
572
+ };
573
+ }
574
+ function markConflict(pending, entry, server) {
575
+ pending.recordConflict({
576
+ key: entry.key,
577
+ server,
578
+ local: entry.localRow ?? entry.intent ?? server,
579
+ at: Date.now()
580
+ });
581
+ pending.settle(entry, new PodCollectionError("write_conflict", `row ${entry.key} was changed by someone else; server wins`));
582
+ }
583
+ function reconcilePendingWrites(pending, next, hashOf, writeOnly = EMPTY_WRITE_ONLY) {
584
+ for (const entry of pending.entries.values()) {
585
+ if (entry.settled)
586
+ continue;
587
+ const server = next.get(entry.key);
588
+ if (entry.intent === undefined) {
589
+ if (server === undefined) {
590
+ pending.settle(entry);
591
+ continue;
592
+ }
593
+ if (entry.beforeHash !== undefined && hashOf(server) !== entry.beforeHash) {
594
+ markConflict(pending, entry, server);
595
+ }
596
+ continue;
597
+ }
598
+ if (projectionCovers(server, entry.intent, writeOnly)) {
599
+ pending.settle(entry);
600
+ continue;
601
+ }
602
+ if (server !== undefined && hashOf(server) !== entry.beforeHash) {
603
+ markConflict(pending, entry, server);
604
+ continue;
605
+ }
606
+ if (server === undefined && entry.beforeHash !== undefined) {
607
+ pending.settle(entry, new PodCollectionError("write_conflict", `row ${entry.key} disappeared before the write was confirmed; server wins`));
608
+ }
609
+ }
610
+ }
611
+ var EMPTY_WRITE_ONLY = new Set;
612
+ function absoluteUri(value, base) {
613
+ if (typeof value !== "string" || value.length === 0)
614
+ return;
615
+ if (/^[a-z][a-z0-9+.-]*:/iu.test(value))
616
+ return value;
617
+ return new URL(value, base).toString();
618
+ }
619
+ async function writeField(context, fieldName, options) {
620
+ const field = context.descriptor.fields[fieldName];
621
+ if (!field || !isUriArrayField(field)) {
622
+ throw new PodCollectionError("write_field_not_uri_array", `field ${fieldName} is not array+uri; it must go through the ORM`);
623
+ }
624
+ const documentUrl = documentOfIri(context.document);
625
+ const previous = (Array.isArray(options.previous) ? options.previous : [options.previous]).map((value) => absoluteUri(value, documentUrl)).filter((value) => value !== undefined);
626
+ const next = (Array.isArray(options.next) ? options.next : [options.next]).map((value) => absoluteUri(value, documentUrl)).filter((value) => value !== undefined);
627
+ const triples = (iris) => iris.map((iri) => `<${options.subjectIri}> <${field.predicate}> <${iri}> .`).join(`
628
+ `);
629
+ const operations = [
630
+ previous.length > 0 ? `DELETE DATA { ${triples(previous)} }` : undefined,
631
+ next.length > 0 ? `INSERT DATA { ${triples(next)} }` : undefined
632
+ ].filter((operation) => operation !== undefined);
633
+ if (operations.length === 0)
634
+ return;
635
+ const fetchFn = context.authenticatedFetch ?? sessionFetchOf(context.database);
636
+ if (!fetchFn) {
637
+ throw new PodCollectionError("write_field_no_fetch", "array+uri fields need an authenticated fetch (SolidAuthSession.fetch); none available");
638
+ }
639
+ const response = await fetchFn(documentUrl, {
640
+ method: "PATCH",
641
+ headers: { "content-type": "application/sparql-update" },
642
+ body: operations.join(`;
643
+ `)
644
+ });
645
+ if (!response.ok) {
646
+ throw new PodCollectionError("write_field_rejected", `SPARQL PATCH for ${fieldName} failed with HTTP ${response.status}`);
647
+ }
648
+ }
649
+ function createMutationHandlers(context) {
650
+ const { descriptor, table, pending } = context;
651
+ const fieldOrder = projectionFieldOrder(descriptor);
652
+ const hashOf = (row) => projectionHash(row, fieldOrder);
653
+ const uriArrayFieldNames = new Set(Object.entries(descriptor.fields).filter(([, field]) => isUriArrayField(field)).map(([name]) => name));
654
+ const columnBindings = fieldBindings(descriptor, table);
655
+ const columnOf = (field) => columnBindings.get(field)?.column;
656
+ const runWrite = async (key, write) => {
657
+ try {
658
+ await write();
659
+ } catch (error) {
660
+ pending.clear(key);
661
+ throw error instanceof Error ? error : new PodCollectionError("write_failed", String(error), { cause: error });
662
+ }
663
+ try {
664
+ await context.confirm(key);
665
+ } finally {
666
+ pending.clear(key);
667
+ }
668
+ };
669
+ return {
670
+ onInsert: async ({ transaction }) => {
671
+ for (const mutation of transaction.mutations) {
672
+ const row = mutation.modified;
673
+ const key = String(mutation.key);
674
+ const resourceId = resourceIdForRow(descriptor, context.document, context.podUrl, key);
675
+ const subjectIri = subjectIriForRow(descriptor, context.document, key);
676
+ pending.register({
677
+ key,
678
+ intent: row,
679
+ localRow: row,
680
+ beforeHash: undefined
681
+ });
682
+ await runWrite(key, async () => {
683
+ const values = descriptorRowToColumnValues(descriptor, table, row, {
684
+ resourceId,
685
+ includeField: (field) => !uriArrayFieldNames.has(field)
686
+ });
687
+ await context.database.insert(table).values(values).execute();
688
+ await writeUriArrayFields(context, row, subjectIri, undefined, row);
689
+ });
690
+ }
691
+ },
692
+ onUpdate: async ({ transaction }) => {
693
+ for (const mutation of transaction.mutations) {
694
+ const key = String(mutation.key);
695
+ const original = mutation.original;
696
+ const modified = mutation.modified;
697
+ const changes = mutation.changes;
698
+ const resourceId = resourceIdForRow(descriptor, context.document, context.podUrl, key);
699
+ const subjectIri = subjectIriForRow(descriptor, context.document, key);
700
+ const beforeHash = original && Object.keys(original).length > 0 ? hashOf(original) : undefined;
701
+ pending.register({
702
+ key,
703
+ intent: modified,
704
+ localRow: modified,
705
+ beforeHash
706
+ });
707
+ await runWrite(key, async () => {
708
+ const columnChanges = {};
709
+ for (const [field, value] of Object.entries(changes)) {
710
+ if (uriArrayFieldNames.has(field))
711
+ continue;
712
+ const column = columnOf(field);
713
+ if (column === undefined)
714
+ continue;
715
+ columnChanges[column] = value;
716
+ }
717
+ if (Object.keys(columnChanges).length > 0) {
718
+ const updated = await context.database.updateById(table, resourceId, columnChanges);
719
+ if (!updated) {
720
+ throw new PodCollectionError("write_rejected", `drizzle-solid did not update ${resourceId}`);
721
+ }
722
+ }
723
+ await writeUriArrayFields(context, changes, subjectIri, original, modified);
724
+ });
725
+ }
726
+ },
727
+ onDelete: async ({ transaction }) => {
728
+ for (const mutation of transaction.mutations) {
729
+ const key = String(mutation.key);
730
+ const original = mutation.original;
731
+ const resourceId = resourceIdForRow(descriptor, context.document, context.podUrl, key);
732
+ pending.register({
733
+ key,
734
+ intent: undefined,
735
+ localRow: original,
736
+ beforeHash: original && Object.keys(original).length > 0 ? hashOf(original) : undefined
737
+ });
738
+ await runWrite(key, async () => {
739
+ await context.database.deleteById(table, resourceId);
740
+ });
741
+ }
742
+ }
743
+ };
744
+ }
745
+ async function writeUriArrayFields(context, changed, subjectIri, previousRow, nextRow) {
746
+ for (const [field, fieldDescriptor] of Object.entries(context.descriptor.fields)) {
747
+ if (!isUriArrayField(fieldDescriptor))
748
+ continue;
749
+ if (!(field in changed))
750
+ continue;
751
+ await writeField(context, field, {
752
+ subjectIri,
753
+ previous: previousRow?.[field],
754
+ next: nextRow?.[field]
755
+ });
756
+ }
757
+ }
758
+
759
+ // src/feed.ts
760
+ var NOOP_SUBSCRIPTION = {
761
+ available: false,
762
+ unsubscribe: () => {}
763
+ };
764
+ function subscribeDocumentFeed(feed, topicUrl, listener) {
765
+ if (!feed || typeof feed.watch !== "function")
766
+ return NOOP_SUBSCRIPTION;
767
+ try {
768
+ const unsubscribe = feed.watch(topicUrl, listener);
769
+ if (typeof unsubscribe !== "function")
770
+ return NOOP_SUBSCRIPTION;
771
+ let active = true;
772
+ return {
773
+ available: true,
774
+ unsubscribe: () => {
775
+ if (!active)
776
+ return;
777
+ active = false;
778
+ unsubscribe();
779
+ }
780
+ };
781
+ } catch {
782
+ return NOOP_SUBSCRIPTION;
783
+ }
784
+ }
785
+
786
+ // src/sync.ts
787
+ var DEFAULT_COALESCE_MS = 75;
788
+ var DEFAULT_CONFIRM_RETRIES = 2;
789
+ function sleep(ms) {
790
+ return new Promise((resolve) => {
791
+ setTimeout(resolve, ms);
792
+ });
793
+ }
794
+ function createPodSync(options) {
795
+ const { descriptor, table, database, document, podUrl, pending } = options;
796
+ const coalesceMs = options.coalesceMs ?? DEFAULT_COALESCE_MS;
797
+ const confirmRetries = options.confirmRetries ?? DEFAULT_CONFIRM_RETRIES;
798
+ const fieldOrder = projectionFieldOrder(descriptor);
799
+ const writeOnly = writeOnlyFields(descriptor);
800
+ const hashOf = (row) => projectionHash(row, fieldOrder);
801
+ let params;
802
+ let subscription;
803
+ let feedAvailable = false;
804
+ let ready = false;
805
+ let failureReported = false;
806
+ let syncState = "initializing";
807
+ let timer;
808
+ let bufferedSignals = [];
809
+ let running;
810
+ let rerunRequested = false;
811
+ let disposed = false;
812
+ let lastEtag;
813
+ async function ensureParams() {
814
+ if (params)
815
+ return params;
816
+ const collection = options.collection();
817
+ if (!collection) {
818
+ throw new PodCollectionError("sync_not_started", "collection has not started syncing yet");
819
+ }
820
+ await collection.preload();
821
+ if (!params) {
822
+ throw new PodCollectionError("sync_not_started", "collection sync did not start");
823
+ }
824
+ return params;
825
+ }
826
+ function schedulePass() {
827
+ if (disposed || timer !== undefined)
828
+ return;
829
+ timer = setTimeout(() => {
830
+ timer = undefined;
831
+ runPass().catch(() => {
832
+ syncState = "degraded";
833
+ });
834
+ }, coalesceMs);
835
+ }
836
+ function runPass() {
837
+ if (running) {
838
+ rerunRequested = true;
839
+ return running;
840
+ }
841
+ const task = (async () => {
842
+ try {
843
+ do {
844
+ rerunRequested = false;
845
+ await passOnce();
846
+ } while (rerunRequested && !disposed);
847
+ } finally {
848
+ running = undefined;
849
+ }
850
+ })();
851
+ running = task;
852
+ return task;
853
+ }
854
+ async function passOnce() {
855
+ const sync2 = await ensureParams();
856
+ if (disposed)
857
+ return;
858
+ let read;
859
+ try {
860
+ read = await conditionalDocumentRead({ descriptor, table, database, document, podUrl }, { ifNoneMatch: lastEtag });
861
+ } catch (error) {
862
+ syncState = "degraded";
863
+ if (!ready && !failureReported) {
864
+ failureReported = true;
865
+ sync2.markError(error);
866
+ }
867
+ return;
868
+ }
869
+ if (read.etag !== undefined)
870
+ lastEtag = read.etag;
871
+ const rows = mapSubjectRows(descriptor, table, read.subjects);
872
+ const next = new Map(rows.map((row) => [String(row.id), row]));
873
+ const presentKeys = [...sync2.collection.keys()].map((key) => String(key));
874
+ const knownHash = (key) => {
875
+ const entry = sync2.metadata?.row.get(key);
876
+ return entry?.hash;
877
+ };
878
+ const diff = computeDocumentDiff({
879
+ next,
880
+ presentKeys,
881
+ pendingKeys: pending.keys,
882
+ knownHash,
883
+ hashOf,
884
+ presentRow: (key) => sync2.collection.get(key)
885
+ });
886
+ if (diff.inserts.length + diff.updates.length + diff.deletes.length > 0) {
887
+ sync2.begin({ immediate: true });
888
+ for (const entry of diff.inserts) {
889
+ sync2.write({ type: "insert", value: stripVirtualProps(entry.row) });
890
+ }
891
+ for (const entry of diff.updates) {
892
+ sync2.write({ type: "update", value: stripVirtualProps(entry.row) });
893
+ }
894
+ for (const entry of diff.deletes) {
895
+ sync2.write({
896
+ type: "delete",
897
+ key: entry.key,
898
+ value: stripVirtualProps(entry.row)
899
+ });
900
+ }
901
+ for (const entry of [...diff.inserts, ...diff.updates]) {
902
+ sync2.metadata?.row.set(entry.key, { hash: hashOf(entry.row) });
903
+ }
904
+ await sync2.commit();
905
+ }
906
+ if (!ready) {
907
+ ready = true;
908
+ failureReported = false;
909
+ sync2.markReady();
910
+ }
911
+ reconcilePendingWrites(pending, next, hashOf, writeOnly);
912
+ syncState = feedAvailable ? "live" : "unavailable";
913
+ }
914
+ async function confirmPending(key) {
915
+ const entry = pending.entries.get(key);
916
+ if (!entry)
917
+ return;
918
+ for (let attempt = 0;; attempt += 1) {
919
+ await runPass();
920
+ if (entry.settled) {
921
+ if (entry.error)
922
+ throw entry.error;
923
+ return;
924
+ }
925
+ if (attempt >= confirmRetries) {
926
+ throw new PodCollectionError("write_unconfirmed", `write to ${key} was not visible in the document after ${confirmRetries + 1} reads`);
927
+ }
928
+ await sleep(coalesceMs);
929
+ }
930
+ }
931
+ const sync = (syncParams) => {
932
+ if (disposed)
933
+ return () => {};
934
+ params = syncParams;
935
+ subscription = subscribeDocumentFeed(options.feed, document, () => {
936
+ if (!ready) {
937
+ bufferedSignals.push({ topic: document });
938
+ return;
939
+ }
940
+ schedulePass();
941
+ });
942
+ feedAvailable = subscription.available;
943
+ runPass().then(() => {
944
+ if (disposed)
945
+ return;
946
+ const replay = bufferedSignals;
947
+ bufferedSignals = [];
948
+ if (replay.length > 0)
949
+ schedulePass();
950
+ }).catch(() => {
951
+ syncState = "degraded";
952
+ });
953
+ return () => {
954
+ dispose();
955
+ };
956
+ };
957
+ function dispose() {
958
+ if (disposed)
959
+ return;
960
+ disposed = true;
961
+ if (timer !== undefined) {
962
+ clearTimeout(timer);
963
+ timer = undefined;
964
+ }
965
+ subscription?.unsubscribe();
966
+ subscription = undefined;
967
+ bufferedSignals = [];
968
+ }
969
+ return {
970
+ sync,
971
+ refresh: () => runPass(),
972
+ confirmPending,
973
+ state: () => syncState,
974
+ dispose,
975
+ truncate: () => {
976
+ if (!params || disposed)
977
+ return;
978
+ params.begin({ immediate: true });
979
+ params.truncate();
980
+ Promise.resolve(params.commit()).catch(() => {});
981
+ }
982
+ };
983
+ }
984
+
985
+ // src/index.ts
986
+ function definePodCollection(descriptor, options) {
987
+ assertDescriptorTableAlignment(descriptor, options.table);
988
+ const document = resolveTableDocument(descriptor, {
989
+ podUrl: options.podUrl,
990
+ document: options.document,
991
+ scope: options.scope
992
+ });
993
+ const pending = createPendingWrites(options.onConflict);
994
+ let collection;
995
+ const engine = createPodSync({
996
+ descriptor,
997
+ table: options.table,
998
+ database: options.database,
999
+ podUrl: options.podUrl,
1000
+ document,
1001
+ feed: options.feed,
1002
+ coalesceMs: options.coalesceMs,
1003
+ confirmRetries: options.confirmRetries,
1004
+ pending,
1005
+ collection: () => collection
1006
+ });
1007
+ const handlers = createMutationHandlers({
1008
+ descriptor,
1009
+ table: options.table,
1010
+ database: options.database,
1011
+ podUrl: options.podUrl,
1012
+ document,
1013
+ pending,
1014
+ confirm: (key) => engine.confirmPending(key)
1015
+ });
1016
+ const created = import_db.createCollection({
1017
+ id: `pod-collection:${descriptor.uri}:${document}`,
1018
+ getKey: (row) => row.id,
1019
+ sync: { sync: engine.sync, rowUpdateMode: "full" },
1020
+ startSync: true,
1021
+ onInsert: handlers.onInsert,
1022
+ onUpdate: handlers.onUpdate,
1023
+ onDelete: handlers.onDelete
1024
+ });
1025
+ collection = created;
1026
+ return Object.assign(created, {
1027
+ tableDocument: document,
1028
+ pendingKeys: pending.keys,
1029
+ conflicts: pending.conflicts,
1030
+ refresh: () => engine.refresh(),
1031
+ syncState: () => engine.state(),
1032
+ dispose: () => engine.dispose(),
1033
+ truncateForTest: () => engine.truncate()
1034
+ });
1035
+ }
1036
+ function podCollectionInternals(collection) {
1037
+ const internals = collection;
1038
+ if (typeof internals.syncState !== "function" || typeof internals.dispose !== "function") {
1039
+ throw new PodCollectionError("collection_not_from_define", "collection was not created by definePodCollection()");
1040
+ }
1041
+ return internals;
1042
+ }