jazz-tools 0.17.4 → 0.17.6

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 (35) hide show
  1. package/.turbo/turbo-build.log +44 -44
  2. package/CHANGELOG.md +21 -0
  3. package/dist/{chunk-NPXI4XAS.js → chunk-SJHXI5AB.js} +103 -14
  4. package/dist/chunk-SJHXI5AB.js.map +1 -0
  5. package/dist/index.js +1 -1
  6. package/dist/media/{chunk-JBLT443O.js → chunk-E5J3WLQW.js} +2 -2
  7. package/dist/media/{chunk-JBLT443O.js.map → chunk-E5J3WLQW.js.map} +1 -1
  8. package/dist/media/index.browser.js +1 -1
  9. package/dist/media/index.js +1 -1
  10. package/dist/media/index.native.js +1 -1
  11. package/dist/media/utils.d.ts.map +1 -1
  12. package/dist/react/index.js.map +1 -1
  13. package/dist/testing.js +9 -1
  14. package/dist/testing.js.map +1 -1
  15. package/dist/tools/coValues/coList.d.ts +43 -1
  16. package/dist/tools/coValues/coList.d.ts.map +1 -1
  17. package/dist/tools/implementation/schema.d.ts.map +1 -1
  18. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +15 -1
  19. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  20. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +11 -0
  21. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  22. package/dist/tools/testing.d.ts +9 -0
  23. package/dist/tools/testing.d.ts.map +1 -1
  24. package/package.json +4 -4
  25. package/src/media/utils.test.ts +3 -2
  26. package/src/media/utils.ts +5 -1
  27. package/src/tools/coValues/coList.ts +124 -4
  28. package/src/tools/implementation/schema.ts +3 -1
  29. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +44 -1
  30. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +25 -0
  31. package/src/tools/testing.ts +18 -0
  32. package/src/tools/tests/coList.test.ts +167 -0
  33. package/src/tools/tests/coMap.record.test.ts +104 -0
  34. package/src/tools/tests/coMap.test.ts +19 -1
  35. package/dist/chunk-NPXI4XAS.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.17.4 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.17.6 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
3
  > tsup && pnpm types && pnpm build:svelte
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
@@ -100,84 +100,84 @@
100
100
  ESM Build start
101
101
  CLI Cleaning output folder
102
102
  ESM Build start
103
- ESM dist/worker/index.js 2.31 KB
104
- ESM dist/worker/index.js.map 4.77 KB
105
- ESM ⚡️ Build success in 17ms
106
103
  ESM dist/react/ssr.js 688.00 B
107
104
  ESM dist/react/ssr.js.map 1.12 KB
108
- ESM ⚡️ Build success in 19ms
105
+ ESM ⚡️ Build success in 17ms
109
106
  ESM dist/tiptap/index.js 564.00 B
110
107
  ESM dist/tiptap/index.js.map 1.21 KB
111
- ESM ⚡️ Build success in 17ms
112
- ESM dist/media/index.js 236.00 B
113
- ESM dist/media/index.browser.js 3.21 KB
114
- ESM dist/media/chunk-JBLT443O.js 6.33 KB
115
- ESM dist/media/index.native.js 3.53 KB
116
- ESM dist/media/index.js.map 71.00 B
117
- ESM dist/media/index.browser.js.map 6.02 KB
118
- ESM dist/media/chunk-JBLT443O.js.map 15.68 KB
119
- ESM dist/media/index.native.js.map 6.52 KB
120
- ESM ⚡️ Build success in 22ms
121
- ESM dist/browser/index.js 13.43 KB
122
- ESM dist/browser/index.js.map 28.65 KB
123
- ESM ⚡️ Build success in 27ms
124
- ESM dist/expo/index.js 4.65 KB
125
- ESM dist/expo/crypto.js 153.00 B
126
- ESM dist/expo/testing.js 112.00 B
127
- ESM dist/expo/index.js.map 10.17 KB
128
- ESM dist/expo/crypto.js.map 189.00 B
129
- ESM dist/expo/testing.js.map 168.00 B
130
- ESM ⚡️ Build success in 27ms
108
+ ESM ⚡️ Build success in 15ms
109
+ ESM dist/worker/index.js 2.31 KB
110
+ ESM dist/worker/index.js.map 4.77 KB
111
+ ESM ⚡️ Build success in 16ms
131
112
  ESM dist/react-core/index.js 8.41 KB
132
113
  ESM dist/react-core/testing.js 1.17 KB
