@riebeckite/node 0.0.34 → 0.0.36

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.
@@ -0,0 +1,7 @@
1
+ import type { ContentSource } from "@riebeckite/core";
2
+ export type ContentSourceConfig = {
3
+ readonly source?: ContentSource;
4
+ readonly directory: string;
5
+ readonly exclude?: readonly string[];
6
+ };
7
+ export declare function createContentSource(config: ContentSourceConfig, directory?: string): ContentSource;
@@ -0,0 +1,48 @@
1
+ import { type ContentMigrationHistory, type ContentMigrationListEntry, type ContentMutationFileChange, type ContentSource } from "@riebeckite/core";
2
+ import type { ContentMigrationApplyOptions, ContentMigrationApplyResult, ContentMigrationPlan, ContentMigrationRecoverOptions, ContentMigrationRecoveryResult, ContentMigrationRollbackOptions, ContentMigrationRollbackOutcome, ContentMigrationStatusReport, FileSystemContentMigrationOptions, FutureContentSource } from "./file_system_content_migration_types.js";
3
+ export type { ContentMigrationApplyOptions, ContentMigrationApplyResult, ContentMigrationPlan, ContentMigrationPlanFile, ContentMigrationRecoverOptions, ContentMigrationRecoveryResult, ContentMigrationRollbackOptions, ContentMigrationRollbackOutcome, ContentMigrationStatusEntry, ContentMigrationStatusReport, ContentMigrationVerification, FileSystemContentMigrationOptions, FutureContentSource, } from "./file_system_content_migration_types.js";
4
+ export declare class FileSystemContentMigration {
5
+ private readonly options;
6
+ private readonly mutation;
7
+ private readonly source;
8
+ constructor(options: FileSystemContentMigrationOptions);
9
+ private get contentDirectory();
10
+ plan(options?: {
11
+ readonly ids?: readonly string[];
12
+ }): Promise<ContentMigrationPlan>;
13
+ savePlan(plan: ContentMigrationPlan, outputPath?: string): Promise<string>;
14
+ loadPlan(planPath: string): Promise<ContentMigrationPlan>;
15
+ history(options?: {
16
+ readonly limit?: number;
17
+ }): Promise<ContentMigrationHistory>;
18
+ list(): Promise<readonly ContentMigrationListEntry[]>;
19
+ apply(options?: ContentMigrationApplyOptions): Promise<ContentMigrationApplyResult>;
20
+ status(): Promise<ContentMigrationStatusReport>;
21
+ recover(options?: ContentMigrationRecoverOptions): Promise<ContentMigrationRecoveryResult>;
22
+ rollback(options: ContentMigrationRollbackOptions): Promise<ContentMigrationRollbackOutcome>;
23
+ private reconcile;
24
+ private preflight;
25
+ private stateWith;
26
+ private supersede;
27
+ private setStatuses;
28
+ private appendHistory;
29
+ private appendHistoryForRecords;
30
+ private failedJournal;
31
+ private currentContentFingerprint;
32
+ private readState;
33
+ private writeState;
34
+ private readHistory;
35
+ private writeHistory;
36
+ private relativeToContent;
37
+ private absoluteFromContent;
38
+ private acquireLock;
39
+ private tryAnalyze;
40
+ private analyze;
41
+ private redirectOperations;
42
+ private verify;
43
+ }
44
+ export declare function createFutureContentSource(base: ContentSource, changes: readonly ContentMutationFileChange[]): FutureContentSource;
45
+ export declare function fingerprintContentFiles(files: readonly {
46
+ readonly path: string;
47
+ readonly content: string | Uint8Array;
48
+ }[]): string;
@@ -0,0 +1,53 @@
1
+ import type { ContentManifest, ContentManifestEntry, ContentMigrationBatch, ContentMigrationDiagnostic, ContentMigrationRecord, ContentMutationFileChange, ContentMutationOperation, ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ import type { ContentMigrationPlan } from "./file_system_content_migration_types.js";
3
+ export declare function redirectFieldFromConfig(config: ResolvedRiebeckiteConfig | undefined): string;
4
+ export declare function fingerprintFiles(files: readonly {
5
+ readonly path: string;
6
+ readonly content: string | Uint8Array;
7
+ }[]): string;
8
+ export declare function fingerprintMutationPlan(operations: readonly ContentMutationOperation[], changes: readonly ContentMutationFileChange[]): string;
9
+ export declare function fingerprintPlan(input: {
10
+ readonly migrations: readonly {
11
+ readonly id: string;
12
+ readonly version: number;
13
+ readonly fingerprint: string;
14
+ }[];
15
+ readonly baseContentFingerprint: string;
16
+ readonly mutationPlanFingerprint: string;
17
+ readonly operations: readonly ContentMutationOperation[];
18
+ readonly diagnostics: readonly ContentMigrationDiagnostic[];
19
+ readonly conflicts: readonly ContentMigrationDiagnostic[];
20
+ }): string;
21
+ export declare function canonicalJson(value: unknown): string;
22
+ export declare function sortValue(value: unknown): unknown;
23
+ export declare function findEntry(manifest: ContentManifest, contentPath: string): ContentManifestEntry | undefined;
24
+ export declare function changedFrontmatterKeys(file: ContentMigrationBatch["files"][number]): Set<string>;
25
+ export declare function diagnosticKey(diagnostic: {
26
+ readonly code: string;
27
+ readonly filePath?: string;
28
+ readonly target?: string;
29
+ }): string;
30
+ export declare function mutationIssue(issue: {
31
+ readonly severity: "warning" | "error";
32
+ readonly code: string;
33
+ readonly message: string;
34
+ readonly path?: string;
35
+ }, severity: "warning" | "error"): ContentMigrationDiagnostic;
36
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
37
+ export declare function sameMigrationPlan(left: ContentMigrationPlan, right: ContentMigrationPlan): boolean;
38
+ export declare function isAppliedRecord(record: ContentMigrationRecord | undefined, fingerprint: string): boolean;
39
+ export type JournalSnapshot = {
40
+ readonly state: string;
41
+ readonly changes: readonly {
42
+ readonly path: string;
43
+ readonly afterFingerprint: string | null;
44
+ }[];
45
+ };
46
+ export declare function readJournalSnapshot(journalPath: string): Promise<JournalSnapshot | undefined>;
47
+ export declare function journalMatchesApplied(contentDirectory: string, journal: JournalSnapshot): Promise<boolean>;
48
+ export declare function isWithin(root: string, target: string): boolean;
49
+ export declare function exists(file: string): Promise<boolean>;
50
+ export declare function staleLockContent(lockPath: string): Promise<string | null>;
51
+ export declare function errorMessage(error: unknown): string;
52
+ export declare function sanitizeErrorMessage(error: unknown, contentDirectory: string): string;
53
+ export declare function errorPath(error: unknown): string | undefined;
@@ -0,0 +1,99 @@
1
+ import type { ContentMigrationBatch, ContentMigrationDiagnostic, ContentMigrationListEntry, ContentMigrationRegistry, ContentMigrationStatus, ContentMutationOperation, ContentSource, ResolvedRiebeckiteConfig, RiebeckitePlugin } from "@riebeckite/core";
2
+ export type FutureContentSource = ContentSource & {
3
+ readonly changes: ReadonlyMap<string, Uint8Array | null>;
4
+ };
5
+ export type ContentMigrationPlanFile = {
6
+ readonly path: string;
7
+ readonly beforeFingerprint: string | null;
8
+ readonly afterFingerprint: string | null;
9
+ };
10
+ export type ContentMigrationVerification = {
11
+ readonly beforeFiles: number;
12
+ readonly afterFiles: number;
13
+ readonly beforePublicationFingerprint: string;
14
+ readonly afterPublicationFingerprint: string;
15
+ readonly derivedViews: number;
16
+ };
17
+ export type ContentMigrationPlan = {
18
+ readonly schemaVersion: 1;
19
+ readonly id: string;
20
+ readonly createdAt: string;
21
+ readonly migrations: readonly {
22
+ readonly id: string;
23
+ readonly version: number;
24
+ readonly fingerprint: string;
25
+ }[];
26
+ readonly baseContentFingerprint: string;
27
+ readonly mutationPlanId: string;
28
+ readonly mutationPlanFingerprint: string;
29
+ readonly planFingerprint: string;
30
+ readonly operations: readonly ContentMutationOperation[];
31
+ readonly changes: readonly ContentMigrationPlanFile[];
32
+ readonly diagnostics: readonly ContentMigrationDiagnostic[];
33
+ readonly conflicts: readonly ContentMigrationDiagnostic[];
34
+ readonly selections: ContentMigrationBatch["selections"];
35
+ readonly skipped: ContentMigrationBatch["skipped"];
36
+ readonly impact: ContentMigrationBatch["impact"];
37
+ readonly verification: ContentMigrationVerification;
38
+ };
39
+ export type FileSystemContentMigrationOptions = {
40
+ readonly contentDirectory: string;
41
+ readonly registry: ContentMigrationRegistry;
42
+ readonly config?: ResolvedRiebeckiteConfig;
43
+ readonly plugins?: readonly RiebeckitePlugin[];
44
+ readonly buildTime?: Date;
45
+ readonly exclude?: readonly string[];
46
+ readonly redirectField?: string;
47
+ };
48
+ export type ContentMigrationApplyOptions = {
49
+ readonly planPath?: string;
50
+ readonly ids?: readonly string[];
51
+ };
52
+ export type ContentMigrationApplyResult = {
53
+ readonly applied: boolean;
54
+ readonly skipped: boolean;
55
+ readonly plan: ContentMigrationPlan;
56
+ readonly journalPath?: string;
57
+ readonly changedPaths: readonly string[];
58
+ readonly conflicts: readonly ContentMigrationDiagnostic[];
59
+ };
60
+ export type ContentMigrationStatusEntry = {
61
+ readonly id: string;
62
+ readonly version: number;
63
+ readonly latestVersion?: number;
64
+ readonly status: ContentMigrationStatus;
65
+ readonly definitionMatches: boolean;
66
+ readonly planId?: string;
67
+ readonly appliedAt?: string;
68
+ readonly updatedAt: string;
69
+ readonly journal?: string;
70
+ readonly error?: string;
71
+ };
72
+ export type ContentMigrationStatusReport = {
73
+ readonly schemaVersion: 1;
74
+ readonly updatedAt: string;
75
+ readonly entries: readonly ContentMigrationStatusEntry[];
76
+ readonly migrations: readonly ContentMigrationListEntry[];
77
+ readonly historyCount: number;
78
+ };
79
+ export type ContentMigrationRecoverOptions = {
80
+ readonly journal?: string;
81
+ readonly migrationId?: string;
82
+ };
83
+ export type ContentMigrationRecoveryResult = {
84
+ readonly recovered: boolean;
85
+ readonly applied: boolean;
86
+ readonly skipped: boolean;
87
+ readonly restoredPaths: readonly string[];
88
+ readonly conflicts: readonly ContentMigrationDiagnostic[];
89
+ };
90
+ export type ContentMigrationRollbackOptions = {
91
+ readonly planId?: string;
92
+ readonly migrationId?: string;
93
+ };
94
+ export type ContentMigrationRollbackOutcome = {
95
+ readonly rolledBack: boolean;
96
+ readonly skipped: boolean;
97
+ readonly restoredPaths: readonly string[];
98
+ readonly conflicts: readonly ContentMigrationDiagnostic[];
99
+ };
@@ -0,0 +1,25 @@
1
+ import { type ContentMutationOperation, type ContentMutationPlan, type ContentMutationRecoveryResult, type ContentMutationResult, type ContentMutationRollbackResult } from "@riebeckite/core";
2
+ export type FileSystemContentMutationOptions = {
3
+ readonly beforeWrite?: (path: string) => void | Promise<void>;
4
+ readonly beforeRecoveryRestore?: (path: string) => void | Promise<void>;
5
+ readonly afterRecoveryCapture?: (path: string) => void | Promise<void>;
6
+ };
7
+ export declare class FileSystemContentMutation {
8
+ private readonly contentDirectory;
9
+ private readonly options;
10
+ constructor(contentDirectory: string, options?: FileSystemContentMutationOptions);
11
+ plan(operations: readonly ContentMutationOperation[]): Promise<ContentMutationPlan>;
12
+ apply(plan: ContentMutationPlan): Promise<ContentMutationResult>;
13
+ recover(journalPath: string): Promise<ContentMutationRecoveryResult>;
14
+ rollback(journalPath: string): Promise<ContentMutationRollbackResult>;
15
+ private restoreChange;
16
+ savePlan(plan: ContentMutationPlan, planPath?: string): Promise<string>;
17
+ loadPlan(planPath: string): Promise<ContentMutationPlan>;
18
+ private revalidatePlan;
19
+ private planPath;
20
+ private root;
21
+ private loadFiles;
22
+ private verifyPreconditions;
23
+ private backup;
24
+ private acquireLock;
25
+ }
@@ -0,0 +1,9 @@
1
+ import { type ContentMigrationHistory, type ContentMigrationState } from "@riebeckite/core";
2
+ export declare function migrationStateDirectory(contentDirectory: string): string;
3
+ export declare function migrationStatePath(contentDirectory: string): string;
4
+ export declare function migrationHistoryPath(contentDirectory: string): string;
5
+ export declare function migrationLockPath(contentDirectory: string): string;
6
+ export declare function readMigrationState(contentDirectory: string): Promise<ContentMigrationState>;
7
+ export declare function writeMigrationState(contentDirectory: string, state: ContentMigrationState): Promise<void>;
8
+ export declare function readMigrationHistory(contentDirectory: string): Promise<ContentMigrationHistory>;
9
+ export declare function writeMigrationHistory(contentDirectory: string, history: ContentMigrationHistory): Promise<void>;
@@ -0,0 +1,33 @@
1
+ import type { ContentMutationFileChange, ContentMutationPlan } from "@riebeckite/core";
2
+ export type MutationJournal = {
3
+ readonly version: 1;
4
+ readonly id: string;
5
+ state: "prepared" | "applying" | "failed" | "complete" | "recovered" | "rolled-back";
6
+ readonly changes: readonly JournalChange[];
7
+ };
8
+ type StoredMutationPlan = {
9
+ readonly schemaVersion: 1;
10
+ readonly id: string;
11
+ readonly operations: unknown;
12
+ readonly changes: readonly StoredFileChange[];
13
+ readonly preconditions: ContentMutationPlan["preconditions"];
14
+ readonly warnings: ContentMutationPlan["warnings"];
15
+ readonly conflicts: ContentMutationPlan["conflicts"];
16
+ };
17
+ type StoredFileChange = Omit<ContentMutationFileChange, "content"> & {
18
+ readonly content: string | null;
19
+ };
20
+ export type JournalChange = {
21
+ readonly path: string;
22
+ readonly beforeFingerprint: string | null;
23
+ readonly afterFingerprint: string | null;
24
+ readonly backupPath?: string;
25
+ status: "pending" | "applied";
26
+ };
27
+ export declare function markApplied(journal: MutationJournal, filePath: string): void;
28
+ export declare function parseJournal(value: string): MutationJournal;
29
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
30
+ export declare function serializePlan(plan: ContentMutationPlan): StoredMutationPlan;
31
+ export declare function parsePlan(value: string): ContentMutationPlan;
32
+ export declare function samePlan(expected: ContentMutationPlan, actual: ContentMutationPlan): boolean;
33
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function isPathInsideDirectory(directory: string, file: string): boolean;
2
+ export declare function toLogicalPath(directory: string, file: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/node",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,10 +23,11 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
- "@riebeckite/core": "0.0.34"
26
+ "@riebeckite/core": "0.0.36",
27
+ "yaml": "^2.9.0"
27
28
  },
28
29
  "devDependencies": {
29
- "@riebeckite/test": "0.0.34",
30
+ "@riebeckite/test": "0.0.36",
30
31
  "tsx": "^4.22.4"
31
32
  },
32
33
  "repository": {