@devvit/metrics 0.11.11-next-2025-03-20-2debaee6b.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.
package/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2023 Reddit Inc.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+ 3. Neither the name of the copyright holder nor the names of its
13
+ contributors may be used to endorse or promote products derived from
14
+ this software without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
+ SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @devvit/metrics
2
+
3
+ Intended for internal use only.
4
+
5
+ Sign up for Reddit's Developer Platform [here!](https://developers.reddit.com)
package/index.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ export type Metric = Counter | Gauge | Histogram;
2
+ /**
3
+ * Devvit looks for a MetricsProvider assigned to globalThis.devvitMetricsProvider.
4
+ * Metrics created by Devvit.addCounterMetric, etc., are provided by this instance.
5
+ * If none is registered, Devvit falls back to a noop provider.
6
+ */
7
+ export type MetricsProvider = {
8
+ counter(def: CounterDefinition): Counter;
9
+ gauge(def: GaugeDefinition): Gauge;
10
+ histogram(def: HistogramDefinition): Histogram;
11
+ };
12
+ type BaseDefinition = {
13
+ name: string;
14
+ labels: string[];
15
+ };
16
+ export type CounterDefinition = BaseDefinition;
17
+ export type GaugeDefinition = BaseDefinition;
18
+ export type HistogramDefinition = BaseDefinition & {
19
+ buckets: number[];
20
+ };
21
+ export type LabelMap = Record<string, string>;
22
+ export type Counter = {
23
+ inc(labels: LabelMap, by?: number): void;
24
+ labels(...values: string[]): CounterInternal;
25
+ };
26
+ export type CounterInternal = {
27
+ inc(by?: number): void;
28
+ };
29
+ export type Gauge = {
30
+ set(labels: LabelMap, value: number): void;
31
+ inc(labels: LabelMap, value: number): void;
32
+ dec(labels: LabelMap, value: number): void;
33
+ setToCurrentTime(labels: LabelMap): void;
34
+ labels(...values: string[]): GaugeInternal;
35
+ };
36
+ export type GaugeInternal = {
37
+ set(value: number): void;
38
+ inc(value: number): void;
39
+ dec(value: number): void;
40
+ setToCurrentTime(): void;
41
+ };
42
+ export type Histogram = {
43
+ observe(labels: LabelMap, value: number): void;
44
+ labels(...values: string[]): HistogramInternal;
45
+ };
46
+ export type HistogramInternal = {
47
+ observe(value: number): void;
48
+ };
49
+ export declare function counter(def: CounterDefinition): Counter;
50
+ export declare function gauge(def: GaugeDefinition): Gauge;
51
+ export declare function histogram(def: HistogramDefinition): Histogram;
52
+ export declare function setMetricsProvider(provider: MetricsProvider): void;
53
+ export declare function getMetricsProvider(): MetricsProvider;
54
+ export {};
55
+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,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,gBAAgB,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC;IACzC,MAAM,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,gBAAgB,IAAI,IAAI,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/C,MAAM,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,wBAAgB,OAAO,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAEvD;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,eAAe,GAAG,KAAK,CAEjD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,mBAAmB,GAAG,SAAS,CAE7D;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAElE;AAED,wBAAgB,kBAAkB,IAAI,eAAe,CAKpD"}
package/index.js ADDED
@@ -0,0 +1,60 @@
1
+ export function counter(def) {
2
+ return getMetricsProvider().counter(def);
3
+ }
4
+ export function gauge(def) {
5
+ return getMetricsProvider().gauge(def);
6
+ }
7
+ export function histogram(def) {
8
+ return getMetricsProvider().histogram(def);
9
+ }
10
+ export function setMetricsProvider(provider) {
11
+ Object.assign(globalThis, { devvitMetricsProvider: provider });
12
+ }
13
+ export function getMetricsProvider() {
14
+ return (globalThis.devvitMetricsProvider ??
15
+ new NullMetrics());
16
+ }
17
+ class NullMetrics {
18
+ counter(_def) {
19
+ return new NullCounter();
20
+ }
21
+ gauge(_def) {
22
+ return new NullGauge();
23
+ }
24
+ histogram(_def) {
25
+ return new NullHistogram();
26
+ }
27
+ }
28
+ class NullCounter {
29
+ inc(_labels, _by) { }
30
+ labels(..._values) {
31
+ return new NullCounterInternal();
32
+ }
33
+ }
34
+ class NullCounterInternal {
35
+ inc(_by) { }
36
+ }
37
+ class NullGauge {
38
+ set(_labels, _value) { }
39
+ inc(_labels, _by) { }
40
+ dec(_labels, _by) { }
41
+ setToCurrentTime(_labels) { }
42
+ labels(..._values) {
43
+ return new NullGaugeInternal();
44
+ }
45
+ }
46
+ class NullGaugeInternal {
47
+ set(_value) { }
48
+ inc(_by) { }
49
+ dec(_by) { }
50
+ setToCurrentTime() { }
51
+ }
52
+ class NullHistogram {
53
+ observe(_labels, _value) { }
54
+ labels(..._values) {
55
+ return new NullHistogramInternal();
56
+ }
57
+ }
58
+ class NullHistogramInternal {
59
+ observe(_value) { }
60
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@devvit/metrics",
3
+ "version": "0.11.11-next-2025-03-20-2debaee6b.0",
4
+ "license": "BSD-3-Clause",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://developers.reddit.com/"
8
+ },
9
+ "type": "module",
10
+ "main": "./index.js",
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "clean": "rm -rf .turbo coverage dist",
14
+ "clobber": "yarn clean && rm -rf node_modules",
15
+ "dev": "tsc -w",
16
+ "lint": "redlint .",
17
+ "lint:fix": "yarn lint --fix",
18
+ "prepublishOnly": "publish-package-json",
19
+ "test": "yarn test:unit && yarn test:types && yarn lint",
20
+ "test:types": "tsc --noEmit",
21
+ "test:unit": "vitest run",
22
+ "test:unit-with-coverage": "vitest run --coverage"
23
+ },
24
+ "types": "./index.d.ts",
25
+ "dependencies": {
26
+ "@devvit/protos": "0.11.11-next-2025-03-20-2debaee6b.0"
27
+ },
28
+ "devDependencies": {
29
+ "@devvit/repo-tools": "0.11.11-next-2025-03-20-2debaee6b.0",
30
+ "@devvit/tsconfig": "0.11.11-next-2025-03-20-2debaee6b.0",
31
+ "eslint": "9.11.1",
32
+ "typescript": "5.3.2",
33
+ "vitest": "1.6.0"
34
+ },
35
+ "publishConfig": {
36
+ "directory": "dist"
37
+ },
38
+ "source": "./src/index.ts",
39
+ "gitHead": "830bd77dca876101350373ff7d84e924663cb5b7"
40
+ }