@payloadcms/storage-gcs 4.0.0-canary.35 → 4.0.0-canary.37

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.
package/dist/index.d.ts CHANGED
@@ -3,16 +3,6 @@ import type { ClientUploadsConfig, CollectionOptions } from '@payloadcms/plugin-
3
3
  import type { StorageAdapter, UploadCollectionSlug } from 'payload';
4
4
  export interface GcsStorageOptions {
5
5
  acl?: 'Private' | 'Public';
6
- /**
7
- * When enabled, fields (like the prefix field) will always be inserted into
8
- * the collection schema regardless of whether the plugin is enabled. This
9
- * ensures a consistent schema across all environments.
10
- *
11
- * This will be enabled by default in Payload v4.
12
- *
13
- * @default false
14
- */
15
- alwaysInsertFields?: boolean;
16
6
  /**
17
7
  * The name of the bucket to use.
18
8
  */
@@ -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,EACV,mBAAmB,EAEnB,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAO3E,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;IAE1B;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAE5B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IAC7F;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;OAIG;IACH,OAAO,EAAE,cAAc,CAAA;IAEvB;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,KAAK,iBAAiB,GAAG,CAAC,cAAc,EAAE,iBAAiB,KAAK,cAAc,CAAA;AAI9E,eAAO,MAAM,UAAU,EAAE,iBAqEvB,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,EACV,mBAAmB,EAEnB,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAO3E,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;IAE1B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IAC7F;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;OAIG;IACH,OAAO,EAAE,cAAc,CAAA;IAEvB;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,KAAK,iBAAiB,GAAG,CAAC,cAAc,EAAE,iBAAiB,KAAK,cAAc,CAAA;AAI9E,eAAO,MAAM,UAAU,EAAE,iBAoFvB,CAAA"}
package/dist/index.js CHANGED
@@ -23,7 +23,20 @@ export const gcsStorage = (gcsStorageOptions)=>({
23
23
  });
24
24
  const isPluginDisabled = gcsStorageOptions.enabled === false;
25
25
  if (isPluginDisabled) {
26
- return incomingConfig;
26
+ // Still call cloudStoragePlugin with adapter: null so fields (like prefix) are
27
+ // inserted into the schema, keeping it consistent across environments.
28
+ const collectionsWithoutAdapter = Object.entries(gcsStorageOptions.collections).reduce((acc, [slug, collOptions])=>({
29
+ ...acc,
30
+ [slug]: {
31
+ ...collOptions === true ? {} : collOptions,
32
+ adapter: null
33
+ }
34
+ }), {});
35
+ return cloudStoragePlugin({
36
+ collections: collectionsWithoutAdapter,
37
+ enabled: false,
38
+ useCompositePrefixes: gcsStorageOptions.useCompositePrefixes
39
+ })(incomingConfig);
27
40
  }
28
41
  // Add adapter to each collection option object
29
42
  const collectionsWithAdapter = Object.entries(gcsStorageOptions.collections).reduce((acc, [slug, collOptions])=>({
@@ -50,7 +63,6 @@ export const gcsStorage = (gcsStorageOptions)=>({
50
63
  })
51
64
  };
52
65
  return cloudStoragePlugin({
53
- alwaysInsertFields: gcsStorageOptions.alwaysInsertFields,
54
66
  collections: collectionsWithAdapter,
55
67
  useCompositePrefixes: gcsStorageOptions.useCompositePrefixes
56
68
  })(config);
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 ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, StorageAdapter, UploadCollectionSlug } from 'payload'\n\nimport { Storage } from '@google-cloud/storage'\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport { createGcsAdapter } from './adapter.js'\n\nexport interface GcsStorageOptions {\n acl?: 'Private' | 'Public'\n\n /**\n * When enabled, fields (like the prefix field) will always be inserted into\n * the collection schema regardless of whether the plugin is enabled. This\n * ensures a consistent schema across all environments.\n *\n * This will be enabled by default in Payload v4.\n *\n * @default false\n */\n alwaysInsertFields?: boolean\n\n /**\n * The name of the bucket to use.\n */\n bucket: string\n /**\n * Optional cache key to identify the GCS storage client instance.\n * If not provided, a default key will be used.\n *\n * @default `gcs:containerName`\n */\n clientCacheKey?: string\n /**\n * Upload directly to GCS instead of through Payload. You must allow CORS PUT requests from your website.\n */\n clientUploads?: ClientUploadsConfig\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * Google Cloud Storage client configuration.\n *\n * @see https://github.com/googleapis/nodejs-storage\n */\n options: StorageOptions\n\n /**\n * When true, the collection-level prefix and document-level prefix are combined\n * (compositional). When false (default), a document prefix already within the\n * collection prefix is used as-is for new uploads; otherwise it is nested beneath it.\n * Existing files retain their stored prefixes for reads, URLs, and cleanup.\n *\n * Example with a document prefix already contained by the collection prefix:\n * - collection prefix: `uploads/`\n * - document prefix: `uploads/documents/`\n * - resulting prefix with useCompositePrefixes=true: `uploads/uploads/documents/`\n * - resulting prefix with useCompositePrefixes=false: `uploads/documents/`\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n\ntype GcsStorageFactory = (gcsStorageArgs: GcsStorageOptions) => StorageAdapter\n\nconst gcsClients = new Map<string, Storage>()\n\nexport const gcsStorage: GcsStorageFactory = (\n gcsStorageOptions: GcsStorageOptions,\n): StorageAdapter => ({\n name: 'gcs',\n collections: Object.keys(gcsStorageOptions.collections),\n init: (incomingConfig: Config): Config => {\n const cacheKey = gcsStorageOptions.clientCacheKey || `gcs:${gcsStorageOptions.bucket}`\n\n const getStorageClient = (): Storage => {\n if (gcsClients.has(cacheKey)) {\n return gcsClients.get(cacheKey)!\n }\n gcsClients.set(cacheKey, new Storage(gcsStorageOptions.options))\n\n return gcsClients.get(cacheKey)!\n }\n\n const adapter = createGcsAdapter({\n acl: gcsStorageOptions.acl,\n bucket: gcsStorageOptions.bucket,\n clientUploads: gcsStorageOptions.clientUploads,\n getStorageClient,\n useCompositePrefixes: gcsStorageOptions.useCompositePrefixes,\n })\n\n const isPluginDisabled = gcsStorageOptions.enabled === false\n\n if (isPluginDisabled) {\n return incomingConfig\n }\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 cloudStoragePlugin({\n alwaysInsertFields: gcsStorageOptions.alwaysInsertFields,\n collections: collectionsWithAdapter,\n useCompositePrefixes: gcsStorageOptions.useCompositePrefixes,\n })(config)\n },\n})\n"],"names":["Storage","cloudStoragePlugin","createGcsAdapter","gcsClients","Map","gcsStorage","gcsStorageOptions","name","collections","Object","keys","init","incomingConfig","cacheKey","clientCacheKey","bucket","getStorageClient","has","get","set","options","adapter","acl","clientUploads","useCompositePrefixes","isPluginDisabled","enabled","collectionsWithAdapter","entries","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","alwaysInsertFields"],"mappings":"AAQA,SAASA,OAAO,QAAQ,wBAAuB;AAC/C,SAASC,kBAAkB,QAAQ,mCAAkC;AAErE,SAASC,gBAAgB,QAAQ,eAAc;AAmE/C,MAAMC,aAAa,IAAIC;AAEvB,OAAO,MAAMC,aAAgC,CAC3CC,oBACoB,CAAA;QACpBC,MAAM;QACNC,aAAaC,OAAOC,IAAI,CAACJ,kBAAkBE,WAAW;QACtDG,MAAM,CAACC;YACL,MAAMC,WAAWP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AmB;gBACxBqC,oBAAoBhC,kBAAkBgC,kBAAkB;gBACxD9B,aAAamB;gBACbH,sBAAsBlB,kBAAkBkB,oBAAoB;YAC9D,GAAGS;QACL;IACF,CAAA,EAAE"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { StorageOptions } from '@google-cloud/storage'\nimport type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, StorageAdapter, UploadCollectionSlug } from 'payload'\n\nimport { Storage } from '@google-cloud/storage'\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport { createGcsAdapter } from './adapter.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 * Optional cache key to identify the GCS storage client instance.\n * If not provided, a default key will be used.\n *\n * @default `gcs:containerName`\n */\n clientCacheKey?: string\n /**\n * Upload directly to GCS instead of through Payload. You must allow CORS PUT requests from your website.\n */\n clientUploads?: ClientUploadsConfig\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * Google Cloud Storage client configuration.\n *\n * @see https://github.com/googleapis/nodejs-storage\n */\n options: StorageOptions\n\n /**\n * When true, the collection-level prefix and document-level prefix are combined\n * (compositional). When false (default), a document prefix already within the\n * collection prefix is used as-is for new uploads; otherwise it is nested beneath it.\n * Existing files retain their stored prefixes for reads, URLs, and cleanup.\n *\n * Example with a document prefix already contained by the collection prefix:\n * - collection prefix: `uploads/`\n * - document prefix: `uploads/documents/`\n * - resulting prefix with useCompositePrefixes=true: `uploads/uploads/documents/`\n * - resulting prefix with useCompositePrefixes=false: `uploads/documents/`\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n\ntype GcsStorageFactory = (gcsStorageArgs: GcsStorageOptions) => StorageAdapter\n\nconst gcsClients = new Map<string, Storage>()\n\nexport const gcsStorage: GcsStorageFactory = (\n gcsStorageOptions: GcsStorageOptions,\n): StorageAdapter => ({\n name: 'gcs',\n collections: Object.keys(gcsStorageOptions.collections),\n init: (incomingConfig: Config): Config => {\n const cacheKey = gcsStorageOptions.clientCacheKey || `gcs:${gcsStorageOptions.bucket}`\n\n const getStorageClient = (): Storage => {\n if (gcsClients.has(cacheKey)) {\n return gcsClients.get(cacheKey)!\n }\n gcsClients.set(cacheKey, new Storage(gcsStorageOptions.options))\n\n return gcsClients.get(cacheKey)!\n }\n\n const adapter = createGcsAdapter({\n acl: gcsStorageOptions.acl,\n bucket: gcsStorageOptions.bucket,\n clientUploads: gcsStorageOptions.clientUploads,\n getStorageClient,\n useCompositePrefixes: gcsStorageOptions.useCompositePrefixes,\n })\n\n const isPluginDisabled = gcsStorageOptions.enabled === false\n\n if (isPluginDisabled) {\n // Still call cloudStoragePlugin with adapter: null so fields (like prefix) are\n // inserted into the schema, keeping it consistent across environments.\n const collectionsWithoutAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n gcsStorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: { ...(collOptions === true ? {} : collOptions), adapter: null },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n return cloudStoragePlugin({\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: gcsStorageOptions.useCompositePrefixes,\n })(incomingConfig)\n }\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 cloudStoragePlugin({\n collections: collectionsWithAdapter,\n useCompositePrefixes: gcsStorageOptions.useCompositePrefixes,\n })(config)\n },\n})\n"],"names":["Storage","cloudStoragePlugin","createGcsAdapter","gcsClients","Map","gcsStorage","gcsStorageOptions","name","collections","Object","keys","init","incomingConfig","cacheKey","clientCacheKey","bucket","getStorageClient","has","get","set","options","adapter","acl","clientUploads","useCompositePrefixes","isPluginDisabled","enabled","collectionsWithoutAdapter","entries","reduce","acc","slug","collOptions","collectionsWithAdapter","config","map","collection","upload","disableLocalStorage"],"mappings":"AAQA,SAASA,OAAO,QAAQ,wBAAuB;AAC/C,SAASC,kBAAkB,QAAQ,mCAAkC;AAErE,SAASC,gBAAgB,QAAQ,eAAc;AAwD/C,MAAMC,aAAa,IAAIC;AAEvB,OAAO,MAAMC,aAAgC,CAC3CC,oBACoB,CAAA;QACpBC,MAAM;QACNC,aAAaC,OAAOC,IAAI,CAACJ,kBAAkBE,WAAW;QACtDG,MAAM,CAACC;YACL,MAAMC,WAAWP,kBAAkBQ,cAAc,IAAI,CAAC,IAAI,EAAER,kBAAkBS,MAAM,EAAE;YAEtF,MAAMC,mBAAmB;gBACvB,IAAIb,WAAWc,GAAG,CAACJ,WAAW;oBAC5B,OAAOV,WAAWe,GAAG,CAACL;gBACxB;gBACAV,WAAWgB,GAAG,CAACN,UAAU,IAAIb,QAAQM,kBAAkBc,OAAO;gBAE9D,OAAOjB,WAAWe,GAAG,CAACL;YACxB;YAEA,MAAMQ,UAAUnB,iBAAiB;gBAC/BoB,KAAKhB,kBAAkBgB,GAAG;gBAC1BP,QAAQT,kBAAkBS,MAAM;gBAChCQ,eAAejB,kBAAkBiB,aAAa;gBAC9CP;gBACAQ,sBAAsBlB,kBAAkBkB,oBAAoB;YAC9D;YAEA,MA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AA,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-gcs",
3
- "version": "4.0.0-canary.35",
3
+ "version": "4.0.0-canary.37",
4
4
  "description": "Payload storage adapter for Google Cloud Storage",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -33,13 +33,13 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@google-cloud/storage": "7.19.0",
36
- "@payloadcms/plugin-cloud-storage": "4.0.0-canary.35"
36
+ "@payloadcms/plugin-cloud-storage": "4.0.0-canary.37"
37
37
  },
38
38
  "devDependencies": {
39
- "payload": "4.0.0-canary.35"
39
+ "payload": "4.0.0-canary.37"
40
40
  },
41
41
  "peerDependencies": {
42
- "payload": "4.0.0-canary.35"
42
+ "payload": "4.0.0-canary.37"
43
43
  },
44
44
  "engines": {
45
45
  "node": ">=24.15.0"
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=generateUploadInstructions.createOnly.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateUploadInstructions.createOnly.spec.d.ts","sourceRoot":"","sources":["../src/generateUploadInstructions.createOnly.spec.ts"],"names":[],"mappings":""}
@@ -1,59 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
- vi.mock('@payloadcms/plugin-cloud-storage/utilities', ()=>({
3
- resolveSignedURLKey: vi.fn(async ()=>({
4
- storageFilePath: 'reference.png',
5
- sanitizedDocPrefix: '',
6
- sanitizedFilename: 'reference.png'
7
- }))
8
- }));
9
- import { generateUploadInstructions } from './generateUploadInstructions.js';
10
- describe('generateUploadInstructions', ()=>{
11
- it('should issue create-only GCS upload instructions', async ()=>{
12
- const getSignedUrl = vi.fn(async ()=>[
13
- 'https://example.com/reference.png'
14
- ]);
15
- const generate = generateUploadInstructions({
16
- bucket: 'media',
17
- collectionPrefix: '',
18
- getStorageClient: ()=>({
19
- bucket: ()=>({
20
- file: ()=>({
21
- getSignedUrl
22
- })
23
- })
24
- })
25
- });
26
- const instructions = await generate({
27
- collectionSlug: 'media',
28
- filename: 'reference.png',
29
- filesize: 100,
30
- mimeType: 'image/png',
31
- overrideAccess: true,
32
- req: {
33
- payload: {
34
- collections: {
35
- media: {
36
- config: {
37
- upload: true
38
- }
39
- }
40
- }
41
- }
42
- }
43
- });
44
- expect(getSignedUrl).toHaveBeenCalledWith(expect.objectContaining({
45
- extensionHeaders: {
46
- 'x-goog-if-generation-match': '0'
47
- }
48
- }));
49
- expect(instructions).toMatchObject({
50
- request: {
51
- headers: {
52
- 'x-goog-if-generation-match': '0'
53
- }
54
- }
55
- });
56
- });
57
- });
58
-
59
- //# sourceMappingURL=generateUploadInstructions.createOnly.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/generateUploadInstructions.createOnly.spec.ts"],"sourcesContent":["import type { Storage } from '@google-cloud/storage'\nimport type { PayloadRequest } from 'payload'\n\nimport { describe, expect, it, vi } from 'vitest'\n\nvi.mock('@payloadcms/plugin-cloud-storage/utilities', () => ({\n resolveSignedURLKey: vi.fn(async () => ({\n storageFilePath: 'reference.png',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'reference.png',\n })),\n}))\n\nimport { generateUploadInstructions } from './generateUploadInstructions.js'\n\ndescribe('generateUploadInstructions', () => {\n it('should issue create-only GCS upload instructions', async () => {\n const getSignedUrl = vi.fn(async () => ['https://example.com/reference.png'])\n const generate = generateUploadInstructions({\n bucket: 'media',\n collectionPrefix: '',\n getStorageClient: () =>\n ({\n bucket: () => ({ file: () => ({ getSignedUrl }) }),\n }) as unknown as Storage,\n })\n\n const instructions = await generate({\n collectionSlug: 'media',\n filename: 'reference.png',\n filesize: 100,\n mimeType: 'image/png',\n overrideAccess: true,\n req: {\n payload: {\n collections: {\n media: {\n config: {\n upload: true,\n },\n },\n },\n },\n } as unknown as PayloadRequest,\n })\n\n expect(getSignedUrl).toHaveBeenCalledWith(\n expect.objectContaining({\n extensionHeaders: { 'x-goog-if-generation-match': '0' },\n }),\n )\n expect(instructions).toMatchObject({\n request: {\n headers: { 'x-goog-if-generation-match': '0' },\n },\n })\n })\n})\n"],"names":["describe","expect","it","vi","mock","resolveSignedURLKey","fn","storageFilePath","sanitizedDocPrefix","sanitizedFilename","generateUploadInstructions","getSignedUrl","generate","bucket","collectionPrefix","getStorageClient","file","instructions","collectionSlug","filename","filesize","mimeType","overrideAccess","req","payload","collections","media","config","upload","toHaveBeenCalledWith","objectContaining","extensionHeaders","toMatchObject","request","headers"],"mappings":"AAGA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAEjDA,GAAGC,IAAI,CAAC,8CAA8C,IAAO,CAAA;QAC3DC,qBAAqBF,GAAGG,EAAE,CAAC,UAAa,CAAA;gBACtCC,iBAAiB;gBACjBC,oBAAoB;gBACpBC,mBAAmB;YACrB,CAAA;IACF,CAAA;AAEA,SAASC,0BAA0B,QAAQ,kCAAiC;AAE5EV,SAAS,8BAA8B;IACrCE,GAAG,oDAAoD;QACrD,MAAMS,eAAeR,GAAGG,EAAE,CAAC,UAAY;gBAAC;aAAoC;QAC5E,MAAMM,WAAWF,2BAA2B;YAC1CG,QAAQ;YACRC,kBAAkB;YAClBC,kBAAkB,IACf,CAAA;oBACCF,QAAQ,IAAO,CAAA;4BAAEG,MAAM,IAAO,CAAA;oCAAEL;gCAAa,CAAA;wBAAG,CAAA;gBAClD,CAAA;QACJ;QAEA,MAAMM,eAAe,MAAML,SAAS;YAClCM,gBAAgB;YAChBC,UAAU;YACVC,UAAU;YACVC,UAAU;YACVC,gBAAgB;YAChBC,KAAK;gBACHC,SAAS;oBACPC,aAAa;wBACXC,OAAO;4BACLC,QAAQ;gCACNC,QAAQ;4BACV;wBACF;oBACF;gBACF;YACF;QACF;QAEA3B,OAAOU,cAAckB,oBAAoB,CACvC5B,OAAO6B,gBAAgB,CAAC;YACtBC,kBAAkB;gBAAE,8BAA8B;YAAI;QACxD;QAEF9B,OAAOgB,cAAce,aAAa,CAAC;YACjCC,SAAS;gBACPC,SAAS;oBAAE,8BAA8B;gBAAI;YAC/C;QACF;IACF;AACF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=staticHandler.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"staticHandler.spec.d.ts","sourceRoot":"","sources":["../src/staticHandler.spec.ts"],"names":[],"mappings":""}
@@ -1,66 +0,0 @@
1
- import { Readable } from 'node:stream';
2
- import { describe, expect, it, vi } from 'vitest';
3
- import { createGcsAdapter } from './adapter.js';
4
- describe('static handler document locations', ()=>{
5
- it('should read the checked document without another lookup', async ()=>{
6
- const file = vi.fn(()=>({
7
- createReadStream: ()=>Readable.from([
8
- Buffer.from('file')
9
- ]),
10
- getMetadata: vi.fn(async ()=>[
11
- {
12
- contentType: 'image/png',
13
- size: 4
14
- }
15
- ])
16
- }));
17
- const adapter = createGcsAdapter({
18
- bucket: 'bucket',
19
- getStorageClient: ()=>({
20
- bucket: ()=>({
21
- file
22
- })
23
- })
24
- });
25
- const find = vi.fn(async ()=>({
26
- docs: [
27
- {
28
- prefix: 'database'
29
- }
30
- ]
31
- }));
32
- const generatedAdapter = adapter({
33
- collection: {
34
- fields: [],
35
- slug: 'media',
36
- upload: {}
37
- },
38
- prefix: 'media'
39
- });
40
- const doc = {
41
- id: 'authorized',
42
- prefix: 'legacy'
43
- };
44
- const response = await generatedAdapter.staticHandler({
45
- headers: new Headers(),
46
- payload: {
47
- find,
48
- logger: {
49
- error: vi.fn()
50
- }
51
- }
52
- }, {
53
- doc,
54
- params: {
55
- collection: 'media',
56
- filename: 'original.png'
57
- }
58
- });
59
- expect(response.status).toBe(200);
60
- expect(await response.text()).toBe('file');
61
- expect(file).toHaveBeenCalledWith('legacy/original.png');
62
- expect(find).not.toHaveBeenCalled();
63
- });
64
- });
65
-
66
- //# sourceMappingURL=staticHandler.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/staticHandler.spec.ts"],"sourcesContent":["import { Readable } from 'node:stream'\nimport { describe, expect, it, vi } from 'vitest'\n\nimport { createGcsAdapter } from './adapter.js'\n\ndescribe('static handler document locations', () => {\n it('should read the checked document without another lookup', async () => {\n const file = vi.fn(() => ({\n createReadStream: () => Readable.from([Buffer.from('file')]),\n getMetadata: vi.fn(async () => [{ contentType: 'image/png', size: 4 }]),\n }))\n const adapter = createGcsAdapter({\n bucket: 'bucket',\n getStorageClient: () => ({ bucket: () => ({ file }) }) as never,\n })\n const find = vi.fn(async () => ({ docs: [{ prefix: 'database' }] }))\n const generatedAdapter = adapter({\n collection: {\n fields: [],\n slug: 'media',\n upload: {},\n },\n prefix: 'media',\n })\n const doc = {\n id: 'authorized',\n prefix: 'legacy',\n }\n const response = await generatedAdapter.staticHandler(\n {\n headers: new Headers(),\n payload: { find, logger: { error: vi.fn() } },\n } as never,\n {\n doc,\n params: { collection: 'media', filename: 'original.png' },\n },\n )\n\n expect(response.status).toBe(200)\n expect(await response.text()).toBe('file')\n expect(file).toHaveBeenCalledWith('legacy/original.png')\n expect(find).not.toHaveBeenCalled()\n })\n})\n"],"names":["Readable","describe","expect","it","vi","createGcsAdapter","file","fn","createReadStream","from","Buffer","getMetadata","contentType","size","adapter","bucket","getStorageClient","find","docs","prefix","generatedAdapter","collection","fields","slug","upload","doc","id","response","staticHandler","headers","Headers","payload","logger","error","params","filename","status","toBe","text","toHaveBeenCalledWith","not","toHaveBeenCalled"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAa;AACtC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAEjD,SAASC,gBAAgB,QAAQ,eAAc;AAE/CJ,SAAS,qCAAqC;IAC5CE,GAAG,2DAA2D;QAC5D,MAAMG,OAAOF,GAAGG,EAAE,CAAC,IAAO,CAAA;gBACxBC,kBAAkB,IAAMR,SAASS,IAAI,CAAC;wBAACC,OAAOD,IAAI,CAAC;qBAAQ;gBAC3DE,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