@anuma/sdk 2.0.1 → 2.1.0

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.
@@ -21447,7 +21447,7 @@ function startObserve(entry, walletAddress) {
21447
21447
  isInitialEmission = false;
21448
21448
  }
21449
21449
  function subscribeUserSettings(database, walletAddress, listener) {
21450
- if (!walletAddress) return () => void 0;
21450
+ if (!database || !walletAddress) return () => void 0;
21451
21451
  const perDb = getOrCreatePerDb(database);
21452
21452
  let entry = perDb.get(walletAddress);
21453
21453
  if (!entry) {
@@ -21477,17 +21477,18 @@ function subscribeUserSettings(database, walletAddress, listener) {
21477
21477
  };
21478
21478
  }
21479
21479
  function getUserSettingsSnapshot(database, walletAddress) {
21480
- if (!walletAddress) return EMPTY_SNAPSHOT;
21480
+ if (!database || !walletAddress) return EMPTY_SNAPSHOT;
21481
21481
  return pool.get(database)?.get(walletAddress)?.snapshot ?? EMPTY_SNAPSHOT;
21482
21482
  }
21483
21483
  function patchUserSettingsSnapshot(database, walletAddress, patch) {
21484
- if (!walletAddress) return;
21484
+ if (!database || !walletAddress) return;
21485
21485
  const entry = pool.get(database)?.get(walletAddress);
21486
21486
  if (!entry) return;
21487
21487
  patchSnapshot(entry, patch);
21488
21488
  }
21489
21489
 
21490
21490
  // src/react/useSettings.ts
21491
+ var DB_NOT_READY = "Database not ready";
21491
21492
  function useSettings(options) {
21492
21493
  const { database, walletAddress } = options;
21493
21494
  const subscribe = (0, import_react9.useCallback)(
@@ -21500,24 +21501,25 @@ function useSettings(options) {
21500
21501
  );
21501
21502
  const snapshot = (0, import_react9.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
21502
21503
  const storageCtx = (0, import_react9.useMemo)(
21503
- () => ({
21504
+ () => database ? {
21504
21505
  database,
21505
21506
  userPreferencesCollection: database.get("userPreferences"),
21506
21507
  modelPreferencesCollection: database.get("modelPreferences")
21507
- }),
21508
+ } : null,
21508
21509
  [database]
21509
21510
  );
21510
21511
  const legacyStorageCtx = (0, import_react9.useMemo)(
21511
- () => ({
21512
+ () => database ? {
21512
21513
  database,
21513
21514
  modelPreferencesCollection: database.get("modelPreferences")
21514
- }),
21515
+ } : null,
21515
21516
  [database]
21516
21517
  );
21517
21518
  const getModelPreference = (0, import_react9.useCallback)(
21518
21519
  async (address) => {
21519
21520
  try {
21520
21521
  if (!address) throw new Error("Wallet address is required");
21522
+ if (!legacyStorageCtx) throw new Error(DB_NOT_READY);
21521
21523
  const result = await getModelPreferenceOp(legacyStorageCtx, address);
21522
21524
  return result;
21523
21525
  } catch (error) {
@@ -21530,6 +21532,7 @@ function useSettings(options) {
21530
21532
  async (address, models) => {
21531
21533
  try {
21532
21534
  if (!address) throw new Error("Wallet address is required");
21535
+ if (!legacyStorageCtx) throw new Error(DB_NOT_READY);
21533
21536
  const result = await setModelPreferenceOp(legacyStorageCtx, address, models);
21534
21537
  if (walletAddress && address === walletAddress) {
21535
21538
  patchUserSettingsSnapshot(database, walletAddress, { modelPreference: result });
@@ -21545,6 +21548,7 @@ function useSettings(options) {
21545
21548
  async (address) => {
21546
21549
  try {
21547
21550
  if (!address) throw new Error("Wallet address is required");
21551
+ if (!legacyStorageCtx) throw new Error(DB_NOT_READY);
21548
21552
  const deleted = await deleteModelPreferenceOp(legacyStorageCtx, address);
21549
21553
  if (deleted && walletAddress && address === walletAddress) {
21550
21554
  patchUserSettingsSnapshot(database, walletAddress, { modelPreference: null });
@@ -21560,6 +21564,7 @@ function useSettings(options) {
21560
21564
  async (address) => {
21561
21565
  try {
21562
21566
  if (!address) throw new Error("Wallet address is required");
21567
+ if (!storageCtx) throw new Error(DB_NOT_READY);
21563
21568
  const result = await getUserPreferenceOp(storageCtx, address);
21564
21569
  return result;
21565
21570
  } catch (error) {
@@ -21572,6 +21577,7 @@ function useSettings(options) {
21572
21577
  async (address, opts) => {
21573
21578
  try {
21574
21579
  if (!address) throw new Error("Wallet address is required");
21580
+ if (!storageCtx) throw new Error(DB_NOT_READY);
21575
21581
  const result = await setUserPreferenceOp(storageCtx, address, opts);
21576
21582
  if (walletAddress && address === walletAddress) {
21577
21583
  patchUserSettingsSnapshot(database, walletAddress, { userPreference: result });
@@ -21587,6 +21593,7 @@ function useSettings(options) {
21587
21593
  async (address, profile) => {
21588
21594
  try {
21589
21595
  if (!address) throw new Error("Wallet address is required");
21596
+ if (!storageCtx) throw new Error(DB_NOT_READY);
21590
21597
  const result = await updateProfileOp(storageCtx, address, profile);
21591
21598
  if (result && walletAddress && address === walletAddress) {
21592
21599
  patchUserSettingsSnapshot(database, walletAddress, { userPreference: result });
@@ -21602,6 +21609,7 @@ function useSettings(options) {
21602
21609
  async (address, personality) => {
21603
21610
  try {
21604
21611
  if (!address) throw new Error("Wallet address is required");
21612
+ if (!storageCtx) throw new Error(DB_NOT_READY);
21605
21613
  const result = await updatePersonalityOp(storageCtx, address, personality);
21606
21614
  if (result && walletAddress && address === walletAddress) {
21607
21615
  patchUserSettingsSnapshot(database, walletAddress, { userPreference: result });
@@ -21617,6 +21625,7 @@ function useSettings(options) {
21617
21625
  async (address, models) => {
21618
21626
  try {
21619
21627
  if (!address) throw new Error("Wallet address is required");
21628
+ if (!storageCtx) throw new Error(DB_NOT_READY);
21620
21629
  const result = await updateModelsOp(storageCtx, address, models);
21621
21630
  if (result && walletAddress && address === walletAddress) {
21622
21631
  patchUserSettingsSnapshot(database, walletAddress, { userPreference: result });
@@ -21632,6 +21641,7 @@ function useSettings(options) {
21632
21641
  async (address) => {
21633
21642
  try {
21634
21643
  if (!address) throw new Error("Wallet address is required");
21644
+ if (!storageCtx) throw new Error(DB_NOT_READY);
21635
21645
  const deleted = await deleteUserPreferenceOp(storageCtx, address);
21636
21646
  if (deleted && walletAddress && address === walletAddress) {
21637
21647
  patchUserSettingsSnapshot(database, walletAddress, { userPreference: null });
@@ -8855,7 +8855,14 @@ interface UpdateModelPreferenceOptions {
8855
8855
  * @inline
8856
8856
  */
8857
8857
  interface BaseUseSettingsOptions {
8858
- database: Database;
8858
+ /**
8859
+ * The WatermelonDB instance. May be `null` while the database is not yet
8860
+ * bound (e.g. during cold start / logged-out renders on mobile, where the
8861
+ * wrapper holds `null` until the wallet resolves). When `null`, the hook is
8862
+ * inert: `userPreference`/`modelPreference` are `null`, `isLoading` is
8863
+ * `false`, and mutation callbacks reject with a clear error.
8864
+ */
8865
+ database: Database | null;
8859
8866
  walletAddress?: string;
8860
8867
  }
8861
8868
  interface BaseUseSettingsResult {
@@ -8855,7 +8855,14 @@ interface UpdateModelPreferenceOptions {
8855
8855
  * @inline
8856
8856
  */
8857
8857
  interface BaseUseSettingsOptions {
8858
- database: Database;
8858
+ /**
8859
+ * The WatermelonDB instance. May be `null` while the database is not yet
8860
+ * bound (e.g. during cold start / logged-out renders on mobile, where the
8861
+ * wrapper holds `null` until the wallet resolves). When `null`, the hook is
8862
+ * inert: `userPreference`/`modelPreference` are `null`, `isLoading` is
8863
+ * `false`, and mutation callbacks reject with a clear error.
8864
+ */
8865
+ database: Database | null;
8859
8866
  walletAddress?: string;
8860
8867
  }
8861
8868
  interface BaseUseSettingsResult {
@@ -14142,7 +14142,7 @@ function startObserve(entry, walletAddress) {
14142
14142
  isInitialEmission = false;
14143
14143
  }
14144
14144
  function subscribeUserSettings(database, walletAddress, listener) {
14145
- if (!walletAddress) return () => void 0;
14145
+ if (!database || !walletAddress) return () => void 0;
14146
14146
  const perDb = getOrCreatePerDb(database);
14147
14147
  let entry = perDb.get(walletAddress);
14148
14148
  if (!entry) {
@@ -14172,17 +14172,18 @@ function subscribeUserSettings(database, walletAddress, listener) {
14172
14172
  };
14173
14173
  }
14174
14174
  function getUserSettingsSnapshot(database, walletAddress) {
14175
- if (!walletAddress) return EMPTY_SNAPSHOT;
14175
+ if (!database || !walletAddress) return EMPTY_SNAPSHOT;
14176
14176
  return pool.get(database)?.get(walletAddress)?.snapshot ?? EMPTY_SNAPSHOT;
14177
14177
  }
14178
14178
  function patchUserSettingsSnapshot(database, walletAddress, patch) {
14179
- if (!walletAddress) return;
14179
+ if (!database || !walletAddress) return;
14180
14180
  const entry = pool.get(database)?.get(walletAddress);
14181
14181
  if (!entry) return;
14182
14182
  patchSnapshot(entry, patch);
14183
14183
  }
14184
14184
 
14185
14185
  // src/react/useSettings.ts
14186
+ var DB_NOT_READY = "Database not ready";
14186
14187
  function useSettings(options) {
14187
14188
  const { database, walletAddress } = options;
14188
14189
  const subscribe = useCallback7(
@@ -14195,24 +14196,25 @@ function useSettings(options) {
14195
14196
  );
14196
14197
  const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
14197
14198
  const storageCtx = useMemo7(
14198
- () => ({
14199
+ () => database ? {
14199
14200
  database,
14200
14201
  userPreferencesCollection: database.get("userPreferences"),
14201
14202
  modelPreferencesCollection: database.get("modelPreferences")
14202
- }),
14203
+ } : null,
14203
14204
  [database]
14204
14205
  );
14205
14206
  const legacyStorageCtx = useMemo7(
14206
- () => ({
14207
+ () => database ? {
14207
14208
  database,
14208
14209
  modelPreferencesCollection: database.get("modelPreferences")
14209
- }),
14210
+ } : null,
14210
14211
  [database]
14211
14212
  );
14212
14213
  const getModelPreference = useCallback7(
14213
14214
  async (address) => {
14214
14215
  try {
14215
14216
  if (!address) throw new Error("Wallet address is required");
14217
+ if (!legacyStorageCtx) throw new Error(DB_NOT_READY);
14216
14218
  const result = await getModelPreferenceOp(legacyStorageCtx, address);
14217
14219
  return result;
14218
14220
  } catch (error) {
@@ -14225,6 +14227,7 @@ function useSettings(options) {
14225
14227
  async (address, models) => {
14226
14228
  try {
14227
14229
  if (!address) throw new Error("Wallet address is required");
14230
+ if (!legacyStorageCtx) throw new Error(DB_NOT_READY);
14228
14231
  const result = await setModelPreferenceOp(legacyStorageCtx, address, models);
14229
14232
  if (walletAddress && address === walletAddress) {
14230
14233
  patchUserSettingsSnapshot(database, walletAddress, { modelPreference: result });
@@ -14240,6 +14243,7 @@ function useSettings(options) {
14240
14243
  async (address) => {
14241
14244
  try {
14242
14245
  if (!address) throw new Error("Wallet address is required");
14246
+ if (!legacyStorageCtx) throw new Error(DB_NOT_READY);
14243
14247
  const deleted = await deleteModelPreferenceOp(legacyStorageCtx, address);
14244
14248
  if (deleted && walletAddress && address === walletAddress) {
14245
14249
  patchUserSettingsSnapshot(database, walletAddress, { modelPreference: null });
@@ -14255,6 +14259,7 @@ function useSettings(options) {
14255
14259
  async (address) => {
14256
14260
  try {
14257
14261
  if (!address) throw new Error("Wallet address is required");
14262
+ if (!storageCtx) throw new Error(DB_NOT_READY);
14258
14263
  const result = await getUserPreferenceOp(storageCtx, address);
14259
14264
  return result;
14260
14265
  } catch (error) {
@@ -14267,6 +14272,7 @@ function useSettings(options) {
14267
14272
  async (address, opts) => {
14268
14273
  try {
14269
14274
  if (!address) throw new Error("Wallet address is required");
14275
+ if (!storageCtx) throw new Error(DB_NOT_READY);
14270
14276
  const result = await setUserPreferenceOp(storageCtx, address, opts);
14271
14277
  if (walletAddress && address === walletAddress) {
14272
14278
  patchUserSettingsSnapshot(database, walletAddress, { userPreference: result });
@@ -14282,6 +14288,7 @@ function useSettings(options) {
14282
14288
  async (address, profile) => {
14283
14289
  try {
14284
14290
  if (!address) throw new Error("Wallet address is required");
14291
+ if (!storageCtx) throw new Error(DB_NOT_READY);
14285
14292
  const result = await updateProfileOp(storageCtx, address, profile);
14286
14293
  if (result && walletAddress && address === walletAddress) {
14287
14294
  patchUserSettingsSnapshot(database, walletAddress, { userPreference: result });
@@ -14297,6 +14304,7 @@ function useSettings(options) {
14297
14304
  async (address, personality) => {
14298
14305
  try {
14299
14306
  if (!address) throw new Error("Wallet address is required");
14307
+ if (!storageCtx) throw new Error(DB_NOT_READY);
14300
14308
  const result = await updatePersonalityOp(storageCtx, address, personality);
14301
14309
  if (result && walletAddress && address === walletAddress) {
14302
14310
  patchUserSettingsSnapshot(database, walletAddress, { userPreference: result });
@@ -14312,6 +14320,7 @@ function useSettings(options) {
14312
14320
  async (address, models) => {
14313
14321
  try {
14314
14322
  if (!address) throw new Error("Wallet address is required");
14323
+ if (!storageCtx) throw new Error(DB_NOT_READY);
14315
14324
  const result = await updateModelsOp(storageCtx, address, models);
14316
14325
  if (result && walletAddress && address === walletAddress) {
14317
14326
  patchUserSettingsSnapshot(database, walletAddress, { userPreference: result });
@@ -14327,6 +14336,7 @@ function useSettings(options) {
14327
14336
  async (address) => {
14328
14337
  try {
14329
14338
  if (!address) throw new Error("Wallet address is required");
14339
+ if (!storageCtx) throw new Error(DB_NOT_READY);
14330
14340
  const deleted = await deleteUserPreferenceOp(storageCtx, address);
14331
14341
  if (deleted && walletAddress && address === walletAddress) {
14332
14342
  patchUserSettingsSnapshot(database, walletAddress, { userPreference: null });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",