@faststats/nitro 0.5.0 → 0.6.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.
@@ -23,7 +23,7 @@ function resolveFaststatsNitroOptions(overrides = {}) {
23
23
  };
24
24
  }
25
25
  const SDK_NAME = "@faststats/nitro";
26
- const SDK_VERSION = "0.5.0";
26
+ const SDK_VERSION = "0.6.0";
27
27
  //#endregion
28
28
  //#region src/context.ts
29
29
  function readPackageVersion(name) {
@@ -145,29 +145,31 @@ const defaultRuntime = {
145
145
  function definedStrings(context) {
146
146
  return Object.fromEntries(Object.entries(context).filter(([, value]) => value !== void 0 && value !== ""));
147
147
  }
148
+ function mergeBucket(target, incoming) {
149
+ target.count += incoming.count;
150
+ if (incoming.path !== void 0) target.path = incoming.path;
151
+ if (incoming.tags.length > 0) target.tags = incoming.tags;
152
+ }
148
153
  function mergeBuckets(target, incoming) {
149
154
  for (const [hash, bucket] of incoming) {
150
155
  const existing = target.get(hash);
151
- if (!existing) {
152
- target.set(hash, { ...bucket });
153
- continue;
154
- }
155
- existing.count += bucket.count;
156
- if (bucket.path !== void 0) existing.path = bucket.path;
157
- if (bucket.tags.length > 0) existing.tags = bucket.tags;
156
+ if (existing) mergeBucket(existing, bucket);
157
+ else target.set(hash, { ...bucket });
158
158
  }
159
159
  }
160
160
  function buildPayload(buckets, options, sessionId) {
161
- const errors = [...buckets.entries()].map(([hash, bucket]) => ({
162
- ...bucket.entry,
163
- hash,
164
- count: bucket.count
165
- }));
166
- const tags = [...new Set([...buckets.values()].flatMap((b) => b.tags))];
161
+ const errors = [];
162
+ const tags = /* @__PURE__ */ new Set();
167
163
  let route;
168
164
  let routeCount = -1;
169
165
  const custom = {};
170
- for (const bucket of buckets.values()) {
166
+ for (const [hash, bucket] of buckets) {
167
+ errors.push({
168
+ ...bucket.entry,
169
+ hash,
170
+ count: bucket.count
171
+ });
172
+ for (const tag of bucket.tags) tags.add(tag);
171
173
  if (bucket.path !== void 0 && bucket.count > routeCount) {
172
174
  routeCount = bucket.count;
173
175
  route = bucket.path;
@@ -184,7 +186,7 @@ function buildPayload(buckets, options, sessionId) {
184
186
  ...definedStrings(buildServerReportContext({
185
187
  route,
186
188
  plugin: options.pluginId,
187
- tags: tags.length > 0 ? tags.join(",") : void 0
189
+ tags: tags.size > 0 ? [...tags].join(",") : void 0
188
190
  })),
189
191
  ...custom
190
192
  }
@@ -202,10 +204,9 @@ function createNitroErrorReporter(options, runtime) {
202
204
  return sessionId;
203
205
  };
204
206
  const clearTimer = () => {
205
- if (timer !== null) {
206
- runtime.clearTimeout(timer);
207
- timer = null;
208
- }
207
+ if (timer === null) return;
208
+ runtime.clearTimeout(timer);
209
+ timer = null;
209
210
  };
210
211
  const scheduleFlush = () => {
211
212
  if (timer !== null) return;
@@ -266,11 +267,12 @@ function createNitroErrorReporter(options, runtime) {
266
267
  if (runtime.now() < pausedUntil) return;
267
268
  const { hash, entry } = hashServerError(error);
268
269
  const existing = buckets.get(hash);
269
- if (existing) {
270
- existing.count += 1;
271
- if (args.path !== void 0) existing.path = args.path;
272
- if (args.tags.length > 0) existing.tags = args.tags;
273
- } else {
270
+ if (existing) mergeBucket(existing, {
271
+ count: 1,
272
+ path: args.path,
273
+ tags: args.tags
274
+ });
275
+ else {
274
276
  let custom = {};
275
277
  if (options.getContext) try {
276
278
  custom = await options.getContext({
@@ -299,11 +301,11 @@ function createNitroErrorReporter(options, runtime) {
299
301
  //#endregion
300
302
  //#region src/plugin-hook.ts
301
303
  function extractPath(event) {
302
- if (!event || typeof event !== "object") return;
304
+ if (!event || typeof event !== "object") return void 0;
303
305
  const e = event;
304
306
  if (e.path) return e.path;
305
307
  const url = e.node?.req?.url;
306
- return url !== void 0 ? String(url) : void 0;
308
+ return url === void 0 ? void 0 : String(url);
307
309
  }
308
310
  function createNitroErrorHook(resolved) {
309
311
  const reporter = createNitroErrorReporter(resolved, defaultRuntime);
package/dist/v2.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as resolveFaststatsNitroOptions, t as createNitroErrorHook } from "./plugin-hook-BMw88N35.mjs";
1
+ import { n as resolveFaststatsNitroOptions, t as createNitroErrorHook } from "./plugin-hook-TnJ41MN2.mjs";
2
2
  import { defineNitroPlugin } from "nitropack/runtime";
3
3
  //#region src/v2.ts
4
4
  function createFaststatsNitroPluginV2(options) {
package/dist/v3.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as resolveFaststatsNitroOptions, t as createNitroErrorHook } from "./plugin-hook-BMw88N35.mjs";
1
+ import { n as resolveFaststatsNitroOptions, t as createNitroErrorHook } from "./plugin-hook-TnJ41MN2.mjs";
2
2
  import { definePlugin } from "nitro";
3
3
  //#region src/v3.ts
4
4
  function createFaststatsNitroPluginV3(options) {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/faststats-dev/faststats-javascript.git"
6
6
  },
7
- "version": "0.5.0",
7
+ "version": "0.6.0",
8
8
  "type": "module",
9
9
  "main": "./dist/v2.mjs",
10
10
  "module": "./dist/v2.mjs",