@idb-orm/zod-adapter 0.0.5 → 0.1.1

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.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@idb-orm/core"),r=require("zod"),n=e.core.Type;function t(r){switch(r.type){case"array":return n.Array(t(r.element));case"bigint":return n.BigInt();case"number":return n.Number();case"string":return n.String();case"boolean":return n.Boolean();case"date":return n.Date();case"file":return n.File();case"symbol":return n.Symbol();case"literal":return e.core.Property.nameToType(typeof Array.from(r.values)[0]);case"optional":return n.Optional(t(r.unwrap()));case"set":return n.Set(t(r._zod.def.valueType));case"enum":return n.Union(r.options.map(e=>n.Literal(e)));case"union":return n.Union(r.options.map(e=>t(e)));case"object":{const e={};for(const n in r.shape)Object.hasOwn(r.shape,n)&&(e[n]=t(r.shape[n]));return n.Object(e)}default:return n.Unknown()}}function o(n){const a=n;return new e.core.Property(t(n)),n instanceof r.ZodDefault?o(a.unwrap()):new e.core.Property(t(n))}exports.zodModel=function(n,t){const a={};for(const e in t){if(!Object.hasOwn(t,e))continue;const n=t[e];n instanceof r.ZodType?a[e]=o(n):a[e]=n}return new e.Model(n,a)};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@idb-orm/core"),n=require("zod"),r=e.core.Type;function t(n){switch(n.type){case"array":return r.array(t(n.element));case"bigint":return r.bigint();case"number":return r.number();case"string":return r.string();case"boolean":return r.boolean();case"date":return r.date();case"file":return r.file();case"undefined":return r.undefined();case"null":return r.null();case"literal":return e.core.Property.nameToType(typeof Array.from(n.values)[0]);case"optional":return r.optional(t(n.unwrap()));case"set":return r.set(t(n._zod.def.valueType));case"enum":return r.union(n.options.map(e=>r.literal(e)));case"union":return r.union(n.options.map(e=>t(e)));case"object":{const e={};for(const r in n.shape)Object.hasOwn(n.shape,r)&&(e[r]=t(n.shape[r]));return r.object(e)}default:return r.unknown()}}function o(o){const a=t(o instanceof n.ZodDefault?o.unwrap():o),s=new e.core.Property(r.custom({isType:e=>o.safeParse(e).success,parse:e=>o.parse(e),serialize:a,deserialize:a}));return o instanceof n.ZodDefault&&s.default(o.def.defaultValue),s}exports.zodModel=function(r,t){const a={};for(const e in t){if(!Object.hasOwn(t,e))continue;const r=t[e];r instanceof n.ZodType?a[e]=o(r):a[e]=r}return new e.Model(r,a)};
package/dist/index.es.js CHANGED
@@ -1 +1 @@
1
- import{core as e,Model as n}from"@idb-orm/core";import r from"zod";const t=e.Type;function o(n){switch(n.type){case"array":return t.Array(o(n.element));case"bigint":return t.BigInt();case"number":return t.Number();case"string":return t.String();case"boolean":return t.Boolean();case"date":return t.Date();case"file":return t.File();case"symbol":return t.Symbol();case"literal":return e.Property.nameToType(typeof Array.from(n.values)[0]);case"optional":return t.Optional(o(n.unwrap()));case"set":return t.Set(o(n._zod.def.valueType));case"enum":return t.Union(n.options.map(e=>t.Literal(e)));case"union":return t.Union(n.options.map(e=>o(e)));case"object":{const e={};for(const r in n.shape)Object.hasOwn(n.shape,r)&&(e[r]=o(n.shape[r]));return t.Object(e)}default:return t.Unknown()}}function a(n){const t=n;return new e.Property(o(n)),n instanceof r.ZodDefault?a(t.unwrap()):new e.Property(o(n))}function s(e,t){const o={};for(const n in t){if(!Object.hasOwn(t,n))continue;const e=t[n];e instanceof r.ZodType?o[n]=a(e):o[n]=e}return new n(e,o)}export{s as zodModel};
1
+ import{core as e,Model as n}from"@idb-orm/core";import r from"zod";const t=e.Type;function a(n){switch(n.type){case"array":return t.array(a(n.element));case"bigint":return t.bigint();case"number":return t.number();case"string":return t.string();case"boolean":return t.boolean();case"date":return t.date();case"file":return t.file();case"undefined":return t.undefined();case"null":return t.null();case"literal":return e.Property.nameToType(typeof Array.from(n.values)[0]);case"optional":return t.optional(a(n.unwrap()));case"set":return t.set(a(n._zod.def.valueType));case"enum":return t.union(n.options.map(e=>t.literal(e)));case"union":return t.union(n.options.map(e=>a(e)));case"object":{const e={};for(const r in n.shape)Object.hasOwn(n.shape,r)&&(e[r]=a(n.shape[r]));return t.object(e)}default:return t.unknown()}}function o(n){const o=a(n instanceof r.ZodDefault?n.unwrap():n),s=new e.Property(t.custom({isType:e=>n.safeParse(e).success,parse:e=>n.parse(e),serialize:o,deserialize:o}));return n instanceof r.ZodDefault&&s.default(n.def.defaultValue),s}function s(e,t){const a={};for(const n in t){if(!Object.hasOwn(t,n))continue;const e=t[n];e instanceof r.ZodType?a[n]=o(e):a[n]=e}return new n(e,a)}export{s as zodModel};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idb-orm/zod-adapter",
3
- "version": "0.0.5",
3
+ "version": "0.1.1",
4
4
  "description": "An adapter for the Zod validation library for @idb-orm",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -24,7 +24,7 @@
24
24
  "author": "jtb",
25
25
  "license": "ISC",
26
26
  "peerDependencies": {
27
- "@idb-orm/core": "^1.0.7",
27
+ "@idb-orm/core": "^1.2.0",
28
28
  "zod": "^4.1.12"
29
29
  },
30
30
  "devDependencies": {