@wetoria/siyuan-sdk 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +44 -0
  2. package/dist/api/archive/index.d.ts +12 -0
  3. package/dist/api/archive/index.d.ts.map +1 -0
  4. package/dist/api/archive/index.js +8 -0
  5. package/dist/api/archive/index.js.map +1 -0
  6. package/dist/api/asset/index.d.ts +12 -0
  7. package/dist/api/asset/index.d.ts.map +1 -0
  8. package/dist/api/asset/index.js +10 -0
  9. package/dist/api/asset/index.js.map +1 -0
  10. package/dist/api/attr/index.d.ts +39 -0
  11. package/dist/api/attr/index.d.ts.map +1 -0
  12. package/dist/api/attr/index.js +17 -0
  13. package/dist/api/attr/index.js.map +1 -0
  14. package/dist/api/block/index.d.ts +91 -0
  15. package/dist/api/block/index.d.ts.map +1 -0
  16. package/dist/api/block/index.js +87 -0
  17. package/dist/api/block/index.js.map +1 -0
  18. package/dist/api/convert/index.d.ts +12 -0
  19. package/dist/api/convert/index.d.ts.map +1 -0
  20. package/dist/api/convert/index.js +5 -0
  21. package/dist/api/convert/index.js.map +1 -0
  22. package/dist/api/export/index.d.ts +18 -0
  23. package/dist/api/export/index.d.ts.map +1 -0
  24. package/dist/api/export/index.js +12 -0
  25. package/dist/api/export/index.js.map +1 -0
  26. package/dist/api/file/index.d.ts +27 -0
  27. package/dist/api/file/index.d.ts.map +1 -0
  28. package/dist/api/file/index.js +27 -0
  29. package/dist/api/file/index.js.map +1 -0
  30. package/dist/api/filetree/index.d.ts +50 -0
  31. package/dist/api/filetree/index.d.ts.map +1 -0
  32. package/dist/api/filetree/index.js +47 -0
  33. package/dist/api/filetree/index.js.map +1 -0
  34. package/dist/api/index.d.ts +38 -0
  35. package/dist/api/index.d.ts.map +1 -0
  36. package/dist/api/index.js +17 -0
  37. package/dist/api/index.js.map +1 -0
  38. package/dist/api/network/index.d.ts +12 -0
  39. package/dist/api/network/index.d.ts.map +1 -0
  40. package/dist/api/network/index.js +12 -0
  41. package/dist/api/network/index.js.map +1 -0
  42. package/dist/api/notebook/index.d.ts +48 -0
  43. package/dist/api/notebook/index.d.ts.map +1 -0
  44. package/dist/api/notebook/index.js +32 -0
  45. package/dist/api/notebook/index.js.map +1 -0
  46. package/dist/api/notification/index.d.ts +17 -0
  47. package/dist/api/notification/index.d.ts.map +1 -0
  48. package/dist/api/notification/index.js +14 -0
  49. package/dist/api/notification/index.js.map +1 -0
  50. package/dist/api/sql/index.d.ts +29 -0
  51. package/dist/api/sql/index.d.ts.map +1 -0
  52. package/dist/api/sql/index.js +18 -0
  53. package/dist/api/sql/index.js.map +1 -0
  54. package/dist/api/sqlite/index.d.ts +12 -0
  55. package/dist/api/sqlite/index.d.ts.map +1 -0
  56. package/dist/api/sqlite/index.js +5 -0
  57. package/dist/api/sqlite/index.js.map +1 -0
  58. package/dist/api/system/index.d.ts +27 -0
  59. package/dist/api/system/index.d.ts.map +1 -0
  60. package/dist/api/system/index.js +14 -0
  61. package/dist/api/system/index.js.map +1 -0
  62. package/dist/api/template/index.d.ts +18 -0
  63. package/dist/api/template/index.d.ts.map +1 -0
  64. package/dist/api/template/index.js +11 -0
  65. package/dist/api/template/index.js.map +1 -0
  66. package/dist/core/index.d.ts +103 -0
  67. package/dist/core/index.d.ts.map +1 -0
  68. package/dist/core/index.js +152 -0
  69. package/dist/core/index.js.map +1 -0
  70. package/dist/index.d.ts +8 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +7 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/types/index.d.ts +88 -0
  75. package/dist/types/index.d.ts.map +1 -0
  76. package/dist/types/index.js +2 -0
  77. package/dist/types/index.js.map +1 -0
  78. package/dist/utils/index.d.ts +2 -0
  79. package/dist/utils/index.d.ts.map +1 -0
  80. package/dist/utils/index.js +4 -0
  81. package/dist/utils/index.js.map +1 -0
  82. package/package.json +42 -0
  83. package/src/api/archive/index.ts +26 -0
  84. package/src/api/asset/index.ts +26 -0
  85. package/src/api/attr/index.ts +59 -0
  86. package/src/api/block/index.ts +226 -0
  87. package/src/api/convert/index.ts +18 -0
  88. package/src/api/export/index.ts +36 -0
  89. package/src/api/file/index.ts +59 -0
  90. package/src/api/filetree/index.ts +129 -0
  91. package/src/api/index.ts +56 -0
  92. package/src/api/network/index.ts +32 -0
  93. package/src/api/notebook/index.ts +93 -0
  94. package/src/api/notification/index.ts +33 -0
  95. package/src/api/sql/index.ts +65 -0
  96. package/src/api/sqlite/index.ts +20 -0
  97. package/src/api/system/index.ts +46 -0
  98. package/src/api/template/index.ts +32 -0
  99. package/src/core/index.ts +237 -0
  100. package/src/index.ts +9 -0
  101. package/src/types/index.ts +140 -0
  102. package/src/utils/index.ts +3 -0
