diff --git a/bun.lockb b/bun.lockb index 74e015c..4e23eb8 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 414881e..cc31d6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@thilawyn/schemable-classes", - "version": "20231230.0.0", + "name": "@thilawyn/schemable-class", + "version": "1.0.0", "type": "module", "publishConfig": { "registry": "https://git.jvalver.de/api/packages/thilawyn/npm/" @@ -31,14 +31,13 @@ } }, "scripts": { - "build": "rollup -c", + "build": "rollup -c rollup.config.ts", "lint:tsc": "tsc --noEmit", "clean:cache": "rm -f tsconfig.tsbuildinfo", "clean:dist": "rm -rf dist", "clean:node": "rm -rf node_modules" }, "dependencies": { - "@thilawyn/thilatrait": "^20231230.0.0", "decimal.js": "^10.4.3", "effect": "^2.0.0-next.62", "lodash-es": "^4.17.21", @@ -46,6 +45,7 @@ "zod": "^3.22.4" }, "devDependencies": { + "@rollup/plugin-node-resolve": "^15.2.3", "@types/lodash-es": "^4.17.12", "bun-types": "latest", "npm-check-updates": "^16.14.12", diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index aa4dbe2..0000000 --- a/rollup.config.js +++ /dev/null @@ -1,38 +0,0 @@ -import { defineConfig } from "rollup" -import cleanup from "rollup-plugin-cleanup" -import ts from "rollup-plugin-ts" -import pkg from "./package.json" assert { type: "json" } - - -export default defineConfig({ - input: "src/index.ts", - - output: [ - { - file: pkg.exports["."].import.default, - format: "esm", - }, - { - file: pkg.exports["."].require.default, - format: "cjs", - }, - - { - file: pkg.exports["./jsonifiable"].import.default, - format: "esm", - }, - { - file: pkg.exports["./jsonifiable"].require.default, - format: "cjs", - }, - ], - - plugins: [ - ts(), - - cleanup({ - comments: "jsdoc", - extensions: ["ts"], - }), - ], -}) diff --git a/rollup.config.ts b/rollup.config.ts new file mode 100644 index 0000000..8625946 --- /dev/null +++ b/rollup.config.ts @@ -0,0 +1,43 @@ +import { nodeResolve } from "@rollup/plugin-node-resolve" +import { defineConfig } from "rollup" +import cleanup from "rollup-plugin-cleanup" +import ts from "rollup-plugin-ts" +import pkg from "./package.json" assert { type: "json" } + + +export const createBundleConfig = ( + input: string, + name: keyof typeof pkg.exports, +) => + defineConfig({ + input, + + output: [ + { + file: pkg.exports[name].import.default, + format: "esm", + }, + { + file: pkg.exports[name].require.default, + format: "cjs", + }, + ], + + external: id => !/^[./]/.test(id), + + plugins: [ + nodeResolve(), + ts(), + + cleanup({ + comments: "jsdoc", + extensions: ["ts"], + }), + ], + }) + + +export default [ + createBundleConfig("src/index.ts", "."), + createBundleConfig("src/jsonifiable/index.ts", "./jsonifiable"), +] diff --git a/src/newSchemable.ts b/src/newSchemable.ts index 955d0f3..da0be36 100644 --- a/src/newSchemable.ts +++ b/src/newSchemable.ts @@ -13,6 +13,14 @@ type NewSchemableArgs = : [] | [Input, ...ParamsArgs] +/** + * Creates a new instance of a SchemableClass with default values. + * + * @param class_ - The SchemableClass. + * @param values - The values to be parsed and used to create the instance. + * @param params - Optional parameters for parsing. + * @returns A new instance of the specified SchemableClass. + */ export const newSchemable = < C extends SchemableClass<$Config>, $Config extends SchemableConfig, @@ -22,6 +30,15 @@ export const newSchemable = < ) => new class_(class_.schemaWithDefaultValues.parse(values || {}, params)) as InstanceType + +/** + * Creates a new instance of a SchemableClass with default values asynchronously. + * + * @param class_ - The SchemableClass. + * @param values - The values to be parsed and used to create the instance. + * @param params - Optional parameters for parsing. + * @returns A Promise resolving to a new instance of the specified SchemableClass. + */ export const newSchemablePromise = async < C extends SchemableClass<$Config>, $Config extends SchemableConfig, @@ -31,6 +48,15 @@ export const newSchemablePromise = async < ) => new class_(await class_.schemaWithDefaultValues.parseAsync(values || {}, params)) as InstanceType + +/** + * Creates a new instance of a SchemableClass with default values as an Effect. + * + * @param class_ - The SchemableClass. + * @param values - The values to be parsed and used to create the instance. + * @param params - Optional parameters for parsing. + * @returns An Effect producing a new instance of the specified SchemableClass. + */ export const newSchemableEffect = < C extends SchemableClass<$Config>, $Config extends SchemableConfig,