Class Schema (2.13.0)

A Schema object allows you to interact with a Cloud Pub/Sub schema.

This should only be instantiated by the PubSub class. To obtain an instance for end user usage, call pubsub.schema().

Package

@google-cloud/pubsub!

Constructors

(constructor)(pubsub, idOrName)

constructor(pubsub: PubSub, idOrName: string);

Constructs a new instance of the Schema class

Parameters
NameDescription
pubsub PubSub
idOrName string

Properties

id

id: string;
Property Value
TypeDescription
string

name_

name_?: string;
Property Value
TypeDescription
string

pubsub

pubsub: PubSub;
Property Value
TypeDescription
PubSub

Methods

create(type, definition, gaxOpts)

create(type: SchemaType, definition: string, gaxOpts?: CallOptions): Promise<void>;

Create a schema.

[Schemas: create API Documentation]https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/create

Parameters
NameDescription
type SchemaType

The type of the schema (Protobuf, Avro, etc).

definition string

The text describing the schema in terms of the type.

gaxOpts CallOptions
Returns
TypeDescription
Promise<void>

{Promise

delete(gaxOpts)

delete(gaxOpts?: CallOptions): Promise<void>;

Delete the schema from the project.

[Schemas: deleteSchema API Documentation]https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/delete

Parameter
NameDescription
gaxOpts CallOptions
Returns
TypeDescription
Promise<void>

{Promise

formatName_(projectId, nameOrId)

static formatName_(projectId: string, nameOrId: string): string;
Parameters
NameDescription
projectId string
nameOrId string
Returns
TypeDescription
string

get(view, gaxOpts)

get(view?: SchemaView, gaxOpts?: CallOptions): Promise<ISchema>;

Get full information about the schema from the service.

[Schemas: getSchema API Documentation]https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/get

Parameters
NameDescription
view SchemaView

The type of schema object requested, which should be an enum value from SchemaViews. Defaults to Full.

gaxOpts CallOptions
Returns
TypeDescription
Promise<ISchema>

{Promise

getName()

getName(): Promise<string>;

Return the fully qualified name of this schema.

Note that we have to verify that we have a projectId before returning this, so we have to check that first.

{Promise

Returns
TypeDescription
Promise<string>

metadataFromMessage(attributes)

static metadataFromMessage(attributes: Attributes): SchemaMessageMetadata;

Translates the schema attributes in messages delivered from Pub/Sub. All resulting fields may end up being blank.

Parameter
NameDescription
attributes Attributes
Returns
TypeDescription
SchemaMessageMetadata

validateMessage(message, encoding, gaxOpts)

validateMessage(message: string, encoding: google.pubsub.v1.Encoding | keyof typeof google.pubsub.v1.Encoding, gaxOpts?: CallOptions): Promise<void>;

Validate a message against this schema's definition.

If you would like to validate a message against an arbitrary schema, please use the GAPIC class directly, using your PubSub instance's configuration, via .

[Schemas: validateMessage API Documentation]https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/validateMessage

Parameters
NameDescription
message string

The message to validate.

encoding google.pubsub.v1.Encoding | keyof typeof google.pubsub.v1.Encoding

The encoding of the message to validate.

gaxOpts CallOptions
Returns
TypeDescription
Promise<void>

{Promise