vue-context-storage 0.1.41 → 0.1.42

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.
Files changed (3) hide show
  1. package/README.md +963 -900
  2. package/dist/index.js +84 -3
  3. package/package.json +14 -6
package/dist/index.js CHANGED
@@ -130,6 +130,78 @@ function unwrapZodField(field) {
130
130
  }
131
131
  return t;
132
132
  }
133
+ function readZodFieldMeta(field) {
134
+ let t = field;
135
+ while (true) {
136
+ const m = typeof t?.meta === "function" ? t.meta() : void 0;
137
+ if (m !== void 0) return m;
138
+ const type = zodDefType(t);
139
+ if (type === "default" || type === "optional" || type === "nullable") t = t.unwrap();
140
+ else break;
141
+ }
142
+ }
143
+ function extractAdditionalDefaultDataFromSchema(schema) {
144
+ const shape = schema?.shape;
145
+ if (!shape || typeof shape !== "object") return void 0;
146
+ let result;
147
+ for (const key of Object.keys(shape)) {
148
+ const meta = readZodFieldMeta(shape[key]);
149
+ if (meta && "additionalDefaultData" in meta) {
150
+ if (!result) result = {};
151
+ result[key] = meta.additionalDefaultData;
152
+ } else {
153
+ const base = unwrapZodField(shape[key]);
154
+ if (zodDefType(base) === "object" && base.shape) {
155
+ const nested = extractAdditionalDefaultDataFromSchema(base);
156
+ if (nested) {
157
+ if (!result) result = {};
158
+ result[key] = nested;
159
+ }
160
+ }
161
+ }
162
+ }
163
+ return result;
164
+ }
165
+ function readZodFieldDefault(field) {
166
+ let t = field;
167
+ while (true) {
168
+ const type = zodDefType(t);
169
+ if (type === "default") return {
170
+ hasDefault: true,
171
+ value: t._zod.def.defaultValue
172
+ };
173
+ if (type === "optional" || type === "nullable") t = t.unwrap();
174
+ else break;
175
+ }
176
+ return { hasDefault: false };
177
+ }
178
+ function extractDefaultsFromSchema(schema) {
179
+ const shape = schema?.shape;
180
+ if (!shape || typeof shape !== "object") return void 0;
181
+ let result;
182
+ for (const key of Object.keys(shape)) {
183
+ const base = unwrapZodField(shape[key]);
184
+ if (zodDefType(base) === "object" && base.shape) {
185
+ const { hasDefault: hasDefault2, value: objectDefault } = readZodFieldDefault(shape[key]);
186
+ const nested = extractDefaultsFromSchema(base);
187
+ let combined;
188
+ if (hasDefault2 && nested) combined = merge({}, objectDefault, nested);
189
+ else if (hasDefault2) combined = objectDefault;
190
+ else combined = nested;
191
+ if (combined !== void 0) {
192
+ if (!result) result = {};
193
+ result[key] = combined;
194
+ }
195
+ continue;
196
+ }
197
+ const { hasDefault, value } = readZodFieldDefault(shape[key]);
198
+ if (hasDefault) {
199
+ if (!result) result = {};
200
+ result[key] = value;
201
+ }
202
+ }
203
+ return result;
204
+ }
133
205
  function coerceDataForSchema(data, schema) {
134
206
  const shape = schema?.shape;
135
207
  if (!shape || typeof shape !== "object") return data;
@@ -258,7 +330,7 @@ function buildQuery(input) {
258
330
  warnings.push("[vue-context-storage] preserveEmptyState is not supported with onlyChanges");
259
331
  }
260
332
  Object.keys(patch).forEach((key2) => {
261
- if (isEqual(patch[key2], item.initialQueryData[key2]) || item.additionalDefaultQueryData && isEqual(patch[key2], item.additionalDefaultQueryData[key2])) delete patch[key2];
333
+ if (isEqual(patch[key2], item.initialQueryData[key2]) || item.additionalDefaultQueryData && isEqual(patch[key2], item.additionalDefaultQueryData[key2]) || item.schemaMetaDefaultQueryData && isEqual(patch[key2], item.schemaMetaDefaultQueryData[key2]) || item.schemaDefaultQueryData && isEqual(patch[key2], item.schemaDefaultQueryData[key2])) delete patch[key2];
262
334
  });
263
335
  }
264
336
  const patchKeys = Object.keys(patch);
@@ -457,11 +529,18 @@ function createQueryHandler(baseOptions) {
457
529
  scheduleSyncToQuery();
458
530
  }, { deep: true });
