@anweb/nuxt-ancore 1.1.1 → 1.2.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/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/module.d.mts +8 -1
- package/dist/module.d.ts +15 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +5 -8
- package/dist/runtime/composables/useData.d.ts +16 -0
- package/dist/runtime/composables/useData.js +30 -0
- package/dist/runtime/utils/api.d.ts +2 -2
- package/dist/runtime/utils/api.js +2 -2
- package/dist/runtime/utils/index.d.ts +1 -0
- package/dist/runtime/utils/index.js +1 -0
- package/dist/types.d.mts +6 -2
- package/package.json +5 -4
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/runtime/utils/index.js';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/runtime/utils/index.js';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/runtime/utils/index.js';
|
package/dist/module.d.mts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { TApi } from '@anweb/nuxt-ancore';
|
|
2
3
|
|
|
3
4
|
interface ModuleOptions {
|
|
4
5
|
}
|
|
6
|
+
|
|
7
|
+
declare module '#app' {
|
|
8
|
+
interface NuxtApp {
|
|
9
|
+
$api: TApi
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
6
14
|
|
|
7
15
|
export { _default as default };
|
|
8
|
-
export type { ModuleOptions };
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { TApi } from '@anweb/nuxt-ancore';
|
|
3
|
+
|
|
4
|
+
interface ModuleOptions {
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare module '#app' {
|
|
8
|
+
interface NuxtApp {
|
|
9
|
+
$api: TApi
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
14
|
+
|
|
15
|
+
export { _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver,
|
|
1
|
+
import { defineNuxtModule, createResolver, addImportsDir } from '@nuxt/kit';
|
|
2
2
|
|
|
3
3
|
const module = defineNuxtModule({
|
|
4
4
|
meta: {
|
|
5
5
|
name: "AnCore",
|
|
6
6
|
configKey: "ancore"
|
|
7
7
|
},
|
|
8
|
-
// Default configuration options of the Nuxt module
|
|
9
8
|
defaults: {},
|
|
10
|
-
setup(_options, _nuxt) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
from: resolver.resolve("runtime/utils/api")
|
|
15
|
-
});
|
|
9
|
+
async setup(_options, _nuxt) {
|
|
10
|
+
const { resolve } = createResolver(import.meta.url);
|
|
11
|
+
_nuxt.options.runtimeConfig.public.ancore = {};
|
|
12
|
+
addImportsDir(resolve("./runtime/composables"));
|
|
16
13
|
}
|
|
17
14
|
});
|
|
18
15
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { NitroFetchRequest } from 'nitropack';
|
|
2
|
+
import { type Ref, type ComputedRef } from 'vue';
|
|
3
|
+
import { useAsyncData } from '#app';
|
|
4
|
+
interface TConfig {
|
|
5
|
+
request: NitroFetchRequest;
|
|
6
|
+
}
|
|
7
|
+
interface TUseData<TData, TError> {
|
|
8
|
+
init: () => Promise<void>;
|
|
9
|
+
loading: ComputedRef<boolean>;
|
|
10
|
+
request: Ref<NitroFetchRequest>;
|
|
11
|
+
data: Ref<TData>;
|
|
12
|
+
error: Ref<TError>;
|
|
13
|
+
status: ReturnType<typeof useAsyncData>['status'];
|
|
14
|
+
}
|
|
15
|
+
export declare const useData: <TData = unknown, TError = unknown>(config: TConfig) => TUseData<TData, TError>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
|
+
import { useAsyncData } from "#app";
|
|
3
|
+
import { userApi } from "../../utils";
|
|
4
|
+
export const useData = (config) => {
|
|
5
|
+
const request = ref(config.request);
|
|
6
|
+
const loading = computed(() => {
|
|
7
|
+
return status.value === "pending";
|
|
8
|
+
});
|
|
9
|
+
const key = computed(() => {
|
|
10
|
+
return request.value.toString();
|
|
11
|
+
});
|
|
12
|
+
const {
|
|
13
|
+
data,
|
|
14
|
+
error,
|
|
15
|
+
execute,
|
|
16
|
+
status
|
|
17
|
+
} = useAsyncData(
|
|
18
|
+
key,
|
|
19
|
+
() => userApi(request.value, { method: "GET" }),
|
|
20
|
+
{ immediate: false }
|
|
21
|
+
);
|
|
22
|
+
return {
|
|
23
|
+
init: execute,
|
|
24
|
+
loading,
|
|
25
|
+
request,
|
|
26
|
+
data,
|
|
27
|
+
error,
|
|
28
|
+
status
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { NitroFetchOptions, NitroFetchRequest } from 'nitropack';
|
|
2
|
-
declare const
|
|
3
|
-
export
|
|
2
|
+
export declare const api: <TData = unknown, TError = unknown>(request: NitroFetchRequest, opts: NitroFetchOptions<string>) => Promise<TData>;
|
|
3
|
+
export type TApi = typeof api;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './api.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./api.js";
|
package/dist/types.d.mts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
|
+
|
|
3
|
+
import type { default as Module } from './module.mjs'
|
|
2
4
|
|
|
3
|
-
export
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
+
|
|
7
|
+
export { default } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anweb/nuxt-ancore",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "AnCore Nuxt module",
|
|
5
5
|
"repository": "https://github.com/ANLTD/ancore",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"types": "./dist/
|
|
11
|
-
"import": "./dist/
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"import": "./dist/index.mjs"
|
|
12
12
|
},
|
|
13
13
|
"./module": {
|
|
14
14
|
"types": "./dist/types.d.mts",
|
|
15
15
|
"import": "./dist/module.mjs"
|
|
16
|
-
}
|
|
16
|
+
},
|
|
17
|
+
"./composables/*": "./dist/runtime/composables/*"
|
|
17
18
|
},
|
|
18
19
|
"main": "./dist/module.mjs",
|
|
19
20
|
"typesVersions": {
|