diff --git a/etc/brick-types.api.md b/etc/brick-types.api.md index 241ecd0d56..69af092c88 100644 --- a/etc/brick-types.api.md +++ b/etc/brick-types.api.md @@ -2452,6 +2452,16 @@ export interface UpdateQueryOptions extends PluginHistoryState { keepHash?: boolean; } +// @public +export interface UseBackendConf { + // (undocumented) + args: any[] | ((...args: any[]) => any[]); + // (undocumented) + provider: string; + // (undocumented) + transform?: (data: any) => void; +} + // @public export type UseBrickConf = UseSingleBrickConf | UseSingleBrickConf[]; diff --git a/packages/brick-types/src/manifest.ts b/packages/brick-types/src/manifest.ts index d6b5bbb4b5..cfde310c64 100644 --- a/packages/brick-types/src/manifest.ts +++ b/packages/brick-types/src/manifest.ts @@ -1466,6 +1466,13 @@ export interface UseBrickSlotConf { bricks: UseSingleBrickConf[]; } +/** 在 `useBackend` 中使用provider的配置 **/ +export interface UseBackendConf { + provider: string; + args: any[] | ((...args: any[]) => any[]); + transform?: (data: any) => void; +} + /** * 应用的 Storyboard 元信息(包括自定义模板和国际化配置)。 */ diff --git a/packages/brick-utils/src/scanStoryboard.spec.ts b/packages/brick-utils/src/scanStoryboard.spec.ts index 3b619d5864..e348d75d5e 100644 --- a/packages/brick-utils/src/scanStoryboard.spec.ts +++ b/packages/brick-utils/src/scanStoryboard.spec.ts @@ -5,6 +5,7 @@ describe("scanStoryboard", () => { const customApiA = "easyops.custom_api@awesomeApiA"; const customApiB = "easyops.custom_api@awesomeApiB"; const customApiC = "easyops.custom_api_c@awesomeApiC"; + const customApiD = "easyops.custom_api_c@awesomeApiD"; const storyboard: Storyboard = { meta: { customTemplates: [ @@ -67,6 +68,17 @@ describe("scanStoryboard", () => { }, }, }, + { + brick: "b-d", + properties: { + useBackend: { + provider: customApiD, + }, + useBrick: { + brick: "b-f", + }, + }, + }, ], menu: { type: "resolve", @@ -103,10 +115,12 @@ describe("scanStoryboard", () => { "b-b", "b-c", "b-e", + "b-d", + "b-f", "b-x", "b-y", ], - customApis: [customApiA, customApiB, customApiC], + customApis: [customApiA, customApiB, customApiD, customApiC], }); }); }); diff --git a/packages/brick-utils/src/scanStoryboard.ts b/packages/brick-utils/src/scanStoryboard.ts index 397d663a48..0ee6d7a5df 100644 --- a/packages/brick-utils/src/scanStoryboard.ts +++ b/packages/brick-utils/src/scanStoryboard.ts @@ -12,6 +12,7 @@ import { ContextConf, ResolveConf, MessageConf, + UseBackendConf, } from "@next-core/brick-types"; import { uniq } from "lodash"; import { isObject } from "./isObject"; @@ -205,23 +206,36 @@ function collectUsedBricksInProperties(value: any, collection: string[]): void { collectUsedBricksInProperties(item, collection); }); } else if (isObject(value)) { - if (value.useBrick) { - [].concat(value.useBrick).forEach((useBrickConf: UseSingleBrickConf) => { - if (typeof useBrickConf?.brick === "string") { - collection.push(useBrickConf.brick); - collectUsedBricksInProperties(useBrickConf.properties, collection); - collectUsedBricksInEventHandlers(useBrickConf.events, collection); - - if (useBrickConf.slots) { - Object.values(useBrickConf.slots).forEach((slotConf) => { - collectBricksInBrickConfs( - slotConf.bricks as BrickConf[], + if (value.useBrick || value.useBackend) { + if (value.useBrick) { + [] + .concat(value.useBrick) + .forEach((useBrickConf: UseSingleBrickConf) => { + if (typeof useBrickConf?.brick === "string") { + collection.push(useBrickConf.brick); + collectUsedBricksInProperties( + useBrickConf.properties, collection ); - }); - } + collectUsedBricksInEventHandlers(useBrickConf.events, collection); + + if (useBrickConf.slots) { + Object.values(useBrickConf.slots).forEach((slotConf) => { + collectBricksInBrickConfs( + slotConf.bricks as BrickConf[], + collection + ); + }); + } + } + }); + } + + if (value.useBackend as UseBackendConf) { + if (typeof value.useBackend?.provider === "string") { + collection.push(value.useBackend?.provider); } - }); + } } else { Object.values(value).forEach((item) => { collectUsedBricksInProperties(item, collection);