@topik/core 0.1.0-alpha.4 → 0.1.0-alpha.6

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/dist/index.d.mts CHANGED
@@ -1,20 +1,39 @@
1
+ import { CourseReferenceContext, ResolvedCourseContentLink, ResolvedCourseContentReference, ResolvedCourseNavigation, ResolvedCoursePage, resolveCourseContentHref, resolveCourseContentReference, resolveCourseNavigation } from "./course-navigation.mjs";
2
+ import { $ as TopikAssetPathDiagnosticReason, A as AssetBlobUri, B as parseGeneratedAssetName, C as TopikMaterializationResourceV1, D as digestTopikAssetSemanticRecord, E as createTopikMaterializationRecord, F as generateAutomaticAssetName, G as validateProjectNamespace, H as topikAssetNameDescriptor, I as isAssetBlobUri, J as TOPIK_ASSET_DIAGNOSTIC_IDS, K as TOPIK_ASSET_CORRELATION_ID_PATTERN, L as isGeneratedAssetName, M as GenerateAutomaticAssetNameOptions, N as GeneratedAssetName, O as digestTopikMaterializationRecord, P as ParsedAsset, Q as TopikAssetDiagnosticLocation, R as parseAsset, S as TopikMaterializationResourceInput, T as createTopikAssetSemanticRecord, U as validateAssetBlobUri, V as serializeAsset, W as validateAssetValue, X as TopikAssetDiagnostic, Y as TopikAssetCorrelationId, Z as TopikAssetDiagnosticId, _ as TopikAssetReferenceMappingV1, a as PreviewState, at as ASSET_TYPE, b as TopikMaterializationPayloadV1, c as AssetCompilationOptions, ct as TOPIK_ASSET_REFERENCE_VERSION, d as AssetNameInput, dt as TOPIK_MATERIALIZATION_VERSION, et as TopikAssetRecoveryCategory, f as AssetPayload, ft as TOPIK_PATH_V1_DESCRIPTOR, g as compileAssetResources, gt as SourceResource, h as ContentBearingResource, ht as ResourceType, i as PreviewPayloadDescriptor, it as ASSET_SCHEMA_ID, j as CompiledAsset, k as validateTopikMaterializationRecord, l as AssetCompilationResult, lt as TOPIK_BLOB_OUTPUT_PREFIX, m as CompiledResource, mt as Resource, n as CourseNavigationModule, nt as correlateTopikAssetResult, o as TOPIK_PREVIEW_PROTOCOL, ot as TOPIK_ASSET_LIMITS, p as CompileAssetResourcesInput, pt as TOPIK_PATH_VERSION, q as TOPIK_ASSET_DEFAULT_CORRELATION_ID, r as PreviewDiagnostic, rt as ASSET_API_VERSION, s as AssetCompilationError, st as TOPIK_ASSET_NAME_VERSION, t as CourseNavigationIndex, tt as TopikAssetResult, u as AssetNameGenerator, ut as TOPIK_JSON_VERSION, v as TopikAssetSemanticRecordV1, w as compareTopikAssetIdentities, x as TopikMaterializationRecordV1, y as TopikMaterializationPayloadInput, z as parseAssetBlobUri } from "./preview-C_3OnNUi.mjs";
3
+ import { ExternalWikiDropdown, ExternalWikiTab, InternalWikiDropdown, InternalWikiTab, ResolvedWikiContentLink, ResolvedWikiContentReference, ResolvedWikiNavigation, ResolvedWikiPage, WikiSwitcherNode, findFirstWikiPage, findWikiPageAncestors, hasWikiNavChildren, isExternalWikiDropdown, isExternalWikiTab, isInternalWikiDropdown, isInternalWikiTab, joinWikiPath, resolveWikiContentHref, resolveWikiContentReference, resolveWikiNavigation } from "./wiki-navigation.mjs";
1
4
  import { z } from "zod";
2
- import { Asset, Guide, Wiki, WikiPage } from "@topik/schema";
3
- import { TopikContentDiagnostic } from "@topik/content-schema";
4
-
5
+ import { TopikContentDiagnostic, TopikNavigationReference, TopikResourceReference } from "@topik/content";
6
+ import "yaml";
7
+ import { Person } from "@topik/schema/person/v1";
8
+ import { CoursePage } from "@topik/schema/course-page/v1";
9
+ import { Guide } from "@topik/schema/guide/v1";
10
+ import { Wiki, WikiNavNode } from "@topik/schema/wiki/v1";
11
+ import { WikiPage } from "@topik/schema/wiki-page/v1";
12
+ //#region src/config/source-version.d.ts
13
+ /** The public resource validator owns Person fields, including future schema additions. */
14
+ declare function parseSourcePersons(value: unknown): Person[];
15
+ //#endregion
5
16
  //#region src/config/collection.d.ts
6
17
  declare const collectionConfigSchema: z.ZodObject<{
7
18
  id: z.ZodString;
8
19
  title: z.ZodString;
20
+ sourceVersion: z.ZodOptional<z.ZodLiteral<1>>;
21
+ persons: z.ZodOptional<z.ZodUnknown>;
22
+ assets: z.ZodDefault<z.ZodObject<{
23
+ directory: z.ZodDefault<z.ZodString>;
24
+ }, z.core.$strict>>;
9
25
  tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
10
26
  }, z.core.$strip>;
11
- type CollectionConfig = z.infer<typeof collectionConfigSchema>;
12
- declare function parseCollectionConfig(raw: unknown): CollectionConfig;
27
+ type CollectionConfig = Omit<z.infer<typeof collectionConfigSchema>, "persons"> & {
28
+ persons?: ReturnType<typeof parseSourcePersons>;
29
+ };
30
+ export declare function parseCollectionConfig(raw: unknown): CollectionConfig;
13
31
  //#endregion
14
32
  //#region src/config/wiki.d.ts
