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

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 (124) hide show
  1. package/AGENTS.md +210 -0
  2. package/README.md +44 -0
  3. package/dist/adapter.d.ts +155 -12
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +2 -3
  6. package/dist/attachment.d.ts +3 -0
  7. package/dist/attachment.d.ts.map +1 -0
  8. package/dist/attachment.js +8 -0
  9. package/dist/bootstrap.d.ts +3 -7
  10. package/dist/bootstrap.d.ts.map +1 -1
  11. package/dist/bootstrap.js +29 -27
  12. package/dist/change-set.d.ts +33 -0
  13. package/dist/change-set.d.ts.map +1 -0
  14. package/dist/change-set.js +87 -0
  15. package/dist/change.d.ts +9 -0
  16. package/dist/change.d.ts.map +1 -1
  17. package/dist/change.js +6 -5
  18. package/dist/client.d.ts +40 -28
  19. package/dist/client.d.ts.map +1 -1
  20. package/dist/client.js +121 -177
  21. package/dist/collection.d.ts +15 -16
  22. package/dist/collection.d.ts.map +1 -1
  23. package/dist/collection.js +54 -87
  24. package/dist/connection.d.ts +57 -35
  25. package/dist/connection.d.ts.map +1 -1
  26. package/dist/connection.js +1475 -964
  27. package/dist/conversation.d.ts +41 -19
  28. package/dist/conversation.d.ts.map +1 -1
  29. package/dist/conversation.js +483 -327
  30. package/dist/durability.js +6 -6
  31. package/dist/file.d.ts +2 -2
  32. package/dist/file.d.ts.map +1 -1
  33. package/dist/file.js +48 -71
  34. package/dist/host.d.ts +7 -2
  35. package/dist/host.d.ts.map +1 -1
  36. package/dist/host.js +100 -102
  37. package/dist/identity.d.ts +1 -0
  38. package/dist/identity.d.ts.map +1 -1
  39. package/dist/identity.js +10 -9
  40. package/dist/index.d.ts +12 -10
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +1 -2
  43. package/dist/log.js +5 -6
  44. package/dist/memory.d.ts +6 -3
  45. package/dist/memory.d.ts.map +1 -1
  46. package/dist/memory.js +206 -210
  47. package/dist/model.d.ts +10 -25
  48. package/dist/model.d.ts.map +1 -1
  49. package/dist/model.js +18 -21
  50. package/dist/observation.d.ts +25 -0
  51. package/dist/observation.d.ts.map +1 -0
  52. package/dist/observation.js +85 -0
  53. package/dist/outcome.d.ts +17 -20
  54. package/dist/outcome.d.ts.map +1 -1
  55. package/dist/outcome.js +1 -23
  56. package/dist/overlay.d.ts +9 -2
  57. package/dist/overlay.d.ts.map +1 -1
  58. package/dist/overlay.js +187 -43
  59. package/dist/paths.d.ts +0 -1
  60. package/dist/paths.d.ts.map +1 -1
  61. package/dist/paths.js +12 -19
  62. package/dist/query.d.ts +210 -10
  63. package/dist/query.d.ts.map +1 -1
  64. package/dist/query.js +420 -15
  65. package/dist/read-side.d.ts +14 -0
  66. package/dist/read-side.d.ts.map +1 -0
  67. package/dist/read-side.js +371 -0
  68. package/dist/refresh.d.ts +4 -5
  69. package/dist/refresh.d.ts.map +1 -1
  70. package/dist/refresh.js +45 -30
  71. package/dist/replica.d.ts +25 -5
  72. package/dist/replica.d.ts.map +1 -1
  73. package/dist/replica.js +232 -38
  74. package/dist/room-draft.d.ts +124 -0
  75. package/dist/room-draft.d.ts.map +1 -0
  76. package/dist/room-draft.js +327 -0
  77. package/dist/rows.d.ts +41 -0
  78. package/dist/rows.d.ts.map +1 -0
  79. package/dist/rows.js +100 -0
  80. package/dist/save.d.ts +8 -4
  81. package/dist/save.d.ts.map +1 -1
  82. package/dist/save.js +265 -350
  83. package/dist/search.d.ts +61 -0
  84. package/dist/search.d.ts.map +1 -0
  85. package/dist/search.js +125 -0
  86. package/dist/status.d.ts +4 -6
  87. package/dist/status.d.ts.map +1 -1
  88. package/dist/status.js +9 -13
  89. package/dist/store.d.ts +68 -30
  90. package/dist/store.d.ts.map +1 -1
  91. package/dist/store.js +360 -134
  92. package/dist/transfer.d.ts +5 -0
  93. package/dist/transfer.d.ts.map +1 -1
  94. package/dist/transfer.js +1 -5
  95. package/dist/wire.d.ts +4 -3
  96. package/dist/wire.d.ts.map +1 -1
  97. package/dist/wire.js +50 -65
  98. package/package.json +6 -12
  99. package/dist/adapter.js.map +0 -1
  100. package/dist/bootstrap.js.map +0 -1
  101. package/dist/change.js.map +0 -1
  102. package/dist/client.js.map +0 -1
  103. package/dist/collection.js.map +0 -1
  104. package/dist/connection.js.map +0 -1
  105. package/dist/conversation.js.map +0 -1
  106. package/dist/durability.js.map +0 -1
  107. package/dist/file.js.map +0 -1
  108. package/dist/host.js.map +0 -1
  109. package/dist/identity.js.map +0 -1
  110. package/dist/index.js.map +0 -1
  111. package/dist/log.js.map +0 -1
  112. package/dist/memory.js.map +0 -1
  113. package/dist/model.js.map +0 -1
  114. package/dist/outcome.js.map +0 -1
  115. package/dist/overlay.js.map +0 -1
  116. package/dist/paths.js.map +0 -1
  117. package/dist/query.js.map +0 -1
  118. package/dist/refresh.js.map +0 -1
  119. package/dist/replica.js.map +0 -1
  120. package/dist/save.js.map +0 -1
  121. package/dist/status.js.map +0 -1
  122. package/dist/store.js.map +0 -1
  123. package/dist/transfer.js.map +0 -1
  124. package/dist/wire.js.map +0 -1
