-
Notifications
You must be signed in to change notification settings - Fork 32
/
mod.ts
161 lines (142 loc) · 5.64 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Core
import env_var from "./src/core/env_var.ts";
// Compilers
import doc_blocks_to_json from "./src/compilers/doc_blocks_to_json.ts";
// Dictionaries
import * as log_levels from "./src/dictionaries/log_levels.ts";
import mime_db from "https://raw.githubusercontent.com/jshttp/mime-db/master/db.json";
// Exceptions
import http_exception from "./src/exceptions/http_exception.ts";
// Http
import request from "./src/http/request.ts";
import resource from "./src/http/resource.ts";
import response from "./src/http/response.ts";
import server from "./src/http/server.ts";
// Loggers
import base_logger from "./src/loggers/logger.ts";
import console_logger from "./src/loggers/console_logger.ts";
import class_core_logger from "./src/loggers/core_logger.ts";
import file_logger from "./src/loggers/file_logger.ts";
// Services
import http_service from "./src/services/http_service.ts";
// Util
import util_object_parser from "./src/util/object_parser.ts";
import * as util_members from "./src/util/members.ts";
////////////////////////////////////////////////////////////////////////////////
// FILE MARKER: NAMESPACE - DRASH //////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Usage: import Drash from "/path/to/drash/mod.ts";
//
namespace Drash {
export namespace Core {
export type EnvVar = env_var; export const EnvVar = env_var;
}
export namespace Compilers {
export type DocBlocksToJson = doc_blocks_to_json; export const DocBlocksToJson = doc_blocks_to_json;
}
export namespace Dictionaries {
export const LogLevels = log_levels.LogLevels;
export const MimeDb = mime_db;
// export namespace Enums {
// export const LogLevel = log_levels.LogLevel;
// }
}
export namespace Exceptions {
export type HttpException = http_exception; export const HttpException = http_exception;
}
export namespace Loggers {
export type ConsoleLogger = console_logger; export const ConsoleLogger = console_logger;
export type CoreLogger = class_core_logger; export const CoreLogger = class_core_logger;
export type FileLogger = file_logger; export const FileLogger = file_logger;
export type Logger = base_logger; export const Logger = base_logger;
}
export namespace Http {
export type Request = request; export let Request = request;
export type Resource = resource; export const Resource = resource;
export type Response = response; export let Response = response;
export type Server = server; export const Server = server;
}
export namespace Services {
export type HttpService = http_service; export const HttpService = new http_service();
}
export namespace Util {
export type ObjectParser = util_object_parser; export const ObjectParser = util_object_parser;
export const Exports = util_members;
}
/**
* A property to hold all members added via `Drash.addMember()`. This property
* allows users to access members via `Drash.Members.SomeMember` and acts like
* a namespace for members that are external to Drash.
*
* @property Drash.Members Members
*/
export const Members: any = {};
/**
* A property to hold the core logger. This logger is for debugging purposes.
* It helps Drash developers debug issues within the Drash namespace. For
* example, the `DocBlocksToJson` compiler could run into issues while parsing
* doc blocks and writing the JSON to a file. In order to debug where issues
* occur, `Drash.core_logger` is called within that class.
*
* This logger can only be enabled using the `DRASH_CORE_LOGGER_ENABLED`
* environment variable. You can also set the logger's output level using the
* `DRASH_CORE_LOGGER_LEVEL` environment variable.
*
* @property Drash.Loggers.CoreLogger core_logger
*/
export const core_logger = new Drash.Loggers.CoreLogger({
enabled: Deno.env().DRASH_CORE_LOGGER_ENABLED === "true",
level: Deno.env().DRASH_CORE_LOGGER_LEVEL,
tag_string: "{level} |"
});
/**
* Add an app to the Members namespace. After adding an app, you can use the
* app via `Drash.Members.YourApp.doSomething()`.
*
* @param string name
* The app's name which can be accessed via `Drash.Members[name]`.
* @param any app
* The app.
*/
export function addMember(name: string, app: any) {
this.core_logger.debug(
`Add member "${name}" to Drash.Members namespace.`
);
this.Members[name] = app;
}
/**
* Set an environment variable in `Deno.env()`.
*
* @param string variableName
* The variable name.
*
* @return Drash.Core.EnvVar
* Returns a new EnvVar object with helper functions. For example, if
* the value of the environment variable is a JSON string, you can call
* `.toArray().value` to turn it into a parsable JSON array before
* retrieving the actual value.
*/
export function getEnvVar(variableName: string): Drash.Core.EnvVar {
let exists = Deno.env().hasOwnProperty(variableName);
let value;
value = exists ? Deno.env()[variableName] : undefined;
return new Drash.Core.EnvVar(variableName, value);
}
/**
* Set an environment variable in `Deno.env()`.
*
* @param string variableName
* The variable name which can be accessed via
* `Drash.getEnvVar(variableName)`.
* @param string value
* The value of the variable. `Deno.env()` only accepts strings. See
* https://deno.land/typedoc/index.html#env for more info.
*/
export function setEnvVar(variableName: string, value: string) {
if (!Deno.env()[variableName]) {
Deno.env()[variableName] = value;
}
}
}
export default Drash;