@arkstack/common 0.18.9 → 0.18.10
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.
|
@@ -2,8 +2,8 @@ import { ChannelOptions, Cipher, CipherOptions, Codec, DeriveOptions, DerivedKey
|
|
|
2
2
|
import { NodeCipher } from "@arkstack/encryption/node";
|
|
3
3
|
import { JitiOptions, JitiResolveOptions } from "jiti";
|
|
4
4
|
import { TOTP } from "otpauth";
|
|
5
|
-
import { Model, ModelStatic, RegisteredModelClass, RegisteredModelName, RelatedModelClass } from "arkormx";
|
|
6
5
|
import { ChalkInstance } from "chalk";
|
|
6
|
+
import { Model, ModelStatic, RegisteredModelClass, RegisteredModelName, RelatedModelClass } from "arkormx";
|
|
7
7
|
//#region src/Logger.d.ts
|
|
8
8
|
declare class Console {
|
|
9
9
|
static log: (...args: any[]) => string | void;
|
|
@@ -583,6 +583,15 @@ declare class Hash {
|
|
|
583
583
|
type AbstractModelConstructor<TModel = unknown> = abstract new (attributes?: Record<string, unknown>) => TModel;
|
|
584
584
|
type ModelConstructor<TModel extends Model = Model> = AbstractModelConstructor<TModel> & Pick<ModelStatic<TModel>, keyof ModelStatic<TModel>>;
|
|
585
585
|
interface ModelRegistry {}
|
|
586
|
+
type ModelResolver = (modelName: string) => RelatedModelClass;
|
|
587
|
+
/**
|
|
588
|
+
* Configure the synchronous model resolver used by {@link getModel}.
|
|
589
|
+
*
|
|
590
|
+
* Database integrations should call this during module initialization. Keeping
|
|
591
|
+
* the resolver injectable lets `@arkstack/common` remain usable without loading
|
|
592
|
+
* a specific ORM at runtime.
|
|
593
|
+
*/
|
|
594
|
+
declare const setModelResolver: (resolver: ModelResolver) => void;
|
|
586
595
|
/**
|
|
587
596
|
* Checks and asserts if target is a class
|
|
588
597
|
*
|
|
@@ -630,16 +639,14 @@ declare const resolvePagination: (query: {
|
|
|
630
639
|
/**
|
|
631
640
|
* Synchronously resolve an application model by name.
|
|
632
641
|
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
* the matching constructor.
|
|
642
|
+
* The configured database integration resolves and, when supported, loads the
|
|
643
|
+
* requested model.
|
|
636
644
|
*
|
|
637
645
|
* @param modelName
|
|
638
|
-
* @alias {@link getArkormxModel}
|
|
639
646
|
* @returns
|
|
640
647
|
*/
|
|
641
|
-
declare function getModel
|
|
642
|
-
declare function getModel
|
|
648
|
+
declare function getModel<TName extends RegisteredModelName>(modelName: TName): RegisteredModelClass<TName>;
|
|
649
|
+
declare function getModel<TModel extends RelatedModelClass = RelatedModelClass>(modelName: string): TModel;
|
|
643
650
|
/**
|
|
644
651
|
* Synchronously import an application model by name.
|
|
645
652
|
*
|
|
@@ -647,8 +654,7 @@ declare function getModel$1<TModel extends RelatedModelClass = RelatedModelClass
|
|
|
647
654
|
* Without a registry entry, pass the class type explicitly: `getModel<typeof User>('User')`.
|
|
648
655
|
*
|
|
649
656
|
* @param modelName
|
|
650
|
-
* @
|
|
651
|
-
* @deprecated 0.17.27 - Use {@link getModel} or {@link getArkormxModel}
|
|
657
|
+
* @deprecated 0.17.27 - Use {@link getModel}
|
|
652
658
|
*/
|
|
653
659
|
declare function getModelSync<TName extends RegisteredModelName>(modelName: TName): RegisteredModelClass<TName>;
|
|
654
660
|
declare function getModelSync<TModel extends RelatedModelClass = RelatedModelClass>(modelName: string): TModel;
|
|
@@ -684,4 +690,4 @@ declare const abortIf: <T>(boolean: T, message?: string, code?: number) => asser
|
|
|
684
690
|
*/
|
|
685
691
|
declare const assertFound: <T>(value: T | null | undefined, message: string, code?: number) => asserts value is T;
|
|
686
692
|
//#endregion
|
|
687
|
-
export {
|
|
693
|
+
export { HookPos as $, SealedBox as A, ConfigShape as B, Encryption as C, KeyPair as D, KeyInput as E, ArkstackErrorShape as F, EnvRegistry as G, DotPathValue as H, Choice as I, GlobalConfig as J, EnvReturn as K, Choices as L, SerializedKeyPair as M, AppConfig as N, Keys as O, ArkstackErrorPayload as P, HookName as Q, Concrete as R, DerivedKey as S, FingerprintOptions as T, EnvKey as U, DotPath as V, EnvLookup as W, HookArgs as X, GlobalEnv as Y, HookFor as Z, ChannelOptions as _, abort as a, LoggerParseSignature as at, Codec as b, getModel as c, Primitive as ct, isClass as d, PublishFilter as dt, HookPositions as et, normalizePositiveInteger as f, PublishGroup as ft, Hash as g, setModelResolver as h, ModelResolver as i, LoggerLog as it, SecureChannel as j, NodeCipher as k, getModelSync as l, PublishConfirmation as lt, resolvePagination as m, Logger as mt, ModelConstructor as n, IHook as nt, abortIf as o, MergedConfig as ot, perPage as p, UnionToIntersection as pt, FileImporter as q, ModelRegistry as r, LoggerChalk as rt, assertFound as s, PaginationOptions as st, AbstractModelConstructor as t, HookRegistry as tt, initializeGlobalContext as u, PublishEntry as ut, Cipher as v, EncryptionKey as w, DeriveOptions as x, CipherOptions as y, ConfigRegistry as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference path="./app.d.ts" />
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as HookPos, A as SealedBox, B as ConfigShape, C as Encryption, D as KeyPair, E as KeyInput, F as ArkstackErrorShape, G as EnvRegistry, H as DotPathValue, I as Choice, J as GlobalConfig, K as EnvReturn, L as Choices, M as SerializedKeyPair, N as AppConfig, O as Keys, P as ArkstackErrorPayload, Q as HookName, R as Concrete, S as DerivedKey, T as FingerprintOptions, U as EnvKey, V as DotPath, W as EnvLookup, X as HookArgs, Y as GlobalEnv, Z as HookFor, _ as ChannelOptions, a as abort, at as LoggerParseSignature, b as Codec, c as getModel, ct as Primitive, d as isClass, dt as PublishFilter, et as HookPositions, f as normalizePositiveInteger, ft as PublishGroup, g as Hash, h as setModelResolver, i as ModelResolver, it as LoggerLog, j as SecureChannel, k as NodeCipher, l as getModelSync, lt as PublishConfirmation, m as resolvePagination, mt as Logger, n as ModelConstructor, nt as IHook, o as abortIf, ot as MergedConfig, p as perPage, pt as UnionToIntersection, q as FileImporter, r as ModelRegistry, rt as LoggerChalk, s as assertFound, st as PaginationOptions, t as AbstractModelConstructor, tt as HookRegistry, u as initializeGlobalContext, ut as PublishEntry, v as Cipher, w as EncryptionKey, x as DeriveOptions, y as CipherOptions, z as ConfigRegistry } from "./helpers-D7et2JwN.js";
|
|
3
3
|
import { Arkstack } from "@arkstack/contract";
|
|
4
4
|
import { ForkOptions } from "node:child_process";
|
|
5
5
|
import pino from "pino";
|
|
@@ -533,4 +533,4 @@ declare const devServer: (options: DevServerRunnerOptions) => {
|
|
|
533
533
|
closeWatcher(): Promise<void>;
|
|
534
534
|
};
|
|
535
535
|
//#endregion
|
|
536
|
-
export { AbstractModelConstructor, AppConfig, AppException, ArkstackErrorPayload, ArkstackErrorShape, CONFIG_KEY, type ChannelOptions, Choice, Choices, Cipher, type CipherOptions, Codec, Concrete, ConfigLoader, ConfigRegistry, ConfigShape, type DeriveOptions, type DerivedKey, DevServerRunnerOptions, DotPath, DotPathValue, Encryption, EncryptionKey, EnvKey, EnvLoader, EnvLookup, EnvRegistry, EnvReturn, ErrorHandler, Exception, FileImporter, type FingerprintOptions, GlobalConfig, GlobalEnv, Hash, Hook, HookArgs, HookFor, HookName, HookPos, HookPositions, HookRegistry, IHook, type KeyInput, KeyPair, Keys, Logger, LoggerChalk, LoggerLog, LoggerParseSignature, MergedConfig, ModelConstructor, ModelRegistry, NodeCipher, PaginationOptions, Primitive, PublishConfirmation, PublishEntry, PublishFilter, PublishGroup, Publisher, RequestException, SealedBox, SecureChannel, type SerializedKeyPair, TlsCredentials, UnionToIntersection, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, configLoader, createErrorPayload, devServer, devTlsCredentials, discoverCommands, env, envLoader, getErrorLogger, getModel, getModelSync, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, localNetworkAddress, logUnhandledError, nodeEnv, normalizePositiveInteger, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolvePagination, resolveRuntimeDir, resolveRuntimeModule, serializeError, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
|
|
536
|
+
export { AbstractModelConstructor, AppConfig, AppException, ArkstackErrorPayload, ArkstackErrorShape, CONFIG_KEY, type ChannelOptions, Choice, Choices, Cipher, type CipherOptions, Codec, Concrete, ConfigLoader, ConfigRegistry, ConfigShape, type DeriveOptions, type DerivedKey, DevServerRunnerOptions, DotPath, DotPathValue, Encryption, EncryptionKey, EnvKey, EnvLoader, EnvLookup, EnvRegistry, EnvReturn, ErrorHandler, Exception, FileImporter, type FingerprintOptions, GlobalConfig, GlobalEnv, Hash, Hook, HookArgs, HookFor, HookName, HookPos, HookPositions, HookRegistry, IHook, type KeyInput, KeyPair, Keys, Logger, LoggerChalk, LoggerLog, LoggerParseSignature, MergedConfig, ModelConstructor, ModelRegistry, ModelResolver, NodeCipher, PaginationOptions, Primitive, PublishConfirmation, PublishEntry, PublishFilter, PublishGroup, Publisher, RequestException, SealedBox, SecureChannel, type SerializedKeyPair, TlsCredentials, UnionToIntersection, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, configLoader, createErrorPayload, devServer, devTlsCredentials, discoverCommands, env, envLoader, getErrorLogger, getModel, getModelSync, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, localNetworkAddress, logUnhandledError, nodeEnv, normalizePositiveInteger, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolvePagination, resolveRuntimeDir, resolveRuntimeModule, serializeError, setModelResolver, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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-BH1phDBR.js";
|
|
2
|
-
import { C as
|
|
2
|
+
import { A as SecureChannel, C as Codec, D as Keys, E as KeyPair, O as NodeCipher, S as Cipher, T as EncryptionKey, _ as setModelResolver, b as Exception, c as abortIf, d as getModelSync, f as initializeGlobalContext, g as resolvePagination, h as perPage, k as SealedBox, l as assertFound, m as normalizePositiveInteger, p as isClass, s as abort, u as getModel, v as RequestException, w as Encryption, x as Hash, y as AppException } from "./utils-DbBtlcTv.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";
|
|
@@ -660,4 +660,4 @@ const devServer = (options) => {
|
|
|
660
660
|
};
|
|
661
661
|
};
|
|
662
662
|
//#endregion
|
|
663
|
-
export { AppException, CONFIG_KEY, Cipher, Codec, ConfigLoader, Encryption, EncryptionKey, EnvLoader, ErrorHandler, Exception, Hash, Hook, KeyPair, Keys, Logger, NodeCipher, Publisher, RequestException, SealedBox, SecureChannel, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, configLoader, createErrorPayload, devServer, devTlsCredentials, discoverCommands, env, envLoader, getErrorLogger, getModel, getModelSync, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, localNetworkAddress, logUnhandledError, nodeEnv, normalizePositiveInteger, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolvePagination, resolveRuntimeDir, resolveRuntimeModule, serializeError, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
|
|
663
|
+
export { AppException, CONFIG_KEY, Cipher, Codec, ConfigLoader, Encryption, EncryptionKey, EnvLoader, ErrorHandler, Exception, Hash, Hook, KeyPair, Keys, Logger, NodeCipher, Publisher, RequestException, SealedBox, SecureChannel, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, configLoader, createErrorPayload, devServer, devTlsCredentials, discoverCommands, env, envLoader, getErrorLogger, getModel, getModelSync, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, localNetworkAddress, logUnhandledError, nodeEnv, normalizePositiveInteger, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolvePagination, resolveRuntimeDir, resolveRuntimeModule, serializeError, setModelResolver, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as SealedBox, C as Encryption, D as KeyPair, E as KeyInput, M as SerializedKeyPair, O as Keys, S as DerivedKey, T as FingerprintOptions, _ as ChannelOptions, a as abort, b as Codec, c as getModel, d as isClass, f as normalizePositiveInteger, g as Hash, h as setModelResolver, i as ModelResolver, j as SecureChannel, k as NodeCipher, l as getModelSync, m as resolvePagination, n as ModelConstructor, o as abortIf, p as perPage, r as ModelRegistry, s as assertFound, t as AbstractModelConstructor, u as initializeGlobalContext, v as Cipher, w as EncryptionKey, x as DeriveOptions, y as CipherOptions } from "../helpers-D7et2JwN.js";
|
|
2
2
|
import { Model } from "arkormx";
|
|
3
3
|
//#region src/utils/traits.d.ts
|
|
4
4
|
declare const crc32: (str: string) => number;
|
|
@@ -184,4 +184,4 @@ type Derived<T extends (Trait | TypeFactory<Trait> | Cons)> = T extends TypeFact
|
|
|
184
184
|
*/
|
|
185
185
|
declare function uses<T extends (Trait | TypeFactory<Trait> | Cons)>(instance: unknown, trait: T): instance is Derived<T>;
|
|
186
186
|
//#endregion
|
|
187
|
-
export { AbstractModelConstructor, type ChannelOptions, Cipher, type CipherOptions, Codec, type DeriveOptions, Derived, type DerivedKey, Encryption, EncryptionKey, type FingerprintOptions, Hash, type KeyInput, KeyPair, Keys, ModelConstructor, ModelRegistry, NodeCipher, SealedBox, SecureChannel, type SerializedKeyPair, Trait, abort, abortIf, assertFound, callTraitMethods, crc32, getModel, getModelSync, getTraitMethods, initializeGlobalContext, isClass, normalizePositiveInteger, perPage, resolvePagination, trait, use, uses };
|
|
187
|
+
export { AbstractModelConstructor, type ChannelOptions, Cipher, type CipherOptions, Codec, type DeriveOptions, Derived, type DerivedKey, Encryption, EncryptionKey, type FingerprintOptions, Hash, type KeyInput, KeyPair, Keys, ModelConstructor, ModelRegistry, ModelResolver, NodeCipher, SealedBox, SecureChannel, type SerializedKeyPair, Trait, abort, abortIf, assertFound, callTraitMethods, crc32, getModel, getModelSync, getTraitMethods, initializeGlobalContext, isClass, normalizePositiveInteger, perPage, resolvePagination, setModelResolver, trait, use, uses };
|
package/dist/utils/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
export { Cipher, Codec, Encryption, EncryptionKey, Hash, KeyPair, Keys, NodeCipher, SealedBox, SecureChannel, abort, abortIf, assertFound, callTraitMethods, crc32, getModel, getModelSync, getTraitMethods, initializeGlobalContext, isClass, normalizePositiveInteger, perPage, resolvePagination, trait, use, uses };
|
|
1
|
+
import { A as SecureChannel, C as Codec, D as Keys, E as KeyPair, O as NodeCipher, S as Cipher, T as EncryptionKey, _ as setModelResolver, a as use, c as abortIf, d as getModelSync, f as initializeGlobalContext, g as resolvePagination, h as perPage, i as trait, k as SealedBox, 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, w as Encryption, x as Hash } from "../utils-DbBtlcTv.js";
|
|
2
|
+
export { Cipher, Codec, Encryption, EncryptionKey, Hash, KeyPair, Keys, NodeCipher, SealedBox, SecureChannel, abort, abortIf, assertFound, callTraitMethods, crc32, getModel, getModelSync, getTraitMethods, initializeGlobalContext, isClass, normalizePositiveInteger, perPage, resolvePagination, setModelResolver, trait, use, uses };
|
|
@@ -3,7 +3,6 @@ import { Cipher, Codec, EncryptionKey, KeyPair, Keys, SealedBox, SecureChannel }
|
|
|
3
3
|
import { NodeCipher } from "@arkstack/encryption/node";
|
|
4
4
|
import { Secret, TOTP } from "otpauth";
|
|
5
5
|
import { compare, genSalt, hash } from "bcryptjs";
|
|
6
|
-
import { getModel } from "arkormx";
|
|
7
6
|
//#region src/utils/encryption.ts
|
|
8
7
|
/**
|
|
9
8
|
* Application facing encryption, bound to the app key.
|
|
@@ -329,6 +328,17 @@ var RequestException = class RequestException extends AppException {
|
|
|
329
328
|
};
|
|
330
329
|
//#endregion
|
|
331
330
|
//#region src/utils/helpers.ts
|
|
331
|
+
let modelResolver;
|
|
332
|
+
/**
|
|
333
|
+
* Configure the synchronous model resolver used by {@link getModel}.
|
|
334
|
+
*
|
|
335
|
+
* Database integrations should call this during module initialization. Keeping
|
|
336
|
+
* the resolver injectable lets `@arkstack/common` remain usable without loading
|
|
337
|
+
* a specific ORM at runtime.
|
|
338
|
+
*/
|
|
339
|
+
const setModelResolver = (resolver) => {
|
|
340
|
+
modelResolver = resolver;
|
|
341
|
+
};
|
|
332
342
|
/**
|
|
333
343
|
* Checks and asserts if target is a class
|
|
334
344
|
*
|
|
@@ -369,8 +379,9 @@ const resolvePagination = (query, defaults) => {
|
|
|
369
379
|
perPage: perPage(query, defaults)
|
|
370
380
|
};
|
|
371
381
|
};
|
|
372
|
-
function getModel
|
|
373
|
-
|
|
382
|
+
function getModel(modelName) {
|
|
383
|
+
if (!modelResolver) throw new Error(`No model resolver has been configured. Load your database integration before resolving "${modelName}".`);
|
|
384
|
+
return modelResolver(modelName);
|
|
374
385
|
}
|
|
375
386
|
function getModelSync(modelName) {
|
|
376
387
|
return getModel(modelName);
|
|
@@ -633,4 +644,4 @@ function uses(instance, trait) {
|
|
|
633
644
|
return false;
|
|
634
645
|
}
|
|
635
646
|
//#endregion
|
|
636
|
-
export {
|
|
647
|
+
export { SecureChannel as A, Codec as C, Keys as D, KeyPair as E, NodeCipher as O, Cipher as S, EncryptionKey as T, setModelResolver as _, use as a, Exception as b, abortIf as c, getModelSync as d, initializeGlobalContext as f, resolvePagination as g, perPage as h, trait as i, SealedBox as k, assertFound as l, normalizePositiveInteger as m, crc32 as n, uses as o, isClass as p, getTraitMethods as r, abort as s, callTraitMethods as t, getModel as u, RequestException as v, Encryption as w, Hash as x, AppException as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/common",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Core utilities, primitives, and shared infrastructure for the Arkstack ecosystem.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"otpauth": "^9.5.1",
|
|
44
44
|
"pino": "^10.3.1",
|
|
45
45
|
"selfsigned": "^2.4.1",
|
|
46
|
-
"@arkstack/encryption": "^0.18.
|
|
46
|
+
"@arkstack/encryption": "^0.18.10"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@h3ravel/support": "^2.2.7",
|
|
50
50
|
"arkormx": "^2.12.8",
|
|
51
|
-
"@arkstack/contract": "^0.18.
|
|
52
|
-
"@arkstack/foundry": "^0.18.
|
|
51
|
+
"@arkstack/contract": "^0.18.10",
|
|
52
|
+
"@arkstack/foundry": "^0.18.10"
|
|
53
53
|
},
|
|
54
54
|
"optionalDependencies": {
|
|
55
55
|
"@faker-js/faker": "^10.4.0"
|