{
if (!editor) return
- const toCamel = (s) => {
- return s.replace(/([-_][a-z])/gi, ($1) => {
- return $1.toUpperCase().replace('-', '').replace('_', '')
- })
- }
const resourceType = await ResourceService.getResourceType({
workspace: $workspaceStore ?? 'NO_W',
path: name
})
- const tsSchema = compile(resourceType.schema)
- console.log(tsSchema)
- editor.insertAtCursor(`type ${toCamel(capitalize(name))} = ${tsSchema}\n`)
+ if (lang == 'python3') {
+ const pySchema = pythonCompile(resourceType.schema)
+
+ editor.insertAtCursor(`class ${name}(TypedDict):\n${pySchema}\n`)
+ const code = editor.getCode()
+ if (!code.includes('from typing import TypedDict')) {
+ editor.insertAtBeginning('from typing import TypedDict\n')
+ }
+ } else {
+ const tsSchema = compile(resourceType.schema)
+ console.log(tsSchema)
+ editor.insertAtCursor(`type ${toCamel(capitalize(name))} = ${tsSchema}\n`)
+ }
sendUserToast(`${name} inserted at cursor`)
}}
tooltip="Resources Types are the schemas associated with a Resource. They define the structure of the data that is returned from a Resource."
@@ -339,46 +407,51 @@
class="rounded-full w-2 h-2 mx-2 {validCode ? 'bg-green-300' : 'bg-red-300'}"
/>
-
+ {#if showContextVarPicker}
+
+ {/if}
+ {#if showVarPicker}
+
+ {/if}
-
+ {#if showResourcePicker}
+
+ {/if}
-
-
- {#if lang == 'deno'}
+ {#if showResourceTypePicker}