@ data-fair/ lib- 常见类型
JSON 计划类型和 TypeScript 类型在数据公平堆栈(会话状态,账户,事件,通知,主题,目录和处理插件合同...)之间共享,其生成的验证器和几个帮助器在其上建起. 服务, Vue 应用程序和插件导入它,以便它们都说相同的合同.
安装
npm i @data-fair/lib-common-types
可选对等依赖 : tinycolor2 (v1),仅需满足 theme/index.js。 。 。 .
模块
每个目录模块都会导出其生成的类型(和 validate 编号 : assertValid 编号 : returnValid 从 index.js作为默认导出 schema.js。 。 。 .
| 导入路径 | 说明 |
|---|---|
@data-fair/lib-common-types/session/index.js | SessionState, (中文(简体) ), SessionStateAuthenticated, (中文(简体) ), User, (中文(简体) ), Account...类型、验证符和 isAuthenticated, (中文(简体) ), assertAuthenticated, (中文(简体) ), assertAdminMode, (中文(简体) ), getAccountRole, (中文(简体) ), assertAccountRole, (中文(简体) ), isValidAccountType, (中文(简体) ), assertValidAccountType 帮手. |
@data-fair/lib-common-types/account/index.js | Account (资源拥有者)和 AccountKeys 类型,验证符. |
@data-fair/lib-common-types/access-ref/index.js | AccessRef 允许目标类型、验证符、, matchAccessRef(session, accessRef) 财务报告和审定财务报表 mongoFilterAccessRef(session)。 。 。 . |
@data-fair/lib-common-types/application/index.js | Application, (中文(简体) ), Dataset 财务报告和审定财务报表 Field 类型,如数据公平应用程序所示. |
@data-fair/lib-common-types/event/index.js | Event 类型(活动服务). |
@data-fair/lib-common-types/notification/index.js | Notification 类型,验证符. |
@data-fair/lib-common-types/theme/index.js | Theme 编号 : Colors 类型, defaultTheme, (中文(简体) ), fillTheme,颜色对比帮助器(getReadableColor, (中文(简体) ), getOnColor, (中文(简体) ), getColorsWarnings, (中文(简体) ), getSiteColorsWarnings(......) (中文(简体) ). |
@data-fair/lib-common-types/catalog/index.js | 这个 CatalogPlugin 合同目录插件及其上下文类型. |
@data-fair/lib-common-types/processings.js | 这个 PrepareFunction, (中文(简体) ), RunFunction, (中文(简体) ), ProcessingContext 财务报告和审定财务报表 LogFunctions 类型处理插件. |
@data-fair/lib-common-types/ws.js | Message 类型. |
@data-fair/lib-common-types/scopes.js | defineScopes (a) 服务范围词汇:每级接受范围、说明、全球范围), globalScopes, (中文(简体) ), oauth2SecurityScheme。 。 。 . |
使用量
会议
会话状态通常通过会话中间软件获得: @data-fair/lib-express 或者说 useSession 联 合 国 @data-fair/lib-vue;此包提供了其类型和检查。 见 数据-公平会议技能。 。 。 .
import { type SessionState, assertAccountRole } from '@data-fair/lib-common-types/session/index.js'
// throws httpError(401) if not authenticated, httpError(403) if the active account does not have the role
assertAccountRole(sessionState, resource.owner, 'admin')
getAccountRole(sessionState, account, { allAccounts?, acceptDepAsRoot? }) 返回角色而不是抛出( e)'admin' 在管理模式中,为了用户自己的账户, null (如果无).
参考共享计划
与 @data-fair/lib-types-builder 能够 $ref 共同的计谋 $id (单位:千美元)https://github.com/data-fair/lib/<name>:
owner: { $ref: 'https://github.com/data-fair/lib/account' },
topic: { $ref: 'https://github.com/data-fair/lib/event#/$defs/topicRef' }
插件
import type { PrepareFunction, RunFunction, ProcessingContext } from '@data-fair/lib-common-types/processings.js'
import type { CatalogPlugin } from '@data-fair/lib-common-types/catalog/index.js'
见 数据处理技能。 。 。 .
范围
一个服务宣布其范围家族一次;匹配 session/index.js (单位:千美元)hasScope准确的或赤裸的伞, 从来没有前缀)保持不变.
import { defineScopes, oauth2SecurityScheme, oauth2Alternatives } from '@data-fair/lib-common-types/scopes.js'
const scopes = defineScopes({
notifications: {
tiers: ['read', 'write'],
descriptions: {
umbrella: { fr: 'Tous les droits sur les notifications', en: 'All notification scopes' },
read: { fr: 'Lire ses notifications', en: 'Read own notifications' },
write: { fr: 'Gérer ses abonnements', en: 'Manage own subscriptions' }
}
}
})
// notifications:write notifications all:write all:admin
requireScope(scopes.acceptedScopes('notifications', 'write'))
// the oauth2 scheme of the service's OpenAPI document
oauth2SecurityScheme(scopes, { directoryUrl, locale: 'fr' })
// an operation's security: [{ sdCookie: [] }, { oauth2: ['notifications:write'] }, { oauth2: ['notifications'] }, ...]
const security = [{ sdCookie: [] }, ...oauth2Alternatives(scopes.acceptedScopes('notifications', 'write'))]
acceptedScopes(family, tier): 家庭申报的级别在或以上tier伞,然后all:<tier>和更高层次的全球范围。 家庭不申报投球.familyScopes(family):每个能达到家庭某层的瞄准镜, 对于一个粗糙的门.scopeDescriptions(locale):对每个申报范围的说明all:*包括这些.oauth2Alternatives(accepted):每个接受范围有一个OpenAPI安全选项. 单人{ oauth2: [a, b] }意味着一个象征 既需要。 真是个all:*范围补助金从 列出它的操作,数据公平平台文档依赖于此表单.- 全球级范围及其描述在此拥有(
globalScopes),每项服务都相同.all作为姓氏保留.