jazz-tools 0.18.5 → 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 (111) hide show
  1. package/.turbo/turbo-build.log +57 -57
  2. package/CHANGELOG.md +33 -0
  3. package/dist/better-auth/auth/client.d.ts.map +1 -1
  4. package/dist/better-auth/auth/client.js +7 -1
  5. package/dist/better-auth/auth/client.js.map +1 -1
  6. package/dist/better-auth/auth/react.d.ts +0 -2145
  7. package/dist/better-auth/auth/react.d.ts.map +1 -1
  8. package/dist/better-auth/auth/react.js +2 -14
  9. package/dist/better-auth/auth/react.js.map +1 -1
  10. package/dist/better-auth/auth/server.d.ts.map +1 -1
  11. package/dist/better-auth/auth/server.js +77 -22
  12. package/dist/better-auth/auth/server.js.map +1 -1
  13. package/dist/better-auth/auth/tests/react.test.d.ts +2 -0
  14. package/dist/better-auth/auth/tests/react.test.d.ts.map +1 -0
  15. package/dist/{chunk-3LE7N6TH.js → chunk-CFAY3FMQ.js} +192 -101
  16. package/dist/chunk-CFAY3FMQ.js.map +1 -0
  17. package/dist/index.js +1 -1
  18. package/dist/inspector/{custom-element-WCY6D3QJ.js → custom-element-G6SPZEBR.js} +308 -97
  19. package/dist/inspector/custom-element-G6SPZEBR.js.map +1 -0
  20. package/dist/inspector/index.d.ts +5 -1
  21. package/dist/inspector/index.d.ts.map +1 -1
  22. package/dist/inspector/index.js +318 -56
  23. package/dist/inspector/index.js.map +1 -1
  24. package/dist/inspector/register-custom-element.js +1 -1
  25. package/dist/inspector/ui/button.d.ts +1 -1
  26. package/dist/inspector/ui/button.d.ts.map +1 -1
  27. package/dist/inspector/ui/heading.d.ts +2 -1
  28. package/dist/inspector/ui/heading.d.ts.map +1 -1
  29. package/dist/inspector/ui/input.d.ts.map +1 -1
  30. package/dist/inspector/ui/modal.d.ts +16 -0
  31. package/dist/inspector/ui/modal.d.ts.map +1 -0
  32. package/dist/inspector/viewer/delete-local-data.d.ts +2 -0
  33. package/dist/inspector/viewer/delete-local-data.d.ts.map +1 -0
  34. package/dist/inspector/viewer/{inpsector-button.d.ts → inspector-button.d.ts} +1 -1
  35. package/dist/inspector/viewer/{inpsector-button.d.ts.map → inspector-button.d.ts.map} +1 -1
  36. package/dist/inspector/viewer/new-app.d.ts +1 -4
  37. package/dist/inspector/viewer/new-app.d.ts.map +1 -1
  38. package/dist/react/hooks.d.ts +1 -1
  39. package/dist/react/hooks.d.ts.map +1 -1
  40. package/dist/react/index.d.ts +1 -1
  41. package/dist/react/index.d.ts.map +1 -1
  42. package/dist/react/index.js +3 -1
  43. package/dist/react/index.js.map +1 -1
  44. package/dist/react-core/hooks.d.ts +133 -0
  45. package/dist/react-core/hooks.d.ts.map +1 -1
  46. package/dist/react-core/index.js +83 -17
  47. package/dist/react-core/index.js.map +1 -1
  48. package/dist/react-core/tests/useCoStateWithSelector.test.d.ts +2 -0
  49. package/dist/react-core/tests/useCoStateWithSelector.test.d.ts.map +1 -0
  50. package/dist/react-native-core/hooks.d.ts +1 -1
  51. package/dist/react-native-core/hooks.d.ts.map +1 -1
  52. package/dist/react-native-core/index.js +3 -1
  53. package/dist/react-native-core/index.js.map +1 -1
  54. package/dist/testing.js +2 -2
  55. package/dist/testing.js.map +1 -1
  56. package/dist/tools/coValues/CoValueBase.d.ts +14 -0
  57. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  58. package/dist/tools/coValues/coMap.d.ts +0 -12
  59. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  60. package/dist/tools/coValues/inbox.d.ts +5 -5
  61. package/dist/tools/coValues/inbox.d.ts.map +1 -1
  62. package/dist/tools/implementation/createContext.d.ts +2 -1
  63. package/dist/tools/implementation/createContext.d.ts.map +1 -1
  64. package/dist/tools/tests/utils.d.ts.map +1 -1
  65. package/dist/worker/index.d.ts +12 -2
  66. package/dist/worker/index.d.ts.map +1 -1
  67. package/dist/worker/index.js +10 -4
  68. package/dist/worker/index.js.map +1 -1
  69. package/package.json +6 -4
  70. package/src/better-auth/auth/client.ts +8 -2
  71. package/src/better-auth/auth/react.tsx +2 -51
  72. package/src/better-auth/auth/server.ts +98 -24
  73. package/src/better-auth/auth/tests/client.test.ts +92 -4
  74. package/src/better-auth/auth/tests/react.test.tsx +43 -0
  75. package/src/better-auth/auth/tests/server.test.ts +276 -98
  76. package/src/inspector/custom-element.tsx +1 -1
  77. package/src/inspector/index.tsx +44 -0
  78. package/src/inspector/ui/button.tsx +15 -1
  79. package/src/inspector/ui/heading.tsx +7 -2
  80. package/src/inspector/ui/input.tsx +6 -2
  81. package/src/inspector/ui/modal.tsx +158 -0
  82. package/src/inspector/viewer/delete-local-data.tsx +101 -0
  83. package/src/inspector/viewer/new-app.tsx +3 -19
  84. package/src/react/hooks.tsx +1 -0
  85. package/src/react/index.ts +1 -0
  86. package/src/react-core/hooks.ts +162 -0
  87. package/src/react-core/tests/useCoStateWithSelector.test.ts +149 -0
  88. package/src/react-native-core/hooks.tsx +1 -0
  89. package/src/tools/coValues/CoValueBase.ts +32 -0
  90. package/src/tools/coValues/coList.ts +35 -0
  91. package/src/tools/coValues/coMap.ts +0 -18
  92. package/src/tools/coValues/inbox.ts +190 -108
  93. package/src/tools/implementation/createContext.ts +9 -2
  94. package/src/tools/testing.ts +1 -1
  95. package/src/tools/tests/coFeed.test.ts +33 -22
  96. package/src/tools/tests/coList.test.ts +47 -4
  97. package/src/tools/tests/coMap.test.ts +13 -5
  98. package/src/tools/tests/coPlainText.test.ts +24 -0
  99. package/src/tools/tests/createContext.test.ts +24 -0
  100. package/src/tools/tests/deepLoading.test.ts +2 -0
  101. package/src/tools/tests/exportImport.test.ts +3 -1
  102. package/src/tools/tests/groupsAndAccounts.test.ts +56 -44
  103. package/src/tools/tests/inbox.test.ts +293 -31
  104. package/src/tools/tests/patterns/requestToJoin.test.ts +14 -6
  105. package/src/tools/tests/utils.ts +1 -0
  106. package/src/worker/index.ts +21 -5
  107. package/tsup.config.ts +1 -1
  108. package/dist/chunk-3LE7N6TH.js.map +0 -1
  109. package/dist/inspector/custom-element-WCY6D3QJ.js.map +0 -1
  110. package/src/inspector/index.ts +0 -23
  111. /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
 
@@ -2763,7 +2807,9 @@ var Profile = class extends CoMap {
2763
2807
  };
2764
2808
 
2765
2809
  // src/tools/coValues/inbox.ts
2766
- import { RawAccount as RawAccount2 } from "cojson";
2810
+ import {
2811
+ RawAccount as RawAccount2
2812
+ } from "cojson";
2767
2813
  function createInboxRoot(account) {
2768
2814
  if (!account.$jazz.isLocalNodeOwner) {
2769
2815
  throw new Error("Account is not controlled");
@@ -4858,6 +4904,25 @@ function useCoState(Schema4, id, options) {
4858
4904
  );
4859
4905
  return value;
4860
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
+ }
4861
4926
  function useAccountSubscription(Schema4, options) {
4862
4927
  const contextManager = useJazzContextManager();
4863
4928
  const createSubscription = () => {
@@ -5027,6 +5092,7 @@ export {
5027
5092
  useAccount,
5028
5093
  useAuthSecretStorage,
5029
5094
  useCoState,
5095
+ useCoStateWithSelector,
5030
5096
  useDemoAuth,
5031
5097
  useIsAuthenticated,
5032
5098
  useJazzContext,