@arkstack/foundry 0.11.0
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/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Toneflix Technologies Limited
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# `@arkstack/foundry`
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@arkstack/foundry)
|
|
4
|
+
|
|
5
|
+
Extensibility primitives and framework internals for the Arkstack ecosystem. This package provides the tools that shape how Arkstack behaves at runtime. Hooks, lifecycle interception, and utilities designed to extend and adapt the framework without modifying its core.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @arkstack/foundry
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Modules
|
|
14
|
+
|
|
15
|
+
### Hook
|
|
16
|
+
|
|
17
|
+
**`src/Hook.ts`**
|
|
18
|
+
|
|
19
|
+
A global, named hook registry for extending Arkstack internals without modifying core code. Hooks are keyed by name and support positional slots (`before`, `after`, or any custom string).
|
|
20
|
+
|
|
21
|
+
#### `Hook.set(name, hook)`
|
|
22
|
+
|
|
23
|
+
Registers a hook. Multiple calls for the same name are merged.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { Hook } from '@arkstack/foundry';
|
|
27
|
+
|
|
28
|
+
Hook.set('request:handle', {
|
|
29
|
+
before: (ctx) => console.log('before handler'),
|
|
30
|
+
after: (ctx) => console.log('after handler'),
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
#### `Hook.get(name, pos?)`
|
|
35
|
+
|
|
36
|
+
Retrieves the full hook object or a specific positional handler.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
const hook = Hook.get('request:handle'); // IHook | undefined
|
|
40
|
+
const before = Hook.get('request:handle', 'before'); // function | undefined
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### `Hook.has(name, pos?)`
|
|
44
|
+
|
|
45
|
+
Checks whether a hook (or a specific position within it) exists.
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
Hook.has('request:handle'); // true | false
|
|
49
|
+
Hook.has('request:handle', 'after'); // true | false
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### `Hook.unset(name?, pos?)`
|
|
53
|
+
|
|
54
|
+
Removes a hook or a single positional handler. If the hook becomes empty after removal, it is deleted entirely. Called with no arguments, it delegates to `Hook.clear()`.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
Hook.unset('request:handle', 'before'); // removes only the 'before' handler
|
|
58
|
+
Hook.unset('request:handle'); // removes the entire hook
|
|
59
|
+
Hook.unset(); // clears all hooks
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### `Hook.getAll()`
|
|
63
|
+
|
|
64
|
+
Returns all registered hooks as a plain record.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const hooks = Hook.getAll();
|
|
68
|
+
// { 'request:handle': { before: fn, after: fn } }
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### `Hook.clear()`
|
|
72
|
+
|
|
73
|
+
Clears all registered hooks.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface HookRegistry {}
|
|
3
|
+
type Position = 'before' | 'after' | (string & {});
|
|
4
|
+
type IHook = { [P in Position]?: (...args: any[]) => void };
|
|
5
|
+
type HookName = keyof HookRegistry extends never ? string : keyof HookRegistry | (string & {});
|
|
6
|
+
type HookFor<N extends string> = N extends keyof HookRegistry ? HookRegistry[N] : IHook;
|
|
7
|
+
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;
|
|
8
|
+
type HookPositions<N extends string> = N extends keyof HookRegistry ? keyof HookRegistry[N] : Position;
|
|
9
|
+
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[];
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/Hook.d.ts
|
|
12
|
+
declare class Hook {
|
|
13
|
+
private static hooks;
|
|
14
|
+
static set<N extends HookName>(name: N | (string & {}), hook: HookFor<N>): void;
|
|
15
|
+
static has<N extends HookName, P extends HookPositions<N>>(name: N | (string & {}), pos?: P): boolean;
|
|
16
|
+
static get<N extends HookName>(name: N): HookFor<N> | undefined;
|
|
17
|
+
static get<N extends HookName, P extends HookPositions<N>>(name: N, pos: P): HookPos<N, P> | undefined;
|
|
18
|
+
static get<N extends HookName, P extends HookPositions<N>>(name: N, pos: P, ...args: HookArgs<N, P>): void;
|
|
19
|
+
static getAll: () => Record<string, IHook> & HookRegistry;
|
|
20
|
+
static unset<N extends HookName, P extends HookPositions<N>>(name?: N | (string & {}), pos?: P): undefined;
|
|
21
|
+
static clear: () => void;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { Hook, HookArgs, HookFor, HookName, HookPos, HookPositions, HookRegistry, IHook };
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//#region src/Hook.ts
|
|
2
|
+
var Hook = class {
|
|
3
|
+
static hooks = /* @__PURE__ */ new Map();
|
|
4
|
+
/**
|
|
5
|
+
* Hooks define code that should run within defined boundaries to add extra functionalities.
|
|
6
|
+
*
|
|
7
|
+
* @param name
|
|
8
|
+
* @param value
|
|
9
|
+
*/
|
|
10
|
+
static set(name, hook) {
|
|
11
|
+
const oldhook = this.hooks.get(name) ?? {};
|
|
12
|
+
this.hooks.set(name, {
|
|
13
|
+
...oldhook,
|
|
14
|
+
...hook
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check if a hook is defined by name
|
|
19
|
+
*
|
|
20
|
+
* @param name
|
|
21
|
+
*/
|
|
22
|
+
static has(name, pos) {
|
|
23
|
+
if (pos && this.hooks.has(name)) return Boolean(this.get(name, pos));
|
|
24
|
+
return this.hooks.has(name);
|
|
25
|
+
}
|
|
26
|
+
static get(name, pos, ...args) {
|
|
27
|
+
const hook = this.hooks.get(name);
|
|
28
|
+
if (!hook) return void 0;
|
|
29
|
+
if (pos === void 0) return hook;
|
|
30
|
+
const fn = hook[pos];
|
|
31
|
+
if (!fn) return void 0;
|
|
32
|
+
if (args.length > 0) return fn(...args);
|
|
33
|
+
return fn;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Retrieve all defined hooks
|
|
37
|
+
*
|
|
38
|
+
* @param name
|
|
39
|
+
*/
|
|
40
|
+
static getAll = () => {
|
|
41
|
+
const hooks = {};
|
|
42
|
+
for (const [name, value] of this.hooks) hooks[name] = value;
|
|
43
|
+
return hooks;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Remove the defined hook
|
|
47
|
+
*
|
|
48
|
+
* @param name
|
|
49
|
+
*/
|
|
50
|
+
static unset(name, pos) {
|
|
51
|
+
if (name && this.hooks.has(name)) {
|
|
52
|
+
if (pos !== void 0) {
|
|
53
|
+
const hook = this.get(name);
|
|
54
|
+
if (hook?.[pos]) delete hook[pos];
|
|
55
|
+
Object.keys(hook ?? {}).length < 1 && this.hooks.delete(name);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.hooks.delete(name);
|
|
59
|
+
} else this.clear();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Clear all the defined hooks
|
|
63
|
+
*/
|
|
64
|
+
static clear = () => {
|
|
65
|
+
this.hooks.clear();
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { Hook };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/Hook.ts"],"sourcesContent":["import { HookArgs, HookFor, HookName, HookPos, HookPositions, HookRegistry, IHook } from './types'\n\nexport class Hook {\n private static hooks = new Map<string, IHook>()\n\n /**\n * Hooks define code that should run within defined boundaries to add extra functionalities.\n * \n * @param name \n * @param value \n */\n static set<N extends HookName> (\n name: N | (string & {}),\n hook: HookFor<N>\n ) {\n const oldhook = this.hooks.get(name) ?? {}\n\n this.hooks.set(name, {\n ...oldhook,\n ...hook,\n })\n }\n\n /**\n * Check if a hook is defined by name\n * \n * @param name \n */\n static has<N extends HookName, P extends HookPositions<N>> (name: N | (string & {}), pos?: P) {\n if (pos && this.hooks.has(name))\n return Boolean(this.get(name, pos))\n\n return this.hooks.has(name)\n }\n\n /**\n * Retrieve a defined hook by name\n * \n * @param name \n */\n static get<N extends HookName> (name: N): HookFor<N> | undefined\n /**\n * Retrieve a defined hook by name and position\n * \n * @param name \n * @param pos \n */\n static get<N extends HookName, P extends HookPositions<N>> (name: N, pos: P): HookPos<N, P> | undefined\n /**\n * Retrieve a defined hook by name and position the set args for callback\n * \n * @param name \n * @param pos \n */\n static get<N extends HookName, P extends HookPositions<N>> (name: N, pos: P, ...args: HookArgs<N, P>): void\n static get<N extends HookName, P extends HookPositions<N>> (\n name: N,\n pos?: P,\n ...args: HookArgs<N, P> | any[]\n ): HookFor<N> | HookPos<N, P> | undefined {\n const hook = this.hooks.get(name)\n\n if (!hook) return undefined\n if (pos === undefined) return hook as HookFor<N>\n\n const fn = hook[pos]\n if (!fn) return undefined\n\n if (args.length > 0) return fn(...args) as HookPos<N, P>\n\n return fn as HookPos<N, P>\n }\n\n /**\n * Retrieve all defined hooks\n * \n * @param name \n */\n static getAll = () => {\n const hooks: Record<string, IHook> & HookRegistry = {}\n\n for (const [name, value] of this.hooks)\n hooks[name] = value\n\n return hooks\n }\n\n /**\n * Remove the defined hook\n * \n * @param name \n */\n static unset<N extends HookName, P extends HookPositions<N>> (name?: N | (string & {}), pos?: P) {\n if (name && this.hooks.has(name)) {\n if (pos !== undefined) {\n const hook = this.get(name)\n if (hook?.[pos]) delete hook[pos]\n\n return Object.keys(hook ?? {}).length < 1\n ? void this.hooks.delete(name)\n : undefined\n }\n\n this.hooks.delete(name)\n } else this.clear()\n }\n\n /**\n * Clear all the defined hooks\n */\n static clear = () => {\n this.hooks.clear()\n }\n}\n"],"mappings":";AAEA,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
|
2
|
+
"name": "@arkstack/foundry",
|
|
3
|
+
"version": "0.11.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Extensibility primitives and framework internals for the Arkstack ecosystem.",
|
|
6
|
+
"homepage": "https://arkstack.toneflix.net",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/arkstack-tmp/arkstack.git",
|
|
10
|
+
"directory": "packages/foundry"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"foundry",
|
|
14
|
+
"utilities",
|
|
15
|
+
"helpers",
|
|
16
|
+
"logging",
|
|
17
|
+
"configuration",
|
|
18
|
+
"error-handling",
|
|
19
|
+
"validation",
|
|
20
|
+
"arkstack"
|
|
21
|
+
],
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"resources"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./dist/index.js",
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsdown --config-loader unrun",
|
|
35
|
+
"version:patch": "pnpm version patch"
|
|
36
|
+
}
|
|
37
|
+
}
|