sailfork / t3code-github / .repos/ alchemy-effect/ packages/ aws/ src/ MediaConvert/ JobTemplate.ts

import * as mediaconvert from "@distilled.cloud/aws/mediaconvert";
import { Unowned } from "alchemy/AdoptPolicy";
import { isResolved } from "alchemy/Diff";
import { createPhysicalName } from "alchemy/PhysicalName";
import * as Provider from "alchemy/Provider";
import { Resource } from "alchemy/Resource";
import { createInternalTags, hasAlchemyTags } from "alchemy/Tags";
import * as Effect from "effect/Effect";
import * as Stream from "effect/Stream";
import type { Providers } from "../Providers.ts";
import { readMcTags, syncMcTags } from "./internal.ts";

export interface JobTemplateProps {
  /**
   * Name of the job template. Must be unique within the account/region and
   * match `^[\w-]+

	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	.repos/alchemy-effect/packages/aws/src/MediaConvert/JobTemplate.ts at main · sailfork/t3code-github · Sailfork
	
		
. If omitted, a unique name is generated. Changing the * name replaces the job template. */ jobTemplateName?: string; /** * Optional description of the job template. */ description?: string; /** * Optional category used to group job templates in the MediaConvert console. */ category?: string; /** * Name of the queue jobs created from this template are submitted to. If * omitted, the account's `Default` queue is used. */ queue?: string; /** * Relative priority (-50 to 50) of jobs created from this template. */ priority?: number; /** * The transcode settings — input template(s), output groups, timecode * config, and so on — applied to jobs created from this template. Required. */ settings: mediaconvert.JobTemplateSettings; /** * Accelerated transcoding configuration. */ accelerationSettings?: mediaconvert.AccelerationSettings; /** * Optional destination queues jobs hop to if they wait too long. */ hopDestinations?: mediaconvert.HopDestination[]; /** * How often, in seconds, MediaConvert emits `STATUS_UPDATE` events for jobs * created from this template. */ statusUpdateInterval?: mediaconvert.StatusUpdateInterval; /** * User-defined tags for the job template. */ tags?: Record<string, string>; } export interface JobTemplate extends Resource< "AWS.MediaConvert.JobTemplate", JobTemplateProps, { jobTemplateName: string; jobTemplateArn: string; type: string | undefined; category: string | undefined; }, never, Providers > {} /** * An AWS Elemental MediaConvert job template — a reusable, named transcode * configuration (inputs, output groups, and job-level settings) that new jobs * are created from so callers only supply the input/output specifics. * * ### Creating a Job Template * **Example:** MP4 File-Group Template * ```typescript * const template = yield* MediaConvert.JobTemplate("Mp4", { * description: "Single MP4 output", * settings: { * Inputs: [{ TimecodeSource: "ZEROBASED" }], * OutputGroups: [ * { * OutputGroupSettings: { * Type: "FILE_GROUP_SETTINGS", * FileGroupSettings: {}, * }, * Outputs: [ * { * ContainerSettings: { Container: "MP4" }, * VideoDescription: { * CodecSettings: { * Codec: "H_264", * H264Settings: { * RateControlMode: "QVBR", * MaxBitrate: 5000000, * }, * }, * }, * }, * ], * }, * ], * }, * }); * ``` * * @resource */ export const JobTemplate = Resource<JobTemplate>("AWS.MediaConvert.JobTemplate"); export const JobTemplateProvider = () => Provider.effect( JobTemplate, Effect.gen(function* () { const createName = Effect.fn(function* (id: string, props: JobTemplateProps) { return props.jobTemplateName ?? (yield* createPhysicalName({ id, maxLength: 128 })); }); const toAttrs = (template: mediaconvert.JobTemplate & { Name: string }) => ({ jobTemplateName: template.Name, jobTemplateArn: template.Arn!, type: template.Type, category: template.Category, }); /** Get a job template by name; typed not-found → undefined. */ const getJobTemplate = Effect.fn(function* (name: string) { const response = yield* mediaconvert .getJobTemplate({ Name: name }) .pipe(Effect.catchTag("NotFoundException", () => Effect.undefined)); return response?.JobTemplate; }); return { stables: ["jobTemplateName", "jobTemplateArn"], diff: Effect.fn(function* ({ id, olds, news }) { if (!isResolved(news)) return undefined; const oldName = yield* createName(id, olds); const newName = yield* createName(id, news); if (oldName !== newName) return { action: "replace" } as const; }), read: Effect.fn(function* ({ id, olds, output }) { const name = output?.jobTemplateName ?? (yield* createName(id, olds ?? {})); const template = yield* getJobTemplate(name); if (template === undefined) return undefined; const attrs = toAttrs(template); const tags = yield* readMcTags(template.Arn!); return (yield* hasAlchemyTags(id, tags)) ? attrs : Unowned(attrs); }), reconcile: Effect.fn(function* ({ id, news, output, session }) { const internalTags = yield* createInternalTags(id); const desiredTags = { ...internalTags, ...news.tags }; const name = output?.jobTemplateName ?? (yield* createName(id, news)); // 1. Observe — cloud state is authoritative. let template = yield* getJobTemplate(name); // 2. Ensure — create if missing. if (template === undefined) { const created = yield* mediaconvert.createJobTemplate({ Name: name, Description: news.description, Category: news.category, Queue: news.queue, Priority: news.priority, Settings: news.settings, AccelerationSettings: news.accelerationSettings, HopDestinations: news.hopDestinations, StatusUpdateInterval: news.statusUpdateInterval, Tags: desiredTags, }); template = created.JobTemplate!; } else { // 3. Sync — UpdateJobTemplate re-applies the mutable fields. const updated = yield* mediaconvert.updateJobTemplate({ Name: name, Description: news.description, Category: news.category, Queue: news.queue, Priority: news.priority, Settings: news.settings, AccelerationSettings: news.accelerationSettings, HopDestinations: news.hopDestinations, StatusUpdateInterval: news.statusUpdateInterval, }); template = updated.JobTemplate!; } // 3b. Sync tags — diff against OBSERVED cloud tags. yield* syncMcTags(template.Arn!, desiredTags); yield* session.note(name); return toAttrs(template as mediaconvert.JobTemplate & { Name: string }); }), delete: Effect.fn(function* ({ output }) { yield* mediaconvert .deleteJobTemplate({ Name: output.jobTemplateName }) .pipe(Effect.catchTag("NotFoundException", () => Effect.void)); }), list: () => mediaconvert.listJobTemplates.pages({}).pipe( Stream.runCollect, Effect.map((chunk) => Array.from(chunk).flatMap((page) => page.JobTemplates ?? [])), Effect.map((templates) => templates.map(toAttrs)), ), }; }), );
.repos/alchemy-effect/packages/aws/src/MediaConvert/JobTemplate.ts at main · sailfork/t3code-github · Sailfork
. If omitted, a unique name is generated. Changing the\n * name replaces the job template.\n */\n jobTemplateName?: string;\n /**\n * Optional description of the job template.\n */\n description?: string;\n /**\n * Optional category used to group job templates in the MediaConvert console.\n */\n category?: string;\n /**\n * Name of the queue jobs created from this template are submitted to. If\n * omitted, the account's `Default` queue is used.\n */\n queue?: string;\n /**\n * Relative priority (-50 to 50) of jobs created from this template.\n */\n priority?: number;\n /**\n * The transcode settings — input template(s), output groups, timecode\n * config, and so on — applied to jobs created from this template. Required.\n */\n settings: mediaconvert.JobTemplateSettings;\n /**\n * Accelerated transcoding configuration.\n */\n accelerationSettings?: mediaconvert.AccelerationSettings;\n /**\n * Optional destination queues jobs hop to if they wait too long.\n */\n hopDestinations?: mediaconvert.HopDestination[];\n /**\n * How often, in seconds, MediaConvert emits `STATUS_UPDATE` events for jobs\n * created from this template.\n */\n statusUpdateInterval?: mediaconvert.StatusUpdateInterval;\n /**\n * User-defined tags for the job template.\n */\n tags?: Record\u003cstring, string>;\n}\n\nexport interface JobTemplate extends Resource\u003c\n \"AWS.MediaConvert.JobTemplate\",\n JobTemplateProps,\n {\n jobTemplateName: string;\n jobTemplateArn: string;\n type: string | undefined;\n category: string | undefined;\n },\n never,\n Providers\n> {}\n\n/**\n * An AWS Elemental MediaConvert job template — a reusable, named transcode\n * configuration (inputs, output groups, and job-level settings) that new jobs\n * are created from so callers only supply the input/output specifics.\n *\n * ### Creating a Job Template\n * **Example:** MP4 File-Group Template\n * ```typescript\n * const template = yield* MediaConvert.JobTemplate(\"Mp4\", {\n * description: \"Single MP4 output\",\n * settings: {\n * Inputs: [{ TimecodeSource: \"ZEROBASED\" }],\n * OutputGroups: [\n * {\n * OutputGroupSettings: {\n * Type: \"FILE_GROUP_SETTINGS\",\n * FileGroupSettings: {},\n * },\n * Outputs: [\n * {\n * ContainerSettings: { Container: \"MP4\" },\n * VideoDescription: {\n * CodecSettings: {\n * Codec: \"H_264\",\n * H264Settings: {\n * RateControlMode: \"QVBR\",\n * MaxBitrate: 5000000,\n * },\n * },\n * },\n * },\n * ],\n * },\n * ],\n * },\n * });\n * ```\n *\n * @resource\n */\nexport const JobTemplate = Resource\u003cJobTemplate>(\"AWS.MediaConvert.JobTemplate\");\n\nexport const JobTemplateProvider = () =>\n Provider.effect(\n JobTemplate,\n Effect.gen(function* () {\n const createName = Effect.fn(function* (id: string, props: JobTemplateProps) {\n return props.jobTemplateName ?? (yield* createPhysicalName({ id, maxLength: 128 }));\n });\n\n const toAttrs = (template: mediaconvert.JobTemplate & { Name: string }) => ({\n jobTemplateName: template.Name,\n jobTemplateArn: template.Arn!,\n type: template.Type,\n category: template.Category,\n });\n\n /** Get a job template by name; typed not-found → undefined. */\n const getJobTemplate = Effect.fn(function* (name: string) {\n const response = yield* mediaconvert\n .getJobTemplate({ Name: name })\n .pipe(Effect.catchTag(\"NotFoundException\", () => Effect.undefined));\n return response?.JobTemplate;\n });\n\n return {\n stables: [\"jobTemplateName\", \"jobTemplateArn\"],\n\n diff: Effect.fn(function* ({ id, olds, news }) {\n if (!isResolved(news)) return undefined;\n const oldName = yield* createName(id, olds);\n const newName = yield* createName(id, news);\n if (oldName !== newName) return { action: \"replace\" } as const;\n }),\n\n read: Effect.fn(function* ({ id, olds, output }) {\n const name = output?.jobTemplateName ?? (yield* createName(id, olds ?? {}));\n const template = yield* getJobTemplate(name);\n if (template === undefined) return undefined;\n const attrs = toAttrs(template);\n const tags = yield* readMcTags(template.Arn!);\n return (yield* hasAlchemyTags(id, tags)) ? attrs : Unowned(attrs);\n }),\n\n reconcile: Effect.fn(function* ({ id, news, output, session }) {\n const internalTags = yield* createInternalTags(id);\n const desiredTags = { ...internalTags, ...news.tags };\n const name = output?.jobTemplateName ?? (yield* createName(id, news));\n\n // 1. Observe — cloud state is authoritative.\n let template = yield* getJobTemplate(name);\n\n // 2. Ensure — create if missing.\n if (template === undefined) {\n const created = yield* mediaconvert.createJobTemplate({\n Name: name,\n Description: news.description,\n Category: news.category,\n Queue: news.queue,\n Priority: news.priority,\n Settings: news.settings,\n AccelerationSettings: news.accelerationSettings,\n HopDestinations: news.hopDestinations,\n StatusUpdateInterval: news.statusUpdateInterval,\n Tags: desiredTags,\n });\n template = created.JobTemplate!;\n } else {\n // 3. Sync — UpdateJobTemplate re-applies the mutable fields.\n const updated = yield* mediaconvert.updateJobTemplate({\n Name: name,\n Description: news.description,\n Category: news.category,\n Queue: news.queue,\n Priority: news.priority,\n Settings: news.settings,\n AccelerationSettings: news.accelerationSettings,\n HopDestinations: news.hopDestinations,\n StatusUpdateInterval: news.statusUpdateInterval,\n });\n template = updated.JobTemplate!;\n }\n\n // 3b. Sync tags — diff against OBSERVED cloud tags.\n yield* syncMcTags(template.Arn!, desiredTags);\n\n yield* session.note(name);\n return toAttrs(template as mediaconvert.JobTemplate & { Name: string });\n }),\n\n delete: Effect.fn(function* ({ output }) {\n yield* mediaconvert\n .deleteJobTemplate({ Name: output.jobTemplateName })\n .pipe(Effect.catchTag(\"NotFoundException\", () => Effect.void));\n }),\n\n list: () =>\n mediaconvert.listJobTemplates.pages({}).pipe(\n Stream.runCollect,\n Effect.map((chunk) => Array.from(chunk).flatMap((page) => page.JobTemplates ?? [])),\n Effect.map((templates) => templates.map(toAttrs)),\n ),\n };\n }),\n );\n","preview":null,"history":null,"version":"adf5848b725907447b4d42c5c35e8de2675a23b5"},"/_session?shell=1":null}