@conloca/content-api 0.1.14 → 0.1.16
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/asset-manifest.d.ts +23 -0
- package/dist/asset-manifest.d.ts.map +1 -0
- package/dist/asset-manifest.js +73 -0
- package/dist/asset-operations.d.ts +159 -0
- package/dist/asset-operations.d.ts.map +1 -0
- package/dist/asset-operations.js +736 -0
- package/dist/asset-types.d.ts +56 -0
- package/dist/asset-types.d.ts.map +1 -0
- package/dist/asset-types.js +7 -0
- package/dist/base-content-index.d.ts +57 -0
- package/dist/base-content-index.d.ts.map +1 -0
- package/dist/base-content-index.js +179 -0
- package/dist/block-index.d.ts +9 -0
- package/dist/block-index.d.ts.map +1 -0
- package/dist/block-index.js +11 -0
- package/dist/blocks.d.ts +16 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +103 -0
- package/dist/cf-access.d.ts +31 -0
- package/dist/cf-access.d.ts.map +1 -0
- package/dist/cf-access.js +66 -0
- package/dist/component-registry.d.ts +50 -0
- package/dist/component-registry.d.ts.map +1 -0
- package/dist/component-registry.js +120 -0
- package/dist/component-registry.types-C0ctF9nh.d.mts +71 -0
- package/dist/component-registry.types-C0ctF9nh.d.mts.map +1 -0
- package/dist/component-registry.types.d.ts +11 -0
- package/dist/component-registry.types.d.ts.map +1 -0
- package/dist/component-registry.types.js +1 -0
- package/dist/content-api.interface.d.ts +64 -0
- package/dist/content-api.interface.d.ts.map +1 -0
- package/dist/content-api.interface.js +1 -0
- package/dist/content-filters.d.ts +31 -0
- package/dist/content-filters.d.ts.map +1 -0
- package/dist/content-filters.js +246 -0
- package/dist/content-index-D092_vk1.mjs +629 -0
- package/dist/content-index-D092_vk1.mjs.map +1 -0
- package/dist/content-index-D6IVMmAB.d.mts +127 -0
- package/dist/content-index-D6IVMmAB.d.mts.map +1 -0
- package/dist/content-index.d.ts +126 -0
- package/dist/content-index.d.ts.map +1 -0
- package/dist/content-index.js +418 -0
- package/dist/content-operations-DIbsxG5A.d.mts +354 -0
- package/dist/content-operations-DIbsxG5A.d.mts.map +1 -0
- package/dist/content-operations.d.ts +93 -0
- package/dist/content-operations.d.ts.map +1 -0
- package/dist/content-operations.js +275 -0
- package/dist/content-reader.d.ts +10 -0
- package/dist/content-reader.d.ts.map +1 -0
- package/dist/content-reader.js +13 -0
- package/dist/content-utils-fWNHTrPy.mjs +280 -0
- package/dist/content-utils-fWNHTrPy.mjs.map +1 -0
- package/dist/content-utils.d.ts +132 -0
- package/dist/content-utils.d.ts.map +1 -0
- package/dist/content-utils.js +352 -0
- package/dist/content-watcher.d.ts +43 -0
- package/dist/content-watcher.d.ts.map +1 -0
- package/dist/content-watcher.js +83 -0
- package/dist/data-DquNIEnQ.mjs +62 -0
- package/dist/data-DquNIEnQ.mjs.map +1 -0
- package/dist/data-index.d.ts +8 -0
- package/dist/data-index.d.ts.map +1 -0
- package/dist/data-index.js +7 -0
- package/dist/data.d.ts +43 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +103 -0
- package/dist/etag-utils.d.ts +77 -0
- package/dist/etag-utils.d.ts.map +1 -0
- package/dist/etag-utils.js +160 -0
- package/dist/filesystem-content-api-B1KIQJfk.mjs +2 -0
- package/dist/filesystem-content-api-C0HIhqZi.mjs +1620 -0
- package/dist/filesystem-content-api-C0HIhqZi.mjs.map +1 -0
- package/dist/filesystem-content-api-DCdNi-co.d.mts +134 -0
- package/dist/filesystem-content-api-DCdNi-co.d.mts.map +1 -0
- package/dist/filesystem-content-api.d.ts +135 -0
- package/dist/filesystem-content-api.d.ts.map +1 -0
- package/dist/filesystem-content-api.js +2181 -0
- package/dist/git-operations.d.ts +49 -0
- package/dist/git-operations.d.ts.map +1 -0
- package/dist/git-operations.js +252 -0
- package/dist/header-parser.d.ts +37 -0
- package/dist/header-parser.d.ts.map +1 -0
- package/dist/header-parser.js +286 -0
- package/dist/in-memory-content-api.d.ts +35 -0
- package/dist/in-memory-content-api.d.ts.map +1 -0
- package/dist/in-memory-content-api.js +591 -0
- package/dist/index-DxVTFK66.d.mts +105 -0
- package/dist/index-DxVTFK66.d.mts.map +1 -0
- package/dist/index.d.mts +6 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.mjs +37 -5
- package/dist/index.mjs.map +1 -1
- package/dist/indexing.d.mts +152 -0
- package/dist/indexing.d.mts.map +1 -0
- package/dist/indexing.d.ts +5 -0
- package/dist/indexing.d.ts.map +1 -0
- package/dist/indexing.js +7 -0
- package/dist/indexing.mjs +255 -0
- package/dist/indexing.mjs.map +1 -0
- package/dist/json-whitespace-view.d.ts +32 -0
- package/dist/json-whitespace-view.d.ts.map +1 -0
- package/dist/json-whitespace-view.js +152 -0
- package/dist/middleware.d.ts +20 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +1031 -0
- package/dist/node.d.mts +28 -126
- package/dist/node.d.mts.map +1 -1
- package/dist/node.d.ts +25 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +24 -0
- package/dist/node.mjs +199 -2890
- package/dist/node.mjs.map +1 -1
- package/dist/reader.d.mts +15 -0
- package/dist/reader.d.mts.map +1 -0
- package/dist/reader.d.ts +15 -0
- package/dist/reader.d.ts.map +1 -0
- package/dist/reader.js +13 -0
- package/dist/reader.mjs +22 -0
- package/dist/reader.mjs.map +1 -0
- package/dist/schemas/index.d.mts +2 -90
- package/dist/schemas/index.d.ts +102 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +87 -0
- package/dist/schemas/index.mjs +2 -70
- package/dist/schemas-CFRD0FIQ.mjs +84 -0
- package/dist/schemas-CFRD0FIQ.mjs.map +1 -0
- package/dist/{types-BUG0Cfkg.mjs → site-8oaj1Q60.mjs} +20 -222
- package/dist/site-8oaj1Q60.mjs.map +1 -0
- package/dist/site-index-B_254bCc.d.mts +136 -0
- package/dist/site-index-B_254bCc.d.mts.map +1 -0
- package/dist/site-index.d.ts +60 -0
- package/dist/site-index.d.ts.map +1 -0
- package/dist/site-index.js +287 -0
- package/dist/site.d.ts +21 -0
- package/dist/site.d.ts.map +1 -0
- package/dist/site.js +168 -0
- package/dist/types-DOdldbfD.mjs +34 -0
- package/dist/types-DOdldbfD.mjs.map +1 -0
- package/dist/types-DjfhS272.d.mts +456 -0
- package/dist/types-DjfhS272.d.mts.map +1 -0
- package/dist/types.d.ts +453 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +36 -0
- package/dist/url-safe-base64.d.ts +12 -0
- package/dist/url-safe-base64.d.ts.map +1 -0
- package/dist/url-safe-base64.js +40 -0
- package/dist/url-validation.d.ts +14 -0
- package/dist/url-validation.d.ts.map +1 -0
- package/dist/url-validation.js +81 -0
- package/dist/utils/atomic-write.d.ts +6 -0
- package/dist/utils/atomic-write.d.ts.map +1 -0
- package/dist/utils/atomic-write.js +20 -0
- package/dist/utils.d.ts +46 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +70 -0
- package/dist/vite-plugin.d.ts +12 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +29 -0
- package/dist/vxjson-qHrgLGip.mjs +555 -0
- package/dist/vxjson-qHrgLGip.mjs.map +1 -0
- package/dist/vxjson-serialize-geF6qvpn.mjs +34 -0
- package/dist/vxjson-serialize-geF6qvpn.mjs.map +1 -0
- package/dist/vxjson-serialize.d.mts +17 -0
- package/dist/vxjson-serialize.d.mts.map +1 -0
- package/dist/vxjson-serialize.d.ts +14 -0
- package/dist/vxjson-serialize.d.ts.map +1 -0
- package/dist/vxjson-serialize.js +50 -0
- package/dist/vxjson-serialize.mjs +2 -0
- package/dist/vxjson.d.ts +112 -0
- package/dist/vxjson.d.ts.map +1 -0
- package/dist/vxjson.js +391 -0
- package/dist/xxhash.d.ts +10 -0
- package/dist/xxhash.d.ts.map +1 -0
- package/dist/xxhash.js +31 -0
- package/package.json +88 -17
- package/dist/content-operations-BZLfJWqT.d.mts +0 -916
- package/dist/content-operations-BZLfJWqT.d.mts.map +0 -1
- package/dist/schemas/index.d.mts.map +0 -1
- package/dist/schemas/index.mjs.map +0 -1
- package/dist/types-BUG0Cfkg.mjs.map +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface GitStatus {
|
|
2
|
+
isRepo: boolean;
|
|
3
|
+
hasChanges: boolean;
|
|
4
|
+
changedFiles: number;
|
|
5
|
+
ahead: number;
|
|
6
|
+
behind: number;
|
|
7
|
+
branch: string;
|
|
8
|
+
remoteConfigured?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface GitCommitResult {
|
|
11
|
+
success: boolean;
|
|
12
|
+
commit?: string;
|
|
13
|
+
summary?: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface GitPushResult {
|
|
17
|
+
success: boolean;
|
|
18
|
+
error?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface GitPullResult {
|
|
21
|
+
success: boolean;
|
|
22
|
+
summary?: string;
|
|
23
|
+
error?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface GitAuthor {
|
|
26
|
+
name: string;
|
|
27
|
+
email: string;
|
|
28
|
+
}
|
|
29
|
+
export interface GitOperations {
|
|
30
|
+
getStatus(): Promise<GitStatus>;
|
|
31
|
+
commitAll(message: string, author?: GitAuthor): Promise<GitCommitResult>;
|
|
32
|
+
pushOrigin(): Promise<GitPushResult>;
|
|
33
|
+
pull(): Promise<GitPullResult>;
|
|
34
|
+
}
|
|
35
|
+
export interface GitConfig {
|
|
36
|
+
contentPath: string;
|
|
37
|
+
branch?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create git operations using local git CLI commands.
|
|
41
|
+
* Requires git binary available on PATH and CONTENT_PATH inside a git repository.
|
|
42
|
+
*/
|
|
43
|
+
export declare function createGitOperations(config: GitConfig): GitOperations;
|
|
44
|
+
/**
|
|
45
|
+
* Ensure .gitattributes exists at contentRoot with LFS tracking patterns for web image extensions.
|
|
46
|
+
* Creates the file if missing, or appends missing patterns if file exists.
|
|
47
|
+
*/
|
|
48
|
+
export declare function setupGitLfsAttributes(contentRoot: string): Promise<void>;
|
|
49
|
+
//# sourceMappingURL=git-operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-operations.d.ts","sourceRoot":"","sources":["../src/git-operations.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACzE,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;IACrC,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAgDD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,GAAG,aAAa,CAwMpE;AAaD;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoB9E"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { access, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
function runGitCommand(cwd, args) {
|
|
5
|
+
return new Promise((resolveCommand, reject) => {
|
|
6
|
+
const process = spawn('git', args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
7
|
+
let stdout = '';
|
|
8
|
+
let stderr = '';
|
|
9
|
+
process.stdout.on('data', (data) => {
|
|
10
|
+
stdout += data.toString();
|
|
11
|
+
});
|
|
12
|
+
process.stderr.on('data', (data) => {
|
|
13
|
+
stderr += data.toString();
|
|
14
|
+
});
|
|
15
|
+
process.on('error', reject);
|
|
16
|
+
process.on('close', (exitCode) => {
|
|
17
|
+
resolveCommand({
|
|
18
|
+
exitCode: exitCode ?? 1,
|
|
19
|
+
stdout: stdout.trim(),
|
|
20
|
+
stderr: stderr.trim(),
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve the git repository root from a content path.
|
|
27
|
+
* Uses `git rev-parse --show-toplevel` starting from the parent of the content directory.
|
|
28
|
+
*/
|
|
29
|
+
async function resolveRepoRoot(contentPath) {
|
|
30
|
+
const contentRoot = resolve(contentPath);
|
|
31
|
+
const startDir = dirname(contentRoot);
|
|
32
|
+
const result = await runGitCommand(startDir, ['rev-parse', '--show-toplevel']);
|
|
33
|
+
if (result.exitCode !== 0) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return result.stdout;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create git operations using local git CLI commands.
|
|
40
|
+
* Requires git binary available on PATH and CONTENT_PATH inside a git repository.
|
|
41
|
+
*/
|
|
42
|
+
export function createGitOperations(config) {
|
|
43
|
+
const { contentPath, branch } = config;
|
|
44
|
+
let cachedRepoRoot;
|
|
45
|
+
async function getCachedRepoRoot() {
|
|
46
|
+
if (cachedRepoRoot === undefined) {
|
|
47
|
+
cachedRepoRoot = await resolveRepoRoot(contentPath);
|
|
48
|
+
}
|
|
49
|
+
return cachedRepoRoot;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
async getStatus() {
|
|
53
|
+
try {
|
|
54
|
+
const repoRoot = await getCachedRepoRoot();
|
|
55
|
+
if (!repoRoot) {
|
|
56
|
+
return { isRepo: false, hasChanges: false, changedFiles: 0, ahead: 0, behind: 0, branch: 'unknown' };
|
|
57
|
+
}
|
|
58
|
+
// Get current branch
|
|
59
|
+
const branchResult = await runGitCommand(repoRoot, ['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
60
|
+
const currentBranch = branchResult.exitCode === 0 ? branchResult.stdout : 'unknown';
|
|
61
|
+
// Get changed files count
|
|
62
|
+
const statusResult = await runGitCommand(repoRoot, ['status', '--porcelain', '--', contentPath]);
|
|
63
|
+
const changedLines = statusResult.stdout ? statusResult.stdout.split('\n').filter((l) => l.trim()) : [];
|
|
64
|
+
const changedFiles = changedLines.length;
|
|
65
|
+
const hasChanges = changedFiles > 0;
|
|
66
|
+
// Check if remote origin is configured
|
|
67
|
+
const remoteResult = await runGitCommand(repoRoot, ['remote', 'get-url', 'origin']);
|
|
68
|
+
const remoteConfigured = remoteResult.exitCode === 0;
|
|
69
|
+
// Get ahead/behind counts
|
|
70
|
+
let ahead = 0;
|
|
71
|
+
let behind = 0;
|
|
72
|
+
if (remoteConfigured) {
|
|
73
|
+
const trackingBranch = branch || currentBranch;
|
|
74
|
+
const revListResult = await runGitCommand(repoRoot, [
|
|
75
|
+
'rev-list',
|
|
76
|
+
'--left-right',
|
|
77
|
+
'--count',
|
|
78
|
+
`HEAD...origin/${trackingBranch}`,
|
|
79
|
+
]);
|
|
80
|
+
if (revListResult.exitCode === 0 && revListResult.stdout) {
|
|
81
|
+
const [a, b] = revListResult.stdout.split('\t').map(Number);
|
|
82
|
+
ahead = a || 0;
|
|
83
|
+
behind = b || 0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { isRepo: true, hasChanges, changedFiles, ahead, behind, branch: currentBranch, remoteConfigured };
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return { isRepo: false, hasChanges: false, changedFiles: 0, ahead: 0, behind: 0, branch: 'unknown' };
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
async commitAll(message, author) {
|
|
93
|
+
try {
|
|
94
|
+
const repoRoot = await getCachedRepoRoot();
|
|
95
|
+
if (!repoRoot) {
|
|
96
|
+
return { success: false, error: 'Not a git repository' };
|
|
97
|
+
}
|
|
98
|
+
// Stage all changes
|
|
99
|
+
const addResult = await runGitCommand(repoRoot, ['add', '-A', '--', contentPath]);
|
|
100
|
+
if (addResult.exitCode !== 0) {
|
|
101
|
+
return { success: false, error: addResult.stderr || 'Failed to stage changes' };
|
|
102
|
+
}
|
|
103
|
+
// Check if there's anything to commit after staging
|
|
104
|
+
const diffResult = await runGitCommand(repoRoot, ['diff', '--cached', '--quiet', '--', contentPath]);
|
|
105
|
+
if (diffResult.exitCode === 0) {
|
|
106
|
+
return { success: false, error: 'No changes to commit' };
|
|
107
|
+
}
|
|
108
|
+
// Count staged files for summary
|
|
109
|
+
const diffStatResult = await runGitCommand(repoRoot, ['diff', '--cached', '--numstat', '--', contentPath]);
|
|
110
|
+
const fileCount = diffStatResult.stdout ? diffStatResult.stdout.split('\n').filter((l) => l.trim()).length : 0;
|
|
111
|
+
// Build commit command
|
|
112
|
+
const commitArgs = ['commit', '-m', message];
|
|
113
|
+
if (author) {
|
|
114
|
+
commitArgs.push('--author', `${author.name} <${author.email}>`);
|
|
115
|
+
}
|
|
116
|
+
const commitResult = await runGitCommand(repoRoot, commitArgs);
|
|
117
|
+
if (commitResult.exitCode !== 0) {
|
|
118
|
+
return { success: false, error: commitResult.stderr || 'Commit failed' };
|
|
119
|
+
}
|
|
120
|
+
// Get the commit SHA
|
|
121
|
+
const shaResult = await runGitCommand(repoRoot, ['rev-parse', 'HEAD']);
|
|
122
|
+
const commitSha = shaResult.stdout || undefined;
|
|
123
|
+
return {
|
|
124
|
+
success: true,
|
|
125
|
+
commit: commitSha,
|
|
126
|
+
summary: `${fileCount} files committed`,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
return {
|
|
131
|
+
success: false,
|
|
132
|
+
error: error instanceof Error ? error.message : 'Commit failed',
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
async pushOrigin() {
|
|
137
|
+
try {
|
|
138
|
+
const repoRoot = await getCachedRepoRoot();
|
|
139
|
+
if (!repoRoot) {
|
|
140
|
+
return { success: false, error: 'Not a git repository' };
|
|
141
|
+
}
|
|
142
|
+
// Pre-check: verify remote is configured
|
|
143
|
+
const remoteResult = await runGitCommand(repoRoot, ['remote', 'get-url', 'origin']);
|
|
144
|
+
if (remoteResult.exitCode !== 0) {
|
|
145
|
+
return {
|
|
146
|
+
success: false,
|
|
147
|
+
error: 'No git remote "origin" configured. Please configure a remote to enable push.',
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
// Determine branch to push
|
|
151
|
+
let targetBranch = branch;
|
|
152
|
+
if (!targetBranch) {
|
|
153
|
+
const branchResult = await runGitCommand(repoRoot, ['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
154
|
+
targetBranch = branchResult.stdout;
|
|
155
|
+
}
|
|
156
|
+
const pushResult = await runGitCommand(repoRoot, ['push', 'origin', targetBranch]);
|
|
157
|
+
if (pushResult.exitCode !== 0) {
|
|
158
|
+
const stderr = pushResult.stderr || '';
|
|
159
|
+
if (stderr.includes('non-fast-forward') || stderr.includes('rejected')) {
|
|
160
|
+
return {
|
|
161
|
+
success: false,
|
|
162
|
+
error: 'Push rejected: remote has changes. Pull first, then try pushing again.',
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (stderr.includes('Could not resolve host')) {
|
|
166
|
+
return {
|
|
167
|
+
success: false,
|
|
168
|
+
error: 'Cannot reach git remote. Check your network connection.',
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (stderr.includes('Permission denied') || stderr.includes('Authentication failed')) {
|
|
172
|
+
return {
|
|
173
|
+
success: false,
|
|
174
|
+
error: 'Git remote authentication failed. Check server SSH key or credential configuration.',
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return { success: false, error: stderr || 'Push failed' };
|
|
178
|
+
}
|
|
179
|
+
return { success: true };
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
return {
|
|
183
|
+
success: false,
|
|
184
|
+
error: error instanceof Error ? error.message : 'Push failed',
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
async pull() {
|
|
189
|
+
try {
|
|
190
|
+
const repoRoot = await getCachedRepoRoot();
|
|
191
|
+
if (!repoRoot) {
|
|
192
|
+
return { success: false, error: 'Not a git repository' };
|
|
193
|
+
}
|
|
194
|
+
// Determine branch for pull
|
|
195
|
+
let targetBranch = branch;
|
|
196
|
+
if (!targetBranch) {
|
|
197
|
+
const branchResult = await runGitCommand(repoRoot, ['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
198
|
+
targetBranch = branchResult.stdout;
|
|
199
|
+
}
|
|
200
|
+
const pullResult = await runGitCommand(repoRoot, ['pull', '--autostash', '--rebase', 'origin', targetBranch]);
|
|
201
|
+
if (pullResult.exitCode !== 0) {
|
|
202
|
+
return {
|
|
203
|
+
success: false,
|
|
204
|
+
error: pullResult.stderr || pullResult.stdout || 'Pull failed',
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
success: true,
|
|
209
|
+
summary: pullResult.stdout || `Pulled latest changes from origin/${targetBranch}`,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
return {
|
|
214
|
+
success: false,
|
|
215
|
+
error: error instanceof Error ? error.message : 'Pull failed',
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const LFS_PATTERNS = [
|
|
222
|
+
'*.jpg filter=lfs diff=lfs merge=lfs -text',
|
|
223
|
+
'*.jpeg filter=lfs diff=lfs merge=lfs -text',
|
|
224
|
+
'*.png filter=lfs diff=lfs merge=lfs -text',
|
|
225
|
+
'*.gif filter=lfs diff=lfs merge=lfs -text',
|
|
226
|
+
'*.svg filter=lfs diff=lfs merge=lfs -text',
|
|
227
|
+
'*.webp filter=lfs diff=lfs merge=lfs -text',
|
|
228
|
+
'*.avif filter=lfs diff=lfs merge=lfs -text',
|
|
229
|
+
'*.ico filter=lfs diff=lfs merge=lfs -text',
|
|
230
|
+
];
|
|
231
|
+
/**
|
|
232
|
+
* Ensure .gitattributes exists at contentRoot with LFS tracking patterns for web image extensions.
|
|
233
|
+
* Creates the file if missing, or appends missing patterns if file exists.
|
|
234
|
+
*/
|
|
235
|
+
export async function setupGitLfsAttributes(contentRoot) {
|
|
236
|
+
const gitattributesPath = join(contentRoot, '.gitattributes');
|
|
237
|
+
let existing = '';
|
|
238
|
+
try {
|
|
239
|
+
await access(gitattributesPath);
|
|
240
|
+
existing = await readFile(gitattributesPath, 'utf-8');
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
// File doesn't exist — will create fresh
|
|
244
|
+
}
|
|
245
|
+
const missingPatterns = LFS_PATTERNS.filter((pattern) => !existing.includes(pattern));
|
|
246
|
+
if (missingPatterns.length === 0)
|
|
247
|
+
return;
|
|
248
|
+
const newContent = existing
|
|
249
|
+
? `${existing.trimEnd()}\n${missingPatterns.join('\n')}\n`
|
|
250
|
+
: `${missingPatterns.join('\n')}\n`;
|
|
251
|
+
await writeFile(gitattributesPath, newContent, 'utf-8');
|
|
252
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ContentData, ContentManifest, LocaleVersion } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Result of parsing a content blob's header.
|
|
4
|
+
*
|
|
5
|
+
* `repaired === true` means the bytes parsed but were not in canonical form;
|
|
6
|
+
* the manifest reflects the canonical interpretation. The hydrator never
|
|
7
|
+
* writes back; spec 03 may opt to rewrite the file via the FS API's own
|
|
8
|
+
* write path, but that decision lives outside this pure parser.
|
|
9
|
+
*/
|
|
10
|
+
export type ParseHeaderResult = {
|
|
11
|
+
ok: true;
|
|
12
|
+
manifest: ContentManifest;
|
|
13
|
+
locale: string;
|
|
14
|
+
localeVersion: LocaleVersion;
|
|
15
|
+
content?: ContentData;
|
|
16
|
+
repaired: boolean;
|
|
17
|
+
} | {
|
|
18
|
+
ok: false;
|
|
19
|
+
reason: 'unknown-format' | 'malformed-vxjson' | 'malformed-mdx' | 'unsupported-locale-path';
|
|
20
|
+
message: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Parse a content blob's header bytes (default 4 KB) into a manifest entry.
|
|
24
|
+
*
|
|
25
|
+
* Pure: no I/O, no clock, no FS. The `repaired` flag means "header bytes
|
|
26
|
+
* were not canonical, so we computed the canonical manifest entry from a
|
|
27
|
+
* repaired in-memory copy" — actual writes (e.g., FS rename) happen in
|
|
28
|
+
* the caller, not here. The Branch DO never writes-on-read; it just records
|
|
29
|
+
* the canonical form for the next commit.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseContentHeader(input: {
|
|
32
|
+
path: string;
|
|
33
|
+
header: Uint8Array;
|
|
34
|
+
size: number;
|
|
35
|
+
complete: boolean;
|
|
36
|
+
}): ParseHeaderResult;
|
|
37
|
+
//# sourceMappingURL=header-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header-parser.d.ts","sourceRoot":"","sources":["../src/header-parser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAe,aAAa,EAAc,MAAM,SAAS,CAAC;AAMpG;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GACzB;IACE,EAAE,EAAE,IAAI,CAAC;IACT,QAAQ,EAAE,eAAe,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;CACnB,GACD;IACE,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EAAE,gBAAgB,GAAG,kBAAkB,GAAG,eAAe,GAAG,yBAAyB,CAAC;IAC5F,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AA0MN;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB,GAAG,iBAAiB,CA2FpB"}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import matter from 'gray-matter';
|
|
2
|
+
import { calculateEtagsFromMdxBuffer, findMdxContentStartPosition } from './etag-utils';
|
|
3
|
+
import { VXJSON } from './vxjson';
|
|
4
|
+
const textDecoder = new TextDecoder();
|
|
5
|
+
const textEncoder = new TextEncoder();
|
|
6
|
+
/**
|
|
7
|
+
* Pure path → identity mapper. Returns null when the path doesn't match any
|
|
8
|
+
* supported layout or lacks an explicit locale suffix; the caller maps null
|
|
9
|
+
* to a `unsupported-locale-path` ParseHeaderResult.
|
|
10
|
+
*
|
|
11
|
+
* Layouts honoured here mirror filesystem-content-api.ts:137-144 and
|
|
12
|
+
* 00-overview.md "Commit Flow":
|
|
13
|
+
*
|
|
14
|
+
* - `blocks/<collection>/<name>.<locale>.{mdx,vxjson}` (collection required;
|
|
15
|
+
* `blocks/<name>.<locale>.ext` is a legacy form that FileSystemContentAPI
|
|
16
|
+
* repairs by renaming. The pure parser refuses it.)
|
|
17
|
+
* - `data/<collection>/<name>.<locale>.json`
|
|
18
|
+
* - `<site>/<collection>/<path...>/<file>.<locale>.vxjson` (pages; `index`
|
|
19
|
+
* basename maps to the parent path).
|
|
20
|
+
*/
|
|
21
|
+
function parsePathLayout(path) {
|
|
22
|
+
const parts = path.split('/').filter(Boolean);
|
|
23
|
+
if (parts.length < 3)
|
|
24
|
+
return null;
|
|
25
|
+
const filename = parts[parts.length - 1];
|
|
26
|
+
if (parts[0] === 'blocks') {
|
|
27
|
+
// blocks/<collection>/<name>.<locale>.<ext>
|
|
28
|
+
if (parts.length !== 3)
|
|
29
|
+
return null;
|
|
30
|
+
const match = filename.match(/^(.+)\.([a-zA-Z]{2}(?:-[A-Z]{2})?)\.(mdx|vxjson)$/);
|
|
31
|
+
if (!match)
|
|
32
|
+
return null;
|
|
33
|
+
return { kind: 'block', collection: parts[1], name: match[1], locale: match[2] };
|
|
34
|
+
}
|
|
35
|
+
if (parts[0] === 'data') {
|
|
36
|
+
// data/<collection>/<name>.<locale>.json
|
|
37
|
+
if (parts.length !== 3)
|
|
38
|
+
return null;
|
|
39
|
+
const match = filename.match(/^(.+)\.([a-z]{2}(?:-[A-Z]{2})?)\.json$/);
|
|
40
|
+
if (!match)
|
|
41
|
+
return null;
|
|
42
|
+
return { kind: 'data', collection: parts[1], name: match[1], locale: match[2] };
|
|
43
|
+
}
|
|
44
|
+
// <site>/<collection>/<path...>/<file>.<locale>.{vxjson,mdx}
|
|
45
|
+
// Reads accept .mdx pages even though the OSS filesystem writer emits
|
|
46
|
+
// main-layout pages as .vxjson only (its mdx pages live under the separate
|
|
47
|
+
// mdxPagesRoot): the SaaS commit pipeline derives the extension from the
|
|
48
|
+
// content type, so an mdx-typed page lands here as <site>/pages/<f>.<l>.mdx
|
|
49
|
+
// and must re-parse — dropping it made written pages unreadable.
|
|
50
|
+
const match = filename.match(/^(.+)\.([a-zA-Z]{2}(?:-[A-Z]{2})?)\.(mdx|vxjson)$/);
|
|
51
|
+
if (!match)
|
|
52
|
+
return null;
|
|
53
|
+
const site = parts[0];
|
|
54
|
+
const collection = parts[1];
|
|
55
|
+
const pathParts = parts.slice(2);
|
|
56
|
+
pathParts[pathParts.length - 1] = match[1];
|
|
57
|
+
const pathname = pathParts[pathParts.length - 1] === 'index'
|
|
58
|
+
? `/${pathParts.slice(0, -1).join('/')}` || '/'
|
|
59
|
+
: `/${pathParts.join('/')}`;
|
|
60
|
+
return { kind: 'page', site, collection, locale: match[2], pathname };
|
|
61
|
+
}
|
|
62
|
+
function parseHeaderMetadataMdx(bytes) {
|
|
63
|
+
const partial = textDecoder.decode(bytes);
|
|
64
|
+
// Empty options opt out of gray-matter's module-level memo cache — a plain
|
|
65
|
+
// object keyed by the raw input, so inputs naming an Object.prototype member
|
|
66
|
+
// ('valueOf', 'toString', …) return the inherited member instead of a parse.
|
|
67
|
+
// Errors as data, like the JSON/VXJSON siblings: a leading delimiter with
|
|
68
|
+
// unparseable YAML ('---\n[') makes js-yaml throw, and that used to escape
|
|
69
|
+
// straight through parseContentHeader instead of its malformed-mdx result.
|
|
70
|
+
let frontmatter;
|
|
71
|
+
try {
|
|
72
|
+
({ data: frontmatter } = matter(partial, {}));
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const contentStartPos = findMdxContentStartPosition(bytes);
|
|
78
|
+
const { id, created, modified, publishAt, unpublishAt, name: _name, ...rest } = frontmatter;
|
|
79
|
+
return {
|
|
80
|
+
id,
|
|
81
|
+
created,
|
|
82
|
+
modified,
|
|
83
|
+
publishAt,
|
|
84
|
+
unpublishAt,
|
|
85
|
+
meta: rest,
|
|
86
|
+
contentStartPos,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function parseHeaderMetadataJson(bytes) {
|
|
90
|
+
try {
|
|
91
|
+
const data = JSON.parse(textDecoder.decode(bytes));
|
|
92
|
+
return {
|
|
93
|
+
id: data.id,
|
|
94
|
+
type: 'json',
|
|
95
|
+
created: data.created,
|
|
96
|
+
modified: data.modified,
|
|
97
|
+
publishAt: data.publishAt,
|
|
98
|
+
unpublishAt: data.unpublishAt,
|
|
99
|
+
meta: data.meta,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function parseHeaderMetadataVxjson(bytes, complete) {
|
|
107
|
+
// VXJSON.parse4KB throws on malformed headers; we want errors-as-data here.
|
|
108
|
+
try {
|
|
109
|
+
return VXJSON.parse4KB(bytes, bytes.length);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
if (!complete) {
|
|
113
|
+
// Could be a thinly truncated header that doesn't yet contain enough
|
|
114
|
+
// metadata to parse. Caller will report malformed-vxjson.
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function canonicalizeVxjsonBytes(bytes) {
|
|
121
|
+
try {
|
|
122
|
+
const parsed = JSON.parse(textDecoder.decode(bytes));
|
|
123
|
+
const canonical = {
|
|
124
|
+
id: parsed.id,
|
|
125
|
+
type: parsed.type,
|
|
126
|
+
created: parsed.created,
|
|
127
|
+
modified: parsed.modified,
|
|
128
|
+
publishAt: parsed.publishAt,
|
|
129
|
+
unpublishAt: parsed.unpublishAt,
|
|
130
|
+
previousPathnames: parsed.previousPathnames,
|
|
131
|
+
meta: parsed.meta || {},
|
|
132
|
+
content: parsed.content || {},
|
|
133
|
+
};
|
|
134
|
+
return textEncoder.encode(VXJSON.serialize(canonical));
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function bytesEqual(a, b) {
|
|
141
|
+
if (a.byteLength !== b.byteLength)
|
|
142
|
+
return false;
|
|
143
|
+
for (let i = 0; i < a.byteLength; i++) {
|
|
144
|
+
if (a[i] !== b[i])
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
function deriveType(path, parsed) {
|
|
150
|
+
if (parsed.type)
|
|
151
|
+
return parsed.type;
|
|
152
|
+
if (path.endsWith('.mdx'))
|
|
153
|
+
return 'mdx';
|
|
154
|
+
if (path.endsWith('.json'))
|
|
155
|
+
return 'json';
|
|
156
|
+
return 'puck';
|
|
157
|
+
}
|
|
158
|
+
function parseFullContent(path, bytes) {
|
|
159
|
+
try {
|
|
160
|
+
if (path.endsWith('.mdx')) {
|
|
161
|
+
// Empty options: see parseHeaderMetadataMdx on the memo-cache hazard.
|
|
162
|
+
const { content } = matter(textDecoder.decode(bytes), {});
|
|
163
|
+
return { mdx: content };
|
|
164
|
+
}
|
|
165
|
+
const data = JSON.parse(textDecoder.decode(bytes));
|
|
166
|
+
if (path.endsWith('.json'))
|
|
167
|
+
return { data: data.data || {} };
|
|
168
|
+
return data.content || {};
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function etagFor(path, bytes, contentStartPos) {
|
|
175
|
+
if (path.endsWith('.mdx')) {
|
|
176
|
+
const etags = calculateEtagsFromMdxBuffer(bytes, contentStartPos ?? findMdxContentStartPosition(bytes));
|
|
177
|
+
return `${etags.metaEtag}.${etags.contentEtag}`;
|
|
178
|
+
}
|
|
179
|
+
if (path.endsWith('.json')) {
|
|
180
|
+
return VXJSON.calculateSimpleEtag(bytes);
|
|
181
|
+
}
|
|
182
|
+
const result = VXJSON.calculateETags(bytes);
|
|
183
|
+
if (!result.success)
|
|
184
|
+
return null;
|
|
185
|
+
return result.contentEtag ? `${result.metaEtag}.${result.contentEtag}` : result.metaEtag;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Parse a content blob's header bytes (default 4 KB) into a manifest entry.
|
|
189
|
+
*
|
|
190
|
+
* Pure: no I/O, no clock, no FS. The `repaired` flag means "header bytes
|
|
191
|
+
* were not canonical, so we computed the canonical manifest entry from a
|
|
192
|
+
* repaired in-memory copy" — actual writes (e.g., FS rename) happen in
|
|
193
|
+
* the caller, not here. The Branch DO never writes-on-read; it just records
|
|
194
|
+
* the canonical form for the next commit.
|
|
195
|
+
*/
|
|
196
|
+
export function parseContentHeader(input) {
|
|
197
|
+
const { path, header, complete } = input;
|
|
198
|
+
const layout = parsePathLayout(path);
|
|
199
|
+
if (!layout) {
|
|
200
|
+
return {
|
|
201
|
+
ok: false,
|
|
202
|
+
reason: 'unsupported-locale-path',
|
|
203
|
+
message: `Path does not match any known content layout: ${path}`,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
let parsedMeta;
|
|
207
|
+
let bytes = header;
|
|
208
|
+
let repaired = false;
|
|
209
|
+
if (path.endsWith('.mdx')) {
|
|
210
|
+
parsedMeta = parseHeaderMetadataMdx(bytes);
|
|
211
|
+
if (!parsedMeta) {
|
|
212
|
+
return { ok: false, reason: 'malformed-mdx', message: `Could not parse MDX header for ${path}` };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else if (path.endsWith('.json')) {
|
|
216
|
+
parsedMeta = parseHeaderMetadataJson(bytes);
|
|
217
|
+
if (!parsedMeta) {
|
|
218
|
+
return { ok: false, reason: 'malformed-vxjson', message: `Could not parse JSON header for ${path}` };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else if (path.endsWith('.vxjson')) {
|
|
222
|
+
if (complete) {
|
|
223
|
+
// For complete blobs, treat canonical-form serialization as the
|
|
224
|
+
// source of truth for etag stability. Even if VXJSON.calculateETags
|
|
225
|
+
// succeeds on the raw bytes, the meta-etag depends on the alphabetic
|
|
226
|
+
// sort order that VXJSON.serialize enforces — so a file whose
|
|
227
|
+
// metadata fields are in a different order produces a different
|
|
228
|
+
// meta-etag than its canonical form. Re-serialize, compare, mark
|
|
229
|
+
// repaired when bytes diverge.
|
|
230
|
+
const canonical = canonicalizeVxjsonBytes(bytes);
|
|
231
|
+
if (canonical) {
|
|
232
|
+
if (!bytesEqual(canonical, bytes)) {
|
|
233
|
+
bytes = canonical;
|
|
234
|
+
repaired = true;
|
|
235
|
+
}
|
|
236
|
+
parsedMeta = parseHeaderMetadataVxjson(bytes, true);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
parsedMeta = null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
// Partial header: parse what we can; no canonicalisation possible
|
|
244
|
+
// without the full blob, and `complete: false` is the caller's
|
|
245
|
+
// signal that the etag will be deferred.
|
|
246
|
+
parsedMeta = parseHeaderMetadataVxjson(bytes, false);
|
|
247
|
+
}
|
|
248
|
+
if (!parsedMeta) {
|
|
249
|
+
return { ok: false, reason: 'malformed-vxjson', message: `Could not parse VXJSON header for ${path}` };
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
return { ok: false, reason: 'unknown-format', message: `Unknown file extension for ${path}` };
|
|
254
|
+
}
|
|
255
|
+
const type = deriveType(path, parsedMeta);
|
|
256
|
+
const localeVersion = {
|
|
257
|
+
locale: layout.locale,
|
|
258
|
+
etag: '',
|
|
259
|
+
created: parsedMeta.created || '',
|
|
260
|
+
modified: parsedMeta.modified || '',
|
|
261
|
+
...(parsedMeta.publishAt ? { publishAt: parsedMeta.publishAt } : {}),
|
|
262
|
+
...(parsedMeta.unpublishAt ? { unpublishAt: parsedMeta.unpublishAt } : {}),
|
|
263
|
+
...(layout.pathname ? { pathname: layout.pathname } : {}),
|
|
264
|
+
...(parsedMeta.previousPathnames ? { previousPathnames: parsedMeta.previousPathnames } : {}),
|
|
265
|
+
...(layout.name ? { name: layout.name } : {}),
|
|
266
|
+
meta: parsedMeta.meta || { title: layout.name || 'Untitled' },
|
|
267
|
+
};
|
|
268
|
+
const manifest = {
|
|
269
|
+
id: parsedMeta.id || '',
|
|
270
|
+
type,
|
|
271
|
+
kind: layout.kind,
|
|
272
|
+
site: layout.site,
|
|
273
|
+
collection: layout.collection,
|
|
274
|
+
locales: { [layout.locale]: localeVersion },
|
|
275
|
+
};
|
|
276
|
+
let content;
|
|
277
|
+
if (complete || repaired) {
|
|
278
|
+
const full = parseFullContent(path, bytes);
|
|
279
|
+
if (full)
|
|
280
|
+
content = full;
|
|
281
|
+
const etag = etagFor(path, bytes, parsedMeta.contentStartPos);
|
|
282
|
+
if (etag)
|
|
283
|
+
localeVersion.etag = etag;
|
|
284
|
+
}
|
|
285
|
+
return { ok: true, manifest, locale: layout.locale, localeVersion, content, repaired };
|
|
286
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Blocks } from './blocks';
|
|
2
|
+
import type { ContentAPI } from './content-api.interface';
|
|
3
|
+
import { Data } from './data';
|
|
4
|
+
import { Site } from './site';
|
|
5
|
+
import type { BatchResult, ContentEntry, ContentManifest, CreateContentInput, CreateResult, DeleteLocaleInput, DeleteResult, FindOptions, GlobalFilters, LocalizedEntry, SitesConfig, UpdateLocaleInput, UpdateResult } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* In-memory implementation of ContentAPI for testing
|
|
8
|
+
* Provides a clean, mock-free way to test the API without filesystem dependencies
|
|
9
|
+
*/
|
|
10
|
+
export declare class InMemoryContentAPI implements ContentAPI {
|
|
11
|
+
private contentIndex;
|
|
12
|
+
readonly sitesConfig: SitesConfig;
|
|
13
|
+
readonly blocks: Blocks;
|
|
14
|
+
readonly data: Data;
|
|
15
|
+
private readonly sites;
|
|
16
|
+
constructor(sitesConfig?: SitesConfig);
|
|
17
|
+
getContent(id: string): Promise<ContentEntry | null>;
|
|
18
|
+
getLocalized(id: string, locale: string): Promise<LocalizedEntry | null>;
|
|
19
|
+
createContent(data: CreateContentInput): Promise<CreateResult>;
|
|
20
|
+
updateLocalized(input: UpdateLocaleInput): Promise<UpdateResult>;
|
|
21
|
+
deleteContent(id: string, etag: string): Promise<DeleteResult>;
|
|
22
|
+
getSite(siteName: string): Site | null;
|
|
23
|
+
listAllContent(filters?: GlobalFilters): Generator<ContentManifest>;
|
|
24
|
+
findUntranslatedContent(targetLocale: string, options?: FindOptions): Generator<ContentManifest>;
|
|
25
|
+
deleteLocalized(input: DeleteLocaleInput): Promise<DeleteResult>;
|
|
26
|
+
batchUpdate(operations: UpdateLocaleInput[]): Promise<BatchResult>;
|
|
27
|
+
setContent(id: string, content: ContentEntry): void;
|
|
28
|
+
clear(): void;
|
|
29
|
+
getContentAsBuffer(id: string, locale: string): Promise<{
|
|
30
|
+
buffer: Uint8Array;
|
|
31
|
+
etag: string;
|
|
32
|
+
contentType: 'application/json' | 'text/mdx';
|
|
33
|
+
} | null>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=in-memory-content-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-content-api.d.ts","sourceRoot":"","sources":["../src/in-memory-content-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAc1D,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,KAAK,EACV,WAAW,EAEX,YAAY,EACZ,eAAe,EAEf,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,aAAa,EAEb,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,YAAY,EAEb,MAAM,SAAS,CAAC;AAGjB;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,UAAU;IACnD,OAAO,CAAC,YAAY,CAAe;IACnC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuB;IAE7C,YAAY,WAAW,CAAC,EAAE,WAAW,EAuBpC;IAGK,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAkCzD;IAEK,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CA8B7E;IAEK,aAAa,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CA0HnE;IAEK,eAAe,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAyLrE;IAEK,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAkCnE;IAGD,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAOrC;IAGA,cAAc,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC,eAAe,CAAC,CAEnE;IAEA,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC,eAAe,CAAC,CAGhG;IAEK,eAAe,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAkDrE;IAEK,WAAW,CAAC,UAAU,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAgCvE;IAGD,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CA4ClD;IAGD,KAAK,IAAI,IAAI,CAEZ;IAEK,kBAAkB,CACtB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;QACT,MAAM,EAAE,UAAU,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,kBAAkB,GAAG,UAAU,CAAC;KAC9C,GAAG,IAAI,CAAC,CAwER;CACF"}
|