@snack-kit/lib 0.3.0 → 0.5.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 +261 -17
- package/dist/cjs/chunk-IMHC6CTK.cjs +13 -0
- package/dist/{es/chunk-BEL6AFK4.js.map → cjs/chunk-IMHC6CTK.cjs.map} +1 -1
- package/dist/cjs/{chunk-N7BJS6LI.cjs → chunk-XEQEQWDB.cjs} +48 -14
- package/dist/cjs/chunk-XEQEQWDB.cjs.map +1 -0
- package/dist/cjs/{chunk-YOWLTZM5.cjs → chunk-ZJMTV2GJ.cjs} +7 -6
- package/dist/cjs/chunk-ZJMTV2GJ.cjs.map +1 -0
- package/dist/cjs/debugger.cjs +7 -3
- package/dist/cjs/http.cjs +22 -14
- package/dist/cjs/index.cjs +29 -17
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/es/{chunk-4DLFIN3C.js → chunk-4SGFAIRT.js} +4 -3
- package/dist/es/chunk-4SGFAIRT.js.map +1 -0
- package/dist/es/chunk-MHCY2PIP.js +3 -0
- package/dist/{cjs/chunk-YY5WQN7B.cjs.map → es/chunk-MHCY2PIP.js.map} +1 -1
- package/dist/es/{chunk-JQYH5FWE.js → chunk-YV6SGXUJ.js} +48 -15
- package/dist/es/chunk-YV6SGXUJ.js.map +1 -0
- package/dist/es/debugger.js +2 -2
- package/dist/es/http.js +2 -2
- package/dist/es/index.js +4 -4
- package/dist/es/index.js.map +1 -1
- package/dist/types/context-C4dFUDbw.d.ts +237 -0
- package/dist/types/debugger.d.ts +3 -0
- package/dist/types/http.d.ts +61 -236
- package/dist/types/index.d.ts +4 -3
- package/dist/umd/debugger.global.js +28 -5
- package/dist/umd/debugger.global.js.map +1 -1
- package/dist/umd/http.global.js +46 -12
- package/dist/umd/http.global.js.map +1 -1
- package/dist/umd/index.global.js +49 -13
- package/dist/umd/index.global.js.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/chunk-N7BJS6LI.cjs.map +0 -1
- package/dist/cjs/chunk-YOWLTZM5.cjs.map +0 -1
- package/dist/cjs/chunk-YY5WQN7B.cjs +0 -4
- package/dist/es/chunk-4DLFIN3C.js.map +0 -1
- package/dist/es/chunk-BEL6AFK4.js +0 -3
- package/dist/es/chunk-JQYH5FWE.js.map +0 -1
package/dist/umd/index.global.js
CHANGED
|
@@ -11625,7 +11625,7 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
|
|
|
11625
11625
|
});
|
|
11626
11626
|
|
|
11627
11627
|
// package.json
|
|
11628
|
-
var version = "0.
|
|
11628
|
+
var version = "0.5.0";
|
|
11629
11629
|
|
|
11630
11630
|
// node_modules/axios/lib/helpers/bind.js
|
|
11631
11631
|
function bind(fn, thisArg) {
|
|
@@ -15376,6 +15376,7 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
|
|
|
15376
15376
|
} = axios_default;
|
|
15377
15377
|
|
|
15378
15378
|
// src/http/context.ts
|
|
15379
|
+
var DEBUGGER_ACTIVE_KEY = "__snackkit_debugger__active";
|
|
15379
15380
|
var HttpContext = class {
|
|
15380
15381
|
constructor() {
|
|
15381
15382
|
this._store = /* @__PURE__ */ new Map();
|
|
@@ -15384,12 +15385,24 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
|
|
|
15384
15385
|
/**
|
|
15385
15386
|
* 加载服务地址映射
|
|
15386
15387
|
*
|
|
15388
|
+
* 支持三种调用方式:
|
|
15389
|
+
* - **传入字符串**:作为网关地址,自动请求 `GET /ngw/context` 获取映射表
|
|
15390
|
+
* - **传入对象**:直接注入键值映射,不发起网络请求
|
|
15391
|
+
* - **不传参数**:
|
|
15392
|
+
* - 生产环境(`NODE_ENV === 'production'`):以当前页面 `Origin` 为网关地址自动加载
|
|
15393
|
+
* - 开发环境:立即返回,不做任何操作(应由 `Debugger.init()` 接管加载流程)
|
|
15394
|
+
*
|
|
15387
15395
|
* 远程加载时,响应中的 `$info` 元数据字段会被单独存储,不计入路由映射表。
|
|
15388
15396
|
*
|
|
15389
|
-
* @param source
|
|
15397
|
+
* @param source 网关 URL / 键值对象 / 省略
|
|
15390
15398
|
* @param timeout 远程加载超时(ms),默认 5000
|
|
15391
15399
|
*
|
|
15392
|
-
* @example
|
|
15400
|
+
* @example 不传参——生产环境自动使用当前页面 Origin
|
|
15401
|
+
* ```ts
|
|
15402
|
+
* await Context.load()
|
|
15403
|
+
* ```
|
|
15404
|
+
*
|
|
15405
|
+
* @example 传入网关地址
|
|
15393
15406
|
* ```ts
|
|
15394
15407
|
* await Context.load('http://172.16.32.155:20000', 3000)
|
|
15395
15408
|
* ```
|
|
@@ -15400,6 +15413,11 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
|
|
|
15400
15413
|
* ```
|
|
15401
15414
|
*/
|
|
15402
15415
|
async load(source, timeout = 5e3) {
|
|
15416
|
+
if (source === void 0) {
|
|
15417
|
+
if (globalThis[DEBUGGER_ACTIVE_KEY]) return;
|
|
15418
|
+
if (!Origin) return;
|
|
15419
|
+
source = Origin;
|
|
15420
|
+
}
|
|
15403
15421
|
if (typeof source === "string") {
|
|
15404
15422
|
const url2 = `${source}/ngw/context`;
|
|
15405
15423
|
const res = await axios_default.get(url2, { timeout });
|
|
@@ -15553,20 +15571,35 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
|
|
|
15553
15571
|
Unregister(cancelId);
|
|
15554
15572
|
}
|
|
15555
15573
|
}
|
|
15556
|
-
function Get(
|
|
15557
|
-
|
|
15574
|
+
function Get(urlOrConfig, config) {
|
|
15575
|
+
if (typeof urlOrConfig === "string") {
|
|
15576
|
+
return Request({ ...config, method: "GET", url: urlOrConfig });
|
|
15577
|
+
}
|
|
15578
|
+
return Request({ ...urlOrConfig, method: "GET" });
|
|
15558
15579
|
}
|
|
15559
|
-
function Post(
|
|
15560
|
-
|
|
15580
|
+
function Post(urlOrConfig, data, config) {
|
|
15581
|
+
if (typeof urlOrConfig === "string") {
|
|
15582
|
+
return Request({ ...config, method: "POST", url: urlOrConfig, data });
|
|
15583
|
+
}
|
|
15584
|
+
return Request({ ...urlOrConfig, method: "POST" });
|
|
15561
15585
|
}
|
|
15562
|
-
function Put(
|
|
15563
|
-
|
|
15586
|
+
function Put(urlOrConfig, data, config) {
|
|
15587
|
+
if (typeof urlOrConfig === "string") {
|
|
15588
|
+
return Request({ ...config, method: "PUT", url: urlOrConfig, data });
|
|
15589
|
+
}
|
|
15590
|
+
return Request({ ...urlOrConfig, method: "PUT" });
|
|
15564
15591
|
}
|
|
15565
|
-
function Patch(
|
|
15566
|
-
|
|
15592
|
+
function Patch(urlOrConfig, data, config) {
|
|
15593
|
+
if (typeof urlOrConfig === "string") {
|
|
15594
|
+
return Request({ ...config, method: "PATCH", url: urlOrConfig, data });
|
|
15595
|
+
}
|
|
15596
|
+
return Request({ ...urlOrConfig, method: "PATCH" });
|
|
15567
15597
|
}
|
|
15568
|
-
function Del(
|
|
15569
|
-
|
|
15598
|
+
function Del(urlOrConfig, config) {
|
|
15599
|
+
if (typeof urlOrConfig === "string") {
|
|
15600
|
+
return Request({ ...config, method: "DELETE", url: urlOrConfig });
|
|
15601
|
+
}
|
|
15602
|
+
return Request({ ...urlOrConfig, method: "DELETE" });
|
|
15570
15603
|
}
|
|
15571
15604
|
|
|
15572
15605
|
// src/debugger/debugger.ts
|
|
@@ -16139,6 +16172,7 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
|
|
|
16139
16172
|
* ```
|
|
16140
16173
|
*/
|
|
16141
16174
|
static async init(options) {
|
|
16175
|
+
globalThis[DEBUGGER_ACTIVE_KEY] = true;
|
|
16142
16176
|
const instance = new _Debugger({ timeout: 1e4, ...options });
|
|
16143
16177
|
instance.injectStyle();
|
|
16144
16178
|
instance.buildDOM();
|
|
@@ -16679,6 +16713,7 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
|
|
|
16679
16713
|
exports.CleanObject = CleanObject;
|
|
16680
16714
|
exports.Context = Context;
|
|
16681
16715
|
exports.Ctx = Ctx;
|
|
16716
|
+
exports.DEBUGGER_ACTIVE_KEY = DEBUGGER_ACTIVE_KEY;
|
|
16682
16717
|
exports.Debounce = Debounce;
|
|
16683
16718
|
exports.Debugger = Debugger;
|
|
16684
16719
|
exports.DeepClone = DeepClone;
|
|
@@ -16722,6 +16757,7 @@ var SnackKit = (function (exports, crypto2, url, http, https, http2, util2, zlib
|
|
|
16722
16757
|
exports.Unique = Unique;
|
|
16723
16758
|
exports.UniqueByKey = UniqueByKey;
|
|
16724
16759
|
exports.VERSION = version;
|
|
16760
|
+
exports.axios = axios_default;
|
|
16725
16761
|
|
|
16726
16762
|
return exports;
|
|
16727
16763
|
|