UNPKG

@pagenote/notion-database

Version:

make notion as a real-database for server

62 lines 2.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dataToNotionFilter = exports.dataToNotionProperties = void 0; const util_1 = require("../transformer/util"); const transformer_1 = require("../transformer"); function dataToNotionProperties(data, cloudPropertiesSchema, localPropertiesSchema) { var _a; const properties = {}; for (let i in data) { const currentTempData = data[i]; let type; if (cloudPropertiesSchema && cloudPropertiesSchema[i]) { type = (_a = cloudPropertiesSchema[i]) === null || _a === void 0 ? void 0 : _a.type; } else if (localPropertiesSchema && localPropertiesSchema[i]) { type = localPropertiesSchema[i].type; console.warn('未匹配到远程表结构对应字段,使用 demo 数据推断类型,可能异常,请注意'); } else { type = (0, util_1.getNotionTypeFromData)(currentTempData); console.warn('含有未定义的字段,请注意,正通过推断设置类型' + i, '推断结果为:', type); } const notionDefinedType = transformer_1.default[type]; if (notionDefinedType) { properties[i] = notionDefinedType === null || notionDefinedType === void 0 ? void 0 : notionDefinedType.objectToProperty(currentTempData); } else { console.warn('没有找到对应类型的转换方法,objectToProperty'); } } return properties; } exports.dataToNotionProperties = dataToNotionProperties; // 用户自己定义的类型保护! function isCustomFilter(arg) { return (arg === null || arg === void 0 ? void 0 : arg.and) !== undefined; } /** * 将js 查询对象,转换为 notion 可接收的过滤器。 */ function dataToNotionFilter(data, properties) { var _a; if (isCustomFilter(data)) { return data; } else { const result = { and: [] }; for (let i in data) { const currentTempData = data[i]; const type = (_a = properties[i]) === null || _a === void 0 ? void 0 : _a.type; if (type && transformer_1.default[type]) { result.and.push(transformer_1.default[type].objectToPropertyFilter(i, currentTempData)); } else { console.error(`property ${i} is undefined,ignored. schema is:`, properties); } } return result; } } exports.dataToNotionFilter = dataToNotionFilter; //# sourceMappingURL=table.js.map