@jini-ai/agent-plugins 0.7.3-next.1 → 0.7.3-next.3
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/CHANGELOG.md +2 -0
- package/README.md +22 -4
- package/calendly/README.md +29 -0
- package/calendly/mcp.json +1 -1
- package/cloudflare/lib/assets.mjs +1 -1
- package/cloudflare/lib/cms-forms.mjs +1 -1
- package/core/persistent-state.d.ts +4 -1
- package/core/persistent-state.js +55 -21
- package/dist/admin-surfaces/callback-field-inbox.d.ts +1 -6
- package/dist/admin-surfaces/connections/connections.d.ts +2 -6
- package/dist/admin-surfaces/connections/index.d.ts +3 -2
- package/dist/admin-surfaces/index.d.ts +3 -1
- package/dist/connect/access-token-tool.d.ts +1 -1
- package/dist/connect/access-token-tool.js +1 -1
- package/dist/connect/catalog.d.ts +26 -0
- package/dist/connect/catalog.js +42 -0
- package/dist/connect/connect-tool.d.ts +2 -294
- package/dist/connect/connect-tool.js +2 -53
- package/dist/connect/contracts.d.ts +257 -0
- package/dist/connect/contracts.js +2 -0
- package/dist/connect/credential-cards.d.ts +2 -0
- package/dist/connect/credential-cards.js +7 -4
- package/dist/connect/grant-signed-in-defaults.js +1 -1
- package/dist/connect/host-deps.d.ts +32 -0
- package/dist/connect/host-deps.js +35 -0
- package/dist/connect/import-access-token.js +1 -1
- package/dist/connect/index.d.ts +7 -2
- package/dist/connect/index.js +5 -2
- package/dist/connect/installed-plugin.d.ts +28 -0
- package/dist/connect/installed-plugin.js +19 -0
- package/dist/connect/new-site-agent-plugin-tokens.d.ts +88 -0
- package/dist/connect/new-site-agent-plugin-tokens.js +107 -0
- package/dist/connect/plugin-host/index.d.ts +2 -2
- package/dist/connect/plugin-host/index.js +19 -10
- package/dist/connect/token-sign-in.d.ts +1 -14
- package/dist/connect/token-sign-in.js +4 -23
- package/dist/core/export-props.d.ts +10 -0
- package/dist/core/export-props.js +31 -0
- package/dist/core/folder-zip-error.d.ts +5 -0
- package/dist/core/folder-zip-error.js +8 -0
- package/dist/core/host-incompatible-error.d.ts +8 -0
- package/dist/core/host-incompatible-error.js +9 -0
- package/dist/core/identity-namespace.d.ts +27 -16
- package/dist/core/identity-namespace.js +25 -22
- package/dist/core/plugin-display-name.d.ts +7 -0
- package/dist/core/plugin-display-name.js +11 -0
- package/dist/core/provider-plugin-link.d.ts +7 -0
- package/dist/core/provider-plugin-link.js +5 -0
- package/dist/{connect → core}/token-map.d.ts +11 -1
- package/dist/{connect → core}/token-map.js +15 -0
- package/dist/core/token-sign-in-list.d.ts +18 -0
- package/dist/core/token-sign-in-list.js +23 -0
- package/dist/core/update-error.d.ts +8 -0
- package/dist/core/update-error.js +9 -0
- package/dist/{lifecycle → core}/update-plan.d.ts +1 -1
- package/dist/ffmpeg-transcode/adapter.d.ts +74 -0
- package/dist/ffmpeg-transcode/adapter.js +155 -0
- package/dist/folder-zip-node.d.ts +2 -1
- package/dist/folder-zip-node.js +6 -5
- package/dist/folder-zip.d.ts +0 -4
- package/dist/folder-zip.js +1 -7
- package/dist/index.d.ts +3 -1
- package/dist/lifecycle/activation.d.ts +39 -3
- package/dist/lifecycle/activation.js +467 -418
- package/dist/lifecycle/automatic-use-offer.d.ts +62 -0
- package/dist/lifecycle/automatic-use-offer.js +52 -0
- package/dist/lifecycle/automatic-use.d.ts +33 -1
- package/dist/lifecycle/automatic-use.js +157 -38
- package/dist/lifecycle/bundled-source-archive.d.ts +1 -1
- package/dist/lifecycle/capability-projection.d.ts +0 -1
- package/dist/lifecycle/capability-projection.js +92 -23
- package/dist/lifecycle/compatibility-metadata.d.ts +1 -0
- package/dist/lifecycle/compatibility-metadata.js +6 -1
- package/dist/lifecycle/compatibility.d.ts +1 -8
- package/dist/lifecycle/compatibility.js +1 -8
- package/dist/lifecycle/credential-card-metadata.d.ts +2 -2
- package/dist/lifecycle/exports.d.ts +2 -45
- package/dist/lifecycle/exports.js +1 -30
- package/dist/lifecycle/host-tools/identity.d.ts +5 -4
- package/dist/lifecycle/host-tools/identity.js +5 -5
- package/dist/lifecycle/host-tools/ports.d.ts +10 -1
- package/dist/lifecycle/host-tools/search-tool.d.ts +4 -2
- package/dist/lifecycle/host-tools/search-tool.js +19 -8
- package/dist/lifecycle/host-tools/skill-tool.js +1 -1
- package/dist/lifecycle/index.d.ts +20 -17
- package/dist/lifecycle/index.js +5 -4
- package/dist/lifecycle/install-from-url.d.ts +1 -2
- package/dist/lifecycle/install.d.ts +4 -34
- package/dist/lifecycle/install.js +3 -3
- package/dist/lifecycle/installed-package-index.d.ts +1 -1
- package/dist/lifecycle/installed-package-index.js +4 -4
- package/dist/lifecycle/layout.d.ts +21 -25
- package/dist/lifecycle/layout.js +79 -0
- package/dist/lifecycle/manifest.d.ts +10 -7
- package/dist/lifecycle/manifest.js +20 -15
- package/dist/lifecycle/mcp-provisioning.d.ts +1 -1
- package/dist/lifecycle/metadata.d.ts +6 -3
- package/dist/lifecycle/metadata.js +2 -1
- package/dist/lifecycle/package-paths.js +59 -56
- package/dist/lifecycle/persistent-state.d.ts +10 -1
- package/dist/lifecycle/persistent-state.js +4 -2
- package/dist/lifecycle/ports.d.ts +18 -6
- package/dist/lifecycle/resolve-agent-plugin-refs.d.ts +2 -14
- package/dist/lifecycle/retire-bundled.d.ts +1 -1
- package/dist/lifecycle/search-projection.d.ts +3 -1
- package/dist/lifecycle/search-projection.js +7 -3
- package/dist/lifecycle/search.d.ts +1 -0
- package/dist/lifecycle/seed-bundled.d.ts +86 -1
- package/dist/lifecycle/seed-bundled.js +48 -84
- package/dist/lifecycle/set-enabled.d.ts +1 -13
- package/dist/lifecycle/set-enabled.js +11 -7
- package/dist/lifecycle/trusted-plugin-files.d.ts +1 -1
- package/dist/lifecycle/trusted-plugin-files.js +33 -30
- package/dist/lifecycle/types.d.ts +13 -34
- package/dist/lifecycle/uninstall.d.ts +1 -33
- package/dist/lifecycle/update-store.d.ts +0 -7
- package/dist/lifecycle/update-store.js +1 -8
- package/dist/lifecycle/update.d.ts +1 -1
- package/dist/lifecycle/update.js +60 -10
- package/dist/lifecycle/yauzl-archive-reader.d.ts +7 -2
- package/dist/lifecycle/yauzl-archive-reader.js +11 -6
- package/dist/manifest.d.ts +4 -8
- package/dist/react/AgentPluginDetailsModal.d.ts +187 -0
- package/dist/react/AgentPluginDetailsModal.js +29 -0
- package/dist/react/agent-plugin-install-port.d.ts +24 -0
- package/dist/react/agent-plugin-install-port.js +15 -0
- package/dist/react/installed-skills-composer-source.d.ts +60 -0
- package/dist/react/installed-skills-composer-source.js +111 -0
- package/dist/react/use-agent-plugins.hooks.d.ts +211 -0
- package/dist/react/use-agent-plugins.hooks.js +128 -0
- package/dist/site/activation-effects.d.ts +17 -0
- package/dist/site/activation-effects.js +31 -0
- package/dist/site/admin-surfaces/capabilities.d.ts +29 -0
- package/dist/site/admin-surfaces/capabilities.js +30 -0
- package/dist/site/admin-surfaces/delivery-bindings.d.ts +81 -0
- package/dist/site/admin-surfaces/delivery-bindings.js +161 -0
- package/dist/site/admin-surfaces/forms.d.ts +28 -0
- package/dist/site/admin-surfaces/forms.js +29 -0
- package/dist/site/admin-surfaces/handlers.d.ts +61 -0
- package/dist/site/admin-surfaces/handlers.js +35 -0
- package/dist/site/admin-surfaces/public-config.d.ts +12 -0
- package/dist/site/admin-surfaces/public-config.js +28 -0
- package/dist/site/analytics-provider-registry.d.ts +87 -0
- package/dist/site/analytics-provider-registry.js +87 -0
- package/dist/site/archive-reader-abi.d.ts +35 -0
- package/dist/site/archive-reader-abi.js +25 -0
- package/dist/site/auth-schemes.d.ts +110 -0
- package/dist/site/auth-schemes.js +119 -0
- package/dist/site/automatic-agent-plugins.d.ts +200 -0
- package/dist/site/automatic-agent-plugins.js +277 -0
- package/dist/site/bundled-contribution-sources.d.ts +24 -0
- package/dist/site/bundled-contribution-sources.js +17 -0
- package/dist/site/bundled-id-upgrade.d.ts +115 -0
- package/dist/site/bundled-id-upgrade.js +169 -0
- package/dist/site/customize-tool.d.ts +39 -0
- package/dist/site/customize-tool.js +31 -0
- package/dist/site/deploy-split-activation.d.ts +28 -0
- package/dist/site/deploy-split-activation.js +21 -0
- package/dist/site/exports/diagnostics.d.ts +37 -0
- package/dist/site/exports/diagnostics.js +55 -0
- package/dist/site/exports/runtime.d.ts +54 -0
- package/dist/site/exports/runtime.js +196 -0
- package/dist/site/exports/source.d.ts +42 -0
- package/dist/site/exports/source.js +58 -0
- package/dist/site/host-plugin-guidance.d.ts +137 -0
- package/dist/site/host-plugin-guidance.js +223 -0
- package/dist/site/host-signals.d.ts +78 -0
- package/dist/site/host-signals.js +83 -0
- package/dist/site/install-tool.d.ts +69 -0
- package/dist/site/install-tool.js +192 -0
- package/dist/site/install-upload.d.ts +175 -0
- package/dist/site/install-upload.js +324 -0
- package/dist/site/memory-i18n.d.ts +5 -0
- package/dist/site/memory-i18n.js +176 -0
- package/dist/site/memory.d.ts +80 -0
- package/dist/site/memory.js +83 -0
- package/dist/site/plugin-memory.d.ts +80 -0
- package/dist/site/plugin-memory.js +86 -0
- package/dist/site/provider-plugin-link.d.ts +112 -0
- package/dist/site/provider-plugin-link.js +100 -0
- package/dist/site/retired-plugin-tool-aliases.d.ts +40 -0
- package/dist/site/retired-plugin-tool-aliases.js +41 -0
- package/dist/site/service-ports.d.ts +108 -0
- package/dist/site/service-ports.js +2 -0
- package/dist/site/set-enabled.d.ts +80 -0
- package/dist/site/set-enabled.js +42 -0
- package/dist/site/soon-lock.d.ts +83 -0
- package/dist/site/soon-lock.js +78 -0
- package/dist/site/supersession.d.ts +61 -0
- package/dist/site/supersession.js +122 -0
- package/dist/site/uninstall-tool.d.ts +136 -0
- package/dist/site/uninstall-tool.js +203 -0
- package/dist/site/update-effects.d.ts +47 -0
- package/dist/site/update-effects.js +49 -0
- package/ffmpeg-transcode/plugin.json +16 -0
- package/github/source-control/backup-push.mjs +66 -46
- package/github/source-control/commit-site.mjs +124 -67
- package/github/source-control/write-files.mjs +86 -53
- package/github-pages/targets/github-pages.mjs +294 -233
- package/google-workspace/form-destinations/mapping.mjs +15 -7
- package/google-workspace/form-destinations/sheets.mjs +4 -2
- package/google-workspace/plugin.json +1 -0
- package/kuinetic/CHANGELOG.md +4 -0
- package/kuinetic/plugin.json +4 -1
- package/kuinetic/skills/kuinetic/SKILL.md +1 -2
- package/package.json +297 -20
- package/persistent-state.d.ts +4 -1
- package/resend/adapters/resend.mjs +5 -2
- package/resend/plugin.json +1 -1
- package/s3-compatible/jini-deploy-targets.json +1 -1
- package/s3-compatible/object-stores/s3-compatible.mjs +27 -4
- package/s3-compatible/targets/s3-compatible.mjs +3 -3
- package/site-import/plugin.json +3 -3
- package/site-import/skills/site-import/SKILL.md +62 -54
- package/site-import/skills/site-import/references/content-mapping.md +26 -20
- package/slide-design/plugin.json +1 -1
- package/slide-design/skills/slide-design/SKILL.md +8 -2
- package/ui-ux-design/CHANGELOG.md +6 -0
- package/ui-ux-design/plugin.json +1 -1
- package/ui-ux-design/skills/gstack-design/SKILL.md +6 -6
- package/ui-ux-design/skills/ui-ux-design/SKILL.md +3 -2
- package/ui-ux-design/skills/ui-ux-design/references/chrome-mobile-test-matrix.md +14 -12
- package/ui-ux-design/skills/ui-ux-design/references/ui-loop.md +16 -17
- package/vercel/NOTES.md +2 -1
- package/vercel/object-stores/vercel-blob.mjs +3 -4
- package/vercel/targets/vercel.mjs +425 -351
- package/core/commerce-server.d.ts +0 -2
- package/core/commerce-server.mjs +0 -2
- package/dist/admin-surfaces/connections/ports.d.ts +0 -110
- package/dist/admin-surfaces/connections/ports.js +0 -2
- /package/dist/{lifecycle → core}/install-errors.d.ts +0 -0
- /package/dist/{lifecycle → core}/install-errors.js +0 -0
- /package/dist/{lifecycle → core}/update-plan.js +0 -0
|
@@ -72,12 +72,59 @@ function isGitHubTimeout({ err }, _options = {}) {
|
|
|
72
72
|
return err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError");
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
/** @param {Response} response @returns {Promise<{ ok: true, json: Record<string, any> } | { ok: false, message: string }>} */
|
|
76
|
+
async function readJsonBody(response) {
|
|
77
|
+
try {
|
|
78
|
+
const json = await response.json();
|
|
79
|
+
// `null`, an array or a scalar is valid JSON but carries none of the fields callers read:
|
|
80
|
+
// treat it as an empty object so each caller's own missing-field handling applies.
|
|
81
|
+
return { ok: true, json: json !== null && typeof json === "object" && !Array.isArray(json) ? json : {} };
|
|
82
|
+
} catch {
|
|
83
|
+
return { ok: false, message: "GitHub returned a non-JSON response." };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** @param {Response} response @param {string} fallback */
|
|
88
|
+
async function providerErrorMessage(response, fallback) {
|
|
89
|
+
const body = await readJsonBody(response);
|
|
90
|
+
if (body.ok && typeof body.json.message === "string" && body.json.message.trim() !== "") return body.json.message;
|
|
91
|
+
return `${fallback} (${response.status}).`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @param {{ kind: "network-unreachable" | "provider-rejected", message: string }} result @returns {StepFailure} */
|
|
95
|
+
function nonResponseFailure(result) {
|
|
96
|
+
return { ok: false, code: result.kind === "network-unreachable" ? "network-unreachable" : PROVIDER_ERROR, message: result.message };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Prefix payloads once and reserve the local ownership manifest before any provider I/O.
|
|
100
|
+
* @param {{ kit: Kit, input: { folder?: string, previousManagedManifestPath?: string, files: readonly CommitFile[] } }} required
|
|
101
|
+
* @complexity O(file count + path bytes), no effects.
|
|
79
102
|
*/
|
|
80
|
-
|
|
103
|
+
function prepareCommitScope({ input, kit }, _options = {}) {
|
|
104
|
+
try {
|
|
105
|
+
const folder = kit.repositoryPaths.normalizeFolder({ folder: input.folder });
|
|
106
|
+
const manifestPath = kit.repositoryPaths.prefixPath({ folder, path: MANAGED_MANIFEST_PATH });
|
|
107
|
+
const previousManagedManifestPath = input.previousManagedManifestPath ? kit.repositoryPaths.prefixPath({ folder, path: input.previousManagedManifestPath }) : undefined;
|
|
108
|
+
const files = input.files.map(file => ({ ...file, path: kit.repositoryPaths.prefixPath({ folder, path: file.path }) }));
|
|
109
|
+
if (files.some(file => file.path === manifestPath || file.path === previousManagedManifestPath)) return { ok: false, code: PROVIDER_ERROR, message: "Export cannot overwrite the managed manifest." };
|
|
110
|
+
return { ok: true, folder, manifestPath, previousManagedManifestPath, files };
|
|
111
|
+
} catch {
|
|
112
|
+
return { ok: false, code: PROVIDER_ERROR, message: "Invalid target folder or repository file path." };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** @param {{ input: { branch?: string }, defaultBranch: string }} required */
|
|
117
|
+
function siteCommitBranch({ input, defaultBranch }, _options = {}) {
|
|
118
|
+
return input.branch ?? defaultBranch;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** @param {{ baseTreeSha: string | undefined, treeSha: string }} required */
|
|
122
|
+
function unchangedSiteTree({ baseTreeSha, treeSha }, _options = {}) {
|
|
123
|
+
return baseTreeSha !== undefined && baseTreeSha === treeSha;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** @param {Kit} kit */
|
|
127
|
+
function createSiteCommitTransport(kit) {
|
|
81
128
|
/**
|
|
82
129
|
* One request, classified before any status interpretation.
|
|
83
130
|
* @param {string} url @param {RequestInit} init
|
|
@@ -99,27 +146,6 @@ export function createSiteCommitter(kit, _optional = {}) {
|
|
|
99
146
|
}
|
|
100
147
|
}
|
|
101
148
|
|
|
102
|
-
/** @param {Response} response @returns {Promise<{ ok: true, json: Record<string, any> } | { ok: false, message: string }>} */
|
|
103
|
-
async function readJsonBody(response) {
|
|
104
|
-
try {
|
|
105
|
-
return { ok: true, json: /** @type {Record<string, any>} */ (await response.json()) };
|
|
106
|
-
} catch {
|
|
107
|
-
return { ok: false, message: "GitHub returned a non-JSON response." };
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** @param {Response} response @param {string} fallback */
|
|
112
|
-
async function providerErrorMessage(response, fallback) {
|
|
113
|
-
const body = await readJsonBody(response);
|
|
114
|
-
if (body.ok && typeof body.json.message === "string" && body.json.message.trim() !== "") return body.json.message;
|
|
115
|
-
return `${fallback} (${response.status}).`;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** @param {{ kind: "network-unreachable" | "provider-rejected", message: string }} result @returns {StepFailure} */
|
|
119
|
-
function nonResponseFailure(result) {
|
|
120
|
-
return { ok: false, code: result.kind === "network-unreachable" ? "network-unreachable" : PROVIDER_ERROR, message: result.message };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
149
|
/** POSTs JSON and reads back `sha`. @param {string} url @param {unknown} body @param {string} what
|
|
124
150
|
* @returns {Promise<{ ok: true, sha: string } | StepFailure>} */
|
|
125
151
|
async function postForSha(url, body, what, token) {
|
|
@@ -134,6 +160,11 @@ export function createSiteCommitter(kit, _optional = {}) {
|
|
|
134
160
|
return { ok: true, sha };
|
|
135
161
|
}
|
|
136
162
|
|
|
163
|
+
return { githubFetch, postForSha };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** @param {ReturnType<typeof createSiteCommitTransport>["githubFetch"]} githubFetch */
|
|
167
|
+
function createCommitRepositoryReads(githubFetch) {
|
|
137
168
|
/** @param {string} token @param {string} owner @param {string} repo */
|
|
138
169
|
async function fetchRepo(token, owner, repo) {
|
|
139
170
|
const result = await githubFetch(`${GITHUB_API}/repos/${enc(owner)}/${enc(repo)}`, { headers: githubHeaders(token) });
|
|
@@ -181,10 +212,23 @@ export function createSiteCommitter(kit, _optional = {}) {
|
|
|
181
212
|
return { ok: true, treeSha: sha };
|
|
182
213
|
}
|
|
183
214
|
|
|
215
|
+
return { fetchRepo, fetchBranchTip, fetchParentTree };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** @param {{ kit: Kit, githubFetch: ReturnType<typeof createSiteCommitTransport>["githubFetch"] }} required */
|
|
219
|
+
function createManagedManifestReads({ kit, githubFetch }) {
|
|
220
|
+
async function fetchManagedManifestResponse({ token, owner, repo, branch, scope }) {
|
|
221
|
+
const result = await githubFetch(`${GITHUB_API}/repos/${enc(owner)}/${enc(repo)}/contents/${encPath(scope.manifestPath)}?ref=${enc(branch)}`, { headers: githubHeaders(token) });
|
|
222
|
+
if (result.kind === "response" && result.response.status === 404 && scope.previousManagedManifestPath) {
|
|
223
|
+
return githubFetch(`${GITHUB_API}/repos/${enc(owner)}/${enc(repo)}/contents/${encPath(scope.previousManagedManifestPath)}?ref=${enc(branch)}`, { headers: githubHeaders(token) });
|
|
224
|
+
}
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
|
|
184
228
|
/** @param {string} token @param {string} owner @param {string} repo @param {string} branch
|
|
185
229
|
* @returns {Promise<{ ok: true, files: readonly PreviouslyManagedFile[] } | StepFailure>} */
|
|
186
230
|
async function fetchManagedManifest(token, owner, repo, branch, scope) {
|
|
187
|
-
const result = await
|
|
231
|
+
const result = await fetchManagedManifestResponse({ token, owner, repo, branch, scope });
|
|
188
232
|
if (result.kind !== "response") return nonResponseFailure(result);
|
|
189
233
|
const { response } = result;
|
|
190
234
|
if (response.status === 404) return { ok: true, files: [] }; // verified: no manifest yet — safe, not "unreadable"
|
|
@@ -226,6 +270,29 @@ export function createSiteCommitter(kit, _optional = {}) {
|
|
|
226
270
|
return typeof body.json.sha === "string" ? { kind: "found", sha: body.json.sha } : { kind: "unverifiable" };
|
|
227
271
|
}
|
|
228
272
|
|
|
273
|
+
return { fetchManagedManifest, fetchLiveBlobSha };
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** @param {Pick<ReturnType<typeof createCommitRepositoryReads>, "fetchParentTree"> & Pick<ReturnType<typeof createManagedManifestReads>, "fetchManagedManifest">} required */
|
|
277
|
+
function createCommitPrerequisiteReader({ fetchParentTree, fetchManagedManifest }) {
|
|
278
|
+
/** A new branch has no parent, no base tree and no manifest. @param {string} token @param {string} owner
|
|
279
|
+
* @param {string} repo @param {string} branch @param {string | undefined} parentSha */
|
|
280
|
+
async function resolveCommitPrerequisites(token, owner, repo, branch, parentSha, scope) {
|
|
281
|
+
if (parentSha === undefined) return /** @type {const} */ ({ ok: true, baseTreeSha: undefined, previousManagedFiles: undefined, parents: [], readRef: branch });
|
|
282
|
+
|
|
283
|
+
const parentTreeResult = await fetchParentTree(token, owner, repo, parentSha);
|
|
284
|
+
if (!parentTreeResult.ok) return parentTreeResult;
|
|
285
|
+
const readRef = scope.previousManagedManifestPath ? parentSha : branch;
|
|
286
|
+
const manifestResult = await fetchManagedManifest(token, owner, repo, readRef, scope);
|
|
287
|
+
if (!manifestResult.ok) return manifestResult;
|
|
288
|
+
return /** @type {const} */ ({ ok: true, baseTreeSha: parentTreeResult.treeSha, previousManagedFiles: manifestResult.files, parents: [parentSha], readRef });
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return resolveCommitPrerequisites;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** @param {Pick<ReturnType<typeof createSiteCommitTransport>, "postForSha"> & Pick<ReturnType<typeof createManagedManifestReads>, "fetchLiveBlobSha">} required */
|
|
295
|
+
function createManagedTreeEntries({ postForSha, fetchLiveBlobSha }) {
|
|
229
296
|
/** @param {string} token @param {string} owner @param {string} repo @param {string | Buffer} data */
|
|
230
297
|
function createBlob(token, owner, repo, data) {
|
|
231
298
|
return postForSha(`${GITHUB_API}/repos/${enc(owner)}/${enc(repo)}/git/blobs`, { content: Buffer.from(data).toString("base64"), encoding: "base64" }, "blob creation", token);
|
|
@@ -280,6 +347,13 @@ export function createSiteCommitter(kit, _optional = {}) {
|
|
|
280
347
|
return { deletions, deletedPaths, divergedPaths };
|
|
281
348
|
}
|
|
282
349
|
|
|
350
|
+
return { createBlob, buildFileTreeEntries, resolveDeletionCandidates };
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** @param {Pick<ReturnType<typeof createSiteCommitTransport>, "postForSha"> & Pick<ReturnType<typeof createManagedManifestReads>, "fetchLiveBlobSha">} required */
|
|
354
|
+
function createManagedTreeWriter({ postForSha, fetchLiveBlobSha }) {
|
|
355
|
+
const { createBlob, buildFileTreeEntries, resolveDeletionCandidates } = createManagedTreeEntries({ postForSha, fetchLiveBlobSha });
|
|
356
|
+
|
|
283
357
|
/** @param {string} token @param {string} owner @param {string} repo @param {string} branch
|
|
284
358
|
* @param {readonly CommitFile[]} files @param {string | undefined} baseTreeSha
|
|
285
359
|
* @param {readonly PreviouslyManagedFile[] | undefined} previousManagedFiles */
|
|
@@ -287,7 +361,7 @@ export function createSiteCommitter(kit, _optional = {}) {
|
|
|
287
361
|
const fileTree = await buildFileTreeEntries(token, owner, repo, files);
|
|
288
362
|
if (!fileTree.ok) return fileTree;
|
|
289
363
|
|
|
290
|
-
const candidates = (previousManagedFiles ?? []).filter((f) => !fileTree.currentPaths.has(f.path) && f.path !== scope.manifestPath);
|
|
364
|
+
const candidates = (previousManagedFiles ?? []).filter((f) => !fileTree.currentPaths.has(f.path) && f.path !== scope.manifestPath && f.path !== scope.previousManagedManifestPath);
|
|
291
365
|
const { deletions, deletedPaths, divergedPaths } = await resolveDeletionCandidates(token, owner, repo, branch, candidates);
|
|
292
366
|
|
|
293
367
|
const sortedFiles = fileTree.currentFileShas.slice().sort((a, b) => {
|
|
@@ -313,6 +387,11 @@ export function createSiteCommitter(kit, _optional = {}) {
|
|
|
313
387
|
return /** @type {const} */ ({ ok: true, sha: treeResult.sha, deletedPaths, divergedPaths });
|
|
314
388
|
}
|
|
315
389
|
|
|
390
|
+
return buildTree;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** @param {ReturnType<typeof createSiteCommitTransport>["githubFetch"]} githubFetch */
|
|
394
|
+
function createSiteRefWriter(githubFetch) {
|
|
316
395
|
/** @param {string} token @param {string} owner @param {string} repo @param {string} branch
|
|
317
396
|
* @param {string} sha @param {"create" | "update"} mode */
|
|
318
397
|
async function writeRef(token, owner, repo, branch, sha, mode) {
|
|
@@ -333,51 +412,29 @@ export function createSiteCommitter(kit, _optional = {}) {
|
|
|
333
412
|
return { ok: false, code: PROVIDER_ERROR, message: await providerErrorMessage(response, `GitHub branch ${mode} failed`) };
|
|
334
413
|
}
|
|
335
414
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
async function resolveCommitPrerequisites(token, owner, repo, branch, parentSha, scope) {
|
|
339
|
-
if (parentSha === undefined) return /** @type {const} */ ({ ok: true, baseTreeSha: undefined, previousManagedFiles: undefined, parents: [] });
|
|
340
|
-
|
|
341
|
-
const parentTreeResult = await fetchParentTree(token, owner, repo, parentSha);
|
|
342
|
-
if (!parentTreeResult.ok) return parentTreeResult;
|
|
343
|
-
const manifestResult = await fetchManagedManifest(token, owner, repo, branch, scope);
|
|
344
|
-
if (!manifestResult.ok) return manifestResult;
|
|
345
|
-
return /** @type {const} */ ({ ok: true, baseTreeSha: parentTreeResult.treeSha, previousManagedFiles: manifestResult.files, parents: [parentSha] });
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/** Prefix payloads once and reserve the local ownership manifest before any provider I/O.
|
|
349
|
-
* @param {{ input: { folder?: string, files: readonly CommitFile[] } }} required
|
|
350
|
-
* @complexity O(file count + path bytes), no effects.
|
|
351
|
-
*/
|
|
352
|
-
function prepareCommitScope({ input }, _options = {}) {
|
|
353
|
-
try {
|
|
354
|
-
const folder = kit.repositoryPaths.normalizeFolder({ folder: input.folder });
|
|
355
|
-
const manifestPath = kit.repositoryPaths.prefixPath({ folder, path: MANAGED_MANIFEST_PATH });
|
|
356
|
-
const files = input.files.map(file => ({ ...file, path: kit.repositoryPaths.prefixPath({ folder, path: file.path }) }));
|
|
357
|
-
if (files.some(file => file.path === manifestPath)) return { ok: false, code: PROVIDER_ERROR, message: "Export cannot overwrite the managed manifest." };
|
|
358
|
-
return { ok: true, folder, manifestPath, files };
|
|
359
|
-
} catch {
|
|
360
|
-
return { ok: false, code: PROVIDER_ERROR, message: "Invalid target folder or repository file path." };
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/** @param {{ input: { branch?: string }, defaultBranch: string }} required */
|
|
365
|
-
function siteCommitBranch({ input, defaultBranch }, _options = {}) {
|
|
366
|
-
return input.branch ?? defaultBranch;
|
|
367
|
-
}
|
|
415
|
+
return writeRef;
|
|
416
|
+
}
|
|
368
417
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
418
|
+
/**
|
|
419
|
+
* The commit operation, bound to one kit.
|
|
420
|
+
*
|
|
421
|
+
* @param {Kit} kit
|
|
422
|
+
*/
|
|
423
|
+
export function createSiteCommitter(kit, _optional = {}) {
|
|
424
|
+
const { githubFetch, postForSha } = createSiteCommitTransport(kit);
|
|
425
|
+
const { fetchRepo, fetchBranchTip, fetchParentTree } = createCommitRepositoryReads(githubFetch);
|
|
426
|
+
const { fetchManagedManifest, fetchLiveBlobSha } = createManagedManifestReads({ kit, githubFetch });
|
|
427
|
+
const resolveCommitPrerequisites = createCommitPrerequisiteReader({ fetchParentTree, fetchManagedManifest });
|
|
428
|
+
const buildTree = createManagedTreeWriter({ postForSha, fetchLiveBlobSha });
|
|
429
|
+
const writeRef = createSiteRefWriter(githubFetch);
|
|
373
430
|
|
|
374
431
|
/**
|
|
375
|
-
* @param {{ token: string, owner: string, repo: string, branch?: string, commitMessage: string, folder?: string, files: readonly CommitFile[] }} input
|
|
432
|
+
* @param {{ token: string, owner: string, repo: string, branch?: string, commitMessage: string, folder?: string, previousManagedManifestPath?: string, files: readonly CommitFile[] }} input
|
|
376
433
|
* @complexity O(f) requests in the file count, plus one per path a previous export owned and dropped.
|
|
377
434
|
*/
|
|
378
435
|
return async function commitSite(input) {
|
|
379
436
|
const { token, owner, repo, commitMessage } = input;
|
|
380
|
-
const scope = prepareCommitScope({ input });
|
|
437
|
+
const scope = prepareCommitScope({ input, kit });
|
|
381
438
|
if (!scope.ok) return scope;
|
|
382
439
|
const files = scope.files;
|
|
383
440
|
|
|
@@ -393,7 +450,7 @@ export function createSiteCommitter(kit, _optional = {}) {
|
|
|
393
450
|
const prereqs = await resolveCommitPrerequisites(token, owner, repo, branch, parentSha, scope);
|
|
394
451
|
if (!prereqs.ok) return prereqs;
|
|
395
452
|
|
|
396
|
-
const treeResult = await buildTree(token, owner, repo,
|
|
453
|
+
const treeResult = await buildTree(token, owner, repo, prereqs.readRef, files, prereqs.baseTreeSha, prereqs.previousManagedFiles, scope);
|
|
397
454
|
if (!treeResult.ok) return treeResult;
|
|
398
455
|
|
|
399
456
|
if (unchangedSiteTree({ baseTreeSha: prereqs.baseTreeSha, treeSha: treeResult.sha })) {
|
|
@@ -33,20 +33,20 @@ const GITHUB_WRITE_FILES_TIMEOUT_MS = 30_000;
|
|
|
33
33
|
const CONTENTS_API_DIRECTORY_LISTING_CAP = 1000;
|
|
34
34
|
const GITHUB_UNREACHABLE_MESSAGE = "GitHub could not be reached: the request failed before any response arrived (a network error or timeout).";
|
|
35
35
|
|
|
36
|
-
/** @param {string}
|
|
37
|
-
export function enc(value) {
|
|
36
|
+
/** @param {{ value: string }} required */
|
|
37
|
+
export function enc({ value }, _optional = {}) {
|
|
38
38
|
return encodeURIComponent(value);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/** @param {{ path: string }} required */
|
|
42
42
|
export function encPath({ path }, _optional = {}) {
|
|
43
|
-
return path.split("/").map(enc).join("/");
|
|
43
|
+
return path.split("/").map(value => enc({ value })).join("/");
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/** `<baseUrl>/repos/<owner>/<repo>`. @param {Target} target */
|
|
47
47
|
export function repoPathOf(target, _optional = {}) {
|
|
48
48
|
const base = target.baseUrl.endsWith("/") ? target.baseUrl.slice(0, -1) : target.baseUrl;
|
|
49
|
-
return `${base}/repos/${enc(target.owner)}/${enc(target.repo)}`;
|
|
49
|
+
return `${base}/repos/${enc({ value: target.owner })}/${enc({ value: target.repo })}`;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/** @param {HttpResponse} response */
|
|
@@ -145,17 +145,8 @@ export function retryDelayMs({ result, attempt, policy }, _optional = {}) {
|
|
|
145
145
|
* `maxWaitMs` caps one wait: GitHub asking for longer (an hourly limit) is reported, not slept on.
|
|
146
146
|
*/
|
|
147
147
|
|
|
148
|
-
/**
|
|
149
|
-
|
|
150
|
-
*
|
|
151
|
-
* @param {Kit} kit
|
|
152
|
-
* @param {{ timeoutMs?: number, retry?: RetryPolicy }} [options] - `timeoutMs` is each request's
|
|
153
|
-
* socket-idle budget (the egress policy may cap it lower). `retry` re-sends a request that failed
|
|
154
|
-
* transiently ({@link retryDelayMs}); every GitHub Git Data write is safe to repeat (a blob or tree
|
|
155
|
-
* is addressed by its content, and a non-force ref update to the same commit is a no-op). Without
|
|
156
|
-
* it a request is sent once, as `custom_credential_write_files` always has.
|
|
157
|
-
*/
|
|
158
|
-
export function createGitDataClient(kit, options = {}) {
|
|
148
|
+
/** @param {Kit} kit @param {{ timeoutMs?: number, retry?: RetryPolicy }} options */
|
|
149
|
+
function createGitHubSender(kit, options) {
|
|
159
150
|
const timeoutMs = options.timeoutMs ?? GITHUB_WRITE_FILES_TIMEOUT_MS;
|
|
160
151
|
const sleep = kit.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
161
152
|
|
|
@@ -203,6 +194,11 @@ export function createGitDataClient(kit, options = {}) {
|
|
|
203
194
|
}
|
|
204
195
|
}
|
|
205
196
|
|
|
197
|
+
return send;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** @param {ReturnType<typeof createGitHubSender>} send */
|
|
201
|
+
function createGitHubJsonOperations(send) {
|
|
206
202
|
/** @param {{ message: string, logDetail: string }} result @returns {Failure} */
|
|
207
203
|
function nonResponseFailure(result) {
|
|
208
204
|
return { ok: false, code: "network-unreachable", message: result.message, logDetail: result.logDetail };
|
|
@@ -231,6 +227,23 @@ export function createGitDataClient(kit, options = {}) {
|
|
|
231
227
|
return { ok: true, json: parsed.json };
|
|
232
228
|
}
|
|
233
229
|
|
|
230
|
+
return { getJson, postJson, nonResponseFailure };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* The credentialed GitHub calls, bound to one kit.
|
|
235
|
+
*
|
|
236
|
+
* @param {Kit} kit
|
|
237
|
+
* @param {{ timeoutMs?: number, retry?: RetryPolicy }} [options] - `timeoutMs` is each request's
|
|
238
|
+
* socket-idle budget (the egress policy may cap it lower). `retry` re-sends a request that failed
|
|
239
|
+
* transiently ({@link retryDelayMs}); every GitHub Git Data write is safe to repeat (a blob or tree
|
|
240
|
+
* is addressed by its content, and a non-force ref update to the same commit is a no-op). Without
|
|
241
|
+
* it a request is sent once, as `custom_credential_write_files` always has.
|
|
242
|
+
*/
|
|
243
|
+
export function createGitDataClient(kit, options = {}) {
|
|
244
|
+
const send = createGitHubSender(kit, options);
|
|
245
|
+
const { getJson, postJson, nonResponseFailure } = createGitHubJsonOperations(send);
|
|
246
|
+
|
|
234
247
|
/** @param {Target} target @param {string | Uint8Array} content @returns {Promise<{ ok: true, sha: string } | Failure>} */
|
|
235
248
|
async function createBlob(target, content) {
|
|
236
249
|
const bytes = typeof content === "string" ? Buffer.from(content, "utf8") : Buffer.from(content.buffer, content.byteOffset, content.byteLength);
|
|
@@ -258,38 +271,49 @@ export function createGitDataClient(kit, options = {}) {
|
|
|
258
271
|
|
|
259
272
|
/** @typedef {ReturnType<typeof createGitDataClient>} GitDataClient */
|
|
260
273
|
|
|
261
|
-
/**
|
|
262
|
-
|
|
274
|
+
/** @param {string} path @param {unknown} entry */
|
|
275
|
+
function stateFromListingEntry(path, entry) {
|
|
276
|
+
if (entry === undefined) return { ok: true, state: { path, exists: false } };
|
|
277
|
+
if (!isRegularFileEntry(entry)) return notRegularFileFailure(path);
|
|
278
|
+
return { ok: true, state: { path, exists: true } };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** @param {{ files: readonly WriteFile[] }} required */
|
|
282
|
+
function groupWriteFilesByDirectory({ files }, _options = {}) {
|
|
283
|
+
/** @type {Map<string, WriteFile[]>} */
|
|
284
|
+
const filesByDir = new Map();
|
|
285
|
+
for (const file of files) {
|
|
286
|
+
const { dir } = splitRepoPath(file.path);
|
|
287
|
+
const bucket = filesByDir.get(dir);
|
|
288
|
+
if (bucket) bucket.push(file);
|
|
289
|
+
else filesByDir.set(dir, [file]);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return filesByDir;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** @param {{ entry: any }} required */
|
|
296
|
+
function isModeDirectory({ entry }, _options = {}) {
|
|
297
|
+
return entry.type === "tree" && typeof entry.sha === "string" && !!entry.sha;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** @param {{ entry: any, path: string }} required */
|
|
301
|
+
function modeFromBlobEntry({ entry, path }, _options = {}) {
|
|
302
|
+
if (entry.type !== "blob" || !["100644", "100755"].includes(entry.mode)) return notRegularFileFailure(path);
|
|
303
|
+
return { ok: true, mode: entry.mode };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** @param {GitDataClient} git */
|
|
307
|
+
function createDirectoryFileStateReader(git) {
|
|
263
308
|
/** @param {Target} target @param {string} branch @param {string} path */
|
|
264
309
|
async function checkOneFileExistence(target, branch, path) {
|
|
265
|
-
const result = await git.getJson(target, `${repoPathOf(target)}/contents/${encPath({ path })}?ref=${enc(branch)}`, `GitHub lookup of '${path}' failed`);
|
|
310
|
+
const result = await git.getJson(target, `${repoPathOf(target)}/contents/${encPath({ path })}?ref=${enc({ value: branch })}`, `GitHub lookup of '${path}' failed`);
|
|
266
311
|
if (!result.ok) return result;
|
|
267
312
|
if (!result.found) return { ok: true, state: { path, exists: false } };
|
|
268
313
|
if (Array.isArray(result.json) || result.json.type !== "file") return notRegularFileFailure(path);
|
|
269
314
|
return { ok: true, state: { path, exists: true } };
|
|
270
315
|
}
|
|
271
316
|
|
|
272
|
-
/** @param {string} path @param {unknown} entry */
|
|
273
|
-
function stateFromListingEntry(path, entry) {
|
|
274
|
-
if (entry === undefined) return { ok: true, state: { path, exists: false } };
|
|
275
|
-
if (!isRegularFileEntry(entry)) return notRegularFileFailure(path);
|
|
276
|
-
return { ok: true, state: { path, exists: true } };
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/** @param {{ files: readonly WriteFile[] }} required */
|
|
280
|
-
function groupWriteFilesByDirectory({ files }, _options = {}) {
|
|
281
|
-
/** @type {Map<string, WriteFile[]>} */
|
|
282
|
-
const filesByDir = new Map();
|
|
283
|
-
for (const file of files) {
|
|
284
|
-
const { dir } = splitRepoPath(file.path);
|
|
285
|
-
const bucket = filesByDir.get(dir);
|
|
286
|
-
if (bucket) bucket.push(file);
|
|
287
|
-
else filesByDir.set(dir, [file]);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return filesByDir;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
317
|
/** @param {{ target: Target, branch: string, dirFiles: WriteFile[], entries: any[], stateByPath: Map<string, { path: string, exists: boolean }> }} required */
|
|
294
318
|
async function resolveDirectoryFileStates({ target, branch, dirFiles, entries, stateByPath }, _options = {}) {
|
|
295
319
|
const entryByName = new Map(entries.map((entry) => [extractStringField({ value: entry, field: "name" }), entry]));
|
|
@@ -306,7 +330,7 @@ export function createFileWriter(git, _optional = {}) {
|
|
|
306
330
|
/** @param {{ target: Target, branch: string, dir: string, dirFiles: WriteFile[], stateByPath: Map<string, { path: string, exists: boolean }> }} required */
|
|
307
331
|
async function checkDirectoryFileExistence({ target, branch, dir, dirFiles, stateByPath }, _options = {}) {
|
|
308
332
|
const directoryPath = dir ? `/${encPath({ path: dir })}` : "";
|
|
309
|
-
const listUrl = `${repoPathOf(target)}/contents${directoryPath}?ref=${enc(branch)}`;
|
|
333
|
+
const listUrl = `${repoPathOf(target)}/contents${directoryPath}?ref=${enc({ value: branch })}`;
|
|
310
334
|
const listResult = await git.getJson(target, listUrl, `GitHub directory lookup of '${dir}' failed`);
|
|
311
335
|
if (!listResult.ok) return listResult;
|
|
312
336
|
if (!listResult.found) {
|
|
@@ -320,6 +344,13 @@ export function createFileWriter(git, _optional = {}) {
|
|
|
320
344
|
return resolveDirectoryFileStates({ target, branch, dirFiles, entries, stateByPath });
|
|
321
345
|
}
|
|
322
346
|
|
|
347
|
+
return checkDirectoryFileExistence;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** @param {GitDataClient} git */
|
|
351
|
+
function createFileWritePlanner(git) {
|
|
352
|
+
const checkDirectoryFileExistence = createDirectoryFileStateReader(git);
|
|
353
|
+
|
|
323
354
|
/** One directory listing per distinct parent directory, falling back to a per-file lookup only when
|
|
324
355
|
* a listing may be truncated. @param {Target} target @param {string} branch @param {readonly WriteFile[]} files */
|
|
325
356
|
async function checkFileExistence(target, branch, files) {
|
|
@@ -343,7 +374,7 @@ export function createFileWriter(git, _optional = {}) {
|
|
|
343
374
|
const parentCommitSha = extractStringField({ value: refJson.json.object, field: "sha" });
|
|
344
375
|
if (!parentCommitSha) return { ok: false, code: PROVIDER_ERROR, message: "GitHub branch lookup response did not include a sha" };
|
|
345
376
|
|
|
346
|
-
const commitJson = await git.getJson(input, `${repoPath}/git/commits/${enc(parentCommitSha)}`, "GitHub parent-commit lookup failed");
|
|
377
|
+
const commitJson = await git.getJson(input, `${repoPath}/git/commits/${enc({ value: parentCommitSha })}`, "GitHub parent-commit lookup failed");
|
|
347
378
|
if (!commitJson.ok) return commitJson;
|
|
348
379
|
if (!commitJson.found) return { ok: false, code: PROVIDER_ERROR, message: "GitHub parent-commit lookup returned 404 for a sha this call just resolved" };
|
|
349
380
|
const baseTreeSha = extractStringField({ value: commitJson.json.tree, field: "sha" });
|
|
@@ -354,11 +385,16 @@ export function createFileWriter(git, _optional = {}) {
|
|
|
354
385
|
return { ok: true, plan: { parentCommitSha, baseTreeSha, fileStates: existence.fileStates } };
|
|
355
386
|
}
|
|
356
387
|
|
|
388
|
+
return planFileWrite;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** @param {GitDataClient} git */
|
|
392
|
+
function createFileModeReader(git) {
|
|
357
393
|
/** @param {{ target: Target, treeSha: string, trees: Map<string, any[]> }} required */
|
|
358
394
|
async function readModeTree({ target, treeSha, trees }, _options = {}) {
|
|
359
395
|
let tree = trees.get(treeSha);
|
|
360
396
|
if (!tree) {
|
|
361
|
-
const result = await git.getJson(target, `${repoPathOf(target)}/git/trees/${enc(treeSha)}`, "GitHub file-mode lookup failed");
|
|
397
|
+
const result = await git.getJson(target, `${repoPathOf(target)}/git/trees/${enc({ value: treeSha })}`, "GitHub file-mode lookup failed");
|
|
362
398
|
if (!result.ok) return result;
|
|
363
399
|
if (!result.found || !Array.isArray(result.json.tree) || result.json.truncated === true) {
|
|
364
400
|
return { ok: false, code: PROVIDER_ERROR, message: "GitHub returned an incomplete tree — refusing to guess file modes" };
|
|
@@ -369,17 +405,6 @@ export function createFileWriter(git, _optional = {}) {
|
|
|
369
405
|
return { ok: true, tree };
|
|
370
406
|
}
|
|
371
407
|
|
|
372
|
-
/** @param {{ entry: any }} required */
|
|
373
|
-
function isModeDirectory({ entry }, _options = {}) {
|
|
374
|
-
return entry.type === "tree" && typeof entry.sha === "string" && !!entry.sha;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
/** @param {{ entry: any, path: string }} required */
|
|
378
|
-
function modeFromBlobEntry({ entry, path }, _options = {}) {
|
|
379
|
-
if (entry.type !== "blob" || !["100644", "100755"].includes(entry.mode)) return notRegularFileFailure(path);
|
|
380
|
-
return { ok: true, mode: entry.mode };
|
|
381
|
-
}
|
|
382
|
-
|
|
383
408
|
/** @param {{ target: Target, baseTreeSha: string, file: WriteFile, trees: Map<string, any[]> }} required */
|
|
384
409
|
async function readFileMode({ target, baseTreeSha, file, trees }, _options = {}) {
|
|
385
410
|
let treeSha = baseTreeSha;
|
|
@@ -412,6 +437,14 @@ export function createFileWriter(git, _optional = {}) {
|
|
|
412
437
|
return { ok: true, modes };
|
|
413
438
|
}
|
|
414
439
|
|
|
440
|
+
return readFileModes;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** The two write-files operations. @param {GitDataClient} git */
|
|
444
|
+
export function createFileWriter(git, _optional = {}) {
|
|
445
|
+
const planFileWrite = createFileWritePlanner(git);
|
|
446
|
+
const readFileModes = createFileModeReader(git);
|
|
447
|
+
|
|
415
448
|
/** @param {{ input: Target & { files: readonly WriteFile[] }, modes: Map<string, string> }} required */
|
|
416
449
|
async function buildWriteBlobEntries({ input, modes }, _options = {}) {
|
|
417
450
|
/** @type {Map<string, string>} */
|