@agentshouse/mdruntime 0.1.0-alpha.9 → 0.1.0-c037654ea7e04

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 (133) hide show
  1. package/AGENTS.md +232 -0
  2. package/README.md +44 -0
  3. package/dist/adapter.d.ts +207 -36
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +1 -10
  6. package/dist/attached-model.d.ts +11 -0
  7. package/dist/attached-model.d.ts.map +1 -0
  8. package/dist/attached-model.js +34 -0
  9. package/dist/attachment.d.ts +3 -0
  10. package/dist/attachment.d.ts.map +1 -0
  11. package/dist/attachment.js +8 -0
  12. package/dist/bootstrap.d.ts +7 -9
  13. package/dist/bootstrap.d.ts.map +1 -1
  14. package/dist/bootstrap.js +30 -28
  15. package/dist/change-set.d.ts +33 -0
  16. package/dist/change-set.d.ts.map +1 -0
  17. package/dist/change-set.js +83 -0
  18. package/dist/change.d.ts +9 -0
  19. package/dist/change.d.ts.map +1 -1
  20. package/dist/change.js +6 -5
  21. package/dist/client.d.ts +39 -32
  22. package/dist/client.d.ts.map +1 -1
  23. package/dist/client.js +114 -183
  24. package/dist/collection.d.ts +13 -16
  25. package/dist/collection.d.ts.map +1 -1
  26. package/dist/collection.js +45 -88
  27. package/dist/connection.d.ts +51 -46
  28. package/dist/connection.d.ts.map +1 -1
  29. package/dist/connection.js +1551 -1161
  30. package/dist/conversation.d.ts +57 -24
  31. package/dist/conversation.d.ts.map +1 -1
  32. package/dist/conversation.js +631 -330
  33. package/dist/durability.js +6 -6
  34. package/dist/file.d.ts +2 -2
  35. package/dist/file.d.ts.map +1 -1
  36. package/dist/file.js +48 -71
  37. package/dist/host.d.ts +12 -2
  38. package/dist/host.d.ts.map +1 -1
  39. package/dist/host.js +97 -119
  40. package/dist/identity.d.ts +1 -0
  41. package/dist/identity.d.ts.map +1 -1
  42. package/dist/identity.js +10 -9
  43. package/dist/index.d.ts +12 -11
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +1 -3
  46. package/dist/log.js +5 -6
  47. package/dist/memory.d.ts +16 -7
  48. package/dist/memory.d.ts.map +1 -1
  49. package/dist/memory.js +267 -220
  50. package/dist/model.d.ts +7 -29
  51. package/dist/model.d.ts.map +1 -1
  52. package/dist/model.js +19 -21
  53. package/dist/observation.d.ts +27 -0
  54. package/dist/observation.d.ts.map +1 -0
  55. package/dist/observation.js +95 -0
  56. package/dist/outcome.d.ts +10 -29
  57. package/dist/outcome.d.ts.map +1 -1
  58. package/dist/outcome.js +1 -23
  59. package/dist/overlay.d.ts +9 -2
  60. package/dist/overlay.d.ts.map +1 -1
  61. package/dist/overlay.js +187 -43
  62. package/dist/paths.d.ts +0 -2
  63. package/dist/paths.d.ts.map +1 -1
  64. package/dist/paths.js +6 -29
  65. package/dist/query.d.ts +215 -10
  66. package/dist/query.d.ts.map +1 -1
  67. package/dist/query.js +429 -15
  68. package/dist/reach.d.ts +40 -0
  69. package/dist/reach.d.ts.map +1 -0
  70. package/dist/reach.js +270 -0
  71. package/dist/react.d.ts +31 -0
  72. package/dist/react.d.ts.map +1 -0
  73. package/dist/react.js +62 -0
  74. package/dist/read-side.d.ts +18 -0
  75. package/dist/read-side.d.ts.map +1 -0
  76. package/dist/read-side.js +377 -0
  77. package/dist/refresh.d.ts +5 -5
  78. package/dist/refresh.d.ts.map +1 -1
  79. package/dist/refresh.js +49 -30
  80. package/dist/replica.d.ts +25 -5
  81. package/dist/replica.d.ts.map +1 -1
  82. package/dist/replica.js +227 -38
  83. package/dist/room-draft.d.ts +127 -0
  84. package/dist/room-draft.d.ts.map +1 -0
  85. package/dist/room-draft.js +329 -0
  86. package/dist/rows.d.ts +41 -0
  87. package/dist/rows.d.ts.map +1 -0
  88. package/dist/rows.js +97 -0
  89. package/dist/save.d.ts +7 -4
  90. package/dist/save.d.ts.map +1 -1
  91. package/dist/save.js +314 -356
  92. package/dist/search.d.ts +61 -0
  93. package/dist/search.d.ts.map +1 -0
  94. package/dist/search.js +125 -0
  95. package/dist/status.d.ts +4 -6
  96. package/dist/status.d.ts.map +1 -1
  97. package/dist/status.js +9 -13
  98. package/dist/store.d.ts +60 -32
  99. package/dist/store.d.ts.map +1 -1
  100. package/dist/store.js +338 -134
  101. package/dist/transfer.d.ts +5 -0
  102. package/dist/transfer.d.ts.map +1 -1
  103. package/dist/transfer.js +1 -5
  104. package/dist/wire.d.ts +52 -16
  105. package/dist/wire.d.ts.map +1 -1
  106. package/dist/wire.js +78 -108
  107. package/package.json +17 -11
  108. package/dist/adapter.js.map +0 -1
  109. package/dist/bootstrap.js.map +0 -1
  110. package/dist/change.js.map +0 -1
  111. package/dist/client.js.map +0 -1
  112. package/dist/collection.js.map +0 -1
  113. package/dist/connection.js.map +0 -1
  114. package/dist/conversation.js.map +0 -1
  115. package/dist/durability.js.map +0 -1
  116. package/dist/file.js.map +0 -1
  117. package/dist/host.js.map +0 -1
  118. package/dist/identity.js.map +0 -1
  119. package/dist/index.js.map +0 -1
  120. package/dist/log.js.map +0 -1
  121. package/dist/memory.js.map +0 -1
  122. package/dist/model.js.map +0 -1
  123. package/dist/outcome.js.map +0 -1
  124. package/dist/overlay.js.map +0 -1
  125. package/dist/paths.js.map +0 -1
  126. package/dist/query.js.map +0 -1
  127. package/dist/refresh.js.map +0 -1
  128. package/dist/replica.js.map +0 -1
  129. package/dist/save.js.map +0 -1
  130. package/dist/status.js.map +0 -1
  131. package/dist/store.js.map +0 -1
  132. package/dist/transfer.js.map +0 -1
  133. package/dist/wire.js.map +0 -1
