@arkstack/common 0.14.18 → 0.14.20

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.
@@ -0,0 +1,9 @@
1
+ import { Faker, ImageModule } from "@faker-js/faker";
2
+ import { PictwoFakerImage } from "@pictwo/faker";
3
+
4
+ //#region src/faker.d.ts
5
+ declare const faker: Faker & {
6
+ image: ImageModule & PictwoFakerImage;
7
+ };
8
+ //#endregion
9
+ export { faker };
package/dist/faker.js ADDED
@@ -0,0 +1,20 @@
1
+ import { v as configLoader } from "./system-DUaI4u99.js";
2
+ import * as fakerLocales from "@faker-js/faker";
3
+ import { Faker } from "@faker-js/faker";
4
+ import { pictwoImage } from "@pictwo/faker";
5
+ //#region src/faker.ts
6
+ const config = globalThis.config ?? ((key, def) => configLoader.resolve(key, def));
7
+ const fallbackLocale = "en";
8
+ const resolveLocale = () => {
9
+ const locale = config("app.locale", fallbackLocale);
10
+ if (typeof locale === "string" && locale in fakerLocales && typeof fakerLocales[locale] === "object") return fakerLocales[locale];
11
+ return fakerLocales[fallbackLocale];
12
+ };
13
+ const fakerInstance = new Faker({ locale: [resolveLocale()].filter(Boolean) });
14
+ const { faker: _, ...image } = fakerInstance.image;
15
+ const faker = {
16
+ ...fakerInstance,
17
+ image: Object.assign({}, image, pictwoImage())
18
+ };
19
+ //#endregion
20
+ export { faker };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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";
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-BrQ0B-EX.js";
3
3
  import { JitiOptions, JitiResolveOptions } from "jiti";
4
4
  import { Arkstack } from "@arkstack/contract";
5
5
  import pino from "pino";
@@ -170,9 +170,105 @@ declare class Logger {
170
170
  static console(): typeof Console;
171
171
  }
172
172
  //#endregion
173
+ //#region src/locales.d.ts
174
+ declare const locales: readonly ["af_ZA", "ar", "az", "bn_BD", "cs_CZ", "cy", "da", "de", "de_AT", "de_CH", "dv", "el", "en", "en_AU", "en_AU_ocker", "en_BORK", "en_CA", "en_GB", "en_GH", "en_HK", "en_IE", "en_IN", "en_NG", "en_US", "en_ZA", "eo", "es", "es_MX", "fa", "fi", "fr", "fr_BE", "fr_CA", "fr_CH", "fr_LU", "fr_SN", "he", "hr", "hu", "hy", "id_ID", "it", "ja", "ka_GE", "ko", "ku_ckb", "ku_kmr_latin", "lv", "mk", "mn_MN_cyrl", "nb_NO", "ne", "nl", "nl_BE", "pl", "pt_BR", "pt_PT", "ro", "ro_MD", "ru", "sk", "sl_SI", "sr_RS_latin", "sv", "ta_IN", "th", "tr", "uk", "ur", "uz_UZ_latin", "vi", "yo_NG", "zh_CN", "zh_TW", "zu_ZA"];
175
+ //#endregion
173
176
  //#region src/types.d.ts
174
177
  interface ConfigRegistry {}
