|
| 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 Document ID", |
| 35 | + type: "textInput", |
| 36 | +} as const; |
| 37 | + |
| 38 | +const firestoreDataParamConfig = { |
| 39 | + key: "data", |
| 40 | + label: "Data", |
| 41 | + type: "jsonInput", |
| 42 | +} as const; |
| 43 | + |
| 44 | +const categories = { |
| 45 | + label: "Service", |
| 46 | + items: [ |
| 47 | + { label: "Realtime Database", value: FirebaseCategory.RealtimeDatabase }, |
| 48 | + { label: "Firestore", value: FirebaseCategory.Firestore }, |
| 49 | + ], |
| 50 | +}; |
| 51 | + |
| 52 | +const queryConfig = { |
| 53 | + type: "query", |
| 54 | + categories, |
| 55 | + label: "Action", |
| 56 | + actions: [ |
| 57 | + // actions of realtime database |
| 58 | + ...( |
| 59 | + [ |
| 60 | + { |
| 61 | + label: "Query Database", |
| 62 | + actionName: "RTDB.QueryDatabase", |
| 63 | + params: [databaseRefParamConfig], |
| 64 | + }, |
| 65 | + { |
| 66 | + label: "Set Data", |
| 67 | + actionName: "RTDB.SetData", |
| 68 | + params: [databaseRefParamConfig, dataParamConfig], |
| 69 | + }, |
| 70 | + { |
| 71 | + label: "Update Data", |
| 72 | + actionName: "RTDB.UpdateData", |
| 73 | + params: [databaseRefParamConfig, dataParamConfig], |
| 74 | + }, |
| 75 | + { |
| 76 | + label: "Append Data to a list", |
| 77 | + actionName: "RTDB.AppendDataToList", |
| 78 | + params: [databaseRefParamConfig, dataParamConfig], |
| 79 | + }, |
| 80 | + ] as const |
| 81 | + ).map((i) => ({ ...i, category: [FirebaseCategory.RealtimeDatabase] })), |
| 82 | + |
| 83 | + // actions of firestore |
| 84 | + ...( |
| 85 | + [ |
| 86 | + { |
| 87 | + label: "Query Firestore", |
| 88 | + actionName: "FS.QueryFireStore", |
| 89 | + params: [firestoreCollectionParamConfig], |
| 90 | + }, |
| 91 | + { |
| 92 | + label: "Insert Document", |
| 93 | + actionName: "FS.InsertDocument", |
| 94 | + params: [ |
| 95 | + firestoreCollectionParamConfig, |
| 96 | + firestoreDocIdParamConfig, |
| 97 | + firestoreDataParamConfig, |
| 98 | + ], |
| 99 | + }, |
| 100 | + { |
| 101 | + label: "Update Document", |
| 102 | + actionName: "FS.UpdateDocument", |
| 103 | + params: [ |
| 104 | + firestoreCollectionParamConfig, |
| 105 | + firestoreDocIdParamConfig, |
| 106 | + firestoreDataParamConfig, |
| 107 | + ], |
| 108 | + }, |
| 109 | + { |
| 110 | + label: "Get Document", |
| 111 | + actionName: "FS.GetDocument", |
| 112 | + params: [firestoreCollectionParamConfig, firestoreDocIdParamConfig], |
| 113 | + }, |
| 114 | + { |
| 115 | + label: "Delete Document", |
| 116 | + actionName: "FS.DeleteDocument", |
| 117 | + params: [firestoreCollectionParamConfig, firestoreDocIdParamConfig], |
| 118 | + }, |
| 119 | + { |
| 120 | + label: "Get Collections", |
| 121 | + actionName: "FS.GetCollections", |
| 122 | + params: [firestoreParentDocIdParamConfig], |
| 123 | + }, |
| 124 | + { |
| 125 | + label: "Get Collection Group", |
| 126 | + actionName: "FS.GetDocumentGroup", |
| 127 | + params: [firestoreCollectionParamConfig], |
| 128 | + } as const, |
| 129 | + ] as const |
| 130 | + ).map((i) => ({ ...i, category: [FirebaseCategory.Firestore] })), |
| 131 | + ], |
| 132 | +} as const; |
| 133 | + |
| 134 | +export type ActionDataType = ConfigToType<typeof queryConfig>; |
| 135 | + |
| 136 | +export default queryConfig; |
0 commit comments