@payloadcms/storage-gcs 3.0.0-alpha.63 → 3.0.0-beta.12

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAUpD,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;IAE1B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IACtE;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,OAAO,EAAE,cAAc,CAAA;CACxB;AAED,KAAK,gBAAgB,GAAG,CAAC,cAAc,EAAE,iBAAiB,KAAK,MAAM,CAAA;AAErE,eAAO,MAAM,UAAU,EAAE,gBA0BtB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAUpD,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;IAE1B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IACtE;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,OAAO,EAAE,cAAc,CAAA;CACxB;AAED,KAAK,gBAAgB,GAAG,CAAC,cAAc,EAAE,iBAAiB,KAAK,MAAM,CAAA;AAErE,eAAO,MAAM,UAAU,EAAE,gBA4CtB,CAAA"}
package/dist/index.js CHANGED
@@ -17,9 +17,25 @@ export const gcsStorage = (gcsStorageOptions)=>(incomingConfig)=>{
17
17
  adapter
18
18
  }
19
19
  }), {});
20
+ // Set disableLocalStorage: true for collections specified in the plugin options
21
+ const config = {
22
+ ...incomingConfig,
23
+ collections: (incomingConfig.collections || []).map((collection)=>{
24
+ if (!collectionsWithAdapter[collection.slug]) {
25
+ return collection;
26
+ }
27
+ return {
28
+ ...collection,
29
+ upload: {
30
+ ...typeof collection.upload === 'object' ? collection.upload : {},
31
+ disableLocalStorage: true
32
+ }
33
+ };
34
+ })
35
+ };
20
36
  return cloudStorage({
21
37
  collections: collectionsWithAdapter
22
- })(incomingConfig);
38
+ })(config);
23
39
  };
