Visibility
TypeScript offers private
, protected
and public
keywords to handle member visibility in a class. However, Dagger will only expose those fields of a Dagger Module that are explicitly decorated with the @field()
decorator. Other fields will remain private.
note
Even if a field remains private, its state will still be loaded and it can be used even though it is not exposed via the Dagger API.
Here's an example of a Dagger Module that has multiple properties which are not exposed outside the module, and a Dagger Function that uses the crypto
library to hash these:
import * as crypto from "crypto"
import { object, func, field } from "@dagger.io/dagger"
@object()
class person {
/**
* Get the name of the person
*/
@field()
name: string
private age: number
job: string
constructor(name: string, job: string, age: number) {
this.name = name
this.age = age
this.job = job
}
/**
* Get the identity of the person based on its personal information.
*/
@func()
identity(): string {
return crypto
.createHash("sha256")
.update(`${this.name}-${this.job}-${this.age.toString()}`)
.digest("hex")
}
}
From dagger functions
, it can be seen that age
and job
are not exposed:
dagger functions
Name Description
identity Get the identity of the person based on its personal information.
name Get the name of the person
Here is an example call for this module:
dagger call --name="john" --age=23 --job="devops" identity
The result will be:
c11fb2dc1c5bfe34b0ed5737b8c58914ddb56a83602ead3eff2f06e46efc4a24