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