kintone-as-code
Version:
A CLI tool for managing kintone applications as code with type-safe TypeScript schemas
81 lines • 2.02 kB
JavaScript
// 日付関数
export const TODAY = () => ({
_tag: 'function',
_type: 'date',
name: 'TODAY',
});
export const NOW = () => ({
_tag: 'function',
_type: 'date',
name: 'NOW',
});
export const FROM_TODAY = (days, unit) => ({
_tag: 'function',
_type: 'date',
name: 'FROM_TODAY',
args: [days, unit],
});
export const THIS_WEEK = () => ({
_tag: 'function',
_type: 'date',
name: 'THIS_WEEK',
});
export const THIS_MONTH = () => ({
_tag: 'function',
_type: 'date',
name: 'THIS_MONTH',
});
export const THIS_YEAR = () => ({
_tag: 'function',
_type: 'date',
name: 'THIS_YEAR',
});
export const LAST_WEEK = () => ({
_tag: 'function',
_type: 'date',
name: 'LAST_WEEK',
});
export const LAST_MONTH = () => ({
_tag: 'function',
_type: 'date',
name: 'LAST_MONTH',
});
export const LAST_YEAR = () => ({
_tag: 'function',
_type: 'date',
name: 'LAST_YEAR',
});
// ユーザー関数
export const LOGINUSER = () => ({
_tag: 'function',
_type: 'user',
name: 'LOGINUSER',
});
// カスタム関数(将来の拡張や未サポート関数を型安全に表現するためのエスケープハッチ)
export const customDateFunction = (name, ...args) => ({
_tag: 'function',
_type: 'date',
name,
args,
});
export const customUserFunction = (name, ...args) => ({
_tag: 'function',
_type: 'user',
name,
args,
});
// 関数を文字列に変換
export const formatFunction = (func) => {
const escapeString = (value) => value
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\n/g, '\\n')
.replace(/\t/g, '\\t')
.replace(/\r/g, '\\r');
if (func.args && func.args.length > 0) {
const formattedArgs = func.args.map((arg) => typeof arg === 'string' ? `"${escapeString(arg)}"` : String(arg));
return `${func.name}(${formattedArgs.join(', ')})`;
}
return `${func.name}()`;
};
//# sourceMappingURL=functions.js.map