@genoacms/adapter-gcp 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/config.d.ts +1 -1
- package/dist/services/authorization/index.d.ts +2 -2
- package/dist/services/authorization/index.js +1 -1
- package/dist/services/database/index.d.ts +6 -6
- package/dist/services/database/index.js +1 -1
- package/dist/services/storage/index.d.ts +7 -7
- package/package.json +5 -5
- package/src/genoa.config.d.ts +1 -1
- package/src/services/authorization/index.ts +3 -3
- package/src/services/database/index.ts +23 -16
- package/src/services/storage/index.ts +9 -9
package/dist/config.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
declare const _default:
|
1
|
+
declare const _default: any;
|
2
2
|
export default _default;
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import type {
|
2
|
-
declare const isEmailAdmins:
|
1
|
+
import type { Adapter } from '@genoacms/cloudabstraction/authorization';
|
2
|
+
declare const isEmailAdmins: Adapter.isEmailAdmins;
|
3
3
|
export { isEmailAdmins };
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { ProjectsClient } from '@google-cloud/resource-manager';
|
2
1
|
import config from '../../config.js';
|
2
|
+
import { ProjectsClient } from '@google-cloud/resource-manager';
|
3
3
|
const resourceManager = new ProjectsClient({
|
4
4
|
projectId: config.authorization.projectId,
|
5
5
|
credentials: config.authorization.credentials
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import type {
|
2
|
-
declare const createDocument:
|
3
|
-
declare const getCollection:
|
4
|
-
declare const getDocument:
|
5
|
-
declare const updateDocument:
|
6
|
-
declare const deleteDocument:
|
1
|
+
import type { Adapter } from '@genoacms/cloudabstraction/database';
|
2
|
+
declare const createDocument: Adapter.createDocument;
|
3
|
+
declare const getCollection: Adapter.getCollection;
|
4
|
+
declare const getDocument: Adapter.getDocument;
|
5
|
+
declare const updateDocument: Adapter.updateDocument;
|
6
|
+
declare const deleteDocument: Adapter.deleteDocument;
|
7
7
|
export { createDocument, getDocument, getCollection, updateDocument, deleteDocument };
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { Adapter } from '@genoacms/cloudabstraction/storage';
|
2
|
-
declare const getObject: Adapter
|
3
|
-
declare const getPublicURL: Adapter
|
4
|
-
declare const getSignedURL: Adapter
|
5
|
-
declare const uploadObject: Adapter
|
6
|
-
declare const deleteObject: Adapter
|
7
|
-
declare const listDirectory: Adapter
|
8
|
-
declare const createDirectory: Adapter
|
2
|
+
declare const getObject: Adapter.getObject;
|
3
|
+
declare const getPublicURL: Adapter.getPublicURL;
|
4
|
+
declare const getSignedURL: Adapter.getSignedURL;
|
5
|
+
declare const uploadObject: Adapter.uploadObject;
|
6
|
+
declare const deleteObject: Adapter.deleteObject;
|
7
|
+
declare const listDirectory: Adapter.listDirectory;
|
8
|
+
declare const createDirectory: Adapter.createDirectory;
|
9
9
|
export { getObject, getPublicURL, getSignedURL, uploadObject, deleteObject, listDirectory, createDirectory };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@genoacms/adapter-gcp",
|
3
|
-
"version": "0.4.
|
3
|
+
"version": "0.4.2",
|
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": "
|
20
|
+
"@genoacms/cloudabstraction": "0.4.2-fix.2",
|
21
21
|
"@google-cloud/firestore": "^7.1.0",
|
22
22
|
"@google-cloud/resource-manager": "^5.1.0",
|
23
23
|
"@google-cloud/storage": "^7.7.0"
|
@@ -38,9 +38,9 @@
|
|
38
38
|
"dist"
|
39
39
|
],
|
40
40
|
"exports": {
|
41
|
-
"./
|
42
|
-
"import": "./dist/services/
|
43
|
-
"types": "./dist/services/
|
41
|
+
"./authorization": {
|
42
|
+
"import": "./dist/services/authorization/index.js",
|
43
|
+
"types": "./dist/services/authorization/index.d.ts"
|
44
44
|
},
|
45
45
|
"./database": {
|
46
46
|
"import": "./dist/services/database/index.js",
|
package/src/genoa.config.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import type { Adapter } from '@genoacms/cloudabstraction/authorization'
|
2
2
|
import config from '../../config.js'
|
3
|
-
import
|
3
|
+
import { ProjectsClient } from '@google-cloud/resource-manager'
|
4
4
|
|
5
5
|
const resourceManager = new ProjectsClient({
|
6
6
|
projectId: config.authorization.projectId,
|
@@ -8,7 +8,7 @@ const resourceManager = new ProjectsClient({
|
|
8
8
|
})
|
9
9
|
const projectId = config.authorization.projectId
|
10
10
|
|
11
|
-
const isEmailAdmins:
|
11
|
+
const isEmailAdmins: Adapter.isEmailAdmins = async (email: string) => {
|
12
12
|
const resource = `projects/${projectId}`
|
13
13
|
const role = resource + '/roles/genoacms'
|
14
14
|
const data = await resourceManager.getIamPolicy({ resource })
|
@@ -1,6 +1,13 @@
|
|
1
|
-
import {
|
1
|
+
import type {
|
2
|
+
Adapter,
|
3
|
+
CollectionSnapshot,
|
4
|
+
Document,
|
5
|
+
DocumentReference,
|
6
|
+
DocumentSnapshot,
|
7
|
+
UpdateSnapshot
|
8
|
+
} from '@genoacms/cloudabstraction/database'
|
2
9
|
import config from '../../config.js'
|
3
|
-
import
|
10
|
+
import { Firestore } from '@google-cloud/firestore'
|
4
11
|
|
5
12
|
const firestore = new Firestore({
|
6
13
|
credentials: config.database.credentials,
|
@@ -8,24 +15,24 @@ const firestore = new Firestore({
|
|
8
15
|
projectId: config.database.projectId
|
9
16
|
})
|
10
17
|
|
11
|
-
const createDocument:
|
18
|
+
const createDocument: Adapter.createDocument = async (reference, data) => {
|
12
19
|
const document = await firestore.collection(reference.name).add(data)
|
13
|
-
const documentReference:
|
20
|
+
const documentReference: DocumentReference<typeof reference> = {
|
14
21
|
collection: reference,
|
15
22
|
id: document.id
|
16
23
|
}
|
17
24
|
return {
|
18
25
|
reference: documentReference,
|
19
26
|
data
|
20
|
-
} satisfies
|
27
|
+
} satisfies DocumentSnapshot<typeof reference>
|
21
28
|
}
|
22
29
|
|
23
|
-
const getCollection:
|
30
|
+
const getCollection: Adapter.getCollection = async (reference) => {
|
24
31
|
const collection = await firestore.collection(reference.name).get()
|
25
|
-
const documents:
|
32
|
+
const documents: CollectionSnapshot<typeof reference> = []
|
26
33
|
|
27
34
|
collection.forEach(document => {
|
28
|
-
const documentData:
|
35
|
+
const documentData: Document<typeof reference.schema> = {}
|
29
36
|
Object.keys(reference.schema.properties).forEach(key => {
|
30
37
|
documentData[key] = document.get(key)
|
31
38
|
})
|
@@ -35,35 +42,35 @@ const getCollection: databaseT.getCollection = async (reference) => {
|
|
35
42
|
collection: reference,
|
36
43
|
id: document.id
|
37
44
|
},
|
38
|
-
data: document.data() as
|
45
|
+
data: document.data() as Document<typeof reference.schema>
|
39
46
|
})
|
40
47
|
})
|
41
48
|
return documents
|
42
49
|
}
|
43
50
|
|
44
|
-
const getDocument:
|
51
|
+
const getDocument: Adapter.getDocument = async ({ collection, id }) => {
|
45
52
|
const document = await firestore.collection(collection.name).doc(id).get()
|
46
53
|
if (!document.exists) return undefined
|
47
|
-
const documentReference:
|
54
|
+
const documentReference: DocumentReference<typeof collection> = {
|
48
55
|
collection,
|
49
56
|
id
|
50
57
|
}
|
51
|
-
const documentSnapshot:
|
58
|
+
const documentSnapshot: DocumentSnapshot<typeof collection> = {
|
52
59
|
reference: documentReference,
|
53
|
-
data: document.data() as
|
60
|
+
data: document.data() as Document<typeof collection>
|
54
61
|
}
|
55
62
|
return documentSnapshot
|
56
63
|
}
|
57
64
|
|
58
|
-
const updateDocument:
|
65
|
+
const updateDocument: Adapter.updateDocument = async (reference, document) => {
|
59
66
|
await firestore.collection(reference.collection.name).doc(reference.id).update(document)
|
60
67
|
return {
|
61
68
|
reference,
|
62
69
|
data: document
|
63
|
-
} satisfies
|
70
|
+
} satisfies UpdateSnapshot<typeof reference.collection>
|
64
71
|
}
|
65
72
|
|
66
|
-
const deleteDocument:
|
73
|
+
const deleteDocument: Adapter.deleteDocument = async (reference) => {
|
67
74
|
await firestore.collection(reference.collection.name).doc(reference.id).delete()
|
68
75
|
}
|
69
76
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type {
|
2
|
-
|
3
|
-
|
2
|
+
Adapter,
|
3
|
+
StorageObject
|
4
4
|
} from '@genoacms/cloudabstraction/storage'
|
5
5
|
import { type Bucket, Storage, type File } from '@google-cloud/storage'
|
6
6
|
import config from '../../config.js'
|
@@ -15,7 +15,7 @@ const getBucket = (name: string): Bucket => {
|
|
15
15
|
return bucket
|
16
16
|
}
|
17
17
|
|
18
|
-
const getObject: Adapter
|
18
|
+
const getObject: Adapter.getObject = async ({ bucket, name }) => {
|
19
19
|
const bucketInstance = getBucket(bucket)
|
20
20
|
const file = bucketInstance.file(name)
|
21
21
|
|
@@ -24,13 +24,13 @@ const getObject: Adapter['getObject'] = async ({ bucket, name }) => {
|
|
24
24
|
}
|
25
25
|
}
|
26
26
|
|
27
|
-
const getPublicURL: Adapter
|
27
|
+
const getPublicURL: Adapter.getPublicURL = async ({ bucket, name }) => {
|
28
28
|
const bucketInstance = getBucket(bucket)
|
29
29
|
const file = bucketInstance.file(name)
|
30
30
|
return file.publicUrl()
|
31
31
|
}
|
32
32
|
|
33
|
-
const getSignedURL: Adapter
|
33
|
+
const getSignedURL: Adapter.getSignedURL = async ({ bucket, name }) => {
|
34
34
|
const bucketInstance = getBucket(bucket)
|
35
35
|
const file = bucketInstance.file(name)
|
36
36
|
const expires = new Date()
|
@@ -42,19 +42,19 @@ const getSignedURL: Adapter['getSignedURL'] = async ({ bucket, name }) => {
|
|
42
42
|
return url
|
43
43
|
}
|
44
44
|
|
45
|
-
const uploadObject: Adapter
|
45
|
+
const uploadObject: Adapter.uploadObject = async ({ bucket, name }, stream) => {
|
46
46
|
const bucketInstance = getBucket(bucket)
|
47
47
|
const file = bucketInstance.file(name)
|
48
48
|
await file.save(stream)
|
49
49
|
}
|
50
50
|
|
51
|
-
const deleteObject: Adapter
|
51
|
+
const deleteObject: Adapter.deleteObject = async ({ bucket, name }) => {
|
52
52
|
const bucketInstance = getBucket(bucket)
|
53
53
|
const file = bucketInstance.file(name)
|
54
54
|
await file.delete()
|
55
55
|
}
|
56
56
|
|
57
|
-
const listDirectory: Adapter
|
57
|
+
const listDirectory: Adapter.listDirectory = async ({ bucket, name }, listingParams = {}) => {
|
58
58
|
const bucketInstance = getBucket(bucket)
|
59
59
|
const options = {
|
60
60
|
autoPaginate: false,
|
@@ -81,7 +81,7 @@ const listDirectory: Adapter['listDirectory'] = async ({ bucket, name }, listing
|
|
81
81
|
}
|
82
82
|
}
|
83
83
|
|
84
|
-
const createDirectory: Adapter
|
84
|
+
const createDirectory: Adapter.createDirectory = async ({ bucket, name }) => {
|
85
85
|
const bucketInstance = getBucket(bucket)
|
86
86
|
const file = bucketInstance.file(`${name}/.folderPlaceholder`)
|
87
87
|
await file.save('')
|