@payloadcms/storage-gcs 3.0.0-alpha.62 → 3.0.0-alpha.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/index.ts +0 -97
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-gcs",
3
- "version": "3.0.0-alpha.62",
3
+ "version": "3.0.0-alpha.64",
4
4
  "description": "Payload storage adapter for Google Cloud Storage",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,13 +22,13 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@google-cloud/storage": "^7.7.0",
25
- "@payloadcms/plugin-cloud-storage": "3.0.0-alpha.62"
25
+ "@payloadcms/plugin-cloud-storage": "3.0.0-alpha.64"
26
26
  },
27
27
  "devDependencies": {
28
- "payload": "3.0.0-alpha.62"
28
+ "payload": "3.0.0-alpha.64"
29
29
  },
30
30
  "peerDependencies": {
31
- "payload": "3.0.0-alpha.62"
31
+ "payload": "3.0.0-alpha.64"
32
32
  },
33
33
  "engines": {
34
34
  "node": ">=18.20.2"
package/src/index.ts DELETED
@@ -1,97 +0,0 @@
1
- import type { StorageOptions } from '@google-cloud/storage'
2
- import type {
3
- Adapter,
4
- PluginOptions as CloudStoragePluginOptions,
5
- CollectionOptions,
6
- GeneratedAdapter,
7
- } from '@payloadcms/plugin-cloud-storage/types'
8
- import type { Config, Plugin } from 'payload/config'
9
-
10
- import { Storage } from '@google-cloud/storage'
11
- import { cloudStorage } from '@payloadcms/plugin-cloud-storage'
12
-
13
- import { getGenerateURL } from './generateURL.js'
14
- import { getHandleDelete } from './handleDelete.js'
15
- import { getHandleUpload } from './handleUpload.js'
16
- import { getHandler } from './staticHandler.js'
17
-
18
- export interface GcsStorageOptions {
19
- acl?: 'Private' | 'Public'
20
-
21
- /**
22
- * The name of the bucket to use.
23
- */
24
- bucket: string
25
- /**
26
- * Collection options to apply the S3 adapter to.
27
- */
28
- collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>
29
- /**
30
- * Whether or not to enable the plugin
31
- *
32
- * Default: true
33
- */
34
- enabled?: boolean
35
-
36
- /**
37
- * Google Cloud Storage client configuration.
38
- *
39
- * @see https://github.com/googleapis/nodejs-storage
40
- */
41
- options: StorageOptions
42
- }
43
-
44
- type GcsStoragePlugin = (gcsStorageArgs: GcsStorageOptions) => Plugin
45
-
46
- export const gcsStorage: GcsStoragePlugin =
47
- (gcsStorageOptions: GcsStorageOptions) =>
48
- (incomingConfig: Config): Config => {
49
- if (gcsStorageOptions.enabled === false) {
50
- return incomingConfig
51
- }
52
-
53
- const adapter = gcsStorageInternal(gcsStorageOptions)
54
-
55
- // Add adapter to each collection option object
56
- const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(
57
- gcsStorageOptions.collections,
58
- ).reduce(
59
- (acc, [slug, collOptions]) => ({
60
- ...acc,
61
- [slug]: {
62
- ...(collOptions === true ? {} : collOptions),
63
- adapter,
64
- },
65
- }),
66
- {} as Record<string, CollectionOptions>,
67
- )
68
-
69
- return cloudStorage({
70
- collections: collectionsWithAdapter,
71
- })(incomingConfig)
72
- }
73
-
74
- function gcsStorageInternal({ acl, bucket, options }: GcsStorageOptions): Adapter {
75
- return ({ collection, prefix }): GeneratedAdapter => {
76
- let storageClient: Storage | null = null
77
-
78
- const getStorageClient = (): Storage => {
79
- if (storageClient) return storageClient
80
- storageClient = new Storage(options)
81
- return storageClient
82
- }
83
-
84
- return {
85
- generateURL: getGenerateURL({ bucket, getStorageClient }),
86
- handleDelete: getHandleDelete({ bucket, getStorageClient }),
87
- handleUpload: getHandleUpload({
88
- acl,
89
- bucket,
90
- collection,
91
- getStorageClient,
92
- prefix,
93
- }),
94
- staticHandler: getHandler({ bucket, collection, getStorageClient }),
95
- }
96
- }
97
- }