@ooopsstudio/performance 0.9.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 +21 -0
- package/README.md +50 -0
- package/dist/budget-engine-KDA4FRYU.js +160 -0
- package/dist/budget-engine-KDA4FRYU.js.map +1 -0
- package/dist/chunk-2XXIOHOO.js +58 -0
- package/dist/chunk-2XXIOHOO.js.map +1 -0
- package/dist/chunk-3GMKPRQP.js +197 -0
- package/dist/chunk-3GMKPRQP.js.map +1 -0
- package/dist/chunk-J6KBSLYO.js +118 -0
- package/dist/chunk-J6KBSLYO.js.map +1 -0
- package/dist/chunk-MMO5UEUU.js +20 -0
- package/dist/chunk-MMO5UEUU.js.map +1 -0
- package/dist/chunk-RL2752FW.js +31 -0
- package/dist/chunk-RL2752FW.js.map +1 -0
- package/dist/chunk-RY65GERM.js +159 -0
- package/dist/chunk-RY65GERM.js.map +1 -0
- package/dist/chunk-W72QW2AD.js +29 -0
- package/dist/chunk-W72QW2AD.js.map +1 -0
- package/dist/chunk-ZAXGEDZW.js +1184 -0
- package/dist/chunk-ZAXGEDZW.js.map +1 -0
- package/dist/custom/exporters/http.d.ts +11 -0
- package/dist/custom/exporters/http.js +364 -0
- package/dist/custom/exporters/http.js.map +1 -0
- package/dist/custom/exporters/raw.d.ts +8 -0
- package/dist/custom/exporters/raw.js +6 -0
- package/dist/custom/exporters/raw.js.map +1 -0
- package/dist/custom.d.ts +58 -0
- package/dist/custom.js +299 -0
- package/dist/custom.js.map +1 -0
- package/dist/development.d.ts +19 -0
- package/dist/development.js +55 -0
- package/dist/development.js.map +1 -0
- package/dist/event-export-manager-DEB64LWZ.js +632 -0
- package/dist/event-export-manager-DEB64LWZ.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +205 -0
- package/dist/index.js.map +1 -0
- package/dist/monitors-VNNUIKAK.js +753 -0
- package/dist/monitors-VNNUIKAK.js.map +1 -0
- package/dist/n1-detector-6IQ2DINP.js +247 -0
- package/dist/n1-detector-6IQ2DINP.js.map +1 -0
- package/dist/observability.d.ts +32 -0
- package/dist/observability.js +76 -0
- package/dist/observability.js.map +1 -0
- package/dist/ports-DwUYdKj-.d.ts +23 -0
- package/dist/production.d.ts +19 -0
- package/dist/production.js +42 -0
- package/dist/production.js.map +1 -0
- package/dist/public/types.d.ts +11 -0
- package/dist/public/types.js +3 -0
- package/dist/public/types.js.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { isRuntimeProxy } from './chunk-RL2752FW.js';
|
|
2
|
+
|
|
3
|
+
// src/performance/core/utils/event-helpers.ts
|
|
4
|
+
var RESOURCE_SNAPSHOT_EVENT_NAMES = /* @__PURE__ */ new Set(["cpu_usage", "memory_usage"]);
|
|
5
|
+
function isResourceSnapshotEvent(source, name) {
|
|
6
|
+
return source === "runtime" && RESOURCE_SNAPSHOT_EVENT_NAMES.has(name);
|
|
7
|
+
}
|
|
8
|
+
function clonePerformanceValue(value) {
|
|
9
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
let remainingNodes = 512;
|
|
11
|
+
let remainingCharacters = 16384;
|
|
12
|
+
const clone = (current, depth = 0) => {
|
|
13
|
+
if (typeof current === "string") {
|
|
14
|
+
const length = Math.min(current.length, remainingCharacters, 1024);
|
|
15
|
+
remainingCharacters -= length;
|
|
16
|
+
return current.slice(0, length);
|
|
17
|
+
}
|
|
18
|
+
if (typeof current === "bigint") return current.toString();
|
|
19
|
+
if (current === null || typeof current !== "object" && typeof current !== "function") return current;
|
|
20
|
+
if (typeof current === "function" || isRuntimeProxy(current) || depth > 8 || remainingNodes-- <= 0) return void 0;
|
|
21
|
+
const existing = seen.get(current);
|
|
22
|
+
if (existing !== void 0) return existing;
|
|
23
|
+
try {
|
|
24
|
+
const timestamp = Reflect.apply(Date.prototype.getTime, current, []);
|
|
25
|
+
const snapshot = new Date(timestamp);
|
|
26
|
+
seen.set(current, snapshot);
|
|
27
|
+
return snapshot;
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
if (Array.isArray(current)) {
|
|
32
|
+
const result2 = [];
|
|
33
|
+
seen.set(current, result2);
|
|
34
|
+
const lengthDescriptor = Object.getOwnPropertyDescriptor(current, "length");
|
|
35
|
+
const length = Math.min(lengthDescriptor && "value" in lengthDescriptor ? lengthDescriptor.value : 0, 32);
|
|
36
|
+
for (let index = 0; index < length; index += 1) {
|
|
37
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, String(index));
|
|
38
|
+
result2.push(descriptor && "value" in descriptor ? clone(descriptor.value, depth + 1) : void 0);
|
|
39
|
+
}
|
|
40
|
+
return result2;
|
|
41
|
+
}
|
|
42
|
+
} catch {
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
46
|
+
seen.set(current, result);
|
|
47
|
+
let copied = 0;
|
|
48
|
+
try {
|
|
49
|
+
for (const key in current) {
|
|
50
|
+
if (copied >= 64) break;
|
|
51
|
+
if (key === "__proto__" || key === "prototype" || key === "constructor") continue;
|
|
52
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
53
|
+
if (!descriptor?.enumerable || !("value" in descriptor)) continue;
|
|
54
|
+
const cloned = clone(descriptor.value, depth + 1);
|
|
55
|
+
if (cloned !== void 0 || descriptor.value === void 0) result[key] = cloned;
|
|
56
|
+
copied += 1;
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
return clone(value);
|
|
64
|
+
}
|
|
65
|
+
var SAFE_DB_FIELDS = /* @__PURE__ */ new Set([
|
|
66
|
+
"operation",
|
|
67
|
+
"table",
|
|
68
|
+
"collection",
|
|
69
|
+
"rows",
|
|
70
|
+
"method",
|
|
71
|
+
"limit",
|
|
72
|
+
"offset",
|
|
73
|
+
"orderBy",
|
|
74
|
+
"permissionExpansion",
|
|
75
|
+
"projection",
|
|
76
|
+
"documentCount",
|
|
77
|
+
"payloadSize",
|
|
78
|
+
"statusCode",
|
|
79
|
+
"retryCount",
|
|
80
|
+
"timeout",
|
|
81
|
+
"success",
|
|
82
|
+
"failureCode",
|
|
83
|
+
"queryHash"
|
|
84
|
+
]);
|
|
85
|
+
function snapshotSafeDBMetadata(value) {
|
|
86
|
+
if (!value || typeof value !== "object" || isRuntimeProxy(value) || Array.isArray(value)) return void 0;
|
|
87
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
88
|
+
for (const key of SAFE_DB_FIELDS) {
|
|
89
|
+
let descriptor;
|
|
90
|
+
try {
|
|
91
|
+
descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
92
|
+
} catch {
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
95
|
+
if (!descriptor?.enumerable || !("value" in descriptor)) continue;
|
|
96
|
+
const field = descriptor.value;
|
|
97
|
+
if (key === "failureCode") {
|
|
98
|
+
if (field === "query_failed") result[key] = field;
|
|
99
|
+
} else if (typeof field === "string") result[key] = field.slice(0, 256);
|
|
100
|
+
else if (typeof field === "number" && Number.isFinite(field)) result[key] = field;
|
|
101
|
+
else if (typeof field === "boolean") result[key] = field;
|
|
102
|
+
else {
|
|
103
|
+
const values = clonePerformanceValue(field);
|
|
104
|
+
if (Array.isArray(values)) result[key] = values.filter((item) => typeof item === "string").map((item) => item.slice(0, 128));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
function deepFreezePerformanceValue(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
110
|
+
if (!value || typeof value !== "object" || seen.has(value)) return value;
|
|
111
|
+
seen.add(value);
|
|
112
|
+
for (const child of Object.values(value)) deepFreezePerformanceValue(child, seen);
|
|
113
|
+
return Object.freeze(value);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { clonePerformanceValue, deepFreezePerformanceValue, isResourceSnapshotEvent, snapshotSafeDBMetadata };
|
|
117
|
+
//# sourceMappingURL=chunk-J6KBSLYO.js.map
|
|
118
|
+
//# sourceMappingURL=chunk-J6KBSLYO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/performance/core/utils/event-helpers.ts"],"names":["result"],"mappings":";;;AAYA,IAAM,gDAAgC,IAAI,GAAA,CAAI,CAAC,WAAA,EAAa,cAAc,CAAC,CAAA;AAUpE,SAAS,uBAAA,CAAwB,QAAgB,IAAA,EAAuB;AAC9E,EAAA,OAAO,MAAA,KAAW,SAAA,IAAa,6BAAA,CAA8B,GAAA,CAAI,IAAI,CAAA;AACtE;AAGO,SAAS,sBAAyB,KAAA,EAAa;AACrD,EAAA,MAAM,IAAA,uBAAW,OAAA,EAAyB;AAC1C,EAAA,IAAI,cAAA,GAAiB,GAAA;AACrB,EAAA,IAAI,mBAAA,GAAsB,KAAA;AAC1B,EAAA,MAAM,KAAA,GAAQ,CAAC,OAAA,EAAkB,KAAA,GAAQ,CAAA,KAAe;AACvD,IAAA,IAAI,OAAO,YAAY,QAAA,EAAU;AAChC,MAAA,MAAM,SAAS,IAAA,CAAK,GAAA,CAAI,OAAA,CAAQ,MAAA,EAAQ,qBAAqB,IAAK,CAAA;AAClE,MAAA,mBAAA,IAAuB,MAAA;AACvB,MAAA,OAAO,OAAA,CAAQ,KAAA,CAAM,CAAA,EAAG,MAAM,CAAA;AAAA,IAC/B;AACA,IAAA,IAAI,OAAO,OAAA,KAAY,QAAA,EAAU,OAAO,QAAQ,QAAA,EAAS;AACzD,IAAA,IAAI,OAAA,KAAY,QAAS,OAAO,OAAA,KAAY,YAAY,OAAO,OAAA,KAAY,YAAa,OAAO,OAAA;AAC/F,IAAA,IAAI,OAAO,OAAA,KAAY,UAAA,IAAc,cAAA,CAAe,OAAO,KAAK,KAAA,GAAQ,CAAA,IAAK,cAAA,EAAA,IAAoB,CAAA,EAAG,OAAO,MAAA;AAC3G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Q,MAAM,CAAA,SAAU,GAAG,CAAA,GAAI,MAAA,CACvC,MAAA,CAAO,CAAC,IAAA,KAAyB,OAAO,IAAA,KAAS,QAAQ,EACzD,GAAA,CAAI,CAAC,SAAS,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,GAAG,CAAC,CAAA;AAAA,IACnC;AAAA,EACD;AACA,EAAA,OAAO,MAAA;AACR;AAEO,SAAS,0BAAA,CAA8B,KAAA,EAAU,IAAA,mBAAO,IAAI,SAAgB,EAAM;AACxF,EAAA,IAAI,CAAC,SAAS,OAAO,KAAA,KAAU,YAAY,IAAA,CAAK,GAAA,CAAI,KAAK,CAAA,EAAG,OAAO,KAAA;AACnE,EAAA,IAAA,CAAK,IAAI,KAAK,CAAA;AACd,EAAA,KAAA,MAAW,SAAS,MAAA,CAAO,MAAA,CAAO,KAAgC,CAAA,EAAG,0BAAA,CAA2B,OAAO,IAAI,CAAA;AAC3G,EAAA,OAAO,MAAA,CAAO,OAAO,KAAK,CAAA;AAC3B","file":"chunk-J6KBSLYO.js","sourcesContent":["/**\n * @file Event helper utilities for performance service.\n * Shared constants and functions for event processing.\n */\n\nimport {isRuntimeProxy} from '../../utils/safe-object'\n\n/**\n * DB event name prefix\n */\nexport const DB_EVENT_PREFIX = 'db.'\n\nconst RESOURCE_SNAPSHOT_EVENT_NAMES = new Set(['cpu_usage', 'memory_usage'])\n\n/**\n * Check if an event name is a DB event\n */\nexport function isDBEvent(name: string): boolean {\n\treturn name.startsWith(DB_EVENT_PREFIX)\n}\n\n/** Runtime resource snapshots carry changing numeric values, not dimensions. */\nexport function isResourceSnapshotEvent(source: string, name: string): boolean {\n\treturn source === 'runtime' && RESOURCE_SNAPSHOT_EVENT_NAMES.has(name)\n}\n\n/** Deeply snapshots plain performance payloads even when structuredClone rejects custom values. */\nexport function clonePerformanceValue<T>(value: T): T {\n\tconst seen = new WeakMap<object, unknown>()\n\tlet remainingNodes = 512\n\tlet remainingCharacters = 16_384\n\tconst clone = (current: unknown, depth = 0): unknown => {\n\t\tif (typeof current === 'string') {\n\t\t\tconst length = Math.min(current.length, remainingCharacters, 1_024)\n\t\t\tremainingCharacters -= length\n\t\t\treturn current.slice(0, length)\n\t\t}\n\t\tif (typeof current === 'bigint') return current.toString()\n\t\tif (current === null || (typeof current !== 'object' && typeof current !== 'function')) return current\n\t\tif (typeof current === 'function' || isRuntimeProxy(current) || depth > 8 || remainingNodes-- <= 0) return undefined\n\t\tconst existing = seen.get(current)\n\t\tif (existing !== undefined) return existing\n\t\ttry {\n\t\t\tconst timestamp = Reflect.apply(Date.prototype.getTime, current, []) as number\n\t\t\tconst snapshot = new Date(timestamp)\n\t\t\tseen.set(current, snapshot)\n\t\t\treturn snapshot\n\t\t} catch { /* native brand check identifies non-Date values without walking prototypes */ }\n\t\ttry {\n\t\t\tif (Array.isArray(current)) {\n\t\t\t\tconst result: unknown[] = []\n\t\t\t\tseen.set(current, result)\n\t\t\t\tconst lengthDescriptor = Object.getOwnPropertyDescriptor(current, 'length')\n\t\t\t\tconst length = Math.min(lengthDescriptor && 'value' in lengthDescriptor\n\t\t\t\t\t? lengthDescriptor.value as number : 0, 32)\n\t\t\t\tfor (let index = 0; index < length; index += 1) {\n\t\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(current, String(index))\n\t\t\t\t\tresult.push(descriptor && 'value' in descriptor ? clone(descriptor.value, depth + 1) : undefined)\n\t\t\t\t}\n\t\t\t\treturn result\n\t\t\t}\n\t\t} catch {\n\t\t\treturn undefined\n\t\t}\n\t\tconst result: Record<string, unknown> = Object.create(null) as Record<string, unknown>\n\t\tseen.set(current, result)\n\t\tlet copied = 0\n\t\ttry {\n\t\t\tfor (const key in current) {\n\t\t\t\tif (copied >= 64) break\n\t\t\t\tif (key === '__proto__' || key === 'prototype' || key === 'constructor') continue\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(current, key)\n\t\t\t\tif (!descriptor?.enumerable || !('value' in descriptor)) continue\n\t\t\t\tconst cloned = clone(descriptor.value, depth + 1)\n\t\t\t\tif (cloned !== undefined || descriptor.value === undefined) result[key] = cloned\n\t\t\t\tcopied += 1\n\t\t\t}\n\t\t} catch { return result }\n\t\treturn result\n\t}\n\treturn clone(value) as T\n}\n\nconst SAFE_DB_FIELDS = new Set([\n\t'operation', 'table', 'collection', 'rows', 'method', 'limit', 'offset',\n\t'orderBy', 'permissionExpansion', 'projection', 'documentCount', 'payloadSize',\n\t'statusCode', 'retryCount', 'timeout', 'success', 'failureCode', 'queryHash'\n])\n\n/** Captures only the non-sensitive DB metadata contract. */\nexport function snapshotSafeDBMetadata(value: unknown): import('@ooopsstudio/core/contracts/performance').DBQueryMetadata | undefined {\n\tif (!value || typeof value !== 'object' || isRuntimeProxy(value) || Array.isArray(value)) return undefined\n\tconst result: Record<string, unknown> = Object.create(null) as Record<string, unknown>\n\tfor (const key of SAFE_DB_FIELDS) {\n\t\tlet descriptor: PropertyDescriptor | undefined\n\t\ttry { descriptor = Object.getOwnPropertyDescriptor(value, key) } catch { return undefined }\n\t\tif (!descriptor?.enumerable || !('value' in descriptor)) continue\n\t\tconst field = descriptor.value\n\t\tif (key === 'failureCode') {\n\t\t\tif (field === 'query_failed') result[key] = field\n\t\t} else if (typeof field === 'string') result[key] = field.slice(0, 256)\n\t\telse if (typeof field === 'number' && Number.isFinite(field)) result[key] = field\n\t\telse if (typeof field === 'boolean') result[key] = field\n\t\telse {\n\t\t\tconst values = clonePerformanceValue(field)\n\t\t\tif (Array.isArray(values)) result[key] = values\n\t\t\t\t.filter((item): item is string => typeof item === 'string')\n\t\t\t\t.map((item) => item.slice(0, 128))\n\t\t}\n\t}\n\treturn result as import('@ooopsstudio/core/contracts/performance').DBQueryMetadata\n}\n\nexport function deepFreezePerformanceValue<T>(value: T, seen = new WeakSet<object>()): T {\n\tif (!value || typeof value !== 'object' || seen.has(value)) return value\n\tseen.add(value)\n\tfor (const child of Object.values(value as Record<string, unknown>)) deepFreezePerformanceValue(child, seen)\n\treturn Object.freeze(value)\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/performance/core/runtime-capabilities.ts
|
|
2
|
+
var dispatchers = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function registerPerformanceDispatcher(performance, dispatcher) {
|
|
4
|
+
dispatchers.set(performance, dispatcher);
|
|
5
|
+
}
|
|
6
|
+
function attachPerformanceTelemetry(performance, callbacks) {
|
|
7
|
+
const dispatcher = dispatchers.get(performance);
|
|
8
|
+
if (!dispatcher) throw new Error("PERFORMANCE_TELEMETRY_UNAVAILABLE");
|
|
9
|
+
dispatcher.add(callbacks);
|
|
10
|
+
let active = true;
|
|
11
|
+
return () => {
|
|
12
|
+
if (!active) return;
|
|
13
|
+
active = false;
|
|
14
|
+
dispatcher.remove(callbacks);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { attachPerformanceTelemetry, registerPerformanceDispatcher };
|
|
19
|
+
//# sourceMappingURL=chunk-MMO5UEUU.js.map
|
|
20
|
+
//# sourceMappingURL=chunk-MMO5UEUU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/performance/core/runtime-capabilities.ts"],"names":[],"mappings":";AAIA,IAAM,WAAA,uBAAkB,OAAA,EAA+C;AAEhE,SAAS,6BAAA,CACf,aACA,UAAA,EACO;AACP,EAAA,WAAA,CAAY,GAAA,CAAI,aAAa,UAAU,CAAA;AACxC;AAEO,SAAS,0BAAA,CACf,aACA,SAAA,EACa;AACb,EAAA,MAAM,UAAA,GAAa,WAAA,CAAY,GAAA,CAAI,WAAW,CAAA;AAC9C,EAAA,IAAI,CAAC,UAAA,EAAY,MAAM,IAAI,MAAM,mCAAmC,CAAA;AACpE,EAAA,UAAA,CAAW,IAAI,SAAS,CAAA;AACxB,EAAA,IAAI,MAAA,GAAS,IAAA;AACb,EAAA,OAAO,MAAM;AACZ,IAAA,IAAI,CAAC,MAAA,EAAQ;AACb,IAAA,MAAA,GAAS,KAAA;AACT,IAAA,UAAA,CAAW,OAAO,SAAS,CAAA;AAAA,EAC5B,CAAA;AACD","file":"chunk-MMO5UEUU.js","sourcesContent":["import type {ManagedPerformance} from '../types/ports'\n\nimport type {PerformanceCallbackDispatcher, PerformanceTelemetryCallbacks} from './callback-dispatcher'\n\nconst dispatchers = new WeakMap<object, PerformanceCallbackDispatcher>()\n\nexport function registerPerformanceDispatcher(\n\tperformance: ManagedPerformance,\n\tdispatcher: PerformanceCallbackDispatcher\n): void {\n\tdispatchers.set(performance, dispatcher)\n}\n\nexport function attachPerformanceTelemetry(\n\tperformance: ManagedPerformance,\n\tcallbacks: PerformanceTelemetryCallbacks\n): () => void {\n\tconst dispatcher = dispatchers.get(performance)\n\tif (!dispatcher) throw new Error('PERFORMANCE_TELEMETRY_UNAVAILABLE')\n\tdispatcher.add(callbacks)\n\tlet active = true\n\treturn () => {\n\t\tif (!active) return\n\t\tactive = false\n\t\tdispatcher.remove(callbacks)\n\t}\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { types } from 'util';
|
|
2
|
+
|
|
3
|
+
// src/performance/utils/safe-object.ts
|
|
4
|
+
var isRuntimeProxy = types.isProxy;
|
|
5
|
+
var isRuntimePromise = types.isPromise;
|
|
6
|
+
var ignoreRuntimePromiseRejection = (value) => {
|
|
7
|
+
if (!isRuntimePromise(value)) return;
|
|
8
|
+
try {
|
|
9
|
+
void Reflect.apply(Promise.prototype.then, value, [void 0, () => void 0]);
|
|
10
|
+
} catch {
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var isRuntimeError = types.isNativeError;
|
|
14
|
+
var hasSafeRuntimePrototype = (value, expected) => {
|
|
15
|
+
if (!value || typeof value !== "object" && typeof value !== "function") return false;
|
|
16
|
+
try {
|
|
17
|
+
let owner = value;
|
|
18
|
+
for (let depth = 0; owner && depth < 32; depth += 1) {
|
|
19
|
+
if (isRuntimeProxy(owner)) return false;
|
|
20
|
+
if (owner === expected) return true;
|
|
21
|
+
owner = Object.getPrototypeOf(owner);
|
|
22
|
+
}
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { hasSafeRuntimePrototype, ignoreRuntimePromiseRejection, isRuntimeError, isRuntimePromise, isRuntimeProxy };
|
|
30
|
+
//# sourceMappingURL=chunk-RL2752FW.js.map
|
|
31
|
+
//# sourceMappingURL=chunk-RL2752FW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/performance/utils/safe-object.ts"],"names":[],"mappings":";;;AAGO,IAAM,iBAAiB,KAAA,CAAM;AAG7B,IAAM,mBAAmB,KAAA,CAAM;AAG/B,IAAM,6BAAA,GAAgC,CAAC,KAAA,KAAyB;AACtE,EAAA,IAAI,CAAC,gBAAA,CAAiB,KAAK,CAAA,EAAG;AAC9B,EAAA,IAAI;AACH,IAAA,KAAK,OAAA,CAAQ,KAAA,CAAM,OAAA,CAAQ,SAAA,CAAU,IAAA,EAAM,OAAO,CAAC,KAAA,CAAA,EAAW,MAAM,KAAA,CAAS,CAAC,CAAA;AAAA,EAC/E,CAAA,CAAA,MAAQ;AAAA,EAER;AACD;AAGO,IAAM,iBAAiB,KAAA,CAAM;AAG7B,IAAM,uBAAA,GAA0B,CAAC,KAAA,EAAgB,QAAA,KAA8B;AACrF,EAAA,IAAI,CAAC,SAAU,OAAO,KAAA,KAAU,YAAY,OAAO,KAAA,KAAU,YAAa,OAAO,KAAA;AACjF,EAAA,IAAI;AACH,IAAA,IAAI,KAAA,GAAuB,KAAA;AAC3B,IAAA,KAAA,IAAS,QAAQ,CAAA,EAAG,KAAA,IAAS,KAAA,GAAQ,EAAA,EAAI,SAAS,CAAA,EAAG;AACpD,MAAA,IAAI,cAAA,CAAe,KAAK,CAAA,EAAG,OAAO,KAAA;AAClC,MAAA,IAAI,KAAA,KAAU,UAAU,OAAO,IAAA;AAC/B,MAAA,KAAA,GAAQ,MAAA,CAAO,eAAe,KAAK,CAAA;AAAA,IACpC;AAAA,EACD,CAAA,CAAA,MAAQ;AAAE,IAAA,OAAO,KAAA;AAAA,EAAM;AACvB,EAAA,OAAO,KAAA;AACR","file":"chunk-RL2752FW.js","sourcesContent":["import {types} from 'node:util'\n\n/** Rejects runtime proxies before any operation that could invoke user traps. */\nexport const isRuntimeProxy = types.isProxy as (value: unknown) => boolean\n\n/** Recognizes native promises without reading an arbitrary `then` property. */\nexport const isRuntimePromise = types.isPromise as (value: unknown) => boolean\n\n/** Observes rejections from genuine promises without assimilating arbitrary thenables. */\nexport const ignoreRuntimePromiseRejection = (value: unknown): void => {\n\tif (!isRuntimePromise(value)) return\n\ttry {\n\t\tvoid Reflect.apply(Promise.prototype.then, value, [undefined, () => undefined])\n\t} catch {\n\t\t// Observation is best-effort and must remain fail-safe.\n\t}\n}\n\n/** Recognizes native Error values without prototype-chain traversal. */\nexport const isRuntimeError = types.isNativeError as (value: unknown) => boolean\n\n/** Walks an ordinary prototype chain while stopping before any Proxy hop. */\nexport const hasSafeRuntimePrototype = (value: unknown, expected: object): boolean => {\n\tif (!value || (typeof value !== 'object' && typeof value !== 'function')) return false\n\ttry {\n\t\tlet owner: object | null = value\n\t\tfor (let depth = 0; owner && depth < 32; depth += 1) {\n\t\t\tif (isRuntimeProxy(owner)) return false\n\t\t\tif (owner === expected) return true\n\t\t\towner = Object.getPrototypeOf(owner) as object | null\n\t\t}\n\t} catch { return false }\n\treturn false\n}\n"]}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { isRuntimeProxy, isRuntimePromise, ignoreRuntimePromiseRejection } from './chunk-RL2752FW.js';
|
|
2
|
+
import { createServiceErrorReporter } from '@ooopsstudio/core/runtime/runtime/service-error-reporter';
|
|
3
|
+
|
|
4
|
+
var captureReport = (errors) => {
|
|
5
|
+
if (!errors || isRuntimeProxy(errors)) return void 0;
|
|
6
|
+
try {
|
|
7
|
+
let owner = errors;
|
|
8
|
+
for (let depth = 0; owner && depth < 16; depth += 1) {
|
|
9
|
+
if (isRuntimeProxy(owner)) return void 0;
|
|
10
|
+
const descriptor = Object.getOwnPropertyDescriptor(owner, "report");
|
|
11
|
+
if (descriptor) return "value" in descriptor && typeof descriptor.value === "function" ? descriptor.value : void 0;
|
|
12
|
+
owner = Object.getPrototypeOf(owner);
|
|
13
|
+
}
|
|
14
|
+
} catch {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
return void 0;
|
|
18
|
+
};
|
|
19
|
+
function createPerformanceOnError(errors, fixedContext) {
|
|
20
|
+
const report = captureReport(errors);
|
|
21
|
+
let pending = false;
|
|
22
|
+
const guardedErrors = report && errors ? {
|
|
23
|
+
report(...args) {
|
|
24
|
+
if (pending) return;
|
|
25
|
+
pending = true;
|
|
26
|
+
let result;
|
|
27
|
+
try {
|
|
28
|
+
result = Reflect.apply(report, errors, args);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
pending = false;
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
if (!isRuntimePromise(result)) {
|
|
34
|
+
pending = false;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const release = () => {
|
|
38
|
+
pending = false;
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
void Reflect.apply(Promise.prototype.then, result, [release, release]);
|
|
42
|
+
} catch {
|
|
43
|
+
release();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} : void 0;
|
|
47
|
+
return createServiceErrorReporter({
|
|
48
|
+
...guardedErrors ? { errors: guardedErrors } : {},
|
|
49
|
+
...fixedContext ? { fixedContext } : {},
|
|
50
|
+
serviceName: "performance"
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/performance/core/clock.ts
|
|
55
|
+
var captureClockMethod = (clock, key) => {
|
|
56
|
+
if (!clock || typeof clock !== "object" && typeof clock !== "function" || isRuntimeProxy(clock)) return void 0;
|
|
57
|
+
try {
|
|
58
|
+
let owner = clock;
|
|
59
|
+
for (let depth = 0; owner && depth < 16; depth += 1) {
|
|
60
|
+
if (isRuntimeProxy(owner)) return void 0;
|
|
61
|
+
const descriptor = Object.getOwnPropertyDescriptor(owner, key);
|
|
62
|
+
if (descriptor) {
|
|
63
|
+
if (!("value" in descriptor) || typeof descriptor.value !== "function") return void 0;
|
|
64
|
+
const method = descriptor.value;
|
|
65
|
+
let valid = true;
|
|
66
|
+
return () => {
|
|
67
|
+
if (!valid) return void 0;
|
|
68
|
+
valid = false;
|
|
69
|
+
let result;
|
|
70
|
+
try {
|
|
71
|
+
result = Reflect.apply(method, clock, []);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
valid = true;
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
if (isRuntimePromise(result)) {
|
|
77
|
+
ignoreRuntimePromiseRejection(result);
|
|
78
|
+
} else valid = true;
|
|
79
|
+
return result;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
owner = Object.getPrototypeOf(owner);
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
return void 0;
|
|
88
|
+
};
|
|
89
|
+
function createHighResClock(options = {}) {
|
|
90
|
+
if (!options || typeof options !== "object" || isRuntimeProxy(options)) {
|
|
91
|
+
throw new Error("High-resolution clock options must be an object");
|
|
92
|
+
}
|
|
93
|
+
const clockDescriptor = Object.getOwnPropertyDescriptor(options, "clock");
|
|
94
|
+
if (clockDescriptor && !("value" in clockDescriptor)) {
|
|
95
|
+
throw new Error("High-resolution clock requires clock to be a data property");
|
|
96
|
+
}
|
|
97
|
+
const baseClock = clockDescriptor?.value ?? { now: Date.now };
|
|
98
|
+
const providedNow = captureClockMethod(baseClock, "now");
|
|
99
|
+
if (!providedNow) {
|
|
100
|
+
throw new Error("High-resolution clock requires a clock with now()");
|
|
101
|
+
}
|
|
102
|
+
let lastNow = Number.NEGATIVE_INFINITY;
|
|
103
|
+
const now = () => {
|
|
104
|
+
let current = Number.NaN;
|
|
105
|
+
try {
|
|
106
|
+
current = providedNow();
|
|
107
|
+
} catch {
|
|
108
|
+
}
|
|
109
|
+
if (!Number.isFinite(current)) {
|
|
110
|
+
if (!Number.isFinite(lastNow)) lastNow = Date.now();
|
|
111
|
+
return lastNow;
|
|
112
|
+
}
|
|
113
|
+
return lastNow = Math.max(lastNow, current);
|
|
114
|
+
};
|
|
115
|
+
const providedNowHr = captureClockMethod(baseClock, "nowHr");
|
|
116
|
+
if (providedNowHr) {
|
|
117
|
+
let lastNowHr = 0n;
|
|
118
|
+
return {
|
|
119
|
+
now,
|
|
120
|
+
nowHr: () => {
|
|
121
|
+
let current;
|
|
122
|
+
try {
|
|
123
|
+
current = providedNowHr();
|
|
124
|
+
} catch {
|
|
125
|
+
return lastNowHr;
|
|
126
|
+
}
|
|
127
|
+
if (typeof current !== "bigint" || current < 0n) return lastNowHr;
|
|
128
|
+
return lastNowHr = current > lastNowHr ? current : lastNowHr;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (typeof process !== "undefined" && typeof process.hrtime?.bigint === "function") {
|
|
133
|
+
const origin2 = process.hrtime.bigint();
|
|
134
|
+
return {
|
|
135
|
+
now,
|
|
136
|
+
nowHr: () => process.hrtime.bigint() - origin2
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const perf = typeof performance !== "undefined" && performance;
|
|
140
|
+
if (perf && typeof perf.now === "function") {
|
|
141
|
+
const origin2 = perf.now();
|
|
142
|
+
return {
|
|
143
|
+
now,
|
|
144
|
+
nowHr: () => BigInt(Math.floor((perf.now() - origin2) * 1e6))
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const origin = Date.now();
|
|
148
|
+
return {
|
|
149
|
+
now,
|
|
150
|
+
nowHr: () => BigInt(Math.floor((Date.now() - origin) * 1e6))
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function nsToMs(ns) {
|
|
154
|
+
return Number(ns) / 1e6;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { createHighResClock, createPerformanceOnError, nsToMs };
|
|
158
|
+
//# sourceMappingURL=chunk-RY65GERM.js.map
|
|
159
|
+
//# sourceMappingURL=chunk-RY65GERM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/performance/utils/on-error.ts","../src/performance/core/clock.ts"],"names":["origin"],"mappings":";;;AAYA,IAAM,aAAA,GAAgB,CAAC,MAAA,KAAyD;AAC/E,EAAA,IAAI,CAAC,MAAA,IAAU,cAAA,CAAe,MAAM,GAAG,OAAO,MAAA;AAC9C,EAAA,IAAI;AACH,IAAA,IAAI,KAAA,GAAuB,MAAA;AAC3B,IAAA,KAAA,IAAS,QAAQ,CAAA,EAAG,KAAA,IAAS,KAAA,GAAQ,EAAA,EAAI,SAAS,CAAA,EAAG;AACpD,MAAA,IAAI,cAAA,CAAe,KAAK,CAAA,EAAG,OAAO,KAAA,CAAA;AAClC,MAAA,MAAM,UAAA,GAAa,MAAA,CAAO,wBAAA,CAAyB,KAAA,EAAO,QAAQ,CAAA;AAClE,MAAA,IAAI,UAAA,SAAmB,OAAA,IAAW,UAAA,IAAc,OAAO,UAAA,CAAW,KAAA,KAAU,UAAA,GACzE,UAAA,CAAW,KAAA,GACX,KAAA,CAAA;AACH,MAAA,KAAA,GAAQ,MAAA,CAAO,eAAe,KAAK,CAAA;AAAA,IACpC;AAAA,EACD,CAAA,CAAA,MAAQ;AAAE,IAAA,OAAO,MAAA;AAAA,EAAU;AAC3B,EAAA,OAAO,MAAA;AACR,CAAA;AAUO,SAAS,wBAAA,CACf,QACA,YAAA,EAC2D;AAC3D,EAAA,MAAM,MAAA,GAAS,cAAc,MAAM,CAAA;AACnC,EAAA,IAAI,OAAA,GAAU,KAAA;AACd,EAAA,MAAM,aAAA,GAAgB,UAAU,MAAA,GAAS;AAAA,IACxC,UAAU,IAAA,EAAuB;AAChC,MAAA,IA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,GAAI,GAAA;AACrB","file":"chunk-RY65GERM.js","sourcesContent":["/**\n * @file Error handling utilities for performance service.\n * Uses shared service error reporter from engines with registry fallback.\n */\n\nimport type {Errors} from '@ooopsstudio/core/ports/errors'\nimport {createServiceErrorReporter} from '@ooopsstudio/core/runtime/runtime/service-error-reporter'\n\nimport {isRuntimePromise, isRuntimeProxy} from './safe-object'\n\ntype ReportMethod = (...args: unknown[]) => unknown\n\nconst captureReport = (errors: Errors | undefined): ReportMethod | undefined => {\n\tif (!errors || isRuntimeProxy(errors)) return undefined\n\ttry {\n\t\tlet owner: object | null = errors\n\t\tfor (let depth = 0; owner && depth < 16; depth += 1) {\n\t\t\tif (isRuntimeProxy(owner)) return undefined\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(owner, 'report')\n\t\t\tif (descriptor) return 'value' in descriptor && typeof descriptor.value === 'function'\n\t\t\t\t? descriptor.value as ReportMethod\n\t\t\t\t: undefined\n\t\t\towner = Object.getPrototypeOf(owner) as object | null\n\t\t}\n\t} catch { return undefined }\n\treturn undefined\n}\n\n/**\n * Create an error handler function for performance stage errors.\n * Uses shared service error reporter from engines with registry fallback.\n *\n * @param errors - Optional errors port\n * @param fixedContext - Fixed context to include with all errors\n * @returns Error handler function\n */\nexport function createPerformanceOnError(\n\terrors?: Errors,\n\tfixedContext?: Record<string, string>\n): (error: unknown, extra?: Record<string, string>) => void {\n\tconst report = captureReport(errors)\n\tlet pending = false\n\tconst guardedErrors = report && errors ? {\n\t\treport(...args: unknown[]): void {\n\t\t\tif (pending) return\n\t\t\tpending = true\n\t\t\tlet result: unknown\n\t\t\ttry { result = Reflect.apply(report, errors, args) } catch(error) {\n\t\t\t\tpending = false\n\t\t\t\tthrow error\n\t\t\t}\n\t\t\tif (!isRuntimePromise(result)) { pending = false; return }\n\t\t\tconst release = () => { pending = false }\n\t\t\ttry { void Reflect.apply(Promise.prototype.then, result, [release, release]) }\n\t\t\tcatch { release() }\n\t\t}\n\t} as Errors : undefined\n\treturn createServiceErrorReporter({\n\t\t...(guardedErrors ? {errors: guardedErrors} : {}),\n\t\t...(fixedContext ? {fixedContext} : {}),\n\t\tserviceName: 'performance'\n\t})\n}\n","/**\n * @file High-resolution clock wrapper for performance measurements.\n * Extends Clock with high-resolution timing using bigint nanoseconds.\n */\n\nimport type {Clock} from '@ooopsstudio/core/contracts/clock'\n\nimport {ignoreRuntimePromiseRejection, isRuntimePromise, isRuntimeProxy} from '../utils/safe-object'\n\n/**\n * High-resolution clock interface extending Clock with nanosecond precision\n */\nexport interface HighResClock extends Clock {\n\n\t/** High-resolution monotonic time in nanoseconds (bigint) */\n\tnowHr(): bigint\n\n\t/** Current time in milliseconds (inherited from Clock) */\n\tnow(): number\n}\n\n/**\n * Options for creating a high-resolution clock\n */\nexport interface HighResClockOptions {\n\n\t/** Base clock to wrap (defaults to system clock) */\n\tclock?: Clock\n}\n\nconst captureClockMethod = (clock: unknown, key: 'now' | 'nowHr'): (() => unknown) | undefined => {\n\tif (!clock || (typeof clock !== 'object' && typeof clock !== 'function') || isRuntimeProxy(clock)) return undefined\n\ttry {\n\t\tlet owner: object | null = clock\n\t\tfor (let depth = 0; owner && depth < 16; depth += 1) {\n\t\t\tif (isRuntimeProxy(owner)) return undefined\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(owner, key)\n\t\t\tif (descriptor) {\n\t\t\t\tif (!('value' in descriptor) || typeof descriptor.value !== 'function') return undefined\n\t\t\t\tconst method = descriptor.value as (...args: never[]) => unknown\n\t\t\t\tlet valid = true\n\t\t\t\treturn () => {\n\t\t\t\t\tif (!valid) return undefined\n\t\t\t\t\tvalid = false\n\t\t\t\t\tlet result: unknown\n\t\t\t\t\ttry {\n\t\t\t\t\t\tresult = Reflect.apply(method, clock, [])\n\t\t\t\t\t} catch(error) {\n\t\t\t\t\t\tvalid = true\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\t\t\t\t\tif (isRuntimePromise(result)) {\n\t\t\t\t\t\tignoreRuntimePromiseRejection(result)\n\t\t\t\t\t} else valid = true\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t}\n\t\t\towner = Object.getPrototypeOf(owner) as object | null\n\t\t}\n\t} catch { return undefined }\n\treturn undefined\n}\n\n/**\n * Create a high-resolution clock that wraps an existing clock.\n * Uses Node.js hrtime.bigint() or performance.now() for high-resolution timing.\n *\n * @param options - Clock options\n * @returns High-resolution clock instance\n */\nexport function createHighResClock(options: HighResClockOptions = {}): HighResClock {\n\tif (!options || typeof options !== 'object' || isRuntimeProxy(options)) {\n\t\tthrow new Error('High-resolution clock options must be an object')\n\t}\n\tconst clockDescriptor = Object.getOwnPropertyDescriptor(options, 'clock')\n\tif (clockDescriptor && !('value' in clockDescriptor)) {\n\t\tthrow new Error('High-resolution clock requires clock to be a data property')\n\t}\n\tconst baseClock = clockDescriptor?.value ?? {now: Date.now}\n\tconst providedNow = captureClockMethod(baseClock, 'now')\n\tif (!providedNow) {\n\t\tthrow new Error('High-resolution clock requires a clock with now()')\n\t}\n\tlet lastNow = Number.NEGATIVE_INFINITY\n\tconst now = () => {\n\t\tlet current = Number.NaN\n\t\ttry { current = providedNow() as number } catch { /* use the retained timestamp */ }\n\t\tif (!Number.isFinite(current)) {\n\t\t\tif (!Number.isFinite(lastNow)) lastNow = Date.now()\n\t\t\treturn lastNow\n\t\t}\n\t\treturn lastNow = Math.max(lastNow, current)\n\t}\n\tconst providedNowHr = captureClockMethod(baseClock, 'nowHr')\n\tif (providedNowHr) {\n\t\tlet lastNowHr = 0n\n\t\treturn {\n\t\t\tnow,\n\t\t\tnowHr: () => {\n\t\t\t\tlet current: unknown\n\t\t\t\ttry {\n\t\t\t\t\tcurrent = providedNowHr()\n\t\t\t\t} catch {\n\t\t\t\t\treturn lastNowHr\n\t\t\t\t}\n\t\t\t\tif (typeof current !== 'bigint' || current < 0n) return lastNowHr\n\t\t\t\treturn lastNowHr = current > lastNowHr ? current : lastNowHr\n\t\t\t}\n\t\t}\n\t}\n\n\t// Check for Node.js hrtime.bigint() (Node 10.7+)\n\tif (typeof process !== 'undefined' && typeof process.hrtime?.bigint === 'function') {\n\t\t// Use hrtime.bigint() for high-resolution timing\n\t\tconst origin = process.hrtime.bigint()\n\n\t\treturn {\n\t\t\tnow,\n\t\t\tnowHr: () => process.hrtime.bigint() - origin\n\t\t}\n\t}\n\n\t// Check for performance.now() (browser or Node 16+)\n\tconst perf = typeof performance !== 'undefined' && performance\n\tif (perf && typeof perf.now === 'function') {\n\t\tconst origin = perf.now()\n\t\treturn {\n\t\t\tnow,\n\t\t\tnowHr: () => BigInt(Math.floor((perf.now() - origin) * 1_000_000))\n\t\t}\n\t}\n\n\t// Fallback: use Date.now() with millisecond precision\n\t// This is not ideal but provides compatibility\n\tconst origin = Date.now()\n\treturn {\n\t\tnow,\n\t\tnowHr: () => BigInt(Math.floor((Date.now() - origin) * 1_000_000))\n\t}\n}\n\n/**\n * Convert bigint nanoseconds to milliseconds\n *\n * @param ns - Nanoseconds as bigint\n * @returns Milliseconds as number\n */\nexport function nsToMs(ns: bigint): number {\n\n\treturn Number(ns) / 1_000_000\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isRuntimeProxy } from './chunk-RL2752FW.js';
|
|
2
|
+
|
|
3
|
+
// src/performance/utils/preset-options.ts
|
|
4
|
+
function snapshotPerformancePresetOptions(value, allowedFields, label) {
|
|
5
|
+
try {
|
|
6
|
+
if (!value || typeof value !== "object" || isRuntimeProxy(value) || Array.isArray(value)) throw new TypeError();
|
|
7
|
+
const prototype = Object.getPrototypeOf(value);
|
|
8
|
+
if (prototype !== Object.prototype && prototype !== null) throw new TypeError();
|
|
9
|
+
if (Object.getOwnPropertySymbols(value).length > 0) throw new TypeError();
|
|
10
|
+
const snapshot = /* @__PURE__ */ Object.create(null);
|
|
11
|
+
let inspected = 0;
|
|
12
|
+
for (const key in value) {
|
|
13
|
+
if (inspected >= allowedFields.size) throw new TypeError();
|
|
14
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
15
|
+
if (key.length > 64 || !descriptor?.enumerable || !("value" in descriptor) || !allowedFields.has(key)) {
|
|
16
|
+
throw new TypeError();
|
|
17
|
+
}
|
|
18
|
+
inspected += 1;
|
|
19
|
+
snapshot[key] = descriptor.value;
|
|
20
|
+
}
|
|
21
|
+
return Object.freeze(snapshot);
|
|
22
|
+
} catch {
|
|
23
|
+
throw new TypeError(`${label} must be a closed plain data object`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { snapshotPerformancePresetOptions };
|
|
28
|
+
//# sourceMappingURL=chunk-W72QW2AD.js.map
|
|
29
|
+
//# sourceMappingURL=chunk-W72QW2AD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/performance/utils/preset-options.ts"],"names":[],"mappings":";;;AAGO,SAAS,gCAAA,CACf,KAAA,EACA,aAAA,EACA,KAAA,EACoC;AACpC,EAAA,IAAI;AACH,IAAA,IAAI,CAAC,KAAA,IAAS,OAAO,KAAA,KAAU,YAAY,cAAA,CAAe,KAAK,CAAA,IAAK,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG,MAAM,IAAI,SAAA,EAAU;AAC9G,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,cAAA,CAAe,KAAK,CAAA;AAC7C,IAAA,IAAI,cAAc,MAAA,CAAO,SAAA,IAAa,cAAc,IAAA,EAAM,MAAM,IAAI,SAAA,EAAU;AAC9E,IAAA,IAAI,MAAA,CAAO,sBAAsB,KAAK,CAAA,CAAE,SAAS,CAAA,EAAG,MAAM,IAAI,SAAA,EAAU;AACxE,IAAA,MAAM,QAAA,mBAAoC,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA;AAC5D,IAAA,IAAI,SAAA,GAAY,CAAA;AAChB,IAAA,KAAA,MAAW,OAAO,KAAA,EAAO;AACxB,MAAA,IAAI,SAAA,IAAa,aAAA,CAAc,IAAA,EAAM,MAAM,IAAI,SAAA,EAAU;AACzD,MAAA,MAAM,UAAA,GAAa,MAAA,CAAO,wBAAA,CAAyB,KAAA,EAAO,GAAG,CAAA;AAC7D,MAAA,IAAI,GAAA,CAAI,MAAA,GAAS,EAAA,IAAM,CAAC,UAAA,EAAY,UAAA,IAAc,EAAE,OAAA,IAAW,UAAA,CAAA,IAAe,CAAC,aAAA,CAAc,GAAA,CAAI,GAAG,CAAA,EAAG;AACtG,QAAA,MAAM,IAAI,SAAA,EAAU;AAAA,MACrB;AACA,MAAA,SAAA,IAAa,CAAA;AACb,MAAA,QAAA,CAAS,GAAG,IAAI,UAAA,CAAW,KAAA;AAAA,IAC5B;AACA,IAAA,OAAO,MAAA,CAAO,OAAO,QAAQ,CAAA;AAAA,EAC9B,CAAA,CAAA,MAAQ;AACP,IAAA,MAAM,IAAI,SAAA,CAAU,CAAA,EAAG,KAAK,CAAA,mCAAA,CAAqC,CAAA;AAAA,EAClE;AACD","file":"chunk-W72QW2AD.js","sourcesContent":["import {isRuntimeProxy} from './safe-object'\n\n/** Snapshots a preset's shallow dependency options without invoking accessors. */\nexport function snapshotPerformancePresetOptions(\n\tvalue: unknown,\n\tallowedFields: ReadonlySet<string>,\n\tlabel: string\n): Readonly<Record<string, unknown>> {\n\ttry {\n\t\tif (!value || typeof value !== 'object' || isRuntimeProxy(value) || Array.isArray(value)) throw new TypeError()\n\t\tconst prototype = Object.getPrototypeOf(value)\n\t\tif (prototype !== Object.prototype && prototype !== null) throw new TypeError()\n\t\tif (Object.getOwnPropertySymbols(value).length > 0) throw new TypeError()\n\t\tconst snapshot: Record<string, unknown> = Object.create(null) as Record<string, unknown>\n\t\tlet inspected = 0\n\t\tfor (const key in value) {\n\t\t\tif (inspected >= allowedFields.size) throw new TypeError()\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key)\n\t\t\tif (key.length > 64 || !descriptor?.enumerable || !('value' in descriptor) || !allowedFields.has(key)) {\n\t\t\t\tthrow new TypeError()\n\t\t\t}\n\t\t\tinspected += 1\n\t\t\tsnapshot[key] = descriptor.value\n\t\t}\n\t\treturn Object.freeze(snapshot)\n\t} catch {\n\t\tthrow new TypeError(`${label} must be a closed plain data object`)\n\t}\n}\n"]}
|