@arkstack/common 0.17.16 → 0.17.18

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/dist/faker.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Faker, ImageModule } from "@faker-js/faker";
2
2
  import { PictwoFakerImage } from "@pictwo/faker";
3
-
4
3
  //#region src/faker.d.ts
5
4
  declare const faker: Faker & {
6
5
  image: ImageModule & PictwoFakerImage;
package/dist/faker.js CHANGED
@@ -1,4 +1,4 @@
1
- import { g as configLoader } from "./system-XvUhJFS0.js";
1
+ import { g as configLoader } from "./system-Die_Dv5y.js";
2
2
  import * as fakerLocales from "@faker-js/faker";
3
3
  import { Faker } from "@faker-js/faker";
4
4
  import { pictwoImage } from "@pictwo/faker";
@@ -2,7 +2,6 @@ import { JitiOptions, JitiResolveOptions } from "jiti";
2
2
  import { TOTP } from "otpauth";
3
3
  import { ChalkInstance } from "chalk";
4
4
  import { Model, ModelStatic } from "arkormx";
5
-
6
5
  //#region src/Logger.d.ts
7
6
  declare class Console {
8
7
  static log: (...args: any[]) => string | void;
@@ -165,6 +164,7 @@ interface EnvRegistry {
165
164
  APP_HOST: string;
166
165
  APP_PORT: number;
167
166
  APP_DEBUG: boolean;
167
+ APP_SECURE: boolean;
168
168
  APP_TIMEZONE: string;
169
169
  APP_LOCALE: typeof locales[number];
170
170
  APP_FALLBACK_LOCALE: typeof locales[number];
@@ -245,7 +245,7 @@ type Primitive = string | number | boolean | null | undefined | Function;
245
245
  type LoggerChalk = keyof ChalkInstance | ChalkInstance | (keyof ChalkInstance)[];
246
246
  type LoggerParseSignature = [string, LoggerChalk][];
247
247
  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;
248
- 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];
248
+ 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];
249
249
  /**
250
250
  * Ouput formater object or format the output
251
251
  *
@@ -294,7 +294,8 @@ type ArkstackErrorShape = Error & {
294
294
  errors?: unknown;
295
295
  getModelName?: () => string;
296
296
  status?: number;
297
- statusCode?: number; /** Custom properties merged into the error response payload. */
297
+ statusCode?: number;
298
+ /** Custom properties merged into the error response payload. */
298
299
  body?: Record<string, unknown>;
299
300
  };
