@dshtrading/watchlist 0.1.2 → 0.1.4

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/lib/file-store.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { WATCHLIST_SEEDS } from "./seeds.js";
1
2
  import { dirname } from "node:path";
2
3
  import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
3
4
  //#region src/file-store.ts
@@ -86,7 +87,8 @@ function createFileWatchlistStore(filePath) {
86
87
  async remove(market, symbol) {
87
88
  return enqueue(async () => {
88
89
  const map = await load();
89
- const rows = map[market] ?? [];
90
+ const existing = map[market];
91
+ const rows = Array.isArray(existing) ? existing : WATCHLIST_SEEDS[market] ?? [];
90
92
  const nextRows = rows.filter((row) => row.symbol !== symbol);
91
93
  if (nextRows.length === rows.length) return false;
92
94
  const next = {
package/lib/index.js CHANGED
@@ -20,7 +20,8 @@ function createMemoryWatchlistStore(initial = {}) {
20
20
  return true;
21
21
  },
22
22
  async remove(market, symbol) {
23
- const rows = map[market] ?? [];
23
+ const existing = map[market];
24
+ const rows = Array.isArray(existing) ? existing : WATCHLIST_SEEDS[market] ?? [];
24
25
  const next = rows.filter((row) => row.symbol !== symbol);
25
26
  if (next.length === rows.length) return false;
26
27
  map = {
package/lib/plugin.js CHANGED
@@ -44,7 +44,7 @@ function createWatchlistListTool(deps) {
44
44
  },
45
45
  async execute() {
46
46
  const map = await deps.watchlists.list();
47
- const markets = [.../* @__PURE__ */ new Set([...Object.keys(map), ...Object.keys(WATCHLIST_SEEDS)])].filter((market) => effectiveWatchlistRows(map, market).length > 0);
47
+ const markets = [.../* @__PURE__ */ new Set([...Object.keys(WATCHLIST_SEEDS), ...Object.keys(map)])];
48
48
  const watchlists = {};
49
49
  const sources = {};
50
50
  let total = 0;
package/lib/seeds.d.ts CHANGED
@@ -2,9 +2,9 @@ import { WatchlistInstrument, WatchlistsMap } from "./index.js";
2
2
  //#region src/seeds.d.ts
3
3
  /** 各市场种子行(connector-validated symbol formats)。 */
4
4
  declare const WATCHLIST_SEEDS: WatchlistsMap;
5
- /** 单市场展示行:用户定制行优先;未定制(缺键/空数组)回落该市场种子。 */
5
+ /** 单市场展示行:用户定制行优先;未定制(缺键)回落该市场种子。已定制(包括空数组)以用户定制为准。 */
6
6
  declare function effectiveWatchlistRows(map: WatchlistsMap, market: string): WatchlistInstrument[];
7
- /** 单市场行来源:'custom' = 用户定制行;'seed' = 种子展示行(未定制)。 */
7
+ /** 单市场行来源:'custom' = 用户定制行(键存在);'seed' = 种子展示行(未定制,缺键)。 */
8
8
  declare function watchlistRowSource(map: WatchlistsMap, market: string): 'custom' | 'seed';
9
9
  //#endregion
10
10
  export { WATCHLIST_SEEDS, effectiveWatchlistRows, watchlistRowSource };
package/lib/seeds.js CHANGED
@@ -80,16 +80,16 @@ const WATCHLIST_SEEDS = {
80
80
  }
81
81
  ]
82
82
  };
83
- /** 单市场展示行:用户定制行优先;未定制(缺键/空数组)回落该市场种子。 */
83
+ /** 单市场展示行:用户定制行优先;未定制(缺键)回落该市场种子。已定制(包括空数组)以用户定制为准。 */
84
84
  function effectiveWatchlistRows(map, market) {
85
85
  const rows = map[market];
86
- if (rows !== void 0 && rows.length > 0) return rows;
86
+ if (Array.isArray(rows)) return rows;
87
87
  return WATCHLIST_SEEDS[market] ?? [];
88
88
  }
89
- /** 单市场行来源:'custom' = 用户定制行;'seed' = 种子展示行(未定制)。 */
89
+ /** 单市场行来源:'custom' = 用户定制行(键存在);'seed' = 种子展示行(未定制,缺键)。 */
90
90
  function watchlistRowSource(map, market) {
91
91
  const rows = map[market];
92
- return rows !== void 0 && rows.length > 0 ? "custom" : "seed";
92
+ return Array.isArray(rows) ? "custom" : "seed";
93
93
  }
94
94
  //#endregion
95
95
  export { WATCHLIST_SEEDS, effectiveWatchlistRows, watchlistRowSource };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dshtrading/watchlist",
3
3
  "description": "Host-side watchlist + selection stores for dsh-trading: multi-list file store (~/.dsh/watchlists.json), selection store (~/.dsh/selection.json), and cross-market watchlist_* tools (watchlist_list/add/remove/select) on the host plane",
4
- "version": "0.1.2",
4
+ "version": "0.1.4",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "./lib/index.d.ts",