@aldel/test-func-kit 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,66 @@
1
1
  # test-func-kit
2
2
 
3
- A minimal, experimental Firebase Function Kit.
3
+ A minimal, experimental Firebase Function Kit. Has one parameter, `MESSAGE`,
4
+ and one function, `helloWorld`, an HTTPS endpoint that returns the value of `MESSAGE`.
5
+
6
+ Function kits are very new, and the only existing documentation is steps for
7
+ converting a Firebase Extension to a kit. This is a kit that I created to try
8
+ to understand more about how they work.
9
+
10
+ Earlier I made [this repo](https://github.com/adelespinasse/funckittest), which
11
+ is just a simple Firebase project with one kit installed, so I could see what
12
+ installation does.
13
+
14
+ ### How kits work
15
+
16
+ Based on the conversion instructions and the only existing kit that I'm aware
17
+ of
18
+ ([@firebase-function-kits/firestore-bigquery-export](https://www.npmjs.com/package/@firebase-function-kits/firestore-bigquery-export)),
19
+ a function kits appears to consist of:
20
+
21
+ * A straightforward extension of the [codebases and function groups
22
+ features](https://firebase.google.com/docs/functions/organize-functions#organize_functions_in_codebases),
23
+ where you can list a "kit" in the functions section of firebase.json instead
24
+ of a "codebase", and it automatically adds a prefix to each of the exported
25
+ functions, and loads parameters from a named config for that installation
26
+ * The functions:kits:install command, which creates a whole new npm package
27
+ under function-kits/ (parallel to functions/, not nested under it), installs
28
+ the package you name there, generates a wrapper to import and re-export its
29
+ functions, adds the necessary "kit" entry to firebase.json, prompts for
30
+ parameter values, and creates the named .env file for the parameters
31
+ * [Lifecycle
32
+ triggers](https://firebase.google.com/docs/extensions/publishers/migrate#convert-lifecycle-hooks)
33
+ to replace the Extensions install/upgrade hooks
34
+ * A way to [declare required APIs and service account roles in the
35
+ code]()https://firebase.google.com/docs/extensions/publishers/migrate#declare-apis-and-roles
36
+
37
+ I'm probably missing things.
38
+
39
+ Compared with Extensions, kits lose the "app store" type of registry, which has
40
+ advantages and disadvantages: it helps users discover extensions and have
41
+ confidence in them, but also is a barrier to entry for extension developers,
42
+ and requires that extensions be open source and Apache licensed. Kits just use
43
+ the npm free-for-all model.
44
+
45
+ ### Lessons learned
46
+
47
+ * It appears to be impossible to install a kit that isn't published on a
48
+ registry. The `firebase functions:kits:install --package` command doesn't
49
+ work with other package specifiers, like a tarball or path to a directory.
50
+ There is a `--directory` option you can use instead of `--package`, but it
51
+ doesn't appear to work, at least not as I expected. This makes testing hard,
52
+ and hopefully will be fixed.
53
+ * There are also `functions:kits:uninstall` and `functions:kits:list` commands,
54
+ which work as you would expect.
55
+ * Always generate `.d.ts` files for your kit's package. The installation
56
+ process generates TypeScript wrapper code that is compiled with `tsc`, which
57
+ fails when it tries to import from the kit if there are no type definitions.
58
+ (Or maybe you could just have the package.json "main" property point to a
59
+ TypeScript file? Since it's running the compiler anyway...)
60
+ * Don't call `setGlobalOptions` in a kit. The generated wrapper calls it, and
61
+ calling it twice generates a warning; apparently it "leads to undefined
62
+ behavior". Also it doesn't really make sense to call it, I guess. It wouldn't
63
+ have occurred to me to call it, but it's called in the default functions code
64
+ generated by `firebase init`, and I hadn't thought to remove it.
65
+
66
+
Binary file
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Minimal Function Kit function with one parameter
3
+ */
4
+ export declare const helloWorld: import("firebase-functions/https").HttpsFunction;
package/lib/index.js CHANGED
@@ -1,18 +1,12 @@
1
1
  "use strict";
2
2
  /**
3
- * Import function triggers from their respective submodules:
4
- *
5
- * import {onCall} from "firebase-functions/v2/https";
6
- * import {onDocumentWritten} from "firebase-functions/v2/firestore";
7
- *
8
- * See a full list of supported triggers at https://firebase.google.com/docs/functions
3
+ * Minimal Function Kit function with one parameter
9
4
  */
10
5
  Object.defineProperty(exports, "__esModule", { value: true });
11
6
  exports.helloWorld = void 0;
12
- const firebase_functions_1 = require("firebase-functions");
7
+ // import {setGlobalOptions} from "firebase-functions";
13
8
  const https_1 = require("firebase-functions/https");
14
9
  const params_1 = require("firebase-functions/params");
15
- // import * as logger from "firebase-functions/logger";
16
10
  const message = (0, params_1.defineString)('MESSAGE', {
17
11
  label: 'Message sent by the helloWorld function',
18
12
  description: 'The message to be sent by the helloWorld function. Must begin with "Hello".',
@@ -24,19 +18,10 @@ const message = (0, params_1.defineString)('MESSAGE', {
24
18
  },
25
19
  },
26
20
  });
27
- // Start writing functions
28
- // https://firebase.google.com/docs/functions/typescript
29
- // For cost control, you can set the maximum number of containers that can be
30
- // running at the same time. This helps mitigate the impact of unexpected
31
- // traffic spikes by instead downgrading performance. This limit is a
32
- // per-function limit. You can override the limit for each function using the
33
- // `maxInstances` option in the function's options, e.g.
34
- // `onRequest({ maxInstances: 5 }, (req, res) => { ... })`.
35
- // NOTE: setGlobalOptions does not apply to functions using the v1 API. V1
36
- // functions should each use functions.runWith({ maxInstances: 10 }) instead.
37
- // In the v1 API, each function can only serve one request per container, so
38
- // this will be the maximum concurrent request count.
39
- (0, firebase_functions_1.setGlobalOptions)({ maxInstances: 10 });
21
+ // NOTE: Don't call setGlobalOptions in a function kit; the generated wrapper
22
+ // calls it, and calling twice outputs a warning ("leads to undefined
23
+ // behavior").
24
+ //setGlobalOptions({maxInstances: 10});
40
25
  exports.helloWorld = (0, https_1.onRequest)((request, response) => {
41
26
  console.log("Hello logs!", { structuredData: true });
42
27
  response.send(message.value());
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,uDAAuD;AACvD,oDAAmD;AACnD,sDAAyD;AAEzD,MAAM,OAAO,GAAG,IAAA,qBAAY,EAC1B,SAAS,EACT;IACE,KAAK,EAAE,yCAAyC;IAChD,WAAW,EAAE,6EAA6E;IAC1F,OAAO,EAAE,eAAe;IACxB,KAAK,EAAE;QACL,IAAI,EAAE;YACJ,eAAe,EAAE,WAAW;YAC5B,sBAAsB,EAAE,yBAAyB;SAClD;KACF;CACF,CACF,CAAC;AAEF,6EAA6E;AAC7E,qEAAqE;AACrE,cAAc;AACd,uCAAuC;AAE1B,QAAA,UAAU,GAAG,IAAA,iBAAS,EAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;IACxD,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,EAAC,cAAc,EAAE,IAAI,EAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@aldel/test-func-kit",
3
3
  "description": "A minimal, experimental function kit for Firebase.",
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/adelespinasse/test-func-kit.git"
8
+ },
5
9
  "publishConfig": {
6
10
  "access": "public"
7
11
  },
@@ -20,6 +24,7 @@
20
24
  "node": "24"
21
25
  },
22
26
  "main": "lib/index.js",
27
+ "types": "lib/index.d.ts",
23
28
  "dependencies": {
24
29
  "firebase-admin": "^13.6.0",
25
30
  "firebase-functions": "^7.0.0"
package/src/index.ts CHANGED
@@ -1,16 +1,10 @@
1
1
  /**
2
- * Import function triggers from their respective submodules:
3
- *
4
- * import {onCall} from "firebase-functions/v2/https";
5
- * import {onDocumentWritten} from "firebase-functions/v2/firestore";
6
- *
7
- * See a full list of supported triggers at https://firebase.google.com/docs/functions
2
+ * Minimal Function Kit function with one parameter
8
3
  */
9
4
 
10
- import {setGlobalOptions} from "firebase-functions";
5
+ // import {setGlobalOptions} from "firebase-functions";
11
6
  import {onRequest} from "firebase-functions/https";
12
7
  import { defineString } from 'firebase-functions/params';
13
- // import * as logger from "firebase-functions/logger";
14
8
 
15
9
  const message = defineString(
16
10
  'MESSAGE',
@@ -27,21 +21,10 @@ const message = defineString(
27
21
  },
28
22
  );
29
23
 
30
-
31
- // Start writing functions
32
- // https://firebase.google.com/docs/functions/typescript
33
-
34
- // For cost control, you can set the maximum number of containers that can be
35
- // running at the same time. This helps mitigate the impact of unexpected
36
- // traffic spikes by instead downgrading performance. This limit is a
37
- // per-function limit. You can override the limit for each function using the
38
- // `maxInstances` option in the function's options, e.g.
39
- // `onRequest({ maxInstances: 5 }, (req, res) => { ... })`.
40
- // NOTE: setGlobalOptions does not apply to functions using the v1 API. V1
41
- // functions should each use functions.runWith({ maxInstances: 10 }) instead.
42
- // In the v1 API, each function can only serve one request per container, so
43
- // this will be the maximum concurrent request count.
44
- setGlobalOptions({maxInstances: 10});
24
+ // NOTE: Don't call setGlobalOptions in a function kit; the generated wrapper
25
+ // calls it, and calling twice outputs a warning ("leads to undefined
26
+ // behavior").
27
+ //setGlobalOptions({maxInstances: 10});
45
28
 
46
29
  export const helloWorld = onRequest((request, response) => {
47
30
  console.log("Hello logs!", {structuredData: true});
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "module": "NodeNext",
4
+ "declaration": true,
4
5
  "esModuleInterop": true,
5
6
  "moduleResolution": "nodenext",
6
7
  "noImplicitReturns": true,
Binary file