@agentshouse/mdmodel 0.1.0-ccf1367190878 → 0.1.0-cd5ace6e0b27a

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 (177) hide show
  1. package/API.md +232 -182
  2. package/README.md +21 -22
  3. package/dist/definition.d.ts +18 -1
  4. package/dist/definition.d.ts.map +1 -1
  5. package/dist/definition.js +176 -48
  6. package/dist/divide.d.ts.map +1 -1
  7. package/dist/divide.js +32 -21
  8. package/dist/document.d.ts +10 -6
  9. package/dist/document.d.ts.map +1 -1
  10. package/dist/document.js +424 -207
  11. package/dist/event.d.ts +78 -0
  12. package/dist/event.d.ts.map +1 -0
  13. package/dist/event.js +201 -0
  14. package/dist/facts.d.ts +15 -0
  15. package/dist/facts.d.ts.map +1 -0
  16. package/dist/facts.js +41 -0
  17. package/dist/form.d.ts +4 -0
  18. package/dist/form.d.ts.map +1 -0
  19. package/dist/form.js +139 -0
  20. package/dist/index.d.ts +25 -11
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +15 -8
  23. package/dist/kinds.d.ts +18 -0
  24. package/dist/kinds.d.ts.map +1 -0
  25. package/dist/kinds.js +150 -0
  26. package/dist/markdown.d.ts +51 -0
  27. package/dist/markdown.d.ts.map +1 -0
  28. package/dist/markdown.js +271 -0
  29. package/dist/paths.d.ts +18 -2
  30. package/dist/paths.d.ts.map +1 -1
  31. package/dist/paths.js +69 -15
  32. package/dist/pattern.d.ts +10 -0
  33. package/dist/pattern.d.ts.map +1 -0
  34. package/dist/pattern.js +356 -0
  35. package/dist/project.d.ts +1 -0
  36. package/dist/project.d.ts.map +1 -1
  37. package/dist/project.js +44 -26
  38. package/dist/query/language.d.ts +254 -0
  39. package/dist/query/language.d.ts.map +1 -0
  40. package/dist/query/language.js +620 -0
  41. package/dist/query/match.d.ts +14 -0
  42. package/dist/query/match.d.ts.map +1 -0
  43. package/dist/query/match.js +150 -0
  44. package/dist/query/rows.d.ts +32 -0
  45. package/dist/query/rows.d.ts.map +1 -0
  46. package/dist/query/rows.js +161 -0
  47. package/dist/query/sql.d.ts +39 -0
  48. package/dist/query/sql.d.ts.map +1 -0
  49. package/dist/query/sql.js +285 -0
  50. package/dist/references.d.ts.map +1 -1
  51. package/dist/references.js +6 -1
  52. package/dist/reserved.d.ts +6 -0
  53. package/dist/reserved.d.ts.map +1 -0
  54. package/dist/reserved.js +21 -0
  55. package/dist/schema.d.ts +1 -0
  56. package/dist/schema.d.ts.map +1 -1
  57. package/dist/schema.js +55 -4
  58. package/dist/types.d.ts +46 -5
  59. package/dist/types.d.ts.map +1 -1
  60. package/dist/validate.d.ts +31 -4
  61. package/dist/validate.d.ts.map +1 -1
  62. package/dist/validate.js +387 -129
  63. package/dist/yaml.d.ts.map +1 -1
  64. package/dist/yaml.js +40 -14
  65. package/fixtures/README.md +34 -7
  66. package/fixtures/cases/conditional-section/context.json +1 -0
  67. package/fixtures/cases/conditional-section/expected.json +6 -0
  68. package/fixtures/cases/conditional-section/library/questions/hosting.md +9 -0
  69. package/fixtures/cases/conditional-section/library/questions/payments.md +12 -0
  70. package/fixtures/cases/conditional-section/schema.yaml +14 -0
  71. package/fixtures/cases/cross-room-link/context.json +1 -0
  72. package/fixtures/cases/cross-room-link/expected.json +1 -0
  73. package/fixtures/cases/cross-room-link/library/clients/acme.md +6 -0
  74. package/fixtures/cases/cross-room-link/schema.yaml +3 -0
  75. package/fixtures/cases/cross-room-reference/context.json +1 -0
  76. package/fixtures/cases/cross-room-reference/expected.json +1 -0
  77. package/fixtures/cases/cross-room-reference/library/clients/acme.md +9 -0
  78. package/fixtures/cases/cross-room-reference/schema.yaml +9 -0
  79. package/fixtures/cases/equal-labels/context.json +1 -0
  80. package/fixtures/cases/equal-labels/expected.json +5 -0
  81. package/fixtures/cases/equal-labels/schema.yaml +4 -0
  82. package/fixtures/cases/labels-in-the-rooms-language/context.json +1 -0
  83. package/fixtures/cases/labels-in-the-rooms-language/expected.json +1 -0
  84. package/fixtures/cases/labels-in-the-rooms-language/library/deals/atlas.md +6 -0
  85. package/fixtures/cases/labels-in-the-rooms-language/schema.yaml +9 -0
  86. package/fixtures/cases/lazy-list-item/context.json +1 -0
  87. package/fixtures/cases/lazy-list-item/expected.json +3 -0
  88. package/fixtures/cases/lazy-list-item/library/item.md +8 -0
  89. package/fixtures/cases/lazy-list-item/schema.yaml +3 -0
  90. package/fixtures/cases/link-into-a-reserved-name/context.json +1 -0
  91. package/fixtures/cases/link-into-a-reserved-name/expected.json +5 -0
  92. package/fixtures/cases/link-into-a-reserved-name/library/notes/a.md +6 -0
  93. package/fixtures/cases/link-into-a-reserved-name/schema.yaml +3 -0
  94. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/context.json +1 -0
  95. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/expected.json +5 -0
  96. package/fixtures/cases/link-into-a-reserved-name-from-an-untyped-document/library/notes/b.md +5 -0
  97. package/fixtures/cases/long-value-past-six-levels/context.json +1 -0
  98. package/fixtures/cases/long-value-past-six-levels/expected.json +5 -0
  99. package/fixtures/cases/long-value-past-six-levels/schema.yaml +15 -0
  100. package/fixtures/cases/member-on-an-untyped-document/context.json +1 -0
  101. package/fixtures/cases/member-on-an-untyped-document/expected.json +6 -0
  102. package/fixtures/cases/member-on-an-untyped-document/library/note.md +4 -0
  103. package/fixtures/cases/member-on-another-type/context.json +1 -0
  104. package/fixtures/cases/member-on-another-type/expected.json +6 -0
  105. package/fixtures/cases/member-on-another-type/library/note.md +4 -0
  106. package/fixtures/cases/member-on-another-type/schema.yaml +7 -0
  107. package/fixtures/cases/name-not-a-string/context.json +1 -0
  108. package/fixtures/cases/name-not-a-string/expected.json +5 -0
  109. package/fixtures/cases/name-not-a-string/schema.yaml +5 -0
  110. package/fixtures/cases/one-key-two-labels/context.json +1 -0
  111. package/fixtures/cases/one-key-two-labels/expected.json +5 -0
  112. package/fixtures/cases/one-key-two-labels/schema.yaml +5 -0
  113. package/fixtures/cases/one-key-two-types/context.json +1 -0
  114. package/fixtures/cases/one-key-two-types/expected.json +5 -0
  115. package/fixtures/cases/one-key-two-types/schema.yaml +4 -0
  116. package/fixtures/cases/reference-into-a-reserved-name/context.json +1 -0
  117. package/fixtures/cases/reference-into-a-reserved-name/expected.json +6 -0
  118. package/fixtures/cases/reference-into-a-reserved-name/library/notes/a.md +4 -0
  119. package/fixtures/cases/reference-into-a-reserved-name/library/settings/brief.md +1 -0
  120. package/fixtures/cases/reference-into-a-reserved-name/schema.yaml +3 -0
  121. package/fixtures/cases/room-md-declares-a-type/context.json +1 -0
  122. package/fixtures/cases/room-md-declares-a-type/expected.json +6 -0
  123. package/fixtures/cases/room-md-declares-a-type/library/ROOM.md +5 -0
  124. package/fixtures/cases/thematic-break-in-a-list-section/context.json +1 -0
  125. package/fixtures/cases/thematic-break-in-a-list-section/expected.json +6 -0
  126. package/fixtures/cases/thematic-break-in-a-list-section/library/item.md +7 -0
  127. package/fixtures/cases/thematic-break-in-a-list-section/schema.yaml +3 -0
  128. package/fixtures/cases/typed-path-names-another-type/context.json +11 -0
  129. package/fixtures/cases/typed-path-names-another-type/expected.json +6 -0
  130. package/fixtures/cases/typed-path-names-another-type/library/settings/prefs/one.md +3 -0
  131. package/fixtures/cases/typed-path-names-another-type/schema.yaml +6 -0
  132. package/fixtures/cases/typed-path-names-its-type/context.json +11 -0
  133. package/fixtures/cases/typed-path-names-its-type/expected.json +3 -0
  134. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/deeper/two.md +1 -0
  135. package/fixtures/cases/typed-path-names-its-type/library/settings/prefs/one.md +4 -0
  136. package/fixtures/cases/typed-path-names-its-type/schema.yaml +6 -0
  137. package/fixtures/cases/typed-path-names-no-type/context.json +11 -0
  138. package/fixtures/cases/typed-path-names-no-type/expected.json +6 -0
  139. package/fixtures/cases/typed-path-names-no-type/library/settings/prefs/one.md +1 -0
  140. package/fixtures/cases/typed-path-names-no-type/schema.yaml +6 -0
  141. package/fixtures/cases/unnamed-typed-path-checks-its-fields/context.json +11 -0
  142. package/fixtures/cases/unnamed-typed-path-checks-its-fields/expected.json +6 -0
  143. package/fixtures/cases/unnamed-typed-path-checks-its-fields/library/rooms/team/tasks/plan.md +4 -0
  144. package/fixtures/cases/unnamed-typed-path-checks-its-fields/schema.yaml +5 -0
  145. package/fixtures/cases/unnamed-typed-path-names-a-type/context.json +11 -0
  146. package/fixtures/cases/unnamed-typed-path-names-a-type/expected.json +6 -0
  147. package/fixtures/cases/unnamed-typed-path-names-a-type/library/rooms/team/tasks/plan.md +6 -0
  148. package/fixtures/cases/unnamed-typed-path-names-a-type/schema.yaml +5 -0
  149. package/fixtures/cases/unnamed-typed-path-reads-its-type/context.json +11 -0
  150. package/fixtures/cases/unnamed-typed-path-reads-its-type/expected.json +3 -0
  151. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/plan.md +1 -0
  152. package/fixtures/cases/unnamed-typed-path-reads-its-type/library/rooms/team/tasks/plan.md +5 -0
  153. package/fixtures/cases/unnamed-typed-path-reads-its-type/schema.yaml +5 -0
  154. package/fixtures/cases/unnamed-typed-path-without-a-body/context.json +11 -0
  155. package/fixtures/cases/unnamed-typed-path-without-a-body/expected.json +5 -0
  156. package/fixtures/cases/unnamed-typed-path-without-a-body/library/rooms/team/tasks/plan.md +5 -0
  157. package/fixtures/cases/unnamed-typed-path-without-a-body/schema.yaml +5 -0
  158. package/fixtures/division.json +73 -28
  159. package/fixtures/preamble.json +24 -3
  160. package/fixtures/projection.json +105 -2
  161. package/fixtures/queries.json +964 -0
  162. package/package.json +16 -2
  163. package/dist/blocks.d.ts +0 -11
  164. package/dist/blocks.d.ts.map +0 -1
  165. package/dist/blocks.js +0 -76
  166. package/dist/condition.d.ts +0 -149
  167. package/dist/condition.d.ts.map +0 -1
  168. package/dist/condition.js +0 -500
  169. package/dist/links.d.ts +0 -27
  170. package/dist/links.d.ts.map +0 -1
  171. package/dist/links.js +0 -774
  172. package/dist/profile.d.ts +0 -6
  173. package/dist/profile.d.ts.map +0 -1
  174. package/dist/profile.js +0 -5
  175. package/dist/sections.d.ts +0 -11
  176. package/dist/sections.d.ts.map +0 -1
  177. package/dist/sections.js +0 -57
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).
@@ -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[];
@@ -55,16 +56,31 @@ export type Failure = {
55
56
  readonly rule: string;
56
57
  readonly location?: string;
57
58
  };
