From 5a33b34bd4d39207b51b25a65be7489e44f9c7cd Mon Sep 17 00:00:00 2001 From: Peramanathan Sathyamoorthy Date: Mon, 11 Nov 2024 16:10:59 +0100 Subject: [PATCH] Add missing root export for @adaptate/core --- packages/core/package.json | 13 +++-- packages/core/src/mutate-model.ts | 89 ------------------------------- packages/core/vite.config.js | 2 +- pnpm-lock.yaml | 7 ++- vitest.config.ts | 1 - 5 files changed, 12 insertions(+), 100 deletions(-) delete mode 100644 packages/core/src/mutate-model.ts diff --git a/packages/core/package.json b/packages/core/package.json index 6c94660..a31384d 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@adaptate/core", - "version": "0.1.0-beta", + "version": "0.1.0-beta.1", "author": { "name": "Peramanathan Sathyamoorthy", "url": "https://github.com/p10ns11y/adaptate.git" @@ -22,12 +22,10 @@ "build": "vite build", "check-types": "tsc --noEmit" }, - "dependencies": { - "zod": "^3.23.8" - }, "devDependencies": { "@adaptate/utils": "workspace:*", - "vite": "^5.4.10" + "vite": "^5.4.10", + "zod": "^3.23.8" }, "peerDependencies": { "zod": "^3.23.8" @@ -38,6 +36,11 @@ "README.md" ], "exports": { + ".": { + "types": "./src/index.d.ts", + "import": "./build/index.es.js", + "default": "./build/index.es.js" + }, "./*": { "types": "./src/*.ts", "default": "./build/*.es.js" diff --git a/packages/core/src/mutate-model.ts b/packages/core/src/mutate-model.ts deleted file mode 100644 index 1d1cfc0..0000000 --- a/packages/core/src/mutate-model.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { ZodSchema, ZodObject, ZodArray, ZodTypeAny } from 'zod'; - -type Config = { - requiredProperties: Record; -}; - -/** - * Check the given Zod schema and unwrap the properties that are required. - * @param schema - The Zod schema to check. - * @param config - The configuration object. - * @throws If the given schema is not a Zod object. - * @example - * const schema = z.object({ - * name: z.string().optional(), - * age: z.number().optional(), - * address: z.object({ - * street: z.string().optional(), - * city: z.string().optional(), - * }).optional(), - * }); - * - * const config = { - * requiredProperties: { - * name: true, - * 'address.city': true, - * }, - * }; - * - * checkModel(schema, config); - * - * const validData = { - * name: 'John Doe', - * address: { city: 'New York' }, - * }; - * - * const invalidDataMissingName = { - * address: { city: 'New York' }, - * }; - * - * const invalidDataMissingCity = { - * name: 'John Doe', - * address: {}, - * }; - * - * schema.parse(validData); // Should pass - * schema.parse(invalidDataMissingName); // Should fail due to missing 'name' - * schema.parse(invalidDataMissingCity); // Should fail due to missing 'address.city' - * @category Helper - * @module mutateModel - */ -function mutateModel(schema: ZodSchema, config: Config) { - const { requiredProperties } = config; - - const checkProperties = (object: ZodObject, path: string = '') => { - const shape = object.shape; - - for (const key in shape) { - const currentPath = path ? `${path}.${key}` : key; - - if (requiredProperties[currentPath]) { - shape[key] = shape[key].unwrap(); - } - - const keyShape = shape[key]?.isOptional?.() - ? shape[key].unwrap() - : shape[key]; - - // Recursively check nested structures - if (keyShape instanceof ZodObject) { - checkProperties(keyShape as ZodObject, currentPath); - } else if (keyShape instanceof ZodArray) { - // Handle list elements if it's an array - // Assuming we use a Zod array type here - const element = keyShape.element as ZodTypeAny; - if (element instanceof ZodObject) { - checkProperties(element as ZodObject, currentPath); - } - } - } - }; - - if (schema instanceof ZodObject) { - return checkProperties(schema); - } else { - console.error('The given schema must be a Zod object.'); - } -} - -export { mutateModel }; diff --git a/packages/core/vite.config.js b/packages/core/vite.config.js index 93ddc5c..8627ede 100644 --- a/packages/core/vite.config.js +++ b/packages/core/vite.config.js @@ -7,7 +7,7 @@ export default defineConfig({ outDir: 'build', sourcemap: true, lib: { - entry: ['src/index.ts', 'src/mutate-model.ts'], + entry: ['src/index.ts'], formats: ['es'], fileName: (format, entryName) => `${entryName}.${format}.js`, types: 'src/index.d.ts', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c2631ca..318dfd8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,10 +31,6 @@ importers: version: 2.1.4(@types/node@22.9.0) packages/core: - dependencies: - zod: - specifier: ^3.23.8 - version: 3.23.8 devDependencies: '@adaptate/utils': specifier: workspace:* @@ -42,6 +38,9 @@ importers: vite: specifier: ^5.4.10 version: 5.4.10(@types/node@22.9.0) + zod: + specifier: ^3.23.8 + version: 3.23.8 packages/utils: dependencies: diff --git a/vitest.config.ts b/vitest.config.ts index a952d2a..d42db6e 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -12,7 +12,6 @@ export default defineConfig({ 'build', 'test', 'packages/**/*.test.ts', - 'packages/core/src/mutate-model.ts', // export only no source code 'packages/utils/src/index.ts', ],