@agentshouse/mdmodel 0.1.0-c03f6cf931ca0 → 0.1.0-c047361b218db

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.
Files changed (96) hide show
  1. package/API.md +33 -94
  2. package/README.md +1 -1
  3. package/dist/definition.d.ts +4 -0
  4. package/dist/definition.d.ts.map +1 -1
  5. package/dist/definition.js +13 -4
  6. package/dist/document.d.ts +1 -0
  7. package/dist/document.d.ts.map +1 -1
  8. package/dist/document.js +56 -21
  9. package/dist/house-model.d.ts +103 -5
  10. package/dist/house-model.d.ts.map +1 -1
  11. package/dist/house-model.js +54 -4
  12. package/dist/index.d.ts +12 -8
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +8 -7
  15. package/dist/indexed.d.ts +9 -0
  16. package/dist/indexed.d.ts.map +1 -0
  17. package/dist/indexed.js +55 -0
  18. package/dist/kinds.d.ts +3 -0
  19. package/dist/kinds.d.ts.map +1 -1
  20. package/dist/kinds.js +60 -0
  21. package/dist/markdown.d.ts +0 -4
  22. package/dist/markdown.d.ts.map +1 -1
  23. package/dist/markdown.js +1 -34
  24. package/dist/moment.d.ts +7 -0
  25. package/dist/moment.d.ts.map +1 -0
  26. package/dist/moment.js +18 -0
  27. package/dist/paths.d.ts +6 -0
  28. package/dist/paths.d.ts.map +1 -1
  29. package/dist/paths.js +33 -3
  30. package/dist/query/language.d.ts +2 -1
  31. package/dist/query/language.d.ts.map +1 -1
  32. package/dist/query/language.js +1 -1
  33. package/dist/query/rows.d.ts.map +1 -1
  34. package/dist/query/rows.js +1 -4
  35. package/dist/query/sql.d.ts +5 -1
  36. package/dist/query/sql.d.ts.map +1 -1
  37. package/dist/query/sql.js +3 -3
  38. package/dist/query/walk.d.ts +63 -0
  39. package/dist/query/walk.d.ts.map +1 -0
  40. package/dist/query/walk.js +263 -0
  41. package/dist/reserved.d.ts +1 -0
  42. package/dist/reserved.d.ts.map +1 -1
  43. package/dist/reserved.js +15 -4
  44. package/dist/room-types.d.ts +1 -1
  45. package/dist/room-types.d.ts.map +1 -1
  46. package/dist/room-types.js +1 -0
  47. package/dist/types.d.ts +0 -21
  48. package/dist/types.d.ts.map +1 -1
  49. package/dist/validate.d.ts +2 -0
  50. package/dist/validate.d.ts.map +1 -1
  51. package/dist/validate.js +9 -5
  52. package/dist/yaml.d.ts +3 -1
  53. package/dist/yaml.d.ts.map +1 -1
  54. package/dist/yaml.js +153 -32
  55. package/fixtures/README.md +41 -53
  56. package/fixtures/cases/block-scalar-frontmatter/context.json +1 -0
  57. package/fixtures/cases/block-scalar-frontmatter/expected.json +1 -0
  58. package/fixtures/cases/block-scalar-frontmatter/library/notes/literal.md +17 -0
  59. package/fixtures/cases/block-scalar-frontmatter/library/skills/notes/SKILL.md +10 -0
  60. package/fixtures/cases/frontmatter-construct/context.json +1 -0
  61. package/fixtures/cases/frontmatter-construct/expected.json +7 -0
  62. package/fixtures/cases/frontmatter-construct/library/note.md +6 -0
  63. package/fixtures/cases/reference-to-any-file-name/context.json +1 -0
  64. package/fixtures/cases/reference-to-any-file-name/expected.json +1 -0
  65. package/fixtures/cases/reference-to-any-file-name/library/people/100%.md +4 -0
  66. package/fixtures/cases/reference-to-any-file-name/library/people/C#.md +4 -0
  67. package/fixtures/cases/reference-to-any-file-name/library/people/My notes.md +4 -0
  68. package/fixtures/cases/reference-to-any-file-name/library/people/[draft].md +4 -0
  69. package/fixtures/cases/reference-to-any-file-name/library/people/c (d).md +4 -0
  70. package/fixtures/cases/reference-to-any-file-name/library/people/caf/303/251.md +4 -0
  71. package/fixtures/cases/reference-to-any-file-name/library/people//320/236/321/202/321/207/321/221/321/202.md +4 -0
  72. package/fixtures/cases/reference-to-any-file-name/library/tasks/bracket.md +9 -0
  73. package/fixtures/cases/reference-to-any-file-name/library/tasks/cyrillic.md +9 -0
  74. package/fixtures/cases/reference-to-any-file-name/library/tasks/decomposed.md +9 -0
  75. package/fixtures/cases/reference-to-any-file-name/library/tasks/hash.md +9 -0
  76. package/fixtures/cases/reference-to-any-file-name/library/tasks/parenthesis.md +9 -0
  77. package/fixtures/cases/reference-to-any-file-name/library/tasks/percent.md +9 -0
  78. package/fixtures/cases/reference-to-any-file-name/library/tasks/spaced.md +9 -0
  79. package/fixtures/cases/reference-to-any-file-name/schema.yaml +10 -0
  80. package/fixtures/cases/referenced-missing-non-latin-file/context.json +1 -0
  81. package/fixtures/cases/referenced-missing-non-latin-file/expected.json +6 -0
  82. package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/a.md +9 -0
  83. package/fixtures/cases/referenced-missing-non-latin-file/library/tasks/b.md +9 -0
  84. package/fixtures/cases/referenced-missing-non-latin-file/schema.yaml +10 -0
  85. package/fixtures/forms.json +24 -0
  86. package/fixtures/preamble.json +4 -4
  87. package/fixtures/queries.json +397 -2
  88. package/package.json +1 -1
  89. package/dist/divide.d.ts +0 -3
  90. package/dist/divide.d.ts.map +0 -1
  91. package/dist/divide.js +0 -321
  92. package/dist/project.d.ts +0 -22
  93. package/dist/project.d.ts.map +0 -1
  94. package/dist/project.js +0 -101
  95. package/fixtures/division.json +0 -454
  96. package/fixtures/projection.json +0 -358
