Skip to content

Commit

Permalink
chore: document stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed May 14, 2024
1 parent 26a5627 commit c67db9c
Showing 1 changed file with 67 additions and 11 deletions.
78 changes: 67 additions & 11 deletions packages/astro/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type ContainerRenderOptions = {
/**
* @param renderers
* @param config
* @param manifest
* @param middleware
*/
function createContainerManifest(
Expand Down Expand Up @@ -123,17 +124,63 @@ function createContainerManifest(
};
}

type AstroContainerOptions = {
mode?: RuntimeMode;
export type AstroContainerUserConfig = Omit<AstroUserConfig, 'integrations' | 'adapter' >

/**
* Options that are used for the entire lifecycle of the current instance of the container.
*/
export type AstroContainerOptions = {
/**
* @default false
*
* @description
*
* Enables streaming during rendering
*
* ## Example
*
* ```js
* const container = await AstroContainer.create({
* streaming: true
* });
* ```
*/
streaming?: boolean;
/**
* @default []
* @description
*
* List or renderers to use when rendering components. Usually they are entry points
*
* ## Example
*
* ```js
* const container = await AstroContainer.create({
* renderers: ["@astrojs/react/server.js"]
* });
* ```
*/
renderers?: SSRLoadedRenderer[];
astroConfig?: AstroUserConfig;
middleware?: MiddlewareHandler;
resolve?: SSRResult['resolve'];
manifest?: SSRManifest;
/**
* @default {}
* @description
*
* A subset of the astro configuration object.
*
* ## Example
*
* ```js
* const container = await AstroContainer.create({
* astroConfig: {
* trailingSlash: "never"
* }
* });
* ```
*/
astroConfig?: AstroContainerUserConfig;
};

export type AstroContainerManifest = Pick<
type AstroContainerManifest = Pick<
SSRManifest,
| 'middleware'
| 'clientDirectives'
Expand Down Expand Up @@ -205,21 +252,30 @@ export class unstable_AstroContainer {
return found;
}

/**
* Creates a new instance of a container.
*
* @param {AstroContainerOptions} containerOptions
*/
static async create(
containerOptions: AstroContainerOptions = {}
): Promise<unstable_AstroContainer> {
const {
astroConfig = ASTRO_CONFIG_DEFAULTS,
streaming = false,
renderers = [],
resolve,
manifest,
} = containerOptions;
const config = await validateConfig(astroConfig, process.cwd(), 'container');
return new unstable_AstroContainer({ streaming, renderers, config, manifest, resolve });
return new unstable_AstroContainer({ streaming, renderers, config });
}

static async createFromManifest(manifest: SSRManifest): Promise<unstable_AstroContainer> {
// NOTE: we keep this private via TS instead via `#` so it's still available on the surface, so we can play with it.
/**
*
* @param manifest
* @private
*/
private static async createFromManifest(manifest: SSRManifest): Promise<unstable_AstroContainer> {
const config = await validateConfig(ASTRO_CONFIG_DEFAULTS, process.cwd(), 'container');
const container = new unstable_AstroContainer({
manifest,
Expand Down

0 comments on commit c67db9c

Please sign in to comment.