133
114
  ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
134
- ESM dist/react-core/index.js.map 20.68 KB
135
115
  ESM dist/react-core/testing.js.map 1.82 KB
116
+ ESM dist/react-core/index.js.map 20.68 KB
136
117
  ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
137
- ESM ⚡️ Build success in 27ms
118
+ ESM ⚡️ Build success in 18ms
138
119
  ESM dist/react-native/index.js 2.53 KB
139
120
  ESM dist/react-native/testing.js 120.00 B
140
121
  ESM dist/react-native/crypto.js 161.00 B
141
122
  ESM dist/react-native/index.js.map 5.68 KB
142
123
  ESM dist/react-native/testing.js.map 176.00 B
143
124
  ESM dist/react-native/crypto.js.map 197.00 B
144
- ESM ⚡️ Build success in 29ms
145
- ESM dist/react/testing.js 122.00 B
146
- ESM dist/react/index.js 24.55 KB
147
- ESM dist/react/testing.js.map 165.00 B
148
- ESM dist/react/index.js.map 52.42 KB
149
- ESM ⚡️ Build success in 37ms
125
+ ESM ⚡️ Build success in 20ms
126
+ ESM dist/expo/index.js 4.65 KB
127
+ ESM dist/expo/crypto.js 153.00 B
128
+ ESM dist/expo/testing.js 112.00 B
129
+ ESM dist/expo/index.js.map 10.17 KB
130
+ ESM dist/expo/crypto.js.map 189.00 B
131
+ ESM dist/expo/testing.js.map 168.00 B
132
+ ESM ⚡️ Build success in 25ms
133
+ ESM dist/media/index.js 236.00 B
134
+ ESM dist/media/index.browser.js 3.21 KB
135
+ ESM dist/media/index.native.js 3.53 KB
136
+ ESM dist/media/chunk-E5J3WLQW.js 6.34 KB
137
+ ESM dist/media/index.js.map 71.00 B
138
+ ESM dist/media/index.browser.js.map 6.02 KB
139
+ ESM dist/media/index.native.js.map 6.52 KB
140
+ ESM dist/media/chunk-E5J3WLQW.js.map 15.95 KB
141
+ ESM ⚡️ Build success in 32ms
142
+ ESM dist/browser/index.js 13.43 KB
143
+ ESM dist/browser/index.js.map 28.65 KB
144
+ ESM ⚡️ Build success in 34ms
150
145
  ESM dist/react-native-core/index.js 17.90 KB
151
146
  ESM dist/react-native-core/testing.js 119.00 B
152
147
  ESM dist/react-native-core/crypto.js 2.10 KB
153
148
  ESM dist/react-native-core/index.js.map 36.65 KB
154
149
  ESM dist/react-native-core/testing.js.map 175.00 B
155
150
  ESM dist/react-native-core/crypto.js.map 4.25 KB
156
- ESM ⚡️ Build success in 35ms
151
+ ESM ⚡️ Build success in 49ms
152
+ ESM dist/react/index.js 24.55 KB
153
+ ESM dist/react/testing.js 122.00 B
154
+ ESM dist/react/testing.js.map 165.00 B
155
+ ESM dist/react/index.js.map 52.68 KB
156
+ ESM ⚡️ Build success in 53ms
157
157
  ESM dist/prosemirror/index.js 76.90 KB
158
158
  ESM dist/prosemirror/index.js.map 305.53 KB
159
- ESM ⚡️ Build success in 44ms
159
+ ESM ⚡️ Build success in 54ms
160
160
  ESM dist/inspector/index.js 60.40 KB
161
161
  ESM dist/inspector/index.js.map 107.91 KB
162
- ESM ⚡️ Build success in 54ms
162
+ ESM ⚡️ Build success in 65ms
163
+ ESM dist/testing.js 6.97 KB
163
164
  ESM dist/index.js 25.96 KB
164
- ESM dist/testing.js 6.76 KB
165
- ESM dist/chunk-NPXI4XAS.js 150.66 KB
166
- ESM dist/testing.js.map 13.07 KB
165
+ ESM dist/chunk-SJHXI5AB.js 153.63 KB
166
+ ESM dist/testing.js.map 13.65 KB
167
167
  ESM dist/index.js.map 52.62 KB
168
- ESM dist/chunk-NPXI4XAS.js.map 361.51 KB
169
- ESM ⚡️ Build success in 73ms
168
+ ESM dist/chunk-SJHXI5AB.js.map 368.28 KB
169
+ ESM ⚡️ Build success in 84ms
170
170
  ESM dist/inspector/register-custom-element.js 218.00 B
