├── .gitignore ├── README.md ├── build.gradle ├── firebase.json ├── functions ├── index.js ├── index.js.map ├── index.meta.js ├── index │ └── com │ │ ├── expressjs │ │ └── wrapper │ │ │ └── wrapper.kjsm │ │ ├── firebase │ │ ├── wrapper │ │ │ └── admin │ │ │ │ └── firestore │ │ │ │ └── firestore.kjsm │ │ └── wrappers │ │ │ ├── admin │ │ │ ├── admin.kjsm │ │ │ ├── database │ │ │ │ └── database.kjsm │ │ │ ├── firestore │ │ │ │ └── firestore.kjsm │ │ │ └── storage │ │ │ │ └── storage.kjsm │ │ │ └── functions │ │ │ └── functions.kjsm │ │ └── todo │ │ └── todo.kjsm └── package.json ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib ├── kotlin-stdlib-js-sources.jar └── kotlin-stdlib-js.jar └── src └── main └── kotlin └── com ├── expressjs └── wrapper │ ├── Application.kt │ ├── CookieOptions.kt │ ├── Express.kt │ ├── Request.kt │ └── Response.kt ├── firebase └── wrapper │ ├── admin │ ├── Admin.kt │ ├── CloudFunction.kt │ ├── Config.kt │ ├── Event.kt │ ├── FirebaseAppOptions.kt │ ├── FirebaseError.kt │ ├── database │ │ ├── Database.kt │ │ ├── DeltaSnapshot.kt │ │ └── Reference.kt │ ├── firestore │ │ ├── CollectionReference.kt │ │ ├── DocumentData.kt │ │ ├── DocumentReference.kt │ │ ├── DocumentSnapshot.kt │ │ ├── Firestore.kt │ │ ├── QueryDocumentSnapshot.kt │ │ ├── QuerySnapshot.kt │ │ ├── SnapshotMetadata.kt │ │ └── SnapshotOptions.kt │ └── storage │ │ ├── Bucket.kt │ │ ├── BucketFileOptions.kt │ │ ├── File.kt │ │ ├── Storage.kt │ │ ├── WriteStream.kt │ │ └── WriteStreamOptions.kt │ └── functions │ ├── Functions.kt │ └── Https.kt └── todo └── Index.kt /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | **/node_modules/* 3 | **/.firebaserc 4 | */npm-debug.log 5 | lerna-debug.log 6 | *~ 7 | service-account-credentials.json 8 | build 9 | .gradle 10 | functions/firebase-debug.log -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ToDo sample 2 | 3 | This project contains a ToDo sample based on firebase cloud functions. 4 | 5 | Source code starts from JavaScript sample to KotlinJS sample. 6 | 7 | 8 | ## Overview 9 | 10 | Project is composed of 3 WS : 11 | 12 | * GET /todo/id 13 | 14 | Get list of todo if no id set, get the todo information if id set 15 | 16 | ``` 17 | curl -X GET \ 18 | http://localhost:5000/todomedium/us-central1/v1/todo/OPTIONAL_TODO_ID 19 | ``` 20 | 21 | * PUT /todo 22 | 23 | Create a new todo with a label. 24 | 25 | ``` 26 | curl -X DELETE \ 27 | http://localhost:5000/todomedium/us-central1/v1/todo/TODO_ID 28 | ``` 29 | 30 | * DELETE /todo/id 31 | 32 | Delete todo with id 33 | 34 | ``` 35 | curl -X PUT \ 36 | http://localhost:5000/todomedium/us-central1/v1/todo \ 37 | -H 'Content-Type: application/x-www-form-urlencoded' \ 38 | -d 'label=New%20Todo!' 39 | ``` 40 | 41 | ## Database 42 | 43 | Firestore is used to store data, don't forget to enable it. 44 | 45 | ## Test it 46 | 47 | You can test project locally with the command (from functions folder) : 48 | 49 | `npm run serve` -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.2.30' 3 | 4 | repositories { 5 | mavenCentral() 6 | } 7 | dependencies { 8 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 9 | } 10 | } 11 | 12 | apply plugin: 'kotlin2js' 13 | 14 | repositories { 15 | mavenCentral() 16 | } 17 | 18 | dependencies { 19 | compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" 20 | testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version" 21 | } 22 | 23 | compileKotlin2Js.kotlinOptions { 24 | moduleKind = "commonjs" 25 | outputFile = "functions/index.js" 26 | sourceMap = true 27 | } -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /functions/index.js: -------------------------------------------------------------------------------- 1 | (function (_, Kotlin, $module$express, $module$firebase_admin, $module$firebase_functions) { 2 | 'use strict'; 3 | var $$importsForInline$$ = _.$$importsForInline$$ || (_.$$importsForInline$$ = {}); 4 | var Kind_CLASS = Kotlin.Kind.CLASS; 5 | var defineInlineFunction = Kotlin.defineInlineFunction; 6 | var equals = Kotlin.equals; 7 | var Unit = Kotlin.kotlin.Unit; 8 | var ensureNotNull = Kotlin.ensureNotNull; 9 | var throwCCE = Kotlin.throwCCE; 10 | function Config(type, project_id, private_key_id, private_key, client_id, client_email, auth_uri, token_uri, auth_provider_x509_cert_url, client_x509_cert_url) { 11 | this.type = type; 12 | this.project_id = project_id; 13 | this.private_key_id = private_key_id; 14 | this.private_key = private_key; 15 | this.client_id = client_id; 16 | this.client_email = client_email; 17 | this.auth_uri = auth_uri; 18 | this.token_uri = token_uri; 19 | this.auth_provider_x509_cert_url = auth_provider_x509_cert_url; 20 | this.client_x509_cert_url = client_x509_cert_url; 21 | } 22 | Config.$metadata$ = { 23 | kind: Kind_CLASS, 24 | simpleName: 'Config', 25 | interfaces: [] 26 | }; 27 | Config.prototype.component1 = function () { 28 | return this.type; 29 | }; 30 | Config.prototype.component2 = function () { 31 | return this.project_id; 32 | }; 33 | Config.prototype.component3 = function () { 34 | return this.private_key_id; 35 | }; 36 | Config.prototype.component4 = function () { 37 | return this.private_key; 38 | }; 39 | Config.prototype.component5 = function () { 40 | return this.client_id; 41 | }; 42 | Config.prototype.component6 = function () { 43 | return this.client_email; 44 | }; 45 | Config.prototype.component7 = function () { 46 | return this.auth_uri; 47 | }; 48 | Config.prototype.component8 = function () { 49 | return this.token_uri; 50 | }; 51 | Config.prototype.component9 = function () { 52 | return this.auth_provider_x509_cert_url; 53 | }; 54 | Config.prototype.component10 = function () { 55 | return this.client_x509_cert_url; 56 | }; 57 | Config.prototype.copy_cvx4o0$ = function (type, project_id, private_key_id, private_key, client_id, client_email, auth_uri, token_uri, auth_provider_x509_cert_url, client_x509_cert_url) { 58 | return new Config(type === void 0 ? this.type : type, project_id === void 0 ? this.project_id : project_id, private_key_id === void 0 ? this.private_key_id : private_key_id, private_key === void 0 ? this.private_key : private_key, client_id === void 0 ? this.client_id : client_id, client_email === void 0 ? this.client_email : client_email, auth_uri === void 0 ? this.auth_uri : auth_uri, token_uri === void 0 ? this.token_uri : token_uri, auth_provider_x509_cert_url === void 0 ? this.auth_provider_x509_cert_url : auth_provider_x509_cert_url, client_x509_cert_url === void 0 ? this.client_x509_cert_url : client_x509_cert_url); 59 | }; 60 | Config.prototype.toString = function () { 61 | return 'Config(type=' + Kotlin.toString(this.type) + (', project_id=' + Kotlin.toString(this.project_id)) + (', private_key_id=' + Kotlin.toString(this.private_key_id)) + (', private_key=' + Kotlin.toString(this.private_key)) + (', client_id=' + Kotlin.toString(this.client_id)) + (', client_email=' + Kotlin.toString(this.client_email)) + (', auth_uri=' + Kotlin.toString(this.auth_uri)) + (', token_uri=' + Kotlin.toString(this.token_uri)) + (', auth_provider_x509_cert_url=' + Kotlin.toString(this.auth_provider_x509_cert_url)) + (', client_x509_cert_url=' + Kotlin.toString(this.client_x509_cert_url)) + ')'; 62 | }; 63 | Config.prototype.hashCode = function () { 64 | var result = 0; 65 | result = result * 31 + Kotlin.hashCode(this.type) | 0; 66 | result = result * 31 + Kotlin.hashCode(this.project_id) | 0; 67 | result = result * 31 + Kotlin.hashCode(this.private_key_id) | 0; 68 | result = result * 31 + Kotlin.hashCode(this.private_key) | 0; 69 | result = result * 31 + Kotlin.hashCode(this.client_id) | 0; 70 | result = result * 31 + Kotlin.hashCode(this.client_email) | 0; 71 | result = result * 31 + Kotlin.hashCode(this.auth_uri) | 0; 72 | result = result * 31 + Kotlin.hashCode(this.token_uri) | 0; 73 | result = result * 31 + Kotlin.hashCode(this.auth_provider_x509_cert_url) | 0; 74 | result = result * 31 + Kotlin.hashCode(this.client_x509_cert_url) | 0; 75 | return result; 76 | }; 77 | Config.prototype.equals = function (other) { 78 | return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && (Kotlin.equals(this.type, other.type) && Kotlin.equals(this.project_id, other.project_id) && Kotlin.equals(this.private_key_id, other.private_key_id) && Kotlin.equals(this.private_key, other.private_key) && Kotlin.equals(this.client_id, other.client_id) && Kotlin.equals(this.client_email, other.client_email) && Kotlin.equals(this.auth_uri, other.auth_uri) && Kotlin.equals(this.token_uri, other.token_uri) && Kotlin.equals(this.auth_provider_x509_cert_url, other.auth_provider_x509_cert_url) && Kotlin.equals(this.client_x509_cert_url, other.client_x509_cert_url))))); 79 | }; 80 | function FirebaseAppOptions(credential, databaseAuthVariableOverride, databaseURL, storageBucket, projectId) { 81 | if (credential === void 0) 82 | credential = undefined; 83 | if (databaseAuthVariableOverride === void 0) 84 | databaseAuthVariableOverride = undefined; 85 | if (databaseURL === void 0) 86 | databaseURL = undefined; 87 | if (storageBucket === void 0) 88 | storageBucket = undefined; 89 | if (projectId === void 0) 90 | projectId = undefined; 91 | this.credential = credential; 92 | this.databaseAuthVariableOverride = databaseAuthVariableOverride; 93 | this.databaseURL = databaseURL; 94 | this.storageBucket = storageBucket; 95 | this.projectId = projectId; 96 | } 97 | FirebaseAppOptions.$metadata$ = { 98 | kind: Kind_CLASS, 99 | simpleName: 'FirebaseAppOptions', 100 | interfaces: [] 101 | }; 102 | FirebaseAppOptions.prototype.component1 = function () { 103 | return this.credential; 104 | }; 105 | FirebaseAppOptions.prototype.component2 = function () { 106 | return this.databaseAuthVariableOverride; 107 | }; 108 | FirebaseAppOptions.prototype.component3 = function () { 109 | return this.databaseURL; 110 | }; 111 | FirebaseAppOptions.prototype.component4 = function () { 112 | return this.storageBucket; 113 | }; 114 | FirebaseAppOptions.prototype.component5 = function () { 115 | return this.projectId; 116 | }; 117 | FirebaseAppOptions.prototype.copy_o0npqe$ = function (credential, databaseAuthVariableOverride, databaseURL, storageBucket, projectId) { 118 | return new FirebaseAppOptions(credential === void 0 ? this.credential : credential, databaseAuthVariableOverride === void 0 ? this.databaseAuthVariableOverride : databaseAuthVariableOverride, databaseURL === void 0 ? this.databaseURL : databaseURL, storageBucket === void 0 ? this.storageBucket : storageBucket, projectId === void 0 ? this.projectId : projectId); 119 | }; 120 | FirebaseAppOptions.prototype.toString = function () { 121 | return 'FirebaseAppOptions(credential=' + Kotlin.toString(this.credential) + (', databaseAuthVariableOverride=' + Kotlin.toString(this.databaseAuthVariableOverride)) + (', databaseURL=' + Kotlin.toString(this.databaseURL)) + (', storageBucket=' + Kotlin.toString(this.storageBucket)) + (', projectId=' + Kotlin.toString(this.projectId)) + ')'; 122 | }; 123 | FirebaseAppOptions.prototype.hashCode = function () { 124 | var result = 0; 125 | result = result * 31 + Kotlin.hashCode(this.credential) | 0; 126 | result = result * 31 + Kotlin.hashCode(this.databaseAuthVariableOverride) | 0; 127 | result = result * 31 + Kotlin.hashCode(this.databaseURL) | 0; 128 | result = result * 31 + Kotlin.hashCode(this.storageBucket) | 0; 129 | result = result * 31 + Kotlin.hashCode(this.projectId) | 0; 130 | return result; 131 | }; 132 | FirebaseAppOptions.prototype.equals = function (other) { 133 | return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && (Kotlin.equals(this.credential, other.credential) && Kotlin.equals(this.databaseAuthVariableOverride, other.databaseAuthVariableOverride) && Kotlin.equals(this.databaseURL, other.databaseURL) && Kotlin.equals(this.storageBucket, other.storageBucket) && Kotlin.equals(this.projectId, other.projectId))))); 134 | }; 135 | var get = defineInlineFunction('index.com.firebase.wrappers.admin.firestore.get_tt04a2$', function ($receiver, field) { 136 | return $receiver[field]; 137 | }); 138 | var set = defineInlineFunction('index.com.firebase.wrappers.admin.firestore.set_pywg9r$', function ($receiver, field, value) { 139 | $receiver[field] = value; 140 | }); 141 | function BucketFileOptions(generation) { 142 | if (generation === void 0) 143 | generation = undefined; 144 | this.generation = generation; 145 | } 146 | BucketFileOptions.$metadata$ = { 147 | kind: Kind_CLASS, 148 | simpleName: 'BucketFileOptions', 149 | interfaces: [] 150 | }; 151 | BucketFileOptions.prototype.component1 = function () { 152 | return this.generation; 153 | }; 154 | BucketFileOptions.prototype.copy_pdl1vj$ = function (generation) { 155 | return new BucketFileOptions(generation === void 0 ? this.generation : generation); 156 | }; 157 | BucketFileOptions.prototype.toString = function () { 158 | return 'BucketFileOptions(generation=' + Kotlin.toString(this.generation) + ')'; 159 | }; 160 | BucketFileOptions.prototype.hashCode = function () { 161 | var result = 0; 162 | result = result * 31 + Kotlin.hashCode(this.generation) | 0; 163 | return result; 164 | }; 165 | BucketFileOptions.prototype.equals = function (other) { 166 | return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.generation, other.generation)))); 167 | }; 168 | function WriteStreamOptions(gzip, metadata, offset, predefinedAct, private_0, public_0, resumable, uri, validation) { 169 | if (gzip === void 0) 170 | gzip = null; 171 | if (metadata === void 0) 172 | metadata = null; 173 | if (offset === void 0) 174 | offset = null; 175 | if (predefinedAct === void 0) 176 | predefinedAct = null; 177 | if (private_0 === void 0) 178 | private_0 = null; 179 | if (public_0 === void 0) 180 | public_0 = null; 181 | if (resumable === void 0) 182 | resumable = null; 183 | if (uri === void 0) 184 | uri = null; 185 | if (validation === void 0) 186 | validation = null; 187 | this.gzip = gzip; 188 | this.metadata = metadata; 189 | this.offset = offset; 190 | this.predefinedAct = predefinedAct; 191 | this.private = private_0; 192 | this.public = public_0; 193 | this.resumable = resumable; 194 | this.uri = uri; 195 | this.validation = validation; 196 | } 197 | WriteStreamOptions.$metadata$ = { 198 | kind: Kind_CLASS, 199 | simpleName: 'WriteStreamOptions', 200 | interfaces: [] 201 | }; 202 | WriteStreamOptions.prototype.component1 = function () { 203 | return this.gzip; 204 | }; 205 | WriteStreamOptions.prototype.component2 = function () { 206 | return this.metadata; 207 | }; 208 | WriteStreamOptions.prototype.component3 = function () { 209 | return this.offset; 210 | }; 211 | WriteStreamOptions.prototype.component4 = function () { 212 | return this.predefinedAct; 213 | }; 214 | WriteStreamOptions.prototype.component5 = function () { 215 | return this.private; 216 | }; 217 | WriteStreamOptions.prototype.component6 = function () { 218 | return this.public; 219 | }; 220 | WriteStreamOptions.prototype.component7 = function () { 221 | return this.resumable; 222 | }; 223 | WriteStreamOptions.prototype.component8 = function () { 224 | return this.uri; 225 | }; 226 | WriteStreamOptions.prototype.component9 = function () { 227 | return this.validation; 228 | }; 229 | WriteStreamOptions.prototype.copy_jiahnr$ = function (gzip, metadata, offset, predefinedAct, private_0, public_0, resumable, uri, validation) { 230 | return new WriteStreamOptions(gzip === void 0 ? this.gzip : gzip, metadata === void 0 ? this.metadata : metadata, offset === void 0 ? this.offset : offset, predefinedAct === void 0 ? this.predefinedAct : predefinedAct, private_0 === void 0 ? this.private : private_0, public_0 === void 0 ? this.public : public_0, resumable === void 0 ? this.resumable : resumable, uri === void 0 ? this.uri : uri, validation === void 0 ? this.validation : validation); 231 | }; 232 | WriteStreamOptions.prototype.toString = function () { 233 | return 'WriteStreamOptions(gzip=' + Kotlin.toString(this.gzip) + (', metadata=' + Kotlin.toString(this.metadata)) + (', offset=' + Kotlin.toString(this.offset)) + (', predefinedAct=' + Kotlin.toString(this.predefinedAct)) + (', private=' + Kotlin.toString(this.private)) + (', public=' + Kotlin.toString(this.public)) + (', resumable=' + Kotlin.toString(this.resumable)) + (', uri=' + Kotlin.toString(this.uri)) + (', validation=' + Kotlin.toString(this.validation)) + ')'; 234 | }; 235 | WriteStreamOptions.prototype.hashCode = function () { 236 | var result = 0; 237 | result = result * 31 + Kotlin.hashCode(this.gzip) | 0; 238 | result = result * 31 + Kotlin.hashCode(this.metadata) | 0; 239 | result = result * 31 + Kotlin.hashCode(this.offset) | 0; 240 | result = result * 31 + Kotlin.hashCode(this.predefinedAct) | 0; 241 | result = result * 31 + Kotlin.hashCode(this.private) | 0; 242 | result = result * 31 + Kotlin.hashCode(this.public) | 0; 243 | result = result * 31 + Kotlin.hashCode(this.resumable) | 0; 244 | result = result * 31 + Kotlin.hashCode(this.uri) | 0; 245 | result = result * 31 + Kotlin.hashCode(this.validation) | 0; 246 | return result; 247 | }; 248 | WriteStreamOptions.prototype.equals = function (other) { 249 | return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && (Kotlin.equals(this.gzip, other.gzip) && Kotlin.equals(this.metadata, other.metadata) && Kotlin.equals(this.offset, other.offset) && Kotlin.equals(this.predefinedAct, other.predefinedAct) && Kotlin.equals(this.private, other.private) && Kotlin.equals(this.public, other.public) && Kotlin.equals(this.resumable, other.resumable) && Kotlin.equals(this.uri, other.uri) && Kotlin.equals(this.validation, other.validation))))); 250 | }; 251 | function FileMetaData(contentType, metadata, cacheControl) { 252 | if (contentType === void 0) 253 | contentType = null; 254 | if (metadata === void 0) 255 | metadata = null; 256 | if (cacheControl === void 0) 257 | cacheControl = null; 258 | this.contentType = contentType; 259 | this.metadata = metadata; 260 | this.cacheControl = cacheControl; 261 | } 262 | FileMetaData.$metadata$ = { 263 | kind: Kind_CLASS, 264 | simpleName: 'FileMetaData', 265 | interfaces: [] 266 | }; 267 | FileMetaData.prototype.component1 = function () { 268 | return this.contentType; 269 | }; 270 | FileMetaData.prototype.component2 = function () { 271 | return this.metadata; 272 | }; 273 | FileMetaData.prototype.component3 = function () { 274 | return this.cacheControl; 275 | }; 276 | FileMetaData.prototype.copy_zhtotu$ = function (contentType, metadata, cacheControl) { 277 | return new FileMetaData(contentType === void 0 ? this.contentType : contentType, metadata === void 0 ? this.metadata : metadata, cacheControl === void 0 ? this.cacheControl : cacheControl); 278 | }; 279 | FileMetaData.prototype.toString = function () { 280 | return 'FileMetaData(contentType=' + Kotlin.toString(this.contentType) + (', metadata=' + Kotlin.toString(this.metadata)) + (', cacheControl=' + Kotlin.toString(this.cacheControl)) + ')'; 281 | }; 282 | FileMetaData.prototype.hashCode = function () { 283 | var result = 0; 284 | result = result * 31 + Kotlin.hashCode(this.contentType) | 0; 285 | result = result * 31 + Kotlin.hashCode(this.metadata) | 0; 286 | result = result * 31 + Kotlin.hashCode(this.cacheControl) | 0; 287 | return result; 288 | }; 289 | FileMetaData.prototype.equals = function (other) { 290 | return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && (Kotlin.equals(this.contentType, other.contentType) && Kotlin.equals(this.metadata, other.metadata) && Kotlin.equals(this.cacheControl, other.cacheControl))))); 291 | }; 292 | function main$lambda$lambda(closure$res) { 293 | return function (doc) { 294 | if (!doc.exists) { 295 | closure$res.status(404).json(new Message('Task not found!')); 296 | } 297 | else { 298 | var data = doc.data(); 299 | closure$res.status(200).json(new Task(doc.id, data.label, data.time)); 300 | } 301 | return Unit; 302 | }; 303 | } 304 | function main$lambda$lambda_0(closure$res) { 305 | return function (err) { 306 | closure$res.status(500).json(err); 307 | return Unit; 308 | }; 309 | } 310 | var ArrayList_init = Kotlin.kotlin.collections.ArrayList_init_ww73n8$; 311 | function main$lambda$lambda_1(closure$res) { 312 | return function (snapshot) { 313 | var $receiver = snapshot.docs; 314 | var destination = ArrayList_init($receiver.length); 315 | var tmp$; 316 | for (tmp$ = 0; tmp$ !== $receiver.length; ++tmp$) { 317 | var item = $receiver[tmp$]; 318 | var tmp$_0, tmp$_1; 319 | destination.add_11rb$(new Task(item.id, typeof (tmp$_0 = ensureNotNull(item.data())['label']) === 'string' ? tmp$_0 : throwCCE(), typeof (tmp$_1 = ensureNotNull(item.data())['time']) === 'number' ? tmp$_1 : throwCCE())); 320 | } 321 | var result = destination; 322 | closure$res.status(200).json(result); 323 | return Unit; 324 | }; 325 | } 326 | function main$lambda$lambda_2(closure$res) { 327 | return function (err) { 328 | closure$res.status(500).json(err); 329 | return Unit; 330 | }; 331 | } 332 | function main$lambda(closure$db) { 333 | return function (req, res) { 334 | var params = req.params; 335 | if (!equals(params.id, undefined)) { 336 | closure$db.collection('task').doc(params.id).get().then(main$lambda$lambda(res)).catch(main$lambda$lambda_0(res)); 337 | } 338 | else { 339 | closure$db.collection('task').get().then(main$lambda$lambda_1(res)).catch(main$lambda$lambda_2(res)); 340 | } 341 | return Unit; 342 | }; 343 | } 344 | function main$lambda$lambda_3(closure$res, closure$inputTask) { 345 | return function (ref) { 346 | closure$res.status(201).json(new Task(ref.id, closure$inputTask.label, closure$inputTask.time)); 347 | return Unit; 348 | }; 349 | } 350 | function main$lambda$lambda_4(closure$res) { 351 | return function (error) { 352 | closure$res.status(500).json(error); 353 | return Unit; 354 | }; 355 | } 356 | function main$lambda_0(closure$db) { 357 | return function (req, res) { 358 | var input = req.body; 359 | var inputTask = new Task(void 0, input.label, (new Date()).getTime()); 360 | closure$db.collection('task').add(JSON.parse(JSON.stringify(inputTask))).then(main$lambda$lambda_3(res, inputTask)).catch(main$lambda$lambda_4(res)); 361 | return Unit; 362 | }; 363 | } 364 | function main$lambda$lambda_5(closure$res) { 365 | return function (it) { 366 | closure$res.status(200).json(new Message('Task has been deleted')); 367 | return Unit; 368 | }; 369 | } 370 | function main$lambda_1(closure$db) { 371 | return function (req, res) { 372 | var params = req.params; 373 | closure$db.collection('task').doc(params.id).delete().then(main$lambda$lambda_5(res)); 374 | return Unit; 375 | }; 376 | } 377 | function main(args) { 378 | var app = new $module$express(); 379 | $module$firebase_admin.initializeApp($module$firebase_functions.config().firebase); 380 | var db = $module$firebase_admin.firestore(); 381 | app.get('/task/:id?', main$lambda(db)); 382 | app.put('/task', main$lambda_0(db)); 383 | app.delete('/task/:id', main$lambda_1(db)); 384 | exports.v1 = $module$firebase_functions.https.onRequest(app); 385 | } 386 | function TaskInput(label) { 387 | this.label = label; 388 | } 389 | TaskInput.$metadata$ = { 390 | kind: Kind_CLASS, 391 | simpleName: 'TaskInput', 392 | interfaces: [] 393 | }; 394 | TaskInput.prototype.component1 = function () { 395 | return this.label; 396 | }; 397 | TaskInput.prototype.copy_61zpoe$ = function (label) { 398 | return new TaskInput(label === void 0 ? this.label : label); 399 | }; 400 | TaskInput.prototype.toString = function () { 401 | return 'TaskInput(label=' + Kotlin.toString(this.label) + ')'; 402 | }; 403 | TaskInput.prototype.hashCode = function () { 404 | var result = 0; 405 | result = result * 31 + Kotlin.hashCode(this.label) | 0; 406 | return result; 407 | }; 408 | TaskInput.prototype.equals = function (other) { 409 | return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.label, other.label)))); 410 | }; 411 | function Task(id, label, time) { 412 | if (id === void 0) 413 | id = undefined; 414 | this.id = id; 415 | this.label = label; 416 | this.time = time; 417 | } 418 | Task.$metadata$ = { 419 | kind: Kind_CLASS, 420 | simpleName: 'Task', 421 | interfaces: [] 422 | }; 423 | Task.prototype.component1 = function () { 424 | return this.id; 425 | }; 426 | Task.prototype.component2 = function () { 427 | return this.label; 428 | }; 429 | Task.prototype.component3 = function () { 430 | return this.time; 431 | }; 432 | Task.prototype.copy_s10xjv$ = function (id, label, time) { 433 | return new Task(id === void 0 ? this.id : id, label === void 0 ? this.label : label, time === void 0 ? this.time : time); 434 | }; 435 | Task.prototype.toString = function () { 436 | return 'Task(id=' + Kotlin.toString(this.id) + (', label=' + Kotlin.toString(this.label)) + (', time=' + Kotlin.toString(this.time)) + ')'; 437 | }; 438 | Task.prototype.hashCode = function () { 439 | var result = 0; 440 | result = result * 31 + Kotlin.hashCode(this.id) | 0; 441 | result = result * 31 + Kotlin.hashCode(this.label) | 0; 442 | result = result * 31 + Kotlin.hashCode(this.time) | 0; 443 | return result; 444 | }; 445 | Task.prototype.equals = function (other) { 446 | return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && (Kotlin.equals(this.id, other.id) && Kotlin.equals(this.label, other.label) && Kotlin.equals(this.time, other.time))))); 447 | }; 448 | function Params(id) { 449 | if (id === void 0) 450 | id = undefined; 451 | this.id = id; 452 | } 453 | Params.$metadata$ = { 454 | kind: Kind_CLASS, 455 | simpleName: 'Params', 456 | interfaces: [] 457 | }; 458 | Params.prototype.component1 = function () { 459 | return this.id; 460 | }; 461 | Params.prototype.copy_pdl1vj$ = function (id) { 462 | return new Params(id === void 0 ? this.id : id); 463 | }; 464 | Params.prototype.toString = function () { 465 | return 'Params(id=' + Kotlin.toString(this.id) + ')'; 466 | }; 467 | Params.prototype.hashCode = function () { 468 | var result = 0; 469 | result = result * 31 + Kotlin.hashCode(this.id) | 0; 470 | return result; 471 | }; 472 | Params.prototype.equals = function (other) { 473 | return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.id, other.id)))); 474 | }; 475 | function Message(msg) { 476 | this.msg = msg; 477 | } 478 | Message.$metadata$ = { 479 | kind: Kind_CLASS, 480 | simpleName: 'Message', 481 | interfaces: [] 482 | }; 483 | Message.prototype.component1 = function () { 484 | return this.msg; 485 | }; 486 | Message.prototype.copy_61zpoe$ = function (msg) { 487 | return new Message(msg === void 0 ? this.msg : msg); 488 | }; 489 | Message.prototype.toString = function () { 490 | return 'Message(msg=' + Kotlin.toString(this.msg) + ')'; 491 | }; 492 | Message.prototype.hashCode = function () { 493 | var result = 0; 494 | result = result * 31 + Kotlin.hashCode(this.msg) | 0; 495 | return result; 496 | }; 497 | Message.prototype.equals = function (other) { 498 | return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.msg, other.msg)))); 499 | }; 500 | var package$com = _.com || (_.com = {}); 501 | var package$firebase = package$com.firebase || (package$com.firebase = {}); 502 | var package$wrappers = package$firebase.wrappers || (package$firebase.wrappers = {}); 503 | var package$admin = package$wrappers.admin || (package$wrappers.admin = {}); 504 | package$admin.Config = Config; 505 | package$admin.FirebaseAppOptions = FirebaseAppOptions; 506 | var package$firestore = package$admin.firestore || (package$admin.firestore = {}); 507 | package$firestore.get_tt04a2$ = get; 508 | package$firestore.set_pywg9r$ = set; 509 | var package$storage = package$admin.storage || (package$admin.storage = {}); 510 | package$storage.BucketFileOptions = BucketFileOptions; 511 | package$storage.WriteStreamOptions = WriteStreamOptions; 512 | package$storage.FileMetaData = FileMetaData; 513 | $$importsForInline$$.index = _; 514 | var package$todo = package$com.todo || (package$com.todo = {}); 515 | package$todo.main_kand9s$ = main; 516 | package$todo.TaskInput = TaskInput; 517 | package$todo.Task = Task; 518 | package$todo.Params = Params; 519 | package$todo.Message = Message; 520 | main([]); 521 | Kotlin.defineModule('index', _); 522 | return _; 523 | }(module.exports, require('kotlin'), require('express'), require('firebase-admin'), require('firebase-functions'))); 524 | 525 | //# sourceMappingURL=index.js.map 526 | -------------------------------------------------------------------------------- /functions/index.meta.js: -------------------------------------------------------------------------------- 1 | // Kotlin.kotlin_module_metadata(513, "index", "H4sIAAAAAAAAAM06y5IbR3KDV6NReEyh54UByeEQfIgciVqw+dTqsTsckiJnxceC1GN3tR71AD2D5gBoqLtBkdr1rq1dS/bFdvDgoE97c9gXX+xwMBzho1d/oHCErxt70c0RPtgnZ2ZlP4CZoUxJjnAgAplVlVWZlVWVmZVdU3rG+PwF8ZcFkWm7fVGwHw492/fv+yL/kWcNh7YniqvDYc9pW4HjDoS24wY9ZyAyq4NHIr/huaMASLSe27Z6vsj0raHIePaHIt+yPxzZfoAlX+gt2x+6A98WOhTdkde2hRb2vRt4zmCby0Dr20EAFb6Y7dhb1qgXrLmDLWd75CkJsm8PnEBoHbtnB7bIUS+hA/veptXeEYVro0EbCU1RvmN5Vh+ovFsARHaA//mO41ubPUCYj9C5piPyl123Z1swS3ugaBTsiMy2HYisQ5x7jh/YQNO1Bh2giRg2hb4WSpEduh7M/cYgEHrX9QPFGpt67ja0WkFX5IYonsitep4FulTDefF452P0jMhd9TzXE6Vb9sMgUmZ2ACWRe2D1RjayRHUPRyCiZw86MFTG9jyR7Qb9nsi7QxwIlgimLTLQRWRGfkL6s6K85ro7jn2bCbWO27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8KPVdYIrt0ohWGP2wrZHyAEmepGlmQ9GNd4338n2nxD6n993Fhi/eLH28df3wL5/BlM+z46wTCVPWzr4J7ZqiNKEOdYIqxgXodrzZq+ADauPNcicwMJTKxLDgtiSnMQpTCrIbpxYvj6cWKLEBQXOQ0iM6PoSh9CGurVyh9SF8tToTPIDSIqCUFaBXYP4nOtMEe61nS+39kxJe79B4FIbuDpTkKS3aFGPFK7Q4/JiKZ8aQIREDhZz2Rs/vD4FEcn2R952POYOS3XO8qBBKs/T3v7XlYaH/Ve/aaG5/874IGbNHoeGNLnlr0yFTotLAFwIv8fbHI5qIoKwwlQ4PhLMP50ECUQgNRwHVrkzmAUmn9ZToi0jTglKuP5jl2zVXKv83Bai7QapbIaU3LYvTNsazOGD6Fqyh0GvPO6pUZL3qdl6AebuL6xEeZ+h5H4H8A8hMBr3YyAAA="); 2 | -------------------------------------------------------------------------------- /functions/index/com/expressjs/wrapper/wrapper.kjsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-maillot/FirebaseFunctionToDo/a29dcc4c89857f69f6086be43acf394974d91c53/functions/index/com/expressjs/wrapper/wrapper.kjsm -------------------------------------------------------------------------------- /functions/index/com/firebase/wrapper/admin/firestore/firestore.kjsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-maillot/FirebaseFunctionToDo/a29dcc4c89857f69f6086be43acf394974d91c53/functions/index/com/firebase/wrapper/admin/firestore/firestore.kjsm -------------------------------------------------------------------------------- /functions/index/com/firebase/wrappers/admin/admin.kjsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-maillot/FirebaseFunctionToDo/a29dcc4c89857f69f6086be43acf394974d91c53/functions/index/com/firebase/wrappers/admin/admin.kjsm -------------------------------------------------------------------------------- /functions/index/com/firebase/wrappers/admin/database/database.kjsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-maillot/FirebaseFunctionToDo/a29dcc4c89857f69f6086be43acf394974d91c53/functions/index/com/firebase/wrappers/admin/database/database.kjsm -------------------------------------------------------------------------------- /functions/index/com/firebase/wrappers/admin/firestore/firestore.kjsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-maillot/FirebaseFunctionToDo/a29dcc4c89857f69f6086be43acf394974d91c53/functions/index/com/firebase/wrappers/admin/firestore/firestore.kjsm -------------------------------------------------------------------------------- /functions/index/com/firebase/wrappers/admin/storage/storage.kjsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-maillot/FirebaseFunctionToDo/a29dcc4c89857f69f6086be43acf394974d91c53/functions/index/com/firebase/wrappers/admin/storage/storage.kjsm -------------------------------------------------------------------------------- /functions/index/com/firebase/wrappers/functions/functions.kjsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-maillot/FirebaseFunctionToDo/a29dcc4c89857f69f6086be43acf394974d91c53/functions/index/com/firebase/wrappers/functions/functions.kjsm -------------------------------------------------------------------------------- /functions/index/com/todo/todo.kjsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-maillot/FirebaseFunctionToDo/a29dcc4c89857f69f6086be43acf394974d91c53/functions/index/com/todo/todo.kjsm -------------------------------------------------------------------------------- /functions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "functions", 3 | "description": "Cloud Functions for Firebase", 4 | "scripts": { 5 | "serve": "firebase serve --only functions", 6 | "shell": "firebase experimental:functions:shell", 7 | "start": "npm run shell", 8 | "deploy": "firebase deploy --only functions", 9 | "logs": "firebase functions:log" 10 | }, 11 | "dependencies": { 12 | "express": "^4.16.3", 13 | "firebase-admin": "~5.4.2", 14 | "firebase-functions": "^0.7.1", 15 | "kotlin": "^1.2.31" 16 | }, 17 | "private": true 18 | } 19 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-maillot/FirebaseFunctionToDo/a29dcc4c89857f69f6086be43acf394974d91c53/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /lib/kotlin-stdlib-js-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-maillot/FirebaseFunctionToDo/a29dcc4c89857f69f6086be43acf394974d91c53/lib/kotlin-stdlib-js-sources.jar -------------------------------------------------------------------------------- /lib/kotlin-stdlib-js.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-maillot/FirebaseFunctionToDo/a29dcc4c89857f69f6086be43acf394974d91c53/lib/kotlin-stdlib-js.jar -------------------------------------------------------------------------------- /src/main/kotlin/com/expressjs/wrapper/Application.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.expressjs.wrapper 4 | 5 | open external class Application { 6 | 7 | /** 8 | * Express instance itself is a request handler, which could be invoked without 9 | * third argument. 10 | */ 11 | val req: Request 12 | val res: Response 13 | 14 | /** 15 | * Initialize the server. 16 | * 17 | * - setup default configuration 18 | * - setup default middleware 19 | * - setup route reflection methods 20 | */ 21 | fun init() 22 | 23 | /** 24 | * Initialize application configuration. 25 | */ 26 | fun defaultConfiguration() 27 | 28 | /** 29 | * Register the given template engine callback `fn` 30 | * as `ext`. 31 | * 32 | * By default will `require()` the engine based on the 33 | * file extension. For example if you try to render 34 | * a "foo.jade" file Express will invoke the following internally: 35 | * 36 | * app.engine('jade', require('jade').__express); 37 | * 38 | * For engines that do not provide `.__express` out of the box, 39 | * or if you wish to "map" a different extension to the template engine 40 | * you may use this method. For example mapping the EJS template engine to 41 | * ".html" files: 42 | * 43 | * app.engine('html', require('ejs').renderFile); 44 | * 45 | * In this case EJS provides a `.renderFile()` method with 46 | * the same signature that Express expects: `(path, options, callback)`, 47 | * though note that it aliases this method as `ejs.__express` internally 48 | * so if you're using ".ejs" extensions you dont need to do anything. 49 | * 50 | * Some template engines do not follow this convention, the 51 | * [Consolidate.js](https://github.com/visionmedia/consolidate.js) 52 | * library was created to map all of node's popular template 53 | * engines to follow this convention, thus allowing them to 54 | * work seamlessly within Express. 55 | */ 56 | // TODO fun engine(ext: String, fn: Function): Application 57 | 58 | /** 59 | * Assign `setting` to `val`, or return `setting`'s value. 60 | * 61 | * app.set('foo', 'bar'); 62 | * app.get('foo'); 63 | * // => "bar" 64 | * app.set('foo', ['bar', 'baz']); 65 | * app.get('foo'); 66 | * // => ["bar", "baz"] 67 | * 68 | * Mounted servers inherit their parent server's settings. 69 | */ 70 | fun set(setting: String, `val`: Any): Application 71 | 72 | fun get(setting: String): String 73 | 74 | fun get(route: String, callback: (req: Request, res: Response) -> Unit) 75 | fun post(route: String, callback: (req: Request, res: Response) -> Unit) 76 | fun put(route: String, callback: (req: Request, res: Response) -> Unit) 77 | fun delete(route: String, callback: (req: Request, res: Response) -> Unit) 78 | 79 | fun param(name: String, handler: (req: Request, res: Response, next: NextResponse, value: Any, name: String) -> Any): Application 80 | fun param(name: Array, handler: (req: Request, res: Response, next: NextResponse, value: Any, name: String) -> Any): Application 81 | 82 | /** 83 | * Return the app's absolute pathname 84 | * based on the parent(s) that have 85 | * mounted it. 86 | * 87 | * For example if the application was 88 | * mounted as "/admin", which itself 89 | * was mounted as "/blog" then the 90 | * return value would be "/blog/admin". 91 | */ 92 | fun path(): String 93 | 94 | /** 95 | * Check if `setting` is enabled (truthy). 96 | * 97 | * app.enabled('foo') 98 | * // => false 99 | * 100 | * app.enable('foo') 101 | * app.enabled('foo') 102 | * // => true 103 | */ 104 | fun enabled(setting: String): Boolean 105 | 106 | /** 107 | * Check if `setting` is disabled. 108 | * 109 | * app.disabled('foo') 110 | * // => true 111 | * 112 | * app.enable('foo') 113 | * app.disabled('foo') 114 | * // => false 115 | */ 116 | fun disabled(setting: String): Boolean 117 | 118 | /** Enable `setting`. */ 119 | fun enable(setting: String): Application 120 | 121 | /** Disable `setting`. */ 122 | fun disable(setting: String): Application 123 | 124 | /** 125 | * Render the given view `name` name with `options` 126 | * and a callback accepting an error and the 127 | * rendered template string. 128 | * 129 | * Example: 130 | * 131 | * app.render('email', { name: 'Tobi' }, function(err, html){ 132 | * // ... 133 | * }) 134 | */ 135 | fun render(name: String, options: Any?, callback: ((err: Error, html: String) -> Unit)?) 136 | 137 | fun render(name: String, callback: (err: Error, html: String) -> Unit) 138 | 139 | /** 140 | * Listen for connections. 141 | * 142 | * A node `http.Server` is returned, with this 143 | * application (which is a `Function`) as its 144 | * callback. If you wish to create both an HTTP 145 | * and HTTPS server you may do so with the "http" 146 | * and "https" modules as shown here: 147 | * 148 | * var http = require('http') 149 | * , https = require('https') 150 | * , express = require('express') 151 | * , app = express(); 152 | * 153 | * http.createServer(app).listen(80); 154 | * https.createServer({ ... }, app).listen(443); 155 | */ 156 | fun listen(port: Int, hostname: String, backlog: Int, callback: Callback?) //TODO http.Server; 157 | 158 | fun listen(port: Int, hostname: String, callback: Callback?) // TODO http.Server; 159 | fun listen(port: Int, callback: Callback?) // TODO http.Server; 160 | fun listen(path: String, callback: Callback?) // TODO http.Server; 161 | fun listen(handle: Any, callback: Callback?) // TODO http.Server; 162 | 163 | val router: String 164 | 165 | val settings: Any 166 | 167 | val resource: Any 168 | 169 | val map: Any 170 | 171 | val locals: Any 172 | 173 | /** 174 | * The app.routes object houses all of the routes defined mapped by the 175 | * associated HTTP verb. This object may be used for introspection 176 | * capabilities, for example Express uses this internally not only for 177 | * routing but to provide default OPTIONS behaviour unless app.options() 178 | * is used. Your application or framework may also remove routes by 179 | * simply by removing them from this object. 180 | */ 181 | val routes: Any 182 | 183 | /** 184 | * Used to get all registered routes in Express Application 185 | */ 186 | val _router: Any 187 | 188 | fun use(router: (req: Request, res: Response, next: NextResponse) -> Unit) // TODO : ApplicationRequestHandler; 189 | fun use(router: Array<(req: Request, res: Response, next: NextResponse) -> Unit>) // TODO : ApplicationRequestHandler; 190 | // fun use(path: String = definedExternally, router: Array<(req: Request, res: Response, next: (Error?) -> Unit) -> Unit>) // TODO : ApplicationRequestHandler; 191 | // fun use(path: String = definedExternally, router: Array<(req: Request, res: Response, next: (Error?) -> Unit) -> Unit>) // TODO : ApplicationRequestHandler; 192 | } 193 | 194 | typealias Callback = () -> Unit 195 | typealias NextResponse = (Error?) -> Unit -------------------------------------------------------------------------------- /src/main/kotlin/com/expressjs/wrapper/CookieOptions.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.expressjs.wrapper 4 | 5 | import kotlin.js.Date 6 | 7 | external interface CookieOptions { 8 | val maxAge: Int? 9 | val signed: Boolean? 10 | val expires: Date? 11 | val httpOnly: Boolean? 12 | val path: String? 13 | val domain: String? 14 | val secure: Boolean? // | 'auto'; 15 | val encode: (`val`: String) -> Unit 16 | val sameSite: Boolean // | string; 17 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/expressjs/wrapper/Express.kt: -------------------------------------------------------------------------------- 1 | package com.expressjs.wrapper 2 | 3 | @JsModule("express") 4 | external class Express: Application -------------------------------------------------------------------------------- /src/main/kotlin/com/expressjs/wrapper/Request.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.expressjs.wrapper 4 | 5 | external interface Request { 6 | /** 7 | * Return request header. 8 | * 9 | * The `Referrer` header field is special-cased, 10 | * both `Referrer` and `Referer` are interchangeable. 11 | * 12 | * Examples: 13 | * 14 | * req.get('Content-Type'); 15 | * // => "text/plain" 16 | * 17 | * req.get('content-type'); 18 | * // => "text/plain" 19 | * 20 | * req.get('Something'); 21 | * // => undefined 22 | * 23 | * Aliased as `req.header()`. 24 | */ 25 | fun get(name: String): Array? 26 | fun header(name: String): Array? 27 | 28 | /** 29 | * Check if the given `type(s)` is acceptable, returning 30 | * the best match when true, otherwise `undefined`, in which 31 | * case you should respond with 406 "Not Acceptable". 32 | * 33 | * The `type` value may be a single mime type string 34 | * such as "application/json", the extension name 35 | * such as "json", a comma-delimted list such as "json, html, text/plain", 36 | * or an array `["json", "html", "text/plain"]`. When a list 37 | * or array is given the _best_ match, if any is returned. 38 | * 39 | * Examples: 40 | * 41 | * // Accept: text/html 42 | * req.accepts('html'); 43 | * // => "html" 44 | * 45 | * // Accept: text/*, application/json 46 | * req.accepts('html'); 47 | * // => "html" 48 | * req.accepts('text/html'); 49 | * // => "text/html" 50 | * req.accepts('json, text'); 51 | * // => "json" 52 | * req.accepts('application/json'); 53 | * // => "application/json" 54 | * 55 | * // Accept: text/*, application/json 56 | * req.accepts('image/png'); 57 | * req.accepts('png'); 58 | * // => undefined 59 | * 60 | * // Accept: text/*;q=.5, application/json 61 | * req.accepts(['html', 'json']); 62 | * req.accepts('html, json'); 63 | * // => "json" 64 | * */*/*/*/ 65 | fun accepts(): Array 66 | fun accepts(type: String): String? 67 | fun accepts(type: Array): String? 68 | fun accepts(vararg type: Array): String? 69 | 70 | /** 71 | * Returns the first accepted charset of the specified character sets, 72 | * based on the request's Accept-Charset HTTP header field. 73 | * If none of the specified charsets is accepted, returns false. 74 | * 75 | * For more information, or if you have issues or concerns, see accepts. 76 | */ 77 | fun acceptsCharsets(): Array 78 | fun acceptsCharsets(charset: String): String 79 | fun acceptsCharsets(charset: Array): String 80 | fun acceptsCharsets(vararg charset: Array): String 81 | 82 | /** 83 | * Returns the first accepted encoding of the specified encodings, 84 | * based on the request's Accept-Encoding HTTP header field. 85 | * If none of the specified encodings is accepted, returns false. 86 | * 87 | * For more information, or if you have issues or concerns, see accepts. 88 | */ 89 | fun acceptsEncodings(): Array 90 | fun acceptsEncodings(encoding: String): String 91 | fun acceptsEncodings(encoding: Array): String 92 | fun acceptsEncodings(vararg encoding: Array): String 93 | 94 | /** 95 | * Returns the first accepted language of the specified languages, 96 | * based on the request's Accept-Language HTTP header field. 97 | * If none of the specified languages is accepted, returns false. 98 | * 99 | * For more information, or if you have issues or concerns, see accepts. 100 | */ 101 | fun acceptsLanguages(): Array; 102 | fun acceptsLanguages(lang: String): String 103 | fun acceptsLanguages(lang: Array): String 104 | fun acceptsLanguages(vararg lang: Array): String 105 | 106 | /** 107 | * Parse Range header field, 108 | * capping to the given `size`. 109 | * 110 | * Unspecified ranges such as "0-" require 111 | * knowledge of your resource length. In 112 | * the case of a byte range this is of course 113 | * the total number of bytes. If the Range 114 | * header field is not given `null` is returned, 115 | * `-1` when unsatisfiable, `-2` when syntactically invalid. 116 | * 117 | * NOTE: remember that ranges are inclusive, so 118 | * for example "Range: users=0-3" should respond 119 | * with 4 users when available, not 3. 120 | */ 121 | // TODO fun range(size: number): RequestRanges|null|-1|-2; 122 | 123 | /** 124 | * Return an array of Accepted media types 125 | * ordered from highest quality to lowest. 126 | */ 127 | // TODO fun accepted: MediaType[]; 128 | 129 | /** 130 | * @deprecated since 4.11 Use either req.params, req.body or req.query, as applicable. 131 | * 132 | * Return the value of param `name` when present or `defaultValue`. 133 | * 134 | * - Checks route placeholders, ex: _/user/:id_ 135 | * - Checks body params, ex: id=12, {"id":12} 136 | * - Checks query string params, ex: ?id=12 137 | * 138 | * To utilize request bodies, `req.body` 139 | * should be an object. This can be done by using 140 | * the `connect.bodyParser()` middleware. 141 | */ 142 | fun param(name: String, defaultValue: dynamic): String 143 | 144 | /** 145 | * Check if the incoming request contains the "Content-Type" 146 | * header field, and it contains the give mime `type`. 147 | * 148 | * Examples: 149 | * 150 | * // With Content-Type: text/html; charset=utf-8 151 | * req.is('html'); 152 | * req.is('text/html'); 153 | * req.is('text/*'); 154 | * // => true 155 | * 156 | * // When Content-Type is application/json 157 | * req.is('json'); 158 | * req.is('application/json'); 159 | * req.is('application/*'); 160 | * // => true 161 | * 162 | * req.is('html'); 163 | * // => false 164 | */*/*/ 165 | fun `is`(type: String): String 166 | 167 | /** 168 | * Return the protocol string "http" or "https" 169 | * when requested with TLS. When the "trust proxy" 170 | * setting is enabled the "X-Forwarded-Proto" header 171 | * field will be trusted. If you're running behind 172 | * a reverse proxy that supplies https for you this 173 | * may be enabled. 174 | */ 175 | val protocol: String 176 | 177 | /** 178 | * Short-hand for: 179 | * 180 | * req.protocol == 'https' 181 | */ 182 | val secure: Boolean 183 | 184 | /** 185 | * Return the remote address, or when 186 | * "trust proxy" is `true` return 187 | * the upstream addr. 188 | */ 189 | val ip: String 190 | 191 | /** 192 | * When "trust proxy" is `true`, parse 193 | * the "X-Forwarded-For" ip address list. 194 | * 195 | * For example if the value were "client, proxy1, proxy2" 196 | * you would receive the array `["client", "proxy1", "proxy2"]` 197 | * where "proxy2" is the furthest down-stream. 198 | */ 199 | val ips: Array 200 | 201 | /** 202 | * Return subdomains as an array. 203 | * 204 | * Subdomains are the dot-separated parts of the host before the main domain of 205 | * the app. By default, the domain of the app is assumed to be the last two 206 | * parts of the host. This can be changed by setting "subdomain offset". 207 | * 208 | * For example, if the domain is "tobi.ferrets.example.com": 209 | * If "subdomain offset" is not set, req.subdomains is `["ferrets", "tobi"]`. 210 | * If "subdomain offset" is 3, req.subdomains is `["tobi"]`. 211 | */ 212 | val subdomains: Array 213 | 214 | /** 215 | * Short-hand for `url.parse(req.url).pathname`. 216 | */ 217 | val path: String 218 | 219 | /** 220 | * Parse the "Host" header field hostname. 221 | */ 222 | val hostname: String 223 | 224 | /** 225 | * @deprecated Use hostname instead. 226 | */ 227 | val host: String 228 | 229 | /** 230 | * Check if the request is fresh, aka 231 | * Last-Modified and/or the ETag 232 | * still match. 233 | */ 234 | val fresh: Boolean 235 | 236 | /** 237 | * Check if the request is stale, aka 238 | * "Last-Modified" and / or the "ETag" for the 239 | * resource has changed. 240 | */ 241 | val stale: Boolean 242 | 243 | /** 244 | * Check if the request was an _XMLHttpRequest_. 245 | */ 246 | val xhr: Boolean 247 | 248 | //body: { username: string; password: string; remember: boolean; title: string; }; 249 | val body: Any 250 | 251 | //cookies: { string; remember: boolean; }; 252 | val cookies: Any 253 | 254 | val method: String 255 | 256 | val params: Any 257 | 258 | /** Clear cookie `name`. */ 259 | fun clearCookie(name: String, options: dynamic): Response 260 | 261 | val query: Any 262 | 263 | val route: Any 264 | 265 | val signedCookies: Any 266 | 267 | val originalUrl: String 268 | 269 | val url: String 270 | 271 | val baseUrl: String 272 | 273 | // TODO val app: Application; 274 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/expressjs/wrapper/Response.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.expressjs.wrapper 4 | 5 | external interface Response { 6 | 7 | /** 8 | * Set status `code`. 9 | */ 10 | fun status(code: Int): Response 11 | 12 | /** 13 | * Set the response HTTP status code to `statusCode` and send its string representation as the response body. 14 | * @link http://expressjs.com/4x/api.html#res.sendStatus 15 | * 16 | * Examples: 17 | * 18 | * res.sendStatus(200); // equivalent to res.status(200).send('OK') 19 | * res.sendStatus(403); // equivalent to res.status(403).send('Forbidden') 20 | * res.sendStatus(404); // equivalent to res.status(404).send('Not Found') 21 | * res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error') 22 | */ 23 | fun sendStatus(code: Int): Response 24 | 25 | /** 26 | * Set Link header field with the given `links`. 27 | * 28 | * Examples: 29 | * 30 | * res.links({ 31 | * next: 'http://api.example.com/users?page=2', 32 | * last: 'http://api.example.com/users?page=5' 33 | * }); 34 | */ 35 | fun links(links: Any): Response 36 | 37 | /** 38 | * Send a response. 39 | * 40 | * Examples: 41 | * 42 | * res.send(new Buffer('wahoo')); 43 | * res.send({ some: 'json' }); 44 | * res.send('