15
- type WikiPageNavNode = {
33
+ type WikiPageNavNode$1 = {
16
34
  type: "page";
17
35
  slug: string;
36
+ source?: string;
18
37
  icon?: string;
19
38
  hidden?: boolean;
20
39
  };
@@ -25,7 +44,7 @@ type WikiGroupNavNode = {
25
44
  icon?: string;
26
45
  expanded?: boolean;
27
46
  hidden?: boolean;
28
- children: WikiNavNode[];
47
+ children: WikiNavNode$1[];
29
48
  };
30
49
  type WikiInternalSwitcherNavNode = {
31
50
  type: "tab" | "dropdown";
@@ -33,7 +52,7 @@ type WikiInternalSwitcherNavNode = {
33
52
  slug?: string;
34
53
  icon?: string;
35
54
  hidden?: boolean;
36
- children: WikiNavNode[];
55
+ children: WikiNavNode$1[];
37
56
  };
38
57
  type WikiExternalSwitcherNavNode = {
39
58
  type: "tab" | "dropdown";
@@ -49,12 +68,17 @@ type WikiLinkNavNode = {
49
68
  icon?: string;
50
69
  hidden?: boolean;
51
70
  };
52
- type WikiNavNode = string | WikiPageNavNode | WikiGroupNavNode | WikiInternalSwitcherNavNode | WikiExternalSwitcherNavNode | WikiLinkNavNode;
71
+ type WikiNavNode$1 = string | WikiPageNavNode$1 | WikiGroupNavNode | WikiInternalSwitcherNavNode | WikiExternalSwitcherNavNode | WikiLinkNavNode;
53
72
  declare const wikiConfigSchema: z.ZodObject<{
54
73
  id: z.ZodString;
55
74
  title: z.ZodString;
75
+ sourceVersion: z.ZodOptional<z.ZodLiteral<1>>;
76
+ labels: z.ZodOptional<z.ZodUnknown>;
77
+ assets: z.ZodDefault<z.ZodObject<{
78
+ directory: z.ZodDefault<z.ZodString>;
79
+ }, z.core.$strict>>;
56
80
  description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
57
- navigation: z.ZodOptional<z.ZodArray<z.ZodType<WikiNavNode, unknown, z.core.$ZodTypeInternals<WikiNavNode, unknown>>>>;
81
+ navigation: z.ZodOptional<z.ZodArray<z.ZodType<WikiNavNode$1, unknown, z.core.$ZodTypeInternals<WikiNavNode$1, unknown>>>>;
58
82
  theme: z.ZodOptional<z.ZodObject<{
59
83
  colors: z.ZodOptional<z.ZodObject<{
60
84
  primary: z.ZodString;
@@ -70,57 +94,292 @@ declare const wikiConfigSchema: z.ZodObject<{
70
94
  }, z.core.$strip>>;
71
95
  }, z.core.$strip>>;
72
96
  }, z.core.$strip>;
73
- type WikiConfig = z.infer<typeof wikiConfigSchema>;
74
- declare function parseWikiConfig(raw: unknown): WikiConfig;
97
+ type WikiConfig = Omit<z.infer<typeof wikiConfigSchema>, "labels"> & {
98
+ labels?: Record<string, string>;
99
+ };
100
+ export declare function parseWikiConfig(raw: unknown): WikiConfig;
75
101
  //#endregion
76
- //#region src/resource.d.ts
77
- type Resource = Asset | Guide | Wiki | WikiPage;
78
- type ResourceType = Resource["type"];
102
+ //#region src/config/course.d.ts
103
+ declare const moduleSchema: z.ZodObject<{
104
+ id: z.ZodString;
105
+ title: z.ZodString;
106
+ slug: z.ZodString;
107
+ order: z.ZodNumber;
108
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
109
+ labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
110
+ pages: z.ZodArray<z.ZodString>;
111
+ }, z.core.$strip>;
112
+ declare const courseConfigSchema: z.ZodObject<{
113
+ sourceVersion: z.ZodLiteral<1>;
114
+ id: z.ZodString;
115
+ title: z.ZodString;
116
+ slug: z.ZodString;
117
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
118
+ labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
119
+ authors: z.ZodOptional<z.ZodArray<z.ZodString>>;
120
+ persons: z.ZodOptional<z.ZodUnknown>;
121
+ assets: z.ZodDefault<z.ZodObject<{
122
+ directory: z.ZodDefault<z.ZodString>;
123
+ }, z.core.$strict>>;
124
+ modules: z.ZodArray<z.ZodObject<{
125
+ id: z.ZodString;
126
+ title: z.ZodString;
127
+ slug: z.ZodString;
128
+ order: z.ZodNumber;
129
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
130
+ labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
131
+ pages: z.ZodArray<z.ZodString>;
132
+ }, z.core.$strip>>;
133
+ }, z.core.$strip>;
134
+ type CourseConfig = Omit<z.infer<typeof courseConfigSchema>, "persons"> & {
135
+ persons?: ReturnType<typeof parseSourcePersons>;
136
+ };
137
+ type CourseModuleConfig = z.infer<typeof moduleSchema>;
138
+ export declare function parseCourseConfig(raw: unknown): CourseConfig;
139
+ //#endregion
140
+ //#region src/config/manifest.d.ts
141
+ export declare const TOPIK_MANIFEST_FILENAME = ".topik.yaml";
142
+ export declare const TOPIK_MANIFEST_LIMITS: {
143
+ readonly maxBytes: 1048576;
144
+ readonly maxSources: 1000;
145
+ readonly maxDepth: 32;
146
+ };
147
+ export declare const topikManifestSourceSchema: z.ZodObject<{
148
+ kind: z.ZodEnum<{
149
+ collection: "collection";
150
+ course: "course";
151
+ wiki: "wiki";
152
+ }>;
153
+ config: z.ZodString;
154
+ }, z.core.$strict>;
155
+ export declare const topikManifestSchema: z.ZodObject<{
156
+ version: z.ZodLiteral<1>;
157
+ namespace: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
158
+ sources: z.ZodArray<z.ZodObject<{
159
+ kind: z.ZodEnum<{
160
+ collection: "collection";
161
+ course: "course";
162
+ wiki: "wiki";
163
+ }>;
164
+ config: z.ZodString;
165
+ }, z.core.$strict>>;
166
+ }, z.core.$strict>;
167
+ type TopikManifest = z.infer<typeof topikManifestSchema>;
168
+ type TopikManifestSource = z.infer<typeof topikManifestSourceSchema>;
169
+ export declare function parseTopikManifest(raw: unknown): TopikManifest;
170
+ //#endregion
171
+ //#region src/config/assets.d.ts
172
+ export declare const DEFAULT_ASSET_DIRECTORY = "_assets";
173
+ /** Source-local destination for new synced media; not an input scan or compiler output path. */
174
+ export declare const sourceAssetsConfigSchema: z.ZodObject<{
175
+ directory: z.ZodDefault<z.ZodString>;
176
+ }, z.core.$strict>;
177
+ type SourceAssetsConfig = z.infer<typeof sourceAssetsConfigSchema>;
178
+ //#endregion
179
+ //#region src/compile/public-errors.d.ts
180
+ declare const PUBLIC_COMPILE_ERROR_MESSAGES: {
181
+ readonly "manifest-required": 'Project compilation requires .topik.yaml in the selected directory. Add a manifest such as: {"version":1,"namespace":"owner/project","sources":[{"kind":"wiki","config":"wiki.yaml"}]}';
182
+ readonly "manifest-invalid": "Root manifest is invalid.";
183
+ readonly "manifest-source-failed": "Manifest source could not be compiled.";
184
+ readonly "manifest-resource-conflict": "Manifest sources produce conflicting resource identities.";
185
+ readonly "config-access-failed": "Configuration file could not be accessed.";
186
+ readonly "config-invalid": "Configuration is invalid.";
187
+ readonly "config-not-found": "Required configuration file was not found.";
188
+ readonly "config-parse-failed": "Configuration file could not be parsed.";
189
+ readonly "config-read-failed": "Configuration file could not be read safely.";
190
+ readonly "file-safe-read-unsupported": "This platform cannot safely open compilation inputs.";
191
+ readonly "file-not-regular": "Compilation input must be a regular file.";
192
+ readonly "file-outside-compilation-root": "Compilation input resolves outside the source root.";
193
+ readonly "frontmatter-invalid": "Document frontmatter is invalid.";
194
+ readonly "reference-list-invalid": "Document resource references are invalid.";
195
+ readonly "reference-targets-invalid": "Resource reference target catalogue is invalid.";
196
+ readonly "wiki-page-not-found": "A configured Wiki page file was not found.";
197
+ readonly "wiki-page-ambiguous": "A Wiki source path matches more than one Markdown file. Keep exactly one source file.";
198
+ readonly "course-page-not-found": "A configured Course page file was not found.";
199
+ readonly "course-page-ambiguous": "A Course source path matches more than one Markdown file. Keep exactly one source file.";
200
+ readonly "author-not-found": "An author must reference a Person in the declared project.";
201
+ };
202
+ type PublicCompileErrorId = keyof typeof PUBLIC_COMPILE_ERROR_MESSAGES;
203
+ export declare function publicCompileErrorMessage(id: unknown): string | undefined;
204
+ /** Public compiler failure with fixed wording, stable ID, and optional safe relative location. */
205
+ export declare class PublicCompileError extends Error {
206
+ readonly id: PublicCompileErrorId;
207
+ readonly location?: string;
208
+ constructor(id: PublicCompileErrorId, location?: string);
209
+ }
210
+ //#endregion
211
+ //#region src/compile/manifest.d.ts
212
+ interface ManifestSourceDescriptor extends TopikManifestSource {
213
+ /** Zero-based declaration index, used only for provenance and diagnostics. */
214
+ sourceIndex: number;
215
+ /** Canonical root-relative directory; empty for the project root. */
216
+ directory: string;
217
+ /** Project namespace declared in the manifest. */
218
+ namespace: string;
219
+ }
220
+ interface ManifestSourceProvenance extends ManifestSourceDescriptor {
221
+ /** Root-relative destination for new synced media. Compilation does not write here. */
222
+ assetDirectory: string;
223
+ /** Authored resource keys mapped to root-relative content/config paths. */
224
+ sourcePathsByResource: Readonly<Record<string, string>>;
225
+ }
226
+ interface ManifestCompileResult extends CompileResult {
227
+ provenance: ManifestSourceProvenance[];
228
+ }
229
+ export declare class ManifestSourceError extends PublicCompileError {
230
+ readonly sourceIndex: number;
231
+ readonly kind?: TopikManifestSource["kind"];
232
+ constructor(id: PublicCompileErrorId, sourceIndex: number, kind?: TopikManifestSource["kind"], config?: string);
233
+ }
234
+ /** Explicit loading requires the canonical file in exactly the supplied root. */
235
+ export declare function loadTopikManifest(dir: string): Promise<TopikManifest>;
236
+ export declare function discoverManifestSources(options: CompileOptions): Promise<ManifestSourceDescriptor[]>;
237
+ /** Compile only declared sources, sharing the existing local compiler and Asset pipeline. */
238
+ export declare function compileManifest(options: CompileOptions): Promise<ManifestCompileResult>;
79
239
  //#endregion
80
240
  //#region src/compile/shared.d.ts
81
241
  interface CompileResult {
242
+ courseNavigation: CourseNavigationIndex;
243
+ /** Present for manifest compilation, in declaration order. */
244
+ provenance?: ManifestSourceProvenance[];
82
245
  diagnostics: TopikContentDiagnostic[];
83
- resources: Resource[];
246
+ resources: CompiledResource[];
247
+ payloads: AssetPayload[];
248
+ semantic: TopikAssetSemanticRecordV1;
249
+ materialization: TopikMaterializationRecordV1;
250
+ /** Portable document references and their compilation-time validation state. */
251
+ references: CompiledResourceReference[];
84
252
  }
85
253
  type LinkValidationPolicy = "error" | "warning" | "off";
86
254
  interface CompileValidationOptions {
87
- /** How unresolved wiki page links and same-page guide fragments are handled. */
255
+ /** How unresolved document targets and invalid destination fragments are handled. */
88
256
  links?: LinkValidationPolicy;
89
257
  }
90
- declare class CompileError extends Error {
258
+ export declare class CompileError extends Error {
91
259
  readonly diagnostics: TopikContentDiagnostic[];
92
260
  constructor(diagnostics: TopikContentDiagnostic[]);
93
261
  }
94
- declare function isErrorDiagnostic(diagnostic: TopikContentDiagnostic): boolean;
262
+ export declare function isErrorDiagnostic(diagnostic: TopikContentDiagnostic): boolean;
263
+ //#endregion
264
+ //#region src/compile/links.d.ts
265
+ /** Optional application-provided catalogue; Topik never fetches targets. */
266
+ interface CompileResourceReferenceTarget {
267
+ type: TopikResourceReference["type"];
268
+ name: string;
269
+ /** Published heading IDs, when known. Without them a fragment remains deferred. */
270
+ headings?: readonly string[];
271
+ }
272
+ interface CompiledResourceReference {
273
+ resource: string;
274
+ sourcePath: string;
275
+ kind: "link" | "card";
276
+ position: string;
277
+ /** The original authored destination, retained for source round trips. */
278
+ href: string;
279
+ reference: TopikResourceReference;
280
+ status: "verified" | "deferred" | "invalid";
281
+ }
282
+ interface CompileResourceLinksInput {
283
+ rootDir: string;
284
+ resources: readonly SourceResource[];
285
+ sourcePathsByResource: Readonly<Record<string, string>>;
286
+ sourceDirectoriesByResource?: Readonly<Record<string, string>>;
287
+ referenceTargets?: readonly CompileResourceReferenceTarget[];
288
+ /** @internal Source round-trip comparison may already contain compiled Asset locators. */
289
+ allowCompiledAssetReferences?: boolean;
290
+ validation?: CompileValidationOptions;
291
+ }
292
+ /** Resolve document identity after all declared sources have been discovered, before Assets. */
293
+ export declare function compileResourceLinks(input: CompileResourceLinksInput): Promise<{
294
+ resources: SourceResource[];
295
+ diagnostics: TopikContentDiagnostic[];
296
+ references: CompiledResourceReference[];
297
+ }>;
298
+ //#endregion
299
+ //#region src/compile/guide.d.ts
300
+ interface CompileGuidesOptions {
301
+ dir: string;
302
+ /** Exact config path relative to dir; content is relative to the config directory. */
303
+ configFile?: string;
304
+ validation?: CompileValidationOptions;
305
+ assets?: AssetCompilationOptions;
306
+ referenceTargets?: readonly CompileResourceReferenceTarget[];
307
+ }
308
+ interface CompileResourceDiscovery {
309
+ courseNavigation?: CourseNavigationIndex;
310
+ sourceVersion?: 1;
311
+ /** Destination relative to the selected configuration directory, if a config was loaded. */
312
+ assetDirectory?: string;
313
+ diagnostics: CompileResult["diagnostics"];
314
+ resources: SourceResource[];
315
+ sourcePathsByResource: Record<string, string>;
316
+ consumedSourcePaths: string[];
317
+ }
318
+ export declare function compileGuides(options: CompileGuidesOptions): Promise<CompileResult>;
319
+ //#endregion
320
+ //#region src/compile/discovery.d.ts
321
+ interface DiscoverResourceOptions {
322
+ dir: string;
323
+ /** Exact config path relative to dir; content is relative to its directory. */
324
+ configFile?: string;
325
+ }
326
+ type SourceResourceDiscovery = CompileResourceDiscovery;
327
+ /** Read authoring metadata and paths before combining a caller-owned source inventory. */
328
+ export declare function discoverGuideResources(options: DiscoverResourceOptions): Promise<SourceResourceDiscovery>;
329
+ /** Read authoring metadata and paths before combining a caller-owned source inventory. */
330
+ export declare function discoverWikiResources(options: DiscoverResourceOptions): Promise<SourceResourceDiscovery>;
331
+ /** Read Course membership, metadata and paths without compiling links or Assets. */
332
+ export declare function discoverCourseResources(options: DiscoverResourceOptions): Promise<SourceResourceDiscovery>;
95
333
  //#endregion
96
334
  //#region src/compile/wiki.d.ts
97
335
  interface CompileWikiOptions {
98
336
  dir: string;
337
+ /** Exact config path relative to dir; content is relative to the config directory. */
338
+ configFile?: string;
99
339
  validation?: CompileValidationOptions;
340
+ assets?: AssetCompilationOptions;
341
+ referenceTargets?: readonly CompileResourceReferenceTarget[];
100
342
  }
101
- declare function compileWiki(options: CompileWikiOptions): Promise<CompileResult>;
102
- declare function pagePathToName(wikiId: string, pagePath: string): string;
343
+ export declare function compileWiki(options: CompileWikiOptions): Promise<CompileResult>;
344
+ export declare function pagePathToName(wikiId: string, pagePath: string): string;
103
345
  //#endregion
104
- //#region src/compile/guide.d.ts
105
- interface CompileGuidesOptions {
346
+ //#region src/compile/course.d.ts
347
+ interface CompileCourseOptions {
106
348
  dir: string;
349
+ /** Exact configuration path relative to dir; page sources are relative to its directory. */
350
+ configFile?: string;
107
351
  validation?: CompileValidationOptions;
352
+ assets?: AssetCompilationOptions;
353
+ referenceTargets?: readonly CompileResourceReferenceTarget[];
108
354
  }
109
- declare function compileGuides(options: CompileGuidesOptions): Promise<CompileResult>;
355
+ export declare function compileCourse(options: CompileCourseOptions): Promise<CompileResult>;
356
+ //#endregion
357
+ //#region src/compile/asset-names.d.ts
358
+ interface ProjectAssetNameOptions {
359
+ /** Directory containing the manifest, or an explicitly chosen root for standalone use. */
360
+ projectRoot: string;
361
+ projectNamespace: string;
362
+ }
363
+ /** Create the project's naming policy without reading or requiring a manifest. */
364
+ export declare function createProjectAssetNameGenerator(options: ProjectAssetNameOptions): AssetNameGenerator;
110
365
  //#endregion
111
366
  //#region src/compile/index.d.ts
112
367
  interface CompileOptions {
113
368
  dir: string;
114
369
  validation?: CompileValidationOptions;
370
+ /** Optional application-supplied inventory for explicit resource references. */
371
+ referenceTargets?: readonly CompileResourceReferenceTarget[];
115
372
  }
116
- declare function compile(options: CompileOptions): Promise<CompileResult>;
373
+ /** Compile exactly the project declared by .topik.yaml in dir. */
374
+ export declare function compile(options: CompileOptions): Promise<CompileResult>;
117
375
  interface LintResult {
118
376
  diagnostics: CompileResult["diagnostics"];
119
377
  }
120
- declare function lint(options: CompileOptions): Promise<LintResult>;
378
+ export declare function lint(options: CompileOptions): Promise<LintResult>;
121
379
  //#endregion
122
380
  //#region src/validate.d.ts
123
381
  interface ValidationError {
382
+ id?: "resource-invalid" | "resource-unsupported-type" | "resource-unsupported-version" | TopikAssetDiagnosticId;
124
383
  resource: string;
125
384
  path: string;
126
385
  message: string;
@@ -130,7 +389,7 @@ interface ValidationResult {
130
389
  errors: ValidationError[];
131
390
  }
132
391
  /** Validate the resources produced by `compile` and the CLI export. */
133
- declare function validateResources(resources: readonly unknown[]): ValidationResult;
392
+ export declare function validateResources(resources: readonly unknown[]): ValidationResult;
134
393
  //#endregion
135
394
  //#region src/watch.d.ts
136
395
  interface WatchOptions {
@@ -139,15 +398,361 @@ interface WatchOptions {
139
398
  }
140
399
  type UpdateListener = (key: string, resource: Resource) => void;
141
400
  type ErrorListener = (error: Error) => void;
401
+ type PreviewStateListener = (state: PreviewState) => void;
142
402
  interface Watcher {
143
- /** Current compiled resources, keyed by `Type/name`. */
403
+ /** Compatibility inventory; replaced completely before any success notification. */
144
404
  resources: Map<string, Resource>;
405
+ payloads: Map<string, AssetPayload>;
406
+ /** Immutable, complete authoritative state. Treat resources/order/payloads as one commit. */
407
+ readonly state: PreviewState;
408
+ on(event: "preview-state", listener: PreviewStateListener): this;
145
409
  on(event: "update", listener: UpdateListener): this;
146
410
  on(event: "error", listener: ErrorListener): this;
411
+ off(event: "preview-state", listener: PreviewStateListener): this;
147
412
  off(event: "update", listener: UpdateListener): this;
148
413
  off(event: "error", listener: ErrorListener): this;
149
414
  close(): Promise<void>;
150
415
  }
151
- declare function watch(options: WatchOptions): Promise<Watcher>;
416
+ export declare function watch(options: WatchOptions): Promise<Watcher>;
417
+ //#endregion
418
+ //#region src/assets/path.d.ts
419
+ interface ValidateTopikPathOptions {
420
+ bindingRoot?: string;
421
+ capabilities?: {
422
+ maxComponentUtf8Bytes?: number;
423
+ maxComponents?: number;
424
+ maxRepositoryPathUtf8Bytes?: number;
425
+ };
426
+ }
427
+ interface ValidTopikPath {
428
+ path: string;
429
+ collisionKey: string;
430
+ utf8Bytes: number;
431
+ }
432
+ export declare function validateTopikPath(input: string | Uint8Array, options?: ValidateTopikPathOptions): TopikAssetResult<ValidTopikPath>;
433
+ export declare function computeTopikPathCollisionKey(path: string, options?: ValidateTopikPathOptions): TopikAssetResult<string>;
434
+ export declare function validateTopikPathSet(paths: readonly string[], options?: ValidateTopikPathOptions): TopikAssetResult<Map<string, string>>;
435
+ /** Unicode 17 NFKC casefold for topik-path-v1-admitted input. */
436
+ export declare function toNfkcCasefold(value: string): string;
437
+ //#endregion
438
+ //#region src/assets/json.d.ts
439
+ export declare class TopikJsonSyntaxError extends SyntaxError {
440
+ readonly offset: number;
441
+ readonly duplicatePointer?: string | undefined;
442
+ constructor(message: string, offset: number, duplicatePointer?: string | undefined);
443
+ }
444
+ export declare function parseStrictTopikJson(source: string, maxDepth?: number): unknown;
445
+ /** RFC 8785 scalar/member rules with Topik's two-space layout and final LF. */
446
+ export declare function serializeTopikJson(value: unknown): string;
447
+ export declare function topikJsonDescriptor(): {
448
+ id: typeof TOPIK_JSON_VERSION;
449
+ };
450
+ //#endregion
451
+ //#region src/assets/files.d.ts
452
+ type PortableAssetFileType = "regular" | "symlink" | "hardlink" | "gitlink" | "device" | "fifo" | "socket" | "special" | "sparse" | "archive-link";
453
+ interface PortableAssetFileDescriptor {
454
+ path: string;
455
+ type: PortableAssetFileType;
456
+ source?: "git" | "archive" | "filesystem";
457
+ /** Git mode (`100644`) or archive mode (`0644`). */
458
+ mode: string;
459
+ bytes?: Uint8Array;
460
+ linkCount?: number;
461
+ hasAlternateDataStream?: boolean;
462
+ contentFilter?: string;
463
+ workingTreeEncoding?: string;
464
+ }
465
+ export declare function validatePortableAssetFile(file: PortableAssetFileDescriptor): TopikAssetResult<PortableAssetFileDescriptor>;
466
+ export declare function validatePortableAssetTree(files: readonly PortableAssetFileDescriptor[]): TopikAssetResult<readonly PortableAssetFileDescriptor[]>;
467
+ interface ReadPortableAssetFileOptions {
468
+ root: string;
469
+ path: string;
470
+ /** Optional tighter read limit; cannot exceed the portable asset maximum. */
471
+ maxBytes?: number;
472
+ }
473
+ /** Filesystem reader using no-follow traversal and stable same-handle identity checks. */
474
+ export declare function readPortableAssetFile(options: ReadPortableAssetFileOptions): Promise<TopikAssetResult<PortableAssetFileDescriptor>>;
475
+ export declare function looksLikeGitLfsPointer(bytes: Uint8Array): boolean;
476
+ //#endregion
477
+ //#region src/assets/media.d.ts
478
+ export declare const TOPIK_UNRESOLVED_ACTIVE_CONTENT_TYPE: "application/x-topik-active-content";
479
+ /** Sniff exact bytes conservatively. Unknown safe bytes remain opaque downloads. */
480
+ export declare function sniffPortableMediaType(bytes: Uint8Array): string;
481
+ export declare function isTopikActiveMediaType(mediaType: string): boolean;
482
+ export declare function isInlineMediaCompatible(mediaType: string, role: string): boolean;
483
+ //#endregion
484
+ //#region src/source/syntax.d.ts
485
+ interface SourceByteRange {
486
+ start: number;
487
+ end: number;
488
+ }
489
+ interface SourceFieldEvidence {
490
+ selector: string;
491
+ value?: SourceByteRange;
492
+ entry?: SourceByteRange;
493
+ insertion: number;
494
+ }
495
+ interface SourceByteEdit extends SourceByteRange {
496
+ selector: string;
497
+ oldSha256: string;
498
+ replacement: Uint8Array;
499
+ }
500
+ //#endregion
501
+ //#region src/source/project.d.ts
502
+ export declare const SOURCE_WRITER_VERSION: "topik-source-writer-v1";
503
+ export declare const SOURCE_PROJECT_LIMITS: {
504
+ readonly maxFiles: 10000;
505
+ readonly maxFileBytes: 268435456;
506
+ readonly maxTreeBytes: 536870912;
507
+ };
508
+ export declare const SOURCE_WRITER_DESCRIPTOR: {
509
+ readonly writer: "topik-source-writer-v1";
510
+ readonly manifest: 1;
511
+ readonly sourceVersions: readonly [0, 1];
512
+ readonly formatter: 1;
513
+ readonly contentSchema: "0.2.2";
514
+ readonly resourceSchema: "v1";
515
+ readonly references: "source-links-v5";
516
+ readonly provenance: 7;
517
+ readonly graph: "authored-resource-bytes-v1";
518
+ readonly packageVersion: string;
519
+ };
520
+ interface SourceTreeFile {
521
+ path: string;
522
+ mode: "100644" | "100755";
523
+ bytes: Uint8Array;
524
+ }
525
+ interface SourceDocumentProvenance {
526
+ resource: string;
527
+ apiVersion: Resource["apiVersion"];
528
+ type: Resource["type"];
529
+ name: string;
530
+ path: string;
531
+ config: string;
532
+ kind: ManifestSourceProvenance["kind"];
533
+ directory: string;
534
+ sourceVersion?: 1;
535
+ sha256: string;
536
+ mode: SourceTreeFile["mode"];
537
+ body?: SourceByteRange;
538
+ frontmatter?: SourceByteRange;
539
+ fields: readonly SourceFieldEvidence[];
540
+ fieldOrigins: readonly SourceFieldOrigin[];
541
+ /** Recognized legacy metadata whose compiled value would lose authored meaning. */
542
+ lossyMetadata?: readonly string[];
543
+ /** Context travels with immutable saved source; a later source move must not reinterpret it. */
544
+ sourceContext: {
545
+ path: string;
546
+ extension: string;
547
+ /** Key in SourceProject.wikiContexts; retain that snapshot with saved content. */
548
+ wiki?: string;
549
+ /** Key in SourceProject.courseContexts for a Course page's immutable saved links. */
550
+ course?: string;
551
+ };
552
+ references: readonly (TopikNavigationReference & {
553
+ target?: string;
554
+ search?: string;
555
+ hash?: string;
556
+ })[];
557
+ /** Complete derived Asset identity closure for this compiled resource. */
558
+ assetReferences: readonly string[];
559
+ }
560
+ interface SourceFieldOrigin {
561
+ field: string;
562
+ origin: "explicit" | "derived" | "inherited" | "default";
563
+ path?: string;
564
+ selector?: string;
565
+ range?: SourceByteRange;
566
+ }
567
+ interface SourceConfigurationProvenance {
568
+ path: string;
569
+ sha256: string;
570
+ mode: SourceTreeFile["mode"];
571
+ fields: readonly SourceFieldEvidence[];
572
+ insertion: number;
573
+ }
574
+ interface SourceProject {
575
+ tree: readonly SourceTreeFile[];
576
+ treeDigest: string;
577
+ manifest: TopikManifest;
578
+ manifestSha256: string;
579
+ compilation: ManifestCompileResult;
580
+ documents: readonly SourceDocumentProvenance[];
581
+ configurations: readonly SourceConfigurationProvenance[];
582
+ wikiContexts: Readonly<Record<string, Wiki>>;
583
+ courseContexts: Readonly<Record<string, CourseReferenceContext>>;
584
+ descriptor: typeof SOURCE_WRITER_DESCRIPTOR;
585
+ }
586
+ export declare function digestSourceTree(tree: readonly SourceTreeFile[]): string;
587
+ /** Seal the exact desired authoring graph without parsing or formatting its content. */
588
+ export declare function digestSourceResourceGraph(resources: readonly Resource[]): string;
589
+ /** Inspection compiles exactly the manifest tree and retains original documents and byte ranges. */
590
+ export declare function readSourceProject(input: {
591
+ tree: readonly SourceTreeFile[];
592
+ }): Promise<SourceProject>;
593
+ //#endregion
594
+ //#region src/source/asset-context.d.ts
595
+ type SourceAssetReferenceContexts = Readonly<Record<string, Readonly<Record<string, string>>>>;
596
+ //#endregion
597
+ //#region src/source/initialize.d.ts
598
+ interface SourceInitializationIntent {
599
+ namespace: string;
600
+ source: TopikManifestSource & {
601
+ id: string;
602
+ title: string;
603
+ assetDirectory?: string;
604
+ };
605
+ }
606
+ interface SourceMediaSelection {
607
+ name: string;
608
+ filename: string;
609
+ sha256: string;
610
+ bytes: Uint8Array;
611
+ }
612
+ interface InitializeSourceProjectInput {
613
+ /** Full occupied-path inventory; missing/invalid manifests are never admitted as empty projects. */
614
+ tree: readonly SourceTreeFile[];
615
+ expectedTreeDigest: string;
616
+ packageCohort: string;
617
+ /** This explicit reviewed intent is sealed by the application before planning. */
618
+ intent: SourceInitializationIntent;
619
+ resources: readonly Resource[];
620
+ media?: readonly SourceMediaSelection[];
621
+ /** Immutable Wiki context retained with each saved page body. */
622
+ referenceContexts?: Readonly<Record<string, Wiki>>;
623
+ courseReferenceContexts?: Readonly<Record<string, CourseReferenceContext>>;
624
+ /** Explicit new Guide or CoursePage file paths, independently admitted in createPaths. */
625
+ documentPaths?: Readonly<Record<string, string>>;
626
+ assetReferenceContexts?: SourceAssetReferenceContexts;
627
+ /** Exact expected-absence paths admitted from the complete inventory. */
628
+ createPaths: readonly string[];
629
+ }
630
+ /** Initialization is distinct from adding a source to a valid existing manifest. */
631
+ export declare function initializeSourceProject(input: InitializeSourceProjectInput): Promise<SourcePlanResult>;
632
+ interface AddSourceToProjectInput {
633
+ project: SourceProject;
634
+ expectedTreeDigest: string;
635
+ packageCohort: string;
636
+ source: SourceInitializationIntent["source"];
637
+ resources: readonly Resource[];
638
+ media?: readonly SourceMediaSelection[];
639
+ referenceContexts?: Readonly<Record<string, Wiki>>;
640
+ courseReferenceContexts?: Readonly<Record<string, CourseReferenceContext>>;
641
+ documentPaths?: Readonly<Record<string, string>>;
642
+ assetReferenceContexts?: SourceAssetReferenceContexts;
643
+ createPaths: readonly string[];
644
+ manifestAuthority: SourceSharedAuthority;
645
+ }
646
+ /** Adding a declaration preserves the existing namespace, order and every original source. */
647
+ export declare function addSourceToProject(input: AddSourceToProjectInput): Promise<SourcePlanResult>;
648
+ //#endregion
649
+ //#region src/source/diagnostics.d.ts
650
+ interface SourcePlanDiagnostic {
651
+ code: string;
652
+ message: string;
653
+ resource?: string;
654
+ path?: string;
655
+ /** One-based lines in the compiled document body, excluding frontmatter. */
656
+ lines?: readonly number[];
657
+ sourceIndex?: number;
658
+ kind?: "wiki" | "collection" | "course";
659
+ config?: string;
660
+ }
661
+ //#endregion
662
+ //#region src/source/plan.d.ts
663
+ type SourceResourceOperation = {
664
+ kind: "update" | "delete";
665
+ resource: string;
666
+ } | {
667
+ kind: "move";
668
+ resource: string;
669
+ path: string;
670
+ } | {
671
+ kind: "create";
672
+ resource: string;
673
+ config: string;
674
+ path?: string;
675
+ };
676
+ interface SourceExclusiveAuthority {
677
+ path: string;
678
+ sha256: string;
679
+ mode: SourceTreeFile["mode"];
680
+ }
681
+ interface SourceSharedAuthority extends SourceExclusiveAuthority {
682
+ fields: readonly SourceFieldEvidence[];
683
+ }
684
+ interface SourceWriteAuthority {
685
+ /** Resources whose authored or shared referenced facts may change, admitted independently. */
686
+ resources: readonly string[];
687
+ exclusive: readonly SourceExclusiveAuthority[];
688
+ shared: readonly SourceSharedAuthority[];
689
+ create: readonly string[];
690
+ }
691
+ interface SourceFileChange {
692
+ kind: "create" | "update" | "delete";
693
+ path: string;
694
+ base: {
695
+ sha256: string;
696
+ mode: SourceTreeFile["mode"];
697
+ } | null;
698
+ candidate: {
699
+ sha256: string;
700
+ mode: SourceTreeFile["mode"];
701
+ bytes: Uint8Array;
702
+ } | null;
703
+ sharedEdits?: readonly SourceByteEdit[];
704
+ }
705
+ interface SourceUpdatePlan {
706
+ assetMappings: readonly {
707
+ from: string;
708
+ to: string;
709
+ path: string;
710
+ }[];
711
+ descriptor: typeof SOURCE_WRITER_DESCRIPTOR;
712
+ packageCohort: string;
713
+ baseTreeDigest: string;
714
+ desiredGraphDigest: string;
715
+ candidateTreeDigest: string;
716
+ planDigest: string;
717
+ changes: readonly SourceFileChange[];
718
+ candidate: SourceProject;
719
+ affectedResources: readonly string[];
720
+ derivedRepairs: readonly {
721
+ resource: string;
722
+ kind: "navigation" | "reference";
723
+ position?: string;
724
+ before?: string;
725
+ after?: string;
726
+ target?: string;
727
+ }[];
728
+ }
729
+ type SourcePlanResult = {
730
+ ok: true;
731
+ plan: SourceUpdatePlan;
732
+ } | {
733
+ ok: false;
734
+ diagnostics: readonly SourcePlanDiagnostic[];
735
+ };
736
+ interface PlanSourceUpdatesInput {
737
+ project: SourceProject;
738
+ expectedTreeDigest: string;
739
+ packageCohort: string;
740
+ /** Complete project graph, including untouched declarations and derived Assets. */
741
+ desiredResources: readonly Resource[];
742
+ operations: readonly SourceResourceOperation[];
743
+ authority: SourceWriteAuthority;
744
+ /** Explicit reviewed opt-in; reserved legacy keys still block it. */
745
+ optInConfigs?: readonly string[];
746
+ /** Retained portable context of saved authoring content, before previous source repairs. */
747
+ referenceContexts?: Readonly<Record<string, Wiki>>;
748
+ /** Retained Course route/source snapshots keyed by CoursePage identity. */
749
+ courseReferenceContexts?: Readonly<Record<string, CourseReferenceContext>>;
750
+ assetReferenceContexts?: SourceAssetReferenceContexts;
751
+ media?: readonly (SourceMediaSelection & {
752
+ config: string;
753
+ })[];
754
+ }
755
+ /** The complete candidate is compiled before any applicable file changes are returned. */
756
+ export declare function planSourceUpdates(input: PlanSourceUpdatesInput): Promise<SourcePlanResult>;
152
757
  //#endregion
153
- export { type CollectionConfig, CompileError, type CompileGuidesOptions, type CompileOptions, type CompileResult, type CompileValidationOptions, type CompileWikiOptions, type LinkValidationPolicy, type LintResult, type Resource, type ResourceType, type ValidationError, type ValidationResult, type WatchOptions, type Watcher, type WikiConfig, compile, compileGuides, compileWiki, isErrorDiagnostic, lint, pagePathToName, parseCollectionConfig, parseWikiConfig, validateResources, watch };
758
+ export { ASSET_API_VERSION, ASSET_SCHEMA_ID, ASSET_TYPE, type AddSourceToProjectInput, type AssetBlobUri, AssetCompilationError, type AssetCompilationOptions, type AssetCompilationResult, type AssetNameGenerator, type AssetNameInput, type AssetPayload, type CollectionConfig, type CompileAssetResourcesInput, type CompileCourseOptions, type CompileGuidesOptions, type CompileOptions, type CompileResourceLinksInput, type CompileResourceReferenceTarget, type CompileResult, type CompileValidationOptions, type CompileWikiOptions, type CompiledAsset, type CompiledResource, type CompiledResourceReference, type ContentBearingResource, type CourseConfig, type CourseModuleConfig, CourseNavigationIndex, CourseNavigationModule, type CourseReferenceContext, type DiscoverResourceOptions, type ExternalWikiDropdown, type ExternalWikiTab, type GenerateAutomaticAssetNameOptions, type GeneratedAssetName, type InitializeSourceProjectInput, type InternalWikiDropdown, type InternalWikiTab, type LinkValidationPolicy, type LintResult, type ManifestCompileResult, type ManifestSourceDescriptor, type ManifestSourceProvenance, type ParsedAsset, type PlanSourceUpdatesInput, type PortableAssetFileDescriptor, type PortableAssetFileType, PreviewDiagnostic, PreviewPayloadDescriptor, PreviewState, type ProjectAssetNameOptions, type PublicCompileErrorId, type ReadPortableAssetFileOptions, type ResolvedCourseContentLink, type ResolvedCourseContentReference, type ResolvedCourseNavigation, type ResolvedCoursePage, type ResolvedWikiContentLink, type ResolvedWikiContentReference, type ResolvedWikiNavigation, type ResolvedWikiPage, type Resource, type ResourceType, type SourceAssetsConfig, type SourceByteEdit, type SourceByteRange, type SourceConfigurationProvenance, type SourceDocumentProvenance, type SourceExclusiveAuthority, type SourceFieldEvidence, type SourceFieldOrigin, type SourceFileChange, type SourceInitializationIntent, type SourceMediaSelection, type SourcePlanDiagnostic, type SourcePlanResult, type SourceProject, type SourceResource, type SourceResourceDiscovery, type SourceResourceOperation, type SourceSharedAuthority, type SourceTreeFile, type SourceUpdatePlan, type SourceWriteAuthority, TOPIK_ASSET_CORRELATION_ID_PATTERN, TOPIK_ASSET_DEFAULT_CORRELATION_ID, TOPIK_ASSET_DIAGNOSTIC_IDS, TOPIK_ASSET_LIMITS, TOPIK_ASSET_NAME_VERSION, TOPIK_ASSET_REFERENCE_VERSION, TOPIK_BLOB_OUTPUT_PREFIX, TOPIK_JSON_VERSION, TOPIK_MATERIALIZATION_VERSION, TOPIK_PATH_V1_DESCRIPTOR, TOPIK_PATH_VERSION, TOPIK_PREVIEW_PROTOCOL, type TopikAssetCorrelationId, type TopikAssetDiagnostic, type TopikAssetDiagnosticId, type TopikAssetDiagnosticLocation, type TopikAssetPathDiagnosticReason, type TopikAssetRecoveryCategory, type TopikAssetReferenceMappingV1, type TopikAssetResult, type TopikAssetSemanticRecordV1, type TopikManifest, type TopikManifestSource, type TopikMaterializationPayloadInput, type TopikMaterializationPayloadV1, type TopikMaterializationRecordV1, type TopikMaterializationResourceInput, type TopikMaterializationResourceV1, type ValidTopikPath, type ValidateTopikPathOptions, type ValidationError, type ValidationResult, type WatchOptions, type Watcher, type WikiConfig, type WikiSwitcherNode, compareTopikAssetIdentities, compileAssetResources, correlateTopikAssetResult, createTopikAssetSemanticRecord, createTopikMaterializationRecord, digestTopikAssetSemanticRecord, digestTopikMaterializationRecord, findFirstWikiPage, findWikiPageAncestors, generateAutomaticAssetName, hasWikiNavChildren, isAssetBlobUri, isExternalWikiDropdown, isExternalWikiTab, isGeneratedAssetName, isInternalWikiDropdown, isInternalWikiTab, joinWikiPath, parseAsset, parseAssetBlobUri, parseGeneratedAssetName, resolveCourseContentHref, resolveCourseContentReference, resolveCourseNavigation, resolveWikiContentHref, resolveWikiContentReference, resolveWikiNavigation, serializeAsset, topikAssetNameDescriptor, validateAssetBlobUri, validateAssetValue, validateProjectNamespace, validateTopikMaterializationRecord };