package/dist/client.js CHANGED
@@ -1,227 +1,158 @@
1
- import { answer, AUTHORIZATION_ENDED, carried, envelope, PROTOCOL_MISMATCH } from './wire.js';
1
+ import { observed } from './observation.js';
2
+ import { answer, AUTHORIZATION_ENDED, PORT_CLOSED, } from './wire.js';
2
3
  export function connectMdRuntime(port) {
3
4
  let sequence = 0;
4
5
  let refusal = null;
5
- let ended = false;
6
+ let ended = null;
6
7
  const calls = new Map();
7
- const acks = new Map();
8
- const listeners = new Map();
9
- const send = (message)=>{
10
- port.postMessage(envelope(message));
8
+ const opening = new Map();
9
+ const observations = new Map();
10
+ const send = (message) => {
11
+ port.postMessage(message);
11
12
  };
13
+ function begin(id, topic, first) {
14
+ const handle = observed(first, () => {
15
+ observations.delete(id);
16
+ if (refusal === null)
17
+ send({ kind: 'stop', id });
18
+ }, topic === 'query');
19
+ observations.set(id, { topic, handle });
20
+ return handle.observation;
21
+ }
12
22
  function refuse(reported) {
13
23
  refusal = reported;
14
- for (const waiting of acks.values())waiting.settle();
15
- acks.clear();
24
+ for (const { topic, handle } of observations.values()) {
25
+ if (topic === 'connection-refusal')
26
+ handle.receive(reported);
27
+ }
16
28
  const failure = new Error(reported.reason);
17
- for (const waiting of calls.values())waiting.fail(failure);
18
- calls.clear();
19
- for (const listener of listeners.values()){
20
- if (listener.topic === 'connection-refusal') listener.notify(reported);
29
+ for (const [id, waiting] of opening) {
30
+ if (waiting.topic === 'connection-refusal')
31
+ waiting.settle(begin(id, waiting.topic, reported));
32
+ else
33
+ waiting.fail(failure);
21
34
  }
35
+ opening.clear();
36
+ for (const waiting of calls.values())
37
+ waiting.fail(failure);
38
+ calls.clear();
22
39
  }
23
- function end() {
24
- ended = true;
25
- const failure = new Error(AUTHORIZATION_ENDED);
26
- for (const waiting of acks.values())waiting.fail(failure);
27
- acks.clear();
28
- for (const waiting of calls.values())waiting.fail(failure);
40
+ function end(reason) {
41
+ if (ended !== null)
42
+ return;
43
+ ended = reason;
44
+ const failure = new Error(reason);
45
+ for (const waiting of opening.values())
46
+ waiting.fail(failure);
47
+ opening.clear();
48
+ for (const waiting of calls.values())
49
+ waiting.fail(failure);
29
50
  calls.clear();
30
- listeners.clear();
51
+ for (const { handle } of observations.values())
52
+ handle.end();
53
+ observations.clear();
31
54
  }
32
- port.addEventListener('message', (event)=>{
33
- const wire = carried(event.data);
34
- if (wire === null) return;
35
- if (!wire.matching) {
36
- refuse(PROTOCOL_MISMATCH);
55
+ port.addEventListener('message', (event) => {
56
+ const message = answer(event.data);
57
+ if (message === null)
37
58
  return;
38
- }
39
- const message = answer(wire.message);
40
- if (message === null) return;
41
59
  if (message.kind === 'refusal') {
42
60
  refuse(message.refusal);
43
61
  return;
44
62
  }
45
63
  if (message.kind === 'ended') {
46
- end();
64
+ end(AUTHORIZATION_ENDED);
47
65
  return;
48
66
  }
49
67
  if (message.kind === 'event') {
50
- listeners.get(message.id)?.notify(message.value);
68
+ observations.get(message.id)?.handle.receive(message.value);
51
69
  return;
52
70
  }
53
- const subscribing = acks.get(message.id);
54
- if (subscribing !== undefined) {
55
- acks.delete(message.id);
56
- if (message.kind === 'failure') {
57
- listeners.delete(message.id);
58
- subscribing.fail(new Error(message.message));
59
- } else subscribing.settle();
71
+ const waiting = opening.get(message.id);
72
+ if (waiting !== undefined) {
73
+ opening.delete(message.id);
74
+ if (message.kind === 'failure')
75
+ waiting.fail(new Error(message.message));
76
+ else
77
+ waiting.settle(begin(message.id, waiting.topic, message.value));
60
78
  return;
61
79
  }
62
- const waiting = calls.get(message.id);
63
- if (waiting === undefined) return;
80
+ const called = calls.get(message.id);
81
+ if (called === undefined)
82
+ return;
64
83
  calls.delete(message.id);
65
- if (message.kind === 'failure') waiting.fail(new Error(message.message));
66
- else waiting.settle(message.value);
84
+ if (message.kind === 'failure')
85
+ called.fail(new Error(message.message));
86
+ else
87
+ called.settle(message.value);
67
88
  });
68
- port.start();
69
- send({
70
- kind: 'hello'
89
+ port.addEventListener('close', () => {
90
+ end(PORT_CLOSED);
71
91
  });
92
+ port.start();
93
+ send({ kind: 'hello' });
72
94
  function ask(member, input) {
73
- if (ended) return Promise.reject(new Error(AUTHORIZATION_ENDED));
74
- if (refusal !== null) return Promise.reject(new Error(refusal.reason));
75
- const id = sequence += 1;
76
- return new Promise((settle, fail)=>{
77
- calls.set(id, {
78
- settle: settle,
79
- fail
80
- });
81
- send({
82
- kind: 'call',
83
- id,
84
- member,
85
- input
86
- });
95
+ if (ended !== null)
96
+ return Promise.reject(new Error(ended));
97
+ if (refusal !== null)
98
+ return Promise.reject(new Error(refusal.reason));
99
+ const id = (sequence += 1);
100
+ return new Promise((settle, fail) => {
101
+ calls.set(id, { settle: settle, fail });
102
+ send({ kind: 'call', id, member, input });
87
103
  });
88
104
  }
89
- function watch(topic, input, notify) {
90
- if (ended) return Promise.reject(new Error(AUTHORIZATION_ENDED));
91
- const id = sequence += 1;
92
- listeners.set(id, {
93
- topic,
94
- notify
95
- });
96
- const end = ()=>{
97
- if (!listeners.delete(id)) return;
98
- if (refusal === null) send({
99
- kind: 'stop',
100
- id
101
- });
102
- };
105
+ function watch(topic, input) {
106
+ if (ended !== null)
107
+ return Promise.reject(new Error(ended));
108
+ const id = (sequence += 1);
103
109
  if (refusal !== null) {
104
- if (topic === 'connection-refusal') notify(refusal);
105
- return Promise.resolve(end);
110
+ return topic === 'connection-refusal'
111
+ ? Promise.resolve(begin(id, topic, refusal))
112
+ : Promise.reject(new Error(refusal.reason));
106
113
  }
107
- return new Promise((settle, fail)=>{
108
- acks.set(id, {
109
- settle: ()=>settle(end),
110
- fail
111
- });
112
- send({
113
- kind: 'observe',
114
- id,
115
- topic,
116
- input
117
- });
114
+ return new Promise((settle, fail) => {
115
+ opening.set(id, { topic, settle, fail });
116
+ send({ kind: 'observe', id, topic, input });
118
117
  });
119
118
  }
120
119
  return {
121
- rooms: ()=>ask('rooms', []),
122
- query: (options)=>ask('query', [
123
- options
124
- ]),
125
- types: (locator)=>ask('types', [
126
- locator
127
- ]),
128
- syncStatus: ()=>ask('syncStatus', []),
129
- draft: {
130
- list: ()=>ask('draft.list', []),
131
- read: (locator, path)=>ask('draft.read', [
132
- locator,
133
- path
134
- ]),
135
- replace: (locator, path, content)=>ask('draft.replace', [
136
- locator,
137
- path,
138
- content
139
- ]),
140
- discard: (locator, path)=>ask('draft.discard', [
141
- locator,
142
- path
143
- ])
144
- },
145
- save: (locator, changes, replacing)=>ask('save', [
146
- locator,
147
- changes,
148
- replacing
149
- ]),
150
- outcome: (identifier)=>ask('outcome', [
151
- identifier
152
- ]),
153
- queue: {
154
- discard: (locator, identifier)=>ask('queue.discard', [
155
- locator,
156
- identifier
157
- ])
120
+ rooms: () => ask('rooms', []),
121
+ query: ((query) => ask('query', [query])),
122
+ search: (request) => ask('search', [request]),
123
+ types: (locator) => ask('types', [locator]),
124
+ roomDraft: {
125
+ list: () => ask('roomDraft.list', []),
126
+ read: (room, path) => ask('roomDraft.read', [room, path]),
127
+ write: (room, path, revision, parts) => ask('roomDraft.write', [room, path, revision, parts]),
128
+ discard: (room, path, revision) => ask('roomDraft.discard', [room, path, revision]),
158
129
  },
130
+ save: (room, roomDrafts) => ask('save', [room, roomDrafts]),
159
131
  presentation: {
160
- read: ()=>ask('presentation.read', []),
161
- write: (value)=>ask('presentation.write', [
162
- value
163
- ])
132
+ read: () => ask('presentation.read', []),
133
+ write: (value) => ask('presentation.write', [value]),
164
134
  },
165
135
  conversation: {
166
- list: ()=>ask('conversation.list', []),
167
- read: (conversation)=>ask('conversation.read', [
168
- conversation
169
- ]),
170
- older: (conversation)=>ask('conversation.older', [
171
- conversation
172
- ]),
173
- compose: (conversation, instruction)=>ask('conversation.compose', [
174
- conversation,
175
- instruction
176
- ]),
177
- discard: (conversation)=>ask('conversation.discard', [
178
- conversation
179
- ]),
180
- create: (input)=>ask('conversation.create', [
181
- input
182
- ]),
183
- send: (conversation)=>ask('conversation.send', [
184
- conversation
185
- ]),
186
- answer: (conversation, answer)=>ask('conversation.answer', [
187
- conversation,
188
- answer
189
- ]),
190
- interrupt: (conversation)=>ask('conversation.interrupt', [
191
- conversation
192
- ]),
193
- kill: (conversation)=>ask('conversation.kill', [
194
- conversation
195
- ]),
196
- cancel: (conversation, turn)=>ask('conversation.cancel', [
197
- conversation,
198
- turn
199
- ]),
200
- delete: (conversation)=>ask('conversation.delete', [
201
- conversation
202
- ])
136
+ list: () => ask('conversation.list', []),
137
+ read: (conversation, options) => ask('conversation.read', [conversation, options]),
138
+ create: (input) => ask('conversation.create', [input]),
139
+ send: (conversation) => ask('conversation.send', [conversation]),
140
+ answer: (conversation, answer) => ask('conversation.answer', [conversation, answer]),
141
+ interrupt: (conversation) => ask('conversation.interrupt', [conversation]),
142
+ kill: (conversation) => ask('conversation.kill', [conversation]),
143
+ cancel: (conversation, turn) => ask('conversation.cancel', [conversation, turn]),
144
+ delete: (conversation) => ask('conversation.delete', [conversation]),
203
145
  },
204
- history: (locator, path, query)=>ask('history', [
205
- locator,
206
- path,
207
- query
208
- ]),
209
- call: (name, input)=>ask('call', [
210
- name,
211
- input
212
- ]),
213
- log: ()=>ask('log', []),
214
- storageLoss: ()=>ask('storageLoss', []),
215
- persistence: ()=>ask('persistence', []),
216
- observe (topic, second, third) {
217
- const positional = topic === 'query' || topic === 'queue' || topic === 'conversation';
218
- const notify = positional ? third : second;
219
- return watch(topic, positional ? [
220
- second
221
- ] : [], notify);
146
+ chatDraft: {
147
+ write: (conversation, draft) => ask('chatDraft.write', [conversation, draft]),
148
+ discard: (conversation) => ask('chatDraft.discard', [conversation]),
222
149
  },
223
- reauthorize: ()=>ask('reauthorize', [])
150
+ history: (locator, path, query) => ask('history', [locator, path, query]),
151
+ call: (name, input) => ask('call', [name, input]),
152
+ reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
153
+ log: () => ask('log', []),
154
+ persistence: () => ask('persistence', []),
155
+ observe: ((topic, ...input) => watch(topic, input)),
156
+ reauthorize: () => ask('reauthorize', []),
224
157
  };
225
158
  }
226
-
227
- //# sourceMappingURL=client.js.map
@@ -1,21 +1,13 @@
1
1
  import { type Document, type Validation } from '@agentshouse/mdmodel';
2
- import type { Selector } from '@agentshouse/query';
3
- import type { AttachedModelBinding, ModelState } from './model.js';
2
+ import type { ModelState } from './model.js';
4
3
  import type { MdModelIdentity } from './adapter.js';
4
+ import type { Refused } from './transfer.js';
5
5
  export declare const MD_MODEL: MdModelIdentity;
6
- export declare const PRESENTED: Selector;
7
- export type MdType = {
8
- name: string;
9
- path: string;
10
- fields: Readonly<Record<string, unknown>>;
11
- sections: Readonly<Record<string, unknown>>;
12
- };
13
6
  export type Collection = {
14
7
  documents: Readonly<Record<string, Document>>;
15
8
  composition: Composition;
16
9
  };
17
10
  export type Composition = {
18
- collectionRoot: string;
19
11
  model: ModelState;
20
12
  selection: {
21
13
  roots: readonly string[];
@@ -23,11 +15,16 @@ export type Composition = {
23
15
  } | null;
24
16
  };
25
17
  export declare function governing(composition: Composition, path: string): ModelState;
26
- export declare function typesAt(composition: Composition, path: string): readonly MdType[];
27
- export declare function parseCollection(text: Readonly<Record<string, string>>, composition: Composition): Collection;
28
- export declare function readCollection(text: Readonly<Record<string, string>>, composition: Composition): Collection | null;
29
- export declare function validRoot(root: unknown): root is string;
30
- export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition, binding: AttachedModelBinding | null): Validation & {
31
- source?: 'content' | 'model';
18
+ type Previous = {
19
+ text: Readonly<Record<string, string>>;
20
+ collection: Collection;
32
21
  };
22
+ export declare function parseCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): Collection;
23
+ export declare function readCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): {
24
+ kind: 'read';
25
+ collection: Collection;
26
+ } | Refused;
27
+ export declare function validRoot(root: unknown): root is string;
28
+ export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition): Validation;
29
+ export {};
33
30
  //# sourceMappingURL=collection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,KAAK,EAA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AAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC;AAanF,wBAAgB,eAAe,CAC7B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE,QAAQ,GAClB,UAAU,CAOZ;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE,QAAQ,GAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,GAAG,OAAO,CAQpD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAEvD;AAwBD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,WAAW,EAAE,WAAW,GACvB,UAAU,CA0BZ"}
@@ -1,115 +1,72 @@
1
- import { parse, validate, VERSION } from '@agentshouse/mdmodel';
1
+ import { parse, validate, VERSION, } from '@agentshouse/mdmodel';
2
2
  import { beneath, normalize } from './paths.js';
3
- export const MD_MODEL = {
4
- identity: '@agentshouse/mdmodel',
5
- version: VERSION
6
- };
7
- export const PRESENTED = {
8
- path: {
9
- $regex: '\\.md$'
10
- }
11
- };
3
+ export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
4
+ const NO_TYPES = { types: {} };
12
5
  function selected(composition, path) {
13
- return composition.selection !== null && composition.selection.roots.some((root)=>beneath(root, path));
6
+ return (composition.selection !== null &&
7
+ composition.selection.roots.some((root) => beneath(root, path)));
14
8
  }
15
9
  export function governing(composition, path) {
16
- return composition.selection !== null && selected(composition, path) ? composition.selection.model : composition.model;
10
+ return composition.selection !== null && selected(composition, path)
11
+ ? composition.selection.model
12
+ : composition.model;
17
13
  }
18
- export function typesAt(composition, path) {
19
- const model = governing(composition, path);
20
- return model.status === 'unavailable' ? [] : model.types;
14
+ function parsedAt(text, path, previous) {
15
+ const retained = previous?.collection.documents[path];
16
+ return retained !== undefined && previous?.text[path] === text[path]
17
+ ? { ok: true, document: retained }
18
+ : parse(text[path], path);
21
19
  }
22
- export function parseCollection(text, composition) {
20
+ export function parseCollection(text, composition, previous) {
23
21
  const documents = {};
24
- for (const path of Object.keys(text).sort()){
25
- const parsed = parse(text[path], path);
26
- if (parsed.ok) documents[path] = parsed.document;
22
+ for (const path of Object.keys(text).sort()) {
23
+ const parsed = parsedAt(text, path, previous);
24
+ if (parsed.ok)
25
+ documents[path] = parsed.document;
27
26
  }
28
- return {
29
- documents,
30
- composition
31
- };
27
+ return { documents, composition };
32
28
  }
33
- export function readCollection(text, composition) {
34
- if (!validRoot(composition.collectionRoot)) return null;
35
- const collection = parseCollection(text, composition);
36
- if (Object.keys(collection.documents).length !== Object.keys(text).length) return null;
37
- if (Object.entries(collection.documents).some(([path, document])=>!member(path, composition.collectionRoot) && !selected(composition, path) && document.type !== undefined && document.type !== 'any')) return null;
38
- return collection;
29
+ export function readCollection(text, composition, previous) {
30
+ const documents = {};
31
+ for (const path of Object.keys(text).sort()) {
32
+ const parsed = parsedAt(text, path, previous);
33
+ if (!parsed.ok)
34
+ return { kind: 'refused', refusal: parsed.refusal };
35
+ documents[path] = parsed.document;
36
+ }
37
+ return { kind: 'read', collection: { documents, composition } };
39
38
  }
40
39
  export function validRoot(root) {
41
40
  return typeof root === 'string' && normalize(root) === root;
42
41
  }
43
- function member(path, root) {
44
- return root === '' || path.startsWith(`${root}/`);
45
- }
46
- function validateAgainst(documents, binaryTargets, prefix, model, binding) {
47
- if (model.status === 'unavailable' || binding === null) {
48
- const typed = Object.entries(documents).find(([, content])=>{
42
+ function validateAgainst(documents, binaryTargets, model) {
43
+ if (model.status === 'unavailable') {
44
+ const typed = Object.entries(documents).find(([, content]) => {
49
45
  const parsed = parse(content);
50
46
  return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
51
47
  });
52
- if (typed !== undefined) return {
53
- verdict: 'refuse',
54
- rule: 'model-unavailable',
55
- file: `${prefix}${typed[0]}`,
56
- version: VERSION
57
- };
58
- return validate(documents, {
59
- binaryTargets
60
- });
48
+ if (typed !== undefined)
49
+ return { verdict: 'refuse', rule: 'model-unavailable', file: typed[0] };
61
50
  }
62
- const verdict = binding.validate({
63
- model: model.snapshot,
64
- documents,
65
- binaryTargets
66
- });
67
- if (verdict.verdict === 'refuse' && verdict.source === 'model') return verdict;
68
- if (verdict.verdict === 'accept') return verdict;
69
- return {
70
- ...verdict,
71
- file: `${prefix}${verdict.file}`,
72
- ...verdict.referrers === undefined ? {} : {
73
- referrers: verdict.referrers.map((path)=>`${prefix}${path}`)
74
- }
75
- };
51
+ return validate(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
76
52
  }
77
- export function validateCollection(text, binaryTargets, composition, binding) {
78
- const prefix = composition.collectionRoot === '' ? '' : `${composition.collectionRoot}/`;
53
+ export function validateCollection(text, binaryTargets, composition) {
79
54
  const collection = {};
80
55
  const selection = {};
81
- for (const [path, content] of Object.entries(text)){
82
- if (member(path, composition.collectionRoot)) {
83
- collection[path.slice(prefix.length)] = content;
84
- continue;
85
- }
86
- if (selected(composition, path)) {
56
+ for (const [path, content] of Object.entries(text)) {
57
+ if (selected(composition, path))
87
58
  selection[path] = content;
88
- continue;
89
- }
90
- const parsed = parse(content, path);
91
- if (!parsed.ok) return {
92
- verdict: 'refuse',
93
- ...parsed.refusal
94
- };
95
- if (Object.hasOwn(parsed.document.fields, 'type') && parsed.document.fields.type !== 'any') {
96
- return {
97
- verdict: 'refuse',
98
- rule: 'outside-collection-type',
99
- file: path,
100
- version: VERSION
101
- };
102
- }
59
+ else
60
+ collection[path] = content;
103
61
  }
104
62
  const verdicts = [
105
- validateAgainst(collection, binaryTargets.filter((path)=>member(path, composition.collectionRoot)).map((path)=>path.slice(prefix.length)), prefix, composition.model, binding)
63
+ validateAgainst(collection, binaryTargets.filter((path) => !selected(composition, path)), composition.model),
106
64
  ];
107
65
  if (composition.selection !== null) {
108
- verdicts.push(validateAgainst(selection, binaryTargets.filter((path)=>selected(composition, path)), '', composition.selection.model, binding));
66
+ verdicts.push(validateAgainst(selection, binaryTargets.filter((path) => selected(composition, path)), composition.selection.model));
109
67
  }
110
- const refusals = verdicts.filter((verdict)=>verdict.verdict === 'refuse');
111
- if (refusals.length === 0) return verdicts[0];
112
- return refusals.find((refusal)=>refusal.rule !== 'model-unavailable') ?? refusals[0];
68
+ const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
69
+ if (refusals.length === 0)
70
+ return verdicts[0];
71
+ return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
113
72
  }
114
-
115
- //# sourceMappingURL=collection.js.map