package/dist/client.js CHANGED
@@ -1,227 +1,171 @@
1
- import { answer, AUTHORIZATION_ENDED, carried, envelope, PROTOCOL_MISMATCH } from './wire.js';
1
+ import { observed } from './observation.js';
2
+ import { answer, AUTHORIZATION_ENDED, carried, envelope, PORT_CLOSED, PROTOCOL_MISMATCH, } 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)=>{
8
+ const opening = new Map();
9
+ const observations = new Map();
10
+ const send = (message) => {
10
11
  port.postMessage(envelope(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)=>{
55
+ port.addEventListener('message', (event) => {
33
56
  const wire = carried(event.data);
34
- if (wire === null) return;
57
+ if (wire === null)
58
+ return;
35
59
  if (!wire.matching) {
36
60
  refuse(PROTOCOL_MISMATCH);
37
61
  return;
38
62
  }
39
63
  const message = answer(wire.message);
40
- if (message === null) return;
64
+ if (message === null)
65
+ return;
41
66
  if (message.kind === 'refusal') {
42
67
  refuse(message.refusal);
43
68
  return;
44
69
  }
45
70
  if (message.kind === 'ended') {
46
- end();
71
+ end(AUTHORIZATION_ENDED);
47
72
  return;
48
73
  }
49
74
  if (message.kind === 'event') {
50
- listeners.get(message.id)?.notify(message.value);
75
+ observations.get(message.id)?.handle.receive(message.value);
51
76
  return;
52
77
  }
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();
78
+ const waiting = opening.get(message.id);
79
+ if (waiting !== undefined) {
80
+ opening.delete(message.id);
81
+ if (message.kind === 'failure')
82
+ waiting.fail(new Error(message.message));
83
+ else
84
+ waiting.settle(begin(message.id, waiting.topic, message.value));
60
85
  return;
61
86
  }
62
- const waiting = calls.get(message.id);
63
- if (waiting === undefined) return;
87
+ const called = calls.get(message.id);
88
+ if (called === undefined)
89
+ return;
64
90
  calls.delete(message.id);
65
- if (message.kind === 'failure') waiting.fail(new Error(message.message));
66
- else waiting.settle(message.value);
91
+ if (message.kind === 'failure')
92
+ called.fail(new Error(message.message));
93
+ else
94
+ called.settle(message.value);
67
95
  });
68
- port.start();
69
- send({
70
- kind: 'hello'
96
+ port.addEventListener('close', () => {
97
+ end(PORT_CLOSED);
71
98
  });
99
+ port.start();
100
+ send({ kind: 'hello' });
72
101
  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
- });
102
+ if (ended !== null)
103
+ return Promise.reject(new Error(ended));
104
+ if (refusal !== null)
105
+ return Promise.reject(new Error(refusal.reason));
106
+ const id = (sequence += 1);
107
+ return new Promise((settle, fail) => {
108
+ calls.set(id, { settle: settle, fail });
109
+ send({ kind: 'call', id, member, input });
87
110
  });
88
111
  }
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
- };
112
+ function watch(topic, input) {
113
+ if (ended !== null)
114
+ return Promise.reject(new Error(ended));
115
+ const id = (sequence += 1);
103
116
  if (refusal !== null) {
104
- if (topic === 'connection-refusal') notify(refusal);
105
- return Promise.resolve(end);
117
+ return topic === 'connection-refusal'
118
+ ? Promise.resolve(begin(id, topic, refusal))
119
+ : Promise.reject(new Error(refusal.reason));
106
120
  }
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
- });
121
+ return new Promise((settle, fail) => {
122
+ opening.set(id, { topic, settle, fail });
123
+ send({ kind: 'observe', id, topic, input });
118
124
  });
119
125
  }
