-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #309 from AntlerVC/rc
Release v1.3.0
- Loading branch information
Showing
311 changed files
with
29,834 additions
and
7,353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
steps: | ||
- name: node:14.9.0 | ||
entrypoint: yarn | ||
args: ["install"] | ||
dir: "FT_functions/compiler" | ||
- name: node:14.9.0 | ||
entrypoint: yarn | ||
args: | ||
- "compile" | ||
- "${_SCHEMA_PATH}" | ||
dir: "FT_functions/compiler" | ||
- name: node:14.9.0 | ||
entrypoint: yarn | ||
args: ["install"] | ||
dir: "FT_functions/functions" | ||
- name: node:14.9.0 | ||
entrypoint: yarn | ||
args: | ||
- "deployFT" | ||
- "--project" | ||
- "${_PROJECT_ID}" | ||
- "--token" | ||
- "${_FIREBASE_TOKEN}" | ||
- "--only" | ||
- "functions" | ||
dir: "FT_functions/functions" | ||
|
||
substitutions: | ||
_PROJECT_ID: "project-id" # default value | ||
options: | ||
machineType: "N1_HIGHCPU_8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
firebase-debug.log* | ||
firebase-debug.*.log* | ||
|
||
# Firebase cache | ||
.firebase/ | ||
|
||
# Firebase config | ||
|
||
# Uncomment this if you'd like others to create their own Firebase project. | ||
# For a team working on the same Firebase project(s), it is recommended to leave | ||
# it commented so all members can deploy to the same project(s) in .firebaserc. | ||
# .firebaserc | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es6: true, | ||
node: true, | ||
}, | ||
extends: ["plugin:import/errors", "plugin:import/warnings"], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: "tsconfig.json", | ||
sourceType: "module", | ||
}, | ||
plugins: ["@typescript-eslint", "import"], | ||
rules: { | ||
"@typescript-eslint/adjacent-overload-signatures": "error", | ||
"@typescript-eslint/no-empty-function": "error", | ||
"@typescript-eslint/no-empty-interface": "warn", | ||
"@typescript-eslint/no-floating-promises": "error", | ||
"@typescript-eslint/no-namespace": "error", | ||
"@typescript-eslint/no-unnecessary-type-assertion": "error", | ||
"@typescript-eslint/prefer-for-of": "warn", | ||
"@typescript-eslint/triple-slash-reference": "error", | ||
"@typescript-eslint/unified-signatures": "warn", | ||
"comma-dangle": "warn", | ||
"constructor-super": "error", | ||
eqeqeq: ["warn", "always"], | ||
"import/no-deprecated": "warn", | ||
"import/no-extraneous-dependencies": "error", | ||
"import/no-unassigned-import": "warn", | ||
"no-cond-assign": "error", | ||
"no-duplicate-case": "error", | ||
"no-duplicate-imports": "error", | ||
"no-empty": [ | ||
"error", | ||
{ | ||
allowEmptyCatch: true, | ||
}, | ||
], | ||
"no-invalid-this": "error", | ||
"no-new-wrappers": "error", | ||
"no-param-reassign": "error", | ||
"no-redeclare": "error", | ||
"no-sequences": "error", | ||
"no-shadow": [ | ||
"error", | ||
{ | ||
hoist: "all", | ||
}, | ||
], | ||
"no-throw-literal": "error", | ||
"no-unsafe-finally": "error", | ||
"no-unused-labels": "error", | ||
"no-var": "warn", | ||
"no-void": "error", | ||
"prefer-const": "warn", | ||
}, | ||
settings: { | ||
jsdoc: { | ||
tagNamePreference: { | ||
returns: "return", | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { addPackages, addSparkLib } from "./terminal"; | ||
const fs = require("fs"); | ||
import { generateConfigFromTableSchema } from "./loader"; | ||
|
||
async function asyncForEach(array: any[], callback: Function) { | ||
for (let index = 0; index < array.length; index++) { | ||
await callback(array[index], index, array); | ||
} | ||
} | ||
|
||
generateConfigFromTableSchema(process.argv[2]).then(async () => { | ||
const configFile = fs.readFileSync( | ||
"../functions/src/functionConfig.ts", | ||
"utf-8" | ||
); | ||
const requiredDependencies = configFile.match( | ||
/(?<=(require\(("|'))).*?(?=("|')\))/g | ||
); | ||
if (requiredDependencies) { | ||
await addPackages(requiredDependencies.map((p) => ({ name: p }))); | ||
} | ||
|
||
const { sparksConfig } = require("../functions/src/functionConfig"); | ||
const requiredSparks = sparksConfig.map((s) => s.type); | ||
console.log({ requiredSparks }); | ||
|
||
await asyncForEach(requiredSparks, async (s) => await addSparkLib(s)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
const fs = require("fs"); | ||
const beautify = require("js-beautify").js; | ||
// Initialize Firebase Admin | ||
import * as admin from "firebase-admin"; | ||
// Initialize Firebase Admin | ||
//const serverTimestamp = admin.firestore.FieldValue.serverTimestamp; | ||
|
||
admin.initializeApp(); | ||
//const serviceAccount = require("./antler-vc-firebase.json"); | ||
//admin.initializeApp({ credential: admin.credential.cert(serviceAccount) }); | ||
const db = admin.firestore(); | ||
|
||
export const generateConfigFromTableSchema = async (schemaDocPath) => { | ||
const schemaDoc = await db.doc(schemaDocPath).get(); | ||
const schemaData = schemaDoc.data(); | ||
if (!schemaData) throw new Error("no schema found"); | ||
const derivativeColumns = Object.values(schemaData.columns).filter( | ||
(col: any) => col.type === "DERIVATIVE" | ||
); | ||
const derivativesConfig = `[${derivativeColumns.reduce( | ||
(acc, currColumn: any) => { | ||
if ( | ||
!currColumn.config.listenerFields || | ||
currColumn.config.listenerFields.length === 0 | ||
) | ||
throw new Error( | ||
`${currColumn.key} derivative is missing listener fields` | ||
); | ||
if (currColumn.config.listenerFields.includes(currColumn.key)) | ||
throw new Error( | ||
`${currColumn.key} derivative has its own key as a listener field` | ||
); | ||
return `${acc}{\nfieldName:'${ | ||
currColumn.key | ||
}',evaluate:async ({row,ref,db,auth,utilFns}) =>{${ | ||
currColumn.config.script | ||
}},\nlistenerFields:[${currColumn.config.listenerFields | ||
.map((fieldKey) => `"${fieldKey}"`) | ||
.join(",\n")}]},\n`; | ||
}, | ||
"" | ||
)}]`; | ||
|
||
const initializableColumns = Object.values( | ||
schemaData.columns | ||
).filter((col: any) => Boolean(col.config?.defaultValue)); | ||
console.log(JSON.stringify({ initializableColumns })); | ||
const initializeConfig = `[${initializableColumns.reduce( | ||
(acc, currColumn: any) => { | ||
if (currColumn.config.defaultValue.type === "static") { | ||
return `${acc}{\nfieldName:'${currColumn.key}', | ||
type:"${currColumn.config.defaultValue.type}", | ||
value:${ | ||
typeof currColumn.config.defaultValue.value === "string" | ||
? `"${currColumn.config.defaultValue.value}"` | ||
: currColumn.config.defaultValue.value | ||
}, | ||
},\n`; | ||
} else if (currColumn.config.defaultValue.type === "dynamic") { | ||
return `${acc}{\nfieldName:'${currColumn.key}', | ||
type:"${currColumn.config.defaultValue.type}", | ||
script:async ({row,ref,db,auth,utilFns}) =>{${currColumn.config.defaultValue.script}}, | ||
},\n`; | ||
} else { | ||
return `${acc}{\nfieldName:'${currColumn.key}', | ||
type:"${currColumn.config.defaultValue.type}" | ||
},\n`; | ||
} | ||
}, | ||
"" | ||
)}]`; | ||
const documentSelectColumns = Object.values(schemaData.columns).filter( | ||
(col: any) => col.type === "DOCUMENT_SELECT" && col.config?.trackedFields | ||
); | ||
const documentSelectConfig = `[${documentSelectColumns.reduce( | ||
(acc, currColumn: any) => { | ||
return `${acc}{\nfieldName:'${ | ||
currColumn.key | ||
}',\ntrackedFields:[${currColumn.config.trackedFields | ||
.map((fieldKey) => `"${fieldKey}"`) | ||
.join(",\n")}]},\n`; | ||
}, | ||
"" | ||
)}]`; | ||
|
||
const sparksConfig = schemaData.sparks ? schemaData.sparks : "[]"; | ||
const collectionType = schemaDocPath.includes("subTables") | ||
? "subCollection" | ||
: schemaDocPath.includes("groupSchema") | ||
? "groupCollection" | ||
: "collection"; | ||
let collectionId = ""; | ||
let functionName = ""; | ||
let triggerPath = ""; | ||
switch (collectionType) { | ||
case "collection": | ||
collectionId = schemaDocPath.split("/").pop(); | ||
functionName = `"${collectionId}"`; | ||
triggerPath = `"${collectionId}/{docId}"`; | ||
break; | ||
case "subCollection": | ||
let pathParentIncrement = 0; | ||
triggerPath = | ||
'"' + | ||
schemaDocPath | ||
.replace("_FIRETABLE_/settings/schema/", "") | ||
.replace(/subTables/g, function () { | ||
pathParentIncrement++; | ||
return `{parentDoc${pathParentIncrement}}`; | ||
}) + | ||
"/{docId}" + | ||
'"'; | ||
functionName = | ||
'"' + | ||
schemaDocPath | ||
.replace("_FIRETABLE_/settings/schema/", "") | ||
.replace(/\/subTables\//g, "_") + | ||
'"'; | ||
break; | ||
case "groupCollection": | ||
collectionId = schemaDocPath.split("/").pop(); | ||
const triggerDepth = schemaData.triggerDepth | ||
? schemaData.triggerDepth | ||
: 1; | ||
triggerPath = ""; | ||
for (let i = 1; i <= triggerDepth; i++) { | ||
triggerPath = triggerPath + `{parentCol${i}}/{parentDoc${i}}/`; | ||
} | ||
triggerPath = '"' + triggerPath + collectionId + "/" + "{docId}" + '"'; | ||
functionName = `"CG_${collectionId}${ | ||
triggerDepth > 1 ? `_D${triggerDepth}` : "" | ||
}"`; | ||
break; | ||
default: | ||
break; | ||
} | ||
const exports = { | ||
triggerPath, | ||
functionName: functionName.replace(/-/g, "_"), | ||
derivativesConfig, | ||
initializeConfig, | ||
documentSelectConfig, | ||
sparksConfig, | ||
}; | ||
|
||
const fileData = Object.keys(exports).reduce((acc, currKey) => { | ||
return `${acc}\nexport const ${currKey} = ${exports[currKey]}`; | ||
}, ``); | ||
fs.writeFileSync( | ||
"../functions/src/functionConfig.ts", | ||
beautify(fileData, { indent_size: 2 }) | ||
); | ||
}; |
Oops, something went wrong.