175
- interface EnvRegistry {}
178
+ /**
179
+ * Map of known environment variables to their (coerced) value types.
180
+ *
181
+ * Used to give {@link GlobalEnv | env()} precise return types. Unknown keys fall
182
+ * back to `string`. Augment this interface (declaration merging) to register
183
+ * application-specific variables:
184
+ *
185
+ * ```ts
186
+ * declare module '@arkstack/common' {
187
+ * interface EnvRegistry { MY_FLAG: boolean }
188
+ * }
189
+ * ```
190
+ */
191
+ interface EnvRegistry {
192
+ APP_NAME: string;
193
+ APP_ENV: 'development' | 'production' | 'staging' | 'local';
194
+ APP_KEY: string;
195
+ APP_URL: string;
196
+ APP_HOST: string;
197
+ APP_PORT: number;
198
+ APP_DEBUG: boolean;
199
+ APP_TIMEZONE: string;
200
+ APP_LOCALE: typeof locales[number];
201
+ APP_FALLBACK_LOCALE: typeof locales[number];
202
+ APP_FAKER_LOCALE: typeof locales[number];
203
+ NODE_ENV: 'development' | 'production' | 'test';
204
+ PORT: number;
205
+ HOST: string;
206
+ FRONTEND_URL: string;
207
+ OUTPUT_DIR: string;
208
+ OUTPUT_DIR_DEV: string;
209
+ CONFIG_PATH: string;
210
+ TUNNEL: boolean;
211
+ NGROK_AUTHTOKEN: string;
212
+ NGROK_DOMAIN: string;
213
+ FILESYSTEM_DISK: string;
214
+ CACHE_STORE: string;
215
+ CACHE_PREFIX: string;
216
+ CACHE_TABLE: string;
217
+ QUEUE_CONNECTION: string;
218
+ QUEUE_TABLE: string;
219
+ QUEUE_NAME: string;
220
+ QUEUE_RETRY_AFTER: number;
221
+ REDIS_HOST: string;
222
+ REDIS_PORT: number;
223
+ REDIS_PASSWORD: string;
224
+ REDIS_CACHE_DB: number;
225
+ REDIS_QUEUE_DB: number;
226
+ JWT_EXPIRES_IN: string;
227
+ SESSION_LIFETIME: number;
228
+ TWO_FACTOR_SMS_TTL_MINUTES: number;
229
+ DATABASE_URL: string;
230
+ DB_CONNECTION: string;
231
+ DB_HOST: string;
232
+ DB_PORT: number;
233
+ DB_DATABASE: string;
234
+ DB_USERNAME: string;
235
+ DB_PASSWORD: string;
236
+ MAIL_HOST: string;
237
+ MAIL_PORT: number;
238
+ MAIL_SECURE: boolean;
239
+ MAIL_USERNAME: string;
240
+ MAIL_PASSWORD: string;
241
+ MAIL_FROM_ADDRESS: string;
242
+ MAIL_TEST_ADDRESS: string;
243
+ AWS_ACCESS_KEY_ID: string;
244
+ AWS_SECRET_ACCESS_KEY: string;
245
+ AWS_DEFAULT_REGION: string;
246
+ AWS_BUCKET: string;
247
+ AWS_URL: string;
248
+ AWS_ENDPOINT: string;
249
+ }
250
+ /**
251
+ * App Confifuration
252
+ */
253
+ interface AppConfig {
254
+ env: string;
255
+ key: string;
256
+ url: string;
257
+ host: string;
258
+ name: string;
259
+ frontend_url: string;
260
+ debug: boolean;
261
+ timezone: string;
262
+ locale: typeof locales[number];
263
+ fallback_locale: typeof locales[number];
264
+ faker_locale: typeof locales[number];
265
+ }
266
+ /**
267
+ * Known environment variable names.
268
+ */
269
+ type EnvKey = keyof EnvRegistry & string;
270
+ /** The registered type for a known key, or `string` for an unknown one. */
271
+ type EnvLookup<K extends string> = [K] extends [EnvKey] ? EnvRegistry[K] : string;
176
272
  type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
177
273
  type MergedConfig<X> = UnionToIntersection<X>;
178
274
  type Primitive = string | number | boolean | null | undefined | Function;
@@ -196,8 +292,17 @@ interface LoggerLog {
196
292
  <L extends boolean>(config: LoggerParseSignature, joiner?: string, log?: L, sc?: LoggerChalk): L extends true ? void : string;
197
293
  <L extends boolean>(config?: LoggerParseSignature, joiner?: string, log?: L, sc?: LoggerChalk): L extends true ? void : string | Logger;
198
294
  }
