@agentshouse/mdmodel 0.1.0-ce9295da1c4c9 → 0.1.0-cf24f2baa8f2d

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 (139) hide show
  1. package/API.md +223 -193
  2. package/README.md +21 -22
  3. package/dist/blocks.d.ts.map +1 -1
  4. package/dist/blocks.js +35 -24
  5. package/dist/definition.d.ts +5 -1
  6. package/dist/definition.d.ts.map +1 -1
  7. package/dist/definition.js +125 -29
  8. package/dist/divide.d.ts.map +1 -1
  9. package/dist/divide.js +27 -17
  10. package/dist/document.d.ts +6 -5
  11. package/dist/document.d.ts.map +1 -1
  12. package/dist/document.js +326 -190
  13. package/dist/event.d.ts +78 -0
  14. package/dist/event.d.ts.map +1 -0
  15. package/dist/event.js +201 -0
  16. package/dist/facts.d.ts +15 -0
  17. package/dist/facts.d.ts.map +1 -0
  18. package/dist/facts.js +38 -0
  19. package/dist/index.d.ts +23 -9
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +14 -7
  22. package/dist/kinds.d.ts +18 -0
  23. package/dist/kinds.d.ts.map +1 -0
  24. package/dist/kinds.js +150 -0
  25. package/dist/links.d.ts +2 -0
  26. package/dist/links.d.ts.map +1 -1
  27. package/dist/links.js +112 -65
  28. package/dist/paths.d.ts +9 -1
  29. package/dist/paths.d.ts.map +1 -1
  30. package/dist/paths.js +28 -2
  31. package/dist/pattern.d.ts +10 -0
  32. package/dist/pattern.d.ts.map +1 -0
  33. package/dist/pattern.js +356 -0
  34. package/dist/project.d.ts +1 -0
  35. package/dist/project.d.ts.map +1 -1
  36. package/dist/project.js +37 -16
  37. package/dist/query/language.d.ts +254 -0
  38. package/dist/query/language.d.ts.map +1 -0
  39. package/dist/query/language.js +620 -0
  40. package/dist/query/match.d.ts +14 -0
  41. package/dist/query/match.d.ts.map +1 -0
  42. package/dist/query/match.js +150 -0
  43. package/dist/query/rows.d.ts +32 -0
  44. package/dist/query/rows.d.ts.map +1 -0
  45. package/dist/query/rows.js +161 -0
  46. package/dist/query/sql.d.ts +39 -0
  47. package/dist/query/sql.d.ts.map +1 -0
  48. package/dist/query/sql.js +285 -0
  49. package/dist/references.d.ts.map +1 -1
  50. package/dist/references.js +6 -1
  51. package/dist/reserved.d.ts +5 -0
  52. package/dist/reserved.d.ts.map +1 -0
  53. package/dist/reserved.js +20 -0
  54. package/dist/schema.d.ts +1 -0
  55. package/dist/schema.d.ts.map +1 -1
  56. package/dist/schema.js +55 -4
  57. package/dist/types.d.ts +39 -4
  58. package/dist/types.d.ts.map +1 -1
  59. package/dist/validate.d.ts +30 -4
  60. package/dist/validate.d.ts.map +1 -1
  61. package/dist/validate.js +365 -101
  62. package/dist/yaml.d.ts.map +1 -1
  63. package/dist/yaml.js +40 -14
  64. package/fixtures/README.md +26 -6
  65. package/fixtures/cases/conditional-section/context.json +1 -0
  66. package/fixtures/cases/conditional-section/expected.json +6 -0
  67. package/fixtures/cases/conditional-section/library/questions/hosting.md +9 -0
  68. package/fixtures/cases/conditional-section/library/questions/payments.md +12 -0
  69. package/fixtures/cases/conditional-section/schema.yaml +14 -0
  70. package/fixtures/cases/cross-room-link/context.json +1 -0
  71. package/fixtures/cases/cross-room-link/expected.json +1 -0
  72. package/fixtures/cases/cross-room-link/library/clients/acme.md +6 -0
  73. package/fixtures/cases/cross-room-link/schema.yaml +3 -0
  74. package/fixtures/cases/cross-room-reference/context.json +1 -0
  75. package/fixtures/cases/cross-room-reference/expected.json +1 -0
  76. package/fixtures/cases/cross-room-reference/library/clients/acme.md +9 -0
  77. package/fixtures/cases/cross-room-reference/schema.yaml +9 -0
  78. package/fixtures/cases/link-into-a-reserved-name/context.json +1 -0
  79. package/fixtures/cases/link-into-a-reserved-name/expected.json +5 -0
  80. package/fixtures/cases/link-into-a-reserved-name/library/notes/a.md +6 -0
  81. package/fixtures/cases/link-into-a-reserved-name/schema.yaml +3 -0
  82. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/context.json +1 -0
  83. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
  84. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
  85. package/fixtures/cases/member-on-an-untyped-document/context.json +1 -0
  86. package/fixtures/cases/member-on-an-untyped-document/expected.json +6 -0
  87. package/fixtures/cases/member-on-an-untyped-document/library/note.md +4 -0
  88. package/fixtures/cases/member-on-another-type/context.json +1 -0
  89. package/fixtures/cases/member-on-another-type/expected.json +6 -0
  90. package/fixtures/cases/member-on-another-type/library/note.md +4 -0
  91. package/fixtures/cases/member-on-another-type/schema.yaml +7 -0
  92. package/fixtures/cases/reference-into-a-reserved-name/context.json +1 -0
  93. package/fixtures/cases/reference-into-a-reserved-name/expected.json +6 -0
  94. package/fixtures/cases/reference-into-a-reserved-name/library/notes/a.md +4 -0
  95. package/fixtures/cases/reference-into-a-reserved-name/library/settings/brief.md +1 -0
  96. package/fixtures/cases/reference-into-a-reserved-name/schema.yaml +3 -0
  97. package/fixtures/cases/room-md-declares-a-type/context.json +1 -0
  98. package/fixtures/cases/room-md-declares-a-type/expected.json +6 -0
  99. package/fixtures/cases/room-md-declares-a-type/library/ROOM.md +5 -0
  100. package/fixtures/cases/typed-path-names-another-type/context.json +11 -0
  101. package/fixtures/cases/typed-path-names-another-type/expected.json +6 -0
  102. package/fixtures/cases/typed-path-names-another-type/library/settings/prefs/one.md +3 -0
  103. package/fixtures/cases/typed-path-names-another-type/schema.yaml +6 -0
  104. package/fixtures/cases/typed-path-names-its-type/context.json +11 -0
  105. package/fixtures/cases/typed-path-names-its-type/expected.json +3 -0
  106. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/deeper/two.md +1 -0
  107. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +4 -0
  108. package/fixtures/cases/typed-path-names-its-type/schema.yaml +6 -0
  109. package/fixtures/cases/typed-path-names-no-type/context.json +11 -0
  110. package/fixtures/cases/typed-path-names-no-type/expected.json +6 -0
  111. package/fixtures/cases/typed-path-names-no-type/library/settings/prefs/one.md +1 -0
  112. package/fixtures/cases/typed-path-names-no-type/schema.yaml +6 -0
  113. package/fixtures/cases/unnamed-typed-path-checks-its-fields/context.json +11 -0
  114. package/fixtures/cases/unnamed-typed-path-checks-its-fields/expected.json +6 -0
  115. package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +4 -0
  116. package/fixtures/cases/unnamed-typed-path-checks-its-fields/schema.yaml +5 -0
  117. package/fixtures/cases/unnamed-typed-path-names-a-type/context.json +11 -0
  118. package/fixtures/cases/unnamed-typed-path-names-a-type/expected.json +6 -0
  119. package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +6 -0
  120. package/fixtures/cases/unnamed-typed-path-names-a-type/schema.yaml +5 -0
  121. package/fixtures/cases/unnamed-typed-path-reads-its-type/context.json +11 -0
  122. package/fixtures/cases/unnamed-typed-path-reads-its-type/expected.json +3 -0
  123. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/plan.md +1 -0
  124. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +5 -0
  125. package/fixtures/cases/unnamed-typed-path-reads-its-type/schema.yaml +5 -0
  126. package/fixtures/cases/unnamed-typed-path-without-a-body/context.json +11 -0
  127. package/fixtures/cases/unnamed-typed-path-without-a-body/expected.json +5 -0
  128. package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +5 -0
  129. package/fixtures/cases/unnamed-typed-path-without-a-body/schema.yaml +5 -0
  130. package/fixtures/division.json +27 -28
  131. package/fixtures/projection.json +1 -2
  132. package/fixtures/queries.json +964 -0
  133. package/package.json +7 -2
  134. package/dist/condition.d.ts +0 -150
  135. package/dist/condition.d.ts.map +0 -1
  136. package/dist/condition.js +0 -502
  137. package/dist/profile.d.ts +0 -6
  138. package/dist/profile.d.ts.map +0 -1
  139. package/dist/profile.js +0 -5
