@cloudcome/utils-uni 1.3.0 → 1.4.0
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.
- package/dist/_helpers.cjs +10 -0
- package/dist/_helpers.cjs.map +1 -0
- package/dist/_helpers.d.ts +8 -0
- package/dist/_helpers.mjs +11 -0
- package/dist/_helpers.mjs.map +1 -0
- package/dist/client.cjs +26 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.ts +49 -0
- package/dist/client.mjs +26 -0
- package/dist/client.mjs.map +1 -0
- package/dist/cloud/error.d.ts +4 -0
- package/dist/cloud/expose.d.ts +48 -0
- package/dist/cloud/object.d.ts +132 -0
- package/dist/cloud/respond.d.ts +3 -0
- package/dist/cloud/uni-id.d.ts +14 -0
- package/dist/cloud.cjs +90 -19
- package/dist/cloud.cjs.map +1 -1
- package/dist/cloud.d.ts +5 -53
- package/dist/cloud.mjs +90 -19
- package/dist/cloud.mjs.map +1 -1
- package/dist/database/db.d.ts +11079 -0
- package/dist/database/types.d.ts +9 -0
- package/dist/database.cjs +200 -0
- package/dist/database.cjs.map +1 -0
- package/dist/database.d.ts +2 -0
- package/dist/database.mjs +200 -0
- package/dist/database.mjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +22 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const error = require("@cloudcome/utils-core/error");
|
|
3
|
+
function parseCloudObjectOutput(output, fallbackErrorMessage = "") {
|
|
4
|
+
if (output.errCode) {
|
|
5
|
+
throw error.errorAssign(new Error(output.errMsg || fallbackErrorMessage), output);
|
|
6
|
+
}
|
|
7
|
+
return output.data;
|
|
8
|
+
}
|
|
9
|
+
exports.parseCloudObjectOutput = parseCloudObjectOutput;
|
|
10
|
+
//# sourceMappingURL=_helpers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_helpers.cjs","sources":["../src/_helpers.ts"],"sourcesContent":["import { errorAssign } from '@cloudcome/utils-core/error';\nimport type { UniCloudObjectOutput } from './cloud';\n\n/**\n * 解析云对象输出结果\n * @param output 云对象输出结果\n * @param fallbackErrorMessage 错误信息\n * @returns 返回云对象输出结果中的数据\n */\nexport function parseCloudObjectOutput<O>(output: UniCloudObjectOutput<O>, fallbackErrorMessage = ''): O {\n if (output.errCode) {\n throw errorAssign(new Error(output.errMsg || fallbackErrorMessage), output);\n }\n\n return output.data;\n}\n"],"names":["errorAssign"],"mappings":";;AASgB,SAAA,uBAA0B,QAAiC,uBAAuB,IAAO;AACvG,MAAI,OAAO,SAAS;AAClB,UAAMA,MAAAA,YAAY,IAAI,MAAM,OAAO,UAAU,oBAAoB,GAAG,MAAM;AAAA,EAAA;AAG5E,SAAO,OAAO;AAChB;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { UniCloudObjectOutput } from './cloud';
|
|
2
|
+
/**
|
|
3
|
+
* 解析云对象输出结果
|
|
4
|
+
* @param output 云对象输出结果
|
|
5
|
+
* @param fallbackErrorMessage 错误信息
|
|
6
|
+
* @returns 返回云对象输出结果中的数据
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseCloudObjectOutput<O>(output: UniCloudObjectOutput<O>, fallbackErrorMessage?: string): O;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { errorAssign } from "@cloudcome/utils-core/error";
|
|
2
|
+
function parseCloudObjectOutput(output, fallbackErrorMessage = "") {
|
|
3
|
+
if (output.errCode) {
|
|
4
|
+
throw errorAssign(new Error(output.errMsg || fallbackErrorMessage), output);
|
|
5
|
+
}
|
|
6
|
+
return output.data;
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
parseCloudObjectOutput as p
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=_helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_helpers.mjs","sources":["../src/_helpers.ts"],"sourcesContent":["import { errorAssign } from '@cloudcome/utils-core/error';\nimport type { UniCloudObjectOutput } from './cloud';\n\n/**\n * 解析云对象输出结果\n * @param output 云对象输出结果\n * @param fallbackErrorMessage 错误信息\n * @returns 返回云对象输出结果中的数据\n */\nexport function parseCloudObjectOutput<O>(output: UniCloudObjectOutput<O>, fallbackErrorMessage = ''): O {\n if (output.errCode) {\n throw errorAssign(new Error(output.errMsg || fallbackErrorMessage), output);\n }\n\n return output.data;\n}\n"],"names":[],"mappings":";AASgB,SAAA,uBAA0B,QAAiC,uBAAuB,IAAO;AACvG,MAAI,OAAO,SAAS;AAClB,UAAM,YAAY,IAAI,MAAM,OAAO,UAAU,oBAAoB,GAAG,MAAM;AAAA,EAAA;AAG5E,SAAO,OAAO;AAChB;"}
|
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const request = require("@cloudcome/utils-vue/request");
|
|
4
|
+
const _helpers = require("./_helpers.cjs");
|
|
5
|
+
function createUseCloudObject(objectName, options) {
|
|
6
|
+
const server = (options == null ? void 0 : options._mockServer) || uniCloud.importObject(objectName, options);
|
|
7
|
+
const fallbackErrorMessage = (options == null ? void 0 : options.fallbackErrorMessage) || "请求失败";
|
|
8
|
+
const useCloudObject = (caller, options2) => {
|
|
9
|
+
return request.useRequest(async (...inputs) => {
|
|
10
|
+
const result = await caller(server, ...inputs);
|
|
11
|
+
return _helpers.parseCloudObjectOutput(result, fallbackErrorMessage);
|
|
12
|
+
}, options2);
|
|
13
|
+
};
|
|
14
|
+
return useCloudObject;
|
|
15
|
+
}
|
|
16
|
+
function useDatabase(caller, options) {
|
|
17
|
+
const db = (options == null ? void 0 : options._mockDatabase) || uniCloud.database();
|
|
18
|
+
return request.useRequest(async (...inputs) => {
|
|
19
|
+
const { result } = await caller(db, ...inputs);
|
|
20
|
+
if (!result.errCode) return result;
|
|
21
|
+
throw new Error(result.errMsg || "请求失败");
|
|
22
|
+
}, options);
|
|
23
|
+
}
|
|
24
|
+
exports.createUseCloudObject = createUseCloudObject;
|
|
25
|
+
exports.useDatabase = useDatabase;
|
|
26
|
+
//# sourceMappingURL=client.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.cjs","sources":["../src/client.ts"],"sourcesContent":["import type { UniCloudObjectOutput } from '@/cloud';\nimport type { UniClientDatabaseOutput } from '@/database';\nimport type { AnyArray } from '@cloudcome/utils-core/types';\nimport {\n type UseRequestOptions,\n type UseRequestOutput,\n type UseRequestOutputFilled,\n useRequest,\n} from '@cloudcome/utils-vue/request';\nimport { parseCloudObjectOutput } from './_helpers';\n\ntype ImportObject = UniCloudNamespace.UniCloud['importObject'];\ntype ImportObjectArgs = Parameters<ImportObject>;\n\nexport type UniCloudObjectServer<O> = Record<string, (...inputs: unknown[]) => Promise<UniCloudObjectOutput<O>>>;\n\nexport type CreateUseCloudObjectOptions = ImportObjectArgs[1] & {\n /**\n * 模拟云对象,用于单元测试\n * @private\n */\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n _mockServer?: any;\n\n /**\n * 回退错误信息\n * @default '请求失败'\n */\n fallbackErrorMessage?: string;\n};\n\nexport type UseCloudObject = {\n <I extends AnyArray, O>(\n caller: (server: UniCloudObjectServer<O>, ...inputs: I) => Promise<UniCloudObjectOutput<O>>,\n options: Omit<UseRequestOptions<I, O>, 'placeholder'> & { placeholder: () => O },\n ): UseRequestOutputFilled<I, O>;\n <I extends AnyArray, O>(\n caller: (server: UniCloudObjectServer<O>, ...inputs: I) => Promise<UniCloudObjectOutput<O>>,\n options?: UseRequestOptions<I, O>,\n ): UseRequestOutput<I, O>;\n};\n\n/**\n * 创建一个用于调用云对象的hook工厂函数\n * @param objectName 云对象名称,用于导入对应的云对象\n * @param options 导入云对象时的可选配置参数\n * @returns 返回一个函数,该函数可以用于创建云对象调用hook\n */\nexport function createUseCloudObject(objectName: ImportObjectArgs[0], options?: CreateUseCloudObjectOptions) {\n const server = options?._mockServer || uniCloud.importObject(objectName, options);\n const fallbackErrorMessage = options?.fallbackErrorMessage || '请求失败';\n const useCloudObject: UseCloudObject = (caller, options) => {\n // 使用请求hook处理云对象调用\n return useRequest(async (...inputs) => {\n const result = await caller(server, ...inputs);\n return parseCloudObjectOutput(result, fallbackErrorMessage);\n }, options);\n };\n\n return useCloudObject;\n}\n\nexport type UseDatabaseOptions<I extends AnyArray, O> = UseRequestOptions<I, O> & {\n /**\n * 模拟数据库,用于单元测试\n */\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n _mockDatabase?: any;\n};\n\n/**\n * 创建一个用于调用云数据库的hook\n * @param caller 调用云数据库的函数,接收数据库实例和输入参数,返回Promise\n * @param options 配置选项\n * @returns 返回一个请求hook,用于处理云数据库调用\n */\nexport function useDatabase<I extends AnyArray, O>(\n caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniClientDatabaseOutput<O>>,\n options: Omit<UseDatabaseOptions<I, O>, 'placeholder'> & { placeholder: () => O },\n): UseRequestOutputFilled<I, O>;\nexport function useDatabase<I extends AnyArray, O>(\n caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniClientDatabaseOutput<O>>,\n options?: UseDatabaseOptions<I, O>,\n): UseRequestOutput<I, O>;\nexport function useDatabase<I extends AnyArray, O>(\n caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniClientDatabaseOutput<O>>,\n options?: UseDatabaseOptions<I, O>,\n): UseRequestOutput<I, O> {\n // 获取数据库实例,优先使用模拟数据库(用于测试),否则使用uniCloud数据库\n const db = options?._mockDatabase || uniCloud.database();\n return useRequest(async (...inputs: I) => {\n const { result } = await caller(db, ...inputs);\n if (!result.errCode) return result;\n throw new Error(result.errMsg || '请求失败');\n }, options);\n}\n"],"names":["options","useRequest","parseCloudObjectOutput"],"mappings":";;;;AAgDgB,SAAA,qBAAqB,YAAiC,SAAuC;AAC3G,QAAM,UAAS,mCAAS,gBAAe,SAAS,aAAa,YAAY,OAAO;AAC1E,QAAA,wBAAuB,mCAAS,yBAAwB;AACxD,QAAA,iBAAiC,CAAC,QAAQA,aAAY;AAEnD,WAAAC,QAAA,WAAW,UAAU,WAAW;AACrC,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,MAAM;AACtC,aAAAC,SAAA,uBAAuB,QAAQ,oBAAoB;AAAA,OACzDF,QAAO;AAAA,EACZ;AAEO,SAAA;AACT;AAwBgB,SAAA,YACd,QACA,SACwB;AAExB,QAAM,MAAK,mCAAS,kBAAiB,SAAS,SAAS;AAChD,SAAAC,QAAA,WAAW,UAAU,WAAc;AACxC,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,IAAI,GAAG,MAAM;AACzC,QAAA,CAAC,OAAO,QAAgB,QAAA;AAC5B,UAAM,IAAI,MAAM,OAAO,UAAU,MAAM;AAAA,KACtC,OAAO;AACZ;;;"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { UniCloudObjectOutput } from './cloud';
|
|
2
|
+
import { UniClientDatabaseOutput } from './database';
|
|
3
|
+
import { AnyArray } from '@cloudcome/utils-core/types';
|
|
4
|
+
import { UseRequestOptions, UseRequestOutput, UseRequestOutputFilled } from '@cloudcome/utils-vue/request';
|
|
5
|
+
type ImportObject = UniCloudNamespace.UniCloud['importObject'];
|
|
6
|
+
type ImportObjectArgs = Parameters<ImportObject>;
|
|
7
|
+
export type UniCloudObjectServer<O> = Record<string, (...inputs: unknown[]) => Promise<UniCloudObjectOutput<O>>>;
|
|
8
|
+
export type CreateUseCloudObjectOptions = ImportObjectArgs[1] & {
|
|
9
|
+
/**
|
|
10
|
+
* 模拟云对象,用于单元测试
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
_mockServer?: any;
|
|
14
|
+
/**
|
|
15
|
+
* 回退错误信息
|
|
16
|
+
* @default '请求失败'
|
|
17
|
+
*/
|
|
18
|
+
fallbackErrorMessage?: string;
|
|
19
|
+
};
|
|
20
|
+
export type UseCloudObject = {
|
|
21
|
+
<I extends AnyArray, O>(caller: (server: UniCloudObjectServer<O>, ...inputs: I) => Promise<UniCloudObjectOutput<O>>, options: Omit<UseRequestOptions<I, O>, 'placeholder'> & {
|
|
22
|
+
placeholder: () => O;
|
|
23
|
+
}): UseRequestOutputFilled<I, O>;
|
|
24
|
+
<I extends AnyArray, O>(caller: (server: UniCloudObjectServer<O>, ...inputs: I) => Promise<UniCloudObjectOutput<O>>, options?: UseRequestOptions<I, O>): UseRequestOutput<I, O>;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* 创建一个用于调用云对象的hook工厂函数
|
|
28
|
+
* @param objectName 云对象名称,用于导入对应的云对象
|
|
29
|
+
* @param options 导入云对象时的可选配置参数
|
|
30
|
+
* @returns 返回一个函数,该函数可以用于创建云对象调用hook
|
|
31
|
+
*/
|
|
32
|
+
export declare function createUseCloudObject(objectName: ImportObjectArgs[0], options?: CreateUseCloudObjectOptions): UseCloudObject;
|
|
33
|
+
export type UseDatabaseOptions<I extends AnyArray, O> = UseRequestOptions<I, O> & {
|
|
34
|
+
/**
|
|
35
|
+
* 模拟数据库,用于单元测试
|
|
36
|
+
*/
|
|
37
|
+
_mockDatabase?: any;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* 创建一个用于调用云数据库的hook
|
|
41
|
+
* @param caller 调用云数据库的函数,接收数据库实例和输入参数,返回Promise
|
|
42
|
+
* @param options 配置选项
|
|
43
|
+
* @returns 返回一个请求hook,用于处理云数据库调用
|
|
44
|
+
*/
|
|
45
|
+
export declare function useDatabase<I extends AnyArray, O>(caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniClientDatabaseOutput<O>>, options: Omit<UseDatabaseOptions<I, O>, 'placeholder'> & {
|
|
46
|
+
placeholder: () => O;
|
|
47
|
+
}): UseRequestOutputFilled<I, O>;
|
|
48
|
+
export declare function useDatabase<I extends AnyArray, O>(caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniClientDatabaseOutput<O>>, options?: UseDatabaseOptions<I, O>): UseRequestOutput<I, O>;
|
|
49
|
+
export {};
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useRequest } from "@cloudcome/utils-vue/request";
|
|
2
|
+
import { p as parseCloudObjectOutput } from "./_helpers.mjs";
|
|
3
|
+
function createUseCloudObject(objectName, options) {
|
|
4
|
+
const server = (options == null ? void 0 : options._mockServer) || uniCloud.importObject(objectName, options);
|
|
5
|
+
const fallbackErrorMessage = (options == null ? void 0 : options.fallbackErrorMessage) || "请求失败";
|
|
6
|
+
const useCloudObject = (caller, options2) => {
|
|
7
|
+
return useRequest(async (...inputs) => {
|
|
8
|
+
const result = await caller(server, ...inputs);
|
|
9
|
+
return parseCloudObjectOutput(result, fallbackErrorMessage);
|
|
10
|
+
}, options2);
|
|
11
|
+
};
|
|
12
|
+
return useCloudObject;
|
|
13
|
+
}
|
|
14
|
+
function useDatabase(caller, options) {
|
|
15
|
+
const db = (options == null ? void 0 : options._mockDatabase) || uniCloud.database();
|
|
16
|
+
return useRequest(async (...inputs) => {
|
|
17
|
+
const { result } = await caller(db, ...inputs);
|
|
18
|
+
if (!result.errCode) return result;
|
|
19
|
+
throw new Error(result.errMsg || "请求失败");
|
|
20
|
+
}, options);
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
createUseCloudObject,
|
|
24
|
+
useDatabase
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.mjs","sources":["../src/client.ts"],"sourcesContent":["import type { UniCloudObjectOutput } from '@/cloud';\nimport type { UniClientDatabaseOutput } from '@/database';\nimport type { AnyArray } from '@cloudcome/utils-core/types';\nimport {\n type UseRequestOptions,\n type UseRequestOutput,\n type UseRequestOutputFilled,\n useRequest,\n} from '@cloudcome/utils-vue/request';\nimport { parseCloudObjectOutput } from './_helpers';\n\ntype ImportObject = UniCloudNamespace.UniCloud['importObject'];\ntype ImportObjectArgs = Parameters<ImportObject>;\n\nexport type UniCloudObjectServer<O> = Record<string, (...inputs: unknown[]) => Promise<UniCloudObjectOutput<O>>>;\n\nexport type CreateUseCloudObjectOptions = ImportObjectArgs[1] & {\n /**\n * 模拟云对象,用于单元测试\n * @private\n */\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n _mockServer?: any;\n\n /**\n * 回退错误信息\n * @default '请求失败'\n */\n fallbackErrorMessage?: string;\n};\n\nexport type UseCloudObject = {\n <I extends AnyArray, O>(\n caller: (server: UniCloudObjectServer<O>, ...inputs: I) => Promise<UniCloudObjectOutput<O>>,\n options: Omit<UseRequestOptions<I, O>, 'placeholder'> & { placeholder: () => O },\n ): UseRequestOutputFilled<I, O>;\n <I extends AnyArray, O>(\n caller: (server: UniCloudObjectServer<O>, ...inputs: I) => Promise<UniCloudObjectOutput<O>>,\n options?: UseRequestOptions<I, O>,\n ): UseRequestOutput<I, O>;\n};\n\n/**\n * 创建一个用于调用云对象的hook工厂函数\n * @param objectName 云对象名称,用于导入对应的云对象\n * @param options 导入云对象时的可选配置参数\n * @returns 返回一个函数,该函数可以用于创建云对象调用hook\n */\nexport function createUseCloudObject(objectName: ImportObjectArgs[0], options?: CreateUseCloudObjectOptions) {\n const server = options?._mockServer || uniCloud.importObject(objectName, options);\n const fallbackErrorMessage = options?.fallbackErrorMessage || '请求失败';\n const useCloudObject: UseCloudObject = (caller, options) => {\n // 使用请求hook处理云对象调用\n return useRequest(async (...inputs) => {\n const result = await caller(server, ...inputs);\n return parseCloudObjectOutput(result, fallbackErrorMessage);\n }, options);\n };\n\n return useCloudObject;\n}\n\nexport type UseDatabaseOptions<I extends AnyArray, O> = UseRequestOptions<I, O> & {\n /**\n * 模拟数据库,用于单元测试\n */\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n _mockDatabase?: any;\n};\n\n/**\n * 创建一个用于调用云数据库的hook\n * @param caller 调用云数据库的函数,接收数据库实例和输入参数,返回Promise\n * @param options 配置选项\n * @returns 返回一个请求hook,用于处理云数据库调用\n */\nexport function useDatabase<I extends AnyArray, O>(\n caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniClientDatabaseOutput<O>>,\n options: Omit<UseDatabaseOptions<I, O>, 'placeholder'> & { placeholder: () => O },\n): UseRequestOutputFilled<I, O>;\nexport function useDatabase<I extends AnyArray, O>(\n caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniClientDatabaseOutput<O>>,\n options?: UseDatabaseOptions<I, O>,\n): UseRequestOutput<I, O>;\nexport function useDatabase<I extends AnyArray, O>(\n caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniClientDatabaseOutput<O>>,\n options?: UseDatabaseOptions<I, O>,\n): UseRequestOutput<I, O> {\n // 获取数据库实例,优先使用模拟数据库(用于测试),否则使用uniCloud数据库\n const db = options?._mockDatabase || uniCloud.database();\n return useRequest(async (...inputs: I) => {\n const { result } = await caller(db, ...inputs);\n if (!result.errCode) return result;\n throw new Error(result.errMsg || '请求失败');\n }, options);\n}\n"],"names":["options"],"mappings":";;AAgDgB,SAAA,qBAAqB,YAAiC,SAAuC;AAC3G,QAAM,UAAS,mCAAS,gBAAe,SAAS,aAAa,YAAY,OAAO;AAC1E,QAAA,wBAAuB,mCAAS,yBAAwB;AACxD,QAAA,iBAAiC,CAAC,QAAQA,aAAY;AAEnD,WAAA,WAAW,UAAU,WAAW;AACrC,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,MAAM;AACtC,aAAA,uBAAuB,QAAQ,oBAAoB;AAAA,OACzDA,QAAO;AAAA,EACZ;AAEO,SAAA;AACT;AAwBgB,SAAA,YACd,QACA,SACwB;AAExB,QAAM,MAAK,mCAAS,kBAAiB,SAAS,SAAS;AAChD,SAAA,WAAW,UAAU,WAAc;AACxC,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,IAAI,GAAG,MAAM;AACzC,QAAA,CAAC,OAAO,QAAgB,QAAA;AAC5B,UAAM,IAAI,MAAM,OAAO,UAAU,MAAM;AAAA,KACtC,OAAO;AACZ;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { MaybePromise } from '@cloudcome/utils-core/types';
|
|
2
|
+
import { default as z, ZodObject } from 'zod';
|
|
3
|
+
import { UniCloudObject, UniCloudObjectThis } from './object';
|
|
4
|
+
import { UniIdCloudObject } from './uni-id';
|
|
5
|
+
export type UniCloudObjectThisAppendUser = {
|
|
6
|
+
id: string;
|
|
7
|
+
role: string[];
|
|
8
|
+
permission: string[];
|
|
9
|
+
isAdmin: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type UniCloudObjectThisAppend = {
|
|
12
|
+
options: Required<CreateCloudObjectOptions>;
|
|
13
|
+
user: UniCloudObjectThisAppendUser;
|
|
14
|
+
};
|
|
15
|
+
export type UniCloudObjectContext = UniCloudObjectThis & UniCloudObjectThisAppend;
|
|
16
|
+
/**
|
|
17
|
+
* 构建云函数暴露创建器的选项配置
|
|
18
|
+
* 用于配置云函数暴露创建器的行为,目前支持传入UniIdCloudObject实例
|
|
19
|
+
*/
|
|
20
|
+
export type BuildCloudExposeCreatorOptions = {
|
|
21
|
+
/**
|
|
22
|
+
* 可选的UniIdCloudObject实例
|
|
23
|
+
* 用于处理用户身份验证和权限管理相关功能
|
|
24
|
+
*/
|
|
25
|
+
uniIdCloudObject?: UniIdCloudObject;
|
|
26
|
+
/**
|
|
27
|
+
* 需要用户登录态的错误码
|
|
28
|
+
* @default 'uni-id-check-token-failed'
|
|
29
|
+
*/
|
|
30
|
+
requiredUserErrCode?: number | string;
|
|
31
|
+
/**
|
|
32
|
+
* 需要用户登录态的错误消息
|
|
33
|
+
* @default '需要登录后才能进行此操作'
|
|
34
|
+
*/
|
|
35
|
+
requiredUserErrMsg?: string;
|
|
36
|
+
};
|
|
37
|
+
export type CreateCloudObjectOptions = {
|
|
38
|
+
/**
|
|
39
|
+
* 是否需要用户登录态
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
requiredUser?: boolean;
|
|
43
|
+
};
|
|
44
|
+
export type CreateCloudObjectExpose = {
|
|
45
|
+
<S extends ZodObject, O>(schema: S, fn: (context: UniCloudObjectContext, input: z.infer<S>) => MaybePromise<O>, options?: CreateCloudObjectOptions): UniCloudObject<z.infer<S>, O>;
|
|
46
|
+
<O>(fn: (context: UniCloudObjectContext) => MaybePromise<O>, options?: CreateCloudObjectOptions): UniCloudObject<void, O>;
|
|
47
|
+
};
|
|
48
|
+
export declare function buildCloudObjectExposeCreator(options?: BuildCloudExposeCreatorOptions): CreateCloudObjectExpose;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 客户端信息类型定义
|
|
3
|
+
* 包含了客户端的各种环境和设备信息
|
|
4
|
+
*/
|
|
5
|
+
export type ClientInfo = {
|
|
6
|
+
/** 场景值 */
|
|
7
|
+
scene: number;
|
|
8
|
+
/** 应用ID */
|
|
9
|
+
appId: string;
|
|
10
|
+
/** 应用语言 */
|
|
11
|
+
appLanguage: string;
|
|
12
|
+
/** 应用名称 */
|
|
13
|
+
appName: string;
|
|
14
|
+
/** 应用版本 */
|
|
15
|
+
appVersion: string;
|
|
16
|
+
/** 应用版本号 */
|
|
17
|
+
appVersionCode: string;
|
|
18
|
+
/** 浏览器名称 */
|
|
19
|
+
browserName: string;
|
|
20
|
+
/** 浏览器版本 */
|
|
21
|
+
browserVersion: string;
|
|
22
|
+
/** 设备ID */
|
|
23
|
+
deviceId: string;
|
|
24
|
+
/** 设备型号 */
|
|
25
|
+
deviceModel: string;
|
|
26
|
+
/** 设备类型 */
|
|
27
|
+
deviceType: 'phone' | 'pad' | 'pc' | 'unknown';
|
|
28
|
+
/** 宿主名称 */
|
|
29
|
+
hostName: string;
|
|
30
|
+
/** 宿主版本 */
|
|
31
|
+
hostVersion: string;
|
|
32
|
+
/** 操作系统名称 */
|
|
33
|
+
osName: 'ios' | 'android' | 'windows' | 'macos' | 'linux' | 'harmonyos';
|
|
34
|
+
/** 操作系统版本 */
|
|
35
|
+
osVersion: string;
|
|
36
|
+
/** User-Agent字符串 */
|
|
37
|
+
ua: string;
|
|
38
|
+
/** Uni编译器版本 */
|
|
39
|
+
uniCompilerVersion: string;
|
|
40
|
+
/** Uni平台 */
|
|
41
|
+
uniPlatform: string;
|
|
42
|
+
/** Uni运行时版本 */
|
|
43
|
+
uniRuntimeVersion: string;
|
|
44
|
+
/** 语言环境 */
|
|
45
|
+
locale: string;
|
|
46
|
+
/** 密钥类型 */
|
|
47
|
+
secretType: string;
|
|
48
|
+
/** 运行环境 */
|
|
49
|
+
RUNTIME_ENV: 'local' | 'cloud';
|
|
50
|
+
/** 操作系统 */
|
|
51
|
+
os: string;
|
|
52
|
+
/** 客户端IP地址 */
|
|
53
|
+
clientIP: string;
|
|
54
|
+
/** 用户代理字符串 */
|
|
55
|
+
userAgent: string;
|
|
56
|
+
/** 平台信息 */
|
|
57
|
+
platform: string;
|
|
58
|
+
/** 请求来源 */
|
|
59
|
+
source: 'client' | 'function' | 'http' | 'timing' | 'server';
|
|
60
|
+
/** 请求ID */
|
|
61
|
+
requestId: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* 云环境信息类型定义
|
|
65
|
+
* 包含了云函数运行环境的相关信息
|
|
66
|
+
*/
|
|
67
|
+
export type CloudInfo = {
|
|
68
|
+
/** 云服务提供商 */
|
|
69
|
+
provider: 'alipay' | 'aliyun' | 'tencent';
|
|
70
|
+
/** 空间ID */
|
|
71
|
+
spaceId: string;
|
|
72
|
+
/** 是否使用旧版空间ID */
|
|
73
|
+
useOldSpaceId: boolean;
|
|
74
|
+
/** 函数名称 */
|
|
75
|
+
functionName: string;
|
|
76
|
+
/** 函数类型 */
|
|
77
|
+
functionType: string;
|
|
78
|
+
/** 运行环境 */
|
|
79
|
+
runtimeEnv: 'local' | 'cloud';
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* HTTP请求信息类型定义
|
|
83
|
+
* 包含了HTTP请求的详细信息
|
|
84
|
+
*/
|
|
85
|
+
export type HttpInfo = {
|
|
86
|
+
/** 请求路径 */
|
|
87
|
+
path: string;
|
|
88
|
+
/** HTTP方法 */
|
|
89
|
+
httpMethod: string;
|
|
90
|
+
/** 请求头 */
|
|
91
|
+
headers: Record<string, string>;
|
|
92
|
+
/** 查询参数 */
|
|
93
|
+
queryStringParameters: Record<string, string>;
|
|
94
|
+
/** 请求体 */
|
|
95
|
+
body: string;
|
|
96
|
+
/** 是否为Base64编码 */
|
|
97
|
+
isBase64Encoded: boolean;
|
|
98
|
+
};
|
|
99
|
+
export type UniCloudObjectThis = {
|
|
100
|
+
/**
|
|
101
|
+
* 获取客户端信息
|
|
102
|
+
*/
|
|
103
|
+
getClientInfo: () => ClientInfo;
|
|
104
|
+
/**
|
|
105
|
+
* 获取云端信息
|
|
106
|
+
*/
|
|
107
|
+
getCloudInfo: () => CloudInfo;
|
|
108
|
+
/**
|
|
109
|
+
* 获取客户端token
|
|
110
|
+
* 仅在客户端已登录的情况下返回token
|
|
111
|
+
*/
|
|
112
|
+
getUniIdToken: () => string | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* 获取当前调用的方法名
|
|
115
|
+
*/
|
|
116
|
+
getMethodName: () => string;
|
|
117
|
+
/**
|
|
118
|
+
* 获取当前请求id
|
|
119
|
+
*/
|
|
120
|
+
getUniCloudRequestId: () => string;
|
|
121
|
+
/**
|
|
122
|
+
* 获取url化时的http信息
|
|
123
|
+
*/
|
|
124
|
+
getHttpInfo: () => HttpInfo | undefined;
|
|
125
|
+
};
|
|
126
|
+
export type UniCloudObjectOutput<T> = {
|
|
127
|
+
requestId?: string;
|
|
128
|
+
errCode?: number | string;
|
|
129
|
+
errMsg?: string;
|
|
130
|
+
data: T;
|
|
131
|
+
};
|
|
132
|
+
export type UniCloudObject<I, O> = (this: UniCloudObjectThis, input: I) => Promise<UniCloudObjectOutput<O>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ClientInfo, UniCloudObjectOutput } from './object';
|
|
2
|
+
export type UniIdCloudObject = {
|
|
3
|
+
createInstance: (options: {
|
|
4
|
+
clientInfo: ClientInfo;
|
|
5
|
+
}) => UniIdInstance;
|
|
6
|
+
};
|
|
7
|
+
export type UniIdInstance = {
|
|
8
|
+
checkToken: (token: string) => Promise<UniIdUser | undefined>;
|
|
9
|
+
};
|
|
10
|
+
export type UniIdUser = UniCloudObjectOutput<{
|
|
11
|
+
uid?: string;
|
|
12
|
+
role?: string[];
|
|
13
|
+
permission?: string[];
|
|
14
|
+
}>;
|
package/dist/cloud.cjs
CHANGED
|
@@ -1,25 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
const error = require("@cloudcome/utils-core/error");
|
|
4
|
+
const _helpers = require("./_helpers.cjs");
|
|
5
|
+
const object = require("@cloudcome/utils-core/object");
|
|
6
|
+
const _try = require("@cloudcome/utils-core/try");
|
|
7
|
+
const type = require("@cloudcome/utils-core/type");
|
|
8
|
+
function createCloudObjectError(message, code) {
|
|
9
|
+
return error.errorAssign(new Error(message), {
|
|
10
|
+
errCode: code,
|
|
11
|
+
errMsg: message
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
async function respondCloudObject(fn, requestId) {
|
|
15
|
+
try {
|
|
16
|
+
const data = await fn();
|
|
17
|
+
return {
|
|
18
|
+
requestId,
|
|
19
|
+
data,
|
|
20
|
+
errCode: 0,
|
|
21
|
+
errMsg: ""
|
|
22
|
+
};
|
|
23
|
+
} catch (err) {
|
|
24
|
+
const err2 = error.errorNormalize(err);
|
|
25
|
+
return {
|
|
26
|
+
requestId,
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
data: null,
|
|
29
|
+
errCode: err2.errCode || -1,
|
|
30
|
+
errMsg: err2.errMsg || err2.message || ""
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function buildCloudObjectExposeCreator(options) {
|
|
35
|
+
const buildOptions = object.objectDefaults(options || {}, {
|
|
36
|
+
requiredUserErrCode: "uni-id-check-token-failed",
|
|
37
|
+
requiredUserErrMsg: "需要登录后才能进行此操作"
|
|
38
|
+
});
|
|
39
|
+
const createCloudObjectExpose = (arg0, arg1, arg2) => {
|
|
40
|
+
const optionsSource = type.isFunction(arg0) ? arg1 : arg2;
|
|
41
|
+
const createOptions = object.objectDefaults(optionsSource || {}, {
|
|
42
|
+
requiredUser: false
|
|
43
|
+
});
|
|
44
|
+
return async function(input) {
|
|
45
|
+
return await respondCloudObject(async () => {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
const user = await parseAppendUser(this, options == null ? void 0 : options.uniIdCloudObject);
|
|
48
|
+
const append = {
|
|
49
|
+
options: createOptions,
|
|
50
|
+
user
|
|
51
|
+
};
|
|
52
|
+
const context = Object.assign(this, append);
|
|
53
|
+
if (createOptions.requiredUser && !user.id) {
|
|
54
|
+
throw createCloudObjectError(buildOptions.requiredUserErrMsg, buildOptions.requiredUserErrCode);
|
|
55
|
+
}
|
|
56
|
+
if (type.isFunction(arg0)) {
|
|
57
|
+
return await arg0(context);
|
|
58
|
+
}
|
|
59
|
+
const parsed = arg0.safeParse(input);
|
|
60
|
+
if (!parsed.success) {
|
|
61
|
+
console.log(parsed.error.issues);
|
|
62
|
+
const issue0 = (_b = (_a = parsed.error) == null ? void 0 : _a.issues) == null ? void 0 : _b[0];
|
|
63
|
+
if ((issue0 == null ? void 0 : issue0.code) === "custom") throw issue0.message;
|
|
64
|
+
throw new Error("请求数据不正确");
|
|
65
|
+
}
|
|
66
|
+
return await arg1(context, parsed.data);
|
|
67
|
+
}, this.getUniCloudRequestId());
|
|
68
|
+
};
|
|
12
69
|
};
|
|
13
|
-
return
|
|
70
|
+
return createCloudObjectExpose;
|
|
14
71
|
}
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
72
|
+
async function parseAppendUser(objectThis, uniIdCloudObject) {
|
|
73
|
+
const appendUser = {
|
|
74
|
+
id: "",
|
|
75
|
+
role: [],
|
|
76
|
+
permission: [],
|
|
77
|
+
isAdmin: false
|
|
78
|
+
};
|
|
79
|
+
if (!uniIdCloudObject) return appendUser;
|
|
80
|
+
const uniId = uniIdCloudObject.createInstance({
|
|
81
|
+
clientInfo: objectThis.getClientInfo()
|
|
82
|
+
});
|
|
83
|
+
const [err1, user] = await _try.tryFlatten(uniId.checkToken(objectThis.getUniIdToken() || ""));
|
|
84
|
+
if (!user) return appendUser;
|
|
85
|
+
const [err2, userData] = _try.tryFlatten(() => _helpers.parseCloudObjectOutput(user));
|
|
86
|
+
if (!userData) return appendUser;
|
|
87
|
+
appendUser.id = userData.uid || "";
|
|
88
|
+
appendUser.role = userData.role || [];
|
|
89
|
+
appendUser.permission = userData.permission || [];
|
|
90
|
+
appendUser.isAdmin = appendUser.role.includes("admin") && appendUser.permission.length === 0;
|
|
91
|
+
return appendUser;
|
|
22
92
|
}
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
93
|
+
exports.buildCloudObjectExposeCreator = buildCloudObjectExposeCreator;
|
|
94
|
+
exports.createCloudObjectError = createCloudObjectError;
|
|
95
|
+
exports.respondCloudObject = respondCloudObject;
|
|
25
96
|
//# sourceMappingURL=cloud.cjs.map
|
package/dist/cloud.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud.cjs","sources":["../src/cloud.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"cloud.cjs","sources":["../src/cloud/error.ts","../src/cloud/respond.ts","../src/cloud/expose.ts"],"sourcesContent":["import { errorAssign } from '@cloudcome/utils-core/error';\n\nexport function createCloudObjectError(message: string, code?: number | string) {\n return errorAssign(new Error(message), {\n errCode: code,\n errMsg: message,\n });\n}\n","import { errorNormalize } from '@cloudcome/utils-core/error';\nimport type { MaybePromise } from '@cloudcome/utils-core/types';\nimport type { UniCloudObjectOutput } from './object';\n\nexport async function respondCloudObject<O>(\n fn: () => MaybePromise<O>,\n requestId?: string,\n): Promise<UniCloudObjectOutput<O>> {\n try {\n const data = await fn();\n\n return {\n requestId,\n data,\n errCode: 0,\n errMsg: '',\n };\n } catch (err) {\n const err2 = errorNormalize(err as Error & { errCode?: number | string; errMsg?: string });\n\n return {\n requestId,\n // @ts-ignore\n data: null,\n errCode: err2.errCode || -1,\n errMsg: err2.errMsg || err2.message || '',\n };\n }\n}\n","import { parseCloudObjectOutput } from '@/_helpers';\nimport { objectDefaults } from '@cloudcome/utils-core/object';\nimport { tryFlatten } from '@cloudcome/utils-core/try';\nimport { isFunction } from '@cloudcome/utils-core/type';\nimport type { MaybePromise } from '@cloudcome/utils-core/types';\nimport type z from 'zod';\nimport type { ZodObject } from 'zod';\nimport { createCloudObjectError } from './error';\nimport type { UniCloudObject, UniCloudObjectThis } from './object';\nimport { respondCloudObject } from './respond';\nimport type { UniIdCloudObject } from './uni-id';\n\nexport type UniCloudObjectThisAppendUser = {\n id: string;\n role: string[];\n permission: string[];\n isAdmin: boolean;\n};\n\nexport type UniCloudObjectThisAppend = {\n options: Required<CreateCloudObjectOptions>;\n user: UniCloudObjectThisAppendUser;\n};\n\nexport type UniCloudObjectContext = UniCloudObjectThis & UniCloudObjectThisAppend;\n\n/**\n * 构建云函数暴露创建器的选项配置\n * 用于配置云函数暴露创建器的行为,目前支持传入UniIdCloudObject实例\n */\nexport type BuildCloudExposeCreatorOptions = {\n /**\n * 可选的UniIdCloudObject实例\n * 用于处理用户身份验证和权限管理相关功能\n */\n uniIdCloudObject?: UniIdCloudObject;\n\n /**\n * 需要用户登录态的错误码\n * @default 'uni-id-check-token-failed'\n */\n requiredUserErrCode?: number | string;\n\n /**\n * 需要用户登录态的错误消息\n * @default '需要登录后才能进行此操作'\n */\n requiredUserErrMsg?: string;\n};\n\nexport type CreateCloudObjectOptions = {\n /**\n * 是否需要用户登录态\n * @default false\n */\n requiredUser?: boolean;\n};\n\nexport type CreateCloudObjectExpose = {\n <S extends ZodObject, O>(\n schema: S,\n fn: (context: UniCloudObjectContext, input: z.infer<S>) => MaybePromise<O>,\n options?: CreateCloudObjectOptions,\n ): UniCloudObject<z.infer<S>, O>;\n <O>(\n fn: (context: UniCloudObjectContext) => MaybePromise<O>,\n options?: CreateCloudObjectOptions,\n ): UniCloudObject<void, O>;\n};\n\nexport function buildCloudObjectExposeCreator(options?: BuildCloudExposeCreatorOptions) {\n const buildOptions = objectDefaults(options || {}, {\n requiredUserErrCode: 'uni-id-check-token-failed',\n requiredUserErrMsg: '需要登录后才能进行此操作',\n }) as Required<BuildCloudExposeCreatorOptions>;\n\n // @ts-ignore\n const createCloudObjectExpose: CreateCloudObjectExpose = (arg0, arg1, arg2) => {\n // 选项来源\n const optionsSource = (isFunction(arg0) ? arg1 : arg2) as CreateCloudObjectOptions | undefined;\n // 设置默认选项值\n const createOptions = objectDefaults(optionsSource || {}, {\n requiredUser: false,\n }) as Required<CreateCloudObjectOptions>;\n\n return async function (input) {\n // 处理云函数响应逻辑\n return await respondCloudObject(async () => {\n // 构建附加的上下文信息\n const user = await parseAppendUser(this, options?.uniIdCloudObject);\n const append: UniCloudObjectThisAppend = {\n options: createOptions,\n user: user,\n };\n const context = Object.assign(this, append) as UniCloudObjectContext;\n\n if (createOptions.requiredUser && !user.id) {\n throw createCloudObjectError(buildOptions.requiredUserErrMsg, buildOptions.requiredUserErrCode);\n }\n\n // 无入参\n if (isFunction(arg0)) {\n return await arg0(context);\n }\n\n // 单入参\n // 验证输入数据\n const parsed = arg0.safeParse(input);\n\n if (!parsed.success) {\n console.log(parsed.error.issues);\n\n const issue0 = parsed.error?.issues?.[0];\n\n // 处理验证错误\n if (issue0?.code === 'custom') throw issue0.message;\n throw new Error('请求数据不正确');\n }\n\n return await arg1(context, parsed.data);\n }, this.getUniCloudRequestId());\n };\n };\n\n return createCloudObjectExpose;\n}\n\nasync function parseAppendUser(\n objectThis: UniCloudObjectThis,\n uniIdCloudObject?: UniIdCloudObject,\n): Promise<UniCloudObjectThisAppendUser> {\n const appendUser: UniCloudObjectThisAppendUser = {\n id: '',\n role: [],\n permission: [],\n isAdmin: false,\n };\n\n if (!uniIdCloudObject) return appendUser;\n\n const uniId = uniIdCloudObject.createInstance({\n clientInfo: objectThis.getClientInfo(),\n });\n\n // 忽略错误1\n const [err1, user] = await tryFlatten(uniId.checkToken(objectThis.getUniIdToken() || ''));\n if (!user) return appendUser;\n\n // 忽略错误2\n const [err2, userData] = tryFlatten(() => parseCloudObjectOutput(user));\n if (!userData) return appendUser;\n\n appendUser.id = userData.uid || '';\n appendUser.role = userData.role || [];\n appendUser.permission = userData.permission || [];\n appendUser.isAdmin = appendUser.role.includes('admin') && appendUser.permission.length === 0;\n\n return appendUser;\n}\n"],"names":["errorAssign","errorNormalize","objectDefaults","isFunction","tryFlatten","parseCloudObjectOutput"],"mappings":";;;;;;;AAEgB,SAAA,uBAAuB,SAAiB,MAAwB;AAC9E,SAAOA,kBAAY,IAAI,MAAM,OAAO,GAAG;AAAA,IACrC,SAAS;AAAA,IACT,QAAQ;AAAA,EAAA,CACT;AACH;ACHsB,eAAA,mBACpB,IACA,WACkC;AAC9B,MAAA;AACI,UAAA,OAAO,MAAM,GAAG;AAEf,WAAA;AAAA,MACL;AAAA,MACA;AAAA,MACA,SAAS;AAAA,MACT,QAAQ;AAAA,IACV;AAAA,WACO,KAAK;AACN,UAAA,OAAOC,qBAAe,GAA6D;AAElF,WAAA;AAAA,MACL;AAAA;AAAA,MAEA,MAAM;AAAA,MACN,SAAS,KAAK,WAAW;AAAA,MACzB,QAAQ,KAAK,UAAU,KAAK,WAAW;AAAA,IACzC;AAAA,EAAA;AAEJ;AC0CO,SAAS,8BAA8B,SAA0C;AACtF,QAAM,eAAeC,OAAAA,eAAe,WAAW,IAAI;AAAA,IACjD,qBAAqB;AAAA,IACrB,oBAAoB;AAAA,EAAA,CACrB;AAGD,QAAM,0BAAmD,CAAC,MAAM,MAAM,SAAS;AAE7E,UAAM,gBAAiBC,KAAA,WAAW,IAAI,IAAI,OAAO;AAEjD,UAAM,gBAAgBD,OAAAA,eAAe,iBAAiB,IAAI;AAAA,MACxD,cAAc;AAAA,IAAA,CACf;AAED,WAAO,eAAgB,OAAO;AAErB,aAAA,MAAM,mBAAmB,YAAY;;AAE1C,cAAM,OAAO,MAAM,gBAAgB,MAAM,mCAAS,gBAAgB;AAClE,cAAM,SAAmC;AAAA,UACvC,SAAS;AAAA,UACT;AAAA,QACF;AACA,cAAM,UAAU,OAAO,OAAO,MAAM,MAAM;AAE1C,YAAI,cAAc,gBAAgB,CAAC,KAAK,IAAI;AAC1C,gBAAM,uBAAuB,aAAa,oBAAoB,aAAa,mBAAmB;AAAA,QAAA;AAI5F,YAAAC,KAAAA,WAAW,IAAI,GAAG;AACb,iBAAA,MAAM,KAAK,OAAO;AAAA,QAAA;AAKrB,cAAA,SAAS,KAAK,UAAU,KAAK;AAE/B,YAAA,CAAC,OAAO,SAAS;AACX,kBAAA,IAAI,OAAO,MAAM,MAAM;AAE/B,gBAAM,UAAS,kBAAO,UAAP,mBAAc,WAAd,mBAAuB;AAGtC,eAAI,iCAAQ,UAAS,SAAU,OAAM,OAAO;AACtC,gBAAA,IAAI,MAAM,SAAS;AAAA,QAAA;AAG3B,eAAO,MAAM,KAAK,SAAS,OAAO,IAAI;AAAA,MAAA,GACrC,KAAK,sBAAsB;AAAA,IAChC;AAAA,EACF;AAEO,SAAA;AACT;AAEA,eAAe,gBACb,YACA,kBACuC;AACvC,QAAM,aAA2C;AAAA,IAC/C,IAAI;AAAA,IACJ,MAAM,CAAC;AAAA,IACP,YAAY,CAAC;AAAA,IACb,SAAS;AAAA,EACX;AAEI,MAAA,CAAC,iBAAyB,QAAA;AAExB,QAAA,QAAQ,iBAAiB,eAAe;AAAA,IAC5C,YAAY,WAAW,cAAc;AAAA,EAAA,CACtC;AAGD,QAAM,CAAC,MAAM,IAAI,IAAI,MAAMC,KAAA,WAAW,MAAM,WAAW,WAAW,cAAmB,KAAA,EAAE,CAAC;AACpF,MAAA,CAAC,KAAa,QAAA;AAGZ,QAAA,CAAC,MAAM,QAAQ,IAAIA,gBAAW,MAAMC,SAAAA,uBAAuB,IAAI,CAAC;AAClE,MAAA,CAAC,SAAiB,QAAA;AAEX,aAAA,KAAK,SAAS,OAAO;AACrB,aAAA,OAAO,SAAS,QAAQ,CAAC;AACzB,aAAA,aAAa,SAAS,cAAc,CAAC;AACrC,aAAA,UAAU,WAAW,KAAK,SAAS,OAAO,KAAK,WAAW,WAAW,WAAW;AAEpF,SAAA;AACT;;;;"}
|
package/dist/cloud.d.ts
CHANGED
|
@@ -1,53 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
errCode?: number | string;
|
|
7
|
-
errMsg?: string;
|
|
8
|
-
data: T;
|
|
9
|
-
};
|
|
10
|
-
export type UniCloudObjectServer<O> = Record<string, (...inputs: unknown[]) => Promise<UniCloudObjectOutput<O>>>;
|
|
11
|
-
export type CreateUseCloudObjectOptions = ImportObjectArgs[1] & {
|
|
12
|
-
/**
|
|
13
|
-
* 模拟云对象,用于单元测试
|
|
14
|
-
* @private
|
|
15
|
-
*/
|
|
16
|
-
_mockServer?: any;
|
|
17
|
-
};
|
|
18
|
-
export type UseCloudObject = {
|
|
19
|
-
<I extends AnyArray, O>(caller: (server: UniCloudObjectServer<O>, ...inputs: I) => Promise<UniCloudObjectOutput<O>>, options: Omit<UseRequestOptions<I, O>, 'placeholder'> & {
|
|
20
|
-
placeholder: () => O;
|
|
21
|
-
}): UseRequestOutputFilled<I, O>;
|
|
22
|
-
<I extends AnyArray, O>(caller: (server: UniCloudObjectServer<O>, ...inputs: I) => Promise<UniCloudObjectOutput<O>>, options?: UseRequestOptions<I, O>): UseRequestOutput<I, O>;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* 创建一个用于调用云对象的hook工厂函数
|
|
26
|
-
* @param objectName 云对象名称,用于导入对应的云对象
|
|
27
|
-
* @param options 导入云对象时的可选配置参数
|
|
28
|
-
* @returns 返回一个函数,该函数可以用于创建云对象调用hook
|
|
29
|
-
*/
|
|
30
|
-
export declare function createUseCloudObject(objectName: ImportObjectArgs[0], options?: CreateUseCloudObjectOptions): UseCloudObject;
|
|
31
|
-
export type UniCloudDatabaseOutput<T> = {
|
|
32
|
-
result: T & {
|
|
33
|
-
errCode?: number | string;
|
|
34
|
-
errMsg?: string;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
export type UseCloudDatabaseOptions<I extends AnyArray, O> = UseRequestOptions<I, O> & {
|
|
38
|
-
/**
|
|
39
|
-
* 模拟数据库,用于单元测试
|
|
40
|
-
*/
|
|
41
|
-
_mockDatabase?: any;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* 创建一个用于调用云数据库的hook
|
|
45
|
-
* @param caller 调用云数据库的函数,接收数据库实例和输入参数,返回Promise
|
|
46
|
-
* @param options 配置选项
|
|
47
|
-
* @returns 返回一个请求hook,用于处理云数据库调用
|
|
48
|
-
*/
|
|
49
|
-
export declare function useCloudDatabase<I extends AnyArray, O>(caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniCloudDatabaseOutput<O>>, options: Omit<UseCloudDatabaseOptions<I, O>, 'placeholder'> & {
|
|
50
|
-
placeholder: () => O;
|
|
51
|
-
}): UseRequestOutputFilled<I, O>;
|
|
52
|
-
export declare function useCloudDatabase<I extends AnyArray, O>(caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniCloudDatabaseOutput<O>>, options?: UseCloudDatabaseOptions<I, O>): UseRequestOutput<I, O>;
|
|
53
|
-
export {};
|
|
1
|
+
export * from './cloud/error';
|
|
2
|
+
export * from './cloud/expose';
|
|
3
|
+
export * from './cloud/object';
|
|
4
|
+
export * from './cloud/respond';
|
|
5
|
+
export * from './cloud/uni-id';
|