deltafold 0.0.0 → 0.1.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/README.md +278 -4
- package/dist/changelog.d.ts +116 -0
- package/dist/changelog.d.ts.map +1 -0
- package/dist/changelog.js +304 -0
- package/dist/changelog.js.map +1 -0
- package/dist/document-BZcZo9nr.js +171 -0
- package/dist/document-BZcZo9nr.js.map +1 -0
- package/dist/document-DWHsgywm.d.ts +257 -0
- package/dist/document-DWHsgywm.d.ts.map +1 -0
- package/dist/html.d.ts +8 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +13 -0
- package/dist/html.js.map +1 -0
- package/dist/index.d.ts +517 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2126 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown.d.ts +8 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +16 -0
- package/dist/markdown.js.map +1 -0
- package/dist/mdast-DiRsYwPU.js +108 -0
- package/dist/mdast-DiRsYwPU.js.map +1 -0
- package/dist/package-BfBYnaCz.d.ts +1125 -0
- package/dist/package-BfBYnaCz.d.ts.map +1 -0
- package/dist/rolldown-runtime-D8jQpDG7.js +12 -0
- package/package.json +13 -1
- package/src/features/documents/changelog.ts +450 -0
- package/src/features/documents/document.ts +357 -0
- package/src/features/documents/index.ts +4 -0
- package/src/features/documents/public-document.ts +31 -0
- package/src/features/documents/sections.ts +44 -0
- package/src/features/execution/executor.ts +968 -0
- package/src/features/execution/handler.ts +485 -0
- package/src/features/execution/settlement.ts +52 -0
- package/src/features/package.ts +32 -0
- package/src/features/planning/guide.ts +56 -0
- package/src/features/planning/history.ts +174 -0
- package/src/features/planning/identifiers.ts +43 -0
- package/src/features/planning/resolve-error.ts +201 -0
- package/src/features/planning/resolve.ts +724 -0
- package/src/features/planning/rewrite.ts +331 -0
- package/src/features/planning/validate.ts +388 -0
- package/src/foundation/action.ts +188 -0
- package/src/foundation/change.ts +147 -0
- package/src/foundation/instruction.ts +110 -0
- package/src/foundation/migration.ts +236 -0
- package/src/foundation/plan.ts +245 -0
- package/src/foundation/rule.ts +74 -0
- package/src/foundation/shortcut.ts +79 -0
- package/src/foundation/template.ts +28 -0
- package/src/foundation/version.ts +78 -0
- package/src/index.ts +22 -11
- package/src/renderers/html.ts +12 -0
- package/src/renderers/markdown.ts +12 -0
- package/src/renderers/mdast.ts +120 -0
- package/src/types.ts +2 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { Data, Predicate, type Pipeable } from "effect";
|
|
2
|
+
|
|
3
|
+
import type { Version } from "../../foundation/version.ts";
|
|
4
|
+
import type { Package } from "../package.ts";
|
|
5
|
+
|
|
6
|
+
/** @since @next */
|
|
7
|
+
export type Text = { readonly _tag: "Text"; readonly value: string };
|
|
8
|
+
/** @since @next */
|
|
9
|
+
export type Code = { readonly _tag: "Code"; readonly value: string };
|
|
10
|
+
/** @since @next */
|
|
11
|
+
export type Link = {
|
|
12
|
+
readonly _tag: "Link";
|
|
13
|
+
readonly url: string;
|
|
14
|
+
readonly children: ReadonlyArray<Inline>;
|
|
15
|
+
};
|
|
16
|
+
/** @since @next */
|
|
17
|
+
export type Strong = { readonly _tag: "Strong"; readonly children: ReadonlyArray<Inline> };
|
|
18
|
+
/** @since @next */
|
|
19
|
+
export type Emphasis = { readonly _tag: "Emphasis"; readonly children: ReadonlyArray<Inline> };
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Phrasing content.
|
|
23
|
+
*
|
|
24
|
+
* @since @next
|
|
25
|
+
*/
|
|
26
|
+
export type Inline = Text | Code | Link | Strong | Emphasis;
|
|
27
|
+
|
|
28
|
+
/** @since @next */
|
|
29
|
+
export type Paragraph = { readonly _tag: "Paragraph"; readonly children: ReadonlyArray<Inline> };
|
|
30
|
+
/** @since @next */
|
|
31
|
+
export type List = {
|
|
32
|
+
readonly _tag: "List";
|
|
33
|
+
readonly ordered: boolean;
|
|
34
|
+
/** One entry per item. */
|
|
35
|
+
readonly items: ReadonlyArray<ReadonlyArray<Block>>;
|
|
36
|
+
};
|
|
37
|
+
/** @since @next */
|
|
38
|
+
export type CodeBlock = {
|
|
39
|
+
readonly _tag: "CodeBlock";
|
|
40
|
+
readonly value: string;
|
|
41
|
+
readonly lang: string | undefined;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** @since @next */
|
|
45
|
+
export type Title = Pipeable.Pipeable & {
|
|
46
|
+
readonly _tag: "Title";
|
|
47
|
+
readonly children: ReadonlyArray<Inline>;
|
|
48
|
+
/** An absolute heading level. Absent means the level follows section nesting. */
|
|
49
|
+
readonly level: number | undefined;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A titled part of a document. Its `id` must be unique within the containing release,
|
|
54
|
+
* or within the document outside releases.
|
|
55
|
+
*
|
|
56
|
+
* @since @next
|
|
57
|
+
*/
|
|
58
|
+
export type Section = Pipeable.Pipeable & {
|
|
59
|
+
readonly _tag: "Section";
|
|
60
|
+
readonly id: string;
|
|
61
|
+
readonly title: Title | undefined;
|
|
62
|
+
/** Content inserted before the title. */
|
|
63
|
+
readonly before: ReadonlyArray<Block>;
|
|
64
|
+
/** Content inserted after the title, before the body. */
|
|
65
|
+
readonly after: ReadonlyArray<Block>;
|
|
66
|
+
readonly children: ReadonlyArray<Block>;
|
|
67
|
+
/** Set on a release section, which scopes the identifiers of its sections. */
|
|
68
|
+
readonly release: Version | undefined;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** @since @next */
|
|
72
|
+
export type Block = Paragraph | List | CodeBlock | Section;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A complete document returned by changelog builders.
|
|
76
|
+
*
|
|
77
|
+
* @since @next
|
|
78
|
+
*/
|
|
79
|
+
export type Document = {
|
|
80
|
+
readonly _tag: "Document";
|
|
81
|
+
readonly kind: "change" | "release" | "history" | "upgrade" | "downgrade";
|
|
82
|
+
readonly children: ReadonlyArray<Block>;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Text, or inline nodes.
|
|
87
|
+
*
|
|
88
|
+
* @since @next
|
|
89
|
+
*/
|
|
90
|
+
export type InlineInput = string | Inline | ReadonlyArray<string | Inline>;
|
|
91
|
+
|
|
92
|
+
const isInline = (value: unknown): value is Inline =>
|
|
93
|
+
Predicate.isTagged(value, "Text") ||
|
|
94
|
+
Predicate.isTagged(value, "Code") ||
|
|
95
|
+
Predicate.isTagged(value, "Link") ||
|
|
96
|
+
Predicate.isTagged(value, "Strong") ||
|
|
97
|
+
Predicate.isTagged(value, "Emphasis");
|
|
98
|
+
|
|
99
|
+
export const isBlock = (value: unknown): value is Block =>
|
|
100
|
+
Predicate.isTagged(value, "Paragraph") ||
|
|
101
|
+
Predicate.isTagged(value, "List") ||
|
|
102
|
+
Predicate.isTagged(value, "CodeBlock") ||
|
|
103
|
+
Predicate.isTagged(value, "Section");
|
|
104
|
+
|
|
105
|
+
const inlines = (value: InlineInput): ReadonlyArray<Inline> => {
|
|
106
|
+
if (typeof value === "string") return [Text(value)];
|
|
107
|
+
if (isInline(value)) return [value];
|
|
108
|
+
|
|
109
|
+
return value.map((item) => (typeof item === "string" ? Text(item) : item));
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** @since @next */
|
|
113
|
+
export const Text = (value: string): Text => ({ _tag: "Text", value });
|
|
114
|
+
/** @since @next */
|
|
115
|
+
export const Code = (value: string): Code => ({ _tag: "Code", value });
|
|
116
|
+
/** @since @next */
|
|
117
|
+
export const Link = (text: InlineInput, url: string): Link => ({
|
|
118
|
+
_tag: "Link",
|
|
119
|
+
url,
|
|
120
|
+
children: inlines(text),
|
|
121
|
+
});
|
|
122
|
+
/** @since @next */
|
|
123
|
+
export const Strong = (children: InlineInput): Strong => ({
|
|
124
|
+
_tag: "Strong",
|
|
125
|
+
children: inlines(children),
|
|
126
|
+
});
|
|
127
|
+
/** @since @next */
|
|
128
|
+
export const Emphasis = (children: InlineInput): Emphasis => ({
|
|
129
|
+
_tag: "Emphasis",
|
|
130
|
+
children: inlines(children),
|
|
131
|
+
});
|
|
132
|
+
/** @since @next */
|
|
133
|
+
export const Paragraph = (children: InlineInput): Paragraph => ({
|
|
134
|
+
_tag: "Paragraph",
|
|
135
|
+
children: inlines(children),
|
|
136
|
+
});
|
|
137
|
+
/** @since @next */
|
|
138
|
+
export const CodeBlock = (value: string, options: { readonly lang?: string } = {}): CodeBlock => ({
|
|
139
|
+
_tag: "CodeBlock",
|
|
140
|
+
value,
|
|
141
|
+
lang: options.lang,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Builds a list. Each item is text, an inline node, a block, or several blocks.
|
|
146
|
+
*
|
|
147
|
+
* @since @next
|
|
148
|
+
*/
|
|
149
|
+
export const List = (
|
|
150
|
+
items: ReadonlyArray<string | Inline | Block | ReadonlyArray<Block>>,
|
|
151
|
+
options: { readonly ordered?: boolean } = {},
|
|
152
|
+
): List => ({
|
|
153
|
+
_tag: "List",
|
|
154
|
+
ordered: options.ordered ?? false,
|
|
155
|
+
items: items.map((item): ReadonlyArray<Block> => {
|
|
156
|
+
if (typeof item === "string" || isInline(item)) return [Paragraph(item)];
|
|
157
|
+
if (isBlock(item)) return [item];
|
|
158
|
+
|
|
159
|
+
return item;
|
|
160
|
+
}),
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* An insertion point inside a plugin's scope.
|
|
165
|
+
*
|
|
166
|
+
* @since @next
|
|
167
|
+
*/
|
|
168
|
+
export type Anchor = {
|
|
169
|
+
readonly _tag: "Anchor";
|
|
170
|
+
readonly part: "title" | "body";
|
|
171
|
+
readonly position: "pre" | "post";
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const anchor = (part: Anchor["part"], position: Anchor["position"]): Anchor => ({
|
|
175
|
+
_tag: "Anchor",
|
|
176
|
+
part,
|
|
177
|
+
position,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
class TitleValue extends Data.TaggedClass("Title")<Omit<Title, "_tag" | "pipe">> {}
|
|
181
|
+
|
|
182
|
+
/** Builds section values. Like titles, they are immutable and have Effect's `pipe`. */
|
|
183
|
+
export class SectionValue extends Data.TaggedClass("Section")<Omit<Section, "_tag" | "pipe">> {}
|
|
184
|
+
|
|
185
|
+
const makeTitle = (text: InlineInput, options: { readonly level?: number } = {}): Title =>
|
|
186
|
+
new TitleValue({ children: inlines(text), level: options.level });
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Builds a title. `Document.Title.pre` and `Document.Title.post` are the insertion points
|
|
190
|
+
* around a scoped section's title.
|
|
191
|
+
*
|
|
192
|
+
* @since @next
|
|
193
|
+
*/
|
|
194
|
+
export const Title = Object.assign(makeTitle, {
|
|
195
|
+
pre: anchor("title", "pre"),
|
|
196
|
+
post: anchor("title", "post"),
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The insertion points around a scoped section's body.
|
|
201
|
+
*
|
|
202
|
+
* @since @next
|
|
203
|
+
*/
|
|
204
|
+
export const Body = { pre: anchor("body", "pre"), post: anchor("body", "post") } as const;
|
|
205
|
+
|
|
206
|
+
const titleOf = (title: Title | string | undefined) =>
|
|
207
|
+
typeof title === "string" ? makeTitle(title) : title;
|
|
208
|
+
|
|
209
|
+
/** @since @next */
|
|
210
|
+
export const Section = (id: string, options: SectionOptions = {}): Section => {
|
|
211
|
+
if (id.startsWith(reservedPrefix)) {
|
|
212
|
+
throw new DocumentError({
|
|
213
|
+
reason: "reserved-id",
|
|
214
|
+
message: `Section identifier "${id}" uses the reserved "${reservedPrefix}" prefix.`,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return generatedSection(id, options);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
type SectionOptions = {
|
|
222
|
+
readonly title?: Title | string;
|
|
223
|
+
readonly children?: ReadonlyArray<Block>;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/** Section identifiers that deltafold generates start with this prefix. */
|
|
227
|
+
const reservedPrefix = "deltafold/";
|
|
228
|
+
|
|
229
|
+
/** Builds a section without the reserved-prefix check, for sections deltafold generates. */
|
|
230
|
+
export const generatedSection = (id: string, options: SectionOptions = {}): Section =>
|
|
231
|
+
new SectionValue({
|
|
232
|
+
id,
|
|
233
|
+
title: titleOf(options.title),
|
|
234
|
+
before: [],
|
|
235
|
+
after: [],
|
|
236
|
+
children: options.children ?? [],
|
|
237
|
+
release: undefined,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Sets an absolute heading level on a title. Levels outside 1 to 6 fail at render time.
|
|
242
|
+
*
|
|
243
|
+
* @since @next
|
|
244
|
+
*/
|
|
245
|
+
export const withLevel =
|
|
246
|
+
(level: number) =>
|
|
247
|
+
(title: Title): Title =>
|
|
248
|
+
new TitleValue({ ...title, level });
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Sets the title of a section.
|
|
252
|
+
*
|
|
253
|
+
* @since @next
|
|
254
|
+
*/
|
|
255
|
+
export const withTitle =
|
|
256
|
+
(title: Title | string) =>
|
|
257
|
+
(section: Section): Section =>
|
|
258
|
+
new SectionValue({ ...section, title: titleOf(title) });
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Appends blocks to a section's body.
|
|
262
|
+
*
|
|
263
|
+
* @since @next
|
|
264
|
+
*/
|
|
265
|
+
export const append =
|
|
266
|
+
(...blocks: ReadonlyArray<Block>) =>
|
|
267
|
+
(section: Section): Section =>
|
|
268
|
+
new SectionValue({ ...section, children: [...section.children, ...blocks] });
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* A document structure that cannot be rendered.
|
|
272
|
+
*
|
|
273
|
+
* @since @next
|
|
274
|
+
*/
|
|
275
|
+
export class DocumentError extends Data.TaggedError("DocumentError")<{
|
|
276
|
+
readonly reason: "duplicate-section" | "heading-level" | "reserved-id";
|
|
277
|
+
readonly message: string;
|
|
278
|
+
}> {}
|
|
279
|
+
|
|
280
|
+
// Plugins.
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Release-scoped plugins run once per included release.
|
|
284
|
+
*
|
|
285
|
+
* @since @next
|
|
286
|
+
*/
|
|
287
|
+
export const Release = "release";
|
|
288
|
+
/**
|
|
289
|
+
* History-scoped plugins run once per history document.
|
|
290
|
+
*
|
|
291
|
+
* @since @next
|
|
292
|
+
*/
|
|
293
|
+
export const History = "history";
|
|
294
|
+
|
|
295
|
+
/** @since @next */
|
|
296
|
+
export type ReleaseContext<M> = {
|
|
297
|
+
readonly package: Package;
|
|
298
|
+
readonly version: Version;
|
|
299
|
+
readonly metadata: M;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/** @since @next */
|
|
303
|
+
export type HistoryContext<M> = {
|
|
304
|
+
readonly package: Package;
|
|
305
|
+
readonly releases: ReadonlyArray<ReleaseContext<M>>;
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Plugin output: blocks to insert, or `null` for nothing.
|
|
310
|
+
*
|
|
311
|
+
* @since @next
|
|
312
|
+
*/
|
|
313
|
+
export type PluginOutput = Block | ReadonlyArray<Block> | null;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Where a plugin's content goes. `scope` is `Document.Release`, once per included
|
|
317
|
+
* release, or `Document.History`, once per history document. `at` is
|
|
318
|
+
* `Document.Title.pre`, `Document.Title.post`, `Document.Body.pre`, or
|
|
319
|
+
* `Document.Body.post` of that scope's section. Each insertion point receives every
|
|
320
|
+
* plugin's content in configuration order.
|
|
321
|
+
*
|
|
322
|
+
* @since @next
|
|
323
|
+
*/
|
|
324
|
+
export type PluginOptions<M> =
|
|
325
|
+
| {
|
|
326
|
+
readonly scope: typeof Release;
|
|
327
|
+
readonly at: Anchor;
|
|
328
|
+
readonly resolve: (context: ReleaseContext<M>) => PluginOutput;
|
|
329
|
+
}
|
|
330
|
+
| {
|
|
331
|
+
readonly scope: typeof History;
|
|
332
|
+
readonly at: Anchor;
|
|
333
|
+
readonly resolve: (context: HistoryContext<M>) => PluginOutput;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Contributes content at an insertion point. Plugins work on format-neutral content:
|
|
338
|
+
* they must not fetch metadata or execute migrations. Output is inserted once and is not
|
|
339
|
+
* processed by other plugins.
|
|
340
|
+
*
|
|
341
|
+
* @since @next
|
|
342
|
+
*/
|
|
343
|
+
export type Plugin<M> = { readonly _tag: "Plugin"; readonly id: string } & PluginOptions<M>;
|
|
344
|
+
|
|
345
|
+
/** @since @next */
|
|
346
|
+
export const makePlugin = <M>(id: string, options: PluginOptions<M>): Plugin<M> => ({
|
|
347
|
+
_tag: "Plugin",
|
|
348
|
+
id,
|
|
349
|
+
...options,
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* `Document.Plugin.make`
|
|
354
|
+
*
|
|
355
|
+
* @since @next
|
|
356
|
+
*/
|
|
357
|
+
export const Plugin = { make: makePlugin } as const;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export {
|
|
2
|
+
Body,
|
|
3
|
+
Code,
|
|
4
|
+
CodeBlock,
|
|
5
|
+
DocumentError,
|
|
6
|
+
Emphasis,
|
|
7
|
+
History,
|
|
8
|
+
Link,
|
|
9
|
+
List,
|
|
10
|
+
Paragraph,
|
|
11
|
+
Plugin,
|
|
12
|
+
Release,
|
|
13
|
+
Section,
|
|
14
|
+
Strong,
|
|
15
|
+
Text,
|
|
16
|
+
Title,
|
|
17
|
+
append,
|
|
18
|
+
withLevel,
|
|
19
|
+
withTitle,
|
|
20
|
+
} from "./document.ts";
|
|
21
|
+
export type {
|
|
22
|
+
Anchor,
|
|
23
|
+
Block,
|
|
24
|
+
Document,
|
|
25
|
+
HistoryContext,
|
|
26
|
+
Inline,
|
|
27
|
+
InlineInput,
|
|
28
|
+
PluginOptions,
|
|
29
|
+
PluginOutput,
|
|
30
|
+
ReleaseContext,
|
|
31
|
+
} from "./document.ts";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Version } from "../../foundation/version.ts";
|
|
2
|
+
import {
|
|
3
|
+
isBlock,
|
|
4
|
+
SectionValue,
|
|
5
|
+
type Anchor,
|
|
6
|
+
type Block,
|
|
7
|
+
type PluginOutput,
|
|
8
|
+
type Section,
|
|
9
|
+
} from "./document.ts";
|
|
10
|
+
|
|
11
|
+
/** Marks a section as the section of one release. */
|
|
12
|
+
export const asRelease = (section: Section, version: Version): Section =>
|
|
13
|
+
new SectionValue({ ...section, release: version });
|
|
14
|
+
|
|
15
|
+
/** Content that one plugin contributes at an anchor. */
|
|
16
|
+
export type Contribution = { readonly at: Anchor; readonly blocks: ReadonlyArray<Block> };
|
|
17
|
+
|
|
18
|
+
/** Inserts contributions in configuration order. Each anchor receives its blocks at once. */
|
|
19
|
+
export const insertAll = (
|
|
20
|
+
section: Section,
|
|
21
|
+
contributions: ReadonlyArray<Contribution>,
|
|
22
|
+
): Section => {
|
|
23
|
+
const at = (part: Anchor["part"], position: Anchor["position"]) =>
|
|
24
|
+
contributions
|
|
25
|
+
.filter(
|
|
26
|
+
(contribution) =>
|
|
27
|
+
contribution.at.part === part && contribution.at.position === position,
|
|
28
|
+
)
|
|
29
|
+
.flatMap((contribution) => contribution.blocks);
|
|
30
|
+
|
|
31
|
+
return new SectionValue({
|
|
32
|
+
...section,
|
|
33
|
+
before: [...section.before, ...at("title", "pre")],
|
|
34
|
+
after: [...section.after, ...at("title", "post")],
|
|
35
|
+
children: [...at("body", "pre"), ...section.children, ...at("body", "post")],
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const blocksOf = (output: PluginOutput): ReadonlyArray<Block> => {
|
|
40
|
+
if (output === null) return [];
|
|
41
|
+
if (isBlock(output)) return [output];
|
|
42
|
+
|
|
43
|
+
return output;
|
|
44
|
+
};
|