jazz-tools 0.17.4 → 0.17.5

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.
@@ -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.5 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 18ms
106
+ ESM dist/worker/index.js 2.31 KB
107
+ ESM dist/worker/index.js.map 4.77 KB
108
+ ESM ⚡️ Build success in 15ms
109
109
  ESM dist/tiptap/index.js 564.00 B
110
110
  ESM dist/tiptap/index.js.map 1.21 KB
111
- ESM ⚡️ Build success in 17ms
111
+ ESM ⚡️ Build success in 15ms
112
112
  ESM dist/media/index.js 236.00 B
113
113
  ESM dist/media/index.browser.js 3.21 KB
114
114
  ESM dist/media/chunk-JBLT443O.js 6.33 KB
115
115
  ESM dist/media/index.native.js 3.53 KB
116
116
  ESM dist/media/index.js.map 71.00 B
117
- ESM dist/media/index.browser.js.map 6.02 KB
118
117
  ESM dist/media/chunk-JBLT443O.js.map 15.68 KB
119
118
  ESM dist/media/index.native.js.map 6.52 KB
120
- ESM ⚡️ Build success in 22ms
119
+ ESM dist/media/index.browser.js.map 6.02 KB
120
+ ESM ⚡️ Build success in 21ms
121
+ ESM dist/react-native/index.js 2.53 KB
122
+ ESM dist/react-native/testing.js 120.00 B
123
+ ESM dist/react-native/crypto.js 161.00 B
124
+ ESM dist/react-native/index.js.map 5.68 KB
125
+ ESM dist/react-native/testing.js.map 176.00 B
126
+ ESM dist/react-native/crypto.js.map 197.00 B
127
+ ESM ⚡️ Build success in 19ms
121
128
  ESM dist/browser/index.js 13.43 KB
122
129
  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
130
+ ESM ⚡️ Build success in 33ms
131
131
  ESM dist/react-core/index.js 8.41 KB
132
132
  ESM dist/react-core/testing.js 1.17 KB
133
133
  ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
134
134
  ESM dist/react-core/index.js.map 20.68 KB
135
135
  ESM dist/react-core/testing.js.map 1.82 KB
136
136
  ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
137
- ESM ⚡️ Build success in 27ms
138
- ESM dist/react-native/index.js 2.53 KB
139
- ESM dist/react-native/testing.js 120.00 B
140
- ESM dist/react-native/crypto.js 161.00 B
141
- ESM dist/react-native/index.js.map 5.68 KB
142
- ESM dist/react-native/testing.js.map 176.00 B
143
- ESM dist/react-native/crypto.js.map 197.00 B
144
137
  ESM ⚡️ Build success in 29ms
145
138
  ESM dist/react/testing.js 122.00 B
146
139
  ESM dist/react/index.js 24.55 KB
147
140
  ESM dist/react/testing.js.map 165.00 B
148
141
  ESM dist/react/index.js.map 52.42 KB
149
- ESM ⚡️ Build success in 37ms
142
+ ESM ⚡️ Build success in 30ms
150
143
  ESM dist/react-native-core/index.js 17.90 KB
151
144
  ESM dist/react-native-core/testing.js 119.00 B
152
145
  ESM dist/react-native-core/crypto.js 2.10 KB
153
146
  ESM dist/react-native-core/index.js.map 36.65 KB
154
147
  ESM dist/react-native-core/testing.js.map 175.00 B
155
148
  ESM dist/react-native-core/crypto.js.map 4.25 KB
156
- ESM ⚡️ Build success in 35ms
149
+ ESM ⚡️ Build success in 32ms
150
+ ESM dist/expo/index.js 4.65 KB
151
+ ESM dist/expo/crypto.js 153.00 B
152
+ ESM dist/expo/testing.js 112.00 B
153
+ ESM dist/expo/index.js.map 10.17 KB
154
+ ESM dist/expo/crypto.js.map 189.00 B
155
+ ESM dist/expo/testing.js.map 168.00 B
156
+ ESM ⚡️ Build success in 37ms
157
157
  ESM dist/prosemirror/index.js 76.90 KB
158
158
  ESM dist/prosemirror/index.js.map 305.53 KB
159
159
  ESM ⚡️ Build success in 44ms
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 55ms
163
163
  ESM dist/index.js 25.96 KB
164
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-EEKKLGF2.js 153.53 KB
167
166
  ESM dist/index.js.map 52.62 KB
168
- ESM dist/chunk-NPXI4XAS.js.map 361.51 KB
169
- ESM ⚡️ Build success in 73ms
167
+ ESM dist/testing.js.map 13.07 KB
168
+ ESM dist/chunk-EEKKLGF2.js.map 368.10 KB
169
+ ESM ⚡️ Build success in 71ms
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 107ms
175
175
 
176
- > jazz-tools@0.17.4 types /home/runner/_work/jazz/jazz/packages/jazz-tools
176
+ > jazz-tools@0.17.5 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.5 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,16 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.17.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 5963658: Implement/expose loadUnique and upsertUnique on co.list and co.record
8
+ - Updated dependencies [71c1411]
9
+ - Updated dependencies [2d11d44]
10
+ - cojson@0.17.5
11
+ - cojson-storage-indexeddb@0.17.5
12
+ - cojson-transport-ws@0.17.5
13
+
3
14
  ## 0.17.4
4
15
 
5
16
  ### 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" }
@@ -4130,6 +4207,16 @@ var CoListSchema = class {
4130
4207
  getCoValueClass() {
4131
4208
  return this.coValueClass;
4132
4209
  }
4210
+ /** @deprecated Use `CoList.upsertUnique` and `CoList.loadUnique` instead. */
4211
+ findUnique(unique, ownerID, as) {
4212
+ return this.coValueClass.findUnique(unique, ownerID, as);
4213
+ }
4214
+ upsertUnique(options) {
4215
+ return this.coValueClass.upsertUnique(options);
4216
+ }
4217
+ loadUnique(unique, ownerID, options) {
4218
+ return this.coValueClass.loadUnique(unique, ownerID, options);
4219
+ }
4133
4220
  optional() {
4134
4221
  return coOptionalDefiner(this);
4135
4222
  }
@@ -4558,7 +4645,7 @@ var ImageDefinitionBase = coMapDefiner({
4558
4645
  var ImageDefinition = ImageDefinitionBase;
4559
4646
 
4560
4647
  // src/tools/implementation/ContextManager.ts
4561
- import { cojsonInternals as cojsonInternals4 } from "cojson";
4648
+ import { cojsonInternals as cojsonInternals5 } from "cojson";
4562
4649
  import { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
4563
4650
 
4564
4651
  // src/tools/auth/KvStoreContext.ts
@@ -4887,7 +4974,7 @@ var JazzContextManager = class {
4887
4974
  }
4888
4975
  const currentContext = this.context;
4889
4976
  if (prevContext && currentContext && "me" in prevContext && "me" in currentContext) {
4890
- const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals4.connectedPeers(
4977
+ const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals5.connectedPeers(
4891
4978
  prevContext.me.id,
4892
4979
  currentContext.me.id,
4893
4980
  {
@@ -5283,4 +5370,4 @@ export {
5283
5370
  JazzContextManager
5284
5371
  };
5285
5372
  /* istanbul ignore file -- @preserve */
5286
- //# sourceMappingURL=chunk-NPXI4XAS.js.map
5373
+ //# sourceMappingURL=chunk-EEKKLGF2.js.map