@dune2/tools 1.0.6 → 1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dune2/tools",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "i18n"
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import type { ComponentType, FC, PropsWithChildren } from "react";
3
- import React, { useContext } from "react";
3
+ import React, { use, useContext } from "react";
4
4
 
5
5
  interface Params<P, T> {
6
6
  /**
@@ -52,5 +52,9 @@ export function createStateContext<P, T>(params: Params<P, T>) {
52
52
  Provider,
53
53
  withProvider,
54
54
  Context,
55
+
56
+ use: () => {
57
+ return use(Context);
58
+ },
55
59
  };
56
60
  }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * fieldsMap 是一个通过 Proxy 实现的工具,
3
+ * 用于在访问任意属性时返回属性名的字符串形式。
4
+ *
5
+ * 使用场景:
6
+ * - 在字段映射、动态生成键值等需要自动获取属性名的场景中,避免手动硬编码。
7
+ */
8
+ export const fieldsMap = new Proxy(
9
+ // 目标对象,这里使用一个空对象作为代理的基础
10
+ {},
11
+ {
12
+ /**
13
+ * 拦截对象的属性读取操作,并返回属性名的字符串形式。
14
+ *
15
+ * @param target 原始被代理的对象(此处为空对象)
16
+ * @param p 被访问的属性名(可能是 string 或 symbol)
17
+ * @param receiver Proxy 接收者
18
+ * @returns 属性名的字符串表示
19
+ */
20
+ get(target, p, receiver) {
21
+ return String(p);
22
+ },
23
+ },
24
+ ) as any;
25
+
26
+ export type FieldsMap<T extends Record<string, any>> = {
27
+ [K in keyof T]: K;
28
+ };
@@ -149,7 +149,7 @@ export class RequestBuilder<Req = any, Res = any> {
149
149
  return this.request(queryKey[2], {
150
150
  signal: ctx.signal,
151
151
  meta: ctx.meta,
152
- requestFn: ctx.meta?.requestFn as never,
152
+ requestFn: ctx.meta?.["requestFn"] as never,
153
153
  });
154
154
  }
155
155