@@ -0,0 +1,8 @@
1
+ /**
2
+ * SiYuan SDK
3
+ */
4
+ export * from './api/index.js';
5
+ export type * from './core/index.js';
6
+ export * from './core/index.js';
7
+ export * from './types/index.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,mBAAmB,iBAAiB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * SiYuan SDK
3
+ */
4
+ export * from './api/index.js';
5
+ export * from './core/index.js';
6
+ export * from './types/index.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,gBAAgB,CAAA;AAE9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Frequently used data structures in SiYuan
3
+ */
4
+ export type DocumentId = string;
5
+ export type BlockId = string;
6
+ export type NotebookId = string;
7
+ export type PreviousID = BlockId;
8
+ export type ParentID = BlockId | DocumentId;
9
+ export interface Notebook {
10
+ id: NotebookId;
11
+ name: string;
12
+ icon: string;
13
+ sort: number;
14
+ closed: boolean;
15
+ }
16
+ export interface NotebookConf {
17
+ name: string;
18
+ closed: boolean;
19
+ refCreateSavePath: string;
20
+ createDocNameTemplate: string;
21
+ dailyNoteSavePath: string;
22
+ dailyNoteTemplatePath: string;
23
+ }
24
+ export type BlockType = "d" | "s" | "h" | "t" | "i" | "p" | "f" | "audio" | "video" | "other";
25
+ export type BlockSubType = "d1" | "d2" | "s1" | "s2" | "s3" | "t1" | "t2" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "table" | "task" | "toggle" | "latex" | "quote" | "html" | "code" | "footnote" | "cite" | "collection" | "bookmark" | "attachment" | "comment" | "mindmap" | "spreadsheet" | "calendar" | "image" | "audio" | "video" | "other";
26
+ export interface Block {
27
+ id: BlockId;
28
+ parent_id?: BlockId;
29
+ root_id: DocumentId;
30
+ hash: string;
31
+ box: string;
32
+ path: string;
33
+ hpath: string;
34
+ name: string;
35
+ alias: string;
36
+ memo: string;
37
+ tag: string;
38
+ content: string;
39
+ fcontent?: string;
40
+ markdown: string;
41
+ length: number;
42
+ type: BlockType;
43
+ subtype: BlockSubType;
44
+ /**
45
+ * string of { [key: string]: string }
46
+ * For instance: "{: custom-type=\"query-code\" id=\"20230613234017-zkw3pr0\" updated=\"20230613234509\"}"
47
+ */
48
+ ial?: string;
49
+ sort: number;
50
+ created: string;
51
+ updated: string;
52
+ }
53
+ export interface doOperation {
54
+ action: string;
55
+ data: string;
56
+ id: BlockId;
57
+ parentID: BlockId | DocumentId;
58
+ previousID: BlockId;
59
+ retData: null;
60
+ }
61
+ declare global {
62
+ interface Window {
63
+ siyuan: {
64
+ notebooks: any;
65
+ menus: any;
66
+ dialogs: any;
67
+ blockPanels: any;
68
+ storage: any;
69
+ user: any;
70
+ ws: any;
71
+ languages: any;
72
+ config: import('siyuan').Config.IConf;
73
+ };
74
+ }
75
+ }
76
+ export interface IBreadcrumb {
77
+ id: string;
78
+ name: string;
79
+ type: string;
80
+ subType: string;
81
+ children: any;
82
+ }
83
+ export interface backlinkData {
84
+ dom: string;
85
+ blockPaths: IBreadcrumb[];
86
+ expand: boolean;
87
+ }
88
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export declare function trimSqlBlank(sql: string): string;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,UAEvC"}
@@ -0,0 +1,4 @@
1
+ export function trimSqlBlank(sql) {
2
+ return sql.replace(/\s+/g, ' ').trim();
3
+ }
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;AACxC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@wetoria/siyuan-sdk",
3
+ "version": "0.0.2",
4
+ "description": "SiYuan SDK",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "src",
19
+ "README.md"
20
+ ],
21
+ "keywords": [
22
+ "siyuan",
23
+ "sdk",
24
+ "api"
25
+ ],
26
+ "author": "Wetoria",
27
+ "license": "MIT",
28
+ "engines": {
29
+ "node": ">=18.0.0"
30
+ },
31
+ "peerDependencies": {
32
+ "siyuan": "^1.1.5"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc",
39
+ "dev": "tsc --watch",
40
+ "clean": "rm -rf dist"
41
+ }
42
+ }
@@ -0,0 +1,26 @@
1
+ import {
2
+ SiYuanAPI,
3
+ SyApiMethodResponse,
4
+ } from '../../core/index.js'
5
+
6
+ /**
7
+ * Archive API 类型定义
8
+ */
9
+ export interface ArchiveAPI {
10
+ /**
11
+ * 解压 ZIP 文件
12
+ * @path /api/archive/unzip
13
+ */
14
+ unzip: <T = any>(
15
+ zipPath: string,
16
+ path: string
17
+ ) => SyApiMethodResponse<T>
18
+ }
19
+
20
+ SiYuanAPI.prototype.unzip = function <T = any>(zipPath: string, path: string): SyApiMethodResponse<T> {
21
+ return this.request('/api/archive/unzip', {
22
+ zipPath,
23
+ path,
24
+ })
25
+ }
26
+
@@ -0,0 +1,26 @@
1
+ import type { SyApiMethodResponse } from '../../core/index.js'
2
+ import { SiYuanAPI } from '../../core/index.js'
3
+
4
+ /**
5
+ * Asset Files API 类型定义
6
+ */
7
+ export interface AssetAPI {
8
+ /**
9
+ * 上传资源文件
10
+ * @path /api/asset/upload
11
+ */
12
+ upload: (
13
+ assetsDirPath: string,
14
+ files: any[]
15
+ ) => SyApiMethodResponse<any>
16
+ }
17
+
18
+ SiYuanAPI.prototype.upload = function (assetsDirPath: string, files: any[]) {
19
+ const form = new FormData()
20
+ form.append('assetsDirPath', assetsDirPath)
21
+ for (const file of files) {
22
+ form.append('file[]', file)
23
+ }
24
+ return this.request('/api/asset/upload', form)
25
+ }
26
+
@@ -0,0 +1,59 @@
1
+ import type { SyApiMethodResponse } from '../../core/index.js'
2
+ import type { BlockId } from '../../types/index.js'
3
+ import { SiYuanAPI } from '../../core/index.js'
4
+
5
+ /**
6
+ * Attributes API 类型定义
7
+ */
8
+ export interface AttrAPI {
9
+ /**
10
+ * 设置块属性
11
+ * @path /api/attr/setBlockAttrs
12
+ */
13
+ setBlockAttrs: (
14
+ id: BlockId,
15
+ attrs: { [key: string]: string }
16
+ ) => SyApiMethodResponse<any>
17
+ /**
18
+ * 获取块属性
19
+ * @path /api/attr/getBlockAttrs
20
+ */
21
+ getBlockAttrs: (id: BlockId) => SyApiMethodResponse<{
22
+ [key: string]: string
23
+ }>
24
+ /**
25
+ * 批量设置块属性
26
+ * @path /api/attr/batchSetBlockAttrs
27
+ */
28
+ batchSetBlockAttrs: (blockAttrs: Array<{
29
+ id: BlockId
30
+ attrs: { [key: string]: string }
31
+ }>) => SyApiMethodResponse<any>
32
+ /**
33
+ * 批量获取块属性
34
+ * @path /api/attr/batchGetBlockAttrs
35
+ */
36
+ batchGetBlockAttrs: (ids: BlockId[]) => SyApiMethodResponse<{
37
+ [key: string]: string
38
+ }>
39
+ }
40
+
41
+ SiYuanAPI.prototype.setBlockAttrs = function (id: string, attrs: { [key: string]: string }) {
42
+ return this.request('/api/attr/setBlockAttrs', {
43
+ id,
44
+ attrs,
45
+ })
46
+ }
47
+
48
+ SiYuanAPI.prototype.getBlockAttrs = function (id: string) {
49
+ return this.request('/api/attr/getBlockAttrs', { id })
50
+ }
51
+
52
+ SiYuanAPI.prototype.batchSetBlockAttrs = function (blockAttrs: Array<{ id: string, attrs: { [key: string]: string } }>) {
53
+ return this.request('/api/attr/batchSetBlockAttrs', { blockAttrs })
54
+ }
55
+
56
+ SiYuanAPI.prototype.batchGetBlockAttrs = function (ids: string[]) {
57
+ return this.request('/api/attr/batchGetBlockAttrs', { ids })
58
+ }
59
+
@@ -0,0 +1,226 @@
1
+ import type { SyApiMethodResponse } from '../../core/index.js'
2
+ import type {
3
+ BlockId,
4
+ NotebookId,
5
+ } from '../../types/index.js'
6
+ import { SiYuanAPI } from '../../core/index.js'
7
+
8
+ /**
9
+ * Block API 类型定义
10
+ */
11
+ export interface BlockAPI {
12
+ /**
13
+ * 插入块
14
+ * @path /api/block/insertBlock
15
+ */
16
+ insertBlock: (
17
+ dataType: 'markdown' | 'dom',
18
+ data: string,
19
+ nextID?: BlockId,
20
+ previousID?: BlockId,
21
+ parentID?: BlockId
22
+ ) => SyApiMethodResponse<any[]>
23
+ /**
24
+ * 在块的开头插入内容
25
+ * @path /api/block/prependBlock
26
+ */
27
+ prependBlock: (
28
+ dataType: 'markdown' | 'dom',
29
+ data: string,
30
+ parentID: BlockId
31
+ ) => SyApiMethodResponse<any[]>
32
+ /**
33
+ * 在块的末尾追加内容
34
+ * @path /api/block/appendBlock
35
+ */
36
+ appendBlock: (
37
+ dataType: 'markdown' | 'dom',
38
+ data: string,
39
+ parentID: BlockId
40
+ ) => SyApiMethodResponse<any[]>
41
+ /**
42
+ * 追加 Markdown 内容到块(便捷方法)
43
+ * @path wrapper: uses appendBlock
44
+ */
45
+ appendMDToBlock: (params: {
46
+ data: string
47
+ parentID: BlockId
48
+ }) => SyApiMethodResponse<any[]>
49
+ /**
50
+ * 追加 Markdown 内容到块并返回块 ID(便捷方法)
51
+ * @path wrapper: uses appendBlock
52
+ */
53
+ appendMDToBlockAndGetBlockId: (params: {
54
+ data: string
55
+ parentID: BlockId
56
+ }) => SyApiMethodResponse<string | undefined>
57
+ /**
58
+ * 追加内容到日记
59
+ * @path /api/block/appendDailyNoteBlock
60
+ */
61
+ appendDailyNoteBlock: (
62
+ dataType: 'markdown' | 'dom',
63
+ data: string,
64
+ notebook: NotebookId
65
+ ) => SyApiMethodResponse<any[]>
66
+ /**
67
+ * 更新块内容
68
+ * @path /api/block/updateBlock
69
+ */
70
+ updateBlock: (
71
+ dataType: 'markdown' | 'dom',
72
+ data: string,
73
+ id: BlockId
74
+ ) => SyApiMethodResponse<any[]>
75
+ /**
76
+ * 删除块
77
+ * @path /api/block/deleteBlock
78
+ */
79
+ deleteBlock: (id: BlockId) => SyApiMethodResponse<any[]>
80
+ /**
81
+ * 移动块
82
+ * @path /api/block/moveBlock
83
+ */
84
+ moveBlock: (
85
+ id: BlockId,
86
+ previousID?: BlockId,
87
+ parentID?: BlockId
88
+ ) => SyApiMethodResponse<any[]>
89
+ /**
90
+ * 获取块的 Kramdown 格式
91
+ * @path /api/block/getBlockKramdown
92
+ */
93
+ getBlockKramdown: (id: BlockId) => SyApiMethodResponse<any>
94
+ /**
95
+ * 获取子块列表
96
+ * @path /api/block/getChildBlocks
97
+ */
98
+ getChildBlocks: (id: BlockId) => SyApiMethodResponse<any[]>
99
+ /**
100
+ * 获取块的索引位置
101
+ * @path /api/block/getBlocksIndexes
102
+ */
103
+ getBlocksIndexes: (ids: BlockId[]) => SyApiMethodResponse<{
104
+ [key: string]: number
105
+ }>
106
+ /**
107
+ * 转移块引用
108
+ * @path /api/block/transferBlockRef
109
+ */
110
+ transferBlockRef: (
111
+ fromID: BlockId,
112
+ toID: BlockId,
113
+ refIDs: BlockId[]
114
+ ) => SyApiMethodResponse<any>
115
+ /**
116
+ * 获取块信息(通过 SQL 查询)
117
+ * @path wrapper: uses sql
118
+ */
119
+ getBlockInfo: (id: BlockId) => SyApiMethodResponse<any>
120
+ /**
121
+ * 获取块的 DOM 结构
122
+ * @path /api/block/getBlockDOM
123
+ */
124
+ getBlockDOM: (id: BlockId) => SyApiMethodResponse<any>
125
+ }
126
+
127
+ SiYuanAPI.prototype.insertBlock = function (dataType: 'markdown' | 'dom', data: string, nextID?: string, previousID?: string, parentID?: string) {
128
+ return this.request('/api/block/insertBlock', {
129
+ dataType,
130
+ data,
131
+ nextID,
132
+ previousID,
133
+ parentID,
134
+ })
135
+ }
136
+
137
+ SiYuanAPI.prototype.prependBlock = function (dataType: 'markdown' | 'dom', data: string, parentID: string) {
138
+ return this.request('/api/block/prependBlock', {
139
+ dataType,
140
+ data,
141
+ parentID,
142
+ })
143
+ }
144
+
145
+ SiYuanAPI.prototype.appendBlock = function (dataType: 'markdown' | 'dom' = 'markdown', data: string, parentID: string) {
146
+ return this.request('/api/block/appendBlock', {
147
+ dataType,
148
+ data,
149
+ parentID,
150
+ })
151
+ }
152
+
153
+ SiYuanAPI.prototype.appendMDToBlock = function (params: { data: string, parentID: string }) {
154
+ return this.appendBlock('markdown', params.data, params.parentID)
155
+ }
156
+
157
+ SiYuanAPI.prototype.appendMDToBlockAndGetBlockId = async function (params: { data: string, parentID: string }) {
158
+ const res = await this.appendBlock('markdown', params.data, params.parentID)
159
+ return {
160
+ code: res.code,
161
+ msg: res.msg,
162
+ data: res.data?.[0]?.doOperations?.[0]?.id,
163
+ }
164
+ }
165
+
166
+ SiYuanAPI.prototype.appendDailyNoteBlock = function (dataType: 'markdown' | 'dom', data: string, notebook: string) {
167
+ return this.request('/api/block/appendDailyNoteBlock', {
168
+ dataType,
169
+ data,
170
+ notebook,
171
+ })
172
+ }
173
+
174
+ SiYuanAPI.prototype.updateBlock = function (dataType: 'markdown' | 'dom', data: string, id: string) {
175
+ return this.request('/api/block/updateBlock', {
176
+ dataType,
177
+ data,
178
+ id,
179
+ })
180
+ }
181
+
182
+ SiYuanAPI.prototype.deleteBlock = function (id: string) {
183
+ return this.request('/api/block/deleteBlock', { id })
184
+ }
185
+
186
+ SiYuanAPI.prototype.moveBlock = function (id: string, previousID?: string, parentID?: string) {
187
+ return this.request('/api/block/moveBlock', {
188
+ id,
189
+ previousID,
190
+ parentID,
191
+ })
192
+ }
193
+
194
+ SiYuanAPI.prototype.getBlockKramdown = function (id: string) {
195
+ return this.request('/api/block/getBlockKramdown', { id })
196
+ }
197
+
198
+ SiYuanAPI.prototype.getChildBlocks = function (id: string) {
199
+ return this.request('/api/block/getChildBlocks', { id })
200
+ }
201
+
202
+ SiYuanAPI.prototype.getBlocksIndexes = function (ids: string[]) {
203
+ return this.request('/api/block/getBlocksIndexes', { ids })
204
+ }
205
+
206
+ SiYuanAPI.prototype.transferBlockRef = function (fromID: string, toID: string, refIDs: string[]) {
207
+ return this.request('/api/block/transferBlockRef', {
208
+ fromID,
209
+ toID,
210
+ refIDs,
211
+ })
212
+ }
213
+
214
+ SiYuanAPI.prototype.getBlockInfo = async function (id: string) {
215
+ const res = await this.sql(`select * from blocks where id = '${id}'`)
216
+ return {
217
+ code: res.code,
218
+ msg: res.msg,
219
+ data: res.data?.[0],
220
+ }
221
+ }
222
+
223
+ SiYuanAPI.prototype.getBlockDOM = function (id: string) {
224
+ return this.request('/api/block/getBlockDOM', { id })
225
+ }
226
+
@@ -0,0 +1,18 @@
1
+ import type { SyApiMethodResponse } from '../../core/index.js'
2
+ import { SiYuanAPI } from '../../core/index.js'
3
+
4
+ /**
5
+ * Convert API 类型定义
6
+ */
7
+ export interface ConvertAPI {
8
+ /**
9
+ * 使用 Pandoc 转换文档
10
+ * @path /api/convert/pandoc
11
+ */
12
+ pandoc: (args: string[]) => SyApiMethodResponse<any>
13
+ }
14
+
15
+ SiYuanAPI.prototype.pandoc = function (args: string[]) {
16
+ return this.request('/api/convert/pandoc', { args })
17
+ }
18
+
@@ -0,0 +1,36 @@
1
+ import type { SyApiMethodResponse } from '../../core/index.js'
2
+ import type { DocumentId } from '../../types/index.js'
3
+
4
+ // 实现
5
+ import { SiYuanAPI } from '../../core/index.js'
6
+
7
+ /**
8
+ * Export API 类型定义
9
+ */
10
+ export interface ExportAPI {
11
+ /**
12
+ * 导出 Markdown 内容
13
+ * @path /api/export/exportMdContent
14
+ */
15
+ exportMdContent: (id: DocumentId) => SyApiMethodResponse<any>
16
+ /**
17
+ * 导出资源文件
18
+ * @path /api/export/exportResources
19
+ */
20
+ exportResources: (
21
+ paths: string[],
22
+ name: string
23
+ ) => SyApiMethodResponse<any>
24
+ }
25
+
26
+ SiYuanAPI.prototype.exportMdContent = function (id: string) {
27
+ return this.request('/api/export/exportMdContent', { id })
28
+ }
29
+
30
+ SiYuanAPI.prototype.exportResources = function (paths: string[], name: string) {
31
+ return this.request('/api/export/exportResources', {
32
+ paths,
33
+ name,
34
+ })
35
+ }
36
+
@@ -0,0 +1,59 @@
1
+ import {
2
+ SiYuanAPI,
3
+ SyApiMethodResponse,
4
+ } from '../../core/index.js'
5
+
6
+ /**
7
+ * File API 类型定义
8
+ */
9
+ export interface FileAPI {
10
+ /**
11
+ * 获取文件内容
12
+ * @path /api/file/getFile
13
+ */
14
+ getFile: (path: string) => SyApiMethodResponse<any>
15
+ /**
16
+ * 上传/创建文件
17
+ * @path /api/file/putFile
18
+ */
19
+ putFile: (path: string, isDir: boolean, file: any) => SyApiMethodResponse<any>
20
+ /**
21
+ * 删除文件
22
+ * @path /api/file/removeFile
23
+ */
24
+ removeFile: (path: string) => SyApiMethodResponse<any>
25
+ /**
26
+ * 读取目录
27
+ * @path /api/file/readDir
28
+ */
29
+ readDir: (path: string) => SyApiMethodResponse<any>
30
+ }
31
+
32
+ SiYuanAPI.prototype.getFile = async function (path: string) {
33
+ try {
34
+ return await this.request('/api/file/getFile', { path })
35
+ } catch {
36
+ return {
37
+ code: -1,
38
+ msg: 'Failed to get file',
39
+ data: null,
40
+ }
41
+ }
42
+ }
43
+
44
+ SiYuanAPI.prototype.putFile = function (path: string, isDir: boolean, file: any) {
45
+ const form = new FormData()
46
+ form.append('path', path)
47
+ form.append('isDir', isDir.toString())
48
+ form.append('file', file)
49
+ return this.request('/api/file/putFile', form)
50
+ }
51
+
52
+ SiYuanAPI.prototype.removeFile = function (path: string) {
53
+ return this.request('/api/file/removeFile', { path })
54
+ }
55
+
56
+ SiYuanAPI.prototype.readDir = function (path: string) {
57
+ return this.request('/api/file/readDir', { path })
58
+ }
59
+