googleapis-nodejs-functions
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -18,2 +18,3 @@ import { ServiceObject } from '@google-cloud/common'; | ||
name: string; | ||
metadata: CloudFunctionMetadata; | ||
/** | ||
@@ -32,3 +33,3 @@ * A reference to the {@link GCF} associated with this {@link CloudFunction} | ||
userProject: string; | ||
constructor(gcf: any, name: any, options?: any); | ||
constructor(gcf: any, name: any, metadata?: any, options?: any); | ||
/** | ||
@@ -35,0 +36,0 @@ * Delete the function. |
@@ -16,3 +16,3 @@ "use strict"; | ||
class CloudFunction extends common_1.ServiceObject { | ||
constructor(gcf, name, options) { | ||
constructor(gcf, name, metadata, options) { | ||
options = options || {}; | ||
@@ -34,4 +34,5 @@ const methods = { | ||
}); | ||
this.gcf = gcf; | ||
this.name = name; | ||
this.gcf = gcf; | ||
this.metadata = metadata; | ||
this.userProject = options.userProject; | ||
@@ -38,0 +39,0 @@ } |
import { Service, GoogleAuthOptions } from '@google-cloud/common'; | ||
import * as request from 'request'; | ||
import { CloudFunction } from './cloudfunction'; | ||
export declare enum CloudFunctionStatus { | ||
CLOUD_FUNCTION_STATUS_UNSPECIFIED = 0, | ||
ACTIVE = 1, | ||
OFFLINE = 2, | ||
DEPLOY_IN_PROGRESS = 3, | ||
DELETE_IN_PROGRESS = 4, | ||
UNKNOWN = 5 | ||
} | ||
export declare enum CloudFunctionRuntimes { | ||
nodejs6 = 0, | ||
nodejs8 = 1, | ||
python3 = 2 | ||
} | ||
export interface HttpsTrigger { | ||
url: string; | ||
} | ||
export interface FailurePolicy { | ||
retry: any; | ||
} | ||
export interface EventTrigger { | ||
eventType: string; | ||
resource: string; | ||
service: string; | ||
failurePolicy?: FailurePolicy; | ||
} | ||
export interface SourceRepository { | ||
url: string; | ||
deployedUrl?: string; | ||
} | ||
export interface CloudFunctionMetadata { | ||
runtime: string; | ||
description: string; | ||
status: CloudFunctionStatus; | ||
entryPoint: string; | ||
timeout: string; | ||
availableMemoryMb: number; | ||
serviceAccountEmail: string; | ||
updateTime: string; | ||
versionId: string; | ||
labels: any; | ||
environmentVariables: any; | ||
network: string; | ||
maxInstances: number; | ||
sourceArchiveUrl?: string; | ||
sourceRepository?: SourceRepository; | ||
sourceUploadUrl?: string; | ||
httpsTrigger?: HttpsTrigger; | ||
eventTrigger?: EventTrigger; | ||
} | ||
export interface CloudFunctionConfig { | ||
location?: string; | ||
runtime?: string; | ||
location?: string; | ||
description?: string; | ||
entryPoint?: string; | ||
timeout?: string; | ||
availableMemoryMb?: number; | ||
labels?: any; | ||
sourceArchiveUrl?: string; | ||
sourceRepository?: SourceRepository; | ||
sourceUploadUrl?: string; | ||
httpsTrigger?: HttpsTrigger; | ||
eventTrigger?: EventTrigger; | ||
} | ||
@@ -22,10 +78,10 @@ export interface CloudFunctionQuery { | ||
message: string; | ||
details: object[]; | ||
details?: any; | ||
} | ||
export interface Operation { | ||
name: string; | ||
metadata: object; | ||
metadata: any; | ||
done: boolean; | ||
error: Status; | ||
response: object; | ||
error?: Status; | ||
response?: any; | ||
} | ||
@@ -52,3 +108,3 @@ export interface ListOperationsResponse { | ||
export interface CloudFunctionCallback { | ||
(err: Error | null, fn?: CloudFunction | null | undefined, apiResponse?: request.Response): void; | ||
(err: Error | null, fn?: CloudFunction | null | undefined | Operation, apiResponse?: request.Response): void; | ||
} | ||
@@ -78,3 +134,3 @@ export interface CloudFunctionsCallback { | ||
*/ | ||
cloudFunction(name: string): CloudFunction; | ||
cloudFunction(name: string, metadata?: CloudFunctionMetadata): CloudFunction; | ||
/** | ||
@@ -90,4 +146,4 @@ * Create a function. | ||
*/ | ||
createCloudFunction(name: string, callback: CloudFunctionCallback): void; | ||
createCloudFunction(name: string, metadata: CloudFunctionConfig, callback: CloudFunctionCallback): void; | ||
createCloudFunction(name: string, callback: CloudFunctionCallback): void | Promise<[Operation, any]>; | ||
createCloudFunction(name: string, metadata: CloudFunctionConfig, callback?: CloudFunctionCallback): void | Promise<[Operation, any]>; | ||
private getLocations; | ||
@@ -102,3 +158,4 @@ /** | ||
getCloudFunctions(query?: CloudFunctionQuery, callback?: CloudFunctionsCallback): void | Promise<[CloudFunction[], any]>; | ||
operation(name: string, callback?: CloudFunctionCallback): void | Promise<[Operation, any]>; | ||
} | ||
export { GCF, CloudFunction }; |
@@ -11,2 +11,17 @@ "use strict"; | ||
exports.CloudFunction = cloudfunction_1.CloudFunction; | ||
var CloudFunctionStatus; | ||
(function (CloudFunctionStatus) { | ||
CloudFunctionStatus[CloudFunctionStatus["CLOUD_FUNCTION_STATUS_UNSPECIFIED"] = 0] = "CLOUD_FUNCTION_STATUS_UNSPECIFIED"; | ||
CloudFunctionStatus[CloudFunctionStatus["ACTIVE"] = 1] = "ACTIVE"; | ||
CloudFunctionStatus[CloudFunctionStatus["OFFLINE"] = 2] = "OFFLINE"; | ||
CloudFunctionStatus[CloudFunctionStatus["DEPLOY_IN_PROGRESS"] = 3] = "DEPLOY_IN_PROGRESS"; | ||
CloudFunctionStatus[CloudFunctionStatus["DELETE_IN_PROGRESS"] = 4] = "DELETE_IN_PROGRESS"; | ||
CloudFunctionStatus[CloudFunctionStatus["UNKNOWN"] = 5] = "UNKNOWN"; | ||
})(CloudFunctionStatus = exports.CloudFunctionStatus || (exports.CloudFunctionStatus = {})); | ||
var CloudFunctionRuntimes; | ||
(function (CloudFunctionRuntimes) { | ||
CloudFunctionRuntimes[CloudFunctionRuntimes["nodejs6"] = 0] = "nodejs6"; | ||
CloudFunctionRuntimes[CloudFunctionRuntimes["nodejs8"] = 1] = "nodejs8"; | ||
CloudFunctionRuntimes[CloudFunctionRuntimes["python3"] = 2] = "python3"; | ||
})(CloudFunctionRuntimes = exports.CloudFunctionRuntimes || (exports.CloudFunctionRuntimes = {})); | ||
/*! | ||
@@ -36,7 +51,7 @@ * @param {ConfigurationObject} [options] Configuration options. | ||
*/ | ||
cloudFunction(name) { | ||
cloudFunction(name, metadata) { | ||
if (!name) { | ||
throw new Error('A function name is needed to use Cloud Functions.'); | ||
} | ||
return new cloudfunction_1.CloudFunction(this, name); | ||
return new cloudfunction_1.CloudFunction(this, name, metadata); | ||
} | ||
@@ -60,10 +75,7 @@ createCloudFunction(name, metadataOrCallback, callback) { | ||
// @developer @archelogos | ||
// @TODO business logic here | ||
// is there a way to get this dynamically? | ||
const functionRuntimes = { | ||
node6: 'nodejs6', | ||
node8: 'nodejs8', | ||
python3: 'python3' | ||
}; | ||
// @TODO business logic here -> runtimes check | ||
const location = metadata.location || this.location; // GCP region | ||
// @developer @archelogos | ||
// @TODO business logic here -> name check | ||
body.name = `projects/${this.projectId}/locations/${location}/functions/${name}`; | ||
this.request({ | ||
@@ -79,10 +91,6 @@ method: 'POST', | ||
} | ||
const operation = resp; | ||
// @developer @archelogos | ||
// @TODO wait until the operations is resolved --> return CloudFunction instance | ||
const cloudFunction = this.cloudFunction(name); | ||
// check this | ||
// cloudFunction.metadata = resp; | ||
// @developer @archelogos | ||
// That's the non-null assertion operator (https://stackoverflow.com/questions/42273853/in-typescript-what-is-the-exclamation-mark-bang-operator-when-dereferenci) | ||
callback(null, cloudFunction, resp); | ||
callback(null, operation, resp); | ||
}); | ||
@@ -114,4 +122,3 @@ } | ||
const cloudFunctions = arrify(resp.functions).map(fn => { | ||
const cloudFunctionInstance = this.cloudFunction(fn.name); | ||
cloudFunctionInstance.metadata = { runtime: fn.runtime }; | ||
const cloudFunctionInstance = this.cloudFunction(fn.name, fn); | ||
return cloudFunctionInstance; | ||
@@ -126,2 +133,20 @@ }); | ||
} | ||
operation(name, callback) { | ||
// @TODO validate name /operations/some/unique/name | ||
this.request({ | ||
method: 'GET', | ||
uri: `/projects/${this.projectId}/operations/${name}`, | ||
qs: '', | ||
json: {}, | ||
}, (err, resp) => { | ||
if (err) { | ||
callback(err, null, resp); | ||
return; | ||
} | ||
const operation = resp; | ||
// @developer @archelogos | ||
// That's the non-null assertion operator (https://stackoverflow.com/questions/42273853/in-typescript-what-is-the-exclamation-mark-bang-operator-when-dereferenci) | ||
callback(null, operation, resp); | ||
}); | ||
} | ||
} | ||
@@ -128,0 +153,0 @@ /** |
{ | ||
"name": "googleapis-nodejs-functions", | ||
"description": "Google Cloud Functions Client Library for Node.js (unofficial)", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "author": "vizzuality-research", |
@@ -47,3 +47,3 @@ # Google Cloud Functions Node.js Library | ||
// Imports the Google Cloud client library | ||
const { GCF } = require('../build/src'); // @TODO vizzuality/googleapis-nodejs-functions | ||
const { GCF } = require('googleapis-nodejs-functions'); | ||
@@ -66,9 +66,3 @@ // Your Google Cloud Platform project ID | ||
const fn = fns[0]; | ||
fn.getMetadata() | ||
.then(data => { | ||
console.log('Function: ', data[0]); | ||
}) | ||
.catch(err => { | ||
console.error('ERROR:', err); | ||
}); | ||
console.log(fn.metadata); | ||
}) | ||
@@ -75,0 +69,0 @@ .catch(err => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
41287
567
86