jazz-tools 0.18.6 → 0.18.7

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 (84) hide show
  1. package/.turbo/turbo-build.log +49 -49
  2. package/CHANGELOG.md +17 -0
  3. package/dist/better-auth/auth/server.d.ts.map +1 -1
  4. package/dist/better-auth/auth/server.js +8 -4
  5. package/dist/better-auth/auth/server.js.map +1 -1
  6. package/dist/{chunk-45VKEOXG.js → chunk-CFAY3FMQ.js} +70 -21
  7. package/dist/chunk-CFAY3FMQ.js.map +1 -0
  8. package/dist/index.js +1 -1
  9. package/dist/inspector/{custom-element-IBHKHN27.js → custom-element-G6SPZEBR.js} +292 -31
  10. package/dist/inspector/custom-element-G6SPZEBR.js.map +1 -0
  11. package/dist/inspector/index.d.ts +1 -1
  12. package/dist/inspector/index.js +302 -41
  13. package/dist/inspector/index.js.map +1 -1
  14. package/dist/inspector/register-custom-element.js +1 -1
  15. package/dist/inspector/ui/button.d.ts +1 -1
  16. package/dist/inspector/ui/button.d.ts.map +1 -1
  17. package/dist/inspector/ui/heading.d.ts +2 -1
  18. package/dist/inspector/ui/heading.d.ts.map +1 -1
  19. package/dist/inspector/ui/input.d.ts.map +1 -1
  20. package/dist/inspector/ui/modal.d.ts +16 -0
  21. package/dist/inspector/ui/modal.d.ts.map +1 -0
  22. package/dist/inspector/viewer/delete-local-data.d.ts +2 -0
  23. package/dist/inspector/viewer/delete-local-data.d.ts.map +1 -0
  24. package/dist/inspector/viewer/{inpsector-button.d.ts → inspector-button.d.ts} +1 -1
  25. package/dist/inspector/viewer/{inpsector-button.d.ts.map → inspector-button.d.ts.map} +1 -1
  26. package/dist/inspector/viewer/new-app.d.ts +1 -1
  27. package/dist/inspector/viewer/new-app.d.ts.map +1 -1
  28. package/dist/react/hooks.d.ts +1 -1
  29. package/dist/react/hooks.d.ts.map +1 -1
  30. package/dist/react/index.d.ts +1 -1
  31. package/dist/react/index.d.ts.map +1 -1
  32. package/dist/react/index.js +3 -1
  33. package/dist/react/index.js.map +1 -1
  34. package/dist/react-core/hooks.d.ts +133 -0
  35. package/dist/react-core/hooks.d.ts.map +1 -1
  36. package/dist/react-core/index.js +80 -16
  37. package/dist/react-core/index.js.map +1 -1
  38. package/dist/react-core/tests/useCoStateWithSelector.test.d.ts +2 -0
  39. package/dist/react-core/tests/useCoStateWithSelector.test.d.ts.map +1 -0
  40. package/dist/react-native-core/hooks.d.ts +1 -1
  41. package/dist/react-native-core/hooks.d.ts.map +1 -1
  42. package/dist/react-native-core/index.js +3 -1
  43. package/dist/react-native-core/index.js.map +1 -1
  44. package/dist/testing.js +1 -1
  45. package/dist/tools/coValues/CoValueBase.d.ts +14 -0
  46. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  47. package/dist/tools/coValues/coMap.d.ts +0 -12
  48. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  49. package/dist/tools/implementation/createContext.d.ts +2 -1
  50. package/dist/tools/implementation/createContext.d.ts.map +1 -1
  51. package/dist/tools/tests/utils.d.ts.map +1 -1
  52. package/dist/worker/index.d.ts +4 -0
  53. package/dist/worker/index.d.ts.map +1 -1
  54. package/dist/worker/index.js +4 -2
  55. package/dist/worker/index.js.map +1 -1
  56. package/package.json +6 -4
  57. package/src/better-auth/auth/server.ts +8 -4
  58. package/src/better-auth/auth/tests/server.test.ts +2 -2
  59. package/src/inspector/index.tsx +1 -1
  60. package/src/inspector/ui/button.tsx +15 -1
  61. package/src/inspector/ui/heading.tsx +7 -2
  62. package/src/inspector/ui/input.tsx +6 -2
  63. package/src/inspector/ui/modal.tsx +158 -0
  64. package/src/inspector/viewer/delete-local-data.tsx +101 -0
  65. package/src/inspector/viewer/new-app.tsx +3 -1
  66. package/src/react/hooks.tsx +1 -0
  67. package/src/react/index.ts +1 -0
  68. package/src/react-core/hooks.ts +162 -0
  69. package/src/react-core/tests/useCoStateWithSelector.test.ts +149 -0
  70. package/src/react-native-core/hooks.tsx +1 -0
  71. package/src/tools/coValues/CoValueBase.ts +32 -0
  72. package/src/tools/coValues/coList.ts +35 -0
  73. package/src/tools/coValues/coMap.ts +0 -18
  74. package/src/tools/implementation/createContext.ts +9 -2
  75. package/src/tools/tests/coList.test.ts +41 -0
  76. package/src/tools/tests/coPlainText.test.ts +24 -0
  77. package/src/tools/tests/createContext.test.ts +24 -0
  78. package/src/tools/tests/deepLoading.test.ts +2 -0
  79. package/src/tools/tests/patterns/requestToJoin.test.ts +14 -6
  80. package/src/tools/tests/utils.ts +1 -0
  81. package/src/worker/index.ts +6 -0
  82. package/dist/chunk-45VKEOXG.js.map +0 -1
  83. package/dist/inspector/custom-element-IBHKHN27.js.map +0 -1
  84. /package/src/inspector/viewer/{inpsector-button.tsx → inspector-button.tsx} +0 -0
