Skip to content

Commit 5c6a5d7

Browse files
author
Jake Champion
committed
feat: add fastly:experimental module which contains all our experimental functions such as includeBytes and enableDebugLogging
1 parent 919bf0d commit 5c6a5d7

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

src/bundle.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,24 @@ let fastlyPlugin = {
1111
})
1212
build.onLoad({ filter: /^.*/, namespace: 'fastly' }, async (args) => {
1313
switch (args.path) {
14-
case 'backend': {return {contents:`export const Backend = globalThis.Backend`}}
15-
case 'cache-override': {return {contents:`export const CacheOverride = globalThis.CacheOverride`}}
16-
case 'config-store': {return {contents:`export const ConfigStore = globalThis.ConfigStore`}}
17-
case 'dictionary': {return {contents:`export const Dictionary = globalThis.Dictionary`}}
18-
case 'env': {return {contents:`export const env = globalThis.fastly.env.get`}}
19-
case 'geolocation': {return {contents:`export const getGeolocationForIpAddress = globalThis.fastly.getGeolocationForIpAddress`}}
20-
case 'logger': {return {contents:`export const Logger = globalThis.Logger`}}
21-
case 'object-store': {return {contents:`export const ObjectStore = globalThis.ObjectStore`}}
14+
case 'backend': { return { contents: `export const Backend = globalThis.Backend;` } }
15+
case 'cache-override': { return { contents: `export const CacheOverride = globalThis.CacheOverride;` } }
16+
case 'config-store': { return { contents: `export const ConfigStore = globalThis.ConfigStore;` } }
17+
case 'dictionary': { return { contents: `export const Dictionary = globalThis.Dictionary;` } }
18+
case 'env': { return { contents: `export const env = globalThis.fastly.env.get;` } }
19+
case 'experimental': {
20+
return {
21+
contents: `
22+
export const includeBytes = globalThis.fastly.includeBytes;
23+
export const enableDebugLogging = globalThis.fastly.enableDebugLogging;
24+
export const setBaseURL = Object.getOwnPropertyDescriptor(globalThis.fastly, 'baseURL').set;
25+
export const setDefaultBackend = Object.getOwnPropertyDescriptor(globalThis.fastly, 'defaultBackend').set;
26+
`
27+
}
28+
}
29+
case 'geolocation': { return { contents: `export const getGeolocationForIpAddress = globalThis.fastly.getGeolocationForIpAddress;` } }
30+
case 'logger': { return { contents: `export const Logger = globalThis.Logger;` } }
31+
case 'object-store': { return { contents: `export const ObjectStore = globalThis.ObjectStore;` } }
2232
}
2333
})
2434
},

test-d/fastly:experimental.test-d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="../types/fastly:experimental.d.ts" />
2+
import { setBaseURL, setDefaultBackend, enableDebugLogging, includeBytes } from "fastly:experimental";
3+
import { expectType } from 'tsd';
4+
5+
expectType<(path: string) => Uint8Array>(includeBytes)
6+
expectType<(enabled: boolean) => void>(enableDebugLogging)
7+
expectType<(base: URL | null | undefined) => void>(setBaseURL)
8+
expectType<(backend: string) => void>(setDefaultBackend)

typedoc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"types/fastly:config-store.d.ts",
1111
"types/fastly:dictionary.d.ts",
1212
"types/fastly:env.d.ts",
13+
"types/fastly:experimental.d.ts",
1314
"types/fastly:geolocation.d.ts",
1415
"types/fastly:logger.d.ts",
1516
"types/fastly:object-store.d.ts",

types/fastly:experimental.d.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @experimental
3+
*/
4+
declare module "fastly:experimental" {
5+
/**
6+
* @experimental
7+
*/
8+
export function setBaseURL(base: URL | null | undefined): void;
9+
/**
10+
* @experimental
11+
*/
12+
export function setDefaultBackend(backend: string): void;
13+
/**
14+
* Causes the Compute@Edge JS runtime environment to log debug information to stdout.
15+
*
16+
* **Note**: This is mostly for internal debugging purposes and will generate highly unstable
17+
* output.
18+
* @experimental
19+
*/
20+
export function enableDebugLogging(enabled: boolean): void;
21+
22+
/**
23+
* Embed a file as a Uint8Array.
24+
*
25+
* @param path - The path to include, relative to the project's top-level directory
26+
*
27+
* **Note**: Can only be used during build-time initialization, not when processing requests.
28+
* @experimental
29+
*/
30+
export function includeBytes(path: string): Uint8Array;
31+
}

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// <reference path="fastly:config-store.d.ts" />
44
/// <reference path="fastly:dictionary.d.ts" />
55
/// <reference path="fastly:env.d.ts" />
6+
/// <reference path="fastly:experimental.d.ts" />
67
/// <reference path="fastly:geolocation.d.ts" />
78
/// <reference path="fastly:logger.d.ts" />
89
/// <reference path="fastly:object-store.d.ts" />

0 commit comments

Comments
 (0)