package/API.md CHANGED
@@ -3,10 +3,8 @@
3
3
  ```ts
4
4
  import {
5
5
  apply,
6
- divide,
7
6
  links,
8
7
  parse,
9
- project,
10
8
  retarget,
11
9
  serialize,
12
10
  target,
@@ -46,7 +44,10 @@ JSON Schema of its Documents' values; `$defs` holds shapes the types reuse, reac
46
44
  beside it admits a Document in another Room, of a type that Room declares; `title` is the label a
47
45
  Document shows for a field and `contentMediaType: text/markdown` marks a string of Markdown text
48
46
  written under its own heading; `member_document: true` marks at most one type. A type alone takes `create_roles` and
49
- `delete_roles`, each a list of role names. `verify(schema, provided)` holds every type of a model
47
+ `delete_roles`, each a list of role names, and `indexed`, which validates nothing: a list of its own top-level
48
+ fields, each admitting one plain value or `null`, a number, an integer, a boolean, or a choice, `date`,
49
+ `date-time`, `time` or `maxLength`-bounded string. `verifyIndexBounds(model, { perType, longestText })`
50
+ refuses a type past those bounds under the rule `indexed`. `verify(schema, provided)` holds every type of a model
50
51
  `provided` as its own, named only for those two and only if `provided.nameable` lists it. On a field
51
52
  of a type's own `properties` alone, `change_roles` and `initial_roles` each list role names, and
52
53
  `transitions` lists `{ from, to, roles? }`, each end a scalar or `null`, on a field whose `type`,
@@ -94,7 +95,7 @@ a path neither holds is not refused: it dangles. One written `/rooms/<handle>/<p
94
95
  another Room, which the caller checks; any other absolute path, or one that leaves the collection, is
95
96
  `unresolved-link`. A binary target supplies no Document or MD Type. `model` types the Library. A typed
96
97
  Document, `any` included, at an `isDocumentPath` (no `isReservedName` of `RESERVED_NAMES` first) linking
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
+ 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. `isReservedName` compares a name with `RESERVED_NAMES` after `foldedName(name)`, the name in Unicode NFC under Unicode default case folding, which is how two names of one folder compare. 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
99
 
99
100
  `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
101
 
@@ -136,7 +137,9 @@ refused as `pattern`; `openPatternBudget()` opens one such bound over the assess
136
137
  function it returns is called, and an inner one shares the outer.
137
138
 
138
139
  Validation returns acceptance or one refusal naming the file, the field, its line and the violated
139
- rule. `parse`, `apply`, and `serialize` operate on a single text Document; they do not validate
140
+ rule. A frontmatter outside the YAML subset the fixtures README states is refused as
141
+ `frontmatter-fence`, its `location` naming the construct the subset does not take and its `line`
142
+ where that construct is written. `parse`, `apply`, and `serialize` operate on a single text Document; they do not validate
140
143
  collection membership or consume binary bytes. `parse(content, file?, definition?)` and
141
144
  `apply(document, changes, definition?, nameOf?)` take the Document's MD Type definition: `parse` takes the
142
145
  `Definition` itself or a `DefinitionOf`, a function from the type the frontmatter declares to its
@@ -154,10 +157,10 @@ With a definition a field change rewrites that value's lines alone and writes a
154
157
  schema position, after the nearest field before it the Document holds; a value whose form changes
155
158
  moves, and `undefined` removes it. A reference is written as a link whose text is `nameOf(value)`,
156
159
  else the file name, and never changed after; a value no form carries is `malformed-value`, and a
157
- section change naming a field's label `required-section`. Without one a field is written in the
160
+ section change naming a field's label `field-section`, at that field's key. Without one a field is written in the
158
161
  frontmatter. A `{ kind: 'section', name, value, prior: undefined }` change opens a
159
162
  section after the Document's last line, in the order the changes give, and is stale where the
160
- Document holds that section. The Document a typed write of values returns carries the values it wrote, and reads its body only when a caller asks for what only the text holds; a write that carries text from outside, a Markdown value, a text value that does not fit its line, free text, a section or the preamble, or rewrites a link, reads the text it made. All apply or none: one refused refuses
163
+ Document holds that section; one with a prior text is stale where the Document lacks the section, a name no `## ` heading reads back as itself being `unwritable-section`, and a section's or the preamble's prior is compared as `partText(part)` reads it, its text without the blank lines around it, which a writer sends back. The Document a typed write of values returns carries the values it wrote, and reads its body only when a caller asks for what only the text holds; a write that carries text from outside, a Markdown value, a text value that does not fit its line, free text, a section or the preamble, or rewrites a link, reads the text it made. All apply or none: one refused refuses
161
164
  all, and `{ outcome: 'stale', document, stale }` keeps the Document and lists the positions of each
