@atlantjs/backend 6.0.21 → 7.0.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.
@@ -1,5 +0,0 @@
1
- import { PickVerseType } from "./parchment.type";
2
- export declare class Parchment {
3
- static verse<VerseType>({ ...verse }: PickVerseType<VerseType>): VerseType;
4
- private static convertSetValue;
5
- }
@@ -1,3 +0,0 @@
1
- export declare class PickEnvError extends Error {
2
- constructor(variableName: string, variableDescription: string, messageError: string);
3
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PickEnvError = void 0;
4
- class PickEnvError extends Error {
5
- constructor(variableName, variableDescription, messageError) {
6
- super(`\n❯ ${process.env.ENVIRONMENT} - ${messageError}:\n\n - ${variableName}: ${variableDescription}`);
7
- }
8
- }
9
- exports.PickEnvError = PickEnvError;
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Parchment = void 0;
4
- const arch_1 = require("@atlantjs/arch");
5
- const parchment_error_1 = require("./parchment.error");
6
- class Parchment {
7
- static verse({ ...verse }) {
8
- const setValue = process.env[verse.name] || verse.default?.toString();
9
- if (arch_1._.isNullOrUndefined(setValue) && verse.isRequired.truthy()) {
10
- throw new parchment_error_1.PickEnvError(verse.name, verse.description, "The environment variable must have its value defined");
11
- }
12
- return Parchment.convertSetValue(verse, setValue);
13
- }
14
- static convertSetValue(verse, value) {
15
- if (arch_1._.isUndefined(value)) {
16
- return undefined;
17
- }
18
- if (verse.type === "array") {
19
- return value.split(",");
20
- }
21
- if (verse.type === "boolean") {
22
- if (arch_1._.isAnyOf(value, ["false", "true"]).falsy()) {
23
- throw new parchment_error_1.PickEnvError(verse.name, verse.description, `The value of the environment variable ${value} must be "false" or "true"`);
24
- }
25
- return arch_1._.isEqual(value, "true");
26
- }
27
- if (verse.type === "enum") {
28
- if (arch_1._.isUndefined(verse.values)) {
29
- throw new parchment_error_1.PickEnvError(verse.name, verse.description, `A definição da variável de ambiente ${verse.name} deve conter os valores de referencia`);
30
- }
31
- if (verse.values.includes(value).falsy()) {
32
- throw new parchment_error_1.PickEnvError(verse.name, verse.description, `A variável ${verse.name} deve conter algum dos seguintes valores: [${verse.values.join(", ")}]`);
33
- }
34
- return value;
35
- }
36
- if (verse.type === "float") {
37
- const floatValue = Number.parseFloat(value);
38
- if (Number.isNaN(floatValue)) {
39
- throw new parchment_error_1.PickEnvError(verse.name, verse.description, `The value of the environment variable ${verse.name} must be a valid float number`);
40
- }
41
- return floatValue;
42
- }
43
- if (verse.type === "int") {
44
- const intValue = Number.parseInt(value, 10);
45
- if (Number.isNaN(intValue)) {
46
- throw new parchment_error_1.PickEnvError(verse.name, verse.description, `O valor da variável de ambiente ${verse.name} deve ser um número inteiro válido`);
47
- }
48
- return intValue;
49
- }
50
- if (verse.type === "port-number") {
51
- const portNumber = Number.parseInt(value, 10);
52
- if (Number.isNaN(portNumber) || portNumber < 1 || portNumber > 65535) {
53
- throw new parchment_error_1.PickEnvError(verse.name, verse.description, `O valor da variável de ambiente ${verse.name} deve ser um número de porta válido entre 1 e 65535`);
54
- }
55
- return portNumber;
56
- }
57
- if (verse.type === "text") {
58
- return value;
59
- }
60
- if (verse.type === "url-https") {
61
- const urlPattern = /^https?:\/\/[^\s/$.?#].[^\s]*$/i;
62
- if (!urlPattern.test(value)) {
63
- throw new parchment_error_1.PickEnvError(verse.name, verse.description, `O valor da variável de ambiente ${verse.name} deve ser uma URL válida começando com http ou https`);
64
- }
65
- return value;
66
- }
67
- // If none of the types matched, return undefined
68
- return undefined;
69
- }
70
- }
71
- exports.Parchment = Parchment;
@@ -1,9 +0,0 @@
1
- export type VerseTypes = "text" | "port-number" | "array" | "enum" | "url-https" | "int" | "boolean" | "float";
2
- export interface PickVerseType<VerseType> {
3
- name: string;
4
- description: string;
5
- type: VerseTypes;
6
- values?: string[];
7
- isRequired: boolean;
8
- default?: VerseType;
9
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });