@soffits/dsh-card-board 0.3.0 → 0.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/CHANGELOG.md +13 -0
- package/README.md +19 -6
- package/client.actions.js +36 -61
- package/client.js +285 -146
- package/examples/boards/home/board.json +25 -5
- package/examples/boards/home/cards/chores.json +40 -10
- package/examples/boards/home/cards/energy.json +53 -8
- package/examples/boards/home/cards/house.json +44 -11
- package/examples/boards/home/cards/next-weeks.json +47 -6
- package/examples/boards/home/cards/savings.json +64 -11
- package/examples/boards/home/cards/spending.json +44 -7
- package/examples/boards/home/cards/weather.json +29 -3
- package/index.js +3 -0
- package/locale/en.json +50 -1
- package/locale/fr.json +50 -0
- package/locale/zh.json +50 -1
- package/package.json +3 -2
- package/src/messages.js +53 -0
- package/src/routes.js +13 -2
- package/src/schema.js +57 -28
package/locale/zh.json
CHANGED
|
@@ -1 +1,50 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "卡片面板",
|
|
4
|
+
"description": "由你自己的脚本更新的卡片和图表面板。每个人只能看到允许自己看的面板。"
|
|
5
|
+
},
|
|
6
|
+
"ui": {
|
|
7
|
+
"panel": "面板",
|
|
8
|
+
"title": "面板",
|
|
9
|
+
"updated": "{time} 更新",
|
|
10
|
+
"refreshFailed": "刷新失败,稍后重试",
|
|
11
|
+
"loading": "加载中…",
|
|
12
|
+
"emptyTitle": "还没有面板。",
|
|
13
|
+
"emptyHint": "脚本把 board.json 写进数据目录后,面板就会出现在这里。",
|
|
14
|
+
"noCards": "这个面板还没有卡片。",
|
|
15
|
+
"cardError": "这张卡片无法显示",
|
|
16
|
+
"boardProblems": "board.json 有问题:",
|
|
17
|
+
"stale": "已过时 · {age}",
|
|
18
|
+
"open": "打开",
|
|
19
|
+
"listEmpty": "暂无",
|
|
20
|
+
"checked": "已完成",
|
|
21
|
+
"unchecked": "未完成",
|
|
22
|
+
"error.forbidden": "你没有权限查看这个面板。",
|
|
23
|
+
"error.notFound": "这个面板已经不存在了。",
|
|
24
|
+
"error.gone": "这个操作已经不在卡片上了。",
|
|
25
|
+
"error.noProvider": "面板需要一个能确认访问者身份的登录插件,但现在没有运行。",
|
|
26
|
+
"error.http": "出了点问题(HTTP {status})。",
|
|
27
|
+
"summary.latest": "{name}:{value}({x},共 {n} 个点,从 {from} 起)",
|
|
28
|
+
"summary.latestName": "最新",
|
|
29
|
+
"summary.goal": "目标:{value}",
|
|
30
|
+
"summary.progress": "进度:{done}/{total}",
|
|
31
|
+
"action.chat": "问问",
|
|
32
|
+
"action.chatAbout": "聊聊这个",
|
|
33
|
+
"action.done": "完成",
|
|
34
|
+
"action.snooze": "稍后提醒",
|
|
35
|
+
"action.event": "执行",
|
|
36
|
+
"action.link": "打开",
|
|
37
|
+
"action.in3h": "3 小时后",
|
|
38
|
+
"action.tomorrow": "明天 9:00",
|
|
39
|
+
"action.pick": "选个时间…",
|
|
40
|
+
"action.set": "稍后提醒",
|
|
41
|
+
"action.cancel": "取消",
|
|
42
|
+
"action.sending": "发送中…",
|
|
43
|
+
"action.pending": "等待处理",
|
|
44
|
+
"action.handled": "已处理",
|
|
45
|
+
"action.unhandled": "还没有被处理",
|
|
46
|
+
"action.failed": "没有成功:{message}",
|
|
47
|
+
"action.noWorkspace": "请先打开一次对话,再试一次。",
|
|
48
|
+
"action.chatNamed": "问问 {name}"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soffits/dsh-card-board",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A data-driven card board for DeepSeek Harness: scripts write small JSON cards, the Web UI shows each person the boards they may see.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
"@deepseek-ai/cordis": "^4.1.0",
|
|
78
78
|
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.1",
|
|
79
79
|
"@deepseek-ai/dsh-credentials": "0.2.2-rc.1",
|
|
80
|
-
"@deepseek-ai/dsh-host-webserver": "0.2.2-rc.1"
|
|
80
|
+
"@deepseek-ai/dsh-host-webserver": "0.2.2-rc.1",
|
|
81
|
+
"acorn": "^8.19.0"
|
|
81
82
|
}
|
|
82
83
|
}
|
package/src/messages.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's own words. One file per language in `locale/<tag>.json` (the same
|
|
3
|
+
* layout DSH packages use for their titles); a file's `ui` object holds the
|
|
4
|
+
* page's messages next to its `meta`. Which languages exist is whatever files
|
|
5
|
+
* are there: nothing in the code names one.
|
|
6
|
+
*
|
|
7
|
+
* A request for a language gets English overlaid by the language's primary
|
|
8
|
+
* tag and then by the exact tag, so a half-translated file still shows whole
|
|
9
|
+
* pages (`pt-BR` → `pt` → `en`).
|
|
10
|
+
*/
|
|
11
|
+
import { readFile, readdir } from 'node:fs/promises'
|
|
12
|
+
import { join } from 'node:path'
|
|
13
|
+
|
|
14
|
+
export const LANGUAGE_ID = /^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/
|
|
15
|
+
const REFERENCE = 'en'
|
|
16
|
+
|
|
17
|
+
/** Every language file in `directory`: lowercase id → its `ui` messages. */
|
|
18
|
+
export async function readLanguages(directory) {
|
|
19
|
+
const languages = new Map()
|
|
20
|
+
for (const name of (await readdir(directory)).sort()) {
|
|
21
|
+
if (!name.endsWith('.json') || !LANGUAGE_ID.test(name.slice(0, -5))) continue
|
|
22
|
+
const parsed = JSON.parse(await readFile(join(directory, name), 'utf8'))
|
|
23
|
+
if (typeof parsed.ui === 'object' && parsed.ui !== null) languages.set(name.slice(0, -5).toLowerCase(), parsed.ui)
|
|
24
|
+
}
|
|
25
|
+
return languages
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The tags to try for `tag`, most specific first, ending with English: `fr-CA` → fr-ca, fr, en. */
|
|
29
|
+
export function fallbackChain(tag) {
|
|
30
|
+
const parts = String(tag).toLowerCase().split('-')
|
|
31
|
+
const chain = parts.map((_, i) => parts.slice(0, parts.length - i).join('-'))
|
|
32
|
+
return chain.includes(REFERENCE) ? chain : [...chain, REFERENCE]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The merged messages for `tag`, and the tags that contributed (most specific first). */
|
|
36
|
+
export function messagesFor(languages, tag) {
|
|
37
|
+
const used = fallbackChain(tag).filter(id => languages.has(id))
|
|
38
|
+
const messages = {}
|
|
39
|
+
for (const id of [...used].reverse()) Object.assign(messages, languages.get(id))
|
|
40
|
+
return { tag: used[0] ?? REFERENCE, messages }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {string} directory - the package's `locale` folder
|
|
45
|
+
* @returns {(tag: string) => Promise<{ tag: string, messages: Record<string, string> }>}
|
|
46
|
+
*/
|
|
47
|
+
export function createMessages(directory) {
|
|
48
|
+
let languages
|
|
49
|
+
return async tag => {
|
|
50
|
+
languages ??= readLanguages(directory)
|
|
51
|
+
return messagesFor(await languages, tag)
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/routes.js
CHANGED
|
@@ -6,15 +6,18 @@
|
|
|
6
6
|
*
|
|
7
7
|
* GET /api/card-board/boards the boards this viewer may see
|
|
8
8
|
* GET /api/card-board/board?id=<id> one board with its cards (ETag, 304)
|
|
9
|
+
* GET /api/card-board/locale?tag=fr the page's own words for a language (from locale/*.json)
|
|
9
10
|
* POST /api/card-board/action press a done, snooze or event action
|
|
10
11
|
*/
|
|
11
12
|
import { maySee, viewerOf } from './access.js'
|
|
13
|
+
import { LANGUAGE_ID } from './messages.js'
|
|
12
14
|
import { ID_PATTERN, PRESS_KINDS, findAction } from './schema.js'
|
|
13
15
|
import { boardTag, cardPath, listBoards, readBoard, readCard, readCards, resolveDataDir } from './store.js'
|
|
14
16
|
|
|
15
17
|
export const BOARDS_PATH = '/api/card-board/boards'
|
|
16
18
|
export const BOARD_PATH = '/api/card-board/board'
|
|
17
19
|
export const ACTION_PATH = '/api/card-board/action'
|
|
20
|
+
export const LOCALE_PATH = '/api/card-board/locale'
|
|
18
21
|
const DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/
|
|
19
22
|
|
|
20
23
|
const HEADERS = {
|
|
@@ -36,9 +39,16 @@ const NO_PROVIDER = 'This board needs a sign-in plugin that provides requestIden
|
|
|
36
39
|
* @param {() => object | undefined} options.identity - the requestIdentity service right now, if any
|
|
37
40
|
* @param {number} options.pollSeconds
|
|
38
41
|
* @param {ReturnType<import('./presses.js').createPresses>} options.presses
|
|
42
|
+
* @param {(tag: string) => Promise<object>} options.messages - the page's words for a language
|
|
39
43
|
* @param {string} [options.version] - mixed into ETags, so a plugin update refreshes open pages
|
|
40
44
|
*/
|
|
41
|
-
export function createRoutes({ dataDir, people, identity, pollSeconds, presses, version = '' }) {
|
|
45
|
+
export function createRoutes({ dataDir, people, identity, pollSeconds, presses, messages, version = '' }) {
|
|
46
|
+
async function locale(request) {
|
|
47
|
+
const tag = new URL(request.url).searchParams.get('tag') ?? 'en'
|
|
48
|
+
if (!LANGUAGE_ID.test(tag)) return json(400, { error: 'Not a language id.' })
|
|
49
|
+
return json(200, await messages(tag))
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
async function boards() {
|
|
43
53
|
const viewer = await viewerOf(people, identity())
|
|
44
54
|
if (viewer.unavailable) return json(503, { error: NO_PROVIDER })
|
|
@@ -65,7 +75,7 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
|
|
|
65
75
|
const tag = await boardTag(root, id, `${version}\0${viewer.mode}\0${viewer.person ?? ''}\0${JSON.stringify(states)}`)
|
|
66
76
|
if (request.headers.get('if-none-match') === tag) return new Response(null, { status: 304, headers: { ...HEADERS, etag: tag } })
|
|
67
77
|
const cards = (await readCards(root, id, entry.board)).map(card => (states[card.id] ? { ...card, presses: states[card.id] } : card))
|
|
68
|
-
return json(200, { id, title: entry.board?.title ?? id, problems: entry.problems, cards }, { etag: tag })
|
|
78
|
+
return json(200, { id, title: entry.board?.title ?? id, ...(entry.board?.assistant ? { assistant: entry.board.assistant } : {}), problems: entry.problems, cards }, { etag: tag })
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
/** Press states of every card on a board that has recent presses, by card id. */
|
|
@@ -115,6 +125,7 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
|
|
|
115
125
|
return [
|
|
116
126
|
{ path: BOARDS_PATH, methods: ['GET'], requestBody: 'buffered', fetch: boards },
|
|
117
127
|
{ path: BOARD_PATH, methods: ['GET'], requestBody: 'buffered', fetch: board },
|
|
128
|
+
{ path: LOCALE_PATH, methods: ['GET'], requestBody: 'buffered', fetch: locale },
|
|
118
129
|
{ path: ACTION_PATH, methods: ['POST'], requestBody: 'buffered', fetch: action },
|
|
119
130
|
]
|
|
120
131
|
}
|
package/src/schema.js
CHANGED
|
@@ -23,6 +23,8 @@ export const MAX_CARD_BYTES = 256 * 1024
|
|
|
23
23
|
|
|
24
24
|
const MAX_TEXT = 200
|
|
25
25
|
const MAX_ITEMS = 500
|
|
26
|
+
const MAX_LANGUAGES = 12
|
|
27
|
+
const LANGUAGE_ID = /^[a-z]{2,3}(-[a-z0-9]{2,8})*$/
|
|
26
28
|
const MAX_POINTS = 2000
|
|
27
29
|
const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/
|
|
28
30
|
const DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/
|
|
@@ -63,6 +65,25 @@ class Check {
|
|
|
63
65
|
return true
|
|
64
66
|
}
|
|
65
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Text a person reads: a string, or a map of language id to string with `en` always present
|
|
70
|
+
* (the shape DSH uses for localized package text). The browser picks by the active language.
|
|
71
|
+
*/
|
|
72
|
+
label(value, path, options = {}) {
|
|
73
|
+
if (value === undefined) return false
|
|
74
|
+
if (typeof value === 'string') return this.text(value, path, options)
|
|
75
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) return this.fail(path, 'must be a string or an object of language id to string')
|
|
76
|
+
const languages = Object.keys(value)
|
|
77
|
+
if (languages.length === 0 || languages.length > MAX_LANGUAGES) return this.fail(path, `needs 1 to ${MAX_LANGUAGES} languages`)
|
|
78
|
+
if (!('en' in value)) this.fail(path, 'needs an "en" text')
|
|
79
|
+
let ok = true
|
|
80
|
+
for (const language of languages) {
|
|
81
|
+
if (!LANGUAGE_ID.test(language)) ok = this.fail(join(path, language), 'is not a lowercase language id like en or zh-cn')
|
|
82
|
+
else ok = this.text(value[language], join(path, language), options) && ok
|
|
83
|
+
}
|
|
84
|
+
return ok
|
|
85
|
+
}
|
|
86
|
+
|
|
66
87
|
number(value, path, { min = -Infinity } = {}) {
|
|
67
88
|
if (value === undefined) return false
|
|
68
89
|
if (typeof value !== 'number' || !Number.isFinite(value)) return this.fail(path, 'must be a finite number')
|
|
@@ -86,6 +107,13 @@ class Check {
|
|
|
86
107
|
return this.text(value, path)
|
|
87
108
|
}
|
|
88
109
|
|
|
110
|
+
/** A shown value: a number, or a label. */
|
|
111
|
+
labelOrNumber(value, path) {
|
|
112
|
+
if (value === undefined) return false
|
|
113
|
+
if (typeof value === 'number') return this.number(value, path)
|
|
114
|
+
return this.label(value, path)
|
|
115
|
+
}
|
|
116
|
+
|
|
89
117
|
date(value, path) {
|
|
90
118
|
if (value === undefined) return false
|
|
91
119
|
if (typeof value !== 'string' || !(DATE_ONLY.test(value) || DATE_TIME.test(value)) || Number.isNaN(Date.parse(value)))
|
|
@@ -125,7 +153,7 @@ function actions(c, list, path) {
|
|
|
125
153
|
if (typeof action.id !== 'string' || !ACTION_ID_PATTERN.test(action.id)) c.fail(join(p, 'id'), 'must be letters, digits and . _ : - (up to 100), starting with a letter or digit')
|
|
126
154
|
else if (seen.has(action.id)) c.fail(join(p, 'id'), 'repeats another action id here')
|
|
127
155
|
else seen.add(action.id)
|
|
128
|
-
if ('label' in action) c.
|
|
156
|
+
if ('label' in action) c.label(action.label, join(p, 'label'), { max: 40 })
|
|
129
157
|
else if (action.kind === 'event') c.fail(join(p, 'label'), 'is required for an event action')
|
|
130
158
|
const payload = action.payload
|
|
131
159
|
if ('payload' in action) {
|
|
@@ -152,16 +180,16 @@ function statData(c, data, path) {
|
|
|
152
180
|
data.items.forEach((item, i) => {
|
|
153
181
|
const p = join(join(path, 'items'), i)
|
|
154
182
|
if (!c.object(item, p, ['label', 'value'], ['unit', 'delta', 'sub', 'tone'])) return
|
|
155
|
-
c.
|
|
156
|
-
c.
|
|
157
|
-
c.optional(item, 'unit', v => c.
|
|
158
|
-
c.optional(item, 'sub', v => c.
|
|
183
|
+
c.label(item.label, join(p, 'label'))
|
|
184
|
+
c.labelOrNumber(item.value, join(p, 'value'))
|
|
185
|
+
c.optional(item, 'unit', v => c.label(v, join(p, 'unit'), { max: 20 }))
|
|
186
|
+
c.optional(item, 'sub', v => c.label(v, join(p, 'sub')))
|
|
159
187
|
tone(c, item, p)
|
|
160
188
|
c.optional(item, 'delta', delta => {
|
|
161
189
|
const dp = join(p, 'delta')
|
|
162
190
|
if (!c.object(delta, dp, ['value'], ['unit', 'tone'])) return
|
|
163
191
|
c.number(delta.value, join(dp, 'value'))
|
|
164
|
-
c.optional(delta, 'unit', v => c.
|
|
192
|
+
c.optional(delta, 'unit', v => c.label(v, join(dp, 'unit'), { max: 20 }))
|
|
165
193
|
tone(c, delta, dp)
|
|
166
194
|
})
|
|
167
195
|
})
|
|
@@ -186,7 +214,7 @@ function goalLine(c, goal, path, allowPoints) {
|
|
|
186
214
|
if (!c.object(goal, path, ['y'], ['label'])) return
|
|
187
215
|
c.number(goal.y, join(path, 'y'))
|
|
188
216
|
}
|
|
189
|
-
c.optional(goal, 'label', v => c.
|
|
217
|
+
c.optional(goal, 'label', v => c.label(v, join(path, 'label')))
|
|
190
218
|
}
|
|
191
219
|
|
|
192
220
|
function lineData(c, data, path) {
|
|
@@ -195,11 +223,11 @@ function lineData(c, data, path) {
|
|
|
195
223
|
data.series.forEach((series, i) => {
|
|
196
224
|
const p = join(join(path, 'series'), i)
|
|
197
225
|
if (!c.object(series, p, ['name', 'points'], ['tone'])) return
|
|
198
|
-
c.
|
|
226
|
+
c.label(series.name, join(p, 'name'), { empty: true })
|
|
199
227
|
points(c, series.points, join(p, 'points'))
|
|
200
228
|
tone(c, series, p)
|
|
201
229
|
})
|
|
202
|
-
c.optional(data, 'unit', v => c.
|
|
230
|
+
c.optional(data, 'unit', v => c.label(v, join(path, 'unit'), { max: 20 }))
|
|
203
231
|
c.optional(data, 'area', v => c.boolean(v, join(path, 'area')))
|
|
204
232
|
c.optional(data, 'goal', v => goalLine(c, v, join(path, 'goal'), true))
|
|
205
233
|
c.optional(data, 'markers', markers => {
|
|
@@ -208,7 +236,7 @@ function lineData(c, data, path) {
|
|
|
208
236
|
const p = join(join(path, 'markers'), i)
|
|
209
237
|
if (!c.object(marker, p, ['x', 'label'])) return
|
|
210
238
|
c.textOrNumber(marker.x, join(p, 'x'))
|
|
211
|
-
c.
|
|
239
|
+
c.label(marker.label, join(p, 'label'))
|
|
212
240
|
})
|
|
213
241
|
})
|
|
214
242
|
}
|
|
@@ -235,7 +263,7 @@ function barData(c, data, path) {
|
|
|
235
263
|
})
|
|
236
264
|
})
|
|
237
265
|
c.optional(data, 'stacked', v => c.boolean(v, join(path, 'stacked')))
|
|
238
|
-
c.optional(data, 'unit', v => c.
|
|
266
|
+
c.optional(data, 'unit', v => c.label(v, join(path, 'unit'), { max: 20 }))
|
|
239
267
|
c.optional(data, 'goal', v => goalLine(c, v, join(path, 'goal'), false))
|
|
240
268
|
}
|
|
241
269
|
|
|
@@ -245,17 +273,17 @@ function donutData(c, data, path) {
|
|
|
245
273
|
data.segments.forEach((segment, i) => {
|
|
246
274
|
const p = join(join(path, 'segments'), i)
|
|
247
275
|
if (!c.object(segment, p, ['label', 'value'], ['tone'])) return
|
|
248
|
-
c.
|
|
276
|
+
c.label(segment.label, join(p, 'label'))
|
|
249
277
|
c.number(segment.value, join(p, 'value'), { min: 0 })
|
|
250
278
|
tone(c, segment, p)
|
|
251
279
|
})
|
|
252
280
|
c.optional(data, 'centre', centre => {
|
|
253
281
|
const p = join(path, 'centre')
|
|
254
282
|
if (!c.object(centre, p, ['text'], ['sub'])) return
|
|
255
|
-
c.
|
|
256
|
-
c.optional(centre, 'sub', v => c.
|
|
283
|
+
c.label(centre.text, join(p, 'text'), { max: 40 })
|
|
284
|
+
c.optional(centre, 'sub', v => c.label(v, join(p, 'sub'), { max: 40 }))
|
|
257
285
|
})
|
|
258
|
-
c.optional(data, 'unit', v => c.
|
|
286
|
+
c.optional(data, 'unit', v => c.label(v, join(path, 'unit'), { max: 20 }))
|
|
259
287
|
}
|
|
260
288
|
|
|
261
289
|
function listData(c, data, path) {
|
|
@@ -265,25 +293,25 @@ function listData(c, data, path) {
|
|
|
265
293
|
const p = join(join(path, 'rows'), i)
|
|
266
294
|
if (!c.object(row, p, ['title'], ['sub', 'chip', 'checked', 'date', 'actions'])) return
|
|
267
295
|
c.optional(row, 'actions', v => actions(c, v, join(p, 'actions')))
|
|
268
|
-
c.
|
|
269
|
-
c.optional(row, 'sub', v => c.
|
|
296
|
+
c.label(row.title, join(p, 'title'))
|
|
297
|
+
c.optional(row, 'sub', v => c.label(v, join(p, 'sub')))
|
|
270
298
|
c.optional(row, 'checked', v => c.boolean(v, join(p, 'checked')))
|
|
271
299
|
c.optional(row, 'date', v => c.date(v, join(p, 'date')))
|
|
272
300
|
c.optional(row, 'chip', chip => {
|
|
273
301
|
const cp = join(p, 'chip')
|
|
274
302
|
if (!c.object(chip, cp, ['text'], ['tone'])) return
|
|
275
|
-
c.
|
|
303
|
+
c.label(chip.text, join(cp, 'text'), { max: 40 })
|
|
276
304
|
tone(c, chip, cp)
|
|
277
305
|
})
|
|
278
306
|
})
|
|
279
|
-
c.optional(data, 'empty', v => c.
|
|
307
|
+
c.optional(data, 'empty', v => c.label(v, join(path, 'empty')))
|
|
280
308
|
c.optional(data, 'progress', progress => {
|
|
281
309
|
const p = join(path, 'progress')
|
|
282
310
|
if (!c.object(progress, p, ['done', 'total'], ['label'])) return
|
|
283
311
|
const done = c.number(progress.done, join(p, 'done'), { min: 0 })
|
|
284
312
|
const total = c.number(progress.total, join(p, 'total'), { min: 0 })
|
|
285
313
|
if (done && total && progress.done > progress.total) c.fail(join(p, 'done'), 'must not be more than total')
|
|
286
|
-
c.optional(progress, 'label', v => c.
|
|
314
|
+
c.optional(progress, 'label', v => c.label(v, join(p, 'label'), { max: 40 }))
|
|
287
315
|
})
|
|
288
316
|
}
|
|
289
317
|
|
|
@@ -298,7 +326,7 @@ function timelineData(c, data, path) {
|
|
|
298
326
|
const p = join(join(path, 'points'), i)
|
|
299
327
|
if (!c.object(point, p, ['date', 'label'], ['kind', 'tone'])) return
|
|
300
328
|
c.date(point.date, join(p, 'date'))
|
|
301
|
-
c.
|
|
329
|
+
c.label(point.label, join(p, 'label'))
|
|
302
330
|
c.optional(point, 'kind', v => c.text(v, join(p, 'kind'), { max: 20 }))
|
|
303
331
|
tone(c, point, p)
|
|
304
332
|
})
|
|
@@ -311,7 +339,7 @@ function timelineData(c, data, path) {
|
|
|
311
339
|
const fromValid = c.date(span.from, join(p, 'from'))
|
|
312
340
|
const toValid = c.date(span.to, join(p, 'to'))
|
|
313
341
|
if (fromValid && toValid && Date.parse(span.to) < Date.parse(span.from)) c.fail(join(p, 'to'), 'must not be before from')
|
|
314
|
-
c.
|
|
342
|
+
c.label(span.label, join(p, 'label'))
|
|
315
343
|
tone(c, span, p)
|
|
316
344
|
})
|
|
317
345
|
})
|
|
@@ -324,10 +352,10 @@ function statusData(c, data, path) {
|
|
|
324
352
|
const p = join(join(path, 'rows'), i)
|
|
325
353
|
if (!c.object(row, p, ['label', 'value', 'tone'], ['sub', 'spark', 'actions'])) return
|
|
326
354
|
c.optional(row, 'actions', v => actions(c, v, join(p, 'actions')))
|
|
327
|
-
c.
|
|
328
|
-
c.
|
|
355
|
+
c.label(row.label, join(p, 'label'))
|
|
356
|
+
c.labelOrNumber(row.value, join(p, 'value'))
|
|
329
357
|
c.oneOf(row.tone, join(p, 'tone'), TONES)
|
|
330
|
-
c.optional(row, 'sub', v => c.
|
|
358
|
+
c.optional(row, 'sub', v => c.label(v, join(p, 'sub')))
|
|
331
359
|
c.optional(row, 'spark', spark => {
|
|
332
360
|
if (!c.array(spark, join(p, 'spark'), { min: 2, max: MAX_POINTS })) return
|
|
333
361
|
spark.forEach((v, j) => c.number(v, join(join(p, 'spark'), j)))
|
|
@@ -354,7 +382,7 @@ export function checkCard(card) {
|
|
|
354
382
|
const c = new Check()
|
|
355
383
|
if (!c.object(card, '', ['type', 'title', 'updatedAt', 'data'], ['staleAfter', 'link', 'stat', 'actions'])) return c.problems
|
|
356
384
|
if (!c.oneOf(card.type, 'type', CARD_TYPES)) return c.problems
|
|
357
|
-
c.
|
|
385
|
+
c.label(card.title, 'title', { max: 120 })
|
|
358
386
|
c.dateTime(card.updatedAt, 'updatedAt')
|
|
359
387
|
c.optional(card, 'staleAfter', v => c.number(v, 'staleAfter', { min: 1 }))
|
|
360
388
|
c.optional(card, 'link', v => isSafeLink(v) || c.fail('link', 'must be an http(s) URL or a path starting with /'))
|
|
@@ -380,8 +408,9 @@ export function findAction(card, actionId, row) {
|
|
|
380
408
|
/** Problems with a board.json's parsed content. */
|
|
381
409
|
export function checkBoard(board) {
|
|
382
410
|
const c = new Check()
|
|
383
|
-
if (!c.object(board, '', ['title'], ['viewers', 'order', 'layout'])) return c.problems
|
|
384
|
-
c.
|
|
411
|
+
if (!c.object(board, '', ['title'], ['viewers', 'order', 'layout', 'assistant'])) return c.problems
|
|
412
|
+
c.label(board.title, 'title', { max: 80 })
|
|
413
|
+
c.optional(board, 'assistant', v => c.text(v, 'assistant', { max: 40 }))
|
|
385
414
|
c.optional(board, 'viewers', viewers => {
|
|
386
415
|
if (c.array(viewers, 'viewers', { max: 100 })) viewers.forEach((v, i) => c.text(v, join('viewers', i), { max: 100 }))
|
|
387
416
|
})
|