@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 CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: Config<object, object, object, object>;
1
+ declare const _default: any;
2
2
  export default _default;
@@ -1,3 +1,3 @@
1
- import type { isEmailAdmins as isEmailAdminsT } from '@genoacms/cloudabstraction/authorization';
2
- declare const isEmailAdmins: isEmailAdminsT;
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 { database as databaseT } from '@genoacms/cloudabstraction';
2
- declare const createDocument: databaseT.createDocument;
3
- declare const getCollection: databaseT.getCollection;
4
- declare const getDocument: databaseT.getDocument;
5
- declare const updateDocument: databaseT.updateDocument;
6
- declare const deleteDocument: databaseT.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,5 +1,5 @@
1
- import { Firestore } from '@google-cloud/firestore';
2
1
  import config from '../../config.js';
2
+ import { Firestore } from '@google-cloud/firestore';
3
3
  const firestore = new Firestore({
4
4
  credentials: config.database.credentials,
5
5
  databaseId: config.database.databaseId,
@@ -1,9 +1,9 @@
1
1
  import type { Adapter } from '@genoacms/cloudabstraction/storage';
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'];
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.1",
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": "^0.4.0",
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
- "./auth": {
42
- "import": "./dist/services/auth/index.js",
43
- "types": "./dist/services/auth/index.d.ts"
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",
@@ -25,6 +25,6 @@ interface StorageConfig {
25
25
  buckets: string[]
26
26
  }
27
27
 
28
- interface ConfigGCP extends Config<object, DatabaseConfig, StorageConfig> {}
28
+ interface ConfigGCP extends Config<object, object, DatabaseConfig, StorageConfig> {}
29
29
 
30
30
  export default ConfigGCP
@@ -1,6 +1,6 @@
1
- import { ProjectsClient } from '@google-cloud/resource-manager'
1
+ import type { Adapter } from '@genoacms/cloudabstraction/authorization'
2
2
  import config from '../../config.js'
3
- import type { isEmailAdmins as isEmailAdminsT } from '@genoacms/cloudabstraction/authorization'
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: isEmailAdminsT = async (email: string) => {
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 { Firestore } from '@google-cloud/firestore'
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 type { database as databaseT } from '@genoacms/cloudabstraction'
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: databaseT.createDocument = async (reference, data) => {
18
+ const createDocument: Adapter.createDocument = async (reference, data) => {
12
19
  const document = await firestore.collection(reference.name).add(data)
13
- const documentReference: databaseT.DocumentReference<typeof reference> = {
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 databaseT.DocumentSnapshot<typeof reference>
27
+ } satisfies DocumentSnapshot<typeof reference>
21
28
  }
22
29
 
23
- const getCollection: databaseT.getCollection = async (reference) => {
30
+ const getCollection: Adapter.getCollection = async (reference) => {
24
31
  const collection = await firestore.collection(reference.name).get()
25
- const documents: databaseT.CollectionSnapshot<typeof reference> = []
32
+ const documents: CollectionSnapshot<typeof reference> = []
26
33
 
27
34
  collection.forEach(document => {
28
- const documentData: databaseT.Document<typeof reference.schema> = {}
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 databaseT.Document<typeof reference.schema>
45
+ data: document.data() as Document<typeof reference.schema>
39
46
  })
40
47
  })
41
48
  return documents
42
49
  }
43
50
 
44
- const getDocument: databaseT.getDocument = async ({ collection, id }) => {
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: databaseT.DocumentReference<typeof collection> = {
54
+ const documentReference: DocumentReference<typeof collection> = {
48
55
  collection,
49
56
  id
50
57
  }
51
- const documentSnapshot: databaseT.DocumentSnapshot<typeof collection> = {
58
+ const documentSnapshot: DocumentSnapshot<typeof collection> = {
52
59
  reference: documentReference,
53
- data: document.data() as databaseT.Document<typeof collection>
60
+ data: document.data() as Document<typeof collection>
54
61
  }
55
62
  return documentSnapshot
56
63
  }
57
64
 
58
- const updateDocument: databaseT.updateDocument = async (reference, document) => {
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 databaseT.UpdateSnapshot<typeof reference.collection>
70
+ } satisfies UpdateSnapshot<typeof reference.collection>
64
71
  }
65
72
 
66
- const deleteDocument: databaseT.deleteDocument = async (reference) => {
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
- StorageObject,
3
- Adapter
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['getObject'] = async ({ bucket, name }) => {
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['getPublicURL'] = async ({ bucket, name }) => {
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['getSignedURL'] = async ({ bucket, name }) => {
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['uploadObject'] = async ({ bucket, name }, stream) => {
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['deleteObject'] = async ({ bucket, name }) => {
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['listDirectory'] = async ({ bucket, name }, listingParams = {}) => {
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['createDirectory'] = async ({ bucket, name }) => {
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('')