171
171
  ESM dist/inspector/register-custom-element.js.map 314.00 B
172
172
  ESM dist/inspector/custom-element-I7L56H6B.js 1.53 MB
173
173
  ESM dist/inspector/custom-element-I7L56H6B.js.map 2.35 MB
174
- ESM ⚡️ Build success in 110ms
174
+ ESM ⚡️ Build success in 119ms
175
175
 
176
- > jazz-tools@0.17.4 types /home/runner/_work/jazz/jazz/packages/jazz-tools
176
+ > jazz-tools@0.17.6 types /home/runner/_work/jazz/jazz/packages/jazz-tools
177
177
  > tsc --outDir dist
178
178
 
179
179
 
180
- > jazz-tools@0.17.4 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
180
+ > jazz-tools@0.17.6 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
181
181
  > rm -rf dist/svelte && svelte-package -i src/svelte -o dist/svelte --tsconfig tsconfig.svelte.json
182
182
 
183
183
  src/svelte -> dist/svelte
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.17.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 82de51c: allow creating CoValues from JSON without an active account
8
+ - 694b168: get resized image's id without triggering shallow load in `loadImageBySize`
9
+ - cojson@0.17.6
10
+ - cojson-storage-indexeddb@0.17.6
11
+ - cojson-transport-ws@0.17.6
12
+
13
+ ## 0.17.5
14
+
15
+ ### Patch Changes
16
+
17
+ - 5963658: Implement/expose loadUnique and upsertUnique on co.list and co.record
18
+ - Updated dependencies [71c1411]
19
+ - Updated dependencies [2d11d44]
20
+ - cojson@0.17.5
21
+ - cojson-storage-indexeddb@0.17.5
22
+ - cojson-transport-ws@0.17.5
23
+
3
24
  ## 0.17.4
4
25
 
5
26
  ### Patch Changes