59
+ export type Placed = {
60
+ readonly node: Record<string, unknown>;
61
+ readonly at: string;
62
+ };
58
63
  export declare const JSON_TYPES: readonly JsonType[];
59
64
  export declare const BUILT_IN_TYPE = "any";
60
65
  export declare const ATTACHMENT = "attachment";
66
+ export declare const OPENING: readonly string[];
61
67
  export declare const ARRAY_INDEX: RegExp;
68
+ export declare const JSON_POINTER: RegExp;
69
+ export declare function refuse(rule: string, location: string): Failure;
62
70
  export declare function escapePointer(key: string): string;
63
71
  export declare function pointerSegments(pointer: string): string[];
64
72
  export declare function refTarget(reference: string, defs: Readonly<Record<string, unknown>>): {
65
73
  readonly name: string;
66
74
  readonly node: unknown;
67
75
  } | undefined;
76
+ export declare function conjoined(declared: readonly {
77
+ readonly node: unknown;
78
+ readonly at: string;
79
+ }[], defs: Readonly<Record<string, unknown>>, ancestry: ReadonlySet<unknown>): {
80
+ readonly held: readonly Placed[];
81
+ readonly ancestry: ReadonlySet<unknown>;
82
+ };
83
+ export declare function variantsOf({ node, at }: Placed): Placed[];
68
84
  export declare function valueFacts(node: unknown, defs: Readonly<Record<string, unknown>>): ValueFacts;
