@devvit/media 0.12.6-next-2025-12-03-22-15-24-1118f1acb.0 → 0.12.6-next-2025-12-04-00-40-11-042274f3d.0

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":"MediaClient.d.ts","sourceRoot":"","sources":["../src/MediaClient.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEvE,qBAAa,WAAW;;IAGhB,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;CAe5D"}
1
+ {"version":3,"file":"MediaClient.d.ts","sourceRoot":"","sources":["../src/MediaClient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEvE,qBAAa,WAAW;;IAGhB,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;CAsB5D"}
package/MediaClient.js CHANGED
@@ -3,12 +3,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
6
  var _MediaClient_instances, _MediaClient_pluginCache, _MediaClient_metadata_get, _MediaClient_plugin_get;
13
7
  import { MediaServiceDefinition } from '@devvit/protos';
14
8
  import { context } from '@devvit/server';
@@ -16,7 +10,7 @@ import { getDevvitConfig } from '@devvit/shared-types/server/get-devvit-config.j
16
10
  export class MediaClient {
17
11
  constructor() {
18
12
  _MediaClient_instances.add(this);
19
- _MediaClient_pluginCache.set(this, void 0);
13
+ _MediaClient_pluginCache.set(this, new WeakMap());
20
14
  }
21
15
  async upload(opts) {
22
16
  const response = await __classPrivateFieldGet(this, _MediaClient_instances, "a", _MediaClient_plugin_get).Upload(opts, __classPrivateFieldGet(this, _MediaClient_instances, "a", _MediaClient_metadata_get));
@@ -29,5 +23,12 @@ export class MediaClient {
29
23
  _MediaClient_pluginCache = new WeakMap(), _MediaClient_instances = new WeakSet(), _MediaClient_metadata_get = function _MediaClient_metadata_get() {
30
24
  return context.metadata;
31
25
  }, _MediaClient_plugin_get = function _MediaClient_plugin_get() {
32
- return (__classPrivateFieldSet(this, _MediaClient_pluginCache, __classPrivateFieldGet(this, _MediaClient_pluginCache, "f") ?? getDevvitConfig().use(MediaServiceDefinition), "f"));
26
+ const config = getDevvitConfig();
27
+ const cached = __classPrivateFieldGet(this, _MediaClient_pluginCache, "f").get(config);
28
+ if (cached) {
29
+ return cached;
30
+ }
31
+ const plugin = config.use(MediaServiceDefinition);
32
+ __classPrivateFieldGet(this, _MediaClient_pluginCache, "f").set(config, plugin);
33
+ return plugin;
33
34
  };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MediaClient.test.d.ts","sourceRoot":"","sources":["../src/MediaClient.test.ts"],"names":[],"mappings":"AAAA,OAAO,qDAAqD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvit/media",
3
- "version": "0.12.6-next-2025-12-03-22-15-24-1118f1acb.0",
3
+ "version": "0.12.6-next-2025-12-04-00-40-11-042274f3d.0",
4
4
  "license": "BSD-3-Clause",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,7 +12,8 @@
12
12
  "browser": "./serverImportInClientCodePanic.js",
13
13
  "default": "./index.js"
14
14
  },
15
- "./package.json": "./package.json"
15
+ "./package.json": "./package.json",
16
+ "./test": "./test/index.js"
16
17
  },
17
18
  "files": [
18
19
  "**"
@@ -31,19 +32,19 @@
31
32
  "test:unit-with-coverage": "vitest run --coverage"
32
33
  },
33
34
  "dependencies": {
34
- "@devvit/protos": "0.12.6-next-2025-12-03-22-15-24-1118f1acb.0"
35
+ "@devvit/protos": "0.12.6-next-2025-12-04-00-40-11-042274f3d.0"
35
36
  },
36
37
  "peerDependencies": {
37
38
  "@devvit/server": "*"
38
39
  },
39
40
  "devDependencies": {
40
- "@devvit/repo-tools": "0.12.6-next-2025-12-03-22-15-24-1118f1acb.0",
41
- "@devvit/server": "0.12.6-next-2025-12-03-22-15-24-1118f1acb.0",
42
- "@devvit/shared-types": "0.12.6-next-2025-12-03-22-15-24-1118f1acb.0",
43
- "@devvit/tsconfig": "0.12.6-next-2025-12-03-22-15-24-1118f1acb.0",
41
+ "@devvit/repo-tools": "0.12.6-next-2025-12-04-00-40-11-042274f3d.0",
42
+ "@devvit/server": "0.12.6-next-2025-12-04-00-40-11-042274f3d.0",
43
+ "@devvit/shared-types": "0.12.6-next-2025-12-04-00-40-11-042274f3d.0",
44
+ "@devvit/tsconfig": "0.12.6-next-2025-12-04-00-40-11-042274f3d.0",
44
45
  "eslint": "9.11.1",
45
46
  "typescript": "5.8.3",
46
47
  "vitest": "1.6.1"
47
48
  },
48
- "gitHead": "3293b1077156dc32b6ae842db48735106cad6b16"
49
+ "gitHead": "2b4995dbaba64659d4362ea86801650e6944fe89"
49
50
  }
@@ -0,0 +1,2 @@
1
+ export * from './mocks/index.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
package/test/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './mocks/index.js';
@@ -0,0 +1,10 @@
1
+ import { type MediaService, type MediaUploadRequest, type MediaUploadResponse, type Metadata } from '@devvit/protos';
2
+ export declare class MediaMock implements MediaService {
3
+ private static _store;
4
+ private readonly _installationId;
5
+ constructor(installationId?: string);
6
+ Upload(request: MediaUploadRequest, _metadata?: Metadata): Promise<MediaUploadResponse>;
7
+ get uploads(): MediaUploadRequest[];
8
+ private _getUploads;
9
+ }
10
+ //# sourceMappingURL=MediaMock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MediaMock.d.ts","sourceRoot":"","sources":["../../../src/test/mocks/MediaMock.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACd,MAAM,gBAAgB,CAAC;AAExB,qBAAa,SAAU,YAAW,YAAY;IAE5C,OAAO,CAAC,MAAM,CAAC,MAAM,CAA2C;IAChE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAE7B,cAAc,CAAC,EAAE,MAAM;IAO7B,MAAM,CAAC,OAAO,EAAE,kBAAkB,EAAE,SAAS,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAsB7F,IAAI,OAAO,IAAI,kBAAkB,EAAE,CAElC;IAED,OAAO,CAAC,WAAW;CAGpB"}
@@ -0,0 +1,34 @@
1
+ import {} from '@devvit/protos';
2
+ export class MediaMock {
3
+ constructor(installationId) {
4
+ this._installationId = installationId ?? '';
5
+ if (this._installationId && !MediaMock._store.has(this._installationId)) {
6
+ MediaMock._store.set(this._installationId, []);
7
+ }
8
+ }
9
+ async Upload(request, _metadata) {
10
+ const uploads = this._getUploads();
11
+ uploads.push(request);
12
+ const mediaId = `media-${uploads.length}`;
13
+ const extensionMap = {
14
+ image: 'png',
15
+ video: 'mp4',
16
+ gif: 'gif',
17
+ };
18
+ const ext = extensionMap[request.type] ?? 'png';
19
+ // Fake URL generation
20
+ const mediaUrl = `https://i.redd.it/bogus-for-testing/${mediaId}.${ext}`;
21
+ return {
22
+ mediaId,
23
+ mediaUrl,
24
+ };
25
+ }
26
+ get uploads() {
27
+ return this._getUploads();
28
+ }
29
+ _getUploads() {
30
+ return MediaMock._store.get(this._installationId) ?? [];
31
+ }
32
+ }
33
+ // Static store to persist uploads across instances, scoped by installationId
34
+ MediaMock._store = new Map();
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MediaMock.test.d.ts","sourceRoot":"","sources":["../../../src/test/mocks/MediaMock.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export * from './MediaMock.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/test/mocks/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './MediaMock.js';