162
165
  change it does not hold and of each later change of a part an earlier one changes, such as a link
163
166
  inside a replaced section. A section, preamble or free text replacement that would hide a section the
@@ -209,7 +212,9 @@ Frontmatter values and the links that write reference values are never in it.
209
212
  by the rule `links` and `validate` read: surrounding spaces and the `?query` or `#fragment` it
210
213
  carries are not part of that Path. It reads backslash escapes and character references, strips as a
211
214
  URL does, then percent-encodings, so `plan\.md`, `pl&#97;n.md` and `pl%61n.md` all name `plan.md`;
212
- an escaped or referenced `?` or `#` starts the suffix. A destination that is empty, a bare fragment,
215
+ an escaped or referenced `?` or `#` starts the suffix. The Path is in Unicode NFC, so a destination
216
+ written decomposed names the composed Path, and every target `links`, `validate` and `documentFacts`
217
+ read is NFC. A destination that is empty, a bare fragment,
213
218
  carries a URL scheme, starts at `/` once read, encodes no UTF-8 text, or leaves the collection
214
219
  resolves to `null`. It reads a destination written anywhere, such as a typed reference field value,
215
220
  which `links` never enumerates. `roomTarget(href)` reads `/rooms/<handle>/<path>` as its `handle`
@@ -218,10 +223,12 @@ any reference written so. `linkedPath(from, href)` reads a link so, with the `ha
218
223
  `/rooms/<handle>` one names, `''` for the Room's root and the heading its `#fragment` names, `from`
219
224
  if it names no Path. `retarget(href, to)` is that destination rewritten to `to`, keeping the
220
225
  `?query` or `#fragment` it carried, which is the destination the `link` change below writes. It
221
- percent-encodes in `to` what `target` would decode, so it resolves to `to` again.
226
+ percent-encodes in `to` what `target` would decode or strip, a space at either end among them, so it
227
+ resolves to `to` again. `urlDestination(url)` is the destination that reads as `url`, the address a
228
+ Markdown renderer gives a link with its escapes and character references already read, so
229
+ `linkedPath(from, urlDestination(url))` reads them once.
222
230
 
223
- `untitled(definition)` is a definition without its `title`s at any depth, a property named `title`
224
- kept, so two types that differ only in their labels compare equal.
231
+ `untitled(definition)` is a definition without its `title`s at any depth, a property named `title` kept, so two types that differ only in their labels compare equal.
225
232
 
226
233
  `checkDocument(file, content, model, context?)` reads one Document as `validate` does in that
227
234
  context: `ok: false` where it refuses, else its `type`, whether it is `typed`, and each reference's
@@ -239,7 +246,7 @@ rewrites, in one `apply`, each link destination and reference written `/rooms/<h
239
246
  not in `kept` to `relative(file, path)`, keeping its `?query` or `#fragment`. A text without
240
247
  frontmatter, such as a captured body, is read from its first character: `relativizeBody(body, file, handle)` converts it
241
248
  so, refusing a `/rooms/` one naming no Room's file as `unresolved-link`; `bodyLinks(body, file)`
242
- is its `links` and `bodyRoomLinks(body)` its other Rooms'. `relinkBody(body, file, moves)` writes,
249
+ 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, each name percent-encoding every ASCII character but letters, digits, `.`, `_`, `~` and `-` and keeping every other character as written, which `keyedLink` decodes and takes in NFC. `relinkBody(body, file, moves)` writes,
243
250
  in the `link` change's form, each destination whose Path keys `moves` as that value relative to
244
251
  `file`, or as that value when it is a `/rooms/` path, and one whose `roomPath` does as that value.
245
252
  `unlinkBody(body, hrefs)` cuts every link and reference definition whose written destination is
@@ -260,83 +267,6 @@ profile reads back: bare when it carries no whitespace, does not open with `<`,
260
267
  parentheses, otherwise inside angle brackets, which the original form is kept in when it still
261
268
  fits. A destination that neither form can carry is refused as `unwritable-link`.
262
269
 