@@ -718,7 +718,7 @@ var CoMapProxyHandler = {
718
718
  RegisteredSchemas["CoMap"] = CoMap;
719
719
 
720
720
  // src/tools/coValues/coList.ts
721
- import { ControlledAccount as ControlledAccount2, RawAccount as RawAccount2 } from "cojson";
721
+ import { ControlledAccount as ControlledAccount2, RawAccount as RawAccount2, cojsonInternals as cojsonInternals2 } from "cojson";
722
722
  import { calcPatch } from "fast-myers-diff";
723
723
  var _CoList = class _CoList extends Array {
724
724
  /**
@@ -847,10 +847,13 @@ var _CoList = class _CoList extends Array {
847
847
  * @category Creation
848
848
  **/
849
849
  static create(items, options) {
850
- const { owner } = parseCoValueCreateOptions(options);
850
+ const { owner, uniqueness } = parseCoValueCreateOptions(options);
851
851
  const instance = new this({ init: items, owner });
852
852
  const raw = owner._raw.createList(
853
- toRawItems(items, instance._schema[ItemsSym], owner)
853
+ toRawItems(items, instance._schema[ItemsSym], owner),
854
+ null,
855
+ "private",
856
+ uniqueness
854
857
  );
855
858
  Object.defineProperties(instance, {
856
859
  id: {
@@ -1027,6 +1030,80 @@ var _CoList = class _CoList extends Array {
1027
1030
  castAs(cl) {
1028
1031
  return cl.fromRaw(this._raw);
1029
1032
  }
1033
+ /** @deprecated Use `CoList.upsertUnique` and `CoList.loadUnique` instead. */
1034
+ static findUnique(unique, ownerID, as) {
1035
+ return _CoList._findUnique(unique, ownerID, as);
1036
+ }
1037
+ /** @internal */
1038
+ static _findUnique(unique, ownerID, as) {
1039
+ as ||= activeAccountContext.get();
1040
+ const header = {
1041
+ type: "colist",
1042
+ ruleset: {
1043
+ type: "ownedByGroup",
1044
+ group: ownerID
1045
+ },
1046
+ meta: null,
1047
+ uniqueness: unique
1048
+ };
1049
+ const crypto = as._type === "Anonymous" ? as.node.crypto : as._raw.core.node.crypto;
1050
+ return cojsonInternals2.idforHeader(header, crypto);
1051
+ }
1052
+ /**
1053
+ * Given some data, updates an existing CoList or initialises a new one if none exists.
1054
+ *
1055
+ * Note: This method respects resolve options, and thus can return `null` if the references cannot be resolved.
1056
+ *
1057
+ * @example
1058
+ * ```ts
1059
+ * const activeItems = await ItemList.upsertUnique(
1060
+ * {
1061
+ * value: [item1, item2, item3],
1062
+ * unique: sourceData.identifier,
1063
+ * owner: workspace,
1064
+ * }
1065
+ * );
1066
+ * ```
1067
+ *
1068
+ * @param options The options for creating or loading the CoList. This includes the intended state of the CoList, its unique identifier, its owner, and the references to resolve.
1069
+ * @returns Either an existing & modified CoList, or a new initialised CoList if none exists.
1070
+ * @category Subscription & Loading
1071
+ */
1072
+ static async upsertUnique(options) {
1073
+ let listId = _CoList._findUnique(options.unique, options.owner.id);
1074
+ let list = await loadCoValueWithoutMe(this, listId, {
1075
+ ...options,
1076
+ loadAs: options.owner._loadedAs,
1077
+ skipRetry: true
1078
+ });
1079
+ if (!list) {
1080
+ list = this.create(options.value, {
1081
+ owner: options.owner,
1082
+ unique: options.unique
1083
+ });
1084
+ } else {
1085
+ list.applyDiff(options.value);
1086
+ }
1087
+ return await loadCoValueWithoutMe(this, listId, {
1088
+ ...options,
1089
+ loadAs: options.owner._loadedAs,
1090
+ skipRetry: true
1091
+ });
1092
+ }
1093
+ /**
1094
+ * Loads a CoList by its unique identifier and owner's ID.
1095
+ * @param unique The unique identifier of the CoList to load.
1096
+ * @param ownerID The ID of the owner of the CoList.
1097
+ * @param options Additional options for loading the CoList.
1098
+ * @returns The loaded CoList, or null if unavailable.
1099
+ */
1100
+ static loadUnique(unique, ownerID, options) {
1101
+ return loadCoValueWithoutMe(
1102
+ this,
1103
+ _CoList._findUnique(unique, ownerID, options?.loadAs),
1104
+ { ...options, skipRetry: true }
1105
+ );
1106
+ }
1030
1107
  /**
1031
1108
  * Wait for the `CoList` to be uploaded to the other peers.
1032
1109
  *
@@ -1136,7 +1213,7 @@ var CoListProxyHandler = {
1136
1213
  };
1137
1214
 
1138
1215
  // src/tools/coValues/coFeed.ts
1139
- import { cojsonInternals as cojsonInternals2 } from "cojson";
1216
+ import { cojsonInternals as cojsonInternals3 } from "cojson";
1140
1217
  var _CoFeed = class _CoFeed extends CoValueBase {
1141
1218
  /**
1142
1219
  * Declare a `CoFeed` by subclassing `CoFeed.Of(...)` and passing the item schema using a `co` primitive or a `coField.ref`.
@@ -1469,12 +1546,12 @@ var CoStreamPerSessionProxyHandler = (innerTarget, accessFrom) => ({
1469
1546
  const sessionID = key;
1470
1547
  const rawEntry = innerTarget._raw.lastItemIn(sessionID);
1471
1548
  if (!rawEntry) return;
1472
- const by = cojsonInternals2.accountOrAgentIDfromSessionID(sessionID);
1549
+ const by = cojsonInternals3.accountOrAgentIDfromSessionID(sessionID);
1473
1550
  const entry = entryFromRawEntry(
1474
1551
  accessFrom,
1475
1552
  rawEntry,
1476
1553
  innerTarget._loadedAs,
1477
- cojsonInternals2.isAccountID(by) ? by : void 0,
1554
+ cojsonInternals3.isAccountID(by) ? by : void 0,
1478
1555
  innerTarget._schema[ItemsSym]
1479
1556
  );
1480
1557
  Object.defineProperty(entry, "all", {
@@ -1488,7 +1565,7 @@ var CoStreamPerSessionProxyHandler = (innerTarget, accessFrom) => ({
1488
1565
  accessFrom,
1489
1566
  rawEntry2.value,
1490
1567
  innerTarget._loadedAs,
1491
- cojsonInternals2.isAccountID(by) ? by : void 0,
1568
+ cojsonInternals3.isAccountID(by) ? by : void 0,
1492
1569
  innerTarget._schema[ItemsSym]
1493
1570
  );
1494
1571
  }
@@ -1658,7 +1735,7 @@ var FileStream = class extends CoValueBase {
1658
1735
  totalSizeBytes: arrayBuffer.byteLength,
1659
1736
  fileName
1660
1737
  });
1661
- const chunkSize = cojsonInternals2.TRANSACTION_CONFIG.MAX_RECOMMENDED_TX_SIZE;
1738
+ const chunkSize = cojsonInternals3.TRANSACTION_CONFIG.MAX_RECOMMENDED_TX_SIZE;
1662
1739
  let lastProgressUpdate = Date.now();
1663
1740
  for (let idx = 0; idx < data.length; idx += chunkSize) {
1664
1741
  stream.push(data.slice(idx, idx + chunkSize));
@@ -1742,7 +1819,7 @@ var FileStream = class extends CoValueBase {
1742
1819
  import {
1743
1820
  ControlledAccount as ControlledAccount3,
1744
1821
  LocalNode,
1745
- cojsonInternals as cojsonInternals3
1822
+ cojsonInternals as cojsonInternals4
1746
1823
  } from "cojson";
1747
1824
  var _Account = class _Account extends CoValueBase {
1748
1825
  get _schema() {
@@ -1888,7 +1965,7 @@ var _Account = class _Account extends CoValueBase {
1888
1965
  return activeAccountContext.get();
1889
1966
  }
1890
1967
  static async createAs(as, options) {
1891
- const connectedPeers = cojsonInternals3.connectedPeers(
1968
+ const connectedPeers = cojsonInternals4.connectedPeers(
1892
1969
  "creatingAccount",
1893
1970
  "createdAccount",
1894
1971
  { peer1role: "server", peer2role: "client" }
@@ -3014,7 +3091,9 @@ function instantiateRefEncodedWithInit(schema, init, parentOwner) {
3014
3091
  `Cannot automatically create CoValue from value: ${JSON.stringify(init)}. Use the CoValue schema's create() method instead.`
3015
3092
  );
3016
3093
  }
3017
- const owner = Group.create();
3094
+ const node = parentOwner._raw.core.node;
3095
+ const rawGroup = node.createGroup();
3096
+ const owner = new Group({ fromRaw: rawGroup });
3018
3097
  owner.addMember(parentOwner.castAs(Group));
3019
3098
  return schema.ref.create(init, owner);
3020
3099
  }
@@ -4130,6 +4209,16 @@ var CoListSchema = class {
4130
4209
  getCoValueClass() {
4131
4210
  return this.coValueClass;
4132
4211
  }
4212
+ /** @deprecated Use `CoList.upsertUnique` and `CoList.loadUnique` instead. */
4213
+ findUnique(unique, ownerID, as) {
4214
+ return this.coValueClass.findUnique(unique, ownerID, as);
4215
+ }
4216
+ upsertUnique(options) {
4217
+ return this.coValueClass.upsertUnique(options);
4218
+ }
4219
+ loadUnique(unique, ownerID, options) {
4220
+ return this.coValueClass.loadUnique(unique, ownerID, options);
4221
+ }
4133
4222
  optional() {
4134
4223
  return coOptionalDefiner(this);
4135
4224
  }
@@ -4558,7 +4647,7 @@ var ImageDefinitionBase = coMapDefiner({
4558
4647
  var ImageDefinition = ImageDefinitionBase;
4559
4648
 
4560
4649
  // src/tools/implementation/ContextManager.ts
4561
- import { cojsonInternals as cojsonInternals4 } from "cojson";
4650
+ import { cojsonInternals as cojsonInternals5 } from "cojson";
4562
4651
  import { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
4563
4652
 
4564
4653
  // src/tools/auth/KvStoreContext.ts
@@ -4887,7 +4976,7 @@ var JazzContextManager = class {
4887
4976
  }
4888
4977
  const currentContext = this.context;
4889
4978
  if (prevContext && currentContext && "me" in prevContext && "me" in currentContext) {
4890
- const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals4.connectedPeers(
4979
+ const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals5.connectedPeers(
4891
4980
  prevContext.me.id,
4892
4981
  currentContext.me.id,
4893
4982
  {
@@ -5283,4 +5372,4 @@ export {
5283
5372
  JazzContextManager
5284
5373
  };
5285
5374
  /* istanbul ignore file -- @preserve */
5286
- //# sourceMappingURL=chunk-NPXI4XAS.js.map
5375
+ //# sourceMappingURL=chunk-SJHXI5AB.js.map