295
+ /**
296
+ * Return type of {@link GlobalEnv | env()}.
297
+ *
298
+ * When an explicit value type `X` is given it wins (backward compatible with
299
+ * `env<boolean>('FLAG')`). Otherwise the type registered for the key `K` is used
300
+ * — falling back to `string` for unknown keys. A provided default `D` is unioned
301
+ * into the result.
302
+ */
303
+ type EnvReturn<X, K extends string, D> = [X] extends [never] ? [D] extends [undefined] ? EnvLookup<K> : EnvLookup<K> | D : [D] extends [undefined] ? X : X | D;
199
304
  interface GlobalEnv {
200
- <X = string, Y = undefined | X>(env: string, defaultValue?: Y): Y extends undefined ? X : Y;
305
+ <X = never, D = undefined, K extends (keyof EnvRegistry | (string & {})) = keyof EnvRegistry>(env: K, defaultValue?: D): EnvReturn<X, K, D>;
201
306
  }
202
307
  type ConfigShape = keyof ConfigRegistry extends never ? Record<string, any> : ConfigRegistry;
203
308
  interface GlobalConfig {
@@ -285,7 +390,6 @@ declare const env: GlobalEnv;
285
390
  * @returns
286
391
  */
287
392
  declare const appUrl: (link?: string) => string;
288
- declare const CONFIG_KEY: unique symbol;
289
393
  /**
290
394
  * Gets the application configuration.
291
395
  *
@@ -589,4 +693,81 @@ declare class Hook {
589
693
  static clear: () => void;
590
694
  }
591
695
  //#endregion
592
- 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, PublishEntry, PublishFilter, PublishGroup, Publisher, RequestException, UnionToIntersection, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, createErrorPayload, discoverCommands, env, getErrorLogger, getModel, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, logUnhandledError, nodeEnv, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolveRuntimeDir, resolveRuntimeModule, serializeError, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
696
+ //#region src/EnvLoader.d.ts
697
+ /**
698
+ * Loads environment variables, reading the `.env` file on first access.
699
+ *
700
+ * The `.env` file is loaded lazily the first time a variable is read, so
701
+ * environment access never depends on a side-effect `import 'dotenv/config'`
702
+ * running first. Import ordering — which linters and bundlers may rewrite —
703
+ * could otherwise place an env-reading module before dotenv has populated
704
+ * `process.env`, leaving that module with default/stale values.
705
+ * `dotenv.config()` never overrides variables already set, so the lazy load is
706
+ * safe alongside other loaders.
707
+ */
708
+ declare class EnvLoader {
709
+ private loaded;
710
+ /**
711
+ * Load the `.env` file once.
712
+ *
713
+ * @returns
714
+ */
715
+ private ensureLoaded;
716
+ /**
717
+ * Read an environment variable, coercing booleans, numbers and `null`, and
718
+ * falling back to `defaultValue` when it is unset.
719
+ *
720
+ * @param name The variable name.
721
+ * @param defaultValue Returned when the variable is unset.
722
+ */
723
+ get<X = never, D = undefined, K extends string = string>(name: K, defaultValue?: D): EnvReturn<X, K, D>;
724
+ }
725
+ /**
726
+ * Shared environment loader backing {@link env}.
727
+ */
728
+ declare const envLoader: EnvLoader;
729
+ //#endregion
730
+ //#region src/ConfigLoader.d.ts
731
+ declare const CONFIG_KEY: unique symbol;
732
+ /**
733
+ * Loads and resolves application configuration from the config directory.
734
+ *
735
+ * Config modules are read once (lazily) from the output directory and cached on
736
+ * a global symbol, then queried by dot-path. A partial config object can also be
737
+ * merged in at runtime.
738
+ */
739
+ declare class ConfigLoader {
740
+ /**
741
+ * The cached config store, shared across instances via a global symbol.
742
+ */
743
+ private get store();
744
+ private set store(value);
745
+ /**
746
+ * Read and cache config modules from the config directory on first use.
747
+ */
748
+ private load;
749
+ /**
750
+ * Resolve the directory to load config modules from.
751
+ *
752
+ * Prefers an explicit `CONFIG_PATH`, then the environment-selected output
753
+ * directory. Falls back to the other build output (`dist` ⇄
754
+ * `.arkstack/build`) so config still loads if the selected directory is
755
+ * missing or transiently emptied — e.g. a concurrent rebuild (`clean: true`)
756
+ * during a test run.
757
+ */
758
+ private resolveConfigDir;
759
+ /**
760
+ * Resolve configuration: read a dot-path value, merge a partial config
761
+ * object, or return the whole config.
762
+ *
763
+ * @param key Dot-path to read, or an object to merge in.
764
+ * @param defaultValue Returned when a string key is not found.
765
+ */
766
+ resolve<X extends ConfigRegistry | unknown = unknown, P extends DotPath<X> | undefined = undefined>(key?: P, defaultValue?: any): any;
767
+ }
768
+ /**
769
+ * Shared config loader backing {@link config}.
770
+ */
771
+ declare const configLoader: ConfigLoader;
772
+ //#endregion
773
+ export { AbstractModelConstructor, AppConfig, AppException, ArkstackErrorPayload, ArkstackErrorShape, CONFIG_KEY, ConfigLoader, ConfigRegistry, ConfigShape, DotPath, DotPathValue, Encryption, EnvKey, EnvLoader, EnvLookup, EnvRegistry, EnvReturn, ErrorHandler, Exception, FileImporter, GlobalConfig, GlobalEnv, Hash, Hook, HookArgs, HookFor, HookName, HookPos, HookPositions, HookRegistry, IHook, Logger, LoggerChalk, LoggerLog, LoggerParseSignature, MergedConfig, ModelConstructor, ModelRegistry, Primitive, PublishEntry, PublishFilter, PublishGroup, Publisher, RequestException, UnionToIntersection, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, configLoader, createErrorPayload, discoverCommands, env, envLoader, getErrorLogger, getModel, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, logUnhandledError, nodeEnv, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolveRuntimeDir, resolveRuntimeModule, serializeError, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import { A as resolveRuntimeDir, C as discoverCommands, D as nodeEnv, E as interopDefault, M as toOutputPath, O as outputDir, S as config, T as importFile, _ as Hash, b as appKey, c as abortIf, d as initializeGlobalContext, f as isClass, g as Exception, h as AppException, j as resolveRuntimeModule, k as rebuildOutput, l as assertFound, m as RequestException, p as perPage, s as abort, u as getModel, v as Encryption, w as env, x as appUrl, y as CONFIG_KEY } from "./utils-DJQAOLbx.js";
1
+ import { _ as ConfigLoader, a as env, c as nodeEnv, d as resolveRuntimeDir, f as resolveRuntimeModule, g as CONFIG_KEY, h as envLoader, i as discoverCommands, l as outputDir, m as EnvLoader, n as appUrl, o as importFile, p as toOutputPath, r as config, s as interopDefault, t as appKey, u as rebuildOutput, v as configLoader } from "./system-DUaI4u99.js";
2
+ import { _ as Hash, c as abortIf, d as initializeGlobalContext, f as isClass, g as Exception, h as AppException, l as assertFound, m as RequestException, p as perPage, s as abort, u as getModel, v as Encryption } from "./utils-Df3nH1sG.js";
2
3
  import { Hook as Hook$1 } from "@arkstack/foundry";
3
- import { str } from "@h3ravel/support";
4
4
  import { Arkstack } from "@arkstack/contract";
5
+ import { str } from "@h3ravel/support";
5
6
  import path from "node:path";
6
7
  import { ModelNotFoundException } from "arkormx";
7
8
  import { detect } from "detect-port";
@@ -529,4 +530,4 @@ var Hook = class {
529
530
  };
530
531
  };
531
532
  //#endregion
532
- export { AppException, CONFIG_KEY, Encryption, ErrorHandler, Exception, Hash, Hook, Logger, Publisher, RequestException, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, createErrorPayload, discoverCommands, env, getErrorLogger, getModel, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, logUnhandledError, nodeEnv, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolveRuntimeDir, resolveRuntimeModule, serializeError, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
533
+ export { AppException, CONFIG_KEY, ConfigLoader, Encryption, EnvLoader, ErrorHandler, Exception, Hash, Hook, Logger, Publisher, RequestException, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, configLoader, createErrorPayload, discoverCommands, env, envLoader, getErrorLogger, getModel, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, logUnhandledError, nodeEnv, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolveRuntimeDir, resolveRuntimeModule, serializeError, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };