|
| 1 | +import { ConfigToType, QueryConfig } from "openblocks-sdk/dataSource"; |
| 2 | + |
| 3 | +enum FirebaseCategory { |
| 4 | + RealtimeDatabase = "RealtimeDatabase", |
| 5 | + Firestore = "Firestore", |
| 6 | +} |
| 7 | + |
| 8 | +const databaseRefParamConfig = { |
| 9 | + key: "databaseRef", |
| 10 | + label: "Database Ref", |
| 11 | + type: "textInput", |
| 12 | +} as const; |
| 13 | + |
| 14 | +const dataParamConfig = { |
| 15 | + key: "data", |
| 16 | + label: "Data", |
| 17 | + type: "jsonInput", |
| 18 | +} as const; |
| 19 | + |
| 20 | +const firestoreCollectionParamConfig = { |
| 21 | + key: "collection", |
| 22 | + label: "Collection", |
| 23 | + type: "textInput", |
| 24 | +} as const; |
| 25 | + |
| 26 | +const firestoreDocIdParamConfig = { |
| 27 | + key: "documentId", |
| 28 | + label: "Document ID", |
| 29 | + type: "textInput", |
| 30 | +} as const; |
| 31 | + |
| 32 | +const firestoreParentDocIdParamConfig = { |
| 33 | + key: "parentDocumentId", |
| 34 | + label: "Parent", |
| 35 | + type: "textInput", |
| 36 | + tooltip: |
| 37 | + "The parent document id of collections you want to list. Leave empty for top-level collections.", |
| 38 | +} as const; |
| 39 | + |
| 40 | +const firestoreDataParamConfig = { |
| 41 | + key: "data", |
| 42 | + label: "Data", |
| 43 | + type: "jsonInput", |
| 44 | +} as const; |
| 45 | + |
| 46 | +const categories = { |
| 47 | + label: "Service", |
| 48 | + items: [ |
| 49 | + { label: "Realtime Database", value: FirebaseCategory.RealtimeDatabase }, |
| 50 | + { label: "Firestore", value: FirebaseCategory.Firestore }, |
| 51 | + ], |
| 52 | +}; |
| 53 | + |
| 54 | +const queryConfig = { |
| 55 | + type: "query", |
| 56 | + categories, |
| 57 | + label: "Action", |
| 58 | + actions: [ |
| 59 | + // actions of realtime database |
| 60 | + ...( |
| 61 | + [ |
| 62 | + { |
| 63 | + label: "Query Database", |
| 64 | + actionName: "RTDB.QueryDatabase", |
| 65 | + params: [databaseRefParamConfig], |
| 66 | + }, |
| 67 | + { |
| 68 | + label: "Set Data", |
| 69 | + actionName: "RTDB.SetData", |
| 70 | + params: [databaseRefParamConfig, dataParamConfig], |
| 71 | + }, |
| 72 | + { |
| 73 | + label: "Update Data", |
| 74 | + actionName: "RTDB.UpdateData", |
| 75 | + params: [databaseRefParamConfig, dataParamConfig], |
| 76 | + }, |
| 77 | + { |
| 78 | + label: "Append Data to a list", |
| 79 | + actionName: "RTDB.AppendDataToList", |
| 80 | + params: [databaseRefParamConfig, dataParamConfig], |
| 81 | + }, |
| 82 | + ] as const |
| 83 | + ).map((i) => ({ ...i, category: [FirebaseCategory.RealtimeDatabase] })), |
| 84 | + |
| 85 | + // actions of firestore |
| 86 | + ...( |
| 87 | + [ |
| 88 | + { |
| 89 | + label: "Query Firestore", |
| 90 | + actionName: "FS.QueryFireStore", |
| 91 | + params: [ |
| 92 | + firestoreCollectionParamConfig, |
| 93 | + { |
| 94 | + key: "orderBy", |
| 95 | + label: "Order by", |
| 96 | + type: "textInput", |
| 97 | + }, |
| 98 | + { |
| 99 | + key: "orderDirection", |
| 100 | + label: "Order direction", |
| 101 | + type: "textInput", |
| 102 | + defaultValue: "asc", |
| 103 | + placeholder: "asc", |
| 104 | + }, |
| 105 | + { |
| 106 | + key: "limit", |
| 107 | + label: "Limit", |
| 108 | + type: "numberInput", |
| 109 | + defaultValue: 10, |
| 110 | + }, |
| 111 | + ], |
| 112 | + }, |
| 113 | + { |
| 114 | + label: "Insert Document", |
| 115 | + actionName: "FS.InsertDocument", |
| 116 | + params: [ |
| 117 | + firestoreCollectionParamConfig, |
| 118 | + { |
| 119 | + ...firestoreDocIdParamConfig, |
| 120 | + tooltip: "Leaving empty will use auto generated document id.", |
| 121 | + }, |
| 122 | + firestoreDataParamConfig, |
| 123 | + ], |
| 124 | + }, |
| 125 | + { |
| 126 | + label: "Update Document", |
| 127 | + actionName: "FS.UpdateDocument", |
| 128 | + params: [ |
| 129 | + firestoreCollectionParamConfig, |
| 130 | + firestoreDocIdParamConfig, |
| 131 | + firestoreDataParamConfig, |
| 132 | + ], |
| 133 | + }, |
| 134 | + { |
| 135 | + label: "Get Document", |
| 136 | + actionName: "FS.GetDocument", |
| 137 | + params: [firestoreCollectionParamConfig, firestoreDocIdParamConfig], |
| 138 | + }, |
| 139 | + { |
| 140 | + label: "Delete Document", |
| 141 | + actionName: "FS.DeleteDocument", |
| 142 | + params: [firestoreCollectionParamConfig, firestoreDocIdParamConfig], |
| 143 | + }, |
| 144 | + { |
| 145 | + label: "Get Collections", |
| 146 | + actionName: "FS.GetCollections", |
| 147 | + params: [firestoreParentDocIdParamConfig], |
| 148 | + }, |
| 149 | + ] as const |
| 150 | + ).map((i) => ({ ...i, category: [FirebaseCategory.Firestore] })), |
| 151 | + ], |
| 152 | +} as const; |
| 153 | + |
| 154 | +export type ActionDataType = ConfigToType<typeof queryConfig>; |
| 155 | + |
| 156 | +export default queryConfig; |
0 commit comments