@genoacms/adapter-gcp 0.3.0 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
package/dist/config.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
declare const _default: Config
|
1
|
+
declare const _default: Config<object, object, object>;
|
2
2
|
export default _default;
|
@@ -7,30 +7,53 @@ const firestore = new Firestore({
|
|
7
7
|
});
|
8
8
|
const createDocument = async (reference, data) => {
|
9
9
|
const document = await firestore.collection(reference.name).add(data);
|
10
|
-
|
10
|
+
const documentReference = {
|
11
11
|
collection: reference,
|
12
12
|
id: document.id
|
13
13
|
};
|
14
|
+
return {
|
15
|
+
reference: documentReference,
|
16
|
+
data
|
17
|
+
};
|
14
18
|
};
|
15
|
-
const getCollection = async (
|
16
|
-
const collection = await firestore.collection(name).get();
|
19
|
+
const getCollection = async (reference) => {
|
20
|
+
const collection = await firestore.collection(reference.name).get();
|
17
21
|
const documents = [];
|
18
22
|
collection.forEach(document => {
|
19
23
|
const documentData = {};
|
20
|
-
Object.keys(schema.properties).forEach(key => {
|
24
|
+
Object.keys(reference.schema.properties).forEach(key => {
|
21
25
|
documentData[key] = document.get(key);
|
22
26
|
});
|
23
|
-
documents.push(
|
27
|
+
documents.push({
|
28
|
+
reference: {
|
29
|
+
collection: reference,
|
30
|
+
id: document.id
|
31
|
+
},
|
32
|
+
data: document.data()
|
33
|
+
});
|
24
34
|
});
|
25
35
|
return documents;
|
26
36
|
};
|
27
37
|
const getDocument = async ({ collection, id }) => {
|
28
38
|
const document = await firestore.collection(collection.name).doc(id).get();
|
29
|
-
|
39
|
+
if (!document.exists)
|
40
|
+
return undefined;
|
41
|
+
const documentReference = {
|
42
|
+
collection,
|
43
|
+
id
|
44
|
+
};
|
45
|
+
const documentSnapshot = {
|
46
|
+
reference: documentReference,
|
47
|
+
data: document.data()
|
48
|
+
};
|
49
|
+
return documentSnapshot;
|
30
50
|
};
|
31
51
|
const updateDocument = async (reference, document) => {
|
32
52
|
await firestore.collection(reference.collection.name).doc(reference.id).update(document);
|
33
|
-
return
|
53
|
+
return {
|
54
|
+
reference,
|
55
|
+
data: document
|
56
|
+
};
|
34
57
|
};
|
35
58
|
const deleteDocument = async (reference) => {
|
36
59
|
await firestore.collection(reference.collection.name).doc(reference.id).delete();
|
@@ -36,7 +36,7 @@ const listDirectory = async ({ bucket, name }, listingParams = {}) => {
|
|
36
36
|
return files.map((file) => {
|
37
37
|
return {
|
38
38
|
name: file.name,
|
39
|
-
size: file.metadata.size,
|
39
|
+
size: file.metadata.size ? parseInt(file.metadata.size) : 0,
|
40
40
|
lastModified: new Date(file.metadata.updated)
|
41
41
|
};
|
42
42
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@genoacms/adapter-gcp",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.8",
|
4
4
|
"description": "Implementation of abstraction layer of GenoaCMS for GCP",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -17,7 +17,7 @@
|
|
17
17
|
"homepage": "https://github.com/GenoaCMS/adapter-gcp#readme",
|
18
18
|
"type": "module",
|
19
19
|
"dependencies": {
|
20
|
-
"@genoacms/cloudabstraction": "^0.3.
|
20
|
+
"@genoacms/cloudabstraction": "^0.3.8",
|
21
21
|
"@google-cloud/firestore": "^7.1.0",
|
22
22
|
"@google-cloud/storage": "^7.4.0"
|
23
23
|
},
|
package/src/genoa.config.d.ts
CHANGED
@@ -10,34 +10,57 @@ const firestore = new Firestore({
|
|
10
10
|
|
11
11
|
const createDocument: databaseT.createDocument = async (reference, data) => {
|
12
12
|
const document = await firestore.collection(reference.name).add(data)
|
13
|
-
|
13
|
+
const documentReference: databaseT.DocumentReference<typeof reference> = {
|
14
14
|
collection: reference,
|
15
15
|
id: document.id
|
16
16
|
}
|
17
|
+
return {
|
18
|
+
reference: documentReference,
|
19
|
+
data
|
20
|
+
} satisfies databaseT.DocumentSnapshot<typeof reference>
|
17
21
|
}
|
18
22
|
|
19
|
-
const getCollection: databaseT.getCollection = async (
|
20
|
-
const collection = await firestore.collection(name).get()
|
21
|
-
const documents:
|
23
|
+
const getCollection: databaseT.getCollection = async (reference) => {
|
24
|
+
const collection = await firestore.collection(reference.name).get()
|
25
|
+
const documents: databaseT.CollectionSnapshot<typeof reference> = []
|
26
|
+
|
22
27
|
collection.forEach(document => {
|
23
|
-
const documentData: databaseT.Document<typeof schema> = {}
|
24
|
-
Object.keys(schema.properties).forEach(key => {
|
28
|
+
const documentData: databaseT.Document<typeof reference.schema> = {}
|
29
|
+
Object.keys(reference.schema.properties).forEach(key => {
|
25
30
|
documentData[key] = document.get(key)
|
26
31
|
})
|
27
32
|
|
28
|
-
documents.push(
|
33
|
+
documents.push({
|
34
|
+
reference: {
|
35
|
+
collection: reference,
|
36
|
+
id: document.id
|
37
|
+
},
|
38
|
+
data: document.data() as databaseT.Document<typeof reference.schema>
|
39
|
+
})
|
29
40
|
})
|
30
41
|
return documents
|
31
42
|
}
|
32
43
|
|
33
44
|
const getDocument: databaseT.getDocument = async ({ collection, id }) => {
|
34
45
|
const document = await firestore.collection(collection.name).doc(id).get()
|
35
|
-
|
46
|
+
if (!document.exists) return undefined
|
47
|
+
const documentReference: databaseT.DocumentReference<typeof collection> = {
|
48
|
+
collection,
|
49
|
+
id
|
50
|
+
}
|
51
|
+
const documentSnapshot: databaseT.DocumentSnapshot<typeof collection> = {
|
52
|
+
reference: documentReference,
|
53
|
+
data: document.data() as databaseT.Document<typeof collection>
|
54
|
+
}
|
55
|
+
return documentSnapshot
|
36
56
|
}
|
37
57
|
|
38
58
|
const updateDocument: databaseT.updateDocument = async (reference, document) => {
|
39
59
|
await firestore.collection(reference.collection.name).doc(reference.id).update(document)
|
40
|
-
return
|
60
|
+
return {
|
61
|
+
reference,
|
62
|
+
data: document
|
63
|
+
} satisfies databaseT.UpdateSnapshot<typeof reference.collection>
|
41
64
|
}
|
42
65
|
|
43
66
|
const deleteDocument: databaseT.deleteDocument = async (reference) => {
|
@@ -45,7 +45,7 @@ const listDirectory: storageT.listDirectory = async ({ bucket, name }, listingPa
|
|
45
45
|
return files.map((file) => {
|
46
46
|
return {
|
47
47
|
name: file.name,
|
48
|
-
size: file.metadata.size as
|
48
|
+
size: file.metadata.size ? parseInt(file.metadata.size as string) : 0,
|
49
49
|
lastModified: new Date(file.metadata.updated as string)
|
50
50
|
} satisfies storageT.StorageObject
|
51
51
|
})
|