120
126
  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
- ])
127
+ rooms: () => ask('rooms', []),
128
+ slots: () => ask('slots', []),
129
+ query: ((query) => ask('query', [query])),
130
+ search: (request) => ask('search', [request]),
131
+ types: (locator) => ask('types', [locator]),
132
+ syncStatus: () => ask('syncStatus', []),
133
+ serviceMode: () => ask('serviceMode', []),
134
+ roomDraft: {
135
+ list: () => ask('roomDraft.list', []),
136
+ read: (room, path) => ask('roomDraft.read', [room, path]),
137
+ write: (room, path, revision, parts) => ask('roomDraft.write', [room, path, revision, parts]),
138
+ discard: (room, path, revision) => ask('roomDraft.discard', [room, path, revision]),
158
139
  },
140
+ save: (room, roomDrafts) => ask('save', [room, roomDrafts]),
141
+ outcome: (identifier) => ask('outcome', [identifier]),
159
142
  presentation: {
160
- read: ()=>ask('presentation.read', []),
161
- write: (value)=>ask('presentation.write', [
162
- value
163
- ])
143
+ read: () => ask('presentation.read', []),
144
+ write: (value) => ask('presentation.write', [value]),
164
145
  },
165
146
  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
- ])
147
+ list: () => ask('conversation.list', []),
148
+ read: (conversation, options) => ask('conversation.read', [conversation, options]),
149
+ create: (input) => ask('conversation.create', [input]),
150
+ send: (conversation) => ask('conversation.send', [conversation]),
151
+ answer: (conversation, answer) => ask('conversation.answer', [conversation, answer]),
152
+ interrupt: (conversation) => ask('conversation.interrupt', [conversation]),
153
+ kill: (conversation) => ask('conversation.kill', [conversation]),
154
+ cancel: (conversation, turn) => ask('conversation.cancel', [conversation, turn]),
155
+ delete: (conversation) => ask('conversation.delete', [conversation]),
203
156
  },
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);
157
+ chatDraft: {
158
+ write: (conversation, draft) => ask('chatDraft.write', [conversation, draft]),
159
+ discard: (conversation) => ask('chatDraft.discard', [conversation]),
222
160
  },
223
- reauthorize: ()=>ask('reauthorize', [])
161
+ history: (locator, path, query) => ask('history', [locator, path, query]),
162
+ call: (name, input) => ask('call', [name, input]),
163
+ reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
164
+ log: () => ask('log', []),
165
+ storageLoss: () => ask('storageLoss', []),
166
+ persistence: () => ask('persistence', []),
167
+ deploymentFacts: () => ask('deploymentFacts', []),
168
+ observe: ((topic, ...input) => watch(topic, input)),
169
+ reauthorize: () => ask('reauthorize', []),
224
170
  };
225
171
  }
226
-
227
- //# sourceMappingURL=client.js.map
@@ -1,33 +1,32 @@
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[];
22
14
  model: ModelState;
23
15
  } | null;
16
+ untypedFolders: readonly string[];
24
17
  };
18
+ export declare function untyped(roots: readonly string[], path: string): boolean;
25
19
  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';
20
+ type Previous = {
21
+ text: Readonly<Record<string, string>>;
22
+ collection: Collection;
32
23
  };
