vue-context-storage 0.1.38 → 0.1.39

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 CHANGED
@@ -726,6 +726,44 @@ const Schema = z.object({
726
726
  })
727
727
  ```
728
728
 
729
+ ### `zNumberArray()`
730
+
731
+ Creates a Zod schema for arrays of numbers serialized as URL query parameters. Handles the common issue where a single query value (`?ids=1`) is deserialized as a string `'1'` instead of an array `['1']`, which would cause `z.coerce.number().array()` to fail with `"expected array, received string"`.
732
+
733
+ This helper normalizes the input by accepting both a single value and an array, coercing each element to a number.
734
+
735
+ ```typescript
736
+ import { z } from 'zod'
737
+ import { zNumberArray } from 'vue-context-storage/zod'
738
+
739
+ const Schema = z.object({
740
+ users_ids: zNumberArray(),
741
+ })
742
+
743
+ // All of these work:
744
+ Schema.parse({ users_ids: ['1', '2'] }) // → { users_ids: [1, 2] }
745
+ Schema.parse({ users_ids: '1' }) // → { users_ids: [1] }
746
+ Schema.parse({}) // → { users_ids: [] }
747
+ ```
748
+
749
+ ### `zStringArray()`
750
+
751
+ Creates a Zod schema for arrays of strings serialized as URL query parameters. Same problem as `zNumberArray()` — a single query value (`?tags=vue`) is deserialized as a string `'vue'` instead of an array `['vue']`, which would cause `z.string().array()` to fail.
752
+
753
+ ```typescript
754
+ import { z } from 'zod'
755
+ import { zStringArray } from 'vue-context-storage/zod'
756
+
757
+ const Schema = z.object({
758
+ tags: zStringArray(),
759
+ })
760
+
761
+ // All of these work:
762
+ Schema.parse({ tags: ['vue', 'react'] }) // → { tags: ['vue', 'react'] }
763
+ Schema.parse({ tags: 'vue' }) // → { tags: ['vue'] }
764
+ Schema.parse({}) // → { tags: [] }
765
+ ```
766
+
729
767
  ### `createSchemaObject(schema, options?)`
730
768
 
731
769
  Creates a plain object with empty/default values based on a Zod schema. Useful for initializing reactive data from a schema definition.
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import * as vue19 from "vue";
1
+ import * as vue9 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: vue19.DefineComponent<{}, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
7
+ declare const __VLS_export$4: vue9.DefineComponent<{}, () => vue9.VNode<vue9.RendererNode, vue9.RendererElement, {
8
8
  [key: string]: any;
9
- }>, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
9
+ }>, {}, {}, {}, vue9.ComponentOptionsMixin, vue9.ComponentOptionsMixin, {}, string, vue9.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue9.ComponentProvideOptions, true, {}, any>;
10
10
  //#endregion
11
11
  //#region src/handlers/types.d.ts
12
12
  interface HandlerSchema<T> {
@@ -65,7 +65,7 @@ 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: vue19.DefineComponent<vue19.ExtractPropTypes<{
68
+ declare const __VLS_export$3: vue9.DefineComponent<vue9.ExtractPropTypes<{
69
69
  handlers: {
70
70
  type: PropType<ContextStorageHandlerFactory[]>;
71
71
  default: () => ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
@@ -81,9 +81,9 @@ declare const __VLS_export$3: vue19.DefineComponent<vue19.ExtractPropTypes<{
81
81
  type: PropType<ContextStorageHandlerFactory[]>;
82
82
  default: undefined;
83
83
  };
84
- }>, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
84
+ }>, () => vue9.VNode<vue9.RendererNode, vue9.RendererElement, {
85
85
  [key: string]: any;
86
- }>[] | undefined, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<vue19.ExtractPropTypes<{
86
+ }>[] | undefined, {}, {}, {}, vue9.ComponentOptionsMixin, vue9.ComponentOptionsMixin, {}, string, vue9.PublicProps, Readonly<vue9.ExtractPropTypes<{
87
87
  handlers: {
88
88
  type: PropType<ContextStorageHandlerFactory[]>;
89
89
  default: () => ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
@@ -102,27 +102,27 @@ declare const __VLS_export$3: vue19.DefineComponent<vue19.ExtractPropTypes<{
102
102
  }>> & Readonly<{}>, {
103
103
  handlers: ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
104
104
  additionalHandlers: ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
105
- }, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
105
+ }, {}, {}, {}, string, vue9.ComponentProvideOptions, true, {}, any>;
106
106
  //#endregion
107
107
  //#region src/components/ContextStorageProvider.vue.d.ts
108
108
  declare const _default$4: typeof __VLS_export$2;
109
- declare const __VLS_export$2: vue19.DefineComponent<vue19.ExtractPropTypes<{
109
+ declare const __VLS_export$2: vue9.DefineComponent<vue9.ExtractPropTypes<{
110
110
  itemKey: {
111
111
  type: StringConstructor;
112
112
  required: true;
113
113
  };
114
- }>, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
114
+ }>, () => vue9.VNode<vue9.RendererNode, vue9.RendererElement, {
115
115
  [key: string]: any;
116
- }>[] | undefined, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<vue19.ExtractPropTypes<{
116
+ }>[] | undefined, {}, {}, {}, vue9.ComponentOptionsMixin, vue9.ComponentOptionsMixin, {}, string, vue9.PublicProps, Readonly<vue9.ExtractPropTypes<{
117
117
  itemKey: {
118
118
  type: StringConstructor;
119
119
  required: true;
120
120
  };
121
- }>> & Readonly<{}>, {}, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
121
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, vue9.ComponentProvideOptions, true, {}, any>;
122
122
  //#endregion
123
123
  //#region src/components/ContextStorage.vue.d.ts
124
124
  declare const _default: typeof __VLS_export$1;
125
- declare const __VLS_export$1: vue19.DefineComponent<vue19.ExtractPropTypes<{
125
+ declare const __VLS_export$1: vue9.DefineComponent<vue9.ExtractPropTypes<{
126
126
  handlers: {
127
127
  type: PropType<ContextStorageHandlerFactory[]>;
128
128
  default: () => ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
@@ -138,9 +138,9 @@ declare const __VLS_export$1: vue19.DefineComponent<vue19.ExtractPropTypes<{
138
138
  type: PropType<ContextStorageHandlerFactory[]>;
139
139
  default: undefined;
140
140
  };
141
- }>, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
141
+ }>, () => vue9.VNode<vue9.RendererNode, vue9.RendererElement, {
142
142
  [key: string]: any;
143
- }>[] | undefined, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<vue19.ExtractPropTypes<{
143
+ }>[] | undefined, {}, {}, {}, vue9.ComponentOptionsMixin, vue9.ComponentOptionsMixin, {}, string, vue9.PublicProps, Readonly<vue9.ExtractPropTypes<{
144
144
  handlers: {
145
145
  type: PropType<ContextStorageHandlerFactory[]>;
146
146
  default: () => ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
@@ -159,7 +159,7 @@ declare const __VLS_export$1: vue19.DefineComponent<vue19.ExtractPropTypes<{
159
159
  }>> & Readonly<{}>, {
160
160
  handlers: ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
161
161
  additionalHandlers: ContextStorageHandlerFactory<{}, RegisterOptions<{}>>[];
162
- }, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
162
+ }, {}, {}, {}, string, vue9.ComponentProvideOptions, true, {}, any>;
163
163
  //#endregion
164
164
  //#region src/prefix.d.ts
165
165
  /**
@@ -181,19 +181,19 @@ declare const contextStoragePrefixSegmentsInjectKey: InjectionKey<MaybeRefOrGett
181
181
  //#endregion
182
182
  //#region src/components/ContextStoragePrefix.vue.d.ts
183
183
  declare const _default$3: typeof __VLS_export;
184
- declare const __VLS_export: vue19.DefineComponent<vue19.ExtractPropTypes<{
184
+ declare const __VLS_export: vue9.DefineComponent<vue9.ExtractPropTypes<{
185
185
  name: {
186
186
  type: PropType<ContextStoragePrefixSegment>;
187
187
  required: true;
188
188
  };
189
- }>, () => vue19.VNode<vue19.RendererNode, vue19.RendererElement, {
189
+ }>, () => vue9.VNode<vue9.RendererNode, vue9.RendererElement, {
190
190
  [key: string]: any;
191
- }>, {}, {}, {}, vue19.ComponentOptionsMixin, vue19.ComponentOptionsMixin, {}, string, vue19.PublicProps, Readonly<vue19.ExtractPropTypes<{
191
+ }>, {}, {}, {}, vue9.ComponentOptionsMixin, vue9.ComponentOptionsMixin, {}, string, vue9.PublicProps, Readonly<vue9.ExtractPropTypes<{
192
192
  name: {
193
193
  type: PropType<ContextStoragePrefixSegment>;
194
194
  required: true;
195
195
  };
196
- }>> & Readonly<{}>, {}, {}, {}, {}, string, vue19.ComponentProvideOptions, true, {}, any>;
196
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, vue9.ComponentProvideOptions, true, {}, any>;
197
197
  //#endregion
198
198
  //#region src/plugin.d.ts
199
199
  declare const VueContextStoragePlugin: Plugin;
package/dist/zod.d.ts CHANGED
@@ -62,6 +62,64 @@ declare function zObjectArray<T extends z.ZodTypeAny>(itemSchema: T): z.ZodPipe<
62
62
  * ```
