@leed-ai/git-gateway-worker 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +49 -2
- package/dist/audit/audit-recorder.d.ts +2 -0
- package/dist/audit/audit-recorder.js +53 -0
- package/dist/audit/audit-recorder.js.map +1 -0
- package/dist/audit/push-report.d.ts +13 -0
- package/dist/audit/push-report.js +66 -0
- package/dist/audit/push-report.js.map +1 -0
- package/dist/audit-recorder-K1Ns3tfC.d.ts +31 -0
- package/dist/auth/authenticate.d.ts +14 -0
- package/dist/auth/authenticate.js +59 -0
- package/dist/auth/authenticate.js.map +1 -0
- package/dist/auth/authorize.d.ts +12 -0
- package/dist/auth/authorize.js +57 -0
- package/dist/auth/authorize.js.map +1 -0
- package/dist/auth/read-token-auth.d.ts +60 -0
- package/dist/auth/read-token-auth.js +83 -0
- package/dist/auth/read-token-auth.js.map +1 -0
- package/dist/cache/decision-cache.d.ts +2 -0
- package/dist/cache/decision-cache.js +45 -0
- package/dist/cache/decision-cache.js.map +1 -0
- package/dist/commit-workflow-schemas-BWlg7bZR.d.ts +95 -0
- package/dist/decision-cache-87U32iSj.d.ts +24 -0
- package/dist/gateway-app.d.ts +69 -0
- package/dist/gateway-app.js +80 -0
- package/dist/gateway-app.js.map +1 -0
- package/dist/gateway-context-Boh9I0mk.d.ts +54 -0
- package/dist/gateway-env-DnsBU4Pq.d.ts +40 -0
- package/dist/gateway-worker.d.ts +13 -0
- package/dist/gateway-worker.js +22 -0
- package/dist/gateway-worker.js.map +1 -0
- package/dist/git-route-Spxi09Rm.d.ts +22 -0
- package/dist/health.d.ts +6 -0
- package/dist/health.js +16 -0
- package/dist/health.js.map +1 -0
- package/dist/logger-BZ1zyKLb.d.ts +27 -0
- package/dist/logging/logger.d.ts +2 -0
- package/dist/logging/logger.js +15 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/on-push-DTREOB__.d.ts +62 -0
- package/dist/policy/branch-policy.d.ts +24 -0
- package/dist/policy/branch-policy.js +125 -0
- package/dist/policy/branch-policy.js.map +1 -0
- package/dist/policy/enforce-branch-policy.d.ts +30 -0
- package/dist/policy/enforce-branch-policy.js +214 -0
- package/dist/policy/enforce-branch-policy.js.map +1 -0
- package/dist/policy/fast-forward.d.ts +32 -0
- package/dist/policy/fast-forward.js +95 -0
- package/dist/policy/fast-forward.js.map +1 -0
- package/dist/policy/ref-pattern.d.ts +7 -0
- package/dist/policy/ref-pattern.js +25 -0
- package/dist/policy/ref-pattern.js.map +1 -0
- package/dist/policy/rule-branch-policy.d.ts +17 -0
- package/dist/policy/rule-branch-policy.js +69 -0
- package/dist/policy/rule-branch-policy.js.map +1 -0
- package/dist/proxy/defer.d.ts +8 -0
- package/dist/proxy/defer.js +15 -0
- package/dist/proxy/defer.js.map +1 -0
- package/dist/proxy/forward-read.d.ts +11 -0
- package/dist/proxy/forward-read.js +53 -0
- package/dist/proxy/forward-read.js.map +1 -0
- package/dist/proxy/gateway-deps.d.ts +39 -0
- package/dist/proxy/gateway-deps.js +0 -0
- package/dist/proxy/gateway-env.d.ts +2 -0
- package/dist/proxy/gateway-env.js +0 -0
- package/dist/proxy/git-responses.d.ts +25 -0
- package/dist/proxy/git-responses.js +83 -0
- package/dist/proxy/git-responses.js.map +1 -0
- package/dist/proxy/git-route.d.ts +2 -0
- package/dist/proxy/git-route.js +34 -0
- package/dist/proxy/git-route.js.map +1 -0
- package/dist/proxy/push-events.d.ts +28 -0
- package/dist/proxy/push-events.js +65 -0
- package/dist/proxy/push-events.js.map +1 -0
- package/dist/proxy/push-guard.d.ts +43 -0
- package/dist/proxy/push-guard.js +81 -0
- package/dist/proxy/push-guard.js.map +1 -0
- package/dist/proxy/push-options.d.ts +16 -0
- package/dist/proxy/push-options.js +33 -0
- package/dist/proxy/push-options.js.map +1 -0
- package/dist/proxy/receive-pack.d.ts +17 -0
- package/dist/proxy/receive-pack.js +244 -0
- package/dist/proxy/receive-pack.js.map +1 -0
- package/dist/proxy/request-log.d.ts +13 -0
- package/dist/proxy/request-log.js +41 -0
- package/dist/proxy/request-log.js.map +1 -0
- package/dist/proxy/resolve-route.d.ts +9 -0
- package/dist/proxy/resolve-route.js +22 -0
- package/dist/proxy/resolve-route.js.map +1 -0
- package/dist/proxy/upstream-call.d.ts +23 -0
- package/dist/proxy/upstream-call.js +63 -0
- package/dist/proxy/upstream-call.js.map +1 -0
- package/dist/proxy/upstream.d.ts +2 -0
- package/dist/proxy/upstream.js +68 -0
- package/dist/proxy/upstream.js.map +1 -0
- package/dist/push-event-f-5TsFUY.d.ts +15 -0
- package/dist/push-policy/changed-paths.d.ts +26 -0
- package/dist/push-policy/changed-paths.js +117 -0
- package/dist/push-policy/changed-paths.js.map +1 -0
- package/dist/push-policy/pushed-objects.d.ts +30 -0
- package/dist/push-policy/pushed-objects.js +76 -0
- package/dist/push-policy/pushed-objects.js.map +1 -0
- package/dist/push-policy/run-push-policy.d.ts +35 -0
- package/dist/push-policy/run-push-policy.js +77 -0
- package/dist/push-policy/run-push-policy.js.map +1 -0
- package/dist/push-policy/tree-diff.d.ts +21 -0
- package/dist/push-policy/tree-diff.js +78 -0
- package/dist/push-policy/tree-diff.js.map +1 -0
- package/dist/push-policy/uncheckable.d.ts +14 -0
- package/dist/push-policy/uncheckable.js +25 -0
- package/dist/push-policy/uncheckable.js.map +1 -0
- package/dist/rpc/branch-methods.d.ts +16 -0
- package/dist/rpc/branch-methods.js +43 -0
- package/dist/rpc/branch-methods.js.map +1 -0
- package/dist/rpc/commit-attempt.d.ts +27 -0
- package/dist/rpc/commit-attempt.js +85 -0
- package/dist/rpc/commit-attempt.js.map +1 -0
- package/dist/rpc/commit-graph.d.ts +20 -0
- package/dist/rpc/commit-graph.js +38 -0
- package/dist/rpc/commit-graph.js.map +1 -0
- package/dist/rpc/commit-method.d.ts +13 -0
- package/dist/rpc/commit-method.js +30 -0
- package/dist/rpc/commit-method.js.map +1 -0
- package/dist/rpc/commit-source.d.ts +12 -0
- package/dist/rpc/commit-source.js +9 -0
- package/dist/rpc/commit-source.js.map +1 -0
- package/dist/rpc/gateway-context.d.ts +2 -0
- package/dist/rpc/gateway-context.js +30 -0
- package/dist/rpc/gateway-context.js.map +1 -0
- package/dist/rpc/gateway-rpc.d.ts +10 -0
- package/dist/rpc/gateway-rpc.js +48 -0
- package/dist/rpc/gateway-rpc.js.map +1 -0
- package/dist/rpc/gateway-service.d.ts +24 -0
- package/dist/rpc/gateway-service.js +63 -0
- package/dist/rpc/gateway-service.js.map +1 -0
- package/dist/rpc/history-page.d.ts +35 -0
- package/dist/rpc/history-page.js +122 -0
- package/dist/rpc/history-page.js.map +1 -0
- package/dist/rpc/lifecycle-methods.d.ts +12 -0
- package/dist/rpc/lifecycle-methods.js +39 -0
- package/dist/rpc/lifecycle-methods.js.map +1 -0
- package/dist/rpc/paint-down.d.ts +17 -0
- package/dist/rpc/paint-down.js +96 -0
- package/dist/rpc/paint-down.js.map +1 -0
- package/dist/rpc/promote-attempt.d.ts +21 -0
- package/dist/rpc/promote-attempt.js +55 -0
- package/dist/rpc/promote-attempt.js.map +1 -0
- package/dist/rpc/push-ref.d.ts +21 -0
- package/dist/rpc/push-ref.js +47 -0
- package/dist/rpc/push-ref.js.map +1 -0
- package/dist/rpc/read-methods.d.ts +17 -0
- package/dist/rpc/read-methods.js +94 -0
- package/dist/rpc/read-methods.js.map +1 -0
- package/dist/rpc/read-token.d.ts +39 -0
- package/dist/rpc/read-token.js +107 -0
- package/dist/rpc/read-token.js.map +1 -0
- package/dist/rpc/repo-access.d.ts +36 -0
- package/dist/rpc/repo-access.js +75 -0
- package/dist/rpc/repo-access.js.map +1 -0
- package/dist/rpc/sync-attempt.d.ts +23 -0
- package/dist/rpc/sync-attempt.js +105 -0
- package/dist/rpc/sync-attempt.js.map +1 -0
- package/dist/sync-workflow-schemas-DCNmNE5-.d.ts +57 -0
- package/dist/upstream-DvqMCj5N.d.ts +15 -0
- package/dist/workflow-starter-BqhwX6oA.d.ts +45 -0
- package/dist/workflows/commit-workflow-schemas.d.ts +2 -0
- package/dist/workflows/commit-workflow-schemas.js +84 -0
- package/dist/workflows/commit-workflow-schemas.js.map +1 -0
- package/dist/workflows/commit-workflow.d.ts +16 -0
- package/dist/workflows/commit-workflow.js +22 -0
- package/dist/workflows/commit-workflow.js.map +1 -0
- package/dist/workflows/on-push.d.ts +2 -0
- package/dist/workflows/on-push.js +90 -0
- package/dist/workflows/on-push.js.map +1 -0
- package/dist/workflows/push-event.d.ts +2 -0
- package/dist/workflows/push-event.js +28 -0
- package/dist/workflows/push-event.js.map +1 -0
- package/dist/workflows/run-commit-workflow.d.ts +15 -0
- package/dist/workflows/run-commit-workflow.js +49 -0
- package/dist/workflows/run-commit-workflow.js.map +1 -0
- package/dist/workflows/run-sync-workflow.d.ts +14 -0
- package/dist/workflows/run-sync-workflow.js +67 -0
- package/dist/workflows/run-sync-workflow.js.map +1 -0
- package/dist/workflows/step-errors.d.ts +15 -0
- package/dist/workflows/step-errors.js +24 -0
- package/dist/workflows/step-errors.js.map +1 -0
- package/dist/workflows/step-runner.d.ts +31 -0
- package/dist/workflows/step-runner.js +6 -0
- package/dist/workflows/step-runner.js.map +1 -0
- package/dist/workflows/sync-branch-workflow.d.ts +15 -0
- package/dist/workflows/sync-branch-workflow.js +21 -0
- package/dist/workflows/sync-branch-workflow.js.map +1 -0
- package/dist/workflows/sync-workflow-schemas.d.ts +2 -0
- package/dist/workflows/sync-workflow-schemas.js +104 -0
- package/dist/workflows/sync-workflow-schemas.js.map +1 -0
- package/dist/workflows/workflow-instance-id.d.ts +12 -0
- package/dist/workflows/workflow-instance-id.js +33 -0
- package/dist/workflows/workflow-instance-id.js.map +1 -0
- package/dist/workflows/workflow-runtime.d.ts +7 -0
- package/dist/workflows/workflow-runtime.js +11 -0
- package/dist/workflows/workflow-runtime.js.map +1 -0
- package/dist/workflows/workflow-starter.d.ts +2 -0
- package/dist/workflows/workflow-starter.js +40 -0
- package/dist/workflows/workflow-starter.js.map +1 -0
- package/package.json +381 -4
- package/src/audit/audit-recorder.ts +74 -0
- package/src/audit/push-report.ts +60 -0
- package/src/auth/authenticate.ts +68 -0
- package/src/auth/authorize.ts +57 -0
- package/src/auth/read-token-auth.ts +119 -0
- package/src/cache/decision-cache.ts +57 -0
- package/src/gateway-app.ts +147 -0
- package/src/gateway-worker.ts +32 -0
- package/src/health.ts +12 -0
- package/src/logging/logger.ts +40 -0
- package/src/policy/branch-policy.ts +119 -0
- package/src/policy/enforce-branch-policy.ts +213 -0
- package/src/policy/fast-forward.ts +136 -0
- package/src/policy/ref-pattern.ts +24 -0
- package/src/policy/rule-branch-policy.ts +76 -0
- package/src/proxy/defer.ts +18 -0
- package/src/proxy/forward-read.ts +52 -0
- package/src/proxy/gateway-deps.ts +43 -0
- package/src/proxy/gateway-env.ts +43 -0
- package/src/proxy/git-responses.ts +89 -0
- package/src/proxy/git-route.ts +49 -0
- package/src/proxy/push-events.ts +91 -0
- package/src/proxy/push-guard.ts +109 -0
- package/src/proxy/push-options.ts +38 -0
- package/src/proxy/receive-pack.ts +257 -0
- package/src/proxy/request-log.ts +44 -0
- package/src/proxy/resolve-route.ts +24 -0
- package/src/proxy/upstream-call.ts +71 -0
- package/src/proxy/upstream.ts +76 -0
- package/src/push-policy/changed-paths.ts +143 -0
- package/src/push-policy/pushed-objects.ts +88 -0
- package/src/push-policy/run-push-policy.ts +99 -0
- package/src/push-policy/tree-diff.ts +107 -0
- package/src/push-policy/uncheckable.ts +27 -0
- package/src/rpc/branch-methods.ts +57 -0
- package/src/rpc/commit-attempt.ts +87 -0
- package/src/rpc/commit-graph.ts +44 -0
- package/src/rpc/commit-method.ts +36 -0
- package/src/rpc/commit-source.ts +15 -0
- package/src/rpc/gateway-context.ts +77 -0
- package/src/rpc/gateway-rpc.ts +65 -0
- package/src/rpc/gateway-service.ts +85 -0
- package/src/rpc/history-page.ts +163 -0
- package/src/rpc/lifecycle-methods.ts +50 -0
- package/src/rpc/paint-down.ts +120 -0
- package/src/rpc/promote-attempt.ts +52 -0
- package/src/rpc/push-ref.ts +54 -0
- package/src/rpc/read-methods.ts +111 -0
- package/src/rpc/read-token.ts +135 -0
- package/src/rpc/repo-access.ts +112 -0
- package/src/rpc/sync-attempt.ts +84 -0
- package/src/workflows/commit-workflow-schemas.ts +95 -0
- package/src/workflows/commit-workflow.ts +39 -0
- package/src/workflows/on-push.ts +128 -0
- package/src/workflows/push-event.ts +41 -0
- package/src/workflows/run-commit-workflow.ts +45 -0
- package/src/workflows/run-sync-workflow.ts +52 -0
- package/src/workflows/step-errors.ts +26 -0
- package/src/workflows/step-runner.ts +36 -0
- package/src/workflows/sync-branch-workflow.ts +40 -0
- package/src/workflows/sync-workflow-schemas.ts +122 -0
- package/src/workflows/workflow-instance-id.ts +26 -0
- package/src/workflows/workflow-runtime.ts +13 -0
- package/src/workflows/workflow-starter.ts +69 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { composeOnPush } from "../workflows/on-push.js";
|
|
2
|
+
import { ReadTokenSecret } from "./read-token.js";
|
|
3
|
+
import { GatewayConfig } from "@leed-ai/git-gateway-contract/schemas/gateway-config";
|
|
4
|
+
// src/rpc/gateway-context.ts
|
|
5
|
+
/** The default onPush failure handler: the failure is dropped (the write itself succeeded). */
|
|
6
|
+
const ignorePushHookError = () => void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Validates options (the configuration and the secret, with Zod) and applies the defaults. Throws
|
|
9
|
+
* a TypeError when sync rules are configured without a `syncWorkflow`.
|
|
10
|
+
*/
|
|
11
|
+
function gatewayContext(options) {
|
|
12
|
+
const config = GatewayConfig.parse(options.config ?? {});
|
|
13
|
+
return {
|
|
14
|
+
backend: options.backend,
|
|
15
|
+
config,
|
|
16
|
+
readTokenSecret: ReadTokenSecret.parse(options.readTokenSecret),
|
|
17
|
+
fetch: options.fetch,
|
|
18
|
+
now: options.now ?? (() => /* @__PURE__ */ new Date()),
|
|
19
|
+
commitWorkflow: options.commitWorkflow,
|
|
20
|
+
onPush: composeOnPush({
|
|
21
|
+
syncRules: config.syncRules,
|
|
22
|
+
syncWorkflow: options.syncWorkflow,
|
|
23
|
+
onPush: options.onPush
|
|
24
|
+
}),
|
|
25
|
+
onPushError: options.onPushError ?? ignorePushHookError
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export { gatewayContext };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=gateway-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-context.js","names":[],"sources":["../../src/rpc/gateway-context.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { GatewayConfig, type GatewayConfigInput } from '@leed-ai/git-gateway-contract/schemas/gateway-config';\nimport type { StorageBackend } from '@leed-ai/git-gateway-contract/storage/storage-backend';\nimport type { FetchLike } from '@leed-ai/git-gateway-core/smart-http/git-http-client';\n\nimport type { CommitWorkflowParams } from '../workflows/commit-workflow-schemas.ts';\nimport { composeOnPush, type OnPushHook } from '../workflows/on-push.ts';\nimport type { SyncBranchWorkflowParams } from '../workflows/sync-workflow-schemas.ts';\nimport type { WorkflowStarter } from '../workflows/workflow-starter.ts';\nimport { ReadTokenSecret } from './read-token.ts';\n\n/** How a deployment composes the RPC service and its Workflows. */\nexport interface GatewayOptions {\n /** Where the repositories live. */\n readonly backend: StorageBackend;\n /** Gateway configuration; every field has a default. */\n readonly config?: GatewayConfigInput;\n /** HMAC key read tokens are signed with (see {@link ReadTokenSecret}). */\n readonly readTokenSecret: string;\n /** How pushes reach the backend's git remote; default the global `fetch`. */\n readonly fetch?: FetchLike;\n /** The clock for commit dates, token expiry and the idempotency window; default the system clock. */\n readonly now?: () => Date;\n /** The CommitWorkflow binding commits are handed to when inline retries run out. */\n readonly commitWorkflow?: WorkflowStarter<CommitWorkflowParams>;\n /**\n * The SyncBranchWorkflow binding `config.syncRules` start instances of after every ref update\n * the RPC API pushes; required when there are sync rules.\n */\n readonly syncWorkflow?: WorkflowStarter<SyncBranchWorkflowParams>;\n /**\n * Called after every ref update the RPC API or its Workflows push (commits, syncs, promotions),\n * beside the sync rules, e.g. to send the event to a Queue. The write has\n * already happened, so a failure is reported to {@link onPushError} and does not fail the call.\n */\n readonly onPush?: OnPushHook;\n /** Receives onPush failures, e.g. to log or count them; default: they are dropped. */\n readonly onPushError?: (error: unknown) => void;\n}\n\n/** {@link GatewayOptions} validated, with defaults applied; what every method works with. */\nexport interface GatewayContext {\n readonly backend: StorageBackend;\n readonly config: GatewayConfig;\n readonly readTokenSecret: string;\n readonly fetch: FetchLike | undefined;\n readonly now: () => Date;\n readonly commitWorkflow: WorkflowStarter<CommitWorkflowParams> | undefined;\n /** The sync rules and the deployment's own hook, composed (see composeOnPush). */\n readonly onPush: OnPushHook | undefined;\n readonly onPushError: (error: unknown) => void;\n}\n\n/** The default onPush failure handler: the failure is dropped (the write itself succeeded). */\nconst ignorePushHookError = (): void => undefined;\n\n/**\n * Validates options (the configuration and the secret, with Zod) and applies the defaults. Throws\n * a TypeError when sync rules are configured without a `syncWorkflow`.\n */\nexport function gatewayContext(options: GatewayOptions): GatewayContext {\n const config = GatewayConfig.parse(options.config ?? {});\n return {\n backend: options.backend,\n config,\n readTokenSecret: ReadTokenSecret.parse(options.readTokenSecret),\n fetch: options.fetch,\n now: options.now ?? (() => new Date()),\n commitWorkflow: options.commitWorkflow,\n onPush: composeOnPush({\n syncRules: config.syncRules,\n syncWorkflow: options.syncWorkflow,\n onPush: options.onPush,\n }),\n onPushError: options.onPushError ?? ignorePushHookError,\n };\n}\n"],"mappings":";;;;;AAsDA,MAAM,4BAAkC,KAAA;;;;;AAMxC,SAAgB,eAAe,SAAyC;CACtE,MAAM,SAAS,cAAc,MAAM,QAAQ,UAAU,CAAC,CAAC;CACvD,OAAO;EACL,SAAS,QAAQ;EACjB;EACA,iBAAiB,gBAAgB,MAAM,QAAQ,eAAe;EAC9D,OAAO,QAAQ;EACf,KAAK,QAAQ,8BAAc,IAAI,KAAK;EACpC,gBAAgB,QAAQ;EACxB,QAAQ,cAAc;GACpB,WAAW,OAAO;GAClB,cAAc,QAAQ;GACtB,QAAQ,QAAQ;EAClB,CAAC;EACD,aAAa,QAAQ,eAAe;CACtC;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { n as GatewayOptions } from "../gateway-context-Boh9I0mk.js";
|
|
2
|
+
import { GitGateway } from "@leed-ai/git-gateway-contract/git-gateway";
|
|
3
|
+
/**
|
|
4
|
+
* The gateway's {@link GitGateway} over a storage backend: the methods the RPC entrypoint serves,
|
|
5
|
+
* usable directly wherever a gateway is needed in-process (tests, a deployment's own Worker).
|
|
6
|
+
* Every input is parsed with its contract schema before anything is read (invalid_input) and
|
|
7
|
+
* every output with its schema before it is returned; errors are GatewayErrors.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createGatewayRpc(options: GatewayOptions): GitGateway;
|
|
10
|
+
//# sourceMappingURL=gateway-rpc.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { gatewayPromote, gatewaySyncBranch } from "./branch-methods.js";
|
|
2
|
+
import { gatewayCommit } from "./commit-method.js";
|
|
3
|
+
import { gatewayContext } from "./gateway-context.js";
|
|
4
|
+
import { gatewayCreateRepo, gatewayDeleteRepo, gatewayMintReadToken } from "./lifecycle-methods.js";
|
|
5
|
+
import { gatewayCommitExists, gatewayListTree, gatewayLog, gatewayReadFile, gatewayResolveRef } from "./read-methods.js";
|
|
6
|
+
import { isCoreError } from "@leed-ai/git-gateway-core/core-error";
|
|
7
|
+
import { storageUnavailable } from "@leed-ai/git-gateway-contract/storage/storage-errors";
|
|
8
|
+
import { RPC_SCHEMAS } from "@leed-ai/git-gateway-contract/git-gateway";
|
|
9
|
+
import { runMethod } from "@leed-ai/git-gateway-contract/reference/run-method";
|
|
10
|
+
// src/rpc/gateway-rpc.ts
|
|
11
|
+
/**
|
|
12
|
+
* Runs a method's work so that a core error (an object the backend handed back that is missing or
|
|
13
|
+
* malformed) is reported as storage_unavailable: storage cannot be trusted for this call.
|
|
14
|
+
*/
|
|
15
|
+
async function guarded(name, work) {
|
|
16
|
+
try {
|
|
17
|
+
return await work();
|
|
18
|
+
} catch (thrown) {
|
|
19
|
+
if (isCoreError(thrown)) throw storageUnavailable(name, thrown);
|
|
20
|
+
throw thrown;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The gateway's {@link GitGateway} over a storage backend: the methods the RPC entrypoint serves,
|
|
25
|
+
* usable directly wherever a gateway is needed in-process (tests, a deployment's own Worker).
|
|
26
|
+
* Every input is parsed with its contract schema before anything is read (invalid_input) and
|
|
27
|
+
* every output with its schema before it is returned; errors are GatewayErrors.
|
|
28
|
+
*/
|
|
29
|
+
function createGatewayRpc(options) {
|
|
30
|
+
const context = gatewayContext(options);
|
|
31
|
+
const s = RPC_SCHEMAS;
|
|
32
|
+
return {
|
|
33
|
+
commit: (input) => runMethod(s.commit, input, (p) => guarded("commit", () => gatewayCommit(context, p))),
|
|
34
|
+
readFile: (input) => runMethod(s.readFile, input, (p) => guarded("readFile", () => gatewayReadFile(context, p))),
|
|
35
|
+
listTree: (input) => runMethod(s.listTree, input, (p) => guarded("listTree", () => gatewayListTree(context, p))),
|
|
36
|
+
resolveRef: (input) => runMethod(s.resolveRef, input, (p) => guarded("resolveRef", () => gatewayResolveRef(context, p))),
|
|
37
|
+
log: (input) => runMethod(s.log, input, (p) => guarded("log", () => gatewayLog(context, p))),
|
|
38
|
+
commitExists: (input) => runMethod(s.commitExists, input, (p) => guarded("commitExists", () => gatewayCommitExists(context, p))),
|
|
39
|
+
syncBranch: (input) => runMethod(s.syncBranch, input, (p) => guarded("syncBranch", () => gatewaySyncBranch(context, p))),
|
|
40
|
+
promote: (input) => runMethod(s.promote, input, (p) => guarded("promote", () => gatewayPromote(context, p))),
|
|
41
|
+
createRepo: (input) => runMethod(s.createRepo, input, (p) => guarded("createRepo", () => gatewayCreateRepo(context, p))),
|
|
42
|
+
deleteRepo: (input) => runMethod(s.deleteRepo, input, (p) => guarded("deleteRepo", () => gatewayDeleteRepo(context, p))),
|
|
43
|
+
mintReadToken: (input) => runMethod(s.mintReadToken, input, (p) => guarded("mintReadToken", () => gatewayMintReadToken(context, p)))
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export { createGatewayRpc };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=gateway-rpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-rpc.js","names":[],"sources":["../../src/rpc/gateway-rpc.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { RPC_SCHEMAS, type GitGateway } from '@leed-ai/git-gateway-contract/git-gateway';\nimport { runMethod } from '@leed-ai/git-gateway-contract/reference/run-method';\nimport { storageUnavailable } from '@leed-ai/git-gateway-contract/storage/storage-errors';\nimport { isCoreError } from '@leed-ai/git-gateway-core/core-error';\n\nimport { gatewayPromote, gatewaySyncBranch } from './branch-methods.ts';\nimport { gatewayCommit } from './commit-method.ts';\nimport { gatewayContext, type GatewayOptions } from './gateway-context.ts';\nimport { gatewayCreateRepo, gatewayDeleteRepo, gatewayMintReadToken } from './lifecycle-methods.ts';\nimport {\n gatewayCommitExists,\n gatewayListTree,\n gatewayLog,\n gatewayReadFile,\n gatewayResolveRef,\n} from './read-methods.ts';\n\n/**\n * Runs a method's work so that a core error (an object the backend handed back that is missing or\n * malformed) is reported as storage_unavailable: storage cannot be trusted for this call.\n */\nasync function guarded<T>(name: string, work: () => Promise<T>): Promise<T> {\n try {\n return await work();\n } catch (thrown) {\n if (isCoreError(thrown)) throw storageUnavailable(name, thrown);\n throw thrown;\n }\n}\n\n/**\n * The gateway's {@link GitGateway} over a storage backend: the methods the RPC entrypoint serves,\n * usable directly wherever a gateway is needed in-process (tests, a deployment's own Worker).\n * Every input is parsed with its contract schema before anything is read (invalid_input) and\n * every output with its schema before it is returned; errors are GatewayErrors.\n */\nexport function createGatewayRpc(options: GatewayOptions): GitGateway {\n const context = gatewayContext(options);\n const s = RPC_SCHEMAS;\n return {\n commit: (input) => runMethod(s.commit, input, (p) => guarded('commit', () => gatewayCommit(context, p))),\n readFile: (input) =>\n runMethod(s.readFile, input, (p) => guarded('readFile', () => gatewayReadFile(context, p))),\n listTree: (input) =>\n runMethod(s.listTree, input, (p) => guarded('listTree', () => gatewayListTree(context, p))),\n resolveRef: (input) =>\n runMethod(s.resolveRef, input, (p) => guarded('resolveRef', () => gatewayResolveRef(context, p))),\n log: (input) => runMethod(s.log, input, (p) => guarded('log', () => gatewayLog(context, p))),\n commitExists: (input) =>\n runMethod(s.commitExists, input, (p) => guarded('commitExists', () => gatewayCommitExists(context, p))),\n syncBranch: (input) =>\n runMethod(s.syncBranch, input, (p) => guarded('syncBranch', () => gatewaySyncBranch(context, p))),\n promote: (input) =>\n runMethod(s.promote, input, (p) => guarded('promote', () => gatewayPromote(context, p))),\n createRepo: (input) =>\n runMethod(s.createRepo, input, (p) => guarded('createRepo', () => gatewayCreateRepo(context, p))),\n deleteRepo: (input) =>\n runMethod(s.deleteRepo, input, (p) => guarded('deleteRepo', () => gatewayDeleteRepo(context, p))),\n mintReadToken: (input) =>\n runMethod(s.mintReadToken, input, (p) =>\n guarded('mintReadToken', () => gatewayMintReadToken(context, p)),\n ),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,eAAe,QAAW,MAAc,MAAoC;CAC1E,IAAI;EACF,OAAO,MAAM,KAAK;CACpB,SAAS,QAAQ;EACf,IAAI,YAAY,MAAM,GAAG,MAAM,mBAAmB,MAAM,MAAM;EAC9D,MAAM;CACR;AACF;;;;;;;AAQA,SAAgB,iBAAiB,SAAqC;CACpE,MAAM,UAAU,eAAe,OAAO;CACtC,MAAM,IAAI;CACV,OAAO;EACL,SAAS,UAAU,UAAU,EAAE,QAAQ,QAAQ,MAAM,QAAQ,gBAAgB,cAAc,SAAS,CAAC,CAAC,CAAC;EACvG,WAAW,UACT,UAAU,EAAE,UAAU,QAAQ,MAAM,QAAQ,kBAAkB,gBAAgB,SAAS,CAAC,CAAC,CAAC;EAC5F,WAAW,UACT,UAAU,EAAE,UAAU,QAAQ,MAAM,QAAQ,kBAAkB,gBAAgB,SAAS,CAAC,CAAC,CAAC;EAC5F,aAAa,UACX,UAAU,EAAE,YAAY,QAAQ,MAAM,QAAQ,oBAAoB,kBAAkB,SAAS,CAAC,CAAC,CAAC;EAClG,MAAM,UAAU,UAAU,EAAE,KAAK,QAAQ,MAAM,QAAQ,aAAa,WAAW,SAAS,CAAC,CAAC,CAAC;EAC3F,eAAe,UACb,UAAU,EAAE,cAAc,QAAQ,MAAM,QAAQ,sBAAsB,oBAAoB,SAAS,CAAC,CAAC,CAAC;EACxG,aAAa,UACX,UAAU,EAAE,YAAY,QAAQ,MAAM,QAAQ,oBAAoB,kBAAkB,SAAS,CAAC,CAAC,CAAC;EAClG,UAAU,UACR,UAAU,EAAE,SAAS,QAAQ,MAAM,QAAQ,iBAAiB,eAAe,SAAS,CAAC,CAAC,CAAC;EACzF,aAAa,UACX,UAAU,EAAE,YAAY,QAAQ,MAAM,QAAQ,oBAAoB,kBAAkB,SAAS,CAAC,CAAC,CAAC;EAClG,aAAa,UACX,UAAU,EAAE,YAAY,QAAQ,MAAM,QAAQ,oBAAoB,kBAAkB,SAAS,CAAC,CAAC,CAAC;EAClG,gBAAgB,UACd,UAAU,EAAE,eAAe,QAAQ,MACjC,QAAQ,uBAAuB,qBAAqB,SAAS,CAAC,CAAC,CACjE;CACJ;AACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { n as GatewayOptions } from "../gateway-context-Boh9I0mk.js";
|
|
2
|
+
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
3
|
+
import { GitGateway } from "@leed-ai/git-gateway-contract/git-gateway";
|
|
4
|
+
/** Builds a deployment's {@link GatewayOptions} from its Worker environment (bindings and secrets). */
|
|
5
|
+
export type GatewayOptionsResolver<Env> = (env: Env) => GatewayOptions;
|
|
6
|
+
/** The RPC entrypoint class {@link createGatewayService} returns. */
|
|
7
|
+
export type GatewayServiceClass<Env> = new (ctx: ExecutionContext, env: Env) => WorkerEntrypoint<Env> & GitGateway;
|
|
8
|
+
/**
|
|
9
|
+
* The git-gateway RPC API as a `WorkerEntrypoint`, for other Workers to call over a service
|
|
10
|
+
* binding. A deployment exports the returned class under a name of its choosing and binds it:
|
|
11
|
+
*
|
|
12
|
+
* export const GatewayService = createGatewayService((env: Env) => ({
|
|
13
|
+
* backend: new ArtifactsBackend(env.ARTIFACTS),
|
|
14
|
+
* readTokenSecret: env.READ_TOKEN_SECRET,
|
|
15
|
+
* commitWorkflow: env.COMMIT_WORKFLOW,
|
|
16
|
+
* }));
|
|
17
|
+
*
|
|
18
|
+
* Every method validates its input and output with the contract schemas. Errors are
|
|
19
|
+
* GatewayErrors, whose message carries the error body so callers recover it with
|
|
20
|
+
* `readGatewayError` on the far side of the binding. The options (and the secret in them) live in
|
|
21
|
+
* a closure, never on the class, so no RPC call can reach them.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createGatewayService<Env>(resolve: GatewayOptionsResolver<Env>): GatewayServiceClass<Env>;
|
|
24
|
+
//# sourceMappingURL=gateway-service.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createGatewayRpc } from "./gateway-rpc.js";
|
|
2
|
+
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
3
|
+
// src/rpc/gateway-service.ts
|
|
4
|
+
/**
|
|
5
|
+
* The git-gateway RPC API as a `WorkerEntrypoint`, for other Workers to call over a service
|
|
6
|
+
* binding. A deployment exports the returned class under a name of its choosing and binds it:
|
|
7
|
+
*
|
|
8
|
+
* export const GatewayService = createGatewayService((env: Env) => ({
|
|
9
|
+
* backend: new ArtifactsBackend(env.ARTIFACTS),
|
|
10
|
+
* readTokenSecret: env.READ_TOKEN_SECRET,
|
|
11
|
+
* commitWorkflow: env.COMMIT_WORKFLOW,
|
|
12
|
+
* }));
|
|
13
|
+
*
|
|
14
|
+
* Every method validates its input and output with the contract schemas. Errors are
|
|
15
|
+
* GatewayErrors, whose message carries the error body so callers recover it with
|
|
16
|
+
* `readGatewayError` on the far side of the binding. The options (and the secret in them) live in
|
|
17
|
+
* a closure, never on the class, so no RPC call can reach them.
|
|
18
|
+
*/
|
|
19
|
+
function createGatewayService(resolve) {
|
|
20
|
+
return class GatewayService extends WorkerEntrypoint {
|
|
21
|
+
#gateway;
|
|
22
|
+
#rpc() {
|
|
23
|
+
this.#gateway ??= createGatewayRpc(resolve(this.env));
|
|
24
|
+
return this.#gateway;
|
|
25
|
+
}
|
|
26
|
+
async commit(input) {
|
|
27
|
+
return await this.#rpc().commit(input);
|
|
28
|
+
}
|
|
29
|
+
async readFile(input) {
|
|
30
|
+
return await this.#rpc().readFile(input);
|
|
31
|
+
}
|
|
32
|
+
async listTree(input) {
|
|
33
|
+
return await this.#rpc().listTree(input);
|
|
34
|
+
}
|
|
35
|
+
async resolveRef(input) {
|
|
36
|
+
return await this.#rpc().resolveRef(input);
|
|
37
|
+
}
|
|
38
|
+
async log(input) {
|
|
39
|
+
return await this.#rpc().log(input);
|
|
40
|
+
}
|
|
41
|
+
async commitExists(input) {
|
|
42
|
+
return await this.#rpc().commitExists(input);
|
|
43
|
+
}
|
|
44
|
+
async syncBranch(input) {
|
|
45
|
+
return await this.#rpc().syncBranch(input);
|
|
46
|
+
}
|
|
47
|
+
async promote(input) {
|
|
48
|
+
return await this.#rpc().promote(input);
|
|
49
|
+
}
|
|
50
|
+
async createRepo(input) {
|
|
51
|
+
return await this.#rpc().createRepo(input);
|
|
52
|
+
}
|
|
53
|
+
async deleteRepo(input) {
|
|
54
|
+
return await this.#rpc().deleteRepo(input);
|
|
55
|
+
}
|
|
56
|
+
async mintReadToken(input) {
|
|
57
|
+
return await this.#rpc().mintReadToken(input);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export { createGatewayService };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=gateway-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-service.js","names":[],"sources":["../../src/rpc/gateway-service.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { WorkerEntrypoint } from 'cloudflare:workers';\nimport type { GitGateway, RpcInput, RpcOutput } from '@leed-ai/git-gateway-contract/git-gateway';\n\nimport type { GatewayOptions } from './gateway-context.ts';\nimport { createGatewayRpc } from './gateway-rpc.ts';\n\n/** Builds a deployment's {@link GatewayOptions} from its Worker environment (bindings and secrets). */\nexport type GatewayOptionsResolver<Env> = (env: Env) => GatewayOptions;\n\n/** The RPC entrypoint class {@link createGatewayService} returns. */\nexport type GatewayServiceClass<Env> = new (\n ctx: ExecutionContext,\n env: Env,\n) => WorkerEntrypoint<Env> & GitGateway;\n\n/**\n * The git-gateway RPC API as a `WorkerEntrypoint`, for other Workers to call over a service\n * binding. A deployment exports the returned class under a name of its choosing and binds it:\n *\n * export const GatewayService = createGatewayService((env: Env) => ({\n * backend: new ArtifactsBackend(env.ARTIFACTS),\n * readTokenSecret: env.READ_TOKEN_SECRET,\n * commitWorkflow: env.COMMIT_WORKFLOW,\n * }));\n *\n * Every method validates its input and output with the contract schemas. Errors are\n * GatewayErrors, whose message carries the error body so callers recover it with\n * `readGatewayError` on the far side of the binding. The options (and the secret in them) live in\n * a closure, never on the class, so no RPC call can reach them.\n */\nexport function createGatewayService<Env>(resolve: GatewayOptionsResolver<Env>): GatewayServiceClass<Env> {\n return class GatewayService extends WorkerEntrypoint<Env> implements GitGateway {\n #gateway: GitGateway | undefined;\n\n #rpc(): GitGateway {\n this.#gateway ??= createGatewayRpc(resolve(this.env));\n return this.#gateway;\n }\n\n async commit(input: RpcInput<'commit'>): Promise<RpcOutput<'commit'>> {\n return await this.#rpc().commit(input);\n }\n\n async readFile(input: RpcInput<'readFile'>): Promise<RpcOutput<'readFile'>> {\n return await this.#rpc().readFile(input);\n }\n\n async listTree(input: RpcInput<'listTree'>): Promise<RpcOutput<'listTree'>> {\n return await this.#rpc().listTree(input);\n }\n\n async resolveRef(input: RpcInput<'resolveRef'>): Promise<RpcOutput<'resolveRef'>> {\n return await this.#rpc().resolveRef(input);\n }\n\n async log(input: RpcInput<'log'>): Promise<RpcOutput<'log'>> {\n return await this.#rpc().log(input);\n }\n\n async commitExists(input: RpcInput<'commitExists'>): Promise<RpcOutput<'commitExists'>> {\n return await this.#rpc().commitExists(input);\n }\n\n async syncBranch(input: RpcInput<'syncBranch'>): Promise<RpcOutput<'syncBranch'>> {\n return await this.#rpc().syncBranch(input);\n }\n\n async promote(input: RpcInput<'promote'>): Promise<RpcOutput<'promote'>> {\n return await this.#rpc().promote(input);\n }\n\n async createRepo(input: RpcInput<'createRepo'>): Promise<RpcOutput<'createRepo'>> {\n return await this.#rpc().createRepo(input);\n }\n\n async deleteRepo(input: RpcInput<'deleteRepo'>): Promise<RpcOutput<'deleteRepo'>> {\n return await this.#rpc().deleteRepo(input);\n }\n\n async mintReadToken(input: RpcInput<'mintReadToken'>): Promise<RpcOutput<'mintReadToken'>> {\n return await this.#rpc().mintReadToken(input);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,SAAgB,qBAA0B,SAAgE;CACxG,OAAO,MAAM,uBAAuB,iBAA4C;EAC9E;EAEA,OAAmB;GACjB,KAAK,aAAa,iBAAiB,QAAQ,KAAK,GAAG,CAAC;GACpD,OAAO,KAAK;EACd;EAEA,MAAM,OAAO,OAAyD;GACpE,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,OAAO,KAAK;EACvC;EAEA,MAAM,SAAS,OAA6D;GAC1E,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,SAAS,KAAK;EACzC;EAEA,MAAM,SAAS,OAA6D;GAC1E,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,SAAS,KAAK;EACzC;EAEA,MAAM,WAAW,OAAiE;GAChF,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,WAAW,KAAK;EAC3C;EAEA,MAAM,IAAI,OAAmD;GAC3D,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,IAAI,KAAK;EACpC;EAEA,MAAM,aAAa,OAAqE;GACtF,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,aAAa,KAAK;EAC7C;EAEA,MAAM,WAAW,OAAiE;GAChF,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,WAAW,KAAK;EAC3C;EAEA,MAAM,QAAQ,OAA2D;GACvE,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,QAAQ,KAAK;EACxC;EAEA,MAAM,WAAW,OAAiE;GAChF,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,WAAW,KAAK;EAC3C;EAEA,MAAM,WAAW,OAAiE;GAChF,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,WAAW,KAAK;EAC3C;EAEA,MAAM,cAAc,OAAuE;GACzF,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,cAAc,KAAK;EAC9C;CACF;AACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CommitSource } from "./commit-source.js";
|
|
2
|
+
import { Commit } from "@leed-ai/git-gateway-contract/schemas/commit";
|
|
3
|
+
/** Which page of history to list. */
|
|
4
|
+
export interface HistoryPageRequest {
|
|
5
|
+
readonly limit: number;
|
|
6
|
+
readonly offset: number;
|
|
7
|
+
/** ISO timestamp; commits committed before it are left out. */
|
|
8
|
+
readonly since?: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
/** One page of history and whether more follows it. */
|
|
11
|
+
export interface HistoryPage {
|
|
12
|
+
readonly commits: Commit[];
|
|
13
|
+
readonly hasMore: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The walk behind log(): emits the history reachable from `start` in exactly the reference's
|
|
17
|
+
* order (`walkHistory`: newest committer date first, never a parent before its child, the
|
|
18
|
+
* reference's tie rule), but reads only as far as the page needs.
|
|
19
|
+
*
|
|
20
|
+
* Commits are expanded (their parents read) newest committer date first. A ready commit — one
|
|
21
|
+
* whose known children have all been emitted — is certain once every other unexpanded commit is
|
|
22
|
+
* dated strictly before it: while committer dates never decrease from parent to child, an unseen
|
|
23
|
+
* child of it would be dated at or after it, and could only be reached through such a commit. The
|
|
24
|
+
* reference's pick is emitted only when it cannot be changed by a ready commit that is not
|
|
25
|
+
* certain; otherwise the newest unexpanded commit is expanded first. The walk stops once
|
|
26
|
+
* `offset + limit + 1` commits from `since` on have been emitted, or once everything left is older
|
|
27
|
+
* than `since`.
|
|
28
|
+
*
|
|
29
|
+
* Every edge read is checked: on a parent dated after its child (clock skew) the walk gives up and
|
|
30
|
+
* orders the whole reachable history instead, as the reference does. Skew lying entirely beyond
|
|
31
|
+
* the commits the page needed is never read, and so cannot be detected; within it, the page can
|
|
32
|
+
* differ from the reference's.
|
|
33
|
+
*/
|
|
34
|
+
export declare function historyPage(source: CommitSource, start: Commit, request: HistoryPageRequest): Promise<HistoryPage>;
|
|
35
|
+
//# sourceMappingURL=history-page.d.ts.map
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { dateOrder } from "./commit-source.js";
|
|
2
|
+
import { walkHistory } from "@leed-ai/git-gateway-contract/reference/history";
|
|
3
|
+
// src/rpc/history-page.ts
|
|
4
|
+
/** Thrown inside the walk when a parent is dated after its child; the walk then reads everything. */
|
|
5
|
+
var DateSkew = class extends Error {};
|
|
6
|
+
/** Timestamps compared as strings can disagree with time by less than one second (fractions). */
|
|
7
|
+
const STRING_ORDER_SLACK_MS = 1e3;
|
|
8
|
+
/** The reference's pick among ready commits: the newest committer date, with its tie rule. */
|
|
9
|
+
function referencePick(ready) {
|
|
10
|
+
let pick = ready.length - 1;
|
|
11
|
+
ready.forEach((candidate, index) => {
|
|
12
|
+
const best = ready[pick];
|
|
13
|
+
if (best !== void 0 && candidate.committer.date > best.committer.date) pick = index;
|
|
14
|
+
});
|
|
15
|
+
return pick;
|
|
16
|
+
}
|
|
17
|
+
/** Applies `since`, then cuts the page. */
|
|
18
|
+
function cut(history, { limit, offset, since }) {
|
|
19
|
+
const lowest = since === void 0 ? Number.NEGATIVE_INFINITY : Date.parse(since);
|
|
20
|
+
const kept = history.filter((commit) => Date.parse(commit.committer.date) >= lowest);
|
|
21
|
+
return {
|
|
22
|
+
commits: kept.slice(offset, offset + limit),
|
|
23
|
+
hasMore: kept.length > offset + limit
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** The whole reachable history in the reference's order, read in full (the fallback). */
|
|
27
|
+
async function fullHistory(source, start) {
|
|
28
|
+
const commits = /* @__PURE__ */ new Map([[start.sha, start]]);
|
|
29
|
+
let frontier = [start];
|
|
30
|
+
while (frontier.length > 0) {
|
|
31
|
+
const wanted = [...new Set(frontier.flatMap((commit) => commit.parents))].filter((sha) => !commits.has(sha));
|
|
32
|
+
frontier = (await Promise.all(wanted.map((sha) => source.commit(sha)))).filter((commit) => commit !== null);
|
|
33
|
+
for (const commit of frontier) commits.set(commit.sha, commit);
|
|
34
|
+
}
|
|
35
|
+
return walkHistory((sha) => commits.get(sha), start.sha);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The walk behind log(): emits the history reachable from `start` in exactly the reference's
|
|
39
|
+
* order (`walkHistory`: newest committer date first, never a parent before its child, the
|
|
40
|
+
* reference's tie rule), but reads only as far as the page needs.
|
|
41
|
+
*
|
|
42
|
+
* Commits are expanded (their parents read) newest committer date first. A ready commit — one
|
|
43
|
+
* whose known children have all been emitted — is certain once every other unexpanded commit is
|
|
44
|
+
* dated strictly before it: while committer dates never decrease from parent to child, an unseen
|
|
45
|
+
* child of it would be dated at or after it, and could only be reached through such a commit. The
|
|
46
|
+
* reference's pick is emitted only when it cannot be changed by a ready commit that is not
|
|
47
|
+
* certain; otherwise the newest unexpanded commit is expanded first. The walk stops once
|
|
48
|
+
* `offset + limit + 1` commits from `since` on have been emitted, or once everything left is older
|
|
49
|
+
* than `since`.
|
|
50
|
+
*
|
|
51
|
+
* Every edge read is checked: on a parent dated after its child (clock skew) the walk gives up and
|
|
52
|
+
* orders the whole reachable history instead, as the reference does. Skew lying entirely beyond
|
|
53
|
+
* the commits the page needed is never read, and so cannot be detected; within it, the page can
|
|
54
|
+
* differ from the reference's.
|
|
55
|
+
*/
|
|
56
|
+
async function historyPage(source, start, request) {
|
|
57
|
+
try {
|
|
58
|
+
return await boundedPage(source, start, request);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (!(error instanceof DateSkew)) throw error;
|
|
61
|
+
return cut(await fullHistory(source, start), request);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function boundedPage(source, start, request) {
|
|
65
|
+
const wanted = request.offset + request.limit + 1;
|
|
66
|
+
const sinceMs = request.since === void 0 ? Number.NEGATIVE_INFINITY : Date.parse(request.since);
|
|
67
|
+
const commits = /* @__PURE__ */ new Map([[start.sha, start]]);
|
|
68
|
+
const unexpanded = /* @__PURE__ */ new Map([[start.sha, start]]);
|
|
69
|
+
const pendingChildren = /* @__PURE__ */ new Map();
|
|
70
|
+
const ready = [start];
|
|
71
|
+
const emitted = [];
|
|
72
|
+
let kept = 0;
|
|
73
|
+
const expand = async (commit) => {
|
|
74
|
+
unexpanded.delete(commit.sha);
|
|
75
|
+
const parents = await Promise.all(commit.parents.map(async (sha) => commits.get(sha) ?? source.commit(sha)));
|
|
76
|
+
commit.parents.forEach((sha, index) => {
|
|
77
|
+
pendingChildren.set(sha, (pendingChildren.get(sha) ?? 0) + 1);
|
|
78
|
+
const at = ready.findIndex((candidate) => candidate.sha === sha);
|
|
79
|
+
if (at !== -1) ready.splice(at, 1);
|
|
80
|
+
const parent = parents[index];
|
|
81
|
+
if (parent === null || parent === void 0) return;
|
|
82
|
+
if (dateOrder(parent, commit) > 0) throw new DateSkew();
|
|
83
|
+
if (!commits.has(sha)) {
|
|
84
|
+
commits.set(sha, parent);
|
|
85
|
+
unexpanded.set(sha, parent);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
const certain = (commit) => [...unexpanded.values()].every((other) => other.sha === commit.sha || dateOrder(other, commit) < 0);
|
|
90
|
+
const nothingLeftSince = () => ready.every((commit) => Date.parse(commit.committer.date) < sinceMs) && [...unexpanded.values()].every((commit) => Date.parse(commit.committer.date) < sinceMs - STRING_ORDER_SLACK_MS);
|
|
91
|
+
while (ready.length > 0 && kept < wanted && !nothingLeftSince()) {
|
|
92
|
+
const pick = ready[referencePick(ready)];
|
|
93
|
+
if (pick === void 0) break;
|
|
94
|
+
if (unexpanded.has(pick.sha)) {
|
|
95
|
+
await expand(pick);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const newest = ready.filter((commit) => dateOrder(commit, pick) === 0);
|
|
99
|
+
const last = ready.at(-1);
|
|
100
|
+
if (!(newest.every(certain) && (newest.length === 1 || last === void 0 || dateOrder(last, pick) === 0 || certain(last)))) {
|
|
101
|
+
let next;
|
|
102
|
+
for (const commit of unexpanded.values()) if (next === void 0 || dateOrder(commit, next) > 0) next = commit;
|
|
103
|
+
if (next !== void 0) {
|
|
104
|
+
await expand(next);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
ready.splice(ready.indexOf(pick), 1);
|
|
109
|
+
emitted.push(pick);
|
|
110
|
+
if (Date.parse(pick.committer.date) >= sinceMs) kept += 1;
|
|
111
|
+
for (const sha of pick.parents) {
|
|
112
|
+
const left = (pendingChildren.get(sha) ?? 1) - 1;
|
|
113
|
+
pendingChildren.set(sha, left);
|
|
114
|
+
const parent = commits.get(sha);
|
|
115
|
+
if (left === 0 && parent !== void 0) ready.push(parent);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return cut(emitted, request);
|
|
119
|
+
}
|
|
120
|
+
export { historyPage };
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=history-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history-page.js","names":[],"sources":["../../src/rpc/history-page.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { walkHistory } from '@leed-ai/git-gateway-contract/reference/history';\nimport type { Commit } from '@leed-ai/git-gateway-contract/schemas/commit';\n\nimport { type CommitSource, dateOrder } from './commit-source.ts';\n\n/** Which page of history to list. */\nexport interface HistoryPageRequest {\n readonly limit: number;\n readonly offset: number;\n /** ISO timestamp; commits committed before it are left out. */\n readonly since?: string | undefined;\n}\n\n/** One page of history and whether more follows it. */\nexport interface HistoryPage {\n readonly commits: Commit[];\n readonly hasMore: boolean;\n}\n\n/** Thrown inside the walk when a parent is dated after its child; the walk then reads everything. */\nclass DateSkew extends Error {}\n\n/** Timestamps compared as strings can disagree with time by less than one second (fractions). */\nconst STRING_ORDER_SLACK_MS = 1000;\n\n/** The reference's pick among ready commits: the newest committer date, with its tie rule. */\nfunction referencePick(ready: readonly Commit[]): number {\n let pick = ready.length - 1;\n ready.forEach((candidate, index) => {\n const best = ready[pick];\n if (best !== undefined && candidate.committer.date > best.committer.date) pick = index;\n });\n return pick;\n}\n\n/** Applies `since`, then cuts the page. */\nfunction cut(history: readonly Commit[], { limit, offset, since }: HistoryPageRequest): HistoryPage {\n const lowest = since === undefined ? Number.NEGATIVE_INFINITY : Date.parse(since);\n const kept = history.filter((commit) => Date.parse(commit.committer.date) >= lowest);\n return { commits: kept.slice(offset, offset + limit), hasMore: kept.length > offset + limit };\n}\n\n/** The whole reachable history in the reference's order, read in full (the fallback). */\nasync function fullHistory(source: CommitSource, start: Commit): Promise<Commit[]> {\n const commits = new Map<string, Commit>([[start.sha, start]]);\n let frontier = [start];\n while (frontier.length > 0) {\n const wanted = [...new Set(frontier.flatMap((commit) => commit.parents))].filter(\n (sha) => !commits.has(sha),\n );\n const read = await Promise.all(wanted.map((sha) => source.commit(sha)));\n frontier = read.filter((commit) => commit !== null);\n for (const commit of frontier) commits.set(commit.sha, commit);\n }\n return walkHistory((sha) => commits.get(sha), start.sha);\n}\n\n/**\n * The walk behind log(): emits the history reachable from `start` in exactly the reference's\n * order (`walkHistory`: newest committer date first, never a parent before its child, the\n * reference's tie rule), but reads only as far as the page needs.\n *\n * Commits are expanded (their parents read) newest committer date first. A ready commit — one\n * whose known children have all been emitted — is certain once every other unexpanded commit is\n * dated strictly before it: while committer dates never decrease from parent to child, an unseen\n * child of it would be dated at or after it, and could only be reached through such a commit. The\n * reference's pick is emitted only when it cannot be changed by a ready commit that is not\n * certain; otherwise the newest unexpanded commit is expanded first. The walk stops once\n * `offset + limit + 1` commits from `since` on have been emitted, or once everything left is older\n * than `since`.\n *\n * Every edge read is checked: on a parent dated after its child (clock skew) the walk gives up and\n * orders the whole reachable history instead, as the reference does. Skew lying entirely beyond\n * the commits the page needed is never read, and so cannot be detected; within it, the page can\n * differ from the reference's.\n */\nexport async function historyPage(\n source: CommitSource,\n start: Commit,\n request: HistoryPageRequest,\n): Promise<HistoryPage> {\n try {\n return await boundedPage(source, start, request);\n } catch (error) {\n if (!(error instanceof DateSkew)) throw error;\n return cut(await fullHistory(source, start), request);\n }\n}\n\nasync function boundedPage(\n source: CommitSource,\n start: Commit,\n request: HistoryPageRequest,\n): Promise<HistoryPage> {\n const wanted = request.offset + request.limit + 1;\n const sinceMs = request.since === undefined ? Number.NEGATIVE_INFINITY : Date.parse(request.since);\n const commits = new Map<string, Commit>([[start.sha, start]]);\n const unexpanded = new Map<string, Commit>([[start.sha, start]]);\n const pendingChildren = new Map<string, number>();\n const ready: Commit[] = [start];\n const emitted: Commit[] = [];\n let kept = 0;\n\n const expand = async (commit: Commit): Promise<void> => {\n unexpanded.delete(commit.sha);\n const parents = await Promise.all(\n commit.parents.map(async (sha) => commits.get(sha) ?? source.commit(sha)),\n );\n commit.parents.forEach((sha, index) => {\n pendingChildren.set(sha, (pendingChildren.get(sha) ?? 0) + 1);\n const at = ready.findIndex((candidate) => candidate.sha === sha);\n if (at !== -1) ready.splice(at, 1);\n const parent = parents[index];\n if (parent === null || parent === undefined) return;\n if (dateOrder(parent, commit) > 0) throw new DateSkew();\n if (!commits.has(sha)) {\n commits.set(sha, parent);\n unexpanded.set(sha, parent);\n }\n });\n };\n const certain = (commit: Commit): boolean =>\n [...unexpanded.values()].every((other) => other.sha === commit.sha || dateOrder(other, commit) < 0);\n const nothingLeftSince = (): boolean =>\n ready.every((commit) => Date.parse(commit.committer.date) < sinceMs) &&\n [...unexpanded.values()].every(\n (commit) => Date.parse(commit.committer.date) < sinceMs - STRING_ORDER_SLACK_MS,\n );\n\n while (ready.length > 0 && kept < wanted && !nothingLeftSince()) {\n const pick = ready[referencePick(ready)];\n if (pick === undefined) break;\n if (unexpanded.has(pick.sha)) {\n await expand(pick);\n continue;\n }\n const newest = ready.filter((commit) => dateOrder(commit, pick) === 0);\n const last = ready.at(-1);\n const safe =\n newest.every(certain) &&\n (newest.length === 1 || last === undefined || dateOrder(last, pick) === 0 || certain(last));\n if (!safe) {\n let next: Commit | undefined;\n for (const commit of unexpanded.values())\n if (next === undefined || dateOrder(commit, next) > 0) next = commit;\n if (next !== undefined) {\n await expand(next);\n continue;\n }\n }\n ready.splice(ready.indexOf(pick), 1);\n emitted.push(pick);\n if (Date.parse(pick.committer.date) >= sinceMs) kept += 1;\n for (const sha of pick.parents) {\n const left = (pendingChildren.get(sha) ?? 1) - 1;\n pendingChildren.set(sha, left);\n const parent = commits.get(sha);\n if (left === 0 && parent !== undefined) ready.push(parent);\n }\n }\n return cut(emitted, request);\n}\n"],"mappings":";;;;AAqBA,IAAM,WAAN,cAAuB,MAAM,CAAC;;AAG9B,MAAM,wBAAwB;;AAG9B,SAAS,cAAc,OAAkC;CACvD,IAAI,OAAO,MAAM,SAAS;CAC1B,MAAM,SAAS,WAAW,UAAU;EAClC,MAAM,OAAO,MAAM;EACnB,IAAI,SAAS,KAAA,KAAa,UAAU,UAAU,OAAO,KAAK,UAAU,MAAM,OAAO;CACnF,CAAC;CACD,OAAO;AACT;;AAGA,SAAS,IAAI,SAA4B,EAAE,OAAO,QAAQ,SAA0C;CAClG,MAAM,SAAS,UAAU,KAAA,IAAY,OAAO,oBAAoB,KAAK,MAAM,KAAK;CAChF,MAAM,OAAO,QAAQ,QAAQ,WAAW,KAAK,MAAM,OAAO,UAAU,IAAI,KAAK,MAAM;CACnF,OAAO;EAAE,SAAS,KAAK,MAAM,QAAQ,SAAS,KAAK;EAAG,SAAS,KAAK,SAAS,SAAS;CAAM;AAC9F;;AAGA,eAAe,YAAY,QAAsB,OAAkC;CACjF,MAAM,0BAAU,IAAI,IAAoB,CAAC,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC;CAC5D,IAAI,WAAW,CAAC,KAAK;CACrB,OAAO,SAAS,SAAS,GAAG;EAC1B,MAAM,SAAS,CAAC,GAAG,IAAI,IAAI,SAAS,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,QACvE,QAAQ,CAAC,QAAQ,IAAI,GAAG,CAC3B;EAEA,YAAW,MADQ,QAAQ,IAAI,OAAO,KAAK,QAAQ,OAAO,OAAO,GAAG,CAAC,CAAC,EAAA,CACtD,QAAQ,WAAW,WAAW,IAAI;EAClD,KAAK,MAAM,UAAU,UAAU,QAAQ,IAAI,OAAO,KAAK,MAAM;CAC/D;CACA,OAAO,aAAa,QAAQ,QAAQ,IAAI,GAAG,GAAG,MAAM,GAAG;AACzD;;;;;;;;;;;;;;;;;;;;AAqBA,eAAsB,YACpB,QACA,OACA,SACsB;CACtB,IAAI;EACF,OAAO,MAAM,YAAY,QAAQ,OAAO,OAAO;CACjD,SAAS,OAAO;EACd,IAAI,EAAE,iBAAiB,WAAW,MAAM;EACxC,OAAO,IAAI,MAAM,YAAY,QAAQ,KAAK,GAAG,OAAO;CACtD;AACF;AAEA,eAAe,YACb,QACA,OACA,SACsB;CACtB,MAAM,SAAS,QAAQ,SAAS,QAAQ,QAAQ;CAChD,MAAM,UAAU,QAAQ,UAAU,KAAA,IAAY,OAAO,oBAAoB,KAAK,MAAM,QAAQ,KAAK;CACjG,MAAM,0BAAU,IAAI,IAAoB,CAAC,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC;CAC5D,MAAM,6BAAa,IAAI,IAAoB,CAAC,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC;CAC/D,MAAM,kCAAkB,IAAI,IAAoB;CAChD,MAAM,QAAkB,CAAC,KAAK;CAC9B,MAAM,UAAoB,CAAC;CAC3B,IAAI,OAAO;CAEX,MAAM,SAAS,OAAO,WAAkC;EACtD,WAAW,OAAO,OAAO,GAAG;EAC5B,MAAM,UAAU,MAAM,QAAQ,IAC5B,OAAO,QAAQ,IAAI,OAAO,QAAQ,QAAQ,IAAI,GAAG,KAAK,OAAO,OAAO,GAAG,CAAC,CAC1E;EACA,OAAO,QAAQ,SAAS,KAAK,UAAU;GACrC,gBAAgB,IAAI,MAAM,gBAAgB,IAAI,GAAG,KAAK,KAAK,CAAC;GAC5D,MAAM,KAAK,MAAM,WAAW,cAAc,UAAU,QAAQ,GAAG;GAC/D,IAAI,OAAO,IAAI,MAAM,OAAO,IAAI,CAAC;GACjC,MAAM,SAAS,QAAQ;GACvB,IAAI,WAAW,QAAQ,WAAW,KAAA,GAAW;GAC7C,IAAI,UAAU,QAAQ,MAAM,IAAI,GAAG,MAAM,IAAI,SAAS;GACtD,IAAI,CAAC,QAAQ,IAAI,GAAG,GAAG;IACrB,QAAQ,IAAI,KAAK,MAAM;IACvB,WAAW,IAAI,KAAK,MAAM;GAC5B;EACF,CAAC;CACH;CACA,MAAM,WAAW,WACf,CAAC,GAAG,WAAW,OAAO,CAAC,CAAC,CAAC,OAAO,UAAU,MAAM,QAAQ,OAAO,OAAO,UAAU,OAAO,MAAM,IAAI,CAAC;CACpG,MAAM,yBACJ,MAAM,OAAO,WAAW,KAAK,MAAM,OAAO,UAAU,IAAI,IAAI,OAAO,KACnE,CAAC,GAAG,WAAW,OAAO,CAAC,CAAC,CAAC,OACtB,WAAW,KAAK,MAAM,OAAO,UAAU,IAAI,IAAI,UAAU,qBAC5D;CAEF,OAAO,MAAM,SAAS,KAAK,OAAO,UAAU,CAAC,iBAAiB,GAAG;EAC/D,MAAM,OAAO,MAAM,cAAc,KAAK;EACtC,IAAI,SAAS,KAAA,GAAW;EACxB,IAAI,WAAW,IAAI,KAAK,GAAG,GAAG;GAC5B,MAAM,OAAO,IAAI;GACjB;EACF;EACA,MAAM,SAAS,MAAM,QAAQ,WAAW,UAAU,QAAQ,IAAI,MAAM,CAAC;EACrE,MAAM,OAAO,MAAM,GAAG,EAAE;EAIxB,IAAI,EAFF,OAAO,MAAM,OAAO,MACnB,OAAO,WAAW,KAAK,SAAS,KAAA,KAAa,UAAU,MAAM,IAAI,MAAM,KAAK,QAAQ,IAAI,KAChF;GACT,IAAI;GACJ,KAAK,MAAM,UAAU,WAAW,OAAO,GACrC,IAAI,SAAS,KAAA,KAAa,UAAU,QAAQ,IAAI,IAAI,GAAG,OAAO;GAChE,IAAI,SAAS,KAAA,GAAW;IACtB,MAAM,OAAO,IAAI;IACjB;GACF;EACF;EACA,MAAM,OAAO,MAAM,QAAQ,IAAI,GAAG,CAAC;EACnC,QAAQ,KAAK,IAAI;EACjB,IAAI,KAAK,MAAM,KAAK,UAAU,IAAI,KAAK,SAAS,QAAQ;EACxD,KAAK,MAAM,OAAO,KAAK,SAAS;GAC9B,MAAM,QAAQ,gBAAgB,IAAI,GAAG,KAAK,KAAK;GAC/C,gBAAgB,IAAI,KAAK,IAAI;GAC7B,MAAM,SAAS,QAAQ,IAAI,GAAG;GAC9B,IAAI,SAAS,KAAK,WAAW,KAAA,GAAW,MAAM,KAAK,MAAM;EAC3D;CACF;CACA,OAAO,IAAI,SAAS,OAAO;AAC7B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as GatewayContext } from "../gateway-context-Boh9I0mk.js";
|
|
2
|
+
import { RpcOutput, RpcParsedInput } from "@leed-ai/git-gateway-contract/git-gateway";
|
|
3
|
+
/** createRepo(): an empty repository on the backend; repo_exists when the name is taken. */
|
|
4
|
+
export declare function gatewayCreateRepo(context: GatewayContext, { repo, defaultBranch }: RpcParsedInput<'createRepo'>): Promise<RpcOutput<'createRepo'>>;
|
|
5
|
+
/** deleteRepo(): deletes the repository; `deleted` is false when there was none. */
|
|
6
|
+
export declare function gatewayDeleteRepo(context: GatewayContext, { repo }: RpcParsedInput<'deleteRepo'>): Promise<RpcOutput<'deleteRepo'>>;
|
|
7
|
+
/**
|
|
8
|
+
* mintReadToken(): a signed, short-lived credential that reads one repository through the
|
|
9
|
+
* gateway (see `verifyReadToken`). It is not a storage-host credential and grants no write.
|
|
10
|
+
*/
|
|
11
|
+
export declare function gatewayMintReadToken(context: GatewayContext, { repo, ttlSeconds }: RpcParsedInput<'mintReadToken'>): Promise<RpcOutput<'mintReadToken'>>;
|
|
12
|
+
//# sourceMappingURL=lifecycle-methods.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { mintReadToken } from "./read-token.js";
|
|
2
|
+
import { requireRepo } from "./repo-access.js";
|
|
3
|
+
import { remoteUrlOf } from "@leed-ai/git-gateway-contract/reference/repo-state";
|
|
4
|
+
// src/rpc/lifecycle-methods.ts
|
|
5
|
+
/** createRepo(): an empty repository on the backend; repo_exists when the name is taken. */
|
|
6
|
+
async function gatewayCreateRepo(context, { repo, defaultBranch }) {
|
|
7
|
+
const info = await context.backend.createRepo(repo, { defaultBranch });
|
|
8
|
+
return {
|
|
9
|
+
name: info.name,
|
|
10
|
+
defaultBranch: info.defaultBranch,
|
|
11
|
+
createdAt: info.createdAt ?? context.now().toISOString(),
|
|
12
|
+
remoteUrl: remoteUrlOf(context.config, info.name)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** deleteRepo(): deletes the repository; `deleted` is false when there was none. */
|
|
16
|
+
async function gatewayDeleteRepo(context, { repo }) {
|
|
17
|
+
if (await context.backend.repoInfo(repo) === null) return { deleted: false };
|
|
18
|
+
await context.backend.deleteRepo(repo);
|
|
19
|
+
return { deleted: true };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* mintReadToken(): a signed, short-lived credential that reads one repository through the
|
|
23
|
+
* gateway (see `verifyReadToken`). It is not a storage-host credential and grants no write.
|
|
24
|
+
*/
|
|
25
|
+
async function gatewayMintReadToken(context, { repo, ttlSeconds }) {
|
|
26
|
+
await requireRepo(context, repo);
|
|
27
|
+
return {
|
|
28
|
+
...await mintReadToken({
|
|
29
|
+
repo,
|
|
30
|
+
ttlSeconds,
|
|
31
|
+
secret: context.readTokenSecret,
|
|
32
|
+
now: context.now()
|
|
33
|
+
}),
|
|
34
|
+
remoteUrl: remoteUrlOf(context.config, repo)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export { gatewayCreateRepo, gatewayDeleteRepo, gatewayMintReadToken };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=lifecycle-methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-methods.js","names":[],"sources":["../../src/rpc/lifecycle-methods.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { RpcOutput, RpcParsedInput } from '@leed-ai/git-gateway-contract/git-gateway';\nimport { remoteUrlOf } from '@leed-ai/git-gateway-contract/reference/repo-state';\n\nimport type { GatewayContext } from './gateway-context.ts';\nimport { mintReadToken } from './read-token.ts';\nimport { requireRepo } from './repo-access.ts';\n\n/** createRepo(): an empty repository on the backend; repo_exists when the name is taken. */\nexport async function gatewayCreateRepo(\n context: GatewayContext,\n { repo, defaultBranch }: RpcParsedInput<'createRepo'>,\n): Promise<RpcOutput<'createRepo'>> {\n const info = await context.backend.createRepo(repo, { defaultBranch });\n return {\n name: info.name,\n defaultBranch: info.defaultBranch,\n // A host that does not report creation times created the repository just now.\n createdAt: info.createdAt ?? context.now().toISOString(),\n remoteUrl: remoteUrlOf(context.config, info.name),\n };\n}\n\n/** deleteRepo(): deletes the repository; `deleted` is false when there was none. */\nexport async function gatewayDeleteRepo(\n context: GatewayContext,\n { repo }: RpcParsedInput<'deleteRepo'>,\n): Promise<RpcOutput<'deleteRepo'>> {\n if ((await context.backend.repoInfo(repo)) === null) return { deleted: false };\n await context.backend.deleteRepo(repo);\n return { deleted: true };\n}\n\n/**\n * mintReadToken(): a signed, short-lived credential that reads one repository through the\n * gateway (see `verifyReadToken`). It is not a storage-host credential and grants no write.\n */\nexport async function gatewayMintReadToken(\n context: GatewayContext,\n { repo, ttlSeconds }: RpcParsedInput<'mintReadToken'>,\n): Promise<RpcOutput<'mintReadToken'>> {\n await requireRepo(context, repo);\n const minted = await mintReadToken({\n repo,\n ttlSeconds,\n secret: context.readTokenSecret,\n now: context.now(),\n });\n return { ...minted, remoteUrl: remoteUrlOf(context.config, repo) };\n}\n"],"mappings":";;;;;AASA,eAAsB,kBACpB,SACA,EAAE,MAAM,iBAC0B;CAClC,MAAM,OAAO,MAAM,QAAQ,QAAQ,WAAW,MAAM,EAAE,cAAc,CAAC;CACrE,OAAO;EACL,MAAM,KAAK;EACX,eAAe,KAAK;EAEpB,WAAW,KAAK,aAAa,QAAQ,IAAI,CAAC,CAAC,YAAY;EACvD,WAAW,YAAY,QAAQ,QAAQ,KAAK,IAAI;CAClD;AACF;;AAGA,eAAsB,kBACpB,SACA,EAAE,QACgC;CAClC,IAAK,MAAM,QAAQ,QAAQ,SAAS,IAAI,MAAO,MAAM,OAAO,EAAE,SAAS,MAAM;CAC7E,MAAM,QAAQ,QAAQ,WAAW,IAAI;CACrC,OAAO,EAAE,SAAS,KAAK;AACzB;;;;;AAMA,eAAsB,qBACpB,SACA,EAAE,MAAM,cAC6B;CACrC,MAAM,YAAY,SAAS,IAAI;CAO/B,OAAO;EAAE,GAAG,MANS,cAAc;GACjC;GACA;GACA,QAAQ,QAAQ;GAChB,KAAK,QAAQ,IAAI;EACnB,CAAC;EACmB,WAAW,YAAY,QAAQ,QAAQ,IAAI;CAAE;AACnE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CommitSource } from "./commit-source.js";
|
|
2
|
+
import { Commit } from "@leed-ai/git-gateway-contract/schemas/commit";
|
|
3
|
+
/**
|
|
4
|
+
* True when `ancestor` is reachable from `descendant` (a commit contains itself), as the
|
|
5
|
+
* reference's `contains` answers it; false when either commit is missing. Reads only the history
|
|
6
|
+
* between the two commits and their merge base, whichever way the answer goes.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isAncestor(source: CommitSource, descendant: string, ancestor: string): Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Every best common ancestor of two commits — a common ancestor no other common ancestor descends
|
|
11
|
+
* from — ranked as the reference's `mergeBase` ranks them: newest committer date first, then the
|
|
12
|
+
* lowest id. Empty when the histories are unrelated or either commit is missing.
|
|
13
|
+
*/
|
|
14
|
+
export declare function bestCommonAncestors(source: CommitSource, a: string, b: string): Promise<Commit[]>;
|
|
15
|
+
/** The best common ancestor of two commits as the reference's `mergeBase` picks it, or null. */
|
|
16
|
+
export declare function mergeBaseOf(source: CommitSource, a: string, b: string): Promise<string | null>;
|
|
17
|
+
//# sourceMappingURL=paint-down.d.ts.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { dateOrder } from "./commit-source.js";
|
|
2
|
+
// src/rpc/paint-down.ts
|
|
3
|
+
/** Reached from the first commit. */
|
|
4
|
+
const ONE = 1;
|
|
5
|
+
/** Reached from the second commit. */
|
|
6
|
+
const TWO = 2;
|
|
7
|
+
/** Reached through a common ancestor, so an ancestor of one: never a best common ancestor. */
|
|
8
|
+
const STALE = 4;
|
|
9
|
+
const BOTH = 3;
|
|
10
|
+
/**
|
|
11
|
+
* Git's paint-down-to-common walk. Both commits are walked back together, newest committer date
|
|
12
|
+
* first, each commit painted with the side(s) it was reached from. A commit reached from both is a
|
|
13
|
+
* common ancestor, and everything beneath it is painted stale. The walk ends once every queued
|
|
14
|
+
* commit is stale: any commit not yet reached then lies beneath a common ancestor, so it can be
|
|
15
|
+
* neither a best common ancestor nor on the way to one. Only the history between the two heads
|
|
16
|
+
* and their merge base is read, never the whole history — unless the histories are unrelated.
|
|
17
|
+
* When `stopAt` is given, the walk ends as soon as that commit is reached from the second commit.
|
|
18
|
+
*/
|
|
19
|
+
async function paintDown(source, one, two, stopAt) {
|
|
20
|
+
const flags = /* @__PURE__ */ new Map();
|
|
21
|
+
const commits = /* @__PURE__ */ new Map();
|
|
22
|
+
const queue = [];
|
|
23
|
+
const reachedBoth = [];
|
|
24
|
+
const paint = (commit, add) => {
|
|
25
|
+
const had = flags.get(commit.sha) ?? 0;
|
|
26
|
+
if ((had & add) === add) return;
|
|
27
|
+
flags.set(commit.sha, had | add);
|
|
28
|
+
commits.set(commit.sha, commit);
|
|
29
|
+
if (!queue.some((queued) => queued.sha === commit.sha)) queue.push(commit);
|
|
30
|
+
};
|
|
31
|
+
const isStale = (commit) => ((flags.get(commit.sha) ?? 0) & STALE) !== 0;
|
|
32
|
+
const stopped = () => stopAt !== null && ((flags.get(stopAt) ?? 0) & TWO) !== 0;
|
|
33
|
+
paint(one, ONE);
|
|
34
|
+
paint(two, TWO);
|
|
35
|
+
while (!stopped() && queue.some((commit) => !isStale(commit))) {
|
|
36
|
+
let newest = 0;
|
|
37
|
+
queue.forEach((commit, index) => {
|
|
38
|
+
const best = queue[newest];
|
|
39
|
+
if (best !== void 0 && dateOrder(commit, best) > 0) newest = index;
|
|
40
|
+
});
|
|
41
|
+
const [commit] = queue.splice(newest, 1);
|
|
42
|
+
if (commit === void 0) break;
|
|
43
|
+
let carried = flags.get(commit.sha) ?? 0;
|
|
44
|
+
if ((carried & 7) === BOTH) {
|
|
45
|
+
if (!reachedBoth.some((found) => found.sha === commit.sha)) reachedBoth.push(commit);
|
|
46
|
+
carried |= STALE;
|
|
47
|
+
}
|
|
48
|
+
const parents = await Promise.all(commit.parents.map(async (sha) => commits.get(sha) ?? source.commit(sha)));
|
|
49
|
+
for (const parent of parents) if (parent !== null) paint(parent, carried);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
stopped: stopped(),
|
|
53
|
+
candidates: reachedBoth.filter((commit) => !isStale(commit))
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* True when `ancestor` is reachable from `descendant` (a commit contains itself), as the
|
|
58
|
+
* reference's `contains` answers it; false when either commit is missing. Reads only the history
|
|
59
|
+
* between the two commits and their merge base, whichever way the answer goes.
|
|
60
|
+
*/
|
|
61
|
+
async function isAncestor(source, descendant, ancestor) {
|
|
62
|
+
const [below, above] = await Promise.all([source.commit(ancestor), source.commit(descendant)]);
|
|
63
|
+
if (below === null || above === null) return false;
|
|
64
|
+
if (below.sha === above.sha) return true;
|
|
65
|
+
return (await paintDown(source, below, above, below.sha)).stopped;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Every best common ancestor of two commits — a common ancestor no other common ancestor descends
|
|
69
|
+
* from — ranked as the reference's `mergeBase` ranks them: newest committer date first, then the
|
|
70
|
+
* lowest id. Empty when the histories are unrelated or either commit is missing.
|
|
71
|
+
*/
|
|
72
|
+
async function bestCommonAncestors(source, a, b) {
|
|
73
|
+
const [first, second] = await Promise.all([source.commit(a), source.commit(b)]);
|
|
74
|
+
if (first === null || second === null) return [];
|
|
75
|
+
const { candidates } = await paintDown(source, first, second, null);
|
|
76
|
+
const best = [];
|
|
77
|
+
for (const candidate of candidates) {
|
|
78
|
+
let beneathAnother = false;
|
|
79
|
+
for (const other of candidates) {
|
|
80
|
+
if (other.sha === candidate.sha) continue;
|
|
81
|
+
if (await isAncestor(source, other.sha, candidate.sha)) {
|
|
82
|
+
beneathAnother = true;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (!beneathAnother) best.push(candidate);
|
|
87
|
+
}
|
|
88
|
+
return best.toSorted((x, y) => dateOrder(y, x) || (x.sha < y.sha ? -1 : 1));
|
|
89
|
+
}
|
|
90
|
+
/** The best common ancestor of two commits as the reference's `mergeBase` picks it, or null. */
|
|
91
|
+
async function mergeBaseOf(source, a, b) {
|
|
92
|
+
return (await bestCommonAncestors(source, a, b))[0]?.sha ?? null;
|
|
93
|
+
}
|
|
94
|
+
export { bestCommonAncestors, isAncestor, mergeBaseOf };
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=paint-down.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paint-down.js","names":[],"sources":["../../src/rpc/paint-down.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { Commit } from '@leed-ai/git-gateway-contract/schemas/commit';\n\nimport { type CommitSource, dateOrder } from './commit-source.ts';\n\n/** Reached from the first commit. */\nconst ONE = 1;\n/** Reached from the second commit. */\nconst TWO = 2;\n/** Reached through a common ancestor, so an ancestor of one: never a best common ancestor. */\nconst STALE = 4;\nconst BOTH = ONE | TWO;\n\n/** What one paint-down walk found. */\ninterface Painted {\n /** True when the walk stopped because `stopAt` was reached from the second commit. */\n readonly stopped: boolean;\n /**\n * Common ancestors met before the walk ended that were not found to sit beneath another one.\n * Every best common ancestor is among them; a few non-best ones may be too.\n */\n readonly candidates: readonly Commit[];\n}\n\n/**\n * Git's paint-down-to-common walk. Both commits are walked back together, newest committer date\n * first, each commit painted with the side(s) it was reached from. A commit reached from both is a\n * common ancestor, and everything beneath it is painted stale. The walk ends once every queued\n * commit is stale: any commit not yet reached then lies beneath a common ancestor, so it can be\n * neither a best common ancestor nor on the way to one. Only the history between the two heads\n * and their merge base is read, never the whole history — unless the histories are unrelated.\n * When `stopAt` is given, the walk ends as soon as that commit is reached from the second commit.\n */\nasync function paintDown(\n source: CommitSource,\n one: Commit,\n two: Commit,\n stopAt: string | null,\n): Promise<Painted> {\n const flags = new Map<string, number>();\n const commits = new Map<string, Commit>();\n const queue: Commit[] = [];\n const reachedBoth: Commit[] = [];\n const paint = (commit: Commit, add: number): void => {\n const had = flags.get(commit.sha) ?? 0;\n if ((had & add) === add) return;\n flags.set(commit.sha, had | add);\n commits.set(commit.sha, commit);\n if (!queue.some((queued) => queued.sha === commit.sha)) queue.push(commit);\n };\n const isStale = (commit: Commit): boolean => ((flags.get(commit.sha) ?? 0) & STALE) !== 0;\n const stopped = (): boolean => stopAt !== null && ((flags.get(stopAt) ?? 0) & TWO) !== 0;\n\n paint(one, ONE);\n paint(two, TWO);\n while (!stopped() && queue.some((commit) => !isStale(commit))) {\n let newest = 0;\n queue.forEach((commit, index) => {\n const best = queue[newest];\n if (best !== undefined && dateOrder(commit, best) > 0) newest = index;\n });\n const [commit] = queue.splice(newest, 1);\n if (commit === undefined) break;\n let carried = flags.get(commit.sha) ?? 0;\n if ((carried & (BOTH | STALE)) === BOTH) {\n if (!reachedBoth.some((found) => found.sha === commit.sha)) reachedBoth.push(commit);\n carried |= STALE;\n }\n const parents = await Promise.all(\n commit.parents.map(async (sha) => commits.get(sha) ?? source.commit(sha)),\n );\n for (const parent of parents) if (parent !== null) paint(parent, carried);\n }\n return { stopped: stopped(), candidates: reachedBoth.filter((commit) => !isStale(commit)) };\n}\n\n/**\n * True when `ancestor` is reachable from `descendant` (a commit contains itself), as the\n * reference's `contains` answers it; false when either commit is missing. Reads only the history\n * between the two commits and their merge base, whichever way the answer goes.\n */\nexport async function isAncestor(\n source: CommitSource,\n descendant: string,\n ancestor: string,\n): Promise<boolean> {\n const [below, above] = await Promise.all([source.commit(ancestor), source.commit(descendant)]);\n if (below === null || above === null) return false;\n if (below.sha === above.sha) return true;\n return (await paintDown(source, below, above, below.sha)).stopped;\n}\n\n/**\n * Every best common ancestor of two commits — a common ancestor no other common ancestor descends\n * from — ranked as the reference's `mergeBase` ranks them: newest committer date first, then the\n * lowest id. Empty when the histories are unrelated or either commit is missing.\n */\nexport async function bestCommonAncestors(source: CommitSource, a: string, b: string): Promise<Commit[]> {\n const [first, second] = await Promise.all([source.commit(a), source.commit(b)]);\n if (first === null || second === null) return [];\n const { candidates } = await paintDown(source, first, second, null);\n const best: Commit[] = [];\n for (const candidate of candidates) {\n let beneathAnother = false;\n for (const other of candidates) {\n if (other.sha === candidate.sha) continue;\n if (await isAncestor(source, other.sha, candidate.sha)) {\n beneathAnother = true;\n break;\n }\n }\n if (!beneathAnother) best.push(candidate);\n }\n return best.toSorted((x, y) => dateOrder(y, x) || (x.sha < y.sha ? -1 : 1));\n}\n\n/** The best common ancestor of two commits as the reference's `mergeBase` picks it, or null. */\nexport async function mergeBaseOf(source: CommitSource, a: string, b: string): Promise<string | null> {\n return (await bestCommonAncestors(source, a, b))[0]?.sha ?? null;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { t as GatewayContext } from "../gateway-context-Boh9I0mk.js";
|
|
2
|
+
import { RpcOutput, RpcParsedInput } from "@leed-ai/git-gateway-contract/git-gateway";
|
|
3
|
+
/** promote() input after parsing. */
|
|
4
|
+
export type PromoteParams = RpcParsedInput<'promote'>;
|
|
5
|
+
/** The outcome of one promote attempt. */
|
|
6
|
+
export type PromoteAttempt = {
|
|
7
|
+
readonly kind: 'done';
|
|
8
|
+
readonly output: RpcOutput<'promote'>;
|
|
9
|
+
} |
|
|
10
|
+
/** `into` moved between the checks and the push; `intoHead` is what the push named. */
|
|
11
|
+
{
|
|
12
|
+
readonly kind: 'stale';
|
|
13
|
+
readonly intoHead: string | null;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* One attempt at promote(): refuses unless `sha` is the head of `from` (not_head_of_source) and
|
|
17
|
+
* contains the head of `into` (not_fast_forward); otherwise moves `into` to `sha` with an update
|
|
18
|
+
* naming its current head (or creates it). Never merges, never forces.
|
|
19
|
+
*/
|
|
20
|
+
export declare function attemptPromote(context: GatewayContext, input: PromoteParams): Promise<PromoteAttempt>;
|
|
21
|
+
//# sourceMappingURL=promote-attempt.d.ts.map
|