@agentshouse/mdruntime 0.1.0-c8c4b020a3ec7 → 0.1.0-c8ca66ac9e99d
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.
- package/AGENTS.md +175 -84
- package/README.md +21 -11
- package/dist/adapter.d.ts +125 -55
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -9
- package/dist/attached-model.d.ts +11 -0
- package/dist/attached-model.d.ts.map +1 -0
- package/dist/attached-model.js +47 -0
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +70 -0
- package/dist/binary.d.ts +23 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +20 -6
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +89 -38
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +19 -12
- package/dist/change.d.ts +15 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +26 -1
- package/dist/chat/acts.d.ts +34 -0
- package/dist/chat/acts.d.ts.map +1 -0
- package/dist/chat/acts.js +36 -0
- package/dist/chat/context.d.ts +3 -0
- package/dist/chat/context.d.ts.map +1 -0
- package/dist/chat/context.js +10 -0
- package/dist/chat/input.d.ts +9 -0
- package/dist/chat/input.d.ts.map +1 -0
- package/dist/chat/input.js +99 -0
- package/dist/chat/kit.d.ts +60 -0
- package/dist/chat/kit.d.ts.map +1 -0
- package/dist/chat/kit.js +123 -0
- package/dist/chat/lasting.d.ts +6 -0
- package/dist/chat/lasting.d.ts.map +1 -0
- package/dist/chat/lasting.js +19 -0
- package/dist/chat/list.d.ts +26 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +62 -0
- package/dist/chat/markdown.d.ts +20 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +188 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +192 -0
- package/dist/chat/messages.d.ts +21 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +151 -0
- package/dist/chat/name.d.ts +6 -0
- package/dist/chat/name.d.ts.map +1 -0
- package/dist/chat/name.js +37 -0
- package/dist/chat/opened.d.ts +11 -0
- package/dist/chat/opened.d.ts.map +1 -0
- package/dist/chat/opened.js +17 -0
- package/dist/chat/overlay.d.ts +31 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +97 -0
- package/dist/chat/parts.d.ts +57 -0
- package/dist/chat/parts.d.ts.map +1 -0
- package/dist/chat/parts.js +119 -0
- package/dist/chat/process.d.ts +20 -0
- package/dist/chat/process.d.ts.map +1 -0
- package/dist/chat/process.js +32 -0
- package/dist/chat/provider.d.ts +63 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +645 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +80 -0
- package/dist/chat/questions.d.ts +31 -0
- package/dist/chat/questions.d.ts.map +1 -0
- package/dist/chat/questions.js +111 -0
- package/dist/chat/read.d.ts +5 -0
- package/dist/chat/read.d.ts.map +1 -0
- package/dist/chat/read.js +13 -0
- package/dist/chat/ready.d.ts +33 -0
- package/dist/chat/ready.d.ts.map +1 -0
- package/dist/chat/ready.js +91 -0
- package/dist/chat/style.d.ts +4 -0
- package/dist/chat/style.d.ts.map +1 -0
- package/dist/chat/style.js +302 -0
- package/dist/chat.d.ts +14 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +8 -0
- package/dist/client.d.ts +17 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +68 -25
- package/dist/collection.d.ts +6 -11
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +56 -19
- package/dist/connection.d.ts +28 -18
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +942 -626
- package/dist/conversation.d.ts +32 -13
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +293 -108
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/host.d.ts +9 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +46 -42
- package/dist/identity.d.ts +3 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +13 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/memory.d.ts +14 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +137 -45
- package/dist/model.d.ts +13 -12
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -3
- package/dist/observation.d.ts +2 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +24 -14
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +28 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +41 -1
- package/dist/overlay.d.ts +14 -3
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +75 -37
- package/dist/paths.d.ts +0 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +0 -16
- package/dist/query.d.ts +12 -3
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +78 -36
- package/dist/reach.d.ts +42 -0
- package/dist/reach.d.ts.map +1 -0
- package/dist/reach.js +294 -0
- package/dist/react.d.ts +41 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +64 -0
- package/dist/read-side.d.ts +4 -0
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +125 -56
- package/dist/refresh.d.ts +12 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +44 -36
- package/dist/replica.d.ts +9 -6
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +81 -62
- package/dist/room-draft.d.ts +29 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +137 -26
- package/dist/rows.d.ts +7 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +85 -40
- package/dist/save.d.ts +28 -3
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +429 -80
- package/dist/search.d.ts +3 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/status.d.ts +2 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +37 -11
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +310 -164
- package/dist/wire.d.ts +58 -19
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +65 -61
- package/package.json +27 -7
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
package/dist/overlay.d.ts
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import type { HeadChange } from './adapter.js';
|
|
1
|
+
import type { BinaryFile, HeadChange } from './adapter.js';
|
|
2
2
|
import type { ChangeBatch } from './change.js';
|
|
3
3
|
export type Heads = {
|
|
4
4
|
revisions: Readonly<Record<string, string>>;
|
|
5
5
|
changes: Readonly<Record<string, HeadChange>>;
|
|
6
6
|
};
|
|
7
|
+
export type HeldBinary = ({
|
|
8
|
+
readonly state: 'accepted';
|
|
9
|
+
} & BinaryFile) | {
|
|
10
|
+
readonly state: 'pending';
|
|
11
|
+
readonly localId: string;
|
|
12
|
+
readonly byteLength: number;
|
|
13
|
+
readonly mediaType: string;
|
|
14
|
+
readonly sha256: string;
|
|
15
|
+
};
|
|
7
16
|
export type Layer = Heads & {
|
|
8
17
|
documents: Readonly<Record<string, string>>;
|
|
9
|
-
|
|
18
|
+
binaries: Readonly<Record<string, HeldBinary>>;
|
|
10
19
|
};
|
|
20
|
+
export declare function acceptedBinaries(files: Readonly<Record<string, BinaryFile>>): Record<string, HeldBinary>;
|
|
21
|
+
export declare function sameBinary(left: HeldBinary | undefined, right: HeldBinary | undefined): boolean;
|
|
11
22
|
export declare function sameChange(left: HeadChange | undefined, right: HeadChange | undefined): boolean;
|
|
12
|
-
export declare function overlay(base: Layer, queue: readonly ChangeBatch[]): Layer;
|
|
23
|
+
export declare function overlay(base: Layer, queue: readonly ChangeBatch[], unapplied?: () => void): Layer;
|
|
13
24
|
export declare function sameLayerText(left: Layer, right: Layer): boolean;
|
|
14
25
|
export declare function overlayChanged(base: Layer, queue: readonly ChangeBatch[], previousBase: Layer, previousQueue: readonly ChangeBatch[], previousVisible: Layer): Layer;
|
|
15
26
|
//# sourceMappingURL=overlay.d.ts.map
|
package/dist/overlay.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../src/overlay.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../src/overlay.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAU,WAAW,EAAgB,MAAM,aAAa,CAAC;AAErE,MAAM,MAAM,KAAK,GAAG;IAClB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB,CAAC;IAAE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAAE,GAAG,UAAU,CAAC,GAC7C;IACE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,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
|
|
2
|
+
export function acceptedBinaries(files) {
|
|
3
|
+
return Object.fromEntries(Object.entries(files).map(([path, file]) => [path, { state: 'accepted', ...file }]));
|
|
4
|
+
}
|
|
5
|
+
export function sameBinary(left, right) {
|
|
6
|
+
if (left === undefined || right === undefined)
|
|
7
|
+
return left === right;
|
|
8
|
+
return (left.state === right.state &&
|
|
9
|
+
left.byteLength === right.byteLength &&
|
|
10
|
+
left.mediaType === right.mediaType &&
|
|
11
|
+
left.sha256 === right.sha256 &&
|
|
12
|
+
(left.state === 'accepted'
|
|
13
|
+
? right.state === 'accepted' && left.fileRef === right.fileRef
|
|
14
|
+
: right.state === 'pending' && left.localId === right.localId));
|
|
15
|
+
}
|
|
2
16
|
export function sameChange(left, right) {
|
|
3
17
|
if (left === undefined || right === undefined)
|
|
4
18
|
return left === right;
|
|
@@ -76,13 +90,15 @@ function edited(document, change, priors) {
|
|
|
76
90
|
function edit(staged, change, priors) {
|
|
77
91
|
const text = staged.documents[change.path];
|
|
78
92
|
if (text === undefined)
|
|
79
|
-
return;
|
|
93
|
+
return false;
|
|
80
94
|
const parsed = parse(text, change.path);
|
|
81
95
|
if (!parsed.ok)
|
|
82
|
-
return;
|
|
96
|
+
return false;
|
|
83
97
|
const next = edited(parsed.document, change, priors);
|
|
84
|
-
if (next?.outcome
|
|
85
|
-
|
|
98
|
+
if (next?.outcome !== 'applied')
|
|
99
|
+
return false;
|
|
100
|
+
staged.documents[change.path] = serialize(next.document);
|
|
101
|
+
return true;
|
|
86
102
|
}
|
|
87
103
|
function relocate(staged, from, to) {
|
|
88
104
|
const text = staged.documents[from];
|
|
@@ -90,13 +106,15 @@ function relocate(staged, from, to) {
|
|
|
90
106
|
delete staged.documents[from];
|
|
91
107
|
staged.documents[to] = text;
|
|
92
108
|
}
|
|
93
|
-
else if (staged.
|
|
94
|
-
staged.
|
|
109
|
+
else if (staged.binaries[from] !== undefined) {
|
|
110
|
+
staged.binaries[to] = staged.binaries[from];
|
|
111
|
+
delete staged.binaries[from];
|
|
95
112
|
}
|
|
96
113
|
else {
|
|
97
|
-
return;
|
|
114
|
+
return false;
|
|
98
115
|
}
|
|
99
116
|
moveHead(staged, from, to);
|
|
117
|
+
return true;
|
|
100
118
|
}
|
|
101
119
|
function moveHead(heads, from, to) {
|
|
102
120
|
const revision = heads.revisions[from];
|
|
@@ -113,46 +131,61 @@ function erase(staged, path) {
|
|
|
113
131
|
delete staged.documents[path];
|
|
114
132
|
delete staged.revisions[path];
|
|
115
133
|
delete staged.changes[path];
|
|
116
|
-
staged.
|
|
134
|
+
delete staged.binaries[path];
|
|
117
135
|
}
|
|
118
136
|
function stage(staged, change, priors) {
|
|
119
137
|
if (change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble') {
|
|
120
|
-
edit(staged, change, priors);
|
|
121
|
-
return;
|
|
138
|
+
return edit(staged, change, priors);
|
|
122
139
|
}
|
|
123
140
|
if (change.kind === 'create') {
|
|
124
141
|
staged.documents[change.path] =
|
|
125
142
|
'content' in change ? change.content : compose(change.fields, change.sections);
|
|
126
143
|
delete staged.changes[change.path];
|
|
127
|
-
return;
|
|
144
|
+
return true;
|
|
128
145
|
}
|
|
129
146
|
if (change.kind === 'replace') {
|
|
130
147
|
if (staged.documents[change.path] === undefined)
|
|
131
|
-
return;
|
|
148
|
+
return false;
|
|
132
149
|
staged.documents[change.path] = change.content;
|
|
133
|
-
return;
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
if (change.kind === 'binary') {
|
|
153
|
+
if (staged.documents[change.path] !== undefined)
|
|
154
|
+
return false;
|
|
155
|
+
staged.binaries[change.path] = {
|
|
156
|
+
state: 'pending',
|
|
157
|
+
localId: change.localId,
|
|
158
|
+
byteLength: change.byteLength,
|
|
159
|
+
mediaType: change.mediaType,
|
|
160
|
+
sha256: change.sha256,
|
|
161
|
+
};
|
|
162
|
+
delete staged.revisions[change.path];
|
|
163
|
+
delete staged.changes[change.path];
|
|
164
|
+
return true;
|
|
134
165
|
}
|
|
135
166
|
if (change.kind === 'move') {
|
|
136
|
-
relocate(staged, change.path, change.to);
|
|
137
|
-
return;
|
|
167
|
+
return relocate(staged, change.path, change.to);
|
|
138
168
|
}
|
|
139
169
|
erase(staged, change.path);
|
|
170
|
+
return true;
|
|
140
171
|
}
|
|
141
|
-
export function overlay(base, queue) {
|
|
172
|
+
export function overlay(base, queue, unapplied) {
|
|
142
173
|
const staged = {
|
|
143
174
|
documents: { ...base.documents },
|
|
144
|
-
|
|
175
|
+
binaries: { ...base.binaries },
|
|
145
176
|
revisions: { ...base.revisions },
|
|
146
177
|
changes: { ...base.changes },
|
|
147
178
|
};
|
|
148
179
|
for (const batch of queue) {
|
|
149
180
|
const priors = priorsOf(batch.preconditions);
|
|
150
|
-
for (const change of batch.changes)
|
|
151
|
-
stage(staged, change, priors)
|
|
181
|
+
for (const change of batch.changes) {
|
|
182
|
+
if (!stage(staged, change, priors))
|
|
183
|
+
unapplied?.();
|
|
184
|
+
}
|
|
152
185
|
}
|
|
153
186
|
return {
|
|
154
187
|
documents: staged.documents,
|
|
155
|
-
|
|
188
|
+
binaries: staged.binaries,
|
|
156
189
|
revisions: staged.revisions,
|
|
157
190
|
changes: staged.changes,
|
|
158
191
|
};
|
|
@@ -164,8 +197,12 @@ export function sameLayerText(left, right) {
|
|
|
164
197
|
const paths = Object.keys(left.documents);
|
|
165
198
|
return (paths.length === Object.keys(right.documents).length &&
|
|
166
199
|
paths.every((path) => left.documents[path] === right.documents[path]) &&
|
|
167
|
-
left.
|
|
168
|
-
|
|
200
|
+
sameBinaries(left.binaries, right.binaries));
|
|
201
|
+
}
|
|
202
|
+
function sameBinaries(left, right) {
|
|
203
|
+
const paths = Object.keys(left);
|
|
204
|
+
return (paths.length === Object.keys(right).length &&
|
|
205
|
+
paths.every((path) => sameBinary(left[path], right[path])));
|
|
169
206
|
}
|
|
170
207
|
function replayHeads(base, queue) {
|
|
171
208
|
const heads = { revisions: { ...base.revisions }, changes: { ...base.changes } };
|
|
@@ -178,6 +215,10 @@ function replayHeads(base, queue) {
|
|
|
178
215
|
else if (change.kind === 'create') {
|
|
179
216
|
delete heads.changes[change.path];
|
|
180
217
|
}
|
|
218
|
+
else if (change.kind === 'binary') {
|
|
219
|
+
delete heads.revisions[change.path];
|
|
220
|
+
delete heads.changes[change.path];
|
|
221
|
+
}
|
|
181
222
|
else if (change.kind === 'move') {
|
|
182
223
|
moveHead(heads, change.path, change.to);
|
|
183
224
|
}
|
|
@@ -193,7 +234,7 @@ export function overlayChanged(base, queue, previousBase, previousQueue, previou
|
|
|
193
234
|
sameLayerText(base, previousBase)) {
|
|
194
235
|
return {
|
|
195
236
|
documents: previousVisible.documents,
|
|
196
|
-
|
|
237
|
+
binaries: previousVisible.binaries,
|
|
197
238
|
...replayHeads(base, queue),
|
|
198
239
|
};
|
|
199
240
|
}
|
|
@@ -205,14 +246,14 @@ export function overlayChanged(base, queue, previousBase, previousQueue, previou
|
|
|
205
246
|
...Object.keys(previousBase.revisions),
|
|
206
247
|
...Object.keys(base.changes),
|
|
207
248
|
...Object.keys(previousBase.changes),
|
|
208
|
-
...base.
|
|
209
|
-
...previousBase.
|
|
249
|
+
...Object.keys(base.binaries),
|
|
250
|
+
...Object.keys(previousBase.binaries),
|
|
210
251
|
]);
|
|
211
252
|
for (const path of paths) {
|
|
212
253
|
if (base.documents[path] !== previousBase.documents[path] ||
|
|
213
254
|
base.revisions[path] !== previousBase.revisions[path] ||
|
|
214
255
|
!sameChange(base.changes[path], previousBase.changes[path]) ||
|
|
215
|
-
base.
|
|
256
|
+
!sameBinary(base.binaries[path], previousBase.binaries[path]))
|
|
216
257
|
affected.add(path);
|
|
217
258
|
}
|
|
218
259
|
const oldIds = new Set(before);
|
|
@@ -245,6 +286,7 @@ export function overlayChanged(base, queue, previousBase, previousQueue, previou
|
|
|
245
286
|
const documents = {};
|
|
246
287
|
const revisions = {};
|
|
247
288
|
const changes = {};
|
|
289
|
+
const binaries = {};
|
|
248
290
|
for (const path of affected) {
|
|
249
291
|
if (base.documents[path] !== undefined)
|
|
250
292
|
documents[path] = base.documents[path];
|
|
@@ -252,32 +294,28 @@ export function overlayChanged(base, queue, previousBase, previousQueue, previou
|
|
|
252
294
|
revisions[path] = base.revisions[path];
|
|
253
295
|
if (base.changes[path] !== undefined)
|
|
254
296
|
changes[path] = base.changes[path];
|
|
297
|
+
if (base.binaries[path] !== undefined)
|
|
298
|
+
binaries[path] = base.binaries[path];
|
|
255
299
|
}
|
|
256
|
-
const staged = overlay({
|
|
257
|
-
documents,
|
|
258
|
-
revisions,
|
|
259
|
-
changes,
|
|
260
|
-
binaryTargets: base.binaryTargets.filter((path) => affected.has(path)),
|
|
261
|
-
}, queue.filter((batch) => pathsOf(batch).some((path) => affected.has(path))));
|
|
300
|
+
const staged = overlay({ documents, revisions, changes, binaries }, queue.filter((batch) => pathsOf(batch).some((path) => affected.has(path))));
|
|
262
301
|
const mergedDocuments = { ...previousVisible.documents };
|
|
263
302
|
const mergedRevisions = { ...previousVisible.revisions };
|
|
264
303
|
const mergedChanges = { ...previousVisible.changes };
|
|
265
|
-
const
|
|
304
|
+
const mergedBinaries = { ...previousVisible.binaries };
|
|
266
305
|
for (const path of affected) {
|
|
267
306
|
delete mergedDocuments[path];
|
|
268
307
|
delete mergedRevisions[path];
|
|
269
308
|
delete mergedChanges[path];
|
|
270
|
-
|
|
309
|
+
delete mergedBinaries[path];
|
|
271
310
|
}
|
|
272
311
|
Object.assign(mergedDocuments, staged.documents);
|
|
273
312
|
Object.assign(mergedRevisions, staged.revisions);
|
|
274
313
|
Object.assign(mergedChanges, staged.changes);
|
|
275
|
-
|
|
276
|
-
mergedTargets.add(path);
|
|
314
|
+
Object.assign(mergedBinaries, staged.binaries);
|
|
277
315
|
return {
|
|
278
316
|
documents: mergedDocuments,
|
|
279
317
|
revisions: mergedRevisions,
|
|
280
318
|
changes: mergedChanges,
|
|
281
|
-
|
|
319
|
+
binaries: mergedBinaries,
|
|
282
320
|
};
|
|
283
321
|
}
|
package/dist/paths.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare function normalize(path: string): string | null;
|
|
2
|
-
export declare function relative(from: string, target: string): string;
|
|
3
2
|
export declare function beneath(prefix: string, path: string): boolean;
|
|
4
3
|
export declare function covered(prefixes: readonly string[], path: string): boolean;
|
|
5
4
|
//# sourceMappingURL=paths.d.ts.map
|
package/dist/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYrD;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,wBAAgB,OAAO,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAK1E"}
|
package/dist/paths.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
function dirname(path) {
|
|
2
|
-
const index = path.lastIndexOf('/');
|
|
3
|
-
return index === -1 ? '' : path.slice(0, index);
|
|
4
|
-
}
|
|
5
1
|
export function normalize(path) {
|
|
6
2
|
const parts = [];
|
|
7
3
|
for (const part of path.split('/')) {
|
|
@@ -17,18 +13,6 @@ export function normalize(path) {
|
|
|
17
13
|
}
|
|
18
14
|
return parts.join('/');
|
|
19
15
|
}
|
|
20
|
-
export function relative(from, target) {
|
|
21
|
-
const base = dirname(from)
|
|
22
|
-
.split('/')
|
|
23
|
-
.filter((part) => part !== '');
|
|
24
|
-
const parts = target.split('/');
|
|
25
|
-
let shared = 0;
|
|
26
|
-
while (shared < base.length && shared + 1 < parts.length && base[shared] === parts[shared]) {
|
|
27
|
-
shared += 1;
|
|
28
|
-
}
|
|
29
|
-
const up = Array.from({ length: base.length - shared }, () => '..');
|
|
30
|
-
return [...up, ...parts.slice(shared)].join('/');
|
|
31
|
-
}
|
|
32
16
|
export function beneath(prefix, path) {
|
|
33
17
|
return path === prefix || path.startsWith(`${prefix}/`);
|
|
34
18
|
}
|
package/dist/query.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Definition } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { HeadChange } from './adapter.js';
|
|
3
|
+
import type { BinaryFileRecord } from './binary.js';
|
|
3
4
|
export type Value = string | number | boolean | null;
|
|
4
5
|
export type Predicate = Value | {
|
|
5
6
|
$eq: Value;
|
|
@@ -93,6 +94,7 @@ export type QueryDocument = {
|
|
|
93
94
|
markdown?: string;
|
|
94
95
|
backlinks?: readonly Backlink[];
|
|
95
96
|
change?: HeadChange | null;
|
|
97
|
+
binaryFile?: BinaryFileRecord;
|
|
96
98
|
};
|
|
97
99
|
export type QueryGroup = {
|
|
98
100
|
key: readonly unknown[];
|
|
@@ -186,8 +188,13 @@ export type GroupShape = {
|
|
|
186
188
|
direction: Direction;
|
|
187
189
|
}[];
|
|
188
190
|
};
|
|
191
|
+
export type PlanReach = {
|
|
192
|
+
rooms: readonly string[];
|
|
193
|
+
documents: readonly string[];
|
|
194
|
+
};
|
|
189
195
|
export type Plan = {
|
|
190
196
|
rooms: readonly string[] | null;
|
|
197
|
+
reach: PlanReach | null;
|
|
191
198
|
root: Scope;
|
|
192
199
|
hop: (Scope & {
|
|
193
200
|
field: string;
|
|
@@ -199,15 +206,17 @@ export type Plan = {
|
|
|
199
206
|
limit: number | null;
|
|
200
207
|
};
|
|
201
208
|
export declare class QueryError extends Error {
|
|
209
|
+
readonly code: QueryErrorCode;
|
|
210
|
+
readonly retryable = false;
|
|
202
211
|
constructor(code: QueryErrorCode, at: string, problem: string);
|
|
203
212
|
}
|
|
204
213
|
type Entries = Readonly<Record<string, unknown>>;
|
|
205
214
|
export declare function invalid(at: string, problem: string): never;
|
|
206
215
|
export declare function plain(value: unknown): value is Entries;
|
|
207
216
|
export declare function known(value: Entries, allowed: readonly string[], at: string): void;
|
|
208
|
-
export declare function planOf(input: unknown, facts: HeldRooms): Plan;
|
|
217
|
+
export declare function planOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
209
218
|
export declare function limitOf(input: unknown): number | null;
|
|
210
|
-
export declare function filterOf(input: unknown, facts: HeldRooms): Plan;
|
|
219
|
+
export declare function filterOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
211
220
|
export declare function identityOf(plan: Plan): string;
|
|
212
221
|
export {};
|
|
213
222
|
//# sourceMappingURL=query.d.ts.map
|
package/dist/query.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EAGhB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAIpD,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAErD,MAAM,MAAM,SAAS,GACjB,KAAK,GACL;IAAE,GAAG,EAAE,KAAK,CAAA;CAAE,GACd;IAAE,GAAG,EAAE,KAAK,CAAA;CAAE,GACd;IAAE,GAAG,EAAE,SAAS,KAAK,EAAE,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,SAAS,KAAK,EAAE,CAAA;CAAE,GAC1B;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAC;IAAC,GAAG,CAA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'./model.js';
|
|
1
3
|
import { normalize } from './paths.js';
|
|
2
4
|
export class QueryError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
retryable = false;
|
|
3
7
|
constructor(code, at, problem) {
|
|
4
8
|
super(`${code} at ${at}: ${problem}`);
|
|
9
|
+
this.code = code;
|
|
5
10
|
}
|
|
6
11
|
}
|
|
7
12
|
const RANGE = ['$gt', '$gte', '$lt', '$lte'];
|
|
@@ -11,6 +16,7 @@ const RELATED = ['types', 'where', 'pathPrefix', 'field'];
|
|
|
11
16
|
const PARTS = ['fields', 'sections', 'preamble', 'markdown', 'backlinks', 'change'];
|
|
12
17
|
const ORDER = ['by', 'direction', 'nulls', 'stringSort', 'locale', 'localeOptions'];
|
|
13
18
|
const CALENDAR_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
19
|
+
const STRAY_ESCAPE = /~(?![01])/u;
|
|
14
20
|
export function invalid(at, problem) {
|
|
15
21
|
throw new QueryError('invalid-query', at, problem);
|
|
16
22
|
}
|
|
@@ -68,23 +74,29 @@ function calendarDate(value) {
|
|
|
68
74
|
const date = new Date(Date.UTC(year, month - 1, day));
|
|
69
75
|
return (date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day);
|
|
70
76
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
function itemOf(facts) {
|
|
78
|
+
return facts.type === 'array' ? facts.items : facts;
|
|
79
|
+
}
|
|
80
|
+
function fits(facts, value) {
|
|
81
|
+
const item = itemOf(facts);
|
|
82
|
+
if (item?.type === undefined)
|
|
83
|
+
return true;
|
|
84
|
+
if (item.values !== undefined)
|
|
85
|
+
return item.values.includes(value);
|
|
86
|
+
if (item.type === 'number')
|
|
74
87
|
return typeof value === 'number';
|
|
75
|
-
if (
|
|
88
|
+
if (item.type === 'integer')
|
|
89
|
+
return Number.isSafeInteger(value);
|
|
90
|
+
if (item.type === 'boolean')
|
|
91
|
+
return typeof value === 'boolean';
|
|
92
|
+
if (item.type !== 'string' || typeof value !== 'string')
|
|
76
93
|
return false;
|
|
77
|
-
if (item.
|
|
78
|
-
return item.values.includes(value);
|
|
79
|
-
if (item.kind === 'date')
|
|
80
|
-
return calendarDate(value);
|
|
81
|
-
if (item.kind === 'reference')
|
|
94
|
+
if (item.reference !== undefined)
|
|
82
95
|
return value !== '' && normalize(value) === value;
|
|
96
|
+
if (item.format === 'date')
|
|
97
|
+
return calendarDate(value);
|
|
83
98
|
return true;
|
|
84
99
|
}
|
|
85
|
-
function reference(spec) {
|
|
86
|
-
return spec.kind === 'reference' || (spec.kind === 'list' && spec.of.kind === 'reference');
|
|
87
|
-
}
|
|
88
100
|
function typing(facts, rooms, types, at) {
|
|
89
101
|
const read = rooms === null ? facts.rooms : facts.rooms.filter((room) => rooms.includes(room.locator));
|
|
90
102
|
const acquiring = !facts.listed &&
|
|
@@ -102,22 +114,46 @@ function typing(facts, rooms, types, at) {
|
|
|
102
114
|
types: types === null ? declared : declared.filter((type) => types.includes(type.name)),
|
|
103
115
|
};
|
|
104
116
|
}
|
|
105
|
-
function
|
|
106
|
-
|
|
117
|
+
function pointer(input, at) {
|
|
118
|
+
if (typeof input !== 'string' || !input.startsWith('/') || STRAY_ESCAPE.test(input)) {
|
|
119
|
+
invalid(at, 'expects a JSON Pointer');
|
|
120
|
+
}
|
|
121
|
+
return input;
|
|
122
|
+
}
|
|
123
|
+
function specs(typed, input, at) {
|
|
124
|
+
const field = pointer(input, at);
|
|
125
|
+
const declared = typed.types.flatMap((type) => {
|
|
126
|
+
const spec = pointerFacts(type, field);
|
|
127
|
+
return spec === undefined ? [] : [spec];
|
|
128
|
+
});
|
|
107
129
|
if (declared.length === 0 && !typed.untyped) {
|
|
108
130
|
throw new QueryError('unknown-field', at, `no MD Type it reads declares ${field}`);
|
|
109
131
|
}
|
|
110
|
-
|
|
132
|
+
if (!declared.some((spec) => spec.conditional))
|
|
133
|
+
return declared;
|
|
134
|
+
return declared.map((spec) => ({
|
|
135
|
+
facts: { prose: false },
|
|
136
|
+
through: several(spec),
|
|
137
|
+
conditional: true,
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
function several(spec) {
|
|
141
|
+
return spec.through || spec.facts.type === 'array';
|
|
142
|
+
}
|
|
143
|
+
function single(spec) {
|
|
144
|
+
return spec.facts.type !== undefined && spec.facts.type !== 'array';
|
|
145
|
+
}
|
|
146
|
+
function every(declared, holds) {
|
|
147
|
+
return declared.length > 0 && declared.every(holds);
|
|
111
148
|
}
|
|
112
149
|
function kind(declared, checked, at) {
|
|
113
|
-
if (checked === null ||
|
|
150
|
+
if (checked === null ||
|
|
151
|
+
declared.length === 0 ||
|
|
152
|
+
declared.some((spec) => fits(spec.facts, checked))) {
|
|
114
153
|
return;
|
|
115
154
|
}
|
|
116
155
|
throw new QueryError('wrong-kind', at, `${JSON.stringify(checked)} is not of its field's kind`);
|
|
117
156
|
}
|
|
118
|
-
function listed(declared, list) {
|
|
119
|
-
return declared.length > 0 && declared.every((spec) => (spec.kind === 'list') === list);
|
|
120
|
-
}
|
|
121
157
|
function test(declared, input, at) {
|
|
122
158
|
if (!plain(input)) {
|
|
123
159
|
const equal = value(input, at);
|
|
@@ -131,8 +167,11 @@ function test(declared, input, at) {
|
|
|
131
167
|
const stray = operators.find((operator) => !RANGE.includes(operator));
|
|
132
168
|
if (stray !== undefined)
|
|
133
169
|
invalid(place(at, stray), 'cannot join a range');
|
|
134
|
-
if (
|
|
170
|
+
if (every(declared, (spec) => spec.facts.type === 'array'))
|
|
135
171
|
invalid(at, 'a range on a list');
|
|
172
|
+
if (every(declared, (spec) => spec.facts.type === 'boolean' || spec.facts.type === 'object')) {
|
|
173
|
+
throw new QueryError('wrong-kind', at, 'its field does not compare in order');
|
|
174
|
+
}
|
|
136
175
|
return {
|
|
137
176
|
op: 'range',
|
|
138
177
|
bounds: RANGE.filter((operator) => operators.includes(operator)).map((operator) => {
|
|
@@ -165,7 +204,7 @@ function test(declared, input, at) {
|
|
|
165
204
|
return { op: 'nin', values: compared };
|
|
166
205
|
if (compared.includes(null))
|
|
167
206
|
invalid(where, 'a list holds no null');
|
|
168
|
-
if (
|
|
207
|
+
if (every(declared, single))
|
|
169
208
|
invalid(where, 'the field is not a list');
|
|
170
209
|
return { op: 'all', values: compared };
|
|
171
210
|
}
|
|
@@ -173,7 +212,7 @@ function test(declared, input, at) {
|
|
|
173
212
|
if (!Number.isSafeInteger(operand) || operand < 0) {
|
|
174
213
|
invalid(where, 'expects a nonnegative integer');
|
|
175
214
|
}
|
|
176
|
-
if (
|
|
215
|
+
if (every(declared, single))
|
|
177
216
|
invalid(where, 'the field is not a list');
|
|
178
217
|
return { op: 'size', size: operand };
|
|
179
218
|
}
|
|
@@ -186,7 +225,7 @@ function condition(typed, input, at) {
|
|
|
186
225
|
invalid(at, 'expects an object of field predicates');
|
|
187
226
|
const conditions = [];
|
|
188
227
|
for (const name of Object.keys(input).sort()) {
|
|
189
|
-
const where = place(at, name);
|
|
228
|
+
const where = name.startsWith('/') ? `${at}${name}` : place(at, name);
|
|
190
229
|
const entry = input[name];
|
|
191
230
|
if (name === '$and' || name === '$or') {
|
|
192
231
|
const nested = list(entry, where).map((item, index) => condition(typed, item, `${where}[${index}]`));
|
|
@@ -215,19 +254,19 @@ function scope(facts, rooms, input, at) {
|
|
|
215
254
|
pathPrefix: input.pathPrefix === undefined ? null : directory(input.pathPrefix, place(at, 'pathPrefix')),
|
|
216
255
|
};
|
|
217
256
|
}
|
|
218
|
-
function
|
|
219
|
-
if (typeof field !== 'string')
|
|
220
|
-
invalid(at, 'expects a field name');
|
|
257
|
+
function referenceName(typed, field, at) {
|
|
221
258
|
const declared = specs(typed, field, at);
|
|
222
|
-
if (declared.length > 0 &&
|
|
259
|
+
if (declared.length > 0 &&
|
|
260
|
+
!declared.some((spec) => spec.conditional || referenceField(spec.facts))) {
|
|
223
261
|
invalid(at, 'not a reference field');
|
|
262
|
+
}
|
|
224
263
|
return field;
|
|
225
264
|
}
|
|
226
265
|
function hopOf(facts, rooms, root, input) {
|
|
227
266
|
if (!plain(input))
|
|
228
267
|
invalid('hop', 'expects an object');
|
|
229
268
|
known(input, RELATED, 'hop');
|
|
230
|
-
const field =
|
|
269
|
+
const field = referenceName(root, input.field, 'hop.field');
|
|
231
270
|
const { types, where, pathPrefix } = scope(facts, rooms, input, 'hop');
|
|
232
271
|
return { types, where, pathPrefix, field };
|
|
233
272
|
}
|
|
@@ -236,14 +275,16 @@ function backlinksOf(facts, rooms, input) {
|
|
|
236
275
|
invalid('backlinks', 'expects an object');
|
|
237
276
|
known(input, RELATED, 'backlinks');
|
|
238
277
|
const { typed, types, where, pathPrefix } = scope(facts, rooms, input, 'backlinks');
|
|
239
|
-
const field = input.field === undefined ? null :
|
|
278
|
+
const field = input.field === undefined ? null : referenceName(typed, input.field, 'backlinks.field');
|
|
240
279
|
return { types, where, pathPrefix, field };
|
|
241
280
|
}
|
|
242
281
|
function keyPlan(typed, input, at, path) {
|
|
243
282
|
if (input === 'room' || input === 'type' || (path && input === 'path'))
|
|
244
283
|
return { of: input };
|
|
245
|
-
if (plain(input) &&
|
|
246
|
-
specs(typed, input.field, place(at, 'field'))
|
|
284
|
+
if (plain(input) && Object.hasOwn(input, 'field') && Object.keys(input).length === 1) {
|
|
285
|
+
if (specs(typed, input.field, place(at, 'field')).some(several)) {
|
|
286
|
+
invalid(place(at, 'field'), 'a path that can hold several values');
|
|
287
|
+
}
|
|
247
288
|
return { of: 'field', field: input.field };
|
|
248
289
|
}
|
|
249
290
|
return invalid(at, path ? 'expects room, path, type or a field' : 'expects room, type or a field');
|
|
@@ -301,10 +342,10 @@ function parts(typed, input, at, fields) {
|
|
|
301
342
|
return 'all';
|
|
302
343
|
const named = list(input, at);
|
|
303
344
|
named.forEach((name, index) => {
|
|
304
|
-
if (typeof name !== 'string')
|
|
305
|
-
invalid(`${at}[${index}]`, 'expects a name');
|
|
306
345
|
if (fields)
|
|
307
346
|
specs(typed, name, `${at}[${index}]`);
|
|
347
|
+
else if (typeof name !== 'string')
|
|
348
|
+
invalid(`${at}[${index}]`, 'expects a name');
|
|
308
349
|
});
|
|
309
350
|
return named;
|
|
310
351
|
}
|
|
@@ -372,7 +413,7 @@ function groupShape(typed, input) {
|
|
|
372
413
|
});
|
|
373
414
|
return { kind: 'groups', groupBy, orderBy };
|
|
374
415
|
}
|
|
375
|
-
export function planOf(input, facts) {
|
|
416
|
+
export function planOf(input, facts, reach = null) {
|
|
376
417
|
if (!plain(input))
|
|
377
418
|
invalid('query', 'expects a query object');
|
|
378
419
|
const grouped = input.groupBy !== undefined;
|
|
@@ -386,6 +427,7 @@ export function planOf(input, facts) {
|
|
|
386
427
|
const { typed, ...root } = scope(facts, rooms, input, '');
|
|
387
428
|
return {
|
|
388
429
|
rooms,
|
|
430
|
+
reach,
|
|
389
431
|
root,
|
|
390
432
|
hop: input.hop === undefined ? null : hopOf(facts, rooms, typed, input.hop),
|
|
391
433
|
backlinks: input.backlinks === undefined ? null : backlinksOf(facts, rooms, input.backlinks),
|
|
@@ -401,11 +443,11 @@ export function limitOf(input) {
|
|
|
401
443
|
}
|
|
402
444
|
return input;
|
|
403
445
|
}
|
|
404
|
-
export function filterOf(input, facts) {
|
|
446
|
+
export function filterOf(input, facts, reach = null) {
|
|
405
447
|
if (!plain(input))
|
|
406
448
|
invalid('documents', 'expects a filter object');
|
|
407
449
|
known(input, FILTER, '');
|
|
408
|
-
return planOf({ ...input, select: {} }, facts);
|
|
450
|
+
return planOf({ ...input, select: {} }, facts, reach);
|
|
409
451
|
}
|
|
410
452
|
function canonical(value) {
|
|
411
453
|
if (Array.isArray(value))
|