@okfit/cli 0.2.0 → 0.4.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/verify/splice.js DELETED
@@ -1,75 +0,0 @@
1
- import { MarkdownEdit } from "@effected/markdown";
2
-
3
- //#region src/verify/splice.ts
4
- /** Prefix two spaces to every line but the first, joining with `newline` (V-13). */
5
- const reindent = (original, newline) => original.split(/\r\n|\n|\r/).map((line, index) => index === 0 ? line : ` ${line}`).join(newline);
6
- /**
7
- * Build the one edit for `target` (contract §3.2). Never calls a YAML
8
- * stringifier: the only syntax emitted is `- `, `{`, `}`, `: `, `,`,
9
- * spaces and `newline`.
10
- *
11
- * @internal
12
- */
13
- const splice = (target, entry, newline) => {
14
- const flow = `{ by: ${entry.by}, at: ${entry.at} }`;
15
- const block = (indent) => `${indent}- by: ${entry.by}${newline}${indent} at: ${entry.at}`;
16
- switch (target._tag) {
17
- case "absent": return MarkdownEdit.make({
18
- offset: target.insertAt,
19
- length: 0,
20
- content: `verified:${newline} - by: ${entry.by}${newline} at: ${entry.at}${newline}`
21
- });
22
- case "blockSeq": {
23
- const fragment = target.lastItemStyle === "flow" ? `${target.indent}- ${flow}` : block(target.indent);
24
- return MarkdownEdit.make({
25
- offset: target.insertAt,
26
- length: 0,
27
- content: target.afterNewline ? `${fragment}${newline}` : `${newline}${fragment}`
28
- });
29
- }
30
- case "flowSeq": return MarkdownEdit.make({
31
- offset: target.insertAt,
32
- length: 0,
33
- content: target.empty ? flow : `, ${flow}`
34
- });
35
- case "bareMapping": return target.style === "flow" ? MarkdownEdit.make({
36
- offset: target.start,
37
- length: target.end - target.start,
38
- content: `${newline}${target.indent}- ${target.original}${newline}${target.indent}- ${flow}`
39
- }) : MarkdownEdit.make({
40
- offset: target.start,
41
- length: target.end - target.start,
42
- content: `${newline}${target.indent}- ${reindent(target.original, newline)}${newline}${block(target.indent)}${newline}`
43
- });
44
- }
45
- };
46
- /**
47
- * Build the one edit for `target` (contract §6.1). Never calls a YAML
48
- * stringifier: the only syntax emitted is the indent, `at: `, the
49
- * preserved quote character (if any), and `newline`. `encodedAt` is
50
- * already `Schema.encodeSync(Timestamp)`'d by the caller (S-1: splice,
51
- * never `YamlFormat.modify` — it drops quote style and re-normalises line
52
- * endings, V-12/V-15 violations `sync/generated.ts` cannot afford).
53
- *
54
- * @internal
55
- */
56
- const spliceGenerated = (target, encodedAt, newline) => {
57
- switch (target._tag) {
58
- case "insertAfterLastKey": return MarkdownEdit.make({
59
- offset: target.insertAt,
60
- length: 0,
61
- content: `${target.indent}at: ${encodedAt}${newline}`
62
- });
63
- case "replaceScalar": {
64
- const quoted = target.quote === "single-quoted" ? `'${encodedAt}'` : target.quote === "double-quoted" ? `"${encodedAt}"` : encodedAt;
65
- return MarkdownEdit.make({
66
- offset: target.start,
67
- length: target.end - target.start,
68
- content: quoted
69
- });
70
- }
71
- }
72
- };
73
-
74
- //#endregion
75
- export { splice, spliceGenerated };