@r_masseater/masseater-utils 0.1.8 → 0.2.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/README.md +7 -0
- package/dist/app-name.d.mts +9 -0
- package/dist/app-name.mjs +27 -0
- package/dist/app-name.mjs.map +1 -0
- package/dist/node-main.mjs +2 -1
- package/dist/node-main.mjs.map +1 -1
- package/dist/plugin-kit.mjs +311 -267
- package/dist/plugin-kit.mjs.map +1 -1
- package/dist/usage-meter-CmCceKx1.mjs +157 -0
- package/dist/usage-meter-CmCceKx1.mjs.map +1 -0
- package/dist/usage-meter-report.d.mts +44 -0
- package/dist/usage-meter-report.mjs +51 -0
- package/dist/usage-meter-report.mjs.map +1 -0
- package/dist/usage-meter.d.mts +14 -0
- package/dist/usage-meter.mjs +3 -0
- package/dist/usage-tally-C7zVBg75.d.mts +20 -0
- package/dist/usage-tally-FiAxcD-H.mjs +15 -0
- package/dist/usage-tally-FiAxcD-H.mjs.map +1 -0
- package/dist/workers-tracing-alchemy.d.mts +2 -2
- package/dist/workers-tracing-alchemy.mjs +3 -3
- package/package.json +19 -7
- package/skills/name-stack-resources/SKILL.md +60 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { n as SPOOL_ENV, r as TallyList } from "./usage-tally-FiAxcD-H.mjs";
|
|
2
|
+
import { Array, Config, Effect, Exit, FileSystem, Layer, Option, Path, Predicate, Random, Record, Schema, String as String$1, pipe } from "effect";
|
|
3
|
+
// src/shared/lib/usage-spool.ts
|
|
4
|
+
const ManifestFields = Schema.Struct({
|
|
5
|
+
name: Schema.String,
|
|
6
|
+
version: Schema.String
|
|
7
|
+
});
|
|
8
|
+
const MANIFEST = "package.json";
|
|
9
|
+
const decodeManifest = Schema.decodeUnknownOption(Schema.fromJsonString(ManifestFields));
|
|
10
|
+
const encodeTallies = Schema.encodeEffect(Schema.fromJsonString(TallyList));
|
|
11
|
+
const manifestAbove = (directory) => Effect.gen(function* manifestAboveDirectory() {
|
|
12
|
+
const fs = yield* FileSystem.FileSystem;
|
|
13
|
+
const path = yield* Path.Path;
|
|
14
|
+
const text = yield* fs.readFileString(path.join(directory, MANIFEST)).pipe(Effect.option);
|
|
15
|
+
const found = pipe(text, Option.flatMap(decodeManifest));
|
|
16
|
+
const parent = path.dirname(directory);
|
|
17
|
+
if (Option.isSome(found) || parent === directory) return found;
|
|
18
|
+
return yield* manifestAbove(parent);
|
|
19
|
+
});
|
|
20
|
+
const tallyOf = ({ moduleUrl, kind, name, calls }) => Effect.gen(function* tallyOfSeen() {
|
|
21
|
+
const path = yield* Path.Path;
|
|
22
|
+
const file = yield* path.fromFileUrl(new URL(moduleUrl)).pipe(Effect.option);
|
|
23
|
+
if (Option.isNone(file)) return Option.none();
|
|
24
|
+
const manifest = yield* manifestAbove(path.dirname(file.value));
|
|
25
|
+
return pipe(manifest, Option.map(({ name: library, version }) => ({
|
|
26
|
+
library,
|
|
27
|
+
version,
|
|
28
|
+
kind,
|
|
29
|
+
name,
|
|
30
|
+
calls
|
|
31
|
+
})));
|
|
32
|
+
});
|
|
33
|
+
const written = (spool, seen) => Effect.gen(function* writeSpool() {
|
|
34
|
+
const fs = yield* FileSystem.FileSystem;
|
|
35
|
+
const path = yield* Path.Path;
|
|
36
|
+
const tallies = yield* Effect.forEach(seen, tallyOf, { concurrency: "unbounded" }).pipe(Effect.map(Array.getSomes));
|
|
37
|
+
const text = yield* encodeTallies(tallies);
|
|
38
|
+
const suffix = yield* Random.nextInt;
|
|
39
|
+
yield* fs.makeDirectory(spool, { recursive: true });
|
|
40
|
+
yield* fs.writeFileString(path.join(spool, `${String(process.pid)}-${String(suffix)}.json`), text);
|
|
41
|
+
}).pipe(Effect.ignore);
|
|
42
|
+
const taggedError = Schema.TaggedError;
|
|
43
|
+
var NodeServicesMissing = class extends taggedError()("NodeServicesMissing", { message: Schema.String }) {};
|
|
44
|
+
const nodeServices = Effect.tryPromise({
|
|
45
|
+
try: () => import("@effect/platform-node/NodeServices"),
|
|
46
|
+
catch: () => NodeServicesMissing.make({ message: "@effect/platform-node could not be loaded" })
|
|
47
|
+
}).pipe(Effect.flatMap(({ layer }) => Layer.build(layer)));
|
|
48
|
+
const spoolWritten = (spool) => (seen) => nodeServices.pipe(Effect.flatMap((services) => Effect.provideContext(written(spool, seen), services)), Effect.scoped, Effect.ignore);
|
|
49
|
+
// src/shared/lib/usage-meter.ts
|
|
50
|
+
const RULE_ENTRIES = [
|
|
51
|
+
"create",
|
|
52
|
+
"createOnce",
|
|
53
|
+
"check",
|
|
54
|
+
"linter",
|
|
55
|
+
"fixer"
|
|
56
|
+
];
|
|
57
|
+
const RULE = "rule";
|
|
58
|
+
const FUNCTION = "function";
|
|
59
|
+
const ONE_CALL = 1;
|
|
60
|
+
const PREFIX_SEPARATOR = "/";
|
|
61
|
+
const KEY_SEPARATOR = "\0";
|
|
62
|
+
const idle = {
|
|
63
|
+
rules: (rules) => rules,
|
|
64
|
+
functions: (functions) => functions,
|
|
65
|
+
plugins: (plugins) => plugins,
|
|
66
|
+
within: () => idle
|
|
67
|
+
};
|
|
68
|
+
const declared = /* @__PURE__ */ new Map();
|
|
69
|
+
const calls = /* @__PURE__ */ new Map();
|
|
70
|
+
const state = {
|
|
71
|
+
flushed: false,
|
|
72
|
+
scheduled: false
|
|
73
|
+
};
|
|
74
|
+
const spoolSetting = Exit.match(Effect.runSyncExit(Config.NonEmptyString(SPOOL_ENV).pipe(Config.option)), {
|
|
75
|
+
onSuccess: (value) => value,
|
|
76
|
+
onFailure: () => Option.none()
|
|
77
|
+
});
|
|
78
|
+
const isCallable = (value) => Predicate.isFunction(value);
|
|
79
|
+
const keyOf = ({ moduleUrl, kind, name }) => Array.join([
|
|
80
|
+
moduleUrl,
|
|
81
|
+
kind,
|
|
82
|
+
name
|
|
83
|
+
], KEY_SEPARATOR);
|
|
84
|
+
const countCall = (key) => {
|
|
85
|
+
const next = (calls.get(key) ?? 0) + ONE_CALL;
|
|
86
|
+
calls.set(key, next);
|
|
87
|
+
};
|
|
88
|
+
const counted = (key, callable) => Object.assign(function countedCall(...args) {
|
|
89
|
+
countCall(key);
|
|
90
|
+
return callable.call(this, ...args);
|
|
91
|
+
}, callable);
|
|
92
|
+
const ruleCounted = (key, rule) => {
|
|
93
|
+
if (isCallable(rule)) return counted(key, rule);
|
|
94
|
+
if (!Predicate.isObject(rule)) return rule;
|
|
95
|
+
const entries = pipe(RULE_ENTRIES, Array.flatMap((entry) => pipe(Option.liftPredicate(Record.get({ ...rule }, entry), Option.isSome), Option.flatMap((found) => Option.liftPredicate(found.value, isCallable)), Option.map((callable) => [entry, counted(key, callable)]), Option.toArray)));
|
|
96
|
+
if (Array.isReadonlyArrayEmpty(entries)) return rule;
|
|
97
|
+
return {
|
|
98
|
+
...rule,
|
|
99
|
+
...Record.fromEntries(entries)
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const functionCounted = (key, value) => {
|
|
103
|
+
if (isCallable(value)) return counted(key, value);
|
|
104
|
+
return value;
|
|
105
|
+
};
|
|
106
|
+
const flushUsage = Effect.suspend(() => {
|
|
107
|
+
if (state.flushed || Option.isNone(spoolSetting)) return Effect.void;
|
|
108
|
+
state.flushed = true;
|
|
109
|
+
const seen = pipe([...declared], Array.map(([key, exported]) => ({
|
|
110
|
+
...exported,
|
|
111
|
+
calls: calls.get(key) ?? 0
|
|
112
|
+
})));
|
|
113
|
+
return spoolWritten(spoolSetting.value)(seen);
|
|
114
|
+
});
|
|
115
|
+
const flushOnExit = () => {
|
|
116
|
+
if (state.scheduled) return;
|
|
117
|
+
state.scheduled = true;
|
|
118
|
+
process.once("beforeExit", () => {
|
|
119
|
+
Effect.runFork(flushUsage);
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
const qualified = (prefix, name) => pipe([prefix, name], Array.filter(String$1.isNonEmpty), Array.join(PREFIX_SEPARATOR));
|
|
123
|
+
const wrapped = (moduleUrl, prefix, kind) => (wrap) => (names) => {
|
|
124
|
+
flushOnExit();
|
|
125
|
+
return pipe(names, Record.map((value, name) => {
|
|
126
|
+
const exported = {
|
|
127
|
+
moduleUrl,
|
|
128
|
+
kind,
|
|
129
|
+
name: qualified(prefix, name)
|
|
130
|
+
};
|
|
131
|
+
declared.set(keyOf(exported), exported);
|
|
132
|
+
return wrap(keyOf(exported), value);
|
|
133
|
+
}));
|
|
134
|
+
};
|
|
135
|
+
const meterOf = (moduleUrl, prefix) => {
|
|
136
|
+
const rules = (named) => wrapped(moduleUrl, prefix, RULE)(ruleCounted)(named);
|
|
137
|
+
const plugins = (named) => pipe(named, Record.map((plugin, name) => pipe(Option.fromUndefinedOr(plugin.rules), Option.match({
|
|
138
|
+
onNone: () => plugin,
|
|
139
|
+
onSome: (pluginRules) => ({
|
|
140
|
+
...plugin,
|
|
141
|
+
rules: meterOf(moduleUrl, qualified(prefix, name)).rules(pluginRules)
|
|
142
|
+
})
|
|
143
|
+
}))));
|
|
144
|
+
return {
|
|
145
|
+
rules,
|
|
146
|
+
functions: (named) => wrapped(moduleUrl, prefix, FUNCTION)(functionCounted)(named),
|
|
147
|
+
plugins,
|
|
148
|
+
within: (inner) => meterOf(moduleUrl, qualified(prefix, inner))
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
const usageMeter = (moduleUrl) => pipe(spoolSetting, Option.match({
|
|
152
|
+
onNone: () => idle,
|
|
153
|
+
onSome: () => meterOf(moduleUrl, "")
|
|
154
|
+
}));
|
|
155
|
+
export { usageMeter as n, flushUsage as t };
|
|
156
|
+
|
|
157
|
+
//# sourceMappingURL=usage-meter-CmCceKx1.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-meter-CmCceKx1.mjs","names":["Arr","Arr","Rec","Str"],"sources":["../src/shared/lib/usage-spool.ts","../src/shared/lib/usage-meter.ts"],"sourcesContent":["import {\n Array as Arr,\n Effect,\n FileSystem,\n Layer,\n Option,\n Path,\n Random,\n Schema,\n pipe,\n} from \"effect\";\nimport type { Context } from \"effect\";\n\nimport { TallyList } from \"./usage-tally.ts\";\nimport type { Tally } from \"./usage-tally.ts\";\n\nexport interface Seen {\n readonly moduleUrl: string;\n readonly kind: string;\n readonly name: string;\n readonly calls: number;\n}\n\nconst ManifestFields = Schema.Struct({ name: Schema.String, version: Schema.String });\n\ntype Manifest = typeof ManifestFields.Type;\n\ntype Services = FileSystem.FileSystem | Path.Path;\n\nconst MANIFEST = \"package.json\";\n\nconst decodeManifest = Schema.decodeUnknownOption(Schema.fromJsonString(ManifestFields));\n\nconst encodeTallies = Schema.encodeEffect(Schema.fromJsonString(TallyList));\n\nconst manifestAbove = (\n directory: string,\n): Effect.Effect<Option.Option<Manifest>, never, Services> =>\n Effect.gen(function* manifestAboveDirectory() {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const text = yield* fs.readFileString(path.join(directory, MANIFEST)).pipe(Effect.option);\n const found = pipe(text, Option.flatMap(decodeManifest));\n const parent = path.dirname(directory);\n if (Option.isSome(found) || parent === directory) {\n return found;\n }\n return yield* manifestAbove(parent);\n });\n\nconst tallyOf = ({\n moduleUrl,\n kind,\n name,\n calls,\n}: Seen): Effect.Effect<Option.Option<Tally>, never, Services> =>\n Effect.gen(function* tallyOfSeen() {\n const path = yield* Path.Path;\n const file = yield* path.fromFileUrl(new URL(moduleUrl)).pipe(Effect.option);\n if (Option.isNone(file)) {\n return Option.none<Tally>();\n }\n const manifest = yield* manifestAbove(path.dirname(file.value));\n return pipe(\n manifest,\n Option.map(({ name: library, version }): Tally => ({ library, version, kind, name, calls })),\n );\n });\n\nconst written = (spool: string, seen: readonly Seen[]): Effect.Effect<void, never, Services> =>\n Effect.gen(function* writeSpool() {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const tallies = yield* Effect.forEach(seen, tallyOf, { concurrency: \"unbounded\" }).pipe(\n Effect.map(Arr.getSomes),\n );\n const text = yield* encodeTallies(tallies);\n const suffix = yield* Random.nextInt;\n yield* fs.makeDirectory(spool, { recursive: true });\n yield* fs.writeFileString(\n path.join(spool, `${String(process.pid)}-${String(suffix)}.json`),\n text,\n );\n }).pipe(Effect.ignore);\n\nconst taggedError = Schema.TaggedError;\n\nclass NodeServicesMissing extends taggedError<\n NodeServicesMissing,\n { readonly brand: unique symbol }\n>()(\"NodeServicesMissing\", { message: Schema.String }) {}\n\nconst nodeServices = Effect.tryPromise({\n try: () => import(\"@effect/platform-node/NodeServices\"),\n catch: () => NodeServicesMissing.make({ message: \"@effect/platform-node could not be loaded\" }),\n}).pipe(Effect.flatMap(({ layer }) => Layer.build(layer)));\n\nexport const spoolWritten =\n (spool: string) =>\n (seen: readonly Seen[]): Effect.Effect<void> =>\n nodeServices.pipe(\n Effect.flatMap((services: Context.Context<Services>) =>\n Effect.provideContext(written(spool, seen), services),\n ),\n Effect.scoped,\n Effect.ignore,\n );\n","import {\n Array as Arr,\n Config,\n Effect,\n Exit,\n Option,\n Predicate,\n Record as Rec,\n String as Str,\n pipe,\n} from \"effect\";\n\nimport { spoolWritten } from \"./usage-spool.ts\";\nimport type { Seen } from \"./usage-spool.ts\";\nimport { NO_CALLS, SPOOL_ENV } from \"./usage-tally.ts\";\n\nexport interface UsageMeter {\n readonly rules: <Name extends string, Rule>(\n rules: Readonly<Record<Name, Rule>>,\n ) => Readonly<Record<Name, Rule>>;\n readonly functions: <Name extends string, Value>(\n functions: Readonly<Record<Name, Value>>,\n ) => Readonly<Record<Name, Value>>;\n readonly plugins: <Plugin extends RulePlugin>(\n plugins: Readonly<Record<string, Plugin>>,\n ) => Readonly<Record<string, Plugin>>;\n readonly within: (prefix: string) => UsageMeter;\n}\n\nexport interface RulePlugin {\n readonly rules?: Readonly<Record<string, unknown>> | undefined;\n}\n\ninterface Declared {\n readonly moduleUrl: string;\n readonly kind: string;\n readonly name: string;\n}\n\ntype Callable = (...args: readonly unknown[]) => unknown;\n\nconst RULE_ENTRIES = [\"create\", \"createOnce\", \"check\", \"linter\", \"fixer\"] as const;\n\nconst RULE = \"rule\";\n\nconst FUNCTION = \"function\";\n\nconst ONE_CALL = 1;\n\nconst PREFIX_SEPARATOR = \"/\";\n\nconst KEY_SEPARATOR = \"\\u0000\";\n\nconst idle: UsageMeter = {\n rules: (rules) => rules,\n functions: (functions) => functions,\n plugins: (plugins) => plugins,\n within: () => idle,\n};\n\nconst declared = new Map<string, Declared>();\n\nconst calls = new Map<string, number>();\n\nconst state = { flushed: false, scheduled: false };\n\nconst spoolSetting = Exit.match(\n Effect.runSyncExit(Config.NonEmptyString(SPOOL_ENV).pipe(Config.option)),\n {\n onSuccess: (value) => value,\n onFailure: () => Option.none<string>(),\n },\n);\n\nconst isCallable = (value: unknown): value is Callable => Predicate.isFunction(value);\n\nconst keyOf = ({ moduleUrl, kind, name }: Declared): string =>\n Arr.join([moduleUrl, kind, name], KEY_SEPARATOR);\n\nconst countCall = (key: string): void => {\n const next = (calls.get(key) ?? NO_CALLS) + ONE_CALL;\n calls.set(key, next);\n};\n\nconst counted = <Value extends Callable>(key: string, callable: Value): Value =>\n Object.assign(function countedCall(this: unknown, ...args: readonly unknown[]): unknown {\n countCall(key);\n return callable.call(this, ...args);\n }, callable);\n\nconst ruleCounted = <Rule>(key: string, rule: Rule): Rule => {\n if (isCallable(rule)) {\n return counted(key, rule);\n }\n if (!Predicate.isObject(rule)) {\n return rule;\n }\n const entries = pipe(\n RULE_ENTRIES,\n Arr.flatMap((entry) =>\n pipe(\n Option.liftPredicate(Rec.get({ ...rule }, entry), Option.isSome),\n Option.flatMap((found) => Option.liftPredicate(found.value, isCallable)),\n Option.map((callable) => [entry, counted(key, callable)] as const),\n Option.toArray,\n ),\n ),\n );\n if (Arr.isReadonlyArrayEmpty(entries)) {\n return rule;\n }\n return { ...rule, ...Rec.fromEntries(entries) };\n};\n\nconst functionCounted = <Value>(key: string, value: Value): Value => {\n if (isCallable(value)) {\n return counted(key, value);\n }\n return value;\n};\n\nexport const flushUsage: Effect.Effect<void> = Effect.suspend(() => {\n if (state.flushed || Option.isNone(spoolSetting)) {\n return Effect.void;\n }\n state.flushed = true;\n const seen = pipe(\n [...declared],\n Arr.map(([key, exported]): Seen => ({ ...exported, calls: calls.get(key) ?? NO_CALLS })),\n );\n return spoolWritten(spoolSetting.value)(seen);\n});\n\nconst flushOnExit = (): void => {\n if (state.scheduled) {\n return;\n }\n state.scheduled = true;\n process.once(\"beforeExit\", () => {\n Effect.runFork(flushUsage);\n });\n};\n\nconst qualified = (prefix: string, name: string): string =>\n pipe([prefix, name], Arr.filter(Str.isNonEmpty), Arr.join(PREFIX_SEPARATOR));\n\nconst wrapped =\n (moduleUrl: string, prefix: string, kind: string) =>\n <Name extends string, Value>(\n wrap: (key: string, value: Value) => Value,\n ): ((names: Readonly<Record<Name, Value>>) => Readonly<Record<Name, Value>>) =>\n (names) => {\n flushOnExit();\n return pipe(\n names,\n Rec.map((value: Value, name: Name) => {\n const exported: Declared = { moduleUrl, kind, name: qualified(prefix, name) };\n declared.set(keyOf(exported), exported);\n return wrap(keyOf(exported), value);\n }),\n );\n };\n\nconst meterOf = (moduleUrl: string, prefix: string): UsageMeter => {\n const rules: UsageMeter[\"rules\"] = (named) =>\n wrapped(moduleUrl, prefix, RULE)(ruleCounted)(named);\n const plugins: UsageMeter[\"plugins\"] = (named) =>\n pipe(\n named,\n Rec.map((plugin, name) =>\n pipe(\n Option.fromUndefinedOr(plugin.rules),\n Option.match({\n onNone: () => plugin,\n onSome: (pluginRules) => ({\n ...plugin,\n rules: meterOf(moduleUrl, qualified(prefix, name)).rules(pluginRules),\n }),\n }),\n ),\n ),\n );\n return {\n rules,\n functions: (named) => wrapped(moduleUrl, prefix, FUNCTION)(functionCounted)(named),\n plugins,\n within: (inner) => meterOf(moduleUrl, qualified(prefix, inner)),\n };\n};\n\nexport const usageMeter = (moduleUrl: string): UsageMeter =>\n pipe(\n spoolSetting,\n Option.match({\n onNone: () => idle,\n onSome: () => meterOf(moduleUrl, \"\"),\n }),\n );\n"],"mappings":";;;AAuBA,MAAM,iBAAiB,OAAO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KAAK,CAAC;CAChE;AACF;AAEA,MAAa,cAAc,cACzB,KACE,cACA,OAAO,MAAM;CACX,cAAc;CACd,cAAc,QAAQ,WAAW,EAAE;AACrC,CAAC,CACH"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { i as TallyList, n as SPOOL_ENV, r as Tally, t as CALLS_METRIC } from "./usage-tally-C7zVBg75.mjs";
|
|
2
|
+
interface Attribute {
|
|
3
|
+
readonly key: string;
|
|
4
|
+
readonly value: {
|
|
5
|
+
readonly stringValue: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
interface DataPoint {
|
|
9
|
+
readonly attributes: readonly Attribute[];
|
|
10
|
+
readonly startTimeUnixNano: string;
|
|
11
|
+
readonly timeUnixNano: string;
|
|
12
|
+
readonly asInt: string;
|
|
13
|
+
}
|
|
14
|
+
interface UsageMetrics {
|
|
15
|
+
readonly resourceMetrics: readonly {
|
|
16
|
+
readonly resource: {
|
|
17
|
+
readonly attributes: readonly Attribute[];
|
|
18
|
+
};
|
|
19
|
+
readonly scopeMetrics: readonly {
|
|
20
|
+
readonly scope: {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
};
|
|
23
|
+
readonly metrics: readonly {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly unit: string;
|
|
26
|
+
readonly sum: {
|
|
27
|
+
readonly aggregationTemporality: number;
|
|
28
|
+
readonly isMonotonic: boolean;
|
|
29
|
+
readonly dataPoints: readonly DataPoint[];
|
|
30
|
+
};
|
|
31
|
+
}[];
|
|
32
|
+
}[];
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
35
|
+
interface UsageWindow {
|
|
36
|
+
readonly resource: Readonly<Record<string, string>>;
|
|
37
|
+
readonly startNanos: bigint;
|
|
38
|
+
readonly endNanos: bigint;
|
|
39
|
+
}
|
|
40
|
+
export declare const talliesIn: (text: string) => readonly Tally[];
|
|
41
|
+
export declare const mergeTallies: (tallies: readonly Tally[]) => readonly Tally[];
|
|
42
|
+
export declare const usageMetricsOf: (window: UsageWindow) => (tallies: readonly Tally[]) => UsageMetrics;
|
|
43
|
+
export { type Attribute, CALLS_METRIC, type DataPoint, SPOOL_ENV, type Tally, TallyList, type UsageMetrics, type UsageWindow };
|
|
44
|
+
//# sourceMappingURL=usage-meter-report.d.mts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { n as SPOOL_ENV, r as TallyList, t as CALLS_METRIC } from "./usage-tally-FiAxcD-H.mjs";
|
|
2
|
+
import { Array, Option, Record, Schema, pipe } from "effect";
|
|
3
|
+
// src/shared/lib/usage-report.ts
|
|
4
|
+
const DELTA = 1;
|
|
5
|
+
const SCOPE = "usage-meter";
|
|
6
|
+
const CALL_UNIT = "{call}";
|
|
7
|
+
const decodeTallies = Schema.decodeUnknownOption(Schema.fromJsonString(TallyList));
|
|
8
|
+
const talliesIn = (text) => pipe(decodeTallies(text), Option.getOrElse(() => []));
|
|
9
|
+
const keyOf = ({ library, version, kind, name }) => Array.join([
|
|
10
|
+
library,
|
|
11
|
+
version,
|
|
12
|
+
kind,
|
|
13
|
+
name
|
|
14
|
+
], "\0");
|
|
15
|
+
const mergeTallies = (tallies) => pipe(tallies, Array.groupBy(keyOf), Record.values, Array.map((group) => ({
|
|
16
|
+
...Array.headNonEmpty(group),
|
|
17
|
+
calls: Array.reduce(group, 0, (sum, { calls }) => sum + calls)
|
|
18
|
+
})));
|
|
19
|
+
const attributesOf = (values) => pipe(Record.toEntries(values), Array.map(([key, value]) => ({
|
|
20
|
+
key,
|
|
21
|
+
value: { stringValue: value }
|
|
22
|
+
})));
|
|
23
|
+
const pointOf = ({ startNanos, endNanos }) => ({ library, version, kind, name, calls }) => ({
|
|
24
|
+
attributes: attributesOf({
|
|
25
|
+
"code.library": library,
|
|
26
|
+
"code.library.version": version,
|
|
27
|
+
"code.export.kind": kind,
|
|
28
|
+
"code.export": name
|
|
29
|
+
}),
|
|
30
|
+
startTimeUnixNano: String(startNanos),
|
|
31
|
+
timeUnixNano: String(endNanos),
|
|
32
|
+
asInt: String(calls)
|
|
33
|
+
});
|
|
34
|
+
const usageMetricsOf = (window) => (tallies) => ({ resourceMetrics: [{
|
|
35
|
+
resource: { attributes: attributesOf(window.resource) },
|
|
36
|
+
scopeMetrics: [{
|
|
37
|
+
scope: { name: SCOPE },
|
|
38
|
+
metrics: [{
|
|
39
|
+
name: CALLS_METRIC,
|
|
40
|
+
unit: CALL_UNIT,
|
|
41
|
+
sum: {
|
|
42
|
+
aggregationTemporality: DELTA,
|
|
43
|
+
isMonotonic: true,
|
|
44
|
+
dataPoints: pipe(tallies, Array.map(pointOf(window)))
|
|
45
|
+
}
|
|
46
|
+
}]
|
|
47
|
+
}]
|
|
48
|
+
}] });
|
|
49
|
+
export { CALLS_METRIC, SPOOL_ENV, TallyList, mergeTallies, talliesIn, usageMetricsOf };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=usage-meter-report.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-meter-report.mjs","names":["Arr","Rec"],"sources":["../src/shared/lib/usage-report.ts"],"sourcesContent":["import { Array as Arr, Option, Record as Rec, Schema, pipe } from \"effect\";\n\nimport { CALLS_METRIC, NO_CALLS, TallyList } from \"./usage-tally.ts\";\nimport type { Tally } from \"./usage-tally.ts\";\n\nexport interface Attribute {\n readonly key: string;\n readonly value: { readonly stringValue: string };\n}\n\nexport interface DataPoint {\n readonly attributes: readonly Attribute[];\n readonly startTimeUnixNano: string;\n readonly timeUnixNano: string;\n readonly asInt: string;\n}\n\nexport interface UsageMetrics {\n readonly resourceMetrics: readonly {\n readonly resource: { readonly attributes: readonly Attribute[] };\n readonly scopeMetrics: readonly {\n readonly scope: { readonly name: string };\n readonly metrics: readonly {\n readonly name: string;\n readonly unit: string;\n readonly sum: {\n readonly aggregationTemporality: number;\n readonly isMonotonic: boolean;\n readonly dataPoints: readonly DataPoint[];\n };\n }[];\n }[];\n }[];\n}\n\nexport interface UsageWindow {\n readonly resource: Readonly<Record<string, string>>;\n readonly startNanos: bigint;\n readonly endNanos: bigint;\n}\n\nconst DELTA = 1;\n\nconst SCOPE = \"usage-meter\";\n\nconst CALL_UNIT = \"{call}\";\n\nconst decodeTallies = Schema.decodeUnknownOption(Schema.fromJsonString(TallyList));\n\nexport const talliesIn = (text: string): readonly Tally[] =>\n pipe(\n decodeTallies(text),\n Option.getOrElse((): readonly Tally[] => []),\n );\n\nconst keyOf = ({ library, version, kind, name }: Tally): string =>\n Arr.join([library, version, kind, name], \"\\u0000\");\n\nexport const mergeTallies = (tallies: readonly Tally[]): readonly Tally[] =>\n pipe(\n tallies,\n Arr.groupBy(keyOf),\n Rec.values,\n Arr.map((group): Tally => ({\n ...Arr.headNonEmpty(group),\n calls: Arr.reduce(group, NO_CALLS, (sum, { calls }) => sum + calls),\n })),\n );\n\nconst attributesOf = (values: Readonly<Record<string, string>>): readonly Attribute[] =>\n pipe(\n Rec.toEntries(values),\n Arr.map(([key, value]) => ({ key, value: { stringValue: value } })),\n );\n\nconst pointOf =\n ({ startNanos, endNanos }: UsageWindow) =>\n ({ library, version, kind, name, calls }: Tally): DataPoint => ({\n attributes: attributesOf({\n \"code.library\": library,\n \"code.library.version\": version,\n \"code.export.kind\": kind,\n \"code.export\": name,\n }),\n startTimeUnixNano: String(startNanos),\n timeUnixNano: String(endNanos),\n asInt: String(calls),\n });\n\nexport const usageMetricsOf =\n (window: UsageWindow) =>\n (tallies: readonly Tally[]): UsageMetrics => ({\n resourceMetrics: [\n {\n resource: { attributes: attributesOf(window.resource) },\n scopeMetrics: [\n {\n scope: { name: SCOPE },\n metrics: [\n {\n name: CALLS_METRIC,\n unit: CALL_UNIT,\n sum: {\n aggregationTemporality: DELTA,\n isMonotonic: true,\n dataPoints: pipe(tallies, Arr.map(pointOf(window))),\n },\n },\n ],\n },\n ],\n },\n ],\n });\n"],"mappings":";;;AAyCA,MAAM,QAAQ;AAEd,MAAM,QAAQ;AAEd,MAAM,YAAY;AAElB,MAA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mjs";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
interface UsageMeter {
|
|
4
|
+
readonly rules: <Name extends string, Rule>(rules: Readonly<Record<Name, Rule>>) => Readonly<Record<Name, Rule>>;
|
|
5
|
+
readonly functions: <Name extends string, Value>(functions: Readonly<Record<Name, Value>>) => Readonly<Record<Name, Value>>;
|
|
6
|
+
readonly plugins: <Plugin extends RulePlugin>(plugins: Readonly<Record<string, Plugin>>) => Readonly<Record<string, Plugin>>;
|
|
7
|
+
readonly within: (prefix: string) => UsageMeter;
|
|
8
|
+
}
|
|
9
|
+
interface RulePlugin {
|
|
10
|
+
readonly rules?: Readonly<Record<string, unknown>> | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare const usageMeter: (moduleUrl: string) => UsageMeter;
|
|
13
|
+
export { type RulePlugin, SPOOL_ENV, type UsageMeter };
|
|
14
|
+
//# sourceMappingURL=usage-meter.d.mts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
declare const TallyFields: Schema.Struct<{
|
|
3
|
+
readonly library: Schema.String;
|
|
4
|
+
readonly version: Schema.String;
|
|
5
|
+
readonly kind: Schema.String;
|
|
6
|
+
readonly name: Schema.String;
|
|
7
|
+
readonly calls: Schema.Finite;
|
|
8
|
+
}>;
|
|
9
|
+
type Tally = typeof TallyFields.Type;
|
|
10
|
+
declare const TallyList: Schema.$Array<Schema.Struct<{
|
|
11
|
+
readonly library: Schema.String;
|
|
12
|
+
readonly version: Schema.String;
|
|
13
|
+
readonly kind: Schema.String;
|
|
14
|
+
readonly name: Schema.String;
|
|
15
|
+
readonly calls: Schema.Finite;
|
|
16
|
+
}>>;
|
|
17
|
+
declare const SPOOL_ENV = "USAGE_METER_SPOOL";
|
|
18
|
+
declare const CALLS_METRIC = "code.usage.calls";
|
|
19
|
+
export { TallyList as i, SPOOL_ENV as n, Tally as r, CALLS_METRIC as t };
|
|
20
|
+
//# sourceMappingURL=usage-tally-C7zVBg75.d.mts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
// src/shared/lib/usage-tally.ts
|
|
3
|
+
const TallyFields = Schema.Struct({
|
|
4
|
+
library: Schema.String,
|
|
5
|
+
version: Schema.String,
|
|
6
|
+
kind: Schema.String,
|
|
7
|
+
name: Schema.String,
|
|
8
|
+
calls: Schema.Finite
|
|
9
|
+
});
|
|
10
|
+
const TallyList = Schema.Array(TallyFields);
|
|
11
|
+
const SPOOL_ENV = "USAGE_METER_SPOOL";
|
|
12
|
+
const CALLS_METRIC = "code.usage.calls";
|
|
13
|
+
export { SPOOL_ENV as n, TallyList as r, CALLS_METRIC as t };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=usage-tally-FiAxcD-H.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-tally-FiAxcD-H.mjs","names":[],"sources":["../src/shared/lib/usage-tally.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nconst TallyFields = Schema.Struct({\n library: Schema.String,\n version: Schema.String,\n kind: Schema.String,\n name: Schema.String,\n calls: Schema.Finite,\n});\n\nexport type Tally = typeof TallyFields.Type;\n\nexport const TallyList = Schema.Array(TallyFields);\n\nexport const SPOOL_ENV = \"USAGE_METER_SPOOL\";\n\nexport const CALLS_METRIC = \"code.usage.calls\";\n\nexport const NO_CALLS = 0;\n"],"mappings":";;AAEA,MAAM,cAAc,OAAO,OAAO;CAChC,SAAS,OAAO;CAChB,SAAS,OAAO;CAChB,MAAM,OAAO;CACb,MAAM,OAAO;CACb,OAAO,OAAO;AAChB,CAAC;AAID,MAAa,YAAY,OAAO,MAAM,WAAW;AAEjD,MAAa,YAAY;AAEzB,MAAa,eAAe"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Workers } from "@alchemy.run/cloudflare";
|
|
2
|
+
import { Effect, Layer } from "effect";
|
|
1
3
|
import { Worker, WorkerProps } from "@alchemy.run/cloudflare/Workers/Worker";
|
|
2
4
|
import { ProviderService } from "alchemy/Provider";
|
|
3
|
-
import { Effect, Layer } from "effect";
|
|
4
|
-
import { Workers } from "@alchemy.run/cloudflare";
|
|
5
5
|
export declare const COMPATIBILITY_DATE = "2026-08-25";
|
|
6
6
|
interface TraceSinkProps {
|
|
7
7
|
readonly destination?: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Worker } from "@alchemy.run/cloudflare/Workers/Worker";
|
|
2
|
-
import { effect, tryFindProviderRegistrationByType } from "alchemy/Provider";
|
|
3
|
-
import { Array, Effect, Layer, Option, Order, Predicate, Record, Redacted, pipe } from "effect";
|
|
4
1
|
import { Workers } from "@alchemy.run/cloudflare";
|
|
5
2
|
import { makeRandom } from "alchemy";
|
|
3
|
+
import { Array, Effect, Layer, Option, Order, Predicate, Record, Redacted, pipe } from "effect";
|
|
4
|
+
import { Worker } from "@alchemy.run/cloudflare/Workers/Worker";
|
|
5
|
+
import { effect, tryFindProviderRegistrationByType } from "alchemy/Provider";
|
|
6
6
|
import { map } from "alchemy/Output";
|
|
7
7
|
// src/shared/config/compatibility.ts
|
|
8
8
|
const COMPATIBILITY_DATE = "2026-08-25";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@r_masseater/masseater-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The small shared libraries of masseater's repositories as subpaths of one package: a chip row for React, Claude Code plugin helpers, Effect entry points for Node.js and GitHub Actions, file import mapping, Node package readers, OTLP assertions for Vitest and Cloudflare Workers tracing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"actions",
|
|
@@ -50,6 +50,14 @@
|
|
|
50
50
|
"default": "./dist/skerm.mjs"
|
|
51
51
|
},
|
|
52
52
|
"./skerm.css": "./src/app/skerm.css",
|
|
53
|
+
"./usage-meter": {
|
|
54
|
+
"types": "./dist/usage-meter.d.mts",
|
|
55
|
+
"default": "./dist/usage-meter.mjs"
|
|
56
|
+
},
|
|
57
|
+
"./usage-meter/report": {
|
|
58
|
+
"types": "./dist/usage-meter-report.d.mts",
|
|
59
|
+
"default": "./dist/usage-meter-report.mjs"
|
|
60
|
+
},
|
|
53
61
|
"./plugin-kit": {
|
|
54
62
|
"types": "./dist/plugin-kit.d.mts",
|
|
55
63
|
"default": "./dist/plugin-kit.mjs"
|
|
@@ -115,6 +123,10 @@
|
|
|
115
123
|
"default": "./dist/vitest-otlp-collector-files.mjs"
|
|
116
124
|
},
|
|
117
125
|
"./vitest-otlp/tail-worker": "./dist/vitest-otlp-tail-to-otlp.mjs",
|
|
126
|
+
"./app-name": {
|
|
127
|
+
"types": "./dist/app-name.d.mts",
|
|
128
|
+
"default": "./dist/app-name.mjs"
|
|
129
|
+
},
|
|
118
130
|
"./workers-tracing/alchemy": {
|
|
119
131
|
"types": "./dist/workers-tracing-alchemy.d.mts",
|
|
120
132
|
"default": "./dist/workers-tracing-alchemy.mjs"
|
|
@@ -162,9 +174,9 @@
|
|
|
162
174
|
"@alchemy.run/cloudflare": "2.0.0-beta.87",
|
|
163
175
|
"@bufbuild/buf": "1.75.0",
|
|
164
176
|
"@bufbuild/protobuf": "2.17.0",
|
|
165
|
-
"@cloudflare/workers-types": "5.
|
|
166
|
-
"@effect/platform-node": "4.
|
|
167
|
-
"@effect/vitest": "4.
|
|
177
|
+
"@cloudflare/workers-types": "5.20261129.1",
|
|
178
|
+
"@effect/platform-node": "4.2.0",
|
|
179
|
+
"@effect/vitest": "4.2.0",
|
|
168
180
|
"@npmcli/package-json": "8.0.1",
|
|
169
181
|
"@opentelemetry/api": "1.10.0",
|
|
170
182
|
"@opentelemetry/sdk-node": "0.301.2",
|
|
@@ -173,19 +185,19 @@
|
|
|
173
185
|
"@pnpm/workspace.projects-reader": "1101.1.9",
|
|
174
186
|
"@pnpm/workspace.workspace-manifest-reader": "1100.3.4",
|
|
175
187
|
"@pnpm/workspace.workspace-manifest-writer": "1100.2.13",
|
|
176
|
-
"@tanstack/react-start": "1.
|
|
188
|
+
"@tanstack/react-start": "1.170.0",
|
|
177
189
|
"@tanstack/router-core": "1.171.39",
|
|
178
190
|
"@types/node": "26.6.11",
|
|
179
191
|
"@types/npmcli__package-json": "4.0.4",
|
|
180
192
|
"@types/react": "19.3.3",
|
|
181
193
|
"alchemy": "2.0.0-beta.87",
|
|
182
|
-
"effect": "4.
|
|
194
|
+
"effect": "4.2.0",
|
|
183
195
|
"elysia": "1.4.32",
|
|
184
196
|
"miniflare": "4.20260730.0",
|
|
185
197
|
"publint": "0.3.25",
|
|
186
198
|
"react": "19.3.1",
|
|
187
199
|
"ts-content-mapper": "0.1.1",
|
|
188
|
-
"typescript": "7.1.0-dev.
|
|
200
|
+
"typescript": "7.1.0-dev.20261128.1",
|
|
189
201
|
"vite-plus": "1.8.0"
|
|
190
202
|
},
|
|
191
203
|
"peerDependencies": {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: name-stack-resources
|
|
3
|
+
description: >
|
|
4
|
+
Use when an Alchemy stack must be named after its app and every Cloudflare resource in it must
|
|
5
|
+
start with the app name, with @r_masseater/masseater-utils/app-name: appNamed, APP_NAME in
|
|
6
|
+
app-name.ts, and yielding requireAppPrefix at the end of the stack.
|
|
7
|
+
metadata:
|
|
8
|
+
type: core
|
|
9
|
+
library: "@r_masseater/masseater-utils"
|
|
10
|
+
library_version: 0.1.9
|
|
11
|
+
sources:
|
|
12
|
+
- src/app/app-name.ts
|
|
13
|
+
- src/features/name-app/**
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# name-stack-resources
|
|
17
|
+
|
|
18
|
+
The Cloudflare resources of every app share one account, and a name alone does not say which app owns a resource.
|
|
19
|
+
Name the stack after the app and start every named resource with the app name, and the dashboard and the bill both point back to the owning app.
|
|
20
|
+
`appNamed` checks this rule before the deploy goes through.
|
|
21
|
+
|
|
22
|
+
## Declaring the name
|
|
23
|
+
|
|
24
|
+
Each app has one `app-name.ts` that holds the app name and the check.
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { appNamed } from "@r_masseater/masseater-utils/app-name";
|
|
28
|
+
|
|
29
|
+
export const APP_NAME = "example";
|
|
30
|
+
|
|
31
|
+
export const { prefix: PREFIX, requireAppPrefix } = appNamed(APP_NAME);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Pass `APP_NAME` as the stack name, put `PREFIX` in front of every resource `name`, and `yield*` `requireAppPrefix` last in the stack.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { D1 } from "@alchemy.run/cloudflare";
|
|
38
|
+
import { Stack } from "alchemy";
|
|
39
|
+
import { Effect } from "effect";
|
|
40
|
+
|
|
41
|
+
import { APP_NAME, PREFIX, requireAppPrefix } from "./src/shared/config/app-name.ts";
|
|
42
|
+
|
|
43
|
+
export default Stack(
|
|
44
|
+
APP_NAME,
|
|
45
|
+
props,
|
|
46
|
+
Effect.gen(function* stack() {
|
|
47
|
+
yield* D1.Database("Db", { name: `${PREFIX}db` });
|
|
48
|
+
yield* requireAppPrefix;
|
|
49
|
+
return {};
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## What it checks
|
|
55
|
+
|
|
56
|
+
- The stack name equals `APP_NAME`.
|
|
57
|
+
- Every resource that declares a `name` starts with `<APP_NAME>-`. A `Rules.List` cannot hold `-`, so it starts with `<APP_NAME>_`, the app name with `-` replaced by `_`. A `Zone` is named by its domain and is not checked.
|
|
58
|
+
- A resource that declares no `name` is not checked, because Alchemy derives its name from the stack name.
|
|
59
|
+
|
|
60
|
+
When any resource is off, `requireAppPrefix` stops the deploy with an error that lists every offender.
|