diff --git a/package.json b/package.json index 8559a35..f6ddff5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@nitric/sdk", "description": "Nitric NodeJS client sdk", - "nitric": "v1.1.0", + "nitric": "v1.6.0", "author": "Nitric ", "repository": "https://github.com/nitrictech/node-sdk", "main": "lib/index.js", diff --git a/src/gen/nitric/proto/deployments/v1/deployments_pb.d.ts b/src/gen/nitric/proto/deployments/v1/deployments_pb.d.ts index d259701..badcb66 100644 --- a/src/gen/nitric/proto/deployments/v1/deployments_pb.d.ts +++ b/src/gen/nitric/proto/deployments/v1/deployments_pb.d.ts @@ -686,6 +686,34 @@ export namespace Schedule { } } +export class SqlDatabase extends jspb.Message { + hasImageUri(): boolean; + clearImageUri(): void; + getImageUri(): string; + setImageUri(value: string): void; + + getMigrationsCase(): SqlDatabase.MigrationsCase; + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): SqlDatabase.AsObject; + static toObject(includeInstance: boolean, msg: SqlDatabase): SqlDatabase.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: SqlDatabase, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): SqlDatabase; + static deserializeBinaryFromReader(message: SqlDatabase, reader: jspb.BinaryReader): SqlDatabase; +} + +export namespace SqlDatabase { + export type AsObject = { + imageUri: string, + } + + export enum MigrationsCase { + MIGRATIONS_NOT_SET = 0, + IMAGE_URI = 1, + } +} + export class ScheduleEvery extends jspb.Message { getRate(): string; setRate(value: string): void; @@ -787,6 +815,11 @@ export class Resource extends jspb.Message { getQueue(): Queue | undefined; setQueue(value?: Queue): void; + hasSqlDatabase(): boolean; + clearSqlDatabase(): void; + getSqlDatabase(): SqlDatabase | undefined; + setSqlDatabase(value?: SqlDatabase): void; + getConfigCase(): Resource.ConfigCase; serializeBinary(): Uint8Array; toObject(includeInstance?: boolean): Resource.AsObject; @@ -812,6 +845,7 @@ export namespace Resource { websocket?: Websocket.AsObject, http?: Http.AsObject, queue?: Queue.AsObject, + sqlDatabase?: SqlDatabase.AsObject, } export enum ConfigCase { @@ -827,6 +861,7 @@ export namespace Resource { WEBSOCKET = 18, HTTP = 19, QUEUE = 20, + SQL_DATABASE = 21, } } diff --git a/src/gen/nitric/proto/deployments/v1/deployments_pb.js b/src/gen/nitric/proto/deployments/v1/deployments_pb.js index d945c53..b17f5f2 100644 --- a/src/gen/nitric/proto/deployments/v1/deployments_pb.js +++ b/src/gen/nitric/proto/deployments/v1/deployments_pb.js @@ -61,6 +61,8 @@ goog.exportSymbol('proto.nitric.proto.deployments.v1.Secret', null, global); goog.exportSymbol('proto.nitric.proto.deployments.v1.Service', null, global); goog.exportSymbol('proto.nitric.proto.deployments.v1.Service.SourceCase', null, global); goog.exportSymbol('proto.nitric.proto.deployments.v1.Spec', null, global); +goog.exportSymbol('proto.nitric.proto.deployments.v1.SqlDatabase', null, global); +goog.exportSymbol('proto.nitric.proto.deployments.v1.SqlDatabase.MigrationsCase', null, global); goog.exportSymbol('proto.nitric.proto.deployments.v1.SubscriptionTarget', null, global); goog.exportSymbol('proto.nitric.proto.deployments.v1.SubscriptionTarget.TargetCase', null, global); goog.exportSymbol('proto.nitric.proto.deployments.v1.Topic', null, global); @@ -574,6 +576,27 @@ if (goog.DEBUG && !COMPILED) { */ proto.nitric.proto.deployments.v1.Schedule.displayName = 'proto.nitric.proto.deployments.v1.Schedule'; } +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.nitric.proto.deployments.v1.SqlDatabase = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, proto.nitric.proto.deployments.v1.SqlDatabase.oneofGroups_); +}; +goog.inherits(proto.nitric.proto.deployments.v1.SqlDatabase, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.nitric.proto.deployments.v1.SqlDatabase.displayName = 'proto.nitric.proto.deployments.v1.SqlDatabase'; +} /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a @@ -5227,6 +5250,179 @@ proto.nitric.proto.deployments.v1.Schedule.prototype.hasCron = function() { +/** + * Oneof group definitions for this message. Each group defines the field + * numbers belonging to that group. When of these fields' value is set, all + * other fields in the group are cleared. During deserialization, if multiple + * fields are encountered for a group, only the last value seen will be kept. + * @private {!Array>} + * @const + */ +proto.nitric.proto.deployments.v1.SqlDatabase.oneofGroups_ = [[1]]; + +/** + * @enum {number} + */ +proto.nitric.proto.deployments.v1.SqlDatabase.MigrationsCase = { + MIGRATIONS_NOT_SET: 0, + IMAGE_URI: 1 +}; + +/** + * @return {proto.nitric.proto.deployments.v1.SqlDatabase.MigrationsCase} + */ +proto.nitric.proto.deployments.v1.SqlDatabase.prototype.getMigrationsCase = function() { + return /** @type {proto.nitric.proto.deployments.v1.SqlDatabase.MigrationsCase} */(jspb.Message.computeOneofCase(this, proto.nitric.proto.deployments.v1.SqlDatabase.oneofGroups_[0])); +}; + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.nitric.proto.deployments.v1.SqlDatabase.prototype.toObject = function(opt_includeInstance) { + return proto.nitric.proto.deployments.v1.SqlDatabase.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.nitric.proto.deployments.v1.SqlDatabase} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.nitric.proto.deployments.v1.SqlDatabase.toObject = function(includeInstance, msg) { + var f, obj = { + imageUri: jspb.Message.getFieldWithDefault(msg, 1, "") + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.nitric.proto.deployments.v1.SqlDatabase} + */ +proto.nitric.proto.deployments.v1.SqlDatabase.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.nitric.proto.deployments.v1.SqlDatabase; + return proto.nitric.proto.deployments.v1.SqlDatabase.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.nitric.proto.deployments.v1.SqlDatabase} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.nitric.proto.deployments.v1.SqlDatabase} + */ +proto.nitric.proto.deployments.v1.SqlDatabase.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {string} */ (reader.readString()); + msg.setImageUri(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.nitric.proto.deployments.v1.SqlDatabase.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.nitric.proto.deployments.v1.SqlDatabase.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.nitric.proto.deployments.v1.SqlDatabase} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.nitric.proto.deployments.v1.SqlDatabase.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = /** @type {string} */ (jspb.Message.getField(message, 1)); + if (f != null) { + writer.writeString( + 1, + f + ); + } +}; + + +/** + * optional string image_uri = 1; + * @return {string} + */ +proto.nitric.proto.deployments.v1.SqlDatabase.prototype.getImageUri = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** + * @param {string} value + * @return {!proto.nitric.proto.deployments.v1.SqlDatabase} returns this + */ +proto.nitric.proto.deployments.v1.SqlDatabase.prototype.setImageUri = function(value) { + return jspb.Message.setOneofField(this, 1, proto.nitric.proto.deployments.v1.SqlDatabase.oneofGroups_[0], value); +}; + + +/** + * Clears the field making it undefined. + * @return {!proto.nitric.proto.deployments.v1.SqlDatabase} returns this + */ +proto.nitric.proto.deployments.v1.SqlDatabase.prototype.clearImageUri = function() { + return jspb.Message.setOneofField(this, 1, proto.nitric.proto.deployments.v1.SqlDatabase.oneofGroups_[0], undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.nitric.proto.deployments.v1.SqlDatabase.prototype.hasImageUri = function() { + return jspb.Message.getField(this, 1) != null; +}; + + + if (jspb.Message.GENERATE_TO_OBJECT) { @@ -5495,7 +5691,7 @@ proto.nitric.proto.deployments.v1.ScheduleCron.prototype.setExpression = functio * @private {!Array>} * @const */ -proto.nitric.proto.deployments.v1.Resource.oneofGroups_ = [[10,11,12,13,14,15,16,17,18,19,20]]; +proto.nitric.proto.deployments.v1.Resource.oneofGroups_ = [[10,11,12,13,14,15,16,17,18,19,20,21]]; /** * @enum {number} @@ -5512,7 +5708,8 @@ proto.nitric.proto.deployments.v1.Resource.ConfigCase = { SECRET: 17, WEBSOCKET: 18, HTTP: 19, - QUEUE: 20 + QUEUE: 20, + SQL_DATABASE: 21 }; /** @@ -5564,7 +5761,8 @@ proto.nitric.proto.deployments.v1.Resource.toObject = function(includeInstance, secret: (f = msg.getSecret()) && proto.nitric.proto.deployments.v1.Secret.toObject(includeInstance, f), websocket: (f = msg.getWebsocket()) && proto.nitric.proto.deployments.v1.Websocket.toObject(includeInstance, f), http: (f = msg.getHttp()) && proto.nitric.proto.deployments.v1.Http.toObject(includeInstance, f), - queue: (f = msg.getQueue()) && proto.nitric.proto.deployments.v1.Queue.toObject(includeInstance, f) + queue: (f = msg.getQueue()) && proto.nitric.proto.deployments.v1.Queue.toObject(includeInstance, f), + sqlDatabase: (f = msg.getSqlDatabase()) && proto.nitric.proto.deployments.v1.SqlDatabase.toObject(includeInstance, f) }; if (includeInstance) { @@ -5661,6 +5859,11 @@ proto.nitric.proto.deployments.v1.Resource.deserializeBinaryFromReader = functio reader.readMessage(value,proto.nitric.proto.deployments.v1.Queue.deserializeBinaryFromReader); msg.setQueue(value); break; + case 21: + var value = new proto.nitric.proto.deployments.v1.SqlDatabase; + reader.readMessage(value,proto.nitric.proto.deployments.v1.SqlDatabase.deserializeBinaryFromReader); + msg.setSqlDatabase(value); + break; default: reader.skipField(); break; @@ -5786,6 +5989,14 @@ proto.nitric.proto.deployments.v1.Resource.serializeBinaryToWriter = function(me proto.nitric.proto.deployments.v1.Queue.serializeBinaryToWriter ); } + f = message.getSqlDatabase(); + if (f != null) { + writer.writeMessage( + 21, + f, + proto.nitric.proto.deployments.v1.SqlDatabase.serializeBinaryToWriter + ); + } }; @@ -6233,6 +6444,43 @@ proto.nitric.proto.deployments.v1.Resource.prototype.hasQueue = function() { }; +/** + * optional SqlDatabase sql_database = 21; + * @return {?proto.nitric.proto.deployments.v1.SqlDatabase} + */ +proto.nitric.proto.deployments.v1.Resource.prototype.getSqlDatabase = function() { + return /** @type{?proto.nitric.proto.deployments.v1.SqlDatabase} */ ( + jspb.Message.getWrapperField(this, proto.nitric.proto.deployments.v1.SqlDatabase, 21)); +}; + + +/** + * @param {?proto.nitric.proto.deployments.v1.SqlDatabase|undefined} value + * @return {!proto.nitric.proto.deployments.v1.Resource} returns this +*/ +proto.nitric.proto.deployments.v1.Resource.prototype.setSqlDatabase = function(value) { + return jspb.Message.setOneofWrapperField(this, 21, proto.nitric.proto.deployments.v1.Resource.oneofGroups_[0], value); +}; + + +/** + * Clears the message field making it undefined. + * @return {!proto.nitric.proto.deployments.v1.Resource} returns this + */ +proto.nitric.proto.deployments.v1.Resource.prototype.clearSqlDatabase = function() { + return this.setSqlDatabase(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.nitric.proto.deployments.v1.Resource.prototype.hasSqlDatabase = function() { + return jspb.Message.getField(this, 21) != null; +}; + + /** * List of repeated fields within this message type. diff --git a/src/gen/nitric/proto/resources/v1/resources_pb.d.ts b/src/gen/nitric/proto/resources/v1/resources_pb.d.ts index 55effb7..77229a7 100644 --- a/src/gen/nitric/proto/resources/v1/resources_pb.d.ts +++ b/src/gen/nitric/proto/resources/v1/resources_pb.d.ts @@ -107,6 +107,11 @@ export class ResourceDeclareRequest extends jspb.Message { getQueue(): QueueResource | undefined; setQueue(value?: QueueResource): void; + hasSqlDatabase(): boolean; + clearSqlDatabase(): void; + getSqlDatabase(): SqlDatabaseResource | undefined; + setSqlDatabase(value?: SqlDatabaseResource): void; + getConfigCase(): ResourceDeclareRequest.ConfigCase; serializeBinary(): Uint8Array; toObject(includeInstance?: boolean): ResourceDeclareRequest.AsObject; @@ -129,6 +134,7 @@ export namespace ResourceDeclareRequest { api?: ApiResource.AsObject, apiSecurityDefinition?: ApiSecurityDefinitionResource.AsObject, queue?: QueueResource.AsObject, + sqlDatabase?: SqlDatabaseResource.AsObject, } export enum ConfigCase { @@ -141,6 +147,7 @@ export namespace ResourceDeclareRequest { API = 15, API_SECURITY_DEFINITION = 16, QUEUE = 17, + SQL_DATABASE = 18, } } @@ -224,6 +231,56 @@ export namespace SecretResource { } } +export class SqlDatabaseMigrations extends jspb.Message { + hasMigrationsPath(): boolean; + clearMigrationsPath(): void; + getMigrationsPath(): string; + setMigrationsPath(value: string): void; + + getMigrationsCase(): SqlDatabaseMigrations.MigrationsCase; + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): SqlDatabaseMigrations.AsObject; + static toObject(includeInstance: boolean, msg: SqlDatabaseMigrations): SqlDatabaseMigrations.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: SqlDatabaseMigrations, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): SqlDatabaseMigrations; + static deserializeBinaryFromReader(message: SqlDatabaseMigrations, reader: jspb.BinaryReader): SqlDatabaseMigrations; +} + +export namespace SqlDatabaseMigrations { + export type AsObject = { + migrationsPath: string, + } + + export enum MigrationsCase { + MIGRATIONS_NOT_SET = 0, + MIGRATIONS_PATH = 1, + } +} + +export class SqlDatabaseResource extends jspb.Message { + hasMigrations(): boolean; + clearMigrations(): void; + getMigrations(): SqlDatabaseMigrations | undefined; + setMigrations(value?: SqlDatabaseMigrations): void; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): SqlDatabaseResource.AsObject; + static toObject(includeInstance: boolean, msg: SqlDatabaseResource): SqlDatabaseResource.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: SqlDatabaseResource, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): SqlDatabaseResource; + static deserializeBinaryFromReader(message: SqlDatabaseResource, reader: jspb.BinaryReader): SqlDatabaseResource; +} + +export namespace SqlDatabaseResource { + export type AsObject = { + migrations?: SqlDatabaseMigrations.AsObject, + } +} + export class ApiOpenIdConnectionDefinition extends jspb.Message { getIssuer(): string; setIssuer(value: string): void; @@ -354,6 +411,7 @@ export interface ResourceTypeMap { HTTP: 11; APISECURITYDEFINITION: 12; QUEUE: 13; + SQLDATABASE: 14; } export const ResourceType: ResourceTypeMap; diff --git a/src/gen/nitric/proto/resources/v1/resources_pb.js b/src/gen/nitric/proto/resources/v1/resources_pb.js index 5fc3b0c..f2ba32a 100644 --- a/src/gen/nitric/proto/resources/v1/resources_pb.js +++ b/src/gen/nitric/proto/resources/v1/resources_pb.js @@ -37,6 +37,9 @@ goog.exportSymbol('proto.nitric.proto.resources.v1.ResourceDeclareResponse', nul goog.exportSymbol('proto.nitric.proto.resources.v1.ResourceIdentifier', null, global); goog.exportSymbol('proto.nitric.proto.resources.v1.ResourceType', null, global); goog.exportSymbol('proto.nitric.proto.resources.v1.SecretResource', null, global); +goog.exportSymbol('proto.nitric.proto.resources.v1.SqlDatabaseMigrations', null, global); +goog.exportSymbol('proto.nitric.proto.resources.v1.SqlDatabaseMigrations.MigrationsCase', null, global); +goog.exportSymbol('proto.nitric.proto.resources.v1.SqlDatabaseResource', null, global); goog.exportSymbol('proto.nitric.proto.resources.v1.TopicResource', null, global); /** * Generated by JsPbCodeGenerator. @@ -206,6 +209,48 @@ if (goog.DEBUG && !COMPILED) { */ proto.nitric.proto.resources.v1.SecretResource.displayName = 'proto.nitric.proto.resources.v1.SecretResource'; } +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, proto.nitric.proto.resources.v1.SqlDatabaseMigrations.oneofGroups_); +}; +goog.inherits(proto.nitric.proto.resources.v1.SqlDatabaseMigrations, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.nitric.proto.resources.v1.SqlDatabaseMigrations.displayName = 'proto.nitric.proto.resources.v1.SqlDatabaseMigrations'; +} +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.nitric.proto.resources.v1.SqlDatabaseResource = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.nitric.proto.resources.v1.SqlDatabaseResource, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.nitric.proto.resources.v1.SqlDatabaseResource.displayName = 'proto.nitric.proto.resources.v1.SqlDatabaseResource'; +} /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a @@ -744,7 +789,7 @@ proto.nitric.proto.resources.v1.ResourceIdentifier.prototype.setName = function( * @private {!Array>} * @const */ -proto.nitric.proto.resources.v1.ResourceDeclareRequest.oneofGroups_ = [[10,11,12,13,14,15,16,17]]; +proto.nitric.proto.resources.v1.ResourceDeclareRequest.oneofGroups_ = [[10,11,12,13,14,15,16,17,18]]; /** * @enum {number} @@ -758,7 +803,8 @@ proto.nitric.proto.resources.v1.ResourceDeclareRequest.ConfigCase = { SECRET: 14, API: 15, API_SECURITY_DEFINITION: 16, - QUEUE: 17 + QUEUE: 17, + SQL_DATABASE: 18 }; /** @@ -807,7 +853,8 @@ proto.nitric.proto.resources.v1.ResourceDeclareRequest.toObject = function(inclu secret: (f = msg.getSecret()) && proto.nitric.proto.resources.v1.SecretResource.toObject(includeInstance, f), api: (f = msg.getApi()) && proto.nitric.proto.resources.v1.ApiResource.toObject(includeInstance, f), apiSecurityDefinition: (f = msg.getApiSecurityDefinition()) && proto.nitric.proto.resources.v1.ApiSecurityDefinitionResource.toObject(includeInstance, f), - queue: (f = msg.getQueue()) && proto.nitric.proto.resources.v1.QueueResource.toObject(includeInstance, f) + queue: (f = msg.getQueue()) && proto.nitric.proto.resources.v1.QueueResource.toObject(includeInstance, f), + sqlDatabase: (f = msg.getSqlDatabase()) && proto.nitric.proto.resources.v1.SqlDatabaseResource.toObject(includeInstance, f) }; if (includeInstance) { @@ -889,6 +936,11 @@ proto.nitric.proto.resources.v1.ResourceDeclareRequest.deserializeBinaryFromRead reader.readMessage(value,proto.nitric.proto.resources.v1.QueueResource.deserializeBinaryFromReader); msg.setQueue(value); break; + case 18: + var value = new proto.nitric.proto.resources.v1.SqlDatabaseResource; + reader.readMessage(value,proto.nitric.proto.resources.v1.SqlDatabaseResource.deserializeBinaryFromReader); + msg.setSqlDatabase(value); + break; default: reader.skipField(); break; @@ -990,6 +1042,14 @@ proto.nitric.proto.resources.v1.ResourceDeclareRequest.serializeBinaryToWriter = proto.nitric.proto.resources.v1.QueueResource.serializeBinaryToWriter ); } + f = message.getSqlDatabase(); + if (f != null) { + writer.writeMessage( + 18, + f, + proto.nitric.proto.resources.v1.SqlDatabaseResource.serializeBinaryToWriter + ); + } }; @@ -1326,6 +1386,43 @@ proto.nitric.proto.resources.v1.ResourceDeclareRequest.prototype.hasQueue = func }; +/** + * optional SqlDatabaseResource sql_database = 18; + * @return {?proto.nitric.proto.resources.v1.SqlDatabaseResource} + */ +proto.nitric.proto.resources.v1.ResourceDeclareRequest.prototype.getSqlDatabase = function() { + return /** @type{?proto.nitric.proto.resources.v1.SqlDatabaseResource} */ ( + jspb.Message.getWrapperField(this, proto.nitric.proto.resources.v1.SqlDatabaseResource, 18)); +}; + + +/** + * @param {?proto.nitric.proto.resources.v1.SqlDatabaseResource|undefined} value + * @return {!proto.nitric.proto.resources.v1.ResourceDeclareRequest} returns this +*/ +proto.nitric.proto.resources.v1.ResourceDeclareRequest.prototype.setSqlDatabase = function(value) { + return jspb.Message.setOneofWrapperField(this, 18, proto.nitric.proto.resources.v1.ResourceDeclareRequest.oneofGroups_[0], value); +}; + + +/** + * Clears the message field making it undefined. + * @return {!proto.nitric.proto.resources.v1.ResourceDeclareRequest} returns this + */ +proto.nitric.proto.resources.v1.ResourceDeclareRequest.prototype.clearSqlDatabase = function() { + return this.setSqlDatabase(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.nitric.proto.resources.v1.ResourceDeclareRequest.prototype.hasSqlDatabase = function() { + return jspb.Message.getField(this, 18) != null; +}; + + @@ -1832,6 +1929,330 @@ proto.nitric.proto.resources.v1.SecretResource.serializeBinaryToWriter = functio +/** + * Oneof group definitions for this message. Each group defines the field + * numbers belonging to that group. When of these fields' value is set, all + * other fields in the group are cleared. During deserialization, if multiple + * fields are encountered for a group, only the last value seen will be kept. + * @private {!Array>} + * @const + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.oneofGroups_ = [[1]]; + +/** + * @enum {number} + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.MigrationsCase = { + MIGRATIONS_NOT_SET: 0, + MIGRATIONS_PATH: 1 +}; + +/** + * @return {proto.nitric.proto.resources.v1.SqlDatabaseMigrations.MigrationsCase} + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.prototype.getMigrationsCase = function() { + return /** @type {proto.nitric.proto.resources.v1.SqlDatabaseMigrations.MigrationsCase} */(jspb.Message.computeOneofCase(this, proto.nitric.proto.resources.v1.SqlDatabaseMigrations.oneofGroups_[0])); +}; + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.prototype.toObject = function(opt_includeInstance) { + return proto.nitric.proto.resources.v1.SqlDatabaseMigrations.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.nitric.proto.resources.v1.SqlDatabaseMigrations} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.toObject = function(includeInstance, msg) { + var f, obj = { + migrationsPath: jspb.Message.getFieldWithDefault(msg, 1, "") + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.nitric.proto.resources.v1.SqlDatabaseMigrations} + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.nitric.proto.resources.v1.SqlDatabaseMigrations; + return proto.nitric.proto.resources.v1.SqlDatabaseMigrations.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.nitric.proto.resources.v1.SqlDatabaseMigrations} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.nitric.proto.resources.v1.SqlDatabaseMigrations} + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {string} */ (reader.readString()); + msg.setMigrationsPath(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.nitric.proto.resources.v1.SqlDatabaseMigrations.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.nitric.proto.resources.v1.SqlDatabaseMigrations} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = /** @type {string} */ (jspb.Message.getField(message, 1)); + if (f != null) { + writer.writeString( + 1, + f + ); + } +}; + + +/** + * optional string migrations_path = 1; + * @return {string} + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.prototype.getMigrationsPath = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** + * @param {string} value + * @return {!proto.nitric.proto.resources.v1.SqlDatabaseMigrations} returns this + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.prototype.setMigrationsPath = function(value) { + return jspb.Message.setOneofField(this, 1, proto.nitric.proto.resources.v1.SqlDatabaseMigrations.oneofGroups_[0], value); +}; + + +/** + * Clears the field making it undefined. + * @return {!proto.nitric.proto.resources.v1.SqlDatabaseMigrations} returns this + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.prototype.clearMigrationsPath = function() { + return jspb.Message.setOneofField(this, 1, proto.nitric.proto.resources.v1.SqlDatabaseMigrations.oneofGroups_[0], undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.nitric.proto.resources.v1.SqlDatabaseMigrations.prototype.hasMigrationsPath = function() { + return jspb.Message.getField(this, 1) != null; +}; + + + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.nitric.proto.resources.v1.SqlDatabaseResource.prototype.toObject = function(opt_includeInstance) { + return proto.nitric.proto.resources.v1.SqlDatabaseResource.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.nitric.proto.resources.v1.SqlDatabaseResource} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.nitric.proto.resources.v1.SqlDatabaseResource.toObject = function(includeInstance, msg) { + var f, obj = { + migrations: (f = msg.getMigrations()) && proto.nitric.proto.resources.v1.SqlDatabaseMigrations.toObject(includeInstance, f) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.nitric.proto.resources.v1.SqlDatabaseResource} + */ +proto.nitric.proto.resources.v1.SqlDatabaseResource.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.nitric.proto.resources.v1.SqlDatabaseResource; + return proto.nitric.proto.resources.v1.SqlDatabaseResource.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.nitric.proto.resources.v1.SqlDatabaseResource} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.nitric.proto.resources.v1.SqlDatabaseResource} + */ +proto.nitric.proto.resources.v1.SqlDatabaseResource.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = new proto.nitric.proto.resources.v1.SqlDatabaseMigrations; + reader.readMessage(value,proto.nitric.proto.resources.v1.SqlDatabaseMigrations.deserializeBinaryFromReader); + msg.setMigrations(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.nitric.proto.resources.v1.SqlDatabaseResource.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.nitric.proto.resources.v1.SqlDatabaseResource.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.nitric.proto.resources.v1.SqlDatabaseResource} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.nitric.proto.resources.v1.SqlDatabaseResource.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getMigrations(); + if (f != null) { + writer.writeMessage( + 1, + f, + proto.nitric.proto.resources.v1.SqlDatabaseMigrations.serializeBinaryToWriter + ); + } +}; + + +/** + * optional SqlDatabaseMigrations migrations = 1; + * @return {?proto.nitric.proto.resources.v1.SqlDatabaseMigrations} + */ +proto.nitric.proto.resources.v1.SqlDatabaseResource.prototype.getMigrations = function() { + return /** @type{?proto.nitric.proto.resources.v1.SqlDatabaseMigrations} */ ( + jspb.Message.getWrapperField(this, proto.nitric.proto.resources.v1.SqlDatabaseMigrations, 1)); +}; + + +/** + * @param {?proto.nitric.proto.resources.v1.SqlDatabaseMigrations|undefined} value + * @return {!proto.nitric.proto.resources.v1.SqlDatabaseResource} returns this +*/ +proto.nitric.proto.resources.v1.SqlDatabaseResource.prototype.setMigrations = function(value) { + return jspb.Message.setWrapperField(this, 1, value); +}; + + +/** + * Clears the message field making it undefined. + * @return {!proto.nitric.proto.resources.v1.SqlDatabaseResource} returns this + */ +proto.nitric.proto.resources.v1.SqlDatabaseResource.prototype.clearMigrations = function() { + return this.setMigrations(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.nitric.proto.resources.v1.SqlDatabaseResource.prototype.hasMigrations = function() { + return jspb.Message.getField(this, 1) != null; +}; + + + /** * List of repeated fields within this message type. * @private {!Array} @@ -2630,7 +3051,8 @@ proto.nitric.proto.resources.v1.ResourceType = { WEBSOCKET: 10, HTTP: 11, APISECURITYDEFINITION: 12, - QUEUE: 13 + QUEUE: 13, + SQLDATABASE: 14 }; /** diff --git a/src/gen/nitric/proto/sql/v1/sql_grpc_pb.d.ts b/src/gen/nitric/proto/sql/v1/sql_grpc_pb.d.ts new file mode 100644 index 0000000..e30c372 --- /dev/null +++ b/src/gen/nitric/proto/sql/v1/sql_grpc_pb.d.ts @@ -0,0 +1,24 @@ +// GENERATED CODE -- DO NOT EDIT! + +// package: nitric.proto.sql.v1 +// file: nitric/proto/sql/v1/sql.proto + +import * as nitric_proto_sql_v1_sql_pb from "../../../../nitric/proto/sql/v1/sql_pb"; +import * as grpc from "@grpc/grpc-js"; + +interface ISqlService extends grpc.ServiceDefinition { + connectionString: grpc.MethodDefinition; +} + +export const SqlService: ISqlService; + +export interface ISqlServer extends grpc.UntypedServiceImplementation { + connectionString: grpc.handleUnaryCall; +} + +export class SqlClient extends grpc.Client { + constructor(address: string, credentials: grpc.ChannelCredentials, options?: object); + connectionString(argument: nitric_proto_sql_v1_sql_pb.SqlConnectionStringRequest, callback: grpc.requestCallback): grpc.ClientUnaryCall; + connectionString(argument: nitric_proto_sql_v1_sql_pb.SqlConnectionStringRequest, metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; + connectionString(argument: nitric_proto_sql_v1_sql_pb.SqlConnectionStringRequest, metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; +} diff --git a/src/gen/nitric/proto/sql/v1/sql_grpc_pb.js b/src/gen/nitric/proto/sql/v1/sql_grpc_pb.js new file mode 100644 index 0000000..1447a1f --- /dev/null +++ b/src/gen/nitric/proto/sql/v1/sql_grpc_pb.js @@ -0,0 +1,46 @@ +// GENERATED CODE -- DO NOT EDIT! + +'use strict'; +var grpc = require('@grpc/grpc-js'); +var nitric_proto_sql_v1_sql_pb = require('../../../../nitric/proto/sql/v1/sql_pb.js'); + +function serialize_nitric_proto_sql_v1_SqlConnectionStringRequest(arg) { + if (!(arg instanceof nitric_proto_sql_v1_sql_pb.SqlConnectionStringRequest)) { + throw new Error('Expected argument of type nitric.proto.sql.v1.SqlConnectionStringRequest'); + } + return Buffer.from(arg.serializeBinary()); +} + +function deserialize_nitric_proto_sql_v1_SqlConnectionStringRequest(buffer_arg) { + return nitric_proto_sql_v1_sql_pb.SqlConnectionStringRequest.deserializeBinary(new Uint8Array(buffer_arg)); +} + +function serialize_nitric_proto_sql_v1_SqlConnectionStringResponse(arg) { + if (!(arg instanceof nitric_proto_sql_v1_sql_pb.SqlConnectionStringResponse)) { + throw new Error('Expected argument of type nitric.proto.sql.v1.SqlConnectionStringResponse'); + } + return Buffer.from(arg.serializeBinary()); +} + +function deserialize_nitric_proto_sql_v1_SqlConnectionStringResponse(buffer_arg) { + return nitric_proto_sql_v1_sql_pb.SqlConnectionStringResponse.deserializeBinary(new Uint8Array(buffer_arg)); +} + + +// The Nitric Secret Service +var SqlService = exports.SqlService = { + // Retrieve the connection string for a given database +connectionString: { + path: '/nitric.proto.sql.v1.Sql/ConnectionString', + requestStream: false, + responseStream: false, + requestType: nitric_proto_sql_v1_sql_pb.SqlConnectionStringRequest, + responseType: nitric_proto_sql_v1_sql_pb.SqlConnectionStringResponse, + requestSerialize: serialize_nitric_proto_sql_v1_SqlConnectionStringRequest, + requestDeserialize: deserialize_nitric_proto_sql_v1_SqlConnectionStringRequest, + responseSerialize: serialize_nitric_proto_sql_v1_SqlConnectionStringResponse, + responseDeserialize: deserialize_nitric_proto_sql_v1_SqlConnectionStringResponse, + }, +}; + +exports.SqlClient = grpc.makeGenericClientConstructor(SqlService); diff --git a/src/gen/nitric/proto/sql/v1/sql_pb.d.ts b/src/gen/nitric/proto/sql/v1/sql_pb.d.ts new file mode 100644 index 0000000..e2dd294 --- /dev/null +++ b/src/gen/nitric/proto/sql/v1/sql_pb.d.ts @@ -0,0 +1,45 @@ +// package: nitric.proto.sql.v1 +// file: nitric/proto/sql/v1/sql.proto + +import * as jspb from "google-protobuf"; + +export class SqlConnectionStringRequest extends jspb.Message { + getDatabaseName(): string; + setDatabaseName(value: string): void; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): SqlConnectionStringRequest.AsObject; + static toObject(includeInstance: boolean, msg: SqlConnectionStringRequest): SqlConnectionStringRequest.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: SqlConnectionStringRequest, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): SqlConnectionStringRequest; + static deserializeBinaryFromReader(message: SqlConnectionStringRequest, reader: jspb.BinaryReader): SqlConnectionStringRequest; +} + +export namespace SqlConnectionStringRequest { + export type AsObject = { + databaseName: string, + } +} + +export class SqlConnectionStringResponse extends jspb.Message { + getConnectionString(): string; + setConnectionString(value: string): void; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): SqlConnectionStringResponse.AsObject; + static toObject(includeInstance: boolean, msg: SqlConnectionStringResponse): SqlConnectionStringResponse.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: SqlConnectionStringResponse, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): SqlConnectionStringResponse; + static deserializeBinaryFromReader(message: SqlConnectionStringResponse, reader: jspb.BinaryReader): SqlConnectionStringResponse; +} + +export namespace SqlConnectionStringResponse { + export type AsObject = { + connectionString: string, + } +} + diff --git a/src/gen/nitric/proto/sql/v1/sql_pb.js b/src/gen/nitric/proto/sql/v1/sql_pb.js new file mode 100644 index 0000000..4281e1c --- /dev/null +++ b/src/gen/nitric/proto/sql/v1/sql_pb.js @@ -0,0 +1,328 @@ +// source: nitric/proto/sql/v1/sql.proto +/** + * @fileoverview + * @enhanceable + * @suppress {missingRequire} reports error on implicit type usages. + * @suppress {messageConventions} JS Compiler reports an error if a variable or + * field starts with 'MSG_' and isn't a translatable message. + * @public + */ +// GENERATED CODE -- DO NOT EDIT! +/* eslint-disable */ +// @ts-nocheck + +var jspb = require('google-protobuf'); +var goog = jspb; +var global = (function() { + if (this) { return this; } + if (typeof window !== 'undefined') { return window; } + if (typeof global !== 'undefined') { return global; } + if (typeof self !== 'undefined') { return self; } + return Function('return this')(); +}.call(null)); + +goog.exportSymbol('proto.nitric.proto.sql.v1.SqlConnectionStringRequest', null, global); +goog.exportSymbol('proto.nitric.proto.sql.v1.SqlConnectionStringResponse', null, global); +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.nitric.proto.sql.v1.SqlConnectionStringRequest = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.nitric.proto.sql.v1.SqlConnectionStringRequest, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.nitric.proto.sql.v1.SqlConnectionStringRequest.displayName = 'proto.nitric.proto.sql.v1.SqlConnectionStringRequest'; +} +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.nitric.proto.sql.v1.SqlConnectionStringResponse = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.nitric.proto.sql.v1.SqlConnectionStringResponse, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.nitric.proto.sql.v1.SqlConnectionStringResponse.displayName = 'proto.nitric.proto.sql.v1.SqlConnectionStringResponse'; +} + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.nitric.proto.sql.v1.SqlConnectionStringRequest.prototype.toObject = function(opt_includeInstance) { + return proto.nitric.proto.sql.v1.SqlConnectionStringRequest.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.nitric.proto.sql.v1.SqlConnectionStringRequest} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.nitric.proto.sql.v1.SqlConnectionStringRequest.toObject = function(includeInstance, msg) { + var f, obj = { + databaseName: jspb.Message.getFieldWithDefault(msg, 1, "") + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.nitric.proto.sql.v1.SqlConnectionStringRequest} + */ +proto.nitric.proto.sql.v1.SqlConnectionStringRequest.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.nitric.proto.sql.v1.SqlConnectionStringRequest; + return proto.nitric.proto.sql.v1.SqlConnectionStringRequest.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.nitric.proto.sql.v1.SqlConnectionStringRequest} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.nitric.proto.sql.v1.SqlConnectionStringRequest} + */ +proto.nitric.proto.sql.v1.SqlConnectionStringRequest.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {string} */ (reader.readString()); + msg.setDatabaseName(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.nitric.proto.sql.v1.SqlConnectionStringRequest.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.nitric.proto.sql.v1.SqlConnectionStringRequest.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.nitric.proto.sql.v1.SqlConnectionStringRequest} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.nitric.proto.sql.v1.SqlConnectionStringRequest.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getDatabaseName(); + if (f.length > 0) { + writer.writeString( + 1, + f + ); + } +}; + + +/** + * optional string database_name = 1; + * @return {string} + */ +proto.nitric.proto.sql.v1.SqlConnectionStringRequest.prototype.getDatabaseName = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** + * @param {string} value + * @return {!proto.nitric.proto.sql.v1.SqlConnectionStringRequest} returns this + */ +proto.nitric.proto.sql.v1.SqlConnectionStringRequest.prototype.setDatabaseName = function(value) { + return jspb.Message.setProto3StringField(this, 1, value); +}; + + + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.nitric.proto.sql.v1.SqlConnectionStringResponse.prototype.toObject = function(opt_includeInstance) { + return proto.nitric.proto.sql.v1.SqlConnectionStringResponse.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.nitric.proto.sql.v1.SqlConnectionStringResponse} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.nitric.proto.sql.v1.SqlConnectionStringResponse.toObject = function(includeInstance, msg) { + var f, obj = { + connectionString: jspb.Message.getFieldWithDefault(msg, 1, "") + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.nitric.proto.sql.v1.SqlConnectionStringResponse} + */ +proto.nitric.proto.sql.v1.SqlConnectionStringResponse.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.nitric.proto.sql.v1.SqlConnectionStringResponse; + return proto.nitric.proto.sql.v1.SqlConnectionStringResponse.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.nitric.proto.sql.v1.SqlConnectionStringResponse} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.nitric.proto.sql.v1.SqlConnectionStringResponse} + */ +proto.nitric.proto.sql.v1.SqlConnectionStringResponse.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {string} */ (reader.readString()); + msg.setConnectionString(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.nitric.proto.sql.v1.SqlConnectionStringResponse.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.nitric.proto.sql.v1.SqlConnectionStringResponse.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.nitric.proto.sql.v1.SqlConnectionStringResponse} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.nitric.proto.sql.v1.SqlConnectionStringResponse.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getConnectionString(); + if (f.length > 0) { + writer.writeString( + 1, + f + ); + } +}; + + +/** + * optional string connection_string = 1; + * @return {string} + */ +proto.nitric.proto.sql.v1.SqlConnectionStringResponse.prototype.getConnectionString = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** + * @param {string} value + * @return {!proto.nitric.proto.sql.v1.SqlConnectionStringResponse} returns this + */ +proto.nitric.proto.sql.v1.SqlConnectionStringResponse.prototype.setConnectionString = function(value) { + return jspb.Message.setProto3StringField(this, 1, value); +}; + + +goog.object.extend(exports, proto.nitric.proto.sql.v1); diff --git a/src/resources/index.ts b/src/resources/index.ts index 87fe222..ecb5394 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -18,6 +18,7 @@ export * from './keyvalue'; export * from './bucket'; export * from './schedule'; export * from './secret'; +export * from './sql'; export * from './http'; export * from './websocket'; export { oidcRule } from './oidc'; diff --git a/src/resources/sql.ts b/src/resources/sql.ts new file mode 100644 index 0000000..4908246 --- /dev/null +++ b/src/resources/sql.ts @@ -0,0 +1,130 @@ +// Copyright 2021, Nitric Technologies Pty Ltd. +// +// 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. +import { + ResourceIdentifier, + ResourceDeclareRequest, + ResourceType, + ResourceTypeMap, + SqlDatabaseResource, + SqlDatabaseMigrations, +} from '@nitric/proto/resources/v1/resources_pb'; +import { SqlConnectionStringRequest } from '@nitric/proto/sql/v1/sql_pb'; +import resourceClient from './client'; +import { make, Resource as Base } from './common'; +import { SqlClient } from '../gen/nitric/proto/sql/v1/sql_grpc_pb'; +import { SERVICE_BIND } from '../constants'; +import * as grpc from '@grpc/grpc-js'; +import { fromGrpcError } from '../api/errors'; + +interface SQLDatabaseOptions { + /** + * Location of migrations for the SQL Database + * This can be specified as either a local file path or a docker file relative to the nitric project root. + * e.g. "file://migrations/main-database" or "dockerfile://path/to/migration.dockerfile" + */ + migrations: string; +} +/** + * Register a SQL resource to the provided application. + */ +export class SQLDatabaseResource extends Base { + private readonly sqlClient: SqlClient; + private readonly options?: SQLDatabaseOptions; + + constructor(name: string, options?: SQLDatabaseOptions) { + super(name); + this.options = options; + this.sqlClient = new SqlClient( + SERVICE_BIND, + grpc.ChannelCredentials.createInsecure() + ); + } + + /** + * Register this SQL as a required resource for the calling function/container. + * + * @returns a promise that resolves when the registration is complete + */ + protected async register(): Promise { + const req = new ResourceDeclareRequest(); + const resource = new ResourceIdentifier(); + resource.setName(this.name); + resource.setType(ResourceType.SQLDATABASE); + req.setId(resource); + + const sqlConfig = new SqlDatabaseResource(); + + if (this.options) { + const sqlMigrations = new SqlDatabaseMigrations(); + sqlMigrations.setMigrationsPath(this.options.migrations); + + sqlConfig.setMigrations(sqlMigrations); + } + + req.setSqlDatabase(sqlConfig); + + const res = await new Promise((resolve, reject) => { + resourceClient.declare(req, (error, _: ResourceDeclareRequest) => { + if (error) { + reject(fromGrpcError(error)); + } else { + resolve(resource); + } + }); + }); + + return res; + } + + /** + * Retrieves the connection string of this SQL Database at runtime. + * + * @returns Promise that returns the connection string of this SQL Database + */ + async connectionString(): Promise { + const request = new SqlConnectionStringRequest(); + request.setDatabaseName(this.name); + + const connectionString = await new Promise((resolve, reject) => { + this.sqlClient.connectionString(request, (error, data) => { + if (error) { + reject(fromGrpcError(error)); + } else { + resolve(data.getConnectionString()); + } + }); + }); + + return connectionString; + } + + protected resourceType(): ResourceTypeMap[keyof ResourceTypeMap] { + return ResourceType.SQLDATABASE; + } +} + +const maker = make(SQLDatabaseResource); + +/** + * Register a SQL Database Resource. If the SQL Database has already been registered, the existing SQL will be returned. + * + * The returned SQL Database object can be used to register handlers for SQL events. + * e.g. const connectionString = db.connectionString() + * + * @param name the name of the SQL Database + * @param options the options for the SQL Database + * @returns a SQL resource + */ +export const sql = (name: string, options?: SQLDatabaseOptions) => + maker(name, options);