263
- `project(document, file, context?)` is the Embedding projection input of one Document: the prose a
264
- consumer embeds, with every internal Markdown-document link reduced to the label a reader sees. A
265
- Document that declares no MD type contributes its body after the frontmatter fence. A typed one
266
- contributes its prose values, each bare without its label, first the ones written on a line, in a
267
- cell or in a `json` block, each followed by a blank line, then its Markdown long values and its free
268
- text, its preamble, each section whose heading names no field and what follows a thematic break,
269
- in Document order. A prose value is a string at any depth whose schema is prose. The Path, every
270
- label and every other value stay outside, so changing them alone leaves the projection unchanged.
271
-
272
- ```ts
273
- const parsed = parse(content);
274
- if (parsed.ok) {
275
- const projected = project(parsed.document, 'tasks/two.md', {
276
- documentTargets: ['plans/q3.md', 'people/ana.md'],
277
- definition: model.types.task,
278
- });
279
- if (projected.ok) embed(projected.text);
280
- }
281
- ```
282
-
283
- `ProjectionContext` carries `documentTargets`, the collection-relative Paths the caller holds as
284
- Markdown documents, and `definition`, the verified MD Type the Document's `type` names, taken from
285
- the model `verify` returned. A Document that declares a type the caller supplies no definition for
286
- is refused as `unknown-type`. `documentTargets` is what makes a destination internal: a destination
287
- resolving to a supplied Path is internal, as is one into another Room, and every other stays text, a
288
- binary target and a Path nobody supplied alike. The caller supplies that membership, as it does for
289
- `validate`; the model reads no bytes, resolves no authority, and classifies nothing unsupplied.
290
-
291
- An internal link contributes its visible label and no destination, fragment, or title, in the inline
292
- `[label](path)`, full `[label][id]`, collapsed `[label][]`, and shortcut `[label]` forms, and the
293
- link reference definition an enumerated use resolves through leaves the projection with it. An image
294
- at a supplied document target contributes its alt text the same way, because a move rewrites that
295
- destination too. External URLs, binary targets, unsupplied destinations, bare fragments, code spans,
296
- fenced code, and escaped syntax stay exactly as authored, read through the same syntax profile
297
- `links` and `validate` read. `project` returns text and never rewrites the Document.
298
-
299
- A `link` change leaves the projection of every Document it rewrites
300
- byte-identical, while a changed visible label changes it.
301
-
302
- `divide(document, file, context)` divides that same Embedding projection input into ordered Spans
303
- under the bound the caller supplies. Each Span carries the `text` to embed and the `start` and `end`
304
- of the extent it addresses in the Document's own source, as UTF-8 byte offsets and never string
305
- positions, so a caller stores the extent and hydrates the text it shows from the Document itself.
306
-
307
- `DivisionContext` is a `ProjectionContext` and one `bound`, the greatest number of characters a
308
- Span's embedded text may carry, counted the way JavaScript counts a string's length and not in the
309
- bytes the extent is measured in. No Span's text is ever longer than the bound. A bound cut never
310
- divides a character: where the bound ends between the two halves of a surrogate pair, the cut falls
311
- before the pair. A cut never falls inside link syntax either: it falls before an internal link, and
312
- a label longer than a whole piece's room is divided at the bound like any other text. The smallest
313
- bound is `2`, the length of one astral character; a bound that is not a whole number of at least
314
- `2` is refused with `division-bound` before any division. The bound is the caller's number alone:
315
- the model holds no tokenizer, counts nothing else, and refuses no input for being too long. A
316
- Document the caller supplies no definition for carries the `unknown-type` refusal of `project`.
317
-
318
- The division descends one level at a time, and only into the piece that does not fit: the whole
319
- input, a heading node, adjacent sibling nodes packed under one parent, adjacent blocks inside a
320
- node, sentences inside a block, and a bound cut inside a single sentence. A Span covers whole
321
- heading nodes or one contiguous piece inside a single node, never a partial node beside another. A
322
- Span that continues a node repeats that node's own heading line, projected like any other text and
323
- so carrying an internal link's label rather than its destination, and never an ancestor's heading,
324
- so renaming a heading costs what editing that heading's own body costs. A heading the bound cannot
325
- hold beside any text is not repeated, a continuation piece that begins with an astral character the
326
- room beside its heading cannot hold is carried without the heading, and a heading with no body of
327
- its own leads its first child node rather than standing as a Span of nothing but itself. Overlap
328
- exists at the sentence level alone, where each Span after the first repeats its predecessor's last
329
- sentence whenever the bound holds both; when it cannot hold both, the Span carries its own sentence
330
- alone. An untyped input arrives without a definition and descends the same ladder.
331
-
332
- Division is total: every authored character of the input belongs to at least one Span, and an input
333
- carrying no authored text divides into no Span at all. A Span's extent is the smallest range of the
334
- source that contains everything the Span covers, so it spans what the input excludes between two
335
- eligible pieces, and the extent addresses the authored source where the embedded text carries a
336
- repeated heading, an internal link's visible label, or a value the author escaped. A Span divided
337
- out of one value written on a line addresses that whole value, and a Span carrying part of one
338
- internal link's label addresses that whole link, because a cut never falls inside link syntax.
339
-
340
270
  `notReadyWaitMs(asked)` is how long a client told a Room's chunk list is not ready waits before it
