@shipfox/api-workflows 13.0.0 → 14.0.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/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +46 -0
- package/README.md +12 -5
- package/dist/core/checkout.d.ts +4 -2
- package/dist/core/checkout.d.ts.map +1 -1
- package/dist/core/checkout.js +7 -2
- package/dist/core/checkout.js.map +1 -1
- package/dist/core/entities/job.d.ts +1 -1
- package/dist/core/entities/job.d.ts.map +1 -1
- package/dist/core/entities/job.js.map +1 -1
- package/dist/core/entities/workflow-run.d.ts +23 -4
- package/dist/core/entities/workflow-run.d.ts.map +1 -1
- package/dist/core/entities/workflow-run.js.map +1 -1
- package/dist/core/errors.d.ts +9 -1
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +5 -1
- package/dist/core/errors.js.map +1 -1
- package/dist/core/job-execution.d.ts.map +1 -1
- package/dist/core/job-execution.js +12 -2
- package/dist/core/job-execution.js.map +1 -1
- package/dist/core/run-workflow.js +1 -1
- package/dist/core/run-workflow.js.map +1 -1
- package/dist/core/step-config/agent.d.ts.map +1 -1
- package/dist/core/step-config/agent.js +9 -1
- package/dist/core/step-config/agent.js.map +1 -1
- package/dist/db/db.d.ts +72 -0
- package/dist/db/db.d.ts.map +1 -1
- package/dist/db/schema/workflow-runs.d.ts +45 -1
- package/dist/db/schema/workflow-runs.d.ts.map +1 -1
- package/dist/db/schema/workflow-runs.js +42 -1
- package/dist/db/schema/workflow-runs.js.map +1 -1
- package/dist/db/workflow-runs/jobs.d.ts +3 -1
- package/dist/db/workflow-runs/jobs.d.ts.map +1 -1
- package/dist/db/workflow-runs/jobs.js +12 -3
- package/dist/db/workflow-runs/jobs.js.map +1 -1
- package/dist/db/workflow-runs/queries.d.ts +3 -2
- package/dist/db/workflow-runs/queries.d.ts.map +1 -1
- package/dist/db/workflow-runs/queries.js +3 -0
- package/dist/db/workflow-runs/queries.js.map +1 -1
- package/dist/presentation/dto/step.d.ts.map +1 -1
- package/dist/presentation/dto/step.js +14 -0
- package/dist/presentation/dto/step.js.map +1 -1
- package/dist/presentation/dto/workflow-run.d.ts.map +1 -1
- package/dist/presentation/dto/workflow-run.js +14 -0
- package/dist/presentation/dto/workflow-run.js.map +1 -1
- package/dist/presentation/routes/agent-runtime-config.d.ts.map +1 -1
- package/dist/presentation/routes/agent-runtime-config.js +22 -0
- package/dist/presentation/routes/agent-runtime-config.js.map +1 -1
- package/dist/presentation/routes/checkout-token.d.ts.map +1 -1
- package/dist/presentation/routes/checkout-token.js +2 -1
- package/dist/presentation/routes/checkout-token.js.map +1 -1
- package/dist/presentation/routes/get-run-aggregates.d.ts.map +1 -1
- package/dist/presentation/routes/get-run-aggregates.js +2 -1
- package/dist/presentation/routes/get-run-aggregates.js.map +1 -1
- package/dist/presentation/routes/leased-step.d.ts +3 -1
- package/dist/presentation/routes/leased-step.d.ts.map +1 -1
- package/dist/presentation/routes/leased-step.js +2 -1
- package/dist/presentation/routes/leased-step.js.map +1 -1
- package/dist/presentation/routes/list-runs.d.ts.map +1 -1
- package/dist/presentation/routes/list-runs.js +2 -1
- package/dist/presentation/routes/list-runs.js.map +1 -1
- package/dist/presentation/routes/project-access.d.ts +1 -0
- package/dist/presentation/routes/project-access.d.ts.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/drizzle/0004_dev_run_origin.sql +12 -0
- package/drizzle/meta/0004_snapshot.json +1773 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +10 -10
- package/src/core/checkout.test.ts +198 -1
- package/src/core/checkout.ts +18 -5
- package/src/core/entities/job.ts +1 -1
- package/src/core/entities/workflow-run.ts +22 -4
- package/src/core/errors.ts +17 -2
- package/src/core/job-execution.test.ts +54 -0
- package/src/core/job-execution.ts +6 -1
- package/src/core/job-transition/decide-job-activation.test.ts +2 -0
- package/src/core/run-workflow.test.ts +50 -1
- package/src/core/run-workflow.ts +1 -1
- package/src/core/step-config/agent.ts +8 -1
- package/src/core/step-config/complete-step-dispatch-config.test.ts +37 -0
- package/src/core/workflow-run-creation.test.ts +2 -0
- package/src/db/job-listeners.test.ts +17 -0
- package/src/db/schema/workflow-runs.ts +58 -0
- package/src/db/workflow-runs/jobs.ts +17 -3
- package/src/db/workflow-runs/queries.ts +6 -1
- package/src/db/workflow-runs/run-create.test.ts +39 -0
- package/src/presentation/dto/step.test.ts +8 -0
- package/src/presentation/dto/step.ts +9 -0
- package/src/presentation/dto/workflow-run.ts +23 -1
- package/src/presentation/routes/agent-runtime-config.test.ts +84 -2
- package/src/presentation/routes/agent-runtime-config.ts +24 -0
- package/src/presentation/routes/checkout-token.test.ts +45 -0
- package/src/presentation/routes/checkout-token.ts +2 -1
- package/src/presentation/routes/get-run-aggregates.test.ts +56 -0
- package/src/presentation/routes/get-run-aggregates.ts +2 -0
- package/src/presentation/routes/get-step-secrets.test.ts +1 -0
- package/src/presentation/routes/leased-step.ts +7 -1
- package/src/presentation/routes/list-runs.test.ts +152 -0
- package/src/presentation/routes/list-runs.ts +2 -0
- package/test/factories/workflow-run.ts +2 -0
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { type LeasedJobContext } from '@shipfox/api-auth-context';
|
|
2
2
|
import type { RunnersInterModuleClient } from '@shipfox/api-runners-dto/inter-module';
|
|
3
3
|
import type { Step } from '#core/entities/step.js';
|
|
4
|
-
import type { WorkflowRunTriggerReference } from '#core/entities/workflow-run.js';
|
|
4
|
+
import type { WorkflowRunOriginState, WorkflowRunTriggerReference } from '#core/entities/workflow-run.js';
|
|
5
5
|
export interface LoadedRunningLeasedStep {
|
|
6
6
|
leasedJob: LeasedJobContext;
|
|
7
7
|
step: Step;
|
|
8
8
|
workspaceId: string;
|
|
9
9
|
projectId: string;
|
|
10
10
|
triggerReference: WorkflowRunTriggerReference | null;
|
|
11
|
+
/** The run's origin state, forwarded for checkout fallbacks. */
|
|
12
|
+
run: WorkflowRunOriginState;
|
|
11
13
|
}
|
|
12
14
|
export declare function loadRunningLeasedStep(params: {
|
|
13
15
|
runners: RunnersInterModuleClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leased-step.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/leased-step.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,gBAAgB,EAA0B,MAAM,2BAA2B,CAAC;AACzF,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AAEpF,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AACjD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"leased-step.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/leased-step.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,gBAAgB,EAA0B,MAAM,2BAA2B,CAAC;AACzF,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AAEpF,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AACjD,OAAO,KAAK,EACV,sBAAsB,EACtB,2BAA2B,EAC5B,MAAM,gCAAgC,CAAC;AAGxC,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,gBAAgB,CAAC;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,2BAA2B,GAAG,IAAI,CAAC;IACrD,gEAAgE;IAChE,GAAG,EAAE,sBAAsB,CAAC;CAC7B;AAED,wBAAsB,qBAAqB,CAAC,MAAM,EAAE;IAClD,OAAO,EAAE,wBAAwB,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CA2CnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/routes/leased-step.ts"],"sourcesContent":["import {type LeasedJobContext, requireLeasedJobContext} from '@shipfox/api-auth-context';\nimport type {RunnersInterModuleClient} from '@shipfox/api-runners-dto/inter-module';\nimport {ClientError} from '@shipfox/node-fastify';\nimport type {Step} from '#core/entities/step.js';\nimport type {WorkflowRunTriggerReference} from '#core/entities/workflow-run.js';\nimport {getJobScope, getStepByIdForJobExecution} from '#db/index.js';\n\nexport interface LoadedRunningLeasedStep {\n leasedJob: LeasedJobContext;\n step: Step;\n workspaceId: string;\n projectId: string;\n triggerReference: WorkflowRunTriggerReference | null;\n}\n\nexport async function loadRunningLeasedStep(params: {\n runners: RunnersInterModuleClient;\n request: object;\n stepId: string;\n attempt: number;\n}): Promise<LoadedRunningLeasedStep> {\n const leasedJob = requireLeasedJobContext(params.request);\n\n const {active: leaseIsActive} = await params.runners.getLeaseState({\n jobId: leasedJob.jobId,\n jobExecutionId: leasedJob.jobExecutionId,\n runnerSessionId: leasedJob.runnerSessionId,\n });\n if (!leaseIsActive) {\n throw new ClientError('Job lease is no longer active', 'lease-not-active', {status: 404});\n }\n\n const step = await getStepByIdForJobExecution({\n stepId: params.stepId,\n jobExecutionId: leasedJob.jobExecutionId,\n });\n if (!step) {\n throw new ClientError('Step not found for leased job', 'step-not-found', {status: 404});\n }\n\n const scope = await getJobScope(leasedJob.jobId);\n if (!scope) {\n throw new ClientError('Leased job not found', 'job-not-found', {status: 404});\n }\n\n if (step.currentAttempt !== params.attempt) {\n throw new ClientError('Step attempt does not match current attempt', 'step-attempt-mismatch', {\n status: 409,\n });\n }\n\n if (step.status !== 'running') {\n throw new ClientError('Step is not running', 'step-not-running', {status: 409});\n }\n\n return {\n leasedJob,\n step,\n workspaceId: scope.workspaceId,\n projectId: scope.projectId,\n triggerReference: scope.triggerReference,\n };\n}\n"],"names":["requireLeasedJobContext","ClientError","getJobScope","getStepByIdForJobExecution","loadRunningLeasedStep","params","leasedJob","request","active","leaseIsActive","runners","getLeaseState","jobId","jobExecutionId","runnerSessionId","status","step","stepId","scope","currentAttempt","attempt","workspaceId","projectId","triggerReference"],"mappings":"AAAA,SAA+BA,uBAAuB,QAAO,4BAA4B;AAEzF,SAAQC,WAAW,QAAO,wBAAwB;
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/leased-step.ts"],"sourcesContent":["import {type LeasedJobContext, requireLeasedJobContext} from '@shipfox/api-auth-context';\nimport type {RunnersInterModuleClient} from '@shipfox/api-runners-dto/inter-module';\nimport {ClientError} from '@shipfox/node-fastify';\nimport type {Step} from '#core/entities/step.js';\nimport type {\n WorkflowRunOriginState,\n WorkflowRunTriggerReference,\n} from '#core/entities/workflow-run.js';\nimport {getJobScope, getStepByIdForJobExecution} from '#db/index.js';\n\nexport interface LoadedRunningLeasedStep {\n leasedJob: LeasedJobContext;\n step: Step;\n workspaceId: string;\n projectId: string;\n triggerReference: WorkflowRunTriggerReference | null;\n /** The run's origin state, forwarded for checkout fallbacks. */\n run: WorkflowRunOriginState;\n}\n\nexport async function loadRunningLeasedStep(params: {\n runners: RunnersInterModuleClient;\n request: object;\n stepId: string;\n attempt: number;\n}): Promise<LoadedRunningLeasedStep> {\n const leasedJob = requireLeasedJobContext(params.request);\n\n const {active: leaseIsActive} = await params.runners.getLeaseState({\n jobId: leasedJob.jobId,\n jobExecutionId: leasedJob.jobExecutionId,\n runnerSessionId: leasedJob.runnerSessionId,\n });\n if (!leaseIsActive) {\n throw new ClientError('Job lease is no longer active', 'lease-not-active', {status: 404});\n }\n\n const step = await getStepByIdForJobExecution({\n stepId: params.stepId,\n jobExecutionId: leasedJob.jobExecutionId,\n });\n if (!step) {\n throw new ClientError('Step not found for leased job', 'step-not-found', {status: 404});\n }\n\n const scope = await getJobScope(leasedJob.jobId);\n if (!scope) {\n throw new ClientError('Leased job not found', 'job-not-found', {status: 404});\n }\n\n if (step.currentAttempt !== params.attempt) {\n throw new ClientError('Step attempt does not match current attempt', 'step-attempt-mismatch', {\n status: 409,\n });\n }\n\n if (step.status !== 'running') {\n throw new ClientError('Step is not running', 'step-not-running', {status: 409});\n }\n\n return {\n leasedJob,\n step,\n workspaceId: scope.workspaceId,\n projectId: scope.projectId,\n triggerReference: scope.triggerReference,\n run: scope.run,\n };\n}\n"],"names":["requireLeasedJobContext","ClientError","getJobScope","getStepByIdForJobExecution","loadRunningLeasedStep","params","leasedJob","request","active","leaseIsActive","runners","getLeaseState","jobId","jobExecutionId","runnerSessionId","status","step","stepId","scope","currentAttempt","attempt","workspaceId","projectId","triggerReference","run"],"mappings":"AAAA,SAA+BA,uBAAuB,QAAO,4BAA4B;AAEzF,SAAQC,WAAW,QAAO,wBAAwB;AAMlD,SAAQC,WAAW,EAAEC,0BAA0B,QAAO,eAAe;AAYrE,OAAO,eAAeC,sBAAsBC,MAK3C;IACC,MAAMC,YAAYN,wBAAwBK,OAAOE,OAAO;IAExD,MAAM,EAACC,QAAQC,aAAa,EAAC,GAAG,MAAMJ,OAAOK,OAAO,CAACC,aAAa,CAAC;QACjEC,OAAON,UAAUM,KAAK;QACtBC,gBAAgBP,UAAUO,cAAc;QACxCC,iBAAiBR,UAAUQ,eAAe;IAC5C;IACA,IAAI,CAACL,eAAe;QAClB,MAAM,IAAIR,YAAY,iCAAiC,oBAAoB;YAACc,QAAQ;QAAG;IACzF;IAEA,MAAMC,OAAO,MAAMb,2BAA2B;QAC5Cc,QAAQZ,OAAOY,MAAM;QACrBJ,gBAAgBP,UAAUO,cAAc;IAC1C;IACA,IAAI,CAACG,MAAM;QACT,MAAM,IAAIf,YAAY,iCAAiC,kBAAkB;YAACc,QAAQ;QAAG;IACvF;IAEA,MAAMG,QAAQ,MAAMhB,YAAYI,UAAUM,KAAK;IAC/C,IAAI,CAACM,OAAO;QACV,MAAM,IAAIjB,YAAY,wBAAwB,iBAAiB;YAACc,QAAQ;QAAG;IAC7E;IAEA,IAAIC,KAAKG,cAAc,KAAKd,OAAOe,OAAO,EAAE;QAC1C,MAAM,IAAInB,YAAY,+CAA+C,yBAAyB;YAC5Fc,QAAQ;QACV;IACF;IAEA,IAAIC,KAAKD,MAAM,KAAK,WAAW;QAC7B,MAAM,IAAId,YAAY,uBAAuB,oBAAoB;YAACc,QAAQ;QAAG;IAC/E;IAEA,OAAO;QACLT;QACAU;QACAK,aAAaH,MAAMG,WAAW;QAC9BC,WAAWJ,MAAMI,SAAS;QAC1BC,kBAAkBL,MAAMK,gBAAgB;QACxCC,KAAKN,MAAMM,GAAG;IAChB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-runs.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/list-runs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAYjF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"list-runs.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/list-runs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAYjF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,oBAAoB,mDA0E3D"}
|
|
@@ -18,7 +18,7 @@ export function listRunsRoute(projects) {
|
|
|
18
18
|
},
|
|
19
19
|
handler: async (request)=>{
|
|
20
20
|
const startedAt = performance.now();
|
|
21
|
-
const { project_id: projectId, limit, cursor, status, definition_id: definitionId, trigger_source: triggerSource, created_from: createdFrom, created_to: createdTo } = request.query;
|
|
21
|
+
const { project_id: projectId, limit, cursor, status, definition_id: definitionId, trigger_source: triggerSource, origin, created_from: createdFrom, created_to: createdTo } = request.query;
|
|
22
22
|
const decodedCursor = decodeTimestampIdCursor(cursor);
|
|
23
23
|
if (cursor && !decodedCursor) {
|
|
24
24
|
throw new ClientError('Invalid cursor', 'invalid-cursor', {
|
|
@@ -30,6 +30,7 @@ export function listRunsRoute(projects) {
|
|
|
30
30
|
status,
|
|
31
31
|
definitionId,
|
|
32
32
|
triggerSource,
|
|
33
|
+
origin,
|
|
33
34
|
createdFrom: createdFrom ? new Date(createdFrom) : undefined,
|
|
34
35
|
createdTo: createdTo ? new Date(createdTo) : undefined
|
|
35
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/routes/list-runs.ts"],"sourcesContent":["import type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';\nimport {\n workflowRunListQuerySchema,\n workflowRunListResponseSchema,\n} from '@shipfox/api-workflows-dto';\nimport {decodeTimestampIdCursor, encodeTimestampIdCursor} from '@shipfox/node-drizzle';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport {listWorkflowRunJobSummaries, listWorkflowRuns} from '#db/index.js';\nimport {toRunListItemDto} from '#presentation/dto/index.js';\nimport {requireProjectAccess} from './project-access.js';\n\nexport function listRunsRoute(projects: ProjectsModuleClient) {\n return defineRoute({\n method: 'GET',\n path: '/',\n description: 'List workflow runs for a project',\n schema: {\n querystring: workflowRunListQuerySchema,\n response: {\n 200: workflowRunListResponseSchema,\n },\n },\n handler: async (request) => {\n const startedAt = performance.now();\n const {\n project_id: projectId,\n limit,\n cursor,\n status,\n definition_id: definitionId,\n trigger_source: triggerSource,\n created_from: createdFrom,\n created_to: createdTo,\n } = request.query;\n const decodedCursor = decodeTimestampIdCursor(cursor);\n if (cursor && !decodedCursor) {\n throw new ClientError('Invalid cursor', 'invalid-cursor', {status: 400});\n }\n\n const project = await requireProjectAccess(request, projectId, projects);\n\n const filters = {\n status,\n definitionId,\n triggerSource,\n createdFrom: createdFrom ? new Date(createdFrom) : undefined,\n createdTo: createdTo ? new Date(createdTo) : undefined,\n };\n const result = await listWorkflowRuns({\n projectId: project.id,\n limit,\n cursor: decodedCursor,\n filters,\n includeTotal: !decodedCursor,\n });\n // Paired with the attempt this read returned, so a re-run landing mid-request cannot\n // pair one attempt's metadata with another's jobs.\n const jobsByRun = await listWorkflowRunJobSummaries(\n result.runs.map((run) => ({id: run.id, currentAttempt: run.currentAttempt})),\n );\n\n logger().info(\n {\n projectId: project.id,\n filterKeys: Object.entries(filters)\n .filter(([, value]) => value !== undefined)\n .map(([key]) => key),\n limit,\n cursorPresent: Boolean(cursor),\n resultCount: result.runs.length,\n nextCursorPresent: Boolean(result.nextCursor),\n durationMs: Math.round(performance.now() - startedAt),\n },\n 'Listed workflow runs',\n );\n\n return {\n runs: result.runs.map((run) => toRunListItemDto(run, jobsByRun.get(run.id))),\n next_cursor: result.nextCursor ? encodeTimestampIdCursor(result.nextCursor) : null,\n filtered_total_count: result.filteredTotalCount,\n };\n },\n });\n}\n"],"names":["workflowRunListQuerySchema","workflowRunListResponseSchema","decodeTimestampIdCursor","encodeTimestampIdCursor","ClientError","defineRoute","logger","listWorkflowRunJobSummaries","listWorkflowRuns","toRunListItemDto","requireProjectAccess","listRunsRoute","projects","method","path","description","schema","querystring","response","handler","request","startedAt","performance","now","project_id","projectId","limit","cursor","status","definition_id","definitionId","trigger_source","triggerSource","created_from","createdFrom","created_to","createdTo","query","decodedCursor","project","filters","Date","undefined","result","id","includeTotal","jobsByRun","runs","map","run","currentAttempt","info","filterKeys","Object","entries","filter","value","key","cursorPresent","Boolean","resultCount","length","nextCursorPresent","nextCursor","durationMs","Math","round","get","next_cursor","filtered_total_count","filteredTotalCount"],"mappings":"AACA,SACEA,0BAA0B,EAC1BC,6BAA6B,QACxB,6BAA6B;AACpC,SAAQC,uBAAuB,EAAEC,uBAAuB,QAAO,wBAAwB;AACvF,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,MAAM,QAAO,8BAA8B;AACnD,SAAQC,2BAA2B,EAAEC,gBAAgB,QAAO,eAAe;AAC3E,SAAQC,gBAAgB,QAAO,6BAA6B;AAC5D,SAAQC,oBAAoB,QAAO,sBAAsB;AAEzD,OAAO,SAASC,cAAcC,QAA8B;IAC1D,OAAOP,YAAY;QACjBQ,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,aAAajB;YACbkB,UAAU;gBACR,KAAKjB;YACP;QACF;QACAkB,SAAS,OAAOC;YACd,MAAMC,YAAYC,YAAYC,GAAG;YACjC,MAAM,EACJC,YAAYC,SAAS,EACrBC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,eAAeC,YAAY,EAC3BC,gBAAgBC,aAAa,EAC7BC,cAAcC,WAAW,EACzBC,YAAYC,SAAS,EACtB,
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/list-runs.ts"],"sourcesContent":["import type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';\nimport {\n workflowRunListQuerySchema,\n workflowRunListResponseSchema,\n} from '@shipfox/api-workflows-dto';\nimport {decodeTimestampIdCursor, encodeTimestampIdCursor} from '@shipfox/node-drizzle';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport {listWorkflowRunJobSummaries, listWorkflowRuns} from '#db/index.js';\nimport {toRunListItemDto} from '#presentation/dto/index.js';\nimport {requireProjectAccess} from './project-access.js';\n\nexport function listRunsRoute(projects: ProjectsModuleClient) {\n return defineRoute({\n method: 'GET',\n path: '/',\n description: 'List workflow runs for a project',\n schema: {\n querystring: workflowRunListQuerySchema,\n response: {\n 200: workflowRunListResponseSchema,\n },\n },\n handler: async (request) => {\n const startedAt = performance.now();\n const {\n project_id: projectId,\n limit,\n cursor,\n status,\n definition_id: definitionId,\n trigger_source: triggerSource,\n origin,\n created_from: createdFrom,\n created_to: createdTo,\n } = request.query;\n const decodedCursor = decodeTimestampIdCursor(cursor);\n if (cursor && !decodedCursor) {\n throw new ClientError('Invalid cursor', 'invalid-cursor', {status: 400});\n }\n\n const project = await requireProjectAccess(request, projectId, projects);\n\n const filters = {\n status,\n definitionId,\n triggerSource,\n origin,\n createdFrom: createdFrom ? new Date(createdFrom) : undefined,\n createdTo: createdTo ? new Date(createdTo) : undefined,\n };\n const result = await listWorkflowRuns({\n projectId: project.id,\n limit,\n cursor: decodedCursor,\n filters,\n includeTotal: !decodedCursor,\n });\n // Paired with the attempt this read returned, so a re-run landing mid-request cannot\n // pair one attempt's metadata with another's jobs.\n const jobsByRun = await listWorkflowRunJobSummaries(\n result.runs.map((run) => ({id: run.id, currentAttempt: run.currentAttempt})),\n );\n\n logger().info(\n {\n projectId: project.id,\n filterKeys: Object.entries(filters)\n .filter(([, value]) => value !== undefined)\n .map(([key]) => key),\n limit,\n cursorPresent: Boolean(cursor),\n resultCount: result.runs.length,\n nextCursorPresent: Boolean(result.nextCursor),\n durationMs: Math.round(performance.now() - startedAt),\n },\n 'Listed workflow runs',\n );\n\n return {\n runs: result.runs.map((run) => toRunListItemDto(run, jobsByRun.get(run.id))),\n next_cursor: result.nextCursor ? encodeTimestampIdCursor(result.nextCursor) : null,\n filtered_total_count: result.filteredTotalCount,\n };\n },\n });\n}\n"],"names":["workflowRunListQuerySchema","workflowRunListResponseSchema","decodeTimestampIdCursor","encodeTimestampIdCursor","ClientError","defineRoute","logger","listWorkflowRunJobSummaries","listWorkflowRuns","toRunListItemDto","requireProjectAccess","listRunsRoute","projects","method","path","description","schema","querystring","response","handler","request","startedAt","performance","now","project_id","projectId","limit","cursor","status","definition_id","definitionId","trigger_source","triggerSource","origin","created_from","createdFrom","created_to","createdTo","query","decodedCursor","project","filters","Date","undefined","result","id","includeTotal","jobsByRun","runs","map","run","currentAttempt","info","filterKeys","Object","entries","filter","value","key","cursorPresent","Boolean","resultCount","length","nextCursorPresent","nextCursor","durationMs","Math","round","get","next_cursor","filtered_total_count","filteredTotalCount"],"mappings":"AACA,SACEA,0BAA0B,EAC1BC,6BAA6B,QACxB,6BAA6B;AACpC,SAAQC,uBAAuB,EAAEC,uBAAuB,QAAO,wBAAwB;AACvF,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,MAAM,QAAO,8BAA8B;AACnD,SAAQC,2BAA2B,EAAEC,gBAAgB,QAAO,eAAe;AAC3E,SAAQC,gBAAgB,QAAO,6BAA6B;AAC5D,SAAQC,oBAAoB,QAAO,sBAAsB;AAEzD,OAAO,SAASC,cAAcC,QAA8B;IAC1D,OAAOP,YAAY;QACjBQ,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,aAAajB;YACbkB,UAAU;gBACR,KAAKjB;YACP;QACF;QACAkB,SAAS,OAAOC;YACd,MAAMC,YAAYC,YAAYC,GAAG;YACjC,MAAM,EACJC,YAAYC,SAAS,EACrBC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,eAAeC,YAAY,EAC3BC,gBAAgBC,aAAa,EAC7BC,MAAM,EACNC,cAAcC,WAAW,EACzBC,YAAYC,SAAS,EACtB,GAAGjB,QAAQkB,KAAK;YACjB,MAAMC,gBAAgBrC,wBAAwByB;YAC9C,IAAIA,UAAU,CAACY,eAAe;gBAC5B,MAAM,IAAInC,YAAY,kBAAkB,kBAAkB;oBAACwB,QAAQ;gBAAG;YACxE;YAEA,MAAMY,UAAU,MAAM9B,qBAAqBU,SAASK,WAAWb;YAE/D,MAAM6B,UAAU;gBACdb;gBACAE;gBACAE;gBACAC;gBACAE,aAAaA,cAAc,IAAIO,KAAKP,eAAeQ;gBACnDN,WAAWA,YAAY,IAAIK,KAAKL,aAAaM;YAC/C;YACA,MAAMC,SAAS,MAAMpC,iBAAiB;gBACpCiB,WAAWe,QAAQK,EAAE;gBACrBnB;gBACAC,QAAQY;gBACRE;gBACAK,cAAc,CAACP;YACjB;YACA,qFAAqF;YACrF,mDAAmD;YACnD,MAAMQ,YAAY,MAAMxC,4BACtBqC,OAAOI,IAAI,CAACC,GAAG,CAAC,CAACC,MAAS,CAAA;oBAACL,IAAIK,IAAIL,EAAE;oBAAEM,gBAAgBD,IAAIC,cAAc;gBAAA,CAAA;YAG3E7C,SAAS8C,IAAI,CACX;gBACE3B,WAAWe,QAAQK,EAAE;gBACrBQ,YAAYC,OAAOC,OAAO,CAACd,SACxBe,MAAM,CAAC,CAAC,GAAGC,MAAM,GAAKA,UAAUd,WAChCM,GAAG,CAAC,CAAC,CAACS,IAAI,GAAKA;gBAClBhC;gBACAiC,eAAeC,QAAQjC;gBACvBkC,aAAajB,OAAOI,IAAI,CAACc,MAAM;gBAC/BC,mBAAmBH,QAAQhB,OAAOoB,UAAU;gBAC5CC,YAAYC,KAAKC,KAAK,CAAC7C,YAAYC,GAAG,KAAKF;YAC7C,GACA;YAGF,OAAO;gBACL2B,MAAMJ,OAAOI,IAAI,CAACC,GAAG,CAAC,CAACC,MAAQzC,iBAAiByC,KAAKH,UAAUqB,GAAG,CAAClB,IAAIL,EAAE;gBACzEwB,aAAazB,OAAOoB,UAAU,GAAG7D,wBAAwByC,OAAOoB,UAAU,IAAI;gBAC9EM,sBAAsB1B,OAAO2B,kBAAkB;YACjD;QACF;IACF;AACF"}
|
|
@@ -6,6 +6,7 @@ export declare function requireProjectAccess(request: FastifyRequest, projectId:
|
|
|
6
6
|
sourceConnectionId: string;
|
|
7
7
|
sourceExternalRepositoryId: string;
|
|
8
8
|
sourceRepositoryOwner?: string | null | undefined;
|
|
9
|
+
sourceDefaultBranch?: string | null | undefined;
|
|
9
10
|
name: string;
|
|
10
11
|
}>;
|
|
11
12
|
//# sourceMappingURL=project-access.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-access.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/project-access.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAEjF,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,SAAS,CAAC;AAE5C,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,oBAAoB
|
|
1
|
+
{"version":3,"file":"project-access.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/project-access.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAEjF,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,SAAS,CAAC;AAE5C,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,oBAAoB;;;;;;;;GAO/B"}
|