some html

'); 45 | * res.send(404, 'Sorry, cant find that'); 46 | * res.send(404); 47 | */ 48 | fun send(data: String) 49 | fun send(code: Int, data: String) 50 | 51 | /** 52 | * Send JSON response. 53 | * 54 | * Examples: 55 | * 56 | * res.json(null); 57 | * res.json({ user: 'tj' }); 58 | * res.json(500, 'oh noes!'); 59 | * res.json(404, 'I dont have that'); 60 | */ 61 | fun json(data: Any) 62 | fun json(code: Int, data: Any) 63 | 64 | /** 65 | * Send JSON response with JSONP callback support. 66 | * 67 | * Examples: 68 | * 69 | * res.jsonp(null); 70 | * res.jsonp({ user: 'tj' }); 71 | * res.jsonp(500, 'oh noes!'); 72 | * res.jsonp(404, 'I dont have that'); 73 | */ 74 | fun jsonp(data: Any) 75 | fun jsonp(code: Int, data: Any) 76 | 77 | /** 78 | * Transfer the file at the given `path`. 79 | * 80 | * Automatically sets the _Content-Type_ response header field. 81 | * The callback `fn(err)` is invoked when the transfer is complete 82 | * or when an error occurs. Be sure to check `res.sentHeader` 83 | * if you wish to attempt responding, as the header and some data 84 | * may have already been transferred. 85 | * 86 | * Options: 87 | * 88 | * - `maxAge` defaulting to 0 (can be string converted by `ms`) 89 | * - `root` root directory for relative filenames 90 | * - `headers` object of headers to serve with file 91 | * - `dotfiles` serve dotfiles, defaulting to false; can be `"allow"` to send them 92 | * 93 | * Other options are passed along to `send`. 94 | * 95 | * Examples: 96 | * 97 | * The following example illustrates how `res.sendFile()` may 98 | * be used as an alternative for the `static()` middleware for 99 | * dynamic situations. The code backing `res.sendFile()` is actually 100 | * the same code, so HTTP cache support etc is identical. 101 | * 102 | * app.get('/user/:uid/photos/:file', function(req, res){ 103 | * var uid = req.params.uid 104 | * , file = req.params.file; 105 | * 106 | * req.user.mayViewFilesFrom(uid, function(yes){ 107 | * if (yes) { 108 | * res.sendFile('/uploads/' + uid + '/' + file); 109 | * } else { 110 | * res.send(403, 'Sorry! you cant see that.'); 111 | * } 112 | * }); 113 | * }); 114 | * 115 | * @api public 116 | */ 117 | fun sendFile(path: String) 118 | fun sendFile(path: String, options: Any) 119 | fun sendFile(path: String, fn: (Error) -> Unit) 120 | fun sendFile(path: String, options: Any, fn: (Error) -> Unit) 121 | 122 | 123 | /** 124 | * Transfer the file at the given `path` as an attachment. 125 | * 126 | * Optionally providing an alternate attachment `filename`, 127 | * and optional callback `fn(err)`. The callback is invoked 128 | * when the data transfer is complete, or when an error has 129 | * ocurred. Be sure to check `res.headerSent` if you plan to respond. 130 | * 131 | * This method uses `res.sendfile()`. 132 | */ 133 | fun download(path: String) 134 | fun download(path: String, filename: String) 135 | fun download(path: String, fn: (Error) -> Unit) 136 | fun download(path: String, filename: String, fn: (Error) -> Unit) 137 | 138 | /** 139 | * Set _Content-Type_ response header with `type` through `mime.lookup()` 140 | * when it does not contain "/", or set the Content-Type to `type` otherwise. 141 | * 142 | * Examples: 143 | * 144 | * res.type('.html'); 145 | * res.type('html'); 146 | * res.type('json'); 147 | * res.type('application/json'); 148 | * res.type('png'); 149 | */ 150 | fun contentType(type: String): Response 151 | 152 | /** 153 | * Set _Content-Type_ response header with `type` through `mime.lookup()` 154 | * when it does not contain "/", or set the Content-Type to `type` otherwise. 155 | * 156 | * Examples: 157 | * 158 | * res.type('.html'); 159 | * res.type('html'); 160 | * res.type('json'); 161 | * res.type('application/json'); 162 | * res.type('png'); 163 | */ 164 | fun type(type: String): Response 165 | 166 | /** 167 | * Respond to the Acceptable formats using an `obj` 168 | * of mime-type callbacks. 169 | * 170 | * This method uses `req.accepted`, an array of 171 | * acceptable types ordered by their quality values. 172 | * When "Accept" is not present the _first_ callback 173 | * is invoked, otherwise the first match is used. When 174 | * no match is performed the server responds with 175 | * 406 "Not Acceptable". 176 | * 177 | * Content-Type is set for you, however if you choose 178 | * you may alter this within the callback using `res.type()` 179 | * or `res.set('Content-Type', ...)`. 180 | * 181 | * res.format({ 182 | * 'text/plain': function(){ 183 | * res.send('hey'); 184 | * }, 185 | * 186 | * 'text/html': function(){ 187 | * res.send('

