@vercel/board 0.39.0 → 0.40.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/README.md +5 -3
- package/dist/{access-CVkjSfxj.mjs → access-Bl_k_Hpa.mjs} +1 -1
- package/dist/access.d.mts +2 -2
- package/dist/access.mjs +4 -4
- package/dist/{actors-kfMejhaw.mjs → actors-yBRWTpt5.mjs} +38 -53
- package/dist/{auth-B3bBYOqf.mjs → auth-C8URZHLx.mjs} +2 -2
- package/dist/{auth-BXLCkeB0.d.mts → auth-DtmZzlHm.d.mts} +5 -2
- package/dist/{backend-HcCCGPG4.d.mts → backend-BW5NbBsp.d.mts} +36 -10
- package/dist/backend-local.d.mts +1 -1
- package/dist/backend-local.mjs +1 -1
- package/dist/blocks-CVoBC7ur.mjs +402 -0
- package/dist/blocks-DGvh2alZ.d.mts +33 -0
- package/dist/{chat-provider-DyNy5xdC.d.mts → chat-provider-Bbb9JguG.d.mts} +2 -2
- package/dist/cli-commands.d.mts +1 -1
- package/dist/cli-commands.mjs +1 -1
- package/dist/cli-embedded.d.mts +2 -2
- package/dist/cli-embedded.mjs +3 -3
- package/dist/cli.mjs +5 -5
- package/dist/{commands-B5d-lmNN.d.mts → commands-BJLocuXj.d.mts} +10 -0
- package/dist/{commands-BLS7erNu.mjs → commands-D6VWegVY.mjs} +88 -8
- package/dist/{conformance-D59Py2m2.mjs → conformance-BWhZ0k8T.mjs} +252 -5
- package/dist/conformance.d.mts +4 -3
- package/dist/conformance.mjs +1 -1
- package/dist/data-values-C-Cq80hz.mjs +176 -0
- package/dist/digest-D32GV_mX.mjs +4 -0
- package/dist/{engine-eUgO5jTM.mjs → engine-Djif8XVk.mjs} +191 -77
- package/dist/{errors-rYDxZEuN.mjs → errors-CNRJqUuL.mjs} +16 -14
- package/dist/{exports-M5o4PTfO.mjs → exports-C2OWIbLU.mjs} +621 -245
- package/dist/exports-FyRBIAMs.d.mts +4 -0
- package/dist/{index-rNqqgkyu.d.mts → index-Cuxbz_E0.d.mts} +2 -2
- package/dist/index.d.mts +7 -6
- package/dist/index.mjs +6 -5
- package/dist/index.node.d.mts +7 -6
- package/dist/index.node.mjs +5 -4
- package/dist/inspect/app.js +110 -109
- package/dist/inspect/engine.js +5 -5
- package/dist/inspect-CLy6FrOZ.mjs +2 -0
- package/dist/{inspect-BkXxR2uB.mjs → inspect-cGcP8ZO9.mjs} +4 -4
- package/dist/{local-DvkOWf4U.mjs → local-CsleYuyM.mjs} +373 -177
- package/dist/{main-DtV_Po9i.mjs → main-D97xuqWZ.mjs} +177 -59
- package/dist/{memory-DkoqhxIH.mjs → memory-BvVoglGv.mjs} +2 -2
- package/dist/{mentions-CB6ShY4R.mjs → mentions-CT2bN5eP.mjs} +17 -3
- package/dist/{middleware-CPqAuRtp.mjs → middleware-BF9vnPPS.mjs} +70 -2
- package/dist/{targets-C1mT3M1N.mjs → origin-DLCmrwmE.mjs} +47 -39
- package/dist/{page-64IwoGRu.mjs → page-6BTCZWGY.mjs} +2 -2
- package/dist/page-BnY8FhPn.mjs +2 -0
- package/dist/{provider-D5yVFisj.d.mts → provider-YqkF1E2k.d.mts} +23 -13
- package/dist/{routes-BffuaoTX.d.mts → routes-CAjd5ARa.d.mts} +101 -25
- package/dist/schemas.d.mts +37 -0
- package/dist/schemas.mjs +3 -0
- package/dist/{serve-CX1rqDF_.mjs → serve-Cs-e0Jke.mjs} +4 -4
- package/dist/{server-DkYkyarg.mjs → server-CIfMdIt3.mjs} +6 -6
- package/dist/{serving-DJMcG0dT.mjs → serving-B4l0nLng.mjs} +1 -1
- package/dist/{sql-l3ysn4O5.mjs → sql-Bv-RQu8n.mjs} +73 -10
- package/dist/{sqlite-CAwNHbQD.mjs → sqlite-D4mkYihG.mjs} +2 -2
- package/dist/{sqlite-db-cm5yhrD-.mjs → sqlite-db-BraLvHtf.mjs} +1 -1
- package/dist/sync-chat-sdk.d.mts +2 -2
- package/dist/sync-github.d.mts +2 -2
- package/dist/sync-linear.d.mts +3 -3
- package/dist/sync-slack.d.mts +14 -8
- package/dist/sync-slack.mjs +42 -15
- package/dist/sync.d.mts +2 -2
- package/dist/{tokens-DA9ipsZ-.mjs → tokens-CrrXAVGz.mjs} +2 -2
- package/docs/01-board/01-mounting.md +5 -3
- package/docs/01-board/03-identity.md +70 -38
- package/docs/01-board/04-messages.md +58 -1
- package/docs/01-board/05-reading.md +3 -3
- package/docs/01-board/06-watchers.md +2 -3
- package/docs/01-board/07-schedules.md +2 -4
- package/docs/01-board/08-middleware.md +1 -1
- package/docs/01-board/09-access.md +24 -21
- package/docs/02-sync/01-overview.md +70 -2
- package/docs/02-sync/02-functions.md +11 -6
- package/docs/02-sync/03-slack.md +40 -16
- package/docs/02-sync/06-providers.md +9 -4
- package/docs/04-reference/01-cli.md +110 -18
- package/docs/04-reference/02-board.md +63 -10
- package/docs/04-reference/03-http.md +154 -28
- package/docs/04-reference/05-conformance.md +13 -6
- package/docs/index.md +1 -1
- package/package.json +5 -1
- package/dist/digest-krhjNAt4.mjs +0 -4
- package/dist/exports-vLQ2Y2Nd.d.mts +0 -4
- package/dist/inspect-lnv1sLXM.mjs +0 -2
- package/dist/page-BUj8_UZv.mjs +0 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { u as BoardError } from "./errors-
|
|
2
|
-
import { c as
|
|
1
|
+
import { u as BoardError } from "./errors-CNRJqUuL.mjs";
|
|
2
|
+
import { c as canonical, t as block } from "./blocks-CVoBC7ur.mjs";
|
|
3
|
+
import { c as compileAccess } from "./access-Bl_k_Hpa.mjs";
|
|
3
4
|
//#region src/conformance/index.ts
|
|
4
5
|
var Mismatch = class extends Error {};
|
|
5
6
|
const show = (value) => JSON.stringify(value) ?? String(value);
|
|
@@ -58,13 +59,14 @@ function isRef(value, what) {
|
|
|
58
59
|
/**
|
|
59
60
|
* The groups a board may keep none of, saying so with a 501: a board without a scheduler answers
|
|
60
61
|
* `no_scheduler`, and without a blob store `no_files`; a backend of one's own that keeps no grants
|
|
61
|
-
* answers `no_grants`. A board that's meant to keep something and doesn't yet answers otherwise,
|
|
62
|
+
* answers `no_grants`, and one that keeps no schemas `no_schemas`. A board that's meant to keep something and doesn't yet answers otherwise,
|
|
62
63
|
* and fails.
|
|
63
64
|
*/
|
|
64
65
|
const OPTIONAL = /* @__PURE__ */ new Set([
|
|
65
66
|
"schedules",
|
|
66
67
|
"grants",
|
|
67
68
|
"tokens",
|
|
69
|
+
"schemas",
|
|
68
70
|
"attachments"
|
|
69
71
|
]);
|
|
70
72
|
const needRoot = (ctx) => {
|
|
@@ -212,6 +214,53 @@ const sortedOf = (values) => [...values ?? []].sort();
|
|
|
212
214
|
function alike(actual, expected, what) {
|
|
213
215
|
if (show(actual) !== show(expected)) throw new Mismatch(`${what}: expected ${show(expected)}, got ${show(actual)}`);
|
|
214
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* The schema the schemas checks register: the same on every run, since a version never changes and
|
|
219
|
+
* is never removed, so a board holds one however often it's checked. A change to it is a new
|
|
220
|
+
* version here, never an edit: a board checked before would refuse this one as another definition.
|
|
221
|
+
* It names every property it requires and gives each keyword its type, as the strictest board asks.
|
|
222
|
+
*/
|
|
223
|
+
const SCHEMA = {
|
|
224
|
+
name: "conformance",
|
|
225
|
+
version: 1,
|
|
226
|
+
description: "What the conformance kit registers, once on every board it checks.",
|
|
227
|
+
schema: {
|
|
228
|
+
type: "object",
|
|
229
|
+
required: ["run", "outcome"],
|
|
230
|
+
additionalProperties: false,
|
|
231
|
+
properties: {
|
|
232
|
+
run: {
|
|
233
|
+
type: "string",
|
|
234
|
+
minLength: 1,
|
|
235
|
+
maxLength: 64
|
|
236
|
+
},
|
|
237
|
+
outcome: { enum: ["passed", "failed"] },
|
|
238
|
+
checks: {
|
|
239
|
+
type: "array",
|
|
240
|
+
maxItems: 500,
|
|
241
|
+
items: {
|
|
242
|
+
type: "object",
|
|
243
|
+
required: ["name"],
|
|
244
|
+
properties: {
|
|
245
|
+
name: { type: "string" },
|
|
246
|
+
skipped: { type: "boolean" }
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
/** `SCHEMA`'s definition, saying the same with its keys the other way around. */
|
|
254
|
+
const reversed = (value) => Array.isArray(value) ? value.map(reversed) : value && typeof value === "object" ? Object.fromEntries(Object.entries(value).reverse().map(([key, child]) => [key, reversed(child)])) : value;
|
|
255
|
+
/** Registers `SCHEMA`, or says why this run can't: a caller without manage at `*` is refused, and the check skipped. */
|
|
256
|
+
async function register(ctx) {
|
|
257
|
+
try {
|
|
258
|
+
return { made: await ctx.board.createSchema(SCHEMA) };
|
|
259
|
+
} catch (error) {
|
|
260
|
+
if (error instanceof BoardError && error.status === 403) return { skip: "this token can't register schemas" };
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
215
264
|
/** The sync key the sync checks register, a platform of their own, so nothing reaches a real one. */
|
|
216
265
|
const SYNC_KEY = "conformance";
|
|
217
266
|
/**
|
|
@@ -466,6 +515,34 @@ const CHECKS = [
|
|
|
466
515
|
same(found.last?.id, reply.id, "its latest reply");
|
|
467
516
|
}
|
|
468
517
|
},
|
|
518
|
+
{
|
|
519
|
+
group: "core",
|
|
520
|
+
name: "matches text anywhere in a message's own, in any case, as it reads now",
|
|
521
|
+
run: async (ctx) => {
|
|
522
|
+
const literal = await post(ctx, "conformance: Deploy FAILED at 100% on a_b");
|
|
523
|
+
const lookalike = await post(ctx, "conformance: deploy failed at 1000 on axb");
|
|
524
|
+
const under = await reply(ctx, lookalike.id, "conformance: a reply that says Crème Brûlée");
|
|
525
|
+
const found = async (text) => (await ctx.board.messages({
|
|
526
|
+
channel: ctx.channel,
|
|
527
|
+
label: ctx.labels,
|
|
528
|
+
after: ctx.start,
|
|
529
|
+
text
|
|
530
|
+
})).messages.map((m) => m.id);
|
|
531
|
+
alike(await found("DEPLOY failed"), [literal.id, lookalike.id], "the messages \"DEPLOY failed\" finds");
|
|
532
|
+
alike(await found("100%"), [literal.id], "the messages \"100%\" finds, % being a character");
|
|
533
|
+
alike(await found("a_b"), [literal.id], "the messages \"a_b\" finds, _ being a character");
|
|
534
|
+
alike(await found("BRÛLÉE"), [under.id], "the messages \"BRÛLÉE\" finds");
|
|
535
|
+
const { threads } = await ctx.board.threads({
|
|
536
|
+
channel: ctx.channel,
|
|
537
|
+
label: ctx.labels,
|
|
538
|
+
text: "crème brûlée"
|
|
539
|
+
});
|
|
540
|
+
alike(threads.map((t) => t.message.id), [lookalike.id], "the threads \"crème brûlée\" finds");
|
|
541
|
+
await ctx.board.edit(lookalike.id, "conformance: deploy fixed");
|
|
542
|
+
alike(await found("1000"), [], "the messages \"1000\" finds, once the one that said it is edited");
|
|
543
|
+
alike(await found("deploy fixed"), [lookalike.id], "the messages \"deploy fixed\" finds, once one is edited to say it");
|
|
544
|
+
}
|
|
545
|
+
},
|
|
469
546
|
{
|
|
470
547
|
group: "core",
|
|
471
548
|
name: "reads events after a cursor, each with a cursor of its own",
|
|
@@ -1021,6 +1098,172 @@ const CHECKS = [
|
|
|
1021
1098
|
await refused(holder.me(), 401, "a request with a revoked token");
|
|
1022
1099
|
}
|
|
1023
1100
|
},
|
|
1101
|
+
{
|
|
1102
|
+
group: "schemas",
|
|
1103
|
+
name: "lists the built-in schemas first, and reads a schema by its ID",
|
|
1104
|
+
run: async (ctx) => {
|
|
1105
|
+
const schemas = await ctx.board.schemas();
|
|
1106
|
+
const own = schemas.findIndex((schema) => !schema.builtIn);
|
|
1107
|
+
check(own === -1 || schemas.slice(own).every((schema) => !schema.builtIn), `schemas should list the built-ins first, got ${show(schemas.map((schema) => schema.id))}`);
|
|
1108
|
+
const commit = schemas.find((schema) => schema.id === "git-commit@1");
|
|
1109
|
+
check(commit, `schemas should list the built-in git-commit@1, got ${show(schemas.map((schema) => schema.id))}`);
|
|
1110
|
+
alike({
|
|
1111
|
+
name: commit.name,
|
|
1112
|
+
version: commit.version,
|
|
1113
|
+
builtIn: commit.builtIn,
|
|
1114
|
+
by: commit.by,
|
|
1115
|
+
at: commit.at
|
|
1116
|
+
}, {
|
|
1117
|
+
name: "git-commit",
|
|
1118
|
+
version: 1,
|
|
1119
|
+
builtIn: true,
|
|
1120
|
+
by: null,
|
|
1121
|
+
at: null
|
|
1122
|
+
}, "the built-in git-commit@1");
|
|
1123
|
+
check(commit.schema.type === "object", `a schema's definition should describe an object, got ${show(commit.schema)}`);
|
|
1124
|
+
same(canonical(await ctx.board.schema("git-commit@1")), canonical(commit), "git-commit@1, read by its ID");
|
|
1125
|
+
await rejects(ctx.board.schema("conformance-none@1"), 404, "schema_not_found", "reading a version no one registered");
|
|
1126
|
+
await rejects(ctx.board.schema("Not A Schema"), 400, "invalid_schema_id", "reading an ID that names no schema");
|
|
1127
|
+
}
|
|
1128
|
+
},
|
|
1129
|
+
{
|
|
1130
|
+
group: "schemas",
|
|
1131
|
+
name: "registers a schema version once: the same definition again changes nothing, and another is refused",
|
|
1132
|
+
run: async (ctx) => {
|
|
1133
|
+
const registered = await register(ctx);
|
|
1134
|
+
if ("skip" in registered) return registered.skip;
|
|
1135
|
+
const { schema, created } = registered.made;
|
|
1136
|
+
check(typeof created === "boolean", `created should say whether this made it, got ${show(created)}`);
|
|
1137
|
+
alike({
|
|
1138
|
+
id: schema.id,
|
|
1139
|
+
name: schema.name,
|
|
1140
|
+
version: schema.version,
|
|
1141
|
+
description: schema.description,
|
|
1142
|
+
builtIn: schema.builtIn
|
|
1143
|
+
}, {
|
|
1144
|
+
id: "conformance@1",
|
|
1145
|
+
name: SCHEMA.name,
|
|
1146
|
+
version: SCHEMA.version,
|
|
1147
|
+
description: SCHEMA.description,
|
|
1148
|
+
builtIn: false
|
|
1149
|
+
}, "the schema it registered");
|
|
1150
|
+
same(canonical(schema.schema), canonical(SCHEMA.schema), "the schema's definition, as it was sent");
|
|
1151
|
+
check(typeof schema.by === "string" && schema.by.length > 0, `a registered schema should say who registered it, got ${show(schema.by)}`);
|
|
1152
|
+
check(typeof schema.at === "string" && !Number.isNaN(Date.parse(schema.at)), `a registered schema should say when, got ${show(schema.at)}`);
|
|
1153
|
+
const again = await ctx.board.createSchema({
|
|
1154
|
+
...SCHEMA,
|
|
1155
|
+
schema: reversed(SCHEMA.schema)
|
|
1156
|
+
});
|
|
1157
|
+
same(again.created, false, "whether registering the same definition again made one");
|
|
1158
|
+
same(canonical(again.schema), canonical(schema), "the schema, registered again");
|
|
1159
|
+
await rejects(ctx.board.createSchema({
|
|
1160
|
+
...SCHEMA,
|
|
1161
|
+
schema: {
|
|
1162
|
+
type: "object",
|
|
1163
|
+
required: ["run"],
|
|
1164
|
+
properties: { run: { type: "string" } }
|
|
1165
|
+
}
|
|
1166
|
+
}), 409, "schema_immutable", "another definition for a version that is there");
|
|
1167
|
+
await rejects(ctx.board.createSchema({
|
|
1168
|
+
...SCHEMA,
|
|
1169
|
+
description: "Something else."
|
|
1170
|
+
}), 409, "schema_immutable", "another description for a version that is there");
|
|
1171
|
+
same(canonical(await ctx.board.schema(schema.id)), canonical(schema), "the schema, read by its ID");
|
|
1172
|
+
same((await ctx.board.schemas()).filter((found) => found.id === schema.id).length, 1, `how many times schemas lists ${schema.id}`);
|
|
1173
|
+
}
|
|
1174
|
+
},
|
|
1175
|
+
{
|
|
1176
|
+
group: "schemas",
|
|
1177
|
+
name: "refuses a built-in's name, and a definition it couldn't check a value against",
|
|
1178
|
+
run: async (ctx) => {
|
|
1179
|
+
const attempt = (schema, name = "conformance-refused", version = 1) => ctx.board.createSchema({
|
|
1180
|
+
name,
|
|
1181
|
+
version,
|
|
1182
|
+
schema
|
|
1183
|
+
});
|
|
1184
|
+
const reserved = await attempt({ type: "object" }, "git-commit", 2).then(() => null, (error) => error);
|
|
1185
|
+
if (reserved instanceof BoardError && reserved.status === 403) return "this token can't register schemas";
|
|
1186
|
+
if (!(reserved instanceof BoardError && reserved.status === 409 && reserved.code === "reserved_schema")) throw new Mismatch(`a version of the built-in git-commit: expected 409 reserved_schema, ${reserved === null ? "and it registered one" : `got ${reserved instanceof BoardError ? `${reserved.status} ${reserved.code}` : String(reserved)}`}`);
|
|
1187
|
+
await rejects(attempt({ type: "string" }), 400, "invalid_schema", "a schema that describes no object");
|
|
1188
|
+
await rejects(attempt({
|
|
1189
|
+
type: "object",
|
|
1190
|
+
properties: { next: { $ref: "#" } }
|
|
1191
|
+
}), 400, "invalid_schema", "a schema with a $ref");
|
|
1192
|
+
await rejects(attempt({
|
|
1193
|
+
type: "object",
|
|
1194
|
+
properties: { id: {
|
|
1195
|
+
type: "string",
|
|
1196
|
+
pattern: "^(a+)+$"
|
|
1197
|
+
} }
|
|
1198
|
+
}), 400, "invalid_schema", "a schema with a pattern");
|
|
1199
|
+
await rejects(attempt({
|
|
1200
|
+
type: "object",
|
|
1201
|
+
properties: { ids: {
|
|
1202
|
+
type: "array",
|
|
1203
|
+
uniqueItems: true
|
|
1204
|
+
} }
|
|
1205
|
+
}), 400, "invalid_schema", "a schema with uniqueItems");
|
|
1206
|
+
}
|
|
1207
|
+
},
|
|
1208
|
+
{
|
|
1209
|
+
group: "schemas",
|
|
1210
|
+
name: "carries a block in a message, checked against the schema its fence names",
|
|
1211
|
+
run: async (ctx) => {
|
|
1212
|
+
const registered = await register(ctx);
|
|
1213
|
+
if ("skip" in registered && !await ctx.board.schema("conformance@1").then(() => true, () => false)) return `${registered.skip}, and none registered conformance@1 before it`;
|
|
1214
|
+
const data = {
|
|
1215
|
+
run: ctx.labels.conformance,
|
|
1216
|
+
outcome: "passed",
|
|
1217
|
+
checks: [{
|
|
1218
|
+
name: "a block",
|
|
1219
|
+
skipped: false
|
|
1220
|
+
}]
|
|
1221
|
+
};
|
|
1222
|
+
const text = `conformance: a block among prose\n\n${block("conformance@1", data)}\n\nand after it`;
|
|
1223
|
+
const message = await post(ctx, text);
|
|
1224
|
+
same(message.text, text, "the post's text, as it was written");
|
|
1225
|
+
same(canonical(message.blocks), canonical([{
|
|
1226
|
+
schema: "conformance",
|
|
1227
|
+
version: 1,
|
|
1228
|
+
data
|
|
1229
|
+
}]), "the post's blocks");
|
|
1230
|
+
same(canonical((await ctx.board.thread(message.id)).message.blocks), canonical(message.blocks), "the post's blocks, read back");
|
|
1231
|
+
const alone = await post(ctx, block("conformance@1", data));
|
|
1232
|
+
same(canonical(alone.blocks), canonical([{
|
|
1233
|
+
schema: "conformance",
|
|
1234
|
+
version: 1,
|
|
1235
|
+
data
|
|
1236
|
+
}]), "the blocks of a message that is only one");
|
|
1237
|
+
const shown = await post(ctx, `conformance: a block shown, not carried\n\n\`\`\`\`\n${block("conformance@1", { outcome: "maybe" })}\n\`\`\`\``);
|
|
1238
|
+
same(canonical(shown.blocks), "[]", "the blocks of a message that shows one inside a longer fence");
|
|
1239
|
+
same(canonical((await post(ctx, "conformance: no block")).blocks), "[]", "the blocks of a message with none");
|
|
1240
|
+
const refusedPost = (body) => ctx.board.post(ctx.channel, {
|
|
1241
|
+
text: body,
|
|
1242
|
+
labels: ctx.labels,
|
|
1243
|
+
noSync: true
|
|
1244
|
+
}).then((wrong) => {
|
|
1245
|
+
ctx.posted.push(wrong.id);
|
|
1246
|
+
return wrong;
|
|
1247
|
+
});
|
|
1248
|
+
await rejects(refusedPost(block("conformance@1", {
|
|
1249
|
+
run: ctx.labels.conformance,
|
|
1250
|
+
outcome: "maybe"
|
|
1251
|
+
})), 400, "invalid_block", "a post whose block doesn't match its schema");
|
|
1252
|
+
await rejects(refusedPost(block("conformance-none@1", { run: ctx.labels.conformance })), 400, "schema_not_found", "a post whose block names a schema no one registered");
|
|
1253
|
+
await rejects(ctx.board.edit(alone.id, block("conformance@1", { outcome: "passed" })), 400, "invalid_block", "an edit whose block doesn't match its schema");
|
|
1254
|
+
same(canonical((await ctx.board.thread(alone.id)).message.blocks), canonical(alone.blocks), "the blocks of a message after an edit that was refused");
|
|
1255
|
+
}
|
|
1256
|
+
},
|
|
1257
|
+
{
|
|
1258
|
+
group: "schemas",
|
|
1259
|
+
name: "refuses a caller narrowed with x-board-can a schema, and lets it read them",
|
|
1260
|
+
run: async (ctx) => {
|
|
1261
|
+
if (!ctx.withCan) return NO_CAN;
|
|
1262
|
+
const narrowed = ctx.withCan(`${ctx.channel}=read,post`);
|
|
1263
|
+
check((await narrowed.schemas()).some((schema) => schema.id === "git-commit@1"), "a caller narrowed to a channel should read the schemas");
|
|
1264
|
+
await narrowedOut(narrowed.createSchema(SCHEMA), "registering a schema");
|
|
1265
|
+
}
|
|
1266
|
+
},
|
|
1024
1267
|
{
|
|
1025
1268
|
group: "attachments",
|
|
1026
1269
|
name: "takes a file, posts it, and gives it back",
|
|
@@ -1112,7 +1355,7 @@ const CHECKS = [
|
|
|
1112
1355
|
},
|
|
1113
1356
|
{
|
|
1114
1357
|
group: "sync",
|
|
1115
|
-
name: "keeps sync's records: an import as a
|
|
1358
|
+
name: "keeps sync's records: an import as a profile of its importer, its lookups by platform ID, a receipt, and where it's synced",
|
|
1116
1359
|
run: async (ctx) => {
|
|
1117
1360
|
const key = SYNC_KEY;
|
|
1118
1361
|
const thread = `${key}:${ctx.labels.conformance}:1`;
|
|
@@ -1161,7 +1404,11 @@ const CHECKS = [
|
|
|
1161
1404
|
isRef(id, "an import's message");
|
|
1162
1405
|
try {
|
|
1163
1406
|
const message = (await ctx.board.thread(id)).message;
|
|
1164
|
-
same(message.by.actor, author.id
|
|
1407
|
+
same(message.by.actor, `${ctx.me.principal}+${author.id}`, "the import's author");
|
|
1408
|
+
same(message.by.principal, ctx.me.principal, "the import's principal");
|
|
1409
|
+
same(message.by.profile, author.id, "the import's profile");
|
|
1410
|
+
same(message.author?.name, author.name, "the import's author's name");
|
|
1411
|
+
check(message.author?.via !== void 0, `the import's author should say who it's via, got ${show(message.author)}`);
|
|
1165
1412
|
same(message.from, key, "the import's from");
|
|
1166
1413
|
same(message.origin?.thread, thread, "the import's origin");
|
|
1167
1414
|
const found = await ctx.board.syncFind({
|
package/dist/conformance.d.mts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { d as Board } from "./backend-
|
|
1
|
+
import { d as Board } from "./backend-BW5NbBsp.mjs";
|
|
2
2
|
//#region src/conformance/index.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Checks that a board speaks the protocol, through a handle on it (`conformance(board())`), as
|
|
5
5
|
* `vb` and agents use it: every board answers all of it. A board may keep no schedules or files,
|
|
6
6
|
* and says so with a 501, which the kit reports as not kept here. It writes to one channel
|
|
7
|
-
* (`conformance` by default), keeps every post on the board, and deletes what it posted.
|
|
7
|
+
* (`conformance` by default), keeps every post on the board, and deletes what it posted. The one
|
|
8
|
+
* schema it registers, `conformance@1`, stays: a schema version is never removed.
|
|
8
9
|
*/
|
|
9
10
|
/** What a check is about, for the report's headings. */
|
|
10
|
-
export type CheckGroup = 'core' | 'schedules' | 'grants' | 'tokens' | 'attachments' | 'watchers' | 'sync';
|
|
11
|
+
export type CheckGroup = 'core' | 'schedules' | 'grants' | 'tokens' | 'schemas' | 'attachments' | 'watchers' | 'sync';
|
|
11
12
|
export type CheckResult = {
|
|
12
13
|
group: CheckGroup;
|
|
13
14
|
name: string;
|
package/dist/conformance.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as conformance } from "./conformance-
|
|
1
|
+
import { t as conformance } from "./conformance-BWhZ0k8T.mjs";
|
|
2
2
|
export { conformance };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
//#region src/contract/data-values.ts
|
|
2
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
+
/** What JSON Schema calls a value's type: an integer is a number too. */
|
|
4
|
+
function typeOf(value) {
|
|
5
|
+
if (value === null) return "null";
|
|
6
|
+
if (Array.isArray(value)) return "array";
|
|
7
|
+
if (typeof value === "number") return Number.isInteger(value) ? "integer" : "number";
|
|
8
|
+
return typeof value;
|
|
9
|
+
}
|
|
10
|
+
const isType = (value, type) => {
|
|
11
|
+
const actual = typeOf(value);
|
|
12
|
+
return actual === type || type === "number" && actual === "integer";
|
|
13
|
+
};
|
|
14
|
+
/** Two JSON values that say the same: objects whatever order their keys come in. */
|
|
15
|
+
function same(a, b) {
|
|
16
|
+
if (a === b) return true;
|
|
17
|
+
if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((item, index) => same(item, b[index]));
|
|
18
|
+
if (!isObject(a) || !isObject(b)) return false;
|
|
19
|
+
const keys = Object.keys(a);
|
|
20
|
+
return keys.length === Object.keys(b).length && keys.every((key) => Object.hasOwn(b, key) && same(a[key], b[key]));
|
|
21
|
+
}
|
|
22
|
+
const DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
23
|
+
const TIME = /^(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:z|[+-](\d{2})(?::?(\d{2}))?)?$/i;
|
|
24
|
+
const LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
|
|
25
|
+
const EMAIL_NAME = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*$/i;
|
|
26
|
+
function isDate(text) {
|
|
27
|
+
const found = DATE.exec(text);
|
|
28
|
+
if (!found) return false;
|
|
29
|
+
const [year, month, day] = [
|
|
30
|
+
Number(found[1]),
|
|
31
|
+
Number(found[2]),
|
|
32
|
+
Number(found[3])
|
|
33
|
+
];
|
|
34
|
+
const days = [
|
|
35
|
+
31,
|
|
36
|
+
year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0) ? 29 : 28,
|
|
37
|
+
31,
|
|
38
|
+
30,
|
|
39
|
+
31,
|
|
40
|
+
30,
|
|
41
|
+
31,
|
|
42
|
+
31,
|
|
43
|
+
30,
|
|
44
|
+
31,
|
|
45
|
+
30,
|
|
46
|
+
31
|
|
47
|
+
][month - 1];
|
|
48
|
+
return days !== void 0 && day >= 1 && day <= days;
|
|
49
|
+
}
|
|
50
|
+
function isTime(text) {
|
|
51
|
+
const found = TIME.exec(text);
|
|
52
|
+
if (!found) return false;
|
|
53
|
+
return Number(found[1]) <= 23 && Number(found[2]) <= 59 && Number(found[3]) <= 60 && Number(found[4] ?? 0) <= 23 && Number(found[5] ?? 0) <= 59;
|
|
54
|
+
}
|
|
55
|
+
/** A hostname's labels, with or without the dot that ends a full one. */
|
|
56
|
+
const isHostname = (text) => text.length <= 253 && text.replace(/\.$/, "").split(".").every((label) => LABEL.test(label));
|
|
57
|
+
const isIpv4 = (text) => {
|
|
58
|
+
const parts = text.split(".");
|
|
59
|
+
return parts.length === 4 && parts.every((part) => /^(?:0|[1-9]\d{0,2})$/.test(part) && Number(part) <= 255);
|
|
60
|
+
};
|
|
61
|
+
function isIpv6(text) {
|
|
62
|
+
let groups = text;
|
|
63
|
+
if (text.includes(".")) {
|
|
64
|
+
const tail = text.lastIndexOf(":");
|
|
65
|
+
if (tail === -1 || !isIpv4(text.slice(tail + 1))) return false;
|
|
66
|
+
groups = `${text.slice(0, tail + 1)}0:0`;
|
|
67
|
+
}
|
|
68
|
+
const halves = groups.split("::");
|
|
69
|
+
if (halves.length > 2) return false;
|
|
70
|
+
const parts = halves.flatMap((half) => half === "" ? [] : half.split(":"));
|
|
71
|
+
if (!parts.every((part) => /^[0-9a-f]{1,4}$/i.test(part))) return false;
|
|
72
|
+
return halves.length === 2 ? parts.length <= 7 : parts.length === 8;
|
|
73
|
+
}
|
|
74
|
+
/** What each format takes, each in time linear in the text. */
|
|
75
|
+
const FORMATS = {
|
|
76
|
+
date: isDate,
|
|
77
|
+
time: isTime,
|
|
78
|
+
"date-time": (text) => {
|
|
79
|
+
const at = text.search(/[t ]/i);
|
|
80
|
+
return at !== -1 && isDate(text.slice(0, at)) && isTime(text.slice(at + 1));
|
|
81
|
+
},
|
|
82
|
+
email: (text) => {
|
|
83
|
+
const at = text.lastIndexOf("@");
|
|
84
|
+
const domain = text.slice(at + 1);
|
|
85
|
+
return at > 0 && EMAIL_NAME.test(text.slice(0, at)) && domain.includes(".") && !domain.endsWith(".") && isHostname(domain);
|
|
86
|
+
},
|
|
87
|
+
uri: (text) => /^[a-z][a-z0-9+.-]*:[^\s]+$/i.test(text),
|
|
88
|
+
uuid: (text) => /^(?:urn:uuid:)?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(text),
|
|
89
|
+
hostname: isHostname,
|
|
90
|
+
ipv4: isIpv4,
|
|
91
|
+
ipv6: isIpv6
|
|
92
|
+
};
|
|
93
|
+
/** A value as a refusal shows it: its JSON, cut short. */
|
|
94
|
+
const shown = (value) => {
|
|
95
|
+
const text = JSON.stringify(value) ?? String(value);
|
|
96
|
+
return text.length > 40 ? `${text.slice(0, 39)}…` : text;
|
|
97
|
+
};
|
|
98
|
+
/** `a`, `a or b`, `a, b, or c`: a few values, as a sentence lists them. */
|
|
99
|
+
function oneOf(values) {
|
|
100
|
+
const listed = values.slice(0, 6).map(shown);
|
|
101
|
+
if (values.length > 6) return `one of ${listed.join(", ")}, …`;
|
|
102
|
+
if (listed.length <= 2) return listed.join(" or ");
|
|
103
|
+
return `${listed.slice(0, -1).join(", ")}, or ${listed.at(-1)}`;
|
|
104
|
+
}
|
|
105
|
+
/** A type, or several, as a sentence names them: `a string`, `an object or null`. */
|
|
106
|
+
const named = (type) => (Array.isArray(type) ? type : [type]).map((one) => one === "null" ? "null" : `${/^[aeio]/.test(String(one)) ? "an" : "a"} ${one}`).join(" or ");
|
|
107
|
+
/**
|
|
108
|
+
* Why `value` doesn't match `schema`, or null when it does: the first thing wrong, said of the
|
|
109
|
+
* field it's wrong in (`action must be "started" or "stopped"`, `config.vcpus must be an integer`).
|
|
110
|
+
*/
|
|
111
|
+
function checkValue(schema, value) {
|
|
112
|
+
return problemIn(schema, value, "");
|
|
113
|
+
}
|
|
114
|
+
function problemIn(schema, value, at) {
|
|
115
|
+
const it = at || "it";
|
|
116
|
+
if (schema === true) return null;
|
|
117
|
+
if (schema === false) return `${it} isn't allowed`;
|
|
118
|
+
if (!isObject(schema)) return null;
|
|
119
|
+
const within = (key) => typeof key === "number" ? `${at}[${key}]` : at ? `${at}.${key}` : key;
|
|
120
|
+
const { type } = schema;
|
|
121
|
+
if (type !== void 0 && !(Array.isArray(type) ? type : [type]).some((one) => isType(value, one))) return `${it} must be ${named(type)}`;
|
|
122
|
+
if ("const" in schema && !same(value, schema.const)) return `${it} must be ${shown(schema.const)}`;
|
|
123
|
+
if (Array.isArray(schema.enum) && !schema.enum.some((one) => same(value, one))) return `${it} must be ${oneOf(schema.enum)}`;
|
|
124
|
+
if (typeof value === "string") {
|
|
125
|
+
const length = [...value].length;
|
|
126
|
+
if (typeof schema.minLength === "number" && length < schema.minLength) return `${it} must be at least ${schema.minLength} characters`;
|
|
127
|
+
if (typeof schema.maxLength === "number" && length > schema.maxLength) return `${it} must be at most ${schema.maxLength} characters`;
|
|
128
|
+
if (typeof schema.format === "string" && FORMATS[schema.format]?.(value) === false) return `${it} must be ${/^[aeiu]/.test(schema.format) ? "an" : "a"} ${schema.format}`;
|
|
129
|
+
if (typeof schema.pattern === "string" && !new RegExp(schema.pattern, "u").test(value)) return `${it} must match ${schema.pattern}`;
|
|
130
|
+
}
|
|
131
|
+
if (typeof value === "number") {
|
|
132
|
+
if (typeof schema.minimum === "number" && value < schema.minimum) return `${it} must be at least ${schema.minimum}`;
|
|
133
|
+
if (typeof schema.maximum === "number" && value > schema.maximum) return `${it} must be at most ${schema.maximum}`;
|
|
134
|
+
if (typeof schema.exclusiveMinimum === "number" && value <= schema.exclusiveMinimum) return `${it} must be above ${schema.exclusiveMinimum}`;
|
|
135
|
+
if (typeof schema.exclusiveMaximum === "number" && value >= schema.exclusiveMaximum) return `${it} must be below ${schema.exclusiveMaximum}`;
|
|
136
|
+
if (typeof schema.multipleOf === "number" && !Number.isInteger(value / schema.multipleOf)) return `${it} must be a multiple of ${schema.multipleOf}`;
|
|
137
|
+
}
|
|
138
|
+
if (Array.isArray(value)) {
|
|
139
|
+
if (typeof schema.minItems === "number" && value.length < schema.minItems) return `${it} must have at least ${schema.minItems} items`;
|
|
140
|
+
if (typeof schema.maxItems === "number" && value.length > schema.maxItems) return `${it} must have at most ${schema.maxItems} items`;
|
|
141
|
+
if (schema.items !== void 0) for (let index = 0; index < value.length; index++) {
|
|
142
|
+
const problem = problemIn(schema.items, value[index], within(index));
|
|
143
|
+
if (problem !== null) return problem;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (isObject(value)) {
|
|
147
|
+
const properties = isObject(schema.properties) ? schema.properties : {};
|
|
148
|
+
if (Array.isArray(schema.required)) {
|
|
149
|
+
for (const name of schema.required) if (typeof name === "string" && !Object.hasOwn(value, name)) return `${within(name)} is missing`;
|
|
150
|
+
}
|
|
151
|
+
for (const [name, child] of Object.entries(value)) if (Object.hasOwn(properties, name)) {
|
|
152
|
+
const problem = problemIn(properties[name], child, within(name));
|
|
153
|
+
if (problem !== null) return problem;
|
|
154
|
+
} else if (schema.additionalProperties !== void 0) {
|
|
155
|
+
if (schema.additionalProperties === false) return `${within(name)} isn't one of its fields`;
|
|
156
|
+
const problem = problemIn(schema.additionalProperties, child, within(name));
|
|
157
|
+
if (problem !== null) return problem;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (Array.isArray(schema.allOf)) for (const one of schema.allOf) {
|
|
161
|
+
const problem = problemIn(one, value, at);
|
|
162
|
+
if (problem !== null) return problem;
|
|
163
|
+
}
|
|
164
|
+
for (const keyword of ["anyOf", "oneOf"]) {
|
|
165
|
+
const options = schema[keyword];
|
|
166
|
+
if (!Array.isArray(options)) continue;
|
|
167
|
+
const problems = options.map((one) => problemIn(one, value, at));
|
|
168
|
+
const matched = problems.filter((problem) => problem === null).length;
|
|
169
|
+
if (matched === 0) return problems.length === 1 ? problems[0] : `${it} matches none of the ${problems.length} it can be: ${[...new Set(problems)].slice(0, 4).join("; ")}`;
|
|
170
|
+
if (keyword === "oneOf" && matched > 1) return `${it} matches ${matched} of the ${problems.length} it can be, and must match one`;
|
|
171
|
+
}
|
|
172
|
+
if (schema.not !== void 0 && problemIn(schema.not, value, at) === null) return `${it} matches what it must not`;
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
export { checkValue as t };
|