@agentshouse/mdmodel 0.1.0-caf6545f57b5d → 0.1.0-cb39915954ec5
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/API.md +33 -9
- package/README.md +15 -13
- package/dist/built-in.d.ts +4 -0
- package/dist/built-in.d.ts.map +1 -0
- package/dist/built-in.js +19 -0
- package/dist/definition.d.ts +2 -2
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +13 -7
- package/dist/document.d.ts +1 -2
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +38 -54
- package/dist/event.js +1 -1
- package/dist/fields.d.ts +1 -1
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +2 -2
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js +3 -2
- package/dist/house-model.d.ts +870 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +472 -0
- package/dist/house-references/crockford.d.ts +4 -0
- package/dist/house-references/crockford.d.ts.map +1 -0
- package/dist/house-references/crockford.js +3 -0
- package/dist/house-references/patterns.d.ts +9 -0
- package/dist/house-references/patterns.d.ts.map +1 -0
- package/dist/house-references/patterns.js +13 -0
- package/dist/index.d.ts +18 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -5
- package/dist/media-type.d.ts +72 -0
- package/dist/media-type.d.ts.map +1 -0
- package/dist/media-type.js +157 -0
- package/dist/moment.d.ts +7 -0
- package/dist/moment.d.ts.map +1 -0
- package/dist/moment.js +18 -0
- package/dist/not-ready.d.ts +2 -0
- package/dist/not-ready.d.ts.map +1 -0
- package/dist/not-ready.js +5 -0
- package/dist/paths.d.ts +5 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +14 -0
- package/dist/query/match.d.ts +1 -1
- package/dist/query/match.d.ts.map +1 -1
- package/dist/query/rows.d.ts +1 -1
- package/dist/query/rows.d.ts.map +1 -1
- package/dist/query/rows.js +1 -1
- package/dist/references.d.ts +2 -2
- package/dist/references.d.ts.map +1 -1
- package/dist/references.js +1 -1
- package/dist/room-types.d.ts +7 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +136 -0
- package/dist/schema.d.ts +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +6 -7
- package/dist/types.d.ts +1 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts +2 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +9 -6
- package/dist/yaml.d.ts +4 -4
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +1 -1
- package/package.json +1 -1
package/API.md
CHANGED
|
@@ -72,7 +72,7 @@ contact: { member_document: true }
|
|
|
72
72
|
The model's `types` expose each MD Type's `name`, `memberDocument`, `shape` (the type as
|
|
73
73
|
written, its rule keywords left out, with every `$defs` shape it reaches), `createRoles` and
|
|
74
74
|
`deleteRoles` when written, its `rules` by field as `changeRoles`, `initialRoles` and `transitions`,
|
|
75
|
-
the facts of its `
|
|
75
|
+
the facts of its whole value, `root`, and of `fields`, its top-level ones: JSON `type`, `format`, `values`,
|
|
76
76
|
`reference` targets, `items`, `properties`, an open map's `patterns` and `additional`, `prose`,
|
|
77
77
|
a string with no `enum`, `const`, `format`, `pattern` or `reference`, its `title`, `markdown` and `json`,
|
|
78
78
|
a value written as one `json` block for no single JSON type, an open object or a union of objects. Facts join `$ref` and `allOf`
|
|
@@ -80,7 +80,7 @@ to their siblings and the variants of `anyOf`, `oneOf`, `then`, `else` and `depe
|
|
|
80
80
|
variant's own keys `conditional`; a path without one `type`, `null` aside, has none. A malformed
|
|
81
81
|
schema is refused whole, naming its `rule`, the keyword or the model's own, and the JSON Pointer
|
|
82
82
|
`location` it concerns, such as `/plan/properties/status/enum`, or `line <n>` outside the YAML
|
|
83
|
-
subset. `pointerFacts(definition, pointer)` reads the facts a
|
|
83
|
+
subset. `pointerFacts(definition, pointer)` reads the facts a pointer into the value reaches, `itemFacts`
|
|
84
84
|
and `memberFacts` take one step and `crossedFacts` reads a list's item facts; `JSON_POINTER` matches the
|
|
85
85
|
JSON Pointer grammar, `''` included, `pointerSegments` and `escapePointer` split and write a pointer,
|
|
86
86
|
`ARRAY_INDEX` matches an index segment, and `ATTACHMENT` is the `reference` that admits any path.
|
|
@@ -96,8 +96,10 @@ another Room, which the caller checks; any other absolute path, or one that leav
|
|
|
96
96
|
Document, `any` included, at an `isDocumentPath` (no `isReservedName` of `RESERVED_NAMES` first) linking
|
|
97
97
|
into a reserved name is `unresolved-link`; a typed `ROOM_DESCRIPTION` is `room-md-type`. `CAPTURE_HOME`, one of `RESERVED_NAMES`, names the Capture home at a Room's root. The context's `typedPaths` bind each `path`, a name's one `*` standing for any nonempty part, to a `type` of `model`: a Document there naming another, or naming any unless `named`, is `unknown-type` at `/type`, one not `named` is checked as it and stays `any`, and one whose free text holds nothing but whitespace is `required-body` if `body`.
|
|
98
98
|
|
|
99
|
+
`HOUSE_ROOM_TYPES` is the `provided` model of every Room, verified: the Inbox's `CHAT_TYPE` card, whose `channel` is one of `INBOX_CHANNEL_KINDS`, and its `CHAT_MESSAGE_TYPE` messages, the two `INBOX_TYPES` and its `nameable` ones, a Wayfinding map and its tickets, and every type of `HOUSE_MODEL`, the House model `HOUSE_MODEL_DECLARATION` declares, from which the `HouseModelType` names and the `HouseDocumentFields<type>` of each type's Document follow. `HOUSE_TYPED_PATHS` binds House's paths to their types: `settings/panel.md`, an App's preferences under `APP_PREFERENCES_HOME` and an Agent function document under `rooms/<handle>/agent-functions/`. Its `room`, `app` and `space` definitions are `ROOM_REFERENCE_PATTERN`, `APP_REFERENCE_PATTERN` and `SPACE_REFERENCE_PATTERN`: a prefix, `ROOM_REFERENCE_PREFIX`, `APP_REFERENCE_PREFIX` or `SPACE_REFERENCE_PREFIX`, then an ordinal, a dot and a check character; `REVISION_REFERENCE_PATTERN` reads a revision, `REVISION_REFERENCE_PREFIX`, its document's ordinal, a dot, the revision's and a check character, each character one `CROCKFORD_CHARACTER` of the lowercase Crockford alphabet `CROCKFORD_ALPHABET`, and `CROCKFORD_LEADING_CHARACTER` any of it but `0`.
|
|
100
|
+
|
|
99
101
|
A typed Document writes its values in its body, as Markdown, and its frontmatter holds only
|
|
100
|
-
`TYPE_FIELD`, `MEMBER_FIELD`, `SITE_FIELD` and `
|
|
102
|
+
`TYPE_FIELD`, `MEMBER_FIELD`, `SITE_FIELD` and `SUBMITTED_FIELD` (`submitted`), which `parse` reads
|
|
101
103
|
into the same value; any other frontmatter key is `malformed-value`. The `#` line is the top-level
|
|
102
104
|
`name`; under it each short value is one line `- **Label**: value` of the value list, a boolean a
|
|
103
105
|
checkbox line `- [x] Label`, a reference a link whose text is no value, a group of short values an
|
|
@@ -117,12 +119,12 @@ everything after a top-level thematic break, which also ends a value under a hea
|
|
|
117
119
|
A typed Document's value satisfies its type's schema, every keyword with its JSON Schema
|
|
118
120
|
meaning, formats asserted and defaults never filled, except that an object schema declaring neither
|
|
119
121
|
`additionalProperties` nor `unevaluatedProperties` is closed: an undeclared key is refused as
|
|
120
|
-
`undeclared-field`. `TYPE_FIELD`, `SITE_FIELD` and `
|
|
122
|
+
`undeclared-field`. `TYPE_FIELD`, `SITE_FIELD` and `SUBMITTED_FIELD` count as declared on every type,
|
|
121
123
|
and the string `MEMBER_FIELD` on the `member_document` type alone, else refused, `any` included;
|
|
122
124
|
`HOUSE_FIELDS` lists the four. A refusal names the keyword, such as `required`, the value's JSON
|
|
123
125
|
Pointer, such as `/shipping/city`, and the `line` the value is written on. A reference, at any depth, reaching a URL, a binary target, another
|
|
124
126
|
Room without `cross_room` or the context's `anyRoom: true`, a Document of a type it does not name, or,
|
|
125
|
-
from an `isDocumentPath`, a reserved name is `unresolved-reference`, and
|
|
127
|
+
from an `isDocumentPath`, a reserved name is `unresolved-reference`, and one reaching no member is `referenced-missing-file`
|
|
126
128
|
naming its `referrers`; `attachment` admits any path, and no body link is a referrer. `validating` is
|
|
127
129
|
`validate` over a `ReadonlyMap` Library, yielding each path read with the references it `resolved`;
|
|
128
130
|
`assess(file, parsed, binary, model?, context?)` reads one member from its `parse` result, naming its
|
|
@@ -163,8 +165,8 @@ Document carried behind a repeated, merged or fenced heading, or change a value,
|
|
|
163
165
|
`overlapping-section` naming that section or value. A frontmatter field change does not reformat
|
|
164
166
|
the rest of the file: an inline value is replaced where it stands, and a value written after the
|
|
165
167
|
key's line, an empty one or a block mapping or list, is written after the key's colon in its place.
|
|
166
|
-
A
|
|
167
|
-
a list without holes or a plain object of them, no cycle, at most 63 deep. `
|
|
168
|
+
A field holds a `DocumentValue`: null, a string, a boolean, a finite number,
|
|
169
|
+
a list without holes or a plain object of them, no cycle, at most 63 deep. `documentValue(value)`
|
|
168
170
|
is that test; `apply` refuses any other value and `parse` a frontmatter past 64 deep as
|
|
169
171
|
`frontmatter-fence`. `equalValue` compares two by value, whatever their key order, as `apply` does.
|
|
170
172
|
`relabel(document, before, after)` is the Document's text with each label `before` wrote replaced by `after`'s, every other byte kept. `relabels(before, after)` is whether a Document of the type `before` defines would be relabelled under `after`: a field's label, its title else its key, differs between the two, or a field is labelled in only one. `labelAt(facts, pointer)` is the label of the value at `pointer` under `facts`.
|
|
@@ -225,7 +227,6 @@ kept, so two types that differ only in their labels compare equal.
|
|
|
225
227
|
context: `ok: false` where it refuses, else its `type`, whether it is `typed`, and each reference's
|
|
226
228
|
`target` and `to`, which `resolves(reference, typeOf, binary)` says reaches a member `validate`
|
|
227
229
|
accepts. It names no other Room's, which `roomReferences(document, definition?)` lists by `kind`.
|
|
228
|
-
`parseFrontmatter(content, file?)` is `parse` without the body: `content`, `type`, `fields`.
|
|
229
230
|
|
|
230
231
|
`references(document, definition)` lists each `reference` value at any depth as `pointer`,
|
|
231
232
|
`value` and `to`; a `{ kind: 'reference', pointer, value, prior }` change rewrites the destination
|
|
@@ -238,7 +239,7 @@ rewrites, in one `apply`, each link destination and reference written `/rooms/<h
|
|
|
238
239
|
not in `kept` to `relative(file, path)`, keeping its `?query` or `#fragment`. A text without
|
|
239
240
|
frontmatter, such as a captured body, is read from its first character: `relativizeBody(body, file, handle)` converts it
|
|
240
241
|
so, refusing a `/rooms/` one naming no Room's file as `unresolved-link`; `bodyLinks(body, file)`
|
|
241
|
-
is its `links` and `bodyRoomLinks(body)` its other Rooms'. `relinkBody(body, file, moves)` writes,
|
|
242
|
+
is its `links` and `bodyRoomLinks(body)` its other Rooms'. A keyed link, `/rooms/<handle>/<path>?key=<key>` as a body link or a reference value, stays as written, which no relativizing or relinking rewrites, out of `roomReferences` and `bodyRoomLinks` and naming no target validation checks; `keyedLink(href)` reads one as its `handle`, `path` and `key`, or `null` for any other href, `bodyKeyedLinks(body)` lists each in a body, and `keyedDestination(path, key)` writes one. `relinkBody(body, file, moves)` writes,
|
|
242
243
|
in the `link` change's form, each destination whose Path keys `moves` as that value relative to
|
|
243
244
|
`file`, or as that value when it is a `/rooms/` path, and one whose `roomPath` does as that value.
|
|
244
245
|
`unlinkBody(body, hrefs)` cuts every link and reference definition whose written destination is
|
|
@@ -336,6 +337,9 @@ repeated heading, an internal link's visible label, or a value the author escape
|
|
|
336
337
|
out of one value written on a line addresses that whole value, and a Span carrying part of one
|
|
337
338
|
internal link's label addresses that whole link, because a cut never falls inside link syntax.
|
|
338
339
|
|
|
340
|
+
`notReadyWaitMs(asked)` is how long a client told a Room's chunk list is not ready waits before it
|
|
341
|
+
asks again: 1, 2, 3, 5, 8, 11 and 15 seconds by `asked`, counted from zero, then 15 seconds.
|
|
342
|
+
|
|
339
343
|
## Queries
|
|
340
344
|
|
|
341
345
|
`planOf(query, rooms)` checks one query against the MD Types of the Rooms `rooms` lists, each `{
|
|
@@ -404,3 +408,23 @@ escaped pointers, `valuedChange(definition, pointer)` holds of a field read as o
|
|
|
404
408
|
prose, a list or reached through one, the only field whose change is tested by its values, and
|
|
405
409
|
`memberPointers(definition, memberType)` the `/members/<name>` paths of the fields referring to
|
|
406
410
|
`memberType`, alone or in a list.
|
|
411
|
+
|
|
412
|
+
## Media types
|
|
413
|
+
|
|
414
|
+
`MEDIA_TYPES` names every media type House writes by a short key, `UTF8_TEXT` its text types with
|
|
415
|
+
a UTF-8 charset, and `withCharset(type, charset)` writes any other charset. `mediaTypeEssence(value)`
|
|
416
|
+
reads a declared type without its parameters, in lower case; `isImageType`, `isVideoType` and
|
|
417
|
+
`isAudioType` test its top-level type, `declaresUtf8(value)` holds where its charset is UTF-8 or
|
|
418
|
+
absent, and `acceptsType(accept, type)` where an `Accept` list names the type. One table pairs each
|
|
419
|
+
type with its file extensions: `FILE_MEDIA_TYPES` maps an extension to its type,
|
|
420
|
+
`servedMediaType(path)` is the type a path is served under, a text type with a UTF-8 charset and an
|
|
421
|
+
unknown extension `application/octet-stream`, and `fileExtension(type)` is the extension a type is
|
|
422
|
+
named by. `SCRIPT_MEDIA_TYPES` lists the types a script is declared under, `dataUrl(type, base64)`
|
|
423
|
+
and `dataUrlPattern(types)` write and match a base64 data URL, `formDataType(boundary)` is a
|
|
424
|
+
multipart form's type and `gitMediaType(service, part)` a Git transport's.
|
|
425
|
+
|
|
426
|
+
## Moments
|
|
427
|
+
|
|
428
|
+
`shownMoment(at, reader)` shows a `Date` to a person as a calendar does: its day and minute in the
|
|
429
|
+
`MomentReader`'s `language` and IANA time `zone`, naming no zone, or in UTC, named, where `zone` is
|
|
430
|
+
`null`. `shownDay(at, reader)` shows its day alone, in UTC where `zone` is `null`.
|
package/README.md
CHANGED
|
@@ -35,19 +35,21 @@ if (checked.verdict === 'accept') {
|
|
|
35
35
|
|
|
36
36
|
## API
|
|
37
37
|
|
|
38
|
-
| Export
|
|
39
|
-
|
|
|
40
|
-
| `verify`
|
|
41
|
-
| `validate`
|
|
42
|
-
| `parse`, `serialize`
|
|
43
|
-
| `apply`
|
|
44
|
-
| `links`, `target`, `retarget`
|
|
45
|
-
| `escapePointer`
|
|
46
|
-
| `project`, `divide`
|
|
47
|
-
| `facts`, `candidateOf`
|
|
48
|
-
| `planOf`, `matches`, `sql`
|
|
49
|
-
| `VERSION`
|
|
50
|
-
| `MEMBER_FIELD`, `SITE_FIELD`, `
|
|
38
|
+
| Export | Purpose |
|
|
39
|
+
| ----------------------------------------------- | ------------------------------------------------------------------ |
|
|
40
|
+
| `verify` | Verify one schema text into a model of MD Types |
|
|
41
|
+
| `validate` | Validate a text Library; returns acceptance or one refusal |
|
|
42
|
+
| `parse`, `serialize` | Read and write one Document |
|
|
43
|
+
| `apply` | Apply field, section, preamble, link and reference changes at once |
|
|
44
|
+
| `links`, `target`, `retarget` | Inventory and rewrite link destinations |
|
|
45
|
+
| `escapePointer` | Write one key as a JSON Pointer token |
|
|
46
|
+
| `project`, `divide` | Embedding projection input and its division into Spans |
|
|
47
|
+
| `facts`, `candidateOf` | A Document as one change saw it, matched as one query candidate |
|
|
48
|
+
| `planOf`, `matches`, `sql` | Check a query, answer it over one Document or compile it to SQL |
|
|
49
|
+
| `VERSION` | The MD model version |
|
|
50
|
+
| `MEMBER_FIELD`, `SITE_FIELD`, `SUBMITTED_FIELD` | The frontmatter keys validation counts as declared beyond a type's |
|
|
51
|
+
| `MEDIA_TYPES`, `servedMediaType` | The media types House writes and the one table of file extensions |
|
|
52
|
+
| `shownMoment`, `shownDay` | A moment shown to a person in their language and time zone |
|
|
51
53
|
|
|
52
54
|
The full reference is in [`API.md`](API.md). The conformance corpus and its
|
|
53
55
|
verdict format and rule ids are described in [`fixtures/README.md`](fixtures/README.md).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"built-in.d.ts","sourceRoot":"","sources":["../src/built-in.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAiBhD,eAAO,MAAM,WAAW,eAA8C,CAAC;AAEvE,eAAO,MAAM,gBAAgB,EAAE,aAG7B,CAAC"}
|
package/dist/built-in.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HOUSE_MODEL_DECLARATION } from './house-model.js';
|
|
2
|
+
import { INBOX_TYPES, ROOM_TYPES_TEXT } from './room-types.js';
|
|
3
|
+
import { verify } from './validate.js';
|
|
4
|
+
function modelText(model) {
|
|
5
|
+
return `${Object.entries(model)
|
|
6
|
+
.map(([name, declared]) => `${name}: ${JSON.stringify(declared)}`)
|
|
7
|
+
.join('\n')}\n`;
|
|
8
|
+
}
|
|
9
|
+
function builtIn(text, provided) {
|
|
10
|
+
const checked = verify(text, provided);
|
|
11
|
+
if (checked.verdict === 'accept')
|
|
12
|
+
return checked.model;
|
|
13
|
+
throw new Error(`House's built-in types refuse: ${checked.rule} ${checked.location ?? ''}`.trim());
|
|
14
|
+
}
|
|
15
|
+
export const HOUSE_MODEL = builtIn(modelText(HOUSE_MODEL_DECLARATION));
|
|
16
|
+
export const HOUSE_ROOM_TYPES = Object.freeze({
|
|
17
|
+
...builtIn(ROOM_TYPES_TEXT, HOUSE_MODEL),
|
|
18
|
+
nameable: INBOX_TYPES,
|
|
19
|
+
});
|
package/dist/definition.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type ValueFacts = {
|
|
|
14
14
|
readonly prefix?: readonly ValueFacts[];
|
|
15
15
|
readonly items?: ValueFacts;
|
|
16
16
|
readonly properties?: Readonly<Record<string, ValueFacts>>;
|
|
17
|
+
readonly required?: readonly string[];
|
|
17
18
|
readonly patterns?: readonly PatternFacts[];
|
|
18
19
|
readonly additional?: ValueFacts;
|
|
19
20
|
};
|
|
@@ -39,7 +40,7 @@ export type FieldRules = {
|
|
|
39
40
|
export type Definition = {
|
|
40
41
|
readonly name: string;
|
|
41
42
|
readonly memberDocument: boolean;
|
|
42
|
-
readonly
|
|
43
|
+
readonly root: ValueFacts;
|
|
43
44
|
readonly fields: Readonly<Record<string, ValueFacts>>;
|
|
44
45
|
readonly rules: Readonly<Record<string, FieldRules>>;
|
|
45
46
|
readonly createRoles?: readonly string[];
|
|
@@ -58,7 +59,6 @@ export declare const JSON_TYPES: readonly JsonType[];
|
|
|
58
59
|
export declare const BUILT_IN_TYPE = "any";
|
|
59
60
|
export declare const ATTACHMENT = "attachment";
|
|
60
61
|
export declare const OPENING: readonly string[];
|
|
61
|
-
export declare const LONG_TEXT = "text/markdown";
|
|
62
62
|
export declare const ARRAY_INDEX: RegExp;
|
|
63
63
|
export declare const JSON_POINTER: RegExp;
|
|
64
64
|
export declare function refuse(rule: string, location: string): Failure;
|
package/dist/definition.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjG,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IACrC,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IACxC,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAC5B,QAA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,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,EAAE,CAK5D;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAItF;AAqBD,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAc9F;AAmED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAY3D;AAgND,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,aAAwB,EAClC,OAAO,UAAO,GACb,aAAa,GAAG,OAAO,CA0CzB"}
|
package/dist/definition.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { MEMBER_FIELD,
|
|
1
|
+
import { MEMBER_FIELD, SITE_FIELD, SUBMITTED_FIELD, TYPE_FIELD } from './fields.js';
|
|
2
|
+
import { MEDIA_TYPES } from './media-type.js';
|
|
2
3
|
import { linearPattern } from './pattern.js';
|
|
3
4
|
import { equalValue, isRecord, jsValue, parseYamlMapping, YamlError } from './yaml.js';
|
|
4
5
|
export const JSON_TYPES = [
|
|
@@ -29,7 +30,6 @@ const PROVIDED_KEYWORDS = ['create_roles', 'delete_roles'];
|
|
|
29
30
|
const NO_TYPES = Object.freeze({ types: Object.freeze({}) });
|
|
30
31
|
const DEFS_REFERENCE = '#/$defs/';
|
|
31
32
|
const UNBOUNDED_FORMAT = 'url';
|
|
32
|
-
export const LONG_TEXT = 'text/markdown';
|
|
33
33
|
const UNIONS = ['anyOf', 'oneOf'];
|
|
34
34
|
const UNRESOLVED = /[\u0000-\u001f\u007f%[\]\\^{|}]|\s$/u;
|
|
35
35
|
export const ARRAY_INDEX = /^(?:0|[1-9][0-9]*)$/u;
|
|
@@ -37,7 +37,7 @@ export const JSON_POINTER = /^(?:\/(?:[^~/]|~[01])*)*$/u;
|
|
|
37
37
|
const HOUSE_KEYS = {
|
|
38
38
|
[TYPE_FIELD]: { prose: false },
|
|
39
39
|
[SITE_FIELD]: { prose: false },
|
|
40
|
-
[
|
|
40
|
+
[SUBMITTED_FIELD]: { prose: false },
|
|
41
41
|
};
|
|
42
42
|
export function refuse(rule, location) {
|
|
43
43
|
return { rule, location };
|
|
@@ -314,6 +314,7 @@ function joined(left, right) {
|
|
|
314
314
|
return shared === undefined ? [] : [{ pattern, facts: shared }];
|
|
315
315
|
});
|
|
316
316
|
const additional = both(left.additional, right.additional);
|
|
317
|
+
const required = (left.required ?? []).filter((name) => right.required?.includes(name) === true);
|
|
317
318
|
const title = left.title ?? right.title;
|
|
318
319
|
return {
|
|
319
320
|
...(type === undefined ? {} : { type }),
|
|
@@ -328,6 +329,7 @@ function joined(left, right) {
|
|
|
328
329
|
...(prefix === undefined ? {} : { prefix }),
|
|
329
330
|
...(items === undefined ? {} : { items }),
|
|
330
331
|
...(Object.keys(properties).length === 0 ? {} : { properties }),
|
|
332
|
+
...(required.length === 0 ? {} : { required }),
|
|
331
333
|
...(patterns.length === 0 ? {} : { patterns }),
|
|
332
334
|
...(additional === undefined ? {} : { additional }),
|
|
333
335
|
};
|
|
@@ -491,6 +493,9 @@ function factsOf(nodes, defs, ancestry) {
|
|
|
491
493
|
: Array.from({ length: Math.max(...tuples.map((tuple) => tuple.length)) }, (_, index) => factsOf(tuples.flatMap((tuple) => (index < tuple.length ? [tuple[index]] : [])), defs, reached))));
|
|
492
494
|
const mapped = type === 'object' || type === undefined;
|
|
493
495
|
const properties = mapped ? propertiesOf(held, variants, defs, reached) : undefined;
|
|
496
|
+
const required = mapped
|
|
497
|
+
? [...new Set(held.flatMap((node) => (Array.isArray(node.required) ? node.required : [])))]
|
|
498
|
+
: [];
|
|
494
499
|
const patterns = mapped
|
|
495
500
|
? held.flatMap((node) => Object.entries(isRecord(node.patternProperties) ? node.patternProperties : {}).map(([pattern, schema]) => ({ pattern, facts: factsOf([schema], defs, reached) })))
|
|
496
501
|
: [];
|
|
@@ -499,7 +504,7 @@ function factsOf(nodes, defs, ancestry) {
|
|
|
499
504
|
: [];
|
|
500
505
|
const additional = opened.length === 0 ? undefined : factsOf(opened, defs, reached);
|
|
501
506
|
const title = firstOf(nodes.filter(isRecord), (node) => typeof node.title === 'string' ? node.title : undefined);
|
|
502
|
-
const markdown = held.some((node) => node.contentMediaType ===
|
|
507
|
+
const markdown = held.some((node) => node.contentMediaType === MEDIA_TYPES.markdown);
|
|
503
508
|
return {
|
|
504
509
|
...(type === undefined ? {} : { type }),
|
|
505
510
|
...(format === undefined ? {} : { format }),
|
|
@@ -513,6 +518,7 @@ function factsOf(nodes, defs, ancestry) {
|
|
|
513
518
|
...(prefix === undefined ? {} : { prefix }),
|
|
514
519
|
...(items === undefined ? {} : { items }),
|
|
515
520
|
...(properties === undefined ? {} : { properties }),
|
|
521
|
+
...(required.length === 0 ? {} : { required }),
|
|
516
522
|
...(patterns.length === 0 ? {} : { patterns }),
|
|
517
523
|
...(additional === undefined ? {} : { additional }),
|
|
518
524
|
};
|
|
@@ -539,7 +545,7 @@ export function fieldFacts(definition, key) {
|
|
|
539
545
|
return definition.fields[key];
|
|
540
546
|
if (Object.hasOwn(HOUSE_KEYS, key))
|
|
541
547
|
return undefined;
|
|
542
|
-
return memberFacts(definition.
|
|
548
|
+
return memberFacts(definition.root, key);
|
|
543
549
|
}
|
|
544
550
|
function stepped({ facts, through, conditional }, token) {
|
|
545
551
|
if (facts.type === 'array' && ARRAY_INDEX.test(token)) {
|
|
@@ -644,7 +650,7 @@ function untitledFacts(facts) {
|
|
|
644
650
|
export function untitled(definition) {
|
|
645
651
|
return {
|
|
646
652
|
...definition,
|
|
647
|
-
|
|
653
|
+
root: untitledFacts(definition.root),
|
|
648
654
|
fields: Object.fromEntries(Object.entries(definition.fields).map(([key, held]) => [key, untitledFacts(held)])),
|
|
649
655
|
shape: {
|
|
650
656
|
schema: untitledSchema(definition.shape.schema),
|
|
@@ -815,7 +821,7 @@ function readType(name, value, context) {
|
|
|
815
821
|
return {
|
|
816
822
|
name,
|
|
817
823
|
memberDocument,
|
|
818
|
-
|
|
824
|
+
root: { ...root, properties: { ...HOUSE_KEYS, ...fields } },
|
|
819
825
|
fields,
|
|
820
826
|
rules,
|
|
821
827
|
...(createRoles === undefined ? {} : { createRoles }),
|
package/dist/document.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { type Body, type Naming } from './body.js';
|
|
2
2
|
import { type Definition } from './definition.js';
|
|
3
3
|
import { type HrefOccurrence, type Reading } from './markdown.js';
|
|
4
|
-
import type { ApplyResult, BodyResult,
|
|
4
|
+
import type { ApplyResult, BodyResult, Change, DefinitionOf, Document, Link, ParseResult, Refusal, Span, UnlinkedBody } from './types.js';
|
|
5
5
|
export declare function readingOf(document: Document): Reading;
|
|
6
6
|
export declare function bodyOf(document: Document): Body | null;
|
|
7
7
|
export declare function linkDestinations(document: Document): readonly HrefOccurrence[];
|
|
8
8
|
export declare function textSpans(document: Document): readonly Span[];
|
|
9
|
-
export declare function parseFrontmatter(content: string, file?: string): FrontmatterResult;
|
|
10
9
|
export declare function parse(content: string, file?: string, definition?: Definition | DefinitionOf): ParseResult;
|
|
11
10
|
export declare function create(type: string | undefined, definition?: Definition): Document;
|
|
12
11
|
export declare function relativize(document: Document, file: string, handle: string, definition?: Definition, kept?: ReadonlySet<string>): ApplyResult;
|
package/dist/document.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,IAAI,EACT,KAAK,MAAM,EAGZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAKL,KAAK,UAAU,EAEhB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,OAAO,EAEb,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts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AAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC,UAAU,CAmBZ;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,YAAY,CAqBjF;AAeD,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,IAAI,EAAE,CAEvE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,IAAI,EAAE,CAErE;AAgCD,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,IAAI,GAAG,IAAI,GAAG,OAAO,CAMvB;AA6mBD,wBAAgB,KAAK,CACnB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,UAAU,CAAC,EAAE,UAAU,EACvB,MAAM,CAAC,EAAE,MAAM,GACd,WAAW,CA2Gb;AAED,wBAAgB,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAYzF;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAEvE;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAEpD"}
|
package/dist/document.js
CHANGED
|
@@ -3,10 +3,10 @@ import { ARRAY_INDEX, escapePointer, memberFacts, pointerSegments, } from './def
|
|
|
3
3
|
import { pointed } from './event.js';
|
|
4
4
|
import { HOUSE_FIELDS, TYPE_FIELD } from './fields.js';
|
|
5
5
|
import { destinations, hrefOccurrences, lineBreaks, lineNumber, linkable, read, sectionSpans, sectionsRecord, } from './markdown.js';
|
|
6
|
-
import { destinationPath, destinationText, relative, retarget, roomPath, roomTarget, SHELL_ROOMS, shellTarget, target, } from './paths.js';
|
|
6
|
+
import { destinationPath, destinationText, keyedLink, relative, retarget, roomPath, roomTarget, SHELL_ROOMS, shellTarget, target, } from './paths.js';
|
|
7
7
|
import { references } from './references.js';
|
|
8
8
|
import { refusal } from './refuse.js';
|
|
9
|
-
import { bodyStartAfterYaml, bodyStartOf, equalValue, extractFrontmatter,
|
|
9
|
+
import { bodyStartAfterYaml, bodyStartOf, documentValue, equalValue, extractFrontmatter, isRecord, jsValue, lineEnding, mapEntry, parseYamlMapping, serializeJs, serializeKey, YamlError, } from './yaml.js';
|
|
10
10
|
const HELD = Symbol('held');
|
|
11
11
|
function heldOf(document) {
|
|
12
12
|
return document[HELD];
|
|
@@ -27,7 +27,7 @@ export function readingOf(document) {
|
|
|
27
27
|
function heldBody(content, held) {
|
|
28
28
|
if (held.body !== undefined)
|
|
29
29
|
return held.body;
|
|
30
|
-
const read = readBody(content, held.internal.bodyStart, heldReading(content, held), held.definition.
|
|
30
|
+
const read = readBody(content, held.internal.bodyStart, heldReading(content, held), held.definition.root);
|
|
31
31
|
if (!read.ok)
|
|
32
32
|
throw new Error(`a document the MD model wrote breaks ${read.refusal.rule}`);
|
|
33
33
|
held.body = read.body;
|
|
@@ -128,13 +128,13 @@ function declaredType(fields) {
|
|
|
128
128
|
function opened(content, file) {
|
|
129
129
|
const fence = extractFrontmatter(content);
|
|
130
130
|
if (fence.kind === 'none')
|
|
131
|
-
return { ok: true,
|
|
131
|
+
return { ok: true, yaml: null, fields: {}, yamlEnd: 0 };
|
|
132
132
|
if (fence.kind === 'unclosed')
|
|
133
133
|
return { ok: false, refusal: refuse(file, 'frontmatter-fence') };
|
|
134
134
|
try {
|
|
135
|
-
const
|
|
136
|
-
const fields = jsValue(
|
|
137
|
-
return { ok: true,
|
|
135
|
+
const yaml = parseYamlMapping(content, fence.yamlStart, fence.yamlEnd);
|
|
136
|
+
const fields = jsValue(yaml);
|
|
137
|
+
return { ok: true, yaml, fields: fields, yamlEnd: fence.yamlEnd };
|
|
138
138
|
}
|
|
139
139
|
catch (error) {
|
|
140
140
|
if (error instanceof YamlError)
|
|
@@ -145,19 +145,6 @@ function opened(content, file) {
|
|
|
145
145
|
throw error;
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
export function parseFrontmatter(content, file = '') {
|
|
149
|
-
const opening = opened(content, file);
|
|
150
|
-
if (!opening.ok)
|
|
151
|
-
return opening;
|
|
152
|
-
return {
|
|
153
|
-
ok: true,
|
|
154
|
-
frontmatter: Object.freeze({
|
|
155
|
-
content,
|
|
156
|
-
type: declaredType(opening.fields),
|
|
157
|
-
fields: Object.freeze(opening.fields),
|
|
158
|
-
}),
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
148
|
function definitionFor(definition, type) {
|
|
162
149
|
return typeof definition === 'function' ? definition(type) : definition;
|
|
163
150
|
}
|
|
@@ -165,16 +152,16 @@ export function parse(content, file = '', definition) {
|
|
|
165
152
|
const opening = opened(content, file);
|
|
166
153
|
if (!opening.ok)
|
|
167
154
|
return opening;
|
|
168
|
-
const bodyStart = opening.
|
|
155
|
+
const bodyStart = opening.yaml === null ? 0 : bodyStartAfterYaml(content, opening.yamlEnd);
|
|
169
156
|
const type = declaredType(opening.fields);
|
|
170
|
-
const internal = {
|
|
157
|
+
const internal = { yaml: opening.yaml, yamlEnd: opening.yamlEnd, bodyStart };
|
|
171
158
|
const typed = definitionFor(definition, type);
|
|
172
159
|
if (typed === undefined)
|
|
173
160
|
return {
|
|
174
161
|
ok: true,
|
|
175
162
|
document: freezeDocument(content, type, opening.fields, internal, undefined, null),
|
|
176
163
|
};
|
|
177
|
-
for (const entry of opening.
|
|
164
|
+
for (const entry of opening.yaml?.entries ?? []) {
|
|
178
165
|
if (HOUSE_FIELDS.includes(entry.key))
|
|
179
166
|
continue;
|
|
180
167
|
return {
|
|
@@ -183,7 +170,7 @@ export function parse(content, file = '', definition) {
|
|
|
183
170
|
};
|
|
184
171
|
}
|
|
185
172
|
const reading = bodyReading(content, bodyStart);
|
|
186
|
-
const read = readBody(content, bodyStart, reading, typed.
|
|
173
|
+
const read = readBody(content, bodyStart, reading, typed.root);
|
|
187
174
|
if (!read.ok)
|
|
188
175
|
return {
|
|
189
176
|
ok: false,
|
|
@@ -203,7 +190,7 @@ function shellRelinked(body, file, handle) {
|
|
|
203
190
|
const occurrences = hrefOccurrences(body);
|
|
204
191
|
const written = new Map();
|
|
205
192
|
for (const href of new Set(occurrences.map((occurrence) => occurrence.href))) {
|
|
206
|
-
const path = shellTarget(href, handle);
|
|
193
|
+
const path = keyedLink(href) === null ? shellTarget(href, handle) : null;
|
|
207
194
|
if (path === null)
|
|
208
195
|
continue;
|
|
209
196
|
const to = retarget(href, relative(file, path));
|
|
@@ -222,8 +209,8 @@ function shellRelinked(body, file, handle) {
|
|
|
222
209
|
}
|
|
223
210
|
return rewritten + body.slice(cursor);
|
|
224
211
|
}
|
|
225
|
-
function nodeAt(
|
|
226
|
-
let node =
|
|
212
|
+
function nodeAt(yaml, pointer, entryOf = mapEntry) {
|
|
213
|
+
let node = yaml;
|
|
227
214
|
for (const key of pointerSegments(pointer)) {
|
|
228
215
|
if (node?.kind === 'map')
|
|
229
216
|
node = entryOf(node, key)?.value;
|
|
@@ -243,7 +230,7 @@ function scalarText(source, value) {
|
|
|
243
230
|
}
|
|
244
231
|
export function relativize(document, file, handle, definition, kept = new Set()) {
|
|
245
232
|
const relativized = (href) => {
|
|
246
|
-
const path = shellTarget(href, handle);
|
|
233
|
+
const path = keyedLink(href) === null ? shellTarget(href, handle) : null;
|
|
247
234
|
return path === null || kept.has(`${SHELL_ROOMS}${handle}/${path}`) ? null : path;
|
|
248
235
|
};
|
|
249
236
|
const changes = [];
|
|
@@ -279,7 +266,7 @@ export function relinkBody(body, file, moves) {
|
|
|
279
266
|
let rewritten = '';
|
|
280
267
|
let cursor = 0;
|
|
281
268
|
for (const match of hrefOccurrences(body)) {
|
|
282
|
-
const from = target(file, match.href) ?? roomPath(match.href);
|
|
269
|
+
const from = target(file, match.href) ?? (keyedLink(match.href) === null ? roomPath(match.href) : null);
|
|
283
270
|
const to = from === null ? undefined : moves.get(from);
|
|
284
271
|
if (to === undefined)
|
|
285
272
|
continue;
|
|
@@ -344,9 +331,9 @@ function internalOf(document) {
|
|
|
344
331
|
if (!opening.ok)
|
|
345
332
|
return opening.refusal;
|
|
346
333
|
return {
|
|
347
|
-
|
|
334
|
+
yaml: opening.yaml,
|
|
348
335
|
yamlEnd: opening.yamlEnd,
|
|
349
|
-
bodyStart: opening.
|
|
336
|
+
bodyStart: opening.yaml === null ? 0 : bodyStartAfterYaml(document.content, opening.yamlEnd),
|
|
350
337
|
};
|
|
351
338
|
}
|
|
352
339
|
export function bodyWith(document, definition) {
|
|
@@ -393,14 +380,14 @@ function planner(document, internal, body) {
|
|
|
393
380
|
return index.get(key);
|
|
394
381
|
};
|
|
395
382
|
const field = (name, value, prior, at) => {
|
|
396
|
-
const
|
|
397
|
-
if (
|
|
383
|
+
const yaml = internal.yaml;
|
|
384
|
+
if (yaml === null)
|
|
398
385
|
return refuse('', 'frontmatter-fence', name);
|
|
399
386
|
if (!equalValue(ownField(document, name), prior))
|
|
400
387
|
return 'stale';
|
|
401
|
-
if (!
|
|
388
|
+
if (!documentValue(value))
|
|
402
389
|
return refuse('', 'frontmatter-fence', name);
|
|
403
|
-
const existing = entryOf(
|
|
390
|
+
const existing = entryOf(yaml, name);
|
|
404
391
|
if (existing !== undefined) {
|
|
405
392
|
const held = existing.value;
|
|
406
393
|
const inline = held.start > existing.after && !/[\r\n]/.test(content.slice(existing.after, held.start));
|
|
@@ -410,13 +397,13 @@ function planner(document, internal, body) {
|
|
|
410
397
|
}
|
|
411
398
|
const entry = `${serializeKey(name)}: ${serializeJs(value)}`;
|
|
412
399
|
added += 1;
|
|
413
|
-
if (content[
|
|
414
|
-
const separator =
|
|
415
|
-
return [{ start:
|
|
400
|
+
if (content[yaml.start] === '{') {
|
|
401
|
+
const separator = yaml.entries.length === 0 && added === 1 ? '' : ', ';
|
|
402
|
+
return [{ start: yaml.end - 1, end: yaml.end - 1, text: `${separator}${entry}`, at }];
|
|
416
403
|
}
|
|
417
|
-
const lineStartAt = content.lastIndexOf('\n',
|
|
404
|
+
const lineStartAt = content.lastIndexOf('\n', yaml.start - 1) + 1;
|
|
418
405
|
ending ??= lineEnding(content);
|
|
419
|
-
const line = `${content.slice(lineStartAt,
|
|
406
|
+
const line = `${content.slice(lineStartAt, yaml.start)}${entry}${ending}`;
|
|
420
407
|
return [{ start: internal.yamlEnd, end: internal.yamlEnd, text: line, at, entry: true }];
|
|
421
408
|
};
|
|
422
409
|
const section = (name, value, prior, at) => {
|
|
@@ -468,7 +455,7 @@ function planner(document, internal, body) {
|
|
|
468
455
|
return refuse('', 'unwritable-link', value);
|
|
469
456
|
return [{ start: destination.start, end: destination.end, text, at }];
|
|
470
457
|
}
|
|
471
|
-
const node = internal.
|
|
458
|
+
const node = internal.yaml === null ? undefined : nodeAt(internal.yaml, pointer, entryOf);
|
|
472
459
|
if (node?.kind !== 'scalar' || node.value !== prior)
|
|
473
460
|
return 'stale';
|
|
474
461
|
return [
|
|
@@ -550,7 +537,7 @@ function skipBlank(content, at) {
|
|
|
550
537
|
}
|
|
551
538
|
function bodyPlan(content, internal, body, definition, fields, text, nameOf) {
|
|
552
539
|
const e = lineEnding(content);
|
|
553
|
-
const root = definition.
|
|
540
|
+
const root = definition.root;
|
|
554
541
|
const order = bodyOrder(root);
|
|
555
542
|
const scale = order.length + 2;
|
|
556
543
|
const rank = (key) => {
|
|
@@ -840,7 +827,7 @@ function opening(change) {
|
|
|
840
827
|
function namesField(name, definition) {
|
|
841
828
|
if (definition === undefined)
|
|
842
829
|
return false;
|
|
843
|
-
const root = definition.
|
|
830
|
+
const root = definition.root;
|
|
844
831
|
return bodyOrder(root).some((key) => labelOf(key, root.properties?.[key]) === name.trim());
|
|
845
832
|
}
|
|
846
833
|
function withSections(document, changes, definition, nameOf) {
|
|
@@ -907,16 +894,16 @@ function written(content, before, fields, changes, definition) {
|
|
|
907
894
|
if (value === undefined)
|
|
908
895
|
delete values[key];
|
|
909
896
|
else
|
|
910
|
-
values[key] = writtenValue(value, memberFacts(definition.
|
|
897
|
+
values[key] = writtenValue(value, memberFacts(definition.root, key));
|
|
911
898
|
for (const change of changes)
|
|
912
899
|
if (change.kind === 'reference' && before.links[change.pointer] !== undefined) {
|
|
913
900
|
const [key, ...rest] = pointerSegments(change.pointer);
|
|
914
901
|
values[key] = repointed(values[key], rest, change.value);
|
|
915
902
|
}
|
|
916
903
|
return freezeDocument(content, declaredType(opening.fields), { ...opening.fields, ...values }, {
|
|
917
|
-
|
|
904
|
+
yaml: opening.yaml,
|
|
918
905
|
yamlEnd: opening.yamlEnd,
|
|
919
|
-
bodyStart: opening.
|
|
906
|
+
bodyStart: opening.yaml === null ? 0 : bodyStartAfterYaml(content, opening.yamlEnd),
|
|
920
907
|
}, definition);
|
|
921
908
|
}
|
|
922
909
|
function settled(before, after, changes, root) {
|
|
@@ -1026,7 +1013,7 @@ export function apply(document, changes, definition, nameOf) {
|
|
|
1026
1013
|
const { content, shifts } = spliced(source, edits);
|
|
1027
1014
|
if (content === source)
|
|
1028
1015
|
return { outcome: 'applied', document };
|
|
1029
|
-
if (body !== null && changes.every((change) => fromValues(change, definition.
|
|
1016
|
+
if (body !== null && changes.every((change) => fromValues(change, definition.root)))
|
|
1030
1017
|
return {
|
|
1031
1018
|
outcome: 'applied',
|
|
1032
1019
|
document: written(content, body, fields, changes, definition),
|
|
@@ -1034,9 +1021,7 @@ export function apply(document, changes, definition, nameOf) {
|
|
|
1034
1021
|
const parsed = parse(content, '', definition);
|
|
1035
1022
|
if (!parsed.ok)
|
|
1036
1023
|
return { outcome: 'refuse', refusal: parsed.refusal };
|
|
1037
|
-
const unsettled = body === null
|
|
1038
|
-
? undefined
|
|
1039
|
-
: settled(document, parsed.document, changes, definition.frontmatter);
|
|
1024
|
+
const unsettled = body === null ? undefined : settled(document, parsed.document, changes, definition.root);
|
|
1040
1025
|
if (unsettled !== undefined)
|
|
1041
1026
|
return { outcome: 'refuse', refusal: unsettled };
|
|
1042
1027
|
const replaced = edits.filter((edit) => {
|
|
@@ -1060,8 +1045,8 @@ export function relabel(document, before, after) {
|
|
|
1060
1045
|
let content = '';
|
|
1061
1046
|
let cursor = 0;
|
|
1062
1047
|
for (const label of [...body.labels].sort((left, right) => left.start - right.start)) {
|
|
1063
|
-
const next = labelAt(after.
|
|
1064
|
-
if (next === undefined || next === labelAt(before.
|
|
1048
|
+
const next = labelAt(after.root, label.path);
|
|
1049
|
+
if (next === undefined || next === labelAt(before.root, label.path))
|
|
1065
1050
|
continue;
|
|
1066
1051
|
content += document.content.slice(cursor, label.start) + writtenLabel(next, label.written);
|
|
1067
1052
|
cursor = label.end;
|
|
@@ -1069,8 +1054,7 @@ export function relabel(document, before, after) {
|
|
|
1069
1054
|
return content + document.content.slice(cursor);
|
|
1070
1055
|
}
|
|
1071
1056
|
export function relabels(before, after) {
|
|
1072
|
-
return
|
|
1073
|
-
JSON.stringify([...labelsIn(after.frontmatter)]));
|
|
1057
|
+
return JSON.stringify([...labelsIn(before.root)]) !== JSON.stringify([...labelsIn(after.root)]);
|
|
1074
1058
|
}
|
|
1075
1059
|
export function serialize(document) {
|
|
1076
1060
|
return document.content;
|
package/dist/event.js
CHANGED
|
@@ -194,7 +194,7 @@ export function candidateOf(document) {
|
|
|
194
194
|
type: document.type,
|
|
195
195
|
fileId: document.id,
|
|
196
196
|
fields,
|
|
197
|
-
definition: {
|
|
197
|
+
definition: { root: { type: 'object', prose: false, properties } },
|
|
198
198
|
text: null,
|
|
199
199
|
};
|
|
200
200
|
}
|
package/dist/fields.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const TYPE_FIELD = "type";
|
|
2
2
|
export declare const MEMBER_FIELD = "member";
|
|
3
3
|
export declare const SITE_FIELD = "site";
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const SUBMITTED_FIELD = "submitted";
|
|
5
5
|
export declare const HOUSE_FIELDS: readonly string[];
|
|
6
6
|
//# sourceMappingURL=fields.d.ts.map
|
package/dist/fields.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,eAAe,cAAc,CAAC;AAE3C,eAAO,MAAM,YAAY,EAAE,SAAS,MAAM,EAKzC,CAAC"}
|