@@ -5,6 +5,7 @@ import {
5
5
  } from "./chunk-7DYMJ74I.js";
6
6
 
7
7
  // src/react-core/hooks.ts
8
+ import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
8
9
  import React, {
9
10
  useCallback,
10
11
  useContext,
@@ -248,6 +249,32 @@ var CoValueJazzApi = class {
248
249
  }
249
250
  return new AnonymousJazzAgent2(this.localNode);
250
251
  }
252
+ /**
253
+ * The timestamp of the creation time of the CoValue
254
+ *
255
+ * @category Content
256
+ */
257
+ get createdAt() {
258
+ const createdAt = this.raw.core.verified.header.meta?.createdAt;
259
+ if (typeof createdAt === "string") {
260
+ return new Date(createdAt).getTime();
261
+ }
262
+ return this.raw.core.earliestTxMadeAt;
263
+ }
264
+ /**
265
+ * The timestamp of the last updated time of the CoValue
266
+ *
267
+ * Returns the creation time if there are no updates.
268
+ *
269
+ * @category Content
270
+ */
271
+ get lastUpdatedAt() {
272
+ const value = this.raw.core.latestTxMadeAt;
273
+ if (value === 0) {
274
+ return this.createdAt;
275
+ }
276
+ return value;
277
+ }
251
278
  };
252
279
 
253
280
  // src/tools/implementation/inspect.ts
@@ -765,22 +792,6 @@ var CoMapJazzApi = class extends CoValueJazzApi {
765
792
  get raw() {
766
793
  return this.getRaw();
767
794
  }
768
- /**
769
- * The timestamp of the creation time of the CoMap
770
- *
771
- * @category Content
772
- */
773
- get createdAt() {
774
- return this.raw.earliestTxMadeAt ?? Number.MAX_SAFE_INTEGER;
775
- }
776
- /**
777
- * The timestamp of the last updated time of the CoMap
778
- *
779
- * @category Content
780
- */
781
- get lastUpdatedAt() {
782
- return this.raw.latestTxMadeAt;
783
- }
784
795
  /** @internal */
785
796
  get schema() {
786
797
  return this.coMap.constructor._schema;
@@ -1523,6 +1534,39 @@ var CoListProxyHandler = {
1523
1534
  } else {
1524
1535
  return Reflect.has(target, key);
1525
1536
  }
1537
+ },
1538
+ ownKeys(target) {
1539
+ const keys = Reflect.ownKeys(target);
1540
+ const indexKeys = target.$jazz.raw.entries().map((_entry, i) => String(i));
1541
+ keys.push(...indexKeys);
1542
+ return keys;
1543
+ },
1544
+ getOwnPropertyDescriptor(target, key) {
1545
+ if (key === TypeSym) {
1546
+ return {
1547
+ enumerable: false,
1548
+ configurable: true,
1549
+ writable: false,
1550
+ value: target[TypeSym]
1551
+ };
1552
+ } else if (key in target) {
1553
+ return Reflect.getOwnPropertyDescriptor(target, key);
1554
+ } else if (typeof key === "string" && !isNaN(+key)) {
1555
+ const index = Number(key);
1556
+ if (index >= 0 && index < target.$jazz.raw.entries().length) {
1557
+ return {
1558
+ enumerable: true,
1559
+ configurable: true,
1560
+ writable: true
1561
+ };
1562
+ }
1563
+ } else if (key === "length") {
1564
+ return {
1565
+ enumerable: false,
1566
+ configurable: false,
1567
+ writable: false
1568
+ };
1569
+ }
1526
1570
  }
1527
1571
  };
1528
1572
 
@@ -4860,6 +4904,25 @@ function useCoState(Schema4, id, options) {
4860
4904
  );
4861
4905
  return value;
4862
4906
  }
4907
+ function useCoStateWithSelector(Schema4, id, options) {
4908
+ const subscription = useCoValueSubscription(Schema4, id, options);
4909
+ return useSyncExternalStoreWithSelector(
4910
+ React.useCallback(
4911
+ (callback) => {
4912
+ if (!subscription) {
4913
+ return () => {
4914
+ };
4915
+ }
4916
+ return subscription.subscribe(callback);
4917
+ },
4918
+ [subscription]
4919
+ ),
4920
+ () => subscription ? subscription.getCurrentValue() : null,
4921
+ () => subscription ? subscription.getCurrentValue() : null,
4922
+ options.select,
4923
+ options.equalityFn ?? Object.is
4924
+ );
4925
+ }
4863
4926
  function useAccountSubscription(Schema4, options) {
4864
4927
  const contextManager = useJazzContextManager();
4865
4928
  const createSubscription = () => {
@@ -5029,6 +5092,7 @@ export {
5029
5092
  useAccount,
5030
5093
  useAuthSecretStorage,
5031
5094
  useCoState,
5095
+ useCoStateWithSelector,
5032
5096
  useDemoAuth,
5033
5097
  useIsAuthenticated,
5034
5098
  useJazzContext,