24
40
  function gcsStorageInternal({ acl, bucket, options }) {
25
41
  return ({ collection, prefix })=>{
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { StorageOptions } from '@google-cloud/storage'\nimport type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload/config'\n\nimport { Storage } from '@google-cloud/storage'\nimport { cloudStorage } from '@payloadcms/plugin-cloud-storage'\n\nimport { getGenerateURL } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.js'\n\nexport interface GcsStorageOptions {\n acl?: 'Private' | 'Public'\n\n /**\n * The name of the bucket to use.\n */\n bucket: string\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n\n /**\n * Google Cloud Storage client configuration.\n *\n * @see https://github.com/googleapis/nodejs-storage\n */\n options: StorageOptions\n}\n\ntype GcsStoragePlugin = (gcsStorageArgs: GcsStorageOptions) => Plugin\n\nexport const gcsStorage: GcsStoragePlugin =\n (gcsStorageOptions: GcsStorageOptions) =>\n (incomingConfig: Config): Config => {\n if (gcsStorageOptions.enabled === false) {\n return incomingConfig\n }\n\n const adapter = gcsStorageInternal(gcsStorageOptions)\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n gcsStorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n return cloudStorage({\n collections: collectionsWithAdapter,\n })(incomingConfig)\n }\n\nfunction gcsStorageInternal({ acl, bucket, options }: GcsStorageOptions): Adapter {\n return ({ collection, prefix }): GeneratedAdapter => {\n let storageClient: Storage | null = null\n\n const getStorageClient = (): Storage => {\n if (storageClient) return storageClient\n storageClient = new Storage(options)\n return storageClient\n }\n\n return {\n generateURL: getGenerateURL({ bucket, getStorageClient }),\n handleDelete: getHandleDelete({ bucket, getStorageClient }),\n handleUpload: getHandleUpload({\n acl,\n bucket,\n collection,\n getStorageClient,\n prefix,\n }),\n staticHandler: getHandler({ bucket, collection, getStorageClient }),\n }\n }\n}\n"],"names":["Storage","cloudStorage","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","gcsStorage","gcsStorageOptions","incomingConfig","enabled","adapter","gcsStorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","acl","bucket","options","collection","prefix","storageClient","getStorageClient","generateURL","handleDelete","handleUpload","staticHandler"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AASA,SAASA,OAAO,QAAQ,wBAAuB;AAC/C,SAASC,YAAY,QAAQ,mCAAkC;AAE/D,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,UAAU,QAAQ,qBAAoB;AA8B/C,OAAO,MAAMC,aACX,CAACC,oBACD,CAACC;QACC,IAAID,kBAAkBE,OAAO,KAAK,OAAO;YACvC,OAAOD;QACT;QAEA,MAAME,UAAUC,mBAAmBJ;QAEnC,+CAA+C;QAC/C,MAAMK,yBAAmEC,OAAOC,OAAO,CACrFP,kBAAkBQ,WAAW,EAC7BC,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;gBAC7B,GAAGF,GAAG;gBACN,CAACC,KAAK,EAAE;oBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAC3CT;gBACF;YACF,CAAA,GACA,CAAC;QAGH,OAAOT,aAAa;YAClBc,aAAaH;QACf,GAAGJ;IACL,EAAC;AAEH,SAASG,mBAAmB,EAAES,GAAG,EAAEC,MAAM,EAAEC,OAAO,EAAqB;IACrE,OAAO,CAAC,EAAEC,UAAU,EAAEC,MAAM,EAAE;QAC5B,IAAIC,gBAAgC;QAEpC,MAAMC,mBAAmB;YACvB,IAAID,eAAe,OAAOA;YAC1BA,gBAAgB,IAAIzB,QAAQsB;YAC5B,OAAOG;QACT;QAEA,OAAO;YACLE,aAAazB,eAAe;gBAAEmB;gBAAQK;YAAiB;YACvDE,cAAczB,gBAAgB;gBAAEkB;gBAAQK;YAAiB;YACzDG,cAAczB,gBAAgB;gBAC5BgB;gBACAC;gBACAE;gBACAG;gBACAF;YACF;YACAM,eAAezB,WAAW;gBAAEgB;gBAAQE;gBAAYG;YAAiB;QACnE;IACF;AACF"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { StorageOptions } from '@google-cloud/storage'\nimport type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload/config'\n\nimport { Storage } from '@google-cloud/storage'\nimport { cloudStorage } from '@payloadcms/plugin-cloud-storage'\n\nimport { getGenerateURL } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.js'\n\nexport interface GcsStorageOptions {\n acl?: 'Private' | 'Public'\n\n /**\n * The name of the bucket to use.\n */\n bucket: string\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n\n /**\n * Google Cloud Storage client configuration.\n *\n * @see https://github.com/googleapis/nodejs-storage\n */\n options: StorageOptions\n}\n\ntype GcsStoragePlugin = (gcsStorageArgs: GcsStorageOptions) => Plugin\n\nexport const gcsStorage: GcsStoragePlugin =\n (gcsStorageOptions: GcsStorageOptions) =>\n (incomingConfig: Config): Config => {\n if (gcsStorageOptions.enabled === false) {\n return incomingConfig\n }\n\n const adapter = gcsStorageInternal(gcsStorageOptions)\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n gcsStorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStorage({\n collections: collectionsWithAdapter,\n })(config)\n }\n\nfunction gcsStorageInternal({ acl, bucket, options }: GcsStorageOptions): Adapter {\n return ({ collection, prefix }): GeneratedAdapter => {\n let storageClient: Storage | null = null\n\n const getStorageClient = (): Storage => {\n if (storageClient) return storageClient\n storageClient = new Storage(options)\n return storageClient\n }\n\n return {\n generateURL: getGenerateURL({ bucket, getStorageClient }),\n handleDelete: getHandleDelete({ bucket, getStorageClient }),\n handleUpload: getHandleUpload({\n acl,\n bucket,\n collection,\n getStorageClient,\n prefix,\n }),\n staticHandler: getHandler({ bucket, collection, getStorageClient }),\n }\n }\n}\n"],"names":["Storage","cloudStorage","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","gcsStorage","gcsStorageOptions","incomingConfig","enabled","adapter","gcsStorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","acl","bucket","options","prefix","storageClient","getStorageClient","generateURL","handleDelete","handleUpload","staticHandler"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AASA,SAASA,OAAO,QAAQ,wBAAuB;AAC/C,SAASC,YAAY,QAAQ,mCAAkC;AAE/D,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,UAAU,QAAQ,qBAAoB;AA8B/C,OAAO,MAAMC,aACX,CAACC,oBACD,CAACC;QACC,IAAID,kBAAkBE,OAAO,KAAK,OAAO;YACvC,OAAOD;QACT;QAEA,MAAME,UAAUC,mBAAmBJ;QAEnC,+CAA+C;QAC/C,MAAMK,yBAAmEC,OAAOC,OAAO,CACrFP,kBAAkBQ,WAAW,EAC7BC,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;gBAC7B,GAAGF,GAAG;gBACN,CAACC,KAAK,EAAE;oBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAC3CT;gBACF;YACF,CAAA,GACA,CAAC;QAGH,gFAAgF;QAChF,MAAMU,SAAS;YACb,GAAGZ,cAAc;YACjBO,aAAa,AAACP,CAAAA,eAAeO,WAAW,IAAI,EAAE,AAAD,EAAGM,GAAG,CAAC,CAACC;gBACnD,IAAI,CAACV,sBAAsB,CAACU,WAAWJ,IAAI,CAAC,EAAE;oBAC5C,OAAOI;gBACT;gBAEA,OAAO;oBACL,GAAGA,UAAU;oBACbC,QAAQ;wBACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;wBAClEC,qBAAqB;oBACvB;gBACF;YACF;QACF;QAEA,OAAOvB,aAAa;YAClBc,aAAaH;QACf,GAAGQ;IACL,EAAC;AAEH,SAAST,mBAAmB,EAAEc,GAAG,EAAEC,MAAM,EAAEC,OAAO,EAAqB;IACrE,OAAO,CAAC,EAAEL,UAAU,EAAEM,MAAM,EAAE;QAC5B,IAAIC,gBAAgC;QAEpC,MAAMC,mBAAmB;YACvB,IAAID,eAAe,OAAOA;YAC1BA,gBAAgB,IAAI7B,QAAQ2B;YAC5B,OAAOE;QACT;QAEA,OAAO;YACLE,aAAa7B,eAAe;gBAAEwB;gBAAQI;YAAiB;YACvDE,cAAc7B,gBAAgB;gBAAEuB;gBAAQI;YAAiB;YACzDG,cAAc7B,gBAAgB;gBAC5BqB;gBACAC;gBACAJ;gBACAQ;gBACAF;YACF;YACAM,eAAe7B,WAAW;gBAAEqB;gBAAQJ;gBAAYQ;YAAiB;QACnE;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-gcs",
3
- "version": "3.0.0-alpha.63",
3
+ "version": "3.0.0-beta.12",
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.63"
25
+ "@payloadcms/plugin-cloud-storage": "3.0.0-beta.12"
26
26
  },
27
27
  "devDependencies": {
28
- "payload": "3.0.0-alpha.63"
28
+ "payload": "3.0.0-beta.12"
29
29
  },
30
30
  "peerDependencies": {
31
- "payload": "3.0.0-alpha.63"
31
+ "payload": "3.0.0-beta.12"
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
- }