package/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # `@agentshouse/mdmodel`
2
2
 
3
- Typed Markdown documents: MD Types declared in JSON Schema, a parser, a validator, and the
4
- deterministic application of one structured change to a Document, plus a
5
- conformance fixture corpus.
3
+ Typed Markdown documents: MD Types declared in JSON Schema, a parser, a validator, the
4
+ deterministic application of one structured change to a Document, and one query language
5
+ answered in SQL over a collection or in memory over one Document, plus a conformance
6
+ fixture corpus.
6
7
 
7
8
  It runs in the browser and in Node, makes no network call, and reads no
8
- filesystem on its own. It ships one ESM artifact that Node 24.21.0 and later
9
+ filesystem on its own. It ships one ESM artifact that Node 24.22.1 and later
9
10
  loads through `import` or `require`.
10
11
 
11
12
  ## Install
@@ -26,30 +27,28 @@ if (checked.verdict === 'accept') {
26
27
 
27
28
  const parsed = parse('---\ntype: note\ntitle: Hello\n---\n');
28
29
  if (parsed.ok) {
29
- const next = apply(parsed.document, {
30
- kind: 'field',
31
- name: 'title',
32
- value: 'World',
33
- prior: 'Hello',
34
- });
30
+ const next = apply(parsed.document, [
31
+ { kind: 'field', name: 'title', value: 'World', prior: 'Hello' },
32
+ ]);
35
33
  if (next.outcome === 'applied') serialize(next.document);
36
34
  }
37
35
  ```
38
36
 
39
37
  ## API
40
38
 
41
- | Export | Purpose |
42
- | ---------------------------------------------- | ----------------------------------------------------------------- |
43
- | `verify` | Verify one schema text into a model of MD Types |
44
- | `validate` | Validate a text Library; returns acceptance or one refusal |
45
- | `parse`, `serialize` | Read and write one Document |
46
- | `apply` | Apply one field, section, preamble, or link change |
47
- | `links`, `target`, `retarget` | Inventory and rewrite link destinations |
48
- | `escapePointer` | Write one key as a JSON Pointer token |
49
- | `project`, `divide` | Embedding projection input and its division into Spans |
50
- | `facts`, `factKind`, `holds`, `fires` | A condition over a Document and over one of its changes |
51
- | `MARKDOWN_SYNTAX_PROFILE`, `VERSION` | The pinned Markdown profile (GFM 0.29) and MD model version |
52
- | `MEMBER_FIELD`, `SITE_FIELD`, `RECEIVED_FIELD` | The field names validation counts as declared beyond a type's own |
39
+ | Export | Purpose |
40
+ | ---------------------------------------------- | ------------------------------------------------------------------ |
41
+ | `verify` | Verify one schema text into a model of MD Types |
42
+ | `validate` | Validate a text Library; returns acceptance or one refusal |
43
+ | `parse`, `serialize` | Read and write one Document |
44
+ | `apply` | Apply field, section, preamble, link and reference changes at once |
45
+ | `links`, `target`, `retarget` | Inventory and rewrite link destinations |
46
+ | `escapePointer` | Write one key as a JSON Pointer token |
47
+ | `project`, `divide` | Embedding projection input and its division into Spans |
48
+ | `facts`, `candidateOf` | A Document as one change saw it, matched as one query candidate |
49
+ | `planOf`, `matches`, `sql` | Check a query, answer it over one Document or compile it to SQL |
50
+ | `VERSION` | The MD model version |
51
+ | `MEMBER_FIELD`, `SITE_FIELD`, `RECEIVED_FIELD` | The field names validation counts as declared beyond a type's own |
53
52
 
54
53
  The full reference is in [`API.md`](API.md). The conformance corpus and its
55
54
  verdict format and rule ids are described in [`fixtures/README.md`](fixtures/README.md).
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAqCF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,WAAW,EAAE,CA+BrF;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAe/E"}
1
+ {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAmDF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,WAAW,EAAE,CA2BrF;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAe/E"}
package/dist/blocks.js CHANGED
@@ -1,5 +1,29 @@
1
- import { fenceSpans } from './links.js';
2
- const HEADING = /^(#{1,6})(?!#)[ \t]+(.+?)(?:[ \t]+#+)?[ \t]*$/;
1
+ import { fenceSpans, spanCursor } from './links.js';
2
+ const HEADING_OPEN = /^(#{1,6})(?!#)([ \t]+)/;
3
+ const LINE_BREAK = /[\n\r\u2028\u2029]/;
4
+ function blank(character) {
5
+ return character === ' ' || character === '\t';
6
+ }
7
+ function heading(text) {
8
+ const open = HEADING_OPEN.exec(text);
9
+ if (open === null || LINE_BREAK.test(text))
10
+ return null;
11
+ const level = open[1].length;
12
+ const rest = text.slice(open[0].length);
13
+ if (rest === '')
14
+ return open[2].length > 1 ? { level, name: '' } : null;
15
+ let end = rest.length;
16
+ while (blank(rest[end - 1]))
17
+ end -= 1;
18
+ let hashes = end;
19
+ while (rest[hashes - 1] === '#')
20
+ hashes -= 1;
21
+ let spaced = hashes;
22
+ while (blank(rest[spaced - 1]))
23
+ spaced -= 1;
24
+ const closed = hashes < end && spaced < hashes && spaced > 0;
25
+ return { level, name: rest.slice(0, closed ? spaced : end).trim() };
26
+ }
3
27
  function lineAt(content, from, to) {
4
28
  const nl = content.indexOf('\n', from);
5
29
  const end = nl === -1 || nl >= to ? to : nl;
@@ -7,43 +31,32 @@ function lineAt(content, from, to) {
7
31
  return { text: raw.endsWith('\r') ? raw.slice(0, -1) : raw, next: end === to ? to : end + 1 };
8
32
  }
9
33
  function scan(content, from, to, visit) {
10
- const fences = fenceSpans(content.slice(from, to));
34
+ const fenced = spanCursor(fenceSpans(content.slice(from, to)));
11
35
  let i = from;
12
36
  while (i < to) {
13
37
  const { text, next } = lineAt(content, i, to);
14
- const at = i - from;
15
- visit({
16
- text,
17
- start: i,
18
- next,
19
- fenced: fences.some(([start, end]) => at >= start && at < end),
20
- });
21
- if (next === i)
22
- break;
38
+ visit({ text, start: i, next, fenced: fenced(i - from) !== undefined });
23
39
  i = next;
24
40
  }
25
41
  }
26
42
  const HASH = 0x23;
27
43
  export function headingLines(content, from, to) {
28
44
  const found = [];
29
- let fences = null;
45
+ let fenced = null;
30
46
  let i = from;
31
47
  while (i < to) {
32
48
  const nl = content.indexOf('\n', i);
33
49
  const end = nl === -1 || nl >= to ? to : nl;
34
50
  const next = end === to ? to : end + 1;
35
51
  if (content.charCodeAt(i) === HASH) {
36
- fences ??= fenceSpans(content.slice(from, to));
37
- const at = i - from;
38
- if (!fences.some(([start, stop]) => at >= start && at < stop)) {
52
+ fenced ??= spanCursor(fenceSpans(content.slice(from, to)));
53
+ if (fenced(i - from) === undefined) {
39
54
  const { text } = lineAt(content, i, to);
40
- const match = HEADING.exec(text);
41
- const hashes = match?.[1];
42
- const name = match?.[2];
43
- if (hashes !== undefined && name !== undefined) {
55
+ const read = heading(text);
56
+ if (read !== null) {
44
57
  found.push({
45
- level: hashes.length,
46
- name: name.trim(),
58
+ level: read.level,
59
+ name: read.name,
47
60
  start: i,
48
61
  textEnd: i + text.length,
49
62
  next,
@@ -51,8 +64,6 @@ export function headingLines(content, from, to) {
51
64
  }
52
65
  }
53
66
  }
54
- if (next === i)
55
- break;
56
67
  i = next;
57
68
  }
58
69
  return found;
@@ -5,6 +5,7 @@ export type ValueFacts = {
5
5
  readonly format?: string;
6
6
  readonly values?: readonly unknown[];
7
7
  readonly reference?: readonly string[];
8
+ readonly crossRoom?: true;
8
9
  readonly prose: boolean;
9
10
  readonly conditional?: true;
10
11
  readonly prefix?: readonly ValueFacts[];
@@ -47,6 +48,8 @@ export type Definition = {
47
48
  readonly fields: Readonly<Record<string, ValueFacts>>;
48
49
  readonly sections: Readonly<Record<string, SectionSpec>>;
49
50
  readonly rules: Readonly<Record<string, FieldRules>>;
51
+ readonly createRoles?: readonly string[];
52
+ readonly deleteRoles?: readonly string[];
50
53
  readonly shape: Shape;
51
54
  };
52
55
  export type Failure = {
@@ -57,6 +60,7 @@ export declare const JSON_TYPES: readonly JsonType[];
57
60
  export declare const BUILT_IN_TYPE = "any";
58
61
  export declare const ATTACHMENT = "attachment";
59
62
  export declare const ARRAY_INDEX: RegExp;
63
+ export declare const JSON_POINTER: RegExp;
60
64
  export declare function escapePointer(key: string): string;
61
65
  export declare function pointerSegments(pointer: string): string[];
62
66
  export declare function refTarget(reference: string, defs: Readonly<Record<string, unknown>>): {
@@ -74,5 +78,5 @@ export type PointerFacts = {
74
78
  export declare function crossedFacts(facts: ValueFacts): ValueFacts[];
75
79
  export declare function fieldFacts(definition: Definition, key: string): ValueFacts | undefined;
76
80
  export declare function pointerFacts(definition: Definition, pointer: string): PointerFacts | undefined;
77
- export declare function readSchema(text: string): VerifiedModel | Failure;
81
+ export declare function readSchema(text: string, provided?: VerifiedModel, checked?: boolean): VerifiedModel | Failure;
78
82
  //# sourceMappingURL=definition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa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OAAO,CAAA;CAAE,GAAG,SAAS,CAoC/D;AAkaD,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,UAAU,CAE7F;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAElF;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAKlF;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,wBAAgB,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;AAqUD,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,aAAwB,EAClC,OAAO,UAAO,GACb,aAAa,GAAG,OAAO,CA0CzB"}
@@ -1,4 +1,5 @@
1
1
  import { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD, TYPE_FIELD } from './fields.js';
2
+ import { linearPattern } from './pattern.js';
2
3
  import { equalValue, isRecord, jsValue, parseYamlMapping, YamlError } from './yaml.js';
3
4
  export const JSON_TYPES = [
4
5
  'string',
@@ -24,16 +25,20 @@ const ANNOTATIONS = new Set([
24
25
  'writeOnly',
25
26
  ]);
26
27
  const FIELD_RULES = ['change_roles', 'initial_roles', 'transitions'];
28
+ const PROVIDED_KEYWORDS = ['create_roles', 'delete_roles'];
29
+ const NO_TYPES = Object.freeze({ types: Object.freeze({}) });
27
30
  const DEFS_REFERENCE = '#/$defs/';
31
+ const UNBOUNDED_FORMAT = 'url';
28
32
  const UNRESOLVED = /[\u0000-\u001f\u007f%[\]\\^{|}]|\s$/u;
29
33
  export const ARRAY_INDEX = /^(?:0|[1-9][0-9]*)$/u;
34
+ export const JSON_POINTER = /^(?:\/(?:[^~/]|~[01])*)*$/u;
30
35
  const HOUSE_KEYS = {
31
36
  [TYPE_FIELD]: { prose: false },
32
37
  [SITE_FIELD]: { prose: false },
33
38
  [RECEIVED_FIELD]: { prose: false },
34
39
  };
35
40
  function refuse(rule, location) {
36
- return location === undefined ? { rule } : { rule, location };
41
+ return { rule, location };
37
42
  }
38
43
  export function escapePointer(key) {
39
44
  return key.replaceAll('~', '~0').replaceAll('/', '~1');
@@ -45,12 +50,12 @@ export function pointerSegments(pointer) {
45
50
  return pointer.split('/').slice(1).map(unescapePointer);
46
51
  }
47
52
  export function refTarget(reference, defs) {
48
- if (!reference.startsWith(DEFS_REFERENCE) || UNRESOLVED.test(reference))
49
- return undefined;
50
- const segments = reference.slice(DEFS_REFERENCE.length).split('/');
51
- const [name = '', ...rest] = segments.map(unescapePointer);
52
- if (segments.some((segment) => escapePointer(unescapePointer(segment)) !== segment))
53
+ const pointer = reference.slice('#'.length);
54
+ if (!reference.startsWith(DEFS_REFERENCE) ||
55
+ UNRESOLVED.test(reference) ||
56
+ !JSON_POINTER.test(pointer))
53
57
  return undefined;
58
+ const [, name = '', ...rest] = pointerSegments(pointer);
54
59
  if (!Object.hasOwn(defs, name))
55
60
  return undefined;
56
61
  let node = defs[name];
@@ -81,15 +86,7 @@ export function refTarget(reference, defs) {
81
86
  return { name, node };
82
87
  }
83
88
  function compiles(pattern) {
84
- if (typeof pattern !== 'string')
85
- return false;
86
- try {
87
- new RegExp(pattern, 'u');
88
- return true;
89
- }
90
- catch {
91
- return false;
92
- }
89
+ return typeof pattern === 'string' && linearPattern(pattern) !== null;
93
90
  }
94
91
  function finite(value) {
95
92
  return typeof value === 'number' && Number.isFinite(value);
@@ -103,7 +100,7 @@ function strings(value) {
103
100
  new Set(value).size === value.length);
104
101
  }
105
102
  function schemaFailure(value, at, context) {
106
- if (typeof value === 'boolean')
103
+ if (!context.checked || typeof value === 'boolean')
107
104
  return undefined;
108
105
  if (!isRecord(value))
109
106
  return refuse('schema', at);
@@ -199,7 +196,7 @@ const KEYWORDS = {
199
196
  uniqueItems: FLAG,
200
197
  required: strings,
201
198
  dependentRequired: (value) => isRecord(value) && Object.values(value).every(strings),
202
- format: TEXT,
199
+ format: (value) => typeof value === 'string' && value !== UNBOUNDED_FORMAT,
203
200
  contentEncoding: TEXT,
204
201
  contentMediaType: TEXT,
205
202
  title: TEXT,
@@ -216,8 +213,12 @@ const KEYWORDS = {
216
213
  return (Array.isArray(named) &&
217
214
  named.length > 0 &&
218
215
  strings(named) &&
219
- named.every((name) => name === BUILT_IN_TYPE || name === ATTACHMENT || context.types.has(name)));
216
+ named.every((name) => name === BUILT_IN_TYPE ||
217
+ name === ATTACHMENT ||
218
+ context.types.has(name) ||
219
+ node.cross_room === true));
220
220
  },
221
+ cross_room: (value, _at, node) => typeof value === 'boolean' && node.reference !== undefined,
221
222
  };
222
223
  function sharedType(values) {
223
224
  if (values.length === 0)
@@ -290,6 +291,7 @@ function joined(left, right) {
290
291
  const format = left.format === right.format ? left.format : undefined;
291
292
  const values = united(left.values, right.values);
292
293
  const reference = united(left.reference, right.reference);
294
+ const crossRoom = left.crossRoom === true || right.crossRoom === true;
293
295
  const items = both(left.items, right.items);
294
296
  const prefix = left.prefix === undefined && right.prefix === undefined
295
297
  ? undefined
@@ -310,6 +312,7 @@ function joined(left, right) {
310
312
  ...(format === undefined ? {} : { format }),
311
313
  ...(values === undefined ? {} : { values }),
312
314
  ...(reference === undefined ? {} : { reference }),
315
+ ...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
313
316
  prose: left.prose && right.prose,
314
317
  ...(prefix === undefined ? {} : { prefix }),
315
318
  ...(items === undefined ? {} : { items }),
@@ -388,6 +391,7 @@ function factsOf(nodes, defs, ancestry) {
388
391
  : Array.isArray(node.reference)
389
392
  ? node.reference
390
393
  : undefined) ?? alternatives.find((facts) => facts.reference !== undefined)?.reference;
394
+ const crossRoom = firstOf(held, (node) => node.reference === undefined ? undefined : node.cross_room === true) ?? alternatives.find((facts) => facts.reference !== undefined)?.crossRoom === true;
391
395
  const format = firstOf(held, (node) => (typeof node.format === 'string' ? node.format : undefined)) ??
392
396
  alternatives.find((facts) => facts.format !== undefined)?.format;
393
397
  const prose = type === 'string' &&
@@ -422,6 +426,7 @@ function factsOf(nodes, defs, ancestry) {
422
426
  ...(format === undefined ? {} : { format }),
423
427
  ...(values === undefined ? {} : { values }),
424
428
  ...(reference === undefined ? {} : { reference }),
429
+ ...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
425
430
  prose,
426
431
  ...(prefix === undefined ? {} : { prefix }),
427
432
  ...(items === undefined ? {} : { items }),
@@ -439,7 +444,7 @@ export function itemFacts(facts, index) {
439
444
  export function memberFacts(facts, key) {
440
445
  if (facts.properties !== undefined && Object.hasOwn(facts.properties, key))
441
446
  return facts.properties[key];
442
- const pattern = facts.patterns?.find((one) => new RegExp(one.pattern, 'u').test(key));
447
+ const pattern = facts.patterns?.find((one) => linearPattern(one.pattern).test(key));
443
448
  return pattern === undefined ? facts.additional : pattern.facts;
444
449
  }
445
450
  export function crossedFacts(facts) {
@@ -542,6 +547,56 @@ function readSections(value, at, context) {
542
547
  }
543
548
  return { sections };
544
549
  }
550
+ function branchSectionsFailure(sections, declared, where) {
551
+ if (!isRecord(sections))
552
+ return refuse('sections', where);
553
+ for (const [name, spec] of Object.entries(sections)) {
554
+ const place = `${where}/${escapePointer(name)}`;
555
+ const own = isRecord(declared) && Object.hasOwn(declared, name) ? declared[name] : undefined;
556
+ if (!isRecord(spec) || !isRecord(own))
557
+ return refuse('sections', place);
558
+ const { required, ...kind } = spec;
559
+ const { required: _required, ...ownKind } = own;
560
+ if (required !== undefined && typeof required !== 'boolean')
561
+ return refuse('sections', `${place}/required`);
562
+ if (!equalValue(kind, ownKind))
563
+ return refuse('sections', place);
564
+ }
565
+ return undefined;
566
+ }
567
+ function withoutBranchSections(schema, declared, at) {
568
+ const kept = { ...schema };
569
+ if (Array.isArray(schema.allOf)) {
570
+ const entries = [];
571
+ for (const [index, entry] of schema.allOf.entries()) {
572
+ const read = isRecord(entry)
573
+ ? withoutBranchSections(entry, declared, `${at}/allOf/${index}`)
574
+ : { schema: entry };
575
+ if ('failure' in read)
576
+ return read;
577
+ entries.push(read.schema);
578
+ }
579
+ kept.allOf = entries;
580
+ }
581
+ if (schema.if === undefined)
582
+ return { schema: kept };
583
+ for (const branch of ['then', 'else']) {
584
+ const held = schema[branch];
585
+ if (!isRecord(held))
586
+ continue;
587
+ const { sections, ...rest } = held;
588
+ const failure = sections === undefined
589
+ ? undefined
590
+ : branchSectionsFailure(sections, declared, `${at}/${branch}/sections`);
591
+ if (failure !== undefined)
592
+ return { failure };
593
+ const read = withoutBranchSections(rest, declared, `${at}/${branch}`);
594
+ if ('failure' in read)
595
+ return read;
596
+ kept[branch] = read.schema;
597
+ }
598
+ return { schema: kept };
599
+ }
545
600
  function deepFreeze(value) {
546
601
  if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
547
602
  Object.freeze(value);
@@ -579,8 +634,9 @@ function composites(node, defs, seen) {
579
634
  const target = typeof node.$ref === 'string' ? refTarget(node.$ref, defs)?.node : undefined;
580
635
  const conditioned = () => {
581
636
  const met = composites(node.then ?? true, defs, seen);
582
- return COMPOSITES.filter((kind) => (composites(node.if, defs, seen).includes(kind) && met.includes(kind)) ||
583
- composites(node.else ?? true, defs, seen).includes(kind));
637
+ const condition = composites(node.if, defs, seen);
638
+ const otherwise = composites(node.else ?? true, defs, seen);
639
+ return COMPOSITES.filter((kind) => (condition.includes(kind) && met.includes(kind)) || otherwise.includes(kind));
584
640
  };
585
641
  const bounds = [
586
642
  typed(node.type),
@@ -649,19 +705,46 @@ function unruled(schema) {
649
705
  }
650
706
  return { schema: written.size === 0 ? schema : { ...schema, properties }, written };
651
707
  }
708
+ function providedType(name, value, provided, checked) {
709
+ const at = `/${escapePointer(name)}`;
710
+ if (checked && provided.nameable?.includes(name) !== true)
711
+ return refuse('provided-type', at);
712
+ if (!isRecord(value))
713
+ return refuse('schema', at);
714
+ const declared = Object.keys(value).find((key) => !PROVIDED_KEYWORDS.includes(key));
715
+ if (checked && declared !== undefined)
716
+ return refuse('provided-type', `${at}/${escapePointer(declared)}`);
717
+ const { create_roles: createRoles, delete_roles: deleteRoles } = value;
718
+ if (createRoles !== undefined && !roleNames(createRoles))
719
+ return refuse('create_roles', `${at}/create_roles`);
720
+ if (deleteRoles !== undefined && !roleNames(deleteRoles))
721
+ return refuse('delete_roles', `${at}/delete_roles`);
722
+ return {
723
+ ...provided.types[name],
724
+ ...(createRoles === undefined ? {} : { createRoles }),
725
+ ...(deleteRoles === undefined ? {} : { deleteRoles }),
726
+ };
727
+ }
652
728
  function readType(name, value, context) {
653
729
  const at = `/${escapePointer(name)}`;
654
730
  if (!isRecord(value))
655
731
  return refuse('schema', at);
656
- const { sections: declared, member_document: mark, ...ruled } = value;
732
+ const { sections: declared, member_document: mark, create_roles: createRoles, delete_roles: deleteRoles, ...ruled } = value;
657
733
  if (mark !== undefined && typeof mark !== 'boolean')
658
734
  return refuse('member_document', `${at}/member_document`);
735
+ if (createRoles !== undefined && !roleNames(createRoles))
736
+ return refuse('create_roles', `${at}/create_roles`);
737
+ if (deleteRoles !== undefined && !roleNames(deleteRoles))
738
+ return refuse('delete_roles', `${at}/delete_roles`);
659
739
  const read = declared === undefined
660
740
  ? { sections: Object.create(null) }
661
741
  : readSections(declared, `${at}/sections`, context);
662
742
  if ('failure' in read)
663
743
  return read.failure;
664
- const { schema, written } = unruled(ruled);
744
+ const unbranched = withoutBranchSections(ruled, declared, at);
745
+ if ('failure' in unbranched)
746
+ return unbranched.failure;
747
+ const { schema, written } = unruled(unbranched.schema);
665
748
  const failure = schemaFailure(schema, at, context);
666
749
  if (failure !== undefined)
667
750
  return failure;
@@ -681,6 +764,7 @@ function readType(name, value, context) {
681
764
  fields[MEMBER_FIELD] = { type: 'string', prose: false };
682
765
  const defs = Object.create(null);
683
766
  reachedDefs(value, context.defs, defs);
767
+ const { create_roles: _create, delete_roles: _delete, ...shaped } = value;
684
768
  return {
685
769
  name,
686
770
  memberDocument,
@@ -688,8 +772,10 @@ function readType(name, value, context) {
688
772
  fields,
689
773
  sections: read.sections,
690
774
  rules,
775
+ ...(createRoles === undefined ? {} : { createRoles }),
776
+ ...(deleteRoles === undefined ? {} : { deleteRoles }),
691
777
  shape: {
692
- schema: written.size === 0 ? value : { ...value, properties: schema.properties },
778
+ schema: written.size === 0 ? shaped : { ...shaped, properties: schema.properties },
693
779
  defs,
694
780
  },
695
781
  };
@@ -697,7 +783,7 @@ function readType(name, value, context) {
697
783
  function lineAt(text, offset) {
698
784
  return text.slice(0, offset).split(/\r\n|\r|\n/).length;
699
785
  }
700
- export function readSchema(text) {
786
+ export function readSchema(text, provided = NO_TYPES, checked = true) {
701
787
  let root;
702
788
  try {
703
789
  root = jsValue(parseYamlMapping(text, 0, text.length));
@@ -711,11 +797,15 @@ export function readSchema(text) {
711
797
  if (!isRecord(defs))
712
798
  return refuse('$defs', '/$defs');
713
799
  const names = Object.keys(root).filter((key) => key !== '$defs');
714
- for (const name of names) {
800
+ for (const name of checked ? names : []) {
715
801
  if (name === '' || name.startsWith('$') || name === BUILT_IN_TYPE || name === ATTACHMENT)
716
802
  return refuse('schema-type-name', `/${escapePointer(name)}`);
717
803
  }
718
- const context = { defs, types: new Set(names) };
804
+ const context = {
805
+ defs,
806
+ types: new Set([...names, ...Object.keys(provided.types)]),
807
+ checked,
808
+ };
719
809
  for (const [name, def] of Object.entries(defs)) {
720
810
  const failure = schemaFailure(def, `/$defs/${escapePointer(name)}`, context);
721
811
  if (failure !== undefined)
@@ -724,15 +814,21 @@ export function readSchema(text) {
724
814
  const types = Object.create(null);
725
815
  let marked = false;
726
816
  for (const name of names) {
727
- const definition = readType(name, root[name], context);
817
+ const definition = Object.hasOwn(provided.types, name)
818
+ ? providedType(name, root[name], provided, checked)
819
+ : readType(name, root[name], context);
728
820
  if ('rule' in definition)
729
821
  return definition;
730
- if (definition.memberDocument) {
822
+ if (checked && definition.memberDocument) {
731
823
  if (marked)
732
824
  return refuse('member_document', `/${escapePointer(name)}/member_document`);
733
825
  marked = true;
734
826
  }
735
827
  types[name] = deepFreeze(definition);
736
828
  }
829
+ for (const [name, definition] of Object.entries(provided.types)) {
830
+ if (!Object.hasOwn(types, name))
831
+ types[name] = definition;
832
+ }
737
833
  return Object.freeze({ types: Object.freeze(types) });
738
834
  }
@@ -1 +1 @@
1
- {"version":3,"file":"divide.d.ts","sourceRoot":"","sources":["../src/divide.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAgB,MAAM,YAAY,CAAC;AA4WpF,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,QAAQ,CAc3F"}
1
+ {"version":3,"file":"divide.d.ts","sourceRoot":"","sources":["../src/divide.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAgB,MAAM,YAAY,CAAC;AAwXpF,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,QAAQ,CAc3F"}
package/dist/divide.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { blockRanges, headingLines } from './blocks.js';
2
- import { projectionInput, rangeText } from './project.js';
2
+ import { firstEditFrom, projectionInput, rangeText, } from './project.js';
3
3
  import { refusal } from './refuse.js';
4
- const SMALLEST_BUDGET = 2;
4
+ const SMALLEST_BOUND = 2;
5
5
  function node(draft) {
6
6
  return {
7
7
  start: draft.start,
@@ -86,8 +86,8 @@ function isTrailingSurrogate(text, index) {
86
86
  function characterLength(text, index) {
87
87
  return isTrailingSurrogate(text, index + 1) ? 2 : 1;
88
88
  }
89
- function boundOf(cutting, from, to, budget) {
90
- const limit = from + budget;
89
+ function boundOf(cutting, from, to, bound) {
90
+ const limit = from + bound;
91
91
  if (limit >= to)
92
92
  return to;
93
93
  for (let index = limit; index > from + 1; index -= 1) {
@@ -131,16 +131,26 @@ function textOf(state, extent) {
131
131
  return rangeText(state.content, extent, state.edits);
132
132
  }
133
133
  function sourceCutting(state, extent) {
134
- let text = state.content.slice(extent.start, extent.end);
134
+ const source = state.content.slice(extent.start, extent.end);
135
135
  const masks = [];
136
- for (const edit of state.edits) {
137
- if (edit.start < extent.start || edit.end > extent.end)
136
+ for (let index = firstEditFrom(state.edits, extent.start); index < state.edits.length; index += 1) {
137
+ const edit = state.edits[index];
138
+ if (edit.start > extent.end)
139
+ break;
140
+ if (edit.end > extent.end)
138
141
  continue;
139
- const from = edit.start - extent.start;
140
- const to = edit.end - extent.start;
141
- text = `${text.slice(0, from)}${'x'.repeat(to - from)}${text.slice(to)}`;
142
- masks.push({ start: from, end: to });
142
+ masks.push({ start: edit.start - extent.start, end: edit.end - extent.start });
143
143
  }
144
+ let text = '';
145
+ let cursor = 0;
146
+ for (const mask of masks) {
147
+ if (mask.end <= cursor)
148
+ continue;
149
+ const from = Math.max(mask.start, cursor);
150
+ text += `${source.slice(cursor, from)}${'x'.repeat(mask.end - from)}`;
151
+ cursor = mask.end;
152
+ }
153
+ text += source.slice(cursor);
144
154
  return {
145
155
  text,
146
156
  masks,
@@ -158,12 +168,12 @@ function valueCutting(value) {
158
168
  };
159
169
  }
160
170
  function prefixOf(state, body) {
161
- if (body.emitted === 0 || body.heading.length >= state.budget)
171
+ if (body.emitted === 0 || body.heading.length >= state.bound)
162
172
  return '';
163
173
  return body.heading;
164
174
  }
165
175
  function available(state, body) {
166
- return state.budget - prefixOf(state, body).length;
176
+ return state.bound - prefixOf(state, body).length;
167
177
  }
168
178
  function emit(state, body, piece, bare = false) {
169
179
  if (piece.text.trim() === '')
@@ -206,7 +216,7 @@ function divideBound(state, body, cutting, range) {
206
216
  let start = range.start;
207
217
  while (start < range.end) {
208
218
  const bare = available(state, body) < characterLength(cutting.text, start);
209
- const room = bare ? state.budget : available(state, body);
219
+ const room = bare ? state.bound : available(state, body);
210
220
  const stop = boundOf(cutting, start, range.end, room);
211
221
  const piece = cutting.piece(start, stop);
212
222
  if (cutting.masks.length === 0 || piece.text.length <= room) {
@@ -293,8 +303,8 @@ function divideInput(state, input) {
293
303
  ]);
294
304
  }
295
305
  export function divide(document, file, context) {
296
- if (!Number.isInteger(context.budget) || context.budget < SMALLEST_BUDGET) {
297
- return { ok: false, refusal: refusal(file, 'division-budget') };
306
+ if (!Number.isInteger(context.bound) || context.bound < SMALLEST_BOUND) {
307
+ return { ok: false, refusal: refusal(file, 'division-bound') };
298
308
  }
299
309
  const result = projectionInput(document, file, context);
300
310
  if (!result.ok)
@@ -302,7 +312,7 @@ export function divide(document, file, context) {
302
312
  const state = {
303
313
  content: document.content,
304
314
  edits: result.input.edits,
305
- budget: context.budget,
315
+ bound: context.bound,
306
316
  spans: [],
307
317
  };
308
318
  divideInput(state, result.input);