@fastly/compute-js-context 0.4.1 → 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 CHANGED
@@ -7,6 +7,22 @@ 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
+
20
+ ## [0.4.2] - 2025-10-08
21
+
22
+ ### Fixed
23
+
24
+ - Fix typing of Proxy when bindings are empty
25
+
10
26
  ## [0.4.1] - 2025-10-06
11
27
 
12
28
  ### Changed
@@ -19,6 +35,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
35
 
20
36
  - Initial public release
21
37
 
22
- [unreleased]: https://github.com/fastly/compute-js-context/compare/v0.4.1...HEAD
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
40
+ [0.4.2]: https://github.com/fastly/compute-js-context/compare/v0.4.1...v0.4.2
23
41
  [0.4.1]: https://github.com/fastly/compute-js-context/compare/v0.2.0...v0.4.1
24
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: {
@@ -29,9 +28,10 @@ type BindingStringToResourceInstanceTypeMapping = {
29
28
  SecretStore: SecretStore;
30
29
  };
31
30
  export type ResourceInstance<T> = T extends Def<infer K extends keyof BindingStringToResourceInstanceTypeMapping> ? BindingStringToResourceInstanceTypeMapping[K] : never;
32
- export type ContextProxy<T extends BindingsDefs> = {
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 buildContextProxy<T extends BindingsDefs>(context: Context, bindingsDefs: T): ContextProxy<T>;
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 buildContextProxy(context, bindingsDefs) {
29
- const target = {};
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(_, key) {
49
- return getEntry(key);
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(_, key) {
52
- return getEntry(key) !== undefined;
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-context",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Surfaces Fastly Compute environment as a context object",
5
5
  "license": "MIT",
6
6
  "repository": {