Skip to content

Commit

Permalink
dct: add schema_dump
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Nov 6, 2023
1 parent fd1bd54 commit 9c8e830
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
26 changes: 16 additions & 10 deletions src/app/dct/dct.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export interface DCT {
/** Input files */
input: string[],
}) => Promise<void>;

schema_dump: (opts: {
input: string,
}) => Promise<string>;
};

export function initialize(wasm: WasmService): DCT {
Expand All @@ -70,6 +74,7 @@ export function initialize(wasm: WasmService): DCT {
make_cert: wasm.wrapper('assets/dct/make_cert.js', 'make_cert'),
schema_cert: wasm.wrapper('assets/dct/schema_cert.js', 'schema_cert'),
make_bundle: wasm.wrapper('assets/dct/make_bundle.js', 'make_bundle'),
schema_dump: wasm.wrapper('assets/dct/schema_dump.js', 'schema_dump'),
};

return {
Expand All @@ -85,11 +90,7 @@ export function initialize(wasm: WasmService): DCT {
if (opts.output) args.push('-o', opts.output);
args.push(opts.input);

const stdout: string[] = [];
await wrappers.schemaCompile(args, {
print: (line) => stdout.push(line) && window.console.log_play(line),
});
return stdout.join('\n');
return await wasm.stdout(wrappers.schemaCompile, args);
},

schema_info: async (opts) => {
Expand All @@ -101,11 +102,7 @@ export function initialize(wasm: WasmService): DCT {
args.push(opts.input);
if (opts.pubname) args.push(opts.pubname);

const stdout: string[] = [];
await wrappers.schema_info(args, {
print: (line) => stdout.push(line) && window.console.log_play(line),
});
return stdout.join('\n');
return await wasm.stdout(wrappers.schema_info, args);
},

make_cert: async (opts) => {
Expand Down Expand Up @@ -141,6 +138,15 @@ export function initialize(wasm: WasmService): DCT {

await wrappers.make_bundle(args);
},

schema_dump: async (opts) => {
requireProps('schema_dump', opts, ['input']);

const args = [];
args.push(opts.input);

return await wasm.stdout(wrappers.schema_dump, args);
},
};
}

Expand Down
16 changes: 15 additions & 1 deletion src/app/wasm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ type WasmExportName =
'schema_info' |
'make_cert' |
'schema_cert' |
'make_bundle';
'make_bundle' |
'schema_dump';

/** WASM module after load */
type WasmModule = EmscriptenModule & {
Expand Down Expand Up @@ -145,6 +146,19 @@ export class WasmService {
};
}

/**
* Patch a wrapper to return stdout.
* @param fun WASM function to wrap
*/
public async stdout(fun: WasmFunction, ...args: Parameters<WasmFunction>): Promise<string> {
const stdout: string[] = [];
await fun(args[0], {
...args[1] ?? {},
print: (line) => stdout.push(line) && window.console.log_play(line),
});
return stdout.join('\n');
}

/**
* Write a file to the virtual filesystem.
* This can be called before the WASM module is loaded since
Expand Down
7 changes: 3 additions & 4 deletions src/assets/user-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ declare interface DCT {
/** Input files */
input: string[];
}) => Promise<void>;
schema_dump: (opts: {
input: string;
}) => Promise<string>;
}

declare interface DebugEntry {
Expand Down Expand Up @@ -4332,10 +4335,6 @@ declare function toKeyName(name: Name): Name;

declare class Topology {
provider: ForwardingProvider;
readonly DEFAULT_LINK_COLOR = "#3583ea";
readonly DEFAULT_NODE_COLOR = "#a4b7fc";
readonly SELECTED_NODE_COLOR = "#4ee44e";
readonly ACTIVE_NODE_COLOR = "#ffcccb";
readonly nodes: DataSet<INode, "id">;
readonly edges: DataSet<IEdge, "id">;
network: Network;
Expand Down

0 comments on commit 9c8e830

Please sign in to comment.