mirror of https://github.com/logseq/logseq
feat(plugin): WIP request api
parent
0f62bc22e9
commit
2aa50f6199
|
@ -5,6 +5,8 @@ import { LSPluginCaller } from './LSPlugin.caller'
|
|||
import { LSPluginExperiments } from './modules/LSPlugin.Experiments'
|
||||
import { LSPluginFileStorage } from './modules/LSPlugin.Storage'
|
||||
|
||||
export type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
||||
|
||||
export type PluginLocalIdentity = string
|
||||
|
||||
export type ThemeMode = 'light' | 'dark'
|
||||
|
@ -114,6 +116,23 @@ export type IDatom = [e: number, a: string, v: any, t: number, added: boolean]
|
|||
|
||||
export type IGitResult = { stdout: string; stderr: string; exitCode: number }
|
||||
|
||||
export type IRequestOptions<R = any> = {
|
||||
url: string
|
||||
headers: Record<string, string>
|
||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE'
|
||||
data: any
|
||||
timeout: number
|
||||
dataType: 'json' | 'text' | 'base64' | 'arraybuffer'
|
||||
success: (result: R) => void
|
||||
fail: (err: any) => void
|
||||
final: () => void
|
||||
}
|
||||
|
||||
export type IRequestTask<R> = {
|
||||
abort: () => void
|
||||
promise: Promise<R>
|
||||
}
|
||||
|
||||
export interface AppUserInfo {
|
||||
[key: string]: any
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { LSPluginUser } from '../LSPlugin.user'
|
||||
import { IRequestOptions, IRequestTask, LSPluginUser, WithOptional } from '../LSPlugin.user'
|
||||
import { PluginLocal } from '../LSPlugin.core'
|
||||
import { safeSnakeCase } from '../helpers'
|
||||
|
||||
|
@ -80,6 +80,19 @@ export class LSPluginExperiments {
|
|||
)
|
||||
}
|
||||
|
||||
request<R = any>(options: WithOptional<IRequestOptions<R>, keyof Omit<IRequestOptions, 'url'>>): IRequestTask<R> {
|
||||
const pid = this.ctx.baseInfo.id
|
||||
const reqID = this.invokeExperMethod('request', pid, options)
|
||||
|
||||
// TODO: impl
|
||||
const task = {
|
||||
abort: (() => reqID),
|
||||
promise: Promise.resolve(null)
|
||||
}
|
||||
|
||||
return task
|
||||
}
|
||||
|
||||
ensureHostScope(): any {
|
||||
if (window === top) {
|
||||
throw new Error('Can not access host scope!')
|
||||
|
|
|
@ -808,6 +808,14 @@
|
|||
(plugin-handler/register-extensions-enhancer
|
||||
(keyword pid) type {:enhancer enhancer})))
|
||||
|
||||
(defn ^:export exper_request
|
||||
[pid options]
|
||||
nil)
|
||||
|
||||
(defn ^:export exper_abort_request
|
||||
[req-id]
|
||||
nil)
|
||||
|
||||
;; helpers
|
||||
(defn ^:export query_element_by_id
|
||||
[id]
|
||||
|
|
Loading…
Reference in New Issue