useUnicloudUrlEvent

  • 用于获取unicloud平台云函数url化之后的集成请求event

    函数签名

    ```typescript type UnicloudUrlOriginEvent = { path: string; httpMethod: string; headers: Record; queryStringParameters: Record; isBase64Encoded: boolean; body: string; };

declare const useUnicloudUrlEvent: () => UnicloudUrlOriginEvent | undefined;

  1. <a name="BxZ6Y"></a>
  2. ### **栗子🌰**
  3. ```typescript
  4. const originUrlEvent = useUnicloudUrlEvent()

useUnicloudContext

  • 用于获取unicloud平台的源context上下文, 在源context中你可以获取到关于unicloud运行时的任何context配置

    函数签名

    ```typescript type UnicloudOriginContext = { APPID?: string; SOURCE: ‘server’ | ‘http’ | ‘client’; CLIENTIP: string; CLIENTUA: string; OS?: unknown; PLATFORM?: unknown; SPACEINFO: { provider: ‘aliyun’ | ‘tencent’; spaceId: string; }; DEVICEID?: undefined; FUNCTION_NAME: string; LOCALE?: unknown; };

declare const useUnicloudContext: () => UnicloudOriginContext;

  1. <a name="EXz6s"></a>
  2. ### **栗子🌰**
  3. ```typescript
  4. const originContext = useUnicloudContext()

useUnicloudTriggerApi ( 内部函数 )

  • 用于触发unicloud的入口函数, 它是一个内部核心hook, 在你主动的编写代码中, 很可能见不到它, 但是它多次出现在unicloud环境的产物中, 它是由sword编译器自动shim到你的应用程序中的

    函数签名

    1. declare const useUnicloudTriggerApi: (event: UnicloudEvent, context: UnicloudContext, apiMap: Record<string, Map>) => ErrorResponse | Promise<void | ErrorResponse>;

    栗子🌰

    1. module.exports = async (event, context) => {
    2. const { apiMap } = await import_sword_framework.useGetApiMap()
    3. return import_sword_framework.useUnicloudTriggerApi(event, context, apiMap)
    4. }

    ps: 实例代码存在于unicloud环境下的index.js之中

useUnicloudValidateEvent (内部函数)

  • 用于在unicloud平台校验event参数

    函数签名

    1. declare const useUnicloudValidateEvent: (event: UnicloudEvent) => true | ErrorReturn;

    栗子🌰

    1. const validateResult = import_sword_framework.useUnicloudValidateEvent(event);
    2. // 判断校验结果是否严格等于true
    3. if (validateResult !== true) {
    4. return validateResult;
    5. }

    ps: 实例代码存在于unicloud环境下的index.js之中