Skip to content

Commit

Permalink
feat: add fastly:experimental module which contains all our experimen…
Browse files Browse the repository at this point in the history
…tal functions such as includeBytes and enableDebugLogging
  • Loading branch information
JakeChampion committed Nov 30, 2022
1 parent 919bf0d commit 5c6a5d7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/bundle.js
Expand Up @@ -11,14 +11,24 @@ let fastlyPlugin = {
})
build.onLoad({ filter: /^.*/, namespace: 'fastly' }, async (args) => {
switch (args.path) {
case 'backend': {return {contents:`export const Backend = globalThis.Backend`}}
case 'cache-override': {return {contents:`export const CacheOverride = globalThis.CacheOverride`}}
case 'config-store': {return {contents:`export const ConfigStore = globalThis.ConfigStore`}}
case 'dictionary': {return {contents:`export const Dictionary = globalThis.Dictionary`}}
case 'env': {return {contents:`export const env = globalThis.fastly.env.get`}}
case 'geolocation': {return {contents:`export const getGeolocationForIpAddress = globalThis.fastly.getGeolocationForIpAddress`}}
case 'logger': {return {contents:`export const Logger = globalThis.Logger`}}
case 'object-store': {return {contents:`export const ObjectStore = globalThis.ObjectStore`}}
case 'backend': { return { contents: `export const Backend = globalThis.Backend;` } }
case 'cache-override': { return { contents: `export const CacheOverride = globalThis.CacheOverride;` } }
case 'config-store': { return { contents: `export const ConfigStore = globalThis.ConfigStore;` } }
case 'dictionary': { return { contents: `export const Dictionary = globalThis.Dictionary;` } }
case 'env': { return { contents: `export const env = globalThis.fastly.env.get;` } }
case 'experimental': {
return {
contents: `
export const includeBytes = globalThis.fastly.includeBytes;
export const enableDebugLogging = globalThis.fastly.enableDebugLogging;
export const setBaseURL = Object.getOwnPropertyDescriptor(globalThis.fastly, 'baseURL').set;
export const setDefaultBackend = Object.getOwnPropertyDescriptor(globalThis.fastly, 'defaultBackend').set;
`
}
}
case 'geolocation': { return { contents: `export const getGeolocationForIpAddress = globalThis.fastly.getGeolocationForIpAddress;` } }
case 'logger': { return { contents: `export const Logger = globalThis.Logger;` } }
case 'object-store': { return { contents: `export const ObjectStore = globalThis.ObjectStore;` } }
}
})
},
Expand Down
8 changes: 8 additions & 0 deletions test-d/fastly:experimental.test-d.ts
@@ -0,0 +1,8 @@
/// <reference path="../types/fastly:experimental.d.ts" />
import { setBaseURL, setDefaultBackend, enableDebugLogging, includeBytes } from "fastly:experimental";
import { expectType } from 'tsd';

expectType<(path: string) => Uint8Array>(includeBytes)
expectType<(enabled: boolean) => void>(enableDebugLogging)
expectType<(base: URL | null | undefined) => void>(setBaseURL)
expectType<(backend: string) => void>(setDefaultBackend)
1 change: 1 addition & 0 deletions typedoc.json
Expand Up @@ -10,6 +10,7 @@
"types/fastly:config-store.d.ts",
"types/fastly:dictionary.d.ts",
"types/fastly:env.d.ts",
"types/fastly:experimental.d.ts",
"types/fastly:geolocation.d.ts",
"types/fastly:logger.d.ts",
"types/fastly:object-store.d.ts",
Expand Down
31 changes: 31 additions & 0 deletions types/fastly:experimental.d.ts
@@ -0,0 +1,31 @@
/**
* @experimental
*/
declare module "fastly:experimental" {
/**
* @experimental
*/
export function setBaseURL(base: URL | null | undefined): void;
/**
* @experimental
*/
export function setDefaultBackend(backend: string): void;
/**
* Causes the Compute@Edge JS runtime environment to log debug information to stdout.
*
* **Note**: This is mostly for internal debugging purposes and will generate highly unstable
* output.
* @experimental
*/
export function enableDebugLogging(enabled: boolean): void;

/**
* Embed a file as a Uint8Array.
*
* @param path - The path to include, relative to the project's top-level directory
*
* **Note**: Can only be used during build-time initialization, not when processing requests.
* @experimental
*/
export function includeBytes(path: string): Uint8Array;
}
1 change: 1 addition & 0 deletions types/index.d.ts
Expand Up @@ -3,6 +3,7 @@
/// <reference path="fastly:config-store.d.ts" />
/// <reference path="fastly:dictionary.d.ts" />
/// <reference path="fastly:env.d.ts" />
/// <reference path="fastly:experimental.d.ts" />
/// <reference path="fastly:geolocation.d.ts" />
/// <reference path="fastly:logger.d.ts" />
/// <reference path="fastly:object-store.d.ts" />
Expand Down

0 comments on commit 5c6a5d7

Please sign in to comment.