@rine-kit/presentation 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/src/builders/pubg.d.ts +35 -0
- package/dist/src/builders/pubg.js +725 -0
- package/dist/src/contracts/owner.d.ts +20 -0
- package/dist/src/contracts/owner.js +1 -0
- package/dist/src/contracts/pubg.d.ts +200 -0
- package/dist/src/contracts/pubg.js +1 -0
- package/dist/src/contracts/session-review.d.ts +72 -0
- package/dist/src/contracts/session-review.js +1 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.js +19 -0
- package/dist/src/pubg-registry.d.ts +21 -0
- package/dist/src/pubg-registry.js +123 -0
- package/dist/src/renderers/daily-review.d.ts +22 -0
- package/dist/src/renderers/daily-review.js +149 -0
- package/dist/src/renderers/owner.d.ts +6 -0
- package/dist/src/renderers/owner.js +35 -0
- package/dist/src/renderers/pubg.d.ts +22 -0
- package/dist/src/renderers/pubg.js +603 -0
- package/dist/src/renderers/session-review.d.ts +15 -0
- package/dist/src/renderers/session-review.js +187 -0
- package/dist/src/reply-check.d.ts +3 -0
- package/dist/src/reply-check.js +44 -0
- package/dist/src/reply-guides.d.ts +10 -0
- package/dist/src/reply-guides.js +64 -0
- package/dist/src/time/format.d.ts +16 -0
- package/dist/src/time/format.js +63 -0
- package/dist/src/validation/session-review.d.ts +3 -0
- package/dist/src/validation/session-review.js +136 -0
- package/dist/src/validation/validate.d.ts +18 -0
- package/dist/src/validation/validate.js +736 -0
- package/dist/src/worldline/adapter.d.ts +3 -0
- package/dist/src/worldline/adapter.js +47 -0
- package/dist/src/worldline/contracts.d.ts +44 -0
- package/dist/src/worldline/contracts.js +40 -0
- package/dist/src/worldline/policy.d.ts +2 -0
- package/dist/src/worldline/policy.js +31 -0
- package/dist/src/worldline/renderer.d.ts +3 -0
- package/dist/src/worldline/renderer.js +5 -0
- package/dist/src/worldline/vocabulary.d.ts +2 -0
- package/dist/src/worldline/vocabulary.js +1 -0
- package/package.json +33 -3
- package/README.md +0 -3
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
import { WORLDLINE_SIGNIFICANCES, WORLDLINE_THEMES } from '../worldline/contracts.js';
|
|
2
|
+
function result(value, errors) {
|
|
3
|
+
return errors.length ? { valid: false, errors } : { valid: true, value, errors: [] };
|
|
4
|
+
}
|
|
5
|
+
function stringValue(value, path, errors, required = true) {
|
|
6
|
+
if (typeof value === 'string' && value.trim())
|
|
7
|
+
return value;
|
|
8
|
+
if (required)
|
|
9
|
+
errors.push(`${path} must be a non-empty string`);
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
function finiteOrNull(value, path, errors) {
|
|
13
|
+
if (value === null)
|
|
14
|
+
return null;
|
|
15
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
16
|
+
return value;
|
|
17
|
+
errors.push(`${path} must be a finite number or null`);
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
function scalar(value, path, errors) {
|
|
21
|
+
if (value === null ||
|
|
22
|
+
typeof value === 'string' ||
|
|
23
|
+
(typeof value === 'number' && Number.isFinite(value)))
|
|
24
|
+
return value;
|
|
25
|
+
errors.push(`${path} must be a string, finite number, or null`);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
function iso(value, path, errors, required = true) {
|
|
29
|
+
const text = stringValue(value, path, errors, required);
|
|
30
|
+
if (text && !Number.isFinite(Date.parse(text)))
|
|
31
|
+
errors.push(`${path} must be an ISO timestamp`);
|
|
32
|
+
return text;
|
|
33
|
+
}
|
|
34
|
+
function refs(value, path, errors, known) {
|
|
35
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== 'string' || !item.trim())) {
|
|
36
|
+
errors.push(`${path} must be an array of non-empty evidence references`);
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const normalized = value.map((item) => String(item));
|
|
40
|
+
if (known)
|
|
41
|
+
for (const ref of normalized)
|
|
42
|
+
if (!known.has(ref))
|
|
43
|
+
errors.push(`${path} references unknown evidence ${ref}`);
|
|
44
|
+
return normalized;
|
|
45
|
+
}
|
|
46
|
+
function textItems(value, path, errors, known) {
|
|
47
|
+
if (!Array.isArray(value)) {
|
|
48
|
+
errors.push(`${path} must be an array`);
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
return value.flatMap((item, index) => {
|
|
52
|
+
if (!item || typeof item !== 'object') {
|
|
53
|
+
errors.push(`${path}[${index}] must be an object`);
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
const row = item;
|
|
57
|
+
const text = stringValue(row.text, `${path}[${index}].text`, errors);
|
|
58
|
+
const evidenceRefs = refs(row.evidenceRefs, `${path}[${index}].evidenceRefs`, errors, known);
|
|
59
|
+
return text ? [{ text, evidenceRefs }] : [];
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function sourceRange(value, path, errors) {
|
|
63
|
+
if (value === undefined)
|
|
64
|
+
return undefined;
|
|
65
|
+
if (!value || typeof value !== 'object') {
|
|
66
|
+
errors.push(`${path} must be an object`);
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const row = value;
|
|
70
|
+
const from = row.from === null ? null : (iso(row.from, `${path}.from`, errors, false) ?? null);
|
|
71
|
+
const to = row.to === null ? null : (iso(row.to, `${path}.to`, errors, false) ?? null);
|
|
72
|
+
const segments = [];
|
|
73
|
+
if (row.segments !== undefined) {
|
|
74
|
+
if (!Array.isArray(row.segments))
|
|
75
|
+
errors.push(`${path}.segments must be an array`);
|
|
76
|
+
else
|
|
77
|
+
row.segments.forEach((item, index) => {
|
|
78
|
+
if (!item || typeof item !== 'object') {
|
|
79
|
+
errors.push(`${path}.segments[${index}] must be an object`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const segment = item;
|
|
83
|
+
const label = stringValue(segment.label, `${path}.segments[${index}].label`, errors);
|
|
84
|
+
const segmentFrom = segment.from === null
|
|
85
|
+
? null
|
|
86
|
+
: (iso(segment.from, `${path}.segments[${index}].from`, errors, false) ?? null);
|
|
87
|
+
const segmentTo = segment.to === null
|
|
88
|
+
? null
|
|
89
|
+
: (iso(segment.to, `${path}.segments[${index}].to`, errors, false) ?? null);
|
|
90
|
+
if (label)
|
|
91
|
+
segments.push({ label, from: segmentFrom, to: segmentTo });
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return { from, to, ...(segments.length ? { segments } : {}) };
|
|
95
|
+
}
|
|
96
|
+
function presentationCoverage(value, path, errors) {
|
|
97
|
+
if (value === undefined)
|
|
98
|
+
return undefined;
|
|
99
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
100
|
+
errors.push(`${path} must be an object`);
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
const row = value;
|
|
104
|
+
const status = stringValue(row.status, `${path}.status`, errors);
|
|
105
|
+
const complete = typeof row.complete === 'boolean'
|
|
106
|
+
? row.complete
|
|
107
|
+
: (errors.push(`${path}.complete must be boolean`), false);
|
|
108
|
+
const freshness = ['fresh', 'stale', 'unknown'].includes(String(row.freshness))
|
|
109
|
+
? row.freshness
|
|
110
|
+
: (errors.push(`${path}.freshness is invalid`), 'unknown');
|
|
111
|
+
const checkedAt = row.checkedAt === null
|
|
112
|
+
? null
|
|
113
|
+
: (iso(row.checkedAt, `${path}.checkedAt`, errors, false) ?? null);
|
|
114
|
+
const coverageStart = row.coverageStart === null
|
|
115
|
+
? null
|
|
116
|
+
: (iso(row.coverageStart, `${path}.coverageStart`, errors, false) ?? null);
|
|
117
|
+
const coverageEnd = row.coverageEnd === null
|
|
118
|
+
? null
|
|
119
|
+
: (iso(row.coverageEnd, `${path}.coverageEnd`, errors, false) ?? null);
|
|
120
|
+
const sourceUnavailable = typeof row.sourceUnavailable === 'boolean'
|
|
121
|
+
? row.sourceUnavailable
|
|
122
|
+
: (errors.push(`${path}.sourceUnavailable must be boolean`), false);
|
|
123
|
+
return status
|
|
124
|
+
? { status, complete, freshness, checkedAt, coverageStart, coverageEnd, sourceUnavailable }
|
|
125
|
+
: undefined;
|
|
126
|
+
}
|
|
127
|
+
function base(value, expectedType, errors, path = 'presentation') {
|
|
128
|
+
if (value.type !== expectedType)
|
|
129
|
+
errors.push(`${path}.type must be ${expectedType}`);
|
|
130
|
+
const statusValue = value.status;
|
|
131
|
+
if (!['ok', 'partial', 'no_matches', 'error'].includes(String(statusValue)))
|
|
132
|
+
errors.push(`${path}.status is invalid`);
|
|
133
|
+
const dataUpdatedAt = iso(value.dataUpdatedAt, `${path}.dataUpdatedAt`, errors) ?? '';
|
|
134
|
+
const range = sourceRange(value.sourceRange, `${path}.sourceRange`, errors);
|
|
135
|
+
const coverage = presentationCoverage(value.coverage, `${path}.coverage`, errors);
|
|
136
|
+
return {
|
|
137
|
+
status: statusValue,
|
|
138
|
+
dataUpdatedAt,
|
|
139
|
+
...(range ? { sourceRange: range } : {}),
|
|
140
|
+
...(coverage ? { coverage } : {}),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function scalarRecord(value, path, errors) {
|
|
144
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
145
|
+
errors.push(`${path} must be an object`);
|
|
146
|
+
return {};
|
|
147
|
+
}
|
|
148
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, scalar(item, `${path}.${key}`, errors)]));
|
|
149
|
+
}
|
|
150
|
+
function metricRows(value, path, errors, known) {
|
|
151
|
+
if (!Array.isArray(value)) {
|
|
152
|
+
errors.push(`${path} must be an array`);
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
return value.flatMap((item, index) => {
|
|
156
|
+
if (!item || typeof item !== 'object') {
|
|
157
|
+
errors.push(`${path}[${index}] must be an object`);
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
const row = item;
|
|
161
|
+
const label = stringValue(row.label, `${path}[${index}].label`, errors);
|
|
162
|
+
const values = scalarRecord(row.values, `${path}[${index}].values`, errors);
|
|
163
|
+
const position = row.position === undefined
|
|
164
|
+
? undefined
|
|
165
|
+
: row.position === null
|
|
166
|
+
? null
|
|
167
|
+
: finiteOrNull(row.position, `${path}[${index}].position`, errors);
|
|
168
|
+
const evidenceRefs = refs(row.evidenceRefs, `${path}[${index}].evidenceRefs`, errors, known);
|
|
169
|
+
if (!label)
|
|
170
|
+
return [];
|
|
171
|
+
return [
|
|
172
|
+
{
|
|
173
|
+
label,
|
|
174
|
+
values,
|
|
175
|
+
...(position === undefined ? {} : { position: position ?? null }),
|
|
176
|
+
evidenceRefs,
|
|
177
|
+
},
|
|
178
|
+
];
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
export function validatePubgStatusPresentation(value, knownEvidence) {
|
|
182
|
+
const errors = [];
|
|
183
|
+
if (!value || typeof value !== 'object')
|
|
184
|
+
return result(value, ['presentation must be an object']);
|
|
185
|
+
const row = value;
|
|
186
|
+
const common = base(row, 'pubg_status', errors);
|
|
187
|
+
const headline = stringValue(row.headline, 'headline', errors);
|
|
188
|
+
const message = stringValue(row.message, 'message', errors);
|
|
189
|
+
const errorCode = stringValue(row.errorCode, 'errorCode', errors, false);
|
|
190
|
+
const evidenceRefs = refs(row.evidenceRefs, 'evidenceRefs', errors, knownEvidence);
|
|
191
|
+
if (!headline || !message)
|
|
192
|
+
return result(value, errors);
|
|
193
|
+
return result({
|
|
194
|
+
...common,
|
|
195
|
+
type: 'pubg_status',
|
|
196
|
+
headline,
|
|
197
|
+
message,
|
|
198
|
+
...(errorCode ? { errorCode } : {}),
|
|
199
|
+
evidenceRefs,
|
|
200
|
+
}, errors);
|
|
201
|
+
}
|
|
202
|
+
export function validatePubgStatsPresentation(value, knownEvidence) {
|
|
203
|
+
const errors = [];
|
|
204
|
+
if (!value || typeof value !== 'object')
|
|
205
|
+
return result(value, ['presentation must be an object']);
|
|
206
|
+
const row = value;
|
|
207
|
+
const common = base(row, 'pubg_stats', errors);
|
|
208
|
+
const headline = stringValue(row.headline, 'headline', errors);
|
|
209
|
+
const operation = stringValue(row.operation, 'operation', errors);
|
|
210
|
+
const groupBy = stringValue(row.groupBy, 'groupBy', errors);
|
|
211
|
+
const summary = stringValue(row.summary, 'summary', errors);
|
|
212
|
+
const rows = metricRows(row.rows, 'rows', errors, knownEvidence);
|
|
213
|
+
const evidenceRefs = refs(row.evidenceRefs, 'evidenceRefs', errors, knownEvidence);
|
|
214
|
+
if (!headline || !operation || !groupBy || !summary)
|
|
215
|
+
return result(value, errors);
|
|
216
|
+
return result({ ...common, type: 'pubg_stats', headline, operation, groupBy, summary, rows, evidenceRefs }, errors);
|
|
217
|
+
}
|
|
218
|
+
export function validatePubgMatchListPresentation(value, knownEvidence) {
|
|
219
|
+
const errors = [];
|
|
220
|
+
if (!value || typeof value !== 'object')
|
|
221
|
+
return result(value, ['presentation must be an object']);
|
|
222
|
+
const row = value;
|
|
223
|
+
const common = base(row, 'pubg_match_list', errors);
|
|
224
|
+
const headline = stringValue(row.headline, 'headline', errors);
|
|
225
|
+
const summary = stringValue(row.summary, 'summary', errors);
|
|
226
|
+
const evidenceRefs = refs(row.evidenceRefs, 'evidenceRefs', errors, knownEvidence);
|
|
227
|
+
const matches = [];
|
|
228
|
+
if (!Array.isArray(row.matches))
|
|
229
|
+
errors.push('matches must be an array');
|
|
230
|
+
else
|
|
231
|
+
row.matches.forEach((item, index) => {
|
|
232
|
+
if (!item || typeof item !== 'object') {
|
|
233
|
+
errors.push(`matches[${index}] must be an object`);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const match = item;
|
|
237
|
+
const matchId = stringValue(match.matchId, `matches[${index}].matchId`, errors);
|
|
238
|
+
const startedAt = match.startedAt === null
|
|
239
|
+
? null
|
|
240
|
+
: (iso(match.startedAt, `matches[${index}].startedAt`, errors, false) ?? null);
|
|
241
|
+
const mapName = stringValue(match.mapName, `matches[${index}].mapName`, errors);
|
|
242
|
+
const gameMode = stringValue(match.gameMode, `matches[${index}].gameMode`, errors);
|
|
243
|
+
const placement = finiteOrNull(match.placement, `matches[${index}].placement`, errors);
|
|
244
|
+
const matchSummary = stringValue(match.summary, `matches[${index}].summary`, errors);
|
|
245
|
+
const matchRefs = refs(match.evidenceRefs, `matches[${index}].evidenceRefs`, errors, knownEvidence);
|
|
246
|
+
if (matchId && mapName && gameMode && matchSummary)
|
|
247
|
+
matches.push({
|
|
248
|
+
matchId,
|
|
249
|
+
startedAt,
|
|
250
|
+
mapName,
|
|
251
|
+
gameMode,
|
|
252
|
+
placement: placement ?? null,
|
|
253
|
+
summary: matchSummary,
|
|
254
|
+
evidenceRefs: matchRefs,
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
if (!headline || !summary)
|
|
258
|
+
return result(value, errors);
|
|
259
|
+
return result({ ...common, type: 'pubg_match_list', headline, summary, matches, evidenceRefs }, errors);
|
|
260
|
+
}
|
|
261
|
+
export function validatePubgComparisonPresentation(value, knownEvidence) {
|
|
262
|
+
const errors = [];
|
|
263
|
+
if (!value || typeof value !== 'object')
|
|
264
|
+
return result(value, ['presentation must be an object']);
|
|
265
|
+
const row = value;
|
|
266
|
+
const common = base(row, 'pubg_comparison', errors);
|
|
267
|
+
const headline = stringValue(row.headline, 'headline', errors);
|
|
268
|
+
const summary = stringValue(row.summary, 'summary', errors);
|
|
269
|
+
const rows = metricRows(row.rows, 'rows', errors, knownEvidence);
|
|
270
|
+
const evidenceRefs = refs(row.evidenceRefs, 'evidenceRefs', errors, knownEvidence);
|
|
271
|
+
const segments = [];
|
|
272
|
+
if (!Array.isArray(row.segments))
|
|
273
|
+
errors.push('segments must be an array');
|
|
274
|
+
else
|
|
275
|
+
row.segments.forEach((item, index) => {
|
|
276
|
+
if (!item || typeof item !== 'object') {
|
|
277
|
+
errors.push(`segments[${index}] must be an object`);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const segment = item;
|
|
281
|
+
const label = stringValue(segment.label, `segments[${index}].label`, errors);
|
|
282
|
+
const range = sourceRange(segment.sourceRange, `segments[${index}].sourceRange`, errors);
|
|
283
|
+
const segmentRows = metricRows(segment.rows, `segments[${index}].rows`, errors, knownEvidence);
|
|
284
|
+
if (label)
|
|
285
|
+
segments.push({ label, ...(range ? { sourceRange: range } : {}), rows: segmentRows });
|
|
286
|
+
});
|
|
287
|
+
if (!headline || !summary)
|
|
288
|
+
return result(value, errors);
|
|
289
|
+
return result({ ...common, type: 'pubg_comparison', headline, summary, rows, segments, evidenceRefs }, errors);
|
|
290
|
+
}
|
|
291
|
+
export function validatePubgMatchDetailPresentation(value, knownEvidence) {
|
|
292
|
+
const errors = [];
|
|
293
|
+
if (!value || typeof value !== 'object')
|
|
294
|
+
return result(value, ['presentation must be an object']);
|
|
295
|
+
const row = value;
|
|
296
|
+
const common = base(row, 'pubg_match_detail', errors);
|
|
297
|
+
const headline = stringValue(row.headline, 'headline', errors);
|
|
298
|
+
const matchId = stringValue(row.matchId, 'matchId', errors);
|
|
299
|
+
const startedAt = row.startedAt === null ? null : (iso(row.startedAt, 'startedAt', errors, false) ?? null);
|
|
300
|
+
const mapName = stringValue(row.mapName, 'mapName', errors);
|
|
301
|
+
const gameMode = stringValue(row.gameMode, 'gameMode', errors);
|
|
302
|
+
const duration = row.duration === null ? null : (finiteOrNull(row.duration, 'duration', errors) ?? null);
|
|
303
|
+
const evidenceRefs = refs(row.evidenceRefs, 'evidenceRefs', errors, knownEvidence);
|
|
304
|
+
const players = [];
|
|
305
|
+
if (!Array.isArray(row.players))
|
|
306
|
+
errors.push('players must be an array');
|
|
307
|
+
else
|
|
308
|
+
row.players.forEach((item, index) => {
|
|
309
|
+
if (!item || typeof item !== 'object') {
|
|
310
|
+
errors.push(`players[${index}] must be an object`);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const player = item;
|
|
314
|
+
const label = stringValue(player.label, `players[${index}].label`, errors);
|
|
315
|
+
const playerValues = scalarRecord(player.values, `players[${index}].values`, errors);
|
|
316
|
+
const playerRefs = refs(player.evidenceRefs, `players[${index}].evidenceRefs`, errors, knownEvidence);
|
|
317
|
+
if (label)
|
|
318
|
+
players.push({ label, values: playerValues, evidenceRefs: playerRefs });
|
|
319
|
+
});
|
|
320
|
+
if (!headline || !matchId || !mapName || !gameMode)
|
|
321
|
+
return result(value, errors);
|
|
322
|
+
return result({
|
|
323
|
+
...common,
|
|
324
|
+
type: 'pubg_match_detail',
|
|
325
|
+
headline,
|
|
326
|
+
matchId,
|
|
327
|
+
startedAt,
|
|
328
|
+
mapName,
|
|
329
|
+
gameMode,
|
|
330
|
+
duration,
|
|
331
|
+
players,
|
|
332
|
+
evidenceRefs,
|
|
333
|
+
}, errors);
|
|
334
|
+
}
|
|
335
|
+
export function validatePubgMatchReviewPresentation(value, knownEvidence) {
|
|
336
|
+
const errors = [];
|
|
337
|
+
if (!value || typeof value !== 'object')
|
|
338
|
+
return result(value, ['presentation must be an object']);
|
|
339
|
+
const row = value;
|
|
340
|
+
const common = base(row, 'pubg_match_review', errors);
|
|
341
|
+
const headline = stringValue(row.headline, 'headline', errors);
|
|
342
|
+
const overviewValue = row.overview;
|
|
343
|
+
const overview = {};
|
|
344
|
+
if (!overviewValue || typeof overviewValue !== 'object')
|
|
345
|
+
errors.push('overview must be an object');
|
|
346
|
+
else {
|
|
347
|
+
const source = overviewValue;
|
|
348
|
+
for (const key of ['placement', 'kills', 'assists', 'damage', 'dbnos', 'revives'])
|
|
349
|
+
overview[key] = finiteOrNull(source[key], `overview.${key}`, errors);
|
|
350
|
+
}
|
|
351
|
+
const keyMoments = textItems(row.keyMoments, 'keyMoments', errors, knownEvidence);
|
|
352
|
+
const highlights = textItems(row.highlights, 'highlights', errors, knownEvidence);
|
|
353
|
+
const improvements = textItems(row.improvements, 'improvements', errors, knownEvidence);
|
|
354
|
+
const analysis = stringValue(row.analysis, 'analysis', errors);
|
|
355
|
+
const evidenceRefs = refs(row.evidenceRefs, 'evidenceRefs', errors, knownEvidence);
|
|
356
|
+
if (!headline || !analysis)
|
|
357
|
+
return result(value, errors);
|
|
358
|
+
return result({
|
|
359
|
+
...common,
|
|
360
|
+
type: 'pubg_match_review',
|
|
361
|
+
headline,
|
|
362
|
+
overview: {
|
|
363
|
+
placement: overview.placement ?? null,
|
|
364
|
+
kills: overview.kills ?? null,
|
|
365
|
+
assists: overview.assists ?? null,
|
|
366
|
+
damage: overview.damage ?? null,
|
|
367
|
+
dbnos: overview.dbnos ?? null,
|
|
368
|
+
revives: overview.revives ?? null,
|
|
369
|
+
},
|
|
370
|
+
keyMoments,
|
|
371
|
+
highlights,
|
|
372
|
+
improvements,
|
|
373
|
+
analysis,
|
|
374
|
+
evidenceRefs,
|
|
375
|
+
}, errors);
|
|
376
|
+
}
|
|
377
|
+
export function validatePubgPeriodReviewPresentation(value, knownEvidence) {
|
|
378
|
+
const errors = [];
|
|
379
|
+
if (!value || typeof value !== 'object')
|
|
380
|
+
return result(value, ['presentation must be an object']);
|
|
381
|
+
const row = value;
|
|
382
|
+
const common = base(row, 'pubg_period_review', errors);
|
|
383
|
+
const periodValue = row.period;
|
|
384
|
+
let label;
|
|
385
|
+
let displayDate;
|
|
386
|
+
if (!periodValue || typeof periodValue !== 'object')
|
|
387
|
+
errors.push('period must be an object');
|
|
388
|
+
else {
|
|
389
|
+
const period = periodValue;
|
|
390
|
+
label = stringValue(period.label, 'period.label', errors);
|
|
391
|
+
displayDate = stringValue(period.displayDate, 'period.displayDate', errors, false);
|
|
392
|
+
}
|
|
393
|
+
const summary = stringValue(row.summary, 'summary', errors);
|
|
394
|
+
const analysis = stringValue(row.analysis, 'analysis', errors);
|
|
395
|
+
const highlights = textItems(row.highlights, 'highlights', errors, knownEvidence);
|
|
396
|
+
const patterns = textItems(row.patterns, 'patterns', errors, knownEvidence);
|
|
397
|
+
const evidenceRefs = refs(row.evidenceRefs, 'evidenceRefs', errors, knownEvidence);
|
|
398
|
+
const orderedMatches = [];
|
|
399
|
+
if (!Array.isArray(row.orderedMatches))
|
|
400
|
+
errors.push('orderedMatches must be an array');
|
|
401
|
+
else
|
|
402
|
+
row.orderedMatches.forEach((item, index) => {
|
|
403
|
+
if (!item || typeof item !== 'object') {
|
|
404
|
+
errors.push(`orderedMatches[${index}] must be an object`);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const match = item;
|
|
408
|
+
const matchId = stringValue(match.matchId, `orderedMatches[${index}].matchId`, errors);
|
|
409
|
+
const matchLabel = stringValue(match.label, `orderedMatches[${index}].label`, errors);
|
|
410
|
+
const startedAt = match.startedAt === null
|
|
411
|
+
? null
|
|
412
|
+
: (iso(match.startedAt, `orderedMatches[${index}].startedAt`, errors, false) ?? null);
|
|
413
|
+
const placement = finiteOrNull(match.placement, `orderedMatches[${index}].placement`, errors);
|
|
414
|
+
if (matchId && matchLabel)
|
|
415
|
+
orderedMatches.push({
|
|
416
|
+
matchId,
|
|
417
|
+
label: matchLabel,
|
|
418
|
+
startedAt,
|
|
419
|
+
placement: placement ?? null,
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
if (!label || !summary || !analysis)
|
|
423
|
+
return result(value, errors);
|
|
424
|
+
return result({
|
|
425
|
+
...common,
|
|
426
|
+
type: 'pubg_period_review',
|
|
427
|
+
period: { label, ...(displayDate ? { displayDate } : {}) },
|
|
428
|
+
summary,
|
|
429
|
+
orderedMatches,
|
|
430
|
+
highlights,
|
|
431
|
+
patterns,
|
|
432
|
+
analysis,
|
|
433
|
+
evidenceRefs,
|
|
434
|
+
}, errors);
|
|
435
|
+
}
|
|
436
|
+
function teamDamageSlices(value, path, errors) {
|
|
437
|
+
if (!Array.isArray(value)) {
|
|
438
|
+
errors.push(`${path} must be an array`);
|
|
439
|
+
return [];
|
|
440
|
+
}
|
|
441
|
+
return value.flatMap((item, index) => {
|
|
442
|
+
const slice = (item ?? {});
|
|
443
|
+
const label = stringValue(slice.label, `${path}[${index}].label`, errors);
|
|
444
|
+
const hitCount = finiteOrNull(slice.hitCount, `${path}[${index}].hitCount`, errors);
|
|
445
|
+
const damage = finiteOrNull(slice.damage, `${path}[${index}].damage`, errors);
|
|
446
|
+
return label && typeof hitCount === 'number' && typeof damage === 'number'
|
|
447
|
+
? [{ label, hitCount, damage }]
|
|
448
|
+
: [];
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
function teamDamageLedger(value, directionCount, errors) {
|
|
452
|
+
if (value === undefined)
|
|
453
|
+
return undefined;
|
|
454
|
+
if (!value || typeof value !== 'object') {
|
|
455
|
+
errors.push('ledger must be an object');
|
|
456
|
+
return undefined;
|
|
457
|
+
}
|
|
458
|
+
const row = value;
|
|
459
|
+
const directionSources = Array.isArray(row.directionSources)
|
|
460
|
+
? row.directionSources.map((item, index) => teamDamageSlices(item, `ledger.directionSources[${index}]`, errors))
|
|
461
|
+
: (errors.push('ledger.directionSources must be an array'), []);
|
|
462
|
+
if (directionSources.length !== directionCount)
|
|
463
|
+
errors.push('ledger.directionSources must align with directions');
|
|
464
|
+
const highlights = Array.isArray(row.highlights)
|
|
465
|
+
? row.highlights.flatMap((item, index) => {
|
|
466
|
+
const highlight = (item ?? {});
|
|
467
|
+
const label = stringValue(highlight.label, `ledger.highlights[${index}].label`, errors);
|
|
468
|
+
const hitCount = finiteOrNull(highlight.hitCount, `ledger.highlights[${index}].hitCount`, errors);
|
|
469
|
+
const damage = finiteOrNull(highlight.damage, `ledger.highlights[${index}].damage`, errors);
|
|
470
|
+
const pairs = Array.isArray(highlight.pairs)
|
|
471
|
+
? highlight.pairs.flatMap((raw, pairIndex) => {
|
|
472
|
+
const pair = (raw ?? {});
|
|
473
|
+
const actor = stringValue(pair.actor, `ledger.highlights[${index}].pairs[${pairIndex}].actor`, errors);
|
|
474
|
+
const victim = stringValue(pair.victim, `ledger.highlights[${index}].pairs[${pairIndex}].victim`, errors);
|
|
475
|
+
const pairHits = finiteOrNull(pair.hitCount, `ledger.highlights[${index}].pairs[${pairIndex}].hitCount`, errors);
|
|
476
|
+
const pairDamage = finiteOrNull(pair.damage, `ledger.highlights[${index}].pairs[${pairIndex}].damage`, errors);
|
|
477
|
+
return actor &&
|
|
478
|
+
victim &&
|
|
479
|
+
typeof pairHits === 'number' &&
|
|
480
|
+
typeof pairDamage === 'number'
|
|
481
|
+
? [{ actor, victim, hitCount: pairHits, damage: pairDamage }]
|
|
482
|
+
: [];
|
|
483
|
+
})
|
|
484
|
+
: (errors.push(`ledger.highlights[${index}].pairs must be an array`), []);
|
|
485
|
+
return label && typeof hitCount === 'number' && typeof damage === 'number'
|
|
486
|
+
? [{ label, hitCount, damage, pairs }]
|
|
487
|
+
: [];
|
|
488
|
+
})
|
|
489
|
+
: (errors.push('ledger.highlights must be an array'), []);
|
|
490
|
+
const quiet = Array.isArray(row.quiet) && row.quiet.every((item) => typeof item === 'string')
|
|
491
|
+
? row.quiet
|
|
492
|
+
: (errors.push('ledger.quiet must be a string array'), []);
|
|
493
|
+
return {
|
|
494
|
+
sources: teamDamageSlices(row.sources, 'ledger.sources', errors),
|
|
495
|
+
directionSources,
|
|
496
|
+
highlights,
|
|
497
|
+
quiet,
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
export function validatePubgTeamDamagePresentation(value, knownEvidence) {
|
|
501
|
+
const errors = [];
|
|
502
|
+
if (!value || typeof value !== 'object')
|
|
503
|
+
return result(value, ['presentation must be an object']);
|
|
504
|
+
const row = value;
|
|
505
|
+
const common = base(row, 'pubg_team_damage', errors);
|
|
506
|
+
const headline = stringValue(row.headline, 'headline', errors);
|
|
507
|
+
const direction = stringValue(row.direction, 'direction', errors);
|
|
508
|
+
const source = row.source === null ? null : (stringValue(row.source, 'source', errors, false) ?? null);
|
|
509
|
+
const meleeKind = row.meleeKind === null
|
|
510
|
+
? null
|
|
511
|
+
: (stringValue(row.meleeKind, 'meleeKind', errors, false) ?? null);
|
|
512
|
+
const totalHitCount = finiteOrNull(row.totalHitCount, 'totalHitCount', errors);
|
|
513
|
+
const totalDamage = finiteOrNull(row.totalDamage, 'totalDamage', errors);
|
|
514
|
+
const summary = stringValue(row.summary, 'summary', errors);
|
|
515
|
+
const evidenceRefs = refs(row.evidenceRefs, 'evidenceRefs', errors, knownEvidence);
|
|
516
|
+
const directions = [];
|
|
517
|
+
if (!Array.isArray(row.directions))
|
|
518
|
+
errors.push('directions must be an array');
|
|
519
|
+
else
|
|
520
|
+
row.directions.forEach((item, index) => {
|
|
521
|
+
if (!item || typeof item !== 'object') {
|
|
522
|
+
errors.push(`directions[${index}] must be an object`);
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
const value = item;
|
|
526
|
+
const actor = stringValue(value.actor, `directions[${index}].actor`, errors);
|
|
527
|
+
const victim = stringValue(value.victim, `directions[${index}].victim`, errors);
|
|
528
|
+
const hitCount = finiteOrNull(value.hitCount, `directions[${index}].hitCount`, errors);
|
|
529
|
+
const damage = finiteOrNull(value.damage, `directions[${index}].damage`, errors);
|
|
530
|
+
const knownHitCount = value.knownHitCount === undefined
|
|
531
|
+
? undefined
|
|
532
|
+
: finiteOrNull(value.knownHitCount, `directions[${index}].knownHitCount`, errors);
|
|
533
|
+
const knownDamage = value.knownDamage === undefined
|
|
534
|
+
? undefined
|
|
535
|
+
: finiteOrNull(value.knownDamage, `directions[${index}].knownDamage`, errors);
|
|
536
|
+
const complete = value.complete === true || value.complete === false
|
|
537
|
+
? value.complete
|
|
538
|
+
: (errors.push(`directions[${index}].complete must be boolean`), false);
|
|
539
|
+
const refsValue = refs(value.evidenceRefs, `directions[${index}].evidenceRefs`, errors, knownEvidence);
|
|
540
|
+
if (actor && victim)
|
|
541
|
+
directions.push({
|
|
542
|
+
actor,
|
|
543
|
+
victim,
|
|
544
|
+
hitCount: hitCount ?? null,
|
|
545
|
+
damage: damage ?? null,
|
|
546
|
+
...(knownHitCount === undefined ? {} : { knownHitCount: knownHitCount ?? 0 }),
|
|
547
|
+
...(knownDamage === undefined ? {} : { knownDamage: knownDamage ?? 0 }),
|
|
548
|
+
complete,
|
|
549
|
+
evidenceRefs: refsValue,
|
|
550
|
+
});
|
|
551
|
+
});
|
|
552
|
+
let actorTotals;
|
|
553
|
+
if (row.actorTotals !== undefined) {
|
|
554
|
+
if (!Array.isArray(row.actorTotals))
|
|
555
|
+
errors.push('actorTotals must be an array');
|
|
556
|
+
else {
|
|
557
|
+
const parsedActorTotals = [];
|
|
558
|
+
row.actorTotals.forEach((item, index) => {
|
|
559
|
+
if (!item || typeof item !== 'object') {
|
|
560
|
+
errors.push(`actorTotals[${index}] must be an object`);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const total = item;
|
|
564
|
+
const actor = stringValue(total.actor, `actorTotals[${index}].actor`, errors);
|
|
565
|
+
const damage = finiteOrNull(total.damage, `actorTotals[${index}].damage`, errors);
|
|
566
|
+
const hitCount = finiteOrNull(total.hitCount, `actorTotals[${index}].hitCount`, errors);
|
|
567
|
+
const knownDamage = finiteOrNull(total.knownDamage, `actorTotals[${index}].knownDamage`, errors);
|
|
568
|
+
const knownHitCount = finiteOrNull(total.knownHitCount, `actorTotals[${index}].knownHitCount`, errors);
|
|
569
|
+
const complete = typeof total.complete === 'boolean'
|
|
570
|
+
? total.complete
|
|
571
|
+
: (errors.push(`actorTotals[${index}].complete must be boolean`), false);
|
|
572
|
+
const position = finiteOrNull(total.position, `actorTotals[${index}].position`, errors);
|
|
573
|
+
const evidenceRefs = refs(total.evidenceRefs, `actorTotals[${index}].evidenceRefs`, errors, knownEvidence);
|
|
574
|
+
if (actor)
|
|
575
|
+
parsedActorTotals.push({
|
|
576
|
+
actor,
|
|
577
|
+
damage: damage ?? null,
|
|
578
|
+
hitCount: hitCount ?? null,
|
|
579
|
+
knownDamage: knownDamage ?? 0,
|
|
580
|
+
knownHitCount: knownHitCount ?? 0,
|
|
581
|
+
complete,
|
|
582
|
+
position: position ?? index + 1,
|
|
583
|
+
evidenceRefs,
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
actorTotals = parsedActorTotals;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
const rankingBasis = row.rankingBasis === undefined
|
|
590
|
+
? undefined
|
|
591
|
+
: row.rankingBasis === 'damage' || row.rankingBasis === 'knownDamage'
|
|
592
|
+
? row.rankingBasis
|
|
593
|
+
: (errors.push('rankingBasis is invalid'), undefined);
|
|
594
|
+
const ledger = teamDamageLedger(row.ledger, directions.length, errors);
|
|
595
|
+
if (!headline || !direction || !summary)
|
|
596
|
+
return result(value, errors);
|
|
597
|
+
return result({
|
|
598
|
+
...common,
|
|
599
|
+
type: 'pubg_team_damage',
|
|
600
|
+
headline,
|
|
601
|
+
direction,
|
|
602
|
+
source,
|
|
603
|
+
meleeKind,
|
|
604
|
+
totalHitCount: totalHitCount ?? null,
|
|
605
|
+
totalDamage: totalDamage ?? null,
|
|
606
|
+
directions,
|
|
607
|
+
...(ledger ? { ledger } : {}),
|
|
608
|
+
...(actorTotals ? { actorTotals } : {}),
|
|
609
|
+
...(rankingBasis ? { rankingBasis } : {}),
|
|
610
|
+
summary,
|
|
611
|
+
evidenceRefs,
|
|
612
|
+
}, errors);
|
|
613
|
+
}
|
|
614
|
+
export function validatePubgPresentation(value, knownEvidence) {
|
|
615
|
+
if (!value || typeof value !== 'object')
|
|
616
|
+
return result(value, ['presentation must be an object']);
|
|
617
|
+
const type = value.type;
|
|
618
|
+
switch (type) {
|
|
619
|
+
case 'pubg_status':
|
|
620
|
+
return validatePubgStatusPresentation(value, knownEvidence);
|
|
621
|
+
case 'pubg_stats':
|
|
622
|
+
return validatePubgStatsPresentation(value, knownEvidence);
|
|
623
|
+
case 'pubg_match_list':
|
|
624
|
+
return validatePubgMatchListPresentation(value, knownEvidence);
|
|
625
|
+
case 'pubg_comparison':
|
|
626
|
+
return validatePubgComparisonPresentation(value, knownEvidence);
|
|
627
|
+
case 'pubg_match_detail':
|
|
628
|
+
return validatePubgMatchDetailPresentation(value, knownEvidence);
|
|
629
|
+
case 'pubg_match_review':
|
|
630
|
+
return validatePubgMatchReviewPresentation(value, knownEvidence);
|
|
631
|
+
case 'pubg_period_review':
|
|
632
|
+
return validatePubgPeriodReviewPresentation(value, knownEvidence);
|
|
633
|
+
case 'pubg_team_damage':
|
|
634
|
+
return validatePubgTeamDamagePresentation(value, knownEvidence);
|
|
635
|
+
default:
|
|
636
|
+
return result(value, [
|
|
637
|
+
`unsupported PUBG presentation type: ${String(type)}`,
|
|
638
|
+
]);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
export function validateOwnerNotificationPresentation(value, knownEvidence) {
|
|
642
|
+
const errors = [];
|
|
643
|
+
if (!value || typeof value !== 'object')
|
|
644
|
+
return result(value, ['presentation must be an object']);
|
|
645
|
+
const row = value;
|
|
646
|
+
if (row.type !== 'owner_notification')
|
|
647
|
+
errors.push('type must be owner_notification');
|
|
648
|
+
const eventType = stringValue(row.eventType, 'eventType', errors);
|
|
649
|
+
const severity = row.severity;
|
|
650
|
+
if (!['info', 'success', 'warning', 'error'].includes(String(severity)))
|
|
651
|
+
errors.push('severity is invalid');
|
|
652
|
+
const significance = row.significance;
|
|
653
|
+
if (!WORLDLINE_SIGNIFICANCES.includes(significance))
|
|
654
|
+
errors.push('significance is invalid');
|
|
655
|
+
const theme = row.theme;
|
|
656
|
+
if (!WORLDLINE_THEMES.includes(theme))
|
|
657
|
+
errors.push('theme is invalid');
|
|
658
|
+
const eventKey = stringValue(row.eventKey, 'eventKey', errors);
|
|
659
|
+
const source = stringValue(row.source, 'source', errors);
|
|
660
|
+
const headline = stringValue(row.headline, 'headline', errors);
|
|
661
|
+
const summary = stringValue(row.summary, 'summary', errors, false);
|
|
662
|
+
const dataUpdatedAt = iso(row.dataUpdatedAt, 'dataUpdatedAt', errors, false);
|
|
663
|
+
const occurredAt = iso(row.occurredAt, 'occurredAt', errors);
|
|
664
|
+
const facts = [];
|
|
665
|
+
if (!Array.isArray(row.facts))
|
|
666
|
+
errors.push('facts must be an array');
|
|
667
|
+
else
|
|
668
|
+
row.facts.forEach((item, index) => {
|
|
669
|
+
if (!item || typeof item !== 'object') {
|
|
670
|
+
errors.push(`facts[${index}] must be an object`);
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
const fact = item;
|
|
674
|
+
const label = stringValue(fact.label, `facts[${index}].label`, errors);
|
|
675
|
+
const raw = fact.value;
|
|
676
|
+
if (!(raw === null ||
|
|
677
|
+
typeof raw === 'string' ||
|
|
678
|
+
typeof raw === 'number' ||
|
|
679
|
+
typeof raw === 'boolean'))
|
|
680
|
+
errors.push(`facts[${index}].value must be scalar or null`);
|
|
681
|
+
const evidenceRefs = refs(fact.evidenceRefs, `facts[${index}].evidenceRefs`, errors, knownEvidence);
|
|
682
|
+
if (label)
|
|
683
|
+
facts.push({ label, value: raw, evidenceRefs });
|
|
684
|
+
});
|
|
685
|
+
const links = [];
|
|
686
|
+
if (row.links !== undefined) {
|
|
687
|
+
if (!Array.isArray(row.links))
|
|
688
|
+
errors.push('links must be an array');
|
|
689
|
+
else
|
|
690
|
+
row.links.forEach((item, index) => {
|
|
691
|
+
if (!item || typeof item !== 'object') {
|
|
692
|
+
errors.push(`links[${index}] must be an object`);
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
const link = item;
|
|
696
|
+
const label = stringValue(link.label, `links[${index}].label`, errors);
|
|
697
|
+
const url = stringValue(link.url, `links[${index}].url`, errors);
|
|
698
|
+
const evidenceRefs = link.evidenceRefs === undefined
|
|
699
|
+
? undefined
|
|
700
|
+
: refs(link.evidenceRefs, `links[${index}].evidenceRefs`, errors, knownEvidence);
|
|
701
|
+
if (label && url)
|
|
702
|
+
links.push({ label, url, ...(evidenceRefs === undefined ? {} : { evidenceRefs }) });
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
if (!eventType ||
|
|
706
|
+
!eventKey ||
|
|
707
|
+
!source ||
|
|
708
|
+
!headline ||
|
|
709
|
+
!occurredAt ||
|
|
710
|
+
!severity ||
|
|
711
|
+
typeof severity !== 'string' ||
|
|
712
|
+
!significance ||
|
|
713
|
+
!theme)
|
|
714
|
+
return result(value, errors);
|
|
715
|
+
return result({
|
|
716
|
+
type: 'owner_notification',
|
|
717
|
+
eventType,
|
|
718
|
+
severity: severity,
|
|
719
|
+
significance: significance,
|
|
720
|
+
theme: theme,
|
|
721
|
+
eventKey,
|
|
722
|
+
source,
|
|
723
|
+
headline,
|
|
724
|
+
facts,
|
|
725
|
+
...(links.length ? { links } : {}),
|
|
726
|
+
...(summary ? { summary } : {}),
|
|
727
|
+
...(dataUpdatedAt ? { dataUpdatedAt } : {}),
|
|
728
|
+
occurredAt,
|
|
729
|
+
...(row.worldLineClosing === true ? { worldLineClosing: true } : {}),
|
|
730
|
+
}, errors);
|
|
731
|
+
}
|
|
732
|
+
export function assertValid(validation) {
|
|
733
|
+
if (!validation.valid || !validation.value)
|
|
734
|
+
throw new Error(`invalid presentation: ${validation.errors.join('; ')}`);
|
|
735
|
+
return validation.value;
|
|
736
|
+
}
|