@brydio/manifest 0.1.0-alpha.28 → 0.1.0-alpha.29
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/package.json +2 -2
- package/src/field-types.d.ts +24 -4
- package/src/field-types.js +42 -4
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brydio/manifest",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.29",
|
|
4
4
|
"description": "The shape of a Brydio app's manifest, its collections' schemas, and the checks that say what is wrong with one.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"url": "https://github.com/nakel-ola/brydio-sdk",
|
|
11
11
|
"directory": "packages/manifest"
|
|
12
12
|
},
|
|
13
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "353f8a61e02fa687ca7eb2e7a48d5a73d66d08a0",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
16
|
"types": "./src/index.d.ts",
|
package/src/field-types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { type ZodType } from 'zod';
|
|
|
12
12
|
* and everything downstream — the store, the generated tools, the screen's
|
|
13
13
|
* form — reads that shape, never the manifest's spelling.
|
|
14
14
|
*/
|
|
15
|
-
export type FieldKind = 'string' | 'text' | 'enum' | 'member' | 'project' | 'date' | 'number' | 'boolean' | 'string[]' | 'token';
|
|
15
|
+
export type FieldKind = 'string' | 'text' | 'enum' | 'member' | 'project' | 'date' | 'number' | 'boolean' | 'string[]' | 'token' | 'canvas';
|
|
16
16
|
export interface FieldType {
|
|
17
17
|
kind: FieldKind;
|
|
18
18
|
/** Written with a trailing `?`: may be left out on create. */
|
|
@@ -27,6 +27,13 @@ export interface FieldType {
|
|
|
27
27
|
* changes, and a value with no label reads as itself.
|
|
28
28
|
*/
|
|
29
29
|
labels?: Readonly<Record<string, string>>;
|
|
30
|
+
/**
|
|
31
|
+
* Written by several people at once (`tasks/docs-wiki` DW01): a `text`
|
|
32
|
+
* field drawn with `bry-rich-text bind` is one fragment of a shared Yjs
|
|
33
|
+
* document the host keeps. Such a field leaves the record's `version`
|
|
34
|
+
* check, and a tool's change to it merges into the live text.
|
|
35
|
+
*/
|
|
36
|
+
coedit?: boolean;
|
|
30
37
|
}
|
|
31
38
|
/**
|
|
32
39
|
* The bounds a schema and a record are held to (A3-F01-S03).
|
|
@@ -74,8 +81,8 @@ export declare const FIELD_NAME: RegExp;
|
|
|
74
81
|
export declare const COLLECTION_NAME: RegExp;
|
|
75
82
|
/** A field type the manifest wrote that Brydio does not have, or a bad list. */
|
|
76
83
|
export declare class FieldTypeInvalid extends Error {
|
|
77
|
-
readonly code: 'data_field_type_unknown' | 'data_enum_empty' | 'data_enum_too_many' | 'data_enum_value_invalid' | 'data_enum_duplicate' | 'data_default_not_allowed' | 'data_default_on_required' | 'data_default_invalid' | 'data_labels_not_allowed' | 'data_label_invalid' | 'data_label_unknown_value' | 'data_field_key_unknown';
|
|
78
|
-
constructor(code: 'data_field_type_unknown' | 'data_enum_empty' | 'data_enum_too_many' | 'data_enum_value_invalid' | 'data_enum_duplicate' | 'data_default_not_allowed' | 'data_default_on_required' | 'data_default_invalid' | 'data_labels_not_allowed' | 'data_label_invalid' | 'data_label_unknown_value' | 'data_field_key_unknown', message: string);
|
|
84
|
+
readonly code: 'data_field_type_unknown' | 'data_enum_empty' | 'data_enum_too_many' | 'data_enum_value_invalid' | 'data_enum_duplicate' | 'data_default_not_allowed' | 'data_default_on_required' | 'data_default_invalid' | 'data_labels_not_allowed' | 'data_label_invalid' | 'data_label_unknown_value' | 'data_field_key_unknown' | 'data_coedit_not_text';
|
|
85
|
+
constructor(code: 'data_field_type_unknown' | 'data_enum_empty' | 'data_enum_too_many' | 'data_enum_value_invalid' | 'data_enum_duplicate' | 'data_default_not_allowed' | 'data_default_on_required' | 'data_default_invalid' | 'data_labels_not_allowed' | 'data_label_invalid' | 'data_label_unknown_value' | 'data_field_key_unknown' | 'data_coedit_not_text', message: string);
|
|
79
86
|
}
|
|
80
87
|
/**
|
|
81
88
|
* One field's manifest spelling, as a type.
|
|
@@ -87,6 +94,16 @@ export declare class FieldTypeInvalid extends Error {
|
|
|
87
94
|
export declare function parseFieldType(raw: unknown): FieldType;
|
|
88
95
|
/** How long a choice value's label may be. */
|
|
89
96
|
export declare const LABEL_CHARS = 60;
|
|
97
|
+
/** True for a field several people write at once, through the co-editing layer. */
|
|
98
|
+
export declare const isCoedited: (type: FieldType) => boolean;
|
|
99
|
+
/**
|
|
100
|
+
* What a drawing's field holds in the record (WB01): a summary the host writes
|
|
101
|
+
* from the live board, so a list, search and the assistant can say what is on
|
|
102
|
+
* it. The drawing itself lives only in the co-edited document.
|
|
103
|
+
*/
|
|
104
|
+
export declare const CANVAS_SUMMARY_CHARS = 10000;
|
|
105
|
+
/** A collection's co-edited fields, by name. */
|
|
106
|
+
export declare const coeditedFields: (fields: Readonly<Record<string, FieldType>>) => string[];
|
|
90
107
|
/** How a choice's value reads to a person: its label, or the value itself. */
|
|
91
108
|
export declare const labelOfValue: (type: FieldType, value: string) => string;
|
|
92
109
|
/** True for a type whose value lands in the plain `fields` column. */
|
|
@@ -127,7 +144,10 @@ type Optional<T> = T extends `${string}?` ? true : T extends {
|
|
|
127
144
|
/** The TypeScript type of one field's value, from its manifest spelling. */
|
|
128
145
|
export type FieldValue<T> = T extends {
|
|
129
146
|
type: infer U;
|
|
130
|
-
} ? FieldValue<U> : T extends readonly (infer V)[] ? V : T extends 'number' | 'number?' ? number : T extends 'boolean' | 'boolean?' ? boolean : T extends 'string[]' | 'string[]?' ? string[] : T extends 'token' | 'token?' ? (typeof COLOUR_TOKENS)[number] : T extends
|
|
147
|
+
} ? FieldValue<U> : T extends readonly (infer V)[] ? V : T extends 'number' | 'number?' ? number : T extends 'boolean' | 'boolean?' ? boolean : T extends 'string[]' | 'string[]?' ? string[] : T extends 'token' | 'token?' ? (typeof COLOUR_TOKENS)[number] : T extends 'canvas' | 'canvas?' ? {
|
|
148
|
+
elements: number;
|
|
149
|
+
text: string;
|
|
150
|
+
} : T extends string ? string : never;
|
|
131
151
|
type Simplify<T> = {
|
|
132
152
|
[K in keyof T]: T[K];
|
|
133
153
|
} & {};
|
package/src/field-types.js
CHANGED
|
@@ -68,7 +68,7 @@ const STRUCTURED = new Set([
|
|
|
68
68
|
]);
|
|
69
69
|
/** Only the words in these may one day be searched (A3-F01-S02). */
|
|
70
70
|
const SEARCHABLE = new Set(['string', 'text', 'string[]']);
|
|
71
|
-
const SCALARS = new Set(['string', 'text', 'member', 'project', 'date', 'number', 'boolean', 'token']);
|
|
71
|
+
const SCALARS = new Set(['string', 'text', 'member', 'project', 'date', 'number', 'boolean', 'token', 'canvas']);
|
|
72
72
|
/** A field type the manifest wrote that Brydio does not have, or a bad list. */
|
|
73
73
|
export class FieldTypeInvalid extends Error {
|
|
74
74
|
code;
|
|
@@ -99,18 +99,24 @@ export function parseFieldType(raw) {
|
|
|
99
99
|
return { kind: 'string[]', optional };
|
|
100
100
|
if (name === 'token')
|
|
101
101
|
return { kind: 'token', optional, values: COLOUR_TOKENS };
|
|
102
|
+
// A drawing is always co-edited and never required: it starts empty (WB01).
|
|
103
|
+
if (name === 'canvas')
|
|
104
|
+
return { kind: 'canvas', optional: true, coedit: true };
|
|
102
105
|
if (SCALARS.has(name))
|
|
103
106
|
return { kind: name, optional };
|
|
104
107
|
throw new FieldTypeInvalid('data_field_type_unknown', `"${raw}" is not a field type.`);
|
|
105
108
|
}
|
|
106
|
-
const FIELD_KEYS = new Set(['type', 'optional', 'default', 'labels']);
|
|
109
|
+
const FIELD_KEYS = new Set(['type', 'optional', 'default', 'labels', 'coedit']);
|
|
107
110
|
/** How long a choice value's label may be. */
|
|
108
111
|
export const LABEL_CHARS = 60;
|
|
109
112
|
/** The object form: the short form under `type`, and what it may add. */
|
|
110
113
|
function parseFieldObject(raw) {
|
|
111
114
|
const unknown = Object.keys(raw).find(key => !FIELD_KEYS.has(key));
|
|
112
115
|
if (unknown) {
|
|
113
|
-
throw new FieldTypeInvalid('data_field_key_unknown', `"${unknown}" is not something a field may say; use type, optional, default and
|
|
116
|
+
throw new FieldTypeInvalid('data_field_key_unknown', `"${unknown}" is not something a field may say; use type, optional, default, labels and coedit.`);
|
|
117
|
+
}
|
|
118
|
+
if (raw.coedit !== undefined && typeof raw.coedit !== 'boolean') {
|
|
119
|
+
throw new FieldTypeInvalid('data_field_key_unknown', '"coedit" is true or false.');
|
|
114
120
|
}
|
|
115
121
|
if (typeof raw.type !== 'string' && !Array.isArray(raw.type)) {
|
|
116
122
|
throw new FieldTypeInvalid('data_field_type_unknown', 'A field written as an object names its type under "type".');
|
|
@@ -119,7 +125,12 @@ function parseFieldObject(raw) {
|
|
|
119
125
|
throw new FieldTypeInvalid('data_field_key_unknown', '"optional" is true or false.');
|
|
120
126
|
}
|
|
121
127
|
const inner = parseFieldType(raw.type);
|
|
122
|
-
const type = {
|
|
128
|
+
const type = {
|
|
129
|
+
...inner,
|
|
130
|
+
optional: inner.optional || raw.optional === true,
|
|
131
|
+
...labelsOf(inner, raw),
|
|
132
|
+
...coeditOf(inner, raw),
|
|
133
|
+
};
|
|
123
134
|
if (!('default' in raw))
|
|
124
135
|
return type;
|
|
125
136
|
const value = raw.default;
|
|
@@ -157,6 +168,27 @@ function labelsOf(type, raw) {
|
|
|
157
168
|
}
|
|
158
169
|
return { labels: { ...labels } };
|
|
159
170
|
}
|
|
171
|
+
/** `coedit`, on long text only: nothing else is typed into by several people at once. */
|
|
172
|
+
function coeditOf(type, raw) {
|
|
173
|
+
if (raw.coedit !== true)
|
|
174
|
+
return {};
|
|
175
|
+
if (type.kind !== 'text' && type.kind !== 'canvas') {
|
|
176
|
+
throw new FieldTypeInvalid('data_coedit_not_text', `Only a text or canvas field may be co-edited, not a ${type.kind}.`);
|
|
177
|
+
}
|
|
178
|
+
return { coedit: true };
|
|
179
|
+
}
|
|
180
|
+
/** True for a field several people write at once, through the co-editing layer. */
|
|
181
|
+
export const isCoedited = (type) => type.kind === 'canvas' || (type.kind === 'text' && type.coedit === true);
|
|
182
|
+
/**
|
|
183
|
+
* What a drawing's field holds in the record (WB01): a summary the host writes
|
|
184
|
+
* from the live board, so a list, search and the assistant can say what is on
|
|
185
|
+
* it. The drawing itself lives only in the co-edited document.
|
|
186
|
+
*/
|
|
187
|
+
export const CANVAS_SUMMARY_CHARS = 10_000;
|
|
188
|
+
/** A collection's co-edited fields, by name. */
|
|
189
|
+
export const coeditedFields = (fields) => Object.entries(fields)
|
|
190
|
+
.filter(([, type]) => isCoedited(type))
|
|
191
|
+
.map(([field]) => field);
|
|
160
192
|
/** How a choice's value reads to a person: its label, or the value itself. */
|
|
161
193
|
export const labelOfValue = (type, value) => type.labels?.[value] ?? value;
|
|
162
194
|
function parseEnumeration(values) {
|
|
@@ -228,6 +260,8 @@ export function valueSchema(type) {
|
|
|
228
260
|
return z.boolean();
|
|
229
261
|
case 'string[]':
|
|
230
262
|
return z.array(z.string().max(FIELD_LIMITS.stringChars)).max(FIELD_LIMITS.listEntries);
|
|
263
|
+
case 'canvas':
|
|
264
|
+
return z.object({ elements: z.number().int().min(0), text: z.string().max(CANVAS_SUMMARY_CHARS) }).strict();
|
|
231
265
|
}
|
|
232
266
|
}
|
|
233
267
|
/**
|
|
@@ -263,6 +297,8 @@ export function valueProblem(field, type, value) {
|
|
|
263
297
|
return Array.isArray(value) && value.length > FIELD_LIMITS.listEntries
|
|
264
298
|
? `${field} may hold at most ${FIELD_LIMITS.listEntries} entries.`
|
|
265
299
|
: `${field} must be a list of short texts, each at most ${FIELD_LIMITS.stringChars.toLocaleString('en-GB')} characters.`;
|
|
300
|
+
case 'canvas':
|
|
301
|
+
return `${field} is a drawing: it is changed on its board, never written.`;
|
|
266
302
|
}
|
|
267
303
|
}
|
|
268
304
|
/** A type in a few words, for a tool's description: every allowed value named. */
|
|
@@ -288,6 +324,8 @@ export function describeType(type) {
|
|
|
288
324
|
return 'true or false';
|
|
289
325
|
case 'string[]':
|
|
290
326
|
return 'a list of short texts';
|
|
327
|
+
case 'canvas':
|
|
328
|
+
return 'a drawing, read only: how many shapes it has and the words on it';
|
|
291
329
|
}
|
|
292
330
|
}
|
|
293
331
|
/** ", read as \"todo\" is To do, \"done\" is Done", for a choice with labels. */
|
package/src/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export { APP_NAME_FORMAT, MANIFEST_LIMITS, SEMVER_FORMAT, baseManifestSchema, brandImagesSchema } from './base.js';
|
|
7
7
|
export { BRAND_FIELDS, BRAND_LIMITS, brandFilePath, brandPathsOf, brandProblems, brandShapeOf, isBrandPath, pngVerdict, svgColours, toolsProblem, type BrandField, type RequirementCode, type RequirementFiles, type RequirementProblem, } from './requirements.js';
|
|
8
8
|
export { BUNDLE_MANIFEST, BUNDLE_MAX_BYTES, BUNDLE_PATH_MAX_CHARS, bundleBytes, bundleHash, brandOf, bundleProblem, codeOf, isBundlePath, isScriptPath, sizeOf, type BundleFiles, type BundleProblem, type BundleProblemCode, } from './bundle.js';
|
|
9
|
-
export { COLOUR_TOKENS, FIELD_LIMITS, RESERVED_FIELDS, describeType, isSearchable, isSortable, isStructured, parseFieldType, structuredFields, valueProblem, valueSchema, FieldTypeInvalid, type DocumentOf, type FieldKind, type FieldType, type FieldValue, type FieldsOf, } from './field-types.js';
|
|
9
|
+
export { COLOUR_TOKENS, coeditedFields, FIELD_LIMITS, RESERVED_FIELDS, describeType, isCoedited, isSearchable, isSortable, isStructured, parseFieldType, structuredFields, valueProblem, valueSchema, FieldTypeInvalid, type DocumentOf, type FieldKind, type FieldType, type FieldValue, type FieldsOf, } from './field-types.js';
|
|
10
10
|
export { appManifestSchema, collectionOf, collectionsOf, dataProblems, effectivePlacementKey, HOME_CARD_SIZES, labelOf, manifestExtensionsSchema, newAppManifestSchema, SIZED_PLACEMENT_KINDS, MAX_APP_SECRETS, MAX_SECRET_CHARS, PLACEMENT_KEY, SECRET_NAME, storedExtensionsSchema, type AppManifestWithData, type CollectionSpec, type DataProblem, type DataProblemCode, type DataProblemOptions, type HomeCardSize, type ManifestExtensions, type SecretSpec, } from './schema.js';
|
|
11
11
|
export { DOCUMENT_LIMITS } from './document-limits.js';
|
|
12
12
|
export { HOST_CAPABILITIES, KNOWN_HOST_GRANTS, isHostCapability, unknownHostGrant } from './grants.js';
|
package/src/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export { APP_NAME_FORMAT, MANIFEST_LIMITS, SEMVER_FORMAT, baseManifestSchema, brandImagesSchema } from "./base.js";
|
|
7
7
|
export { BRAND_FIELDS, BRAND_LIMITS, brandFilePath, brandPathsOf, brandProblems, brandShapeOf, isBrandPath, pngVerdict, svgColours, toolsProblem, } from "./requirements.js";
|
|
8
8
|
export { BUNDLE_MANIFEST, BUNDLE_MAX_BYTES, BUNDLE_PATH_MAX_CHARS, bundleBytes, bundleHash, brandOf, bundleProblem, codeOf, isBundlePath, isScriptPath, sizeOf, } from "./bundle.js";
|
|
9
|
-
export { COLOUR_TOKENS, FIELD_LIMITS, RESERVED_FIELDS, describeType, isSearchable, isSortable, isStructured, parseFieldType, structuredFields, valueProblem, valueSchema, FieldTypeInvalid, } from "./field-types.js";
|
|
9
|
+
export { COLOUR_TOKENS, coeditedFields, FIELD_LIMITS, RESERVED_FIELDS, describeType, isCoedited, isSearchable, isSortable, isStructured, parseFieldType, structuredFields, valueProblem, valueSchema, FieldTypeInvalid, } from "./field-types.js";
|
|
10
10
|
export { appManifestSchema, collectionOf, collectionsOf, dataProblems, effectivePlacementKey, HOME_CARD_SIZES, labelOf, manifestExtensionsSchema, newAppManifestSchema, SIZED_PLACEMENT_KINDS, MAX_APP_SECRETS, MAX_SECRET_CHARS, PLACEMENT_KEY, SECRET_NAME, storedExtensionsSchema, } from "./schema.js";
|
|
11
11
|
export { DOCUMENT_LIMITS } from "./document-limits.js";
|
|
12
12
|
export { HOST_CAPABILITIES, KNOWN_HOST_GRANTS, isHostCapability, unknownHostGrant } from "./grants.js";
|