@enfyra/sdk-nuxt 0.3.16 → 0.3.17
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/index.ts +1 -1
- package/module.d.ts +2 -2
- package/{src/module.ts → module.ts} +10 -9
- package/package.json +22 -25
- package/src/composables/useEnfyraAuth.ts +1 -1
- package/dist/composables/useEnfyraApi.d.ts +0 -8
- package/dist/composables/useEnfyraApi.d.ts.map +0 -1
- package/dist/composables/useEnfyraApi.js +0 -363
- package/dist/composables/useEnfyraApi.mjs +0 -345
- package/dist/composables/useEnfyraAuth.d.ts +0 -89
- package/dist/composables/useEnfyraAuth.d.ts.map +0 -1
- package/dist/composables/useEnfyraAuth.js +0 -77
- package/dist/composables/useEnfyraAuth.mjs +0 -81
- package/dist/constants/auth.d.ts +0 -0
- package/dist/constants/auth.mjs +0 -3
- package/dist/constants/config.d.ts +0 -2
- package/dist/constants/config.d.ts.map +0 -1
- package/dist/constants/config.js +0 -1
- package/dist/constants/config.mjs +0 -1
- package/dist/module.cjs +0 -82
- package/dist/module.d.cts +0 -10
- package/dist/module.d.mts +0 -10
- package/dist/module.d.ts +0 -10
- package/dist/module.json +0 -9
- package/dist/module.mjs +0 -79
- package/dist/runtime/plugin/config-error.client.d.ts +0 -0
- package/dist/runtime/plugin/config-error.client.js +0 -107
- package/dist/runtime/plugin/config-error.client.mjs +0 -107
- package/dist/runtime/server/api/all.d.ts +0 -0
- package/dist/runtime/server/api/all.js +0 -5
- package/dist/runtime/server/api/all.mjs +0 -5
- package/dist/runtime/server/api/login.post.d.ts +0 -0
- package/dist/runtime/server/api/login.post.js +0 -62
- package/dist/runtime/server/api/login.post.mjs +0 -62
- package/dist/runtime/server/api/logout.post.d.ts +0 -0
- package/dist/runtime/server/api/logout.post.js +0 -35
- package/dist/runtime/server/api/logout.post.mjs +0 -35
- package/dist/runtime/server/middleware/auth.d.ts +0 -0
- package/dist/runtime/server/middleware/auth.js +0 -36
- package/dist/runtime/server/middleware/auth.mjs +0 -36
- package/dist/types/auth.d.ts +0 -43
- package/dist/types/auth.d.ts.map +0 -1
- package/dist/types/auth.js +0 -1
- package/dist/types/index.d.ts +0 -141
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types.d.mts +0 -7
- package/dist/types.d.ts +0 -7
- package/dist/utils/config.d.ts +0 -0
- package/dist/utils/config.mjs +0 -16
- package/dist/utils/http.d.ts +0 -8
- package/dist/utils/http.d.ts.map +0 -1
- package/dist/utils/http.js +0 -57
- package/dist/utils/http.mjs +0 -61
- package/dist/utils/server/proxy.d.ts +0 -0
- package/dist/utils/server/proxy.mjs +0 -14
- package/dist/utils/server/refreshToken.d.ts +0 -0
- package/dist/utils/server/refreshToken.mjs +0 -69
- package/dist/utils/url.d.ts +0 -12
- package/dist/utils/url.d.ts.map +0 -1
- package/dist/utils/url.js +0 -77
- package/dist/utils/url.mjs +0 -56
package/index.ts
CHANGED
package/module.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ModuleOptions } from './
|
|
1
|
+
import type { ModuleOptions } from './module'
|
|
2
2
|
|
|
3
3
|
declare module '@nuxt/schema' {
|
|
4
4
|
interface NuxtConfig {
|
|
@@ -9,6 +9,6 @@ declare module '@nuxt/schema' {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export type { ModuleOptions } from './
|
|
12
|
+
export type { ModuleOptions } from './module'
|
|
13
13
|
export type * from './src/types'
|
|
14
14
|
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
addImportsDir,
|
|
6
6
|
addPlugin,
|
|
7
7
|
} from "@nuxt/kit";
|
|
8
|
-
import { ENFYRA_API_PREFIX } from "./constants/config";
|
|
8
|
+
import { ENFYRA_API_PREFIX } from "./src/constants/config";
|
|
9
9
|
|
|
10
10
|
export interface ModuleOptions {
|
|
11
11
|
apiUrl: string;
|
|
@@ -65,45 +65,46 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
65
65
|
|
|
66
66
|
if (!normalizedOptions.apiUrl) {
|
|
67
67
|
addPlugin({
|
|
68
|
-
src: resolve("./runtime/plugin/config-error.client"),
|
|
68
|
+
src: resolve("./src/runtime/plugin/config-error.client"),
|
|
69
69
|
mode: 'client'
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
addImportsDir(resolve("./composables"));
|
|
73
|
+
addImportsDir(resolve("./src/composables"));
|
|
74
74
|
|
|
75
75
|
nuxt.hook('prepare:types', ({ declarations, references }: any) => {
|
|
76
76
|
references.push({
|
|
77
|
-
path: resolve('./types/nuxt-imports.d.ts'),
|
|
77
|
+
path: resolve('./src/types/nuxt-imports.d.ts'),
|
|
78
78
|
})
|
|
79
79
|
})
|
|
80
80
|
|
|
81
81
|
addServerHandler({
|
|
82
|
-
handler:
|
|
82
|
+
handler: '@enfyra/sdk-nuxt/src/runtime/server/middleware/auth',
|
|
83
83
|
middleware: true,
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
addServerHandler({
|
|
87
87
|
route: `${apiPrefix}/login`,
|
|
88
|
-
handler:
|
|
88
|
+
handler: '@enfyra/sdk-nuxt/src/runtime/server/api/login.post',
|
|
89
89
|
method: "post",
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
addServerHandler({
|
|
93
93
|
route: `${apiPrefix}/logout`,
|
|
94
|
-
handler:
|
|
94
|
+
handler: '@enfyra/sdk-nuxt/src/runtime/server/api/logout.post',
|
|
95
95
|
method: "post",
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
|
|
99
99
|
addServerHandler({
|
|
100
100
|
route: "/assets/**",
|
|
101
|
-
handler:
|
|
101
|
+
handler: '@enfyra/sdk-nuxt/src/runtime/server/api/all',
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
addServerHandler({
|
|
105
105
|
route: `${apiPrefix}/**`,
|
|
106
|
-
handler:
|
|
106
|
+
handler: '@enfyra/sdk-nuxt/src/runtime/server/api/all',
|
|
107
107
|
});
|
|
108
108
|
},
|
|
109
109
|
});
|
|
110
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enfyra/sdk-nuxt",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.17",
|
|
4
4
|
"description": "Nuxt SDK for Enfyra CMS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,13 +10,12 @@
|
|
|
10
10
|
"url": "https://github.com/dothinh115/enfyra-sdk-nuxt/issues"
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://github.com/dothinh115/enfyra-sdk-nuxt#readme",
|
|
13
|
-
"main": "./
|
|
14
|
-
"types": "./
|
|
13
|
+
"main": "./module.ts",
|
|
14
|
+
"types": "./module.d.ts",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"types": "./dist/types.d.ts"
|
|
17
|
+
"types": "./module.d.ts",
|
|
18
|
+
"import": "./module.ts"
|
|
20
19
|
},
|
|
21
20
|
"./src/composables/useEnfyraApi": {
|
|
22
21
|
"types": "./src/composables/useEnfyraApi.ts",
|
|
@@ -26,16 +25,24 @@
|
|
|
26
25
|
"types": "./src/composables/useEnfyraAuth.ts",
|
|
27
26
|
"import": "./src/composables/useEnfyraAuth.ts"
|
|
28
27
|
},
|
|
29
|
-
"./types": {
|
|
30
|
-
"types": "./
|
|
31
|
-
"import": "./
|
|
32
|
-
}
|
|
28
|
+
"./src/types": {
|
|
29
|
+
"types": "./src/types/index.ts",
|
|
30
|
+
"import": "./src/types/index.ts"
|
|
31
|
+
},
|
|
32
|
+
"./src/runtime/server/api/all": "./src/runtime/server/api/all.ts",
|
|
33
|
+
"./src/runtime/server/api/all.ts": "./src/runtime/server/api/all.ts",
|
|
34
|
+
"./src/runtime/server/api/login.post": "./src/runtime/server/api/login.post.ts",
|
|
35
|
+
"./src/runtime/server/api/login.post.ts": "./src/runtime/server/api/login.post.ts",
|
|
36
|
+
"./src/runtime/server/api/logout.post": "./src/runtime/server/api/logout.post.ts",
|
|
37
|
+
"./src/runtime/server/api/logout.post.ts": "./src/runtime/server/api/logout.post.ts",
|
|
38
|
+
"./src/runtime/server/middleware/auth": "./src/runtime/server/middleware/auth.ts",
|
|
39
|
+
"./src/runtime/server/middleware/auth.ts": "./src/runtime/server/middleware/auth.ts"
|
|
33
40
|
},
|
|
34
41
|
"files": [
|
|
35
|
-
"
|
|
36
|
-
"src/",
|
|
42
|
+
"module.ts",
|
|
37
43
|
"module.d.ts",
|
|
38
|
-
"index.ts"
|
|
44
|
+
"index.ts",
|
|
45
|
+
"src/**/*"
|
|
39
46
|
],
|
|
40
47
|
"keywords": [
|
|
41
48
|
"nuxt",
|
|
@@ -49,12 +56,7 @@
|
|
|
49
56
|
"access": "public"
|
|
50
57
|
},
|
|
51
58
|
"scripts": {
|
|
52
|
-
"
|
|
53
|
-
"build": "nuxt-module-build build && npx tsc -p tsconfig.build.json",
|
|
54
|
-
"prepack": "nuxt-module-build build && npx tsc -p tsconfig.build.json",
|
|
55
|
-
"test": "vitest",
|
|
56
|
-
"test:ui": "vitest --ui",
|
|
57
|
-
"test:run": "vitest run"
|
|
59
|
+
"build": "npx tsc --noEmit --skipLibCheck"
|
|
58
60
|
},
|
|
59
61
|
"peerDependencies": {
|
|
60
62
|
"@nuxt/kit": "^3.18.1",
|
|
@@ -65,13 +67,8 @@
|
|
|
65
67
|
"ofetch": "^1.3.3"
|
|
66
68
|
},
|
|
67
69
|
"devDependencies": {
|
|
68
|
-
"@nuxt/module-builder": "^0.8.4",
|
|
69
70
|
"@types/node": "^24.10.1",
|
|
70
|
-
"@vitest/ui": "^3.2.4",
|
|
71
71
|
"nuxt": "^3.18.1",
|
|
72
|
-
"typescript": "^5.0.0"
|
|
73
|
-
"vite": "^6.0.7",
|
|
74
|
-
"vite-plugin-dts": "^4.3.0",
|
|
75
|
-
"vitest": "^3.2.4"
|
|
72
|
+
"typescript": "^5.0.0"
|
|
76
73
|
}
|
|
77
74
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ApiOptions, UseEnfyraApiSSRReturn, UseEnfyraApiClientReturn } from "../types";
|
|
2
|
-
export declare function useEnfyraApi<T = any>(path: (() => string) | string, opts: ApiOptions<T> & {
|
|
3
|
-
ssr: true;
|
|
4
|
-
}): UseEnfyraApiSSRReturn<T>;
|
|
5
|
-
export declare function useEnfyraApi<T = any>(path: (() => string) | string, opts?: ApiOptions<T> & {
|
|
6
|
-
ssr?: false | undefined;
|
|
7
|
-
}): UseEnfyraApiClientReturn<T>;
|
|
8
|
-
//# sourceMappingURL=useEnfyraApi.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useEnfyraApi.d.ts","sourceRoot":"","sources":["../../src/composables/useEnfyraApi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAGV,qBAAqB,EACrB,wBAAwB,EAEzB,MAAM,UAAU,CAAC;AA4BlB,wBAAgB,YAAY,CAAC,CAAC,GAAG,GAAG,EAClC,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EAC7B,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,EAAE,IAAI,CAAA;CAAE,GAClC,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAE5B,wBAAgB,YAAY,CAAC,CAAC,GAAG,GAAG,EAClC,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EAC7B,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CAAE,GACjD,wBAAwB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
import { ref, unref, toRaw } from "vue";
|
|
2
|
-
import { $fetch } from "../utils/http";
|
|
3
|
-
import { getAppUrl, normalizeUrl } from "../utils/url";
|
|
4
|
-
import { ENFYRA_API_PREFIX } from "../constants/config";
|
|
5
|
-
import { useRuntimeConfig, useFetch, useRequestHeaders, useNuxtApp } from "#imports";
|
|
6
|
-
function handleError(error, context, customHandler) {
|
|
7
|
-
const apiError = {
|
|
8
|
-
message: error?.message || error?.data?.message || "Request failed",
|
|
9
|
-
status: error?.status || error?.response?.status,
|
|
10
|
-
data: error?.data || error?.response?.data,
|
|
11
|
-
response: error?.response || error,
|
|
12
|
-
};
|
|
13
|
-
if (customHandler) {
|
|
14
|
-
customHandler(apiError, context);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
console.error(`[Enfyra API Error]`, { error: apiError, context });
|
|
18
|
-
}
|
|
19
|
-
return apiError;
|
|
20
|
-
}
|
|
21
|
-
export function useEnfyraApi(path, opts = {}) {
|
|
22
|
-
const { method = "get", body, query, errorContext, onError, ssr, key } = opts;
|
|
23
|
-
const batchOptions = opts;
|
|
24
|
-
const { batchSize, concurrent, onProgress } = batchOptions;
|
|
25
|
-
if (ssr) {
|
|
26
|
-
const config = useRuntimeConfig().public.enfyraSDK;
|
|
27
|
-
const basePath = (typeof path === "function" ? path() : path)
|
|
28
|
-
.replace(/^\/?api\/?/, "")
|
|
29
|
-
.replace(/^\/+/, "");
|
|
30
|
-
const appUrl = getAppUrl();
|
|
31
|
-
const finalUrl = normalizeUrl(appUrl, config?.apiPrefix || ENFYRA_API_PREFIX, basePath);
|
|
32
|
-
const clientHeaders = process.client
|
|
33
|
-
? {}
|
|
34
|
-
: useRequestHeaders([
|
|
35
|
-
"authorization",
|
|
36
|
-
"cookie",
|
|
37
|
-
"user-agent",
|
|
38
|
-
"accept",
|
|
39
|
-
"accept-language",
|
|
40
|
-
"referer",
|
|
41
|
-
]);
|
|
42
|
-
const serverHeaders = { ...clientHeaders };
|
|
43
|
-
delete serverHeaders.connection;
|
|
44
|
-
delete serverHeaders["keep-alive"];
|
|
45
|
-
delete serverHeaders.host;
|
|
46
|
-
delete serverHeaders["content-length"];
|
|
47
|
-
const nuxtApp = useNuxtApp();
|
|
48
|
-
const fetchOptions = {
|
|
49
|
-
method: method,
|
|
50
|
-
body: body,
|
|
51
|
-
query: query,
|
|
52
|
-
headers: {
|
|
53
|
-
...serverHeaders,
|
|
54
|
-
...opts.headers,
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
// Pass all useFetch-specific options
|
|
58
|
-
if (key !== undefined) {
|
|
59
|
-
fetchOptions.key = key;
|
|
60
|
-
}
|
|
61
|
-
if (opts.default !== undefined) {
|
|
62
|
-
fetchOptions.default = opts.default;
|
|
63
|
-
}
|
|
64
|
-
if (opts.server !== undefined) {
|
|
65
|
-
fetchOptions.server = opts.server;
|
|
66
|
-
}
|
|
67
|
-
if (opts.lazy !== undefined) {
|
|
68
|
-
fetchOptions.lazy = opts.lazy;
|
|
69
|
-
}
|
|
70
|
-
if (opts.immediate !== undefined) {
|
|
71
|
-
fetchOptions.immediate = opts.immediate;
|
|
72
|
-
}
|
|
73
|
-
if (opts.transform !== undefined) {
|
|
74
|
-
fetchOptions.transform = opts.transform;
|
|
75
|
-
}
|
|
76
|
-
if (opts.pick !== undefined) {
|
|
77
|
-
fetchOptions.pick = opts.pick;
|
|
78
|
-
}
|
|
79
|
-
if (opts.watch !== undefined) {
|
|
80
|
-
fetchOptions.watch = opts.watch;
|
|
81
|
-
}
|
|
82
|
-
if (opts.deep !== undefined) {
|
|
83
|
-
fetchOptions.deep = opts.deep;
|
|
84
|
-
}
|
|
85
|
-
if (opts.getCachedData !== undefined) {
|
|
86
|
-
fetchOptions.getCachedData = opts.getCachedData;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
// Auto-add getCachedData to ensure cache is used in SPA navigation
|
|
90
|
-
fetchOptions.getCachedData = (cacheKey) => {
|
|
91
|
-
return nuxtApp.payload.data[cacheKey] || nuxtApp.static.data[cacheKey];
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
if (opts.refresh !== undefined) {
|
|
95
|
-
fetchOptions.refresh = opts.refresh;
|
|
96
|
-
}
|
|
97
|
-
if (opts.refreshInterval !== undefined) {
|
|
98
|
-
fetchOptions.refreshInterval = opts.refreshInterval;
|
|
99
|
-
}
|
|
100
|
-
if (opts.dedupe !== undefined) {
|
|
101
|
-
fetchOptions.dedupe = opts.dedupe;
|
|
102
|
-
}
|
|
103
|
-
const result = useFetch(finalUrl, fetchOptions);
|
|
104
|
-
// Map pending to loading for better naming
|
|
105
|
-
// useFetch returns AsyncData with 'pending', but UseEnfyraApiSSRReturn uses 'loading'
|
|
106
|
-
return {
|
|
107
|
-
...result,
|
|
108
|
-
loading: result.pending,
|
|
109
|
-
pending: result.pending, // Keep for backward compatibility
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
const data = ref(null);
|
|
113
|
-
const error = ref(null);
|
|
114
|
-
const pending = ref(false);
|
|
115
|
-
const execute = async (executeOpts) => {
|
|
116
|
-
pending.value = true;
|
|
117
|
-
error.value = null;
|
|
118
|
-
try {
|
|
119
|
-
const config = useRuntimeConfig().public.enfyraSDK;
|
|
120
|
-
const apiUrl = getAppUrl();
|
|
121
|
-
const apiPrefix = config?.apiPrefix;
|
|
122
|
-
const basePath = (typeof path === "function" ? path() : path)
|
|
123
|
-
.replace(/^\/?api\/?/, "")
|
|
124
|
-
.replace(/^\/+/, "");
|
|
125
|
-
const finalBody = executeOpts?.body || unref(body);
|
|
126
|
-
const finalQuery = executeOpts?.query || unref(query);
|
|
127
|
-
const isBatchOperation = !opts.disableBatch &&
|
|
128
|
-
((executeOpts?.ids &&
|
|
129
|
-
executeOpts.ids.length > 0 &&
|
|
130
|
-
(method.toLowerCase() === "patch" ||
|
|
131
|
-
method.toLowerCase() === "delete")) ||
|
|
132
|
-
(method.toLowerCase() === "post" &&
|
|
133
|
-
executeOpts?.files &&
|
|
134
|
-
Array.isArray(executeOpts.files) &&
|
|
135
|
-
executeOpts.files.length > 0));
|
|
136
|
-
const effectiveBatchSize = isBatchOperation
|
|
137
|
-
? executeOpts?.batchSize ?? batchSize
|
|
138
|
-
: undefined;
|
|
139
|
-
const effectiveConcurrent = isBatchOperation
|
|
140
|
-
? executeOpts?.concurrent ?? concurrent
|
|
141
|
-
: undefined;
|
|
142
|
-
const effectiveOnProgress = isBatchOperation
|
|
143
|
-
? executeOpts?.onProgress ?? onProgress
|
|
144
|
-
: undefined;
|
|
145
|
-
const buildPath = (...segments) => {
|
|
146
|
-
return segments.filter(Boolean).join("/");
|
|
147
|
-
};
|
|
148
|
-
const fullBaseURL = normalizeUrl(apiUrl, apiPrefix || ENFYRA_API_PREFIX);
|
|
149
|
-
async function processBatch(items, processor) {
|
|
150
|
-
const results = [];
|
|
151
|
-
const progressResults = [];
|
|
152
|
-
const startTime = Date.now();
|
|
153
|
-
let completed = 0;
|
|
154
|
-
let failed = 0;
|
|
155
|
-
const chunks = effectiveBatchSize
|
|
156
|
-
? Array.from({ length: Math.ceil(items.length / effectiveBatchSize) }, (_, i) => items.slice(i * effectiveBatchSize, i * effectiveBatchSize + effectiveBatchSize))
|
|
157
|
-
: [items];
|
|
158
|
-
const totalBatches = chunks.length;
|
|
159
|
-
let currentBatch = 0;
|
|
160
|
-
const updateProgress = (inProgress = 0) => {
|
|
161
|
-
if (effectiveOnProgress) {
|
|
162
|
-
const elapsed = Date.now() - startTime;
|
|
163
|
-
const progress = items.length > 0
|
|
164
|
-
? Math.round((completed / items.length) * 100)
|
|
165
|
-
: 0;
|
|
166
|
-
const averageTime = completed > 0 ? elapsed / completed : undefined;
|
|
167
|
-
const operationsPerSecond = completed > 0 ? (completed / elapsed) * 1000 : undefined;
|
|
168
|
-
const estimatedTimeRemaining = averageTime && items.length > completed
|
|
169
|
-
? Math.round(averageTime * (items.length - completed))
|
|
170
|
-
: undefined;
|
|
171
|
-
const progressData = {
|
|
172
|
-
progress,
|
|
173
|
-
completed,
|
|
174
|
-
total: items.length,
|
|
175
|
-
failed,
|
|
176
|
-
inProgress,
|
|
177
|
-
estimatedTimeRemaining,
|
|
178
|
-
averageTime,
|
|
179
|
-
currentBatch: currentBatch + 1,
|
|
180
|
-
totalBatches,
|
|
181
|
-
operationsPerSecond,
|
|
182
|
-
results: [...progressResults],
|
|
183
|
-
};
|
|
184
|
-
effectiveOnProgress(progressData);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
updateProgress(0);
|
|
188
|
-
if (!effectiveBatchSize && !effectiveConcurrent) {
|
|
189
|
-
updateProgress(items.length);
|
|
190
|
-
const promises = items.map(async (item, index) => {
|
|
191
|
-
const itemStartTime = Date.now();
|
|
192
|
-
try {
|
|
193
|
-
const result = await processor(item, index);
|
|
194
|
-
const duration = Date.now() - itemStartTime;
|
|
195
|
-
completed++;
|
|
196
|
-
progressResults.push({
|
|
197
|
-
index,
|
|
198
|
-
status: "completed",
|
|
199
|
-
result,
|
|
200
|
-
duration,
|
|
201
|
-
});
|
|
202
|
-
updateProgress(items.length - completed);
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
catch (error) {
|
|
206
|
-
const duration = Date.now() - itemStartTime;
|
|
207
|
-
failed++;
|
|
208
|
-
completed++;
|
|
209
|
-
progressResults.push({
|
|
210
|
-
index,
|
|
211
|
-
status: "failed",
|
|
212
|
-
error: error,
|
|
213
|
-
duration,
|
|
214
|
-
});
|
|
215
|
-
updateProgress(items.length - completed);
|
|
216
|
-
throw error;
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
const results = await Promise.all(promises);
|
|
220
|
-
updateProgress(0);
|
|
221
|
-
return results;
|
|
222
|
-
}
|
|
223
|
-
for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
|
|
224
|
-
currentBatch = chunkIndex;
|
|
225
|
-
const chunk = chunks[chunkIndex];
|
|
226
|
-
if (effectiveConcurrent && chunk.length > effectiveConcurrent) {
|
|
227
|
-
for (let i = 0; i < chunk.length; i += effectiveConcurrent) {
|
|
228
|
-
const batch = chunk.slice(i, i + effectiveConcurrent);
|
|
229
|
-
const baseIndex = chunkIndex * (effectiveBatchSize || items.length) + i;
|
|
230
|
-
updateProgress(batch.length);
|
|
231
|
-
const batchPromises = batch.map(async (item, batchItemIndex) => {
|
|
232
|
-
const globalIndex = baseIndex + batchItemIndex;
|
|
233
|
-
const itemStartTime = Date.now();
|
|
234
|
-
try {
|
|
235
|
-
const result = await processor(item, globalIndex);
|
|
236
|
-
const duration = Date.now() - itemStartTime;
|
|
237
|
-
completed++;
|
|
238
|
-
progressResults.push({
|
|
239
|
-
index: globalIndex,
|
|
240
|
-
status: "completed",
|
|
241
|
-
result,
|
|
242
|
-
duration,
|
|
243
|
-
});
|
|
244
|
-
updateProgress(Math.max(0, batch.length - (batchItemIndex + 1)));
|
|
245
|
-
return result;
|
|
246
|
-
}
|
|
247
|
-
catch (error) {
|
|
248
|
-
const duration = Date.now() - itemStartTime;
|
|
249
|
-
failed++;
|
|
250
|
-
completed++;
|
|
251
|
-
progressResults.push({
|
|
252
|
-
index: globalIndex,
|
|
253
|
-
status: "failed",
|
|
254
|
-
error: error,
|
|
255
|
-
duration,
|
|
256
|
-
});
|
|
257
|
-
updateProgress(Math.max(0, batch.length - (batchItemIndex + 1)));
|
|
258
|
-
throw error;
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
const batchResults = await Promise.all(batchPromises);
|
|
262
|
-
results.push(...batchResults);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
const baseIndex = chunkIndex * (effectiveBatchSize || items.length);
|
|
267
|
-
updateProgress(chunk.length);
|
|
268
|
-
const chunkPromises = chunk.map(async (item, chunkItemIndex) => {
|
|
269
|
-
const globalIndex = baseIndex + chunkItemIndex;
|
|
270
|
-
const itemStartTime = Date.now();
|
|
271
|
-
try {
|
|
272
|
-
const result = await processor(item, globalIndex);
|
|
273
|
-
const duration = Date.now() - itemStartTime;
|
|
274
|
-
completed++;
|
|
275
|
-
progressResults.push({
|
|
276
|
-
index: globalIndex,
|
|
277
|
-
status: "completed",
|
|
278
|
-
result,
|
|
279
|
-
duration,
|
|
280
|
-
});
|
|
281
|
-
updateProgress(Math.max(0, chunk.length - (chunkItemIndex + 1)));
|
|
282
|
-
return result;
|
|
283
|
-
}
|
|
284
|
-
catch (error) {
|
|
285
|
-
const duration = Date.now() - itemStartTime;
|
|
286
|
-
failed++;
|
|
287
|
-
completed++;
|
|
288
|
-
progressResults.push({
|
|
289
|
-
index: globalIndex,
|
|
290
|
-
status: "failed",
|
|
291
|
-
error: error,
|
|
292
|
-
duration,
|
|
293
|
-
});
|
|
294
|
-
updateProgress(Math.max(0, chunk.length - (chunkItemIndex + 1)));
|
|
295
|
-
throw error;
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
const chunkResults = await Promise.all(chunkPromises);
|
|
299
|
-
results.push(...chunkResults);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
updateProgress(0);
|
|
303
|
-
return results;
|
|
304
|
-
}
|
|
305
|
-
if (isBatchOperation && executeOpts?.ids && executeOpts.ids.length > 0) {
|
|
306
|
-
const responses = await processBatch(executeOpts.ids, async (id) => {
|
|
307
|
-
const finalPath = buildPath(basePath, id);
|
|
308
|
-
return $fetch(finalPath, {
|
|
309
|
-
baseURL: fullBaseURL,
|
|
310
|
-
method: method,
|
|
311
|
-
body: finalBody ? toRaw(finalBody) : undefined,
|
|
312
|
-
headers: opts.headers,
|
|
313
|
-
query: finalQuery,
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
data.value = responses;
|
|
317
|
-
return responses;
|
|
318
|
-
}
|
|
319
|
-
if (isBatchOperation &&
|
|
320
|
-
executeOpts?.files &&
|
|
321
|
-
Array.isArray(executeOpts.files) &&
|
|
322
|
-
executeOpts.files.length > 0) {
|
|
323
|
-
const responses = await processBatch(executeOpts.files, async (fileObj) => {
|
|
324
|
-
return $fetch(basePath, {
|
|
325
|
-
baseURL: fullBaseURL,
|
|
326
|
-
method: method,
|
|
327
|
-
body: fileObj,
|
|
328
|
-
headers: opts.headers,
|
|
329
|
-
query: finalQuery,
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
data.value = responses;
|
|
333
|
-
return responses;
|
|
334
|
-
}
|
|
335
|
-
const finalPath = executeOpts?.id
|
|
336
|
-
? buildPath(basePath, executeOpts.id)
|
|
337
|
-
: basePath;
|
|
338
|
-
const response = await $fetch(finalPath, {
|
|
339
|
-
baseURL: fullBaseURL,
|
|
340
|
-
method: method,
|
|
341
|
-
body: finalBody ? toRaw(finalBody) : undefined,
|
|
342
|
-
headers: opts.headers,
|
|
343
|
-
query: finalQuery,
|
|
344
|
-
});
|
|
345
|
-
data.value = response;
|
|
346
|
-
return response;
|
|
347
|
-
}
|
|
348
|
-
catch (err) {
|
|
349
|
-
const apiError = handleError(err, errorContext, onError);
|
|
350
|
-
error.value = apiError;
|
|
351
|
-
return null;
|
|
352
|
-
}
|
|
353
|
-
finally {
|
|
354
|
-
pending.value = false;
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
return {
|
|
358
|
-
data,
|
|
359
|
-
error,
|
|
360
|
-
pending,
|
|
361
|
-
execute,
|
|
362
|
-
};
|
|
363
|
-
}
|