341
271
  asks again: 1, 2, 3, 5, 8, 11 and 15 seconds by `asked`, counted from zero, then 15 seconds.
342
272
 
@@ -366,7 +296,11 @@ the values it takes in words, and `fitsKind(kind, facts, value)` whether a value
366
296
  `dated`, a `date-time` compares as the instant `instant` reads, which `instantKey` writes as text
367
297
  that sorts as the instant does, and a `reference` as the Room Path it resolves to. `compared(left,
368
298
  right, ordering)` orders plain values: numbers and booleans, then text by locale or `byCodePoint`,
369
- then lists item by item.
299
+ then lists item by item. `indexKey(facts, value)` is the key whose bytes order an indexed value so,
300
+ a date-time by its instant, text by code point, and a missing value with `null` first. `pageOrder(plan)` is the one order a page of
301
+ House's query walks, by Path or a field its types index, both by code point, and `walkOf(plan, model)` what drives that walk: an indexed
302
+ order as runs of keys, its continuation's, a missing value's and a range on that field, else the keys of the first top-level equality
303
+ or list on a field every named type indexes, else Path. Each refuses what no walk serves; `walkedValue` names a walked value as a continuation does. `countShape(plan)` says whether a plan asks a total or groups and refuses what no count serves, and `countOf(plan, model, where)` names a count's walk, in no order and from no continuation: those keys, else the range of the first top-level range on such a field, else Path, with every field it tests or groups by.
370
304
 
371
305
  Two evaluators answer a plan's tests on one Document alike, a test on a missing value false and
372
306
  its negation (`$ne`, `$nin`, `$exists: false`) true. `matches(plan, candidate)` answers in
