@ciwergrp/nuxid 1.2.2 → 1.4.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.
@@ -233,6 +233,7 @@ async function run() {
233
233
  if (globalArgs.includes('--help') || globalArgs.includes('-h')) {
234
234
  console.log('\nUsage: pnpm nuxid make:request [options]\n');
235
235
  console.log('Options:');
236
+ console.log(' -a, --app <name> Target app under ./apps/<name>');
236
237
  console.log(' -p, --prefix <dir> Override the target prefix (default: project\'s config or \'app\')');
237
238
  console.log(' -h, --help Show this help message\n');
238
239
  console.log('Examples:');
@@ -288,9 +289,22 @@ async function run() {
288
289
  const fileName = `${camelCaseName}Request.ts`;
289
290
 
290
291
  const argv = process.argv.slice(2);
292
+ let appName;
291
293
  let cliPrefix;
292
294
  for (let i = 0; i < argv.length; i++) {
293
295
  const a = argv[i];
296
+ if (a.startsWith('--app=')) {
297
+ appName = a.split('=')[1];
298
+ }
299
+ if (a === '--app' && argv[i + 1] !== undefined) {
300
+ appName = argv[i + 1];
301
+ }
302
+ if (a.startsWith('-a=')) {
303
+ appName = a.split('=')[1];
304
+ }
305
+ if (a === '-a' && argv[i + 1] !== undefined) {
306
+ appName = argv[i + 1];
307
+ }
294
308
  if (a.startsWith('--prefix=')) {
295
309
  cliPrefix = a.split('=')[1];
296
310
  break;
@@ -312,11 +326,14 @@ async function run() {
312
326
  const configuredPrefix = loadPrefixFromProjectConfig();
313
327
  const prefix = cliPrefix !== undefined ? cliPrefix : (typeof configuredPrefix === 'string' ? configuredPrefix : 'app');
314
328
 
315
- const baseDir = prefix === '' ? cwd() : path.join(cwd(), prefix);
316
- const targetDir = path.join(baseDir, 'requests');
329
+ const baseDir = appName ? path.join(cwd(), 'apps', appName) : cwd();
330
+ const targetRoot = prefix === '' ? baseDir : path.join(baseDir, prefix);
331
+ const targetDir = path.join(targetRoot, 'requests');
317
332
  const targetPath = path.join(targetDir, fileName);
318
333
 
319
334
  const shownPrefix = prefix === '' ? '(project root)' : prefix;
335
+ const shownApp = appName ? `apps/${appName}` : '(project root)';
336
+ console.log(`${colors.dim}App: ${colors.cyan}${shownApp}${colors.reset}`);
320
337
  console.log(`${colors.dim}Using prefix: ${colors.cyan}${shownPrefix}${colors.reset} -> ${colors.dim}${path.relative(cwd(), targetDir) || '.'}${colors.reset}`);
321
338
 
322
339
  const writeFileAndLint = () => {
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
3
  "configKey": "nuxid",
4
- "version": "1.2.2",
4
+ "version": "1.4.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -13,6 +13,7 @@ export interface CursorMetaConfig {
13
13
  }
14
14
  export interface CursorFetchOptions<TRequest extends NitroFetchRequest = NitroFetchRequest> {
15
15
  lazy?: boolean;
16
+ immediate?: boolean;
16
17
  pollInterval?: number;
17
18
  fetcher?: typeof $fetch;
18
19
  fetchOptions?: NitroFetchOptions<TRequest>;
@@ -20,7 +21,7 @@ export interface CursorFetchOptions<TRequest extends NitroFetchRequest = NitroFe
20
21
  itemKey?: string;
21
22
  cursorParam?: string;
22
23
  }
23
- export declare function useCursorHttp<T extends Record<string, any> = any, TResponse extends APIResponseCursor<T> = APIResponseCursor<T>, TRequest extends NitroFetchRequest = NitroFetchRequest>(url: TRequest, options?: CursorFetchOptions<TRequest>): {
24
+ export declare function useCursorHttp<T extends Record<string, any> = any, TResponse extends APIResponseCursor<T> = APIResponseCursor<T>, TRequest extends NitroFetchRequest = NitroFetchRequest>(url: TRequest, options?: CursorFetchOptions<TRequest>): Promise<{
24
25
  data: import("vue").Ref<TResponse | undefined, TResponse | undefined>;
25
26
  loading: Readonly<import("vue").Ref<boolean, boolean>>;
26
27
  error: Readonly<import("vue").Ref<Error | null, Error | null>>;
@@ -28,4 +29,5 @@ export declare function useCursorHttp<T extends Record<string, any> = any, TResp
28
29
  isLoadMoreTriggered: Readonly<import("vue").Ref<boolean, boolean>>;
29
30
  loadMore: () => Promise<void>;
30
31
  refresh: () => Promise<void>;
31
- };
32
+ init: () => Promise<void>;
33
+ }>;
@@ -1,5 +1,5 @@
1
1
  import { isRef, onUnmounted, readonly, ref, shallowRef, watch } from "vue";
2
- export function useCursorHttp(url, options) {
2
+ export async function useCursorHttp(url, options) {
3
3
  function findReactiveSources(obj) {
4
4
  const sources = [];
5
5
  if (!obj || typeof obj !== "object") {
@@ -38,6 +38,7 @@ export function useCursorHttp(url, options) {
38
38
  }
39
39
  const {
40
40
  lazy = false,
41
+ immediate = true,
41
42
  pollInterval,
42
43
  fetcher,
43
44
  fetchOptions,
@@ -56,6 +57,7 @@ export function useCursorHttp(url, options) {
56
57
  unwrapReactiveObject(fetchOptions)
57
58
  );
58
59
  let pollTimer = null;
60
+ let fetchPromise = null;
59
61
  const fetcherFn = fetcher ?? globalThis.$fetch;
60
62
  if (!fetcherFn) {
61
63
  throw new Error("Nuxt $fetch is not available in the current context");
@@ -83,25 +85,35 @@ export function useCursorHttp(url, options) {
83
85
  };
84
86
  const fetchData = async (fetchUrl, params) => {
85
87
  if (loading.value) {
86
- return;
88
+ return fetchPromise ?? Promise.resolve();
87
89
  }
88
90
  if (!hasNextPage.value && data.value) {
89
- return;
91
+ return Promise.resolve();
90
92
  }
91
93
  loading.value = true;
92
94
  error.value = null;
95
+ const promise = (async () => {
96
+ try {
97
+ const response = await fetcherFn(fetchUrl, params);
98
+ data.value = {
99
+ ...response,
100
+ data: [...data.value?.data ?? [], ...response.data]
101
+ };
102
+ nextCursor.value = normalizeCursorValue(response.meta?.[cursorKey]);
103
+ hasNextPage.value = response.meta?.[hasMoreKey] ?? false;
104
+ } catch (e) {
105
+ error.value = e;
106
+ } finally {
107
+ loading.value = false;
108
+ }
109
+ })();
110
+ fetchPromise = promise;
93
111
  try {
94
- const response = await fetcherFn(fetchUrl, params);
95
- data.value = {
96
- ...response,
97
- data: [...data.value?.data ?? [], ...response.data]
98
- };
99
- nextCursor.value = normalizeCursorValue(response.meta?.[cursorKey]);
100
- hasNextPage.value = response.meta?.[hasMoreKey] ?? false;
101
- } catch (e) {
102
- error.value = e;
112
+ await promise;
103
113
  } finally {
104
- loading.value = false;
114
+ if (fetchPromise === promise) {
115
+ fetchPromise = null;
116
+ }
105
117
  }
106
118
  };
107
119
  const pollData = async () => {
@@ -144,6 +156,12 @@ export function useCursorHttp(url, options) {
144
156
  isLoadMoreTriggered.value = false;
145
157
  await fetchData(initialUrl, currentParams.value);
146
158
  };
159
+ const init = async () => {
160
+ if (data.value) {
161
+ return;
162
+ }
163
+ await fetchData(initialUrl, currentParams.value);
164
+ };
147
165
  const reactiveSources = findReactiveSources(fetchOptions);
148
166
  if (reactiveSources.length > 0) {
149
167
  watch(
@@ -163,8 +181,8 @@ export function useCursorHttp(url, options) {
163
181
  clearInterval(pollTimer);
164
182
  }
165
183
  });
166
- if (!lazy) {
167
- void fetchData(initialUrl, currentParams.value);
184
+ if (!lazy && immediate) {
185
+ await init();
168
186
  }
169
187
  return {
170
188
  data,
@@ -173,6 +191,7 @@ export function useCursorHttp(url, options) {
173
191
  hasNextPage: readonly(hasNextPage),
174
192
  isLoadMoreTriggered: readonly(isLoadMoreTriggered),
175
193
  loadMore,
176
- refresh
194
+ refresh,
195
+ init
177
196
  };
178
197
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
- "version": "1.2.2",
3
+ "version": "1.4.0",
4
4
  "description": "All-in-one essential modules for Nuxt",
5
5
  "repository": {
6
6
  "type": "git",