@nsnanocat/util 2.2.4 → 2.3.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.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  核心目标:
6
6
  - 统一不同平台的 HTTP、通知、持久化、结束脚本等调用方式。
7
7
  - 在一个脚本里尽量少写平台分支。
8
- - 提供一组可直接复用的 polyfill(`fetch` / `Storage` / `Console` / `Lodash`)。
8
+ - 提供一组可直接复用的 polyfill(`fetch` / `Storage` / `KV` / `Console` / `Lodash`)。
9
9
 
10
10
  ## 目录
11
11
  - [安装与导入](#安装与导入)
@@ -65,6 +65,7 @@ import {
65
65
  wait, // 延时等待工具(Promise)
66
66
  Console, // 统一日志工具(支持 logLevel)
67
67
  Lodash as _, // Lodash 建议按官方示例惯例使用 `_` 作为工具对象别名
68
+ KV, // Cloudflare Workers KV 异步适配器(显式传入 namespace binding)
68
69
  Storage, // 统一持久化存储接口(适配 $prefs / $persistentStore / 内存 / 文件)
69
70
  } from "@nsnanocat/util";
70
71
  ```
@@ -80,6 +81,7 @@ import {
80
81
  - `lib/wait.mjs`
81
82
  - `polyfill/Console.mjs`
82
83
  - `polyfill/fetch.mjs`
84
+ - `polyfill/KV.mjs`
83
85
  - `polyfill/Lodash.mjs`
84
86
  - `polyfill/StatusTexts.mjs`
85
87
  - `polyfill/Storage.mjs`
@@ -106,6 +108,7 @@ import {
106
108
  | `getStorage.mjs` | `lib/argument.mjs`, `polyfill/Console.mjs`, `polyfill/Lodash.mjs`, `polyfill/Storage.mjs` | `Console.debug`, `Console.logLevel`, `Lodash.merge`, `Storage.getItem` | 先标准化 `$argument`,再合并默认配置/持久化配置/运行参数 |
107
109
  | `polyfill/Console.mjs` | `lib/app.mjs` | `$app` | 日志在 Worker / Node.js 与 iOS 脚本环境使用不同错误输出策略 |
108
110
  | `polyfill/fetch.mjs` | `lib/app.mjs`, `polyfill/Lodash.mjs`, `polyfill/StatusTexts.mjs`, `polyfill/Console.mjs` | `$app`, `Lodash.set`, `StatusTexts`(`Console` 当前版本未实际调用) | 按平台选请求引擎并做参数映射、响应结构统一 |
111
+ | `polyfill/KV.mjs` | `lib/app.mjs`, `polyfill/Lodash.mjs`, `polyfill/Storage.mjs` | `$app`, `Lodash.get`, `Lodash.set`, `Lodash.unset`, `Storage` | 为 Cloudflare Workers KV 提供异步适配,并在非 Worker 平台回退到 `Storage` |
109
112
  | `polyfill/Storage.mjs` | `lib/app.mjs`, `polyfill/Lodash.mjs` | `$app`, `Lodash.get`, `Lodash.set`, `Lodash.unset` | 按平台选持久化后端并支持 `@key.path` 读写 |
110
113
  | `polyfill/Lodash.mjs` | 无 | 无 | 提供路径/合并等基础能力,被多个模块复用 |
111
114
  | `polyfill/StatusTexts.mjs` | 无 | 无 | 提供 HTTP 状态文案,供 `fetch/done` 使用 |
@@ -471,6 +474,39 @@ const store = getStorage("@my_box", ["YouTube", "Global"], database);
471
474
  | Worker | 进程内内存缓存 |
472
475
  | Node.js | 本地 `box.dat` |
473
476
 
477
+ ### `polyfill/KV.mjs`
478
+
479
+ `KV` 是面向 Cloudflare Workers KV 的异步适配器:
480
+ - 调用方显式传入 namespace binding:`new KV(env.NAMESPACE)`
481
+ - Worker 分支直接调用 `namespace.get/put/delete/list`
482
+ - `get()` 不传 `type`,默认按 Cloudflare 行为读取字符串
483
+ - 非 Worker 平台会回退到 `Storage.getItem/setItem/removeItem`
484
+ - `list()` 仅支持 Worker,返回 Cloudflare KV 原生列举结果
485
+ - `clear()` 始终返回 `false`
486
+
487
+ #### `new KV(namespace)`
488
+ - `namespace` 需提供 `get(key)` / `put(key, value)` / `delete(key)`。
489
+
490
+ #### `await kv.getItem(keyName, defaultValue = null)`
491
+ - 支持普通 key。
492
+ - 支持路径 key:`@root.path.to.key`。
493
+ - 读取后会尝试 `JSON.parse`。
494
+
495
+ #### `await kv.setItem(keyName, keyValue)`
496
+ - 支持普通 key 与路径 key。
497
+ - `keyValue` 为对象时自动 `JSON.stringify`。
498
+
499
+ #### `await kv.removeItem(keyName)`
500
+ - 支持普通 key 与路径 key。
501
+
502
+ #### `await kv.list(options = {})`
503
+ - 仅支持 Worker。
504
+ - 透传 `prefix` / `limit` / `cursor` 到 `namespace.list(options)`。
505
+ - 返回 Cloudflare KV 的原生结果:`keys` / `list_complete` / `cursor`。
506
+
507
+ #### `await kv.clear()`
508
+ - 始终返回 `false`。
509
+
474
510
  ### `polyfill/Console.mjs`
475
511
 
476
512
  `Console` 是统一日志工具(静态类)。
package/index.js CHANGED
@@ -6,6 +6,7 @@ export * from "./lib/time.mjs";
6
6
  export * from "./lib/wait.mjs";
7
7
  export * from "./polyfill/Console.mjs";
8
8
  export * from "./polyfill/fetch.mjs";
9
+ export * from "./polyfill/KV.mjs";
9
10
  export * from "./polyfill/Lodash.mjs";
10
11
  export * from "./polyfill/StatusTexts.mjs";
11
12
  export * from "./polyfill/Storage.mjs";
package/package.json CHANGED
@@ -42,5 +42,5 @@
42
42
  "registry": "https://registry.npmjs.org/",
43
43
  "access": "public"
44
44
  },
45
- "version": "2.2.4"
45
+ "version": "2.3.0"
46
46
  }
@@ -0,0 +1,240 @@
1
+ import { $app } from "../lib/app.mjs";
2
+ import { Lodash as _ } from "./Lodash.mjs";
3
+ import { Storage } from "./Storage.mjs";
4
+
5
+ /**
6
+ * Cloudflare Workers KV 异步适配器。
7
+ * Async adapter for Cloudflare Workers KV.
8
+ *
9
+ * 设计目标:
10
+ * Design goal:
11
+ * - 提供与 `Storage` 接近的异步接口
12
+ * - Provide an async API close to `Storage`
13
+ * - 在 Worker 中使用显式传入的 KV namespace binding
14
+ * - Use an explicitly passed KV namespace binding in Workers
15
+ * - 在非 Worker 平台回退到 `Storage`
16
+ * - Fall back to `Storage` on non-Worker platforms
17
+ *
18
+ * 支持路径键:
19
+ * Supports path key:
20
+ * - `@root.path.to.value`
21
+ *
22
+ * @link https://developers.cloudflare.com/kv/get-started/#5-access-your-kv-namespace-from-your-worker
23
+ * @link https://developers.cloudflare.com/kv/api/read-key-value-pairs/
24
+ * @link https://developers.cloudflare.com/kv/api/write-key-value-pairs/
25
+ * @link https://developers.cloudflare.com/kv/api/delete-key-value-pairs/
26
+ * @link https://developers.cloudflare.com/kv/api/list-keys/
27
+ */
28
+ export class KV {
29
+ /**
30
+ * `@key.path` 解析正则。
31
+ * Regex for `@key.path` parsing.
32
+ *
33
+ * @type {RegExp}
34
+ */
35
+ static #nameRegex = /^@(?<key>[^.]+)(?:\.(?<path>.*))?$/;
36
+
37
+ /**
38
+ * Cloudflare KV namespace 绑定。
39
+ * Cloudflare KV namespace binding.
40
+ *
41
+ * @type {{ get(key: string): Promise<string|null>; put(key: string, value: string): Promise<void>; delete(key: string): Promise<void>; list?(options?: { prefix?: string; limit?: number; cursor?: string }): Promise<{ keys: { name: string; expiration?: number; metadata?: object }[]; list_complete: boolean; cursor: string }> } | undefined}
42
+ */
43
+ namespace;
44
+
45
+ /**
46
+ * 创建 KV 适配器实例。
47
+ * Create a KV adapter instance.
48
+ *
49
+ * @param {{ get(key: string): Promise<string|null>; put(key: string, value: string): Promise<void>; delete(key: string): Promise<void>; list?(options?: { prefix?: string; limit?: number; cursor?: string }): Promise<{ keys: { name: string; expiration?: number; metadata?: object }[]; list_complete: boolean; cursor: string }> } | null | undefined} namespace KV namespace 绑定 / KV namespace binding.
50
+ */
51
+ constructor(namespace) {
52
+ this.namespace = namespace ?? undefined;
53
+ }
54
+
55
+ /**
56
+ * 读取存储值。
57
+ * Read value from persistent storage.
58
+ *
59
+ * @param {string} keyName 键名或路径键 / Key or path key.
60
+ * @param {*} [defaultValue=null] 默认值 / Default value when key is missing.
61
+ * @returns {Promise<*>}
62
+ */
63
+ async getItem(keyName, defaultValue = null) {
64
+ let keyValue = defaultValue;
65
+ switch (keyName.startsWith("@")) {
66
+ case true: {
67
+ const { key, path } = keyName.match(KV.#nameRegex)?.groups ?? {};
68
+ keyName = key;
69
+ let value = await this.getItem(keyName, {});
70
+ if (typeof value !== "object" || value === null) value = {};
71
+ keyValue = _.get(value, path);
72
+ keyValue = KV.#deserialize(keyValue);
73
+ break;
74
+ }
75
+ default:
76
+ switch ($app) {
77
+ case "Worker":
78
+ keyValue = await this.#getNamespace().get(keyName);
79
+ break;
80
+ default:
81
+ keyValue = Storage.getItem(keyName, defaultValue);
82
+ break;
83
+ }
84
+ keyValue = KV.#deserialize(keyValue);
85
+ break;
86
+ }
87
+ return keyValue ?? defaultValue;
88
+ }
89
+
90
+ /**
91
+ * 写入存储值。
92
+ * Write value into persistent storage.
93
+ *
94
+ * @param {string} keyName 键名或路径键 / Key or path key.
95
+ * @param {*} keyValue 写入值 / Value to store.
96
+ * @returns {Promise<boolean>}
97
+ */
98
+ async setItem(keyName = new String(), keyValue = new String()) {
99
+ let result = false;
100
+ keyValue = KV.#serialize(keyValue);
101
+ switch (keyName.startsWith("@")) {
102
+ case true: {
103
+ const { key, path } = keyName.match(KV.#nameRegex)?.groups ?? {};
104
+ keyName = key;
105
+ let value = await this.getItem(keyName, {});
106
+ if (typeof value !== "object" || value === null) value = {};
107
+ _.set(value, path, keyValue);
108
+ result = await this.setItem(keyName, value);
109
+ break;
110
+ }
111
+ default:
112
+ switch ($app) {
113
+ case "Worker":
114
+ await this.#getNamespace().put(keyName, keyValue);
115
+ result = true;
116
+ break;
117
+ default:
118
+ result = Storage.setItem(keyName, keyValue);
119
+ break;
120
+ }
121
+ break;
122
+ }
123
+ return result;
124
+ }
125
+
126
+ /**
127
+ * 删除存储值。
128
+ * Remove value from persistent storage.
129
+ *
130
+ * @param {string} keyName 键名或路径键 / Key or path key.
131
+ * @returns {Promise<boolean>}
132
+ */
133
+ async removeItem(keyName) {
134
+ let result = false;
135
+ switch (keyName.startsWith("@")) {
136
+ case true: {
137
+ const { key, path } = keyName.match(KV.#nameRegex)?.groups ?? {};
138
+ keyName = key;
139
+ let value = await this.getItem(keyName);
140
+ if (typeof value !== "object" || value === null) value = {};
141
+ _.unset(value, path);
142
+ result = await this.setItem(keyName, value);
143
+ break;
144
+ }
145
+ default:
146
+ switch ($app) {
147
+ case "Worker":
148
+ await this.#getNamespace().delete(keyName);
149
+ result = true;
150
+ break;
151
+ default:
152
+ result = Storage.removeItem(keyName);
153
+ break;
154
+ }
155
+ break;
156
+ }
157
+ return result;
158
+ }
159
+
160
+ /**
161
+ * 清空存储。
162
+ * Clear storage.
163
+ *
164
+ * @returns {Promise<boolean>}
165
+ */
166
+ async clear() {
167
+ return false;
168
+ }
169
+
170
+ /**
171
+ * 列出命名空间中的键。
172
+ * List keys in the namespace.
173
+ *
174
+ * @param {{ prefix?: string; limit?: number; cursor?: string }} [options={}] 列举选项 / List options.
175
+ * @returns {Promise<{ keys: { name: string; expiration?: number; metadata?: object }[]; list_complete: boolean; cursor: string }>}
176
+ */
177
+ async list(options = {}) {
178
+ switch ($app) {
179
+ case "Worker": {
180
+ const namespace = this.#getNamespace();
181
+ if (typeof namespace.list !== "function") throw new TypeError("KV namespace binding with list() is required in Worker runtime.");
182
+ return await namespace.list(options);
183
+ }
184
+ default:
185
+ throw new TypeError("KV.list() is only supported in Worker runtime.");
186
+ }
187
+ }
188
+
189
+ /**
190
+ * 解析 Worker 所需的 namespace 绑定。
191
+ * Resolve the namespace binding required by Workers.
192
+ *
193
+ * @private
194
+ * @returns {{ get(key: string): Promise<string|null>; put(key: string, value: string): Promise<void>; delete(key: string): Promise<void>; list?(options?: { prefix?: string; limit?: number; cursor?: string }): Promise<{ keys: { name: string; expiration?: number; metadata?: object }[]; list_complete: boolean; cursor: string }> }}
195
+ */
196
+ #getNamespace() {
197
+ if (
198
+ !this.namespace ||
199
+ typeof this.namespace.get !== "function" ||
200
+ typeof this.namespace.put !== "function" ||
201
+ typeof this.namespace.delete !== "function"
202
+ ) {
203
+ throw new TypeError("KV namespace binding is required in Worker runtime.");
204
+ }
205
+ return this.namespace;
206
+ }
207
+
208
+ /**
209
+ * 尝试将字符串反序列化为原始值。
210
+ * Try to deserialize a string into its original value.
211
+ *
212
+ * @private
213
+ * @param {*} value 原始值 / Raw value.
214
+ * @returns {*}
215
+ */
216
+ static #deserialize(value) {
217
+ try {
218
+ return JSON.parse(value);
219
+ } catch (e) {
220
+ return value;
221
+ }
222
+ }
223
+
224
+ /**
225
+ * 规范化待写入的值。
226
+ * Normalize a value before persisting it.
227
+ *
228
+ * @private
229
+ * @param {*} value 原始值 / Raw value.
230
+ * @returns {string}
231
+ */
232
+ static #serialize(value) {
233
+ switch (typeof value) {
234
+ case "object":
235
+ return JSON.stringify(value);
236
+ default:
237
+ return String(value);
238
+ }
239
+ }
240
+ }
@@ -245,9 +245,7 @@ export async function fetch(resource, options = {}) {
245
245
  case "Node.js": {
246
246
  // Worker 复用宿主 `fetch`;Node.js 优先复用原生 `fetch`,缺失时再回退到 `node-fetch`。
247
247
  // Worker reuses host `fetch`; Node.js reuses native `fetch` first and falls back to `node-fetch`.
248
- if (!globalThis.fetch) {
249
- globalThis.fetch = require("node-fetch");
250
- }
248
+ if (!globalThis.fetch) globalThis.fetch = require("node-fetch");
251
249
  switch (resource["auto-cookie"]) {
252
250
  case undefined:
253
251
  case "true":
package/polyfill/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./Console.mjs";
2
2
  export * from "./fetch.mjs";
3
+ export * from "./KV.mjs";
3
4
  export * from "./Lodash.mjs";
4
5
  export * from "./StatusTexts.mjs";
5
6
  export * from "./Storage.mjs";
@@ -0,0 +1,54 @@
1
+ declare module "@nsnanocat/util" {
2
+ export type AppName =
3
+ | "Quantumult X"
4
+ | "Loon"
5
+ | "Shadowrocket"
6
+ | "Egern"
7
+ | "Surge"
8
+ | "Stash"
9
+ | "Worker"
10
+ | "Node.js";
11
+
12
+ export const $app: AppName | undefined;
13
+ export const $argument: Record<string, unknown>;
14
+ export const argument: typeof $argument;
15
+
16
+ export interface DonePayload {
17
+ status?: number | string;
18
+ url?: string;
19
+ headers?: Record<string, unknown>;
20
+ body?: string | ArrayBuffer | ArrayBufferView;
21
+ bodyBytes?: ArrayBuffer;
22
+ policy?: string;
23
+ }
24
+
25
+ export function done(object?: DonePayload): void;
26
+
27
+ export interface NotificationContentObject {
28
+ open?: string;
29
+ "open-url"?: string;
30
+ url?: string;
31
+ openUrl?: string;
32
+ copy?: string;
33
+ "update-pasteboard"?: string;
34
+ updatePasteboard?: string;
35
+ media?: string;
36
+ "media-url"?: string;
37
+ mediaUrl?: string;
38
+ mime?: string;
39
+ "auto-dismiss"?: number;
40
+ sound?: string;
41
+ }
42
+
43
+ export type NotificationContent = NotificationContentObject | string | number | boolean;
44
+
45
+ export function notification(
46
+ title?: string,
47
+ subtitle?: string,
48
+ body?: string,
49
+ content?: NotificationContent,
50
+ ): void;
51
+
52
+ export function time(format: string, ts?: number): string;
53
+ export function wait(delay?: number): Promise<void>;
54
+ }
@@ -0,0 +1,4 @@
1
+ declare module "@nsnanocat/util/lib/environment.mjs" {
2
+ export const $environment: Record<string, unknown>;
3
+ export function environment(): Record<string, unknown>;
4
+ }
@@ -0,0 +1,29 @@
1
+ declare module "@nsnanocat/util" {
2
+ export interface FetchRequest {
3
+ url: string;
4
+ method?: string;
5
+ headers?: Record<string, unknown>;
6
+ body?: string | ArrayBuffer | ArrayBufferView | object;
7
+ bodyBytes?: ArrayBuffer;
8
+ timeout?: number | string;
9
+ policy?: string;
10
+ redirection?: boolean;
11
+ "auto-redirect"?: boolean;
12
+ "auto-cookie"?: boolean | number | string;
13
+ opts?: Record<string, unknown>;
14
+ [key: string]: unknown;
15
+ }
16
+
17
+ export interface FetchResponse {
18
+ ok: boolean;
19
+ status: number;
20
+ statusCode?: number;
21
+ statusText?: string;
22
+ headers?: Record<string, unknown>;
23
+ body?: string | ArrayBuffer;
24
+ bodyBytes?: ArrayBuffer;
25
+ [key: string]: unknown;
26
+ }
27
+
28
+ export function fetch(resource: FetchRequest | string, options?: Partial<FetchRequest>): Promise<FetchResponse>;
29
+ }
@@ -0,0 +1,22 @@
1
+ declare module "@nsnanocat/util/getStorage.mjs" {
2
+ export interface StorageProfile {
3
+ Settings: Record<string, unknown>;
4
+ Configs: Record<string, unknown>;
5
+ Caches: Record<string, unknown>;
6
+ }
7
+
8
+ export function traverseObject(
9
+ o: Record<string, unknown>,
10
+ c: (key: string, value: unknown) => unknown,
11
+ ): Record<string, unknown>;
12
+
13
+ export function string2number(string: string): string | number;
14
+
15
+ export function value2array(value: string | number | boolean | string[] | null | undefined): Array<string | number | boolean>;
16
+
17
+ export default function getStorage(
18
+ key: string,
19
+ names: string | string[] | Array<string | string[]>,
20
+ database: Record<string, unknown>,
21
+ ): StorageProfile;
22
+ }
@@ -0,0 +1,35 @@
1
+ declare module "@nsnanocat/util" {
2
+ export interface KVNamespaceLike {
3
+ get(key: string): Promise<string | null>;
4
+ put(key: string, value: string): Promise<void>;
5
+ delete(key: string): Promise<void>;
6
+ list?(options?: KVListOptions): Promise<KVListResult>;
7
+ }
8
+
9
+ export interface KVListOptions {
10
+ prefix?: string;
11
+ limit?: number;
12
+ cursor?: string;
13
+ }
14
+
15
+ export interface KVListKey {
16
+ name: string;
17
+ expiration?: number;
18
+ metadata?: Record<string, unknown>;
19
+ }
20
+
21
+ export interface KVListResult {
22
+ keys: KVListKey[];
23
+ list_complete: boolean;
24
+ cursor: string;
25
+ }
26
+
27
+ export class KV {
28
+ constructor(namespace?: KVNamespaceLike | null);
29
+ getItem<T = unknown>(keyName: string, defaultValue?: T): Promise<T>;
30
+ setItem(keyName: string, keyValue: unknown): Promise<boolean>;
31
+ removeItem(keyName: string): Promise<boolean>;
32
+ clear(): Promise<boolean>;
33
+ list(options?: KVListOptions): Promise<KVListResult>;
34
+ }
35
+ }
@@ -0,0 +1,34 @@
1
+ declare module "@nsnanocat/util" {
2
+ export class Console {
3
+ static clear(): void;
4
+ static count(label?: string): void;
5
+ static countReset(label?: string): void;
6
+ static debug(...msg: unknown[]): void;
7
+ static error(...msg: unknown[]): void;
8
+ static exception(...msg: unknown[]): void;
9
+ static group(label: string): number;
10
+ static groupEnd(): string | undefined;
11
+ static info(...msg: unknown[]): void;
12
+ static get logLevel(): "OFF" | "ERROR" | "WARN" | "INFO" | "DEBUG" | "ALL";
13
+ static set logLevel(level: number | string);
14
+ static log(...msg: unknown[]): void;
15
+ static time(label?: string): Map<string, number>;
16
+ static timeEnd(label?: string): boolean;
17
+ static timeLog(label?: string): void;
18
+ static warn(...msg: unknown[]): void;
19
+ }
20
+
21
+ export class Lodash {
22
+ static escape(string: string): string;
23
+ static get<T = unknown, D = undefined>(object?: Record<string, unknown>, path?: string | string[], defaultValue?: D): T | D;
24
+ static merge<T extends Record<string, unknown>>(object: T, ...sources: Array<Record<string, unknown> | null | undefined>): T;
25
+ static omit<T extends Record<string, unknown>>(object?: T, paths?: string | string[]): T;
26
+ static pick<T extends Record<string, unknown>, K extends keyof T>(object?: T, paths?: K | K[]): Pick<T, K>;
27
+ static set<T extends Record<string, unknown>>(object: T, path: string | string[], value: unknown): T;
28
+ static toPath(value: string): string[];
29
+ static unescape(string: string): string;
30
+ static unset(object?: Record<string, unknown>, path?: string | string[]): boolean;
31
+ }
32
+
33
+ export const StatusTexts: Record<number, string>;
34
+ }
@@ -0,0 +1,10 @@
1
+ declare module "@nsnanocat/util" {
2
+ export class Storage {
3
+ static data: Record<string, unknown> | null;
4
+ static dataFile: string;
5
+ static getItem<T = unknown>(keyName: string, defaultValue?: T): T;
6
+ static setItem(keyName: string, keyValue: unknown): boolean;
7
+ static removeItem(keyName: string): boolean;
8
+ static clear(): boolean;
9
+ }
10
+ }
@@ -1,152 +1,7 @@
1
- declare module "@nsnanocat/util" {
2
- export type AppName =
3
- | "Quantumult X"
4
- | "Loon"
5
- | "Shadowrocket"
6
- | "Egern"
7
- | "Surge"
8
- | "Stash"
9
- | "Worker"
10
- | "Node.js";
11
-
12
- export const $app: AppName | undefined;
13
- export const $argument: Record<string, unknown>;
14
- export const argument: typeof $argument;
15
-
16
- export interface DonePayload {
17
- status?: number | string;
18
- url?: string;
19
- headers?: Record<string, unknown>;
20
- body?: string | ArrayBuffer | ArrayBufferView;
21
- bodyBytes?: ArrayBuffer;
22
- policy?: string;
23
- }
24
-
25
- export function done(object?: DonePayload): void;
26
-
27
- export interface NotificationContentObject {
28
- open?: string;
29
- "open-url"?: string;
30
- url?: string;
31
- openUrl?: string;
32
- copy?: string;
33
- "update-pasteboard"?: string;
34
- updatePasteboard?: string;
35
- media?: string;
36
- "media-url"?: string;
37
- mediaUrl?: string;
38
- mime?: string;
39
- "auto-dismiss"?: number;
40
- sound?: string;
41
- }
42
-
43
- export type NotificationContent = NotificationContentObject | string | number | boolean;
44
-
45
- export function notification(
46
- title?: string,
47
- subtitle?: string,
48
- body?: string,
49
- content?: NotificationContent,
50
- ): void;
51
-
52
- export function time(format: string, ts?: number): string;
53
- export function wait(delay?: number): Promise<void>;
54
-
55
- export interface FetchRequest {
56
- url: string;
57
- method?: string;
58
- headers?: Record<string, unknown>;
59
- body?: string | ArrayBuffer | ArrayBufferView | object;
60
- bodyBytes?: ArrayBuffer;
61
- timeout?: number | string;
62
- policy?: string;
63
- redirection?: boolean;
64
- "auto-redirect"?: boolean;
65
- "auto-cookie"?: boolean | number | string;
66
- opts?: Record<string, unknown>;
67
- [key: string]: unknown;
68
- }
69
-
70
- export interface FetchResponse {
71
- ok: boolean;
72
- status: number;
73
- statusCode?: number;
74
- statusText?: string;
75
- headers?: Record<string, unknown>;
76
- body?: string | ArrayBuffer;
77
- bodyBytes?: ArrayBuffer;
78
- [key: string]: unknown;
79
- }
80
-
81
- export function fetch(resource: FetchRequest | string, options?: Partial<FetchRequest>): Promise<FetchResponse>;
82
-
83
- export class Console {
84
- static clear(): void;
85
- static count(label?: string): void;
86
- static countReset(label?: string): void;
87
- static debug(...msg: unknown[]): void;
88
- static error(...msg: unknown[]): void;
89
- static exception(...msg: unknown[]): void;
90
- static group(label: string): number;
91
- static groupEnd(): string | undefined;
92
- static info(...msg: unknown[]): void;
93
- static get logLevel(): "OFF" | "ERROR" | "WARN" | "INFO" | "DEBUG" | "ALL";
94
- static set logLevel(level: number | string);
95
- static log(...msg: unknown[]): void;
96
- static time(label?: string): Map<string, number>;
97
- static timeEnd(label?: string): boolean;
98
- static timeLog(label?: string): void;
99
- static warn(...msg: unknown[]): void;
100
- }
101
-
102
- export class Lodash {
103
- static escape(string: string): string;
104
- static get<T = unknown, D = undefined>(object?: Record<string, unknown>, path?: string | string[], defaultValue?: D): T | D;
105
- static merge<T extends Record<string, unknown>>(object: T, ...sources: Array<Record<string, unknown> | null | undefined>): T;
106
- static omit<T extends Record<string, unknown>>(object?: T, paths?: string | string[]): T;
107
- static pick<T extends Record<string, unknown>, K extends keyof T>(object?: T, paths?: K | K[]): Pick<T, K>;
108
- static set<T extends Record<string, unknown>>(object: T, path: string | string[], value: unknown): T;
109
- static toPath(value: string): string[];
110
- static unescape(string: string): string;
111
- static unset(object?: Record<string, unknown>, path?: string | string[]): boolean;
112
- }
113
-
114
- export const StatusTexts: Record<number, string>;
115
-
116
- export class Storage {
117
- static data: Record<string, unknown> | null;
118
- static dataFile: string;
119
- static getItem<T = unknown>(keyName: string, defaultValue?: T): T;
120
- static setItem(keyName: string, keyValue: unknown): boolean;
121
- static removeItem(keyName: string): boolean;
122
- static clear(): boolean;
123
- }
124
- }
125
-
126
- declare module "@nsnanocat/util/getStorage.mjs" {
127
- export interface StorageProfile {
128
- Settings: Record<string, unknown>;
129
- Configs: Record<string, unknown>;
130
- Caches: Record<string, unknown>;
131
- }
132
-
133
- export function traverseObject(
134
- o: Record<string, unknown>,
135
- c: (key: string, value: unknown) => unknown,
136
- ): Record<string, unknown>;
137
-
138
- export function string2number(string: string): string | number;
139
-
140
- export function value2array(value: string | number | boolean | string[] | null | undefined): Array<string | number | boolean>;
141
-
142
- export default function getStorage(
143
- key: string,
144
- names: string | string[] | Array<string | string[]>,
145
- database: Record<string, unknown>,
146
- ): StorageProfile;
147
- }
148
-
149
- declare module "@nsnanocat/util/lib/environment.mjs" {
150
- export const $environment: Record<string, unknown>;
151
- export function environment(): Record<string, unknown>;
152
- }
1
+ /// <reference path="./modules/core.d.ts" />
2
+ /// <reference path="./modules/fetch.d.ts" />
3
+ /// <reference path="./modules/polyfills.d.ts" />
4
+ /// <reference path="./modules/storage.d.ts" />
5
+ /// <reference path="./modules/kv.d.ts" />
6
+ /// <reference path="./modules/getStorage.d.ts" />
7
+ /// <reference path="./modules/environment.d.ts" />