@vesperjs/shared 0.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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Vesper Shared
2
+
3
+ This is Shared library for Vesper.
@@ -0,0 +1,82 @@
1
+ import * as _$_vue_reactivity0 from "@vue/reactivity";
2
+ import { Ref } from "@vue/reactivity";
3
+
4
+ //#region src/types/error/backend-error-info.d.ts
5
+ interface BackendErrorInfo<BER> {
6
+ error?: BER;
7
+ status?: number;
8
+ }
9
+ //#endregion
10
+ //#region src/types/resource/backend-error-resource.d.ts
11
+ interface BackendErrorResource {
12
+ source?: string;
13
+ title: string;
14
+ errors: string[];
15
+ }
16
+ //#endregion
17
+ //#region src/types/resource/errors-resource.d.ts
18
+ interface ErrorsResource<T> {
19
+ errors: T;
20
+ }
21
+ //#endregion
22
+ //#region src/types/error-messages.d.ts
23
+ type ErrorMessages<T extends string> = Partial<Record<T, string[]>>;
24
+ //#endregion
25
+ //#region src/types/flash.d.ts
26
+ interface Flash {
27
+ notice?: string;
28
+ alert?: string;
29
+ }
30
+ //#endregion
31
+ //#region src/composables/backend/error/use-external-errors.d.ts
32
+ declare const useExternalErrors: <P extends string>({
33
+ flash
34
+ }: {
35
+ flash: Ref<Flash>;
36
+ }) => {
37
+ externalErrors: _$_vue_reactivity0.WritableComputedRef<Partial<Record<P, string[]>>, Partial<Record<P, string[]>>>;
38
+ clearExternalErrors: () => void;
39
+ isSuccess: () => boolean;
40
+ };
41
+ //#endregion
42
+ //#region src/composables/backend/error/use-backend-error-info.d.ts
43
+ declare const useBackendErrorInfo: <R extends object>() => {
44
+ backendErrorInfo: _$_vue_reactivity0.ComputedRef<BackendErrorInfo<R>>;
45
+ clearBackendErrorInfo: () => void;
46
+ };
47
+ //#endregion
48
+ //#region src/composables/util/use-date.d.ts
49
+ declare const useDate: () => {
50
+ isValidDate: (str: string) => boolean;
51
+ };
52
+ //#endregion
53
+ //#region src/composables/use-entity.d.ts
54
+ declare const useEntity: <M extends object, R extends object = M>() => {
55
+ create: ({
56
+ from
57
+ }: {
58
+ from: R | M;
59
+ }) => M;
60
+ copy: ({
61
+ from,
62
+ to
63
+ }: {
64
+ from: R | M;
65
+ to: M;
66
+ }) => void;
67
+ };
68
+ //#endregion
69
+ //#region src/composables/use-flash.d.ts
70
+ declare const useFlash: () => {
71
+ flash: _$_vue_reactivity0.Ref<{
72
+ notice?: string | undefined;
73
+ alert?: string | undefined;
74
+ }, Flash | {
75
+ notice?: string | undefined;
76
+ alert?: string | undefined;
77
+ }>;
78
+ clearFlash: () => void;
79
+ };
80
+ type UseFlashType = ReturnType<typeof useFlash>;
81
+ //#endregion
82
+ export { type BackendErrorInfo, type BackendErrorResource, type ErrorMessages, type ErrorsResource, type Flash, type UseFlashType, useBackendErrorInfo, useDate, useEntity, useExternalErrors, useFlash };
package/dist/index.mjs ADDED
@@ -0,0 +1,80 @@
1
+ import { computed, ref } from "@vue/reactivity";
2
+ //#region src/composables/backend/error/use-external-errors.ts
3
+ const useExternalErrors = function({ flash }) {
4
+ const errors = ref({});
5
+ const externalErrors = computed({
6
+ get() {
7
+ return errors.value;
8
+ },
9
+ set(value) {
10
+ if (errors.value) for (const key in value) errors.value[key] = value[key] ?? [];
11
+ }
12
+ });
13
+ const clearExternalErrors = () => {
14
+ externalErrors.value = {};
15
+ };
16
+ const isSuccess = () => {
17
+ let result = true;
18
+ for (const key in errors.value) if (errors.value[key].length > 0) result = false;
19
+ if (flash.value.alert) result = false;
20
+ return result;
21
+ };
22
+ return {
23
+ externalErrors,
24
+ clearExternalErrors,
25
+ isSuccess
26
+ };
27
+ };
28
+ //#endregion
29
+ //#region src/composables/backend/error/use-backend-error-info.ts
30
+ const useBackendErrorInfo = function() {
31
+ const info = ref({});
32
+ const backendErrorInfo = computed(() => {
33
+ return info.value;
34
+ });
35
+ const clearBackendErrorInfo = () => {
36
+ info.value = {};
37
+ };
38
+ return {
39
+ backendErrorInfo,
40
+ clearBackendErrorInfo
41
+ };
42
+ };
43
+ //#endregion
44
+ //#region src/composables/util/use-date.ts
45
+ const useDate = function() {
46
+ const isValidDate = (str) => {
47
+ return !!str && !!str.match(/\d{4}\/\d{2}\/\d{2}/) && !isNaN(Date.parse(str));
48
+ };
49
+ return { isValidDate };
50
+ };
51
+ //#endregion
52
+ //#region src/composables/use-entity.ts
53
+ const useEntity = function() {
54
+ const create = ({ from }) => {
55
+ const model = {};
56
+ Object.assign(model, from);
57
+ return model;
58
+ };
59
+ const copy = ({ from, to }) => {
60
+ Object.assign(to, from);
61
+ };
62
+ return {
63
+ create,
64
+ copy
65
+ };
66
+ };
67
+ //#endregion
68
+ //#region src/composables/use-flash.ts
69
+ const useFlash = function() {
70
+ const flash = ref({});
71
+ const clearFlash = () => {
72
+ flash.value = {};
73
+ };
74
+ return {
75
+ flash,
76
+ clearFlash
77
+ };
78
+ };
79
+ //#endregion
80
+ export { useBackendErrorInfo, useDate, useEntity, useExternalErrors, useFlash };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@vesperjs/shared",
3
+ "version": "0.2.0",
4
+ "keywords": [
5
+ "Nuxt",
6
+ "vue.js"
7
+ ],
8
+ "license": "MIT",
9
+ "author": "Yasumada Ashida",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/asip/vesper"
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "type": "module",
18
+ "exports": {
19
+ ".": "./dist/index.mjs",
20
+ "./package.json": "./package.json"
21
+ },
22
+ "dependencies": {
23
+ "@vue/reactivity": "^3.6.0-beta.9"
24
+ },
25
+ "devDependencies": {
26
+ "@eslint/js": "^9.39.4",
27
+ "@typescript-eslint/eslint-plugin": "^8.58.0",
28
+ "@typescript-eslint/parser": "^8.58.0",
29
+ "@vue/eslint-config-typescript": "^14.7.0",
30
+ "eslint": "^9.39.4",
31
+ "eslint-plugin-vue": "^10.8.0",
32
+ "oxfmt": "^0.43.0",
33
+ "tsdown": "^0.21.7",
34
+ "typescript": "^5.9.3"
35
+ },
36
+ "scripts": {
37
+ "build": "tsdown --dts",
38
+ "build:check": "tsc--noEmit",
39
+ "lint": "eslint --fix './src/**/*.{js,ts}'",
40
+ "fmt": "oxfmt",
41
+ "fmt:check": "oxfmt --check"
42
+ }
43
+ }