63
63
  */
64
64
  declare function zUrlBoolean(defaultValue?: boolean): z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>, z.ZodTransform<boolean, string | boolean>>>;
65
+ /**
66
+ * Creates a Zod schema for arrays of numbers serialized as URL query parameters.
67
+ *
68
+ * URL query parameters serialize arrays as repeated keys:
69
+ * `?users_ids=1&users_ids=2` → `['1', '2']` (array of strings)
70
+ *
71
+ * But when only one value is present:
72
+ * `?users_ids=1` → `'1'` (just a string, not an array)
73
+ *
74
+ * `z.coerce.number().array()` would fail with "expected array, received string"
75
+ * for the single-value case. This helper normalizes the input by wrapping
76
+ * a single value into an array before coercing each element to a number.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * import { z } from 'zod'
81
+ * import { zNumberArray } from 'vue-context-storage/zod'
82
+ *
83
+ * const Schema = z.object({
84
+ * users_ids: zNumberArray(),
85
+ * })
86
+ *
87
+ * // All of these work:
88
+ * Schema.parse({ users_ids: ['1', '2'] }) // → { users_ids: [1, 2] }
89
+ * Schema.parse({ users_ids: '1' }) // → { users_ids: [1] }
90
+ * Schema.parse({}) // → { users_ids: [] }
91
+ * ```
92
+ */
93
+ declare function zNumberArray(): z.ZodDefault<z.ZodUnion<readonly [z.ZodArray<z.ZodCoercedNumber<unknown>>, z.ZodPipe<z.ZodCoercedNumber<unknown>, z.ZodTransform<number[], number>>]>>;
94
+ /**
95
+ * Creates a Zod schema for arrays of strings serialized as URL query parameters.
96
+ *
97
+ * URL query parameters serialize arrays as repeated keys:
98
+ * `?tags=vue&tags=react` → `['vue', 'react']` (array of strings)
99
+ *
100
+ * But when only one value is present:
101
+ * `?tags=vue` → `'vue'` (just a string, not an array)
102
+ *
103
+ * `z.string().array()` would fail with "expected array, received string"
104
+ * for the single-value case. This helper normalizes the input by wrapping
105
+ * a single value into an array.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * import { z } from 'zod'
110
+ * import { zStringArray } from 'vue-context-storage/zod'
111
+ *
112
+ * const Schema = z.object({
113
+ * tags: zStringArray(),
114
+ * })
115
+ *
116
+ * // All of these work:
117
+ * Schema.parse({ tags: ['vue', 'react'] }) // → { tags: ['vue', 'react'] }
118
+ * Schema.parse({ tags: 'vue' }) // → { tags: ['vue'] }
119
+ * Schema.parse({}) // → { tags: [] }
120
+ * ```
121
+ */
122
+ declare function zStringArray(): z.ZodDefault<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>]>>;
65
123
  /**
66
124
  * Creates an object with empty values based on a Zod schema.
67
125
  * Useful for initializing forms.
@@ -78,4 +136,4 @@ declare function createEmptyObject<T extends ZodRawShape>(schema: ZodObject<T>,
78
136
  withSchema?: false;
79
137
  }): z.infer<ZodObject<T>>;
80
138
  //#endregion
81
- export { MaybeWithSchema, SCHEMA_SYMBOL, createEmptyObject, zObjectArray, zUrlBoolean };
139
+ export { MaybeWithSchema, SCHEMA_SYMBOL, createEmptyObject, zNumberArray, zObjectArray, zStringArray, zUrlBoolean };
package/dist/zod.js CHANGED
@@ -12,6 +12,12 @@ function zUrlBoolean(defaultValue = false) {
12
12
  return val === "1" || val === "true";
13
13
  }).default(defaultValue);
14
14
  }
15
+ function zNumberArray() {
16
+ return z.union([z.coerce.number().array(), z.coerce.number().transform((v) => [v])]).default([]);
17
+ }
18
+ function zStringArray() {
19
+ return z.union([z.string().array(), z.string().transform((v) => [v])]).default([]);
20
+ }
15
21
  function createEmptyObject(schema, options) {
16
22
  const shape = schema.shape;
17
23
  const result = {};
@@ -71,4 +77,4 @@ function createEmptyObject(schema, options) {
71
77
  }
72
78
 
73
79
  //#endregion
74
- export { SCHEMA_SYMBOL, createEmptyObject, zObjectArray, zUrlBoolean };
80
+ export { SCHEMA_SYMBOL, createEmptyObject, zNumberArray, zObjectArray, zStringArray, zUrlBoolean };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vue-context-storage",
3
3
  "type": "module",
4
- "version": "0.1.38",
4
+ "version": "0.1.39",
5
5
  "description": "Vue 3 context storage system with URL query synchronization support",
6
6
  "author": "",
7
7
  "license": "MIT",