@fastly/compute-js-context 0.4.2 → 0.5.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/CHANGELOG.md +12 -1
- package/build/proxy.d.ts +2 -2
- package/build/proxy.js +24 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2025-10-14
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- BREAKING: Make build context proxy create the context internally
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- Make proxy object possible to extend an existing object
|
|
19
|
+
|
|
10
20
|
## [0.4.2] - 2025-10-08
|
|
11
21
|
|
|
12
22
|
### Fixed
|
|
@@ -25,7 +35,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
25
35
|
|
|
26
36
|
- Initial public release
|
|
27
37
|
|
|
28
|
-
[unreleased]: https://github.com/fastly/compute-js-context/compare/v0.
|
|
38
|
+
[unreleased]: https://github.com/fastly/compute-js-context/compare/v0.5.0...HEAD
|
|
39
|
+
[0.5.0]: https://github.com/fastly/compute-js-context/compare/v0.4.2...v0.5.0
|
|
29
40
|
[0.4.2]: https://github.com/fastly/compute-js-context/compare/v0.4.1...v0.4.2
|
|
30
41
|
[0.4.1]: https://github.com/fastly/compute-js-context/compare/v0.2.0...v0.4.1
|
|
31
42
|
[0.2.0]: https://github.com/fastly/compute-js-context/releases/tag/v0.2.0
|
package/build/proxy.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { ConfigStore } from 'fastly:config-store';
|
|
|
4
4
|
import type { KVStore } from 'fastly:kv-store';
|
|
5
5
|
import type { Logger } from 'fastly:logger';
|
|
6
6
|
import type { SecretStore } from 'fastly:secret-store';
|
|
7
|
-
import type { Context } from './index.js';
|
|
8
7
|
type Def<T extends string> = T | `${T}:${string}`;
|
|
9
8
|
type Defs<T extends string> = T extends string ? Def<T> : never;
|
|
10
9
|
declare const BindingStringToContextKeyMapping: {
|
|
@@ -32,6 +31,7 @@ export type ResourceInstance<T> = T extends Def<infer K extends keyof BindingStr
|
|
|
32
31
|
export type ContextProxy<T extends BindingsDefs> = keyof T extends never ? Record<string, never> : {
|
|
33
32
|
[K in keyof T]: ResourceInstance<T[K]>;
|
|
34
33
|
};
|
|
35
|
-
export declare function
|
|
34
|
+
export declare function buildContextProxyOn<TTarget extends object, T extends BindingsDefs>(target: TTarget, bindingsDefs: T): (TTarget & ContextProxy<T>);
|
|
35
|
+
export declare function buildContextProxy<T extends BindingsDefs>(bindingsDefs: T): ContextProxy<T>;
|
|
36
36
|
export {};
|
|
37
37
|
//# sourceMappingURL=proxy.d.ts.map
|
package/build/proxy.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
+
import { createContext } from './index.js';
|
|
5
6
|
const BindingStringToContextKeyMapping = {
|
|
6
7
|
Acl: 'ACLS',
|
|
7
8
|
Backend: 'BACKENDS',
|
|
@@ -25,10 +26,10 @@ function getResourceName(key, typeName) {
|
|
|
25
26
|
const [, seg,] = typeName.split(':');
|
|
26
27
|
return seg ?? key;
|
|
27
28
|
}
|
|
28
|
-
export function
|
|
29
|
-
const
|
|
29
|
+
export function buildContextProxyOn(target, bindingsDefs) {
|
|
30
|
+
const context = createContext();
|
|
30
31
|
const getEntry = (key) => {
|
|
31
|
-
if (typeof key !== "string") {
|
|
32
|
+
if (typeof key !== "string" || !(key in bindingsDefs)) {
|
|
32
33
|
return undefined;
|
|
33
34
|
}
|
|
34
35
|
const typeName = bindingsDefs[key];
|
|
@@ -45,12 +46,28 @@ export function buildContextProxy(context, bindingsDefs) {
|
|
|
45
46
|
return contextEntry[resourceName];
|
|
46
47
|
};
|
|
47
48
|
const handler = {
|
|
48
|
-
get(
|
|
49
|
-
|
|
49
|
+
get(target, key, receiver) {
|
|
50
|
+
if (typeof key !== "string") {
|
|
51
|
+
return Reflect.get(target, key, receiver);
|
|
52
|
+
}
|
|
53
|
+
const entry = getEntry(key);
|
|
54
|
+
if (entry !== undefined) {
|
|
55
|
+
return entry;
|
|
56
|
+
}
|
|
57
|
+
return Reflect.get(target, key, receiver);
|
|
50
58
|
},
|
|
51
|
-
has(
|
|
52
|
-
|
|
59
|
+
has(target, key) {
|
|
60
|
+
if (typeof key !== "string") {
|
|
61
|
+
return Reflect.has(target, key);
|
|
62
|
+
}
|
|
63
|
+
if (getEntry(key) !== undefined) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return Reflect.has(target, key);
|
|
53
67
|
},
|
|
54
68
|
};
|
|
55
69
|
return new Proxy(target, handler);
|
|
56
70
|
}
|
|
71
|
+
export function buildContextProxy(bindingsDefs) {
|
|
72
|
+
return buildContextProxyOn({}, bindingsDefs);
|
|
73
|
+
}
|