Skip to content

Commit 5affe8c

Browse files
committed
feat: initial code commit
1 parent d893cc0 commit 5affe8c

17 files changed

+6911
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib
2+
node_modules

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
1-
# firestore-onwrite-processor
1+
# firebase-extension-utilites
2+
3+
## firestore-onwrite-processor
4+
5+
This provides a processor class which you can pass to your firestore onWrite call, and will handle the state of processes on firestore fields for you.
6+
7+
```typescript
8+
import {
9+
FirestoreOnWriteProcessor,
10+
FirestoreOnWriteProcess,
11+
} from "../firestore-onwrite-processor";
12+
13+
const myProcess = new FirestoreOnWriteProcess({
14+
id: "myProcessId",
15+
fieldDependencyArray: ["input"],
16+
processFn: ({ input }) => {
17+
// do stuff here
18+
return { output };
19+
},
20+
});
21+
22+
const myProcessor = new FirestoreOnWriteProcessor({
23+
processes: [myProcess],
24+
});
25+
26+
export const myFunction = functions.firestore
27+
.document(COLLECTION_NAME / { id })
28+
.onWrite(process);
29+
```
30+
31+
TODO:
32+
33+
- change signature of above, process function should be main argument and then should pass `options` which include optional id etc.
34+
35+
Used in:
36+
37+
- PaLM extensions
38+
- Gemini extensions

_emulator/.firebaserc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"projects": {
3+
"default": "extensions-testing"
4+
},
5+
"targets": {}
6+
}

_emulator/.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
firebase-debug.log*
8+
firebase-debug.*.log*
9+
10+
# Firebase cache
11+
.firebase/
12+
13+
# Firebase config
14+
15+
# Uncomment this if you'd like others to create their own Firebase project.
16+
# For a team working on the same Firebase project(s), it is recommended to leave
17+
# it commented so all members can deploy to the same project(s) in .firebaserc.
18+
# .firebaserc
19+
20+
# Runtime data
21+
pids
22+
*.pid
23+
*.seed
24+
*.pid.lock
25+
26+
# Directory for instrumented libs generated by jscoverage/JSCover
27+
lib-cov
28+
29+
# Coverage directory used by tools like istanbul
30+
coverage
31+
32+
# nyc test coverage
33+
.nyc_output
34+
35+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
36+
.grunt
37+
38+
# Bower dependency directory (https://bower.io/)
39+
bower_components
40+
41+
# node-waf configuration
42+
.lock-wscript
43+
44+
# Compiled binary addons (http://nodejs.org/api/addons.html)
45+
build/Release
46+
47+
# Dependency directories
48+
node_modules/
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional REPL history
57+
.node_repl_history
58+
59+
# Output of 'npm pack'
60+
*.tgz
61+
62+
# Yarn Integrity file
63+
.yarn-integrity
64+
65+
# dotenv environment variables file
66+
.env

_emulator/firebase.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"emulators": {
3+
"ui": {
4+
"enabled": true
5+
},
6+
"firestore": {
7+
"host": "127.0.0.1",
8+
"port": 8080
9+
}
10+
},
11+
"firestore": {
12+
"rules": "firestore.rules",
13+
"indexes": "firestore.indexes.json",
14+
"host": "test-firestore.sandbox.googleapis.com"
15+
}
16+
}

_emulator/firestore.indexes.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"indexes": [],
3+
"fieldOverrides": []
4+
}

_emulator/firestore.rules

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
rules_version = '2';
2+
service cloud.firestore {
3+
match /databases/{database}/documents {
4+
match /{document=**} {
5+
// This rule allows anyone with your database reference to view, edit,
6+
// and delete all data in your database. It is useful for getting
7+
// started, but it is configured to expire after 30 days because it
8+
// leaves your app open to attackers. At that time, all client
9+
// requests to your database will be denied.
10+
//
11+
// Make sure to write security rules for your app before that time, or
12+
// else all client requests to your database will be denied until you
13+
// update your rules.
14+
allow read, write;
15+
}
16+
}
17+
}

jest.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const packageJson = require("./package.json");
2+
3+
module.exports = {
4+
name: packageJson.name,
5+
displayName: packageJson.name,
6+
preset: "ts-jest",
7+
testMatch: ["**/*.test.ts"],
8+
moduleNameMapper: {
9+
"firebase-admin/eventarc":
10+
"<rootDir>/node_modules/firebase-admin/lib/eventarc",
11+
"firebase-admin/auth": "<rootDir>/node_modules/firebase-admin/lib/auth",
12+
"firebase-admin/app": "<rootDir>/node_modules/firebase-admin/lib/app",
13+
"firebase-admin/database":
14+
"<rootDir>/node_modules/firebase-admin/lib/database",
15+
"firebase-admin/firestore":
16+
"<rootDir>/node_modules/firebase-admin/lib/firestore",
17+
"firebase-admin/functions":
18+
"<rootDir>/node_modules/firebase-admin/lib/functions",
19+
"firebase-functions/v2": "<rootDir>/node_modules/firebase-functions/lib/v2",
20+
"firebase-admin/extensions":
21+
"<rootDir>/node_modules/firebase-admin/lib/extensions",
22+
},
23+
};

0 commit comments

Comments
 (0)