@fastly/compute-js-context 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/CHANGELOG.md +15 -1
- package/README.md +15 -3
- package/package.json +1 -1
- package/build/bindings.d.ts +0 -37
- package/build/bindings.js +0 -52
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.3] - 2026-01-07
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Release using CI
|
|
15
|
+
|
|
16
|
+
## [0.5.2] - 2025-10-16
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Updated README
|
|
21
|
+
|
|
10
22
|
## [0.5.1] - 2025-10-14
|
|
11
23
|
|
|
12
24
|
### Fixed
|
|
@@ -41,7 +53,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
41
53
|
|
|
42
54
|
- Initial public release
|
|
43
55
|
|
|
44
|
-
[unreleased]: https://github.com/fastly/compute-js-context/compare/v0.5.
|
|
56
|
+
[unreleased]: https://github.com/fastly/compute-js-context/compare/v0.5.3...HEAD
|
|
57
|
+
[0.5.3]: https://github.com/fastly/compute-js-context/compare/v0.5.2...v0.5.3
|
|
58
|
+
[0.5.2]: https://github.com/fastly/compute-js-context/compare/v0.5.1...v0.5.2
|
|
45
59
|
[0.5.1]: https://github.com/fastly/compute-js-context/compare/v0.5.0...v0.5.1
|
|
46
60
|
[0.5.0]: https://github.com/fastly/compute-js-context/compare/v0.4.2...v0.5.0
|
|
47
61
|
[0.4.2]: https://github.com/fastly/compute-js-context/compare/v0.4.1...v0.4.2
|
package/README.md
CHANGED
|
@@ -124,16 +124,29 @@ Creates the main immutable `Context`. Each sub-object is a `Proxy` that:
|
|
|
124
124
|
- **Returns `undefined`** for names that don’t exist (except for `ENV`, which returns `''`)
|
|
125
125
|
- **Is not enumerable** by design (don’t rely on `Object.keys`)
|
|
126
126
|
|
|
127
|
-
### `buildContextProxy<T>(
|
|
127
|
+
### `buildContextProxy<T>(bindingsDefs: T): ContextProxy<T>`
|
|
128
128
|
|
|
129
129
|
Creates a custom, strongly-typed proxy object based on your definitions.
|
|
130
130
|
|
|
131
|
-
- `context`: An instance of the main `Context` object
|
|
132
131
|
- `bindingsDefs`: A `const` object defining your desired bindings
|
|
133
132
|
- **Key**: The property name you want on your final `contextProxy` object
|
|
134
133
|
- **Value**: A string in the format `'ResourceType'` or `'ResourceType:actual-name'`
|
|
135
134
|
- **Returns**: A proxy object `contextProxy` with your custom bindings. Accessing a property on this object looks up the resource from the main `Context`
|
|
136
135
|
|
|
136
|
+
### Type `ContentProxy<T>`
|
|
137
|
+
|
|
138
|
+
Defines a type that represents the content proxy, inferred from your bindings definitions.
|
|
139
|
+
|
|
140
|
+
### (Advanced) `buildContextProxyOn<C, T>(target: C, bindingsDefs: T): C & ContextProxy<T>`
|
|
141
|
+
|
|
142
|
+
Extends the passed-in object with a custom, strongly-typed proxy object based on your definitions.
|
|
143
|
+
|
|
144
|
+
- `target`: An object to extend
|
|
145
|
+
- `bindingsDefs`: A `const` object defining your desired bindings
|
|
146
|
+
- **Key**: The property name you want on your final `contextProxy` object
|
|
147
|
+
- **Value**: A string in the format `'ResourceType'` or `'ResourceType:actual-name'`
|
|
148
|
+
- **Returns**: A proxy object `contextProxy` that extends `target` with your custom bindings. Accessing a property on this object looks up the resource from the main `Context` before falling back to `target`.
|
|
149
|
+
|
|
137
150
|
### Context Categories & Shapes
|
|
138
151
|
|
|
139
152
|
> These are the raw shapes available on the main `Context` object.
|
|
@@ -152,7 +165,6 @@ Creates a custom, strongly-typed proxy object based on your definitions.
|
|
|
152
165
|
- **Don’t mutate** the context or its sub-objects; it’s intentionally `Readonly`
|
|
153
166
|
- **Expect `undefined`** for missing resources and code accordingly (`?.`/guard)
|
|
154
167
|
|
|
155
|
-
|
|
156
168
|
## Issues
|
|
157
169
|
|
|
158
170
|
If you encounter any non-security-related bug or unexpected behavior, please [file an issue][bug] using the bug report template.
|
package/package.json
CHANGED
package/build/bindings.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Acl } from 'fastly:acl';
|
|
2
|
-
import type { Backend } from 'fastly:backend';
|
|
3
|
-
import type { ConfigStore } from 'fastly:config-store';
|
|
4
|
-
import type { KVStore } from 'fastly:kv-store';
|
|
5
|
-
import type { Logger } from 'fastly:logger';
|
|
6
|
-
import type { SecretStore } from 'fastly:secret-store';
|
|
7
|
-
import type { Context } from './index.js';
|
|
8
|
-
type Def<T extends string> = T | `${T}:${string}`;
|
|
9
|
-
type Defs<T extends string> = T extends string ? Def<T> : never;
|
|
10
|
-
declare const BindingStringToContextKeyMapping: {
|
|
11
|
-
readonly Acl: "ACLS";
|
|
12
|
-
readonly Backend: "BACKENDS";
|
|
13
|
-
readonly ConfigStore: "CONFIG_STORES";
|
|
14
|
-
readonly env: "ENV";
|
|
15
|
-
readonly KVStore: "KV_STORES";
|
|
16
|
-
readonly Logger: "LOGGERS";
|
|
17
|
-
readonly SecretStore: "SECRET_STORES";
|
|
18
|
-
};
|
|
19
|
-
export type ResourceType = keyof typeof BindingStringToContextKeyMapping;
|
|
20
|
-
export type BindingsString = Defs<ResourceType>;
|
|
21
|
-
export type EnvBindingsDefs = Record<string, BindingsString>;
|
|
22
|
-
type BindingStringToResourceInstanceTypeMapping = {
|
|
23
|
-
Acl: Acl;
|
|
24
|
-
Backend: Backend;
|
|
25
|
-
ConfigStore: ConfigStore;
|
|
26
|
-
env: string;
|
|
27
|
-
KVStore: KVStore;
|
|
28
|
-
Logger: Logger;
|
|
29
|
-
SecretStore: SecretStore;
|
|
30
|
-
};
|
|
31
|
-
export type ResourceInstance<T> = T extends Def<infer K extends keyof BindingStringToResourceInstanceTypeMapping> ? BindingStringToResourceInstanceTypeMapping[K] : never;
|
|
32
|
-
export type BuildBindings<T extends EnvBindingsDefs> = {
|
|
33
|
-
[K in keyof T]: ResourceInstance<T[K]>;
|
|
34
|
-
};
|
|
35
|
-
export declare function buildEnvironment<T extends EnvBindingsDefs>(context: Context, envBindingsDefs: T): BuildBindings<T>;
|
|
36
|
-
export {};
|
|
37
|
-
//# sourceMappingURL=bindings.d.ts.map
|
package/build/bindings.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const BindingStringToContextKeyMapping = {
|
|
2
|
-
Acl: 'ACLS',
|
|
3
|
-
Backend: 'BACKENDS',
|
|
4
|
-
ConfigStore: 'CONFIG_STORES',
|
|
5
|
-
env: 'ENV',
|
|
6
|
-
KVStore: 'KV_STORES',
|
|
7
|
-
Logger: 'LOGGERS',
|
|
8
|
-
SecretStore: 'SECRET_STORES',
|
|
9
|
-
};
|
|
10
|
-
function isResourceType(resourceType) {
|
|
11
|
-
return resourceType in BindingStringToContextKeyMapping;
|
|
12
|
-
}
|
|
13
|
-
function getResourceType(typeName) {
|
|
14
|
-
const [resourceType,] = typeName.split(':');
|
|
15
|
-
if (isResourceType(resourceType)) {
|
|
16
|
-
return resourceType;
|
|
17
|
-
}
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
function getResourceName(key, typeName) {
|
|
21
|
-
const [, seg,] = typeName.split(':');
|
|
22
|
-
return seg ?? key;
|
|
23
|
-
}
|
|
24
|
-
export function buildEnvironment(context, envBindingsDefs) {
|
|
25
|
-
const target = {};
|
|
26
|
-
const getEntry = (key) => {
|
|
27
|
-
if (typeof key !== "string") {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
const typeName = envBindingsDefs[key];
|
|
31
|
-
const resourceType = getResourceType(typeName);
|
|
32
|
-
if (resourceType == null) {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
const resourceName = getResourceName(key, typeName);
|
|
36
|
-
const contextKey = BindingStringToContextKeyMapping[resourceType];
|
|
37
|
-
const contextEntry = context[contextKey];
|
|
38
|
-
if (contextEntry == null) {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
return contextEntry[resourceName];
|
|
42
|
-
};
|
|
43
|
-
const handler = {
|
|
44
|
-
get(_, key) {
|
|
45
|
-
return getEntry(key);
|
|
46
|
-
},
|
|
47
|
-
has(_, key) {
|
|
48
|
-
return getEntry(key) !== undefined;
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
return new Proxy(target, handler);
|
|
52
|
-
}
|