@osdk/client 2.2.0-beta.2 → 2.2.0-beta.21

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 (483) hide show
  1. package/CHANGELOG.md +282 -0
  2. package/build/browser/Client.js.map +1 -1
  3. package/build/browser/MinimalClientContext.js.map +1 -1
  4. package/build/browser/__unstable/ConjureSupport.js.map +1 -1
  5. package/build/browser/actions/ActionValidationError.js +1 -1
  6. package/build/browser/actions/ActionValidationError.js.map +1 -1
  7. package/build/browser/actions/actions.test.js +226 -87
  8. package/build/browser/actions/actions.test.js.map +1 -1
  9. package/build/browser/actions/applyAction.js +28 -16
  10. package/build/browser/actions/applyAction.js.map +1 -1
  11. package/build/browser/createClient.js +19 -8
  12. package/build/browser/createClient.js.map +1 -1
  13. package/build/browser/createClient.test.js +14 -6
  14. package/build/browser/createClient.test.js.map +1 -1
  15. package/build/browser/createMinimalClient.js +2 -2
  16. package/build/browser/createMinimalClient.js.map +1 -1
  17. package/build/browser/createMinimalClientHelper.js +25 -0
  18. package/build/browser/createMinimalClientHelper.js.map +1 -0
  19. package/build/browser/derivedProperties/createWithPropertiesObjectSet.js +36 -13
  20. package/build/browser/derivedProperties/createWithPropertiesObjectSet.js.map +1 -1
  21. package/build/browser/derivedProperties/createWithPropertiesObjectSet.test.js +133 -0
  22. package/build/browser/derivedProperties/createWithPropertiesObjectSet.test.js.map +1 -1
  23. package/build/browser/derivedProperties/derivedPropertyDefinitionFactory.js +94 -0
  24. package/build/browser/derivedProperties/derivedPropertyDefinitionFactory.js.map +1 -0
  25. package/build/browser/fetchMetadata.test.js +11 -9
  26. package/build/browser/fetchMetadata.test.js.map +1 -1
  27. package/build/browser/index.js +1 -0
  28. package/build/browser/index.js.map +1 -1
  29. package/build/browser/intellisense.test.helpers/showsObjectPropertyJsdoc.js +25 -0
  30. package/build/browser/intellisense.test.helpers/showsObjectPropertyJsdoc.js.map +1 -0
  31. package/build/browser/intellisense.test.js +17 -1
  32. package/build/browser/intellisense.test.js.map +1 -1
  33. package/build/browser/internal/conversions/modernToLegacyGroupByClause.js +7 -0
  34. package/build/browser/internal/conversions/modernToLegacyGroupByClause.js.map +1 -1
  35. package/build/browser/internal/conversions/modernToLegacyWhereClause.js +1 -1
  36. package/build/browser/internal/conversions/modernToLegacyWhereClause.js.map +1 -1
  37. package/build/browser/logger/BaseLogger.js +59 -0
  38. package/build/browser/logger/BaseLogger.js.map +1 -0
  39. package/build/browser/logger/BrowserLogger.js +67 -0
  40. package/build/browser/logger/BrowserLogger.js.map +1 -0
  41. package/build/browser/logger/MinimalLogger.js +39 -0
  42. package/build/browser/logger/MinimalLogger.js.map +1 -0
  43. package/build/browser/logger/MinimalLogger.test.js +60 -0
  44. package/build/browser/logger/MinimalLogger.test.js.map +1 -0
  45. package/build/browser/logger/TestLogger.js +56 -0
  46. package/build/browser/logger/TestLogger.js.map +1 -0
  47. package/build/browser/object/AttachmentUpload.js +3 -0
  48. package/build/browser/object/AttachmentUpload.js.map +1 -1
  49. package/build/browser/object/SimpleOsdkProperties.js +2 -0
  50. package/build/browser/object/SimpleOsdkProperties.js.map +1 -0
  51. package/build/browser/object/aggregate.test.js +12 -2
  52. package/build/browser/object/aggregate.test.js.map +1 -1
  53. package/build/browser/object/attachment.test.js +20 -7
  54. package/build/browser/object/attachment.test.js.map +1 -1
  55. package/build/browser/object/convertWireToOsdkObjects/BaseHolder.js +2 -0
  56. package/build/browser/object/convertWireToOsdkObjects/BaseHolder.js.map +1 -0
  57. package/build/browser/object/convertWireToOsdkObjects/InterfaceHolder.js.map +1 -1
  58. package/build/browser/object/convertWireToOsdkObjects/ObjectHolder.js.map +1 -1
  59. package/build/browser/object/convertWireToOsdkObjects/createOsdkInterface.js +29 -0
  60. package/build/browser/object/convertWireToOsdkObjects/createOsdkInterface.js.map +1 -1
  61. package/build/browser/object/convertWireToOsdkObjects/createOsdkObject.js +53 -35
  62. package/build/browser/object/convertWireToOsdkObjects/createOsdkObject.js.map +1 -1
  63. package/build/browser/object/convertWireToOsdkObjects/getDollarAs.js.map +1 -1
  64. package/build/browser/object/convertWireToOsdkObjects/getDollarLink.js.map +1 -1
  65. package/build/browser/object/convertWireToOsdkObjects.js +10 -11
  66. package/build/browser/object/convertWireToOsdkObjects.js.map +1 -1
  67. package/build/browser/object/convertWireToOsdkObjects.test.js +46 -36
  68. package/build/browser/object/convertWireToOsdkObjects.test.js.map +1 -1
  69. package/build/browser/object/fetchPage.js +17 -4
  70. package/build/browser/object/fetchPage.js.map +1 -1
  71. package/build/browser/object/fetchPage.test.js +56 -2
  72. package/build/browser/object/fetchPage.test.js.map +1 -1
  73. package/build/browser/object/geotimeseriesreference.test.js +56 -134
  74. package/build/browser/object/geotimeseriesreference.test.js.map +1 -1
  75. package/build/browser/object/media.test.js +19 -14
  76. package/build/browser/object/media.test.js.map +1 -1
  77. package/build/browser/object/object.test.js +182 -66
  78. package/build/browser/object/object.test.js.map +1 -1
  79. package/build/browser/object/timeseries.test.js +119 -85
  80. package/build/browser/object/timeseries.test.js.map +1 -1
  81. package/build/browser/objectSet/InterfaceObjectSet.test.js +37 -17
  82. package/build/browser/objectSet/InterfaceObjectSet.test.js.map +1 -1
  83. package/build/browser/objectSet/ObjectSet.test.js +212 -114
  84. package/build/browser/objectSet/ObjectSet.test.js.map +1 -1
  85. package/build/browser/objectSet/ObjectSetListenerWebsocket.js +20 -16
  86. package/build/browser/objectSet/ObjectSetListenerWebsocket.js.map +1 -1
  87. package/build/browser/objectSet/ObjectSetListenerWebsocket.test.js +21 -12
  88. package/build/browser/objectSet/ObjectSetListenerWebsocket.test.js.map +1 -1
  89. package/build/browser/objectSet/createObjectSet.js +2 -1
  90. package/build/browser/objectSet/createObjectSet.js.map +1 -1
  91. package/build/browser/observable/ListPayload.js.map +1 -1
  92. package/build/browser/observable/ObjectPayload.js.map +1 -1
  93. package/build/browser/observable/ObservableClient.js.map +1 -1
  94. package/build/browser/observable/OptimisticBuilder.js.map +1 -1
  95. package/build/browser/observable/internal/ActionApplication.js +102 -0
  96. package/build/browser/observable/internal/ActionApplication.js.map +1 -0
  97. package/build/browser/observable/internal/BulkObjectLoader.js +93 -0
  98. package/build/browser/observable/internal/BulkObjectLoader.js.map +1 -0
  99. package/build/browser/observable/internal/BulkObjectLoader.test.js +112 -0
  100. package/build/browser/observable/internal/BulkObjectLoader.test.js.map +1 -0
  101. package/build/browser/observable/internal/CacheKey.js +38 -1
  102. package/build/browser/observable/internal/CacheKey.js.map +1 -1
  103. package/build/browser/observable/internal/CacheKeys.js +4 -4
  104. package/build/browser/observable/internal/CacheKeys.js.map +1 -1
  105. package/build/browser/observable/internal/Changes.js +58 -0
  106. package/build/browser/observable/internal/Changes.js.map +1 -0
  107. package/build/browser/observable/internal/Layer.js +6 -3
  108. package/build/browser/observable/internal/Layer.js.map +1 -1
  109. package/build/browser/observable/internal/ListQuery.js +495 -129
  110. package/build/browser/observable/internal/ListQuery.js.map +1 -1
  111. package/build/browser/observable/internal/ObjectQuery.js +40 -14
  112. package/build/browser/observable/internal/ObjectQuery.js.map +1 -1
  113. package/build/browser/observable/internal/ObservableClientImpl.js +4 -12
  114. package/build/browser/observable/internal/ObservableClientImpl.js.map +1 -1
  115. package/build/browser/observable/internal/OptimisticJob.js +30 -29
  116. package/build/browser/observable/internal/OptimisticJob.js.map +1 -1
  117. package/build/browser/observable/internal/OrderByCanonicalizer.js +73 -0
  118. package/build/browser/observable/internal/OrderByCanonicalizer.js.map +1 -0
  119. package/build/browser/observable/internal/OrderByCanonicalizer.test.js +78 -0
  120. package/build/browser/observable/internal/OrderByCanonicalizer.test.js.map +1 -0
  121. package/build/browser/observable/internal/Query.js +79 -6
  122. package/build/browser/observable/internal/Query.js.map +1 -1
  123. package/build/browser/observable/internal/RefCounts.js +7 -2
  124. package/build/browser/observable/internal/RefCounts.js.map +1 -1
  125. package/build/browser/observable/internal/SimpleWhereClause.js +2 -0
  126. package/build/browser/observable/internal/SimpleWhereClause.js.map +1 -0
  127. package/build/browser/observable/internal/Store.js +140 -190
  128. package/build/browser/observable/internal/Store.js.map +1 -1
  129. package/build/browser/observable/internal/Store.test.js +666 -300
  130. package/build/browser/observable/internal/Store.test.js.map +1 -1
  131. package/build/browser/observable/internal/WhereClauseCanonicalizer.js +11 -3
  132. package/build/browser/observable/internal/WhereClauseCanonicalizer.js.map +1 -1
  133. package/build/browser/observable/internal/objectMatchesWhereClause.js +0 -4
  134. package/build/browser/observable/internal/objectMatchesWhereClause.js.map +1 -1
  135. package/build/browser/observable/internal/objectMatchesWhereClause.test.js.map +1 -1
  136. package/build/browser/observable/internal/testUtils.js +222 -19
  137. package/build/browser/observable/internal/testUtils.js.map +1 -1
  138. package/build/browser/ontology/StandardOntologyProvider.test.js +17 -16
  139. package/build/browser/ontology/StandardOntologyProvider.test.js.map +1 -1
  140. package/build/browser/ontology/loadFullObjectMetadata.js +0 -1
  141. package/build/browser/ontology/loadFullObjectMetadata.js.map +1 -1
  142. package/build/browser/public/internal.js +2 -0
  143. package/build/browser/public/internal.js.map +1 -1
  144. package/build/browser/public/unstable-do-not-use.js +1 -0
  145. package/build/browser/public/unstable-do-not-use.js.map +1 -1
  146. package/build/browser/public-utils/osdkConfig.js +49 -0
  147. package/build/browser/public-utils/osdkConfig.js.map +1 -0
  148. package/build/{esm/observable/internal/ChangedObjects.js → browser/public-utils/vite-env.d.ts} +2 -7
  149. package/build/browser/queries/applyQuery.js +34 -2
  150. package/build/browser/queries/applyQuery.js.map +1 -1
  151. package/build/browser/queries/queries.test.js +36 -13
  152. package/build/browser/queries/queries.test.js.map +1 -1
  153. package/build/browser/queries/types.js.map +1 -1
  154. package/build/browser/tsserver.js.map +1 -1
  155. package/build/browser/util/UserAgent.js +1 -1
  156. package/build/browser/util/UserAgent.js.map +1 -1
  157. package/build/browser/util/extractRdpDefinition.js +140 -0
  158. package/build/browser/util/extractRdpDefinition.js.map +1 -0
  159. package/build/browser/util/extractRdpDefinition.test.js +233 -0
  160. package/build/browser/util/extractRdpDefinition.test.js.map +1 -0
  161. package/build/browser/{observable/internal/ChangedObjects.js → util/isPoint.js} +3 -7
  162. package/build/browser/util/isPoint.js.map +1 -0
  163. package/build/browser/util/objectSpecifierUtils.js +48 -0
  164. package/build/browser/util/objectSpecifierUtils.js.map +1 -0
  165. package/build/browser/util/objectSpecifierUtils.test.js +42 -0
  166. package/build/browser/util/objectSpecifierUtils.test.js.map +1 -0
  167. package/build/browser/util/toDataValue.js +14 -2
  168. package/build/browser/util/toDataValue.js.map +1 -1
  169. package/build/browser/util/toDataValue.test.js +37 -16
  170. package/build/browser/util/toDataValue.test.js.map +1 -1
  171. package/build/browser/util/toDataValueQueries.js +25 -2
  172. package/build/browser/util/toDataValueQueries.js.map +1 -1
  173. package/build/cjs/{Client-C8K3E1vH.d.cts → Client-CgL2LKN9.d.cts} +7 -8
  174. package/build/cjs/{chunk-T5UE6BI7.cjs → chunk-33GHS3X4.cjs} +256 -80
  175. package/build/cjs/chunk-33GHS3X4.cjs.map +1 -0
  176. package/build/cjs/{chunk-X7WGNFZ4.cjs → chunk-37QC7LR3.cjs} +173 -34
  177. package/build/cjs/chunk-37QC7LR3.cjs.map +1 -0
  178. package/build/cjs/chunk-T4NIFYZS.cjs +14 -0
  179. package/build/cjs/chunk-T4NIFYZS.cjs.map +1 -0
  180. package/build/cjs/index.cjs +298 -177
  181. package/build/cjs/index.cjs.map +1 -1
  182. package/build/cjs/index.d.cts +14 -22
  183. package/build/cjs/public/internal.cjs +61 -7
  184. package/build/cjs/public/internal.cjs.map +1 -1
  185. package/build/cjs/public/internal.d.cts +50 -3
  186. package/build/cjs/public/unstable-do-not-use.cjs +1181 -527
  187. package/build/cjs/public/unstable-do-not-use.cjs.map +1 -1
  188. package/build/cjs/public/unstable-do-not-use.d.cts +44 -25
  189. package/build/esm/Client.js.map +1 -1
  190. package/build/esm/MinimalClientContext.js.map +1 -1
  191. package/build/esm/__unstable/ConjureSupport.js.map +1 -1
  192. package/build/esm/actions/ActionValidationError.js +1 -1
  193. package/build/esm/actions/ActionValidationError.js.map +1 -1
  194. package/build/esm/actions/actions.test.js +226 -87
  195. package/build/esm/actions/actions.test.js.map +1 -1
  196. package/build/esm/actions/applyAction.js +28 -16
  197. package/build/esm/actions/applyAction.js.map +1 -1
  198. package/build/esm/createClient.js +19 -8
  199. package/build/esm/createClient.js.map +1 -1
  200. package/build/esm/createClient.test.js +14 -6
  201. package/build/esm/createClient.test.js.map +1 -1
  202. package/build/esm/createMinimalClient.js +2 -2
  203. package/build/esm/createMinimalClient.js.map +1 -1
  204. package/build/esm/createMinimalClientHelper.js +25 -0
  205. package/build/esm/createMinimalClientHelper.js.map +1 -0
  206. package/build/esm/derivedProperties/createWithPropertiesObjectSet.js +36 -13
  207. package/build/esm/derivedProperties/createWithPropertiesObjectSet.js.map +1 -1
  208. package/build/esm/derivedProperties/createWithPropertiesObjectSet.test.js +133 -0
  209. package/build/esm/derivedProperties/createWithPropertiesObjectSet.test.js.map +1 -1
  210. package/build/esm/derivedProperties/derivedPropertyDefinitionFactory.js +94 -0
  211. package/build/esm/derivedProperties/derivedPropertyDefinitionFactory.js.map +1 -0
  212. package/build/esm/fetchMetadata.test.js +11 -9
  213. package/build/esm/fetchMetadata.test.js.map +1 -1
  214. package/build/esm/index.js +1 -0
  215. package/build/esm/index.js.map +1 -1
  216. package/build/esm/intellisense.test.helpers/showsObjectPropertyJsdoc.js +25 -0
  217. package/build/esm/intellisense.test.helpers/showsObjectPropertyJsdoc.js.map +1 -0
  218. package/build/esm/intellisense.test.js +17 -1
  219. package/build/esm/intellisense.test.js.map +1 -1
  220. package/build/esm/internal/conversions/modernToLegacyGroupByClause.js +7 -0
  221. package/build/esm/internal/conversions/modernToLegacyGroupByClause.js.map +1 -1
  222. package/build/esm/internal/conversions/modernToLegacyWhereClause.js +1 -1
  223. package/build/esm/internal/conversions/modernToLegacyWhereClause.js.map +1 -1
  224. package/build/esm/logger/BaseLogger.js +59 -0
  225. package/build/esm/logger/BaseLogger.js.map +1 -0
  226. package/build/esm/logger/BrowserLogger.js +67 -0
  227. package/build/esm/logger/BrowserLogger.js.map +1 -0
  228. package/build/esm/logger/MinimalLogger.js +39 -0
  229. package/build/esm/logger/MinimalLogger.js.map +1 -0
  230. package/build/esm/logger/MinimalLogger.test.js +60 -0
  231. package/build/esm/logger/MinimalLogger.test.js.map +1 -0
  232. package/build/esm/logger/TestLogger.js +56 -0
  233. package/build/esm/logger/TestLogger.js.map +1 -0
  234. package/build/esm/object/AttachmentUpload.js +3 -0
  235. package/build/esm/object/AttachmentUpload.js.map +1 -1
  236. package/build/esm/object/SimpleOsdkProperties.js +2 -0
  237. package/build/esm/object/SimpleOsdkProperties.js.map +1 -0
  238. package/build/esm/object/aggregate.test.js +12 -2
  239. package/build/esm/object/aggregate.test.js.map +1 -1
  240. package/build/esm/object/attachment.test.js +20 -7
  241. package/build/esm/object/attachment.test.js.map +1 -1
  242. package/build/esm/object/convertWireToOsdkObjects/BaseHolder.js +2 -0
  243. package/build/esm/object/convertWireToOsdkObjects/BaseHolder.js.map +1 -0
  244. package/build/esm/object/convertWireToOsdkObjects/InterfaceHolder.js.map +1 -1
  245. package/build/esm/object/convertWireToOsdkObjects/ObjectHolder.js.map +1 -1
  246. package/build/esm/object/convertWireToOsdkObjects/createOsdkInterface.js +29 -0
  247. package/build/esm/object/convertWireToOsdkObjects/createOsdkInterface.js.map +1 -1
  248. package/build/esm/object/convertWireToOsdkObjects/createOsdkObject.js +53 -35
  249. package/build/esm/object/convertWireToOsdkObjects/createOsdkObject.js.map +1 -1
  250. package/build/esm/object/convertWireToOsdkObjects/getDollarAs.js.map +1 -1
  251. package/build/esm/object/convertWireToOsdkObjects/getDollarLink.js.map +1 -1
  252. package/build/esm/object/convertWireToOsdkObjects.js +10 -11
  253. package/build/esm/object/convertWireToOsdkObjects.js.map +1 -1
  254. package/build/esm/object/convertWireToOsdkObjects.test.js +46 -36
  255. package/build/esm/object/convertWireToOsdkObjects.test.js.map +1 -1
  256. package/build/esm/object/fetchPage.js +17 -4
  257. package/build/esm/object/fetchPage.js.map +1 -1
  258. package/build/esm/object/fetchPage.test.js +56 -2
  259. package/build/esm/object/fetchPage.test.js.map +1 -1
  260. package/build/esm/object/geotimeseriesreference.test.js +56 -134
  261. package/build/esm/object/geotimeseriesreference.test.js.map +1 -1
  262. package/build/esm/object/media.test.js +19 -14
  263. package/build/esm/object/media.test.js.map +1 -1
  264. package/build/esm/object/object.test.js +182 -66
  265. package/build/esm/object/object.test.js.map +1 -1
  266. package/build/esm/object/timeseries.test.js +119 -85
  267. package/build/esm/object/timeseries.test.js.map +1 -1
  268. package/build/esm/objectSet/InterfaceObjectSet.test.js +37 -17
  269. package/build/esm/objectSet/InterfaceObjectSet.test.js.map +1 -1
  270. package/build/esm/objectSet/ObjectSet.test.js +212 -114
  271. package/build/esm/objectSet/ObjectSet.test.js.map +1 -1
  272. package/build/esm/objectSet/ObjectSetListenerWebsocket.js +20 -16
  273. package/build/esm/objectSet/ObjectSetListenerWebsocket.js.map +1 -1
  274. package/build/esm/objectSet/ObjectSetListenerWebsocket.test.js +21 -12
  275. package/build/esm/objectSet/ObjectSetListenerWebsocket.test.js.map +1 -1
  276. package/build/esm/objectSet/createObjectSet.js +2 -1
  277. package/build/esm/objectSet/createObjectSet.js.map +1 -1
  278. package/build/esm/observable/ListPayload.js.map +1 -1
  279. package/build/esm/observable/ObjectPayload.js.map +1 -1
  280. package/build/esm/observable/ObservableClient.js.map +1 -1
  281. package/build/esm/observable/OptimisticBuilder.js.map +1 -1
  282. package/build/esm/observable/internal/ActionApplication.js +102 -0
  283. package/build/esm/observable/internal/ActionApplication.js.map +1 -0
  284. package/build/esm/observable/internal/BulkObjectLoader.js +93 -0
  285. package/build/esm/observable/internal/BulkObjectLoader.js.map +1 -0
  286. package/build/esm/observable/internal/BulkObjectLoader.test.js +112 -0
  287. package/build/esm/observable/internal/BulkObjectLoader.test.js.map +1 -0
  288. package/build/esm/observable/internal/CacheKey.js +38 -1
  289. package/build/esm/observable/internal/CacheKey.js.map +1 -1
  290. package/build/esm/observable/internal/CacheKeys.js +4 -4
  291. package/build/esm/observable/internal/CacheKeys.js.map +1 -1
  292. package/build/esm/observable/internal/Changes.js +58 -0
  293. package/build/esm/observable/internal/Changes.js.map +1 -0
  294. package/build/esm/observable/internal/Layer.js +6 -3
  295. package/build/esm/observable/internal/Layer.js.map +1 -1
  296. package/build/esm/observable/internal/ListQuery.js +495 -129
  297. package/build/esm/observable/internal/ListQuery.js.map +1 -1
  298. package/build/esm/observable/internal/ObjectQuery.js +40 -14
  299. package/build/esm/observable/internal/ObjectQuery.js.map +1 -1
  300. package/build/esm/observable/internal/ObservableClientImpl.js +4 -12
  301. package/build/esm/observable/internal/ObservableClientImpl.js.map +1 -1
  302. package/build/esm/observable/internal/OptimisticJob.js +30 -29
  303. package/build/esm/observable/internal/OptimisticJob.js.map +1 -1
  304. package/build/esm/observable/internal/OrderByCanonicalizer.js +73 -0
  305. package/build/esm/observable/internal/OrderByCanonicalizer.js.map +1 -0
  306. package/build/esm/observable/internal/OrderByCanonicalizer.test.js +78 -0
  307. package/build/esm/observable/internal/OrderByCanonicalizer.test.js.map +1 -0
  308. package/build/esm/observable/internal/Query.js +79 -6
  309. package/build/esm/observable/internal/Query.js.map +1 -1
  310. package/build/esm/observable/internal/RefCounts.js +7 -2
  311. package/build/esm/observable/internal/RefCounts.js.map +1 -1
  312. package/build/esm/observable/internal/SimpleWhereClause.js +2 -0
  313. package/build/esm/observable/internal/SimpleWhereClause.js.map +1 -0
  314. package/build/esm/observable/internal/Store.js +140 -190
  315. package/build/esm/observable/internal/Store.js.map +1 -1
  316. package/build/esm/observable/internal/Store.test.js +666 -300
  317. package/build/esm/observable/internal/Store.test.js.map +1 -1
  318. package/build/esm/observable/internal/WhereClauseCanonicalizer.js +11 -3
  319. package/build/esm/observable/internal/WhereClauseCanonicalizer.js.map +1 -1
  320. package/build/esm/observable/internal/objectMatchesWhereClause.js +0 -4
  321. package/build/esm/observable/internal/objectMatchesWhereClause.js.map +1 -1
  322. package/build/esm/observable/internal/objectMatchesWhereClause.test.js.map +1 -1
  323. package/build/esm/observable/internal/testUtils.js +222 -19
  324. package/build/esm/observable/internal/testUtils.js.map +1 -1
  325. package/build/esm/ontology/StandardOntologyProvider.test.js +17 -16
  326. package/build/esm/ontology/StandardOntologyProvider.test.js.map +1 -1
  327. package/build/esm/ontology/loadFullObjectMetadata.js +0 -1
  328. package/build/esm/ontology/loadFullObjectMetadata.js.map +1 -1
  329. package/build/esm/public/internal.js +2 -0
  330. package/build/esm/public/internal.js.map +1 -1
  331. package/build/esm/public/unstable-do-not-use.js +1 -0
  332. package/build/esm/public/unstable-do-not-use.js.map +1 -1
  333. package/build/esm/public-utils/osdkConfig.js +49 -0
  334. package/build/esm/public-utils/osdkConfig.js.map +1 -0
  335. package/build/esm/public-utils/vite-env.d.ts +19 -0
  336. package/build/esm/queries/applyQuery.js +34 -2
  337. package/build/esm/queries/applyQuery.js.map +1 -1
  338. package/build/esm/queries/queries.test.js +36 -13
  339. package/build/esm/queries/queries.test.js.map +1 -1
  340. package/build/esm/queries/types.js.map +1 -1
  341. package/build/esm/tsserver.js.map +1 -1
  342. package/build/esm/util/UserAgent.js +1 -1
  343. package/build/esm/util/UserAgent.js.map +1 -1
  344. package/build/esm/util/extractRdpDefinition.js +140 -0
  345. package/build/esm/util/extractRdpDefinition.js.map +1 -0
  346. package/build/esm/util/extractRdpDefinition.test.js +233 -0
  347. package/build/esm/util/extractRdpDefinition.test.js.map +1 -0
  348. package/build/esm/util/isPoint.js +20 -0
  349. package/build/esm/util/isPoint.js.map +1 -0
  350. package/build/esm/util/objectSpecifierUtils.js +48 -0
  351. package/build/esm/util/objectSpecifierUtils.js.map +1 -0
  352. package/build/esm/util/objectSpecifierUtils.test.js +42 -0
  353. package/build/esm/util/objectSpecifierUtils.test.js.map +1 -0
  354. package/build/esm/util/toDataValue.js +14 -2
  355. package/build/esm/util/toDataValue.js.map +1 -1
  356. package/build/esm/util/toDataValue.test.js +37 -16
  357. package/build/esm/util/toDataValue.test.js.map +1 -1
  358. package/build/esm/util/toDataValueQueries.js +25 -2
  359. package/build/esm/util/toDataValueQueries.js.map +1 -1
  360. package/build/types/Client.d.ts +1 -1
  361. package/build/types/Client.d.ts.map +1 -1
  362. package/build/types/MinimalClientContext.d.ts +1 -1
  363. package/build/types/MinimalClientContext.d.ts.map +1 -1
  364. package/build/types/__unstable/ConjureSupport.d.ts +2 -2
  365. package/build/types/actions/applyAction.d.ts +1 -2
  366. package/build/types/actions/applyAction.d.ts.map +1 -1
  367. package/build/types/createClient.d.ts +1 -1
  368. package/build/types/createClient.d.ts.map +1 -1
  369. package/build/types/createClient.test.d.ts +2 -1
  370. package/build/types/createClient.test.d.ts.map +1 -1
  371. package/build/types/createMinimalClientHelper.d.ts +1 -0
  372. package/build/types/createMinimalClientHelper.d.ts.map +1 -0
  373. package/build/types/derivedProperties/derivedPropertyDefinitionFactory.d.ts +1 -0
  374. package/build/types/derivedProperties/derivedPropertyDefinitionFactory.d.ts.map +1 -0
  375. package/build/types/index.d.ts +5 -5
  376. package/build/types/index.d.ts.map +1 -1
  377. package/build/types/intellisense.test.helpers/showsObjectPropertyJsdoc.d.ts +1 -0
  378. package/build/types/intellisense.test.helpers/showsObjectPropertyJsdoc.d.ts.map +1 -0
  379. package/build/types/logger/BaseLogger.d.ts +33 -0
  380. package/build/types/logger/BaseLogger.d.ts.map +1 -0
  381. package/build/types/logger/BrowserLogger.d.ts +9 -0
  382. package/build/types/logger/BrowserLogger.d.ts.map +1 -0
  383. package/build/types/logger/MinimalLogger.d.ts +9 -0
  384. package/build/types/logger/MinimalLogger.d.ts.map +1 -0
  385. package/build/types/logger/MinimalLogger.test.d.ts +1 -0
  386. package/build/types/logger/MinimalLogger.test.d.ts.map +1 -0
  387. package/build/types/logger/TestLogger.d.ts +14 -0
  388. package/build/types/logger/TestLogger.d.ts.map +1 -0
  389. package/build/types/object/AttachmentUpload.d.ts +3 -0
  390. package/build/types/object/AttachmentUpload.d.ts.map +1 -1
  391. package/build/types/object/SimpleOsdkProperties.d.ts +1 -0
  392. package/build/types/object/SimpleOsdkProperties.d.ts.map +1 -0
  393. package/build/types/object/convertWireToOsdkObjects/BaseHolder.d.ts +1 -0
  394. package/build/types/object/convertWireToOsdkObjects/BaseHolder.d.ts.map +1 -0
  395. package/build/types/object/convertWireToOsdkObjects.d.ts +8 -1
  396. package/build/types/object/convertWireToOsdkObjects.d.ts.map +1 -1
  397. package/build/types/object/fetchPage.d.ts.map +1 -1
  398. package/build/types/object/object.test.d.ts.map +1 -1
  399. package/build/types/objectSet/ObjectSet.test.d.ts.map +1 -1
  400. package/build/types/observable/ListPayload.d.ts +5 -9
  401. package/build/types/observable/ListPayload.d.ts.map +1 -1
  402. package/build/types/observable/ObjectPayload.d.ts +4 -7
  403. package/build/types/observable/ObjectPayload.d.ts.map +1 -1
  404. package/build/types/observable/ObservableClient.d.ts +33 -10
  405. package/build/types/observable/ObservableClient.d.ts.map +1 -1
  406. package/build/types/observable/OptimisticBuilder.d.ts +1 -1
  407. package/build/types/observable/OptimisticBuilder.d.ts.map +1 -1
  408. package/build/types/observable/internal/ActionApplication.d.ts +9 -0
  409. package/build/types/observable/internal/ActionApplication.d.ts.map +1 -0
  410. package/build/types/observable/internal/BulkObjectLoader.d.ts +8 -0
  411. package/build/types/observable/internal/BulkObjectLoader.d.ts.map +1 -0
  412. package/build/types/observable/internal/BulkObjectLoader.test.d.ts +1 -0
  413. package/build/types/observable/internal/BulkObjectLoader.test.d.ts.map +1 -0
  414. package/build/types/observable/internal/CacheKeys.d.ts +2 -1
  415. package/build/types/observable/internal/CacheKeys.d.ts.map +1 -1
  416. package/build/types/observable/internal/Changes.d.ts +15 -0
  417. package/build/types/observable/internal/Changes.d.ts.map +1 -0
  418. package/build/types/observable/internal/Layer.d.ts +2 -1
  419. package/build/types/observable/internal/Layer.d.ts.map +1 -1
  420. package/build/types/observable/internal/ListQuery.d.ts +69 -23
  421. package/build/types/observable/internal/ListQuery.d.ts.map +1 -1
  422. package/build/types/observable/internal/ObjectQuery.d.ts +8 -9
  423. package/build/types/observable/internal/ObjectQuery.d.ts.map +1 -1
  424. package/build/types/observable/internal/OptimisticJob.d.ts +2 -2
  425. package/build/types/observable/internal/OptimisticJob.d.ts.map +1 -1
  426. package/build/types/observable/internal/OrderByCanonicalizer.d.ts +12 -0
  427. package/build/types/observable/internal/OrderByCanonicalizer.d.ts.map +1 -0
  428. package/build/types/observable/internal/OrderByCanonicalizer.test.d.ts +1 -0
  429. package/build/types/observable/internal/OrderByCanonicalizer.test.d.ts.map +1 -0
  430. package/build/types/observable/internal/Query.d.ts +45 -9
  431. package/build/types/observable/internal/Query.d.ts.map +1 -1
  432. package/build/types/observable/internal/RefCounts.d.ts.map +1 -1
  433. package/build/types/observable/internal/SimpleWhereClause.d.ts +2 -0
  434. package/build/types/observable/internal/SimpleWhereClause.d.ts.map +1 -0
  435. package/build/types/observable/internal/Store.d.ts +34 -30
  436. package/build/types/observable/internal/Store.d.ts.map +1 -1
  437. package/build/types/observable/internal/WhereClauseCanonicalizer.d.ts +2 -1
  438. package/build/types/observable/internal/WhereClauseCanonicalizer.d.ts.map +1 -1
  439. package/build/types/observable/internal/objectMatchesWhereClause.d.ts +4 -2
  440. package/build/types/observable/internal/objectMatchesWhereClause.d.ts.map +1 -1
  441. package/build/types/observable/internal/testUtils.d.ts +48 -9
  442. package/build/types/observable/internal/testUtils.d.ts.map +1 -1
  443. package/build/types/public/internal.d.ts +2 -0
  444. package/build/types/public/internal.d.ts.map +1 -1
  445. package/build/types/public/unstable-do-not-use.d.ts +4 -5
  446. package/build/types/public/unstable-do-not-use.d.ts.map +1 -1
  447. package/build/types/public-utils/osdkConfig.d.ts +8 -0
  448. package/build/types/public-utils/osdkConfig.d.ts.map +1 -0
  449. package/build/types/public-utils/vite-env.d.d.ts +3 -0
  450. package/build/types/public-utils/vite-env.d.d.ts.map +1 -0
  451. package/build/types/queries/applyQuery.d.ts +4 -2
  452. package/build/types/queries/applyQuery.d.ts.map +1 -1
  453. package/build/types/queries/types.d.ts +1 -1
  454. package/build/types/queries/types.d.ts.map +1 -1
  455. package/build/types/tsserver.d.ts +1 -1
  456. package/build/types/tsserver.d.ts.map +1 -1
  457. package/build/types/util/extractRdpDefinition.d.ts +4 -0
  458. package/build/types/util/extractRdpDefinition.d.ts.map +1 -0
  459. package/build/types/util/extractRdpDefinition.test.d.ts +1 -0
  460. package/build/types/util/extractRdpDefinition.test.d.ts.map +1 -0
  461. package/build/types/util/isPoint.d.ts +1 -0
  462. package/build/types/util/isPoint.d.ts.map +1 -0
  463. package/build/types/util/objectSpecifierUtils.d.ts +24 -0
  464. package/build/types/util/objectSpecifierUtils.d.ts.map +1 -0
  465. package/build/types/util/objectSpecifierUtils.test.d.ts +1 -0
  466. package/build/types/util/objectSpecifierUtils.test.d.ts.map +1 -0
  467. package/package.json +20 -16
  468. package/build/browser/Logger.js +0 -2
  469. package/build/browser/Logger.js.map +0 -1
  470. package/build/browser/observable/internal/ChangedObjects.js.map +0 -1
  471. package/build/cjs/chunk-Q7SFCCGT.cjs +0 -11
  472. package/build/cjs/chunk-Q7SFCCGT.cjs.map +0 -1
  473. package/build/cjs/chunk-T5UE6BI7.cjs.map +0 -1
  474. package/build/cjs/chunk-X7WGNFZ4.cjs.map +0 -1
  475. package/build/cjs/graphql-JJX5MZPQ.cjs +0 -10491
  476. package/build/cjs/graphql-JJX5MZPQ.cjs.map +0 -1
  477. package/build/esm/Logger.js +0 -2
  478. package/build/esm/Logger.js.map +0 -1
  479. package/build/esm/observable/internal/ChangedObjects.js.map +0 -1
  480. package/build/types/Logger.d.ts +0 -18
  481. package/build/types/Logger.d.ts.map +0 -1
  482. package/build/types/observable/internal/ChangedObjects.d.ts +0 -7
  483. package/build/types/observable/internal/ChangedObjects.d.ts.map +0 -1
