@pitininja/envious-yup 6.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/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Envious Yup resolver
2
+
3
+ [![npm version](https://badge.fury.io/js/@pitininja%2Fenvious-yup.svg)](https://badge.fury.io/js/@pitininja%2Fenvious-yup)
4
+
5
+ - [Install](#install)
6
+ - [Usage](#usage)
7
+
8
+ ## Install
9
+
10
+ ```shell
11
+ npm i @pitininja/envious-yup
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ See the [official Yup documentation](https://github.com/jquense/yup) for how to write the schema.
17
+
18
+ ```typescript
19
+ import { envious } from '@pitininja/envious';
20
+ import { yupResolver } from '@pitininja/envious-yup';
21
+ import * as yup from 'yup';
22
+
23
+ const env = envious({
24
+ resolver: yupResolver({
25
+ schema: yup.object({
26
+ STRING_VAR: yup.string().required(),
27
+ NUMBER_VAR: yup.number().required().integer(),
28
+ BOOLEAN_VAR_WITH_DEFAULT: yup.boolean().default(true),
29
+ OPTIONAL_VAR: yup.string().optional()
30
+ })
31
+ })
32
+ });
33
+ ```
@@ -0,0 +1,7 @@
1
+ import { type AnyObject, type InferType, type ObjectSchema, type Schema } from 'yup';
2
+ type EnviousYupResolver<T extends Schema> = (env: NodeJS.ProcessEnv) => InferType<T>;
3
+ export type EnviousYupResolverOptions<T extends ObjectSchema<AnyObject>> = {
4
+ schema: T;
5
+ };
6
+ export declare const yupResolver: <T extends ObjectSchema<AnyObject, AnyObject, any, "">>({ schema }: EnviousYupResolverOptions<T>) => EnviousYupResolver<T>;
7
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.yupResolver = void 0;
4
+ const envious_1 = require("@pitininja/envious");
5
+ const yup_1 = require("yup");
6
+ const transformYupValidationError = (yupError) => {
7
+ const { path, message } = yupError;
8
+ return {
9
+ name: path ?? '',
10
+ message
11
+ };
12
+ };
13
+ const yupResolver = ({ schema }) => {
14
+ return (env) => {
15
+ try {
16
+ return schema.validateSync(env, {
17
+ strict: false,
18
+ stripUnknown: true,
19
+ abortEarly: false
20
+ });
21
+ }
22
+ catch (err) {
23
+ if (err instanceof yup_1.ValidationError) {
24
+ throw new envious_1.EnviousError({
25
+ resolverErrors: err.inner,
26
+ transform: transformYupValidationError
27
+ });
28
+ }
29
+ throw err;
30
+ }
31
+ };
32
+ };
33
+ exports.yupResolver = yupResolver;
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,gDAAkD;AAClD,6BAMa;AAUb,MAAM,2BAA2B,GAAG,CAAC,QAAyB,EAAE,EAAE,CAAC;IAC/D,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IACnC,OAAO;QACH,IAAI,EAAE,IAAI,IAAI,EAAE;QAChB,OAAO;KACV,CAAC;AAAA,CACL,CAAC;AAEK,MAAM,WAAW,GAAG,CAAoC,EAC3D,MAAM,EACqB,EAAyB,EAAE,CAAC;IACvD,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;QACZ,IAAI,CAAC;YACD,OAAO,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE;gBAC5B,MAAM,EAAE,KAAK;gBACb,YAAY,EAAE,IAAI;gBAClB,UAAU,EAAE,KAAK;aACpB,CAAC,CAAC;QACP,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,IAAI,GAAG,YAAY,qBAAe,EAAE,CAAC;gBACjC,MAAM,IAAI,sBAAY,CAAC;oBACnB,cAAc,EAAE,GAAG,CAAC,KAAK;oBACzB,SAAS,EAAE,2BAA2B;iBACzC,CAAC,CAAC;YACP,CAAC;YACD,MAAM,GAAG,CAAC;QACd,CAAC;IAAA,CACJ,CAAC;AAAA,CACL,CAAC;AApBW,QAAA,WAAW,GAAX,WAAW,CAoBtB"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@pitininja/envious-yup",
3
+ "version": "6.1.0",
4
+ "license": "AGPL-3.0-or-later",
5
+ "homepage": "https://codeberg.org/pitininja/envious",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://codeberg.org/pitininja/envious"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "files": [
14
+ "./dist",
15
+ "./package.json",
16
+ "./README.md"
17
+ ],
18
+ "main": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "scripts": {
21
+ "build": "npx tsgo --build --clean ./tsconfig.build.json && npx tsgo -b ./tsconfig.build.json"
22
+ },
23
+ "dependencies": {
24
+ "@pitininja/envious": "^6.0.0",
25
+ "yup": "^1.7.1"
26
+ }
27
+ }