Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dylibso/xtp-bindgen",
"version": "1.0.0-rc.7",
"version": "1.0.0-rc.8",
"description": "XTP bindgen helper library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
83 changes: 38 additions & 45 deletions src/normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface Export {
}

export function isExport(e: any): e is Export {
return parser.isSimpleExport(e) || parser.isComplexExport(e)
return !!e.name
}

// These are the same for now
Expand Down Expand Up @@ -208,58 +208,51 @@ function normalizeV1Schema(parsed: parser.V1Schema): XtpSchema {
for (const name in parsed.exports) {
let ex = parsed.exports[name]

if (parser.isComplexExport(ex)) {
const normEx = ex as Export
normEx.name = name
const normEx = ex as Export
normEx.name = name

if (ex.input?.$ref) {
const path = `#/exports/${name}/input`
if (ex.input?.$ref) {
const path = `#/exports/${name}/input`

normalizeProp(
normEx.input!,
querySchemaRef(schemas, ex.input.$ref, path),
path
)
}
if (ex.input?.items?.$ref) {
const path = `#/exports/${name}/input/items`
normalizeProp(
normEx.input!,
querySchemaRef(schemas, ex.input.$ref, path),
path
)
}
if (ex.input?.items?.$ref) {
const path = `#/exports/${name}/input/items`

normalizeProp(
normEx.input!.items!,
querySchemaRef(schemas, ex.input.items.$ref, path),
path
)
}
normalizeProp(
normEx.input!.items!,
querySchemaRef(schemas, ex.input.items.$ref, path),
path
)
}

if (ex.output?.$ref) {
const path = `#/exports/${name}/output`
if (ex.output?.$ref) {
const path = `#/exports/${name}/output`

normalizeProp(
normEx.output!,
querySchemaRef(schemas, ex.output.$ref, path),
path
)
}
if (ex.output?.items?.$ref) {
const path = `#/exports/${name}/output/items`
normalizeProp(
normEx.output!,
querySchemaRef(schemas, ex.output.$ref, path),
path
)
}
if (ex.output?.items?.$ref) {
const path = `#/exports/${name}/output/items`

normalizeProp(
normEx.output!.items!,
querySchemaRef(schemas, ex.output.items.$ref, path),
path
)
}
normalizeProp(
normEx.output!.items!,
querySchemaRef(schemas, ex.output.items.$ref, path),
path
)
}

validateArrayItems(normEx.input?.items, `#/exports/${name}/input/items`);
validateArrayItems(normEx.output?.items, `#/exports/${name}/output/items`);
validateArrayItems(normEx.input?.items, `#/exports/${name}/input/items`);
validateArrayItems(normEx.output?.items, `#/exports/${name}/output/items`);

exports.push(normEx)
} else if (parser.isSimpleExport(ex)) {
// it's just a name
exports.push({ name })
} else {
throw new ValidationError("Unable to match export to a simple or a complex export", `#/exports/${name}`);
}
exports.push(normEx)
}

// denormalize all the imports
Expand Down
14 changes: 2 additions & 12 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,12 @@ type VUnknownSchema = V0Schema | V1Schema

export type Version = 'v0' | 'v1-draft';

export type Export = SimpleExport | ComplexExport;

// for now, imports and exports look the same
export type Import = ComplexExport

export function isComplexExport(exportItem: Export): exportItem is ComplexExport {
return typeof exportItem === 'object' && 'description' in exportItem;
}

export function isSimpleExport(exportItem: Export): exportItem is SimpleExport {
return typeof exportItem === 'object';
}
export type Import = Export

export type SimpleExport = string;

export interface ComplexExport {
export interface Export {
name: string;
description?: string;
codeSamples?: CodeSample[];
Expand Down