@@ -1,94 +1,299 @@
1
1
  'use strict';
2
2
 
3
- var chunkX7WGNFZ4_cjs = require('../chunk-X7WGNFZ4.cjs');
4
- require('../chunk-Q7SFCCGT.cjs');
3
+ var chunkT4NIFYZS_cjs = require('../chunk-T4NIFYZS.cjs');
4
+ var chunk37QC7LR3_cjs = require('../chunk-37QC7LR3.cjs');
5
5
  var rxjs = require('rxjs');
6
6
  var invariant2 = require('tiny-invariant');
7
- var trie = require('@wry/trie');
8
7
  var mnemonist = require('mnemonist');
8
+ var trie = require('@wry/trie');
9
9
  var deepEqual = require('fast-deep-equal');
10
+ var groupBy = require('object.groupby');
11
+ var shared_net_errors = require('@osdk/shared.net.errors');
10
12
 
11
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
14
 
13
15
  var invariant2__default = /*#__PURE__*/_interopDefault(invariant2);
14
16
  var deepEqual__default = /*#__PURE__*/_interopDefault(deepEqual);
17
+ var groupBy__default = /*#__PURE__*/_interopDefault(groupBy);
15
18
 
16
19
  // src/observable/internal/ObservableClientImpl.ts
17
20
  var ObservableClientImpl = class {
18
21
  #store;
19
22
  constructor(store) {
20
23
  this.#store = store;
24
+ this.observeObject = store.observeObject.bind(store);
25
+ this.observeList = store.observeList.bind(store);
26
+ this.applyAction = store.applyAction.bind(store);
27
+ this.canonicalizeWhereClause = store.canonicalizeWhereClause.bind(store);
21
28
  }
22
- observeObject(apiName, pk, options, subFn) {
23
- return this.#store.observeObject(apiName, pk, options, subFn);
24
- }
25
- observeList(apiName, where, options, subFn) {
26
- return this.#store.observeList(apiName, where, options, subFn);
29
+ };
30
+
31
+ // src/observable/DebugFlags.ts
32
+ process.env.NODE_ENV !== "production" && false;
33
+ var DEBUG_CACHE_KEYS = process.env.NODE_ENV !== "production" && false;
34
+
35
+ // ../../node_modules/.pnpm/delay@6.0.0/node_modules/delay/index.js
36
+ var createAbortError = () => {
37
+ const error = new Error("Delay aborted");
38
+ error.name = "AbortError";
39
+ return error;
40
+ };
41
+ var clearMethods = /* @__PURE__ */ new WeakMap();
42
+ function createDelay({
43
+ clearTimeout: defaultClear,
44
+ setTimeout: defaultSet
45
+ } = {}) {
46
+ return (milliseconds, {
47
+ value,
48
+ signal
49
+ } = {}) => {
50
+ if (signal?.aborted) {
51
+ return Promise.reject(createAbortError());
52
+ }
53
+ let timeoutId;
54
+ let settle;
55
+ let rejectFunction;
56
+ const clear = defaultClear ?? clearTimeout;
57
+ const signalListener = () => {
58
+ clear(timeoutId);
59
+ rejectFunction(createAbortError());
60
+ };
61
+ const cleanup = () => {
62
+ if (signal) {
63
+ signal.removeEventListener("abort", signalListener);
64
+ }
65
+ };
66
+ const delayPromise = new Promise((resolve, reject) => {
67
+ settle = () => {
68
+ cleanup();
69
+ resolve(value);
70
+ };
71
+ rejectFunction = reject;
72
+ timeoutId = (defaultSet ?? setTimeout)(settle, milliseconds);
73
+ });
74
+ if (signal) {
75
+ signal.addEventListener("abort", signalListener, {
76
+ once: true
77
+ });
78
+ }
79
+ clearMethods.set(delayPromise, () => {
80
+ clear(timeoutId);
81
+ timeoutId = null;
82
+ settle();
83
+ });
84
+ return delayPromise;
85
+ };
86
+ }
87
+ var delay = createDelay();
88
+ var delay_default = delay;
89
+
90
+ // src/observable/internal/CacheKey.ts
91
+ function DEBUG_ONLY__cacheKeyToString(x) {
92
+ if (process.env.NODE_ENV !== "production") {
93
+ return `${x.type}CacheKey<${x.otherKeys.map((xx) => JSON.stringify(xx)).join(", ")}>`.replaceAll('"', "'");
94
+ } else {
95
+ throw new Error("not implemented");
27
96
  }
28
- applyAction(action, args, opts) {
29
- return this.#store.applyAction(action, args, opts);
97
+ }
98
+ function DEBUG_ONLY__cacheKeysToString(x) {
99
+ if (process.env.NODE_ENV !== "production") {
100
+ return "\n - " + x.map(DEBUG_ONLY__cacheKeyToString).join("\n - ");
101
+ } else {
102
+ throw new Error("not implemented");
30
103
  }
31
- canonicalizeWhereClause(where) {
32
- return this.#store.whereCanonicalizer.canonicalize(where);
104
+ }
105
+
106
+ // src/observable/internal/Changes.ts
107
+ var Changes = class {
108
+ modifiedObjects = new mnemonist.MultiMap();
109
+ addedObjects = new mnemonist.MultiMap();
110
+ added = /* @__PURE__ */ new Set();
111
+ modified = /* @__PURE__ */ new Set();
112
+ registerObject = (cacheKey, data, isNew) => {
113
+ this[isNew ? "addedObjects" : "modifiedObjects"].set(data.$apiName, data);
114
+ this[isNew ? "added" : "modified"].add(cacheKey);
115
+ };
116
+ registerList = (key) => {
117
+ this.modified.add(key);
118
+ };
119
+ isEmpty() {
120
+ return this.modifiedObjects.size === 0 && this.addedObjects.size === 0 && this.added.size === 0 && this.modified.size === 0;
33
121
  }
34
122
  };
35
-
36
- // ../../node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
37
- function isNodeProcess() {
38
- if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
39
- return true;
123
+ function createChangedObjects() {
124
+ return new Changes();
125
+ }
126
+ function DEBUG_ONLY__changesToString(changes) {
127
+ if (process.env.NODE_ENV !== "production") {
128
+ return JSON.stringify({
129
+ modifiedObjects: multimapHelper(changes.modifiedObjects),
130
+ addedObjects: multimapHelper(changes.addedObjects),
131
+ added: listHelper(changes.added),
132
+ modified: listHelper(changes.modified)
133
+ }, null, 2);
134
+ } else {
135
+ throw new Error("not implemented");
40
136
  }
41
- if (typeof process !== "undefined") {
42
- const type = process.type;
43
- if (type === "renderer" || type === "worker") {
44
- return false;
137
+ }
138
+ function listHelper(set) {
139
+ return Array.from(set).map(DEBUG_ONLY__cacheKeyToString);
140
+ }
141
+ function multimapHelper(multimap) {
142
+ return Object.fromEntries(Array.from(multimap.associations()).map(([type, objects]) => {
143
+ return [type, objects.map((o) => o.$primaryKey)];
144
+ }));
145
+ }
146
+
147
+ // src/observable/internal/OptimisticId.ts
148
+ function createOptimisticId() {
149
+ if (process.env.NODE_ENV !== "production") {
150
+ if (createOptimisticId.counter === void 0) {
151
+ createOptimisticId.counter = 0;
45
152
  }
46
- return !!(process.versions && process.versions.node);
153
+ return {
154
+ __optimisticId: createOptimisticId.counter++
155
+ };
47
156
  }
48
- return false;
157
+ return /* @__PURE__ */ Object.create(null);
49
158
  }
50
159
 
51
- // ../../node_modules/.pnpm/msw@2.7.0_@types+node@22.13.1_typescript@5.5.4/node_modules/msw/lib/core/delay.mjs
52
- var SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647;
53
- var MIN_SERVER_RESPONSE_TIME = 100;
54
- var MAX_SERVER_RESPONSE_TIME = 400;
55
- var NODE_SERVER_RESPONSE_TIME = 5;
56
- function getRealisticResponseTime() {
57
- if (isNodeProcess()) {
58
- return NODE_SERVER_RESPONSE_TIME;
59
- }
60
- return Math.floor(Math.random() * (MAX_SERVER_RESPONSE_TIME - MIN_SERVER_RESPONSE_TIME) + MIN_SERVER_RESPONSE_TIME);
160
+ // src/observable/internal/OptimisticJob.ts
161
+ var OptimisticJob = class {
162
+ #result;
163
+ constructor(store, optimisticId) {
164
+ const updatedObjects = [];
165
+ const addedObjectPromises = [];
166
+ this.getResult = () => {
167
+ return this.#result ??= (async () => {
168
+ const addedObjects = await Promise.allSettled(addedObjectPromises);
169
+ const {
170
+ batchResult
171
+ } = store.batch({
172
+ optimisticId
173
+ }, (batch) => {
174
+ for (const obj of addedObjects) {
175
+ if (obj.status === "fulfilled") {
176
+ store.getObjectQuery(obj.value.$objectType, obj.value.$primaryKey).writeToStore(obj.value, "loading", batch);
177
+ } else {
178
+ throw obj;
179
+ }
180
+ }
181
+ for (const obj of updatedObjects) {
182
+ store.getObjectQuery(obj.$objectType, obj.$primaryKey).writeToStore(obj, "loading", batch);
183
+ }
184
+ });
185
+ return batchResult.changes;
186
+ })();
187
+ };
188
+ this.context = {
189
+ updateObject(value) {
190
+ updatedObjects.push(value);
191
+ return this;
192
+ },
193
+ createObject(type, pk, properties) {
194
+ const create = store.client[chunk37QC7LR3_cjs.additionalContext].objectFactory2(store.client[chunk37QC7LR3_cjs.additionalContext], [{
195
+ $primaryKey: pk,
196
+ $apiName: type.apiName,
197
+ $objectType: type.apiName,
198
+ ...properties
199
+ }], void 0, {}).then((objs) => {
200
+ return objs[0];
201
+ });
202
+ addedObjectPromises.push(create);
203
+ return this;
204
+ }
205
+ };
206
+ }
207
+ };
208
+ function runOptimisticJob(store, optimisticUpdate) {
209
+ if (!optimisticUpdate) {
210
+ return () => Promise.resolve();
211
+ }
212
+ const optimisticId = createOptimisticId();
213
+ const job = new OptimisticJob(store, optimisticId);
214
+ optimisticUpdate(job.context);
215
+ const optimisticApplicationDone = job.getResult();
216
+ return () => {
217
+ return optimisticApplicationDone.then(
218
+ // we don't want to leak the result
219
+ () => void 0
220
+ ).finally(() => {
221
+ store.removeLayer(optimisticId);
222
+ });
223
+ };
61
224
  }
62
- async function delay(durationOrMode) {
63
- let delayTime;
64
- if (typeof durationOrMode === "string") {
65
- switch (durationOrMode) {
66
- case "infinite": {
67
- delayTime = SET_TIMEOUT_MAX_ALLOWED_INT;
68
- break;
225
+
226
+ // src/observable/internal/ActionApplication.ts
227
+ var ACTION_DELAY = process.env.NODE_ENV === "production" ? 0 : 1e3;
228
+ var ActionApplication = class {
229
+ constructor(store) {
230
+ this.store = store;
231
+ }
232
+ applyAction = async (action, args, {
233
+ optimisticUpdate
234
+ } = {}) => {
235
+ const logger = process.env.NODE_ENV !== "production" ? this.store.logger?.child({
236
+ methodName: "applyAction"
237
+ }) : this.store.logger;
238
+ const removeOptimisticResult = runOptimisticJob(this.store, optimisticUpdate);
239
+ return await (async () => {
240
+ try {
241
+ const actionResults = await this.store.client(action).applyAction(args, {
242
+ $returnEdits: true
243
+ });
244
+ if (process.env.NODE_ENV !== "production") {
245
+ if (ACTION_DELAY > 0) {
246
+ logger?.debug("action done, pausing", actionResults);
247
+ await delay_default(ACTION_DELAY);
248
+ logger?.debug("action done, pausing done");
249
+ }
250
+ }
251
+ await this.#invalidateActionEditResponse(actionResults);
252
+ return actionResults;
253
+ } finally {
254
+ if (process.env.NODE_ENV !== "production") {
255
+ logger?.debug("optimistic action complete; remove the results");
256
+ }
257
+ await removeOptimisticResult();
69
258
  }
70
- case "real": {
71
- delayTime = getRealisticResponseTime();
72
- break;
259
+ })();
260
+ };
261
+ #invalidateActionEditResponse = async (value) => {
262
+ const typesToInvalidate = /* @__PURE__ */ new Set();
263
+ let changes;
264
+ if (value.type === "edits") {
265
+ const promisesToWait = [];
266
+ for (const obj of value.modifiedObjects) {
267
+ promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
73
268
  }
74
- default: {
75
- throw new Error(`Failed to delay a response: unknown delay mode "${durationOrMode}". Please make sure you provide one of the supported modes ("real", "infinite") or a number.`);
269
+ for (const obj of value.addedObjects) {
270
+ promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
271
+ typesToInvalidate.add(obj.objectType);
272
+ }
273
+ await Promise.all(promisesToWait);
274
+ const changes2 = createChangedObjects();
275
+ for (const changeType of ["addedObjects", "modifiedObjects"]) {
276
+ for (const {
277
+ objectType,
278
+ primaryKey
279
+ } of value[changeType] ?? []) {
280
+ const cacheKey = this.store.getCacheKey("object", objectType, primaryKey);
281
+ const obj = this.store.getValue(cacheKey);
282
+ if (obj && obj.value) {
283
+ changes2[changeType].set(objectType, obj.value);
284
+ (changeType === "addedObjects" ? changes2.added : changes2.modified).add(cacheKey);
285
+ }
286
+ }
287
+ }
288
+ } else {
289
+ for (const apiName of value.editedObjectTypes) {
290
+ typesToInvalidate.add(apiName.toString());
291
+ await this.store.invalidateObjectType(apiName, changes);
76
292
  }
77
293
  }
78
- } else if (typeof durationOrMode === "undefined") {
79
- delayTime = getRealisticResponseTime();
80
- } else {
81
- if (durationOrMode > SET_TIMEOUT_MAX_ALLOWED_INT) {
82
- throw new Error(`Failed to delay a response: provided delay duration (${durationOrMode}) exceeds the maximum allowed duration for "setTimeout" (${SET_TIMEOUT_MAX_ALLOWED_INT}). This will cause the response to be returned immediately. Please use a number within the allowed range to delay the response by exact duration, or consider the "infinite" delay mode to delay the response indefinitely.`);
83
- }
84
- delayTime = durationOrMode;
85
- }
86
- return new Promise((resolve) => setTimeout(resolve, delayTime));
87
- }
88
-
89
- // src/observable/DebugFlags.ts
90
- process.env.NODE_ENV !== "production" && false;
91
- var DEBUG_CACHE_KEYS = process.env.NODE_ENV !== "production" && false;
294
+ return value;
295
+ };
296
+ };
92
297
  var CacheKeys = class {
93
298
  #cacheKeys = new trie.Trie(false, (keys) => {
94
299
  const ret = {
@@ -100,15 +305,15 @@ var CacheKeys = class {
100
305
  });
101
306
  #cacheKeyFactories = /* @__PURE__ */ new Map();
102
307
  #onCreate;
103
- constructor(whereCanonicalizer, onCreate) {
308
+ constructor(whereCanonicalizer, orderByCanonicalizer, onCreate) {
104
309
  this.#onCreate = onCreate;
105
310
  this.#registerCacheKeyFactory("object", (apiName, pk) => {
106
311
  if (process.env.NODE_ENV !== "production" && DEBUG_CACHE_KEYS) ;
107
312
  return this.#cacheKeys.lookupArray(["object", apiName, pk]);
108
313
  });
109
- this.#registerCacheKeyFactory("list", (apiName, where) => {
314
+ this.#registerCacheKeyFactory("list", (type, apiName, where, orderBy) => {
110
315
  if (process.env.NODE_ENV !== "production" && DEBUG_CACHE_KEYS) ;
111
- return this.#cacheKeys.lookupArray(["list", apiName, whereCanonicalizer.canonicalize(where)]);
316
+ return this.#cacheKeys.lookupArray(["list", type, apiName, whereCanonicalizer.canonicalize(where), orderByCanonicalizer.canonicalize(orderBy)]);
112
317
  });
113
318
  }
114
319
  #registerCacheKeyFactory(type, factory) {
@@ -116,19 +321,13 @@ var CacheKeys = class {
116
321
  }
117
322
  get(type, ...args) {
118
323
  const factory = this.#cacheKeyFactories.get(type);
119
- !factory ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `no cache key factory for type "${type}"`) : invariant2__default.default(false) : undefined;
324
+ !factory ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `no cache key factory for type "${type}"`) : invariant2__default.default(false) : void 0;
120
325
  return factory(...args);
121
326
  }
122
327
  remove(cacheKey) {
123
328
  this.#cacheKeys.remove(cacheKey.type, ...cacheKey.otherKeys);
124
329
  }
125
330
  };
126
- function createChangedObjects() {
127
- return {
128
- modifiedObjects: new mnemonist.MultiMap(),
129
- addedObjects: new mnemonist.MultiMap()
130
- };
131
- }
132
331
 
133
332
  // src/observable/internal/WeakMapWithEntries.ts
134
333
  var WeakMapWithEntries = class {
@@ -154,7 +353,7 @@ var WeakMapWithEntries = class {
154
353
  }, 1e3);
155
354
  }
156
355
  #clean() {
157
- this.#list = this.#list.filter((ref) => ref.deref() !== undefined);
356
+ this.#list = this.#list.filter((ref) => ref.deref() !== void 0);
158
357
  }
159
358
  // functions for WeakMap
160
359
  delete(key) {
@@ -194,7 +393,7 @@ var WeakMapWithEntries = class {
194
393
  function* iter() {
195
394
  for (const ref of self.#list) {
196
395
  const key = ref.deref();
197
- if (key !== undefined) {
396
+ if (key !== void 0) {
198
397
  yield [key, self.#map.get(key)];
199
398
  }
200
399
  }
@@ -209,7 +408,7 @@ var WeakMapWithEntries = class {
209
408
  function* iter() {
210
409
  for (const ref of self.#list) {
211
410
  const key = ref.deref();
212
- if (key !== undefined) {
411
+ if (key !== void 0) {
213
412
  yield key;
214
413
  }
215
414
  }
@@ -224,9 +423,9 @@ var WeakMapWithEntries = class {
224
423
  function* iter() {
225
424
  for (const ref of self.#list) {
226
425
  const key = ref.deref();
227
- if (key !== undefined) {
426
+ if (key !== void 0) {
228
427
  const value = self.#map.get(key);
229
- if (value !== undefined) {
428
+ if (value !== void 0) {
230
429
  yield value;
231
430
  }
232
431
  }
@@ -262,11 +461,14 @@ var Layer = class _Layer {
262
461
  this.#parent = this.#parent.removeLayer(layerId);
263
462
  return this;
264
463
  }
265
- return this.#parent ?? this;
464
+ return this.#parent.removeLayer(layerId);
266
465
  }
267
466
  entries() {
268
467
  return this.#cache.entries();
269
468
  }
469
+ keys() {
470
+ return this.#cache.keys();
471
+ }
270
472
  get(cacheKey) {
271
473
  return this.#cache.get(cacheKey) ?? this.#parent?.get(cacheKey);
272
474
  }
@@ -275,18 +477,18 @@ var Layer = class _Layer {
275
477
  }
276
478
  };
277
479
  var Entry = class {
278
- constructor(cacheKey, value, lastUpdated) {
480
+ constructor(cacheKey, value, lastUpdated, status = "init") {
279
481
  this.cacheKey = cacheKey;
280
482
  this.value = value;
281
483
  this.lastUpdated = lastUpdated;
282
- this.status = "init";
484
+ this.status = status;
283
485
  }
284
486
  };
285
487
  function is$and(whereClause) {
286
488
  if (process.env.NODE_ENV !== "production") {
287
489
  if ("$and" in whereClause) {
288
- !Array.isArray(whereClause.$and) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected $and to be an array") : invariant2__default.default(false) : undefined;
289
- !(Object.keys(whereClause).length === 1) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected only $and to be present") : invariant2__default.default(false) : undefined;
490
+ !Array.isArray(whereClause.$and) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected $and to be an array") : invariant2__default.default(false) : void 0;
491
+ !(Object.keys(whereClause).length === 1) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected only $and to be present") : invariant2__default.default(false) : void 0;
290
492
  }
291
493
  }
292
494
  return "$and" in whereClause;
@@ -294,8 +496,8 @@ function is$and(whereClause) {
294
496
  function is$or(whereClause) {
295
497
  if (process.env.NODE_ENV !== "production") {
296
498
  if ("$or" in whereClause) {
297
- !Array.isArray(whereClause.$or) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected $or to be an array") : invariant2__default.default(false) : undefined;
298
- !(Object.keys(whereClause).length === 1) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected only $or to be present") : invariant2__default.default(false) : undefined;
499
+ !Array.isArray(whereClause.$or) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected $or to be an array") : invariant2__default.default(false) : void 0;
500
+ !(Object.keys(whereClause).length === 1) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected only $or to be present") : invariant2__default.default(false) : void 0;
299
501
  }
300
502
  }
301
503
  return "$or" in whereClause;
@@ -303,7 +505,7 @@ function is$or(whereClause) {
303
505
  function is$not(whereClause) {
304
506
  if (process.env.NODE_ENV !== "production") {
305
507
  if ("$not" in whereClause) {
306
- !(Object.keys(whereClause).length === 1) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected only $not to be present") : invariant2__default.default(false) : undefined;
508
+ !(Object.keys(whereClause).length === 1) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected only $not to be present") : invariant2__default.default(false) : void 0;
307
509
  }
308
510
  }
309
511
  return "$not" in whereClause;
@@ -368,46 +570,172 @@ function objectSortaMatchesWhereClause(o, whereClause, strict) {
368
570
  });
369
571
  }
370
572
 
573
+ // ../../node_modules/.pnpm/p-defer@4.0.1/node_modules/p-defer/index.js
574
+ function pDefer() {
575
+ const deferred = {};
576
+ deferred.promise = new Promise((resolve, reject) => {
577
+ deferred.resolve = resolve;
578
+ deferred.reject = reject;
579
+ });
580
+ return deferred;
581
+ }
582
+
583
+ // src/observable/internal/BulkObjectLoader.ts
584
+ var weakCache = new mnemonist.DefaultWeakMap((c) => new BulkObjectLoader(c));
585
+ function getBulkObjectLoader(client) {
586
+ return weakCache.get(client);
587
+ }
588
+ var BulkObjectLoader = class {
589
+ #client;
590
+ #m = new mnemonist.DefaultMap(() => ({
591
+ data: [],
592
+ timer: void 0
593
+ }));
594
+ #logger;
595
+ #maxWait;
596
+ #maxEntries;
597
+ constructor(client, maxWait = 25, maxEntries = 100) {
598
+ this.#client = client;
599
+ this.#logger = client[chunk37QC7LR3_cjs.additionalContext].logger;
600
+ this.#maxWait = maxWait;
601
+ this.#maxEntries = maxEntries;
602
+ }
603
+ fetch(apiName, primaryKey) {
604
+ const deferred = pDefer();
605
+ const entry = this.#m.get(apiName);
606
+ entry.data.push({
607
+ primaryKey,
608
+ deferred
609
+ });
610
+ if (!entry.timer) {
611
+ entry.timer = setTimeout(() => {
612
+ this.#loadObjects(apiName, entry.data);
613
+ }, this.#maxWait);
614
+ }
615
+ if (entry.data.length >= this.#maxEntries) {
616
+ clearTimeout(entry.timer);
617
+ this.#loadObjects(apiName, entry.data);
618
+ }
619
+ return deferred.promise;
620
+ }
621
+ #loadObjects(apiName, arr) {
622
+ this.#m.delete(apiName);
623
+ this.#reallyLoadObjects(apiName, arr).catch((e) => {
624
+ this.#logger?.error("Unhandled exception", e);
625
+ });
626
+ }
627
+ async #reallyLoadObjects(apiName, arr) {
628
+ const miniDef = {
629
+ type: "object",
630
+ apiName
631
+ };
632
+ const objMetadata = await this.#client.fetchMetadata(miniDef);
633
+ const pks = arr.map((x) => x.primaryKey);
634
+ const {
635
+ data
636
+ } = await this.#client(miniDef).where({
637
+ [objMetadata.primaryKeyApiName]: {
638
+ $in: pks
639
+ }
640
+ }).fetchPage({
641
+ $pageSize: pks.length
642
+ });
643
+ for (const {
644
+ primaryKey,
645
+ deferred
646
+ } of arr) {
647
+ const object = data.find((x) => x.$primaryKey === primaryKey);
648
+ if (object) {
649
+ deferred.resolve(object);
650
+ } else {
651
+ deferred.reject(new shared_net_errors.PalantirApiError("Object not found"));
652
+ }
653
+ }
654
+ }
655
+ };
656
+
371
657
  // src/observable/internal/Query.ts
372
658
  var Query = class {
373
659
  retainCount = 0;
374
660
  #connectable;
375
661
  #subscription;
376
662
  #subject;
377
- constructor(store, observable, opts, cacheKey) {
663
+ /** @internal */
664
+ constructor(store, observable, opts, cacheKey, logger) {
378
665
  this.options = opts;
379
666
  this.cacheKey = cacheKey;
380
667
  this.store = store;
381
668
  this.#subject = observable;
669
+ this.logger = logger ?? (process.env.NODE_ENV === "production" ? store.client[chunk37QC7LR3_cjs.additionalContext].logger : store.client[chunk37QC7LR3_cjs.additionalContext].logger?.child({}, {
670
+ msgPrefix: process.env.NODE_ENV !== "production" ? `Query<${cacheKey.type}, ${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>` : "Query"
671
+ }));
382
672
  }
383
673
  subscribe(observer) {
384
674
  this.#connectable ??= this._createConnectable(this.#subject);
385
675
  this.#subscription = this.#connectable.connect();
386
676
  return this.#connectable.subscribe(observer);
387
677
  }
388
- revalidate(force) {
678
+ /**
679
+ * Causes the query to revalidate. This will cause the query to fetch
680
+ * the latest data from the server and update the store if it is deemed
681
+ * "stale" or if `force` is true.
682
+ *
683
+ * @param force
684
+ * @returns
685
+ */
686
+ async revalidate(force) {
687
+ const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
688
+ methodName: "revalidate"
689
+ }) : this.logger;
389
690
  if (force) {
390
691
  this.abortController?.abort();
391
692
  }
392
693
  if (this.pendingFetch) {
393
- return this.pendingFetch;
694
+ if (process.env.NODE_ENV !== "production") {
695
+ logger?.info("Fetch is already pending, using it");
696
+ }
697
+ await this.pendingFetch;
698
+ return;
394
699
  }
395
700
  if ((this.options.dedupeInterval ?? 0) > 0 && this.lastFetchStarted != null && Date.now() - this.lastFetchStarted < (this.options.dedupeInterval ?? 0)) {
701
+ if (process.env.NODE_ENV !== "production") {
702
+ logger?.debug("Within dupeInterval, aborting revalidate");
703
+ }
396
704
  return Promise.resolve();
397
705
  }
706
+ if (process.env.NODE_ENV !== "production") {
707
+ logger?.debug("Starting actual revalidate");
708
+ }
398
709
  this.store.batch({}, (batch) => {
399
710
  this.setStatus("loading", batch);
400
711
  });
401
712
  this._preFetch();
402
713
  this.lastFetchStarted = Date.now();
403
- this.pendingFetch = this._fetch().finally(() => {
404
- this.pendingFetch = undefined;
714
+ if (process.env.NODE_ENV !== "production") {
715
+ logger?.debug("calling _fetchAndStore()");
716
+ }
717
+ this.pendingFetch = this._fetchAndStore().finally(() => {
718
+ logger?.info("finally _fetchAndStore()");
719
+ this.pendingFetch = void 0;
405
720
  });
406
- return this.pendingFetch;
721
+ await this.pendingFetch;
722
+ return;
407
723
  }
408
724
  _preFetch() {
409
725
  }
726
+ /**
727
+ * Sets the status of the query in the store (but does not store that in `changes`).
728
+ *
729
+ * @param status
730
+ * @param batch
731
+ * @returns
732
+ */
410
733
  setStatus(status, batch) {
734
+ if (process.env.NODE_ENV !== "production") {
735
+ this.logger?.child({
736
+ methodName: "setStatus"
737
+ }).debug(status);
738
+ }
411
739
  const existing = batch.read(this.cacheKey);
412
740
  if (existing?.status === status) return;
413
741
  batch.write(this.cacheKey, existing?.value, status);
@@ -419,62 +747,243 @@ var Query = class {
419
747
  this.#subscription?.unsubscribe();
420
748
  this._dispose();
421
749
  }
750
+ /**
751
+ * Per query type dispose functionality
752
+ */
422
753
  _dispose() {
423
754
  }
755
+ /**
756
+ * The purpose of this method is to provide a way for others to write
757
+ * directly into the store for this query.
758
+ *
759
+ * @param data
760
+ * @param status
761
+ * @param batch
762
+ */
763
+ /**
764
+ * @param changes
765
+ * @param optimisticId
766
+ * @returns If revalidation is needed, a promise that resolves after the
767
+ * revalidation is complete. Otherwise, undefined.
768
+ */
424
769
  };
425
770
 
426
- // src/observable/internal/ListQuery.ts
427
- rxjs.auditTime(0);
428
- var ListQuery = class extends Query {
429
- // pageSize?: number; // this is the internal page size. we need to track this properly
430
- #client;
431
- #type;
432
- #whereClause;
433
- // this represents the minimum number of results we need to load if we revalidate
434
- #minNumResults = 0;
435
- #nextPageToken;
436
- #pendingPageFetch;
437
- #toRelease = /* @__PURE__ */ new Set();
438
- constructor(store, subject, type, whereClause, cacheKey, opts) {
439
- super(store, subject, opts, cacheKey);
440
- this.#client = store.client;
441
- this.#type = type;
442
- this.#whereClause = whereClause;
443
- rxjs.observeOn(rxjs.asyncScheduler);
771
+ // src/observable/internal/ObjectQuery.ts
772
+ var ObjectQuery = class extends Query {
773
+ #apiName;
774
+ #pk;
775
+ constructor(store, subject, type, pk, cacheKey, opts) {
776
+ super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunk37QC7LR3_cjs.additionalContext].logger?.child({}, {
777
+ msgPrefix: `ObjectQuery<${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>`
778
+ }) : void 0);
779
+ this.#apiName = type;
780
+ this.#pk = pk;
444
781
  }
445
782
  _createConnectable(subject) {
446
- return rxjs.connectable(subject.pipe(
447
- rxjs.mergeMap((listEntry) => {
448
- return rxjs.combineLatest({
449
- resolvedList: listEntry?.value?.data == null ? rxjs.of([]) : rxjs.combineLatest(listEntry.value.data.map((cacheKey) => this.store.getSubject(cacheKey).pipe(rxjs.map((objectEntry) => objectEntry?.value)))),
450
- isOptimistic: rxjs.of(listEntry.isOptimistic),
451
- fetchMore: rxjs.of(this.fetchMore),
452
- hasMore: rxjs.of(this.#nextPageToken != null),
453
- status: rxjs.of(listEntry.status),
454
- lastUpdated: rxjs.of(listEntry.lastUpdated)
455
- });
456
- }),
457
- // like throttle but returns the tail
458
- rxjs.auditTime(0)
459
- ), {
460
- resetOnDisconnect: false,
461
- connector: () => new rxjs.ReplaySubject(1)
783
+ return rxjs.connectable(subject.pipe(rxjs.map((x) => {
784
+ return {
785
+ status: x.status,
786
+ object: x.value,
787
+ lastUpdated: x.lastUpdated,
788
+ isOptimistic: x.isOptimistic
789
+ };
790
+ })), {
791
+ connector: () => new rxjs.BehaviorSubject({
792
+ status: "init",
793
+ object: void 0,
794
+ lastUpdated: 0,
795
+ isOptimistic: false
796
+ })
462
797
  });
463
798
  }
464
- _preFetch() {
465
- this.#nextPageToken = undefined;
799
+ async _fetchAndStore() {
800
+ if (process.env.NODE_ENV !== "production") {
801
+ this.logger?.child({
802
+ methodName: "_fetchAndStore"
803
+ }).info("calling _fetchAndStore");
804
+ }
805
+ const obj = await getBulkObjectLoader(this.store.client).fetch(this.#apiName, this.#pk);
806
+ this.store.batch({}, (batch) => {
807
+ this.writeToStore(obj, "loaded", batch);
808
+ });
466
809
  }
467
- async _fetch() {
468
- const objectSet = this.#client({
469
- type: "object",
470
- apiName: this.#type
471
- }).where(this.#whereClause);
472
- while (true) {
473
- const entry = await this.#fetchPageAndUpdate(objectSet, "loading", this.abortController?.signal);
474
- if (!entry) {
475
- return;
810
+ writeToStore(data, status, batch) {
811
+ const entry = batch.read(this.cacheKey);
812
+ if (entry && deepEqual__default.default(data, entry.value)) {
813
+ if (process.env.NODE_ENV !== "production") {
814
+ this.logger?.child({
815
+ methodName: "writeToStore"
816
+ }).debug(`Object was deep equal, just setting status`);
476
817
  }
477
- !entry.value?.data ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false) : invariant2__default.default(false) : undefined;
818
+ return batch.write(this.cacheKey, entry.value, status);
819
+ }
820
+ if (process.env.NODE_ENV !== "production") {
821
+ this.logger?.child({
822
+ methodName: "writeToStore"
823
+ }).debug(JSON.stringify({
824
+ status
825
+ }), data);
826
+ }
827
+ const ret = batch.write(this.cacheKey, data, status);
828
+ batch.changes.registerObject(
829
+ this.cacheKey,
830
+ data,
831
+ /* isNew */
832
+ !entry
833
+ );
834
+ return ret;
835
+ }
836
+ };
837
+ function storeOsdkInstances(store, values, batch) {
838
+ return values.map((v) => {
839
+ return store.getObjectQuery(v.$apiName, v.$primaryKey).writeToStore(v, "loaded", batch).cacheKey;
840
+ });
841
+ }
842
+
843
+ // src/observable/internal/ListQuery.ts
844
+ var API_NAME_IDX = 1;
845
+ var BaseListQuery = class extends Query {
846
+ //
847
+ // Per list type implementations
848
+ //
849
+ //
850
+ // Shared Implementations
851
+ //
852
+ /**
853
+ * Only intended to be "protected" and used by subclasses but exposed for
854
+ * testing.
855
+ *
856
+ * @param objectCacheKeys
857
+ * @param append
858
+ * @param status
859
+ * @param batch
860
+ * @returns
861
+ */
862
+ _updateList(objectCacheKeys, append, status, batch) {
863
+ if (process.env.NODE_ENV !== "production") {
864
+ const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
865
+ methodName: "updateList"
866
+ }) : this.logger;
867
+ logger?.debug(`{status: ${status}}`, JSON.stringify(objectCacheKeys, null, 2));
868
+ }
869
+ objectCacheKeys = this.#retainReleaseAppend(batch, append, objectCacheKeys);
870
+ objectCacheKeys = this._sortCacheKeys(objectCacheKeys, batch);
871
+ objectCacheKeys = removeDuplicates(objectCacheKeys, batch);
872
+ return this.writeToStore({
873
+ data: objectCacheKeys
874
+ }, status, batch);
875
+ }
876
+ writeToStore(data, status, batch) {
877
+ const entry = batch.read(this.cacheKey);
878
+ if (entry && deepEqual__default.default(data, entry.value)) {
879
+ if (process.env.NODE_ENV !== "production") {
880
+ this.logger?.child({
881
+ methodName: "writeToStore"
882
+ }).debug(`Object was deep equal, just setting status`);
883
+ }
884
+ return batch.write(this.cacheKey, entry.value, status);
885
+ }
886
+ if (process.env.NODE_ENV !== "production") {
887
+ this.logger?.child({
888
+ methodName: "writeToStore"
889
+ }).debug(`{status: ${status}},`, DEBUG_ONLY__cacheKeysToString(data.data));
890
+ }
891
+ const ret = batch.write(this.cacheKey, data, status);
892
+ batch.changes.registerList(this.cacheKey);
893
+ return ret;
894
+ }
895
+ #retainReleaseAppend(batch, append, objectCacheKeys) {
896
+ const existingList = batch.read(this.cacheKey);
897
+ if (!batch.optimisticWrite) {
898
+ if (!append) {
899
+ for (const objectCacheKey of existingList?.value?.data ?? []) {
900
+ this.store.release(objectCacheKey);
901
+ }
902
+ }
903
+ for (const objectCacheKey of objectCacheKeys) {
904
+ this.store.retain(objectCacheKey);
905
+ }
906
+ }
907
+ if (append) {
908
+ objectCacheKeys = [...existingList?.value?.data ?? [], ...objectCacheKeys];
909
+ }
910
+ return objectCacheKeys;
911
+ }
912
+ _dispose() {
913
+ console.log("DISPOSE LIST QUERY");
914
+ this.store.batch({}, (batch) => {
915
+ const entry = batch.read(this.cacheKey);
916
+ if (entry) {
917
+ for (const objectCacheKey of entry.value?.data ?? []) {
918
+ this.store.release(objectCacheKey);
919
+ }
920
+ }
921
+ });
922
+ }
923
+ };
924
+ var ListQuery = class extends BaseListQuery {
925
+ // pageSize?: number; // this is the internal page size. we need to track this properly
926
+ #type;
927
+ #apiName;
928
+ #whereClause;
929
+ // this represents the minimum number of results we need to load if we revalidate
930
+ #minNumResults = 0;
931
+ #nextPageToken;
932
+ #pendingPageFetch;
933
+ #orderBy;
934
+ #objectSet;
935
+ #sortFns;
936
+ constructor(store, subject, apiType, apiName, whereClause, orderBy, cacheKey, opts) {
937
+ super(store, subject, opts, cacheKey, process.env.NODE_ENV !== "production" ? store.client[chunk37QC7LR3_cjs.additionalContext].logger?.child({}, {
938
+ msgPrefix: `ListQuery<${cacheKey.otherKeys.map((x) => JSON.stringify(x)).join(", ")}>`
939
+ }) : void 0);
940
+ this.#type = apiType;
941
+ this.#apiName = apiName;
942
+ this.#whereClause = whereClause;
943
+ this.#orderBy = orderBy;
944
+ this.#objectSet = store.client({
945
+ type: this.#type,
946
+ apiName: this.#apiName
947
+ }).where(this.#whereClause);
948
+ this.#sortFns = createOrderBySortFns(this.#orderBy);
949
+ }
950
+ get canonicalWhere() {
951
+ return this.#whereClause;
952
+ }
953
+ _createConnectable(subject) {
954
+ return rxjs.connectable(subject.pipe(
955
+ rxjs.switchMap((listEntry) => {
956
+ return rxjs.combineLatest({
957
+ resolvedList: listEntry?.value?.data == null ? rxjs.of([]) : rxjs.combineLatest(listEntry.value.data.map((cacheKey) => this.store.getSubject(cacheKey).pipe(rxjs.map((objectEntry) => objectEntry?.value)))),
958
+ isOptimistic: rxjs.of(listEntry.isOptimistic),
959
+ fetchMore: rxjs.of(this.fetchMore),
960
+ hasMore: rxjs.of(this.#nextPageToken != null),
961
+ status: rxjs.of(listEntry.status),
962
+ lastUpdated: rxjs.of(listEntry.lastUpdated)
963
+ });
964
+ }),
965
+ // like throttle but returns the tail
966
+ rxjs.auditTime(0)
967
+ ), {
968
+ resetOnDisconnect: false,
969
+ connector: () => new rxjs.ReplaySubject(1)
970
+ });
971
+ }
972
+ _preFetch() {
973
+ this.#nextPageToken = void 0;
974
+ }
975
+ async _fetchAndStore() {
976
+ if (process.env.NODE_ENV !== "production") {
977
+ this.logger?.child({
978
+ methodName: "_fetchAndStore"
979
+ }).info("fetching pages");
980
+ }
981
+ while (true) {
982
+ const entry = await this.#fetchPageAndUpdate(this.#objectSet, "loading", this.abortController?.signal);
983
+ if (!entry) {
984
+ return;
985
+ }
986
+ !entry.value?.data ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false) : invariant2__default.default(false) : void 0;
478
987
  const count = entry.value.data.length;
479
988
  if (count > this.#minNumResults || this.#nextPageToken == null) {
480
989
  break;
@@ -502,271 +1011,421 @@ var ListQuery = class extends Query {
502
1011
  this.store.batch({}, (batch) => {
503
1012
  this.setStatus("loading", batch);
504
1013
  });
505
- const objectSet = this.#client({
506
- type: "object",
507
- apiName: this.#type
508
- }).where(this.#whereClause);
509
- this.pendingFetch = this.#fetchPageAndUpdate(objectSet, "loaded", this.abortController?.signal).finally(() => {
510
- this.#pendingPageFetch = undefined;
1014
+ this.pendingFetch = this.#fetchPageAndUpdate(this.#objectSet, "loaded", this.abortController?.signal).finally(() => {
1015
+ this.#pendingPageFetch = void 0;
511
1016
  });
512
1017
  return this.pendingFetch;
513
1018
  };
514
1019
  async #fetchPageAndUpdate(objectSet, status, signal) {
515
1020
  const append = this.#nextPageToken != null;
516
- const {
517
- data,
518
- nextPageToken
519
- } = await objectSet.fetchPage({
520
- $nextPageToken: this.#nextPageToken,
521
- $pageSize: this.options.pageSize
522
- });
523
- if (signal?.aborted) {
524
- return;
1021
+ try {
1022
+ let {
1023
+ data,
1024
+ nextPageToken
1025
+ } = await objectSet.fetchPage({
1026
+ $nextPageToken: this.#nextPageToken,
1027
+ $pageSize: this.options.pageSize,
1028
+ // For now this keeps the shared test code from falling apart
1029
+ // but shouldn't be needed ideally
1030
+ ...Object.keys(this.#orderBy).length > 0 ? {
1031
+ $orderBy: this.#orderBy
1032
+ } : {}
1033
+ });
1034
+ if (signal?.aborted) {
1035
+ return;
1036
+ }
1037
+ this.#nextPageToken = nextPageToken;
1038
+ if (this.#type === "interface") {
1039
+ data = await reloadDataAsFullObjects(this.store.client, data);
1040
+ }
1041
+ const {
1042
+ retVal
1043
+ } = this.store.batch({}, (batch) => {
1044
+ return this._updateList(storeOsdkInstances(this.store, data, batch), append, nextPageToken ? status : "loaded", batch);
1045
+ });
1046
+ return retVal;
1047
+ } catch (e) {
1048
+ this.logger?.error("error", e);
1049
+ this.store.getSubject(this.cacheKey).error(e);
525
1050
  }
526
- this.#nextPageToken = nextPageToken;
527
- const {
528
- retVal
529
- } = this.store.batch({}, (batch) => {
530
- return this.updateList(data, append, nextPageToken ? status : "loaded", batch);
531
- });
532
- return retVal;
533
1051
  }
534
1052
  /**
535
- * Caller is responsible for removing the layer
1053
+ * Will revalidate the list if its query is affected by invalidating the
1054
+ * apiName of the object type passed in.
536
1055
  *
537
- * @param changedObjects
538
- * @param optimisticId
1056
+ * @param apiName to invalidate
539
1057
  * @returns
540
1058
  */
541
- maybeUpdate(changedObjects, optimisticId) {
542
- let needsRevalidation = false;
543
- const objectsToInsert = [];
544
- for (const [type, objects] of changedObjects.addedObjects.associations()) {
545
- if (this.cacheKey.otherKeys[0] !== type) {
546
- continue;
1059
+ revalidateObjectType = async (apiName) => {
1060
+ if (this.#type === "object") {
1061
+ if (this.#apiName === apiName) {
1062
+ await this.revalidate(
1063
+ /* force */
1064
+ true
1065
+ );
1066
+ return;
1067
+ } else {
1068
+ return;
1069
+ }
1070
+ }
1071
+ const objectMetadata = await this.store.client.fetchMetadata({
1072
+ type: "object",
1073
+ apiName
1074
+ });
1075
+ if (this.#apiName in objectMetadata.interfaceMap) {
1076
+ await this.revalidate(
1077
+ /* force */
1078
+ true
1079
+ );
1080
+ return;
1081
+ }
1082
+ };
1083
+ /**
1084
+ * Note: This method is not async because I want it to return right after it
1085
+ * finishes the synchronous updates. The promise that is returned
1086
+ * will resolve after the revalidation is complete.
1087
+ * @param changes
1088
+ * @param optimisticId
1089
+ * @returns If revalidation is needed, a promise that resolves after the
1090
+ * revalidation is complete. Otherwise, undefined.
1091
+ */
1092
+ maybeUpdateAndRevalidate = (changes, optimisticId) => {
1093
+ if (process.env.NODE_ENV !== "production") {
1094
+ this.logger?.child({
1095
+ methodName: "maybeUpdateAndRevalidate"
1096
+ }).debug(DEBUG_ONLY__changesToString(changes));
1097
+ }
1098
+ if (changes.modified.has(this.cacheKey)) return;
1099
+ changes.modified.add(this.cacheKey);
1100
+ try {
1101
+ const relevantObjects = this._extractRelevantObjects(changes);
1102
+ if (relevantObjects.added.all.length === 0 && relevantObjects.modified.all.length === 0) {
1103
+ return;
547
1104
  }
548
- for (const obj of objects) {
1105
+ const status = optimisticId || relevantObjects.added.sortaMatches.size > 0 || relevantObjects.modified.sortaMatches.size > 0 ? "loading" : "loaded";
1106
+ const newList = [];
1107
+ let needsRevalidation = false;
1108
+ this.store.batch({
1109
+ optimisticId,
1110
+ changes
1111
+ }, (batch) => {
1112
+ const existingList = new Set(batch.read(this.cacheKey)?.value?.data);
1113
+ const toAdd = new Set(
1114
+ // easy case. objects are new to the cache and they match this filter
1115
+ relevantObjects.added.strictMatches
1116
+ );
1117
+ const toRemove = /* @__PURE__ */ new Set();
1118
+ for (const obj of relevantObjects.modified.all) {
1119
+ if (relevantObjects.modified.strictMatches.has(obj)) {
1120
+ const objectCacheKey = this.store.getCacheKey("object", obj.$objectType, obj.$primaryKey);
1121
+ if (!existingList.has(objectCacheKey)) {
1122
+ toAdd.add(obj);
1123
+ }
1124
+ continue;
1125
+ } else if (batch.optimisticWrite) {
1126
+ continue;
1127
+ } else {
1128
+ const existingObjectCacheKey = this.store.getCacheKey("object", obj.$objectType, obj.$primaryKey);
1129
+ toRemove.add(existingObjectCacheKey);
1130
+ if (relevantObjects.modified.sortaMatches.has(obj)) {
1131
+ needsRevalidation = true;
1132
+ }
1133
+ }
1134
+ }
1135
+ for (const key of existingList) {
1136
+ if (toRemove.has(key)) continue;
1137
+ newList.push(key);
1138
+ }
1139
+ for (const obj of toAdd) {
1140
+ newList.push(this.store.getCacheKey("object", obj.$objectType, obj.$primaryKey));
1141
+ }
1142
+ this._updateList(
1143
+ newList,
1144
+ /* append */
1145
+ false,
1146
+ status,
1147
+ batch
1148
+ );
1149
+ });
1150
+ if (needsRevalidation) {
1151
+ return this.revalidate(true);
1152
+ }
1153
+ return void 0;
1154
+ } finally {
1155
+ if (process.env.NODE_ENV !== "production") {
1156
+ this.logger?.child({
1157
+ methodName: "maybeUpdateAndRevalidate"
1158
+ }).debug("in finally");
1159
+ }
1160
+ }
1161
+ };
1162
+ _extractRelevantObjects(changes) {
1163
+ const relevantObjects = this.#type === "object" ? this.#extractRelevantObjectsForTypeObject(changes) : this.#extractRelevantObjectsForTypeInterface(changes);
1164
+ for (const group of Object.values(relevantObjects)) {
1165
+ for (const obj of group.all ?? []) {
549
1166
  const strictMatch = objectSortaMatchesWhereClause(obj, this.#whereClause, true);
550
1167
  if (strictMatch) {
551
- objectsToInsert.push(obj);
1168
+ group.strictMatches.add(obj);
552
1169
  } else {
553
1170
  const sortaMatch = objectSortaMatchesWhereClause(obj, this.#whereClause, false);
554
1171
  if (sortaMatch) {
555
- needsRevalidation = true;
1172
+ group.sortaMatches.add(obj);
556
1173
  }
557
1174
  }
558
1175
  }
559
1176
  }
560
- needsRevalidation ||= objectsToInsert.length > 0;
561
- if (objectsToInsert.length > 0) {
562
- this.store.batch({
563
- optimisticId
564
- }, (batch) => {
565
- this.updateList(objectsToInsert, true, "loading", batch);
566
- });
567
- }
568
- return needsRevalidation;
1177
+ return relevantObjects;
1178
+ }
1179
+ #extractRelevantObjectsForTypeInterface(changes) {
1180
+ const added = Array.from(changes.addedObjects).filter(([, object]) => {
1181
+ return this.#apiName in object[chunkT4NIFYZS_cjs.ObjectDefRef].interfaceMap;
1182
+ }).map(([, object]) => object.$as(this.#apiName));
1183
+ const modified = Array.from(changes.modifiedObjects).filter(([, object]) => {
1184
+ return this.#apiName in object[chunkT4NIFYZS_cjs.ObjectDefRef].interfaceMap;
1185
+ }).map(([, object]) => object.$as(this.#apiName));
1186
+ return {
1187
+ added: {
1188
+ all: added,
1189
+ strictMatches: /* @__PURE__ */ new Set(),
1190
+ sortaMatches: /* @__PURE__ */ new Set()
1191
+ },
1192
+ modified: {
1193
+ all: modified,
1194
+ strictMatches: /* @__PURE__ */ new Set(),
1195
+ sortaMatches: /* @__PURE__ */ new Set()
1196
+ }
1197
+ };
569
1198
  }
570
- maybeRevalidate(changedObjects) {
571
- let needsRevalidation = false;
572
- for (const [type, objects] of changedObjects.addedObjects.associations()) {
573
- if (this.cacheKey.otherKeys[0] !== type) {
574
- continue;
1199
+ #extractRelevantObjectsForTypeObject(changes) {
1200
+ return {
1201
+ added: {
1202
+ all: changes.addedObjects.get(this.cacheKey.otherKeys[API_NAME_IDX]) ?? [],
1203
+ strictMatches: /* @__PURE__ */ new Set(),
1204
+ sortaMatches: /* @__PURE__ */ new Set()
1205
+ },
1206
+ modified: {
1207
+ all: changes.modifiedObjects.get(this.cacheKey.otherKeys[API_NAME_IDX]) ?? [],
1208
+ strictMatches: /* @__PURE__ */ new Set(),
1209
+ sortaMatches: /* @__PURE__ */ new Set()
575
1210
  }
576
- for (const obj of objects) {
577
- const sortaMatch = objectSortaMatchesWhereClause(obj, this.#whereClause, false);
578
- if (sortaMatch) {
579
- needsRevalidation = true;
1211
+ };
1212
+ }
1213
+ _sortCacheKeys(objectCacheKeys, batch) {
1214
+ if (Object.keys(this.#orderBy).length > 0) {
1215
+ objectCacheKeys = objectCacheKeys.sort((a, b) => {
1216
+ for (const sortFn of this.#sortFns) {
1217
+ const ret = sortFn(batch.read(a)?.value?.$as(this.#apiName), batch.read(b)?.value?.$as(this.#apiName));
1218
+ if (ret !== 0) {
1219
+ return ret;
1220
+ }
580
1221
  }
581
- }
582
- }
583
- if (needsRevalidation) {
584
- return this.revalidate(true);
1222
+ return 0;
1223
+ });
585
1224
  }
586
- return Promise.resolve();
1225
+ return objectCacheKeys;
587
1226
  }
588
- updateList(values, append, status, batch) {
589
- let objectCacheKeys = values.map((v) => {
590
- if (v instanceof Entry) return v.cacheKey;
591
- this.store.getObjectQuery(this.#type, v.$primaryKey).writeToStore(v, "loaded", batch);
592
- return this.store.getCacheKey("object", v.$apiName, v.$primaryKey);
1227
+ registerStreamUpdates(sub) {
1228
+ const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
1229
+ methodName: "registerStreamUpdates"
1230
+ }) : this.logger;
1231
+ if (process.env.NODE_ENV !== "production") {
1232
+ logger?.child({
1233
+ methodName: "observeList"
1234
+ }).info("Subscribing from websocket");
1235
+ }
1236
+ const websocketSubscription = this.#objectSet.subscribe({
1237
+ onChange: this.#onOswChange.bind(this),
1238
+ onError: this.#onOswError.bind(this),
1239
+ onOutOfDate: this.#onOswOutOfDate.bind(this),
1240
+ onSuccessfulSubscription: this.#onOswSuccessfulSubscription.bind(this)
593
1241
  });
594
- const existingList = batch.read(this.cacheKey);
595
- if (!batch.optimisticWrite) {
596
- if (!append) {
597
- for (const objectCacheKey of existingList?.value?.data ?? []) {
598
- this.store.release(objectCacheKey);
599
- this.#toRelease.delete(objectCacheKey);
600
- }
601
- }
602
- for (const objectCacheKey of objectCacheKeys) {
603
- this.#toRelease.add(objectCacheKey);
604
- this.store.retain(objectCacheKey);
1242
+ sub.add(() => {
1243
+ if (process.env.NODE_ENV !== "production") {
1244
+ logger?.child({
1245
+ methodName: "observeList"
1246
+ }).info("Unsubscribing from websocket");
605
1247
  }
1248
+ websocketSubscription.unsubscribe();
1249
+ });
1250
+ }
1251
+ #onOswSuccessfulSubscription() {
1252
+ if (process.env.NODE_ENV !== "production") {
1253
+ this.logger?.child({
1254
+ methodName: "onSuccessfulSubscription"
1255
+ }).debug("");
606
1256
  }
607
- if (append) {
608
- objectCacheKeys = [...existingList?.value?.data ?? [], ...objectCacheKeys];
1257
+ }
1258
+ #onOswOutOfDate() {
1259
+ if (process.env.NODE_ENV !== "production") {
1260
+ this.logger?.child({
1261
+ methodName: "onOutOfDate"
1262
+ }).info("");
609
1263
  }
610
- return this.writeToStore({
611
- data: objectCacheKeys
612
- }, status, batch);
613
1264
  }
614
- writeToStore(data, status, batch) {
615
- const entry = batch.read(this.cacheKey);
616
- if (entry && deepEqual__default.default(data, entry.value)) {
617
- return batch.write(this.cacheKey, entry.value, status);
1265
+ #onOswError(errors) {
1266
+ if (this.logger) {
1267
+ this.logger?.child({
1268
+ methodName: "onError"
1269
+ }).error("subscription errors", errors);
618
1270
  }
619
- const ret = batch.write(this.cacheKey, data, status);
620
- batch.modifiedLists.add(this.cacheKey);
621
- return ret;
622
1271
  }
623
- _dispose() {
624
- console.log("DISPOSE LIST QUERY");
1272
+ #onOswChange({
1273
+ object: objOrIface,
1274
+ state
1275
+ }) {
1276
+ const logger = process.env.NODE_ENV !== "production" ? this.logger?.child({
1277
+ methodName: "registerStreamUpdates"
1278
+ }) : this.logger;
1279
+ if (process.env.NODE_ENV !== "production") {
1280
+ logger?.child({
1281
+ methodName: "onChange"
1282
+ }).debug(`Got an update of type: ${state}`, objOrIface);
1283
+ }
1284
+ if (state === "ADDED_OR_UPDATED") {
1285
+ const object = objOrIface.$apiName !== objOrIface.$objectType ? objOrIface.$as(objOrIface.$objectType) : objOrIface;
1286
+ this.store.batch({}, (batch) => {
1287
+ storeOsdkInstances(this.store, [object], batch);
1288
+ });
1289
+ } else if (state === "REMOVED") {
1290
+ this.#onOswRemoved(objOrIface, logger);
1291
+ }
1292
+ }
1293
+ #onOswRemoved(objOrIface, logger) {
625
1294
  this.store.batch({}, (batch) => {
626
- const entry = batch.read(this.cacheKey);
627
- if (entry) {
628
- for (const objectCacheKey of entry.value?.data ?? []) {
629
- this.store.release(objectCacheKey);
1295
+ const existing = batch.read(this.cacheKey);
1296
+ !existing ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "the truth value for our list should exist as we already subscribed") : invariant2__default.default(false) : void 0;
1297
+ if (existing.status === "loaded") {
1298
+ const objectCacheKey = this.store.getCacheKey("object", objOrIface.$objectType, objOrIface.$primaryKey);
1299
+ const newObjects = existing.value?.data.filter((o) => o !== objectCacheKey);
1300
+ if (newObjects?.length !== existing.value?.data.length) {
1301
+ batch.changes.registerList(this.cacheKey);
1302
+ batch.write(this.cacheKey, {
1303
+ data: newObjects ?? []
1304
+ }, "loaded");
630
1305
  }
1306
+ return;
1307
+ }
1308
+ if (process.env.NODE_ENV !== "production") {
1309
+ logger?.info("Removing an object from an object list that is in the middle of being loaded.", existing);
631
1310
  }
1311
+ this.revalidate(
1312
+ /* force */
1313
+ true
1314
+ ).catch((e) => {
1315
+ if (logger) {
1316
+ logger?.error("Uncaught error while revalidating list", e);
1317
+ } else {
1318
+ console.error("Uncaught error while revalidating list", e);
1319
+ }
1320
+ });
632
1321
  });
633
1322
  }
634
1323
  };
635
- function isListCacheKey(cacheKey, apiName) {
636
- return cacheKey.type === "list" && (apiName == null || cacheKey.otherKeys[0] === apiName);
1324
+ function removeDuplicates(objectCacheKeys, batch) {
1325
+ const visited = /* @__PURE__ */ new Set();
1326
+ objectCacheKeys = objectCacheKeys.filter((key) => {
1327
+ batch.read(key);
1328
+ if (visited.has(key)) {
1329
+ return false;
1330
+ }
1331
+ visited.add(key);
1332
+ return true;
1333
+ });
1334
+ return objectCacheKeys;
637
1335
  }
638
- var ObjectQuery = class extends Query {
639
- #apiName;
640
- #pk;
641
- constructor(store, subject, type, pk, cacheKey, opts) {
642
- super(store, subject, opts, cacheKey);
643
- this.#apiName = type;
644
- this.#pk = pk;
645
- }
646
- _createConnectable(subject) {
647
- return rxjs.connectable(subject.pipe(rxjs.map((x) => {
648
- return {
649
- status: x.status,
650
- object: x.value,
651
- lastUpdated: x.lastUpdated,
652
- isOptimistic: x.isOptimistic
653
- };
654
- })), {
655
- connector: () => new rxjs.BehaviorSubject({
656
- status: "init",
657
- object: undefined,
658
- lastUpdated: 0,
659
- isOptimistic: false
660
- })
661
- });
662
- }
663
- async _fetch() {
664
- const objectSet = this.store.client({
665
- type: "object",
666
- apiName: this.#apiName
667
- });
668
- const obj = await objectSet.fetchOne(this.#pk);
669
- this.store.batch({}, (batch) => {
670
- this.writeToStore(obj, "loaded", batch);
1336
+ function createOrderBySortFns(orderBy) {
1337
+ return Object.entries(orderBy).map(([key, order]) => {
1338
+ return (a, b) => {
1339
+ const aValue = a?.[key];
1340
+ const bValue = b?.[key];
1341
+ if (aValue == null && bValue == null) {
1342
+ return 0;
1343
+ }
1344
+ if (aValue == null) {
1345
+ return 1;
1346
+ }
1347
+ if (bValue == null) {
1348
+ return -1;
1349
+ }
1350
+ const m = order === "asc" ? -1 : 1;
1351
+ return aValue < bValue ? m : aValue > bValue ? -m : 0;
1352
+ };
1353
+ });
1354
+ }
1355
+ async function reloadDataAsFullObjects(client, data) {
1356
+ const groups = groupBy__default.default(data, (x) => x.$objectType);
1357
+ const objectTypeToPrimaryKeyToObject = Object.fromEntries(await Promise.all(Object.entries(groups).map(async ([apiName, objects]) => {
1358
+ const objectDef = objects[0][chunkT4NIFYZS_cjs.UnderlyingOsdkObject][chunkT4NIFYZS_cjs.ObjectDefRef];
1359
+ const where = {
1360
+ [objectDef.primaryKeyApiName]: {
1361
+ $in: objects.map((x) => x.$primaryKey)
1362
+ }
1363
+ };
1364
+ const result = await client(objectDef).where(where).fetchPage();
1365
+ return [apiName, Object.fromEntries(result.data.map((x) => [x.$primaryKey, x]))];
1366
+ })));
1367
+ data = data.map((obj) => {
1368
+ !objectTypeToPrimaryKeyToObject[obj.$objectType][obj.$primaryKey] ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Could not find object ${obj.$objectType} ${obj.$primaryKey}`) : invariant2__default.default(false) : void 0;
1369
+ return objectTypeToPrimaryKeyToObject[obj.$objectType][obj.$primaryKey];
1370
+ });
1371
+ return data;
1372
+ }
1373
+ function isListCacheKey(cacheKey) {
1374
+ return cacheKey.type === "list";
1375
+ }
1376
+ var defaultMakeData = () => /* @__PURE__ */ Object.create(null);
1377
+ var WeakRefTrie = class {
1378
+ #finalizer = new FinalizationRegistry((orderBy) => {
1379
+ this.#trie.removeArray(Object.entries(orderBy).flat());
1380
+ });
1381
+ #trie;
1382
+ constructor(makeData = defaultMakeData) {
1383
+ this.#trie = new trie.Trie(false, (array) => {
1384
+ const data = makeData(array);
1385
+ this.#finalizer.register(data, array);
1386
+ return new WeakRef(data);
671
1387
  });
672
1388
  }
673
- writeToStore(data, status, batch) {
674
- const entry = batch.read(this.cacheKey);
675
- if (entry && deepEqual__default.default(data, entry.value)) {
676
- return batch.write(this.cacheKey, entry.value, status);
677
- }
678
- const ret = batch.write(this.cacheKey, data, status);
679
- if (entry) {
680
- batch.modifiedObjects.add(this.cacheKey);
681
- } else {
682
- batch.addedObjects.add(this.cacheKey);
1389
+ lookupArray(array) {
1390
+ const maybe = this.#trie.lookupArray(array);
1391
+ let ret = maybe.deref();
1392
+ if (maybe && !ret) {
1393
+ this.#trie.removeArray(array);
1394
+ ret = this.#trie.lookupArray(array).deref();
683
1395
  }
684
1396
  return ret;
685
1397
  }
686
- };
687
-
688
- // src/observable/internal/OptimisticId.ts
689
- function createOptimisticId() {
690
- if (process.env.NODE_ENV !== "production") {
691
- if (createOptimisticId.counter === undefined) {
692
- createOptimisticId.counter = 0;
1398
+ peekArray(array) {
1399
+ const maybe = this.#trie.peekArray(array);
1400
+ const ret = maybe?.deref();
1401
+ if (maybe && !ret) {
1402
+ this.#trie.removeArray(array);
693
1403
  }
694
- return {
695
- __optimisticId: createOptimisticId.counter++
696
- };
1404
+ return ret;
697
1405
  }
698
- return /* @__PURE__ */ Object.create(null);
699
- }
700
-
701
- // src/observable/internal/OptimisticJob.ts
702
- var OptimisticJob = class {
703
- #result;
704
- constructor(store, optimisticId) {
705
- const updatedObjects = [];
706
- const addedObjects = [];
707
- this.getResult = () => {
708
- return this.#result ??= (async () => {
709
- const changes = {
710
- addedObjects: new mnemonist.MultiMap(),
711
- modifiedObjects: new mnemonist.MultiMap()
712
- };
713
- const settled = await Promise.allSettled(addedObjects);
714
- for (const added of settled) {
715
- if (added.status === "fulfilled") {
716
- changes.addedObjects.set(added.value.$objectType, added.value);
717
- } else {
718
- throw added;
719
- }
720
- }
721
- for (const modified of updatedObjects) {
722
- changes.modifiedObjects.set(modified.$apiName, modified);
723
- }
724
- store.batch({
725
- optimisticId
726
- }, (batch) => {
727
- for (const a of ["addedObjects", "modifiedObjects"]) {
728
- for (const b of changes[a].values()) {
729
- store.getObjectQuery(b.$objectType, b.$primaryKey).writeToStore(b, "loading", batch);
730
- }
731
- }
732
- });
733
- return changes;
734
- })();
735
- };
736
- this.context = {
737
- updateObject(value) {
738
- updatedObjects.push(value);
739
- return this;
740
- },
741
- createObject(type, pk, properties) {
742
- const create = store.client[chunkX7WGNFZ4_cjs.additionalContext].objectFactory2(store.client[chunkX7WGNFZ4_cjs.additionalContext], [{
743
- $primaryKey: pk,
744
- $apiName: type.apiName,
745
- $objectType: type.apiName,
746
- ...properties
747
- }], undefined).then((x) => x[0]);
748
- addedObjects.push(create);
749
- return this;
750
- }
751
- };
1406
+ removeArray(array) {
1407
+ return this.#trie.removeArray(array)?.deref();
752
1408
  }
753
1409
  };
754
- function runOptimisticJob(store, optimisticUpdate) {
755
- if (!optimisticUpdate) {
756
- return () => Promise.resolve();
757
- }
758
- const optimisticId = createOptimisticId();
759
- const job = new OptimisticJob(store, optimisticId);
760
- optimisticUpdate(job.context);
761
- const optimisticApplicationDone = job.getResult().then((result) => {
762
- store.maybeUpdateLists(result, optimisticId);
1410
+ var OrderByCanonicalizer = class {
1411
+ #trie = new WeakRefTrie((array) => {
1412
+ const pairs = array.reduce(function(result, _, index, array2) {
1413
+ if (index % 2 === 0 && array2[index] != null) {
1414
+ result.push(array2.slice(index, index + 2));
1415
+ }
1416
+ return result;
1417
+ }, []);
1418
+ let data = Object.fromEntries(pairs);
1419
+ if (process.env.NODE_ENV !== "production") {
1420
+ data = Object.freeze(data);
1421
+ }
1422
+ return data;
763
1423
  });
764
- return () => {
765
- return optimisticApplicationDone.finally(() => {
766
- store.removeLayer(optimisticId);
767
- });
1424
+ canonicalize = (orderBy) => {
1425
+ const strings = Object.entries(orderBy).flat();
1426
+ return this.#trie.lookupArray(strings);
768
1427
  };
769
- }
1428
+ };
770
1429
 
771
1430
  // src/observable/internal/RefCounts.ts
772
1431
  var RefCounts = class {
@@ -792,8 +1451,8 @@ var RefCounts = class {
792
1451
  }
793
1452
  }
794
1453
  release(key) {
795
- const count = this.refCounts.get(key) ?? 0;
796
- if (count === 1) {
1454
+ const count = this.refCounts.get(key);
1455
+ if (count === void 0) ; else if (count === 1) {
797
1456
  this.refCounts.delete(key);
798
1457
  this.gcMap.set(key, Date.now() + this.keepAlive);
799
1458
  } else {
@@ -814,6 +1473,14 @@ var RefCounts = class {
814
1473
  }
815
1474
  };
816
1475
  var WhereClauseCanonicalizer = class {
1476
+ /**
1477
+ * This is a shortcut cache for any WhereClause's that we have
1478
+ * seen and already canonicalized. The theory behind this
1479
+ * is that well behaving React applications will either `useMemo`
1480
+ * their where clause, or store it in state or pass it through as
1481
+ * props such that we are likely to get the same WhereClause
1482
+ * object multiple times and we can skip unnecessary work.
1483
+ */
817
1484
  #cache = /* @__PURE__ */ new WeakMap();
818
1485
  /**
819
1486
  * This is a trie that stores the sorted collapsed keys of a where clause to
@@ -831,14 +1498,14 @@ var WhereClauseCanonicalizer = class {
831
1498
  return this.#cache.get(where);
832
1499
  }
833
1500
  const keysSet = /* @__PURE__ */ new Set();
834
- const tmpCanon = this.#toCanon(where, keysSet);
1501
+ const calculatedCanon = this.#toCanon(where, keysSet);
835
1502
  const cacheKey = this.#trie.lookupArray(Array.from(keysSet).sort());
836
1503
  const lookupEntry = this.#existingOptions.get(cacheKey) ?? {
837
1504
  options: []
838
1505
  };
839
1506
  this.#existingOptions.set(cacheKey, lookupEntry);
840
- const canon = lookupEntry.options.find((ref) => deepEqual__default.default(ref.deref(), tmpCanon))?.deref() ?? tmpCanon;
841
- if (canon === tmpCanon) {
1507
+ const canon = lookupEntry.options.find((ref) => deepEqual__default.default(ref.deref(), calculatedCanon))?.deref() ?? calculatedCanon;
1508
+ if (canon === calculatedCanon) {
842
1509
  lookupEntry.options.push(new WeakRef(canon));
843
1510
  }
844
1511
  this.#cache.set(where, canon);
@@ -847,8 +1514,8 @@ var WhereClauseCanonicalizer = class {
847
1514
  #toCanon = (where, set = /* @__PURE__ */ new Set()) => {
848
1515
  if ("$and" in where) {
849
1516
  if (process.env.NODE_ENV !== "production") {
850
- !Array.isArray(where.$and) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected $and to be an array") : invariant2__default.default(false) : undefined;
851
- !(Object.keys(where).length === 1) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected only $and to be present") : invariant2__default.default(false) : undefined;
1517
+ !Array.isArray(where.$and) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected $and to be an array") : invariant2__default.default(false) : void 0;
1518
+ !(Object.keys(where).length === 1) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "expected only $and to be present") : invariant2__default.default(false) : void 0;
852
1519
  }
853
1520
  if (where.$and.length === 0) {
854
1521
  return {};
@@ -871,28 +1538,36 @@ var WhereClauseCanonicalizer = class {
871
1538
  };
872
1539
 
873
1540
  // src/observable/internal/Store.ts
874
- var ACTION_DELAY = process.env.NODE_ENV === "production" ? 0 : 1e3;
875
1541
  function createInitEntry(cacheKey) {
876
1542
  return {
877
1543
  cacheKey,
878
1544
  status: "init",
879
- value: undefined,
1545
+ value: void 0,
880
1546
  lastUpdated: 0
881
1547
  };
882
1548
  }
883
1549
  var Store = class {
884
1550
  whereCanonicalizer = new WhereClauseCanonicalizer();
885
- #truthLayer = new Layer(undefined, undefined);
1551
+ orderByCanonicalizer = new OrderByCanonicalizer();
1552
+ #truthLayer = new Layer(void 0, void 0);
886
1553
  #topLayer;
887
- #queries = /* @__PURE__ */ new WeakMap();
1554
+ /** @internal */
1555
+ // we can use a regular Map here because the refCounting will
1556
+ // handle cleanup.
1557
+ #queries = /* @__PURE__ */ new Map();
888
1558
  #cacheKeyToSubject = /* @__PURE__ */ new WeakMap();
889
1559
  #cacheKeys;
890
1560
  #refCounts = new RefCounts(6e4, (k) => this.#cleanupCacheKey(k));
1561
+ // we are currently only using this for debug logging and should just remove it in the future if that
1562
+ // continues to be true
891
1563
  #finalizationRegistry;
892
1564
  constructor(client) {
893
1565
  this.client = client;
1566
+ this.logger = client[chunk37QC7LR3_cjs.additionalContext].logger?.child({}, {
1567
+ msgPrefix: "Store"
1568
+ });
894
1569
  this.#topLayer = this.#truthLayer;
895
- this.#cacheKeys = new CacheKeys(this.whereCanonicalizer, (k) => {
1570
+ this.#cacheKeys = new CacheKeys(this.whereCanonicalizer, this.orderByCanonicalizer, (k) => {
896
1571
  this.#refCounts.register(k);
897
1572
  });
898
1573
  setInterval(() => {
@@ -914,7 +1589,7 @@ var Store = class {
914
1589
  const subject = this.peekSubject(key);
915
1590
  this.#cacheKeys.remove(key);
916
1591
  if (process.env.NODE_ENV !== "production") {
917
- !subject ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false) : invariant2__default.default(false) : undefined;
1592
+ !subject ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false) : invariant2__default.default(false) : void 0;
918
1593
  }
919
1594
  if (subject) {
920
1595
  subject.complete();
@@ -923,11 +1598,11 @@ var Store = class {
923
1598
  this.#queries.get(key)?.dispose();
924
1599
  this.#queries.delete(key);
925
1600
  };
926
- applyAction = (action, args, opts) => {
927
- return new ActionApplication(this).applyAction(action, args, opts);
1601
+ applyAction = async (action, args, opts) => {
1602
+ return await new ActionApplication(this).applyAction(action, args, opts);
928
1603
  };
929
1604
  removeLayer(layerId) {
930
- !(layerId != null) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "undefined is the reserved layerId for the truth layer") : invariant2__default.default(false) : undefined;
1605
+ !(layerId != null) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "undefined is the reserved layerId for the truth layer") : invariant2__default.default(false) : void 0;
931
1606
  let currentLayer = this.#topLayer;
932
1607
  const cacheKeys = /* @__PURE__ */ new Map();
933
1608
  while (currentLayer != null && currentLayer.parentLayer != null) {
@@ -970,63 +1645,73 @@ var Store = class {
970
1645
  }
971
1646
  return subject;
972
1647
  };
1648
+ canonicalizeWhereClause(where) {
1649
+ return this.whereCanonicalizer.canonicalize(where);
1650
+ }
973
1651
  observeObject(apiName, pk, options, subFn) {
974
1652
  if (typeof apiName !== "string") {
975
1653
  apiName = apiName.apiName;
976
1654
  }
977
1655
  const query = this.getObjectQuery(apiName, pk);
978
- this.#refCounts.retain(query.cacheKey);
1656
+ this.retain(query.cacheKey);
979
1657
  if (options.mode !== "offline") {
980
- void query.revalidate(options.mode === "force");
1658
+ query.revalidate(options.mode === "force").catch((e) => {
1659
+ subFn.error(e);
1660
+ if (this.logger) {
1661
+ this.logger.error("Unhandled error in observeObject", e);
1662
+ } else {
1663
+ throw e;
1664
+ }
1665
+ });
981
1666
  }
982
- const sub = query.subscribe({
983
- next: subFn
984
- });
1667
+ const sub = query.subscribe(subFn);
985
1668
  return {
986
1669
  unsubscribe: () => {
987
1670
  sub.unsubscribe();
988
- this.#refCounts.release(query.cacheKey);
1671
+ this.release(query.cacheKey);
989
1672
  }
990
1673
  };
991
1674
  }
992
- observeList(apiName, where, options, subFn) {
993
- if (typeof apiName !== "string") {
994
- apiName = apiName.apiName;
995
- }
996
- const query = this.getListQuery(apiName, where, options);
997
- this.#refCounts.retain(query.cacheKey);
1675
+ observeList(options, subFn) {
1676
+ const query = this.getListQuery(options.type, options.where ?? {}, options.orderBy ?? {}, options);
1677
+ this.retain(query.cacheKey);
998
1678
  if (options.mode !== "offline") {
999
- void query.revalidate(options.mode === "force");
1679
+ query.revalidate(options.mode === "force").catch((x) => {
1680
+ subFn.error(x);
1681
+ });
1682
+ }
1683
+ const sub = query.subscribe(subFn);
1684
+ if (options.streamUpdates) {
1685
+ query.registerStreamUpdates(sub);
1000
1686
  }
1001
- const sub = query.subscribe({
1002
- next: subFn
1003
- });
1004
1687
  return {
1005
1688
  unsubscribe: () => {
1006
1689
  sub.unsubscribe();
1007
- this.#refCounts.release(query.cacheKey);
1690
+ this.release(query.cacheKey);
1008
1691
  }
1009
1692
  };
1010
1693
  }
1011
- #peekQuery(cacheKey) {
1694
+ peekQuery(cacheKey) {
1012
1695
  return this.#queries.get(cacheKey);
1013
1696
  }
1014
1697
  #getQuery(cacheKey, createQuery) {
1015
- let query = this.#peekQuery(cacheKey);
1698
+ let query = this.peekQuery(cacheKey);
1016
1699
  if (!query) {
1017
1700
  query = createQuery();
1018
1701
  this.#queries.set(cacheKey, query);
1019
1702
  }
1020
1703
  return query;
1021
1704
  }
1022
- getListQuery(apiName, where, opts, peek = false) {
1023
- if (typeof apiName !== "string") {
1024
- apiName = apiName.apiName;
1025
- }
1705
+ getListQuery(def, where, orderBy, opts) {
1706
+ const {
1707
+ apiName,
1708
+ type
1709
+ } = def;
1026
1710
  const canonWhere = this.whereCanonicalizer.canonicalize(where);
1027
- const listCacheKey = this.getCacheKey("list", apiName, canonWhere);
1711
+ const canonOrderBy = this.orderByCanonicalizer.canonicalize(orderBy);
1712
+ const listCacheKey = this.getCacheKey("list", type, apiName, canonWhere, canonOrderBy);
1028
1713
  return this.#getQuery(listCacheKey, () => {
1029
- return new ListQuery(this, this.getSubject(listCacheKey), apiName, canonWhere, listCacheKey, opts);
1714
+ return new ListQuery(this, this.getSubject(listCacheKey), type, apiName, canonWhere, canonOrderBy, listCacheKey, opts);
1030
1715
  });
1031
1716
  }
1032
1717
  getObjectQuery(apiName, pk) {
@@ -1038,23 +1723,17 @@ var Store = class {
1038
1723
  dedupeInterval: 0
1039
1724
  }));
1040
1725
  }
1041
- getObject(apiName, pk) {
1042
- if (typeof apiName !== "string") {
1043
- apiName = apiName.apiName;
1044
- }
1045
- const objectCacheKey = this.getCacheKey("object", apiName, pk);
1046
- const objEntry = this.#topLayer.get(objectCacheKey);
1047
- return objEntry?.value;
1726
+ getValue(cacheKey) {
1727
+ return this.#topLayer.get(cacheKey);
1048
1728
  }
1049
1729
  batch = ({
1050
- optimisticId
1730
+ optimisticId,
1731
+ changes = createChangedObjects()
1051
1732
  }, batchFn) => {
1052
- !(optimisticId === undefined || !!optimisticId) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "optimistic must be undefined or not falsy") : invariant2__default.default(false) : undefined;
1053
- let needsLayer = optimisticId !== undefined;
1733
+ !(optimisticId === void 0 || !!optimisticId) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "optimistic must be undefined or not falsy") : invariant2__default.default(false) : void 0;
1734
+ let needsLayer = optimisticId !== void 0;
1054
1735
  const batchContext = {
1055
- addedObjects: /* @__PURE__ */ new Set(),
1056
- modifiedObjects: /* @__PURE__ */ new Set(),
1057
- modifiedLists: /* @__PURE__ */ new Set(),
1736
+ changes,
1058
1737
  createLayerIfNeeded: () => {
1059
1738
  if (needsLayer) {
1060
1739
  this.#topLayer = this.#topLayer.addLayer(optimisticId);
@@ -1066,16 +1745,12 @@ var Store = class {
1066
1745
  const oldTopValue = this.#topLayer.get(cacheKey);
1067
1746
  if (optimisticId) batchContext.createLayerIfNeeded();
1068
1747
  const writeLayer = optimisticId ? this.#topLayer : this.#truthLayer;
1069
- const newValue = {
1070
- cacheKey,
1071
- value,
1072
- lastUpdated: Date.now(),
1073
- status
1074
- };
1748
+ const newValue = new Entry(cacheKey, value, Date.now(), status);
1075
1749
  writeLayer.set(cacheKey, newValue);
1076
1750
  const newTopValue = this.#topLayer.get(cacheKey);
1077
1751
  if (oldTopValue !== newTopValue) {
1078
1752
  this.#cacheKeyToSubject.get(cacheKey)?.next({
1753
+ // eslint-disable-next-line @typescript-eslint/no-misused-spread
1079
1754
  ...newValue,
1080
1755
  isOptimistic: newTopValue?.value !== this.#truthLayer.get(cacheKey)?.value
1081
1756
  });
@@ -1087,76 +1762,87 @@ var Store = class {
1087
1762
  }
1088
1763
  };
1089
1764
  const retVal = batchFn(batchContext);
1765
+ this.maybeRevalidateQueries(changes, optimisticId).catch((e) => {
1766
+ if (this.logger) {
1767
+ this.logger.error("Unhandled error in batch", e);
1768
+ } else {
1769
+ console.error("Unhandled error in batch", e);
1770
+ throw e;
1771
+ }
1772
+ });
1090
1773
  return {
1091
1774
  batchResult: batchContext,
1092
- retVal
1775
+ retVal,
1776
+ changes: batchContext.changes
1093
1777
  };
1094
1778
  };
1095
1779
  invalidateObject(apiName, pk) {
1096
1780
  if (typeof apiName !== "string") {
1097
1781
  apiName = apiName.apiName;
1098
1782
  }
1099
- const query = this.getObjectQuery(apiName, pk);
1100
- return query.revalidate(true);
1101
- }
1102
- maybeRevalidateLists(changes) {
1103
- for (const [cacheKey, v] of this.#truthLayer.entries()) {
1104
- if (isListCacheKey(cacheKey)) {
1105
- void this.#peekQuery(cacheKey)?.maybeRevalidate(changes);
1106
- }
1107
- }
1783
+ return this.getObjectQuery(apiName, pk).revalidate(
1784
+ /* force */
1785
+ true
1786
+ );
1108
1787
  }
1109
- maybeUpdateLists(changes, optimisticId) {
1110
- for (const [cacheKey, v] of this.#truthLayer.entries()) {
1111
- if (isListCacheKey(cacheKey)) {
1112
- void this.#peekQuery(cacheKey)?.maybeUpdate(changes, optimisticId);
1788
+ async maybeRevalidateQueries(changes, optimisticId) {
1789
+ if (changes.isEmpty()) {
1790
+ if (process.env.NODE_ENV !== "production") {
1791
+ this.logger?.child({
1792
+ methodName: "maybeRevalidateQueries"
1793
+ }).debug("No changes, aborting");
1113
1794
  }
1795
+ return;
1114
1796
  }
1115
- }
1116
- invalidateObjectType(apiName) {
1117
- if (typeof apiName !== "string") {
1118
- apiName = apiName.apiName;
1797
+ if (process.env.NODE_ENV !== "production") {
1798
+ this.logger?.child({
1799
+ methodName: "maybeRevalidateQueries"
1800
+ }).debug(DEBUG_ONLY__changesToString(changes), {
1801
+ optimisticId
1802
+ });
1119
1803
  }
1120
- for (const [cacheKey, v] of this.#truthLayer.entries()) {
1121
- if (isListCacheKey(cacheKey, apiName)) {
1122
- void this.#peekQuery(cacheKey)?.revalidate(true);
1804
+ try {
1805
+ const promises = [];
1806
+ for (const cacheKey of this.#queries.keys()) {
1807
+ const promise = this.peekQuery(cacheKey)?.maybeUpdateAndRevalidate?.(changes, optimisticId);
1808
+ if (promise) promises.push(promise);
1809
+ }
1810
+ await Promise.all(promises);
1811
+ } finally {
1812
+ if (process.env.NODE_ENV !== "production") {
1813
+ this.logger?.child({
1814
+ methodName: "maybeRevalidateQueries"
1815
+ }).debug("in finally", DEBUG_ONLY__changesToString(changes));
1123
1816
  }
1124
1817
  }
1125
1818
  }
1126
- invalidateList(apiName, where) {
1819
+ /**
1820
+ * @param apiName
1821
+ * @param changes The changes we know about / to update
1822
+ * @returns
1823
+ */
1824
+ invalidateObjectType(apiName, changes) {
1127
1825
  if (typeof apiName !== "string") {
1128
1826
  apiName = apiName.apiName;
1129
1827
  }
1130
- const cacheKey = this.getCacheKey("list", apiName, where);
1131
- void this.#peekQuery(cacheKey)?.revalidate(true);
1132
- }
1133
- updateObject(apiName, value, {
1134
- optimisticId
1135
- } = {}) {
1136
- if (typeof apiName !== "string") {
1137
- apiName = apiName.apiName;
1828
+ if (process.env.NODE_ENV !== "production") {
1829
+ this.logger?.child({
1830
+ methodName: "invalidateObjectType"
1831
+ }).info(changes ? DEBUG_ONLY__changesToString(changes) : void 0);
1138
1832
  }
1139
- const query = this.getObjectQuery(apiName, value.$primaryKey);
1140
- return this.batch({
1141
- optimisticId
1142
- }, (batch) => {
1143
- return query.writeToStore(value, "loaded", batch);
1144
- }).retVal.value;
1145
- }
1146
- updateList(apiName, where, values, {
1147
- optimisticId
1148
- } = {}, opts = {
1149
- dedupeInterval: 0
1150
- }) {
1151
- if (typeof apiName !== "string") {
1152
- apiName = apiName.apiName;
1833
+ const promises = [];
1834
+ for (const cacheKey of this.#truthLayer.keys()) {
1835
+ if (isListCacheKey(cacheKey)) {
1836
+ if (!changes || !changes.modified.has(cacheKey)) {
1837
+ const promise = this.peekQuery(cacheKey)?.revalidate(true);
1838
+ if (promise) {
1839
+ promises.push(promise);
1840
+ changes?.modified.add(cacheKey);
1841
+ }
1842
+ }
1843
+ }
1153
1844
  }
1154
- const query = this.getListQuery(apiName, where, opts);
1155
- this.batch({
1156
- optimisticId
1157
- }, (b) => {
1158
- query.updateList(values, false, "loaded", b);
1159
- });
1845
+ return Promise.all(promises).then(() => void 0);
1160
1846
  }
1161
1847
  retain(cacheKey) {
1162
1848
  this.#refCounts.retain(cacheKey);
@@ -1165,84 +1851,52 @@ var Store = class {
1165
1851
  this.#refCounts.release(cacheKey);
1166
1852
  }
1167
1853
  };
1168
- var ActionApplication = class {
1169
- constructor(store) {
1170
- this.store = store;
1171
- }
1172
- applyAction = (action, args, {
1173
- optimisticUpdate
1174
- } = {}) => {
1175
- const removeOptimisticResult = runOptimisticJob(this.store, optimisticUpdate);
1176
- return (async () => {
1177
- try {
1178
- const actionResults = await this.store.client(action).applyAction(args, {
1179
- $returnEdits: true
1180
- });
1181
- if (ACTION_DELAY > 0) {
1182
- console.log("action done, pausing");
1183
- await delay(ACTION_DELAY);
1184
- console.log("action done, pausing done");
1185
- }
1186
- await this.#invalidateActionEditResponse(actionResults);
1187
- return actionResults;
1188
- } finally {
1189
- await removeOptimisticResult();
1190
- }
1191
- })();
1192
- };
1193
- #invalidateActionEditResponse = (value) => {
1194
- const typesToInvalidate = /* @__PURE__ */ new Set();
1195
- let promisesToWait = [];
1196
- if (value.type === "edits") {
1197
- for (const obj of value.modifiedObjects) {
1198
- promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
1199
- }
1200
- for (const obj of value.addedObjects) {
1201
- promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
1202
- typesToInvalidate.add(obj.objectType);
1203
- }
1204
- promisesToWait = [Promise.allSettled(promisesToWait).then(() => {
1205
- const changes2 = this.#changesFromActionEditResponse(value);
1206
- this.store.maybeRevalidateLists(changes2);
1207
- })];
1208
- } else {
1209
- for (const apiName of value.editedObjectTypes) {
1210
- typesToInvalidate.add(apiName.toString());
1211
- }
1212
- }
1213
- return Promise.allSettled(promisesToWait).then(() => {
1214
- for (const objectType of typesToInvalidate) {
1215
- this.store.invalidateObjectType(objectType);
1216
- }
1217
- return value;
1218
- });
1219
- };
1220
- #changesFromActionEditResponse = (value) => {
1221
- const changes = createChangedObjects();
1222
- for (const changeType of ["addedObjects", "modifiedObjects"]) {
1223
- for (const {
1224
- objectType,
1225
- primaryKey
1226
- } of value[changeType] ?? []) {
1227
- const obj = this.store.getObject(objectType, primaryKey);
1228
- if (obj) {
1229
- changes[changeType].set(objectType, obj);
1230
- }
1231
- }
1232
- }
1233
- return changes;
1234
- };
1235
- };
1236
1854
 
1237
1855
  // src/observable/ObservableClient.ts
1238
1856
  function createObservableClient(client) {
1239
1857
  return new ObservableClientImpl(new Store(client));
1240
1858
  }
1241
1859
 
1860
+ // src/public-utils/osdkConfig.ts
1861
+ function getMetaTagContent(name) {
1862
+ const element = document.querySelector(`meta[name="${name}"]`);
1863
+ const val = element ? element.getAttribute("content") : null;
1864
+ if (val == null) {
1865
+ throw new Error(`Missing meta tag: ${name}`);
1866
+ }
1867
+ return val;
1868
+ }
1869
+ function getViteEnvVar(name) {
1870
+ const val = undefined[name];
1871
+ if (val == null) {
1872
+ throw new Error(`Missing environment variable: ${name}`);
1873
+ }
1874
+ return val;
1875
+ }
1876
+ function isProduction() {
1877
+ return process.env.NODE_ENV === "production";
1878
+ }
1879
+ function getConfigValue(metaTagName, viteEnvVarName) {
1880
+ return isProduction() ? getMetaTagContent(metaTagName) : getViteEnvVar(viteEnvVarName);
1881
+ }
1882
+ function getOntologyRid(ontologyRid) {
1883
+ return isProduction() ? getMetaTagContent("osdk-ontologyRid") : ontologyRid;
1884
+ }
1885
+ function getOsdkConfig(ontologyRid) {
1886
+ return {
1887
+ clientId: getConfigValue("osdk-clientId", "VITE_FOUNDRY_CLIENT_ID"),
1888
+ redirectUrl: getConfigValue("osdk-redirectUrl", "VITE_FOUNDRY_REDIRECT_URL"),
1889
+ foundryUrl: getConfigValue("osdk-foundryUrl", "VITE_FOUNDRY_API_URL"),
1890
+ ontologyRid: getOntologyRid(ontologyRid)
1891
+ };
1892
+ }
1893
+
1242
1894
  Object.defineProperty(exports, "augment", {
1243
1895
  enumerable: true,
1244
- get: function () { return chunkX7WGNFZ4_cjs.augment; }
1896
+ get: function () { return chunk37QC7LR3_cjs.augment; }
1245
1897
  });
1246
1898
  exports.createObservableClient = createObservableClient;
1899
+ exports.getMetaTagContent = getMetaTagContent;
1900
+ exports.getOsdkConfig = getOsdkConfig;
1247
1901
  //# sourceMappingURL=unstable-do-not-use.cjs.map
1248
1902
  //# sourceMappingURL=unstable-do-not-use.cjs.map