@okfit/engine 0.14.1 → 0.16.0
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/config/anchor.js +1 -1
- package/config/layer.js +1 -1
- package/edits/FrontmatterEdits.js +66 -18
- package/errors.js +102 -6
- package/index.d.ts +685 -53
- package/index.js +12 -6
- package/move/references.js +267 -0
- package/move/run.js +212 -0
- package/package.json +18 -18
- package/query/ConceptQuery.js +15 -4
- package/render/context.js +20 -3
- package/render/move.js +52 -0
- package/render/query.js +53 -6
- package/render/sync.js +4 -1
- package/render/verify.js +43 -1
- package/session/BundleSession.js +3 -1
- package/sync/generated.js +112 -49
- package/sync/index.js +4 -3
- package/sync/publication.js +3 -3
- package/sync/run.js +13 -4
- package/targets/inside.js +15 -0
- package/targets/resolve.js +146 -0
- package/trust/run.js +32 -0
- package/validate/run.js +8 -4
- package/verify/diff.js +63 -0
- package/verify/integrity.js +309 -0
- package/verify/locate.js +3 -10
- package/verify/revoke.js +101 -0
- package/verify/run.js +193 -21
- package/verify/select.js +30 -11
- package/verify/splice.js +20 -34
- package/version.js +1 -1
package/config/anchor.js
CHANGED
|
@@ -47,7 +47,7 @@ const resolveProjectRoot = (input) => {
|
|
|
47
47
|
* `<project root>/<bundle.path>`, absolute (K-2). `config` is the MERGED
|
|
48
48
|
* config, so `bundle.path` is `OkfitConfig.DEFAULTS.bundle.path` (`"okf"`)
|
|
49
49
|
* unless a file or profile overrode it. The bundle root is never what
|
|
50
|
-
* `
|
|
50
|
+
* `--root` names.
|
|
51
51
|
*
|
|
52
52
|
* @public
|
|
53
53
|
*/
|
package/config/layer.js
CHANGED
|
@@ -31,7 +31,7 @@ import { Cause, Effect, FileSystem, Option, Result } from "effect";
|
|
|
31
31
|
* `save`/`update` do not fail with `ConfigDefaultPathMissingError`; nothing
|
|
32
32
|
* here sets it explicitly any more.
|
|
33
33
|
*
|
|
34
|
-
* `discoveryCwd` is `
|
|
34
|
+
* `discoveryCwd` is `--root` when given, else `process.cwd()` (K-2), passed
|
|
35
35
|
* straight through as `upwardWalk`'s own `cwd` so nothing in this module
|
|
36
36
|
* reads the process.
|
|
37
37
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { documentNewline, locate, locateTopLevelScalar, stripBom } from "../verify/locate.js";
|
|
2
|
+
import { formatDigest, locateIntegrity, spliceIntegrityVerified } from "../verify/integrity.js";
|
|
2
3
|
import { orderVerifyEdits, splice, spliceTopLevelScalar } from "../verify/splice.js";
|
|
3
4
|
import { DiagnosticRange } from "@okfit/core";
|
|
4
5
|
import { Effect, Result, Runtime, Schema } from "effect";
|
|
@@ -62,25 +63,41 @@ var FrontmatterEdits = class {
|
|
|
62
63
|
const edit = spliceTopLevelScalar(target, "status", status, documentNewline(text));
|
|
63
64
|
return [shift(edit, bom.length)];
|
|
64
65
|
});
|
|
65
|
-
/**
|
|
66
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Edits that append one verified entry and bind it with `integrity.verified`
|
|
68
|
+
* (`content` is the content digest of the source as passed), the same splice
|
|
69
|
+
* `okfit verify` performs. Only the `verified` slot of an existing `integrity`
|
|
70
|
+
* block is rewritten.
|
|
71
|
+
*/
|
|
72
|
+
static verified = (source, entry, content) => Effect.gen(function* () {
|
|
67
73
|
const { text, bom } = stripBom(source);
|
|
68
74
|
const target = yield* locate(text);
|
|
69
75
|
if (target._tag === "unsupported") return yield* new UnsupportedFrontmatterError({
|
|
70
76
|
key: "verified",
|
|
71
77
|
shape: target.shape
|
|
72
78
|
});
|
|
73
|
-
const
|
|
74
|
-
|
|
79
|
+
const newline = documentNewline(text);
|
|
80
|
+
const verifiedEdit = splice(target, entry, newline);
|
|
81
|
+
const integrity = yield* locateIntegrity(text);
|
|
82
|
+
if (integrity._tag === "unsupported") return yield* new UnsupportedFrontmatterError({
|
|
83
|
+
key: "integrity",
|
|
84
|
+
shape: integrity.shape
|
|
85
|
+
});
|
|
86
|
+
const integrityEdit = spliceIntegrityVerified(integrity, text, {
|
|
87
|
+
...entry,
|
|
88
|
+
content
|
|
89
|
+
}, newline);
|
|
90
|
+
return orderVerifyEdits(verifiedEdit, void 0, integrityEdit).map((edit) => shift(edit, bom.length));
|
|
75
91
|
});
|
|
76
92
|
/**
|
|
77
|
-
* Edits that append one verified entry AND set top-level
|
|
78
|
-
* `okfit verify --stable` performs. A `status` scalar already
|
|
79
|
-
* status edit, and equal-offset inserts are merged with `status:`
|
|
80
|
-
*
|
|
81
|
-
* on it fails even when its value
|
|
93
|
+
* Edits that append one verified entry, bind it with `integrity.verified` AND set top-level
|
|
94
|
+
* `status`, the combined write `okfit verify --stable` performs. A `status` scalar already
|
|
95
|
+
* equal to `status` makes no status edit, and equal-offset inserts are merged with `status:`
|
|
96
|
+
* first, then `verified:`, then `integrity:`. Unlike the CLI, which reads the parsed status,
|
|
97
|
+
* this always locates `status`, so an unsupported shape on it fails even when its value
|
|
98
|
+
* already matches.
|
|
82
99
|
*/
|
|
83
|
-
static verifiedWithStatus = (source, entry, status) => Effect.gen(function* () {
|
|
100
|
+
static verifiedWithStatus = (source, entry, status, content) => Effect.gen(function* () {
|
|
84
101
|
const { text, bom } = stripBom(source);
|
|
85
102
|
const located = yield* locate(text);
|
|
86
103
|
if (located._tag === "unsupported") return yield* new UnsupportedFrontmatterError({
|
|
@@ -96,12 +113,23 @@ var FrontmatterEdits = class {
|
|
|
96
113
|
shape: target.shape
|
|
97
114
|
});
|
|
98
115
|
if (target._tag !== "replaceScalar" || unquote(text.slice(target.start, target.end), target.quote) !== status) statusEdit = spliceTopLevelScalar(target, "status", status, newline);
|
|
99
|
-
|
|
116
|
+
const integrity = yield* locateIntegrity(text);
|
|
117
|
+
if (integrity._tag === "unsupported") return yield* new UnsupportedFrontmatterError({
|
|
118
|
+
key: "integrity",
|
|
119
|
+
shape: integrity.shape
|
|
120
|
+
});
|
|
121
|
+
const integrityEdit = spliceIntegrityVerified(integrity, text, {
|
|
122
|
+
...entry,
|
|
123
|
+
content
|
|
124
|
+
}, newline);
|
|
125
|
+
return orderVerifyEdits(verifiedEdit, statusEdit, integrityEdit).map((edit) => shift(edit, bom.length));
|
|
100
126
|
});
|
|
101
127
|
/**
|
|
102
|
-
* Edits that stamp `renders[i].
|
|
103
|
-
* place, a missing key is inserted on the line after
|
|
104
|
-
*
|
|
128
|
+
* Edits that stamp `renders[i].body` with `digests[i]` (16 hex, quoted when numeric-looking): an
|
|
129
|
+
* existing value is replaced in place, a missing key is inserted on the line after
|
|
130
|
+
* `renders[i].path` at that key's column. An `undefined` digest skips its entry. A legacy `renders[i].body_sha256` line in the same
|
|
131
|
+
* entry is removed, so an entry never ends up with both keys. Block-style `renders` only; flow
|
|
132
|
+
* style fails with `UnsupportedFrontmatterError`.
|
|
105
133
|
*/
|
|
106
134
|
static rendersDigests = (source, digests) => Effect.gen(function* () {
|
|
107
135
|
const { text, bom } = stripBom(source);
|
|
@@ -119,13 +147,33 @@ var FrontmatterEdits = class {
|
|
|
119
147
|
const newline = documentNewline(text);
|
|
120
148
|
const edits = [];
|
|
121
149
|
for (const [index, digest] of digests.entries()) {
|
|
122
|
-
|
|
150
|
+
if (digest === void 0) continue;
|
|
151
|
+
const formatted = formatDigest(digest);
|
|
152
|
+
const legacySpan = DiagnosticRange.forFrontmatterPath(document, [
|
|
123
153
|
"renders",
|
|
124
154
|
index,
|
|
125
155
|
"body_sha256"
|
|
126
156
|
]);
|
|
157
|
+
if (legacySpan !== void 0 && legacySpan.offset !== block.offset) {
|
|
158
|
+
const start = text.lastIndexOf("\n", legacySpan.offset - 1) + 1;
|
|
159
|
+
const nl = text.indexOf("\n", legacySpan.offset + legacySpan.length);
|
|
160
|
+
const end = nl === -1 ? text.length : nl + 1;
|
|
161
|
+
const prefix = text.slice(start, legacySpan.offset);
|
|
162
|
+
if (!/^[ ]*(?:-[ ]+)*(?:"body_sha256"|'body_sha256'|body_sha256)[ ]*:[ ]*$/u.test(prefix)) return yield* unsupported("flow-mapping");
|
|
163
|
+
if (prefix.includes("-")) return yield* unsupported("dash-prefixed-key");
|
|
164
|
+
edits.push(shift(MarkdownEdit.make({
|
|
165
|
+
offset: start,
|
|
166
|
+
length: end - start,
|
|
167
|
+
content: ""
|
|
168
|
+
}), bom.length));
|
|
169
|
+
}
|
|
170
|
+
const digestSpan = DiagnosticRange.forFrontmatterPath(document, [
|
|
171
|
+
"renders",
|
|
172
|
+
index,
|
|
173
|
+
"body"
|
|
174
|
+
]);
|
|
127
175
|
if (digestSpan !== void 0 && digestSpan.offset !== block.offset) {
|
|
128
|
-
const content = digestSpan.length === 0 ? ` ${
|
|
176
|
+
const content = digestSpan.length === 0 ? ` ${formatted}` : formatted;
|
|
129
177
|
edits.push(shift(MarkdownEdit.make({
|
|
130
178
|
offset: digestSpan.offset,
|
|
131
179
|
length: digestSpan.length,
|
|
@@ -148,10 +196,10 @@ var FrontmatterEdits = class {
|
|
|
148
196
|
edits.push(shift(MarkdownEdit.make({
|
|
149
197
|
offset: lineEnd,
|
|
150
198
|
length: 0,
|
|
151
|
-
content: `${newline}${" ".repeat(column)}
|
|
199
|
+
content: `${newline}${" ".repeat(column)}body: ${formatted}`
|
|
152
200
|
}), bom.length));
|
|
153
201
|
}
|
|
154
|
-
return edits;
|
|
202
|
+
return edits.toSorted((a, b) => a.offset - b.offset);
|
|
155
203
|
});
|
|
156
204
|
};
|
|
157
205
|
|
package/errors.js
CHANGED
|
@@ -75,7 +75,8 @@ var VerifyUnsupportedFrontmatterError = class extends Schema.TaggedError()("Veri
|
|
|
75
75
|
key: Schema.optionalKey(Schema.Literals([
|
|
76
76
|
"verified",
|
|
77
77
|
"status",
|
|
78
|
-
"stale_after"
|
|
78
|
+
"stale_after",
|
|
79
|
+
"integrity"
|
|
79
80
|
]))
|
|
80
81
|
}) {
|
|
81
82
|
[Runtime.errorExitCode] = 3;
|
|
@@ -83,6 +84,22 @@ var VerifyUnsupportedFrontmatterError = class extends Schema.TaggedError()("Veri
|
|
|
83
84
|
return `"${this.id}"'s ${this.key ?? "verified"} value is a shape okfit verify cannot edit (${this.shape}); edit it by hand`;
|
|
84
85
|
}
|
|
85
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* `okfit verify --revoke` found no `verified` entry by the resolved actor on
|
|
89
|
+
* the concept, so there is nothing to remove. Exit 3, like any other verify
|
|
90
|
+
* outcome that cannot proceed on the concept.
|
|
91
|
+
*
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
var VerifyNothingToRevokeError = class extends Schema.TaggedError()("VerifyNothingToRevokeError", {
|
|
95
|
+
id: Schema.String,
|
|
96
|
+
actor: Schema.String
|
|
97
|
+
}) {
|
|
98
|
+
[Runtime.errorExitCode] = 3;
|
|
99
|
+
get message() {
|
|
100
|
+
return `"${this.id}" has no verified entry by ${this.actor} to revoke`;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
86
103
|
/** The error's `message` when it has one as a string, else `String(error)`. */
|
|
87
104
|
const messageOf = (error) => {
|
|
88
105
|
if (typeof error === "object" && error !== null && "message" in error) {
|
|
@@ -157,21 +174,25 @@ var SyncPublicationConflictError = class extends Schema.TaggedError()("SyncPubli
|
|
|
157
174
|
var VerifySelectionError = class extends Schema.TaggedError()("VerifySelectionError", {
|
|
158
175
|
reason: Schema.Literals([
|
|
159
176
|
"no-selection",
|
|
160
|
-
"
|
|
177
|
+
"targets-and-batch",
|
|
161
178
|
"unknown-type",
|
|
162
179
|
"status-conflict",
|
|
163
180
|
"status-and-batch",
|
|
164
|
-
"dry-run-needs-verify"
|
|
181
|
+
"dry-run-needs-verify",
|
|
182
|
+
"revoke-needs-id",
|
|
183
|
+
"revoke-conflict"
|
|
165
184
|
]),
|
|
166
185
|
detail: Schema.optionalKey(Schema.String)
|
|
167
186
|
}) {
|
|
168
187
|
[Runtime.errorExitCode] = 64;
|
|
169
188
|
get message() {
|
|
170
189
|
if (this.reason === "no-selection") return "verify needs a concept id, --all, or --type <Type> (run in a terminal to pick interactively)";
|
|
171
|
-
if (this.reason === "
|
|
190
|
+
if (this.reason === "targets-and-batch") return "verify takes concept targets or --all/--type, not both";
|
|
191
|
+
if (this.reason === "revoke-needs-id") return "--revoke needs at least one concept target";
|
|
192
|
+
if (this.reason === "revoke-conflict") return `--revoke removes your own verification of the named concepts; it cannot combine with ${this.detail ?? "other selectors"}`;
|
|
172
193
|
if (this.reason === "status-conflict") return "verify takes --stable or --draft, not both";
|
|
173
194
|
if (this.reason === "dry-run-needs-verify") return "--dry-run needs --verify; bare okfit stale writes nothing";
|
|
174
|
-
if (this.reason === "status-and-batch") return "--stable and --draft need
|
|
195
|
+
if (this.reason === "status-and-batch") return "--stable and --draft need exactly one concept target; batch mode never changes status";
|
|
175
196
|
return `type "${this.detail ?? ""}" is not declared in the config`;
|
|
176
197
|
}
|
|
177
198
|
};
|
|
@@ -251,6 +272,81 @@ var QuerySelectionError = class extends Schema.TaggedError()("QuerySelectionErro
|
|
|
251
272
|
return "query list takes --verified or --unverified, not both";
|
|
252
273
|
}
|
|
253
274
|
};
|
|
275
|
+
/**
|
|
276
|
+
* One argument that did not resolve to a concept target.
|
|
277
|
+
*
|
|
278
|
+
* @public
|
|
279
|
+
*/
|
|
280
|
+
const TargetFailure = Schema.Struct({
|
|
281
|
+
arg: Schema.String,
|
|
282
|
+
reason: Schema.Literals([
|
|
283
|
+
"not-found",
|
|
284
|
+
"ambiguous",
|
|
285
|
+
"outside-bundle",
|
|
286
|
+
"reserved",
|
|
287
|
+
"not-a-concept"
|
|
288
|
+
]),
|
|
289
|
+
suggestion: Schema.optionalKey(Schema.String),
|
|
290
|
+
candidates: Schema.optionalKey(Schema.Tuple([Schema.String, Schema.String]))
|
|
291
|
+
});
|
|
292
|
+
const targetLine = (failure) => {
|
|
293
|
+
switch (failure.reason) {
|
|
294
|
+
case "ambiguous": return `"${failure.arg}" is ambiguous: it names both ${failure.candidates?.[0]} and ${failure.candidates?.[1]}; pass an id or an absolute path`;
|
|
295
|
+
case "outside-bundle": return `"${failure.arg}" is outside the bundle`;
|
|
296
|
+
case "reserved": return `"${failure.arg}" is a reserved file, not a concept`;
|
|
297
|
+
case "not-a-concept": return `"${failure.arg}" did not load as a concept (run okfit validate)`;
|
|
298
|
+
default: return `no concept "${failure.arg}"${failure.suggestion === void 0 ? "" : ` (did you mean ${failure.suggestion}?)`}`;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* One or more concept targets did not resolve. Every bad argument is listed;
|
|
303
|
+
* nothing ran. Exit 64: a usage error.
|
|
304
|
+
*
|
|
305
|
+
* @public
|
|
306
|
+
*/
|
|
307
|
+
var TargetResolutionError = class extends Schema.TaggedError()("TargetResolutionError", { failures: Schema.Array(TargetFailure) }) {
|
|
308
|
+
[Runtime.errorExitCode] = 64;
|
|
309
|
+
get message() {
|
|
310
|
+
return this.failures.map(targetLine).join("\n");
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* `okfit mv` refused before writing anything. `outside-bundle`, `destination-exists`, `reserved`,
|
|
315
|
+
* `same-path` and `invalid-name` (whitespace in a destination path segment) name a bad destination
|
|
316
|
+
* (`detail` is the destination); `unrewritable` lists every link that needs rewriting for this move
|
|
317
|
+
* (`file: url`, one per line) whose URL text could not be located; `project-file` refuses to move the
|
|
318
|
+
* bundle's root project file (`detail` is its path), which must stay at the bundle root;
|
|
319
|
+
* `unloaded-files` lists (one per line) the bundle's Markdown files that did not load as concepts,
|
|
320
|
+
* whose links to the moved file could not be rewritten.
|
|
321
|
+
*
|
|
322
|
+
* @public
|
|
323
|
+
*/
|
|
324
|
+
var MoveError = class extends Schema.TaggedError()("MoveError", {
|
|
325
|
+
reason: Schema.Literals([
|
|
326
|
+
"outside-bundle",
|
|
327
|
+
"destination-exists",
|
|
328
|
+
"reserved",
|
|
329
|
+
"same-path",
|
|
330
|
+
"invalid-name",
|
|
331
|
+
"unrewritable",
|
|
332
|
+
"project-file",
|
|
333
|
+
"unloaded-files"
|
|
334
|
+
]),
|
|
335
|
+
detail: Schema.optionalKey(Schema.String)
|
|
336
|
+
}) {
|
|
337
|
+
[Runtime.errorExitCode] = 64;
|
|
338
|
+
get message() {
|
|
339
|
+
const detail = this.detail ?? "";
|
|
340
|
+
if (this.reason === "outside-bundle") return `destination ${detail} is outside the bundle`;
|
|
341
|
+
if (this.reason === "destination-exists") return `destination ${detail} already exists`;
|
|
342
|
+
if (this.reason === "reserved") return `${detail} is a reserved file name`;
|
|
343
|
+
if (this.reason === "same-path") return "source and destination are the same file";
|
|
344
|
+
if (this.reason === "invalid-name") return `destination ${detail} contains whitespace; name it without spaces`;
|
|
345
|
+
if (this.reason === "project-file") return `${detail} is the bundle's project file and must stay at the bundle root; edit it in place`;
|
|
346
|
+
if (this.reason === "unloaded-files") return `these Markdown files are in the bundle but did not load as concepts, so their links to the moved file cannot be rewritten; run \`okfit validate\` and fix them first:\n${detail}`;
|
|
347
|
+
return `these links could not be located for rewriting; nothing was moved:\n${detail}`;
|
|
348
|
+
}
|
|
349
|
+
};
|
|
254
350
|
|
|
255
351
|
//#endregion
|
|
256
|
-
export { ConfigMalformedError, ConfigPathNotFoundError, DocumentPathError, InitOverwriteError, QueryConceptNotFoundError, QuerySelectionError, QueryUnknownVocabularyError, SyncPlanStaleError, SyncPublicationConflictError, SyncStagedLogError, VerifyConceptNotFoundError, VerifySelectionError, VerifyUnsupportedFrontmatterError };
|
|
352
|
+
export { ConfigMalformedError, ConfigPathNotFoundError, DocumentPathError, InitOverwriteError, MoveError, QueryConceptNotFoundError, QuerySelectionError, QueryUnknownVocabularyError, SyncPlanStaleError, SyncPublicationConflictError, SyncStagedLogError, TargetFailure, TargetResolutionError, VerifyConceptNotFoundError, VerifyNothingToRevokeError, VerifySelectionError, VerifyUnsupportedFrontmatterError };
|