@payloadcms/storage-azure 3.0.0-alpha.63 → 3.0.0-alpha.65

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":"AACA,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAUpD,MAAM,MAAM,mBAAmB,GAAG;IAChC,oBAAoB,EAAE,OAAO,CAAA;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IAEtE;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,kBAAkB,GAAG,CAAC,gBAAgB,EAAE,mBAAmB,KAAK,MAAM,CAAA;AAE3E,eAAO,MAAM,YAAY,EAAE,kBA0BxB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAUpD,MAAM,MAAM,mBAAmB,GAAG;IAChC,oBAAoB,EAAE,OAAO,CAAA;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IAEtE;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,kBAAkB,GAAG,CAAC,gBAAgB,EAAE,mBAAmB,KAAK,MAAM,CAAA;AAE3E,eAAO,MAAM,YAAY,EAAE,kBA4CxB,CAAA"}
package/dist/index.js CHANGED
@@ -17,9 +17,25 @@ export const azureStorage = (azureStorageOptions)=>(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 azureStorageInternal({ allowContainerCreate, baseURL, connectionString, containerName }) {
25
41
  let storageClient = null;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\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 { BlobServiceClient } from '@azure/storage-blob'\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 type AzureStorageOptions = {\n allowContainerCreate: boolean\n baseURL: string\n /**\n * Collection options to apply the Azure Blob adapter to.\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\n\n /**\n * Azure Blob storage connection string\n */\n connectionString: string\n\n /**\n * Azure Blob storage container name\n */\n containerName: string\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n}\n\ntype AzureStoragePlugin = (azureStorageArgs: AzureStorageOptions) => Plugin\n\nexport const azureStorage: AzureStoragePlugin =\n (azureStorageOptions: AzureStorageOptions) =>\n (incomingConfig: Config): Config => {\n if (azureStorageOptions.enabled === false) {\n return incomingConfig\n }\n\n const adapter = azureStorageInternal(azureStorageOptions)\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n azureStorageOptions.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 azureStorageInternal({\n allowContainerCreate,\n baseURL,\n connectionString,\n containerName,\n}: AzureStorageOptions): Adapter {\n let storageClient: ContainerClient | null = null\n const getStorageClient = () => {\n if (storageClient) return storageClient\n\n const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString)\n storageClient = blobServiceClient.getContainerClient(containerName)\n return storageClient\n }\n\n const createContainerIfNotExists = () => {\n void getStorageClient().createIfNotExists({ access: 'blob' })\n }\n\n return ({ collection, prefix }): GeneratedAdapter => {\n return {\n generateURL: getGenerateURL({ baseURL, containerName }),\n handleDelete: getHandleDelete({ collection, getStorageClient }),\n handleUpload: getHandleUpload({\n collection,\n getStorageClient,\n prefix,\n }),\n staticHandler: getHandler({ collection, getStorageClient }),\n ...(allowContainerCreate && { onInit: createContainerIfNotExists }),\n }\n }\n}\n"],"names":["BlobServiceClient","cloudStorage","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","azureStorage","azureStorageOptions","incomingConfig","enabled","adapter","azureStorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","allowContainerCreate","baseURL","connectionString","containerName","storageClient","getStorageClient","blobServiceClient","fromConnectionString","getContainerClient","createContainerIfNotExists","createIfNotExists","access","collection","prefix","generateURL","handleDelete","handleUpload","staticHandler","onInit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AASA,SAASA,iBAAiB,QAAQ,sBAAqB;AACvD,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,eACX,CAACC,sBACD,CAACC;QACC,IAAID,oBAAoBE,OAAO,KAAK,OAAO;YACzC,OAAOD;QACT;QAEA,MAAME,UAAUC,qBAAqBJ;QAErC,+CAA+C;QAC/C,MAAMK,yBAAmEC,OAAOC,OAAO,CACrFP,oBAAoBQ,WAAW,EAC/BC,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,qBAAqB,EAC5BS,oBAAoB,EACpBC,OAAO,EACPC,gBAAgB,EAChBC,aAAa,EACO;IACpB,IAAIC,gBAAwC;IAC5C,MAAMC,mBAAmB;QACvB,IAAID,eAAe,OAAOA;QAE1B,MAAME,oBAAoB1B,kBAAkB2B,oBAAoB,CAACL;QACjEE,gBAAgBE,kBAAkBE,kBAAkB,CAACL;QACrD,OAAOC;IACT;IAEA,MAAMK,6BAA6B;QACjC,KAAKJ,mBAAmBK,iBAAiB,CAAC;YAAEC,QAAQ;QAAO;IAC7D;IAEA,OAAO,CAAC,EAAEC,UAAU,EAAEC,MAAM,EAAE;QAC5B,OAAO;YACLC,aAAahC,eAAe;gBAAEmB;gBAASE;YAAc;YACrDY,cAAchC,gBAAgB;gBAAE6B;gBAAYP;YAAiB;YAC7DW,cAAchC,gBAAgB;gBAC5B4B;gBACAP;gBACAQ;YACF;YACAI,eAAehC,WAAW;gBAAE2B;gBAAYP;YAAiB;YACzD,GAAIL,wBAAwB;gBAAEkB,QAAQT;YAA2B,CAAC;QACpE;IACF;AACF"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\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 { BlobServiceClient } from '@azure/storage-blob'\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 type AzureStorageOptions = {\n allowContainerCreate: boolean\n baseURL: string\n /**\n * Collection options to apply the Azure Blob adapter to.\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\n\n /**\n * Azure Blob storage connection string\n */\n connectionString: string\n\n /**\n * Azure Blob storage container name\n */\n containerName: string\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n}\n\ntype AzureStoragePlugin = (azureStorageArgs: AzureStorageOptions) => Plugin\n\nexport const azureStorage: AzureStoragePlugin =\n (azureStorageOptions: AzureStorageOptions) =>\n (incomingConfig: Config): Config => {\n if (azureStorageOptions.enabled === false) {\n return incomingConfig\n }\n\n const adapter = azureStorageInternal(azureStorageOptions)\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n azureStorageOptions.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 azureStorageInternal({\n allowContainerCreate,\n baseURL,\n connectionString,\n containerName,\n}: AzureStorageOptions): Adapter {\n let storageClient: ContainerClient | null = null\n const getStorageClient = () => {\n if (storageClient) return storageClient\n\n const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString)\n storageClient = blobServiceClient.getContainerClient(containerName)\n return storageClient\n }\n\n const createContainerIfNotExists = () => {\n void getStorageClient().createIfNotExists({ access: 'blob' })\n }\n\n return ({ collection, prefix }): GeneratedAdapter => {\n return {\n generateURL: getGenerateURL({ baseURL, containerName }),\n handleDelete: getHandleDelete({ collection, getStorageClient }),\n handleUpload: getHandleUpload({\n collection,\n getStorageClient,\n prefix,\n }),\n staticHandler: getHandler({ collection, getStorageClient }),\n ...(allowContainerCreate && { onInit: createContainerIfNotExists }),\n }\n }\n}\n"],"names":["BlobServiceClient","cloudStorage","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","azureStorage","azureStorageOptions","incomingConfig","enabled","adapter","azureStorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","allowContainerCreate","baseURL","connectionString","containerName","storageClient","getStorageClient","blobServiceClient","fromConnectionString","getContainerClient","createContainerIfNotExists","createIfNotExists","access","prefix","generateURL","handleDelete","handleUpload","staticH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BC,aAAa,EACO;IACpB,IAAIC,gBAAwC;IAC5C,MAAMC,mBAAmB;QACvB,IAAID,eAAe,OAAOA;QAE1B,MAAME,oBAAoB/B,kBAAkBgC,oBAAoB,CAACL;QACjEE,gBAAgBE,kBAAkBE,kBAAkB,CAACL;QACrD,OAAOC;IACT;IAEA,MAAMK,6BAA6B;QACjC,KAAKJ,mBAAmBK,iBAAiB,CAAC;YAAEC,QAAQ;QAAO;IAC7D;IAEA,OAAO,CAAC,EAAEd,UAAU,EAAEe,MAAM,EAAE;QAC5B,OAAO;YACLC,aAAapC,eAAe;gBAAEwB;gBAASE;YAAc;YACrDW,cAAcpC,gBAAgB;gBAAEmB;gBAAYQ;YAAiB;YAC7DU,cAAcpC,gBAAgB;gBAC5BkB;gBACAQ;gBACAO;YACF;YACAI,eAAepC,WAAW;gBAAEiB;gBAAYQ;YAAiB;YACzD,GAAIL,wBAAwB;gBAAEiB,QAAQR;YAA2B,CAAC;QACpE;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-azure",
3
- "version": "3.0.0-alpha.63",
3
+ "version": "3.0.0-alpha.65",
4
4
  "description": "Payload storage adapter for Azure Blob Storage",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,14 +24,14 @@
24
24
  "@azure/abort-controller": "^1.1.0",
25
25
  "@azure/storage-blob": "^12.11.0",
26
26
  "range-parser": "^1.2.1",
27
- "@payloadcms/plugin-cloud-storage": "3.0.0-alpha.63"
27
+ "@payloadcms/plugin-cloud-storage": "3.0.0-alpha.65"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/range-parser": "^1.2.7",
31
- "payload": "3.0.0-alpha.63"
31
+ "payload": "3.0.0-alpha.65"
32
32
  },
33
33
  "peerDependencies": {
34
- "payload": "3.0.0-alpha.63"
34
+ "payload": "3.0.0-alpha.65"
35
35
  },
36
36
  "engines": {
37
37
  "node": ">=18.20.2"
package/src/index.ts DELETED
@@ -1,106 +0,0 @@
1
- import type { ContainerClient } from '@azure/storage-blob'
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 { BlobServiceClient } from '@azure/storage-blob'
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 type AzureStorageOptions = {
19
- allowContainerCreate: boolean
20
- baseURL: string
21
- /**
22
- * Collection options to apply the Azure Blob adapter to.
23
- */
24
- collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>
25
-
26
- /**
27
- * Azure Blob storage connection string
28
- */
29
- connectionString: string
30
-
31
- /**
32
- * Azure Blob storage container name
33
- */
34
- containerName: string
35
-
36
- /**
37
- * Whether or not to enable the plugin
38
- *
39
- * Default: true
40
- */
41
- enabled?: boolean
42
- }
43
-
44
- type AzureStoragePlugin = (azureStorageArgs: AzureStorageOptions) => Plugin
45
-
46
- export const azureStorage: AzureStoragePlugin =
47
- (azureStorageOptions: AzureStorageOptions) =>
48
- (incomingConfig: Config): Config => {
49
- if (azureStorageOptions.enabled === false) {
50
- return incomingConfig
51
- }
52
-
53
- const adapter = azureStorageInternal(azureStorageOptions)
54
-
55
- // Add adapter to each collection option object
56
- const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(
57
- azureStorageOptions.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 azureStorageInternal({
75
- allowContainerCreate,
76
- baseURL,
77
- connectionString,
78
- containerName,
79
- }: AzureStorageOptions): Adapter {
80
- let storageClient: ContainerClient | null = null
81
- const getStorageClient = () => {
82
- if (storageClient) return storageClient
83
-
84
- const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString)
85
- storageClient = blobServiceClient.getContainerClient(containerName)
86
- return storageClient
87
- }
88
-
89
- const createContainerIfNotExists = () => {
90
- void getStorageClient().createIfNotExists({ access: 'blob' })
91
- }
92
-
93
- return ({ collection, prefix }): GeneratedAdapter => {
94
- return {
95
- generateURL: getGenerateURL({ baseURL, containerName }),
96
- handleDelete: getHandleDelete({ collection, getStorageClient }),
97
- handleUpload: getHandleUpload({
98
- collection,
99
- getStorageClient,
100
- prefix,
101
- }),
102
- staticHandler: getHandler({ collection, getStorageClient }),
103
- ...(allowContainerCreate && { onInit: createContainerIfNotExists }),
104
- }
105
- }
106
- }