@genoacms/adapter-gcp 0.5.2-fix.9 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/services/authorization/index.js +3 -0
- package/dist/services/database/index.d.ts +5 -5
- package/dist/services/database/index.js +6 -3
- package/dist/services/deployment/index.js +1 -1
- package/dist/services/storage/index.d.ts +7 -7
- package/dist/services/storage/storage.js +3 -0
- package/package.json +8 -5
- package/src/services/authorization/index.ts +3 -1
- package/src/services/database/index.ts +11 -8
- package/src/services/deployment/index.ts +1 -1
- package/src/services/storage/index.ts +7 -7
- package/src/services/storage/storage.ts +3 -0
@@ -1,5 +1,8 @@
|
|
1
1
|
import config from '../../config.js';
|
2
2
|
import { ProjectsClient } from '@google-cloud/resource-manager';
|
3
|
+
const authorizationConfig = config.authorization.providers.find((provider) => provider.name === 'gcp');
|
4
|
+
if (!authorizationConfig)
|
5
|
+
throw new Error('authorization-provider-not-found');
|
3
6
|
const resourceManager = new ProjectsClient({
|
4
7
|
projectId: config.authorization.projectId,
|
5
8
|
credentials: config.authorization.credentials
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { Adapter } from '@genoacms/cloudabstraction/database';
|
2
|
-
declare const createDocument: Adapter
|
3
|
-
declare const getCollection: Adapter
|
4
|
-
declare const getDocument: Adapter
|
5
|
-
declare const updateDocument: Adapter
|
6
|
-
declare const deleteDocument: Adapter
|
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,12 @@
|
|
1
1
|
import config from '../../config.js';
|
2
2
|
import { Firestore } from '@google-cloud/firestore';
|
3
|
+
const firestoreConfig = config.database.providers.find((provider) => provider.name === 'firestore');
|
4
|
+
if (!firestoreConfig)
|
5
|
+
throw new Error('firestore-provider-not-found');
|
3
6
|
const firestore = new Firestore({
|
4
|
-
credentials:
|
5
|
-
databaseId:
|
6
|
-
projectId:
|
7
|
+
credentials: firestoreConfig.credentials,
|
8
|
+
databaseId: firestoreConfig.databaseId,
|
9
|
+
projectId: firestoreConfig.projectId
|
7
10
|
});
|
8
11
|
const createDocument = async (reference, data) => {
|
9
12
|
const document = await firestore.collection(reference.name).add(data);
|
@@ -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 };
|
@@ -1,5 +1,8 @@
|
|
1
1
|
import config from '../../config.js';
|
2
2
|
import { Storage } from '@google-cloud/storage';
|
3
|
+
const storageConfig = config.storage.providers.find((provider) => provider.name === 'gcs');
|
4
|
+
if (!storageConfig)
|
5
|
+
throw new Error('storage-provider-not-found');
|
3
6
|
const storage = new Storage({
|
4
7
|
credentials: config.storage.credentials
|
5
8
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@genoacms/adapter-gcp",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.7.1",
|
4
|
+
"type": "module",
|
4
5
|
"description": "Implementation of abstraction layer of GenoaCMS for GCP",
|
5
6
|
"repository": {
|
6
7
|
"type": "git",
|
@@ -15,11 +16,13 @@
|
|
15
16
|
"url": "https://github.com/GenoaCMS/adapter-gcp/issues"
|
16
17
|
},
|
17
18
|
"homepage": "https://github.com/GenoaCMS/adapter-gcp#readme",
|
18
|
-
"
|
19
|
+
"publishConfig": {
|
20
|
+
"provenance": true
|
21
|
+
},
|
19
22
|
"dependencies": {
|
20
|
-
"@genoacms/cloudabstraction": "^0.
|
23
|
+
"@genoacms/cloudabstraction": "^0.7.1",
|
21
24
|
"@google-cloud/firestore": "^7.1.0",
|
22
|
-
"@google-cloud/functions": "^3.
|
25
|
+
"@google-cloud/functions": "^3.4.0",
|
23
26
|
"@google-cloud/resource-manager": "^5.1.0",
|
24
27
|
"@google-cloud/storage": "^7.7.0",
|
25
28
|
"archiver": "^7.0.0"
|
@@ -37,7 +40,7 @@
|
|
37
40
|
"vitest": "^1.0.4"
|
38
41
|
},
|
39
42
|
"peerDependencies": {
|
40
|
-
"@
|
43
|
+
"@genoacms/sveltekit-adapter-cloud-run-functions": "^1.0.0"
|
41
44
|
},
|
42
45
|
"files": [
|
43
46
|
"src",
|
@@ -1,7 +1,9 @@
|
|
1
|
-
import type { Adapter } from '@genoacms/cloudabstraction/authorization'
|
1
|
+
import type { Adapter, AuthorizationProvider } from '@genoacms/cloudabstraction/authorization'
|
2
2
|
import config from '../../config.js'
|
3
3
|
import { ProjectsClient } from '@google-cloud/resource-manager'
|
4
4
|
|
5
|
+
const authorizationConfig = config.authorization.providers.find((provider: AuthorizationProvider) => provider.name === 'gcp')
|
6
|
+
if (!authorizationConfig) throw new Error('authorization-provider-not-found')
|
5
7
|
const resourceManager = new ProjectsClient({
|
6
8
|
projectId: config.authorization.projectId,
|
7
9
|
credentials: config.authorization.credentials
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type {
|
2
2
|
Adapter,
|
3
|
+
DatabaseProvider,
|
3
4
|
CollectionSnapshot,
|
4
5
|
Document,
|
5
6
|
DocumentReference,
|
@@ -9,13 +10,15 @@ import type {
|
|
9
10
|
import config from '../../config.js'
|
10
11
|
import { Firestore } from '@google-cloud/firestore'
|
11
12
|
|
13
|
+
const firestoreConfig = config.database.providers.find((provider: DatabaseProvider) => provider.name === 'firestore')
|
14
|
+
if (!firestoreConfig) throw new Error('firestore-provider-not-found')
|
12
15
|
const firestore = new Firestore({
|
13
|
-
credentials:
|
14
|
-
databaseId:
|
15
|
-
projectId:
|
16
|
+
credentials: firestoreConfig.credentials,
|
17
|
+
databaseId: firestoreConfig.databaseId,
|
18
|
+
projectId: firestoreConfig.projectId
|
16
19
|
})
|
17
20
|
|
18
|
-
const createDocument: Adapter
|
21
|
+
const createDocument: Adapter['createDocument'] = async (reference, data) => {
|
19
22
|
const document = await firestore.collection(reference.name).add(data)
|
20
23
|
const documentReference: DocumentReference<typeof reference> = {
|
21
24
|
collection: reference,
|
@@ -27,7 +30,7 @@ const createDocument: Adapter.createDocument = async (reference, data) => {
|
|
27
30
|
} satisfies DocumentSnapshot<typeof reference>
|
28
31
|
}
|
29
32
|
|
30
|
-
const getCollection: Adapter
|
33
|
+
const getCollection: Adapter['getCollection'] = async (reference) => {
|
31
34
|
const collection = await firestore.collection(reference.name).get()
|
32
35
|
const documents: CollectionSnapshot<typeof reference> = []
|
33
36
|
|
@@ -48,7 +51,7 @@ const getCollection: Adapter.getCollection = async (reference) => {
|
|
48
51
|
return documents
|
49
52
|
}
|
50
53
|
|
51
|
-
const getDocument: Adapter
|
54
|
+
const getDocument: Adapter['getDocument'] = async ({ collection, id }) => {
|
52
55
|
const document = await firestore.collection(collection.name).doc(id).get()
|
53
56
|
if (!document.exists) return undefined
|
54
57
|
const documentReference: DocumentReference<typeof collection> = {
|
@@ -62,7 +65,7 @@ const getDocument: Adapter.getDocument = async ({ collection, id }) => {
|
|
62
65
|
return documentSnapshot
|
63
66
|
}
|
64
67
|
|
65
|
-
const updateDocument: Adapter
|
68
|
+
const updateDocument: Adapter['updateDocument'] = async (reference, document) => {
|
66
69
|
await firestore.collection(reference.collection.name).doc(reference.id).update(document)
|
67
70
|
return {
|
68
71
|
reference,
|
@@ -70,7 +73,7 @@ const updateDocument: Adapter.updateDocument = async (reference, document) => {
|
|
70
73
|
} satisfies UpdateSnapshot<typeof reference.collection>
|
71
74
|
}
|
72
75
|
|
73
|
-
const deleteDocument: Adapter
|
76
|
+
const deleteDocument: Adapter['deleteDocument'] = async (reference) => {
|
74
77
|
await firestore.collection(reference.collection.name).doc(reference.id).delete()
|
75
78
|
}
|
76
79
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { Adapter } from '@genoacms/cloudabstraction/deployment'
|
2
2
|
|
3
|
-
const svelteKitAdapter: Adapter.svelteKitAdapter = '@
|
3
|
+
const svelteKitAdapter: Adapter.svelteKitAdapter = '@genoacms/sveltekit-adapter-cloud-run-functions'
|
4
4
|
|
5
5
|
const deployProcedure: Adapter.deployProcedure = async () => {
|
6
6
|
const deploy = (await import('./deploy.js')).default
|
@@ -6,7 +6,7 @@ import { type File } from '@google-cloud/storage'
|
|
6
6
|
import { getBucket } from './storage.js'
|
7
7
|
import { join } from 'path'
|
8
8
|
|
9
|
-
const getObject: Adapter
|
9
|
+
const getObject: Adapter['getObject'] = async ({ bucket, name }) => {
|
10
10
|
const bucketInstance = getBucket(bucket)
|
11
11
|
const file = bucketInstance.file(name)
|
12
12
|
|
@@ -15,13 +15,13 @@ const getObject: Adapter.getObject = async ({ bucket, name }) => {
|
|
15
15
|
}
|
16
16
|
}
|
17
17
|
|
18
|
-
const getPublicURL: Adapter
|
18
|
+
const getPublicURL: Adapter['getPublicURL'] = async ({ bucket, name }) => {
|
19
19
|
const bucketInstance = getBucket(bucket)
|
20
20
|
const file = bucketInstance.file(name)
|
21
21
|
return file.publicUrl()
|
22
22
|
}
|
23
23
|
|
24
|
-
const getSignedURL: Adapter
|
24
|
+
const getSignedURL: Adapter['getSignedURL'] = async ({ bucket, name }, expires) => {
|
25
25
|
const bucketInstance = getBucket(bucket)
|
26
26
|
const file = bucketInstance.file(name)
|
27
27
|
const [url] = await file.getSignedUrl({
|
@@ -31,19 +31,19 @@ const getSignedURL: Adapter.getSignedURL = async ({ bucket, name }, expires) =>
|
|
31
31
|
return url
|
32
32
|
}
|
33
33
|
|
34
|
-
const uploadObject: Adapter
|
34
|
+
const uploadObject: Adapter['uploadObject'] = async ({ bucket, name }, stream, options) => {
|
35
35
|
const bucketInstance = getBucket(bucket)
|
36
36
|
const file = bucketInstance.file(name)
|
37
37
|
await file.save(stream, options)
|
38
38
|
}
|
39
39
|
|
40
|
-
const deleteObject: Adapter
|
40
|
+
const deleteObject: Adapter['deleteObject'] = async ({ bucket, name }) => {
|
41
41
|
const bucketInstance = getBucket(bucket)
|
42
42
|
const file = bucketInstance.file(name)
|
43
43
|
await file.delete()
|
44
44
|
}
|
45
45
|
|
46
|
-
const listDirectory: Adapter
|
46
|
+
const listDirectory: Adapter['listDirectory'] = async ({ bucket, name }, listingParams = {}) => {
|
47
47
|
const bucketInstance = getBucket(bucket)
|
48
48
|
const options = {
|
49
49
|
autoPaginate: false,
|
@@ -70,7 +70,7 @@ const listDirectory: Adapter.listDirectory = async ({ bucket, name }, listingPar
|
|
70
70
|
}
|
71
71
|
}
|
72
72
|
|
73
|
-
const createDirectory: Adapter
|
73
|
+
const createDirectory: Adapter['createDirectory'] = async ({ bucket, name }) => {
|
74
74
|
const bucketInstance = getBucket(bucket)
|
75
75
|
const file = bucketInstance.file(`${name}/.folderPlaceholder`)
|
76
76
|
await file.save('')
|
@@ -1,6 +1,9 @@
|
|
1
1
|
import config from '../../config.js'
|
2
2
|
import { type Bucket, Storage } from '@google-cloud/storage'
|
3
|
+
import type { StorageProvider } from '@genoacms/cloudabstraction/storage'
|
3
4
|
|
5
|
+
const storageConfig = config.storage.providers.find((provider: StorageProvider) => provider.name === 'gcs')
|
6
|
+
if (!storageConfig) throw new Error('storage-provider-not-found')
|
4
7
|
const storage = new Storage({
|
5
8
|
credentials: config.storage.credentials
|
6
9
|
})
|