@oxog/utils 1.0.1 → 1.1.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/CHANGELOG.md +34 -0
- package/README.md +56 -43
- package/dist/chunk-25WW2FCA.js +34 -0
- package/dist/chunk-25WW2FCA.js.map +1 -0
- package/dist/chunk-DEVWOLUI.cjs +112 -0
- package/dist/chunk-DEVWOLUI.cjs.map +1 -0
- package/dist/chunk-IUDFQZIP.js +99 -0
- package/dist/chunk-IUDFQZIP.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-Q7SFCCGT.cjs +11 -0
- package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
- package/dist/chunk-SWG777R6.cjs +40 -0
- package/dist/chunk-SWG777R6.cjs.map +1 -0
- package/dist/index.cjs +210 -240
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -11
- package/dist/index.d.ts +32 -11
- package/dist/index.js +156 -221
- package/dist/index.js.map +1 -1
- package/dist/plugins/async.cjs +90 -107
- package/dist/plugins/async.cjs.map +1 -1
- package/dist/plugins/async.d.cts +19 -6
- package/dist/plugins/async.d.ts +19 -6
- package/dist/plugins/async.js +89 -106
- package/dist/plugins/async.js.map +1 -1
- package/dist/plugins/deep.cjs +183 -59
- package/dist/plugins/deep.cjs.map +1 -1
- package/dist/plugins/deep.d.cts +25 -7
- package/dist/plugins/deep.d.ts +25 -7
- package/dist/plugins/deep.js +183 -59
- package/dist/plugins/deep.js.map +1 -1
- package/dist/plugins/guard.cjs +2 -0
- package/dist/plugins/guard.cjs.map +1 -1
- package/dist/plugins/guard.js +2 -0
- package/dist/plugins/guard.js.map +1 -1
- package/dist/plugins/transform.cjs +6 -3
- package/dist/plugins/transform.cjs.map +1 -1
- package/dist/plugins/transform.js +6 -3
- package/dist/plugins/transform.js.map +1 -1
- package/dist/{types-XmRC5wYO.d.cts → types-B-i5UbJo.d.cts} +24 -7
- package/dist/{types-XmRC5wYO.d.ts → types-B-i5UbJo.d.ts} +24 -7
- package/package.json +15 -10
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to @oxog/utils will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.1.0] - 2026-11-30
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- **Security:** `setMut()` no longer pollutes `Object.prototype` (`setMut({}, '__proto__.x', 1)` added `x` to every object). `set()` and `setMut()` now throw `InvalidPathError` for paths containing `__proto__`, `constructor` or `prototype`.
|
|
9
|
+
- **Security:** `cloneDeep()` no longer turns an own `"__proto__"` key (e.g. from `JSON.parse`) into the clone's prototype; `groupBy`, `keyBy`, `mapKeys`, `mapValues`, `invert`, `pick` and `diff` store such keys as data. `mergeDeep()` skips `__proto__`/`constructor`/`prototype` at every nesting level.
|
|
10
|
+
- `chunk(arr, 0)` (or a negative/`NaN` size) looped forever and exhausted memory; it now returns `[]`. Fractional sizes are truncated.
|
|
11
|
+
- `groupBy()` threw `TypeError` for group names such as `"constructor"`, `"toString"` or `"__proto__"`.
|
|
12
|
+
- `has()` returned `true` for any path after an array index (`has(o, 'items[0].missing')`) and for out-of-range indexes; it now checks every segment and only own properties (`has({}, 'toString')` is `false`).
|
|
13
|
+
- `set()` converted arrays on the path into plain objects and did not support bracket indexes in the middle of a path (`set(o, 'items[0].id', 2)` created an `"items[0]"` key). `setMut()` gained bracket support too; missing containers are created as arrays for numeric bracket segments.
|
|
14
|
+
- `get()`/`template()` no longer expose prototypes (`get(o, '__proto__')`, `template('{{constructor}}', {})` printed `function Object() ...`).
|
|
15
|
+
- `cloneDeep()` crashed when used as an `Array#map` callback, turned typed arrays/`Buffer`s into plain objects, dropped class prototypes, symbol keys and `Error` messages. It now also clones `ArrayBuffer` and `DataView`, and returns `WeakMap`/`WeakSet`/`Promise` by reference.
|
|
16
|
+
- `mergeDeep()` did not replace `Date`/`Map`/`Set` values (the target value was kept) and overflowed the stack on circular sources.
|
|
17
|
+
- `isEqual()` reported `[]` equal to `{}`, a `Date`/`Map` equal to `{}`, `Map` equal to `Set`, ignored prototypes, symbol keys and `Error` messages, compared Set members by reference only, treated two invalid Dates as different and overflowed the stack on circular structures.
|
|
18
|
+
- `diff()` reported nothing when a nested object gained or lost keys or an array changed length; those changes are now reported as `{ from, to }`.
|
|
19
|
+
- `slugify()` dropped upper-case Cyrillic and Greek letters (`slugify('Привет мир')` returned `rivet-mir`, the documented result is `privet-mir`) and accented Greek letters.
|
|
20
|
+
- `truncate()` could cut an emoji in half, leaving a lone surrogate.
|
|
21
|
+
- `first(arr, n)` returned a single element instead of an array when only one element was available (`first([1], 5)` is now `[1]`, as documented); `last(arr, 0)` returned the whole array; negative counts are treated as 0 in `first`, `last` and `sample`.
|
|
22
|
+
- `debounce()`: `flush()` left `pending()` stuck at `true` and suppressed later leading calls; the wrapper returned `undefined` instead of the last result; the `maxWait` option was accepted but ignored; `trailing: false` was not honoured by `flush()`.
|
|
23
|
+
- `throttle()`: returned `undefined` instead of the last result, ignored `leading: false` after the first window, and `cancel()` did not reset the window.
|
|
24
|
+
- `retry()` discarded the last error; `MaxRetriesExceededError` now carries it as `cause` and exposes `attempts`.
|
|
25
|
+
- Error classes are no longer duplicated per entry point: a `TimeoutError` thrown by `@oxog/utils/async` is now `instanceof` the `TimeoutError` exported by `@oxog/utils` (ESM and CommonJS).
|
|
26
|
+
- `Kernel`: the `kernel:destroyed` event was emitted after all listeners had been removed; a failed `init()` left rolled-back plugins inactive on the next `init()`, and a circular-dependency failure left the kernel stuck in `initializing` so the next `init()` resolved without initializing anything.
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
- `debounce(fn, wait, { maxWait })` is implemented; `throttle()` returns a function with `flush()`.
|
|
30
|
+
- `DebouncedFunction` and `ThrottledFunction` types are exported from `@oxog/utils/async`.
|
|
31
|
+
- `"./package.json"` is exported.
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
- Types: `mergeDeep()` accepts sources that are not `Partial<target>` and returns the intersection of target and sources (the README "Safe Deep Merging" example did not compile); `diff()` accepts a second object with extra keys (its own JSDoc example did not compile); `groupBy`/`keyBy` key functions may return numbers and `uniqBy` key functions any value; plugin hooks are declared as methods and `onInit`/`onDestroy` may return any value or promise (e.g. `onInit: (ctx) => ctx.db.connect()`). `cloneDeep()` no longer declares its internal second parameter.
|
|
35
|
+
- Behaviour you may notice: `set`/`setMut` throw for `__proto__`/`constructor`/`prototype` path segments; `has()` is own-property based; `isEqual()` returns `false` for values with different prototypes (a class instance vs. an equal-looking plain object); `first(arr, n)` returns an array whenever `n !== 1`; debounce/throttle never run a leading call in the same `wait` window as a trailing call.
|
|
36
|
+
- Build: tsup code splitting is enabled; `dist/` now contains shared `chunk-*` files.
|
|
37
|
+
- Tooling: ESLint 9 flat config (the old `.eslintrc.js` was ignored and `npm run lint` failed), lint covers tests, tests are type-checked, Jest coverage thresholds are enforced (c8 removed), `npm run test:package` verifies the packed archive, CI runs on Node 18-24, and a manual `publish.yml` publishes with npm trusted publishing.
|
|
38
|
+
|
|
5
39
|
## [1.0.1] - 2026-01-25
|
|
6
40
|
|
|
7
41
|
### Added
|
package/README.md
CHANGED
|
@@ -6,18 +6,18 @@
|
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
8
|
[](https://nodejs.org/)
|
|
9
|
-
[](https://github.com/ersinkoc/Utils/actions/workflows/ci.yml)
|
|
10
10
|
|
|
11
|
-
Modern, tree-shakeable utility library for Node.js backend development with zero dependencies.
|
|
11
|
+
Modern, tree-shakeable utility library for Node.js backend development with zero dependencies. Written in TypeScript, shipped as ESM and CommonJS with type definitions for both.
|
|
12
12
|
|
|
13
13
|
## ✨ Features
|
|
14
14
|
|
|
15
15
|
- 📦 **Zero dependencies** - No runtime dependencies
|
|
16
|
-
- 🔒 **
|
|
16
|
+
- 🔒 **Typed** - Written in TypeScript; ESM + CommonJS builds with matching `.d.ts` / `.d.cts`
|
|
17
17
|
- 🌳 **Tree-shakeable** - Import only what you need
|
|
18
18
|
- 🛡️ **Secure** - Prototype pollution protection built-in
|
|
19
19
|
- ⚡ **Performant** - Immutable by default, optimized for Node.js backends
|
|
20
|
-
- 🧪 **Well-tested** -
|
|
20
|
+
- 🧪 **Well-tested** - coverage thresholds enforced in CI, packed archive verified for ESM, CJS and TypeScript
|
|
21
21
|
- 📝 **LLM-native** - Designed for AI/LLM code generation
|
|
22
22
|
|
|
23
23
|
## 📦 Installation
|
|
@@ -83,10 +83,10 @@ import { compose, pipe, flip } from '@oxog/utils/transform';
|
|
|
83
83
|
|
|
84
84
|
| Function | Description |
|
|
85
85
|
|----------|-------------|
|
|
86
|
-
| `get(obj, path, defaultValue?)` | Safe nested property access
|
|
87
|
-
| `set(obj, path, value)` | Immutable property setter |
|
|
88
|
-
| `setMut(obj, path, value)` | Mutable property setter |
|
|
89
|
-
| `has(obj, path)` | Check if path exists
|
|
86
|
+
| `get(obj, path, defaultValue?)` | Safe nested property access (dot and `[0]` paths; returns `any`) |
|
|
87
|
+
| `set(obj, path, value)` | Immutable property setter (arrays stay arrays; throws `InvalidPathError` for `__proto__`/`constructor`/`prototype` segments) |
|
|
88
|
+
| `setMut(obj, path, value)` | Mutable property setter (same path rules as `set`) |
|
|
89
|
+
| `has(obj, path)` | Check if an own-property path exists (inherited keys and out-of-range indexes are `false`) |
|
|
90
90
|
| `pick(obj, keys)` | Create object with specified keys |
|
|
91
91
|
| `omit(obj, keys)` | Create object excluding specified keys |
|
|
92
92
|
| `merge(target, ...sources)` | Safe shallow merge with prototype pollution protection |
|
|
@@ -101,14 +101,14 @@ import { compose, pipe, flip } from '@oxog/utils/transform';
|
|
|
101
101
|
|----------|-------------|
|
|
102
102
|
| `groupBy(arr, key)` | Group array items by property or function |
|
|
103
103
|
| `keyBy(arr, key)` | Index array by property value |
|
|
104
|
-
| `chunk(arr, size)` | Split array into chunks |
|
|
104
|
+
| `chunk(arr, size)` | Split array into chunks (`size < 1` returns `[]`) |
|
|
105
105
|
| `uniq(arr)` | Remove duplicate values |
|
|
106
106
|
| `uniqBy(arr, key)` | Remove duplicates by key |
|
|
107
107
|
| `flatten(arr, depth?)` | Flatten nested arrays |
|
|
108
108
|
| `compact(arr)` | Remove falsy values |
|
|
109
|
-
| `first(arr, n?)` |
|
|
110
|
-
| `last(arr, n?)` |
|
|
111
|
-
| `sample(arr, n?)` |
|
|
109
|
+
| `first(arr, n?)` | First element, or an array of the first `n` elements when `n !== 1` |
|
|
110
|
+
| `last(arr, n?)` | Last element, or an array of the last `n` elements when `n !== 1` |
|
|
111
|
+
| `sample(arr, n?)` | Array of `n` random elements (default 1) |
|
|
112
112
|
|
|
113
113
|
### String Utilities
|
|
114
114
|
|
|
@@ -119,28 +119,28 @@ import { compose, pipe, flip } from '@oxog/utils/transform';
|
|
|
119
119
|
| `snakeCase(str)` | Convert to snake_case |
|
|
120
120
|
| `pascalCase(str)` | Convert to PascalCase |
|
|
121
121
|
| `capitalize(str)` | Capitalize first letter |
|
|
122
|
-
| `truncate(str, length, suffix?)` |
|
|
123
|
-
| `slugify(str)` | URL-safe slug with Turkish
|
|
124
|
-
| `template(str, data)` | String interpolation with `{{variable}}` |
|
|
122
|
+
| `truncate(str, length, suffix?)` | Keep `length` characters, then append `suffix` (never splits an emoji) |
|
|
123
|
+
| `slugify(str)` | URL-safe slug with Turkish, Cyrillic, Greek and accented-Latin transliteration |
|
|
124
|
+
| `template(str, data)` | String interpolation with `{{variable}}` / `{{a.b}}` (own properties only) |
|
|
125
125
|
|
|
126
126
|
### Deep Utilities (`@oxog/utils/deep`)
|
|
127
127
|
|
|
128
128
|
| Function | Description |
|
|
129
129
|
|----------|-------------|
|
|
130
|
-
| `cloneDeep(obj)` | Deep clone
|
|
131
|
-
| `mergeDeep(target, ...sources)` | Deep merge with prototype pollution protection |
|
|
132
|
-
| `isEqual(a, b)` | Deep equality
|
|
133
|
-
| `diff(a, b)` |
|
|
130
|
+
| `cloneDeep(obj)` | Deep clone: circular refs, Date, RegExp, Map, Set, typed arrays/Buffer, ArrayBuffer, DataView, Error; keeps prototypes |
|
|
131
|
+
| `mergeDeep(target, ...sources)` | Deep merge of plain objects (arrays, Dates, Maps... are replaced) with prototype pollution protection |
|
|
132
|
+
| `isEqual(a, b)` | Deep equality (type- and prototype-aware, deep Set/Map, circular refs, `NaN === NaN`) |
|
|
133
|
+
| `diff(a, b)` | `{ changed, added, removed }` between two objects |
|
|
134
134
|
|
|
135
135
|
### Async Utilities (`@oxog/utils/async`)
|
|
136
136
|
|
|
137
137
|
| Function | Description |
|
|
138
138
|
|----------|-------------|
|
|
139
|
-
| `debounce(fn, wait, options?)` | Debounce
|
|
140
|
-
| `throttle(fn, wait, options?)` | Throttle
|
|
139
|
+
| `debounce(fn, wait, options?)` | Debounce (`leading`, `trailing`, `maxWait`; `cancel`/`flush`/`pending`) |
|
|
140
|
+
| `throttle(fn, wait, options?)` | Throttle (`leading`, `trailing`; `cancel`/`flush`/`pending`) |
|
|
141
141
|
| `sleep(ms)` | Sleep for specified milliseconds |
|
|
142
|
-
| `retry(options)` | Retry
|
|
143
|
-
| `timeout(promise, ms)` |
|
|
142
|
+
| `retry(options)` | Retry with backoff; throws `MaxRetriesExceededError` with the last error as `cause` |
|
|
143
|
+
| `timeout(promise, ms)` | Reject with `TimeoutError` if `promise` does not settle in `ms` |
|
|
144
144
|
|
|
145
145
|
### Type Guards (`@oxog/utils/guard`)
|
|
146
146
|
|
|
@@ -229,7 +229,7 @@ interface User {
|
|
|
229
229
|
|
|
230
230
|
const user: User = { profile: { name: 'Ersin' } };
|
|
231
231
|
|
|
232
|
-
//
|
|
232
|
+
// get() returns `any`: annotate the result you expect
|
|
233
233
|
const theme: 'light' | 'dark' | undefined = get(user, 'profile.settings.theme');
|
|
234
234
|
const updated = set(user, 'profile.settings.theme', 'dark' as const);
|
|
235
235
|
```
|
|
@@ -283,21 +283,20 @@ npm run test:watch
|
|
|
283
283
|
npm run test:coverage
|
|
284
284
|
```
|
|
285
285
|
|
|
286
|
-
|
|
287
|
-
- **98.36% statement coverage**
|
|
288
|
-
- **100% function coverage**
|
|
289
|
-
- **94.74% branch coverage**
|
|
286
|
+
Coverage thresholds (statements/lines 99.5%, branches 97%, functions 100%) are enforced by `npm run test:coverage`.
|
|
290
287
|
|
|
291
288
|
## 🔧 Scripts
|
|
292
289
|
|
|
293
290
|
```bash
|
|
294
|
-
npm run build
|
|
295
|
-
npm test
|
|
296
|
-
npm run test:watch
|
|
297
|
-
npm run test:coverage
|
|
298
|
-
npm run
|
|
299
|
-
npm run
|
|
300
|
-
npm run
|
|
291
|
+
npm run build # Build the project
|
|
292
|
+
npm test # Run tests once
|
|
293
|
+
npm run test:watch # Watch mode
|
|
294
|
+
npm run test:coverage # Tests with enforced coverage thresholds
|
|
295
|
+
npm run test:package # Pack, install and import the archive (ESM, CJS, TypeScript)
|
|
296
|
+
npm run lint # Lint src, tests and scripts
|
|
297
|
+
npm run format # Format code with Prettier
|
|
298
|
+
npm run typecheck # Type-check source and tests
|
|
299
|
+
npm run check # lint + typecheck + test:coverage
|
|
301
300
|
```
|
|
302
301
|
|
|
303
302
|
## 🏗️ Build Output
|
|
@@ -308,34 +307,48 @@ dist/
|
|
|
308
307
|
├── index.cjs # CommonJS entry
|
|
309
308
|
├── index.d.ts # TypeScript definitions
|
|
310
309
|
├── index.d.cts # CommonJS definitions
|
|
310
|
+
├── chunk-*.js / *.cjs # Shared code (one copy of errors/helpers for every entry)
|
|
311
311
|
├── plugins/
|
|
312
|
-
│ ├── deep.js # Deep operations
|
|
312
|
+
│ ├── deep.js # Deep operations (+ .cjs, .d.ts, .d.cts)
|
|
313
313
|
│ ├── async.js # Async utilities
|
|
314
314
|
│ ├── guard.js # Type guards
|
|
315
315
|
│ └── transform.js # Transform utilities
|
|
316
316
|
```
|
|
317
317
|
|
|
318
|
+
Entry points share code chunks, so `error instanceof TimeoutError` works no matter
|
|
319
|
+
whether the error came from `@oxog/utils/async` and the class from `@oxog/utils`.
|
|
320
|
+
|
|
318
321
|
## 🛡️ Security
|
|
319
322
|
|
|
320
323
|
This library includes built-in protection against prototype pollution attacks:
|
|
321
324
|
|
|
322
325
|
```typescript
|
|
323
|
-
import { merge } from '@oxog/utils';
|
|
326
|
+
import { merge, setMut } from '@oxog/utils';
|
|
327
|
+
import { mergeDeep } from '@oxog/utils/deep';
|
|
328
|
+
|
|
329
|
+
const payload = JSON.parse('{"__proto__": {"isAdmin": true}}');
|
|
324
330
|
|
|
325
|
-
// Dangerous keys are
|
|
326
|
-
|
|
327
|
-
|
|
331
|
+
// Dangerous keys (__proto__, constructor, prototype) are skipped by merge/mergeDeep
|
|
332
|
+
merge({}, payload);
|
|
333
|
+
mergeDeep({}, payload);
|
|
334
|
+
console.log(({} as any).isAdmin); // undefined
|
|
335
|
+
|
|
336
|
+
// Paths through them are rejected by set/setMut
|
|
337
|
+
setMut({}, '__proto__.isAdmin', true); // throws InvalidPathError
|
|
328
338
|
```
|
|
329
339
|
|
|
340
|
+
`groupBy`, `keyBy`, `mapKeys`, `invert`, `cloneDeep` and `diff` store a `"__proto__"`
|
|
341
|
+
key as ordinary data instead of replacing the result's prototype.
|
|
342
|
+
|
|
330
343
|
## 📄 License
|
|
331
344
|
|
|
332
|
-
MIT © [Ersin Koç](https://github.com/ersinkoc/
|
|
345
|
+
MIT © [Ersin Koç](https://github.com/ersinkoc/Utils)
|
|
333
346
|
|
|
334
347
|
## 🔗 Links
|
|
335
348
|
|
|
336
349
|
- **Documentation**: [https://utils.oxog.dev](https://utils.oxog.dev)
|
|
337
|
-
- **GitHub**: [https://github.com/ersinkoc/
|
|
338
|
-
- **Issues**: [https://github.com/ersinkoc/
|
|
350
|
+
- **GitHub**: [https://github.com/ersinkoc/Utils](https://github.com/ersinkoc/Utils)
|
|
351
|
+
- **Issues**: [https://github.com/ersinkoc/Utils/issues](https://github.com/ersinkoc/Utils/issues)
|
|
339
352
|
|
|
340
353
|
---
|
|
341
354
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/internal.ts
|
|
2
|
+
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
3
|
+
var hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
4
|
+
function assignOwn(obj, key, value) {
|
|
5
|
+
if (key === "__proto__") {
|
|
6
|
+
Object.defineProperty(obj, key, { value, writable: true, enumerable: true, configurable: true });
|
|
7
|
+
} else {
|
|
8
|
+
obj[key] = value;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function parsePath(path) {
|
|
12
|
+
const segments = [];
|
|
13
|
+
const source = String(path);
|
|
14
|
+
const pattern = /\[\s*(?:'([^']*)'|"([^"]*)"|([^\]]*?))\s*\]|([^.[\]]+)/g;
|
|
15
|
+
let match;
|
|
16
|
+
while ((match = pattern.exec(source)) !== null) {
|
|
17
|
+
const [, single, double, bare, dotted] = match;
|
|
18
|
+
if (dotted !== void 0) {
|
|
19
|
+
segments.push({ key: dotted, index: false });
|
|
20
|
+
} else {
|
|
21
|
+
const key = single ?? double ?? bare ?? "";
|
|
22
|
+
if (key === "") continue;
|
|
23
|
+
segments.push({ key, index: single === void 0 && double === void 0 && /^\d+$/.test(key) });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return segments;
|
|
27
|
+
}
|
|
28
|
+
function hasUnsafeSegment(segments) {
|
|
29
|
+
return segments.some((segment) => UNSAFE_KEYS.has(segment.key));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { UNSAFE_KEYS, assignOwn, hasOwn, hasUnsafeSegment, parsePath };
|
|
33
|
+
//# sourceMappingURL=chunk-25WW2FCA.js.map
|
|
34
|
+
//# sourceMappingURL=chunk-25WW2FCA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal.ts"],"names":[],"mappings":";AAMO,IAAM,8B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AW,MAAA,IAAa,OAAA,CAAQ,IAAA,CAAK,GAAG,CAAA,EAAG,CAAA;AAAA,IACjG;AAAA,EACF;AACA,EAAA,OAAO,QAAA;AACT;AAGO,SAAS,iBAAiB,QAAA,EAA2C;AAC1E,EAAA,OAAO,QAAA,CAAS,KAAK,CAAC,OAAA,KAAY,YAAY,GAAA,CAAI,OAAA,CAAQ,GAAG,CAAC,CAAA;AAChE","file":"chunk-25WW2FCA.js","sourcesContent":["/**\n * Internal helpers shared by the public modules. Not part of the public API.\n * @internal\n */\n\n/** Keys that can reach or replace an object's prototype. */\nexport const UNSAFE_KEYS: ReadonlySet<string> = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport const hasOwn = (obj: object, key: PropertyKey): boolean =>\n Object.prototype.hasOwnProperty.call(obj, key);\n\n/**\n * Assign `obj[key] = value` as an own data property.\n *\n * Plain assignment of `\"__proto__\"` would replace the prototype of `obj`\n * instead of storing a value; this helper always stores data.\n */\nexport function assignOwn(obj: any, key: PropertyKey, value: unknown): void {\n if (key === '__proto__') {\n Object.defineProperty(obj, key, { value, writable: true, enumerable: true, configurable: true });\n } else {\n obj[key] = value;\n }\n}\n\n/** One segment of a parsed property path. */\nexport interface PathSegment {\n key: string;\n /** True when the segment was written as a numeric bracket index (`[0]`). */\n index: boolean;\n}\n\n/**\n * Parse a property path such as `a.b[0].c` or `a['b'].c`.\n *\n * Empty segments are ignored, so `a..b` is the same as `a.b`.\n */\nexport function parsePath(path: string | number): PathSegment[] {\n const segments: PathSegment[] = [];\n const source = String(path);\n const pattern = /\\[\\s*(?:'([^']*)'|\"([^\"]*)\"|([^\\]]*?))\\s*\\]|([^.[\\]]+)/g;\n let match: RegExpExecArray | null;\n while ((match = pattern.exec(source)) !== null) {\n const [, single, double, bare, dotted] = match;\n if (dotted !== undefined) {\n segments.push({ key: dotted, index: false });\n } else {\n const key = single ?? double ?? bare ?? '';\n if (key === '') continue;\n segments.push({ key, index: single === undefined && double === undefined && /^\\d+$/.test(key) });\n }\n }\n return segments;\n}\n\n/** True when any segment of the path is `__proto__`, `constructor` or `prototype`. */\nexport function hasUnsafeSegment(segments: readonly PathSegment[]): boolean {\n return segments.some((segment) => UNSAFE_KEYS.has(segment.key));\n}\n"]}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/errors.ts
|
|
4
|
+
var UtilsError = class extends Error {
|
|
5
|
+
code;
|
|
6
|
+
constructor(message, code) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "UtilsError";
|
|
9
|
+
this.code = code;
|
|
10
|
+
Error.captureStackTrace(this, this.constructor);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var InvalidPathError = class extends UtilsError {
|
|
14
|
+
constructor(path) {
|
|
15
|
+
super(`Invalid path: ${path}`, "INVALID_PATH");
|
|
16
|
+
this.name = "InvalidPathError";
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var CircularReferenceError = class extends UtilsError {
|
|
20
|
+
constructor() {
|
|
21
|
+
super("Circular reference detected", "CIRCULAR_REF");
|
|
22
|
+
this.name = "CircularReferenceError";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var TimeoutError = class extends UtilsError {
|
|
26
|
+
constructor(ms) {
|
|
27
|
+
super(`Operation timed out after ${ms}ms`, "TIMEOUT");
|
|
28
|
+
this.name = "TimeoutError";
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var PluginAlreadyRegisteredError = class extends UtilsError {
|
|
32
|
+
constructor(name) {
|
|
33
|
+
super(`Plugin "${name}" already registered`, "PLUGIN_ALREADY_REGISTERED");
|
|
34
|
+
this.name = "PluginAlreadyRegisteredError";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var PluginNotFoundError = class extends UtilsError {
|
|
38
|
+
constructor(name) {
|
|
39
|
+
super(`Plugin "${name}" not found`, "PLUGIN_NOT_FOUND");
|
|
40
|
+
this.name = "PluginNotFoundError";
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var PluginDependencyMissingError = class extends UtilsError {
|
|
44
|
+
constructor(plugin, dependency) {
|
|
45
|
+
super(`Plugin "${plugin}" requires "${dependency}" to be registered first`, "PLUGIN_DEPENDENCY_MISSING");
|
|
46
|
+
this.name = "PluginDependencyMissingError";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var MaxRetriesExceededError = class extends UtilsError {
|
|
50
|
+
/** Number of attempts that were made. */
|
|
51
|
+
attempts;
|
|
52
|
+
/**
|
|
53
|
+
* @param attempts - Number of attempts that were made
|
|
54
|
+
* @param cause - The error thrown by the last attempt (available as `error.cause`)
|
|
55
|
+
*/
|
|
56
|
+
constructor(attempts, cause) {
|
|
57
|
+
super(`Maximum retry attempts (${attempts}) exceeded`, "MAX_RETRIES_EXCEEDED");
|
|
58
|
+
this.name = "MaxRetriesExceededError";
|
|
59
|
+
this.attempts = attempts;
|
|
60
|
+
if (cause !== void 0) {
|
|
61
|
+
Object.defineProperty(this, "cause", {
|
|
62
|
+
value: cause,
|
|
63
|
+
writable: true,
|
|
64
|
+
enumerable: false,
|
|
65
|
+
configurable: true
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var CircularDependencyError = class extends UtilsError {
|
|
71
|
+
constructor(cycle) {
|
|
72
|
+
super(`Circular dependency detected: ${cycle.join(" -> ")}`, "CIRCULAR_DEPENDENCY");
|
|
73
|
+
this.name = "CircularDependencyError";
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var PluginInitializationError = class extends UtilsError {
|
|
77
|
+
pluginName;
|
|
78
|
+
cause;
|
|
79
|
+
constructor(pluginName, cause) {
|
|
80
|
+
super(`Plugin "${pluginName}" failed to initialize: ${cause.message}`, "PLUGIN_INIT_FAILED");
|
|
81
|
+
this.name = "PluginInitializationError";
|
|
82
|
+
this.pluginName = pluginName;
|
|
83
|
+
this.cause = cause;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var KernelAlreadyInitializedError = class extends UtilsError {
|
|
87
|
+
constructor() {
|
|
88
|
+
super("Kernel is already initialized", "KERNEL_ALREADY_INITIALIZED");
|
|
89
|
+
this.name = "KernelAlreadyInitializedError";
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var KernelInitializingError = class extends UtilsError {
|
|
93
|
+
constructor() {
|
|
94
|
+
super("Kernel is currently initializing", "KERNEL_INITIALIZING");
|
|
95
|
+
this.name = "KernelInitializingError";
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
exports.CircularDependencyError = CircularDependencyError;
|
|
100
|
+
exports.CircularReferenceError = CircularReferenceError;
|
|
101
|
+
exports.InvalidPathError = InvalidPathError;
|
|
102
|
+
exports.KernelAlreadyInitializedError = KernelAlreadyInitializedError;
|
|
103
|
+
exports.KernelInitializingError = KernelInitializingError;
|
|
104
|
+
exports.MaxRetriesExceededError = MaxRetriesExceededError;
|
|
105
|
+
exports.PluginAlreadyRegisteredError = PluginAlreadyRegisteredError;
|
|
106
|
+
exports.PluginDependencyMissingError = PluginDependencyMissingError;
|
|
107
|
+
exports.PluginInitializationError = PluginInitializationError;
|
|
108
|
+
exports.PluginNotFoundError = PluginNotFoundError;
|
|
109
|
+
exports.TimeoutError = TimeoutError;
|
|
110
|
+
exports.UtilsError = UtilsError;
|
|
111
|
+
//# sourceMappingURL=chunk-DEVWOLUI.cjs.map
|
|
112
|
+
//# sourceMappingURL=chunk-DEVWOLUI.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";;;AAGO,IAAM,UAAA,GAAN,cAAyB,KAAA,CAAM;AAAA,EACpC,IAAA;AAAA,EAEA,WAAA,CAAY,SAAiB,IAAA,EAAc;AACzC,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AACZ,IAAA,IA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A;AACZ,IAAA,IAAA,CAAK,UAAA,GAAa,UAAA;AAClB,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AAAA,EACf;AACF;AAKO,IAAM,6BAAA,GAAN,cAA4C,UAAA,CAAW;AAAA,EAC5D,WAAA,GAAc;AACZ,IAAA,KAAA,CAAM,iCAAiC,4BAA4B,CAAA;AACnE,IAAA,IAAA,CAAK,IAAA,GAAO,+BAAA;AAAA,EACd;AACF;AAKO,IAAM,uBAAA,GAAN,cAAsC,UAAA,CAAW;AAAA,EACtD,WAAA,GAAc;AACZ,IAAA,KAAA,CAAM,oCAAoC,qBAAqB,CAAA;AAC/D,IAAA,IAAA,CAAK,IAAA,GAAO,yBAAA;AAAA,EACd;AACF","file":"chunk-DEVWOLUI.cjs","sourcesContent":["/**\n * Base error class for all @oxog/utils errors.\n */\nexport class UtilsError extends Error {\n code: string;\n\n constructor(message: string, code: string) {\n super(message);\n this.name = 'UtilsError';\n this.code = code;\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\n/**\n * Error thrown when an invalid path is provided to get/set/has functions.\n */\nexport class InvalidPathError extends UtilsError {\n constructor(path: string) {\n super(`Invalid path: ${path}`, 'INVALID_PATH');\n this.name = 'InvalidPathError';\n }\n}\n\n/**\n * Error thrown when a circular reference is detected during deep operations.\n */\nexport class CircularReferenceError extends UtilsError {\n constructor() {\n super('Circular reference detected', 'CIRCULAR_REF');\n this.name = 'CircularReferenceError';\n }\n}\n\n/**\n * Error thrown when an operation times out.\n */\nexport class TimeoutError extends UtilsError {\n constructor(ms: number) {\n super(`Operation timed out after ${ms}ms`, 'TIMEOUT');\n this.name = 'TimeoutError';\n }\n}\n\n/**\n * Error thrown when a plugin is already registered.\n */\nexport class PluginAlreadyRegisteredError extends UtilsError {\n constructor(name: string) {\n super(`Plugin \"${name}\" already registered`, 'PLUGIN_ALREADY_REGISTERED');\n this.name = 'PluginAlreadyRegisteredError';\n }\n}\n\n/**\n * Error thrown when a requested plugin is not found.\n */\nexport class PluginNotFoundError extends UtilsError {\n constructor(name: string) {\n super(`Plugin \"${name}\" not found`, 'PLUGIN_NOT_FOUND');\n this.name = 'PluginNotFoundError';\n }\n}\n\n/**\n * Error thrown when a plugin dependency is missing.\n */\nexport class PluginDependencyMissingError extends UtilsError {\n constructor(plugin: string, dependency: string) {\n super(`Plugin \"${plugin}\" requires \"${dependency}\" to be registered first`, 'PLUGIN_DEPENDENCY_MISSING');\n this.name = 'PluginDependencyMissingError';\n }\n}\n\n/**\n * Error thrown when retry attempts are exhausted.\n */\nexport class MaxRetriesExceededError extends UtilsError {\n /** Number of attempts that were made. */\n readonly attempts: number;\n\n /**\n * @param attempts - Number of attempts that were made\n * @param cause - The error thrown by the last attempt (available as `error.cause`)\n */\n constructor(attempts: number, cause?: unknown) {\n super(`Maximum retry attempts (${attempts}) exceeded`, 'MAX_RETRIES_EXCEEDED');\n this.name = 'MaxRetriesExceededError';\n this.attempts = attempts;\n if (cause !== undefined) {\n Object.defineProperty(this, 'cause', {\n value: cause,\n writable: true,\n enumerable: false,\n configurable: true,\n });\n }\n }\n}\n\n/**\n * Error thrown when circular dependency is detected between plugins.\n */\nexport class CircularDependencyError extends UtilsError {\n constructor(cycle: string[]) {\n super(`Circular dependency detected: ${cycle.join(' -> ')}`, 'CIRCULAR_DEPENDENCY');\n this.name = 'CircularDependencyError';\n }\n}\n\n/**\n * Error thrown when plugin initialization fails.\n */\nexport class PluginInitializationError extends UtilsError {\n readonly pluginName: string;\n override readonly cause: Error;\n\n constructor(pluginName: string, cause: Error) {\n super(`Plugin \"${pluginName}\" failed to initialize: ${cause.message}`, 'PLUGIN_INIT_FAILED');\n this.name = 'PluginInitializationError';\n this.pluginName = pluginName;\n this.cause = cause;\n }\n}\n\n/**\n * Error thrown when kernel is already initialized.\n */\nexport class KernelAlreadyInitializedError extends UtilsError {\n constructor() {\n super('Kernel is already initialized', 'KERNEL_ALREADY_INITIALIZED');\n this.name = 'KernelAlreadyInitializedError';\n }\n}\n\n/**\n * Error thrown when kernel is currently initializing (race condition prevention).\n */\nexport class KernelInitializingError extends UtilsError {\n constructor() {\n super('Kernel is currently initializing', 'KERNEL_INITIALIZING');\n this.name = 'KernelInitializingError';\n }\n}\n"]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var UtilsError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(message, code) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "UtilsError";
|
|
7
|
+
this.code = code;
|
|
8
|
+
Error.captureStackTrace(this, this.constructor);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var InvalidPathError = class extends UtilsError {
|
|
12
|
+
constructor(path) {
|
|
13
|
+
super(`Invalid path: ${path}`, "INVALID_PATH");
|
|
14
|
+
this.name = "InvalidPathError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var CircularReferenceError = class extends UtilsError {
|
|
18
|
+
constructor() {
|
|
19
|
+
super("Circular reference detected", "CIRCULAR_REF");
|
|
20
|
+
this.name = "CircularReferenceError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var TimeoutError = class extends UtilsError {
|
|
24
|
+
constructor(ms) {
|
|
25
|
+
super(`Operation timed out after ${ms}ms`, "TIMEOUT");
|
|
26
|
+
this.name = "TimeoutError";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var PluginAlreadyRegisteredError = class extends UtilsError {
|
|
30
|
+
constructor(name) {
|
|
31
|
+
super(`Plugin "${name}" already registered`, "PLUGIN_ALREADY_REGISTERED");
|
|
32
|
+
this.name = "PluginAlreadyRegisteredError";
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var PluginNotFoundError = class extends UtilsError {
|
|
36
|
+
constructor(name) {
|
|
37
|
+
super(`Plugin "${name}" not found`, "PLUGIN_NOT_FOUND");
|
|
38
|
+
this.name = "PluginNotFoundError";
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var PluginDependencyMissingError = class extends UtilsError {
|
|
42
|
+
constructor(plugin, dependency) {
|
|
43
|
+
super(`Plugin "${plugin}" requires "${dependency}" to be registered first`, "PLUGIN_DEPENDENCY_MISSING");
|
|
44
|
+
this.name = "PluginDependencyMissingError";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var MaxRetriesExceededError = class extends UtilsError {
|
|
48
|
+
/** Number of attempts that were made. */
|
|
49
|
+
attempts;
|
|
50
|
+
/**
|
|
51
|
+
* @param attempts - Number of attempts that were made
|
|
52
|
+
* @param cause - The error thrown by the last attempt (available as `error.cause`)
|
|
53
|
+
*/
|
|
54
|
+
constructor(attempts, cause) {
|
|
55
|
+
super(`Maximum retry attempts (${attempts}) exceeded`, "MAX_RETRIES_EXCEEDED");
|
|
56
|
+
this.name = "MaxRetriesExceededError";
|
|
57
|
+
this.attempts = attempts;
|
|
58
|
+
if (cause !== void 0) {
|
|
59
|
+
Object.defineProperty(this, "cause", {
|
|
60
|
+
value: cause,
|
|
61
|
+
writable: true,
|
|
62
|
+
enumerable: false,
|
|
63
|
+
configurable: true
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var CircularDependencyError = class extends UtilsError {
|
|
69
|
+
constructor(cycle) {
|
|
70
|
+
super(`Circular dependency detected: ${cycle.join(" -> ")}`, "CIRCULAR_DEPENDENCY");
|
|
71
|
+
this.name = "CircularDependencyError";
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var PluginInitializationError = class extends UtilsError {
|
|
75
|
+
pluginName;
|
|
76
|
+
cause;
|
|
77
|
+
constructor(pluginName, cause) {
|
|
78
|
+
super(`Plugin "${pluginName}" failed to initialize: ${cause.message}`, "PLUGIN_INIT_FAILED");
|
|
79
|
+
this.name = "PluginInitializationError";
|
|
80
|
+
this.pluginName = pluginName;
|
|
81
|
+
this.cause = cause;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var KernelAlreadyInitializedError = class extends UtilsError {
|
|
85
|
+
constructor() {
|
|
86
|
+
super("Kernel is already initialized", "KERNEL_ALREADY_INITIALIZED");
|
|
87
|
+
this.name = "KernelAlreadyInitializedError";
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var KernelInitializingError = class extends UtilsError {
|
|
91
|
+
constructor() {
|
|
92
|
+
super("Kernel is currently initializing", "KERNEL_INITIALIZING");
|
|
93
|
+
this.name = "KernelInitializingError";
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export { CircularDependencyError, CircularReferenceError, InvalidPathError, KernelAlreadyInitializedError, KernelInitializingError, MaxRetriesExceededError, PluginAlreadyRegisteredError, PluginDependencyMissingError, PluginInitializationError, PluginNotFoundError, TimeoutError, UtilsError };
|
|
98
|
+
//# sourceMappingURL=chunk-IUDFQZIP.js.map
|
|
99
|
+
//# sourceMappingURL=chunk-IUDFQZIP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";AAGO,IAAM,UAAA,GAAN,cAAyB,KAAA,CAAM;AAAA,EACpC,IAAA;AAAA,EAEA,WAAA,CAAY,SAAiB,IAAA,EAAc;AACzC,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,KAAA,CAAM,iBAAA,CAAkB,IAAA,EAAM,IAAA,CAAK,WAAW,CAAA;AAAA,EAChD;AACF;AAKO,IAAM,gBAAA,GAAN,cAA+B,UAAA,CAAW;AAAA,EAC/C,YAAY,IAAA,EAAc;AACxB,IAAA,KAAA,CAAM,CAAA,cAAA,EAAiB,IAAI,CAAA,CAAA,EAAI,cAAc,CAAA;AAC7C,IAAA,IAAA,CAAK,IAAA,GAAO,kBAAA;AAAA,EACd;AACF;AAKO,IAAM,sBAAA,GAAN,cAAqC,UAAA,CAAW;AAA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AAqB,CAAA;AAC/D,IAAA,IAAA,CAAK,IAAA,GAAO,yBAAA;AAAA,EACd;AACF","file":"chunk-IUDFQZIP.js","sourcesContent":["/**\n * Base error class for all @oxog/utils errors.\n */\nexport class UtilsError extends Error {\n code: string;\n\n constructor(message: string, code: string) {\n super(message);\n this.name = 'UtilsError';\n this.code = code;\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\n/**\n * Error thrown when an invalid path is provided to get/set/has functions.\n */\nexport class InvalidPathError extends UtilsError {\n constructor(path: string) {\n super(`Invalid path: ${path}`, 'INVALID_PATH');\n this.name = 'InvalidPathError';\n }\n}\n\n/**\n * Error thrown when a circular reference is detected during deep operations.\n */\nexport class CircularReferenceError extends UtilsError {\n constructor() {\n super('Circular reference detected', 'CIRCULAR_REF');\n this.name = 'CircularReferenceError';\n }\n}\n\n/**\n * Error thrown when an operation times out.\n */\nexport class TimeoutError extends UtilsError {\n constructor(ms: number) {\n super(`Operation timed out after ${ms}ms`, 'TIMEOUT');\n this.name = 'TimeoutError';\n }\n}\n\n/**\n * Error thrown when a plugin is already registered.\n */\nexport class PluginAlreadyRegisteredError extends UtilsError {\n constructor(name: string) {\n super(`Plugin \"${name}\" already registered`, 'PLUGIN_ALREADY_REGISTERED');\n this.name = 'PluginAlreadyRegisteredError';\n }\n}\n\n/**\n * Error thrown when a requested plugin is not found.\n */\nexport class PluginNotFoundError extends UtilsError {\n constructor(name: string) {\n super(`Plugin \"${name}\" not found`, 'PLUGIN_NOT_FOUND');\n this.name = 'PluginNotFoundError';\n }\n}\n\n/**\n * Error thrown when a plugin dependency is missing.\n */\nexport class PluginDependencyMissingError extends UtilsError {\n constructor(plugin: string, dependency: string) {\n super(`Plugin \"${plugin}\" requires \"${dependency}\" to be registered first`, 'PLUGIN_DEPENDENCY_MISSING');\n this.name = 'PluginDependencyMissingError';\n }\n}\n\n/**\n * Error thrown when retry attempts are exhausted.\n */\nexport class MaxRetriesExceededError extends UtilsError {\n /** Number of attempts that were made. */\n readonly attempts: number;\n\n /**\n * @param attempts - Number of attempts that were made\n * @param cause - The error thrown by the last attempt (available as `error.cause`)\n */\n constructor(attempts: number, cause?: unknown) {\n super(`Maximum retry attempts (${attempts}) exceeded`, 'MAX_RETRIES_EXCEEDED');\n this.name = 'MaxRetriesExceededError';\n this.attempts = attempts;\n if (cause !== undefined) {\n Object.defineProperty(this, 'cause', {\n value: cause,\n writable: true,\n enumerable: false,\n configurable: true,\n });\n }\n }\n}\n\n/**\n * Error thrown when circular dependency is detected between plugins.\n */\nexport class CircularDependencyError extends UtilsError {\n constructor(cycle: string[]) {\n super(`Circular dependency detected: ${cycle.join(' -> ')}`, 'CIRCULAR_DEPENDENCY');\n this.name = 'CircularDependencyError';\n }\n}\n\n/**\n * Error thrown when plugin initialization fails.\n */\nexport class PluginInitializationError extends UtilsError {\n readonly pluginName: string;\n override readonly cause: Error;\n\n constructor(pluginName: string, cause: Error) {\n super(`Plugin \"${pluginName}\" failed to initialize: ${cause.message}`, 'PLUGIN_INIT_FAILED');\n this.name = 'PluginInitializationError';\n this.pluginName = pluginName;\n this.cause = cause;\n }\n}\n\n/**\n * Error thrown when kernel is already initialized.\n */\nexport class KernelAlreadyInitializedError extends UtilsError {\n constructor() {\n super('Kernel is already initialized', 'KERNEL_ALREADY_INITIALIZED');\n this.name = 'KernelAlreadyInitializedError';\n }\n}\n\n/**\n * Error thrown when kernel is currently initializing (race condition prevention).\n */\nexport class KernelInitializingError extends UtilsError {\n constructor() {\n super('Kernel is currently initializing', 'KERNEL_INITIALIZING');\n this.name = 'KernelInitializingError';\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export { __export };
|
|
8
|
+
//# sourceMappingURL=chunk-PZ5AY32C.js.map
|
|
9
|
+
//# sourceMappingURL=chunk-PZ5AY32C.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-PZ5AY32C.js"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __export = (target, all) => {
|
|
5
|
+
for (var name in all)
|
|
6
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
exports.__export = __export;
|
|
10
|
+
//# sourceMappingURL=chunk-Q7SFCCGT.cjs.map
|
|
11
|
+
//# sourceMappingURL=chunk-Q7SFCCGT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-Q7SFCCGT.cjs"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/internal.ts
|
|
4
|
+
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
5
|
+
var hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
6
|
+
function assignOwn(obj, key, value) {
|
|
7
|
+
if (key === "__proto__") {
|
|
8
|
+
Object.defineProperty(obj, key, { value, writable: true, enumerable: true, configurable: true });
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function parsePath(path) {
|
|
14
|
+
const segments = [];
|
|
15
|
+
const source = String(path);
|
|
16
|
+
const pattern = /\[\s*(?:'([^']*)'|"([^"]*)"|([^\]]*?))\s*\]|([^.[\]]+)/g;
|
|
17
|
+
let match;
|
|
18
|
+
while ((match = pattern.exec(source)) !== null) {
|
|
19
|
+
const [, single, double, bare, dotted] = match;
|
|
20
|
+
if (dotted !== void 0) {
|
|
21
|
+
segments.push({ key: dotted, index: false });
|
|
22
|
+
} else {
|
|
23
|
+
const key = single ?? double ?? bare ?? "";
|
|
24
|
+
if (key === "") continue;
|
|
25
|
+
segments.push({ key, index: single === void 0 && double === void 0 && /^\d+$/.test(key) });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return segments;
|
|
29
|
+
}
|
|
30
|
+
function hasUnsafeSegment(segments) {
|
|
31
|
+
return segments.some((segment) => UNSAFE_KEYS.has(segment.key));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.UNSAFE_KEYS = UNSAFE_KEYS;
|
|
35
|
+
exports.assignOwn = assignOwn;
|
|
36
|
+
exports.hasOwn = hasOwn;
|
|
37
|
+
exports.hasUnsafeSegment = hasUnsafeSegment;
|
|
38
|
+
exports.parsePath = parsePath;
|
|
39
|
+
//# sourceMappingURL=chunk-SWG777R6.cjs.map
|
|
40
|
+
//# sourceMappingURL=chunk-SWG777R6.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal.ts"],"names":[],"mappings":";;;AAMO,IAAM,8BAAmC,IAAI,GAAA,CAAI,CAAC,WAAA,EAAa,aAAA,EAAe,WAAW,CAAC;AAE1F,IAAM,MAAA,GAAS,CAAC,GAAA,EAAa,GAAA,KAClC,OAAO,SAAA,CAAU,cAAA,CAAe,IAAA,CAAK,GAAA,EAAK,GAAG;AAQxC,SAAS,SAAA,CAAU,GAAA,EAAU,GAAA,EAAkB,KAAA,EAAsB;AAC1E,EAAA,IAAI,QAAQ,WAAA,EAAa;AACvB,IAAA,MAAA,CAAO,cAAA,CAAe,GAAA,EAAK,GAAA,EAAK,EAAE,KAAA,EAAO,QAAA,EAAU,IAAA,EAAM,UAAA,EAAY,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,CAAA;AAAA,EACjG,CAAA,MAAO;AACL,IAAA,GAAA,CAAI,GAAG,CAAA,GAAI,KAAA;AAAA,EACb;AACF;AAcO,SAAS,UAAU,IAAA,EAAsC;AAC9D,EAAA,MAAM,WAA0B,EAAC;AACjC,EAAA,MAAM,MAAA,GAAS,OAAO,IAAI,CAAA;AAC1B,EAAA,MAAM,OAAA,GAAU,yDAAA;AAChB,EAAA,IAAI,KAAA;AACJ,EAAA,OAAA,CAAQ,KAAA,GAAQ,OAAA,CAAQ,IAAA,CAAK,MAAM,OAAO,IAAA,EAAM;AAC9C,IAAA,MAAM,GAAG,MAAA,EAAQ,MAAA,EAAQ,IAAA,EAAM,MAAM,CAAA,GAAI,KAAA;AACzC,IAAA,IAAI,WAAW,MAAA,EAAW;AACxB,MAAA,QAAA,CAAS,KAAK,EAAE,GAAA,EAAK,MAAA,EAAQ,KAAA,EAAO,OAAO,CAAA;AAAA,IAC7C,CAAA,MAAO;AACL,MAAA,MAAM,GAAA,GAAM,MAAA,IAAU,MAAA,IAAU,IAAA,IAAQ,EAAA;AACxC,MAAA,IAAI,QAAQ,EAAA,EAAI;AAChB,MAAA,QAAA,CAAS,IAAA,CAAK,EAAE,GAAA,EAAK,KAAA,EAAO,MAAA,KAAW,MAAA,IAAa,MAAA,KAAW,MAAA,IAAa,OAAA,CAAQ,IAAA,CAAK,GAAG,CAAA,EAAG,CAAA;AAAA,IACjG;AAAA,EACF;AACA,EAAA,OAAO,QAAA;AACT;AAGO,SAAS,iBAAiB,QAAA,EAA2C;AAC1E,EAAA,OAAO,QAAA,CAAS,KAAK,CAAC,OAAA,KAAY,YAAY,GAAA,CAAI,OAAA,CAAQ,GAAG,CAAC,CAAA;AAChE","file":"chunk-SWG777R6.cjs","sourcesContent":["/**\n * Internal helpers shared by the public modules. Not part of the public API.\n * @internal\n */\n\n/** Keys that can reach or replace an object's prototype. */\nexport const UNSAFE_KEYS: ReadonlySet<string> = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport const hasOwn = (obj: object, key: PropertyKey): boolean =>\n Object.prototype.hasOwnProperty.call(obj, key);\n\n/**\n * Assign `obj[key] = value` as an own data property.\n *\n * Plain assignment of `\"__proto__\"` would replace the prototype of `obj`\n * instead of storing a value; this helper always stores data.\n */\nexport function assignOwn(obj: any, key: PropertyKey, value: unknown): void {\n if (key === '__proto__') {\n Object.defineProperty(obj, key, { value, writable: true, enumerable: true, configurable: true });\n } else {\n obj[key] = value;\n }\n}\n\n/** One segment of a parsed property path. */\nexport interface PathSegment {\n key: string;\n /** True when the segment was written as a numeric bracket index (`[0]`). */\n index: boolean;\n}\n\n/**\n * Parse a property path such as `a.b[0].c` or `a['b'].c`.\n *\n * Empty segments are ignored, so `a..b` is the same as `a.b`.\n */\nexport function parsePath(path: string | number): PathSegment[] {\n const segments: PathSegment[] = [];\n const source = String(path);\n const pattern = /\\[\\s*(?:'([^']*)'|\"([^\"]*)\"|([^\\]]*?))\\s*\\]|([^.[\\]]+)/g;\n let match: RegExpExecArray | null;\n while ((match = pattern.exec(source)) !== null) {\n const [, single, double, bare, dotted] = match;\n if (dotted !== undefined) {\n segments.push({ key: dotted, index: false });\n } else {\n const key = single ?? double ?? bare ?? '';\n if (key === '') continue;\n segments.push({ key, index: single === undefined && double === undefined && /^\\d+$/.test(key) });\n }\n }\n return segments;\n}\n\n/** True when any segment of the path is `__proto__`, `constructor` or `prototype`. */\nexport function hasUnsafeSegment(segments: readonly PathSegment[]): boolean {\n return segments.some((segment) => UNSAFE_KEYS.has(segment.key));\n}\n"]}
|