enhance(apis): add support for tag properties in createTag API

This commit is contained in:
charlie
2026-01-03 21:51:23 +08:00
parent 664743b286
commit baff8a4cc1
2 changed files with 24 additions and 9 deletions

View File

@@ -349,6 +349,14 @@
(is (= (get tag3 "title") title) "get tag with ident")
(is (= (get tag4 "title") title) "get tag with uuid")))
(testing "create tag with tagProperties"
(let [tag-props [{:name "prop1" :schema {:type "string"}}
{:name "prop2" :schema {:type "number"}}
{:name "prop3" :schema {:type "checkbox"}}]
tag (ls-api-call! :editor.createTag "tag-with-props" {:tagProperties tag-props})
props (get tag ":logseq.property.class/properties")]
(is (= 3 (count props)) "tag has 3 properties")))
(testing "add and remove tag extends"
(let [tag1 (ls-api-call! :editor.createTag "tag1")
tag2 (ls-api-call! :editor.createTag "tag2")
@@ -395,8 +403,8 @@
(is (empty? result) "should not return regular pages, only tags")))
(testing "get tags by name with multiple tags having similar names"
(let [tag1 (ls-api-call! :editor.createTag "category")
tag2 (ls-api-call! :editor.createTag "Category")
(let [_tag1 (ls-api-call! :editor.createTag "category")
_tag2 (ls-api-call! :editor.createTag "Category")
result (ls-api-call! :editor.getTagsByName "category")]
;; Due to case-insensitive name normalization, both tags should be the same
(is (>= (count result) 1) "should return at least one tag")

View File

@@ -327,6 +327,13 @@ export type SearchBlockItem = {
export type SearchPageItem = string
export type SearchFileItem = string
export type PropertySchema = {
type: 'default' | 'number' | 'node' | 'date' | 'checkbox' | 'url' | string,
cardinality: 'many' | 'one',
hide: boolean
public: boolean
}
export interface IPluginSearchServiceHooks {
name: string
options?: Record<string, any>
@@ -767,7 +774,12 @@ export interface IEditorProxy extends Record<string, any> {
getAllTags: () => Promise<PageEntity[] | null>
getAllProperties: () => Promise<PageEntity[] | null>
getTagObjects: (nameOrIdent: string) => Promise<BlockEntity[] | null>
createTag: (tagName: string, opts?: Partial<{ uuid: string }>) => Promise<PageEntity | null>
createTag: (
tagName: string,
opts?: Partial<{
uuid: string, // custom uuid
tagProperties: Array<{ name: string, schema?: Partial<PropertySchema>, properties?: {} }>
}>) => Promise<PageEntity | null>
getTag: (nameOrIdent: string | EntityID) => Promise<PageEntity | null>
getTagsByName: (tagName: string) => Promise<Array<PageEntity> | null>
addTagProperty: (tagId: BlockIdentity, propertyIdOrName: BlockIdentity) => Promise<void>
@@ -819,12 +831,7 @@ export interface IEditorProxy extends Record<string, any> {
// insert or update property entity
upsertProperty: (
key: string,
schema?: Partial<{
type: 'default' | 'number' | 'node' | 'date' | 'checkbox' | 'url' | string,
cardinality: 'many' | 'one',
hide: boolean
public: boolean
}>,
schema?: Partial<PropertySchema>,
opts?: { name?: string }) => Promise<IEntityID>
// remove property entity