@arkstack/common 0.12.12 → 0.12.13

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +434 -0
  2. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -1 +1,435 @@
1
1
  /// <reference path="./app.d.ts" />
2
+ import { a as abortIf, c as initializeGlobalContext, d as Hash, f as Encryption, i as abort, l as isClass, n as ModelConstructor, o as assertFound, r as ModelRegistry, s as getModel, t as AbstractModelConstructor, u as perPage } from "./helpers-CfQxt_q2.js";
3
+ import { JitiOptions, JitiResolveOptions } from "jiti";
4
+ import { Arkstack } from "@arkstack/contract";
5
+ import pino from "pino";
6
+ import { ChalkInstance } from "chalk";
7
+
8
+ //#region src/lifecycle.d.ts
9
+ declare const bindGracefulShutdown: (shutdown: () => Promise<void> | void, defer?: boolean) => void;
10
+ //#endregion
11
+ //#region src/network.d.ts
12
+ /**
13
+ * Boots the app using an available port close to the requested port
14
+ *when requested port is not available
15
+ *
16
+ * @param boot
17
+ * @param preferredPort
18
+ * @param app
19
+ * @param defer
20
+ */
21
+ declare const bootWithDetectedPort: <TApp, TRoutes = unknown, THandler = unknown>(boot: (port: number) => Promise<void>, preferredPort?: number, app?: Arkstack<TApp, TRoutes, THandler>, defer?: boolean) => Promise<void>;
22
+ declare const renderError: ({
23
+ message,
24
+ stack,
25
+ title,
26
+ code
27
+ }: {
28
+ message?: string;
29
+ stack?: string;
30
+ code?: number;
31
+ title?: string;
32
+ }) => any;
33
+ //#endregion
34
+ //#region src/prototypes.d.ts
35
+ declare const loadPrototypes: () => void;
36
+ //#endregion
37
+ //#region src/Logger.d.ts
38
+ declare class Console {
39
+ static log: (...args: any[]) => string | void;
40
+ static debug: (...args: any[]) => void;
41
+ static warn: (...args: any[]) => void[];
42
+ static info: (...args: any[]) => void[];
43
+ static error: (...args: any[]) => void[];
44
+ }
45
+ declare class Logger {
46
+ /**
47
+ * Global verbosity configuration
48
+ */
49
+ private static verbosity;
50
+ private static isQuiet;
51
+ private static isSilent;
52
+ /**
53
+ * Configure global verbosity levels
54
+ */
55
+ static configure(options?: {
56
+ verbosity?: number;
57
+ quiet?: boolean;
58
+ silent?: boolean;
59
+ }): void;
60
+ /**
61
+ * Check if output should be suppressed
62
+ */
63
+ private static shouldSuppressOutput;
64
+ /**
65
+ * Logs the message in two columns
66
+ *
67
+ * @param name
68
+ * @param value
69
+ * @param log If set to false, array of [name, dots, value] output will be returned and not logged
70
+ * @returns
71
+ */
72
+ static twoColumnDetail(name: string, value: string, log?: true, spacer?: string): void;
73
+ static twoColumnDetail(name: string, value: string, log?: false, spacer?: string): [string, string, string];
74
+ /**
75
+ * Logs the message in two columns
76
+ *
77
+ * @param name
78
+ * @param desc
79
+ * @param width
80
+ * @param log If set to false, array of [name, dots, value] output will be returned and not logged
81
+ * @returns
82
+ */
83
+ static describe(name: string, desc: string, width?: number, log?: true): void;
84
+ static describe(name: string, desc: string, width?: number, log?: false): [string, string, string];
85
+ /**
86
+ * Logs the message in two columns but allways passing status
87
+ *
88
+ * @param name
89
+ * @param value
90
+ * @param status
91
+ * @param exit
92
+ * @param preserveCol
93
+ */
94
+ static split(name: string, value: string, status?: 'success' | 'info' | 'error', exit?: boolean, preserveCol?: boolean, spacer?: string): void;
95
+ /**
96
+ * Wraps text with chalk
97
+ *
98
+ * @param txt
99
+ * @param color
100
+ * @param preserveCol
101
+ * @returns
102
+ */
103
+ static textFormat(txt: unknown | unknown[], color: (...text: unknown[]) => string, preserveCol?: boolean): string;
104
+ /**
105
+ * Logs a success message
106
+ *
107
+ * @param msg
108
+ * @param exit
109
+ * @param preserveCol
110
+ */
111
+ static success(msg: any, exit?: boolean, preserveCol?: boolean): void;
112
+ /**
113
+ * Logs an informational message
114
+ *
115
+ * @param msg
116
+ * @param exit
117
+ * @param preserveCol
118
+ */
119
+ static info(msg: any, exit?: boolean, preserveCol?: boolean): void;
120
+ /**
121
+ * Logs an error message
122
+ *
123
+ * @param msg
124
+ * @param exit
125
+ * @param preserveCol
126
+ */
127
+ static error(msg: any, exit?: boolean, preserveCol?: boolean): void;
128
+ /**
129
+ * Logs a warning message
130
+ *
131
+ * @param msg
132
+ * @param exit
133
+ * @param preserveCol
134
+ */
135
+ static warn(msg: any, exit?: boolean, preserveCol?: boolean): void;
136
+ /**
137
+ * Logs a debug message (only shown with verbosity >= 3)
138
+ *
139
+ * @param msg
140
+ * @param exit
141
+ * @param preserveCol
142
+ */
143
+ static debug<M = any>(msg: M | M[], exit?: boolean, preserveCol?: boolean): void;
144
+ /**
145
+ * Terminates the process
146
+ */
147
+ static quiet(): void;
148
+ static chalker(styles: LoggerChalk[]): (input: any) => string;
149
+ /**
150
+ * Parse an array formated message and logs it
151
+ *
152
+ * @param config
153
+ * @param joiner
154
+ * @param log If set to false, string output will be returned and not logged
155
+ * @param sc color to use ue on split text if : is found
156
+ */
157
+ static parse(config: LoggerParseSignature, joiner?: string, log?: true, sc?: LoggerChalk): void;
158
+ static parse(config: LoggerParseSignature, joiner?: string, log?: false, sc?: LoggerChalk): string;
159
+ /**
160
+ * Ouput formater object or format the output
161
+ *
162
+ * @returns
163
+ */
164
+ static log: LoggerLog;
165
+ /**
166
+ * A simple console like output logger
167
+ *
168
+ * @returns
169
+ */
170
+ static console(): typeof Console;
171
+ }
172
+ //#endregion
173
+ //#region src/types.d.ts
174
+ interface ConfigRegistry {}
175
+ interface EnvRegistry {}
176
+ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
177
+ type MergedConfig<X> = UnionToIntersection<X>;
178
+ type Primitive = string | number | boolean | null | undefined | Function;
179
+ type LoggerChalk = keyof ChalkInstance | ChalkInstance | (keyof ChalkInstance)[];
180
+ type LoggerParseSignature = [string, LoggerChalk][];
181
+ type DotPathValue<T, P extends string> = P extends `${infer Head}.${infer Tail}` ? Head extends keyof T ? DotPathValue<T[Head], Tail> : never : P extends keyof T ? T[P] : never;
182
+ type DotPath<T> = T extends Primitive ? never : T extends any[] ? never : { [K in keyof T & string]: T[K] extends Primitive ? `${K}` : T[K] extends any[] ? `${K}` : `${K}` | `${K}.${DotPath<T[K]>}` }[keyof T & string];
183
+ /**
184
+ * Ouput formater object or format the output
185
+ *
186
+ * @param config
187
+ * @param joiner
188
+ * @param log If set to false, string output will be returned and not logged
189
+ * @param sc color to use ue on split text if : is found
190
+ *
191
+ * @returns
192
+ */
193
+ interface LoggerLog {
194
+ (): typeof Logger;
195
+ <L extends boolean>(config: string, joiner: LoggerChalk, log?: L, sc?: LoggerChalk): L extends true ? void : string;
196
+ <L extends boolean>(config: LoggerParseSignature, joiner?: string, log?: L, sc?: LoggerChalk): L extends true ? void : string;
197
+ <L extends boolean>(config?: LoggerParseSignature, joiner?: string, log?: L, sc?: LoggerChalk): L extends true ? void : string | Logger;
198
+ }
199
+ interface GlobalEnv {
200
+ <X = string, Y = undefined | X>(env: string, defaultValue?: Y): Y extends undefined ? X : Y;
201
+ }
202
+ type ConfigShape = keyof ConfigRegistry extends never ? Record<string, any> : ConfigRegistry;
203
+ interface GlobalConfig {
204
+ <X extends ConfigShape>(): X;
205
+ <X extends ConfigShape, P extends DotPath<X>>(key: P): DotPathValue<X, P>;
206
+ <X extends ConfigShape, P extends DotPath<X>>(key: Record<P, Partial<DotPathValue<X, P>>>): void;
207
+ <X extends ConfigShape, P extends DotPath<X>, D>(key: P, defaultValue: D): DotPathValue<X, P> | D;
208
+ }
209
+ interface FileImporter {
210
+ <T = unknown>(filePath: string): Promise<T>;
211
+ <T = unknown>(filePath: string, userOptions?: JitiOptions | undefined): Promise<T>;
212
+ <T = unknown>(filePath: string, userOptions?: JitiOptions | undefined, resolveOptions?: (JitiResolveOptions & {
213
+ default?: true;
214
+ })): Promise<T>;
215
+ }
216
+ type ArkstackErrorShape = Error & {
217
+ cause?: unknown;
218
+ code?: number | string;
219
+ errors?: unknown;
220
+ getModelName?: () => string;
221
+ status?: number;
222
+ statusCode?: number;
223
+ };
224
+ interface ArkstackErrorPayload {
225
+ status: 'error';
226
+ code: number;
227
+ message: string;
228
+ errors?: unknown;
229
+ stack?: string;
230
+ }
231
+ interface HookRegistry {}
232
+ type Position = 'before' | 'after' | (string & {});
233
+ type IHook = { [P in Position]?: (...args: any[]) => void };
234
+ type HookName = keyof HookRegistry extends never ? string : keyof HookRegistry | (string & {});
235
+ type HookFor<N extends string> = N extends keyof HookRegistry ? HookRegistry[N] : IHook;
236
+ type HookPos<N extends string, P extends string> = N extends keyof HookRegistry ? P extends keyof HookRegistry[N] ? HookRegistry[N][P] : (...args: any[]) => void : (...args: any[]) => void;
237
+ type HookPositions<N extends string> = N extends keyof HookRegistry ? keyof HookRegistry[N] : Position;
238
+ type HookArgs<N extends string, P extends string> = N extends keyof HookRegistry ? P extends keyof HookRegistry[N] ? HookRegistry[N][P] extends ((...args: infer A) => any) ? A : any[] : any[] : any[];
239
+ //#endregion
240
+ //#region src/system.d.ts
241
+ /**
242
+ * Read the .env file
243
+ *
244
+ * @param env
245
+ * @param def
246
+ * @returns
247
+ */
248
+ declare const env: GlobalEnv;
249
+ /**
250
+ * Build the app url
251
+ *
252
+ * @param link
253
+ * @returns
254
+ */
255
+ declare const appUrl: (link?: string) => string;
256
+ declare const CONFIG_KEY: unique symbol;
257
+ /**
258
+ * Gets the application configuration.
259
+ *
260
+ * @param key The configuration key to retrieve.
261
+ * @param defaultValue The default value to return if the key is not found.
262
+ * @returns The configuration value.
263
+ */
264
+ declare const config: GlobalConfig;
265
+ /**
266
+ * Gets the current Node environment (development or production).
267
+ *
268
+ * @returns
269
+ */
270
+ declare const nodeEnv: () => "prod" | "dev";
271
+ /**
272
+ * Gets the output directory for the application based on the current environment.
273
+ *
274
+ * @param cwd The current working directory (optional, defaults to Arkstack.rootDir()).
275
+ * @returns
276
+ */
277
+ declare const outputDir: (cwd?: string) => string;
278
+ /**
279
+ *
280
+ * Dynamically imports a file at the given path with full TypeScript support,
281
+ * including `tsconfig.json` path aliases.
282
+ *
283
+ * @param filePath - The path to the file to import.
284
+ * @returns The imported module typed as `T`.
285
+ *
286
+ * @example
287
+ * const config = await importFile<AppConfig>('./config/app.ts')
288
+ */
289
+ declare const importFile: FileImporter;
290
+ /**
291
+ * Resolves the default export from a module, handling both CJS and ESM interop.
292
+ * In CJS modules, the default export is often the module itself (a function or object),
293
+ * while in ESM the default is nested under the `default` property.
294
+ *
295
+ * @param imp - The imported module
296
+ * @returns The resolved default export
297
+ */
298
+ declare const interopDefault: <T>(imp: T | {
299
+ default: T;
300
+ }) => T;
301
+ //#endregion
302
+ //#region src/Exceptions/Exception.d.ts
303
+ declare class Exception extends Error {
304
+ name: string;
305
+ constructor(message?: string, options?: ErrorOptions);
306
+ }
307
+ //#endregion
308
+ //#region src/Exceptions/AppException.d.ts
309
+ declare class AppException extends Exception {
310
+ errors?: {
311
+ [key: string]: string[] | string;
312
+ } | undefined;
313
+ statusCode: number;
314
+ constructor(message?: string, statusCode?: number, options?: ErrorOptions);
315
+ }
316
+ //#endregion
317
+ //#region src/Exceptions/RequestException.d.ts
318
+ declare class RequestException extends AppException {
319
+ statusCode: number;
320
+ constructor(message?: string, statusCode?: number, options?: ErrorOptions);
321
+ /**
322
+ * Asserts that a value is not null or undefined.
323
+ *
324
+ * @param value
325
+ * @param message
326
+ * @param code
327
+ * @throws {RequestException} Throws if the value is null or undefined.
328
+ */
329
+ static assertFound<T>(value: T | null | undefined, message: string, code?: number): asserts value is T;
330
+ /**
331
+ * Asserts that a value is not null or undefined.
332
+ *
333
+ * @param value
334
+ * @param message
335
+ * @param code
336
+ * @throws {RequestException} Throws if the value is null or undefined.
337
+ * @deprecated Use assertFound instead
338
+ */
339
+ static assertNotEmpty<T>(value: T | null | undefined, message: string, code?: number): asserts value is T;
340
+ /**
341
+ * Asserts that a boolean condition is true.
342
+ *
343
+ * @param boolean
344
+ * @param message
345
+ * @param code
346
+ * @throws {RequestException} Throws if the boolean condition is true.
347
+ */
348
+ static abortIf<T>(boolean: T, message: string, code?: number): asserts boolean is T;
349
+ }
350
+ //#endregion
351
+ //#region src/ErrorHandler.d.ts
352
+ declare class ErrorHandler {
353
+ private static loggerCache;
354
+ private static isRecord;
355
+ static toErrorShape(value: unknown): ArkstackErrorShape | undefined;
356
+ static normalizeStatusCode(value: unknown, fallback?: number): number;
357
+ static getErrorLogger(): pino.Logger;
358
+ static serializeError(value: unknown, seen?: WeakSet<object>): unknown;
359
+ static getPrimaryError(error: ArkstackErrorShape | string): string | ArkstackErrorShape;
360
+ static getValidationErrors(error: ArkstackErrorShape): any;
361
+ static isValidationError(error: unknown): error is ArkstackErrorShape;
362
+ static isModelNotFoundError(error: unknown): error is ArkstackErrorShape;
363
+ static shouldHideStack(): boolean;
364
+ static shouldLogError(error: unknown): boolean;
365
+ static createErrorPayload(err: ArkstackErrorShape | string, fallbackMessage?: string): ArkstackErrorPayload;
366
+ static logUnhandledError(err: unknown, request: Record<string, unknown>, message: string): void;
367
+ }
368
+ declare const toErrorShape: typeof ErrorHandler.toErrorShape;
369
+ declare const normalizeStatusCode: typeof ErrorHandler.normalizeStatusCode;
370
+ declare const getErrorLogger: typeof ErrorHandler.getErrorLogger;
371
+ declare const serializeError: typeof ErrorHandler.serializeError;
372
+ declare const getPrimaryError: typeof ErrorHandler.getPrimaryError;
373
+ declare const getValidationErrors: typeof ErrorHandler.getValidationErrors;
374
+ declare const isValidationError: typeof ErrorHandler.isValidationError;
375
+ declare const isModelNotFoundError: typeof ErrorHandler.isModelNotFoundError;
376
+ declare const shouldHideStack: typeof ErrorHandler.shouldHideStack;
377
+ declare const shouldLogError: typeof ErrorHandler.shouldLogError;
378
+ declare const createErrorPayload: typeof ErrorHandler.createErrorPayload;
379
+ declare const logUnhandledError: typeof ErrorHandler.logUnhandledError;
380
+ //#endregion
381
+ //#region src/Hook.d.ts
382
+ declare class Hook {
383
+ private static hooks;
384
+ /**
385
+ * Hooks define code that should run within defined boundaries to add extra functionalities.
386
+ *
387
+ * @param name
388
+ * @param value
389
+ */
390
+ static set<N extends HookName>(name: N | (string & {}), hook: HookFor<N>): void;
391
+ /**
392
+ * Check if a hook is defined by name
393
+ *
394
+ * @param name
395
+ */
396
+ static has<N extends HookName, P extends HookPositions<N>>(name: N | (string & {}), pos?: P): boolean;
397
+ /**
398
+ * Retrieve a defined hook by name
399
+ *
400
+ * @param name
401
+ */
402
+ static get<N extends HookName>(name: N): HookFor<N> | undefined;
403
+ /**
404
+ * Retrieve a defined hook by name and position
405
+ *
406
+ * @param name
407
+ * @param pos
408
+ */
409
+ static get<N extends HookName, P extends HookPositions<N>>(name: N, pos: P): HookPos<N, P> | undefined;
410
+ /**
411
+ * Retrieve a defined hook by name and position the set args for callback
412
+ *
413
+ * @param name
414
+ * @param pos
415
+ */
416
+ static get<N extends HookName, P extends HookPositions<N>>(name: N, pos: P, ...args: HookArgs<N, P>): void;
417
+ /**
418
+ * Retrieve all defined hooks
419
+ *
420
+ * @param name
421
+ */
422
+ static getAll: () => Record<string, IHook> & HookRegistry;
423
+ /**
424
+ * Remove the defined hook
425
+ *
426
+ * @param name
427
+ */
428
+ static unset<N extends HookName, P extends HookPositions<N>>(name?: N | (string & {}), pos?: P): undefined;
429
+ /**
430
+ * Clear all the defined hooks
431
+ */
432
+ static clear: () => void;
433
+ }
434
+ //#endregion
435
+ export { AbstractModelConstructor, AppException, ArkstackErrorPayload, ArkstackErrorShape, CONFIG_KEY, ConfigRegistry, ConfigShape, DotPath, DotPathValue, Encryption, EnvRegistry, ErrorHandler, Exception, FileImporter, GlobalConfig, GlobalEnv, Hash, Hook, HookArgs, HookFor, HookName, HookPos, HookPositions, HookRegistry, IHook, Logger, LoggerChalk, LoggerLog, LoggerParseSignature, MergedConfig, ModelConstructor, ModelRegistry, Primitive, RequestException, UnionToIntersection, abort, abortIf, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, createErrorPayload, env, getErrorLogger, getModel, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, logUnhandledError, nodeEnv, normalizeStatusCode, outputDir, perPage, renderError, serializeError, shouldHideStack, shouldLogError, toErrorShape };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/common",
3
- "version": "0.12.12",
3
+ "version": "0.12.13",
4
4
  "type": "module",
5
5
  "description": "Core utilities, primitives, and shared infrastructure for the Arkstack ecosystem.",
6
6
  "homepage": "https://arkstack.toneflix.net",
@@ -42,8 +42,8 @@
42
42
  "peerDependencies": {
43
43
  "@h3ravel/support": "^0.15.11",
44
44
  "arkormx": "^ 2.4.1",
45
- "@arkstack/foundry": "^0.12.12",
46
- "@arkstack/contract": "^0.12.12"
45
+ "@arkstack/foundry": "^0.12.13",
46
+ "@arkstack/contract": "^0.12.13"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsdown --config-loader unrun",