@tryghost/metafield-types 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 +18 -0
- package/build/index.d.ts +43 -10
- package/build/index.d.ts.map +1 -1
- package/build/index.js +91 -43
- package/build/index.js.map +1 -1
- package/build/shapes.d.ts +185 -0
- package/build/shapes.d.ts.map +1 -0
- package/build/shapes.js +262 -0
- package/build/shapes.js.map +1 -0
- package/build/structure.d.ts +42 -6
- package/build/structure.d.ts.map +1 -1
- package/build/structure.js +24 -3
- package/build/structure.js.map +1 -1
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @tryghost/metafield-types
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Changed how a write clears a value, and described each field shape's rules once, in the package.
|
|
8
|
+
|
|
9
|
+
- `null` is the only way a write clears. A write of `''` to a text field, `[]` to a list, or `''` to a part of an address is refused by `valueSchemaFor` with a message saying to send `null`. A part of an address named as `null` is cleared; before, `null` for a part was refused.
|
|
10
|
+
- A value never holds nothing: a field holding nothing has no value, rather than an empty one. `ValueOf<T>` and `FieldValue` no longer admit `null` or `''` parts, and a write has its own type, `WriteOf<T>` and `FieldWrite`, which does.
|
|
11
|
+
- `./shapes` is a new entry point, zod-free like `./structure`. `SHAPES` holds each shape's rules (`parse`, `same`, `apply`, `diff`), `LEAVES` each kind of leaf's (its JSON kind, `read`, `fromText`), and `FIELD_READING` how a field reads a held value (`held`, `editable`). `shaped(field)` and `shapedType(type)` pair a field or type with its shape, so a table keyed by shape can be indexed with it without a cast. `heldValue`, `editableValue`, `valueFromText`, `textOfValue`, `heldTextOf`, `formTextOf`, `formShows` and `formWrite` read a held value and work out the write a form makes.
|
|
12
|
+
- `accept(shaped(field), raw)` checks a write against the field's strict rule and returns an `Accepted` value branded with its shape, so code that stores a value can require one that passed the rule.
|
|
13
|
+
- `keysOf(value)` lists an object's keys typed as its type's keys. `LeafValues`, `LeafValue`, `LeafKind` and `WriteOf` are exported from `./structure`.
|
|
14
|
+
|
|
15
|
+
- Changed a repeated list option to be refused on the option that repeats an earlier one, and options to repeat each other whatever their case.
|
|
16
|
+
|
|
17
|
+
- `SetSettingsSchema` refuses a repeat at `options.<index>` of the later option, with "This option already exists.". It used to refuse the list at `options` with "Give each option once.".
|
|
18
|
+
- Two options are the same option when their text matches without regard to case, so a list can't offer both "Podcasts" and "podcasts". It used to compare text exactly.
|
|
19
|
+
- `optionKey(option)` is exported from `./structure`: the text two options are compared by, so a client that tidies a list skips the same repeats the schema refuses.
|
|
20
|
+
|
|
3
21
|
## 0.3.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { type FieldType, type FieldShape, type TypedSettings, type ValueOf } from './structure.js';
|
|
3
|
-
|
|
2
|
+
import { type FieldType, type FieldShape, type TypedSettings, type ValueOf, type WriteOf } from './structure.js';
|
|
3
|
+
import { type ShapeWrite, type ShapedField } from './shapes.js';
|
|
4
|
+
export { FIELD_READING, LEAVES, SHAPES, editableValue, formShows, formTextOf, heldTextOf, formWrite, heldValue, leafFromText, shaped, shapedType, textOfValue, valueFromText, type AnyLeafValue, type FieldReading, type ShapeRules, type ShapeText, type ShapeValue, type ShapeWrite, type ShapedField, type ShapedType, type ValueKind, type ValueOfKind, } from './shapes.js';
|
|
5
|
+
export { FIELD_STRUCTURES, FIELD_TYPE_IDS, LIST_SOURCES, MAX_OPTIONS, MIN_OPTIONS, OPTION_SEPARATOR, TEXT_SIZES, choice, country, editableAnswers, inOptionOrder, isFieldType, isRecordValue, matchField, matchLeaf, matchShape, partsOf, text, type ChoiceLeaf, type FieldHandlers, type FieldOfShape, type FieldShape, type FieldStructure, type FieldType, type FieldTypeOfShape, type Leaf, type LeafHandlers, type LeafKind, type LeafValue, type LeafValues, type ListSource, type PartsOf, type RecordStructure, type ScalarStructure, type SetSettings, type SetStructure, type SettingsOf, type ShapeHandlers, type ShapeOf, type StructureOf, type TextLeaf, type TextSize, type TypedSettings, type ValueOf, type WriteOf, keysOf, } from './structure.js';
|
|
4
6
|
/**
|
|
5
7
|
* The shared catalog of member metafield types.
|
|
6
8
|
*
|
|
@@ -16,10 +18,12 @@ export { FIELD_STRUCTURES, FIELD_TYPE_IDS, LIST_SOURCES, MAX_OPTIONS, MIN_OPTION
|
|
|
16
18
|
*
|
|
17
19
|
* ## What a write may say
|
|
18
20
|
*
|
|
19
|
-
* A value is
|
|
20
|
-
* name it does not mention is left as it was, and a name given
|
|
21
|
-
* cleared. That is why every part accepts
|
|
22
|
-
* a statement about the write, not about the part.
|
|
21
|
+
* A value is a leaf's value, and so is every part of one. A write names what it means to
|
|
22
|
+
* change: a name it does not mention is left as it was, and a name given `null` is being
|
|
23
|
+
* cleared, whatever kind of leaf it holds. That is why every part accepts `null` regardless of
|
|
24
|
+
* its own rule: clearing is a statement about the write, not about the part. A value is never
|
|
25
|
+
* empty, so text of nothing but spaces, or a list picking nothing, is refused rather than being
|
|
26
|
+
* a second way of holding nothing.
|
|
23
27
|
*
|
|
24
28
|
* A name nobody recognizes is an error rather than a silent drop, at both depths. A
|
|
25
29
|
* misspelled field key is refused by the values service, which alone knows which fields a
|
|
@@ -106,8 +110,9 @@ export declare const SetSettingsShape: z.ZodObject<{
|
|
|
106
110
|
}, z.core.$strip>;
|
|
107
111
|
/**
|
|
108
112
|
* What a set field is set up with: its shape, with each option's text tidied and the rules a write
|
|
109
|
-
* must meet on top. Options are a set as well, so the same
|
|
110
|
-
*
|
|
113
|
+
* must meet on top. Options are a set as well, so the same option, compared by `optionKey`, can't
|
|
114
|
+
* be offered twice: the option that repeats an earlier one is refused, so a form shows the problem
|
|
115
|
+
* beside the option to change. They are listed in the order they are shown.
|
|
111
116
|
*/
|
|
112
117
|
export declare const SetSettingsSchema: z.ZodPipe<z.ZodObject<{
|
|
113
118
|
options: z.ZodArray<z.ZodString>;
|
|
@@ -381,12 +386,40 @@ export declare const MAX_LONG_TEXT_BYTES = 65535;
|
|
|
381
386
|
* A value of any field type, as a caller holding a field of unknown type must accept it.
|
|
382
387
|
*/
|
|
383
388
|
export type FieldValue = ValueOf<FieldType>;
|
|
389
|
+
/** A write to a field of any type, as a caller holding a field of unknown type must give it. */
|
|
390
|
+
export type FieldWrite = WriteOf<FieldType>;
|
|
384
391
|
export type Address = ValueOf<'address'>;
|
|
385
392
|
/**
|
|
386
|
-
*
|
|
393
|
+
* A value a field's rule accepted for writing, tidied as the rule tidies it. Only `accept` makes
|
|
394
|
+
* one, so a value that skipped the rule can't be handed to code that stores it.
|
|
395
|
+
*/
|
|
396
|
+
export type Accepted<S extends FieldShape> = ShapeWrite[S] & z.core.$brand<'accepted'>;
|
|
397
|
+
/** An accepted value with its shape, so a table keyed by shape can be indexed with it. */
|
|
398
|
+
export type AcceptedValue<S extends FieldShape = FieldShape> = {
|
|
399
|
+
[K in S]: {
|
|
400
|
+
readonly shape: K;
|
|
401
|
+
readonly value: Accepted<K>;
|
|
402
|
+
};
|
|
403
|
+
}[S];
|
|
404
|
+
export type Acceptance<S extends FieldShape = FieldShape> = {
|
|
405
|
+
readonly success: true;
|
|
406
|
+
readonly accepted: AcceptedValue<S>;
|
|
407
|
+
} | {
|
|
408
|
+
readonly success: false;
|
|
409
|
+
readonly issues: readonly z.core.$ZodIssue[];
|
|
410
|
+
};
|
|
411
|
+
/**
|
|
412
|
+
* Strict, for a write, under the field's rule today: only options the field offers now, one answer
|
|
413
|
+
* when it takes one, and each part valid under its leaf's rule. What a held value reads as is
|
|
414
|
+
* lenient instead, and is `FIELD_READING`'s to say.
|
|
415
|
+
*/
|
|
416
|
+
export declare function accept<S extends FieldShape>(of: ShapedField<TypedSettings, S>, raw: unknown): Acceptance<S>;
|
|
417
|
+
/**
|
|
418
|
+
* The rule a write to one field must satisfy, which parses to the write it accepts: a record's
|
|
419
|
+
* part named as `null` clears it. It takes the field rather than its type so that a
|
|
387
420
|
* rule depending on the field's own setup, such as the options a list field offers, changes here
|
|
388
421
|
* and nowhere else; such a rule is built from the field rather than kept per type. Throws for a
|
|
389
422
|
* type this build doesn't know.
|
|
390
423
|
*/
|
|
391
|
-
export declare function valueSchemaFor(field: TypedSettings): z.ZodType<
|
|
424
|
+
export declare function valueSchemaFor(field: TypedSettings): z.ZodType<FieldWrite>;
|
|
392
425
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAQL,KAAK,SAAS,EAMd,KAAK,UAAU,EAKf,KAAK,aAAa,EAClB,KAAK,OAAO,EAEZ,KAAK,OAAO,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAU,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAExE,OAAO,EACL,aAAa,EACb,MAAM,EACN,MAAM,EACN,aAAa,EACb,SAAS,EACT,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,YAAY,EACZ,MAAM,EACN,UAAU,EACV,WAAW,EACX,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AAIrB,OAAO,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_IDS, MAX_OPTIONS, MIN_OPTIONS, OPTION_SEPARATOR,
|
|
3
|
+
import { FIELD_STRUCTURES, FIELD_TYPE_IDS, MAX_OPTIONS, MIN_OPTIONS, OPTION_SEPARATOR, optionKey, optionText, typesOfShape, } from './structure.js';
|
|
4
|
+
import { shaped } from './shapes.js';
|
|
5
|
+
export { FIELD_READING, LEAVES, SHAPES, editableValue, formShows, formTextOf, heldTextOf, formWrite, heldValue, leafFromText, shaped, shapedType, textOfValue, valueFromText, } from './shapes.js';
|
|
4
6
|
// Re-exported so a caller that needs both halves still has one import. The split is
|
|
5
7
|
// about what a bundle pays for, not about where the catalog lives.
|
|
6
|
-
export { FIELD_STRUCTURES, FIELD_TYPE_IDS, LIST_SOURCES, MAX_OPTIONS, MIN_OPTIONS, OPTION_SEPARATOR, TEXT_SIZES, choice, country, editableAnswers, inOptionOrder, isFieldType, isRecordValue, matchField, matchLeaf, matchShape, partsOf, text, } from './structure.js';
|
|
8
|
+
export { FIELD_STRUCTURES, FIELD_TYPE_IDS, LIST_SOURCES, MAX_OPTIONS, MIN_OPTIONS, OPTION_SEPARATOR, TEXT_SIZES, choice, country, editableAnswers, inOptionOrder, isFieldType, isRecordValue, matchField, matchLeaf, matchShape, partsOf, text, keysOf, } from './structure.js';
|
|
7
9
|
/**
|
|
8
10
|
* The shared catalog of member metafield types.
|
|
9
11
|
*
|
|
@@ -19,10 +21,12 @@ export { FIELD_STRUCTURES, FIELD_TYPE_IDS, LIST_SOURCES, MAX_OPTIONS, MIN_OPTION
|
|
|
19
21
|
*
|
|
20
22
|
* ## What a write may say
|
|
21
23
|
*
|
|
22
|
-
* A value is
|
|
23
|
-
* name it does not mention is left as it was, and a name given
|
|
24
|
-
* cleared. That is why every part accepts
|
|
25
|
-
* a statement about the write, not about the part.
|
|
24
|
+
* A value is a leaf's value, and so is every part of one. A write names what it means to
|
|
25
|
+
* change: a name it does not mention is left as it was, and a name given `null` is being
|
|
26
|
+
* cleared, whatever kind of leaf it holds. That is why every part accepts `null` regardless of
|
|
27
|
+
* its own rule: clearing is a statement about the write, not about the part. A value is never
|
|
28
|
+
* empty, so text of nothing but spaces, or a list picking nothing, is refused rather than being
|
|
29
|
+
* a second way of holding nothing.
|
|
26
30
|
*
|
|
27
31
|
* A name nobody recognizes is an error rather than a silent drop, at both depths. A
|
|
28
32
|
* misspelled field key is refused by the values service, which alone knows which fields a
|
|
@@ -114,16 +118,20 @@ function optionProblem(option) {
|
|
|
114
118
|
}
|
|
115
119
|
/**
|
|
116
120
|
* What a set field is set up with: its shape, with each option's text tidied and the rules a write
|
|
117
|
-
* must meet on top. Options are a set as well, so the same
|
|
118
|
-
*
|
|
121
|
+
* must meet on top. Options are a set as well, so the same option, compared by `optionKey`, can't
|
|
122
|
+
* be offered twice: the option that repeats an earlier one is refused, so a form shows the problem
|
|
123
|
+
* beside the option to change. They are listed in the order they are shown.
|
|
119
124
|
*/
|
|
120
125
|
export const SetSettingsSchema = SetSettingsShape.transform(({ options, multiple }) => ({
|
|
121
126
|
options: options.map(optionText),
|
|
122
127
|
multiple,
|
|
123
128
|
})).check((ctx) => {
|
|
124
129
|
const { options } = ctx.value;
|
|
130
|
+
const offered = new Set();
|
|
125
131
|
options.forEach((option, index) => {
|
|
126
|
-
const
|
|
132
|
+
const key = optionKey(option);
|
|
133
|
+
const problem = optionProblem(option) ?? (offered.has(key) ? 'This option already exists.' : null);
|
|
134
|
+
offered.add(key);
|
|
127
135
|
if (problem) {
|
|
128
136
|
ctx.issues.push({
|
|
129
137
|
code: 'custom',
|
|
@@ -137,9 +145,7 @@ export const SetSettingsSchema = SetSettingsShape.transform(({ options, multiple
|
|
|
137
145
|
? `Give the list at least ${MIN_OPTIONS} options.`
|
|
138
146
|
: options.length > MAX_OPTIONS
|
|
139
147
|
? `Give the list ${MAX_OPTIONS} options or fewer.`
|
|
140
|
-
:
|
|
141
|
-
? 'Give each option once.'
|
|
142
|
-
: null;
|
|
148
|
+
: null;
|
|
143
149
|
if (listProblem) {
|
|
144
150
|
ctx.issues.push({ code: 'custom', message: listProblem, input: options, path: ['options'] });
|
|
145
151
|
}
|
|
@@ -251,19 +257,20 @@ export const MAX_LONG_TEXT_BYTES = 65535;
|
|
|
251
257
|
// TextEncoder rather than Buffer: this package runs in the browser too.
|
|
252
258
|
const byteLength = (value) => new TextEncoder().encode(value).length;
|
|
253
259
|
/**
|
|
254
|
-
* Every leaf's rule is built from this, so no two leaves can disagree about whitespace
|
|
255
|
-
*
|
|
256
|
-
* each bound measure the value rather than its padding.
|
|
260
|
+
* Every text leaf's rule is built from this, so no two leaves can disagree about whitespace.
|
|
261
|
+
* Trimming first also makes each bound measure the value rather than its padding.
|
|
257
262
|
*/
|
|
258
263
|
const trimmed = () => z.string({ error: 'Enter text.' }).trim();
|
|
264
|
+
/** Text that holds something: text of nothing but spaces is refused, since a write clears with `null`. */
|
|
265
|
+
const filled = () => trimmed().min(1, { error: 'Enter a value, or send null to clear it.' });
|
|
259
266
|
/** Each text size's bound. Each message is a literal, so it can be a translation key. */
|
|
260
267
|
const TEXT_RULES = {
|
|
261
|
-
line: () =>
|
|
268
|
+
line: () => filled().max(255, { error: 'Use 255 characters or fewer.' }),
|
|
262
269
|
// A sanity limit rather than a format, used for postal codes: they vary too much between
|
|
263
270
|
// countries to check the shape of one without knowing the country, and the country is a
|
|
264
271
|
// sibling part rather than something this can see.
|
|
265
|
-
code: () =>
|
|
266
|
-
long: () =>
|
|
272
|
+
code: () => filled().max(32, { error: 'Use 32 characters or fewer.' }),
|
|
273
|
+
long: () => filled().refine((value) => byteLength(value) <= MAX_LONG_TEXT_BYTES, {
|
|
267
274
|
error: 'This text is too long to save. Shorten it a little.',
|
|
268
275
|
}),
|
|
269
276
|
};
|
|
@@ -277,22 +284,23 @@ const LIST_RULES = {
|
|
|
277
284
|
// Case is normalized so that `gb` and `GB` are not two values for one place, which a filter for
|
|
278
285
|
// either would silently half-miss. Checked as two ASCII letters on the way in rather than by
|
|
279
286
|
// length on the way out, because uppercasing does not preserve length: `ß` becomes `SS`.
|
|
280
|
-
countries: () =>
|
|
287
|
+
countries: () => filled()
|
|
281
288
|
.regex(/^[A-Za-z]{2}$/, { error: 'Enter a 2-letter country code, like US.' })
|
|
282
289
|
.toUpperCase(),
|
|
283
290
|
};
|
|
284
|
-
|
|
291
|
+
/** Each kind of leaf's rule. Keyed by kind, so a kind added to the catalog fails to compile here. */
|
|
292
|
+
const LEAF_RULES = {
|
|
285
293
|
text: ({ size }) => TEXT_RULES[size](),
|
|
286
294
|
choice: ({ from }) => LIST_RULES[from](),
|
|
287
|
-
}
|
|
295
|
+
};
|
|
296
|
+
/** A leaf's rule, whichever kind of leaf it is. */
|
|
297
|
+
const leafRule = (leaf) => LEAF_RULES[leaf.leaf](leaf);
|
|
288
298
|
/**
|
|
289
|
-
* A part as a write may name it: absent,
|
|
290
|
-
*
|
|
291
|
-
*
|
|
299
|
+
* A part as a write may name it: absent to leave it alone, `null` to clear it, or a value of its
|
|
300
|
+
* own leaf. Every part clears the same way, whatever its leaf's rule, so none can be set but never
|
|
301
|
+
* removed.
|
|
292
302
|
*/
|
|
293
|
-
const
|
|
294
|
-
.pipe(z.union([z.literal(''), rule]))
|
|
295
|
-
.optional();
|
|
303
|
+
const part = (leaf) => leafRule(leaf).nullable().optional();
|
|
296
304
|
/** What each record type says when a write names none of its parts. */
|
|
297
305
|
const RECORD_EMPTY = {
|
|
298
306
|
address: 'Enter at least one part of the address.',
|
|
@@ -311,11 +319,8 @@ const RECORD_EMPTY = {
|
|
|
311
319
|
*/
|
|
312
320
|
function recordRule(type) {
|
|
313
321
|
return z
|
|
314
|
-
.strictObject(Object.fromEntries(Object.entries(FIELD_STRUCTURES[type].parts).map(([
|
|
315
|
-
|
|
316
|
-
clearable(leafRule(leaf)),
|
|
317
|
-
])))
|
|
318
|
-
.refine((value) => Object.values(value).some((entry) => typeof entry === 'string'), {
|
|
322
|
+
.strictObject(Object.fromEntries(Object.entries(FIELD_STRUCTURES[type].parts).map(([name, leaf]) => [name, part(leaf)])))
|
|
323
|
+
.refine((value) => Object.values(value).some((entry) => entry !== undefined), {
|
|
319
324
|
error: RECORD_EMPTY[type],
|
|
320
325
|
});
|
|
321
326
|
}
|
|
@@ -345,7 +350,15 @@ function setRule({ options, multiple }) {
|
|
|
345
350
|
return [...new Set(texts.map(optionText))];
|
|
346
351
|
})
|
|
347
352
|
.check((ctx) => {
|
|
348
|
-
if (ctx.value.
|
|
353
|
+
if (ctx.value.length === 0) {
|
|
354
|
+
// A list holding nothing is no answer, which a write gives as `null`.
|
|
355
|
+
ctx.issues.push({
|
|
356
|
+
code: 'custom',
|
|
357
|
+
message: 'Choose at least one option, or send null to clear it.',
|
|
358
|
+
input: ctx.value,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
else if (ctx.value.some((option) => !offered.has(option))) {
|
|
349
362
|
ctx.issues.push({
|
|
350
363
|
code: 'custom',
|
|
351
364
|
message: 'Choose from the options this field offers.',
|
|
@@ -357,24 +370,59 @@ function setRule({ options, multiple }) {
|
|
|
357
370
|
}
|
|
358
371
|
});
|
|
359
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* `build` run once per type, for a rule that comes from the type alone: Ghost checks every value an
|
|
375
|
+
* import writes through these rules, and Admin every keystroke.
|
|
376
|
+
*/
|
|
377
|
+
function oncePerType(build) {
|
|
378
|
+
const built = new Map();
|
|
379
|
+
return (type) => {
|
|
380
|
+
const rule = built.get(type) ?? build(type);
|
|
381
|
+
built.set(type, rule);
|
|
382
|
+
return rule;
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
const scalarRule = oncePerType((type) => leafRule(FIELD_STRUCTURES[type].leaf));
|
|
386
|
+
const recordRuleOf = oncePerType(recordRule);
|
|
387
|
+
/**
|
|
388
|
+
* Each shape's strict rule for a write, from what a field's type is composed of and, for a set,
|
|
389
|
+
* the options the field offers. Keyed by shape, so a shape added to the catalog fails to compile
|
|
390
|
+
* here until it has a rule.
|
|
391
|
+
*/
|
|
392
|
+
const WRITE_RULES = {
|
|
393
|
+
scalar: ({ type }) => scalarRule(type),
|
|
394
|
+
record: ({ type }) => recordRuleOf(type),
|
|
395
|
+
set: ({ settings }) => setRule(settings),
|
|
396
|
+
};
|
|
397
|
+
function writeRuleOf({ shape, field, }) {
|
|
398
|
+
return WRITE_RULES[shape](field);
|
|
399
|
+
}
|
|
360
400
|
/** A field's rule, from what its type is composed of and, for a set, the options the field offers. */
|
|
361
401
|
function ruleOf(field) {
|
|
362
|
-
return
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
402
|
+
return writeRuleOf(shaped(field));
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Strict, for a write, under the field's rule today: only options the field offers now, one answer
|
|
406
|
+
* when it takes one, and each part valid under its leaf's rule. What a held value reads as is
|
|
407
|
+
* lenient instead, and is `FIELD_READING`'s to say.
|
|
408
|
+
*/
|
|
409
|
+
export function accept(of, raw) {
|
|
410
|
+
const result = writeRuleOf(of).brand().safeParse(raw);
|
|
411
|
+
return result.success
|
|
412
|
+
? { success: true, accepted: acceptedAs(of.shape, result.data) }
|
|
413
|
+
: { success: false, issues: result.error.issues };
|
|
414
|
+
}
|
|
415
|
+
function acceptedAs(shape, value) {
|
|
416
|
+
return { shape, value };
|
|
367
417
|
}
|
|
368
|
-
// Built once per type whose rule comes from the type alone: Ghost checks every value an import
|
|
369
|
-
// writes, and Admin every keystroke.
|
|
370
|
-
const RULES = new Map([...typesOfShape('scalar'), ...typesOfShape('record')].map((type) => [type, ruleOf({ type })]));
|
|
371
418
|
/**
|
|
372
|
-
* The rule a
|
|
419
|
+
* The rule a write to one field must satisfy, which parses to the write it accepts: a record's
|
|
420
|
+
* part named as `null` clears it. It takes the field rather than its type so that a
|
|
373
421
|
* rule depending on the field's own setup, such as the options a list field offers, changes here
|
|
374
422
|
* and nowhere else; such a rule is built from the field rather than kept per type. Throws for a
|
|
375
423
|
* type this build doesn't know.
|
|
376
424
|
*/
|
|
377
425
|
export function valueSchemaFor(field) {
|
|
378
|
-
return
|
|
426
|
+
return ruleOf(field);
|
|
379
427
|
}
|
|
380
428
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,SAAS,EAWT,YAAY,GACb,MAAM,gBAAgB,CAAC;AAExB,oFAAoF;AACpF,mEAAmE;AACnE,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,MAAM,EACN,OAAO,EACP,eAAe,EACf,aAAa,EACb,WAAW,EACX,aAAa,EACb,UAAU,EACV,SAAS,EACT,UAAU,EACV,OAAO,EACP,IAAI,GAyBL,MAAM,gBAAgB,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAEtD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAEvE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAC/D,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;CACuC,CAAC;AAExD;;;GAGG;AACH,MAAM,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,MAAM,CAAC,OAAO;QACnB,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE;QAChE,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;AACtD,CAAC;AAED,SAAS,UAAU,CAAuB,KAAQ,EAAE,KAAkB;IACpE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,KAAoB;IACjD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules every field of a shape follows, whatever its type and settings, and the rules a field
|
|
3
|
+
* adds from its settings when a held value is read.
|
|
4
|
+
*
|
|
5
|
+
* A shape's rules look only at structure: they know a list is a list of strings, but not which
|
|
6
|
+
* strings a field offers. They also say what a write does to a held value, which is part of the
|
|
7
|
+
* API's contract rather than storage's choice: a client works out a write against the value its
|
|
8
|
+
* form loaded, and Ghost applies it to whatever is stored when it lands, which another writer may
|
|
9
|
+
* have changed in between. The two only agree because both read the rules here.
|
|
10
|
+
*
|
|
11
|
+
* Each table is keyed by shape, so a shape added to the catalog fails to compile here until it has
|
|
12
|
+
* an entry. Each translator of a shape into another domain's terms, such as the storage translator
|
|
13
|
+
* into rows or the CSV translator into cells, keeps its own table of the same form, which `shaped`
|
|
14
|
+
* lets it index without a cast.
|
|
15
|
+
*
|
|
16
|
+
* Zod-free, like `./structure`, so Portal can use it. The strict rule a write must meet is built
|
|
17
|
+
* from zod and lives in `./index` as `accept`.
|
|
18
|
+
*/
|
|
19
|
+
import { type FieldOfShape, type FieldShape, type FieldType, type FieldTypeOfShape, type Leaf, type LeafKind, type LeafValues, type TypedSettings, type ValueOf, type WriteOf } from './structure.js';
|
|
20
|
+
/** A leaf's value of any kind. */
|
|
21
|
+
export type AnyLeafValue = LeafValues[LeafKind];
|
|
22
|
+
/**
|
|
23
|
+
* What a value of each JSON kind is. Primitives only: the shape rules compare two leaf values with
|
|
24
|
+
* `===`, which a kind holding objects would break.
|
|
25
|
+
*/
|
|
26
|
+
interface KindValues {
|
|
27
|
+
string: string;
|
|
28
|
+
number: number;
|
|
29
|
+
boolean: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** The JSON kind a value comes in. */
|
|
32
|
+
type KindOf<V> = {
|
|
33
|
+
[K in keyof KindValues]: V extends KindValues[K] ? K : never;
|
|
34
|
+
}[keyof KindValues];
|
|
35
|
+
/**
|
|
36
|
+
* The JSON kinds the catalog's leaves' values come in, which is all that tells two leaves' values
|
|
37
|
+
* apart without their field: how storage picks a value's column, and a filter what to compare it
|
|
38
|
+
* in. Read from the leaves, so a leaf kind whose value is a new JSON kind widens it.
|
|
39
|
+
*/
|
|
40
|
+
export type ValueKind = KindOf<AnyLeafValue>;
|
|
41
|
+
/** The leaf values of one JSON kind. */
|
|
42
|
+
export type ValueOfKind<K extends ValueKind> = Extract<AnyLeafValue, KindValues[K]>;
|
|
43
|
+
/**
|
|
44
|
+
* What the domain knows about each kind of leaf beyond its rule, which needs zod and is
|
|
45
|
+
* `LEAF_RULES` in `./index`. Keyed by kind, so a kind added to the catalog fails to compile here
|
|
46
|
+
* until it says each.
|
|
47
|
+
*/
|
|
48
|
+
interface LeafKindRules<K extends LeafKind> {
|
|
49
|
+
/** The JSON kind its value comes in. */
|
|
50
|
+
readonly kind: KindOf<LeafValues[K]>;
|
|
51
|
+
/** A raw value read as this leaf's value, or undefined when it holds none. */
|
|
52
|
+
read(raw: unknown): LeafValues[K] | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Text, as a form's input or a CSV cell holds it, read as this leaf's value, or the text itself
|
|
55
|
+
* where it holds none, so the leaf's rule refuses it rather than it being dropped. Writing a
|
|
56
|
+
* value as text is `String` for every kind.
|
|
57
|
+
*/
|
|
58
|
+
fromText(text: string): LeafValues[K] | string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* What a value of each shape holds: whatever a type of that shape holds, read from the catalog, so a
|
|
62
|
+
* type's parts and leaves are typed the same way here. A value always holds something: a field
|
|
63
|
+
* holding nothing has no value at all, rather than an empty one, so `0` and an answer left blank are
|
|
64
|
+
* never confused. A record holds at least one part, and a set at least one option.
|
|
65
|
+
*/
|
|
66
|
+
export type ShapeValue = {
|
|
67
|
+
[S in FieldShape]: ValueOf<FieldTypeOfShape<S>>;
|
|
68
|
+
};
|
|
69
|
+
/** What a write to a field of each shape gives, from the catalog in the same way; see `WriteOf`. */
|
|
70
|
+
export type ShapeWrite = {
|
|
71
|
+
[S in FieldShape]: WriteOf<FieldTypeOfShape<S>>;
|
|
72
|
+
};
|
|
73
|
+
export interface ShapeRules<S extends FieldShape> {
|
|
74
|
+
/**
|
|
75
|
+
* What `raw` holds as a value of `type`, or undefined when it holds nothing of it. Lenient: a part
|
|
76
|
+
* the type doesn't declare, or one of another kind than its leaf, is left out.
|
|
77
|
+
*/
|
|
78
|
+
parse(type: FieldTypeOfShape<S>, raw: unknown): ShapeValue[S] | undefined;
|
|
79
|
+
/** Whether two values hold the same, which a write that changes nothing leaves alone. */
|
|
80
|
+
same(a: ShapeValue[S], b: ShapeValue[S]): boolean;
|
|
81
|
+
/** What a write does to what is held, which is nothing when a record's write clears every part. */
|
|
82
|
+
apply(held: ShapeValue[S] | undefined, write: ShapeWrite[S]): ShapeValue[S] | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* The smallest write that turns `held` into `next`: `null` when `next` holds nothing, and
|
|
85
|
+
* undefined when the two hold the same.
|
|
86
|
+
*/
|
|
87
|
+
diff(held: ShapeValue[S] | undefined, next: ShapeValue[S] | undefined): ShapeWrite[S] | null | undefined;
|
|
88
|
+
}
|
|
89
|
+
export declare const LEAVES: {
|
|
90
|
+
readonly [K in LeafKind]: LeafKindRules<K>;
|
|
91
|
+
};
|
|
92
|
+
/** Each shape's rules. A shape added to the catalog without rules doesn't compile. */
|
|
93
|
+
export declare const SHAPES: {
|
|
94
|
+
readonly [S in FieldShape]: ShapeRules<S>;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* A field together with its shape, as one of a union with a member per shape. Indexing a table
|
|
98
|
+
* keyed by shape with `shape` gives the entry for the same shape that `field` has, so a translator
|
|
99
|
+
* such as the storage translator can call its entry for a field without a cast or a branch per
|
|
100
|
+
* shape.
|
|
101
|
+
*/
|
|
102
|
+
export type ShapedField<F extends TypedSettings = TypedSettings, S extends FieldShape = FieldShape> = {
|
|
103
|
+
[K in S]: {
|
|
104
|
+
readonly shape: K;
|
|
105
|
+
readonly field: FieldOfShape<K, F>;
|
|
106
|
+
};
|
|
107
|
+
}[S];
|
|
108
|
+
/** A field paired with its shape: the one place a field's union is branched on by shape. */
|
|
109
|
+
export declare function shaped<F extends TypedSettings>(field: F): ShapedField<F>;
|
|
110
|
+
/**
|
|
111
|
+
* A type together with its shape, for a translator that knows a field's type but not its settings,
|
|
112
|
+
* as the CSV translator does.
|
|
113
|
+
*/
|
|
114
|
+
export type ShapedType<S extends FieldShape = FieldShape> = {
|
|
115
|
+
[K in S]: {
|
|
116
|
+
readonly shape: K;
|
|
117
|
+
readonly type: FieldTypeOfShape<K>;
|
|
118
|
+
};
|
|
119
|
+
}[S];
|
|
120
|
+
/** A type paired with its shape. */
|
|
121
|
+
export declare function shapedType(type: FieldType): ShapedType;
|
|
122
|
+
/** How a field of each shape reads a held value, using its type and settings. */
|
|
123
|
+
export interface FieldReading<S extends FieldShape> {
|
|
124
|
+
/**
|
|
125
|
+
* Lenient: what a field holds, read as the field gives it meaning. Keeps answers to options
|
|
126
|
+
* since removed, and parts saved under an older, looser rule, so tightening a rule never hides
|
|
127
|
+
* what members hold. Puts a list's answers in the field's order, then the removed ones.
|
|
128
|
+
*/
|
|
129
|
+
held(field: FieldOfShape<S>, value: ShapeValue[S]): ShapeValue[S] | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* What a form can show of a held value. A save that writes what the form shows drops an answer
|
|
132
|
+
* the form can't show.
|
|
133
|
+
*/
|
|
134
|
+
editable(field: FieldOfShape<S>, held: ShapeValue[S]): ShapeValue[S] | undefined;
|
|
135
|
+
}
|
|
136
|
+
export declare const FIELD_READING: {
|
|
137
|
+
readonly [S in FieldShape]: FieldReading<S>;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* What a held raw value reads as for its field: its structure checked, then read as the field
|
|
141
|
+
* gives it meaning. Undefined when the value isn't the field's structure.
|
|
142
|
+
*/
|
|
143
|
+
export declare function heldValue<S extends FieldShape>({ shape, field }: ShapedField<TypedSettings, S>, raw: unknown): ShapeValue[S] | undefined;
|
|
144
|
+
/** What a form can show of a held raw value, or undefined when it shows nothing. */
|
|
145
|
+
export declare function editableValue<S extends FieldShape>(of: ShapedField<TypedSettings, S>, raw: unknown): ShapeValue[S] | undefined;
|
|
146
|
+
/** A leaf's value as text gives it, or undefined for blank text, which holds nothing. */
|
|
147
|
+
export declare const leafFromText: (leaf: Leaf, text: string) => AnyLeafValue | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* What a value given as text holds, such as a form's inputs or a row's cells: each leaf read from
|
|
150
|
+
* its text, then parsed as a value of its type, which drops blank text. Undefined when it holds
|
|
151
|
+
* nothing.
|
|
152
|
+
*/
|
|
153
|
+
export declare function valueFromText<S extends FieldShape>({ shape, type }: ShapedType<S>, raw: unknown): ShapeValue[S] | undefined;
|
|
154
|
+
/** A value of each shape as a form's inputs hold it: each leaf as its text. */
|
|
155
|
+
export interface ShapeText {
|
|
156
|
+
scalar: string;
|
|
157
|
+
record: {
|
|
158
|
+
readonly [part: string]: string;
|
|
159
|
+
};
|
|
160
|
+
set: string[];
|
|
161
|
+
}
|
|
162
|
+
/** A value as a form's inputs hold it, which `valueFromText` reads back as the same value. */
|
|
163
|
+
export declare function textOfValue<S extends FieldShape>(shape: S, value: ShapeValue[S]): ShapeText[S];
|
|
164
|
+
/** What a field holds, each leaf as its text, as a field shown but not edited draws it. */
|
|
165
|
+
export declare function heldTextOf<S extends FieldShape>(of: ShapedField<TypedSettings, S>, held: unknown): ShapeText[S] | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* What a form's inputs start from for a held raw value: what the form can show of it, each leaf as
|
|
168
|
+
* its text, or undefined when it shows nothing.
|
|
169
|
+
*/
|
|
170
|
+
export declare function formTextOf<S extends FieldShape>(of: ShapedField<TypedSettings, S>, held: unknown): ShapeText[S] | undefined;
|
|
171
|
+
/**
|
|
172
|
+
* What a form's inputs show, read as the field reads a value: each leaf from its text, blank text
|
|
173
|
+
* holding nothing, and only what the form can show. Undefined when they show nothing.
|
|
174
|
+
*/
|
|
175
|
+
export declare function formShows<S extends FieldShape>(of: ShapedField<TypedSettings, S>, inputs: unknown): ShapeValue[S] | undefined;
|
|
176
|
+
/**
|
|
177
|
+
* The write that turns what a field holds into what a form's inputs show: `null` when the inputs
|
|
178
|
+
* show nothing of a replacing shape, and undefined when they show what the field holds. The held
|
|
179
|
+
* value is read as the field reads it first, so a part the form doesn't draw is never written, and
|
|
180
|
+
* an answer the form can't show, such as one to an option the field no longer offers, is cleared
|
|
181
|
+
* by the write.
|
|
182
|
+
*/
|
|
183
|
+
export declare function formWrite<S extends FieldShape>(of: ShapedField<TypedSettings, S>, inputs: unknown, held: unknown): ShapeWrite[S] | null | undefined;
|
|
184
|
+
export {};
|
|
185
|
+
//# sourceMappingURL=shapes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shapes.d.ts","sourceRoot":"","sources":["../src/shapes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAML,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,U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AAS,CAAC,CAAC,SAAS,UAAU,EAC5C,EAAE,EAAE,WAAW,CAAC,aAAa,EAAE,CAAC,CAAC,EACjC,MAAM,EAAE,OAAO,GACd,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAG3B;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,UAAU,EAC5C,EAAE,EAAE,WAAW,CAAC,aAAa,EAAE,CAAC,CAAC,EACjC,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,OAAO,GACZ,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAElC"}
|
package/build/shapes.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules every field of a shape follows, whatever its type and settings, and the rules a field
|
|
3
|
+
* adds from its settings when a held value is read.
|
|
4
|
+
*
|
|
5
|
+
* A shape's rules look only at structure: they know a list is a list of strings, but not which
|
|
6
|
+
* strings a field offers. They also say what a write does to a held value, which is part of the
|
|
7
|
+
* API's contract rather than storage's choice: a client works out a write against the value its
|
|
8
|
+
* form loaded, and Ghost applies it to whatever is stored when it lands, which another writer may
|
|
9
|
+
* have changed in between. The two only agree because both read the rules here.
|
|
10
|
+
*
|
|
11
|
+
* Each table is keyed by shape, so a shape added to the catalog fails to compile here until it has
|
|
12
|
+
* an entry. Each translator of a shape into another domain's terms, such as the storage translator
|
|
13
|
+
* into rows or the CSV translator into cells, keeps its own table of the same form, which `shaped`
|
|
14
|
+
* lets it index without a cast.
|
|
15
|
+
*
|
|
16
|
+
* Zod-free, like `./structure`, so Portal can use it. The strict rule a write must meet is built
|
|
17
|
+
* from zod and lives in `./index` as `accept`.
|
|
18
|
+
*/
|
|
19
|
+
import { FIELD_STRUCTURES, editableAnswers, isRecordValue, matchField, matchShape, keysOf, } from './structure.js';
|
|
20
|
+
/**
|
|
21
|
+
* A leaf's value, or undefined for text of nothing but spaces, which holds nothing: a form's input
|
|
22
|
+
* or a CSV cell left blank says no more than one left out.
|
|
23
|
+
*/
|
|
24
|
+
const filled = (raw) => typeof raw === 'string' && raw.trim() === '' ? undefined : raw;
|
|
25
|
+
/** A value JSON carries as a string, without its padding, which every such leaf's rule trims too. */
|
|
26
|
+
const stringRules = {
|
|
27
|
+
kind: 'string',
|
|
28
|
+
read: (raw) => (typeof raw === 'string' ? filled(raw.trim()) : undefined),
|
|
29
|
+
fromText: (text) => text.trim(),
|
|
30
|
+
};
|
|
31
|
+
export const LEAVES = {
|
|
32
|
+
text: stringRules,
|
|
33
|
+
choice: stringRules,
|
|
34
|
+
};
|
|
35
|
+
/** A raw value read as its leaf's kind of value, typed by the leaf. */
|
|
36
|
+
const readLeaf = (leaf, raw) => LEAVES[leaf.leaf].read(raw);
|
|
37
|
+
/** A raw value read as a value of any kind of leaf, or undefined when no kind reads it. */
|
|
38
|
+
function readAnyLeaf(raw) {
|
|
39
|
+
for (const kind of keysOf(LEAVES)) {
|
|
40
|
+
const value = LEAVES[kind].read(raw);
|
|
41
|
+
if (value !== undefined) {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const isTextList = (raw) => Array.isArray(raw) && raw.every((entry) => typeof entry === 'string');
|
|
48
|
+
/**
|
|
49
|
+
* The diff of a shape whose write replaces what is held, from how it compares two values that both
|
|
50
|
+
* hold something: a value going is the write `null`, and a value arriving is the whole value.
|
|
51
|
+
*/
|
|
52
|
+
const diffing = (change) => (held, next) => {
|
|
53
|
+
if (next === undefined) {
|
|
54
|
+
return held === undefined ? undefined : null;
|
|
55
|
+
}
|
|
56
|
+
return held === undefined ? next : change(held, next);
|
|
57
|
+
};
|
|
58
|
+
/** A record's parts that hold something, or undefined when none does: cleared parts are left out. */
|
|
59
|
+
const someParts = (parts) => {
|
|
60
|
+
const held = {};
|
|
61
|
+
for (const part of keysOf(parts)) {
|
|
62
|
+
const value = filled(parts[part] ?? undefined);
|
|
63
|
+
if (value !== undefined) {
|
|
64
|
+
held[part] = value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return keysOf(held).length > 0 ? held : undefined;
|
|
68
|
+
};
|
|
69
|
+
/** A set's options, or undefined when it has none. */
|
|
70
|
+
const someOptions = (options) => options.length > 0 ? options : undefined;
|
|
71
|
+
const scalar = {
|
|
72
|
+
// Any leaf's value rather than only its own leaf's, so text that holds no value of the leaf is
|
|
73
|
+
// kept for the leaf's rule to refuse; its type decides which kind it must be.
|
|
74
|
+
parse: (_type, raw) => readAnyLeaf(raw),
|
|
75
|
+
same: (a, b) => a === b,
|
|
76
|
+
apply: (_held, write) => write,
|
|
77
|
+
diff: diffing((held, next) => (held === next ? undefined : next)),
|
|
78
|
+
};
|
|
79
|
+
const record = {
|
|
80
|
+
// Only the parts the type declares, each read as its leaf's kind of value.
|
|
81
|
+
parse: (type, raw) => {
|
|
82
|
+
if (!isRecordValue(raw)) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
const parts = FIELD_STRUCTURES[type].parts;
|
|
86
|
+
const value = {};
|
|
87
|
+
for (const part of keysOf(parts)) {
|
|
88
|
+
const held = readLeaf(parts[part], raw[part]);
|
|
89
|
+
if (held !== undefined) {
|
|
90
|
+
value[part] = held;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return keysOf(value).length > 0 ? value : undefined;
|
|
94
|
+
},
|
|
95
|
+
same: (a, b) => record.diff(a, b) === undefined,
|
|
96
|
+
// Merged, as JSON Merge Patch merges objects: a part the write names is set, `null` clears it,
|
|
97
|
+
// and a part it leaves out is left alone, so writes to different parts don't overwrite each
|
|
98
|
+
// other.
|
|
99
|
+
apply: (held, write) => {
|
|
100
|
+
const merged = { ...held };
|
|
101
|
+
for (const part of keysOf(write)) {
|
|
102
|
+
const value = write[part];
|
|
103
|
+
if (value !== undefined) {
|
|
104
|
+
merged[part] = value;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return someParts(merged);
|
|
108
|
+
},
|
|
109
|
+
// Never `null`, even when nothing is left: a merged write names only the parts its writer saw, so
|
|
110
|
+
// a writer clearing the city doesn't also clear a country someone else has just set.
|
|
111
|
+
diff: (held, next) => {
|
|
112
|
+
if (held === undefined) {
|
|
113
|
+
return next;
|
|
114
|
+
}
|
|
115
|
+
const now = next ?? {};
|
|
116
|
+
const write = {};
|
|
117
|
+
for (const part of keysOf({ ...held, ...now })) {
|
|
118
|
+
if (held[part] !== now[part]) {
|
|
119
|
+
write[part] = now[part] ?? null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return keysOf(write).length > 0 ? write : undefined;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
const set = {
|
|
126
|
+
parse: (_type, raw) => (isTextList(raw) ? someOptions(raw) : undefined),
|
|
127
|
+
same: (a, b) => {
|
|
128
|
+
const options = new Set(b);
|
|
129
|
+
return new Set(a).size === options.size && a.every((option) => options.has(option));
|
|
130
|
+
},
|
|
131
|
+
// Replaced, as JSON Merge Patch replaces arrays: a write states the whole answer.
|
|
132
|
+
apply: (_held, write) => write,
|
|
133
|
+
diff: diffing((held, next) => (set.same(held, next) ? undefined : next)),
|
|
134
|
+
};
|
|
135
|
+
/** Each shape's rules. A shape added to the catalog without rules doesn't compile. */
|
|
136
|
+
export const SHAPES = { scalar, record, set };
|
|
137
|
+
/** A field paired with its shape: the one place a field's union is branched on by shape. */
|
|
138
|
+
export function shaped(field) {
|
|
139
|
+
return matchField(field, {
|
|
140
|
+
scalar: (of) => ({ shape: 'scalar', field: of }),
|
|
141
|
+
record: (of) => ({ shape: 'record', field: of }),
|
|
142
|
+
set: (of) => ({ shape: 'set', field: of }),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** A type paired with its shape. */
|
|
146
|
+
export function shapedType(type) {
|
|
147
|
+
return matchShape(type, {
|
|
148
|
+
scalar: (_structure, of) => ({ shape: 'scalar', type: of }),
|
|
149
|
+
record: (_structure, of) => ({ shape: 'record', type: of }),
|
|
150
|
+
set: (_structure, of) => ({ shape: 'set', type: of }),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/** A form shows everything the field holds: true of every shape but a set. */
|
|
154
|
+
const showsWhatItHolds = () => ({
|
|
155
|
+
editable: (_field, held) => held,
|
|
156
|
+
});
|
|
157
|
+
export const FIELD_READING = {
|
|
158
|
+
scalar: { held: (_field, value) => value, ...showsWhatItHolds() },
|
|
159
|
+
// Parsing already kept only the parts the type declares, which are all a client can draw.
|
|
160
|
+
record: { held: (_field, value) => value, ...showsWhatItHolds() },
|
|
161
|
+
set: {
|
|
162
|
+
held: ({ settings }, value) => {
|
|
163
|
+
const rank = (text) => {
|
|
164
|
+
const index = settings.options.indexOf(text);
|
|
165
|
+
return index === -1 ? settings.options.length : index;
|
|
166
|
+
};
|
|
167
|
+
return [...value].sort((a, b) => rank(a) - rank(b) || (a < b ? -1 : a > b ? 1 : 0));
|
|
168
|
+
},
|
|
169
|
+
editable: ({ settings }, held) => someOptions(editableAnswers(settings, held)),
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* What a held raw value reads as for its field: its structure checked, then read as the field
|
|
174
|
+
* gives it meaning. Undefined when the value isn't the field's structure.
|
|
175
|
+
*/
|
|
176
|
+
export function heldValue({ shape, field }, raw) {
|
|
177
|
+
const value = SHAPES[shape].parse(field.type, raw);
|
|
178
|
+
return value === undefined ? undefined : FIELD_READING[shape].held(field, value);
|
|
179
|
+
}
|
|
180
|
+
/** What a form can show of a held raw value, or undefined when it shows nothing. */
|
|
181
|
+
export function editableValue(of, raw) {
|
|
182
|
+
const held = heldValue(of, raw);
|
|
183
|
+
return held === undefined ? undefined : FIELD_READING[of.shape].editable(of.field, held);
|
|
184
|
+
}
|
|
185
|
+
/** A leaf's value as text gives it, or undefined for blank text, which holds nothing. */
|
|
186
|
+
export const leafFromText = (leaf, text) => {
|
|
187
|
+
const value = filled(text);
|
|
188
|
+
return value === undefined ? undefined : LEAVES[leaf.leaf].fromText(text);
|
|
189
|
+
};
|
|
190
|
+
/** A leaf read from its text, where it is text; blank text is kept, for parsing to drop. */
|
|
191
|
+
const leafOf = (leaf, raw) => typeof raw === 'string' ? (leafFromText(leaf, raw) ?? raw) : raw;
|
|
192
|
+
const SHAPE_TEXT = {
|
|
193
|
+
scalar: { fromText: (type, raw) => leafOf(FIELD_STRUCTURES[type].leaf, raw) },
|
|
194
|
+
record: {
|
|
195
|
+
fromText: (type, raw) => {
|
|
196
|
+
if (!isRecordValue(raw)) {
|
|
197
|
+
return raw;
|
|
198
|
+
}
|
|
199
|
+
const leaves = FIELD_STRUCTURES[type].parts;
|
|
200
|
+
return Object.fromEntries(Object.entries(raw).map(([part, held]) => {
|
|
201
|
+
const leaf = Object.prototype.hasOwnProperty.call(leaves, part)
|
|
202
|
+
? leaves[part]
|
|
203
|
+
: undefined;
|
|
204
|
+
return [part, leaf ? leafOf(leaf, held) : held];
|
|
205
|
+
}));
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
set: { fromText: (_type, raw) => raw },
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* What a value given as text holds, such as a form's inputs or a row's cells: each leaf read from
|
|
212
|
+
* its text, then parsed as a value of its type, which drops blank text. Undefined when it holds
|
|
213
|
+
* nothing.
|
|
214
|
+
*/
|
|
215
|
+
export function valueFromText({ shape, type }, raw) {
|
|
216
|
+
return SHAPES[shape].parse(type, SHAPE_TEXT[shape].fromText(type, raw));
|
|
217
|
+
}
|
|
218
|
+
/** How a value of each shape is held by a form's inputs, each leaf as `String` writes it. */
|
|
219
|
+
const VALUE_TEXT = {
|
|
220
|
+
scalar: (value) => String(value),
|
|
221
|
+
record: (value) => Object.fromEntries(keysOf(value).flatMap((part) => {
|
|
222
|
+
const held = value[part];
|
|
223
|
+
return held === undefined ? [] : [[part, String(held)]];
|
|
224
|
+
})),
|
|
225
|
+
set: (value) => value,
|
|
226
|
+
};
|
|
227
|
+
/** A value as a form's inputs hold it, which `valueFromText` reads back as the same value. */
|
|
228
|
+
export function textOfValue(shape, value) {
|
|
229
|
+
return VALUE_TEXT[shape](value);
|
|
230
|
+
}
|
|
231
|
+
/** What a field holds, each leaf as its text, as a field shown but not edited draws it. */
|
|
232
|
+
export function heldTextOf(of, held) {
|
|
233
|
+
const value = heldValue(of, held);
|
|
234
|
+
return value === undefined ? undefined : textOfValue(of.shape, value);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* What a form's inputs start from for a held raw value: what the form can show of it, each leaf as
|
|
238
|
+
* its text, or undefined when it shows nothing.
|
|
239
|
+
*/
|
|
240
|
+
export function formTextOf(of, held) {
|
|
241
|
+
const value = editableValue(of, held);
|
|
242
|
+
return value === undefined ? undefined : textOfValue(of.shape, value);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* What a form's inputs show, read as the field reads a value: each leaf from its text, blank text
|
|
246
|
+
* holding nothing, and only what the form can show. Undefined when they show nothing.
|
|
247
|
+
*/
|
|
248
|
+
export function formShows(of, inputs) {
|
|
249
|
+
const typed = valueFromText({ shape: of.shape, type: of.field.type }, inputs);
|
|
250
|
+
return typed === undefined ? undefined : editableValue(of, typed);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* The write that turns what a field holds into what a form's inputs show: `null` when the inputs
|
|
254
|
+
* show nothing of a replacing shape, and undefined when they show what the field holds. The held
|
|
255
|
+
* value is read as the field reads it first, so a part the form doesn't draw is never written, and
|
|
256
|
+
* an answer the form can't show, such as one to an option the field no longer offers, is cleared
|
|
257
|
+
* by the write.
|
|
258
|
+
*/
|
|
259
|
+
export function formWrite(of, inputs, held) {
|
|
260
|
+
return SHAPES[of.shape].diff(heldValue(of, held), formShows(of, inputs));
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=shapes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../src/shapes.ts"],"names":[],"mappings":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Every type is composed from a few building blocks. A leaf is one value: text of a size,
|
|
5
|
-
* choice from a list. A type is a leaf on its own, a record of named leaves, or a set of options
|
|
6
|
-
*
|
|
4
|
+
* Every type is composed from a few building blocks. A leaf is one value: text of a size, a
|
|
5
|
+
* choice from a list. A type is a leaf on its own, a record of named leaves, or a set of options its
|
|
6
|
+
* field offers. Everything that stores, exports, edits, filters or draws a value is written
|
|
7
7
|
* once per building block, so a type composed from existing blocks needs nothing beyond its entry
|
|
8
8
|
* here.
|
|
9
9
|
*
|
|
@@ -25,9 +25,15 @@ export interface ChoiceLeaf {
|
|
|
25
25
|
readonly leaf: 'choice';
|
|
26
26
|
readonly from: ListSource;
|
|
27
27
|
}
|
|
28
|
-
/** One value
|
|
28
|
+
/** One value. */
|
|
29
29
|
export type Leaf = TextLeaf | ChoiceLeaf;
|
|
30
30
|
export type LeafKind = Leaf['leaf'];
|
|
31
|
+
/** What a value of each kind of leaf is, as JSON carries it. */
|
|
32
|
+
export interface LeafValues {
|
|
33
|
+
text: string;
|
|
34
|
+
choice: string;
|
|
35
|
+
}
|
|
36
|
+
export type LeafValue<L extends Leaf> = LeafValues[L['leaf']];
|
|
31
37
|
export declare const text: <const S extends TextSize>(size: S) => {
|
|
32
38
|
readonly leaf: 'text';
|
|
33
39
|
readonly size: S;
|
|
@@ -137,11 +143,13 @@ export type PartsOf<T extends FieldType> = T extends FieldType ? StructureOf<T>
|
|
|
137
143
|
parts: infer P;
|
|
138
144
|
} ? Extract<keyof P, string> : never : never;
|
|
139
145
|
type ValueOfStructure<S extends FieldStructure> = {
|
|
140
|
-
scalar:
|
|
146
|
+
scalar: S extends {
|
|
147
|
+
leaf: infer L extends Leaf;
|
|
148
|
+
} ? LeafValue<L> : never;
|
|
141
149
|
record: S extends {
|
|
142
150
|
parts: infer P;
|
|
143
151
|
} ? {
|
|
144
|
-
[K in keyof P]?:
|
|
152
|
+
[K in keyof P]?: P[K] extends Leaf ? LeafValue<P[K]> : never;
|
|
145
153
|
} : never;
|
|
146
154
|
set: string[];
|
|
147
155
|
}[S['shape']];
|
|
@@ -152,6 +160,26 @@ type ValueOfStructure<S extends FieldStructure> = {
|
|
|
152
160
|
* always read back what was written.
|
|
153
161
|
*/
|
|
154
162
|
export type ValueOf<T extends FieldType> = T extends FieldType ? ValueOfStructure<StructureOf<T>> : never;
|
|
163
|
+
type WriteOfStructure<S extends FieldStructure> = {
|
|
164
|
+
scalar: ValueOfStructure<S>;
|
|
165
|
+
record: S extends {
|
|
166
|
+
parts: infer P;
|
|
167
|
+
} ? {
|
|
168
|
+
[K in keyof P]?: (P[K] extends Leaf ? LeafValue<P[K]> : never) | null;
|
|
169
|
+
} : never;
|
|
170
|
+
set: ValueOfStructure<S>;
|
|
171
|
+
}[S['shape']];
|
|
172
|
+
/**
|
|
173
|
+
* What a write gives a field of a type that still holds a value afterwards; `null` clears the
|
|
174
|
+
* whole field. As in JSON Merge Patch, a record's write names a part as `null` to clear it and
|
|
175
|
+
* leaves out a part to leave it alone, so a write is not a value: a value never holds `null`.
|
|
176
|
+
*/
|
|
177
|
+
export type WriteOf<T extends FieldType> = T extends FieldType ? WriteOfStructure<StructureOf<T>> : never;
|
|
178
|
+
/**
|
|
179
|
+
* The keys a value has, typed as its type's keys rather than as strings, which is what
|
|
180
|
+
* `Object.keys` gives: a `for...in` over a value of a generic type gives each key as typed.
|
|
181
|
+
*/
|
|
182
|
+
export declare function keysOf<R extends object>(value: R): Extract<keyof R, string>[];
|
|
155
183
|
/**
|
|
156
184
|
* What a field of a set type is set up with: the options it offers, in the order they are shown,
|
|
157
185
|
* and whether a member may pick more than one. An option is named by its text alone, so the same
|
|
@@ -178,6 +206,14 @@ export declare const OPTION_SEPARATOR = "|";
|
|
|
178
206
|
* it was given.
|
|
179
207
|
*/
|
|
180
208
|
export declare function optionText(option: string): string;
|
|
209
|
+
/**
|
|
210
|
+
* What two options are compared by to tell whether they are the same option: their text as
|
|
211
|
+
* `optionText` tidies it, without regard to case. A list offers each option once, so it can't
|
|
212
|
+
* offer both "Podcasts" and "podcasts". Lower-casing, upper-casing and lower-casing again also
|
|
213
|
+
* matches letters that one change of case keeps apart, such as "ß", "ẞ" and "SS", or a final "ς"
|
|
214
|
+
* and "σ", and does so the same way whatever the locale.
|
|
215
|
+
*/
|
|
216
|
+
export declare function optionKey(option: string): string;
|
|
181
217
|
/** The answers among `held` that a set field offers, in the order it offers them. */
|
|
182
218
|
export declare function inOptionOrder(settings: SetSettings, held: readonly unknown[]): string[];
|
|
183
219
|
/**
|
package/build/structure.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structure.d.ts","sourceRoot":"","sources":["../src/structure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,+FAA+F;AAC/F,eAAO,MAAM,UAAU,YAAI,MAAM,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAC5D,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnD,2FAA2F;AAC3F,eAAO,MAAM,YAAY,YAAI,WAAW,CAAU,CAAC;AACnD,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B;AAED,
|
|
1
|
+
{"version":3,"file":"structure.d.ts","sourceRoot":"","sources":["../src/structure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,+FAA+F;AAC/F,eAAO,MAAM,UAAU,YAAI,MAAM,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAC5D,MAAM,MAAM,QAAQ,GAA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,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAW5E;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,aAAa,EAAE,CAAC,IAAI;KACrD,CAAC,IAAI,UAAU,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC;CACpD,CAAC;AAWF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,aAAa,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAcjG;AAYD,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,QAAQ,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,KAAK,CAAC;CAAE,CAAC;AAE3F,2CAA2C;AAC3C,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAOrE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE9E;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,EAAE,GAAG,IAAI,CASxD"}
|
package/build/structure.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* What a field type is made of, with no opinion on what a valid value looks like.
|
|
3
3
|
*
|
|
4
|
-
* Every type is composed from a few building blocks. A leaf is one value: text of a size,
|
|
5
|
-
* choice from a list. A type is a leaf on its own, a record of named leaves, or a set of options
|
|
6
|
-
*
|
|
4
|
+
* Every type is composed from a few building blocks. A leaf is one value: text of a size, a
|
|
5
|
+
* choice from a list. A type is a leaf on its own, a record of named leaves, or a set of options its
|
|
6
|
+
* field offers. Everything that stores, exports, edits, filters or draws a value is written
|
|
7
7
|
* once per building block, so a type composed from existing blocks needs nothing beyond its entry
|
|
8
8
|
* here.
|
|
9
9
|
*
|
|
@@ -46,6 +46,17 @@ export const FIELD_STRUCTURES = {
|
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* The keys a value has, typed as its type's keys rather than as strings, which is what
|
|
51
|
+
* `Object.keys` gives: a `for...in` over a value of a generic type gives each key as typed.
|
|
52
|
+
*/
|
|
53
|
+
export function keysOf(value) {
|
|
54
|
+
const keys = [];
|
|
55
|
+
for (const key in value) {
|
|
56
|
+
keys.push(key);
|
|
57
|
+
}
|
|
58
|
+
return keys;
|
|
59
|
+
}
|
|
49
60
|
/** How many options a set field offers: at least two, or it isn't a choice, and at most a hundred. */
|
|
50
61
|
export const MIN_OPTIONS = 2;
|
|
51
62
|
export const MAX_OPTIONS = 100;
|
|
@@ -65,6 +76,16 @@ export const OPTION_SEPARATOR = '|';
|
|
|
65
76
|
export function optionText(option) {
|
|
66
77
|
return option.trim().normalize('NFC');
|
|
67
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* What two options are compared by to tell whether they are the same option: their text as
|
|
81
|
+
* `optionText` tidies it, without regard to case. A list offers each option once, so it can't
|
|
82
|
+
* offer both "Podcasts" and "podcasts". Lower-casing, upper-casing and lower-casing again also
|
|
83
|
+
* matches letters that one change of case keeps apart, such as "ß", "ẞ" and "SS", or a final "ς"
|
|
84
|
+
* and "σ", and does so the same way whatever the locale.
|
|
85
|
+
*/
|
|
86
|
+
export function optionKey(option) {
|
|
87
|
+
return optionText(option).toLowerCase().toUpperCase().toLowerCase();
|
|
88
|
+
}
|
|
68
89
|
/** The answers among `held` that a set field offers, in the order it offers them. */
|
|
69
90
|
export function inOptionOrder(settings, held) {
|
|
70
91
|
return settings.options.filter((option) => held.includes(option));
|
package/build/structure.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structure.js","sourceRoot":"","sources":["../src/structure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,+FAA+F;AAC/F,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAG5D,2FAA2F;AAC3F,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,WAAW,CAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"structure.js","sourceRoot":"","sources":["../src/structure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,+FAA+F;AAC/F,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAG5D,2FAA2F;AAC3F,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,WAAW,CAAU,CAAC;AAyBnD,MAAM,CAAC,MAAM,IAAI,GAAG,CAA2B,IAAO,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAU,CAAC;AAC7F,MAAM,CAAC,MAAM,MAAM,GAAG,CAA6B,IAAO,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAU,CAAC;AAEnG,oEAAoE;AACpE,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AA6B3C,yFAAyF;AACzF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,CAAU,CAAC;AAGtF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,UAAU,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;IACnD,SAAS,EAAE,EAAE,KAAK,EAAE,Q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;IAC9B,kFAAkF;IAClF,8DAA8D;IAC9D,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzD,CAAC;AAID,2CAA2C;AAC3C,MAAM,UAAU,SAAS,CAAI,IAAU,EAAE,QAAyB;IAChE,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7B,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,IAAe;IACrC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,UAAU,CAAkB,IAAI,EAAE;QACvC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI;QAClB,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;QACzC,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;KAChB,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/metafield-types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Ghost member custom field types: which types exist, what each is made of, and how a value of each is validated",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ghost Foundation",
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
"types": "./build/structure.d.ts",
|
|
25
25
|
"default": "./build/structure.js"
|
|
26
26
|
},
|
|
27
|
+
"./shapes": {
|
|
28
|
+
"types": "./build/shapes.d.ts",
|
|
29
|
+
"default": "./build/shapes.js"
|
|
30
|
+
},
|
|
27
31
|
"./identity": {
|
|
28
32
|
"types": "./build/identity.d.ts",
|
|
29
33
|
"default": "./build/identity.js"
|