-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1891 from polywrap/wrap-golang-patches
fix: various fixes in golang bindings such that wrap-test-harness passes
- Loading branch information
Showing
35 changed files
with
788 additions
and
2,570 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
packages/schema/bind/src/bindings/golang/transforms/appendImportedTypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { | ||
Abi, | ||
EnumRef, | ||
ObjectRef, | ||
ModuleDefinition, | ||
ObjectDefinition, | ||
} from "@polywrap/wrap-manifest-types-js"; | ||
import { AbiTransforms } from "@polywrap/schema-parse"; | ||
|
||
interface State { | ||
importedTypes: Map<string, string>; | ||
moduleDef?: ModuleDefinition; | ||
objectDef?: ObjectDefinition; | ||
} | ||
|
||
export function appendImportedTypes(): AbiTransforms { | ||
const state: State = { | ||
importedTypes: new Map(), | ||
}; | ||
|
||
const addImportedTypeRef = (def: EnumRef | ObjectRef) => { | ||
const importType = state.importedTypes.get(def.type); | ||
|
||
if (importType) { | ||
if (state.moduleDef) { | ||
const importedTypes: string[] = | ||
(state.moduleDef as any).importedTypes || []; | ||
if (importedTypes.indexOf(importType) === -1) { | ||
importedTypes.push(importType); | ||
} | ||
state.moduleDef = { | ||
...state.moduleDef, | ||
importedTypes, | ||
} as ModuleDefinition; | ||
} | ||
|
||
if (state.objectDef) { | ||
const importedTypes: string[] = | ||
(state.objectDef as any).importedTypes || []; | ||
if (importedTypes.indexOf(importType) === -1) { | ||
importedTypes.push(importType); | ||
} | ||
state.objectDef = { | ||
...state.objectDef, | ||
importedTypes, | ||
} as ObjectDefinition; | ||
} | ||
} | ||
|
||
return def; | ||
}; | ||
|
||
return { | ||
enter: { | ||
Abi: (abi: Abi) => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
state.importedTypes = abi.importedTypes; | ||
return abi; | ||
}, | ||
ModuleDefinition: (def: ModuleDefinition) => { | ||
state.moduleDef = def; | ||
return def; | ||
}, | ||
ObjectDefinition: (def: ObjectDefinition) => { | ||
if (!state.moduleDef) { | ||
state.objectDef = def; | ||
} | ||
|
||
return def; | ||
}, | ||
EnumRef: (def: EnumRef) => { | ||
return addImportedTypeRef(def); | ||
}, | ||
ObjectRef: (def: ObjectRef) => { | ||
return addImportedTypeRef(def); | ||
}, | ||
}, | ||
leave: { | ||
ModuleDefinition: (def: ModuleDefinition) => { | ||
const newDef = state.moduleDef || def; | ||
state.moduleDef = undefined; | ||
return newDef; | ||
}, | ||
ObjectDefinition: (def: ObjectDefinition) => { | ||
const newDef = state.objectDef || def; | ||
state.objectDef = undefined; | ||
return newDef; | ||
}, | ||
}, | ||
}; | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/schema/bind/src/bindings/golang/transforms/extractImportedTypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import { | ||
Abi, | ||
ImportedEnumDefinition, | ||
ImportedEnvDefinition, | ||
ImportedModuleDefinition, | ||
ImportedObjectDefinition, | ||
} from "@polywrap/wrap-manifest-types-js"; | ||
import { AbiTransforms } from "@polywrap/schema-parse"; | ||
|
||
interface State { | ||
importedTypes: Map<string, string>; | ||
} | ||
|
||
export function extractImportedTypes(): AbiTransforms { | ||
const state: State = { | ||
importedTypes: new Map(), | ||
}; | ||
|
||
return { | ||
enter: { | ||
ImportedEnumDefinition: (def: ImportedEnumDefinition) => { | ||
state.importedTypes = state.importedTypes.set(def.type, def.namespace); | ||
return def; | ||
}, | ||
ImportedEnvDefinition: (def: ImportedEnvDefinition) => { | ||
state.importedTypes = state.importedTypes.set(def.type, def.namespace); | ||
return def; | ||
}, | ||
ImportedModuleDefinition: (def: ImportedModuleDefinition) => { | ||
state.importedTypes = state.importedTypes.set(def.type, def.namespace); | ||
return def; | ||
}, | ||
ImportedObjectDefinition: (def: ImportedObjectDefinition) => { | ||
state.importedTypes = state.importedTypes.set(def.type, def.namespace); | ||
return def; | ||
}, | ||
}, | ||
leave: { | ||
Abi(abi: Abi) { | ||
return { | ||
...abi, | ||
importedTypes: state.importedTypes, | ||
}; | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./appendImportedTypes"; | ||
export * from "./extractImportedTypes"; | ||
export * from "./moduleNeedsTypes"; | ||
export * from "./moduleNeedsImportedTypes"; |
129 changes: 0 additions & 129 deletions
129
packages/schema/bind/src/bindings/golang/transforms/moduleNeedsImportedTypes.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.