From 0fe2de179040fbba45a7b0b668bbc7b9ffa4f63a Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Fri, 5 Jan 2024 12:44:51 -0500 Subject: [PATCH 01/23] feat: finish adding new methods to Schema wrapper --- src/schema.ts | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/schema.ts | 45 +++++++++++++++++++++++++ 2 files changed, 136 insertions(+) diff --git a/src/schema.ts b/src/schema.ts index 93cb624af..4a811b636 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -128,6 +128,52 @@ export class Schema { await this.pubsub.createSchema(name, type, definition, gaxOpts); } + /** + * Commits a new revision of a schema. + * + * @see [Schemas: commit API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/commit} + * + * @throws {Error} if the schema type is incorrect. + * @throws {Error} if the definition is invalid. + * + * @param {SchemaType} type The type of the schema (Protobuf, Avro, etc). This must match the existing schema. + * @param {string} definition The text describing the schema in terms of the type. + * @param {object} [options] Request configuration options, outlined + * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html. + * @returns {Promise} + * + * @example Commit a new schema revision. + * ``` + * const {PubSub} = require('@google-cloud/pubsub'); + * const pubsub = new PubSub(); + * + * const schema = pubsub.schema('messageType'); + * await schema.commitSchema( + * SchemaTypes.Avro, + * '{...avro definition...}' + * ); + * ``` + */ + async commitSchema( + type: SchemaType, + definition: string, + gaxOpts?: CallOptions + ): Promise { + const client = await this.pubsub.getSchemaClient_(); + const name = await this.getName(); + await client.commitSchema( + { + name, + schema: { + name, + type, + definition, + }, + }, + gaxOpts + ); + } + /** * Get full information about the schema from the service. * @@ -177,6 +223,51 @@ export class Schema { ); } + /** + * Delete a revision from the schema. + * + * @see [Schemas: deleteSchemaRevision API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/deleteRevision} + * + * @param {string} [revisionId] The ID of the revision to be deleted + * @param {object} [gaxOpts] Request configuration options, outlined + * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html. + * @returns {Promise} + */ + async deleteSchemaRevision( + revisionId: string, + gaxOpts?: CallOptions + ): Promise { + const client = await this.pubsub.getSchemaClient_(); + const name = await this.getName(); + await client.deleteSchemaRevision( + { + name, + revisionId, + }, + gaxOpts + ); + } + + /** + * Rollback a schema. + * + * @see [Schemas: rollbackSchema API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/rollback} + * + * @param {object} [gaxOpts] Request configuration options, outlined + * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html. + * @returns {Promise} + */ + async rollbackSchema(gaxOpts?: CallOptions): Promise { + const client = await this.pubsub.getSchemaClient_(); + const name = await this.getName(); + await client.rollbackSchema( + { + name, + }, + gaxOpts + ); + } + /** * Validate a message against this schema's definition. * diff --git a/test/schema.ts b/test/schema.ts index 578a1e61d..7d37e852a 100644 --- a/test/schema.ts +++ b/test/schema.ts @@ -92,6 +92,22 @@ describe('Schema', () => { assert.ok(called); }); + it('calls commitSchema() on the client when commitSchema() is called', async () => { + let called = false; + sandbox + .stub(schemaClient, 'commitSchema') + .callsFake(async (params, gaxOpts) => { + assert.strictEqual(params.name, schemaName); + assert.strictEqual(params.schema!.type, SchemaTypes.Avro); + assert.strictEqual(params.schema!.definition, 'definition'); + assert.ok(gaxOpts); + called = true; + }); + + await schema.commitSchema(SchemaTypes.Avro, 'definition', {}); + assert.ok(called); + }); + it('calls getSchema() on the client when get() is called', async () => { let called = false; sandbox @@ -138,6 +154,35 @@ describe('Schema', () => { assert.ok(called); }); + it('calls deleteSchemaRevision() on the client when deleteSchemaRevision() is called', async () => { + let called = false; + sandbox + .stub(schemaClient, 'deleteSchemaRevision') + .callsFake(async (params, gaxOpts) => { + assert.strictEqual(params.name, schemaName); + assert.strictEqual(params.revisionId, 'revisionId'); + assert.ok(gaxOpts); + called = true; + }); + + await schema.deleteSchemaRevision('revisionId', {}); + assert.ok(called); + }); + + it('calls rollbackSchema() on the client when rollbackSchema() is called', async () => { + let called = false; + sandbox + .stub(schemaClient, 'rollbackSchema') + .callsFake(async (params, gaxOpts) => { + assert.strictEqual(params.name, schemaName); + assert.ok(gaxOpts); + called = true; + }); + + await schema.rollbackSchema({}); + assert.ok(called); + }); + it('calls validateMessage() on the client when validateMessage() is called on the wrapper', async () => { let called = false; sandbox From a2f1b102163b4cf5e78e07ec11b7a1ed31c3cbc1 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Fri, 5 Jan 2024 14:20:32 -0500 Subject: [PATCH 02/23] feat: more updates for the schema update APIs, and a bunch of new samples --- samples/commitAvroSchema.js | 67 +++++++++++++ samples/createTopicWithSchemaRevisions.js | 93 +++++++++++++++++++ samples/deleteSchemaRevision.js | 63 +++++++++++++ samples/rollbackSchema.js | 63 +++++++++++++ samples/typescript/commitAvroSchema.ts | 63 +++++++++++++ .../createTopicWithSchemaRevisions.ts | 89 ++++++++++++++++++ samples/typescript/deleteSchemaRevision.ts | 62 +++++++++++++ samples/typescript/rollbackSchema.ts | 59 ++++++++++++ samples/typescript/updateTopicSchema.ts | 73 +++++++++++++++ samples/updateTopicSchema.js | 77 +++++++++++++++ src/schema.ts | 7 +- test/schema.ts | 3 +- 12 files changed, 717 insertions(+), 2 deletions(-) create mode 100644 samples/commitAvroSchema.js create mode 100644 samples/createTopicWithSchemaRevisions.js create mode 100644 samples/deleteSchemaRevision.js create mode 100644 samples/rollbackSchema.js create mode 100644 samples/typescript/commitAvroSchema.ts create mode 100644 samples/typescript/createTopicWithSchemaRevisions.ts create mode 100644 samples/typescript/deleteSchemaRevision.ts create mode 100644 samples/typescript/rollbackSchema.ts create mode 100644 samples/typescript/updateTopicSchema.ts create mode 100644 samples/updateTopicSchema.js diff --git a/samples/commitAvroSchema.js b/samples/commitAvroSchema.js new file mode 100644 index 000000000..76454428e --- /dev/null +++ b/samples/commitAvroSchema.js @@ -0,0 +1,67 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is a generated sample, using the typeless sample bot. Please +// look for the source TypeScript sample (.ts) for modifications. +'use strict'; + +/** + * This application demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Commit an Avro-Based Schema +// description: Commits a new schema definition revision on a project, using Avro +// usage: node commitAvroSchema.js + +// [START pubsub_commit_avro_schema] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID'; +// const avscFile = 'path/to/an/avro/schema/file/(.avsc)/formatted/in/json'; + +// Imports the Google Cloud client library +const {PubSub, SchemaTypes} = require('@google-cloud/pubsub'); + +const fs = require('fs'); + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function commitAvroSchema(schemaNameOrId, avscFile) { + const definition = fs.readFileSync(avscFile).toString(); + const schema = pubSubClient.schema(schemaNameOrId); + await schema.commitSchema(SchemaTypes.Avro, definition); + + const name = await schema.getName(); + console.log(`Schema ${name} commited.`); +} +// [END pubsub_create_avro_schema] + +function main( + schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', + avscFile = 'path/to/an/avro/schema/file/(.avsc)/formatted/in/json' +) { + commitAvroSchema(schemaNameOrId, avscFile).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/createTopicWithSchemaRevisions.js b/samples/createTopicWithSchemaRevisions.js new file mode 100644 index 000000000..3d7c19b32 --- /dev/null +++ b/samples/createTopicWithSchemaRevisions.js @@ -0,0 +1,93 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is a generated sample, using the typeless sample bot. Please +// look for the source TypeScript sample (.ts) for modifications. +'use strict'; + +/** + * This sample demonstrates how to perform basic operations on topics with + * the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Create Topic With Schema Revisions +// description: Creates a new topic, with a schema definition and revisions. +// usage: node createTopicWithSchema.js + +// [START pubsub_create_topic_with_schema_revisions] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID'; +// const schemaName = 'YOUR_SCHEMA_NAME_OR_ID'; +// const encodingType = 'BINARY'; +// const firstRevisionId = 'YOUR_REVISION_ID'; +// const lastRevisionId = 'YOUR_REVISION_ID'; + +// Imports the Google Cloud client library +const {PubSub} = require('@google-cloud/pubsub'); + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function createTopicWithSchemaRevisions( + topicNameOrId, + schemaNameOrId, + encodingType, + firstRevisionId, + lastRevisionId +) { + // Get the fully qualified schema name. + const schema = pubSubClient.schema(schemaNameOrId); + const fullName = await schema.getName(); + + // Creates a new topic with a schema. Note that you might also + // pass Encodings.Json or Encodings.Binary here. + await pubSubClient.createTopic({ + name: topicNameOrId, + schemaSettings: { + schema: fullName, + encoding: encodingType, + firstRevisionId, + lastRevisionId, + }, + }); + console.log(`Topic ${topicNameOrId} created with schema ${fullName}.`); +} +// [END pubsub_create_topic_with_schema_revisions] + +function main( + topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', + schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', + encodingType = 'BINARY', + firstRevisionId, + lastRevisionId +) { + createTopicWithSchemaRevisions( + topicNameOrId, + schemaNameOrId, + encodingType, + firstRevisionId, + lastRevisionId + ).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/deleteSchemaRevision.js b/samples/deleteSchemaRevision.js new file mode 100644 index 000000000..bdcba695d --- /dev/null +++ b/samples/deleteSchemaRevision.js @@ -0,0 +1,63 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is a generated sample, using the typeless sample bot. Please +// look for the source TypeScript sample (.ts) for modifications. +'use strict'; + +/** + * This application demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Delete a Schema Revision +// description: Deletes a new schema revision on a project +// usage: node deleteSchemaRevision.js + +// [START pubsub_delete_schema_revision] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID'; +// const revisionId = 'YOUR_REVISION_ID'; + +// Imports the Google Cloud client library +const {PubSub} = require('@google-cloud/pubsub'); + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function deleteSchemaRevision(schemaNameOrId, revisionId) { + const schema = pubSubClient.schema(schemaNameOrId); + await schema.deleteSchemaRevision(revisionId); + + console.log(`Schema ${schemaNameOrId} revision ${revisionId} deleted.`); +} +// [END pubsub_delete_schema_revision] + +function main( + schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', + revisionId = 'YOUR_REVISION_ID' +) { + deleteSchemaRevision(schemaNameOrId, revisionId).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/rollbackSchema.js b/samples/rollbackSchema.js new file mode 100644 index 000000000..4084a9729 --- /dev/null +++ b/samples/rollbackSchema.js @@ -0,0 +1,63 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is a generated sample, using the typeless sample bot. Please +// look for the source TypeScript sample (.ts) for modifications. +'use strict'; + +/** + * This application demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Rollback a Schema +// description: Rolls back a schema on a project +// usage: node rollbackSchema.js + +// [START pubsub_rollback_schema] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID'; +// const revisionId = 'YOUR_REVISION_ID'; + +// Imports the Google Cloud client library +const {PubSub} = require('@google-cloud/pubsub'); + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function rollbackSchema(schemaNameOrId, revisionId) { + const schema = pubSubClient.schema(schemaNameOrId); + await schema.rollbackSchema(revisionId); + + console.log(`Schema ${schemaNameOrId} revision ${revisionId} rolled back.`); +} +// [END pubsub_rollback_schema] + +function main( + schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', + revisionId = 'YOUR_REVISION_ID' +) { + rollbackSchema(schemaNameOrId, revisionId).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/typescript/commitAvroSchema.ts b/samples/typescript/commitAvroSchema.ts new file mode 100644 index 000000000..c46ac862e --- /dev/null +++ b/samples/typescript/commitAvroSchema.ts @@ -0,0 +1,63 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * This application demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Commit an Avro-Based Schema +// description: Commits a new schema definition revision on a project, using Avro +// usage: node commitAvroSchema.js + +// [START pubsub_commit_avro_schema] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID'; +// const avscFile = 'path/to/an/avro/schema/file/(.avsc)/formatted/in/json'; + +// Imports the Google Cloud client library +import {PubSub, SchemaTypes} from '@google-cloud/pubsub'; + +import * as fs from 'fs'; + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function commitAvroSchema(schemaNameOrId: string, avscFile: string) { + const definition: string = fs.readFileSync(avscFile).toString(); + const schema = pubSubClient.schema(schemaNameOrId); + await schema.commitSchema(SchemaTypes.Avro, definition); + + const name = await schema.getName(); + console.log(`Schema ${name} commited.`); +} +// [END pubsub_create_avro_schema] + +function main( + schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', + avscFile = 'path/to/an/avro/schema/file/(.avsc)/formatted/in/json' +) { + commitAvroSchema(schemaNameOrId, avscFile).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/typescript/createTopicWithSchemaRevisions.ts b/samples/typescript/createTopicWithSchemaRevisions.ts new file mode 100644 index 000000000..1b4338add --- /dev/null +++ b/samples/typescript/createTopicWithSchemaRevisions.ts @@ -0,0 +1,89 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * This sample demonstrates how to perform basic operations on topics with + * the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Create Topic With Schema Revisions +// description: Creates a new topic, with a schema definition and revisions. +// usage: node createTopicWithSchema.js + +// [START pubsub_create_topic_with_schema_revisions] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID'; +// const schemaName = 'YOUR_SCHEMA_NAME_OR_ID'; +// const encodingType = 'BINARY'; +// const firstRevisionId = 'YOUR_REVISION_ID'; +// const lastRevisionId = 'YOUR_REVISION_ID'; + +// Imports the Google Cloud client library +import {PubSub} from '@google-cloud/pubsub'; + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function createTopicWithSchemaRevisions( + topicNameOrId: string, + schemaNameOrId: string, + encodingType: 'BINARY' | 'JSON', + firstRevisionId: string, + lastRevisionId: string +) { + // Get the fully qualified schema name. + const schema = pubSubClient.schema(schemaNameOrId); + const fullName = await schema.getName(); + + // Creates a new topic with a schema. Note that you might also + // pass Encodings.Json or Encodings.Binary here. + await pubSubClient.createTopic({ + name: topicNameOrId, + schemaSettings: { + schema: fullName, + encoding: encodingType, + firstRevisionId, + lastRevisionId, + }, + }); + console.log(`Topic ${topicNameOrId} created with schema ${fullName}.`); +} +// [END pubsub_create_topic_with_schema_revisions] + +function main( + topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', + schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', + encodingType: 'BINARY' | 'JSON' = 'BINARY', + firstRevisionId: 'YOUR_REVISION_ID', + lastRevisionId: 'YOUR_REVISION_ID' +) { + createTopicWithSchemaRevisions( + topicNameOrId, + schemaNameOrId, + encodingType, + firstRevisionId, + lastRevisionId + ).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/typescript/deleteSchemaRevision.ts b/samples/typescript/deleteSchemaRevision.ts new file mode 100644 index 000000000..ed7365c42 --- /dev/null +++ b/samples/typescript/deleteSchemaRevision.ts @@ -0,0 +1,62 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * This application demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Delete a Schema Revision +// description: Deletes a new schema revision on a project +// usage: node deleteSchemaRevision.js + +// [START pubsub_delete_schema_revision] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID'; +// const revisionId = 'YOUR_REVISION_ID'; + +// Imports the Google Cloud client library +import {PubSub} from '@google-cloud/pubsub'; + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function deleteSchemaRevision( + schemaNameOrId: string, + revisionId: string +) { + const schema = pubSubClient.schema(schemaNameOrId); + await schema.deleteSchemaRevision(revisionId); + + console.log(`Schema ${schemaNameOrId} revision ${revisionId} deleted.`); +} +// [END pubsub_delete_schema_revision] + +function main( + schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', + revisionId = 'YOUR_REVISION_ID' +) { + deleteSchemaRevision(schemaNameOrId, revisionId).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/typescript/rollbackSchema.ts b/samples/typescript/rollbackSchema.ts new file mode 100644 index 000000000..83617daf5 --- /dev/null +++ b/samples/typescript/rollbackSchema.ts @@ -0,0 +1,59 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * This application demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Rollback a Schema +// description: Rolls back a schema on a project +// usage: node rollbackSchema.js + +// [START pubsub_rollback_schema] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID'; +// const revisionId = 'YOUR_REVISION_ID'; + +// Imports the Google Cloud client library +import {PubSub} from '@google-cloud/pubsub'; + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function rollbackSchema(schemaNameOrId: string, revisionId: string) { + const schema = pubSubClient.schema(schemaNameOrId); + await schema.rollbackSchema(revisionId); + + console.log(`Schema ${schemaNameOrId} revision ${revisionId} rolled back.`); +} +// [END pubsub_rollback_schema] + +function main( + schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', + revisionId = 'YOUR_REVISION_ID' +) { + rollbackSchema(schemaNameOrId, revisionId).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/typescript/updateTopicSchema.ts b/samples/typescript/updateTopicSchema.ts new file mode 100644 index 000000000..c31bad802 --- /dev/null +++ b/samples/typescript/updateTopicSchema.ts @@ -0,0 +1,73 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * This application demonstrates how to perform basic operations on + * subscriptions with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Update Topic Schema +// description: Update the schema on a topic. +// usage: node updateTopicSchema.js + +// [START pubsub_update_topic_schema] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID'; +// const firstRevisionId = 'YOUR_REVISION_ID'; +// const lastRevisionId = 'YOUR_REVISION_ID'; + +// Imports the Google Cloud client library +import {PubSub, TopicMetadata} from '@google-cloud/pubsub'; + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function updateTopicSchema( + topicNameOrId: string, + firstRevisionId: string, + lastRevisionId: string +) { + const metadata: TopicMetadata = { + schemaSettings: { + firstRevisionId, + lastRevisionId, + }, + }; + + await pubSubClient.topic(topicNameOrId).setMetadata(metadata); + + console.log('Schema metadata updated successfully.'); +} +// [END pubsub_update_topic_schema] + +function main( + topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', + firstRevisionId = 'YOUR_REVISION_ID', + lastRevisionId = 'YOUR_REVISION_ID' +) { + updateTopicSchema(topicNameOrId, firstRevisionId, lastRevisionId).catch( + err => { + console.error(err.message); + process.exitCode = 1; + } + ); +} + +main(...process.argv.slice(2)); diff --git a/samples/updateTopicSchema.js b/samples/updateTopicSchema.js new file mode 100644 index 000000000..5de59bcd9 --- /dev/null +++ b/samples/updateTopicSchema.js @@ -0,0 +1,77 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is a generated sample, using the typeless sample bot. Please +// look for the source TypeScript sample (.ts) for modifications. +'use strict'; + +/** + * This application demonstrates how to perform basic operations on + * subscriptions with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Update Topic Schema +// description: Update the schema on a topic. +// usage: node updateTopicSchema.js + +// [START pubsub_update_topic_schema] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID'; +// const firstRevisionId = 'YOUR_REVISION_ID'; +// const lastRevisionId = 'YOUR_REVISION_ID'; + +// Imports the Google Cloud client library +const {PubSub} = require('@google-cloud/pubsub'); + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function updateTopicSchema( + topicNameOrId, + firstRevisionId, + lastRevisionId +) { + const metadata = { + schemaSettings: { + firstRevisionId, + lastRevisionId, + }, + }; + + await pubSubClient.topic(topicNameOrId).setMetadata(metadata); + + console.log('Schema metadata updated successfully.'); +} +// [END pubsub_update_topic_schema] + +function main( + topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', + firstRevisionId = 'YOUR_REVISION_ID', + lastRevisionId = 'YOUR_REVISION_ID' +) { + updateTopicSchema(topicNameOrId, firstRevisionId, lastRevisionId).catch( + err => { + console.error(err.message); + process.exitCode = 1; + } + ); +} + +main(...process.argv.slice(2)); diff --git a/src/schema.ts b/src/schema.ts index 4a811b636..6723acb5e 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -253,16 +253,21 @@ export class Schema { * * @see [Schemas: rollbackSchema API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/rollback} * + * @param {string} [revisionId] The ID of the revision to be rolled back * @param {object} [gaxOpts] Request configuration options, outlined * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html. * @returns {Promise} */ - async rollbackSchema(gaxOpts?: CallOptions): Promise { + async rollbackSchema( + revisionId: string, + gaxOpts?: CallOptions + ): Promise { const client = await this.pubsub.getSchemaClient_(); const name = await this.getName(); await client.rollbackSchema( { name, + revisionId, }, gaxOpts ); diff --git a/test/schema.ts b/test/schema.ts index 7d37e852a..f1dc72ae2 100644 --- a/test/schema.ts +++ b/test/schema.ts @@ -175,11 +175,12 @@ describe('Schema', () => { .stub(schemaClient, 'rollbackSchema') .callsFake(async (params, gaxOpts) => { assert.strictEqual(params.name, schemaName); + assert.strictEqual(params.revisionId, 'revisionId'); assert.ok(gaxOpts); called = true; }); - await schema.rollbackSchema({}); + await schema.rollbackSchema('revisionId', {}); assert.ok(called); }); From d522c8639163b729eca8fa04326d1894c60c579b Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Fri, 5 Jan 2024 14:20:47 -0500 Subject: [PATCH 03/23] build: leave out samples/build/ from git checking --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d4f03a0df..79df01522 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ system-test/*key.json .DS_Store package-lock.json __pycache__ +samples/build/ From a469b41993737048ac2409401a28eeaf420ef7a0 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Mon, 8 Jan 2024 15:48:03 -0500 Subject: [PATCH 04/23] feat: remove added veneer for schema revisions --- src/schema.ts | 96 -------------------------------------------------- test/schema.ts | 46 ------------------------ 2 files changed, 142 deletions(-) diff --git a/src/schema.ts b/src/schema.ts index 6723acb5e..93cb624af 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -128,52 +128,6 @@ export class Schema { await this.pubsub.createSchema(name, type, definition, gaxOpts); } - /** - * Commits a new revision of a schema. - * - * @see [Schemas: commit API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/commit} - * - * @throws {Error} if the schema type is incorrect. - * @throws {Error} if the definition is invalid. - * - * @param {SchemaType} type The type of the schema (Protobuf, Avro, etc). This must match the existing schema. - * @param {string} definition The text describing the schema in terms of the type. - * @param {object} [options] Request configuration options, outlined - * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html. - * @returns {Promise} - * - * @example Commit a new schema revision. - * ``` - * const {PubSub} = require('@google-cloud/pubsub'); - * const pubsub = new PubSub(); - * - * const schema = pubsub.schema('messageType'); - * await schema.commitSchema( - * SchemaTypes.Avro, - * '{...avro definition...}' - * ); - * ``` - */ - async commitSchema( - type: SchemaType, - definition: string, - gaxOpts?: CallOptions - ): Promise { - const client = await this.pubsub.getSchemaClient_(); - const name = await this.getName(); - await client.commitSchema( - { - name, - schema: { - name, - type, - definition, - }, - }, - gaxOpts - ); - } - /** * Get full information about the schema from the service. * @@ -223,56 +177,6 @@ export class Schema { ); } - /** - * Delete a revision from the schema. - * - * @see [Schemas: deleteSchemaRevision API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/deleteRevision} - * - * @param {string} [revisionId] The ID of the revision to be deleted - * @param {object} [gaxOpts] Request configuration options, outlined - * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html. - * @returns {Promise} - */ - async deleteSchemaRevision( - revisionId: string, - gaxOpts?: CallOptions - ): Promise { - const client = await this.pubsub.getSchemaClient_(); - const name = await this.getName(); - await client.deleteSchemaRevision( - { - name, - revisionId, - }, - gaxOpts - ); - } - - /** - * Rollback a schema. - * - * @see [Schemas: rollbackSchema API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/rollback} - * - * @param {string} [revisionId] The ID of the revision to be rolled back - * @param {object} [gaxOpts] Request configuration options, outlined - * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html. - * @returns {Promise} - */ - async rollbackSchema( - revisionId: string, - gaxOpts?: CallOptions - ): Promise { - const client = await this.pubsub.getSchemaClient_(); - const name = await this.getName(); - await client.rollbackSchema( - { - name, - revisionId, - }, - gaxOpts - ); - } - /** * Validate a message against this schema's definition. * diff --git a/test/schema.ts b/test/schema.ts index f1dc72ae2..578a1e61d 100644 --- a/test/schema.ts +++ b/test/schema.ts @@ -92,22 +92,6 @@ describe('Schema', () => { assert.ok(called); }); - it('calls commitSchema() on the client when commitSchema() is called', async () => { - let called = false; - sandbox - .stub(schemaClient, 'commitSchema') - .callsFake(async (params, gaxOpts) => { - assert.strictEqual(params.name, schemaName); - assert.strictEqual(params.schema!.type, SchemaTypes.Avro); - assert.strictEqual(params.schema!.definition, 'definition'); - assert.ok(gaxOpts); - called = true; - }); - - await schema.commitSchema(SchemaTypes.Avro, 'definition', {}); - assert.ok(called); - }); - it('calls getSchema() on the client when get() is called', async () => { let called = false; sandbox @@ -154,36 +138,6 @@ describe('Schema', () => { assert.ok(called); }); - it('calls deleteSchemaRevision() on the client when deleteSchemaRevision() is called', async () => { - let called = false; - sandbox - .stub(schemaClient, 'deleteSchemaRevision') - .callsFake(async (params, gaxOpts) => { - assert.strictEqual(params.name, schemaName); - assert.strictEqual(params.revisionId, 'revisionId'); - assert.ok(gaxOpts); - called = true; - }); - - await schema.deleteSchemaRevision('revisionId', {}); - assert.ok(called); - }); - - it('calls rollbackSchema() on the client when rollbackSchema() is called', async () => { - let called = false; - sandbox - .stub(schemaClient, 'rollbackSchema') - .callsFake(async (params, gaxOpts) => { - assert.strictEqual(params.name, schemaName); - assert.strictEqual(params.revisionId, 'revisionId'); - assert.ok(gaxOpts); - called = true; - }); - - await schema.rollbackSchema('revisionId', {}); - assert.ok(called); - }); - it('calls validateMessage() on the client when validateMessage() is called on the wrapper', async () => { let called = false; sandbox From 215c3aa89f8b56436de7fd8a0a39880c726628e5 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Mon, 8 Jan 2024 16:42:17 -0500 Subject: [PATCH 05/23] feat: make getSchemaClient() public so users can easily create a gapic client --- src/pubsub.ts | 14 ++++++++------ src/schema.ts | 6 +++--- test/pubsub.ts | 10 +++++----- test/schema.ts | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/pubsub.ts b/src/pubsub.ts index e7fc0d819..a0aa2876a 100644 --- a/src/pubsub.ts +++ b/src/pubsub.ts @@ -400,7 +400,7 @@ export class PubSub { }, }; - const client = await this.getSchemaClient_(); + const client = await this.getSchemaClient(); await client.createSchema(request, gaxOpts); return new Schema(this, schemaName); } @@ -841,7 +841,7 @@ export class PubSub { view: SchemaView = SchemaViews.Basic, options?: CallOptions ): AsyncIterable { - const client = await this.getSchemaClient_(); + const client = await this.getSchemaClient(); const query = { parent: this.name, view, @@ -1218,10 +1218,12 @@ export class PubSub { } /** - * Gets a schema client, creating one if needed. - * @private + * Gets a schema client, creating one if needed. This is a shortcut for + * `new v1.SchemaServiceClient(await pubsub.getClientConfig())`. + * + * @returns {Promise} */ - async getSchemaClient_(): Promise { + async getSchemaClient(): Promise { if (!this.schemaClient) { const options = await this.getClientConfig(); this.schemaClient = new v1.SchemaServiceClient(options); @@ -1450,7 +1452,7 @@ export class PubSub { * @returns {Promise} */ async validateSchema(schema: ISchema, gaxOpts?: CallOptions): Promise { - const client = await this.getSchemaClient_(); + const client = await this.getSchemaClient(); await client.validateSchema( { parent: this.name, diff --git a/src/schema.ts b/src/schema.ts index 93cb624af..64d83815d 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -144,7 +144,7 @@ export class Schema { view: SchemaView = SchemaViews.Full, gaxOpts?: CallOptions ): Promise { - const client = await this.pubsub.getSchemaClient_(); + const client = await this.pubsub.getSchemaClient(); const name = await this.getName(); const [schema] = await client.getSchema( { @@ -167,7 +167,7 @@ export class Schema { * @returns {Promise} */ async delete(gaxOpts?: CallOptions): Promise { - const client = await this.pubsub.getSchemaClient_(); + const client = await this.pubsub.getSchemaClient(); const name = await this.getName(); await client.deleteSchema( { @@ -202,7 +202,7 @@ export class Schema { | keyof typeof google.pubsub.v1.Encoding, gaxOpts?: CallOptions ): Promise { - const client = await this.pubsub.getSchemaClient_(); + const client = await this.pubsub.getSchemaClient(); const name = await this.getName(); await client.validateMessage( diff --git a/test/pubsub.ts b/test/pubsub.ts index 668857690..08803c0d8 100644 --- a/test/pubsub.ts +++ b/test/pubsub.ts @@ -1686,7 +1686,7 @@ describe('PubSub', () => { it('should close the schema client when it has been opened', async () => { // Force it to create a client. - const client = await pubsub.getSchemaClient_?.(); + const client = await pubsub.getSchemaClient?.(); sandbox.stub(client!, 'close').resolves(); await pubsub.close?.(); }); @@ -1707,7 +1707,7 @@ describe('PubSub', () => { const name = Schema.formatName_(pubsub.projectId!, schemaId); // Grab the schema client it'll be using so we can stub it. - const client = await pubsub.getSchemaClient_!(); + const client = await pubsub.getSchemaClient!(); const def = defer(); sandbox.stub(client, 'createSchema').callsFake(req => { assert.strictEqual(req.parent, pubsub.name); @@ -1726,7 +1726,7 @@ describe('PubSub', () => { it('calls down to listSchemas correctly', async () => { // Grab the schema client it'll be using so we can stub it. - const client = await pubsub.getSchemaClient_!(); + const client = await pubsub.getSchemaClient!(); sandbox.stub(client, 'listSchemasAsync').callsFake((req, gaxOpts) => { assert.strictEqual(req!.parent, pubsub.name); @@ -1754,7 +1754,7 @@ describe('PubSub', () => { it('defaults to BASIC for listSchemas', async () => { // Grab the schema client it'll be using so we can stub it. - const client = await pubsub.getSchemaClient_?.(); + const client = await pubsub.getSchemaClient?.(); sandbox.stub(client!, 'listSchemasAsync').callsFake(req => { assert.strictEqual(req!.view, 'BASIC'); @@ -1777,7 +1777,7 @@ describe('PubSub', () => { }); it('calls validateSchema() on the client when validateSchema() is called', async () => { - const client = await pubsub.getSchemaClient_!(); + const client = await pubsub.getSchemaClient!(); const ischema: ISchema = { name: 'test', type: SchemaTypes.Avro, diff --git a/test/schema.ts b/test/schema.ts index 578a1e61d..c209d5ed3 100644 --- a/test/schema.ts +++ b/test/schema.ts @@ -49,7 +49,7 @@ describe('Schema', () => { // These depend on the create-on-first-call structure in PubSub. // If that changes, this will also need to be updated. - schemaClient = await pubsub.getSchemaClient_(); + schemaClient = await pubsub.getSchemaClient(); schema = pubsub.schema(schemaName); }); From d34044ff331d8096c0da2efffb946cba17009c47 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Mon, 8 Jan 2024 16:45:56 -0500 Subject: [PATCH 06/23] samples: update samples for latest changes --- samples/system-test/schema.test.ts | 55 +++++++++++++++++++ samples/typescript/commitAvroSchema.ts | 20 +++++-- .../createTopicWithSchemaRevisions.ts | 4 +- samples/typescript/deleteSchemaRevision.ts | 12 +++- samples/typescript/rollbackSchema.ts | 12 +++- 5 files changed, 93 insertions(+), 10 deletions(-) diff --git a/samples/system-test/schema.test.ts b/samples/system-test/schema.test.ts index b7b44f9b9..8cf868050 100644 --- a/samples/system-test/schema.test.ts +++ b/samples/system-test/schema.test.ts @@ -126,6 +126,22 @@ describe('schema', () => { return schema; } + async function commitSchema( + testName: string, + type: 'avro' | 'proto' + ): Promise { + const suffix = type === 'avro' ? 'avsc' : 'proto'; + const encoding = + type === 'avro' ? SchemaTypes.Avro : SchemaTypes.ProtocolBuffer; + const def = ( + await fs.readFile(fixturePath(`provinces.${suffix}`)) + ).toString(); + const schemaId = getSchemaId(testName); + + const schema = pubsub.schema(schemaId); + //await schema.commitSchema(encoding, def); + } + async function createTopicWithSchema( testName: string, schemaName: string, @@ -144,6 +160,28 @@ describe('schema', () => { return topic; } + async function createTopicWithSchemaRevisions( + testName: string, + schemaName: string, + encodingType: SchemaEncoding, + firstRevisionId: string, + lastRevisionId: string + ): Promise { + const topicId = getTopicId(testName); + const [topic] = await pubsub.createTopic({ + name: topicId, + schemaSettings: { + schema: fullSchemaName(schemaName), + encoding: encodingType, + firstRevisionId, + lastRevisionId, + }, + }); + assert.ok(topic); + + return topic; + } + async function createSub( testName: string, topicName: string @@ -212,6 +250,23 @@ describe('schema', () => { assert.include(topic.metadata?.schemaSettings?.schema, schema.id); }); + it('should create a topic with schema revisions', async () => { + const id = 'create_topic_rev'; + const schema = await createSchema(id, 'proto'); + const topicId = getTopicId(id); + const output = execSync( + `${commandFor('createTopicWithSchemaRevisions')} ${topicId} ${ + schema.id + } BINARY` + ); + assert.include(output, topicId); + assert.include(output, schema.id); + assert.include(output, 'created with'); + + const [topic] = await pubsub.topic(topicId).get(); + assert.include(topic.metadata?.schemaSettings?.schema, schema.id); + }); + it('should delete a schema', async () => { const schema = await createSchema('delete', 'proto'); diff --git a/samples/typescript/commitAvroSchema.ts b/samples/typescript/commitAvroSchema.ts index c46ac862e..61cb86754 100644 --- a/samples/typescript/commitAvroSchema.ts +++ b/samples/typescript/commitAvroSchema.ts @@ -41,12 +41,24 @@ import * as fs from 'fs'; const pubSubClient = new PubSub(); async function commitAvroSchema(schemaNameOrId: string, avscFile: string) { - const definition: string = fs.readFileSync(avscFile).toString(); + // Get the fully qualified schema name. const schema = pubSubClient.schema(schemaNameOrId); - await schema.commitSchema(SchemaTypes.Avro, definition); - const name = await schema.getName(); - console.log(`Schema ${name} commited.`); + + // Read the new schema definition from storage. + const definition: string = fs.readFileSync(avscFile).toString(); + + // Use the gapic client to commit the new definition. + const schemaClient = await pubSubClient.getSchemaClient(); + const [result] = await schemaClient.commitSchema({ + name, + schema: { + type: SchemaTypes.Avro, + definition, + }, + }); + + console.log(`Schema ${name} committed with revision ${result.revisionId}.`); } // [END pubsub_create_avro_schema] diff --git a/samples/typescript/createTopicWithSchemaRevisions.ts b/samples/typescript/createTopicWithSchemaRevisions.ts index 1b4338add..62d70d860 100644 --- a/samples/typescript/createTopicWithSchemaRevisions.ts +++ b/samples/typescript/createTopicWithSchemaRevisions.ts @@ -71,8 +71,8 @@ function main( topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', encodingType: 'BINARY' | 'JSON' = 'BINARY', - firstRevisionId: 'YOUR_REVISION_ID', - lastRevisionId: 'YOUR_REVISION_ID' + firstRevisionId = 'YOUR_REVISION_ID', + lastRevisionId = 'YOUR_REVISION_ID' ) { createTopicWithSchemaRevisions( topicNameOrId, diff --git a/samples/typescript/deleteSchemaRevision.ts b/samples/typescript/deleteSchemaRevision.ts index ed7365c42..9ee7e8b67 100644 --- a/samples/typescript/deleteSchemaRevision.ts +++ b/samples/typescript/deleteSchemaRevision.ts @@ -42,10 +42,18 @@ async function deleteSchemaRevision( schemaNameOrId: string, revisionId: string ) { + // Get the fully qualified schema name. const schema = pubSubClient.schema(schemaNameOrId); - await schema.deleteSchemaRevision(revisionId); + const name = await schema.getName(); - console.log(`Schema ${schemaNameOrId} revision ${revisionId} deleted.`); + // Use the gapic client to delete the schema revision. + const schemaClient = await pubSubClient.getSchemaClient(); + await schemaClient.deleteSchemaRevision({ + name, + revisionId, + }); + + console.log(`Schema ${name} revision ${revisionId} deleted.`); } // [END pubsub_delete_schema_revision] diff --git a/samples/typescript/rollbackSchema.ts b/samples/typescript/rollbackSchema.ts index 83617daf5..d2e1ac30f 100644 --- a/samples/typescript/rollbackSchema.ts +++ b/samples/typescript/rollbackSchema.ts @@ -39,10 +39,18 @@ import {PubSub} from '@google-cloud/pubsub'; const pubSubClient = new PubSub(); async function rollbackSchema(schemaNameOrId: string, revisionId: string) { + // Get the fully qualified schema name. const schema = pubSubClient.schema(schemaNameOrId); - await schema.rollbackSchema(revisionId); + const name = await schema.getName(); - console.log(`Schema ${schemaNameOrId} revision ${revisionId} rolled back.`); + // Use the gapic client to roll back the schema revision. + const schemaClient = await pubSubClient.getSchemaClient(); + await schemaClient.rollbackSchema({ + name, + revisionId, + }); + + console.log(`Schema ${name} revision ${revisionId} rolled back.`); } // [END pubsub_rollback_schema] From a77cd9ad0461ce4f35b19c3e6a03fe7ca0c94b29 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Mon, 8 Jan 2024 16:48:23 -0500 Subject: [PATCH 07/23] docs: fix mismatched sample tags --- samples/typescript/commitAvroSchema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/typescript/commitAvroSchema.ts b/samples/typescript/commitAvroSchema.ts index 61cb86754..8a068adf3 100644 --- a/samples/typescript/commitAvroSchema.ts +++ b/samples/typescript/commitAvroSchema.ts @@ -60,7 +60,7 @@ async function commitAvroSchema(schemaNameOrId: string, avscFile: string) { console.log(`Schema ${name} committed with revision ${result.revisionId}.`); } -// [END pubsub_create_avro_schema] +// [END pubsub_commit_avro_schema] function main( schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', From 50f5b07271e787dc5e739973b41b26e280c45985 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 8 Jan 2024 21:51:33 +0000 Subject: [PATCH 08/23] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 5 ++ samples/README.md | 100 ++++++++++++++++++++++ samples/commitAvroSchema.js | 20 ++++- samples/createTopicWithSchemaRevisions.js | 4 +- samples/deleteSchemaRevision.js | 12 ++- samples/rollbackSchema.js | 12 ++- 6 files changed, 143 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ceefb3891..c1fec11ed 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-pubsub/tree | Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | +| Commit an Avro-Based Schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/commitAvroSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/commitAvroSchema.js,samples/README.md) | | Create an Avro based Schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createAvroSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createAvroSchema.js,samples/README.md) | | Create BigQuery Subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createBigQuerySubscription.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createBigQuerySubscription.js,samples/README.md) | | Create a Proto based Schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createProtoSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createProtoSchema.js,samples/README.md) | @@ -135,7 +136,9 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-pubsub/tree | Create Subscription With Retry Policy | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createSubscriptionWithRetryPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createSubscriptionWithRetryPolicy.js,samples/README.md) | | Create Topic | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createTopic.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createTopic.js,samples/README.md) | | Create Topic With Schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createTopicWithSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createTopicWithSchema.js,samples/README.md) | +| Create Topic With Schema Revisions | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createTopicWithSchemaRevisions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createTopicWithSchemaRevisions.js,samples/README.md) | | Delete a previously created schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/deleteSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/deleteSchema.js,samples/README.md) | +| Delete a Schema Revision | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/deleteSchemaRevision.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/deleteSchemaRevision.js,samples/README.md) | | Delete Subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/deleteSubscription.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/deleteSubscription.js,samples/README.md) | | Delete Topic | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/deleteTopic.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/deleteTopic.js,samples/README.md) | | Detach Subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/detachSubscription.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/detachSubscription.js,samples/README.md) | @@ -166,6 +169,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-pubsub/tree | Quickstart | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) | | Remove Dead Letter Policy | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/removeDeadLetterPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/removeDeadLetterPolicy.js,samples/README.md) | | Resume Publish | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/resumePublish.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/resumePublish.js,samples/README.md) | +| Rollback a Schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/rollbackSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/rollbackSchema.js,samples/README.md) | | Set Subscription IAM Policy | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/setSubscriptionPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/setSubscriptionPolicy.js,samples/README.md) | | Set Topic IAM Policy | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/setTopicPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/setTopicPolicy.js,samples/README.md) | | Subscribe With Flow Control Settings | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/subscribeWithFlowControlSettings.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/subscribeWithFlowControlSettings.js,samples/README.md) | @@ -175,6 +179,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-pubsub/tree | Test Subscription Permissions | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/testSubscriptionPermissions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/testSubscriptionPermissions.js,samples/README.md) | | Test Topic Permissions | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/testTopicPermissions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/testTopicPermissions.js,samples/README.md) | | Update Dead Letter Policy | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/updateDeadLetterPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/updateDeadLetterPolicy.js,samples/README.md) | +| Update Topic Schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/updateTopicSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/updateTopicSchema.js,samples/README.md) | | Validate a schema definition | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/validateSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/validateSchema.js,samples/README.md) | diff --git a/samples/README.md b/samples/README.md index 749f4493f..231f2f303 100644 --- a/samples/README.md +++ b/samples/README.md @@ -20,6 +20,7 @@ guides. * [Before you begin](#before-you-begin) * [Samples](#samples) + * [Commit an Avro-Based Schema](#commit-an-avro-based-schema) * [Create an Avro based Schema](#create-an-avro-based-schema) * [Create BigQuery Subscription](#create-bigquery-subscription) * [Create a Proto based Schema](#create-a-proto-based-schema) @@ -32,7 +33,9 @@ guides. * [Create Subscription With Retry Policy](#create-subscription-with-retry-policy) * [Create Topic](#create-topic) * [Create Topic With Schema](#create-topic-with-schema) + * [Create Topic With Schema Revisions](#create-topic-with-schema-revisions) * [Delete a previously created schema](#delete-a-previously-created-schema) + * [Delete a Schema Revision](#delete-a-schema-revision) * [Delete Subscription](#delete-subscription) * [Delete Topic](#delete-topic) * [Detach Subscription](#detach-subscription) @@ -63,6 +66,7 @@ guides. * [Quickstart](#quickstart) * [Remove Dead Letter Policy](#remove-dead-letter-policy) * [Resume Publish](#resume-publish) + * [Rollback a Schema](#rollback-a-schema) * [Set Subscription IAM Policy](#set-subscription-iam-policy) * [Set Topic IAM Policy](#set-topic-iam-policy) * [Subscribe With Flow Control Settings](#subscribe-with-flow-control-settings) @@ -72,6 +76,7 @@ guides. * [Test Subscription Permissions](#test-subscription-permissions) * [Test Topic Permissions](#test-topic-permissions) * [Update Dead Letter Policy](#update-dead-letter-policy) + * [Update Topic Schema](#update-topic-schema) * [Validate a schema definition](#validate-a-schema-definition) ## Before you begin @@ -89,6 +94,25 @@ Before running the samples, make sure you've followed the steps outlined in +### Commit an Avro-Based Schema + +Commits a new schema definition revision on a project, using Avro + +View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/commitAvroSchema.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/commitAvroSchema.js,samples/README.md) + +__Usage:__ + + +`node commitAvroSchema.js ` + + +----- + + + + ### Create an Avro based Schema Creates a new schema definition on a project, using Avro @@ -317,6 +341,25 @@ __Usage:__ +### Create Topic With Schema Revisions + +Creates a new topic, with a schema definition and revisions. + +View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createTopicWithSchemaRevisions.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createTopicWithSchemaRevisions.js,samples/README.md) + +__Usage:__ + + +`node createTopicWithSchema.js ` + + +----- + + + + ### Delete a previously created schema Deletes a schema which was previously created in the project. @@ -336,6 +379,25 @@ __Usage:__ +### Delete a Schema Revision + +Deletes a new schema revision on a project + +View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/deleteSchemaRevision.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/deleteSchemaRevision.js,samples/README.md) + +__Usage:__ + + +`node deleteSchemaRevision.js ` + + +----- + + + + ### Delete Subscription Deletes an existing subscription from a topic. @@ -906,6 +968,25 @@ __Usage:__ +### Rollback a Schema + +Rolls back a schema on a project + +View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/rollbackSchema.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/rollbackSchema.js,samples/README.md) + +__Usage:__ + + +`node rollbackSchema.js ` + + +----- + + + + ### Set Subscription IAM Policy Sets the IAM policy for a subscription. @@ -1077,6 +1158,25 @@ __Usage:__ +### Update Topic Schema + +Update the schema on a topic. + +View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/updateTopicSchema.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/updateTopicSchema.js,samples/README.md) + +__Usage:__ + + +`node updateTopicSchema.js ` + + +----- + + + + ### Validate a schema definition Validates an Avro-based schema definition before creation (or other use). diff --git a/samples/commitAvroSchema.js b/samples/commitAvroSchema.js index 76454428e..d186916b5 100644 --- a/samples/commitAvroSchema.js +++ b/samples/commitAvroSchema.js @@ -45,12 +45,24 @@ const fs = require('fs'); const pubSubClient = new PubSub(); async function commitAvroSchema(schemaNameOrId, avscFile) { - const definition = fs.readFileSync(avscFile).toString(); + // Get the fully qualified schema name. const schema = pubSubClient.schema(schemaNameOrId); - await schema.commitSchema(SchemaTypes.Avro, definition); - const name = await schema.getName(); - console.log(`Schema ${name} commited.`); + + // Read the new schema definition from storage. + const definition = fs.readFileSync(avscFile).toString(); + + // Use the gapic client to commit the new definition. + const schemaClient = await pubSubClient.getSchemaClient(); + const [result] = await schemaClient.commitSchema({ + name, + schema: { + type: SchemaTypes.Avro, + definition, + }, + }); + + console.log(`Schema ${name} committed with revision ${result.revisionId}.`); } // [END pubsub_create_avro_schema] diff --git a/samples/createTopicWithSchemaRevisions.js b/samples/createTopicWithSchemaRevisions.js index 3d7c19b32..37934e736 100644 --- a/samples/createTopicWithSchemaRevisions.js +++ b/samples/createTopicWithSchemaRevisions.js @@ -75,8 +75,8 @@ function main( topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', encodingType = 'BINARY', - firstRevisionId, - lastRevisionId + firstRevisionId = 'YOUR_REVISION_ID', + lastRevisionId = 'YOUR_REVISION_ID' ) { createTopicWithSchemaRevisions( topicNameOrId, diff --git a/samples/deleteSchemaRevision.js b/samples/deleteSchemaRevision.js index bdcba695d..f8a871022 100644 --- a/samples/deleteSchemaRevision.js +++ b/samples/deleteSchemaRevision.js @@ -43,10 +43,18 @@ const {PubSub} = require('@google-cloud/pubsub'); const pubSubClient = new PubSub(); async function deleteSchemaRevision(schemaNameOrId, revisionId) { + // Get the fully qualified schema name. const schema = pubSubClient.schema(schemaNameOrId); - await schema.deleteSchemaRevision(revisionId); + const name = await schema.getName(); - console.log(`Schema ${schemaNameOrId} revision ${revisionId} deleted.`); + // Use the gapic client to delete the schema revision. + const schemaClient = await pubSubClient.getSchemaClient(); + await schemaClient.deleteSchemaRevision({ + name, + revisionId, + }); + + console.log(`Schema ${name} revision ${revisionId} deleted.`); } // [END pubsub_delete_schema_revision] diff --git a/samples/rollbackSchema.js b/samples/rollbackSchema.js index 4084a9729..ae5d8fc3f 100644 --- a/samples/rollbackSchema.js +++ b/samples/rollbackSchema.js @@ -43,10 +43,18 @@ const {PubSub} = require('@google-cloud/pubsub'); const pubSubClient = new PubSub(); async function rollbackSchema(schemaNameOrId, revisionId) { + // Get the fully qualified schema name. const schema = pubSubClient.schema(schemaNameOrId); - await schema.rollbackSchema(revisionId); + const name = await schema.getName(); - console.log(`Schema ${schemaNameOrId} revision ${revisionId} rolled back.`); + // Use the gapic client to roll back the schema revision. + const schemaClient = await pubSubClient.getSchemaClient(); + await schemaClient.rollbackSchema({ + name, + revisionId, + }); + + console.log(`Schema ${name} revision ${revisionId} rolled back.`); } // [END pubsub_rollback_schema] From 6b4786b128a6c37c9217b39bc787eb75e156c066 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Wed, 10 Jan 2024 15:15:24 -0500 Subject: [PATCH 09/23] tests: add more system tests for new schema samples --- samples/system-test/schema.test.ts | 86 ++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 27 deletions(-) diff --git a/samples/system-test/schema.test.ts b/samples/system-test/schema.test.ts index 8cf868050..47616f1b2 100644 --- a/samples/system-test/schema.test.ts +++ b/samples/system-test/schema.test.ts @@ -40,6 +40,7 @@ const execSync = (cmd: string) => cp.execSync(cmd, {encoding: 'utf-8'}); describe('schema', () => { const projectId = process.env.GCLOUD_PROJECT; const pubsub = new PubSub({projectId}); + const clientPromise = pubsub.getSchemaClient(); const resources = new TestResources('schema'); @@ -127,45 +128,34 @@ describe('schema', () => { } async function commitSchema( - testName: string, + schemaId: string, type: 'avro' | 'proto' - ): Promise { + ): Promise { const suffix = type === 'avro' ? 'avsc' : 'proto'; - const encoding = + const typeId = type === 'avro' ? SchemaTypes.Avro : SchemaTypes.ProtocolBuffer; - const def = ( + const definition = ( await fs.readFile(fixturePath(`provinces.${suffix}`)) ).toString(); - const schemaId = getSchemaId(testName); const schema = pubsub.schema(schemaId); - //await schema.commitSchema(encoding, def); - } - - async function createTopicWithSchema( - testName: string, - schemaName: string, - encodingType: SchemaEncoding - ): Promise { - const topicId = getTopicId(testName); - const [topic] = await pubsub.createTopic({ - name: topicId, - schemaSettings: { - schema: fullSchemaName(schemaName), - encoding: encodingType, + const schemaName = await schema.getName(); + const schemaClient = await clientPromise; + const [result] = await schemaClient.commitSchema({ + name: schemaName, + schema: { + type: typeId, + definition, }, }); - assert.ok(topic); - return topic; + return result; } - async function createTopicWithSchemaRevisions( + async function createTopicWithSchema( testName: string, schemaName: string, - encodingType: SchemaEncoding, - firstRevisionId: string, - lastRevisionId: string + encodingType: SchemaEncoding ): Promise { const topicId = getTopicId(testName); const [topic] = await pubsub.createTopic({ @@ -173,8 +163,6 @@ describe('schema', () => { schemaSettings: { schema: fullSchemaName(schemaName), encoding: encodingType, - firstRevisionId, - lastRevisionId, }, }); assert.ok(topic); @@ -193,6 +181,18 @@ describe('schema', () => { return sub; } + it('should commit an avro schema', async () => { + const schema = await createSchema('commit_schema', 'avro'); + const name = await schema.getName(); + const output = execSync( + `${commandFor('commitAvroSchema')} ${name} ${fixturePath( + 'provinces.avsc' + )}` + ); + assert.include(output, name); + assert.include(output, 'committed'); + }); + it('should create an avro schema', async () => { const schemaId = getSchemaId('create_avro'); const output = execSync( @@ -253,6 +253,9 @@ describe('schema', () => { it('should create a topic with schema revisions', async () => { const id = 'create_topic_rev'; const schema = await createSchema(id, 'proto'); + const committed = await commitSchema(await schema.getName(), 'proto'); + const revId = committed.revisionId!; + const topicId = getTopicId(id); const output = execSync( `${commandFor('createTopicWithSchemaRevisions')} ${topicId} ${ @@ -265,6 +268,8 @@ describe('schema', () => { const [topic] = await pubsub.topic(topicId).get(); assert.include(topic.metadata?.schemaSettings?.schema, schema.id); + assert.strictEqual(topic.metadata?.schemaSettings?.firstRevisionId, revId); + assert.strictEqual(topic.metadata?.schemaSettings?.lastRevisionId, revId); }); it('should delete a schema', async () => { @@ -283,6 +288,33 @@ describe('schema', () => { }*/ }); + it('should delete a schema revision', async () => { + const id = 'delete_rev'; + const schema = await createSchema(id, 'proto'); + const committed = await commitSchema(await schema.getName(), 'proto'); + const revId = committed.revisionId!; + + const output = execSync( + `${commandFor('deleteSchemaRevision')} ${schema.id} ${revId}` + ); + assert.include(output, schema.id); + assert.include(output, 'deleted.'); + }); + + it('should rollback a schema revision', async () => { + const id = 'rollback_rev'; + const schema = await createSchema(id, 'proto'); + const committed = await commitSchema(await schema.getName(), 'proto'); + const revId = committed.revisionId!; + await commitSchema(await schema.getName(), 'proto'); + + const output = execSync( + `${commandFor('rollbackSchema')} ${schema.id} ${revId}` + ); + assert.include(output, schema.id); + assert.include(output, 'rolled back.'); + }); + it('should get a schema', async () => { const schema = await createSchema('get', 'proto'); From 1f7600b4697e4fd54b77ee305582d24c41a7040d Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Wed, 10 Jan 2024 15:33:42 -0500 Subject: [PATCH 10/23] samples: add listSchemaRevisions sample --- samples/listSchemaRevisions.js | 68 +++++++++++++++++++++++ samples/system-test/schema.test.ts | 17 ++++++ samples/typescript/listSchemaRevisions.ts | 64 +++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 samples/listSchemaRevisions.js create mode 100644 samples/typescript/listSchemaRevisions.ts diff --git a/samples/listSchemaRevisions.js b/samples/listSchemaRevisions.js new file mode 100644 index 000000000..b6a621b87 --- /dev/null +++ b/samples/listSchemaRevisions.js @@ -0,0 +1,68 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is a generated sample, using the typeless sample bot. Please +// look for the source TypeScript sample (.ts) for modifications. +'use strict'; + +/** + * This application demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: List Revisions on a Schema +// description: Gets a list of revisions on a schema which was previously created in the project. +// usage: node listSchemaRevisions.js + +// [START pubsub_list_schema_revisions] +/** + * TODO(developer): Uncomment this variable before running the sample. + */ +// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID'; + +// Imports the Google Cloud client library +const {PubSub} = require('@google-cloud/pubsub'); + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function listSchemaRevisions(schemaNameOrId) { + // Get the fully qualified schema name. + const schema = pubSubClient.schema(schemaNameOrId); + const name = await schema.getName(); + + // Use the gapic client to list the schema revisions. + const schemaClient = await pubSubClient.getSchemaClient(); + const [results] = await schemaClient.listSchemaRevisions({ + name, + }); + for (const rev of results) { + console.log(rev.revisionId, rev.revisionCreateTime); + } + console.log(`Listed revisions of schema ${name}.`); +} +// [END pubsub_list_schema_revisions] + +function main(schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID') { + listSchemaRevisions(schemaNameOrId).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/system-test/schema.test.ts b/samples/system-test/schema.test.ts index 47616f1b2..1e190c34a 100644 --- a/samples/system-test/schema.test.ts +++ b/samples/system-test/schema.test.ts @@ -315,6 +315,23 @@ describe('schema', () => { assert.include(output, 'rolled back.'); }); + it("should list a schema's revisions", async () => { + const id = 'list_rev'; + const schema = await createSchema(id, 'proto'); + const committed = await commitSchema(await schema.getName(), 'proto'); + const revId = committed.revisionId!; + const committed2 = await commitSchema(await schema.getName(), 'proto'); + const revId2 = committed2.revisionId!; + + const output = execSync( + `${commandFor('listSchemaRevisions')} ${schema.id}` + ); + assert.include(output, schema.id); + assert.include(output, revId); + assert.include(output, revId2); + assert.include(output, 'Listed revisions'); + }); + it('should get a schema', async () => { const schema = await createSchema('get', 'proto'); diff --git a/samples/typescript/listSchemaRevisions.ts b/samples/typescript/listSchemaRevisions.ts new file mode 100644 index 000000000..e7b49bdce --- /dev/null +++ b/samples/typescript/listSchemaRevisions.ts @@ -0,0 +1,64 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * This application demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: List Revisions on a Schema +// description: Gets a list of revisions on a schema which was previously created in the project. +// usage: node listSchemaRevisions.js + +// [START pubsub_list_schema_revisions] +/** + * TODO(developer): Uncomment this variable before running the sample. + */ +// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID'; + +// Imports the Google Cloud client library +import {PubSub} from '@google-cloud/pubsub'; + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function listSchemaRevisions(schemaNameOrId: string) { + // Get the fully qualified schema name. + const schema = pubSubClient.schema(schemaNameOrId); + const name = await schema.getName(); + + // Use the gapic client to list the schema revisions. + const schemaClient = await pubSubClient.getSchemaClient(); + const [results] = await schemaClient.listSchemaRevisions({ + name, + }); + for (const rev of results) { + console.log(rev.revisionId, rev.revisionCreateTime); + } + console.log(`Listed revisions of schema ${name}.`); +} +// [END pubsub_list_schema_revisions] + +function main(schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID') { + listSchemaRevisions(schemaNameOrId).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); From 9865a1fba0b338010be42c463b781a5e4459ee27 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Wed, 10 Jan 2024 15:37:07 -0500 Subject: [PATCH 11/23] samples: mismatched end tag --- samples/commitAvroSchema.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/commitAvroSchema.js b/samples/commitAvroSchema.js index d186916b5..2e16f4b17 100644 --- a/samples/commitAvroSchema.js +++ b/samples/commitAvroSchema.js @@ -64,7 +64,7 @@ async function commitAvroSchema(schemaNameOrId, avscFile) { console.log(`Schema ${name} committed with revision ${result.revisionId}.`); } -// [END pubsub_create_avro_schema] +// [END pubsub_commit_avro_schema] function main( schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', From c508ab5e6c6f688f974c480b489d920e8e9979bf Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 10 Jan 2024 20:37:25 +0000 Subject: [PATCH 12/23] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 1 + samples/README.md | 20 ++++++++++++++++++++ samples/commitAvroSchema.js | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c1fec11ed..2869c8665 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-pubsub/tree | Get Subscription Policy | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/getSubscriptionPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/getSubscriptionPolicy.js,samples/README.md) | | Get Topic Policy | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/getTopicPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/getTopicPolicy.js,samples/README.md) | | List All Topics | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listAllTopics.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listAllTopics.js,samples/README.md) | +| List Revisions on a Schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listSchemaRevisions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listSchemaRevisions.js,samples/README.md) | | List schemas on a project | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listSchemas.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listSchemas.js,samples/README.md) | | List Subscriptions | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listSubscriptions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listSubscriptions.js,samples/README.md) | | List Subscriptions On a Topic | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listTopicSubscriptions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listTopicSubscriptions.js,samples/README.md) | diff --git a/samples/README.md b/samples/README.md index 231f2f303..2cc22e5d3 100644 --- a/samples/README.md +++ b/samples/README.md @@ -44,6 +44,7 @@ guides. * [Get Subscription Policy](#get-subscription-policy) * [Get Topic Policy](#get-topic-policy) * [List All Topics](#list-all-topics) + * [List Revisions on a Schema](#list-revisions-on-a-schema) * [List schemas on a project](#list-schemas-on-a-project) * [List Subscriptions](#list-subscriptions) * [List Subscriptions On a Topic](#list-subscriptions-on-a-topic) @@ -550,6 +551,25 @@ __Usage:__ +### List Revisions on a Schema + +Gets a list of revisions on a schema which was previously created in the project. + +View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listSchemaRevisions.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listSchemaRevisions.js,samples/README.md) + +__Usage:__ + + +`node listSchemaRevisions.js ` + + +----- + + + + ### List schemas on a project Gets a list of schemas which were previously created in the project. diff --git a/samples/commitAvroSchema.js b/samples/commitAvroSchema.js index d186916b5..2e16f4b17 100644 --- a/samples/commitAvroSchema.js +++ b/samples/commitAvroSchema.js @@ -64,7 +64,7 @@ async function commitAvroSchema(schemaNameOrId, avscFile) { console.log(`Schema ${name} committed with revision ${result.revisionId}.`); } -// [END pubsub_create_avro_schema] +// [END pubsub_commit_avro_schema] function main( schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', From 80e1f28c7153fcdbb394536ceba22bd3e406c6cf Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Thu, 11 Jan 2024 16:30:33 -0500 Subject: [PATCH 13/23] tests: schema name must be passed in both places --- samples/system-test/schema.test.ts | 8 +++++--- samples/typescript/commitAvroSchema.ts | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/samples/system-test/schema.test.ts b/samples/system-test/schema.test.ts index 1e190c34a..df99626a6 100644 --- a/samples/system-test/schema.test.ts +++ b/samples/system-test/schema.test.ts @@ -144,6 +144,7 @@ describe('schema', () => { const [result] = await schemaClient.commitSchema({ name: schemaName, schema: { + name: schemaName, type: typeId, definition, }, @@ -260,7 +261,7 @@ describe('schema', () => { const output = execSync( `${commandFor('createTopicWithSchemaRevisions')} ${topicId} ${ schema.id - } BINARY` + } BINARY ${revId} ${revId}` ); assert.include(output, topicId); assert.include(output, schema.id); @@ -304,9 +305,10 @@ describe('schema', () => { it('should rollback a schema revision', async () => { const id = 'rollback_rev'; const schema = await createSchema(id, 'proto'); - const committed = await commitSchema(await schema.getName(), 'proto'); + const name = await schema.getName(); + const committed = await commitSchema(name, 'proto'); const revId = committed.revisionId!; - await commitSchema(await schema.getName(), 'proto'); + await commitSchema(name, 'proto'); const output = execSync( `${commandFor('rollbackSchema')} ${schema.id} ${revId}` diff --git a/samples/typescript/commitAvroSchema.ts b/samples/typescript/commitAvroSchema.ts index 8a068adf3..983aab6c0 100644 --- a/samples/typescript/commitAvroSchema.ts +++ b/samples/typescript/commitAvroSchema.ts @@ -53,6 +53,7 @@ async function commitAvroSchema(schemaNameOrId: string, avscFile: string) { const [result] = await schemaClient.commitSchema({ name, schema: { + name, type: SchemaTypes.Avro, definition, }, From 96337ea76ddb4e2fe01cc9a9bc1070a05220d90e Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 11 Jan 2024 21:35:23 +0000 Subject: [PATCH 14/23] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- samples/commitAvroSchema.js | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/commitAvroSchema.js b/samples/commitAvroSchema.js index 2e16f4b17..b9a6eff73 100644 --- a/samples/commitAvroSchema.js +++ b/samples/commitAvroSchema.js @@ -57,6 +57,7 @@ async function commitAvroSchema(schemaNameOrId, avscFile) { const [result] = await schemaClient.commitSchema({ name, schema: { + name, type: SchemaTypes.Avro, definition, }, From f96f5efb7b440ba2eb198265d41a6b637b5e02d6 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Fri, 12 Jan 2024 14:17:13 -0500 Subject: [PATCH 15/23] samples: use @ syntax for delete --- samples/system-test/schema.test.ts | 6 ++++-- samples/typescript/deleteSchemaRevision.ts | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/samples/system-test/schema.test.ts b/samples/system-test/schema.test.ts index df99626a6..446fba7a0 100644 --- a/samples/system-test/schema.test.ts +++ b/samples/system-test/schema.test.ts @@ -292,8 +292,10 @@ describe('schema', () => { it('should delete a schema revision', async () => { const id = 'delete_rev'; const schema = await createSchema(id, 'proto'); - const committed = await commitSchema(await schema.getName(), 'proto'); - const revId = committed.revisionId!; + const name = await schema.getName(); + await commitSchema(name, 'proto'); + const committed2 = await commitSchema(name, 'proto'); + const revId = committed2.revisionId!; const output = execSync( `${commandFor('deleteSchemaRevision')} ${schema.id} ${revId}` diff --git a/samples/typescript/deleteSchemaRevision.ts b/samples/typescript/deleteSchemaRevision.ts index 9ee7e8b67..a3df6ff5b 100644 --- a/samples/typescript/deleteSchemaRevision.ts +++ b/samples/typescript/deleteSchemaRevision.ts @@ -49,8 +49,7 @@ async function deleteSchemaRevision( // Use the gapic client to delete the schema revision. const schemaClient = await pubSubClient.getSchemaClient(); await schemaClient.deleteSchemaRevision({ - name, - revisionId, + name: `${name}@${revisionId}`, }); console.log(`Schema ${name} revision ${revisionId} deleted.`); From 882204299dad840657c99c4b7dec802c48639d26 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Fri, 12 Jan 2024 14:18:49 -0500 Subject: [PATCH 16/23] samples: also commit js to work around merging --- samples/commitAvroSchema.js | 1 + samples/deleteSchemaRevision.js | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/commitAvroSchema.js b/samples/commitAvroSchema.js index 2e16f4b17..b9a6eff73 100644 --- a/samples/commitAvroSchema.js +++ b/samples/commitAvroSchema.js @@ -57,6 +57,7 @@ async function commitAvroSchema(schemaNameOrId, avscFile) { const [result] = await schemaClient.commitSchema({ name, schema: { + name, type: SchemaTypes.Avro, definition, }, diff --git a/samples/deleteSchemaRevision.js b/samples/deleteSchemaRevision.js index f8a871022..ad4f8edd6 100644 --- a/samples/deleteSchemaRevision.js +++ b/samples/deleteSchemaRevision.js @@ -50,8 +50,7 @@ async function deleteSchemaRevision(schemaNameOrId, revisionId) { // Use the gapic client to delete the schema revision. const schemaClient = await pubSubClient.getSchemaClient(); await schemaClient.deleteSchemaRevision({ - name, - revisionId, + name: `${name}@${revisionId}`, }); console.log(`Schema ${name} revision ${revisionId} deleted.`); From 05d7ff5d9d36e02e5994616d0251c926db1fb871 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 12 Jan 2024 19:24:31 +0000 Subject: [PATCH 17/23] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- protos/protos.d.ts | 280 ++++++++++-- protos/protos.js | 1083 +++++++++++++++++++++++++++++++++++++++----- protos/protos.json | 118 +++-- 3 files changed, 1299 insertions(+), 182 deletions(-) diff --git a/protos/protos.d.ts b/protos/protos.d.ts index ee6416f9d..eb65e4c60 100644 --- a/protos/protos.d.ts +++ b/protos/protos.d.ts @@ -9899,6 +9899,9 @@ export namespace google { /** MethodSettings longRunning */ longRunning?: (google.api.MethodSettings.ILongRunning|null); + + /** MethodSettings autoPopulatedFields */ + autoPopulatedFields?: (string[]|null); } /** Represents a MethodSettings. */ @@ -9916,6 +9919,9 @@ export namespace google { /** MethodSettings longRunning. */ public longRunning?: (google.api.MethodSettings.ILongRunning|null); + /** MethodSettings autoPopulatedFields. */ + public autoPopulatedFields: string[]; + /** * Creates a new MethodSettings instance using the specified properties. * @param [properties] Properties to set @@ -10152,7 +10158,8 @@ export namespace google { INPUT_ONLY = 4, IMMUTABLE = 5, UNORDERED_LIST = 6, - NON_EMPTY_DEFAULT = 7 + NON_EMPTY_DEFAULT = 7, + IDENTIFIER = 8 } /** Properties of a ResourceDescriptor. */ @@ -10508,6 +10515,21 @@ export namespace google { public static getTypeUrl(typeUrlPrefix?: string): string; } + /** Edition enum. */ + enum Edition { + EDITION_UNKNOWN = 0, + EDITION_PROTO2 = 998, + EDITION_PROTO3 = 999, + EDITION_2023 = 1000, + EDITION_2024 = 1001, + EDITION_1_TEST_ONLY = 1, + EDITION_2_TEST_ONLY = 2, + EDITION_99997_TEST_ONLY = 99997, + EDITION_99998_TEST_ONLY = 99998, + EDITION_99999_TEST_ONLY = 99999, + EDITION_MAX = 2147483647 + } + /** Properties of a FileDescriptorProto. */ interface IFileDescriptorProto { @@ -10548,7 +10570,7 @@ export namespace google { syntax?: (string|null); /** FileDescriptorProto edition */ - edition?: (string|null); + edition?: (google.protobuf.Edition|keyof typeof google.protobuf.Edition|null); } /** Represents a FileDescriptorProto. */ @@ -10597,7 +10619,7 @@ export namespace google { public syntax: string; /** FileDescriptorProto edition. */ - public edition: string; + public edition: (google.protobuf.Edition|keyof typeof google.protobuf.Edition); /** * Creates a new FileDescriptorProto instance using the specified properties. @@ -11472,8 +11494,8 @@ export namespace google { /** Label enum. */ enum Label { LABEL_OPTIONAL = 1, - LABEL_REQUIRED = 2, - LABEL_REPEATED = 3 + LABEL_REPEATED = 3, + LABEL_REQUIRED = 2 } } @@ -12185,9 +12207,6 @@ export namespace google { /** FileOptions pyGenericServices */ pyGenericServices?: (boolean|null); - /** FileOptions phpGenericServices */ - phpGenericServices?: (boolean|null); - /** FileOptions deprecated */ deprecated?: (boolean|null); @@ -12264,9 +12283,6 @@ export namespace google { /** FileOptions pyGenericServices. */ public pyGenericServices: boolean; - /** FileOptions phpGenericServices. */ - public phpGenericServices: boolean; - /** FileOptions deprecated. */ public deprecated: boolean; @@ -12740,7 +12756,7 @@ export namespace google { interface IEditionDefault { /** EditionDefault edition */ - edition?: (string|null); + edition?: (google.protobuf.Edition|keyof typeof google.protobuf.Edition|null); /** EditionDefault value */ value?: (string|null); @@ -12756,7 +12772,7 @@ export namespace google { constructor(properties?: google.protobuf.FieldOptions.IEditionDefault); /** EditionDefault edition. */ - public edition: string; + public edition: (google.protobuf.Edition|keyof typeof google.protobuf.Edition); /** EditionDefault value. */ public value: string; @@ -13676,17 +13692,14 @@ export namespace google { /** FeatureSet repeatedFieldEncoding */ repeatedFieldEncoding?: (google.protobuf.FeatureSet.RepeatedFieldEncoding|keyof typeof google.protobuf.FeatureSet.RepeatedFieldEncoding|null); - /** FeatureSet stringFieldValidation */ - stringFieldValidation?: (google.protobuf.FeatureSet.StringFieldValidation|keyof typeof google.protobuf.FeatureSet.StringFieldValidation|null); + /** FeatureSet utf8Validation */ + utf8Validation?: (google.protobuf.FeatureSet.Utf8Validation|keyof typeof google.protobuf.FeatureSet.Utf8Validation|null); /** FeatureSet messageEncoding */ messageEncoding?: (google.protobuf.FeatureSet.MessageEncoding|keyof typeof google.protobuf.FeatureSet.MessageEncoding|null); /** FeatureSet jsonFormat */ jsonFormat?: (google.protobuf.FeatureSet.JsonFormat|keyof typeof google.protobuf.FeatureSet.JsonFormat|null); - - /** FeatureSet rawFeatures */ - rawFeatures?: (google.protobuf.IFeatureSet|null); } /** Represents a FeatureSet. */ @@ -13707,8 +13720,8 @@ export namespace google { /** FeatureSet repeatedFieldEncoding. */ public repeatedFieldEncoding: (google.protobuf.FeatureSet.RepeatedFieldEncoding|keyof typeof google.protobuf.FeatureSet.RepeatedFieldEncoding); - /** FeatureSet stringFieldValidation. */ - public stringFieldValidation: (google.protobuf.FeatureSet.StringFieldValidation|keyof typeof google.protobuf.FeatureSet.StringFieldValidation); + /** FeatureSet utf8Validation. */ + public utf8Validation: (google.protobuf.FeatureSet.Utf8Validation|keyof typeof google.protobuf.FeatureSet.Utf8Validation); /** FeatureSet messageEncoding. */ public messageEncoding: (google.protobuf.FeatureSet.MessageEncoding|keyof typeof google.protobuf.FeatureSet.MessageEncoding); @@ -13716,9 +13729,6 @@ export namespace google { /** FeatureSet jsonFormat. */ public jsonFormat: (google.protobuf.FeatureSet.JsonFormat|keyof typeof google.protobuf.FeatureSet.JsonFormat); - /** FeatureSet rawFeatures. */ - public rawFeatures?: (google.protobuf.IFeatureSet|null); - /** * Creates a new FeatureSet instance using the specified properties. * @param [properties] Properties to set @@ -13821,11 +13831,10 @@ export namespace google { EXPANDED = 2 } - /** StringFieldValidation enum. */ - enum StringFieldValidation { - STRING_FIELD_VALIDATION_UNKNOWN = 0, - MANDATORY = 1, - HINT = 2, + /** Utf8Validation enum. */ + enum Utf8Validation { + UTF8_VALIDATION_UNKNOWN = 0, + VERIFY = 2, NONE = 3 } @@ -13844,6 +13853,221 @@ export namespace google { } } + /** Properties of a FeatureSetDefaults. */ + interface IFeatureSetDefaults { + + /** FeatureSetDefaults defaults */ + defaults?: (google.protobuf.FeatureSetDefaults.IFeatureSetEditionDefault[]|null); + + /** FeatureSetDefaults minimumEdition */ + minimumEdition?: (google.protobuf.Edition|keyof typeof google.protobuf.Edition|null); + + /** FeatureSetDefaults maximumEdition */ + maximumEdition?: (google.protobuf.Edition|keyof typeof google.protobuf.Edition|null); + } + + /** Represents a FeatureSetDefaults. */ + class FeatureSetDefaults implements IFeatureSetDefaults { + + /** + * Constructs a new FeatureSetDefaults. + * @param [properties] Properties to set + */ + constructor(properties?: google.protobuf.IFeatureSetDefaults); + + /** FeatureSetDefaults defaults. */ + public defaults: google.protobuf.FeatureSetDefaults.IFeatureSetEditionDefault[]; + + /** FeatureSetDefaults minimumEdition. */ + public minimumEdition: (google.protobuf.Edition|keyof typeof google.protobuf.Edition); + + /** FeatureSetDefaults maximumEdition. */ + public maximumEdition: (google.protobuf.Edition|keyof typeof google.protobuf.Edition); + + /** + * Creates a new FeatureSetDefaults instance using the specified properties. + * @param [properties] Properties to set + * @returns FeatureSetDefaults instance + */ + public static create(properties?: google.protobuf.IFeatureSetDefaults): google.protobuf.FeatureSetDefaults; + + /** + * Encodes the specified FeatureSetDefaults message. Does not implicitly {@link google.protobuf.FeatureSetDefaults.verify|verify} messages. + * @param message FeatureSetDefaults message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.protobuf.IFeatureSetDefaults, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified FeatureSetDefaults message, length delimited. Does not implicitly {@link google.protobuf.FeatureSetDefaults.verify|verify} messages. + * @param message FeatureSetDefaults message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.protobuf.IFeatureSetDefaults, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a FeatureSetDefaults message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns FeatureSetDefaults + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.FeatureSetDefaults; + + /** + * Decodes a FeatureSetDefaults message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns FeatureSetDefaults + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.FeatureSetDefaults; + + /** + * Verifies a FeatureSetDefaults message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a FeatureSetDefaults message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns FeatureSetDefaults + */ + public static fromObject(object: { [k: string]: any }): google.protobuf.FeatureSetDefaults; + + /** + * Creates a plain object from a FeatureSetDefaults message. Also converts values to other types if specified. + * @param message FeatureSetDefaults + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.protobuf.FeatureSetDefaults, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this FeatureSetDefaults to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for FeatureSetDefaults + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + + namespace FeatureSetDefaults { + + /** Properties of a FeatureSetEditionDefault. */ + interface IFeatureSetEditionDefault { + + /** FeatureSetEditionDefault edition */ + edition?: (google.protobuf.Edition|keyof typeof google.protobuf.Edition|null); + + /** FeatureSetEditionDefault features */ + features?: (google.protobuf.IFeatureSet|null); + } + + /** Represents a FeatureSetEditionDefault. */ + class FeatureSetEditionDefault implements IFeatureSetEditionDefault { + + /** + * Constructs a new FeatureSetEditionDefault. + * @param [properties] Properties to set + */ + constructor(properties?: google.protobuf.FeatureSetDefaults.IFeatureSetEditionDefault); + + /** FeatureSetEditionDefault edition. */ + public edition: (google.protobuf.Edition|keyof typeof google.protobuf.Edition); + + /** FeatureSetEditionDefault features. */ + public features?: (google.protobuf.IFeatureSet|null); + + /** + * Creates a new FeatureSetEditionDefault instance using the specified properties. + * @param [properties] Properties to set + * @returns FeatureSetEditionDefault instance + */ + public static create(properties?: google.protobuf.FeatureSetDefaults.IFeatureSetEditionDefault): google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault; + + /** + * Encodes the specified FeatureSetEditionDefault message. Does not implicitly {@link google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.verify|verify} messages. + * @param message FeatureSetEditionDefault message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.protobuf.FeatureSetDefaults.IFeatureSetEditionDefault, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified FeatureSetEditionDefault message, length delimited. Does not implicitly {@link google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.verify|verify} messages. + * @param message FeatureSetEditionDefault message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.protobuf.FeatureSetDefaults.IFeatureSetEditionDefault, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a FeatureSetEditionDefault message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns FeatureSetEditionDefault + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault; + + /** + * Decodes a FeatureSetEditionDefault message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns FeatureSetEditionDefault + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault; + + /** + * Verifies a FeatureSetEditionDefault message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a FeatureSetEditionDefault message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns FeatureSetEditionDefault + */ + public static fromObject(object: { [k: string]: any }): google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault; + + /** + * Creates a plain object from a FeatureSetEditionDefault message. Also converts values to other types if specified. + * @param message FeatureSetEditionDefault + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this FeatureSetEditionDefault to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for FeatureSetEditionDefault + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + } + /** Properties of a SourceCodeInfo. */ interface ISourceCodeInfo { diff --git a/protos/protos.js b/protos/protos.js index 496d846c0..b4d71be66 100644 --- a/protos/protos.js +++ b/protos/protos.js @@ -23658,6 +23658,7 @@ * @interface IMethodSettings * @property {string|null} [selector] MethodSettings selector * @property {google.api.MethodSettings.ILongRunning|null} [longRunning] MethodSettings longRunning + * @property {Array.|null} [autoPopulatedFields] MethodSettings autoPopulatedFields */ /** @@ -23669,6 +23670,7 @@ * @param {google.api.IMethodSettings=} [properties] Properties to set */ function MethodSettings(properties) { + this.autoPopulatedFields = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -23691,6 +23693,14 @@ */ MethodSettings.prototype.longRunning = null; + /** + * MethodSettings autoPopulatedFields. + * @member {Array.} autoPopulatedFields + * @memberof google.api.MethodSettings + * @instance + */ + MethodSettings.prototype.autoPopulatedFields = $util.emptyArray; + /** * Creates a new MethodSettings instance using the specified properties. * @function create @@ -23719,6 +23729,9 @@ writer.uint32(/* id 1, wireType 2 =*/10).string(message.selector); if (message.longRunning != null && Object.hasOwnProperty.call(message, "longRunning")) $root.google.api.MethodSettings.LongRunning.encode(message.longRunning, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); + if (message.autoPopulatedFields != null && message.autoPopulatedFields.length) + for (var i = 0; i < message.autoPopulatedFields.length; ++i) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.autoPopulatedFields[i]); return writer; }; @@ -23761,6 +23774,12 @@ message.longRunning = $root.google.api.MethodSettings.LongRunning.decode(reader, reader.uint32()); break; } + case 3: { + if (!(message.autoPopulatedFields && message.autoPopulatedFields.length)) + message.autoPopulatedFields = []; + message.autoPopulatedFields.push(reader.string()); + break; + } default: reader.skipType(tag & 7); break; @@ -23804,6 +23823,13 @@ if (error) return "longRunning." + error; } + if (message.autoPopulatedFields != null && message.hasOwnProperty("autoPopulatedFields")) { + if (!Array.isArray(message.autoPopulatedFields)) + return "autoPopulatedFields: array expected"; + for (var i = 0; i < message.autoPopulatedFields.length; ++i) + if (!$util.isString(message.autoPopulatedFields[i])) + return "autoPopulatedFields: string[] expected"; + } return null; }; @@ -23826,6 +23852,13 @@ throw TypeError(".google.api.MethodSettings.longRunning: object expected"); message.longRunning = $root.google.api.MethodSettings.LongRunning.fromObject(object.longRunning); } + if (object.autoPopulatedFields) { + if (!Array.isArray(object.autoPopulatedFields)) + throw TypeError(".google.api.MethodSettings.autoPopulatedFields: array expected"); + message.autoPopulatedFields = []; + for (var i = 0; i < object.autoPopulatedFields.length; ++i) + message.autoPopulatedFields[i] = String(object.autoPopulatedFields[i]); + } return message; }; @@ -23842,6 +23875,8 @@ if (!options) options = {}; var object = {}; + if (options.arrays || options.defaults) + object.autoPopulatedFields = []; if (options.defaults) { object.selector = ""; object.longRunning = null; @@ -23850,6 +23885,11 @@ object.selector = message.selector; if (message.longRunning != null && message.hasOwnProperty("longRunning")) object.longRunning = $root.google.api.MethodSettings.LongRunning.toObject(message.longRunning, options); + if (message.autoPopulatedFields && message.autoPopulatedFields.length) { + object.autoPopulatedFields = []; + for (var j = 0; j < message.autoPopulatedFields.length; ++j) + object.autoPopulatedFields[j] = message.autoPopulatedFields[j]; + } return object; }; @@ -24250,6 +24290,7 @@ * @property {number} IMMUTABLE=5 IMMUTABLE value * @property {number} UNORDERED_LIST=6 UNORDERED_LIST value * @property {number} NON_EMPTY_DEFAULT=7 NON_EMPTY_DEFAULT value + * @property {number} IDENTIFIER=8 IDENTIFIER value */ api.FieldBehavior = (function() { var valuesById = {}, values = Object.create(valuesById); @@ -24261,6 +24302,7 @@ values[valuesById[5] = "IMMUTABLE"] = 5; values[valuesById[6] = "UNORDERED_LIST"] = 6; values[valuesById[7] = "NON_EMPTY_DEFAULT"] = 7; + values[valuesById[8] = "IDENTIFIER"] = 8; return values; })(); @@ -25184,6 +25226,38 @@ return FileDescriptorSet; })(); + /** + * Edition enum. + * @name google.protobuf.Edition + * @enum {number} + * @property {number} EDITION_UNKNOWN=0 EDITION_UNKNOWN value + * @property {number} EDITION_PROTO2=998 EDITION_PROTO2 value + * @property {number} EDITION_PROTO3=999 EDITION_PROTO3 value + * @property {number} EDITION_2023=1000 EDITION_2023 value + * @property {number} EDITION_2024=1001 EDITION_2024 value + * @property {number} EDITION_1_TEST_ONLY=1 EDITION_1_TEST_ONLY value + * @property {number} EDITION_2_TEST_ONLY=2 EDITION_2_TEST_ONLY value + * @property {number} EDITION_99997_TEST_ONLY=99997 EDITION_99997_TEST_ONLY value + * @property {number} EDITION_99998_TEST_ONLY=99998 EDITION_99998_TEST_ONLY value + * @property {number} EDITION_99999_TEST_ONLY=99999 EDITION_99999_TEST_ONLY value + * @property {number} EDITION_MAX=2147483647 EDITION_MAX value + */ + protobuf.Edition = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "EDITION_UNKNOWN"] = 0; + values[valuesById[998] = "EDITION_PROTO2"] = 998; + values[valuesById[999] = "EDITION_PROTO3"] = 999; + values[valuesById[1000] = "EDITION_2023"] = 1000; + values[valuesById[1001] = "EDITION_2024"] = 1001; + values[valuesById[1] = "EDITION_1_TEST_ONLY"] = 1; + values[valuesById[2] = "EDITION_2_TEST_ONLY"] = 2; + values[valuesById[99997] = "EDITION_99997_TEST_ONLY"] = 99997; + values[valuesById[99998] = "EDITION_99998_TEST_ONLY"] = 99998; + values[valuesById[99999] = "EDITION_99999_TEST_ONLY"] = 99999; + values[valuesById[2147483647] = "EDITION_MAX"] = 2147483647; + return values; + })(); + protobuf.FileDescriptorProto = (function() { /** @@ -25202,7 +25276,7 @@ * @property {google.protobuf.IFileOptions|null} [options] FileDescriptorProto options * @property {google.protobuf.ISourceCodeInfo|null} [sourceCodeInfo] FileDescriptorProto sourceCodeInfo * @property {string|null} [syntax] FileDescriptorProto syntax - * @property {string|null} [edition] FileDescriptorProto edition + * @property {google.protobuf.Edition|null} [edition] FileDescriptorProto edition */ /** @@ -25325,11 +25399,11 @@ /** * FileDescriptorProto edition. - * @member {string} edition + * @member {google.protobuf.Edition} edition * @memberof google.protobuf.FileDescriptorProto * @instance */ - FileDescriptorProto.prototype.edition = ""; + FileDescriptorProto.prototype.edition = 0; /** * Creates a new FileDescriptorProto instance using the specified properties. @@ -25387,7 +25461,7 @@ if (message.syntax != null && Object.hasOwnProperty.call(message, "syntax")) writer.uint32(/* id 12, wireType 2 =*/98).string(message.syntax); if (message.edition != null && Object.hasOwnProperty.call(message, "edition")) - writer.uint32(/* id 13, wireType 2 =*/106).string(message.edition); + writer.uint32(/* id 14, wireType 0 =*/112).int32(message.edition); return writer; }; @@ -25494,8 +25568,8 @@ message.syntax = reader.string(); break; } - case 13: { - message.edition = reader.string(); + case 14: { + message.edition = reader.int32(); break; } default: @@ -25610,8 +25684,22 @@ if (!$util.isString(message.syntax)) return "syntax: string expected"; if (message.edition != null && message.hasOwnProperty("edition")) - if (!$util.isString(message.edition)) - return "edition: string expected"; + switch (message.edition) { + default: + return "edition: enum value expected"; + case 0: + case 998: + case 999: + case 1000: + case 1001: + case 1: + case 2: + case 99997: + case 99998: + case 99999: + case 2147483647: + break; + } return null; }; @@ -25704,8 +25792,58 @@ } if (object.syntax != null) message.syntax = String(object.syntax); - if (object.edition != null) - message.edition = String(object.edition); + switch (object.edition) { + default: + if (typeof object.edition === "number") { + message.edition = object.edition; + break; + } + break; + case "EDITION_UNKNOWN": + case 0: + message.edition = 0; + break; + case "EDITION_PROTO2": + case 998: + message.edition = 998; + break; + case "EDITION_PROTO3": + case 999: + message.edition = 999; + break; + case "EDITION_2023": + case 1000: + message.edition = 1000; + break; + case "EDITION_2024": + case 1001: + message.edition = 1001; + break; + case "EDITION_1_TEST_ONLY": + case 1: + message.edition = 1; + break; + case "EDITION_2_TEST_ONLY": + case 2: + message.edition = 2; + break; + case "EDITION_99997_TEST_ONLY": + case 99997: + message.edition = 99997; + break; + case "EDITION_99998_TEST_ONLY": + case 99998: + message.edition = 99998; + break; + case "EDITION_99999_TEST_ONLY": + case 99999: + message.edition = 99999; + break; + case "EDITION_MAX": + case 2147483647: + message.edition = 2147483647; + break; + } return message; }; @@ -25737,7 +25875,7 @@ object.options = null; object.sourceCodeInfo = null; object.syntax = ""; - object.edition = ""; + object.edition = options.enums === String ? "EDITION_UNKNOWN" : 0; } if (message.name != null && message.hasOwnProperty("name")) object.name = message.name; @@ -25785,7 +25923,7 @@ if (message.syntax != null && message.hasOwnProperty("syntax")) object.syntax = message.syntax; if (message.edition != null && message.hasOwnProperty("edition")) - object.edition = message.edition; + object.edition = options.enums === String ? $root.google.protobuf.Edition[message.edition] === undefined ? message.edition : $root.google.protobuf.Edition[message.edition] : message.edition; return object; }; @@ -27824,8 +27962,8 @@ default: return "label: enum value expected"; case 1: - case 2: case 3: + case 2: break; } if (message.type != null && message.hasOwnProperty("type")) @@ -27905,14 +28043,14 @@ case 1: message.label = 1; break; - case "LABEL_REQUIRED": - case 2: - message.label = 2; - break; case "LABEL_REPEATED": case 3: message.label = 3; break; + case "LABEL_REQUIRED": + case 2: + message.label = 2; + break; } switch (object.type) { default: @@ -28142,14 +28280,14 @@ * @name google.protobuf.FieldDescriptorProto.Label * @enum {number} * @property {number} LABEL_OPTIONAL=1 LABEL_OPTIONAL value - * @property {number} LABEL_REQUIRED=2 LABEL_REQUIRED value * @property {number} LABEL_REPEATED=3 LABEL_REPEATED value + * @property {number} LABEL_REQUIRED=2 LABEL_REQUIRED value */ FieldDescriptorProto.Label = (function() { var valuesById = {}, values = Object.create(valuesById); values[valuesById[1] = "LABEL_OPTIONAL"] = 1; - values[valuesById[2] = "LABEL_REQUIRED"] = 2; values[valuesById[3] = "LABEL_REPEATED"] = 3; + values[valuesById[2] = "LABEL_REQUIRED"] = 2; return values; })(); @@ -29848,7 +29986,6 @@ * @property {boolean|null} [ccGenericServices] FileOptions ccGenericServices * @property {boolean|null} [javaGenericServices] FileOptions javaGenericServices * @property {boolean|null} [pyGenericServices] FileOptions pyGenericServices - * @property {boolean|null} [phpGenericServices] FileOptions phpGenericServices * @property {boolean|null} [deprecated] FileOptions deprecated * @property {boolean|null} [ccEnableArenas] FileOptions ccEnableArenas * @property {string|null} [objcClassPrefix] FileOptions objcClassPrefix @@ -29960,14 +30097,6 @@ */ FileOptions.prototype.pyGenericServices = false; - /** - * FileOptions phpGenericServices. - * @member {boolean} phpGenericServices - * @memberof google.protobuf.FileOptions - * @instance - */ - FileOptions.prototype.phpGenericServices = false; - /** * FileOptions deprecated. * @member {boolean} deprecated @@ -30122,8 +30251,6 @@ writer.uint32(/* id 40, wireType 2 =*/322).string(message.phpClassPrefix); if (message.phpNamespace != null && Object.hasOwnProperty.call(message, "phpNamespace")) writer.uint32(/* id 41, wireType 2 =*/330).string(message.phpNamespace); - if (message.phpGenericServices != null && Object.hasOwnProperty.call(message, "phpGenericServices")) - writer.uint32(/* id 42, wireType 0 =*/336).bool(message.phpGenericServices); if (message.phpMetadataNamespace != null && Object.hasOwnProperty.call(message, "phpMetadataNamespace")) writer.uint32(/* id 44, wireType 2 =*/354).string(message.phpMetadataNamespace); if (message.rubyPackage != null && Object.hasOwnProperty.call(message, "rubyPackage")) @@ -30210,10 +30337,6 @@ message.pyGenericServices = reader.bool(); break; } - case 42: { - message.phpGenericServices = reader.bool(); - break; - } case 23: { message.deprecated = reader.bool(); break; @@ -30337,9 +30460,6 @@ if (message.pyGenericServices != null && message.hasOwnProperty("pyGenericServices")) if (typeof message.pyGenericServices !== "boolean") return "pyGenericServices: boolean expected"; - if (message.phpGenericServices != null && message.hasOwnProperty("phpGenericServices")) - if (typeof message.phpGenericServices !== "boolean") - return "phpGenericServices: boolean expected"; if (message.deprecated != null && message.hasOwnProperty("deprecated")) if (typeof message.deprecated !== "boolean") return "deprecated: boolean expected"; @@ -30443,8 +30563,6 @@ message.javaGenericServices = Boolean(object.javaGenericServices); if (object.pyGenericServices != null) message.pyGenericServices = Boolean(object.pyGenericServices); - if (object.phpGenericServices != null) - message.phpGenericServices = Boolean(object.phpGenericServices); if (object.deprecated != null) message.deprecated = Boolean(object.deprecated); if (object.ccEnableArenas != null) @@ -30526,7 +30644,6 @@ object.swiftPrefix = ""; object.phpClassPrefix = ""; object.phpNamespace = ""; - object.phpGenericServices = false; object.phpMetadataNamespace = ""; object.rubyPackage = ""; object.features = null; @@ -30565,8 +30682,6 @@ object.phpClassPrefix = message.phpClassPrefix; if (message.phpNamespace != null && message.hasOwnProperty("phpNamespace")) object.phpNamespace = message.phpNamespace; - if (message.phpGenericServices != null && message.hasOwnProperty("phpGenericServices")) - object.phpGenericServices = message.phpGenericServices; if (message.phpMetadataNamespace != null && message.hasOwnProperty("phpMetadataNamespace")) object.phpMetadataNamespace = message.phpMetadataNamespace; if (message.rubyPackage != null && message.hasOwnProperty("rubyPackage")) @@ -31501,6 +31616,7 @@ case 5: case 6: case 7: + case 8: break; } } @@ -31717,6 +31833,10 @@ case 7: message[".google.api.fieldBehavior"][i] = 7; break; + case "IDENTIFIER": + case 8: + message[".google.api.fieldBehavior"][i] = 8; + break; } } if (object[".google.api.resourceReference"] != null) { @@ -31914,7 +32034,7 @@ * Properties of an EditionDefault. * @memberof google.protobuf.FieldOptions * @interface IEditionDefault - * @property {string|null} [edition] EditionDefault edition + * @property {google.protobuf.Edition|null} [edition] EditionDefault edition * @property {string|null} [value] EditionDefault value */ @@ -31935,11 +32055,11 @@ /** * EditionDefault edition. - * @member {string} edition + * @member {google.protobuf.Edition} edition * @memberof google.protobuf.FieldOptions.EditionDefault * @instance */ - EditionDefault.prototype.edition = ""; + EditionDefault.prototype.edition = 0; /** * EditionDefault value. @@ -31973,10 +32093,10 @@ EditionDefault.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); - if (message.edition != null && Object.hasOwnProperty.call(message, "edition")) - writer.uint32(/* id 1, wireType 2 =*/10).string(message.edition); if (message.value != null && Object.hasOwnProperty.call(message, "value")) writer.uint32(/* id 2, wireType 2 =*/18).string(message.value); + if (message.edition != null && Object.hasOwnProperty.call(message, "edition")) + writer.uint32(/* id 3, wireType 0 =*/24).int32(message.edition); return writer; }; @@ -32011,8 +32131,8 @@ while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { - case 1: { - message.edition = reader.string(); + case 3: { + message.edition = reader.int32(); break; } case 2: { @@ -32055,8 +32175,22 @@ if (typeof message !== "object" || message === null) return "object expected"; if (message.edition != null && message.hasOwnProperty("edition")) - if (!$util.isString(message.edition)) - return "edition: string expected"; + switch (message.edition) { + default: + return "edition: enum value expected"; + case 0: + case 998: + case 999: + case 1000: + case 1001: + case 1: + case 2: + case 99997: + case 99998: + case 99999: + case 2147483647: + break; + } if (message.value != null && message.hasOwnProperty("value")) if (!$util.isString(message.value)) return "value: string expected"; @@ -32075,8 +32209,58 @@ if (object instanceof $root.google.protobuf.FieldOptions.EditionDefault) return object; var message = new $root.google.protobuf.FieldOptions.EditionDefault(); - if (object.edition != null) - message.edition = String(object.edition); + switch (object.edition) { + default: + if (typeof object.edition === "number") { + message.edition = object.edition; + break; + } + break; + case "EDITION_UNKNOWN": + case 0: + message.edition = 0; + break; + case "EDITION_PROTO2": + case 998: + message.edition = 998; + break; + case "EDITION_PROTO3": + case 999: + message.edition = 999; + break; + case "EDITION_2023": + case 1000: + message.edition = 1000; + break; + case "EDITION_2024": + case 1001: + message.edition = 1001; + break; + case "EDITION_1_TEST_ONLY": + case 1: + message.edition = 1; + break; + case "EDITION_2_TEST_ONLY": + case 2: + message.edition = 2; + break; + case "EDITION_99997_TEST_ONLY": + case 99997: + message.edition = 99997; + break; + case "EDITION_99998_TEST_ONLY": + case 99998: + message.edition = 99998; + break; + case "EDITION_99999_TEST_ONLY": + case 99999: + message.edition = 99999; + break; + case "EDITION_MAX": + case 2147483647: + message.edition = 2147483647; + break; + } if (object.value != null) message.value = String(object.value); return message; @@ -32096,13 +32280,13 @@ options = {}; var object = {}; if (options.defaults) { - object.edition = ""; object.value = ""; + object.edition = options.enums === String ? "EDITION_UNKNOWN" : 0; } - if (message.edition != null && message.hasOwnProperty("edition")) - object.edition = message.edition; if (message.value != null && message.hasOwnProperty("value")) object.value = message.value; + if (message.edition != null && message.hasOwnProperty("edition")) + object.edition = options.enums === String ? $root.google.protobuf.Edition[message.edition] === undefined ? message.edition : $root.google.protobuf.Edition[message.edition] : message.edition; return object; }; @@ -34382,10 +34566,9 @@ * @property {google.protobuf.FeatureSet.FieldPresence|null} [fieldPresence] FeatureSet fieldPresence * @property {google.protobuf.FeatureSet.EnumType|null} [enumType] FeatureSet enumType * @property {google.protobuf.FeatureSet.RepeatedFieldEncoding|null} [repeatedFieldEncoding] FeatureSet repeatedFieldEncoding - * @property {google.protobuf.FeatureSet.StringFieldValidation|null} [stringFieldValidation] FeatureSet stringFieldValidation + * @property {google.protobuf.FeatureSet.Utf8Validation|null} [utf8Validation] FeatureSet utf8Validation * @property {google.protobuf.FeatureSet.MessageEncoding|null} [messageEncoding] FeatureSet messageEncoding * @property {google.protobuf.FeatureSet.JsonFormat|null} [jsonFormat] FeatureSet jsonFormat - * @property {google.protobuf.IFeatureSet|null} [rawFeatures] FeatureSet rawFeatures */ /** @@ -34428,12 +34611,12 @@ FeatureSet.prototype.repeatedFieldEncoding = 0; /** - * FeatureSet stringFieldValidation. - * @member {google.protobuf.FeatureSet.StringFieldValidation} stringFieldValidation + * FeatureSet utf8Validation. + * @member {google.protobuf.FeatureSet.Utf8Validation} utf8Validation * @memberof google.protobuf.FeatureSet * @instance */ - FeatureSet.prototype.stringFieldValidation = 0; + FeatureSet.prototype.utf8Validation = 0; /** * FeatureSet messageEncoding. @@ -34451,14 +34634,6 @@ */ FeatureSet.prototype.jsonFormat = 0; - /** - * FeatureSet rawFeatures. - * @member {google.protobuf.IFeatureSet|null|undefined} rawFeatures - * @memberof google.protobuf.FeatureSet - * @instance - */ - FeatureSet.prototype.rawFeatures = null; - /** * Creates a new FeatureSet instance using the specified properties. * @function create @@ -34489,14 +34664,12 @@ writer.uint32(/* id 2, wireType 0 =*/16).int32(message.enumType); if (message.repeatedFieldEncoding != null && Object.hasOwnProperty.call(message, "repeatedFieldEncoding")) writer.uint32(/* id 3, wireType 0 =*/24).int32(message.repeatedFieldEncoding); - if (message.stringFieldValidation != null && Object.hasOwnProperty.call(message, "stringFieldValidation")) - writer.uint32(/* id 4, wireType 0 =*/32).int32(message.stringFieldValidation); + if (message.utf8Validation != null && Object.hasOwnProperty.call(message, "utf8Validation")) + writer.uint32(/* id 4, wireType 0 =*/32).int32(message.utf8Validation); if (message.messageEncoding != null && Object.hasOwnProperty.call(message, "messageEncoding")) writer.uint32(/* id 5, wireType 0 =*/40).int32(message.messageEncoding); if (message.jsonFormat != null && Object.hasOwnProperty.call(message, "jsonFormat")) writer.uint32(/* id 6, wireType 0 =*/48).int32(message.jsonFormat); - if (message.rawFeatures != null && Object.hasOwnProperty.call(message, "rawFeatures")) - $root.google.protobuf.FeatureSet.encode(message.rawFeatures, writer.uint32(/* id 999, wireType 2 =*/7994).fork()).ldelim(); return writer; }; @@ -34544,7 +34717,7 @@ break; } case 4: { - message.stringFieldValidation = reader.int32(); + message.utf8Validation = reader.int32(); break; } case 5: { @@ -34555,10 +34728,6 @@ message.jsonFormat = reader.int32(); break; } - case 999: { - message.rawFeatures = $root.google.protobuf.FeatureSet.decode(reader, reader.uint32()); - break; - } default: reader.skipType(tag & 7); break; @@ -34622,12 +34791,11 @@ case 2: break; } - if (message.stringFieldValidation != null && message.hasOwnProperty("stringFieldValidation")) - switch (message.stringFieldValidation) { + if (message.utf8Validation != null && message.hasOwnProperty("utf8Validation")) + switch (message.utf8Validation) { default: - return "stringFieldValidation: enum value expected"; + return "utf8Validation: enum value expected"; case 0: - case 1: case 2: case 3: break; @@ -34650,11 +34818,6 @@ case 2: break; } - if (message.rawFeatures != null && message.hasOwnProperty("rawFeatures")) { - var error = $root.google.protobuf.FeatureSet.verify(message.rawFeatures); - if (error) - return "rawFeatures." + error; - } return null; }; @@ -34734,28 +34897,24 @@ message.repeatedFieldEncoding = 2; break; } - switch (object.stringFieldValidation) { + switch (object.utf8Validation) { default: - if (typeof object.stringFieldValidation === "number") { - message.stringFieldValidation = object.stringFieldValidation; + if (typeof object.utf8Validation === "number") { + message.utf8Validation = object.utf8Validation; break; } break; - case "STRING_FIELD_VALIDATION_UNKNOWN": + case "UTF8_VALIDATION_UNKNOWN": case 0: - message.stringFieldValidation = 0; - break; - case "MANDATORY": - case 1: - message.stringFieldValidation = 1; + message.utf8Validation = 0; break; - case "HINT": + case "VERIFY": case 2: - message.stringFieldValidation = 2; + message.utf8Validation = 2; break; case "NONE": case 3: - message.stringFieldValidation = 3; + message.utf8Validation = 3; break; } switch (object.messageEncoding) { @@ -34798,11 +34957,6 @@ message.jsonFormat = 2; break; } - if (object.rawFeatures != null) { - if (typeof object.rawFeatures !== "object") - throw TypeError(".google.protobuf.FeatureSet.rawFeatures: object expected"); - message.rawFeatures = $root.google.protobuf.FeatureSet.fromObject(object.rawFeatures); - } return message; }; @@ -34823,10 +34977,9 @@ object.fieldPresence = options.enums === String ? "FIELD_PRESENCE_UNKNOWN" : 0; object.enumType = options.enums === String ? "ENUM_TYPE_UNKNOWN" : 0; object.repeatedFieldEncoding = options.enums === String ? "REPEATED_FIELD_ENCODING_UNKNOWN" : 0; - object.stringFieldValidation = options.enums === String ? "STRING_FIELD_VALIDATION_UNKNOWN" : 0; + object.utf8Validation = options.enums === String ? "UTF8_VALIDATION_UNKNOWN" : 0; object.messageEncoding = options.enums === String ? "MESSAGE_ENCODING_UNKNOWN" : 0; object.jsonFormat = options.enums === String ? "JSON_FORMAT_UNKNOWN" : 0; - object.rawFeatures = null; } if (message.fieldPresence != null && message.hasOwnProperty("fieldPresence")) object.fieldPresence = options.enums === String ? $root.google.protobuf.FeatureSet.FieldPresence[message.fieldPresence] === undefined ? message.fieldPresence : $root.google.protobuf.FeatureSet.FieldPresence[message.fieldPresence] : message.fieldPresence; @@ -34834,14 +34987,12 @@ object.enumType = options.enums === String ? $root.google.protobuf.FeatureSet.EnumType[message.enumType] === undefined ? message.enumType : $root.google.protobuf.FeatureSet.EnumType[message.enumType] : message.enumType; if (message.repeatedFieldEncoding != null && message.hasOwnProperty("repeatedFieldEncoding")) object.repeatedFieldEncoding = options.enums === String ? $root.google.protobuf.FeatureSet.RepeatedFieldEncoding[message.repeatedFieldEncoding] === undefined ? message.repeatedFieldEncoding : $root.google.protobuf.FeatureSet.RepeatedFieldEncoding[message.repeatedFieldEncoding] : message.repeatedFieldEncoding; - if (message.stringFieldValidation != null && message.hasOwnProperty("stringFieldValidation")) - object.stringFieldValidation = options.enums === String ? $root.google.protobuf.FeatureSet.StringFieldValidation[message.stringFieldValidation] === undefined ? message.stringFieldValidation : $root.google.protobuf.FeatureSet.StringFieldValidation[message.stringFieldValidation] : message.stringFieldValidation; + if (message.utf8Validation != null && message.hasOwnProperty("utf8Validation")) + object.utf8Validation = options.enums === String ? $root.google.protobuf.FeatureSet.Utf8Validation[message.utf8Validation] === undefined ? message.utf8Validation : $root.google.protobuf.FeatureSet.Utf8Validation[message.utf8Validation] : message.utf8Validation; if (message.messageEncoding != null && message.hasOwnProperty("messageEncoding")) object.messageEncoding = options.enums === String ? $root.google.protobuf.FeatureSet.MessageEncoding[message.messageEncoding] === undefined ? message.messageEncoding : $root.google.protobuf.FeatureSet.MessageEncoding[message.messageEncoding] : message.messageEncoding; if (message.jsonFormat != null && message.hasOwnProperty("jsonFormat")) object.jsonFormat = options.enums === String ? $root.google.protobuf.FeatureSet.JsonFormat[message.jsonFormat] === undefined ? message.jsonFormat : $root.google.protobuf.FeatureSet.JsonFormat[message.jsonFormat] : message.jsonFormat; - if (message.rawFeatures != null && message.hasOwnProperty("rawFeatures")) - object.rawFeatures = $root.google.protobuf.FeatureSet.toObject(message.rawFeatures, options); return object; }; @@ -34922,19 +35073,17 @@ })(); /** - * StringFieldValidation enum. - * @name google.protobuf.FeatureSet.StringFieldValidation + * Utf8Validation enum. + * @name google.protobuf.FeatureSet.Utf8Validation * @enum {number} - * @property {number} STRING_FIELD_VALIDATION_UNKNOWN=0 STRING_FIELD_VALIDATION_UNKNOWN value - * @property {number} MANDATORY=1 MANDATORY value - * @property {number} HINT=2 HINT value + * @property {number} UTF8_VALIDATION_UNKNOWN=0 UTF8_VALIDATION_UNKNOWN value + * @property {number} VERIFY=2 VERIFY value * @property {number} NONE=3 NONE value */ - FeatureSet.StringFieldValidation = (function() { + FeatureSet.Utf8Validation = (function() { var valuesById = {}, values = Object.create(valuesById); - values[valuesById[0] = "STRING_FIELD_VALIDATION_UNKNOWN"] = 0; - values[valuesById[1] = "MANDATORY"] = 1; - values[valuesById[2] = "HINT"] = 2; + values[valuesById[0] = "UTF8_VALIDATION_UNKNOWN"] = 0; + values[valuesById[2] = "VERIFY"] = 2; values[valuesById[3] = "NONE"] = 3; return values; })(); @@ -34974,6 +35123,702 @@ return FeatureSet; })(); + protobuf.FeatureSetDefaults = (function() { + + /** + * Properties of a FeatureSetDefaults. + * @memberof google.protobuf + * @interface IFeatureSetDefaults + * @property {Array.|null} [defaults] FeatureSetDefaults defaults + * @property {google.protobuf.Edition|null} [minimumEdition] FeatureSetDefaults minimumEdition + * @property {google.protobuf.Edition|null} [maximumEdition] FeatureSetDefaults maximumEdition + */ + + /** + * Constructs a new FeatureSetDefaults. + * @memberof google.protobuf + * @classdesc Represents a FeatureSetDefaults. + * @implements IFeatureSetDefaults + * @constructor + * @param {google.protobuf.IFeatureSetDefaults=} [properties] Properties to set + */ + function FeatureSetDefaults(properties) { + this.defaults = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * FeatureSetDefaults defaults. + * @member {Array.} defaults + * @memberof google.protobuf.FeatureSetDefaults + * @instance + */ + FeatureSetDefaults.prototype.defaults = $util.emptyArray; + + /** + * FeatureSetDefaults minimumEdition. + * @member {google.protobuf.Edition} minimumEdition + * @memberof google.protobuf.FeatureSetDefaults + * @instance + */ + FeatureSetDefaults.prototype.minimumEdition = 0; + + /** + * FeatureSetDefaults maximumEdition. + * @member {google.protobuf.Edition} maximumEdition + * @memberof google.protobuf.FeatureSetDefaults + * @instance + */ + FeatureSetDefaults.prototype.maximumEdition = 0; + + /** + * Creates a new FeatureSetDefaults instance using the specified properties. + * @function create + * @memberof google.protobuf.FeatureSetDefaults + * @static + * @param {google.protobuf.IFeatureSetDefaults=} [properties] Properties to set + * @returns {google.protobuf.FeatureSetDefaults} FeatureSetDefaults instance + */ + FeatureSetDefaults.create = function create(properties) { + return new FeatureSetDefaults(properties); + }; + + /** + * Encodes the specified FeatureSetDefaults message. Does not implicitly {@link google.protobuf.FeatureSetDefaults.verify|verify} messages. + * @function encode + * @memberof google.protobuf.FeatureSetDefaults + * @static + * @param {google.protobuf.IFeatureSetDefaults} message FeatureSetDefaults message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + FeatureSetDefaults.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.defaults != null && message.defaults.length) + for (var i = 0; i < message.defaults.length; ++i) + $root.google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.encode(message.defaults[i], writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.minimumEdition != null && Object.hasOwnProperty.call(message, "minimumEdition")) + writer.uint32(/* id 4, wireType 0 =*/32).int32(message.minimumEdition); + if (message.maximumEdition != null && Object.hasOwnProperty.call(message, "maximumEdition")) + writer.uint32(/* id 5, wireType 0 =*/40).int32(message.maximumEdition); + return writer; + }; + + /** + * Encodes the specified FeatureSetDefaults message, length delimited. Does not implicitly {@link google.protobuf.FeatureSetDefaults.verify|verify} messages. + * @function encodeDelimited + * @memberof google.protobuf.FeatureSetDefaults + * @static + * @param {google.protobuf.IFeatureSetDefaults} message FeatureSetDefaults message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + FeatureSetDefaults.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a FeatureSetDefaults message from the specified reader or buffer. + * @function decode + * @memberof google.protobuf.FeatureSetDefaults + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.protobuf.FeatureSetDefaults} FeatureSetDefaults + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + FeatureSetDefaults.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.protobuf.FeatureSetDefaults(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + if (!(message.defaults && message.defaults.length)) + message.defaults = []; + message.defaults.push($root.google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.decode(reader, reader.uint32())); + break; + } + case 4: { + message.minimumEdition = reader.int32(); + break; + } + case 5: { + message.maximumEdition = reader.int32(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a FeatureSetDefaults message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.protobuf.FeatureSetDefaults + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.protobuf.FeatureSetDefaults} FeatureSetDefaults + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + FeatureSetDefaults.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a FeatureSetDefaults message. + * @function verify + * @memberof google.protobuf.FeatureSetDefaults + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + FeatureSetDefaults.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.defaults != null && message.hasOwnProperty("defaults")) { + if (!Array.isArray(message.defaults)) + return "defaults: array expected"; + for (var i = 0; i < message.defaults.length; ++i) { + var error = $root.google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.verify(message.defaults[i]); + if (error) + return "defaults." + error; + } + } + if (message.minimumEdition != null && message.hasOwnProperty("minimumEdition")) + switch (message.minimumEdition) { + default: + return "minimumEdition: enum value expected"; + case 0: + case 998: + case 999: + case 1000: + case 1001: + case 1: + case 2: + case 99997: + case 99998: + case 99999: + case 2147483647: + break; + } + if (message.maximumEdition != null && message.hasOwnProperty("maximumEdition")) + switch (message.maximumEdition) { + default: + return "maximumEdition: enum value expected"; + case 0: + case 998: + case 999: + case 1000: + case 1001: + case 1: + case 2: + case 99997: + case 99998: + case 99999: + case 2147483647: + break; + } + return null; + }; + + /** + * Creates a FeatureSetDefaults message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.protobuf.FeatureSetDefaults + * @static + * @param {Object.} object Plain object + * @returns {google.protobuf.FeatureSetDefaults} FeatureSetDefaults + */ + FeatureSetDefaults.fromObject = function fromObject(object) { + if (object instanceof $root.google.protobuf.FeatureSetDefaults) + return object; + var message = new $root.google.protobuf.FeatureSetDefaults(); + if (object.defaults) { + if (!Array.isArray(object.defaults)) + throw TypeError(".google.protobuf.FeatureSetDefaults.defaults: array expected"); + message.defaults = []; + for (var i = 0; i < object.defaults.length; ++i) { + if (typeof object.defaults[i] !== "object") + throw TypeError(".google.protobuf.FeatureSetDefaults.defaults: object expected"); + message.defaults[i] = $root.google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.fromObject(object.defaults[i]); + } + } + switch (object.minimumEdition) { + default: + if (typeof object.minimumEdition === "number") { + message.minimumEdition = object.minimumEdition; + break; + } + break; + case "EDITION_UNKNOWN": + case 0: + message.minimumEdition = 0; + break; + case "EDITION_PROTO2": + case 998: + message.minimumEdition = 998; + break; + case "EDITION_PROTO3": + case 999: + message.minimumEdition = 999; + break; + case "EDITION_2023": + case 1000: + message.minimumEdition = 1000; + break; + case "EDITION_2024": + case 1001: + message.minimumEdition = 1001; + break; + case "EDITION_1_TEST_ONLY": + case 1: + message.minimumEdition = 1; + break; + case "EDITION_2_TEST_ONLY": + case 2: + message.minimumEdition = 2; + break; + case "EDITION_99997_TEST_ONLY": + case 99997: + message.minimumEdition = 99997; + break; + case "EDITION_99998_TEST_ONLY": + case 99998: + message.minimumEdition = 99998; + break; + case "EDITION_99999_TEST_ONLY": + case 99999: + message.minimumEdition = 99999; + break; + case "EDITION_MAX": + case 2147483647: + message.minimumEdition = 2147483647; + break; + } + switch (object.maximumEdition) { + default: + if (typeof object.maximumEdition === "number") { + message.maximumEdition = object.maximumEdition; + break; + } + break; + case "EDITION_UNKNOWN": + case 0: + message.maximumEdition = 0; + break; + case "EDITION_PROTO2": + case 998: + message.maximumEdition = 998; + break; + case "EDITION_PROTO3": + case 999: + message.maximumEdition = 999; + break; + case "EDITION_2023": + case 1000: + message.maximumEdition = 1000; + break; + case "EDITION_2024": + case 1001: + message.maximumEdition = 1001; + break; + case "EDITION_1_TEST_ONLY": + case 1: + message.maximumEdition = 1; + break; + case "EDITION_2_TEST_ONLY": + case 2: + message.maximumEdition = 2; + break; + case "EDITION_99997_TEST_ONLY": + case 99997: + message.maximumEdition = 99997; + break; + case "EDITION_99998_TEST_ONLY": + case 99998: + message.maximumEdition = 99998; + break; + case "EDITION_99999_TEST_ONLY": + case 99999: + message.maximumEdition = 99999; + break; + case "EDITION_MAX": + case 2147483647: + message.maximumEdition = 2147483647; + break; + } + return message; + }; + + /** + * Creates a plain object from a FeatureSetDefaults message. Also converts values to other types if specified. + * @function toObject + * @memberof google.protobuf.FeatureSetDefaults + * @static + * @param {google.protobuf.FeatureSetDefaults} message FeatureSetDefaults + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + FeatureSetDefaults.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) + object.defaults = []; + if (options.defaults) { + object.minimumEdition = options.enums === String ? "EDITION_UNKNOWN" : 0; + object.maximumEdition = options.enums === String ? "EDITION_UNKNOWN" : 0; + } + if (message.defaults && message.defaults.length) { + object.defaults = []; + for (var j = 0; j < message.defaults.length; ++j) + object.defaults[j] = $root.google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.toObject(message.defaults[j], options); + } + if (message.minimumEdition != null && message.hasOwnProperty("minimumEdition")) + object.minimumEdition = options.enums === String ? $root.google.protobuf.Edition[message.minimumEdition] === undefined ? message.minimumEdition : $root.google.protobuf.Edition[message.minimumEdition] : message.minimumEdition; + if (message.maximumEdition != null && message.hasOwnProperty("maximumEdition")) + object.maximumEdition = options.enums === String ? $root.google.protobuf.Edition[message.maximumEdition] === undefined ? message.maximumEdition : $root.google.protobuf.Edition[message.maximumEdition] : message.maximumEdition; + return object; + }; + + /** + * Converts this FeatureSetDefaults to JSON. + * @function toJSON + * @memberof google.protobuf.FeatureSetDefaults + * @instance + * @returns {Object.} JSON object + */ + FeatureSetDefaults.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for FeatureSetDefaults + * @function getTypeUrl + * @memberof google.protobuf.FeatureSetDefaults + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + FeatureSetDefaults.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.protobuf.FeatureSetDefaults"; + }; + + FeatureSetDefaults.FeatureSetEditionDefault = (function() { + + /** + * Properties of a FeatureSetEditionDefault. + * @memberof google.protobuf.FeatureSetDefaults + * @interface IFeatureSetEditionDefault + * @property {google.protobuf.Edition|null} [edition] FeatureSetEditionDefault edition + * @property {google.protobuf.IFeatureSet|null} [features] FeatureSetEditionDefault features + */ + + /** + * Constructs a new FeatureSetEditionDefault. + * @memberof google.protobuf.FeatureSetDefaults + * @classdesc Represents a FeatureSetEditionDefault. + * @implements IFeatureSetEditionDefault + * @constructor + * @param {google.protobuf.FeatureSetDefaults.IFeatureSetEditionDefault=} [properties] Properties to set + */ + function FeatureSetEditionDefault(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * FeatureSetEditionDefault edition. + * @member {google.protobuf.Edition} edition + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @instance + */ + FeatureSetEditionDefault.prototype.edition = 0; + + /** + * FeatureSetEditionDefault features. + * @member {google.protobuf.IFeatureSet|null|undefined} features + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @instance + */ + FeatureSetEditionDefault.prototype.features = null; + + /** + * Creates a new FeatureSetEditionDefault instance using the specified properties. + * @function create + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @static + * @param {google.protobuf.FeatureSetDefaults.IFeatureSetEditionDefault=} [properties] Properties to set + * @returns {google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault} FeatureSetEditionDefault instance + */ + FeatureSetEditionDefault.create = function create(properties) { + return new FeatureSetEditionDefault(properties); + }; + + /** + * Encodes the specified FeatureSetEditionDefault message. Does not implicitly {@link google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.verify|verify} messages. + * @function encode + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @static + * @param {google.protobuf.FeatureSetDefaults.IFeatureSetEditionDefault} message FeatureSetEditionDefault message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + FeatureSetEditionDefault.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.features != null && Object.hasOwnProperty.call(message, "features")) + $root.google.protobuf.FeatureSet.encode(message.features, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); + if (message.edition != null && Object.hasOwnProperty.call(message, "edition")) + writer.uint32(/* id 3, wireType 0 =*/24).int32(message.edition); + return writer; + }; + + /** + * Encodes the specified FeatureSetEditionDefault message, length delimited. Does not implicitly {@link google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.verify|verify} messages. + * @function encodeDelimited + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @static + * @param {google.protobuf.FeatureSetDefaults.IFeatureSetEditionDefault} message FeatureSetEditionDefault message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + FeatureSetEditionDefault.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a FeatureSetEditionDefault message from the specified reader or buffer. + * @function decode + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault} FeatureSetEditionDefault + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + FeatureSetEditionDefault.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 3: { + message.edition = reader.int32(); + break; + } + case 2: { + message.features = $root.google.protobuf.FeatureSet.decode(reader, reader.uint32()); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a FeatureSetEditionDefault message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault} FeatureSetEditionDefault + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + FeatureSetEditionDefault.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a FeatureSetEditionDefault message. + * @function verify + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + FeatureSetEditionDefault.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.edition != null && message.hasOwnProperty("edition")) + switch (message.edition) { + default: + return "edition: enum value expected"; + case 0: + case 998: + case 999: + case 1000: + case 1001: + case 1: + case 2: + case 99997: + case 99998: + case 99999: + case 2147483647: + break; + } + if (message.features != null && message.hasOwnProperty("features")) { + var error = $root.google.protobuf.FeatureSet.verify(message.features); + if (error) + return "features." + error; + } + return null; + }; + + /** + * Creates a FeatureSetEditionDefault message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @static + * @param {Object.} object Plain object + * @returns {google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault} FeatureSetEditionDefault + */ + FeatureSetEditionDefault.fromObject = function fromObject(object) { + if (object instanceof $root.google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault) + return object; + var message = new $root.google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault(); + switch (object.edition) { + default: + if (typeof object.edition === "number") { + message.edition = object.edition; + break; + } + break; + case "EDITION_UNKNOWN": + case 0: + message.edition = 0; + break; + case "EDITION_PROTO2": + case 998: + message.edition = 998; + break; + case "EDITION_PROTO3": + case 999: + message.edition = 999; + break; + case "EDITION_2023": + case 1000: + message.edition = 1000; + break; + case "EDITION_2024": + case 1001: + message.edition = 1001; + break; + case "EDITION_1_TEST_ONLY": + case 1: + message.edition = 1; + break; + case "EDITION_2_TEST_ONLY": + case 2: + message.edition = 2; + break; + case "EDITION_99997_TEST_ONLY": + case 99997: + message.edition = 99997; + break; + case "EDITION_99998_TEST_ONLY": + case 99998: + message.edition = 99998; + break; + case "EDITION_99999_TEST_ONLY": + case 99999: + message.edition = 99999; + break; + case "EDITION_MAX": + case 2147483647: + message.edition = 2147483647; + break; + } + if (object.features != null) { + if (typeof object.features !== "object") + throw TypeError(".google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.features: object expected"); + message.features = $root.google.protobuf.FeatureSet.fromObject(object.features); + } + return message; + }; + + /** + * Creates a plain object from a FeatureSetEditionDefault message. Also converts values to other types if specified. + * @function toObject + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @static + * @param {google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault} message FeatureSetEditionDefault + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + FeatureSetEditionDefault.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.features = null; + object.edition = options.enums === String ? "EDITION_UNKNOWN" : 0; + } + if (message.features != null && message.hasOwnProperty("features")) + object.features = $root.google.protobuf.FeatureSet.toObject(message.features, options); + if (message.edition != null && message.hasOwnProperty("edition")) + object.edition = options.enums === String ? $root.google.protobuf.Edition[message.edition] === undefined ? message.edition : $root.google.protobuf.Edition[message.edition] : message.edition; + return object; + }; + + /** + * Converts this FeatureSetEditionDefault to JSON. + * @function toJSON + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @instance + * @returns {Object.} JSON object + */ + FeatureSetEditionDefault.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for FeatureSetEditionDefault + * @function getTypeUrl + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + FeatureSetEditionDefault.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault"; + }; + + return FeatureSetEditionDefault; + })(); + + return FeatureSetDefaults; + })(); + protobuf.SourceCodeInfo = (function() { /** diff --git a/protos/protos.json b/protos/protos.json index f1332af79..3cdd783dd 100644 --- a/protos/protos.json +++ b/protos/protos.json @@ -2407,6 +2407,11 @@ "longRunning": { "type": "LongRunning", "id": 2 + }, + "autoPopulatedFields": { + "rule": "repeated", + "type": "string", + "id": 3 } }, "nested": { @@ -2478,7 +2483,8 @@ "INPUT_ONLY": 4, "IMMUTABLE": 5, "UNORDERED_LIST": 6, - "NON_EMPTY_DEFAULT": 7 + "NON_EMPTY_DEFAULT": 7, + "IDENTIFIER": 8 } }, "resourceReference": { @@ -2580,6 +2586,21 @@ } } }, + "Edition": { + "values": { + "EDITION_UNKNOWN": 0, + "EDITION_PROTO2": 998, + "EDITION_PROTO3": 999, + "EDITION_2023": 1000, + "EDITION_2024": 1001, + "EDITION_1_TEST_ONLY": 1, + "EDITION_2_TEST_ONLY": 2, + "EDITION_99997_TEST_ONLY": 99997, + "EDITION_99998_TEST_ONLY": 99998, + "EDITION_99999_TEST_ONLY": 99999, + "EDITION_MAX": 2147483647 + } + }, "FileDescriptorProto": { "fields": { "name": { @@ -2644,8 +2665,8 @@ "id": 12 }, "edition": { - "type": "string", - "id": 13 + "type": "Edition", + "id": 14 } } }, @@ -2754,7 +2775,8 @@ "type": "VerificationState", "id": 3, "options": { - "default": "UNVERIFIED" + "default": "UNVERIFIED", + "retention": "RETENTION_SOURCE" } } }, @@ -2876,8 +2898,8 @@ "Label": { "values": { "LABEL_OPTIONAL": 1, - "LABEL_REQUIRED": 2, - "LABEL_REPEATED": 3 + "LABEL_REPEATED": 3, + "LABEL_REQUIRED": 2 } } } @@ -3065,13 +3087,6 @@ "default": false } }, - "phpGenericServices": { - "type": "bool", - "id": 42, - "options": { - "default": false - } - }, "deprecated": { "type": "bool", "id": 23, @@ -3131,6 +3146,10 @@ ] ], "reserved": [ + [ + 42, + 42 + ], [ 38, 38 @@ -3356,8 +3375,8 @@ "EditionDefault": { "fields": { "edition": { - "type": "string", - "id": 1 + "type": "Edition", + "id": 3 }, "value": { "type": "string", @@ -3587,7 +3606,7 @@ "options": { "retention": "RETENTION_RUNTIME", "targets": "TARGET_TYPE_FILE", - "edition_defaults.edition": "2023", + "edition_defaults.edition": "EDITION_2023", "edition_defaults.value": "EXPLICIT" } }, @@ -3597,7 +3616,7 @@ "options": { "retention": "RETENTION_RUNTIME", "targets": "TARGET_TYPE_FILE", - "edition_defaults.edition": "2023", + "edition_defaults.edition": "EDITION_PROTO3", "edition_defaults.value": "OPEN" } }, @@ -3607,18 +3626,18 @@ "options": { "retention": "RETENTION_RUNTIME", "targets": "TARGET_TYPE_FILE", - "edition_defaults.edition": "2023", + "edition_defaults.edition": "EDITION_PROTO3", "edition_defaults.value": "PACKED" } }, - "stringFieldValidation": { - "type": "StringFieldValidation", + "utf8Validation": { + "type": "Utf8Validation", "id": 4, "options": { "retention": "RETENTION_RUNTIME", "targets": "TARGET_TYPE_FILE", - "edition_defaults.edition": "2023", - "edition_defaults.value": "MANDATORY" + "edition_defaults.edition": "EDITION_PROTO3", + "edition_defaults.value": "VERIFY" } }, "messageEncoding": { @@ -3627,7 +3646,7 @@ "options": { "retention": "RETENTION_RUNTIME", "targets": "TARGET_TYPE_FILE", - "edition_defaults.edition": "2023", + "edition_defaults.edition": "EDITION_PROTO2", "edition_defaults.value": "LENGTH_PREFIXED" } }, @@ -3637,16 +3656,9 @@ "options": { "retention": "RETENTION_RUNTIME", "targets": "TARGET_TYPE_FILE", - "edition_defaults.edition": "2023", + "edition_defaults.edition": "EDITION_PROTO3", "edition_defaults.value": "ALLOW" } - }, - "rawFeatures": { - "type": "FeatureSet", - "id": 999, - "options": { - "targets": "TARGET_TYPE_UNKNOWN" - } } }, "extensions": [ @@ -3663,6 +3675,12 @@ 9999 ] ], + "reserved": [ + [ + 999, + 999 + ] + ], "nested": { "FieldPresence": { "values": { @@ -3686,11 +3704,10 @@ "EXPANDED": 2 } }, - "StringFieldValidation": { + "Utf8Validation": { "values": { - "STRING_FIELD_VALIDATION_UNKNOWN": 0, - "MANDATORY": 1, - "HINT": 2, + "UTF8_VALIDATION_UNKNOWN": 0, + "VERIFY": 2, "NONE": 3 } }, @@ -3710,6 +3727,37 @@ } } }, + "FeatureSetDefaults": { + "fields": { + "defaults": { + "rule": "repeated", + "type": "FeatureSetEditionDefault", + "id": 1 + }, + "minimumEdition": { + "type": "Edition", + "id": 4 + }, + "maximumEdition": { + "type": "Edition", + "id": 5 + } + }, + "nested": { + "FeatureSetEditionDefault": { + "fields": { + "edition": { + "type": "Edition", + "id": 3 + }, + "features": { + "type": "FeatureSet", + "id": 2 + } + } + } + } + }, "SourceCodeInfo": { "fields": { "location": { From a2240ac383d334cde498af54af0c08a11ced2c35 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Mon, 22 Jan 2024 12:26:07 -0500 Subject: [PATCH 18/23] docs: fix incorrect comment in deleteSchemaRevision --- samples/typescript/deleteSchemaRevision.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/typescript/deleteSchemaRevision.ts b/samples/typescript/deleteSchemaRevision.ts index a3df6ff5b..c7d5928f0 100644 --- a/samples/typescript/deleteSchemaRevision.ts +++ b/samples/typescript/deleteSchemaRevision.ts @@ -22,7 +22,7 @@ // sample-metadata: // title: Delete a Schema Revision -// description: Deletes a new schema revision on a project +// description: Deletes a schema revision on a project // usage: node deleteSchemaRevision.js // [START pubsub_delete_schema_revision] From dacb780786bfa4ccf4dd6fa24cd1e899349cc26e Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 22 Jan 2024 17:31:16 +0000 Subject: [PATCH 19/23] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- samples/README.md | 2 +- samples/deleteSchemaRevision.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/README.md b/samples/README.md index 88695a577..b1ea2c92b 100644 --- a/samples/README.md +++ b/samples/README.md @@ -402,7 +402,7 @@ __Usage:__ ### Delete a Schema Revision -Deletes a new schema revision on a project +Deletes a schema revision on a project View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/deleteSchemaRevision.js). diff --git a/samples/deleteSchemaRevision.js b/samples/deleteSchemaRevision.js index ad4f8edd6..bbdafde15 100644 --- a/samples/deleteSchemaRevision.js +++ b/samples/deleteSchemaRevision.js @@ -26,7 +26,7 @@ // sample-metadata: // title: Delete a Schema Revision -// description: Deletes a new schema revision on a project +// description: Deletes a schema revision on a project // usage: node deleteSchemaRevision.js // [START pubsub_delete_schema_revision] From ba770a49c2dd192303329480a76833a17a00cfed Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Tue, 30 Jan 2024 17:00:58 -0500 Subject: [PATCH 20/23] samples: add more schema samples, plus tests --- samples/commitProtoSchema.js | 80 ++++++++++ samples/deleteSchemaRevision.js | 2 +- samples/getSchemaRevision.js | 71 +++++++++ samples/listenForAvroRecordsWithRevisions.js | 140 ++++++++++++++++++ samples/package.json | 2 +- samples/system-test/schema.test.ts | 76 +++++++++- samples/typescript/avro-js.d.ts | 11 +- samples/typescript/commitProtoSchema.ts | 76 ++++++++++ samples/typescript/getSchemaRevision.ts | 67 +++++++++ .../listenForAvroRecordsWithRevisions.ts | 140 ++++++++++++++++++ src/schema.ts | 6 + test/schema.ts | 2 + 12 files changed, 667 insertions(+), 6 deletions(-) create mode 100644 samples/commitProtoSchema.js create mode 100644 samples/getSchemaRevision.js create mode 100644 samples/listenForAvroRecordsWithRevisions.js create mode 100644 samples/typescript/commitProtoSchema.ts create mode 100644 samples/typescript/getSchemaRevision.ts create mode 100644 samples/typescript/listenForAvroRecordsWithRevisions.ts diff --git a/samples/commitProtoSchema.js b/samples/commitProtoSchema.js new file mode 100644 index 000000000..997a1df45 --- /dev/null +++ b/samples/commitProtoSchema.js @@ -0,0 +1,80 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is a generated sample, using the typeless sample bot. Please +// look for the source TypeScript sample (.ts) for modifications. +'use strict'; + +/** + * This application demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Commit an Proto-Based Schema +// description: Commits a new schema definition revision on a project, using Protos +// usage: node commitProtoSchema.js + +// [START pubsub_commit_proto_schema] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID'; +// const protoFile = 'path/to/a/proto/schema/file/(.proto)/formatted/in/protcol/buffers'; + +// Imports the Google Cloud client library +const {PubSub, SchemaTypes} = require('@google-cloud/pubsub'); + +const fs = require('fs'); + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function commitProtoSchema(schemaNameOrId, protoFile) { + // Get the fully qualified schema name. + const schema = pubSubClient.schema(schemaNameOrId); + const name = await schema.getName(); + + // Read the new schema definition from storage. + const definition = fs.readFileSync(protoFile).toString(); + + // Use the gapic client to commit the new definition. + const schemaClient = await pubSubClient.getSchemaClient(); + const [result] = await schemaClient.commitSchema({ + name, + schema: { + name, + type: SchemaTypes.ProtocolBuffer, + definition, + }, + }); + + console.log(`Schema ${name} committed with revision ${result.revisionId}.`); +} +// [END pubsub_commit_proto_schema] + +function main( + schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', + protoFile = 'path/to/a/proto/schema/file/(.proto)/formatted/in/protcol/buffers' +) { + commitProtoSchema(schemaNameOrId, protoFile).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/deleteSchemaRevision.js b/samples/deleteSchemaRevision.js index ad4f8edd6..bbdafde15 100644 --- a/samples/deleteSchemaRevision.js +++ b/samples/deleteSchemaRevision.js @@ -26,7 +26,7 @@ // sample-metadata: // title: Delete a Schema Revision -// description: Deletes a new schema revision on a project +// description: Deletes a schema revision on a project // usage: node deleteSchemaRevision.js // [START pubsub_delete_schema_revision] diff --git a/samples/getSchemaRevision.js b/samples/getSchemaRevision.js new file mode 100644 index 000000000..8cb5278b7 --- /dev/null +++ b/samples/getSchemaRevision.js @@ -0,0 +1,71 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is a generated sample, using the typeless sample bot. Please +// look for the source TypeScript sample (.ts) for modifications. +'use strict'; + +/** + * This snippet demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Get a previously created schema revision +// description: Gets information about a schema revision which was previously created in the project. +// usage: node getSchemaRevision.js + +// [START pubsub_get_schema_revision] +/** + * TODO(developer): Uncomment this variable before running the sample. + */ +// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID'; +// const revisionId = 'YOUR_REVISION_ID'; + +// Imports the Google Cloud client library +const {PubSub} = require('@google-cloud/pubsub'); + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function getSchemaRevision(schemaNameOrId, revisionId) { + const schema = pubSubClient.schema(schemaNameOrId); + const name = await schema.getName(); + + // Use the gapic client to delete the schema revision. + const schemaClient = await pubSubClient.getSchemaClient(); + const schemaInfo = await schemaClient.getSchema({ + name: `${name}@${revisionId}`, + }); + + console.log( + `Schema ${name}@${revisionId} info: ${JSON.stringify(schemaInfo, null, 4)}.` + ); +} +// [END pubsub_get_schema_revision] + +function main( + schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', + revisionId = 'YOUR_REVISION_ID' +) { + getSchemaRevision(schemaNameOrId, revisionId).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/listenForAvroRecordsWithRevisions.js b/samples/listenForAvroRecordsWithRevisions.js new file mode 100644 index 000000000..341883f0a --- /dev/null +++ b/samples/listenForAvroRecordsWithRevisions.js @@ -0,0 +1,140 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is a generated sample, using the typeless sample bot. Please +// look for the source TypeScript sample (.ts) for modifications. +'use strict'; + +/** + * This snippet demonstrates how to perform basic operations on + * subscriptions with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Listen For Avro Records With Revisions +// description: Listens for records in Avro encoding from a subscription with schema revisions. +// usage: node listenForAvroRecordsWithRevisions.js [timeout-in-seconds] + +// [START pubsub_subscribe_avro_records_with_revisions] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID'; +// const timeout = 60; + +// Imports the Google Cloud client library +const {PubSub, Schema, Encodings} = require('@google-cloud/pubsub'); + +// And the Apache Avro library; this lacks typings, so for +// TypeScript, a few synthetic types were created. +const avro = require('avro-js'); + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function listenForAvroRecordsWithRevisions( + subscriptionNameOrId, + timeout +) { + // References an existing subscription + const subscription = pubSubClient.subscription(subscriptionNameOrId); + + // Cache decoders for various schema revisions. + const revisionReaders = new Map(); + + // We need a schema admin service client to retrieve revisions. + const schemaClient = await pubSubClient.getSchemaClient(); + + // Create an event handler to handle messages + let messageCount = 0; + const messageHandler = async message => { + // Get the schema metadata from the message. + const schemaMetadata = Schema.metadataFromMessage(message.attributes); + + let reader; + try { + // Do we already have a decoder for this revision? + const revision = schemaMetadata.revision; + if (revisionReaders.has(revision)) { + reader = revisionReaders.get(revision); + } else { + // This is the first time we are seeing this revision. We need to + // fetch the schema and cache its decoder. + const [schema] = await schemaClient.getSchema({ + name: `${schemaMetadata.name}@${schemaMetadata.revision}`, + }); + reader = avro.parse(schema.definition); + revisionReaders.set(revision, reader); + } + } catch (err) { + console.log('Could not get schema', err); + message.nack(); + return; + } + + let result; + switch (schemaMetadata.encoding) { + case Encodings.Binary: + result = reader.fromBuffer(message.data); + break; + case Encodings.Json: + result = reader.fromString(message.data.toString()); + break; + default: + console.log(`Unknown schema encoding: ${schemaMetadata.encoding}`); + message.nack(); + return; + } + + console.log(`Received message ${message.id}:`); + console.log(`\tData: ${JSON.stringify(result, null, 4)}`); + console.log(`\tAttributes: ${message.attributes}`); + console.log( + `\tProvince ${result.name} is abbreviated as ${result.post_abbr}` + ); + + messageCount += 1; + + // Ack the message. + message.ack(); + }; + + // Listen for new messages until timeout is hit + subscription.on('message', messageHandler); + + setTimeout(() => { + subscription.removeListener('message', messageHandler); + console.log(`${messageCount} message(s) received.`); + }, timeout * 1000); +} +// [END pubsub_subscribe_avro_records_with_revisions] + +function main( + subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID', + timeout = 60 +) { + timeout = Number(timeout); + + listenForAvroRecordsWithRevisions(subscriptionNameOrId, timeout).catch( + err => { + console.error(err.message); + process.exitCode = 1; + } + ); +} + +main(...process.argv.slice(2)); diff --git a/samples/package.json b/samples/package.json index 70065c0a5..6c08be0a9 100644 --- a/samples/package.json +++ b/samples/package.json @@ -24,7 +24,7 @@ "@google-cloud/pubsub": "^4.1.1", "@opentelemetry/api": "^1.0.0", "@opentelemetry/tracing": "^0.24.0", - "avro-js": "^1.10.1", + "avro-js": "^1.11.3", "p-defer": "^3.0.0", "protobufjs": "^7.0.0" }, diff --git a/samples/system-test/schema.test.ts b/samples/system-test/schema.test.ts index 446fba7a0..f6d5d9e5a 100644 --- a/samples/system-test/schema.test.ts +++ b/samples/system-test/schema.test.ts @@ -57,7 +57,11 @@ describe('schema', () => { } function fullSchemaName(base: string) { - return `projects/${projectId}/schemas/${base}`; + if (base.includes('/')) { + return base; + } else { + return `projects/${projectId}/schemas/${base}`; + } } async function cleanAllSchemas() { @@ -156,13 +160,17 @@ describe('schema', () => { async function createTopicWithSchema( testName: string, schemaName: string, - encodingType: SchemaEncoding + encodingType: SchemaEncoding, + firstRevisionId?: string, + lastRevisionId?: string ): Promise { const topicId = getTopicId(testName); const [topic] = await pubsub.createTopic({ name: topicId, schemaSettings: { schema: fullSchemaName(schemaName), + firstRevisionId, + lastRevisionId, encoding: encodingType, }, }); @@ -183,7 +191,7 @@ describe('schema', () => { } it('should commit an avro schema', async () => { - const schema = await createSchema('commit_schema', 'avro'); + const schema = await createSchema('commit_schema_avro', 'avro'); const name = await schema.getName(); const output = execSync( `${commandFor('commitAvroSchema')} ${name} ${fixturePath( @@ -194,6 +202,18 @@ describe('schema', () => { assert.include(output, 'committed'); }); + it('should commit an proto schema', async () => { + const schema = await createSchema('commit_schema_proto', 'proto'); + const name = await schema.getName(); + const output = execSync( + `${commandFor('commitProtoSchema')} ${name} ${fixturePath( + 'provinces.proto' + )}` + ); + assert.include(output, name); + assert.include(output, 'committed'); + }); + it('should create an avro schema', async () => { const schemaId = getSchemaId('create_avro'); const output = execSync( @@ -345,6 +365,20 @@ describe('schema', () => { assert.include(output, 'PROTO'); }); + it('should get a schema revision', async () => { + const schema = await createSchema('get_rev', 'proto'); + const committed = await commitSchema(await schema.getName(), 'proto'); + const revId = committed.revisionId!; + + const output = execSync( + `${commandFor('getSchemaRevision')} ${schema.id} ${revId}` + ); + assert.include(output, schema.id); + assert.include(output, revId); + assert.include(output, 'info:'); + assert.include(output, 'PROTO'); + }); + it('should listen for avro records', async () => { const id = 'listen_avro'; const schema = await createSchema(id, 'avro'); @@ -369,6 +403,42 @@ describe('schema', () => { assert.include(output, 'AB'); }); + it('should listen for avro records with revisions', async () => { + const id = 'listen_avro_rev'; + const schema = await createSchema(id, 'avro'); + const schemaName = await schema.getName(); + const rev1 = await commitSchema(schemaName, 'avro'); + const rev2 = await commitSchema(schemaName, 'avro'); + if (!rev1.name || !rev2.name) { + assert.ok(false, 'revisions could not be committed'); + } + const topic = await createTopicWithSchema( + id, + schema.id, + Encodings.Json, + rev1.name ?? undefined, + rev2.name ?? undefined + ); + const sub = await createSub(id, topic.name); + + topic.publishMessage({ + data: Buffer.from( + JSON.stringify({ + name: 'Alberta', + post_abbr: 'AB', + }) + ), + }); + await topic.flush(); + + const output = execSync( + `${commandFor('listenForAvroRecordsWithRevisions')} ${sub.name} 10` + ); + assert.include(output, 'Received message'); + assert.include(output, 'Alberta'); + assert.include(output, 'AB'); + }); + it('should listen for protobuf messages', async () => { const id = 'listen_proto'; const schema = await createSchema(id, 'proto'); diff --git a/samples/typescript/avro-js.d.ts b/samples/typescript/avro-js.d.ts index 1c6c80b44..20937ee94 100644 --- a/samples/typescript/avro-js.d.ts +++ b/samples/typescript/avro-js.d.ts @@ -13,4 +13,13 @@ // limitations under the License. // This one doesn't seem to have typings. -declare module 'avro-js'; +declare module 'avro-js' { + function parse(def: string): Parser; + + class Parser { + fromBuffer(buf: Buffer): T; + fromString(str: string): T; + toBuffer(item: T): Buffer; + toString(item: T): string; + } +} diff --git a/samples/typescript/commitProtoSchema.ts b/samples/typescript/commitProtoSchema.ts new file mode 100644 index 000000000..b540ed98e --- /dev/null +++ b/samples/typescript/commitProtoSchema.ts @@ -0,0 +1,76 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * This application demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Commit an Proto-Based Schema +// description: Commits a new schema definition revision on a project, using Protos +// usage: node commitProtoSchema.js + +// [START pubsub_commit_proto_schema] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID'; +// const protoFile = 'path/to/a/proto/schema/file/(.proto)/formatted/in/protcol/buffers'; + +// Imports the Google Cloud client library +import {PubSub, SchemaTypes} from '@google-cloud/pubsub'; + +import * as fs from 'fs'; + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function commitProtoSchema(schemaNameOrId: string, protoFile: string) { + // Get the fully qualified schema name. + const schema = pubSubClient.schema(schemaNameOrId); + const name = await schema.getName(); + + // Read the new schema definition from storage. + const definition: string = fs.readFileSync(protoFile).toString(); + + // Use the gapic client to commit the new definition. + const schemaClient = await pubSubClient.getSchemaClient(); + const [result] = await schemaClient.commitSchema({ + name, + schema: { + name, + type: SchemaTypes.ProtocolBuffer, + definition, + }, + }); + + console.log(`Schema ${name} committed with revision ${result.revisionId}.`); +} +// [END pubsub_commit_proto_schema] + +function main( + schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', + protoFile = 'path/to/a/proto/schema/file/(.proto)/formatted/in/protcol/buffers' +) { + commitProtoSchema(schemaNameOrId, protoFile).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/typescript/getSchemaRevision.ts b/samples/typescript/getSchemaRevision.ts new file mode 100644 index 000000000..1650cc9e2 --- /dev/null +++ b/samples/typescript/getSchemaRevision.ts @@ -0,0 +1,67 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * This snippet demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Get a previously created schema revision +// description: Gets information about a schema revision which was previously created in the project. +// usage: node getSchemaRevision.js + +// [START pubsub_get_schema_revision] +/** + * TODO(developer): Uncomment this variable before running the sample. + */ +// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID'; +// const revisionId = 'YOUR_REVISION_ID'; + +// Imports the Google Cloud client library +import {PubSub} from '@google-cloud/pubsub'; + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function getSchemaRevision(schemaNameOrId: string, revisionId: string) { + const schema = pubSubClient.schema(schemaNameOrId); + const name = await schema.getName(); + + // Use the gapic client to delete the schema revision. + const schemaClient = await pubSubClient.getSchemaClient(); + const schemaInfo = await schemaClient.getSchema({ + name: `${name}@${revisionId}`, + }); + + console.log( + `Schema ${name}@${revisionId} info: ${JSON.stringify(schemaInfo, null, 4)}.` + ); +} +// [END pubsub_get_schema_revision] + +function main( + schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID', + revisionId = 'YOUR_REVISION_ID' +) { + getSchemaRevision(schemaNameOrId, revisionId).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); diff --git a/samples/typescript/listenForAvroRecordsWithRevisions.ts b/samples/typescript/listenForAvroRecordsWithRevisions.ts new file mode 100644 index 000000000..cb5f4e7cf --- /dev/null +++ b/samples/typescript/listenForAvroRecordsWithRevisions.ts @@ -0,0 +1,140 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * This snippet demonstrates how to perform basic operations on + * subscriptions with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Listen For Avro Records With Revisions +// description: Listens for records in Avro encoding from a subscription with schema revisions. +// usage: node listenForAvroRecordsWithRevisions.js [timeout-in-seconds] + +// [START pubsub_subscribe_avro_records_with_revisions] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID'; +// const timeout = 60; + +// Imports the Google Cloud client library +import {PubSub, Schema, Encodings, Message} from '@google-cloud/pubsub'; + +// And the Apache Avro library; this lacks typings, so for +// TypeScript, a few synthetic types were created. +import * as avro from 'avro-js'; + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +interface ProvinceObject { + name: string; + post_abbr: string; +} + +async function listenForAvroRecordsWithRevisions( + subscriptionNameOrId: string, + timeout: number +) { + // References an existing subscription + const subscription = pubSubClient.subscription(subscriptionNameOrId); + + // Cache decoders for various schema revisions. + const revisionReaders = new Map(); + + // We need a schema admin service client to retrieve revisions. + const schemaClient = await pubSubClient.getSchemaClient(); + + // Create an event handler to handle messages + let messageCount = 0; + const messageHandler = async (message: Message) => { + // Get the schema metadata from the message. + const schemaMetadata = Schema.metadataFromMessage(message.attributes); + + let reader: avro.Parser; + try { + // Do we already have a decoder for this revision? + const revision = schemaMetadata.revision!; + if (revisionReaders.has(revision)) { + reader = revisionReaders.get(revision)!; + } else { + // This is the first time we are seeing this revision. We need to + // fetch the schema and cache its decoder. + const [schema] = await schemaClient.getSchema({ + name: `${schemaMetadata.name}@${schemaMetadata.revision}`, + }); + reader = avro.parse(schema.definition!); + revisionReaders.set(revision, reader); + } + } catch (err: unknown) { + console.log('Could not get schema', err); + message.nack(); + return; + } + + let result: ProvinceObject | undefined; + switch (schemaMetadata.encoding) { + case Encodings.Binary: + result = reader.fromBuffer(message.data); + break; + case Encodings.Json: + result = reader.fromString(message.data.toString()); + break; + default: + console.log(`Unknown schema encoding: ${schemaMetadata.encoding}`); + message.nack(); + return; + } + + console.log(`Received message ${message.id}:`); + console.log(`\tData: ${JSON.stringify(result, null, 4)}`); + console.log(`\tAttributes: ${message.attributes}`); + console.log( + `\tProvince ${result?.name} is abbreviated as ${result?.post_abbr}` + ); + messageCount += 1; + + // Ack the message. + message.ack(); + }; + + // Listen for new messages until timeout is hit + subscription.on('message', messageHandler); + + setTimeout(() => { + subscription.removeListener('message', messageHandler); + console.log(`${messageCount} message(s) received.`); + }, timeout * 1000); +} +// [END pubsub_subscribe_avro_records_with_revisions] + +function main( + subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID', + timeout = 60 +) { + timeout = Number(timeout); + + listenForAvroRecordsWithRevisions(subscriptionNameOrId, timeout).catch( + err => { + console.error(err.message); + process.exitCode = 1; + } + ); +} + +main(...process.argv.slice(2)); diff --git a/src/schema.ts b/src/schema.ts index 64d83815d..a332d0aff 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -244,6 +244,7 @@ export class Schema { static metadataFromMessage(attributes: Attributes): SchemaMessageMetadata { return { name: attributes['googclient_schemaname'], + revision: attributes['googclient_schemarevisionid'], encoding: attributes[ 'googclient_schemaencoding' ] as unknown as SchemaEncoding, @@ -261,6 +262,11 @@ export interface SchemaMessageMetadata { */ name?: string; + /** + * Schema revision; this goes with {@link name} as needed. + */ + revision?: string; + /** * Encoding; this will be Encodings.Json or Encodings.Binary. */ diff --git a/test/schema.ts b/test/schema.ts index c209d5ed3..d1e629464 100644 --- a/test/schema.ts +++ b/test/schema.ts @@ -175,11 +175,13 @@ describe('Schema', () => { it('loads metadata from a received message', () => { const testAttrs = { googclient_schemaencoding: 'JSON', + googclient_schemarevisionid: 'revision', googclient_schemaname: 'foobar', }; const metadata = Schema.metadataFromMessage(testAttrs); assert.deepStrictEqual(metadata, { name: 'foobar', + revision: 'revision', encoding: 'JSON', }); }); From d72c63e8d158f44dd3bbde2d1dea1f41d5c93c40 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Tue, 30 Jan 2024 18:50:25 -0500 Subject: [PATCH 21/23] samples: update sample package.json versions --- samples/listenForAvroRecords.js | 3 ++- samples/package.json | 10 +++++----- samples/typescript/listenForAvroRecords.ts | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/samples/listenForAvroRecords.js b/samples/listenForAvroRecords.js index b0dbc7aee..10ff478fa 100644 --- a/samples/listenForAvroRecords.js +++ b/samples/listenForAvroRecords.js @@ -104,7 +104,8 @@ function main( try { listenForAvroRecords(subscriptionNameOrId, timeout); - } catch (err) { + } catch (e) { + const err = e; console.error(err.message); process.exitCode = 1; } diff --git a/samples/package.json b/samples/package.json index 6c08be0a9..e095c9c65 100644 --- a/samples/package.json +++ b/samples/package.json @@ -22,21 +22,21 @@ }, "dependencies": { "@google-cloud/pubsub": "^4.1.1", - "@opentelemetry/api": "^1.0.0", + "@opentelemetry/api": "^1.6.0", "@opentelemetry/tracing": "^0.24.0", "avro-js": "^1.11.3", "p-defer": "^3.0.0", - "protobufjs": "^7.0.0" + "protobufjs": "~7.2.5" }, "devDependencies": { "@google-cloud/bigquery": "^7.0.0", "@types/chai": "^4.2.16", "@types/rimraf": "^3.0.0", "chai": "^4.2.0", - "gts": "^3.1.0", - "mocha": "^8.0.0", + "gts": "^5.0.0", + "mocha": "^9.2.2", "rimraf": "^5.0.0", - "typescript": "~4.3.0", + "typescript": "^5.1.6", "uuid": "^9.0.0" } } diff --git a/samples/typescript/listenForAvroRecords.ts b/samples/typescript/listenForAvroRecords.ts index f479e04c1..665141731 100644 --- a/samples/typescript/listenForAvroRecords.ts +++ b/samples/typescript/listenForAvroRecords.ts @@ -100,7 +100,8 @@ function main( try { listenForAvroRecords(subscriptionNameOrId, timeout); - } catch (err) { + } catch (e) { + const err = e as Error; console.error(err.message); process.exitCode = 1; } From 956b27f179896f53e846e8721e7dd32dcdde2741 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:36:55 -0500 Subject: [PATCH 22/23] tests: fix system test for listen with revisions --- samples/system-test/schema.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/system-test/schema.test.ts b/samples/system-test/schema.test.ts index f6d5d9e5a..bbf192900 100644 --- a/samples/system-test/schema.test.ts +++ b/samples/system-test/schema.test.ts @@ -409,15 +409,15 @@ describe('schema', () => { const schemaName = await schema.getName(); const rev1 = await commitSchema(schemaName, 'avro'); const rev2 = await commitSchema(schemaName, 'avro'); - if (!rev1.name || !rev2.name) { + if (!rev1.revisionId || !rev2.revisionId) { assert.ok(false, 'revisions could not be committed'); } const topic = await createTopicWithSchema( id, schema.id, Encodings.Json, - rev1.name ?? undefined, - rev2.name ?? undefined + rev1.revisionId ?? undefined, + rev2.revisionId ?? undefined ); const sub = await createSub(id, topic.name); From 9ff3008a652a8157b46e4109be3fd6c4b294b78e Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 31 Jan 2024 18:41:10 +0000 Subject: [PATCH 23/23] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 3 + samples/README.md | 60 ++++++++++++++++++++ samples/listenForAvroRecordsWithRevisions.js | 1 - 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 424eb20dd..9267ec11e 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-pubsub/tree | Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | | Commit an Avro-Based Schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/commitAvroSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/commitAvroSchema.js,samples/README.md) | +| Commit an Proto-Based Schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/commitProtoSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/commitProtoSchema.js,samples/README.md) | | Create an Avro based Schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createAvroSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createAvroSchema.js,samples/README.md) | | Create BigQuery Subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createBigQuerySubscription.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createBigQuerySubscription.js,samples/README.md) | | Create a Proto based Schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createProtoSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createProtoSchema.js,samples/README.md) | @@ -144,6 +145,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-pubsub/tree | Delete Topic | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/deleteTopic.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/deleteTopic.js,samples/README.md) | | Detach Subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/detachSubscription.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/detachSubscription.js,samples/README.md) | | Get a previously created schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/getSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/getSchema.js,samples/README.md) | +| Get a previously created schema revision | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/getSchemaRevision.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/getSchemaRevision.js,samples/README.md) | | Get Subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/getSubscription.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/getSubscription.js,samples/README.md) | | Get Subscription Policy | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/getSubscriptionPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/getSubscriptionPolicy.js,samples/README.md) | | Get Topic Policy | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/getTopicPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/getTopicPolicy.js,samples/README.md) | @@ -153,6 +155,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-pubsub/tree | List Subscriptions | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listSubscriptions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listSubscriptions.js,samples/README.md) | | List Subscriptions On a Topic | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listTopicSubscriptions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listTopicSubscriptions.js,samples/README.md) | | Listen For Avro Records | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listenForAvroRecords.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listenForAvroRecords.js,samples/README.md) | +| Listen For Avro Records With Revisions | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listenForAvroRecordsWithRevisions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listenForAvroRecordsWithRevisions.js,samples/README.md) | | Listen For Errors | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listenForErrors.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listenForErrors.js,samples/README.md) | | Listen For Messages | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listenForMessages.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listenForMessages.js,samples/README.md) | | Listen with exactly-once delivery | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listenForMessagesWithExactlyOnceDelivery.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listenForMessagesWithExactlyOnceDelivery.js,samples/README.md) | diff --git a/samples/README.md b/samples/README.md index b1ea2c92b..d8fa96fa0 100644 --- a/samples/README.md +++ b/samples/README.md @@ -21,6 +21,7 @@ guides. * [Before you begin](#before-you-begin) * [Samples](#samples) * [Commit an Avro-Based Schema](#commit-an-avro-based-schema) + * [Commit an Proto-Based Schema](#commit-an-proto-based-schema) * [Create an Avro based Schema](#create-an-avro-based-schema) * [Create BigQuery Subscription](#create-bigquery-subscription) * [Create a Proto based Schema](#create-a-proto-based-schema) @@ -41,6 +42,7 @@ guides. * [Delete Topic](#delete-topic) * [Detach Subscription](#detach-subscription) * [Get a previously created schema](#get-a-previously-created-schema) + * [Get a previously created schema revision](#get-a-previously-created-schema-revision) * [Get Subscription](#get-subscription) * [Get Subscription Policy](#get-subscription-policy) * [Get Topic Policy](#get-topic-policy) @@ -50,6 +52,7 @@ guides. * [List Subscriptions](#list-subscriptions) * [List Subscriptions On a Topic](#list-subscriptions-on-a-topic) * [Listen For Avro Records](#listen-for-avro-records) + * [Listen For Avro Records With Revisions](#listen-for-avro-records-with-revisions) * [Listen For Errors](#listen-for-errors) * [Listen For Messages](#listen-for-messages) * [Listen with exactly-once delivery](#listen-with-exactly-once-delivery) @@ -115,6 +118,25 @@ __Usage:__ +### Commit an Proto-Based Schema + +Commits a new schema definition revision on a project, using Protos + +View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/commitProtoSchema.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/commitProtoSchema.js,samples/README.md) + +__Usage:__ + + +`node commitProtoSchema.js ` + + +----- + + + + ### Create an Avro based Schema Creates a new schema definition on a project, using Avro @@ -495,6 +517,25 @@ __Usage:__ +### Get a previously created schema revision + +Gets information about a schema revision which was previously created in the project. + +View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/getSchemaRevision.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/getSchemaRevision.js,samples/README.md) + +__Usage:__ + + +`node getSchemaRevision.js ` + + +----- + + + + ### Get Subscription Gets the metadata for a subscription. @@ -666,6 +707,25 @@ __Usage:__ +### Listen For Avro Records With Revisions + +Listens for records in Avro encoding from a subscription with schema revisions. + +View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/listenForAvroRecordsWithRevisions.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/listenForAvroRecordsWithRevisions.js,samples/README.md) + +__Usage:__ + + +`node listenForAvroRecordsWithRevisions.js [timeout-in-seconds]` + + +----- + + + + ### Listen For Errors Listens to messages and errors for a subscription. diff --git a/samples/listenForAvroRecordsWithRevisions.js b/samples/listenForAvroRecordsWithRevisions.js index 341883f0a..a4a46bf8d 100644 --- a/samples/listenForAvroRecordsWithRevisions.js +++ b/samples/listenForAvroRecordsWithRevisions.js @@ -106,7 +106,6 @@ async function listenForAvroRecordsWithRevisions( console.log( `\tProvince ${result.name} is abbreviated as ${result.post_abbr}` ); - messageCount += 1; // Ack the message.