@idb-orm/zod-adapter 0.0.4 → 0.1.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/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"),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(o){const s=t(o instanceof r.ZodDefault?o.unwrap():o);return new e.core.Property(n.custom({isType:e=>o.safeParse(e).success,parse:e=>o.parse(e),serialize:s,deserialize:s}))}exports.zodModel=function(n,t){const s={};for(const e in t){if(!Object.hasOwn(t,e))continue;const n=t[e];n instanceof r.ZodType?s[e]=o(n):s[e]=n}return new e.Model(n,s)};
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 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 a=o(n instanceof r.ZodDefault?n.unwrap():n);return new e.Property(t.custom({isType:e=>n.safeParse(e).success,parse:e=>n.parse(e),serialize:a,deserialize:a}))}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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idb-orm/zod-adapter",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "description": "An adapter for the Zod validation library for @idb-orm",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {