@leyyo/proxy 1.0.1
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 +31 -0
- package/dist/index.const.d.ts +1 -0
- package/dist/index.const.js +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.foretell.d.ts +1 -0
- package/dist/index.foretell.js +5 -0
- package/dist/index.js +5 -0
- package/dist/index.loader.d.ts +1 -0
- package/dist/index.loader.js +7 -0
- package/dist/index.types.d.ts +115 -0
- package/dist/index.types.js +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +2 -0
- package/dist/proxy.handler.d.ts +5 -0
- package/dist/proxy.handler.js +70 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Mustafa Yelmer
|
|
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,31 @@
|
|
|
1
|
+
# Leyyo: Proxy
|
|
2
|
+
Proxy library for Leyyo framework
|
|
3
|
+
|
|
4
|
+
## Import
|
|
5
|
+
- `npm i @leyyo/proxy`
|
|
6
|
+
|
|
7
|
+
## Usage (Runtime)
|
|
8
|
+
|
|
9
|
+
## Test Cases
|
|
10
|
+
| Test Case | Error | Message | Method |
|
|
11
|
+
|-----------|----------------|-----------------------------------------------------------|--------------------------------------|
|
|
12
|
+
|
|
13
|
+
## Standards
|
|
14
|
+
- Language: `TS`
|
|
15
|
+
- Eslint: `Yes`
|
|
16
|
+
- Static Code Analysis: `Yes` *IntelliJ Code Inspections*
|
|
17
|
+
- DDD - Document Driven: `Yes`
|
|
18
|
+
- DDD - Domain Driven: `Yes`
|
|
19
|
+
- EDD - Exception Driven: `Yes`
|
|
20
|
+
- TDD - Test Driven: `Yes`
|
|
21
|
+
- LDD - Log Driven: `Yes`
|
|
22
|
+
- 12FA - 12 Factor-App: `50%` *Partially*
|
|
23
|
+
|
|
24
|
+
## Dependencies
|
|
25
|
+
### NO
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
### Prepared by
|
|
29
|
+
- Mustafa Yelmer
|
|
30
|
+
- mustafayelmer(at)gmail.com
|
|
31
|
+
- `2022-07-08`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const KEY_PROXY_LINK: unique symbol;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const KEY_PROXY_LINK = Symbol.for('leyyo::proxy:link');
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const foretell_leyyoProxy: (() => void)[];
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const loader_leyyoProxy: import("@leyyo/common").LoaderLike;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { defineLoader } from "@leyyo/common";
|
|
2
|
+
import { FQN } from "./internal.js";
|
|
3
|
+
import { loader_leyyoCommon } from "@leyyo/common";
|
|
4
|
+
// noinspection JSUnusedGlobalSymbols
|
|
5
|
+
export const loader_leyyoProxy = defineLoader(FQN, ...loader_leyyoCommon,
|
|
6
|
+
// instances
|
|
7
|
+
() => import('./proxy.handler.js').then(m => m.proxyHandler));
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy handler
|
|
3
|
+
* */
|
|
4
|
+
export interface ProxyHandlerLike {
|
|
5
|
+
/**
|
|
6
|
+
* Returns proxied, if it's not proxied then returns self
|
|
7
|
+
*
|
|
8
|
+
* Generics:
|
|
9
|
+
* - `S`: type of source
|
|
10
|
+
*
|
|
11
|
+
* @param {any} source
|
|
12
|
+
* @param {symbol} type
|
|
13
|
+
* @param {boolean?} ignoreIfAbsent
|
|
14
|
+
* @return {any}
|
|
15
|
+
* */
|
|
16
|
+
get<S>(source: S, type: symbol, ignoreIfAbsent?: boolean): S;
|
|
17
|
+
/**
|
|
18
|
+
* Source is proxied or not?
|
|
19
|
+
*
|
|
20
|
+
* Generics:
|
|
21
|
+
* - `S`: type of source
|
|
22
|
+
*
|
|
23
|
+
* @param {any} source
|
|
24
|
+
* @param {symbol} type
|
|
25
|
+
* @return {boolean}
|
|
26
|
+
* */
|
|
27
|
+
has<S>(source: S, type: symbol): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Returns all types of proxies
|
|
30
|
+
*
|
|
31
|
+
* Generics:
|
|
32
|
+
* - `S`: type of source
|
|
33
|
+
*
|
|
34
|
+
* @param {any} source
|
|
35
|
+
* @param {boolean?} ignoreIfAbsent
|
|
36
|
+
* @return {Map<symbol, any>}
|
|
37
|
+
* */
|
|
38
|
+
getAll<S>(source: S, ignoreIfAbsent?: boolean): Map<symbol, any>;
|
|
39
|
+
/**
|
|
40
|
+
* Sets proxy, it means that source -> target
|
|
41
|
+
*
|
|
42
|
+
* Generics:
|
|
43
|
+
* - `S`: type of source
|
|
44
|
+
*
|
|
45
|
+
* @param {any} source
|
|
46
|
+
* @param {any} target
|
|
47
|
+
* @param {symbol} type
|
|
48
|
+
* @return {boolean}
|
|
49
|
+
* */
|
|
50
|
+
set<S>(source: S, target: S, type: symbol): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Returns `inherited by` or `successor` or `descendant`
|
|
53
|
+
* - if it is not inherited by (no successor, no descendant) then returns self
|
|
54
|
+
*
|
|
55
|
+
* Generics:
|
|
56
|
+
* - `S`: type of source
|
|
57
|
+
*
|
|
58
|
+
* @param {any} source
|
|
59
|
+
* @return {any}
|
|
60
|
+
* */
|
|
61
|
+
getInheritedBy<S>(source: S): S;
|
|
62
|
+
/**
|
|
63
|
+
* has source `inherited by` or `successor`
|
|
64
|
+
*
|
|
65
|
+
* Generics:
|
|
66
|
+
* - `S`: type of source
|
|
67
|
+
*
|
|
68
|
+
* @param {any} source
|
|
69
|
+
* @return {boolean}
|
|
70
|
+
* */
|
|
71
|
+
hasInheritedBy<S>(source: S): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Sets `inherited by` or `successor`
|
|
74
|
+
*
|
|
75
|
+
* Generics:
|
|
76
|
+
* - `S`: type of source
|
|
77
|
+
*
|
|
78
|
+
* @param {any} source
|
|
79
|
+
* @param {any} target
|
|
80
|
+
* @return {boolean}
|
|
81
|
+
* */
|
|
82
|
+
setInheritedBy<S>(source: S, target: S): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Returns `inherits` or `predecessor` or `ancestor`
|
|
85
|
+
* - if it does not inherit (no predecessor, no ancestor) then returns self
|
|
86
|
+
*
|
|
87
|
+
* Generics:
|
|
88
|
+
* - `S`: type of source
|
|
89
|
+
*
|
|
90
|
+
* @param {any} source
|
|
91
|
+
* @return {any}
|
|
92
|
+
* */
|
|
93
|
+
getInherits<S>(source: S): S;
|
|
94
|
+
/**
|
|
95
|
+
* has source `inherits` or `predecessor`
|
|
96
|
+
* *
|
|
97
|
+
* Generics:
|
|
98
|
+
* - `S`: type of source
|
|
99
|
+
*
|
|
100
|
+
* @param {any} source
|
|
101
|
+
* @return {boolean}
|
|
102
|
+
* */
|
|
103
|
+
hasInherits<S>(source: S): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Sets `inherits` or `predecessor`
|
|
106
|
+
*
|
|
107
|
+
* Generics:
|
|
108
|
+
* - `S`: type of source
|
|
109
|
+
*
|
|
110
|
+
* @param {any} source
|
|
111
|
+
* @param {any} target
|
|
112
|
+
* @return {boolean}
|
|
113
|
+
* */
|
|
114
|
+
setInherits<S>(source: S, target: S): boolean;
|
|
115
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const NME: string, FQN: string, VER: string, CNF: import("@leyyo/common").LeyyoConfig;
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { FQN } from "./internal.js";
|
|
2
|
+
import { getProp, setFqn, setProp } from "@leyyo/common";
|
|
3
|
+
import { KEY_PROXY_LINK } from "./index.const.js";
|
|
4
|
+
const INHERITS = Symbol.for('leyyo::proxy:inherits');
|
|
5
|
+
const INHERITED_BY = Symbol.for('leyyo::proxy:inherited-by');
|
|
6
|
+
class ProxyHandler {
|
|
7
|
+
// region general
|
|
8
|
+
/** @inheritDoc */
|
|
9
|
+
get(source, type, ignoreIfAbsent) {
|
|
10
|
+
const map = this.getAll(source, ignoreIfAbsent);
|
|
11
|
+
return map ? map.get(type) : undefined;
|
|
12
|
+
}
|
|
13
|
+
/** @inheritDoc */
|
|
14
|
+
has(source, type) {
|
|
15
|
+
return this.getAll(source)?.has(type);
|
|
16
|
+
}
|
|
17
|
+
/** @inheritDoc */
|
|
18
|
+
getAll(source, ignoreIfAbsent) {
|
|
19
|
+
let map = getProp(source, KEY_PROXY_LINK);
|
|
20
|
+
if (map && map instanceof Map) {
|
|
21
|
+
return map;
|
|
22
|
+
}
|
|
23
|
+
if (ignoreIfAbsent) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
map = new Map();
|
|
27
|
+
setProp(source, KEY_PROXY_LINK, map);
|
|
28
|
+
return map;
|
|
29
|
+
}
|
|
30
|
+
/** @inheritDoc */
|
|
31
|
+
set(source, target, type) {
|
|
32
|
+
const map = this.getAll(source);
|
|
33
|
+
const exists = map.has(type);
|
|
34
|
+
map.set(type, target);
|
|
35
|
+
return exists;
|
|
36
|
+
}
|
|
37
|
+
// endregion general
|
|
38
|
+
// region inherited-by
|
|
39
|
+
/** @inheritDoc */
|
|
40
|
+
getInheritedBy(source) {
|
|
41
|
+
return this.get(source, INHERITED_BY, true) ?? source;
|
|
42
|
+
}
|
|
43
|
+
/** @inheritDoc */
|
|
44
|
+
hasInheritedBy(source) {
|
|
45
|
+
return this.has(source, INHERITED_BY);
|
|
46
|
+
}
|
|
47
|
+
/** @inheritDoc */
|
|
48
|
+
setInheritedBy(source, target) {
|
|
49
|
+
return this.set(source, target, INHERITED_BY);
|
|
50
|
+
}
|
|
51
|
+
// endregion inherited-by
|
|
52
|
+
// region inherits
|
|
53
|
+
/** @inheritDoc */
|
|
54
|
+
getInherits(source) {
|
|
55
|
+
return this.get(source, INHERITS, true) ?? source;
|
|
56
|
+
}
|
|
57
|
+
/** @inheritDoc */
|
|
58
|
+
hasInherits(source) {
|
|
59
|
+
return this.has(source, INHERITS);
|
|
60
|
+
}
|
|
61
|
+
/** @inheritDoc */
|
|
62
|
+
setInherits(source, target) {
|
|
63
|
+
return this.set(source, target, INHERITS);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Proxy handler instance
|
|
68
|
+
* */
|
|
69
|
+
export const proxyHandler = new ProxyHandler();
|
|
70
|
+
setFqn(ProxyHandler, FQN);
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leyyo/proxy",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Leyyo proxy library",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"proxy"
|
|
7
|
+
],
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/leyyonet/proxy.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/leyyonet/proxy.git/issues",
|
|
14
|
+
"email": "mustafayelmer@gmail.com"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/leyyonet/proxy.git/#readme",
|
|
17
|
+
"author": "Mustafa Yelmer <mustafayelmer@gmail.com>",
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clear": "rimraf dist",
|
|
22
|
+
"lint": "eslint src/**/*.ts",
|
|
23
|
+
"asset": "node -r ts-node/register commands/assets.js",
|
|
24
|
+
"build": "npm run clear && tsc && npm run asset",
|
|
25
|
+
"test": "npx jest --config=jest.json --clearCache && npx jest --config=jest.json --verbose",
|
|
26
|
+
"test:watch": "jest --watch --config=jest.json",
|
|
27
|
+
"test:coverage": "jest --config=jest.json --coverage --coverageDirectory=coverage",
|
|
28
|
+
"~publish": "npm run build && npm publish -access=public"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist/*"
|
|
32
|
+
],
|
|
33
|
+
"license": "ISC",
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@babel/preset-env": "^7.29.0",
|
|
36
|
+
"@babel/preset-typescript": "^7.27.0",
|
|
37
|
+
"@eslint/js": "^9.33.0",
|
|
38
|
+
"@jest/globals": "^29.7.0",
|
|
39
|
+
"@types/jest": "^30.0.0",
|
|
40
|
+
"@types/node": "^24.2.1",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^8.39.1",
|
|
42
|
+
"@typescript-eslint/parser": "^8.39.1",
|
|
43
|
+
"eslint": "^9.33.0",
|
|
44
|
+
"eslint-config-prettier": "^10.1.8",
|
|
45
|
+
"eslint-config-standard": "^17.1.0",
|
|
46
|
+
"eslint-plugin-import": "^2.32.0",
|
|
47
|
+
"eslint-plugin-jsdoc": "^54.0.0",
|
|
48
|
+
"eslint-plugin-node": "^11.1.0",
|
|
49
|
+
"husky": "^9.1.7",
|
|
50
|
+
"jest": "^29.7.0",
|
|
51
|
+
"prettier": "^3.6.2",
|
|
52
|
+
"rimraf": "^6.0.1",
|
|
53
|
+
"test": "^3.3.0",
|
|
54
|
+
"ts-jest": "^29.4.1",
|
|
55
|
+
"ts-node": "^10.9.2",
|
|
56
|
+
"typescript": "^5.9.2",
|
|
57
|
+
"typescript-eslint": "^8.39.1"
|
|
58
|
+
},
|
|
59
|
+
"overrides": {
|
|
60
|
+
"eslint-config-standard": {
|
|
61
|
+
"eslint": "^9.33.0"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@leyyo/common": "^1.3.16"
|
|
66
|
+
}
|
|
67
|
+
}
|