@arkstack/common 0.5.1 → 0.5.3
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/README.md +754 -20
- package/dist/app.d.ts +61 -1
- package/dist/faker.d.ts +9 -0
- package/dist/faker.js +20 -0
- package/dist/helpers-BrQ0B-EX.d.ts +109 -0
- package/dist/index.d.ts +662 -49
- package/dist/index.js +129 -275
- package/dist/system-DUaI4u99.js +475 -0
- package/dist/utils/index.d.ts +188 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils-DLifcZWV.js +452 -0
- package/package.json +19 -7
- package/resources/views/error.edge +199 -0
- package/dist/index.js.map +0 -1
package/dist/app.d.ts
CHANGED
|
@@ -1,8 +1,58 @@
|
|
|
1
|
-
import { GlobalConfig, GlobalEnv } from '
|
|
1
|
+
import type { GlobalConfig, GlobalEnv } from '.'
|
|
2
|
+
|
|
3
|
+
interface Stubs {
|
|
4
|
+
api: string;
|
|
5
|
+
model: string;
|
|
6
|
+
resource: string;
|
|
7
|
+
controller: string;
|
|
8
|
+
collection: string;
|
|
9
|
+
apiResource: string;
|
|
10
|
+
}
|
|
2
11
|
|
|
3
12
|
declare global {
|
|
4
13
|
var env: GlobalEnv
|
|
5
14
|
var config: GlobalConfig
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Thows to abort the current request
|
|
18
|
+
*
|
|
19
|
+
* @param message
|
|
20
|
+
* @param code
|
|
21
|
+
* @throws {RequestException}
|
|
22
|
+
*/
|
|
23
|
+
function abort (
|
|
24
|
+
message?: string,
|
|
25
|
+
code?: number
|
|
26
|
+
): void
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Asserts that a boolean condition is true.
|
|
30
|
+
*
|
|
31
|
+
* @param boolean
|
|
32
|
+
* @param message
|
|
33
|
+
* @param code
|
|
34
|
+
* @throws {RequestException} Throws if the boolean condition is true.
|
|
35
|
+
*/
|
|
36
|
+
function abortIf<T> (
|
|
37
|
+
boolean: T,
|
|
38
|
+
message?: string,
|
|
39
|
+
code?: number,
|
|
40
|
+
): asserts boolean is T
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Asserts that a value is not null or undefined.
|
|
44
|
+
*
|
|
45
|
+
* @param value
|
|
46
|
+
* @param message
|
|
47
|
+
* @param code
|
|
48
|
+
* @throws {RequestException} Throws if the value is null or undefined.
|
|
49
|
+
*/
|
|
50
|
+
function assertFound<T> (
|
|
51
|
+
value: T | null | undefined,
|
|
52
|
+
message: string,
|
|
53
|
+
code: number = 404,
|
|
54
|
+
): asserts value is T
|
|
55
|
+
|
|
6
56
|
interface String {
|
|
7
57
|
/**
|
|
8
58
|
* Converts the string to title case.
|
|
@@ -27,4 +77,14 @@ declare global {
|
|
|
27
77
|
}
|
|
28
78
|
}
|
|
29
79
|
|
|
80
|
+
declare module 'resora' {
|
|
81
|
+
interface Config {
|
|
82
|
+
stubs: Stubs;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface ResoraConfig {
|
|
86
|
+
stubs?: Partial<Stubs> | undefined
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
30
90
|
export { }
|
package/dist/faker.d.ts
ADDED
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 };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { TOTP } from "otpauth";
|
|
2
|
+
import { Model, ModelStatic } from "arkormx";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/encryption.d.ts
|
|
5
|
+
declare class Encryption {
|
|
6
|
+
private static readonly algorithm;
|
|
7
|
+
private static getKey;
|
|
8
|
+
static encrypt(value: string): string;
|
|
9
|
+
static decrypt(payload: string): string;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/utils/hash.d.ts
|
|
13
|
+
declare class Hash {
|
|
14
|
+
/**
|
|
15
|
+
* Hash a value using bcrypt
|
|
16
|
+
*
|
|
17
|
+
* @param value
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
static make(value: string): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Verify a value against a hashed value
|
|
23
|
+
*
|
|
24
|
+
* @param value
|
|
25
|
+
* @param hashedValue
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
static verify(value: string, hashedValue: string): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Generate a one-time password (OTP) using TOTP algorithm
|
|
31
|
+
*
|
|
32
|
+
* @param digits The number of digits for the OTP, default is 6.
|
|
33
|
+
* @param label A label to identify the OTP, can be an email or phone number.
|
|
34
|
+
* @param period Interval of time for which a token is valid, in seconds.
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
static otp(digits?: number, label?: string, period?: number): TOTP;
|
|
38
|
+
static totp(secret: string, label: string, issuer?: string, period?: number): TOTP;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/utils/helpers.d.ts
|
|
42
|
+
type AbstractModelConstructor<TModel = unknown> = abstract new (attributes?: Record<string, unknown>) => TModel;
|
|
43
|
+
type ModelConstructor<TModel extends Model = Model> = AbstractModelConstructor<TModel> & Pick<ModelStatic<TModel>, keyof ModelStatic<TModel>>;
|
|
44
|
+
interface ModelRegistry {}
|
|
45
|
+
type ModelName = Extract<keyof ModelRegistry, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Checks and asserts if target is a class
|
|
48
|
+
*
|
|
49
|
+
* @param target
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
declare const isClass: <T = unknown>(target: unknown) => target is new (...args: any[]) => T;
|
|
53
|
+
/**
|
|
54
|
+
* Determine the number of items to return per page based on the provided query parameters.
|
|
55
|
+
*
|
|
56
|
+
* @param query
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
declare const perPage: (query: {
|
|
60
|
+
limit?: number;
|
|
61
|
+
perPage?: number;
|
|
62
|
+
}) => number;
|
|
63
|
+
/**
|
|
64
|
+
* Import an application model by name.
|
|
65
|
+
*
|
|
66
|
+
* Apps can augment `ModelRegistry` to make `getModel('User')` return `typeof User`.
|
|
67
|
+
* Without a registry entry, pass the class type explicitly: `getModel<typeof User>('User')`.
|
|
68
|
+
*
|
|
69
|
+
* @param modelName
|
|
70
|
+
*/
|
|
71
|
+
declare function getModel<TName extends ModelName>(modelName: TName): Promise<ModelRegistry[TName]>;
|
|
72
|
+
declare function getModel<TModel extends AbstractModelConstructor = ModelConstructor>(modelName: string): Promise<TModel>;
|
|
73
|
+
declare const initializeGlobalContext: ({
|
|
74
|
+
Request,
|
|
75
|
+
Response,
|
|
76
|
+
Session
|
|
77
|
+
}?: {
|
|
78
|
+
Request?: any;
|
|
79
|
+
Response?: any;
|
|
80
|
+
Session?: any;
|
|
81
|
+
}) => Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Thows to abort the current request
|
|
84
|
+
*
|
|
85
|
+
* @param message
|
|
86
|
+
* @param code
|
|
87
|
+
* @throws {RequestException}
|
|
88
|
+
*/
|
|
89
|
+
declare const abort: (message?: string, code?: number) => void;
|
|
90
|
+
/**
|
|
91
|
+
* Asserts that a boolean condition is true.
|
|
92
|
+
*
|
|
93
|
+
* @param boolean
|
|
94
|
+
* @param message
|
|
95
|
+
* @param code
|
|
96
|
+
* @throws {RequestException} Throws if the boolean condition is true.
|
|
97
|
+
*/
|
|
98
|
+
declare const abortIf: <T>(boolean: T, message?: string, code?: number) => asserts boolean is T;
|
|
99
|
+
/**
|
|
100
|
+
* Asserts that a value is not null or undefined.
|
|
101
|
+
*
|
|
102
|
+
* @param value
|
|
103
|
+
* @param message
|
|
104
|
+
* @param code
|
|
105
|
+
* @throws {RequestException} Throws if the value is null or undefined.
|
|
106
|
+
*/
|
|
107
|
+
declare const assertFound: <T>(value: T | null | undefined, message: string, code?: number) => asserts value is T;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { abortIf as a, initializeGlobalContext as c, Hash as d, Encryption as f, abort as i, isClass as l, ModelConstructor as n, assertFound as o, ModelRegistry as r, getModel as s, AbstractModelConstructor as t, perPage as u };
|