ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

Dagger TypeScript SDK PipelineLabel 类型别名完全解析:定义、用法与弃用状态

Dagger TypeScript SDK PipelineLabel 类型别名完全解析:定义、用法与弃用状态 Dagger TypeScript SDK PipelineLabel 类型别名完全解析定义、用法与弃用状态【免费下载链接】daggerAutomation engine to build, test and ship any codebase. Runs locally, in CI, or directly in the cloud项目地址: https://gitcode.com/GitHub_Trending/da/dagger导读本文围绕 Dagger TypeScript SDK 中由代码生成器产出的PipelineLabel类型别名展开完整说明其name与value两个字段的定义与语义、在 GraphQL API 中的底层映射PipelineLabel输入对象、以及它在pipelineAPI 中作为子管道标签参数的使用方式。同时结合仓库源码说明该类型当前已被标记为弃用deprecated且实际为 no-op 的实现现状帮助开发者正确理解并规避该 API避免在新代码中依赖它。关联文档PipelineLabel.mdPipelineLabel 是什么在 Dagger TypeScript SDK 中PipelineLabel是一个Type Alias类型别名由dagger.io/dagger包的 API 客户端代码生成文件自动产出。其完整定义位于 sdk/typescript/src/api/client.gen.tsexport type PipelineLabel { /** * Label name. */ name: string /** * Label value. */ value: string }它是一个简单的对象结构类型核心用途是描述附加到子管道sub-pipeline上的一个键值对标签字段类型说明对应文档原文namestringLabel name标签名valuestringLabel value标签值对应文档位于 type-aliases/PipelineLabel.md该文件属于 Dagger v0.19 版本 TypeScript SDK 的 API 参考文档体系其中api/client.gen命名空间对应 SDK 中由 GraphQL schema 生成的全部类型与函数。从 GraphQL 类型到 TypeScript 别名的映射PipelineLabel并不是 Dagger 中一个独立的运行时对象类型而是 GraphQL API 中的一个input object输入对象。从仓库源码可以看到它的 Go 侧定义core/schema/deprecations.go// PipelineLabel is deprecated and has no effect. type PipelineLabel struct { Name string field:true doc:Label name. Value string field:true doc:Label value. } func (PipelineLabel) TypeName() string { return PipelineLabel } func (PipelineLabel) TypeDescription() string { return Key value object that represents a pipeline label. }在 core/schema/query.go 中PipelineLabel{}通过dagql.MustInputSpec(PipelineLabel{}).Install(srv)注册为 GraphQL 输入对象因此它在各语言 SDK 的代码生成产物中体现为TypeScriptPipelineLabel类型别名本文章主题sdk/typescript/src/api/client.gen.tsGoPipelineLabel结构体sdk/go/dagger.gen.go// Key value object that represents a pipeline label. type PipelineLabel struct { // Label name. Name string json:name // Label value. Value string json:value }PHPsdk/php/generated/PipelineLabel.phpElixirsdk/elixir/lib/dagger/gen/pipeline_label.exRustsdk/rust/crates/dagger-sdk/src/gen.rs中的PipelineLabel结构Pythonsdk/python/src/dagger/client/gen.py中对应的输入对象类这印证了一个关键结论PipelineLabel的语义在所有 SDK 中是统一的只是在不同语言里被生成为不同的语法结构TS 用 type aliasGo/Rust 用 structPython 用 dataclass 等。PipelineLabel 在pipelineAPI 中的用法PipelineLabel作为输入对象是pipelineGraphQL 查询的labels参数类型。以Query根对象为例core/schema/query.godagql.Func(pipeline, s.pipeline). Deprecated(Explicit pipeline creation is now a no-op). Doc(Creates a named sub-pipeline.). Arg(name, ...). Arg(description, ...). Arg(labels, ...).其中pipelineArgs定义core/schema/query.gotype pipelineArgs struct { ... Labels dagql.Optional[dagql.ArrayInput[dagql.InputObject[PipelineLabel]]] }也就是说在 GraphQL 层面一个典型的pipeline调用可以携带labels参数每个 label 都是一个PipelineLabel输入对象namevalue。TypeScript 中对应的类型化 API 会自动把PipelineLabel[]序列化为 GraphQL 输入对象数组。重要现状PipelineLabel 及 pipeline API 已被弃用写代码之前必须明确一个事实PipelineLabel所服务的pipeline功能在当前版本中已经弃用且为 no-op。仓库中有多处直接证据类型定义文件注释core/schema/deprecations.go 首行即注明 PipelineLabel is deprecated and has no effect.GraphQL schema 声明query、container、directory三个对象上的pipeline函数均标注Deprecated(Explicit pipeline creation is now a no-op)例如 core/schema/container.go 与 core/schema/directory.go。实现层面是空操作core/schema/container.go 中的containerSchema.pipeline直接返回parent, nil即无论传入什么 name、description 或 labels容器对象都不发生任何变化type containerPipelineArgs struct { Name string Description string default: Labels []dagql.InputObject[PipelineLabel] default:[] } func (s *containerSchema) pipeline(ctx context.Context, parent *core.Container, args containerPipelineArgs) (*core.Container, error) { // deprecated no-op return parent, nil }core/schema/query.go 与 core/query.go 中Query.pipeline最终调用WithPipeline而该方法也仅仅是q.Clone()后原样返回。由此可以推断在 Dagger 引擎的演进过程中显式创建子管道的机制已被移除PipelineLabel作为其配套的标签输入对象随之失去实际作用保留它只是为了兼容旧版本 API 与已生成的 SDK 代码。开发者实战建议结合上述弃用现状给使用 Dagger TypeScript SDK 的开发者如下建议不要在新建代码中使用PipelineLabel。即使 TypeScript 的类型定义仍然存在不会导致编译错误其运行时行为也是空操作无法真正为管道添加标签依赖它只会造成看起来生效、实际无效的误导。调用pipeline相关 API 时预期其为 no-op。无论是client.pipeline(...)还是 Container/Directory 上的pipeline(...)都不再产生子管道效果相应地labels参数即PipelineLabel[]也会被忽略。关注Deprecated标记。在 TypeScript SDK 中这类 API 的 JSDoc 或类型注释会携带弃用说明在 Go SDK 中对应dagger.gen.go内的类型注释同样写明 deprecated例如 sdk/go/dagger.gen.go。代码审查与生成文档时应以这些标记为准。历史代码迁移若旧代码中通过pipeline(name, description, labels)组织可观测性分组建议改用 Dagger 当前支持的链路追踪tracing与进度输出机制来实现类似的分组效果而不是继续传递PipelineLabel键值对。延伸阅读TypeScript SDK 的PipelineLabel代码生成产物sdk/typescript/src/api/client.gen.ts各语言 SDK 的对应实现sdk/go/dagger.gen.go、sdk/php/generated/PipelineLabel.php、sdk/python/src/dagger/client/gen.pyGraphQL 侧的类型定义与注册core/schema/deprecations.go、core/schema/query.gopipeline函数的 schema 声明与 no-op 实现core/schema/container.go、core/schema/container.go、core/schema/directory.go、core/query.go【免费下载链接】daggerAutomation engine to build, test and ship any codebase. Runs locally, in CI, or directly in the cloud项目地址: https://gitcode.com/GitHub_Trending/da/dagger创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表