300
301
  interface ArkstackErrorPayload {
@@ -308,7 +309,7 @@ interface ArkstackErrorPayload {
308
309
  }
309
310
  interface HookRegistry {}
310
311
  type Position = 'before' | 'after' | (string & {});
311
- type IHook = { [P in Position]?: (...args: any[]) => void };
312
+ type IHook = { [P in Position]?: (...args: any[]) => void; };
312
313
  type HookName = keyof HookRegistry extends never ? string : keyof HookRegistry | (string & {});
313
314
  type HookFor<N extends string> = N extends keyof HookRegistry ? HookRegistry[N] : IHook;
314
315
  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;
@@ -328,9 +329,9 @@ type PaginationOptions = {
328
329
  perPage: number;
329
330
  };
330
331
  /**
331
- * A single source → destination mapping a package wants to publish into the
332
- * consuming application.
333
- */
332
+ * A single source → destination mapping a package wants to publish into the
333
+ * consuming application.
334
+ */
334
335
  interface PublishEntry {
335
336
  /** Absolute path to the file or directory shipped by the package. */
336
337
  from: string;
@@ -492,11 +493,7 @@ declare function getModel<TModel extends AbstractModelConstructor = ModelConstru
492
493
  */
493
494
  declare function getModelSync<TName extends ModelName>(modelName: TName): ModelRegistry[TName];
494
495
  declare function getModelSync<TModel extends AbstractModelConstructor = ModelConstructor>(modelName: string): TModel;
495
- declare const initializeGlobalContext: ({
496
- Request,
497
- Response,
498
- Session
499
- }?: {
496
+ declare const initializeGlobalContext: ({ Request, Response, Session }?: {
500
497
  Request?: any;
501
498
  Response?: any;
502
499
  Session?: any;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  /// <reference path="./app.d.ts" />
2
- import { A as GlobalConfig, B as LoggerLog, C as DotPath, D as EnvRegistry, E as EnvLookup, F as HookPos, G as PublishConfirmation, H as MergedConfig, I as HookPositions, J as PublishGroup, K as PublishEntry, L as HookRegistry, M as HookArgs, N as HookFor, O as EnvReturn, P as HookName, R as IHook, S as ConfigShape, T as EnvKey, U as PaginationOptions, V as LoggerParseSignature, W as Primitive, X as Logger, Y as UnionToIntersection, _ as ArkstackErrorPayload, a as abortIf, b as Choices, c as getModelSync, d as normalizePositiveInteger, f as perPage, g as AppConfig, h as Encryption, i as abort, j as GlobalEnv, k as FileImporter, l as initializeGlobalContext, m as Hash, n as ModelConstructor, o as assertFound, p as resolvePagination, q as PublishFilter, r as ModelRegistry, s as getModel, t as AbstractModelConstructor, u as isClass, v as ArkstackErrorShape, w as DotPathValue, x as ConfigRegistry, y as Choice, z as LoggerChalk } from "./helpers-CC35u6ti.js";
2
+ import { A as GlobalConfig, B as LoggerLog, C as DotPath, D as EnvRegistry, E as EnvLookup, F as HookPos, G as PublishConfirmation, H as MergedConfig, I as HookPositions, J as PublishGroup, K as PublishEntry, L as HookRegistry, M as HookArgs, N as HookFor, O as EnvReturn, P as HookName, R as IHook, S as ConfigShape, T as EnvKey, U as PaginationOptions, V as LoggerParseSignature, W as Primitive, X as Logger, Y as UnionToIntersection, _ as ArkstackErrorPayload, a as abortIf, b as Choices, c as getModelSync, d as normalizePositiveInteger, f as perPage, g as AppConfig, h as Encryption, i as abort, j as GlobalEnv, k as FileImporter, l as initializeGlobalContext, m as Hash, n as ModelConstructor, o as assertFound, p as resolvePagination, q as PublishFilter, r as ModelRegistry, s as getModel, t as AbstractModelConstructor, u as isClass, v as ArkstackErrorShape, w as DotPathValue, x as ConfigRegistry, y as Choice, z as LoggerChalk } from "./helpers-E_O2UDRn.js";
3
3
  import { Arkstack } from "@arkstack/contract";
4
4
  import pino from "pino";
5
-
6
5
  //#region src/lifecycle.d.ts
7
6
  declare const bindGracefulShutdown: (shutdown: () => Promise<void> | void, defer?: boolean) => void;
8
7
  //#endregion
@@ -17,12 +16,7 @@ declare const bindGracefulShutdown: (shutdown: () => Promise<void> | void, defer
17
16
  * @param defer
18
17
  */
19
18
  declare const bootWithDetectedPort: <TApp, TRoutes = unknown, THandler = unknown>(boot: (port: number) => Promise<void>, preferredPort?: number, app?: Arkstack<TApp, TRoutes, THandler>, defer?: boolean) => Promise<void>;
20
- declare const renderError: ({
21
- message,
22
- stack,
23
- title,
24
- code
25
- }: {
19
+ declare const renderError: ({ message, stack, title, code }: {
26
20
  message?: string;
27
21
  stack?: string;
28
22
  code?: number;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { _ as EnvLoader, a as env, c as nodeEnv, d as resolveRuntimeDir, f as resolveRuntimeModule, g as configLoader, h as ConfigLoader, i as discoverCommands, l as outputDir, m as CONFIG_KEY, n as appUrl, o as importFile, p as toOutputPath, r as config, s as interopDefault, t as appKey, u as rebuildOutput, v as envLoader } from "./system-XvUhJFS0.js";
2
- import { _ as RequestException, b as Hash, c as abortIf, d as getModelSync, f as initializeGlobalContext, g as resolvePagination, h as perPage, l as assertFound, m as normalizePositiveInteger, p as isClass, s as abort, u as getModel, v as AppException, x as Encryption, y as Exception } from "./utils-CaaL-9im.js";
1
+ import { _ as EnvLoader, a as env, c as nodeEnv, d as resolveRuntimeDir, f as resolveRuntimeModule, g as configLoader, h as ConfigLoader, i as discoverCommands, l as outputDir, m as CONFIG_KEY, n as appUrl, o as importFile, p as toOutputPath, r as config, s as interopDefault, t as appKey, u as rebuildOutput, v as envLoader } from "./system-Die_Dv5y.js";
2
+ import { _ as RequestException, b as Hash, c as abortIf, d as getModelSync, f as initializeGlobalContext, g as resolvePagination, h as perPage, l as assertFound, m as normalizePositiveInteger, p as isClass, s as abort, u as getModel, v as AppException, x as Encryption, y as Exception } from "./utils-mymPEYd4.js";
3
3
  import { Hook as Hook$1 } from "@arkstack/foundry";
4
4
  import { Arkstack } from "@arkstack/contract";
5
5
  import { str } from "@h3ravel/support";
@@ -32,7 +32,10 @@ var EnvLoader = class {
32
32
  if (this.loaded) return;
33
33
  this.loaded = true;
34
34
  try {
35
- config({ quiet: true });
35
+ config({
36
+ quiet: true,
37
+ override: process.env.ARKSTACK_ENV_RELOAD === "true"
38
+ });
36
39
  } catch {}
37
40
  }
38
41
  /**
@@ -359,7 +362,8 @@ const rebuildOutput = async () => {
359
362
  force: true
360
363
  });
361
364
  await new Promise((resolveBuild, reject) => {
362
- const child = spawn(process.platform === "win32" ? "pnpm.cmd" : "pnpm", [
365
+ const command = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
366
+ const child = spawn(command, [
363
367
  "exec",
364
368
  "tsdown",
365
369
  "--log-level",
@@ -452,7 +456,8 @@ const discoverCommands = async (subPath = path.join("app", "console", "commands"
452
456
  for (const file of files) {
453
457
  const basename = path.basename(file.name, path.extname(file.name));
454
458
  try {
455
- const command = resolveCommandExport(await importFile(path.join(commandsDir, file.name)), basename);
459
+ const mod = await importFile(path.join(commandsDir, file.name));
460
+ const command = resolveCommandExport(mod, basename);
456
461
  if (command) commands.push(command);
457
462
  } catch (error) {
458
463
  console.error(`[arkstack] Failed to load command "${file.name}":`, error);
@@ -1,22 +1,21 @@
1
- import { a as abortIf, c as getModelSync, d as normalizePositiveInteger, f as perPage, h as Encryption, i as abort, l as initializeGlobalContext, m as Hash, n as ModelConstructor, o as assertFound, p as resolvePagination, r as ModelRegistry, s as getModel, t as AbstractModelConstructor, u as isClass } from "../helpers-CC35u6ti.js";
1
+ import { a as abortIf, c as getModelSync, d as normalizePositiveInteger, f as perPage, h as Encryption, i as abort, l as initializeGlobalContext, m as Hash, n as ModelConstructor, o as assertFound, p as resolvePagination, r as ModelRegistry, s as getModel, t as AbstractModelConstructor, u as isClass } from "../helpers-E_O2UDRn.js";
2
2
  import { Model } from "arkormx";
3
-
4
3
  //#region src/utils/traits.d.ts
5
4
  declare const crc32: (str: string) => number;
6
5
  type ResolveTraitLike<T extends Trait | TypeFactory<Trait>> = T extends TypeFactory<Trait> ? ExtractFactory<ReturnType<T>> : T extends Trait ? ExtractFactory<T> : unknown;
7
6
  type Combine<T extends any[]> = T extends [infer Head, ...infer Tail] ? Head & Combine<Tail> : object;
8
7
  type MapClassesToPrototypes<T extends Array<(new () => any) & {
9
8
  prototype: any;
10
- }>> = { [K in keyof T]: T[K]['prototype'] };
9
+ }>> = { [K in keyof T]: T[K]['prototype']; };
11
10
  type MapClassesToInstances<T extends Array<(new () => any) & {
12
11
  prototype: any;
13
- }>> = { [K in keyof T]: InstanceType<T[K]> };
12
+ }>> = { [K in keyof T]: InstanceType<T[K]>; };
14
13
  type CombineClasses<T extends Array<(new () => any) & {
15
14
  prototype: any;
16
15
  }>> = (new () => Combine<MapClassesToInstances<T>>) & {
17
16
  prototype: Combine<MapClassesToPrototypes<T>>;
18
17
  };
19
- type ResolveTraitLikeArray<T extends Array<Trait | TypeFactory<Trait>>> = CombineClasses<{ [K in keyof T]: ResolveTraitLike<T[K]> }>;
18
+ type ResolveTraitLikeArray<T extends Array<Trait | TypeFactory<Trait>>> = CombineClasses<{ [K in keyof T]: ResolveTraitLike<T[K]>; }>;
20
19
  /**
21
20
  * utility type and function: constructor (function)
22
21
  */
@@ -35,7 +34,7 @@ type TypeFactory<T = any> = () => T;
35
34
  /**
36
35
  * utility type: map an object type into a bare properties type
37
36
  */
38
- type Explode<T = any> = { [P in keyof T]: T[P] };
37
+ type Explode<T = any> = { [P in keyof T]: T[P]; };
39
38
  /**
40
39
  * utility type: convert two arrays of types into an array of union types
41
40
  */
@@ -96,7 +95,7 @@ type DeriveTraitsConsOne<T extends (Trait | TypeFactory<Trait>)> = T extends Tra
96
95
  /**
97
96
  * utility type: derive type constructor: from one or more traits or trait factories
98
97
  */
99
- type DeriveTraitsConsAll<T extends (((Trait | TypeFactory<Trait>)[] | [...(Trait | TypeFactory<Trait>)[], DirectBase]) | undefined)> = T extends [infer Only extends DirectBase] ? DeriveTraitsConsDirectBase<Only> : T extends [...infer Others extends (Trait | TypeFactory<Trait>)[], infer Last extends DirectBase] ? (Others extends [] ? DeriveTraitsConsDirectBase<Last> : DeriveTraitsConsConsMerge<DeriveTraitsConsAll<Others>, /* RECURSION */DeriveTraitsConsDirectBase<Last>>) : T extends (Trait | TypeFactory<Trait>)[] ? (T extends [infer First extends (Trait | TypeFactory<Trait>)] ? (DeriveTraitsConsOne<First>) : (T extends [infer First extends (Trait | TypeFactory<Trait>), ...infer Rest extends (Trait | TypeFactory<Trait>)[]] ? (DeriveTraitsConsConsMerge<DeriveTraitsConsOne<First>, DeriveTraitsConsAll<Rest>>) : never)) : never;
98
+ type DeriveTraitsConsAll<T extends (((Trait | TypeFactory<Trait>)[] | [...(Trait | TypeFactory<Trait>)[], DirectBase]) | undefined)> = T extends [infer Only extends DirectBase] ? DeriveTraitsConsDirectBase<Only> : T extends [...infer Others extends (Trait | TypeFactory<Trait>)[], infer Last extends DirectBase] ? (Others extends [] ? DeriveTraitsConsDirectBase<Last> : DeriveTraitsConsConsMerge<DeriveTraitsConsAll<Others>, /* RECURSION */ DeriveTraitsConsDirectBase<Last>>) : T extends (Trait | TypeFactory<Trait>)[] ? (T extends [infer First extends (Trait | TypeFactory<Trait>)] ? (DeriveTraitsConsOne<First>) : (T extends [infer First extends (Trait | TypeFactory<Trait>), ...infer Rest extends (Trait | TypeFactory<Trait>)[]] ? (DeriveTraitsConsConsMerge<DeriveTraitsConsOne<First>, DeriveTraitsConsAll<Rest>>) : never)) : never;
100
99
  /**
101
100
  * utility type: derive type constructor
102
101
  */
@@ -125,7 +124,7 @@ type DeriveTraitsStatsOne<T extends (Trait | TypeFactory<Trait>)> = T extends Tr
125
124
  /**
126
125
  * utility type: derive type statics: from one or more traits or trait factories
127
126
  */
128
- type DeriveTraitsStatsAll<T extends (((Trait | TypeFactory<Trait>)[] | [...(Trait | TypeFactory<Trait>)[], DirectBase]) | undefined)> = T extends [infer Only extends DirectBase] ? DeriveTraitsStatsDirectBase<Only> : T extends [...infer Others extends (Trait | TypeFactory<Trait>)[], infer Last extends DirectBase] ? (Others extends [] ? DeriveTraitsStatsDirectBase<Last> : DeriveTraitsStatsConsMerge<DeriveTraitsStatsAll<Others>, /* RECURSION */DeriveTraitsStatsDirectBase<Last>>) : T extends (Trait | TypeFactory<Trait>)[] ? (T extends [infer First extends (Trait | TypeFactory<Trait>)] ? (DeriveTraitsStatsOne<First>) : (T extends [infer First extends (Trait | TypeFactory<Trait>), ...infer Rest extends (Trait | TypeFactory<Trait>)[]] ? (DeriveTraitsStatsConsMerge<DeriveTraitsStatsOne<First>, DeriveTraitsStatsAll<Rest>>) : never)) : never;
127
+ type DeriveTraitsStatsAll<T extends (((Trait | TypeFactory<Trait>)[] | [...(Trait | TypeFactory<Trait>)[], DirectBase]) | undefined)> = T extends [infer Only extends DirectBase] ? DeriveTraitsStatsDirectBase<Only> : T extends [...infer Others extends (Trait | TypeFactory<Trait>)[], infer Last extends DirectBase] ? (Others extends [] ? DeriveTraitsStatsDirectBase<Last> : DeriveTraitsStatsConsMerge<DeriveTraitsStatsAll<Others>, /* RECURSION */ DeriveTraitsStatsDirectBase<Last>>) : T extends (Trait | TypeFactory<Trait>)[] ? (T extends [infer First extends (Trait | TypeFactory<Trait>)] ? (DeriveTraitsStatsOne<First>) : (T extends [infer First extends (Trait | TypeFactory<Trait>), ...infer Rest extends (Trait | TypeFactory<Trait>)[]] ? (DeriveTraitsStatsConsMerge<DeriveTraitsStatsOne<First>, DeriveTraitsStatsAll<Rest>>) : never)) : never;
129
128
  /**
130
129
  * utility type: derive type statics
131
130
  */
@@ -1,2 +1,2 @@
1
- import { a as use, b as Hash, c as abortIf, d as getModelSync, f as initializeGlobalContext, g as resolvePagination, h as perPage, i as trait, l as assertFound, m as normalizePositiveInteger, n as crc32, o as uses, p as isClass, r as getTraitMethods, s as abort, t as callTraitMethods, u as getModel, x as Encryption } from "../utils-CaaL-9im.js";
1
+ import { a as use, b as Hash, c as abortIf, d as getModelSync, f as initializeGlobalContext, g as resolvePagination, h as perPage, i as trait, l as assertFound, m as normalizePositiveInteger, n as crc32, o as uses, p as isClass, r as getTraitMethods, s as abort, t as callTraitMethods, u as getModel, x as Encryption } from "../utils-mymPEYd4.js";
2
2
  export { Encryption, Hash, abort, abortIf, assertFound, callTraitMethods, crc32, getModel, getModelSync, getTraitMethods, initializeGlobalContext, isClass, normalizePositiveInteger, perPage, resolvePagination, trait, use, uses };
@@ -1,4 +1,4 @@
1
- import { a as env, f as resolveRuntimeModule, o as importFile, t as appKey } from "./system-XvUhJFS0.js";
1
+ import { a as env, f as resolveRuntimeModule, o as importFile, t as appKey } from "./system-Die_Dv5y.js";
2
2
  import { createRequire } from "node:module";
3
3
  import { createCipheriv, createDecipheriv, createHash, randomBytes } from "node:crypto";
4
4
  import { Arkstack } from "@arkstack/contract";
@@ -41,7 +41,8 @@ var Hash = class {
41
41
  * @returns
42
42
  */
43
43
  static async make(value) {
44
- return await hash(value, await genSalt(10));
44
+ const salt = await genSalt(10);
45
+ return await hash(value, salt);
45
46
  }
46
47
  /**
47
48
  * Verify a value against a hashed value
@@ -209,7 +210,9 @@ async function getModel(modelName) {
209
210
  const isModelModule = (value) => typeof value === "object" && value !== null;
210
211
  const { getUserConfig } = await import("arkormx");
211
212
  const modelPath = getUserConfig().paths?.models || "./src/models";
212
- const model = resolveModelExport(await importFile(resolveRuntimeModule(path.join(path.isAbsolute(modelPath) ? modelPath : path.join(Arkstack.rootDir(), modelPath), modelName))), path.basename(modelName, path.extname(modelName)));
213
+ const sourcePath = path.join(path.isAbsolute(modelPath) ? modelPath : path.join(Arkstack.rootDir(), modelPath), modelName);
214
+ const modulePath = resolveRuntimeModule(sourcePath);
215
+ const model = resolveModelExport(await importFile(modulePath), path.basename(modelName, path.extname(modelName)));
213
216
  if (typeof model !== "function") throw new Error(`Model "${modelName}" not found`);
214
217
  return model;
215
218
  }
@@ -225,7 +228,9 @@ function getModelSync(modelName) {
225
228
  const registeredModel = Arkorm.getRegisteredModels().find((model) => model.name === exportName);
226
229
  if (registeredModel) return registeredModel;
227
230
  const modelPath = getUserConfig().paths?.models || "./src/models";
228
- const model = resolveModelExport(require(resolveRuntimeModule(path.join(path.isAbsolute(modelPath) ? modelPath : path.join(Arkstack.rootDir(), modelPath), modelName))), exportName);
231
+ const sourcePath = path.join(path.isAbsolute(modelPath) ? modelPath : path.join(Arkstack.rootDir(), modelPath), modelName);
232
+ const module = require(resolveRuntimeModule(sourcePath));
233
+ const model = resolveModelExport(module, exportName);
229
234
  if (typeof model !== "function") throw new Error(`Model "${modelName}" not found`);
230
235
  return model;
231
236
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/common",
3
- "version": "0.17.16",
3
+ "version": "0.17.18",
4
4
  "type": "module",
5
5
  "description": "Core utilities, primitives, and shared infrastructure for the Arkstack ecosystem.",
6
6
  "homepage": "https://arkstack.toneflix.net",
@@ -45,10 +45,10 @@
45
45
  "selfsigned": "^2.4.1"
46
46
  },
47
47
  "peerDependencies": {
48
- "@h3ravel/support": "^2.2.4",
49
- "arkormx": "^2.12.0",
50
- "@arkstack/contract": "^0.17.16",
51
- "@arkstack/foundry": "^0.17.16"
48
+ "@h3ravel/support": "^2.2.7",
49
+ "arkormx": "^2.12.8",
50
+ "@arkstack/contract": "^0.17.18",
51
+ "@arkstack/foundry": "^0.17.18"
52
52
  },
53
53
  "optionalDependencies": {
54
54
  "@faker-js/faker": "^10.4.0"