mnemospark 0.2.0 → 0.2.2

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.
package/dist/cli.js CHANGED
@@ -2752,16 +2752,21 @@ import { privateKeyToAccount as privateKeyToAccount5 } from "viem/accounts";
2752
2752
  // src/cloud-datastore.ts
2753
2753
  import { randomUUID as randomUUID2 } from "crypto";
2754
2754
  import { mkdir as mkdir4 } from "fs/promises";
2755
+ import { createRequire as createRequire2 } from "module";
2755
2756
  import { homedir as homedir5 } from "os";
2756
2757
  import { dirname as dirname4, join as join7 } from "path";
2757
2758
  var DB_SUBPATH = join7(".openclaw", "mnemospark", "state.db");
2758
2759
  var SCHEMA_VERSION = 3;
2760
+ var require3 = createRequire2(import.meta.url);
2759
2761
  function resolveDbPath(homeDir) {
2760
2762
  return join7(homeDir ?? homedir5(), DB_SUBPATH);
2761
2763
  }
2762
2764
  function nowIso() {
2763
2765
  return (/* @__PURE__ */ new Date()).toISOString();
2764
2766
  }
2767
+ function normalizeWalletAddress(value) {
2768
+ return value.trim().toLowerCase();
2769
+ }
2765
2770
  async function createCloudDatastore(homeDir) {
2766
2771
  const dbPath = resolveDbPath(homeDir);
2767
2772
  let db = null;
@@ -2771,12 +2776,12 @@ async function createCloudDatastore(homeDir) {
2771
2776
  throw new Error("SQLite disabled by MNEMOSPARK_DISABLE_SQLITE=1");
2772
2777
  }
2773
2778
  await mkdir4(dirname4(dbPath), { recursive: true });
2774
- const sqliteMod = await import("sqlite");
2775
- const DatabaseSync = sqliteMod.DatabaseSync;
2776
- if (!DatabaseSync) {
2779
+ const sqliteMod = require3("node:sqlite");
2780
+ const DatabaseSyncCtor = sqliteMod.DatabaseSync;
2781
+ if (!DatabaseSyncCtor) {
2777
2782
  throw new Error("node:sqlite DatabaseSync is unavailable");
2778
2783
  }
2779
- const nextDb = new DatabaseSync(dbPath);
2784
+ const nextDb = new DatabaseSyncCtor(dbPath);
2780
2785
  nextDb.exec("PRAGMA journal_mode=WAL;");
2781
2786
  nextDb.exec("PRAGMA foreign_keys=ON;");
2782
2787
  nextDb.exec(`
@@ -2861,6 +2866,19 @@ async function createCloudDatastore(homeDir) {
2861
2866
  CREATE INDEX IF NOT EXISTS idx_friendly_names_wallet ON friendly_names(wallet_address);
2862
2867
  CREATE INDEX IF NOT EXISTS idx_friendly_names_created_at ON friendly_names(created_at);
2863
2868
  `);
2869
+ nextDb.exec(`
2870
+ UPDATE objects
2871
+ SET wallet_address = lower(trim(wallet_address))
2872
+ WHERE wallet_address <> lower(trim(wallet_address));
2873
+
2874
+ UPDATE payments
2875
+ SET wallet_address = lower(trim(wallet_address))
2876
+ WHERE wallet_address <> lower(trim(wallet_address));
2877
+
2878
+ UPDATE friendly_names
2879
+ SET wallet_address = lower(trim(wallet_address))
2880
+ WHERE wallet_address <> lower(trim(wallet_address));
2881
+ `);
2864
2882
  const addOperationsColumn = (columnName, sqlType) => {
2865
2883
  try {
2866
2884
  nextDb.exec(`ALTER TABLE operations ADD COLUMN ${columnName} ${sqlType}`);
@@ -2899,6 +2917,7 @@ async function createCloudDatastore(homeDir) {
2899
2917
  ensureReady,
2900
2918
  upsertObject: async (row) => {
2901
2919
  await safe(() => {
2920
+ const normalizedWalletAddress = normalizeWalletAddress(row.wallet_address);
2902
2921
  const ts = nowIso();
2903
2922
  db.prepare(
2904
2923
  `INSERT INTO objects(object_id, object_key, wallet_address, quote_id, provider, bucket_name, region, sha256, status, created_at, updated_at)
@@ -2916,7 +2935,7 @@ async function createCloudDatastore(homeDir) {
2916
2935
  ).run(
2917
2936
  row.object_id,
2918
2937
  row.object_key,
2919
- row.wallet_address,
2938
+ normalizedWalletAddress,
2920
2939
  row.quote_id,
2921
2940
  row.provider,
2922
2941
  row.bucket_name,
@@ -2949,6 +2968,7 @@ async function createCloudDatastore(homeDir) {
2949
2968
  }, null),
2950
2969
  upsertPayment: async (row) => {
2951
2970
  await safe(() => {
2971
+ const normalizedWalletAddress = normalizeWalletAddress(row.wallet_address);
2952
2972
  const ts = nowIso();
2953
2973
  db.prepare(
2954
2974
  `INSERT INTO payments(quote_id, wallet_address, trans_id, amount, network, status, settled_at, created_at, updated_at)
@@ -2963,7 +2983,7 @@ async function createCloudDatastore(homeDir) {
2963
2983
  updated_at=excluded.updated_at`
2964
2984
  ).run(
2965
2985
  row.quote_id,
2966
- row.wallet_address,
2986
+ normalizedWalletAddress,
2967
2987
  row.trans_id,
2968
2988
  row.amount,
2969
2989
  row.network,
@@ -3085,6 +3105,7 @@ async function createCloudDatastore(homeDir) {
3085
3105
  }, null),
3086
3106
  upsertFriendlyName: async (row) => {
3087
3107
  await safe(() => {
3108
+ const normalizedWalletAddress = normalizeWalletAddress(row.wallet_address);
3088
3109
  const ts = nowIso();
3089
3110
  db.prepare(
3090
3111
  `INSERT INTO friendly_names(friendly_name_id, friendly_name, object_id, object_key, quote_id, wallet_address, created_at, updated_at, is_active)
@@ -3095,7 +3116,7 @@ async function createCloudDatastore(homeDir) {
3095
3116
  row.object_id,
3096
3117
  row.object_key,
3097
3118
  row.quote_id,
3098
- row.wallet_address,
3119
+ normalizedWalletAddress,
3099
3120
  ts,
3100
3121
  ts,
3101
3122
  row.is_active ?? 1
@@ -3103,6 +3124,7 @@ async function createCloudDatastore(homeDir) {
3103
3124
  }, void 0);
3104
3125
  },
3105
3126
  resolveFriendlyName: async (params) => safe(() => {
3127
+ const normalizedWalletAddress = normalizeWalletAddress(params.walletAddress);
3106
3128
  const atIso = params.at ? new Date(params.at).toISOString() : null;
3107
3129
  const row = params.latest || !atIso ? db.prepare(
3108
3130
  `SELECT friendly_name_id, friendly_name, object_id, object_key, quote_id, wallet_address, created_at
@@ -3110,13 +3132,13 @@ async function createCloudDatastore(homeDir) {
3110
3132
  WHERE wallet_address = ? AND friendly_name = ? AND is_active = 1
3111
3133
  ORDER BY created_at DESC
3112
3134
  LIMIT 1`
3113
- ).get(params.walletAddress, params.friendlyName) : db.prepare(
3135
+ ).get(normalizedWalletAddress, params.friendlyName) : db.prepare(
3114
3136
  `SELECT friendly_name_id, friendly_name, object_id, object_key, quote_id, wallet_address, created_at
3115
3137
  FROM friendly_names
3116
3138
  WHERE wallet_address = ? AND friendly_name = ? AND is_active = 1 AND created_at <= ?
3117
3139
  ORDER BY created_at DESC
3118
3140
  LIMIT 1`
3119
- ).get(params.walletAddress, params.friendlyName, atIso);
3141
+ ).get(normalizedWalletAddress, params.friendlyName, atIso);
3120
3142
  if (!row) return null;
3121
3143
  return {
3122
3144
  friendlyNameId: row.friendly_name_id,
@@ -3129,11 +3151,12 @@ async function createCloudDatastore(homeDir) {
3129
3151
  };
3130
3152
  }, null),
3131
3153
  countFriendlyNameMatches: async (walletAddress, friendlyName) => safe(() => {
3154
+ const normalizedWalletAddress = normalizeWalletAddress(walletAddress);
3132
3155
  const row = db.prepare(
3133
3156
  `SELECT COUNT(1) AS cnt
3134
3157
  FROM friendly_names
3135
3158
  WHERE wallet_address = ? AND friendly_name = ? AND is_active = 1`
3136
- ).get(walletAddress, friendlyName);
3159
+ ).get(normalizedWalletAddress, friendlyName);
3137
3160
  return Number(row?.cnt ?? 0);
3138
3161
  }, 0)
3139
3162
  };
@@ -3264,7 +3287,7 @@ function parseNamedFlagsTokens(tokens, booleanFlags = /* @__PURE__ */ new Set())
3264
3287
  if (!keyToken.startsWith("--")) {
3265
3288
  return null;
3266
3289
  }
3267
- const key = keyToken.slice(2).toLowerCase();
3290
+ const key = keyToken.slice(2).toLowerCase().replace(/_/g, "-");
3268
3291
  const value = tokens[i + 1];
3269
3292
  if (!value || value.startsWith("--")) {
3270
3293
  if (booleanFlags.has(key)) {
@@ -4268,7 +4291,7 @@ async function resolveFriendlyNameFromManifest(params, homeDir) {
4268
4291
  } catch {
4269
4292
  return { objectKey: null, matchCount: 0 };
4270
4293
  }
4271
- const wallet = params.walletAddress.trim();
4294
+ const wallet = params.walletAddress.trim().toLowerCase();
4272
4295
  const name = params.friendlyName.trim();
4273
4296
  const atMs = params.at ? Date.parse(params.at) : Number.NaN;
4274
4297
  const hasAt = Number.isFinite(atMs);
@@ -4282,7 +4305,7 @@ async function resolveFriendlyNameFromManifest(params, homeDir) {
4282
4305
  if (!row.object_key || !row.friendly_name || !row.wallet_address || !row.created_at)
4283
4306
  return false;
4284
4307
  if (row.friendly_name !== name) return false;
4285
- if (row.wallet_address.trim() !== wallet) return false;
4308
+ if (row.wallet_address.trim().toLowerCase() !== wallet) return false;
4286
4309
  if (params.latest || !hasAt) return true;
4287
4310
  const createdAtMs = Date.parse(row.created_at);
4288
4311
  return Number.isFinite(createdAtMs) && createdAtMs <= atMs;