69
85
  export declare function itemFacts(facts: ValueFacts, index: number): ValueFacts | undefined;
70
86
  export declare function memberFacts(facts: ValueFacts, key: string): ValueFacts | undefined;
@@ -76,5 +92,6 @@ export type PointerFacts = {
76
92
  export declare function crossedFacts(facts: ValueFacts): ValueFacts[];
77
93
  export declare function fieldFacts(definition: Definition, key: string): ValueFacts | undefined;
78
94
  export declare function pointerFacts(definition: Definition, pointer: string): PointerFacts | undefined;
79
- export declare function readSchema(text: string): VerifiedModel | Failure;
95
+ export declare function untitled(definition: Definition): Definition;
96
+ export declare function readSchema(text: string, provided?: VerifiedModel, checked?: boolean): VerifiedModel | Failure;
80
97
  //# 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,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,MAA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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;AAgID,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAQ3D;AAyND,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',
@@ -23,17 +24,22 @@ const ANNOTATIONS = new Set([
23
24
  'readOnly',
24
25
  'writeOnly',
25
26
  ]);
27
+ export const OPENING = ['additionalProperties', 'unevaluatedProperties'];
26
28
  const FIELD_RULES = ['change_roles', 'initial_roles', 'transitions'];
29
+ const PROVIDED_KEYWORDS = ['create_roles', 'delete_roles'];
30
+ const NO_TYPES = Object.freeze({ types: Object.freeze({}) });
27
31
  const DEFS_REFERENCE = '#/$defs/';
32
+ const UNBOUNDED_FORMAT = 'url';
28
33
  const UNRESOLVED = /[\u0000-\u001f\u007f%[\]\\^{|}]|\s$/u;
29
34
  export const ARRAY_INDEX = /^(?:0|[1-9][0-9]*)$/u;
35
+ export const JSON_POINTER = /^(?:\/(?:[^~/]|~[01])*)*$/u;
30
36
  const HOUSE_KEYS = {
31
37
  [TYPE_FIELD]: { prose: false },
32
38
  [SITE_FIELD]: { prose: false },
33
39
  [RECEIVED_FIELD]: { prose: false },
34
40
  };
35
- function refuse(rule, location) {
36
- return location === undefined ? { rule } : { rule, location };
41
+ export function refuse(rule, location) {
42
+ return { rule, location };
37
43
  }
38
44
  export function escapePointer(key) {
39
45
  return key.replaceAll('~', '~0').replaceAll('/', '~1');
@@ -45,12 +51,12 @@ export function pointerSegments(pointer) {
45
51
  return pointer.split('/').slice(1).map(unescapePointer);
46
52
  }
47
53
  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))
54
+ const pointer = reference.slice('#'.length);
55
+ if (!reference.startsWith(DEFS_REFERENCE) ||
56
+ UNRESOLVED.test(reference) ||
57
+ !JSON_POINTER.test(pointer))
53
58
  return undefined;
59
+ const [, name = '', ...rest] = pointerSegments(pointer);
54
60
  if (!Object.hasOwn(defs, name))
55
61
  return undefined;
56
62
  let node = defs[name];
@@ -81,15 +87,7 @@ export function refTarget(reference, defs) {
81
87
  return { name, node };
82
88
  }
83
89
  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
- }
90
+ return typeof pattern === 'string' && linearPattern(pattern) !== null;
93
91
  }