459
531
  const initialData = cloneDeep(resolvedData);
532
+ const initialQueryData = serializeParams(initialData, { key: registerOptions.key });
533
+ const additionalDefaultQueryData = registerOptions.additionalDefaultData ? serializeParams(registerOptions.additionalDefaultData, { key: registerOptions.key }) : void 0;
534
+ const schemaMetaDefaults = registerOptions.schema ? extractAdditionalDefaultDataFromSchema(registerOptions.schema) : void 0;
535
+ const schemaMetaDefaultQueryData = schemaMetaDefaults ? serializeParams(schemaMetaDefaults, { key: registerOptions.key }) : void 0;
536
+ const schemaDefaults = registerOptions.schema ? extractDefaultsFromSchema(registerOptions.schema) : void 0;
460
537
  const item = {
461
538
  data,
462
539
  initialData,
463
- initialQueryData: serializeParams(initialData, { key: registerOptions.key }),
464
- additionalDefaultQueryData: registerOptions.additionalDefaultData ? serializeParams(registerOptions.additionalDefaultData, { key: registerOptions.key }) : void 0,
540
+ initialQueryData,
541
+ additionalDefaultQueryData,
542
+ schemaMetaDefaultQueryData,
543
+ schemaDefaultQueryData: schemaDefaults ? serializeParams(schemaDefaults, { key: registerOptions.key }) : void 0,
465
544
  options: registerOptions,
466
545
  watchHandle
467
546
  };
@@ -501,6 +580,8 @@ function createQueryHandler(baseOptions) {
501
580
  data: toValue(item.data),
502
581
  initialQueryData: item.initialQueryData,
503
582
  additionalDefaultQueryData: item.additionalDefaultQueryData,
583
+ schemaMetaDefaultQueryData: item.schemaMetaDefaultQueryData,
584
+ schemaDefaultQueryData: item.schemaDefaultQueryData,
504
585
  key: item.options?.key,
505
586
  onlyChanges: item.options?.onlyChanges,
506
587
  preserveEmptyState: item.options?.preserveEmptyState,
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "vue-context-storage",
3
3
  "type": "module",
4
- "version": "0.1.41",
5
- "description": "Vue 3 context storage system with URL query synchronization support",
4
+ "version": "0.1.42",
5
+ "description": "Vue 3 reactive state management — sync state with the URL query, localStorage, and sessionStorage",
6
6
  "author": "",
7
7
  "license": "MIT",
8
8
  "homepage": "https://github.com/lviobio/vue-context-storage#readme",
@@ -32,16 +32,23 @@
32
32
  "dev": "tsdown --watch",
33
33
  "check": "npm run ts:check && npm run lint:check && npm run format:check && npm run dependency-cruiser:check",
34
34
  "ts:check": "vue-tsc --noEmit",
35
- "format": "prettier --write src/ playground/src",
36
- "format:check": "prettier --check src/ playground/src",
35
+ "format": "prettier --write src/ playground/src playground-e2e/src",
36
+ "format:check": "prettier --check src/ playground/src playground-e2e/src",
37
37
  "lint": "eslint . --fix",
38
38
  "lint:check": "eslint .",
39
39
  "dependency-cruiser:check": "depcruise --config .dependency-cruiser.cjs src playground/src",
40
40
  "play": "vite",
41
+ "play:e2e": "vite --config vite.e2e.config.ts",
41
42
  "build:playground": "vite build",
42
43
  "preview:playground": "vite preview --outDir playground/dist",
43
- "test": "vitest run",
44
- "release": "bumpp && npm publish",
44
+ "test": "npm run test:unit && npm run test:e2e",
45
+ "test:unit": "vitest run",
46
+ "test:e2e": "playwright test",
47
+ "test:e2e:ui": "playwright test --ui",
48
+ "test:e2e:headed": "playwright test --headed",
49
+ "test:e2e:debug": "playwright test --debug",
50
+ "test:e2e:report": "playwright show-report",
51
+ "release": "npm run check && npm run test && bumpp && npm publish",
45
52
  "prepublishOnly": "npm run check && npm run test && npm run build"
46
53
  },
47
54
  "peerDependencies": {
@@ -55,6 +62,7 @@
55
62
  }
56
63
  },
57
64
  "devDependencies": {
65
+ "@playwright/test": "^1.60.0",
58
66
  "@tailwindcss/vite": "^4.1.18",
59
67
  "@types/lodash": "^4.17.21",
60
68
  "@types/node": "^25.0.3",