vue-context-storage 0.1.29 → 0.1.31
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 +2 -2
- package/dist/index.d.ts +45 -22
- package/dist/index.js +27 -4
- package/dist/zod.d.ts +59 -0
- package/dist/zod.js +15 -0
- package/package.json +91 -90
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ Import ContextStorage component in your `App.vue`:
|
|
|
70
70
|
</template>
|
|
71
71
|
|
|
72
72
|
<script setup lang="ts">
|
|
73
|
-
import { ContextStorage } from 'vue-context-storage
|
|
73
|
+
import { ContextStorage } from 'vue-context-storage'
|
|
74
74
|
</script>
|
|
75
75
|
```
|
|
76
76
|
|
|
@@ -80,7 +80,7 @@ Register the plugin in your main app file:
|
|
|
80
80
|
|
|
81
81
|
```typescript
|
|
82
82
|
import { createApp } from 'vue'
|
|
83
|
-
import { VueContextStoragePlugin } from 'vue-context-storage
|
|
83
|
+
import { VueContextStoragePlugin } from 'vue-context-storage'
|
|
84
84
|
import App from './App.vue'
|
|
85
85
|
|
|
86
86
|
const app = createApp(App)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as vue19 from "vue";
|
|
2
2
|
import { ComputedRef, InjectionKey, MaybeRefOrGetter, Plugin, PropType, UnwrapNestedRefs } from "vue";
|
|
3
3
|
import { LocationQuery, LocationQueryValue } from "vue-router";
|
|
4
4
|
|
|
5
5
|
//#region src/components/ContextStorageActivator.vue.d.ts
|
|
6
6
|
declare const _default$1: typeof __VLS_export$4;
|
|
7
|
-
declare const __VLS_export$4:
|
|
7
|
+
declare const __VLS_export$4: vue19.DefineComponent<{}, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
|
|
8
8
|
[key: string]: any;
|
|
9
|
-
}>, {}, {}, {},
|
|
9
|
+
}>, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/handlers/types.d.ts
|
|
12
12
|
interface HandlerSchema<T> {
|
|
@@ -65,55 +65,55 @@ interface ContextStorageHandler<T, O> {
|
|
|
65
65
|
//#endregion
|
|
66
66
|
//#region src/components/ContextStorageCollection.vue.d.ts
|
|
67
67
|
declare const _default$2: typeof __VLS_export$3;
|
|
68
|
-
declare const __VLS_export$3:
|
|
68
|
+
declare const __VLS_export$3: vue19.DefineComponent<vue19.ExtractPropTypes<{
|
|
69
69
|
handlers: {
|
|
70
70
|
type: PropType<ContextStorageHandlerFactory[]>;
|
|
71
71
|
default: () => ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
|
|
72
72
|
};
|
|
73
|
-
}>, () =>
|
|
73
|
+
}>, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
|
|
74
74
|
[key: string]: any;
|
|
75
|
-
}>[] | undefined, {}, {}, {},
|
|
75
|
+
}>[] | undefined, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<vue19.ExtractPropTypes<{
|
|
76
76
|
handlers: {
|
|
77
77
|
type: PropType<ContextStorageHandlerFactory[]>;
|
|
78
78
|
default: () => ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
|
|
79
79
|
};
|
|
80
80
|
}>> & Readonly<{}>, {
|
|
81
81
|
handlers: ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
|
|
82
|
-
}, {}, {}, {}, string,
|
|
82
|
+
}, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
|
|
83
83
|
//#endregion
|
|
84
84
|
//#region src/components/ContextStorageProvider.vue.d.ts
|
|
85
85
|
declare const _default$4: typeof __VLS_export$2;
|
|
86
|
-
declare const __VLS_export$2:
|
|
86
|
+
declare const __VLS_export$2: vue19.DefineComponent<vue19.ExtractPropTypes<{
|
|
87
87
|
itemKey: {
|
|
88
88
|
type: StringConstructor;
|
|
89
89
|
required: true;
|
|
90
90
|
};
|
|
91
|
-
}>, () =>
|
|
91
|
+
}>, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
|
|
92
92
|
[key: string]: any;
|
|
93
|
-
}>[] | undefined, {}, {}, {},
|
|
93
|
+
}>[] | undefined, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<vue19.ExtractPropTypes<{
|
|
94
94
|
itemKey: {
|
|
95
95
|
type: StringConstructor;
|
|
96
96
|
required: true;
|
|
97
97
|
};
|
|
98
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string,
|
|
98
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
|
|
99
99
|
//#endregion
|
|
100
100
|
//#region src/components/ContextStorage.vue.d.ts
|
|
101
101
|
declare const _default: typeof __VLS_export$1;
|
|
102
|
-
declare const __VLS_export$1:
|
|
102
|
+
declare const __VLS_export$1: vue19.DefineComponent<vue19.ExtractPropTypes<{
|
|
103
103
|
handlers: {
|
|
104
104
|
type: PropType<ContextStorageHandlerFactory[]>;
|
|
105
105
|
default: () => ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
|
|
106
106
|
};
|
|
107
|
-
}>, () =>
|
|
107
|
+
}>, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
|
|
108
108
|
[key: string]: any;
|
|
109
|
-
}>[] | undefined, {}, {}, {},
|
|
109
|
+
}>[] | undefined, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<vue19.ExtractPropTypes<{
|
|
110
110
|
handlers: {
|
|
111
111
|
type: PropType<ContextStorageHandlerFactory[]>;
|
|
112
112
|
default: () => ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
|
|
113
113
|
};
|
|
114
114
|
}>> & Readonly<{}>, {
|
|
115
115
|
handlers: ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
|
|
116
|
-
}, {}, {}, {}, string,
|
|
116
|
+
}, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
|
|
117
117
|
//#endregion
|
|
118
118
|
//#region src/prefix.d.ts
|
|
119
119
|
/**
|
|
@@ -136,19 +136,19 @@ declare const contextStoragePrefixSegmentsInjectKey: InjectionKey<MaybeRefOrGett
|
|
|
136
136
|
//#endregion
|
|
137
137
|
//#region src/components/ContextStoragePrefix.vue.d.ts
|
|
138
138
|
declare const _default$3: typeof __VLS_export;
|
|
139
|
-
declare const __VLS_export:
|
|
139
|
+
declare const __VLS_export: vue19.DefineComponent<vue19.ExtractPropTypes<{
|
|
140
140
|
name: {
|
|
141
141
|
type: PropType<ContextStoragePrefixSegment>;
|
|
142
142
|
required: true;
|
|
143
143
|
};
|
|
144
|
-
}>, () =>
|
|
144
|
+
}>, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
|
|
145
145
|
[key: string]: any;
|
|
146
|
-
}>, {}, {}, {},
|
|
146
|
+
}>, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<vue19.ExtractPropTypes<{
|
|
147
147
|
name: {
|
|
148
148
|
type: PropType<ContextStoragePrefixSegment>;
|
|
149
149
|
required: true;
|
|
150
150
|
};
|
|
151
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string,
|
|
151
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
|
|
152
152
|
//#endregion
|
|
153
153
|
//#region src/plugin.d.ts
|
|
154
154
|
declare const VueContextStoragePlugin: Plugin;
|
|
@@ -406,11 +406,11 @@ declare function createQueryHandler(baseOptions?: QueryHandlerBaseOptions): Cont
|
|
|
406
406
|
//#endregion
|
|
407
407
|
//#region src/handlers/local-storage/index.d.ts
|
|
408
408
|
declare function createLocalStorageHandler(customOptions?: WebStorageHandlerBaseOptions): ContextStorageHandlerFactory;
|
|
409
|
-
declare const useContextStorageLocalStorage: (data:
|
|
409
|
+
declare const useContextStorageLocalStorage: (data: vue19.MaybeRefOrGetter<Record<string, unknown>>, options: RegisterWebStorageHandlerOptions<Record<string, unknown>>) => UseContextStorageResult<Record<string, unknown>>;
|
|
410
410
|
//#endregion
|
|
411
411
|
//#region src/handlers/session-storage/index.d.ts
|
|
412
412
|
declare function createSessionStorageHandler(customOptions?: WebStorageHandlerBaseOptions): ContextStorageHandlerFactory;
|
|
413
|
-
declare const useContextStorageSessionStorage: (data:
|
|
413
|
+
declare const useContextStorageSessionStorage: (data: vue19.MaybeRefOrGetter<Record<string, unknown>>, options: RegisterWebStorageHandlerOptions<Record<string, unknown>>) => UseContextStorageResult<Record<string, unknown>>;
|
|
414
414
|
//#endregion
|
|
415
415
|
//#region src/handlers/query/transform-helpers.d.ts
|
|
416
416
|
declare function asNumber(value: QueryValue | number | undefined): number;
|
|
@@ -528,12 +528,35 @@ declare function asBoolean(value: QueryValue | undefined, options: {
|
|
|
528
528
|
missable?: false;
|
|
529
529
|
fallbackValue?: boolean;
|
|
530
530
|
}): boolean;
|
|
531
|
+
declare function asObjectArray(value: unknown): Record<string, unknown>[];
|
|
532
|
+
declare function asObjectArray<T>(value: unknown, transform: (value: Record<string, unknown>) => T): T[];
|
|
533
|
+
declare function asObjectArray<T>(value: unknown, options: {
|
|
534
|
+
nullable: true;
|
|
535
|
+
missable: true;
|
|
536
|
+
transform?: (value: Record<string, unknown>) => T;
|
|
537
|
+
}): T[] | null | undefined;
|
|
538
|
+
declare function asObjectArray<T>(value: unknown, options: {
|
|
539
|
+
nullable: true;
|
|
540
|
+
missable?: false;
|
|
541
|
+
transform?: (value: Record<string, unknown>) => T;
|
|
542
|
+
}): T[] | null;
|
|
543
|
+
declare function asObjectArray<T>(value: unknown, options: {
|
|
544
|
+
nullable?: false;
|
|
545
|
+
missable: true;
|
|
546
|
+
transform?: (value: Record<string, unknown>) => T;
|
|
547
|
+
}): T[] | undefined;
|
|
548
|
+
declare function asObjectArray<T>(value: unknown, options: {
|
|
549
|
+
nullable?: false;
|
|
550
|
+
missable?: false;
|
|
551
|
+
transform?: (value: Record<string, unknown>) => T;
|
|
552
|
+
}): T[];
|
|
531
553
|
declare const transform: {
|
|
532
554
|
asString: typeof asString;
|
|
533
555
|
asNumber: typeof asNumber;
|
|
534
556
|
asArray: typeof asArray;
|
|
535
557
|
asNumberArray: typeof asNumberArray;
|
|
536
558
|
asBoolean: typeof asBoolean;
|
|
559
|
+
asObjectArray: typeof asObjectArray;
|
|
537
560
|
};
|
|
538
561
|
//#endregion
|
|
539
562
|
//#region src/handlers/query/helpers.d.ts
|
|
@@ -593,4 +616,4 @@ declare const contextStorageSessionStorageHandlerInjectKey: InjectionKey<Context
|
|
|
593
616
|
//#region src/constants.d.ts
|
|
594
617
|
declare const defaultHandlers: ContextStorageHandlerFactory[];
|
|
595
618
|
//#endregion
|
|
596
|
-
export { type CollectionManager, type CollectionManagerItem, _default as ContextStorage, _default$1 as ContextStorageActivator, _default$2 as ContextStorageCollection, type ContextStorageHandler, type ContextStorageHandlerFactory, type ContextStorageHandlerMap, _default$3 as ContextStoragePrefix, type ContextStoragePrefixSegment, _default$4 as ContextStorageProvider, type WebStorageHandlerBaseOptions as LocalStorageHandlerBaseOptions, type QueryValue, type RegisterBaseOptions, type RegisterWebStorageHandlerBaseOptions as RegisterLocalStorageHandlerBaseOptions, VueContextStoragePlugin, asArray, asBoolean, asNumber, asNumberArray, asString, contextStorageCollectionInjectKey, contextStorageCollectionItemInjectKey, contextStorageHandlersInjectKey, contextStorageLocalStorageHandlerInjectKey, contextStoragePrefixSegmentsInjectKey, contextStorageQueryHandlerInjectKey, contextStorageSessionStorageHandlerInjectKey, createCollectionManager, createLocalStorageHandler, createQueryHandler, createSessionStorageHandler, defaultHandlers, defineContextStorageHandler, deserializeParams as deserializeQueryParams, resolveHandlerInjectionKey, serializeParams as serializeQueryParams, transform, useContextStorage, useContextStorageActivator, useContextStorageCollection, useContextStorageLocalStorage, useContextStorageProvider, useContextStorageQueryHandler, useContextStorageSessionStorage };
|
|
619
|
+
export { type CollectionManager, type CollectionManagerItem, _default as ContextStorage, _default$1 as ContextStorageActivator, _default$2 as ContextStorageCollection, type ContextStorageHandler, type ContextStorageHandlerFactory, type ContextStorageHandlerMap, _default$3 as ContextStoragePrefix, type ContextStoragePrefixSegment, _default$4 as ContextStorageProvider, type WebStorageHandlerBaseOptions as LocalStorageHandlerBaseOptions, type QueryValue, type RegisterBaseOptions, type RegisterWebStorageHandlerBaseOptions as RegisterLocalStorageHandlerBaseOptions, VueContextStoragePlugin, asArray, asBoolean, asNumber, asNumberArray, asObjectArray, asString, contextStorageCollectionInjectKey, contextStorageCollectionItemInjectKey, contextStorageHandlersInjectKey, contextStorageLocalStorageHandlerInjectKey, contextStoragePrefixSegmentsInjectKey, contextStorageQueryHandlerInjectKey, contextStorageSessionStorageHandlerInjectKey, createCollectionManager, createLocalStorageHandler, createQueryHandler, createSessionStorageHandler, defaultHandlers, defineContextStorageHandler, deserializeParams as deserializeQueryParams, resolveHandlerInjectionKey, serializeParams as serializeQueryParams, transform, useContextStorage, useContextStorageActivator, useContextStorageCollection, useContextStorageLocalStorage, useContextStorageProvider, useContextStorageQueryHandler, useContextStorageSessionStorage };
|
package/dist/index.js
CHANGED
|
@@ -73,7 +73,16 @@ function serializeParams(params, options = {}) {
|
|
|
73
73
|
result[formattedKey] = value;
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
if (typeof value === "object") if (Array.isArray(value))
|
|
76
|
+
if (typeof value === "object") if (Array.isArray(value)) if (value.some((item) => typeof item === "object" && item !== null && !Array.isArray(item))) {
|
|
77
|
+
const indexed = {};
|
|
78
|
+
value.forEach((item, i) => {
|
|
79
|
+
indexed[String(i)] = item;
|
|
80
|
+
});
|
|
81
|
+
Object.assign(result, serializeParams(indexed, {
|
|
82
|
+
...options,
|
|
83
|
+
prefix: formattedKey
|
|
84
|
+
}));
|
|
85
|
+
} else result[formattedKey] = value.map(String);
|
|
77
86
|
else Object.assign(result, serializeParams(value, {
|
|
78
87
|
...options,
|
|
79
88
|
prefix: formattedKey
|
|
@@ -407,7 +416,7 @@ function createQueryHandler(baseOptions) {
|
|
|
407
416
|
setTimeout(syncCallback);
|
|
408
417
|
} else {
|
|
409
418
|
registerOptions.prefix;
|
|
410
|
-
|
|
419
|
+
syncCallback();
|
|
411
420
|
}
|
|
412
421
|
return {
|
|
413
422
|
stop: () => {
|
|
@@ -912,13 +921,27 @@ function asBoolean(value, options) {
|
|
|
912
921
|
}
|
|
913
922
|
return fallbackValue;
|
|
914
923
|
}
|
|
924
|
+
function asObjectArray(value, optionsOrTransform) {
|
|
925
|
+
const { nullable = false, missable = false, transform: transform2 } = typeof optionsOrTransform === "function" ? { transform: optionsOrTransform } : optionsOrTransform || {};
|
|
926
|
+
if (value === null && nullable) return null;
|
|
927
|
+
if (value === void 0 && missable) return;
|
|
928
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return nullable ? null : [];
|
|
929
|
+
const entries = Object.entries(value).sort(([a], [b]) => Number(a) - Number(b));
|
|
930
|
+
if (transform2) return entries.map(([, val]) => {
|
|
931
|
+
return transform2(val && typeof val === "object" && !Array.isArray(val) ? val : {});
|
|
932
|
+
});
|
|
933
|
+
return entries.map(([, val]) => {
|
|
934
|
+
return val && typeof val === "object" && !Array.isArray(val) ? val : {};
|
|
935
|
+
});
|
|
936
|
+
}
|
|
915
937
|
const transform = {
|
|
916
938
|
asString,
|
|
917
939
|
asNumber,
|
|
918
940
|
asArray,
|
|
919
941
|
asNumberArray,
|
|
920
|
-
asBoolean
|
|
942
|
+
asBoolean,
|
|
943
|
+
asObjectArray
|
|
921
944
|
};
|
|
922
945
|
|
|
923
946
|
//#endregion
|
|
924
|
-
export { ContextStorage_default as ContextStorage, ContextStorageActivator_default as ContextStorageActivator, ContextStorageCollection_default as ContextStorageCollection, ContextStoragePrefix_default as ContextStoragePrefix, ContextStorageProvider_default as ContextStorageProvider, VueContextStoragePlugin, asArray, asBoolean, asNumber, asNumberArray, asString, contextStorageCollectionInjectKey, contextStorageCollectionItemInjectKey, contextStorageHandlersInjectKey, contextStorageLocalStorageHandlerInjectKey, contextStoragePrefixSegmentsInjectKey, contextStorageQueryHandlerInjectKey, contextStorageSessionStorageHandlerInjectKey, createCollectionManager, createLocalStorageHandler, createQueryHandler, createSessionStorageHandler, defaultHandlers, defineContextStorageHandler, deserializeParams as deserializeQueryParams, resolveHandlerInjectionKey, serializeParams as serializeQueryParams, transform, useContextStorage, useContextStorageActivator, useContextStorageCollection, useContextStorageLocalStorage, useContextStorageProvider, useContextStorageQueryHandler, useContextStorageSessionStorage };
|
|
947
|
+
export { ContextStorage_default as ContextStorage, ContextStorageActivator_default as ContextStorageActivator, ContextStorageCollection_default as ContextStorageCollection, ContextStoragePrefix_default as ContextStoragePrefix, ContextStorageProvider_default as ContextStorageProvider, VueContextStoragePlugin, asArray, asBoolean, asNumber, asNumberArray, asObjectArray, asString, contextStorageCollectionInjectKey, contextStorageCollectionItemInjectKey, contextStorageHandlersInjectKey, contextStorageLocalStorageHandlerInjectKey, contextStoragePrefixSegmentsInjectKey, contextStorageQueryHandlerInjectKey, contextStorageSessionStorageHandlerInjectKey, createCollectionManager, createLocalStorageHandler, createQueryHandler, createSessionStorageHandler, defaultHandlers, defineContextStorageHandler, deserializeParams as deserializeQueryParams, resolveHandlerInjectionKey, serializeParams as serializeQueryParams, transform, useContextStorage, useContextStorageActivator, useContextStorageCollection, useContextStorageLocalStorage, useContextStorageProvider, useContextStorageQueryHandler, useContextStorageSessionStorage };
|
package/dist/zod.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/zod.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a Zod schema for arrays of objects serialized as indexed query parameters.
|
|
7
|
+
*
|
|
8
|
+
* URL query parameters serialize arrays of objects as indexed keys:
|
|
9
|
+
* `items[0][product]=Apple&items[0][quantity]=5&items[1][product]=Banana&items[1][quantity]=10`
|
|
10
|
+
*
|
|
11
|
+
* After deserialization, these become indexed objects:
|
|
12
|
+
* `{ '0': { product: 'Apple', quantity: '5' }, '1': { product: 'Banana', quantity: '10' } }`
|
|
13
|
+
*
|
|
14
|
+
* This helper wraps `z.record()` + `.transform()` to convert them back to a typed array,
|
|
15
|
+
* so you don't have to write the boilerplate yourself.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { z } from 'zod'
|
|
20
|
+
* import { zObjectArray } from 'vue-context-storage/zod'
|
|
21
|
+
*
|
|
22
|
+
* const ItemSchema = z.object({
|
|
23
|
+
* product: z.string().default(''),
|
|
24
|
+
* quantity: z.coerce.number().default(0),
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* const DataSchema = z.object({
|
|
28
|
+
* title: z.string().default(''),
|
|
29
|
+
* items: zObjectArray(ItemSchema),
|
|
30
|
+
* })
|
|
31
|
+
*
|
|
32
|
+
* useContextStorage('query', data, { schema: DataSchema })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function zObjectArray<T extends z.ZodTypeAny>(itemSchema: T): z.ZodPipe<z.ZodDefault<z.ZodRecord<z.ZodString, T>>, z.ZodTransform<z.core.output<T>[], Record<string, z.core.output<T>>>>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a Zod schema for booleans serialized as URL query parameters.
|
|
38
|
+
*
|
|
39
|
+
* URL query parameters serialize booleans as `'1'`/`'0'` strings.
|
|
40
|
+
* `z.coerce.boolean()` cannot be used because `Boolean('0')` is `true` in JavaScript.
|
|
41
|
+
*
|
|
42
|
+
* This helper correctly handles `'1'`, `'true'`, `'0'`, `'false'`, and native booleans.
|
|
43
|
+
*
|
|
44
|
+
* @param defaultValue - The default value when the field is missing (defaults to `false`)
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { z } from 'zod'
|
|
49
|
+
* import { zUrlBoolean } from 'vue-context-storage/zod'
|
|
50
|
+
*
|
|
51
|
+
* const Schema = z.object({
|
|
52
|
+
* active: zUrlBoolean(), // defaults to false
|
|
53
|
+
* enabled: zUrlBoolean(true), // defaults to true
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function zUrlBoolean(defaultValue?: boolean): z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>, z.ZodTransform<boolean, string | boolean>>>;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { zObjectArray, zUrlBoolean };
|
package/dist/zod.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/zod.ts
|
|
4
|
+
function zObjectArray(itemSchema) {
|
|
5
|
+
return z.record(z.string(), itemSchema).default({}).transform((record) => Object.entries(record).sort(([a], [b]) => Number(a) - Number(b)).map(([, v]) => v));
|
|
6
|
+
}
|
|
7
|
+
function zUrlBoolean(defaultValue = false) {
|
|
8
|
+
return z.union([z.boolean(), z.string()]).transform((val) => {
|
|
9
|
+
if (typeof val === "boolean") return val;
|
|
10
|
+
return val === "1" || val === "true";
|
|
11
|
+
}).default(defaultValue);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { zObjectArray, zUrlBoolean };
|
package/package.json
CHANGED
|
@@ -1,90 +1,91 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vue-context-storage",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"description": "Vue 3 context storage system with URL query synchronization support",
|
|
6
|
-
"author": "",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"homepage": "https://github.com/lviobio/vue-context-storage#readme",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/lviobio/vue-context-storage.git"
|
|
12
|
-
},
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/lviobio/vue-context-storage/issues"
|
|
15
|
-
},
|
|
16
|
-
"exports": {
|
|
17
|
-
".": "./dist/index.js",
|
|
18
|
-
"./
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"ts:check
|
|
34
|
-
"
|
|
35
|
-
"format
|
|
36
|
-
"
|
|
37
|
-
"lint
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"vue
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"@
|
|
59
|
-
"@types/
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"@vitest/
|
|
63
|
-
"@
|
|
64
|
-
"@vue/
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"eslint
|
|
69
|
-
"eslint-
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"typescript
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"vitest
|
|
83
|
-
"vue": "^
|
|
84
|
-
"vue
|
|
85
|
-
"
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "vue-context-storage",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.31",
|
|
5
|
+
"description": "Vue 3 context storage system with URL query synchronization support",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/lviobio/vue-context-storage#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/lviobio/vue-context-storage.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/lviobio/vue-context-storage/issues"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./dist/index.js",
|
|
18
|
+
"./zod": "./dist/zod.js",
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"module": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsdown",
|
|
32
|
+
"dev": "tsdown --watch",
|
|
33
|
+
"check": "npm run ts:check && npm run lint:check && npm run format:check && npm run dependency-cruiser:check",
|
|
34
|
+
"ts:check": "vue-tsc --noEmit",
|
|
35
|
+
"format": "prettier --write src/ playground/src",
|
|
36
|
+
"format:check": "prettier --check src/ playground/src",
|
|
37
|
+
"lint": "eslint . --fix",
|
|
38
|
+
"lint:check": "eslint .",
|
|
39
|
+
"dependency-cruiser:check": "depcruise --config .dependency-cruiser.cjs src playground/src",
|
|
40
|
+
"play": "vite",
|
|
41
|
+
"build:playground": "vite build",
|
|
42
|
+
"preview:playground": "vite preview --outDir playground/dist",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"release": "bumpp && npm publish",
|
|
45
|
+
"prepublishOnly": "npm run check && npm run test && npm run build"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"vue": "^3.0.0",
|
|
49
|
+
"vue-router": "^4.0.0 || ^5.0.0",
|
|
50
|
+
"zod": "^4.0.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"zod": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@tailwindcss/vite": "^4.1.18",
|
|
59
|
+
"@types/lodash": "^4.17.21",
|
|
60
|
+
"@types/node": "^25.0.3",
|
|
61
|
+
"@vitejs/plugin-vue": "^6.0.3",
|
|
62
|
+
"@vitest/browser-playwright": "^4.0.16",
|
|
63
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
64
|
+
"@vue/eslint-config-typescript": "^14.6.0",
|
|
65
|
+
"@vue/test-utils": "^2.4.6",
|
|
66
|
+
"bumpp": "^10.3.2",
|
|
67
|
+
"dependency-cruiser": "^17.3.6",
|
|
68
|
+
"eslint": "^9.39.2",
|
|
69
|
+
"eslint-config-prettier": "^10.1.8",
|
|
70
|
+
"eslint-plugin-vue": "^10.6.2",
|
|
71
|
+
"happy-dom": "^20.1.0",
|
|
72
|
+
"highlight.js": "^11.11.1",
|
|
73
|
+
"jsdom": "^27.4.0",
|
|
74
|
+
"naive-ui": "^2.43.2",
|
|
75
|
+
"playwright": "^1.57.0",
|
|
76
|
+
"prettier": "^3.7.4",
|
|
77
|
+
"tailwindcss": "^4.1.18",
|
|
78
|
+
"tsdown": "^0.18.4",
|
|
79
|
+
"typescript": "^5.9.3",
|
|
80
|
+
"typescript-eslint": "^8.51.0",
|
|
81
|
+
"vite": "^7.3.0",
|
|
82
|
+
"vitest": "^4.0.16",
|
|
83
|
+
"vitest-browser-vue": "^2.0.1",
|
|
84
|
+
"vue": "^3.5.26",
|
|
85
|
+
"vue-tsc": "^3.2.1",
|
|
86
|
+
"zod": "^4.3.5"
|
|
87
|
+
},
|
|
88
|
+
"dependencies": {
|
|
89
|
+
"lodash": "^4.17.23"
|
|
90
|
+
}
|
|
91
|
+
}
|