gravity-run 0.0.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.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/cli/index.js +845 -0
- package/dist/index.d.ts +398 -0
- package/dist/index.js +212 -0
- package/dist/shared/chunk-b636e30q.js +274 -0
- package/package.json +83 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
+
|
|
20
|
+
// node_modules/picocolors/picocolors.js
|
|
21
|
+
var require_picocolors = __commonJS((exports, module) => {
|
|
22
|
+
var p = process || {};
|
|
23
|
+
var argv = p.argv || [];
|
|
24
|
+
var env = p.env || {};
|
|
25
|
+
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
26
|
+
var formatter = (open, close, replace = open) => (input) => {
|
|
27
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
28
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
29
|
+
};
|
|
30
|
+
var replaceClose = (string, close, replace, index) => {
|
|
31
|
+
let result = "", cursor = 0;
|
|
32
|
+
do {
|
|
33
|
+
result += string.substring(cursor, index) + replace;
|
|
34
|
+
cursor = index + close.length;
|
|
35
|
+
index = string.indexOf(close, cursor);
|
|
36
|
+
} while (~index);
|
|
37
|
+
return result + string.substring(cursor);
|
|
38
|
+
};
|
|
39
|
+
var createColors = (enabled = isColorSupported) => {
|
|
40
|
+
let f = enabled ? formatter : () => String;
|
|
41
|
+
return {
|
|
42
|
+
isColorSupported: enabled,
|
|
43
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
44
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
45
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
46
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
47
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
48
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
49
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
50
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
51
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
52
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
53
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
54
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
55
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
56
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
57
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
58
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
59
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
60
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
61
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
62
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
63
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
64
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
65
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
66
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
67
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
68
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
69
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
70
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
71
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
72
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
73
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
74
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
75
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
76
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
77
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
78
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
79
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
80
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
81
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
82
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
83
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
module.exports = createColors();
|
|
87
|
+
module.exports.createColors = createColors;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// src/config/loader.ts
|
|
91
|
+
function loadConfig() {
|
|
92
|
+
return Promise.resolve({});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/config/index.ts
|
|
96
|
+
function defineConfig(config) {
|
|
97
|
+
return config;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/utils/errors.ts
|
|
101
|
+
class BasaltError extends Error {
|
|
102
|
+
code;
|
|
103
|
+
status;
|
|
104
|
+
constructor(message, code, status) {
|
|
105
|
+
super(message);
|
|
106
|
+
this.code = code;
|
|
107
|
+
this.status = status;
|
|
108
|
+
this.name = this.constructor.name;
|
|
109
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
class NotFoundError extends BasaltError {
|
|
114
|
+
constructor(message = "Resource not found") {
|
|
115
|
+
super(message, "NOT_FOUND", 404);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
class UnauthorizedError extends BasaltError {
|
|
120
|
+
constructor(message = "Unauthorized") {
|
|
121
|
+
super(message, "UNAUTHORIZED", 401);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
class ForbiddenError extends BasaltError {
|
|
126
|
+
constructor(message = "Forbidden") {
|
|
127
|
+
super(message, "FORBIDDEN", 403);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
class BadRequestError extends BasaltError {
|
|
132
|
+
constructor(message = "Bad Request") {
|
|
133
|
+
super(message, "BAD_REQUEST", 400);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
class InternalServerError extends BasaltError {
|
|
138
|
+
constructor(message = "Internal Server Error") {
|
|
139
|
+
super(message, "INTERNAL_SERVER_ERROR", 500);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
class NonRetriableError extends BasaltError {
|
|
144
|
+
constructor(message) {
|
|
145
|
+
super(message, "NON_RETRIABLE_ERROR", 500);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/logger/pretty-print.ts
|
|
150
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
151
|
+
var stepTag = (step) => step ? import_picocolors.default.bold(import_picocolors.default.cyan(step)) : "";
|
|
152
|
+
var timestampTag = (timestamp) => import_picocolors.default.gray(timestamp);
|
|
153
|
+
var traceIdTag = (traceId) => traceId ? import_picocolors.default.gray(traceId) : "";
|
|
154
|
+
var levelTags = {
|
|
155
|
+
error: import_picocolors.default.red("[ERROR]"),
|
|
156
|
+
info: import_picocolors.default.blue("[INFO]"),
|
|
157
|
+
warn: import_picocolors.default.yellow("[WARN]"),
|
|
158
|
+
debug: import_picocolors.default.gray("[DEBUG]")
|
|
159
|
+
};
|
|
160
|
+
var numericTag = (value) => import_picocolors.default.green(value);
|
|
161
|
+
var stringTag = (value) => import_picocolors.default.cyan(value);
|
|
162
|
+
var booleanTag = (value) => import_picocolors.default.blue(value);
|
|
163
|
+
var arrayBrackets = ["[", "]"].map((s) => import_picocolors.default.gray(s));
|
|
164
|
+
var objectBrackets = ["{", "}"].map((s) => import_picocolors.default.gray(s));
|
|
165
|
+
var prettyPrintObject = (obj, depth = 0, parentIsLast = false, prefix = "") => {
|
|
166
|
+
const tab = prefix + (depth === 0 ? "" : parentIsLast ? "│ " : "│ ");
|
|
167
|
+
if (depth > 2)
|
|
168
|
+
return `${tab} └ ${import_picocolors.default.gray("[...]")}`;
|
|
169
|
+
const entries = Object.entries(obj);
|
|
170
|
+
return entries.map(([key, value], index) => {
|
|
171
|
+
const isLast = index === entries.length - 1;
|
|
172
|
+
const isObject = typeof value === "object" && value !== null;
|
|
173
|
+
const branch = isLast ? "└" : "├";
|
|
174
|
+
if (isObject) {
|
|
175
|
+
const subObject = prettyPrintObject(value, depth + 1, isLast, tab);
|
|
176
|
+
const [start, end] = Array.isArray(value) ? arrayBrackets : objectBrackets;
|
|
177
|
+
return `${tab}${branch} ${key}: ${start}
|
|
178
|
+
${subObject}
|
|
179
|
+
${tab}${isLast ? " " : "│"} ${end}`;
|
|
180
|
+
}
|
|
181
|
+
let printedValue = value;
|
|
182
|
+
if (typeof value === "number")
|
|
183
|
+
printedValue = numericTag(String(value));
|
|
184
|
+
else if (typeof value === "boolean")
|
|
185
|
+
printedValue = booleanTag(String(value));
|
|
186
|
+
else if (typeof value === "string")
|
|
187
|
+
printedValue = stringTag(value);
|
|
188
|
+
return `${tab}${branch} ${key}: ${printedValue}`;
|
|
189
|
+
}).join(`
|
|
190
|
+
`);
|
|
191
|
+
};
|
|
192
|
+
var prettyPrint = (json, excludeDetails = false) => {
|
|
193
|
+
const { time, traceId, msg, flows, level, step, ...details } = json;
|
|
194
|
+
const levelTag = levelTags[level] ?? levelTags.info;
|
|
195
|
+
const timestamp = timestampTag(`[${new Date(time).toLocaleTimeString()}]`);
|
|
196
|
+
const objectHasKeys = Object.keys(details).length > 0;
|
|
197
|
+
process.stdout.write(`${timestamp} ${traceIdTag(traceId)} ${levelTag} ${stepTag(step)} ${msg}
|
|
198
|
+
`);
|
|
199
|
+
if (objectHasKeys && !excludeDetails) {
|
|
200
|
+
process.stdout.write(`${prettyPrintObject(details)}
|
|
201
|
+
`);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// src/logger/logger.ts
|
|
206
|
+
var LEVELS = {
|
|
207
|
+
DEBUG: 10,
|
|
208
|
+
INFO: 20,
|
|
209
|
+
WARNING: 30,
|
|
210
|
+
ERROR: 40,
|
|
211
|
+
CRITICAL: 50
|
|
212
|
+
};
|
|
213
|
+
var levelMap = {
|
|
214
|
+
debug: LEVELS.DEBUG,
|
|
215
|
+
info: LEVELS.INFO,
|
|
216
|
+
warn: LEVELS.WARNING,
|
|
217
|
+
warning: LEVELS.WARNING,
|
|
218
|
+
error: LEVELS.ERROR,
|
|
219
|
+
critical: LEVELS.CRITICAL
|
|
220
|
+
};
|
|
221
|
+
var getLogLevel = () => {
|
|
222
|
+
const level = process.env.LOG_LEVEL ?? "info";
|
|
223
|
+
return levelMap[level] ?? LEVELS.INFO;
|
|
224
|
+
};
|
|
225
|
+
var shouldLog = (messageLevel) => {
|
|
226
|
+
return messageLevel >= getLogLevel();
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
class Logger {
|
|
230
|
+
isVerbose;
|
|
231
|
+
meta;
|
|
232
|
+
coreListeners;
|
|
233
|
+
listeners = [];
|
|
234
|
+
constructor(isVerbose = false, meta = {}, coreListeners = []) {
|
|
235
|
+
this.isVerbose = isVerbose;
|
|
236
|
+
this.meta = meta;
|
|
237
|
+
this.coreListeners = coreListeners;
|
|
238
|
+
}
|
|
239
|
+
child(meta) {
|
|
240
|
+
return new Logger(this.isVerbose, { ...this.meta, ...meta }, this.coreListeners);
|
|
241
|
+
}
|
|
242
|
+
_log(level, msg, args) {
|
|
243
|
+
const time = Date.now();
|
|
244
|
+
const meta = { ...this.meta, ...args ?? {} };
|
|
245
|
+
prettyPrint({ level, time, msg, ...meta }, !this.isVerbose);
|
|
246
|
+
this.coreListeners.forEach((listener) => {
|
|
247
|
+
listener(level, msg, meta);
|
|
248
|
+
});
|
|
249
|
+
this.listeners.forEach((listener) => {
|
|
250
|
+
listener(level, msg, meta);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
info(message, args) {
|
|
254
|
+
if (shouldLog(LEVELS.INFO))
|
|
255
|
+
this._log("INFO", message, args);
|
|
256
|
+
}
|
|
257
|
+
error(message, args) {
|
|
258
|
+
if (shouldLog(LEVELS.ERROR))
|
|
259
|
+
this._log("ERROR", message, args);
|
|
260
|
+
}
|
|
261
|
+
debug(message, args) {
|
|
262
|
+
if (shouldLog(LEVELS.DEBUG))
|
|
263
|
+
this._log("DEBUG", message, args);
|
|
264
|
+
}
|
|
265
|
+
warn(message, args) {
|
|
266
|
+
if (shouldLog(LEVELS.WARNING))
|
|
267
|
+
this._log("WARNING", message, args);
|
|
268
|
+
}
|
|
269
|
+
addListener(listener) {
|
|
270
|
+
this.listeners.push(listener);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
var globalLogger = new Logger;
|
|
274
|
+
export { loadConfig, defineConfig, globalLogger, BasaltError, NotFoundError, UnauthorizedError, ForbiddenError, BadRequestError, InternalServerError, NonRetriableError };
|
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gravity-run",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "A framework for building scalable applications",
|
|
5
|
+
"homepage": "https://github.com/alihussnainrb/gravity#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/alihussnainrb/gravity/issues"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"bin": {
|
|
14
|
+
"gravity": "./dist/cli/index.js"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"./cli": "./dist/cli/index.js",
|
|
24
|
+
"./db": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/db/index.d.ts",
|
|
27
|
+
"default": "./dist/db/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./logger": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/logger/index.d.ts",
|
|
33
|
+
"default": "./dist/logger/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"module": "./dist/index.js",
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"files": [
|
|
41
|
+
"dist"
|
|
42
|
+
],
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/alihussnainrb/gravity.git"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "bunup",
|
|
49
|
+
"dev": "bunup --watch",
|
|
50
|
+
"lint": "biome check .",
|
|
51
|
+
"lint:fix": "biome check --write .",
|
|
52
|
+
"release": "bumpp --commit --push --tag",
|
|
53
|
+
"test": "bun test",
|
|
54
|
+
"test:coverage": "bun test --coverage",
|
|
55
|
+
"test:watch": "bun test --watch",
|
|
56
|
+
"type-check": "tsc --noEmit"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@biomejs/biome": "^2.3.14",
|
|
60
|
+
"@types/bun": "^1.3.8",
|
|
61
|
+
"@types/commander": "^2.12.5",
|
|
62
|
+
"bumpp": "^10.4.1",
|
|
63
|
+
"bunup": "^0.16.23",
|
|
64
|
+
"typescript": "^5.9.3"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"typescript": ">=4.5.0"
|
|
68
|
+
},
|
|
69
|
+
"peerDependenciesMeta": {
|
|
70
|
+
"typescript": {
|
|
71
|
+
"optional": true
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"type": "module",
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"@sinclair/typebox-codegen": "^0.11.1",
|
|
77
|
+
"chokidar": "^5.0.0",
|
|
78
|
+
"commander": "^14.0.3",
|
|
79
|
+
"cronbake": "^0.4.0",
|
|
80
|
+
"inquirer": "^13.2.2",
|
|
81
|
+
"typebox": "^1.0.81"
|
|
82
|
+
}
|
|
83
|
+
}
|