24
+ export declare function parseCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): Collection;
25
+ export declare function readCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): {
26
+ kind: 'read';
27
+ collection: Collection;
28
+ } | Refused;
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): Validation;
31
+ export {};
33
32
  //# 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,YA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SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAI5E;AAED,KAAK,QAAQ,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;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,CAQZ;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,CASpD;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,CA4BZ"}
@@ -1,115 +1,82 @@
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)));
8
+ }
9
+ export function untyped(roots, path) {
10
+ return roots.some((root) => beneath(root, path));
14
11
  }
15
12
  export function governing(composition, path) {
16
- return composition.selection !== null && selected(composition, path) ? composition.selection.model : composition.model;
13
+ return composition.selection !== null && selected(composition, path)
14
+ ? composition.selection.model
15
+ : composition.model;
17
16
  }
18
- export function typesAt(composition, path) {
19
- const model = governing(composition, path);
20
- return model.status === 'unavailable' ? [] : model.types;
17
+ function parsedAt(text, path, previous) {
18
+ const retained = previous?.collection.documents[path];
19
+ return retained !== undefined && previous?.text[path] === text[path]
20
+ ? { ok: true, document: retained }
21
+ : parse(text[path], path);
21
22
  }
22
- export function parseCollection(text, composition) {
23
+ export function parseCollection(text, composition, previous) {
23
24
  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;
25
+ for (const path of Object.keys(text).sort()) {
26
+ if (untyped(composition.untypedFolders, path))
27
+ continue;
28
+ const parsed = parsedAt(text, path, previous);
29
+ if (parsed.ok)
30
+ documents[path] = parsed.document;
27
31
  }
28
- return {
29
- documents,
30
- composition
31
- };
32
+ return { documents, composition };
32
33
  }
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;
34
+ export function readCollection(text, composition, previous) {
35
+ const documents = {};
36
+ for (const path of Object.keys(text).sort()) {
37
+ if (untyped(composition.untypedFolders, path))
38
+ continue;
39
+ const parsed = parsedAt(text, path, previous);
40
+ if (!parsed.ok)
41
+ return { kind: 'refused', refusal: parsed.refusal };
42
+ documents[path] = parsed.document;
43
+ }
44
+ return { kind: 'read', collection: { documents, composition } };
39
45
  }
40
46
  export function validRoot(root) {
41
47
  return typeof root === 'string' && normalize(root) === root;
42
48
  }
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])=>{
49
+ function validateAgainst(documents, binaryTargets, model) {
50
+ if (model.status === 'unavailable') {
51
+ const typed = Object.entries(documents).find(([, content]) => {
49
52
  const parsed = parse(content);
50
53
  return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
51
54
  });
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
- });
55
+ if (typed !== undefined)
56
+ return { verdict: 'refuse', rule: 'model-unavailable', file: typed[0] };
61
57
  }
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
- };
58
+ return validate(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
76
59
  }
77
- export function validateCollection(text, binaryTargets, composition, binding) {
78
- const prefix = composition.collectionRoot === '' ? '' : `${composition.collectionRoot}/`;
60
+ export function validateCollection(text, binaryTargets, composition) {
79
61
  const collection = {};
80
62
  const selection = {};
81
- for (const [path, content] of Object.entries(text)){
82
- if (member(path, composition.collectionRoot)) {
83
- collection[path.slice(prefix.length)] = content;
63
+ for (const [path, content] of Object.entries(text)) {
64
+ if (untyped(composition.untypedFolders, path))
84
65
  continue;
85
- }
86
- if (selected(composition, path)) {
66
+ if (selected(composition, path))
87
67
  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
- }
68
+ else
69
+ collection[path] = content;
103
70
  }
71
+ const linked = binaryTargets.filter((path) => !untyped(composition.untypedFolders, path));
104
72
  const verdicts = [
105
- validateAgainst(collection, binaryTargets.filter((path)=>member(path, composition.collectionRoot)).map((path)=>path.slice(prefix.length)), prefix, composition.model, binding)
73
+ validateAgainst(collection, linked.filter((path) => !selected(composition, path)), composition.model),
106
74
  ];
107
75
  if (composition.selection !== null) {
108
- verdicts.push(validateAgainst(selection, binaryTargets.filter((path)=>selected(composition, path)), '', composition.selection.model, binding));
76
+ verdicts.push(validateAgainst(selection, linked.filter((path) => selected(composition, path)), composition.selection.model));
109
77
  }
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];
78
+ const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
79
+ if (refusals.length === 0)
80
+ return verdicts[0];
81
+ return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
113
82
  }
114
-
115
- //# sourceMappingURL=collection.js.map