1 | import { CallOptions } from 'google-gax';
|
2 | import { google } from '../protos/protos';
|
3 | import { Attributes } from './publisher';
|
4 | import { PubSub } from './pubsub';
|
5 | /**
|
6 | * A Schema object allows you to interact with a Cloud Pub/Sub schema.
|
7 | *
|
8 | * This should only be instantiated by the PubSub class. To obtain an
|
9 | * instance for end user usage, call pubsub.schema().
|
10 | *
|
11 | * @class
|
12 | * @param {PubSub} pubsub The PubSub object creating this object.
|
13 | * @param {id} id name or ID of the schema.
|
14 | *
|
15 | * @example <caption>Creating an instance of this class.</caption>
|
16 | * const {PubSub} = require('@google-cloud/pubsub');
|
17 | * const pubsub = new PubSub();
|
18 | *
|
19 | * const schema = pubsub.schema('my-schema');
|
20 | *
|
21 | * @example <caption>Getting the details of a schema. Note that Schema
|
22 | * methods do not provide a callback interface. Use .then() or await.</caption>
|
23 | * const {PubSub} = require('@google-cloud/pubsub');
|
24 | * const pubsub = new PubSub();
|
25 | *
|
26 | * const schema = pubsub.schema('my-schema');
|
27 | * schema.get(SchemaViews.Basic).then(console.log);
|
28 | */
|
29 | export declare class Schema {
|
30 | id: string;
|
31 | name_?: string;
|
32 | pubsub: PubSub;
|
33 | constructor(pubsub: PubSub, idOrName: string);
|
34 | /**
|
35 | * Return the fully qualified name of this schema.
|
36 | *
|
37 | * Note that we have to verify that we have a projectId before returning this,
|
38 | * so we have to check that first.
|
39 | *
|
40 | * @return {Promise<string>} a Promise that resolves to the full schema name
|
41 | */
|
42 | getName(): Promise<string>;
|
43 | /**
|
44 | * Create a schema.
|
45 | *
|
46 | * @see [Schemas: create API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/create}
|
47 | *
|
48 | * @throws {Error} if the schema type is incorrect.
|
49 | * @throws {Error} if the definition is invalid.
|
50 | *
|
51 | * @param {SchemaType} type The type of the schema (Protobuf, Avro, etc).
|
52 | * @param {string} definition The text describing the schema in terms of the type.
|
53 | * @param {object} [options] Request configuration options, outlined
|
54 | * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
|
55 | * @returns {Promise<void>}
|
56 | *
|
57 | * @example <caption>Create a schema.</caption>
|
58 | * const {PubSub} = require('@google-cloud/pubsub');
|
59 | * const pubsub = new PubSub();
|
60 | *
|
61 | * const schema = pubsub.schema('messageType');
|
62 | * await schema.create(
|
63 | * SchemaTypes.Avro,
|
64 | * '{...avro definition...}'
|
65 | * );
|
66 | */
|
67 | create(type: SchemaType, definition: string, gaxOpts?: CallOptions): Promise<void>;
|
68 | /**
|
69 | * Get full information about the schema from the service.
|
70 | *
|
71 | * @see [Schemas: getSchema API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/get}
|
72 | *
|
73 | * @param {google.pubsub.v1.SchemaView} [view] The type of schema object
|
74 | * requested, which should be an enum value from {@link SchemaViews}. Defaults
|
75 | * to Full.
|
76 | * @param {object} [options] Request configuration options, outlined
|
77 | * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
|
78 | * @returns {Promise<ISchema>}
|
79 | */
|
80 | get(view?: SchemaView, gaxOpts?: CallOptions): Promise<ISchema>;
|
81 | /**
|
82 | * Delete the schema from the project.
|
83 | *
|
84 | * @see [Schemas: deleteSchema API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/delete}
|
85 | *
|
86 | * @param {object} [options] Request configuration options, outlined
|
87 | * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
|
88 | * @returns {Promise<void>}
|
89 | */
|
90 | delete(gaxOpts?: CallOptions): Promise<void>;
|
91 | /**
|
92 | * Validate a message against this schema's definition.
|
93 | *
|
94 | * If you would like to validate a message against an arbitrary schema, please
|
95 | * use the {@link SchemaServiceClient} GAPIC class directly, using your
|
96 | * {@link PubSub} instance's configuration, via {@link PubSub#getClientConfig}.
|
97 | *
|
98 | * @see [Schemas: validateMessage API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/validateMessage}
|
99 | *
|
100 | * @throws {Error} if the validation fails.
|
101 | * @throws {Error} if other parameters are invalid.
|
102 | *
|
103 | * @param {string} message The message to validate.
|
104 | * @param {Encoding | "JSON" | "BINARY"} encoding The encoding of the message to validate.
|
105 | * @param {object} [options] Request configuration options, outlined
|
106 | * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
|
107 | * @returns {Promise<void>}
|
108 | */
|
109 | validateMessage(message: string, encoding: google.pubsub.v1.Encoding | keyof typeof google.pubsub.v1.Encoding, gaxOpts?: CallOptions): Promise<void>;
|
110 | /*!
|
111 | * Format the name of a schema. A schema's full name is in the
|
112 | * format of projects/{projectId}/schemas/{schemaName}.
|
113 | *
|
114 | * The GAPIC client should do this for us, but since we maintain
|
115 | * names rather than IDs, this is simpler.
|
116 | *
|
117 | * @private
|
118 | */
|
119 | static formatName_(projectId: string, nameOrId: string): string;
|
120 | /**
|
121 | * Translates the schema attributes in messages delivered from Pub/Sub.
|
122 | * All resulting fields may end up being blank.
|
123 | */
|
124 | static metadataFromMessage(attributes: Attributes): SchemaMessageMetadata;
|
125 | }
|
126 | /**
|
127 | * Schema metadata that might be gathered from a Pub/Sub message.
|
128 | * This is created for you from {@link Schema#metadataForMessage}.
|
129 | */
|
130 | export interface SchemaMessageMetadata {
|
131 | /**
|
132 | * Schema name; may be queried using {@link PubSub#schema}.
|
133 | */
|
134 | name?: string;
|
135 | /**
|
136 | * Encoding; this will be Encodings.Json or Encodings.Binary.
|
137 | */
|
138 | encoding: SchemaEncoding | undefined;
|
139 | }
|
140 | export declare type CreateSchemaResponse = google.pubsub.v1.Schema;
|
141 | export declare type ISchema = google.pubsub.v1.ISchema;
|
142 | export declare type SchemaType = keyof typeof google.pubsub.v1.Schema.Type;
|
143 | export declare type SchemaView = keyof typeof google.pubsub.v1.SchemaView;
|
144 | export declare type ICreateSchemaRequest = google.pubsub.v1.ICreateSchemaRequest;
|
145 | export declare type SchemaEncoding = keyof typeof google.pubsub.v1.Encoding;
|
146 | export declare const SchemaTypes: {
|
147 | ProtocolBuffer: "PROTOCOL_BUFFER";
|
148 | Avro: "AVRO";
|
149 | };
|
150 | export declare const SchemaViews: {
|
151 | Basic: "BASIC";
|
152 | Full: "FULL";
|
153 | };
|
154 | export declare const Encodings: {
|
155 | Json: "JSON";
|
156 | Binary: "BINARY";
|
157 | };
|