@pisell/core 1.0.68 → 1.0.70
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/es/app/app.d.ts +107 -0
- package/es/app/app.js +3 -0
- package/es/communicationManager/index.d.ts +59 -0
- package/es/index.d.ts +8 -0
- package/es/locales/index.d.ts +39 -0
- package/es/locales/ja.d.ts +3 -0
- package/es/locales/pt.d.ts +3 -0
- package/es/logger/index.d.ts +135 -0
- package/es/request/index.d.ts +15 -6
- package/es/request/index.js +45 -0
- package/es/request/sse.d.ts +45 -0
- package/es/request/sse.js +164 -0
- package/lib/app/app.d.ts +107 -0
- package/lib/app/app.js +3 -0
- package/lib/communicationManager/index.d.ts +59 -0
- package/lib/index.d.ts +8 -0
- package/lib/locales/index.d.ts +39 -0
- package/lib/locales/ja.d.ts +3 -0
- package/lib/locales/pt.d.ts +3 -0
- package/lib/logger/index.d.ts +135 -0
- package/lib/request/index.d.ts +15 -6
- package/lib/request/index.js +25 -1
- package/lib/request/sse.d.ts +45 -0
- package/lib/request/sse.js +115 -0
- package/package.json +3 -2
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface SSEMetaData {
|
|
2
|
+
total: number;
|
|
3
|
+
store_id?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface SSEProgress {
|
|
6
|
+
current: number;
|
|
7
|
+
total: number;
|
|
8
|
+
last_version: number;
|
|
9
|
+
since_version: number;
|
|
10
|
+
}
|
|
11
|
+
export interface SSEDataPayload<TItem = any> {
|
|
12
|
+
items: TItem[];
|
|
13
|
+
progress?: SSEProgress;
|
|
14
|
+
}
|
|
15
|
+
export interface SSECompletePayload {
|
|
16
|
+
count: number;
|
|
17
|
+
last_version: number;
|
|
18
|
+
}
|
|
19
|
+
export interface SSEErrorPayload {
|
|
20
|
+
message: string;
|
|
21
|
+
code?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface SSEActions<TMeta = SSEMetaData, TData = SSEDataPayload, TComplete = SSECompletePayload> {
|
|
24
|
+
onOpen?: () => void;
|
|
25
|
+
onMeta?: (data: TMeta) => void;
|
|
26
|
+
onProgress?: (data: SSEProgress) => void;
|
|
27
|
+
onData?: (data: TData) => void;
|
|
28
|
+
onTypeDone?: (data: TComplete) => void;
|
|
29
|
+
onDone?: (data: TComplete) => void;
|
|
30
|
+
onError?: (err: SSEErrorPayload | Error) => void;
|
|
31
|
+
}
|
|
32
|
+
export interface SSEConfig {
|
|
33
|
+
url: string;
|
|
34
|
+
params?: Record<string, any>;
|
|
35
|
+
method?: 'GET' | 'POST';
|
|
36
|
+
body?: Record<string, any>;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 底层 SSE 请求封装,基于 @microsoft/fetch-event-source
|
|
41
|
+
* 支持自定义 headers(解决原生 EventSource 无法携带 Authorization 的问题)
|
|
42
|
+
*
|
|
43
|
+
* @returns abort 函数,组件卸载时调用以关闭连接
|
|
44
|
+
*/
|
|
45
|
+
export declare function createSSE<TMeta = SSEMetaData, TData = SSEDataPayload, TComplete = SSECompletePayload>(config: SSEConfig, actions: SSEActions<TMeta, TData, TComplete>): () => void;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/request/sse.ts
|
|
20
|
+
var sse_exports = {};
|
|
21
|
+
__export(sse_exports, {
|
|
22
|
+
createSSE: () => createSSE
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(sse_exports);
|
|
25
|
+
var import_fetch_event_source = require("@microsoft/fetch-event-source");
|
|
26
|
+
function buildUrl(url, params) {
|
|
27
|
+
if (!params || Object.keys(params).length === 0) return url;
|
|
28
|
+
const query = Object.entries(params).filter(([, v]) => v !== void 0 && v !== null).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&");
|
|
29
|
+
return query ? `${url}?${query}` : url;
|
|
30
|
+
}
|
|
31
|
+
function parseEventData(raw) {
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(raw);
|
|
34
|
+
} catch {
|
|
35
|
+
console.warn("[SSE] Failed to parse event data:", raw);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function createSSE(config, actions) {
|
|
40
|
+
const { url, params, method = "GET", body, headers = {} } = config;
|
|
41
|
+
const { onMeta, onProgress, onData, onTypeDone, onDone, onError, onOpen } = actions;
|
|
42
|
+
const controller = new AbortController();
|
|
43
|
+
const fullUrl = buildUrl(url, params);
|
|
44
|
+
(0, import_fetch_event_source.fetchEventSource)(fullUrl, {
|
|
45
|
+
method,
|
|
46
|
+
headers: {
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
"Accept": "text/event-stream",
|
|
49
|
+
...headers
|
|
50
|
+
},
|
|
51
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
52
|
+
signal: controller.signal,
|
|
53
|
+
openWhenHidden: true,
|
|
54
|
+
onopen: async (response) => {
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
const errorData = {
|
|
57
|
+
message: `SSE connection failed: ${response.status} ${response.statusText}`,
|
|
58
|
+
code: response.status
|
|
59
|
+
};
|
|
60
|
+
onError == null ? void 0 : onError(errorData);
|
|
61
|
+
controller.abort();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
onOpen == null ? void 0 : onOpen();
|
|
65
|
+
},
|
|
66
|
+
onmessage: (event) => {
|
|
67
|
+
switch (event.event) {
|
|
68
|
+
case "meta": {
|
|
69
|
+
const data = parseEventData(event.data);
|
|
70
|
+
if (data !== null) onMeta == null ? void 0 : onMeta(data);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case "progress": {
|
|
74
|
+
const data = parseEventData(event.data);
|
|
75
|
+
if (data !== null) onProgress == null ? void 0 : onProgress(data);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case "data": {
|
|
79
|
+
const data = parseEventData(event.data);
|
|
80
|
+
if (data !== null) onData == null ? void 0 : onData(data);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case "type_done": {
|
|
84
|
+
const data = parseEventData(event.data);
|
|
85
|
+
if (data !== null) onTypeDone == null ? void 0 : onTypeDone(data);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case "done": {
|
|
89
|
+
const data = parseEventData(event.data);
|
|
90
|
+
if (data !== null) onDone == null ? void 0 : onDone(data);
|
|
91
|
+
controller.abort();
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case "error": {
|
|
95
|
+
const data = parseEventData(event.data);
|
|
96
|
+
onError == null ? void 0 : onError(data ?? { message: "Unknown SSE error" });
|
|
97
|
+
controller.abort();
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
default:
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
onerror: (err) => {
|
|
105
|
+
if (controller.signal.aborted) return;
|
|
106
|
+
onError == null ? void 0 : onError(err instanceof Error ? err : new Error(String(err)));
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return () => controller.abort();
|
|
111
|
+
}
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
createSSE
|
|
115
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pisell/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.70",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"js-md5": "^0.8.3",
|
|
30
30
|
"axios": "^1.7.2",
|
|
31
31
|
"@aws-sdk/client-s3": "^3.456.0",
|
|
32
|
-
"dexie": "^4.2.1"
|
|
32
|
+
"dexie": "^4.2.1",
|
|
33
|
+
"@microsoft/fetch-event-source": "2.0.1"
|
|
33
34
|
},
|
|
34
35
|
"files": [
|
|
35
36
|
"es",
|