hey

'); 188 | * }, 189 | * 190 | * 'appliation/json': function(){ 191 | * res.send({ message: 'hey' }); 192 | * } 193 | * }); 194 | * 195 | * In addition to canonicalized MIME types you may 196 | * also use extnames mapped to these types: 197 | * 198 | * res.format({ 199 | * text: function(){ 200 | * res.send('hey'); 201 | * }, 202 | * 203 | * html: function(){ 204 | * res.send('

hey

'); 205 | * }, 206 | * 207 | * json: function(){ 208 | * res.send({ message: 'hey' }); 209 | * } 210 | * }); 211 | * 212 | * By default Express passes an `Error` 213 | * with a `.status` of 406 to `next(err)` 214 | * if a match is not made. If you provide 215 | * a `.default` callback it will be invoked 216 | * instead. 217 | */ 218 | fun format(obj: Any): Response 219 | 220 | /** 221 | * Set _Content-Disposition_ header to _attachment_ with optional `filename`. 222 | */ 223 | fun attachment(filename: String?): Response 224 | 225 | /** 226 | * Set header `field` to `val`, or pass 227 | * an object of header fields. 228 | * 229 | * Examples: 230 | * 231 | * res.set('Foo', ['bar', 'baz']); 232 | * res.set('Accept', 'application/json'); 233 | * res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' }); 234 | * 235 | * Aliased as `res.header()`. 236 | */ 237 | fun set(field: Any): Response 238 | fun set(field: String, value: String?): Response 239 | 240 | fun header(field: Any): Response 241 | fun header(field: String, value: String?): Response 242 | 243 | // Property indicating if HTTP headers has been sent for the response. 244 | val headersSent: Boolean 245 | 246 | /** Get value for header `field`. */ 247 | fun get(field: String): String 248 | 249 | /** Clear cookie `name`. */ 250 | fun clearCookie(name: String, options: Any?): Response 251 | 252 | /** 253 | * Set cookie `name` to `val`, with the given `options`. 254 | * 255 | * Options: 256 | * 257 | * - `maxAge` max-age in milliseconds, converted to `expires` 258 | * - `signed` sign the cookie 259 | * - `path` defaults to "/" 260 | * 261 | * Examples: 262 | * 263 | * // "Remember Me" for 15 minutes 264 | * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true }); 265 | * 266 | * // save as above 267 | * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true }) 268 | */ 269 | fun cookie(name: String, `val`: String, options: CookieOptions): Response 270 | fun cookie(name: String, `val`: Any, options: CookieOptions): Response 271 | fun cookie(name: String, `val`: Any): Response 272 | 273 | /** 274 | * Set the location header to `url`. 275 | * 276 | * The given `url` can also be the name of a mapped url, for 277 | * example by default express supports "back" which redirects 278 | * to the _Referrer_ or _Referer_ headers or "/". 279 | * 280 | * Examples: 281 | * 282 | * res.location('/foo/bar').; 283 | * res.location('http://example.com'); 284 | * res.location('../login'); // /blog/post/1 -> /blog/login 285 | * 286 | * Mounting: 287 | * 288 | * When an application is mounted and `res.location()` 289 | * is given a path that does _not_ lead with "/" it becomes 290 | * relative to the mount-point. For example if the application 291 | * is mounted at "/blog", the following would become "/blog/login". 292 | * 293 | * res.location('login'); 294 | * 295 | * While the leading slash would result in a location of "/login": 296 | * 297 | * res.location('/login'); 298 | */ 299 | fun location(url: String): Response 300 | 301 | /** 302 | * Redirect to the given `url` with optional response `status` 303 | * defaulting to 302. 304 | * 305 | * The resulting `url` is determined by `res.location()`, so 306 | * it will play nicely with mounted apps, relative paths, 307 | * `"back"` etc. 308 | * 309 | * Examples: 310 | * 311 | * res.redirect('/foo/bar'); 312 | * res.redirect('http://example.com'); 313 | * res.redirect(301, 'http://example.com'); 314 | * res.redirect('http://example.com', 301); 315 | * res.redirect('../login'); // /blog/post/1 -> /blog/login 316 | */ 317 | fun redirect(url: String) 318 | fun redirect(status: Int, url: String) 319 | fun redirect(url: String, status: Int) 320 | 321 | /** 322 | * Render `view` with the given `options` and optional callback `fn`. 323 | * When a callback function is given a response will _not_ be made 324 | * automatically, otherwise a response of _200_ and _text/html_ is given. 325 | * 326 | * Options: 327 | * 328 | * - `cache` boolean hinting to the engine it should cache 329 | * - `filename` filename of the view being rendered 330 | */ 331 | fun render(view: String, options: Any?, callback: (err: Error, html: String) -> Unit) 332 | fun render(view: String, callback: (err: Error, html: String) -> Unit) 333 | 334 | val locals: Any 335 | 336 | val charset: String 337 | 338 | /** 339 | * Adds the field to the Vary response header, if it is not there already. 340 | * Examples: 341 | * 342 | * res.vary('User-Agent').render('docs'); 343 | * 344 | */ 345 | fun vary(field: String): Response 346 | 347 | val app: Application 348 | 349 | /** 350 | * Appends the specified value to the HTTP response header field. 351 | * If the header is not already set, it creates the header with the specified value. 352 | * The value parameter can be a string or an array. 353 | * 354 | * Note: calling res.set() after res.append() will reset the previously-set header value. 355 | * 356 | * @since 4.11.0 357 | */ 358 | fun append(field: String, value: Array?): Response 359 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/Admin.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin 2 | 3 | import com.firebase.wrappers.admin.database.Database 4 | import com.firebase.wrappers.admin.firestore.Firestore 5 | import com.firebase.wrappers.admin.storage.Storage 6 | 7 | @JsModule("firebase-admin") 8 | external object Admin { 9 | val credential: dynamic 10 | 11 | fun initializeApp(config: FirebaseAppOptions) 12 | fun database(): Database 13 | fun firestore(): Firestore 14 | fun storage(): Storage 15 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/CloudFunction.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin 2 | 3 | external interface CloudFunction -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/Config.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin 2 | 3 | data class Config( 4 | val type: String, 5 | val project_id: String, 6 | val private_key_id: String, 7 | val private_key: String, 8 | val client_id: String, 9 | val client_email: String, 10 | val auth_uri: String, 11 | val token_uri: String, 12 | val auth_provider_x509_cert_url: String, 13 | val client_x509_cert_url: String 14 | ) -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/Event.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin 2 | 3 | import com.firebase.wrappers.admin.database.DeltaSnapshot 4 | 5 | external interface Event { 6 | val data: DeltaSnapshot 7 | val params: dynamic 8 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/FirebaseAppOptions.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin 2 | 3 | data class FirebaseAppOptions( 4 | val credential: dynamic = undefined, 5 | val databaseAuthVariableOverride: Any? = undefined, 6 | val databaseURL: String? = undefined, 7 | val storageBucket: String? = undefined, 8 | val projectId: String? = undefined 9 | ) -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/FirebaseError.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin 2 | 3 | external interface FirebaseError { 4 | val code: String 5 | val message: String 6 | val name: String 7 | val stack: String? 8 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/database/Database.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.database 2 | 3 | external interface Database { 4 | fun ref(path: String): Reference 5 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/database/DeltaSnapshot.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.database 2 | 3 | external interface DeltaSnapshot { 4 | fun `val`(): T 5 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/database/Reference.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.database 2 | 3 | import com.firebase.wrappers.admin.CloudFunction 4 | import com.firebase.wrappers.admin.Event 5 | import com.firebase.wrappers.admin.FirebaseError 6 | import kotlin.js.Promise 7 | 8 | 9 | external interface Reference { 10 | val ref: Reference 11 | val key: String? 12 | val parent: Reference 13 | val root: Reference 14 | 15 | fun child(path: String): Reference 16 | fun push(value: Any?, onComplete: ((FirebaseError) -> Unit)? = definedExternally) : Promise 17 | fun set(value: Any): Promise 18 | 19 | fun onWrite(handler: (Event) -> Unit) : CloudFunction 20 | fun once(type: String): Promise> 21 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/firestore/CollectionReference.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.firestore 2 | 3 | import com.firebase.wrapper.admin.firestore.QuerySnapshot 4 | import kotlin.js.Promise 5 | 6 | external interface CollectionReference { 7 | val id: String 8 | val parent: DocumentReference? 9 | val path: String 10 | 11 | fun get(): Promise 12 | fun doc(documentPath: String?): DocumentReference 13 | fun add(data: DocumentData): Promise 14 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/firestore/DocumentData.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.firestore 2 | 3 | external interface DocumentData 4 | 5 | @Suppress("NOTHING_TO_INLINE") 6 | inline operator fun DocumentData.get(field: String): Any? = asDynamic()[field] 7 | 8 | @Suppress("NOTHING_TO_INLINE") 9 | inline operator fun DocumentData.set(field: String, value: Any) { 10 | asDynamic()[field] = value 11 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/firestore/DocumentReference.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.firestore 2 | 3 | import kotlin.js.Promise 4 | 5 | external interface DocumentReference { 6 | val id: String 7 | val parent: DocumentReference 8 | 9 | fun collection(collectionPath: String): CollectionReference 10 | fun delete() : Promise 11 | fun get(): Promise 12 | fun get(value: String): Promise 13 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/firestore/DocumentSnapshot.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.firestore 2 | 3 | external interface DocumentSnapshot { 4 | 5 | val exists: Boolean 6 | val id: String 7 | val ref: DocumentReference 8 | val metadata: SnapshotMetadata 9 | 10 | 11 | fun data(options: SnapshotOptions? = definedExternally): DocumentData? 12 | fun get(fieldPath:String, options: SnapshotOptions? = definedExternally): Any? 13 | fun isEqual(other: DocumentSnapshot): Boolean 14 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/firestore/Firestore.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.firestore 2 | 3 | external interface Firestore { 4 | fun collection(collectionPath: String): CollectionReference 5 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/firestore/QueryDocumentSnapshot.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrapper.admin.firestore 2 | 3 | import com.firebase.wrappers.admin.firestore.DocumentSnapshot 4 | 5 | external interface QueryDocumentSnapshot : DocumentSnapshot -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/firestore/QuerySnapshot.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrapper.admin.firestore 2 | 3 | external interface QuerySnapshot { 4 | 5 | val docs: Array 6 | val size: Int 7 | val empty: Boolean 8 | 9 | fun forEach(callback: (QueryDocumentSnapshot) -> Unit, thisArg: dynamic = definedExternally) 10 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/firestore/SnapshotMetadata.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.firestore 2 | 3 | external interface SnapshotMetadata { 4 | 5 | val fromCache: Boolean 6 | val hasPendingWrites: Boolean 7 | 8 | fun isEqual(other: SnapshotMetadata): Boolean 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/firestore/SnapshotOptions.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.firestore 2 | 3 | external interface SnapshotOptions { 4 | 5 | val serverTimestamps: String? 6 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/storage/Bucket.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.storage 2 | 3 | external interface Bucket { 4 | 5 | val name: String 6 | 7 | fun file(name: String, options: BucketFileOptions? = definedExternally): File 8 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/storage/BucketFileOptions.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.storage 2 | 3 | data class BucketFileOptions(val generation: String? = undefined) -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/storage/File.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.storage 2 | 3 | import kotlin.js.Promise 4 | 5 | external interface File { 6 | fun createWriteStream(options: WriteStreamOptions? = definedExternally): WriteStream 7 | 8 | fun makePublic(): Promise 9 | } 10 | 11 | external interface MakeFilePublicResponse -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/storage/Storage.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.storage 2 | 3 | external interface Storage { 4 | 5 | fun bucket(name: String? = definedExternally): Bucket 6 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/storage/WriteStream.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.storage 2 | 3 | external interface WriteStream { 4 | 5 | fun on(action: String, callback: (data: dynamic) -> Unit) 6 | 7 | fun end(buffer: dynamic) 8 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/admin/storage/WriteStreamOptions.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.admin.storage 2 | 3 | data class WriteStreamOptions( 4 | val gzip: Boolean? = null, 5 | val metadata: FileMetaData? = null, 6 | val offset: Int? = null, 7 | val predefinedAct: String? = null, 8 | val private: Boolean? = null, 9 | val public: Boolean? = null, 10 | val resumable: Boolean? = null, 11 | val uri: String? = null, 12 | val validation: Boolean? = null 13 | ) 14 | 15 | data class FileMetaData( 16 | val contentType: String? = null, 17 | val metadata: Map? = null, 18 | val cacheControl: String? = null 19 | ) -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/functions/Functions.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.functions 2 | 3 | @JsModule("firebase-functions") 4 | external object Functions { 5 | 6 | fun config(): dynamic 7 | 8 | val https : Https 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/firebase/wrapper/functions/Https.kt: -------------------------------------------------------------------------------- 1 | package com.firebase.wrappers.functions 2 | 3 | external interface Https { 4 | 5 | fun onRequest(express: dynamic) 6 | 7 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/todo/Index.kt: -------------------------------------------------------------------------------- 1 | package com.todo 2 | 3 | import com.expressjs.wrapper.Express 4 | import com.expressjs.wrapper.Request 5 | import com.expressjs.wrapper.Response 6 | import com.firebase.wrappers.admin.Admin 7 | import com.firebase.wrappers.admin.firestore.DocumentData 8 | import com.firebase.wrappers.admin.firestore.get 9 | import com.firebase.wrappers.functions.Functions 10 | import kotlin.js.Date 11 | 12 | external val exports: dynamic 13 | 14 | fun main(args: Array) { 15 | 16 | val app = Express() 17 | Admin.initializeApp(Functions.config().firebase) 18 | val db = Admin.firestore() 19 | 20 | app.get("/task/:id?", { req, res -> 21 | val params = req.params.unsafeCast() 22 | if (params.id != undefined) { 23 | db.collection("task").doc(params.id).get().then({ doc -> 24 | if (!doc.exists) { 25 | res.status(404).json(Message("Task not found!")) 26 | } else { 27 | val data = doc.data().unsafeCast() 28 | res.status(200).json(Task(doc.id, data.label, data.time)) 29 | } 30 | }).catch({ err -> 31 | res.status(500).json(err) 32 | }) 33 | } else { 34 | db.collection("task").get().then({ snapshot -> 35 | val result = snapshot.docs.map { 36 | Task(it.id, it.data()!!["label"] as String, it.data()!!["time"] as Double) 37 | } 38 | res.status(200).json(result) 39 | }).catch({ err -> 40 | res.status(500).json(err) 41 | }) 42 | } 43 | }) 44 | 45 | app.put("/task", { req, res -> 46 | val input = req.body.unsafeCast() 47 | val inputTask = Task(label = input.label, time = Date().getTime()) 48 | 49 | // Hack because firestore check object prototype and KotlinJS has his own 50 | db.collection("task").add(JSON.parse(JSON.stringify(inputTask))).then({ ref -> 51 | res.status(201).json(Task(ref.id, inputTask.label, inputTask.time)) 52 | }).catch({ error -> 53 | res.status(500).json(error) 54 | }) 55 | }) 56 | 57 | app.delete("/task/:id", { req, res -> 58 | val params = req.params.unsafeCast() 59 | db.collection("task").doc(params.id).delete().then({ 60 | res.status(200).json(Message("Task has been deleted")) 61 | }) 62 | }) 63 | 64 | 65 | 66 | exports.v1 = Functions.https.onRequest(app) 67 | } 68 | 69 | data class TaskInput(val label: String) 70 | data class Task(val id: String? = undefined, val label: String, val time: Double) : DocumentData 71 | data class Params(val id: String? = undefined) 72 | data class Message(val msg: String) --------------------------------------------------------------------------------