94
92
  function finite(value) {
95
93
  return typeof value === 'number' && Number.isFinite(value);
@@ -103,7 +101,7 @@ function strings(value) {
103
101
  new Set(value).size === value.length);
104
102
  }
105
103
  function schemaFailure(value, at, context) {
106
- if (typeof value === 'boolean')
104
+ if (!context.checked || typeof value === 'boolean')
107
105
  return undefined;
108
106
  if (!isRecord(value))
109
107
  return refuse('schema', at);
@@ -199,7 +197,7 @@ const KEYWORDS = {
199
197
  uniqueItems: FLAG,
200
198
  required: strings,
201
199
  dependentRequired: (value) => isRecord(value) && Object.values(value).every(strings),
202
- format: TEXT,
200
+ format: (value) => typeof value === 'string' && value !== UNBOUNDED_FORMAT,
203
201
  contentEncoding: TEXT,
204
202
  contentMediaType: TEXT,
205
203
  title: TEXT,
@@ -216,8 +214,12 @@ const KEYWORDS = {
216
214
  return (Array.isArray(named) &&
217
215
  named.length > 0 &&
218
216
  strings(named) &&
219
- named.every((name) => name === BUILT_IN_TYPE || name === ATTACHMENT || context.types.has(name)));
217
+ named.every((name) => name === BUILT_IN_TYPE ||
218
+ name === ATTACHMENT ||
219
+ context.types.has(name) ||
220
+ node.cross_room === true));
220
221
  },
222
+ cross_room: (value, _at, node) => typeof value === 'boolean' && node.reference !== undefined,
221
223
  };
