@pitininja/envious 3.0.0-beta → 3.0.0-beta.2

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.
@@ -0,0 +1,3 @@
1
+ import 'dotenv/config';
2
+ import { type TObject, type Static } from '@sinclair/typebox';
3
+ export declare const envious: <T extends TObject<import("@sinclair/typebox").TProperties>>(schema: T, defaultValues?: Static<T>) => Static<T>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.envious = void 0;
7
+ require("dotenv/config");
8
+ const value_1 = require("@sinclair/typebox/value");
9
+ const os_1 = __importDefault(require("os"));
10
+ const envious = (schema, defaultValues) => {
11
+ const parsed = value_1.Value.Convert(schema, process.env);
12
+ const errors = [...value_1.Value.Errors(schema, parsed)];
13
+ if (errors.length) {
14
+ const computedErrorMessages = {};
15
+ errors.forEach(({ path, message }) => {
16
+ const envVarName = path.replace(/^\//, '');
17
+ if (!computedErrorMessages[envVarName]) {
18
+ computedErrorMessages[envVarName] = [];
19
+ }
20
+ computedErrorMessages[envVarName].push(message);
21
+ });
22
+ const errorTextParts = [
23
+ 'Invalid environment variables',
24
+ ...Object.entries(computedErrorMessages).map(([varName, messages]) => ` ${varName} : ${messages.join(', ')}`)
25
+ ];
26
+ throw new Error(errorTextParts.join(os_1.default.EOL));
27
+ }
28
+ const env = value_1.Value.Cast({
29
+ ...schema,
30
+ additionalProperties: false
31
+ }, parsed);
32
+ return {
33
+ ...defaultValues,
34
+ ...env
35
+ };
36
+ };
37
+ exports.envious = envious;
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,yBAAuB;AAEvB,mDAAgD;AAChD,4CAAoB;AAEb,MAAM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AAA,OAAO,WAkClB"}
@@ -0,0 +1,3 @@
1
+ import 'dotenv/config';
2
+ import { type TObject, type Static } from '@sinclair/typebox';
3
+ export declare const envious: <T extends TObject<import("@sinclair/typebox").TProperties>>(schema: T, defaultValues?: Static<T>) => Static<T>;
@@ -0,0 +1,31 @@
1
+ import 'dotenv/config';
2
+ import { Value } from '@sinclair/typebox/value';
3
+ import Os from 'os';
4
+ export const envious = (schema, defaultValues) => {
5
+ const parsed = Value.Convert(schema, process.env);
6
+ const errors = [...Value.Errors(schema, parsed)];
7
+ if (errors.length) {
8
+ const computedErrorMessages = {};
9
+ errors.forEach(({ path, message }) => {
10
+ const envVarName = path.replace(/^\//, '');
11
+ if (!computedErrorMessages[envVarName]) {
12
+ computedErrorMessages[envVarName] = [];
13
+ }
14
+ computedErrorMessages[envVarName].push(message);
15
+ });
16
+ const errorTextParts = [
17
+ 'Invalid environment variables',
18
+ ...Object.entries(computedErrorMessages).map(([varName, messages]) => ` ${varName} : ${messages.join(', ')}`)
19
+ ];
20
+ throw new Error(errorTextParts.join(Os.EOL));
21
+ }
22
+ const env = Value.Cast({
23
+ ...schema,
24
+ additionalProperties: false
25
+ }, parsed);
26
+ return {
27
+ ...defaultValues,
28
+ ...env
29
+ };
30
+ };
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,CAAC,MAAM,OAAO,GAAG,CACnB,MAAS,EACT,aAAyB,EAChB,EAAE;IACX,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAChB,MAAM,qBAAqB,GAA6B,EAAE,CAAC;QAC3D,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;YACjC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC3C,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,EAAE,CAAC;gBACrC,qBAAqB,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;YAC3C,CAAC;YACD,qBAAqB,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QACH,MAAM,cAAc,GAAa;YAC7B,+BAA+B;YAC/B,GAAG,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,GAAG,CACxC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,KAAK,OAAO,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACnE;SACJ,CAAC;QACF,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAClB;QACI,GAAG,MAAM;QACT,oBAAoB,EAAE,KAAK;KAC9B,EACD,MAAM,CACT,CAAC;IACF,OAAO;QACH,GAAG,aAAa;QAChB,GAAG,GAAG;KACT,CAAC;AACN,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import 'dotenv/config';
2
+ import { type TObject, type Static } from '@sinclair/typebox';
3
+ export declare const envious: <T extends TObject<import("@sinclair/typebox").TProperties>>(schema: T, defaultValues?: Static<T>) => Static<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pitininja/envious",
3
- "version": "3.0.0-beta",
3
+ "version": "3.0.0-beta.2",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "homepage": "https://github.com/pitininja/envious",
6
6
  "repository": {
@@ -16,14 +16,18 @@
16
16
  "./README.md"
17
17
  ],
18
18
  "exports": {
19
- "default": "./dist/index.js",
20
- "import": "./dist/index.js",
21
- "require": "./dist/index.cjs",
22
- "types": "./dist/index.d.ts"
19
+ ".": {
20
+ "types": "./dist/types/index.d.ts",
21
+ "require": "./dist/cjs/index.js",
22
+ "import": "./dist/esm/index.js",
23
+ "default": "./dist/esm/index.js"
24
+ }
23
25
  },
24
26
  "scripts": {
25
27
  "prepare": "[ -d '.husky' ] && husky || true",
26
- "build": "tsup",
28
+ "build": "npm run build:clean && npm run build:package",
29
+ "build:clean": "tsc --build --clean tsconfig.json && tsc --build --clean tsconfig.cjs.json && tsc --build --clean tsconfig.types.json",
30
+ "build:package": "tsc -b ./tsconfig.json ./tsconfig.cjs.json ./tsconfig.types.json",
27
31
  "lint": "npx eslint . --ext=.js,.ts --max-warnings=0 && npx prettier --check . && npx tsc --noEmit",
28
32
  "format": "npx eslint . --fix --ext=.js,.ts --max-warnings=0 && npx prettier --write . && npx tsc --noEmit"
29
33
  },
package/dist/index.cjs DELETED
@@ -1,75 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- envious: () => envious
34
- });
35
- module.exports = __toCommonJS(src_exports);
36
- var import_config = require("dotenv/config");
37
- var import_value = require("@sinclair/typebox/value");
38
- var import_os = __toESM(require("os"), 1);
39
- var envious = (schema, defaultValues) => {
40
- const parsed = import_value.Value.Convert(schema, process.env);
41
- const errors = [...import_value.Value.Errors(schema, parsed)];
42
- if (errors.length) {
43
- const computedErrorMessages = {};
44
- errors.forEach(({ path, message }) => {
45
- const envVarName = path.replace(/^\//, "");
46
- if (!computedErrorMessages[envVarName]) {
47
- computedErrorMessages[envVarName] = [];
48
- }
49
- computedErrorMessages[envVarName].push(message);
50
- });
51
- const errorTextParts = [
52
- "Invalid environment variables",
53
- ...Object.entries(computedErrorMessages).map(
54
- ([varName, messages]) => ` ${varName} : ${messages.join(", ")}`
55
- )
56
- ];
57
- throw new Error(errorTextParts.join(import_os.default.EOL));
58
- }
59
- const env = import_value.Value.Cast(
60
- {
61
- ...schema,
62
- additionalProperties: false
63
- },
64
- parsed
65
- );
66
- return {
67
- ...defaultValues,
68
- ...env
69
- };
70
- };
71
- // Annotate the CommonJS export names for ESM import in node:
72
- 0 && (module.exports = {
73
- envious
74
- });
75
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import 'dotenv/config';\nimport { type TObject, type Static } from '@sinclair/typebox';\nimport { Value } from '@sinclair/typebox/value';\nimport Os from 'os';\n\nexport const envious = <T extends TObject>(\n schema: T,\n defaultValues?: Static<T>\n): Static<T> => {\n const parsed = Value.Convert(schema, process.env);\n const errors = [...Value.Errors(schema, parsed)];\n if (errors.length) {\n const computedErrorMessages: Record<string, string[]> = {};\n errors.forEach(({ path, message }) => {\n const envVarName = path.replace(/^\\//, '');\n if (!computedErrorMessages[envVarName]) {\n computedErrorMessages[envVarName] = [];\n }\n computedErrorMessages[envVarName].push(message);\n });\n const errorTextParts: string[] = [\n 'Invalid environment variables',\n ...Object.entries(computedErrorMessages).map(\n ([varName, messages]) => ` ${varName} : ${messages.join(', ')}`\n )\n ];\n throw new Error(errorTextParts.join(Os.EOL));\n }\n const env = Value.Cast(\n {\n ...schema,\n additionalProperties: false\n },\n parsed\n );\n return {\n ...defaultValues,\n ...env\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAO;AAEP,mBAAsB;AACtB,gBAAe;AAER,IAAM,UAAU,CACnB,QACA,kBACY;AACZ,QAAM,SAAS,mBAAM,QAAQ,QAAQ,QAAQ,GAAG;AAChD,QAAM,SAAS,CAAC,GAAG,mBAAM,OAAO,QAAQ,MAAM,CAAC;AAC/C,MAAI,OAAO,QAAQ;AACf,UAAM,wBAAkD,CAAC;AACzD,WAAO,QAAQ,CAAC,EAAE,MAAM,QAAQ,MAAM;AAClC,YAAM,aAAa,KAAK,QAAQ,OAAO,EAAE;AACzC,UAAI,CAAC,sBAAsB,UAAU,GAAG;AACpC,8BAAsB,UAAU,IAAI,CAAC;AAAA,MACzC;AACA,4BAAsB,UAAU,EAAE,KAAK,OAAO;AAAA,IAClD,CAAC;AACD,UAAM,iBAA2B;AAAA,MAC7B;AAAA,MACA,GAAG,OAAO,QAAQ,qBAAqB,EAAE;AAAA,QACrC,CAAC,CAAC,SAAS,QAAQ,MAAM,KAAK,OAAO,MAAM,SAAS,KAAK,IAAI,CAAC;AAAA,MAClE;AAAA,IACJ;AACA,UAAM,IAAI,MAAM,eAAe,KAAK,UAAAA,QAAG,GAAG,CAAC;AAAA,EAC/C;AACA,QAAM,MAAM,mBAAM;AAAA,IACd;AAAA,MACI,GAAG;AAAA,MACH,sBAAsB;AAAA,IAC1B;AAAA,IACA;AAAA,EACJ;AACA,SAAO;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACP;AACJ;","names":["Os"]}
package/dist/index.d.cts DELETED
@@ -1,6 +0,0 @@
1
- import * as _sinclair_typebox from '@sinclair/typebox';
2
- import { TObject, Static } from '@sinclair/typebox';
3
-
4
- declare const envious: <T extends TObject<_sinclair_typebox.TProperties>>(schema: T, defaultValues?: Static<T>) => Static<T>;
5
-
6
- export { envious };
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import * as _sinclair_typebox from '@sinclair/typebox';
2
- import { TObject, Static } from '@sinclair/typebox';
3
-
4
- declare const envious: <T extends TObject<_sinclair_typebox.TProperties>>(schema: T, defaultValues?: Static<T>) => Static<T>;
5
-
6
- export { envious };
package/dist/index.js DELETED
@@ -1,40 +0,0 @@
1
- // src/index.ts
2
- import "dotenv/config";
3
- import { Value } from "@sinclair/typebox/value";
4
- import Os from "os";
5
- var envious = (schema, defaultValues) => {
6
- const parsed = Value.Convert(schema, process.env);
7
- const errors = [...Value.Errors(schema, parsed)];
8
- if (errors.length) {
9
- const computedErrorMessages = {};
10
- errors.forEach(({ path, message }) => {
11
- const envVarName = path.replace(/^\//, "");
12
- if (!computedErrorMessages[envVarName]) {
13
- computedErrorMessages[envVarName] = [];
14
- }
15
- computedErrorMessages[envVarName].push(message);
16
- });
17
- const errorTextParts = [
18
- "Invalid environment variables",
19
- ...Object.entries(computedErrorMessages).map(
20
- ([varName, messages]) => ` ${varName} : ${messages.join(", ")}`
21
- )
22
- ];
23
- throw new Error(errorTextParts.join(Os.EOL));
24
- }
25
- const env = Value.Cast(
26
- {
27
- ...schema,
28
- additionalProperties: false
29
- },
30
- parsed
31
- );
32
- return {
33
- ...defaultValues,
34
- ...env
35
- };
36
- };
37
- export {
38
- envious
39
- };
40
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import 'dotenv/config';\nimport { type TObject, type Static } from '@sinclair/typebox';\nimport { Value } from '@sinclair/typebox/value';\nimport Os from 'os';\n\nexport const envious = <T extends TObject>(\n schema: T,\n defaultValues?: Static<T>\n): Static<T> => {\n const parsed = Value.Convert(schema, process.env);\n const errors = [...Value.Errors(schema, parsed)];\n if (errors.length) {\n const computedErrorMessages: Record<string, string[]> = {};\n errors.forEach(({ path, message }) => {\n const envVarName = path.replace(/^\\//, '');\n if (!computedErrorMessages[envVarName]) {\n computedErrorMessages[envVarName] = [];\n }\n computedErrorMessages[envVarName].push(message);\n });\n const errorTextParts: string[] = [\n 'Invalid environment variables',\n ...Object.entries(computedErrorMessages).map(\n ([varName, messages]) => ` ${varName} : ${messages.join(', ')}`\n )\n ];\n throw new Error(errorTextParts.join(Os.EOL));\n }\n const env = Value.Cast(\n {\n ...schema,\n additionalProperties: false\n },\n parsed\n );\n return {\n ...defaultValues,\n ...env\n };\n};\n"],"mappings":";AAAA,OAAO;AAEP,SAAS,aAAa;AACtB,OAAO,QAAQ;AAER,IAAM,UAAU,CACnB,QACA,kBACY;AACZ,QAAM,SAAS,MAAM,QAAQ,QAAQ,QAAQ,GAAG;AAChD,QAAM,SAAS,CAAC,GAAG,MAAM,OAAO,QAAQ,MAAM,CAAC;AAC/C,MAAI,OAAO,QAAQ;AACf,UAAM,wBAAkD,CAAC;AACzD,WAAO,QAAQ,CAAC,EAAE,MAAM,QAAQ,MAAM;AAClC,YAAM,aAAa,KAAK,QAAQ,OAAO,EAAE;AACzC,UAAI,CAAC,sBAAsB,UAAU,GAAG;AACpC,8BAAsB,UAAU,IAAI,CAAC;AAAA,MACzC;AACA,4BAAsB,UAAU,EAAE,KAAK,OAAO;AAAA,IAClD,CAAC;AACD,UAAM,iBAA2B;AAAA,MAC7B;AAAA,MACA,GAAG,OAAO,QAAQ,qBAAqB,EAAE;AAAA,QACrC,CAAC,CAAC,SAAS,QAAQ,MAAM,KAAK,OAAO,MAAM,SAAS,KAAK,IAAI,CAAC;AAAA,MAClE;AAAA,IACJ;AACA,UAAM,IAAI,MAAM,eAAe,KAAK,GAAG,GAAG,CAAC;AAAA,EAC/C;AACA,QAAM,MAAM,MAAM;AAAA,IACd;AAAA,MACI,GAAG;AAAA,MACH,sBAAsB;AAAA,IAC1B;AAAA,IACA;AAAA,EACJ;AACA,SAAO;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACP;AACJ;","names":[]}