@@ -374,14 +308,14 @@ memory over one `Candidate`: its `path`, `type`, `fileId`, `fields`, `definition
374
308
  `text` held, and refuses a plan that orders by `size`, `created`, `updated` or `greatest`, or
375
309
  selects a group's totals, which one Document cannot answer. The `sql` namespace compiles them to SQL over a collection: `indexed(path, fields,
376
310
  definition)` derives a Document's values and field links, its date-times with their instants,
377
- `sql.VALUE_TABLE` holds those values and `sql.insertedValues` writes them, and `sql.tests(alias,
311
+ `sql.VALUE_TABLE` holds those values and `sql.insertedValues` writes those of many documents, and `sql.tests(alias,
378
312
  plan)` tests a document row of `id`, `path`, `folder`, `type`, `file_id` and `content`, its
379
313
  phrase through the function a connection registers as `sql.HOLDS_PHRASE` with `sql.holdsPhrase`.
380
314
  `sql.scoped`, `sql.placed`, `sql.sorted`, `sql.beyond`, `sql.following` and `sql.sortValue`
381
315
  render a scope, a pointer, an order and a window's continuation, a date-time ordering as its
382
316
  instant between numbers and text; `sql.fragment`, `sql.joined`, `sql.all`, `sql.any`,
383
317
  `sql.grouped`, `sql.listed` and `sql.exists` build statements, and `heldKind` is the index's value
384
- kind. `fixtures/queries.json` holds both evaluators to one table.
318
+ kind. `fixtures/queries.json` holds both evaluators to one table, and `indexKey` to their order.
385
319
 
386
320
  ## Events
387
321
 
@@ -390,8 +324,7 @@ change: its `id`, its `path` with a leading `/`, its `type` or `null`, and a `Fa
390
324
  for each field it writes that its MD Type declares, held as its kind in the one table
391
325
  of kinds: `reference`, `enum`, `number`, `integer`, `boolean`, `date`, `date-time`, `time` or
392
326
  `string`. A prose value, or one of no kind, is `prose`, a list or an object holds the facts of its members, and a value written
393
- `null` is `null`. A
394
- value that does not fit its kind, such as a string in a number field, a fraction in an integer
327
+ `null` is `null`. A value that does not fit its kind, such as a string in a number field, a fraction in an integer
395
328
  field, a value outside its `enum` or a reference `resolve` maps to no `{ id, member? }`, is `unreadable`; a readable reference holds that
396
329
  `id` and the `member` it binds, which `members(facts, path)` lists at a `/members/<pointer>`.
397
330
 
@@ -422,3 +355,9 @@ unknown extension `application/octet-stream`, and `fileExtension(type)` is the e
422
355
  named by. `SCRIPT_MEDIA_TYPES` lists the types a script is declared under, `dataUrl(type, base64)`
423
356
  and `dataUrlPattern(types)` write and match a base64 data URL, `formDataType(boundary)` is a
424
357
  multipart form's type and `gitMediaType(service, part)` a Git transport's.
358
+
359
+ ## Moments
360
+
361
+ `shownMoment(at, reader)` shows a `Date` to a person as a calendar does: its day and minute in the
362
+ `MomentReader`'s `language` and IANA time `zone`, naming no zone, or in UTC, named, where `zone` is
363
+ `null`. `shownDay(at, reader)` shows its day alone, in UTC where `zone` is `null`.
package/README.md CHANGED
@@ -43,12 +43,12 @@ if (checked.verdict === 'accept') {
43
43
  | `apply` | Apply field, section, preamble, link and reference changes at once |
44
44
  | `links`, `target`, `retarget` | Inventory and rewrite link destinations |
45
45
  | `escapePointer` | Write one key as a JSON Pointer token |
46
- | `project`, `divide` | Embedding projection input and its division into Spans |
47
46
  | `facts`, `candidateOf` | A Document as one change saw it, matched as one query candidate |
48
47
  | `planOf`, `matches`, `sql` | Check a query, answer it over one Document or compile it to SQL |
49
48
  | `VERSION` | The MD model version |
50
49
  | `MEMBER_FIELD`, `SITE_FIELD`, `SUBMITTED_FIELD` | The frontmatter keys validation counts as declared beyond a type's |
51
50
  | `MEDIA_TYPES`, `servedMediaType` | The media types House writes and the one table of file extensions |
51
+ | `shownMoment`, `shownDay` | A moment shown to a person in their language and time zone |
52
52
 
53
53
  The full reference is in [`API.md`](API.md). The conformance corpus and its
54
54
  verdict format and rule ids are described in [`fixtures/README.md`](fixtures/README.md).
@@ -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
  };
@@ -44,6 +45,7 @@ export type Definition = {
44
45
  readonly rules: Readonly<Record<string, FieldRules>>;
45
46
  readonly createRoles?: readonly string[];
46
47
  readonly deleteRoles?: readonly string[];
48
+ readonly indexed?: readonly string[];
47
49
  readonly shape: Shape;
48
50
  };
49
51
  export type Failure = {
@@ -58,6 +60,7 @@ export declare const JSON_TYPES: readonly JsonType[];
58
60
  export declare const BUILT_IN_TYPE = "any";
59
61
  export declare const ATTACHMENT = "attachment";
60
62
  export declare const OPENING: readonly string[];
63
+ export declare const UNIONS: readonly string[];
61
64
  export declare const ARRAY_INDEX: RegExp;
62
65
  export declare const JSON_POINTER: RegExp;
63
66
  export declare function refuse(rule: string, location: string): Failure;
@@ -75,6 +78,7 @@ export declare function conjoined(declared: readonly {
75
78
  readonly ancestry: ReadonlySet<unknown>;
76
79
  };
77
80
  export declare function variantsOf({ node, at }: Placed): Placed[];
81
+ export declare function admitted(nodes: readonly unknown[], defs: Readonly<Record<string, unknown>>, ancestry: ReadonlySet<unknown>): Set<string> | null;
78
82
  export declare function valueFacts(node: unknown, defs: Readonly<Record<string, unknown>>): ValueFacts;
79
83
  export declare function itemFacts(facts: ValueFacts, index: number): ValueFacts | undefined;
80
84
  export declare function memberFacts(facts: ValueFacts, key: string): ValueFacts | undefined;
@@ -1 +1 @@
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,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}) });
31
31
  const DEFS_REFERENCE = '#/$defs/';
32
32
  const UNBOUNDED_FORMAT = 'url';
33
- const UNIONS = ['anyOf', 'oneOf'];
33
+ export 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;
36
36
  export const JSON_POINTER = /^(?:\/(?:[^~/]|~[01])*)*$/u;
@@ -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
  };
@@ -399,7 +401,7 @@ function narrowed(left, right) {
399
401
  return left;
400
402
  return new Set([...left].filter((one) => right.has(one)));
401
403
  }
402
- function admitted(nodes, defs, ancestry) {
404
+ export function admitted(nodes, defs, ancestry) {
403
405
  const conjunction = conjoined(nodes.map((node) => ({ node, at: '' })), defs, ancestry);
404
406
  let kept = null;
405
407
  for (const { node } of conjunction.held) {
@@ -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
  : [];
@@ -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
  };
@@ -784,13 +790,15 @@ function readType(name, value, context) {
784
790
  const at = `/${escapePointer(name)}`;
785
791
  if (!isRecord(value))
786
792
  return refuse('schema', at);
787
- const { member_document: mark, create_roles: createRoles, delete_roles: deleteRoles, ...ruled } = value;
793
+ const { member_document: mark, create_roles: createRoles, delete_roles: deleteRoles, indexed, ...ruled } = value;
788
794
  if (mark !== undefined && typeof mark !== 'boolean')
789
795
  return refuse('member_document', `${at}/member_document`);
790
796
  if (createRoles !== undefined && !roleNames(createRoles))
791
797
  return refuse('create_roles', `${at}/create_roles`);
792
798
  if (deleteRoles !== undefined && !roleNames(deleteRoles))
793
799
  return refuse('delete_roles', `${at}/delete_roles`);
800
+ if (indexed !== undefined && !strings(indexed))
801
+ return refuse('indexed', `${at}/indexed`);
794
802
  const { schema, written } = unruled(ruled);
795
803
  const failure = schemaFailure(schema, at, context);
796
804
  if (failure !== undefined)
@@ -811,7 +819,7 @@ function readType(name, value, context) {
811
819
  fields[MEMBER_FIELD] = { type: 'string', prose: false };
812
820
  const defs = Object.create(null);
813
821
  reachedDefs(value, context.defs, defs);
814
- const { create_roles: _create, delete_roles: _delete, ...shaped } = value;
822
+ const { create_roles: _create, delete_roles: _delete, indexed: _indexed, ...shaped } = value;
815
823
  return {
816
824
  name,
817
825
  memberDocument,
@@ -820,6 +828,7 @@ function readType(name, value, context) {
820
828
  rules,
821
829
  ...(createRoles === undefined ? {} : { createRoles }),
822
830
  ...(deleteRoles === undefined ? {} : { deleteRoles }),
831
+ ...(indexed === undefined ? {} : { indexed }),
823
832
  shape: {
824
833
  schema: written.size === 0 ? shaped : { ...shaped, properties: schema.properties },
825
834
  defs,
@@ -15,6 +15,7 @@ export declare function unlinkBody(body: string, hrefs: ReadonlySet<string>): Un
15
15
  export declare function links(document: Document, file: string): readonly Link[];
16
16
  export declare function bodyLinks(body: string, file: string): readonly Link[];
17
17
  export declare function bodyWith(document: Document, definition: Definition | undefined): Body | null | Refusal;
18
+ export declare function partText(part: string): string;
18
19
  export declare function apply(document: Document, changes: readonly Change[], definition?: Definition, nameOf?: Naming): ApplyResult;
19
20
  export declare function relabel(document: Document, before: Definition, after: Definition): string;
20
21
  export declare function relabels(before: Definition, after: Definition): boolean;
@@ -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;AAcvB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,MAAM,EACN,YAAY,EACZ,QAAQ,EAER,IAAI,EACJ,WAAW,EACX,OAAO,EACP,IAAI,EACJ,YAAY,EACb,MAAM,YAAY,CAAC;AAoDpB,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAKrD;AAeD,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,GAAG,IAAI,CAGtD;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,cAAc,EAAE,CAQ9E;AAiCD,wBAAgB,SAAS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,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,7 +3,7 @@ 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
9
  import { bodyStartAfterYaml, bodyStartOf, documentValue, equalValue, extractFrontmatter, isRecord, jsValue, lineEnding, mapEntry, parseYamlMapping, serializeJs, serializeKey, YamlError, } from './yaml.js';
@@ -140,7 +140,7 @@ function opened(content, file) {
140
140
  if (error instanceof YamlError)
141
141
  return {
142
142
  ok: false,
143
- refusal: refuse(file, 'frontmatter-fence', undefined, lineOf(content, error.offset)),
143
+ refusal: refuse(file, 'frontmatter-fence', error.construct, lineOf(content, error.offset)),
144
144
  };
145
145
  throw error;
146
146
  }
@@ -190,7 +190,7 @@ function shellRelinked(body, file, handle) {
190
190
  const occurrences = hrefOccurrences(body);
191
191
  const written = new Map();
192
192
  for (const href of new Set(occurrences.map((occurrence) => occurrence.href))) {
193
- const path = shellTarget(href, handle);
193
+ const path = keyedLink(href) === null ? shellTarget(href, handle) : null;
194
194
  if (path === null)
195
195
  continue;
196
196
  const to = retarget(href, relative(file, path));
@@ -230,7 +230,7 @@ function scalarText(source, value) {
230
230
  }
231
231
  export function relativize(document, file, handle, definition, kept = new Set()) {
232
232
  const relativized = (href) => {
233
- const path = shellTarget(href, handle);
233
+ const path = keyedLink(href) === null ? shellTarget(href, handle) : null;
234
234
  return path === null || kept.has(`${SHELL_ROOMS}${handle}/${path}`) ? null : path;
235
235
  };
236
236
  const changes = [];
@@ -266,7 +266,7 @@ export function relinkBody(body, file, moves) {
266
266
  let rewritten = '';
267
267
  let cursor = 0;
268
268
  for (const match of hrefOccurrences(body)) {
269
- const from = target(file, match.href) ?? roomPath(match.href);
269
+ const from = target(file, match.href) ?? (keyedLink(match.href) === null ? roomPath(match.href) : null);
270
270
  const to = from === null ? undefined : moves.get(from);
271
271
  if (to === undefined)
272
272
  continue;
@@ -361,7 +361,7 @@ function inBody(change, body) {
361
361
  return (body !== null &&
362
362
  ((change.kind === 'field' && !HOUSE_FIELDS.includes(change.name)) || change.kind === 'text'));
363
363
  }
364
- function planner(document, internal, body) {
364
+ function planner(document, internal, body, definition) {
365
365
  const content = document.content;
366
366
  const keyed = new Map();
367
367
  let spans;
@@ -416,10 +416,11 @@ function planner(document, internal, body) {
416
416
  }
417
417
  const span = spans.get(name);
418
418
  if (span === undefined)
419
- return refuse('', 'required-section', name);
420
- if (content.slice(span.bodyStart, span.bodyEnd) !== prior)
419
+ return unopenable(name, definition) ?? 'stale';
420
+ const held = content.slice(span.bodyStart, span.bodyEnd);
421
+ if (!samePart(held, prior))
421
422
  return 'stale';
422
- return [{ start: span.bodyStart, end: span.bodyEnd, text: value, at }];
423
+ return [{ start: span.bodyStart, end: span.bodyEnd, text: reframed(held, value), at }];
423
424
  };
424
425
  const link = (href, to, at) => {
425
426
  if (occurrences === undefined) {
@@ -476,20 +477,22 @@ function planner(document, internal, body) {
476
477
  return 'stale';
477
478
  return [{ start: internal.bodyStart, end: content.length, text: change.value, at }];
478
479
  }
479
- if (document.preamble !== change.prior)
480
+ const preamble = document.preamble;
481
+ if (!samePart(preamble, change.prior))
480
482
  return 'stale';
483
+ const text = reframed(preamble, change.value);
481
484
  if (body !== null) {
482
485
  const { start, end } = body.preamble;
483
486
  const before = content.slice(internal.bodyStart, start);
484
- const gap = start < end || change.value === '' || before === '' || before.endsWith('\n\n')
487
+ const gap = start < end || text === '' || before === '' || before.endsWith('\n\n')
485
488
  ? ''
486
489
  : before.endsWith('\n')
487
490
  ? '\n'
488
491
  : '\n\n';
489
- return [{ start, end, text: `${gap}${change.value}`, at }];
492
+ return [{ start, end, text: `${gap}${text}`, at }];
490
493
  }
491
494
  const start = internal.bodyStart;
492
- return [{ start, end: start + document.preamble.length, text: change.value, at }];
495
+ return [{ start, end: start + preamble.length, text, at }];
493
496
  };
494
497
  }
495
498
  function repointed(value, segments, to) {
@@ -504,6 +507,32 @@ function repointed(value, segments, to) {
504
507
  copy[key] = key === segment ? repointed(held[key], rest, to) : held[key];
505
508
  return copy;
506
509
  }
510
+ function framed(part) {
511
+ const lead = /^(?:[ \t]*\r?\n)*/u.exec(part)[0];
512
+ let end = part.length;
513
+ while (end > lead.length && ' \t\r\n'.includes(part[end - 1]))
514
+ end -= 1;
515
+ return { lead, text: part.slice(lead.length, end), tail: part.slice(end) };
516
+ }
517
+ export function partText(part) {
518
+ return framed(part).text;
519
+ }
520
+ function samePart(held, prior) {
521
+ return prior !== undefined && partText(held) === partText(prior);
522
+ }
523
+ function lineEnds(text) {
524
+ return text.split('\n').length - 1;
525
+ }
526
+ function wider(held, written) {
527
+ return lineEnds(held) > lineEnds(written) ? held : written;
528
+ }
529
+ function reframed(held, value) {
530
+ const was = framed(held);
531
+ const next = framed(value);
532
+ if (next.text === '')
533
+ return wider(was.lead, value);
534
+ return `${wider(was.lead, next.lead)}${next.text}${wider(was.tail, next.tail)}`;
535
+ }
507
536
  function bulletAt(content, start) {
508
537
  let at = start;
509
538
  while (content[at] === ' ' || content[at] === '\t')
@@ -824,11 +853,16 @@ function checkedReading(source, replaced) {
824
853
  function opening(change) {
825
854
  return change.kind === 'section' && change.prior === undefined;
826
855
  }
827
- function namesField(name, definition) {
828
- if (definition === undefined)
829
- return false;
830
- const root = definition.root;
831
- return bodyOrder(root).some((key) => labelOf(key, root.properties?.[key]) === name.trim());
856
+ function unopenable(name, definition) {
857
+ const root = definition?.root;
858
+ const field = root === undefined
859
+ ? undefined
860
+ : bodyOrder(root).find((key) => labelOf(key, root.properties?.[key]) === name.trim());
861
+ if (field !== undefined)
862
+ return refuse('', 'field-section', field);
863
+ if (read(`## ${name}`, 0).headings[0]?.name !== name)
864
+ return refuse('', 'unwritable-section', name);
865
+ return undefined;
832
866
  }
833
867
  function withSections(document, changes, definition, nameOf) {
834
868
  const opened = [];
@@ -836,8 +870,9 @@ function withSections(document, changes, definition, nameOf) {
836
870
  for (const [at, change] of changes.entries()) {
837
871
  if (!opening(change))
838
872
  continue;
839
- if (namesField(change.name, definition))
840
- return { outcome: 'refuse', refusal: refuse('', 'required-section', change.name) };
873
+ const refusal = unopenable(change.name, definition);
874
+ if (refusal !== undefined)
875
+ return { outcome: 'refuse', refusal };
841
876
  if (Object.hasOwn(document.sections, change.name) || opened.includes(change.name))
842
877
  held.push(at);
843
878
  else
@@ -933,7 +968,7 @@ export function apply(document, changes, definition, nameOf) {
933
968
  const body = bodyWith(document, definition);
934
969
  if (body !== null && !('top' in body))
935
970
  return { outcome: 'refuse', refusal: body };
936
- const plan = planner(document, internal, body);
971
+ const plan = planner(document, internal, body, definition);
937
972
  const edits = [];
938
973
  const stale = new Set();
939
974
  const named = new Set();