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/pubsubExamples
Creating an instance of this class.
const {PubSub} = require('@google-cloud/pubsub'); const pubsub = new PubSub(); const schema = pubsub.schema('my-schema'); Getting the details of a schema. Note that Schema methods do not provide a callback interface. Use .then() or await.
const {PubSub} = require('@google-cloud/pubsub'); const pubsub = new PubSub(); const schema = pubsub.schema('my-schema'); schema.get(SchemaViews.Basic).then(console.log); Constructors
(constructor)(pubsub, idOrName)
constructor(pubsub: PubSub, idOrName: string);Constructs a new instance of the Schema class
| Name | Description |
| pubsub | PubSub |
| idOrName | string |
Properties
id
id: string;name_
name_?: string;pubsub
pubsub: PubSub;Methods
create(type, definition, gaxOpts)
create(type: SchemaType, definition: string, gaxOpts?: CallOptions): Promise<void>;Create a schema.
| Name | Description |
| type | SchemaType The type of the schema (Protobuf, Avro, etc). |
| definition | string The text describing the schema in terms of the type. |
| gaxOpts | CallOptions |
| Type | Description |
| Promise<void> | {Promise
|
Create a schema.
const {PubSub} = require('@google-cloud/pubsub'); const pubsub = new PubSub(); const schema = pubsub.schema('messageType'); await schema.create( SchemaTypes.Avro, '{...avro definition...}' ); delete(gaxOpts)
delete(gaxOpts?: CallOptions): Promise<void>;Delete the schema from the project.
| Name | Description |
| gaxOpts | CallOptions |
| Type | Description |
| Promise<void> | {Promise
|
formatName_(projectId, nameOrId)
static formatName_(projectId: string, nameOrId: string): string;| Name | Description |
| projectId | string |
| nameOrId | string |
| Type | Description |
| string |
get(view, gaxOpts)
get(view?: SchemaView, gaxOpts?: CallOptions): Promise<ISchema>;Get full information about the schema from the service.
| Name | Description |
| view | SchemaView The type of schema object requested, which should be an enum value from SchemaViews. Defaults to Full. |
| gaxOpts | CallOptions |
| Type | Description |
| 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
| Type | Description |
| 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.
| Name | Description |
| attributes | Attributes |
| Type | Description |
| 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 .
| Name | Description |
| 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 |
| Type | Description |
| Promise<void> | {Promise
|