Skip to content

Commit

Permalink
Fix extraction of Blueprint schema
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonpayton committed Nov 26, 2024
1 parent 2119086 commit db8ba54
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/php-wasm/universal/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export type {
} from './php-request-handler';
export { rotatePHPRuntime } from './rotate-php-runtime';
export { writeFiles } from './write-files';
export type { FileTree } from './write-files';
export type { FileTree, FileTreeAsync } from './write-files';

export {
DEFAULT_BASE_URL,
Expand Down
8 changes: 5 additions & 3 deletions packages/php-wasm/universal/src/lib/write-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export interface WriteFilesOptions {
rmRoot?: boolean;
}

// TODO: Consider supporting promised values for content so we can make a lazy version of FileTree
type FileContent = Uint8Array | string | FileTree;
type MaybePromise<T> = T | Promise<T>;

export interface FileTree extends Record<string, MaybePromise<FileContent>> {}
export interface FileTree extends Record<string, FileContent> {}

export interface FileTreeAsync
extends Record<string, MaybePromise<FileContent>> {}

/**
* Writes multiple files to a specified directory in the Playground
Expand All @@ -35,7 +37,7 @@ export interface FileTree extends Record<string, MaybePromise<FileContent>> {}
export async function writeFiles(
php: UniversalPHP,
root: string,
newFiles: MaybePromise<FileTree>,
newFiles: MaybePromise<FileTreeAsync>,
{ rmRoot = false }: WriteFilesOptions = {}
) {
if (rmRoot) {
Expand Down
19 changes: 14 additions & 5 deletions packages/playground/blueprints/src/lib/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
cloneResponseMonitorProgress,
ProgressTracker,
} from '@php-wasm/progress';
import { FileTree, UniversalPHP } from '@php-wasm/universal';
import { FileTree, FileTreeAsync, UniversalPHP } from '@php-wasm/universal';
import { dirname, joinPaths, Semaphore } from '@php-wasm/util';
import {
listDescendantFiles,
Expand All @@ -27,6 +27,12 @@ export type VFSReference = {
/** The path to the file in the VFS */
path: string;
};
export type VFSDirectoryReference = {
/** Identifies the file resource as Virtual File System (VFS) */
resource: 'vfs';
/** The path to the file in the VFS */
path: string;
};
export type LiteralReference = {
/** Identifies the file resource as a literal file */
resource: 'literal';
Expand Down Expand Up @@ -79,13 +85,14 @@ export type BlueprintAssetDirectoryReference = {
};

export interface Directory {
// TODO: I think FileTree contains data that is already read. Can/should we have this lazily read instead?
files: FileTree;
files: FileTreeAsync;
name: string;
}
export type DirectoryLiteralReference = Directory & {
export type DirectoryLiteralReference = {
/** Identifies the file resource as a git directory */
resource: 'literal:directory';
files: FileTree;
name: string;
};

export type FileReference =
Expand All @@ -99,6 +106,7 @@ export type FileReference =
export type DirectoryReference =
| GitDirectoryReference
| DirectoryLiteralReference
| VFSDirectoryReference
| BlueprintAssetDirectoryReference;

export function isResourceReference(ref: any): ref is FileReference {
Expand Down Expand Up @@ -339,7 +347,8 @@ export class BlueprintAssetDirectoryResource extends VFSDirectoryResource {
}
}

export async function createLazyVFSFileTree(
// TODO: Should we export this?
async function createLazyVFSFileTree(
path: string,
playground: UniversalPHP
): Promise<FileTree> {
Expand Down

0 comments on commit db8ba54

Please sign in to comment.