本文整理汇总了TypeScript中cafy.obj函数的典型用法代码示例。如果您正苦于以下问题:TypeScript obj函数的具体用法?TypeScript obj怎么用?TypeScript obj使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了obj函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: default
export default (config: IApiConfig): void => {
const allScopes = AuthScopes.toArray();
// verify api config
const verificationConfig = $.obj({
appSecretKey: $.str,
hostToken: $.obj({
scopes: $.array($.str.pipe(scope => allScopes.find(s => s.id == scope) != null)).unique()
})
});
if (verificationConfig.nok(config)) {
throw new Error('invalid api config');
}
};
示例2: default
export default (config: IServerConfig): void => {
// verify server config
const verificationServerConfig = $.obj({
httpPort: $.num.optional.nullable,
mongo: $.obj({
url: $.str,
dbName: $.str
}),
enableApi: $.bool,
enableWebApp: $.bool
});
if (verificationServerConfig.nok(config)) {
throw new Error('invalid server config');
}
};
示例3: async
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Get 'home' parameter
const [home, homeErr] = $.arr($.obj({
name: $.str,
id: $.str,
data: $.obj()
}).strict()).get(params.home);
if (homeErr) return rej('invalid home param');
await User.update(user._id, {
$set: {
'clientSettings.mobileHome': home
}
});
res();
publishUserStream(user._id, 'mobile_home_updated', home);
});
示例4: default
export default (config: IWebAppConfig): void => {
// verify webapp config
const verificationConfig = $.obj({
apiBaseUrl: $.str,
hostToken: $.obj({
accessToken: $.str
}),
clientToken: $.obj({
scopes: $.array($.str).unique()
}),
recaptcha: $.obj({
enable: $.boolean,
siteKey: $.str,
secretKey: $.str
})
});
if (verificationConfig.nok(config)) {
throw new Error('invalid webapp config');
}
};
示例5:
ja: 'コンテンツの警告。このパラメータを指定すると設定したテキストで投稿のコンテンツを隠す事が出来ます。'
}
}),
viaMobile: $.bool.optional.note({
default: false,
desc: {
ja: 'モバイルデバイスからの投稿か否か。'
}
}),
geo: $.obj({
coordinates: $.arr().length(2)
.item(0, $.num.range(-180, 180))
.item(1, $.num.range(-90, 90)),
altitude: $.num.nullable,
accuracy: $.num.nullable,
altitudeAccuracy: $.num.nullable,
heading: $.num.nullable.range(0, 360),
speed: $.num.nullable
}).optional.nullable.strict().note({
desc: {
ja: '位置情報'
},
ref: 'geo'
}),
mediaIds: $.arr($.type(ID)).optional.unique().range(1, 4).note({
desc: {
ja: '添付するメディア'
}
}),
示例6: async
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Get 'id' parameter
const [id, idErr] = $.str.get(params.id);
if (idErr) return rej('invalid id param');
// Get 'data' parameter
const [data, dataErr] = $.obj().get(params.data);
if (dataErr) return rej('invalid data param');
if (id == null && data == null) return rej('you need to set id and data params if home param unset');
let widget;
//#region Desktop home
if (widget == null && user.clientSettings.home) {
const desktopHome = user.clientSettings.home;
widget = desktopHome.find((w: any) => w.id == id);
if (widget) {
widget.data = data;
await User.update(user._id, {
$set: {
'clientSettings.home': desktopHome
}
});
}
}
//#endregion
//#region Mobile home
if (widget == null && user.clientSettings.mobileHome) {
const mobileHome = user.clientSettings.mobileHome;
widget = mobileHome.find((w: any) => w.id == id);
if (widget) {
widget.data = data;
await User.update(user._id, {
$set: {
'clientSettings.mobileHome': mobileHome
}
});
}
}
//#endregion
//#region Deck
if (widget == null && user.clientSettings.deck && user.clientSettings.deck.columns) {
const deck = user.clientSettings.deck;
deck.columns.filter((c: any) => c.type == 'widgets').forEach((c: any) => {
c.widgets.forEach((w: any) => {
if (w.id == id) widget = w;
});
});
if (widget) {
widget.data = data;
await User.update(user._id, {
$set: {
'clientSettings.deck': deck
}
});
}
}
//#endregion
if (widget) {
publishUserStream(user._id, 'widgetUpdated', {
id, data
});
res();
} else {
rej('widget not found');
}
});