222
224
  function sharedType(values) {
223
225
  if (values.length === 0)
@@ -246,36 +248,41 @@ function firstOf(held, read) {
246
248
  }
247
249
  return undefined;
248
250
  }
249
- function conjoined(nodes, defs, ancestry) {
251
+ export function conjoined(declared, defs, ancestry) {
250
252
  const held = [];
251
253
  const reached = new Set(ancestry);
252
- const visit = (node) => {
253
- if (!isRecord(node) || held.includes(node))
254
+ const visit = (node, at) => {
255
+ if (!isRecord(node) || held.some((one) => one.node === node))
254
256
  return;
255
- held.push(node);
257
+ held.push({ node, at });
256
258
  if (typeof node.$ref === 'string') {
257
259
  const target = refTarget(node.$ref, defs)?.node;
258
260
  if (target !== undefined && !reached.has(target)) {
259
261
  reached.add(target);
260
- visit(target);
262
+ visit(target, node.$ref.slice('#'.length));
261
263
  }
262
264
  }
263
265
  if (Array.isArray(node.allOf))
264
- for (const one of node.allOf)
265
- visit(one);
266
+ node.allOf.forEach((one, index) => visit(one, `${at}/allOf/${index}`));
266
267
  };
267
- for (const node of nodes)
268
- visit(node);
268
+ for (const { node, at } of declared)
269
+ visit(node, at);
269
270
  return { held, ancestry: reached };
270
271
  }
271
- function variantsOf(node) {
272
+ export function variantsOf({ node, at }) {
273
+ const listed = (keyword) => {
274
+ const branches = node[keyword];
275
+ return Array.isArray(branches)
276
+ ? branches.map((branch, index) => ({ node: branch, at: `${at}/${keyword}/${index}` }))
277
+ : [];
278
+ };
272
279
  return [
273
- ...(Array.isArray(node.anyOf) ? node.anyOf : []),
274
- ...(Array.isArray(node.oneOf) ? node.oneOf : []),
275
- node.then,
276
- node.else,
277
- ...(isRecord(node.dependentSchemas) ? Object.values(node.dependentSchemas) : []),
278
- ].filter(isRecord);
280
+ ...listed('anyOf'),
281
+ ...listed('oneOf'),
282
+ { node: node.then, at: `${at}/then` },
283
+ { node: node.else, at: `${at}/else` },
284
+ ...Object.entries(isRecord(node.dependentSchemas) ? node.dependentSchemas : {}).map(([key, branch]) => ({ node: branch, at: `${at}/dependentSchemas/${escapePointer(key)}` })),
285
+ ].filter((one) => isRecord(one.node));
279
286
  }
280
287
  function united(left, right) {
281
288
  if (left === undefined || right === undefined)
@@ -290,6 +297,7 @@ function joined(left, right) {
290
297
  const format = left.format === right.format ? left.format : undefined;
291
298
  const values = united(left.values, right.values);
292
299
  const reference = united(left.reference, right.reference);
300
+ const crossRoom = left.crossRoom === true || right.crossRoom === true;
293
301
  const items = both(left.items, right.items);
294
302
  const prefix = left.prefix === undefined && right.prefix === undefined
295
303
  ? undefined
@@ -310,6 +318,7 @@ function joined(left, right) {
310
318
  ...(format === undefined ? {} : { format }),
311
319
  ...(values === undefined ? {} : { values }),
312
320
  ...(reference === undefined ? {} : { reference }),
321
+ ...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
313
322
  prose: left.prose && right.prose,
314
323
  ...(prefix === undefined ? {} : { prefix }),
315
324
  ...(items === undefined ? {} : { items }),
@@ -366,11 +375,13 @@ function inheritedOf(held) {
366
375
  });
367
376
  }
368
377
  function factsOf(nodes, defs, ancestry) {
369
- const { held, ancestry: reached } = conjoined(nodes, defs, ancestry);
378
+ const conjunction = conjoined(nodes.map((node) => ({ node, at: '' })), defs, ancestry);
379
+ const reached = conjunction.ancestry;
380
+ const held = conjunction.held.map(({ node }) => node);
370
381
  const inherited = inheritedOf(held);
371
- const variants = new Map(held
382
+ const variants = new Map(conjunction.held
372
383
  .flatMap(variantsOf)
373
- .map((branch) => [branch, factsOf([branch, ...inherited], defs, reached)]));
384
+ .map(({ node: branch }) => [branch, factsOf([branch, ...inherited], defs, reached)]));
374
385
  const unions = alternativesOf(held, variants);
375
386
  const alternatives = unions.map((kept) => kept.reduce(joined));
376
387
  const listed = [
@@ -388,6 +399,7 @@ function factsOf(nodes, defs, ancestry) {
388
399
  : Array.isArray(node.reference)
389
400
  ? node.reference
390
401
  : undefined) ?? alternatives.find((facts) => facts.reference !== undefined)?.reference;
402
+ const crossRoom = firstOf(held, (node) => node.reference === undefined ? undefined : node.cross_room === true) ?? alternatives.find((facts) => facts.reference !== undefined)?.crossRoom === true;
391
403
  const format = firstOf(held, (node) => (typeof node.format === 'string' ? node.format : undefined)) ??
392
404
  alternatives.find((facts) => facts.format !== undefined)?.format;
393
405
  const prose = type === 'string' &&
@@ -414,7 +426,7 @@ function factsOf(nodes, defs, ancestry) {
414
426
  ? held.flatMap((node) => Object.entries(isRecord(node.patternProperties) ? node.patternProperties : {}).map(([pattern, schema]) => ({ pattern, facts: factsOf([schema], defs, reached) })))
415
427
  : [];
416
428
  const opened = mapped
417
- ? held.flatMap((node) => [node.additionalProperties, node.unevaluatedProperties].filter(isRecord))
429
+ ? held.flatMap((node) => OPENING.map((keyword) => node[keyword]).filter(isRecord))
418
430
  : [];
419
431
  const additional = opened.length === 0 ? undefined : factsOf(opened, defs, reached);
420
432
  return {
@@ -422,6 +434,7 @@ function factsOf(nodes, defs, ancestry) {
422
434
  ...(format === undefined ? {} : { format }),
423
435
  ...(values === undefined ? {} : { values }),
424
436
  ...(reference === undefined ? {} : { reference }),
437
+ ...(reference !== undefined && crossRoom ? { crossRoom: true } : {}),
425
438
  prose,
426
439
  ...(prefix === undefined ? {} : { prefix }),
427
440
  ...(items === undefined ? {} : { items }),
@@ -439,7 +452,7 @@ export function itemFacts(facts, index) {
439
452
  export function memberFacts(facts, key) {
440
453
  if (facts.properties !== undefined && Object.hasOwn(facts.properties, key))
441
454
  return facts.properties[key];
442
- const pattern = facts.patterns?.find((one) => new RegExp(one.pattern, 'u').test(key));
455
+ const pattern = facts.patterns?.find((one) => linearPattern(one.pattern).test(key));
443
456
  return pattern === undefined ? facts.additional : pattern.facts;
444
457
  }
445
458
  export function crossedFacts(facts) {
@@ -542,6 +555,87 @@ function readSections(value, at, context) {
542
555
  }
543
556
  return { sections };
544
557
  }
558
+ function branchSectionsFailure(sections, declared, where) {
559
+ if (!isRecord(sections))
560
+ return refuse('sections', where);
561
+ for (const [name, spec] of Object.entries(sections)) {
562
+ const place = `${where}/${escapePointer(name)}`;
563
+ const own = isRecord(declared) && Object.hasOwn(declared, name) ? declared[name] : undefined;
564
+ if (!isRecord(spec) || !isRecord(own))
565
+ return refuse('sections', place);
566
+ const { required, ...kind } = spec;
567
+ const { required: _required, ...ownKind } = own;
568
+ if (required !== undefined && typeof required !== 'boolean')
569
+ return refuse('sections', `${place}/required`);
570
+ if (!equalValue(kind, ownKind))
571
+ return refuse('sections', place);
572
+ }
573
+ return undefined;
574
+ }
575
+ function withoutBranchSections(schema, declared, at) {
576
+ const kept = { ...schema };
577
+ if (Array.isArray(schema.allOf)) {
578
+ const entries = [];
579
+ for (const [index, entry] of schema.allOf.entries()) {
580
+ const read = isRecord(entry)
581
+ ? withoutBranchSections(entry, declared, `${at}/allOf/${index}`)
582
+ : { schema: entry };
583
+ if ('failure' in read)
584
+ return read;
585
+ entries.push(read.schema);
586
+ }
587
+ kept.allOf = entries;
588
+ }
589
+ if (schema.if === undefined)
590
+ return { schema: kept };
591
+ for (const branch of ['then', 'else']) {
592
+ const held = schema[branch];
593
+ if (!isRecord(held))
594
+ continue;
595
+ const { sections, ...rest } = held;
596
+ const failure = sections === undefined
597
+ ? undefined
598
+ : branchSectionsFailure(sections, declared, `${at}/${branch}/sections`);
599
+ if (failure !== undefined)
600
+ return { failure };
601
+ const read = withoutBranchSections(rest, declared, `${at}/${branch}`);
602
+ if ('failure' in read)
603
+ return read;
604
+ kept[branch] = read.schema;
605
+ }
606
+ return { schema: kept };
607
+ }
608
+ function untitledSchema(node) {
609
+ if (!isRecord(node))
610
+ return node;
611
+ const kept = {};
612
+ for (const [key, held] of Object.entries(node)) {
613
+ if (key === 'title' && typeof held === 'string')
614
+ continue;
615
+ const check = Object.hasOwn(KEYWORDS, key) ? KEYWORDS[key] : undefined;
616
+ if (check === SCHEMA)
617
+ kept[key] = untitledSchema(held);
618
+ else if (check === SCHEMA_LIST && Array.isArray(held))
619
+ kept[key] = held.map(untitledSchema);
620
+ else if (check === SCHEMA_MAP && isRecord(held))
621
+ kept[key] = untitledMap(held);
622
+ else
623
+ kept[key] = held;
624
+ }
625
+ return kept;
626
+ }
627
+ function untitledMap(map) {
628
+ return Object.fromEntries(Object.entries(map).map(([key, held]) => [key, untitledSchema(held)]));
629
+ }
630
+ export function untitled(definition) {
631
+ return {
632
+ ...definition,
633
+ shape: {
634
+ schema: untitledSchema(definition.shape.schema),
635
+ defs: untitledMap(definition.shape.defs),
636
+ },
637
+ };
638
+ }
545
639
  function deepFreeze(value) {
546
640
  if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
547
641
  Object.freeze(value);
@@ -579,8 +673,9 @@ function composites(node, defs, seen) {
579
673
  const target = typeof node.$ref === 'string' ? refTarget(node.$ref, defs)?.node : undefined;
580
674
  const conditioned = () => {
581
675
  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));
676
+ const condition = composites(node.if, defs, seen);
677
+ const otherwise = composites(node.else ?? true, defs, seen);
678
+ return COMPOSITES.filter((kind) => (condition.includes(kind) && met.includes(kind)) || otherwise.includes(kind));
584
679
  };
585
680
  const bounds = [
586
681
  typed(node.type),
@@ -649,6 +744,26 @@ function unruled(schema) {
649
744
  }
650
745
  return { schema: written.size === 0 ? schema : { ...schema, properties }, written };
651
746
  }
747
+ function providedType(name, value, provided, checked) {
748
+ const at = `/${escapePointer(name)}`;
749
+ if (checked && provided.nameable?.includes(name) !== true)
750
+ return refuse('provided-type', at);
751
+ if (!isRecord(value))
752
+ return refuse('schema', at);
753
+ const declared = Object.keys(value).find((key) => !PROVIDED_KEYWORDS.includes(key));
754
+ if (checked && declared !== undefined)
755
+ return refuse('provided-type', `${at}/${escapePointer(declared)}`);
756
+ const { create_roles: createRoles, delete_roles: deleteRoles } = value;
757
+ if (createRoles !== undefined && !roleNames(createRoles))
758
+ return refuse('create_roles', `${at}/create_roles`);
759
+ if (deleteRoles !== undefined && !roleNames(deleteRoles))
760
+ return refuse('delete_roles', `${at}/delete_roles`);
761
+ return {
762
+ ...provided.types[name],
763
+ ...(createRoles === undefined ? {} : { createRoles }),
764
+ ...(deleteRoles === undefined ? {} : { deleteRoles }),
765
+ };
766
+ }
652
767
  function readType(name, value, context) {
653
768
  const at = `/${escapePointer(name)}`;
654
769
  if (!isRecord(value))
@@ -665,7 +780,10 @@ function readType(name, value, context) {
665
780
  : readSections(declared, `${at}/sections`, context);
666
781
  if ('failure' in read)
667
782
  return read.failure;
668
- const { schema, written } = unruled(ruled);
783
+ const unbranched = withoutBranchSections(ruled, declared, at);
784
+ if ('failure' in unbranched)
785
+ return unbranched.failure;
786
+ const { schema, written } = unruled(unbranched.schema);
669
787
  const failure = schemaFailure(schema, at, context);
670
788
  if (failure !== undefined)
671
789
  return failure;
@@ -704,7 +822,7 @@ function readType(name, value, context) {
704
822
  function lineAt(text, offset) {
705
823
  return text.slice(0, offset).split(/\r\n|\r|\n/).length;
706
824
  }
707
- export function readSchema(text) {
825
+ export function readSchema(text, provided = NO_TYPES, checked = true) {
708
826
  let root;
709
827
  try {
710
828
  root = jsValue(parseYamlMapping(text, 0, text.length));
@@ -718,11 +836,15 @@ export function readSchema(text) {
718
836
  if (!isRecord(defs))
719
837
  return refuse('$defs', '/$defs');
720
838
  const names = Object.keys(root).filter((key) => key !== '$defs');
721
- for (const name of names) {
839
+ for (const name of checked ? names : []) {
722
840
  if (name === '' || name.startsWith('$') || name === BUILT_IN_TYPE || name === ATTACHMENT)
723
841
  return refuse('schema-type-name', `/${escapePointer(name)}`);
724
842
  }
725
- const context = { defs, types: new Set(names) };
843
+ const context = {
844
+ defs,
845
+ types: new Set([...names, ...Object.keys(provided.types)]),
846
+ checked,
847
+ };
726
848
  for (const [name, def] of Object.entries(defs)) {
727
849
  const failure = schemaFailure(def, `/$defs/${escapePointer(name)}`, context);
728
850
  if (failure !== undefined)
@@ -731,15 +853,21 @@ export function readSchema(text) {
731
853
  const types = Object.create(null);
732
854
  let marked = false;
733
855
  for (const name of names) {
734
- const definition = readType(name, root[name], context);
856
+ const definition = Object.hasOwn(provided.types, name)
857
+ ? providedType(name, root[name], provided, checked)
858
+ : readType(name, root[name], context);
735
859
  if ('rule' in definition)
736
860
  return definition;
737
- if (definition.memberDocument) {
861
+ if (checked && definition.memberDocument) {
738
862
  if (marked)
739
863
  return refuse('member_document', `/${escapePointer(name)}/member_document`);
740
864
  marked = true;
741
865
  }
742
866
  types[name] = deepFreeze(definition);
743
867
  }
868
+ for (const [name, definition] of Object.entries(provided.types)) {
869
+ if (!Object.hasOwn(types, name))
870
+ types[name] = definition;
871
+ }
744
872
  return Object.freeze({ types: Object.freeze(types) });
745
873
  }
@@ -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":"AAWA,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,CAe3F"}