atomic-lockfile 0.0.1-security → 1.4.2
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.
Potentially problematic release.
This version of atomic-lockfile might be problematic. Click here for more details.
- package/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.md +207 -3
- package/dist/esm/adapters/atomic.js +42 -0
- package/dist/esm/adapters/atomic.js.map +1 -0
- package/dist/esm/adapters/fs.js +29 -0
- package/dist/esm/adapters/fs.js.map +1 -0
- package/dist/esm/adapters/index.js +27 -0
- package/dist/esm/adapters/index.js.map +1 -0
- package/dist/esm/adapters/mkdir.js +31 -0
- package/dist/esm/adapters/mkdir.js.map +1 -0
- package/dist/esm/adapters/symlink.js +29 -0
- package/dist/esm/adapters/symlink.js.map +1 -0
- package/dist/esm/async/check.js +11 -0
- package/dist/esm/async/check.js.map +1 -0
- package/dist/esm/async/index.js +4 -0
- package/dist/esm/async/index.js.map +1 -0
- package/dist/esm/async/lock.js +13 -0
- package/dist/esm/async/lock.js.map +1 -0
- package/dist/esm/async/unlock.js +8 -0
- package/dist/esm/async/unlock.js.map +1 -0
- package/dist/esm/cli/commands/cleanup.js +28 -0
- package/dist/esm/cli/commands/cleanup.js.map +1 -0
- package/dist/esm/cli/commands/list.js +26 -0
- package/dist/esm/cli/commands/list.js.map +1 -0
- package/dist/esm/cli/commands/lock.js +26 -0
- package/dist/esm/cli/commands/lock.js.map +1 -0
- package/dist/esm/cli/commands/status.js +27 -0
- package/dist/esm/cli/commands/status.js.map +1 -0
- package/dist/esm/cli/commands/unlock.js +20 -0
- package/dist/esm/cli/commands/unlock.js.map +1 -0
- package/dist/esm/cli/formatters/index.js +14 -0
- package/dist/esm/cli/formatters/index.js.map +1 -0
- package/dist/esm/cli/formatters/json.js +15 -0
- package/dist/esm/cli/formatters/json.js.map +1 -0
- package/dist/esm/cli/formatters/table.js +18 -0
- package/dist/esm/cli/formatters/table.js.map +1 -0
- package/dist/esm/cli/formatters/text.js +20 -0
- package/dist/esm/cli/formatters/text.js.map +1 -0
- package/dist/esm/cli/index.js +56 -0
- package/dist/esm/cli/index.js.map +1 -0
- package/dist/esm/compat/cjs.js +11 -0
- package/dist/esm/compat/cjs.js.map +1 -0
- package/dist/esm/compat/esm.js +11 -0
- package/dist/esm/compat/esm.js.map +1 -0
- package/dist/esm/compat/index.js +4 -0
- package/dist/esm/compat/index.js.map +1 -0
- package/dist/esm/compat/v1.js +23 -0
- package/dist/esm/compat/v1.js.map +1 -0
- package/dist/esm/config/defaults.js +12 -0
- package/dist/esm/config/defaults.js.map +1 -0
- package/dist/esm/config/index.js +17 -0
- package/dist/esm/config/index.js.map +1 -0
- package/dist/esm/config/schema.js +55 -0
- package/dist/esm/config/schema.js.map +1 -0
- package/dist/esm/constants/defaults.js +15 -0
- package/dist/esm/constants/defaults.js.map +1 -0
- package/dist/esm/constants/errors.js +37 -0
- package/dist/esm/constants/errors.js.map +1 -0
- package/dist/esm/constants/index.js +14 -0
- package/dist/esm/constants/index.js.map +1 -0
- package/dist/esm/constants/signals.js +21 -0
- package/dist/esm/constants/signals.js.map +1 -0
- package/dist/esm/constants/timeouts.js +16 -0
- package/dist/esm/constants/timeouts.js.map +1 -0
- package/dist/esm/core/acquire.js +51 -0
- package/dist/esm/core/acquire.js.map +1 -0
- package/dist/esm/core/buildLockData.js +23 -0
- package/dist/esm/core/buildLockData.js.map +1 -0
- package/dist/esm/core/check.js +62 -0
- package/dist/esm/core/check.js.map +1 -0
- package/dist/esm/core/cleanup.js +45 -0
- package/dist/esm/core/cleanup.js.map +1 -0
- package/dist/esm/core/handle.js +43 -0
- package/dist/esm/core/handle.js.map +1 -0
- package/dist/esm/core/index.js +8 -0
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/core/list.js +38 -0
- package/dist/esm/core/list.js.map +1 -0
- package/dist/esm/core/release.js +21 -0
- package/dist/esm/core/release.js.map +1 -0
- package/dist/esm/errors/AbortError.js +18 -0
- package/dist/esm/errors/AbortError.js.map +1 -0
- package/dist/esm/errors/ConflictError.js +20 -0
- package/dist/esm/errors/ConflictError.js.map +1 -0
- package/dist/esm/errors/IOError.js +24 -0
- package/dist/esm/errors/IOError.js.map +1 -0
- package/dist/esm/errors/LockError.js +30 -0
- package/dist/esm/errors/LockError.js.map +1 -0
- package/dist/esm/errors/PermissionError.js +21 -0
- package/dist/esm/errors/PermissionError.js.map +1 -0
- package/dist/esm/errors/StaleError.js +27 -0
- package/dist/esm/errors/StaleError.js.map +1 -0
- package/dist/esm/errors/TimeoutError.js +21 -0
- package/dist/esm/errors/TimeoutError.js.map +1 -0
- package/dist/esm/errors/ValidationError.js +21 -0
- package/dist/esm/errors/ValidationError.js.map +1 -0
- package/dist/esm/errors/index.js +24 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/events/emitter.js +41 -0
- package/dist/esm/events/emitter.js.map +1 -0
- package/dist/esm/events/index.js +3 -0
- package/dist/esm/events/index.js.map +1 -0
- package/dist/esm/events/types.js +15 -0
- package/dist/esm/events/types.js.map +1 -0
- package/dist/esm/hooks/afterLock.js +18 -0
- package/dist/esm/hooks/afterLock.js.map +1 -0
- package/dist/esm/hooks/afterUnlock.js +18 -0
- package/dist/esm/hooks/afterUnlock.js.map +1 -0
- package/dist/esm/hooks/beforeLock.js +18 -0
- package/dist/esm/hooks/beforeLock.js.map +1 -0
- package/dist/esm/hooks/beforeUnlock.js +18 -0
- package/dist/esm/hooks/beforeUnlock.js.map +1 -0
- package/dist/esm/hooks/index.js +24 -0
- package/dist/esm/hooks/index.js.map +1 -0
- package/dist/esm/hooks/onError.js +18 -0
- package/dist/esm/hooks/onError.js.map +1 -0
- package/dist/esm/hooks/onStale.js +18 -0
- package/dist/esm/hooks/onStale.js.map +1 -0
- package/dist/esm/hooks/onTimeout.js +18 -0
- package/dist/esm/hooks/onTimeout.js.map +1 -0
- package/dist/esm/index.js +21 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger/console.js +38 -0
- package/dist/esm/logger/console.js.map +1 -0
- package/dist/esm/logger/debug.js +26 -0
- package/dist/esm/logger/debug.js.map +1 -0
- package/dist/esm/logger/index.js +15 -0
- package/dist/esm/logger/index.js.map +1 -0
- package/dist/esm/logger/noop.js +12 -0
- package/dist/esm/logger/noop.js.map +1 -0
- package/dist/esm/meta/index.js +3 -0
- package/dist/esm/meta/index.js.map +1 -0
- package/dist/esm/meta/package.js +27 -0
- package/dist/esm/meta/package.js.map +1 -0
- package/dist/esm/meta/version.js +27 -0
- package/dist/esm/meta/version.js.map +1 -0
- package/dist/esm/middleware/index.js +11 -0
- package/dist/esm/middleware/index.js.map +1 -0
- package/dist/esm/middleware/logging.js +20 -0
- package/dist/esm/middleware/logging.js.map +1 -0
- package/dist/esm/middleware/metrics.js +32 -0
- package/dist/esm/middleware/metrics.js.map +1 -0
- package/dist/esm/middleware/retry.js +22 -0
- package/dist/esm/middleware/retry.js.map +1 -0
- package/dist/esm/middleware/timeout.js +28 -0
- package/dist/esm/middleware/timeout.js.map +1 -0
- package/dist/esm/platform/darwin.js +17 -0
- package/dist/esm/platform/darwin.js.map +1 -0
- package/dist/esm/platform/index.js +6 -0
- package/dist/esm/platform/index.js.map +1 -0
- package/dist/esm/platform/linux.js +31 -0
- package/dist/esm/platform/linux.js.map +1 -0
- package/dist/esm/platform/unix.js +34 -0
- package/dist/esm/platform/unix.js.map +1 -0
- package/dist/esm/platform/windows.js +22 -0
- package/dist/esm/platform/windows.js.map +1 -0
- package/dist/esm/plugins/cleanup.js +39 -0
- package/dist/esm/plugins/cleanup.js.map +1 -0
- package/dist/esm/plugins/heartbeat.js +31 -0
- package/dist/esm/plugins/heartbeat.js.map +1 -0
- package/dist/esm/plugins/index.js +6 -0
- package/dist/esm/plugins/index.js.map +1 -0
- package/dist/esm/plugins/pid.js +25 -0
- package/dist/esm/plugins/pid.js.map +1 -0
- package/dist/esm/plugins/stale.js +21 -0
- package/dist/esm/plugins/stale.js.map +1 -0
- package/dist/esm/plugins/ttl.js +28 -0
- package/dist/esm/plugins/ttl.js.map +1 -0
- package/dist/esm/promise/index.js +3 -0
- package/dist/esm/promise/index.js.map +1 -0
- package/dist/esm/promise/lock.js +13 -0
- package/dist/esm/promise/lock.js.map +1 -0
- package/dist/esm/promise/withLock.js +22 -0
- package/dist/esm/promise/withLock.js.map +1 -0
- package/dist/esm/registry/global.js +29 -0
- package/dist/esm/registry/global.js.map +1 -0
- package/dist/esm/registry/index.js +3 -0
- package/dist/esm/registry/index.js.map +1 -0
- package/dist/esm/registry/local.js +28 -0
- package/dist/esm/registry/local.js.map +1 -0
- package/dist/esm/strategies/advisory.js +19 -0
- package/dist/esm/strategies/advisory.js.map +1 -0
- package/dist/esm/strategies/exclusive.js +19 -0
- package/dist/esm/strategies/exclusive.js.map +1 -0
- package/dist/esm/strategies/index.js +27 -0
- package/dist/esm/strategies/index.js.map +1 -0
- package/dist/esm/strategies/optimistic.js +22 -0
- package/dist/esm/strategies/optimistic.js.map +1 -0
- package/dist/esm/strategies/shared.js +19 -0
- package/dist/esm/strategies/shared.js.map +1 -0
- package/dist/esm/sync/check.js +39 -0
- package/dist/esm/sync/check.js.map +1 -0
- package/dist/esm/sync/index.js +4 -0
- package/dist/esm/sync/index.js.map +1 -0
- package/dist/esm/sync/lock.js +39 -0
- package/dist/esm/sync/lock.js.map +1 -0
- package/dist/esm/sync/unlock.js +21 -0
- package/dist/esm/sync/unlock.js.map +1 -0
- package/dist/esm/types/adapter.js +2 -0
- package/dist/esm/types/adapter.js.map +1 -0
- package/dist/esm/types/events.js +2 -0
- package/dist/esm/types/events.js.map +1 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/lock.js +2 -0
- package/dist/esm/types/lock.js.map +1 -0
- package/dist/esm/types/logger.js +2 -0
- package/dist/esm/types/logger.js.map +1 -0
- package/dist/esm/types/options.js +2 -0
- package/dist/esm/types/options.js.map +1 -0
- package/dist/esm/types/state.js +2 -0
- package/dist/esm/types/state.js.map +1 -0
- package/dist/esm/types/strategy.js +2 -0
- package/dist/esm/types/strategy.js.map +1 -0
- package/dist/esm/utils/backoff.js +40 -0
- package/dist/esm/utils/backoff.js.map +1 -0
- package/dist/esm/utils/fs.js +88 -0
- package/dist/esm/utils/fs.js.map +1 -0
- package/dist/esm/utils/hash.js +20 -0
- package/dist/esm/utils/hash.js.map +1 -0
- package/dist/esm/utils/hostname.js +28 -0
- package/dist/esm/utils/hostname.js.map +1 -0
- package/dist/esm/utils/index.js +14 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/parse.js +44 -0
- package/dist/esm/utils/parse.js.map +1 -0
- package/dist/esm/utils/path.js +35 -0
- package/dist/esm/utils/path.js.map +1 -0
- package/dist/esm/utils/pid.js +35 -0
- package/dist/esm/utils/pid.js.map +1 -0
- package/dist/esm/utils/platform.js +35 -0
- package/dist/esm/utils/platform.js.map +1 -0
- package/dist/esm/utils/random.js +26 -0
- package/dist/esm/utils/random.js.map +1 -0
- package/dist/esm/utils/retry.js +37 -0
- package/dist/esm/utils/retry.js.map +1 -0
- package/dist/esm/utils/serialize.js +27 -0
- package/dist/esm/utils/serialize.js.map +1 -0
- package/dist/esm/utils/time.js +44 -0
- package/dist/esm/utils/time.js.map +1 -0
- package/dist/esm/utils/validate.js +42 -0
- package/dist/esm/utils/validate.js.map +1 -0
- package/dist/types/adapters/atomic.d.ts +3 -0
- package/dist/types/adapters/atomic.d.ts.map +1 -0
- package/dist/types/adapters/fs.d.ts +3 -0
- package/dist/types/adapters/fs.d.ts.map +1 -0
- package/dist/types/adapters/index.d.ts +9 -0
- package/dist/types/adapters/index.d.ts.map +1 -0
- package/dist/types/adapters/mkdir.d.ts +3 -0
- package/dist/types/adapters/mkdir.d.ts.map +1 -0
- package/dist/types/adapters/symlink.d.ts +3 -0
- package/dist/types/adapters/symlink.d.ts.map +1 -0
- package/dist/types/async/check.d.ts +6 -0
- package/dist/types/async/check.d.ts.map +1 -0
- package/dist/types/async/index.d.ts +4 -0
- package/dist/types/async/index.d.ts.map +1 -0
- package/dist/types/async/lock.d.ts +5 -0
- package/dist/types/async/lock.d.ts.map +1 -0
- package/dist/types/async/unlock.d.ts +5 -0
- package/dist/types/async/unlock.d.ts.map +1 -0
- package/dist/types/cli/commands/cleanup.d.ts +2 -0
- package/dist/types/cli/commands/cleanup.d.ts.map +1 -0
- package/dist/types/cli/commands/list.d.ts +2 -0
- package/dist/types/cli/commands/list.d.ts.map +1 -0
- package/dist/types/cli/commands/lock.d.ts +2 -0
- package/dist/types/cli/commands/lock.d.ts.map +1 -0
- package/dist/types/cli/commands/status.d.ts +2 -0
- package/dist/types/cli/commands/status.d.ts.map +1 -0
- package/dist/types/cli/commands/unlock.d.ts +2 -0
- package/dist/types/cli/commands/unlock.d.ts.map +1 -0
- package/dist/types/cli/formatters/index.d.ts +7 -0
- package/dist/types/cli/formatters/index.d.ts.map +1 -0
- package/dist/types/cli/formatters/json.d.ts +5 -0
- package/dist/types/cli/formatters/json.d.ts.map +1 -0
- package/dist/types/cli/formatters/table.d.ts +3 -0
- package/dist/types/cli/formatters/table.d.ts.map +1 -0
- package/dist/types/cli/formatters/text.d.ts +6 -0
- package/dist/types/cli/formatters/text.d.ts.map +1 -0
- package/dist/types/cli/index.d.ts +3 -0
- package/dist/types/cli/index.d.ts.map +1 -0
- package/dist/types/compat/cjs.d.ts +11 -0
- package/dist/types/compat/cjs.d.ts.map +1 -0
- package/dist/types/compat/esm.d.ts +11 -0
- package/dist/types/compat/esm.d.ts.map +1 -0
- package/dist/types/compat/index.d.ts +4 -0
- package/dist/types/compat/index.d.ts.map +1 -0
- package/dist/types/compat/v1.d.ts +15 -0
- package/dist/types/compat/v1.d.ts.map +1 -0
- package/dist/types/config/defaults.d.ts +3 -0
- package/dist/types/config/defaults.d.ts.map +1 -0
- package/dist/types/config/index.d.ts +9 -0
- package/dist/types/config/index.d.ts.map +1 -0
- package/dist/types/config/schema.d.ts +12 -0
- package/dist/types/config/schema.d.ts.map +1 -0
- package/dist/types/constants/defaults.d.ts +15 -0
- package/dist/types/constants/defaults.d.ts.map +1 -0
- package/dist/types/constants/errors.d.ts +21 -0
- package/dist/types/constants/errors.d.ts.map +1 -0
- package/dist/types/constants/index.d.ts +14 -0
- package/dist/types/constants/index.d.ts.map +1 -0
- package/dist/types/constants/signals.d.ts +6 -0
- package/dist/types/constants/signals.d.ts.map +1 -0
- package/dist/types/constants/timeouts.d.ts +16 -0
- package/dist/types/constants/timeouts.d.ts.map +1 -0
- package/dist/types/core/acquire.d.ts +4 -0
- package/dist/types/core/acquire.d.ts.map +1 -0
- package/dist/types/core/buildLockData.d.ts +4 -0
- package/dist/types/core/buildLockData.d.ts.map +1 -0
- package/dist/types/core/check.d.ts +6 -0
- package/dist/types/core/check.d.ts.map +1 -0
- package/dist/types/core/cleanup.d.ts +14 -0
- package/dist/types/core/cleanup.d.ts.map +1 -0
- package/dist/types/core/handle.d.ts +4 -0
- package/dist/types/core/handle.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +9 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/list.d.ts +4 -0
- package/dist/types/core/list.d.ts.map +1 -0
- package/dist/types/core/release.d.ts +4 -0
- package/dist/types/core/release.d.ts.map +1 -0
- package/dist/types/errors/AbortError.d.ts +8 -0
- package/dist/types/errors/AbortError.d.ts.map +1 -0
- package/dist/types/errors/ConflictError.d.ts +9 -0
- package/dist/types/errors/ConflictError.d.ts.map +1 -0
- package/dist/types/errors/IOError.d.ts +10 -0
- package/dist/types/errors/IOError.d.ts.map +1 -0
- package/dist/types/errors/LockError.d.ts +12 -0
- package/dist/types/errors/LockError.d.ts.map +1 -0
- package/dist/types/errors/PermissionError.d.ts +9 -0
- package/dist/types/errors/PermissionError.d.ts.map +1 -0
- package/dist/types/errors/StaleError.d.ts +11 -0
- package/dist/types/errors/StaleError.d.ts.map +1 -0
- package/dist/types/errors/TimeoutError.d.ts +9 -0
- package/dist/types/errors/TimeoutError.d.ts.map +1 -0
- package/dist/types/errors/ValidationError.d.ts +9 -0
- package/dist/types/errors/ValidationError.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +14 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/events/emitter.d.ts +12 -0
- package/dist/types/events/emitter.d.ts.map +1 -0
- package/dist/types/events/index.d.ts +3 -0
- package/dist/types/events/index.d.ts.map +1 -0
- package/dist/types/events/types.d.ts +3 -0
- package/dist/types/events/types.d.ts.map +1 -0
- package/dist/types/hooks/afterLock.d.ts +7 -0
- package/dist/types/hooks/afterLock.d.ts.map +1 -0
- package/dist/types/hooks/afterUnlock.d.ts +7 -0
- package/dist/types/hooks/afterUnlock.d.ts.map +1 -0
- package/dist/types/hooks/beforeLock.d.ts +7 -0
- package/dist/types/hooks/beforeLock.d.ts.map +1 -0
- package/dist/types/hooks/beforeUnlock.d.ts +7 -0
- package/dist/types/hooks/beforeUnlock.d.ts.map +1 -0
- package/dist/types/hooks/index.d.ts +9 -0
- package/dist/types/hooks/index.d.ts.map +1 -0
- package/dist/types/hooks/onError.d.ts +6 -0
- package/dist/types/hooks/onError.d.ts.map +1 -0
- package/dist/types/hooks/onStale.d.ts +7 -0
- package/dist/types/hooks/onStale.d.ts.map +1 -0
- package/dist/types/hooks/onTimeout.d.ts +6 -0
- package/dist/types/hooks/onTimeout.d.ts.map +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger/console.d.ts +3 -0
- package/dist/types/logger/console.d.ts.map +1 -0
- package/dist/types/logger/debug.d.ts +3 -0
- package/dist/types/logger/debug.d.ts.map +1 -0
- package/dist/types/logger/index.d.ts +8 -0
- package/dist/types/logger/index.d.ts.map +1 -0
- package/dist/types/logger/noop.d.ts +3 -0
- package/dist/types/logger/noop.d.ts.map +1 -0
- package/dist/types/meta/index.d.ts +3 -0
- package/dist/types/meta/index.d.ts.map +1 -0
- package/dist/types/meta/package.d.ts +8 -0
- package/dist/types/meta/package.d.ts.map +1 -0
- package/dist/types/meta/version.d.ts +14 -0
- package/dist/types/meta/version.d.ts.map +1 -0
- package/dist/types/middleware/index.d.ts +10 -0
- package/dist/types/middleware/index.d.ts.map +1 -0
- package/dist/types/middleware/logging.d.ts +3 -0
- package/dist/types/middleware/logging.d.ts.map +1 -0
- package/dist/types/middleware/metrics.d.ts +13 -0
- package/dist/types/middleware/metrics.d.ts.map +1 -0
- package/dist/types/middleware/retry.d.ts +5 -0
- package/dist/types/middleware/retry.d.ts.map +1 -0
- package/dist/types/middleware/timeout.d.ts +7 -0
- package/dist/types/middleware/timeout.d.ts.map +1 -0
- package/dist/types/platform/darwin.d.ts +5 -0
- package/dist/types/platform/darwin.d.ts.map +1 -0
- package/dist/types/platform/index.d.ts +6 -0
- package/dist/types/platform/index.d.ts.map +1 -0
- package/dist/types/platform/linux.d.ts +6 -0
- package/dist/types/platform/linux.d.ts.map +1 -0
- package/dist/types/platform/unix.d.ts +8 -0
- package/dist/types/platform/unix.d.ts.map +1 -0
- package/dist/types/platform/windows.d.ts +7 -0
- package/dist/types/platform/windows.d.ts.map +1 -0
- package/dist/types/plugins/cleanup.d.ts +4 -0
- package/dist/types/plugins/cleanup.d.ts.map +1 -0
- package/dist/types/plugins/heartbeat.d.ts +7 -0
- package/dist/types/plugins/heartbeat.d.ts.map +1 -0
- package/dist/types/plugins/index.d.ts +8 -0
- package/dist/types/plugins/index.d.ts.map +1 -0
- package/dist/types/plugins/pid.d.ts +5 -0
- package/dist/types/plugins/pid.d.ts.map +1 -0
- package/dist/types/plugins/stale.d.ts +9 -0
- package/dist/types/plugins/stale.d.ts.map +1 -0
- package/dist/types/plugins/ttl.d.ts +7 -0
- package/dist/types/plugins/ttl.d.ts.map +1 -0
- package/dist/types/promise/index.d.ts +3 -0
- package/dist/types/promise/index.d.ts.map +1 -0
- package/dist/types/promise/lock.d.ts +6 -0
- package/dist/types/promise/lock.d.ts.map +1 -0
- package/dist/types/promise/withLock.d.ts +7 -0
- package/dist/types/promise/withLock.d.ts.map +1 -0
- package/dist/types/registry/global.d.ts +15 -0
- package/dist/types/registry/global.d.ts.map +1 -0
- package/dist/types/registry/index.d.ts +3 -0
- package/dist/types/registry/index.d.ts.map +1 -0
- package/dist/types/registry/local.d.ts +10 -0
- package/dist/types/registry/local.d.ts.map +1 -0
- package/dist/types/strategies/advisory.d.ts +4 -0
- package/dist/types/strategies/advisory.d.ts.map +1 -0
- package/dist/types/strategies/exclusive.d.ts +4 -0
- package/dist/types/strategies/exclusive.d.ts.map +1 -0
- package/dist/types/strategies/index.d.ts +9 -0
- package/dist/types/strategies/index.d.ts.map +1 -0
- package/dist/types/strategies/optimistic.d.ts +8 -0
- package/dist/types/strategies/optimistic.d.ts.map +1 -0
- package/dist/types/strategies/shared.d.ts +4 -0
- package/dist/types/strategies/shared.d.ts.map +1 -0
- package/dist/types/sync/check.d.ts +4 -0
- package/dist/types/sync/check.d.ts.map +1 -0
- package/dist/types/sync/index.d.ts +4 -0
- package/dist/types/sync/index.d.ts.map +1 -0
- package/dist/types/sync/lock.d.ts +7 -0
- package/dist/types/sync/lock.d.ts.map +1 -0
- package/dist/types/sync/unlock.d.ts +3 -0
- package/dist/types/sync/unlock.d.ts.map +1 -0
- package/dist/types/types/adapter.d.ts +21 -0
- package/dist/types/types/adapter.d.ts.map +1 -0
- package/dist/types/types/events.d.ts +37 -0
- package/dist/types/types/events.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +8 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/lock.d.ts +38 -0
- package/dist/types/types/lock.d.ts.map +1 -0
- package/dist/types/types/logger.d.ts +21 -0
- package/dist/types/types/logger.d.ts.map +1 -0
- package/dist/types/types/options.d.ts +52 -0
- package/dist/types/types/options.d.ts.map +1 -0
- package/dist/types/types/state.d.ts +34 -0
- package/dist/types/types/state.d.ts.map +1 -0
- package/dist/types/types/strategy.d.ts +24 -0
- package/dist/types/types/strategy.d.ts.map +1 -0
- package/dist/types/utils/backoff.d.ts +6 -0
- package/dist/types/utils/backoff.d.ts.map +1 -0
- package/dist/types/utils/fs.d.ts +12 -0
- package/dist/types/utils/fs.d.ts.map +1 -0
- package/dist/types/utils/hash.d.ts +7 -0
- package/dist/types/utils/hash.d.ts.map +1 -0
- package/dist/types/utils/hostname.d.ts +9 -0
- package/dist/types/utils/hostname.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +14 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/parse.d.ts +7 -0
- package/dist/types/utils/parse.d.ts.map +1 -0
- package/dist/types/utils/path.d.ts +10 -0
- package/dist/types/utils/path.d.ts.map +1 -0
- package/dist/types/utils/pid.d.ts +11 -0
- package/dist/types/utils/pid.d.ts.map +1 -0
- package/dist/types/utils/platform.d.ts +12 -0
- package/dist/types/utils/platform.d.ts.map +1 -0
- package/dist/types/utils/random.d.ts +7 -0
- package/dist/types/utils/random.d.ts.map +1 -0
- package/dist/types/utils/retry.d.ts +10 -0
- package/dist/types/utils/retry.d.ts.map +1 -0
- package/dist/types/utils/serialize.d.ts +7 -0
- package/dist/types/utils/serialize.d.ts.map +1 -0
- package/dist/types/utils/time.d.ts +12 -0
- package/dist/types/utils/time.d.ts.map +1 -0
- package/dist/types/utils/validate.d.ts +5 -0
- package/dist/types/utils/validate.d.ts.map +1 -0
- package/package.json +132 -3
- package/src/adapters/atomic.ts +39 -0
- package/src/adapters/fs.ts +30 -0
- package/src/adapters/index.ts +31 -0
- package/src/adapters/mkdir.ts +32 -0
- package/src/adapters/symlink.ts +30 -0
- package/src/async/check.ts +15 -0
- package/src/async/index.ts +3 -0
- package/src/async/lock.ts +15 -0
- package/src/async/unlock.ts +11 -0
- package/src/cli/commands/cleanup.ts +28 -0
- package/src/cli/commands/list.ts +27 -0
- package/src/cli/commands/lock.ts +27 -0
- package/src/cli/commands/status.ts +26 -0
- package/src/cli/commands/unlock.ts +20 -0
- package/src/cli/formatters/index.ts +18 -0
- package/src/cli/formatters/json.ts +18 -0
- package/src/cli/formatters/table.ts +26 -0
- package/src/cli/formatters/text.ts +22 -0
- package/src/cli/index.ts +61 -0
- package/src/compat/cjs.ts +11 -0
- package/src/compat/esm.ts +11 -0
- package/src/compat/index.ts +3 -0
- package/src/compat/v1.ts +35 -0
- package/src/config/defaults.ts +20 -0
- package/src/config/index.ts +24 -0
- package/src/config/schema.ts +66 -0
- package/src/constants/defaults.ts +14 -0
- package/src/constants/errors.ts +39 -0
- package/src/constants/index.ts +14 -0
- package/src/constants/signals.ts +26 -0
- package/src/constants/timeouts.ts +18 -0
- package/src/core/acquire.ts +54 -0
- package/src/core/buildLockData.ts +25 -0
- package/src/core/check.ts +66 -0
- package/src/core/cleanup.ts +53 -0
- package/src/core/handle.ts +62 -0
- package/src/core/index.ts +8 -0
- package/src/core/list.ts +38 -0
- package/src/core/release.ts +35 -0
- package/src/errors/AbortError.ts +25 -0
- package/src/errors/ConflictError.ts +28 -0
- package/src/errors/IOError.ts +39 -0
- package/src/errors/LockError.ts +39 -0
- package/src/errors/PermissionError.ts +35 -0
- package/src/errors/StaleError.ts +41 -0
- package/src/errors/TimeoutError.ts +28 -0
- package/src/errors/ValidationError.ts +28 -0
- package/src/errors/index.ts +28 -0
- package/src/events/emitter.ts +50 -0
- package/src/events/index.ts +2 -0
- package/src/events/types.ts +16 -0
- package/src/hooks/afterLock.ts +24 -0
- package/src/hooks/afterUnlock.ts +24 -0
- package/src/hooks/beforeLock.ts +28 -0
- package/src/hooks/beforeUnlock.ts +24 -0
- package/src/hooks/deps +0 -0
- package/src/hooks/index.ts +25 -0
- package/src/hooks/onError.ts +22 -0
- package/src/hooks/onStale.ts +24 -0
- package/src/hooks/onTimeout.ts +27 -0
- package/src/index.ts +25 -0
- package/src/logger/console.ts +39 -0
- package/src/logger/debug.ts +29 -0
- package/src/logger/index.ts +20 -0
- package/src/logger/noop.ts +13 -0
- package/src/meta/index.ts +2 -0
- package/src/meta/package.ts +29 -0
- package/src/meta/version.ts +26 -0
- package/src/middleware/index.ts +18 -0
- package/src/middleware/logging.ts +21 -0
- package/src/middleware/metrics.ts +44 -0
- package/src/middleware/retry.ts +25 -0
- package/src/middleware/timeout.ts +34 -0
- package/src/platform/darwin.ts +19 -0
- package/src/platform/index.ts +6 -0
- package/src/platform/linux.ts +32 -0
- package/src/platform/unix.ts +36 -0
- package/src/platform/windows.ts +26 -0
- package/src/plugins/cleanup.ts +45 -0
- package/src/plugins/heartbeat.ts +42 -0
- package/src/plugins/index.ts +7 -0
- package/src/plugins/pid.ts +26 -0
- package/src/plugins/stale.ts +33 -0
- package/src/plugins/ttl.ts +27 -0
- package/src/promise/index.ts +2 -0
- package/src/promise/lock.ts +23 -0
- package/src/promise/withLock.ts +30 -0
- package/src/registry/global.ts +39 -0
- package/src/registry/index.ts +11 -0
- package/src/registry/local.ts +37 -0
- package/src/strategies/advisory.ts +21 -0
- package/src/strategies/exclusive.ts +21 -0
- package/src/strategies/index.ts +31 -0
- package/src/strategies/optimistic.ts +29 -0
- package/src/strategies/shared.ts +23 -0
- package/src/sync/check.ts +43 -0
- package/src/sync/index.ts +3 -0
- package/src/sync/lock.ts +38 -0
- package/src/sync/unlock.ts +19 -0
- package/src/types/adapter.ts +23 -0
- package/src/types/events.ts +63 -0
- package/src/types/index.ts +24 -0
- package/src/types/lock.ts +40 -0
- package/src/types/logger.ts +23 -0
- package/src/types/options.ts +57 -0
- package/src/types/state.ts +36 -0
- package/src/types/strategy.ts +31 -0
- package/src/utils/backoff.ts +52 -0
- package/src/utils/fs.ts +93 -0
- package/src/utils/hash.ts +25 -0
- package/src/utils/hostname.ts +31 -0
- package/src/utils/index.ts +13 -0
- package/src/utils/parse.ts +43 -0
- package/src/utils/path.ts +43 -0
- package/src/utils/pid.ts +36 -0
- package/src/utils/platform.ts +45 -0
- package/src/utils/random.ts +31 -0
- package/src/utils/retry.ts +59 -0
- package/src/utils/serialize.ts +31 -0
- package/src/utils/time.ts +51 -0
- package/src/utils/validate.ts +45 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LockError } from './LockError.js';
|
|
2
|
+
import { ERROR_CODES } from '../constants/errors.js';
|
|
3
|
+
import type { LockData } from '../types/lock.js';
|
|
4
|
+
|
|
5
|
+
export class ConflictError extends LockError {
|
|
6
|
+
public override name = 'ConflictError';
|
|
7
|
+
public readonly holderData: LockData | null;
|
|
8
|
+
|
|
9
|
+
constructor(path: string, lockPath: string, holderData: LockData | null) {
|
|
10
|
+
super(
|
|
11
|
+
ERROR_CODES.LOCK_CONFLICT,
|
|
12
|
+
path,
|
|
13
|
+
lockPath,
|
|
14
|
+
holderData
|
|
15
|
+
? `Lock on "${path}" is held by PID ${holderData.pid} on ${holderData.hostname}`
|
|
16
|
+
: `Lock on "${path}" is already held`,
|
|
17
|
+
);
|
|
18
|
+
this.holderData = holderData;
|
|
19
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
override toJSON(): Record<string, unknown> {
|
|
23
|
+
return {
|
|
24
|
+
...super.toJSON(),
|
|
25
|
+
holderData: this.holderData,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { LockError } from './LockError.js';
|
|
2
|
+
import { ERROR_CODES } from '../constants/errors.js';
|
|
3
|
+
|
|
4
|
+
export class IOError extends LockError {
|
|
5
|
+
public override name = 'IOError';
|
|
6
|
+
public readonly operation: string;
|
|
7
|
+
public readonly syscall: string | undefined;
|
|
8
|
+
public readonly errno: number | undefined;
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
path: string,
|
|
12
|
+
lockPath: string,
|
|
13
|
+
operation: string,
|
|
14
|
+
cause: Error,
|
|
15
|
+
syscall?: string,
|
|
16
|
+
errno?: number,
|
|
17
|
+
) {
|
|
18
|
+
super(
|
|
19
|
+
ERROR_CODES.LOCK_IO,
|
|
20
|
+
path,
|
|
21
|
+
lockPath,
|
|
22
|
+
`I/O error during "${operation}" on "${lockPath}": ${cause.message}`,
|
|
23
|
+
cause,
|
|
24
|
+
);
|
|
25
|
+
this.operation = operation;
|
|
26
|
+
this.syscall = syscall;
|
|
27
|
+
this.errno = errno;
|
|
28
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override toJSON(): Record<string, unknown> {
|
|
32
|
+
return {
|
|
33
|
+
...super.toJSON(),
|
|
34
|
+
operation: this.operation,
|
|
35
|
+
syscall: this.syscall,
|
|
36
|
+
errno: this.errno,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ErrorCode } from '../constants/errors.js';
|
|
2
|
+
import { ERROR_MESSAGES } from '../constants/errors.js';
|
|
3
|
+
|
|
4
|
+
export class LockError extends Error {
|
|
5
|
+
public override name: string = 'LockError';
|
|
6
|
+
public readonly code: ErrorCode;
|
|
7
|
+
public readonly path: string;
|
|
8
|
+
public readonly lockPath: string;
|
|
9
|
+
public readonly timestamp: number;
|
|
10
|
+
public override readonly cause: Error | undefined;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
code: ErrorCode,
|
|
14
|
+
path: string,
|
|
15
|
+
lockPath: string,
|
|
16
|
+
message?: string,
|
|
17
|
+
cause?: Error,
|
|
18
|
+
) {
|
|
19
|
+
super(message ?? ERROR_MESSAGES[code]);
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.path = path;
|
|
22
|
+
this.lockPath = lockPath;
|
|
23
|
+
this.timestamp = Date.now();
|
|
24
|
+
this.cause = cause;
|
|
25
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
toJSON(): Record<string, unknown> {
|
|
29
|
+
return {
|
|
30
|
+
name: this.name,
|
|
31
|
+
code: this.code,
|
|
32
|
+
message: this.message,
|
|
33
|
+
path: this.path,
|
|
34
|
+
lockPath: this.lockPath,
|
|
35
|
+
timestamp: this.timestamp,
|
|
36
|
+
cause: this.cause?.message,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { LockError } from './LockError.js';
|
|
2
|
+
import { ERROR_CODES } from '../constants/errors.js';
|
|
3
|
+
|
|
4
|
+
export class PermissionError extends LockError {
|
|
5
|
+
public override name = 'PermissionError';
|
|
6
|
+
public readonly operation: string;
|
|
7
|
+
public readonly requiredMode: string;
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
path: string,
|
|
11
|
+
lockPath: string,
|
|
12
|
+
operation: string,
|
|
13
|
+
requiredMode: string,
|
|
14
|
+
cause?: Error,
|
|
15
|
+
) {
|
|
16
|
+
super(
|
|
17
|
+
ERROR_CODES.LOCK_PERMISSION,
|
|
18
|
+
path,
|
|
19
|
+
lockPath,
|
|
20
|
+
`Permission denied: cannot perform "${operation}" on "${lockPath}" (requires ${requiredMode})`,
|
|
21
|
+
cause,
|
|
22
|
+
);
|
|
23
|
+
this.operation = operation;
|
|
24
|
+
this.requiredMode = requiredMode;
|
|
25
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override toJSON(): Record<string, unknown> {
|
|
29
|
+
return {
|
|
30
|
+
...super.toJSON(),
|
|
31
|
+
operation: this.operation,
|
|
32
|
+
requiredMode: this.requiredMode,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { LockError } from './LockError.js';
|
|
2
|
+
import { ERROR_CODES } from '../constants/errors.js';
|
|
3
|
+
|
|
4
|
+
export class StaleError extends LockError {
|
|
5
|
+
public override name = 'StaleError';
|
|
6
|
+
public readonly staleAgeMs: number;
|
|
7
|
+
public readonly actualAgeMs: number;
|
|
8
|
+
public readonly stalePid: number;
|
|
9
|
+
public readonly staleHostname: string;
|
|
10
|
+
|
|
11
|
+
constructor(
|
|
12
|
+
path: string,
|
|
13
|
+
lockPath: string,
|
|
14
|
+
staleAgeMs: number,
|
|
15
|
+
actualAgeMs: number,
|
|
16
|
+
stalePid: number,
|
|
17
|
+
staleHostname: string,
|
|
18
|
+
) {
|
|
19
|
+
super(
|
|
20
|
+
ERROR_CODES.LOCK_STALE,
|
|
21
|
+
path,
|
|
22
|
+
lockPath,
|
|
23
|
+
`Lock on "${path}" is stale: held by PID ${stalePid} on ${staleHostname} for ${actualAgeMs}ms (threshold: ${staleAgeMs}ms)`,
|
|
24
|
+
);
|
|
25
|
+
this.staleAgeMs = staleAgeMs;
|
|
26
|
+
this.actualAgeMs = actualAgeMs;
|
|
27
|
+
this.stalePid = stalePid;
|
|
28
|
+
this.staleHostname = staleHostname;
|
|
29
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
override toJSON(): Record<string, unknown> {
|
|
33
|
+
return {
|
|
34
|
+
...super.toJSON(),
|
|
35
|
+
staleAgeMs: this.staleAgeMs,
|
|
36
|
+
actualAgeMs: this.actualAgeMs,
|
|
37
|
+
stalePid: this.stalePid,
|
|
38
|
+
staleHostname: this.staleHostname,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LockError } from './LockError.js';
|
|
2
|
+
import { ERROR_CODES } from '../constants/errors.js';
|
|
3
|
+
|
|
4
|
+
export class TimeoutError extends LockError {
|
|
5
|
+
public override name = 'TimeoutError';
|
|
6
|
+
public readonly timeoutMs: number;
|
|
7
|
+
public readonly attempts: number;
|
|
8
|
+
|
|
9
|
+
constructor(path: string, lockPath: string, timeoutMs: number, attempts: number) {
|
|
10
|
+
super(
|
|
11
|
+
ERROR_CODES.LOCK_TIMEOUT,
|
|
12
|
+
path,
|
|
13
|
+
lockPath,
|
|
14
|
+
`Timed out after ${timeoutMs}ms and ${attempts} attempt(s) waiting for lock on "${path}"`,
|
|
15
|
+
);
|
|
16
|
+
this.timeoutMs = timeoutMs;
|
|
17
|
+
this.attempts = attempts;
|
|
18
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
override toJSON(): Record<string, unknown> {
|
|
22
|
+
return {
|
|
23
|
+
...super.toJSON(),
|
|
24
|
+
timeoutMs: this.timeoutMs,
|
|
25
|
+
attempts: this.attempts,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LockError } from './LockError.js';
|
|
2
|
+
import { ERROR_CODES } from '../constants/errors.js';
|
|
3
|
+
|
|
4
|
+
export class ValidationError extends LockError {
|
|
5
|
+
public override name = 'ValidationError';
|
|
6
|
+
public readonly field: string;
|
|
7
|
+
public readonly received: unknown;
|
|
8
|
+
|
|
9
|
+
constructor(path: string, lockPath: string, field: string, received: unknown, reason: string) {
|
|
10
|
+
super(
|
|
11
|
+
ERROR_CODES.LOCK_VALIDATION,
|
|
12
|
+
path,
|
|
13
|
+
lockPath,
|
|
14
|
+
`Validation failed for field "${field}": ${reason} (received: ${JSON.stringify(received)})`,
|
|
15
|
+
);
|
|
16
|
+
this.field = field;
|
|
17
|
+
this.received = received;
|
|
18
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
override toJSON(): Record<string, unknown> {
|
|
22
|
+
return {
|
|
23
|
+
...super.toJSON(),
|
|
24
|
+
field: this.field,
|
|
25
|
+
received: this.received,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { LockError } from './LockError.js';
|
|
2
|
+
export { TimeoutError } from './TimeoutError.js';
|
|
3
|
+
export { StaleError } from './StaleError.js';
|
|
4
|
+
export { ConflictError } from './ConflictError.js';
|
|
5
|
+
export { ValidationError } from './ValidationError.js';
|
|
6
|
+
export { PermissionError } from './PermissionError.js';
|
|
7
|
+
export { IOError } from './IOError.js';
|
|
8
|
+
export { AbortError } from './AbortError.js';
|
|
9
|
+
|
|
10
|
+
export function isLockError(err: unknown): err is import('./LockError.js').LockError {
|
|
11
|
+
return err instanceof Error && err.name.endsWith('Error') && 'code' in err && 'lockPath' in err;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isConflictError(err: unknown): err is import('./ConflictError.js').ConflictError {
|
|
15
|
+
return err instanceof Error && err.name === 'ConflictError';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function isTimeoutError(err: unknown): err is import('./TimeoutError.js').TimeoutError {
|
|
19
|
+
return err instanceof Error && err.name === 'TimeoutError';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isStaleError(err: unknown): err is import('./StaleError.js').StaleError {
|
|
23
|
+
return err instanceof Error && err.name === 'StaleError';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isAbortError(err: unknown): err is import('./AbortError.js').AbortError {
|
|
27
|
+
return err instanceof Error && err.name === 'AbortError';
|
|
28
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AnyLockEvent, LockEventHandler, LockEventName } from '../types/events.js';
|
|
2
|
+
|
|
3
|
+
type HandlerMap = Map<LockEventName | '*', Set<LockEventHandler>>;
|
|
4
|
+
|
|
5
|
+
export class LockEventEmitter {
|
|
6
|
+
private readonly handlers: HandlerMap = new Map();
|
|
7
|
+
|
|
8
|
+
on<T extends AnyLockEvent>(event: LockEventName | '*', handler: LockEventHandler<T>): this {
|
|
9
|
+
if (!this.handlers.has(event)) {
|
|
10
|
+
this.handlers.set(event, new Set());
|
|
11
|
+
}
|
|
12
|
+
this.handlers.get(event)!.add(handler as LockEventHandler);
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
off<T extends AnyLockEvent>(event: LockEventName | '*', handler: LockEventHandler<T>): this {
|
|
17
|
+
this.handlers.get(event)?.delete(handler as LockEventHandler);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
once<T extends AnyLockEvent>(event: LockEventName | '*', handler: LockEventHandler<T>): this {
|
|
22
|
+
const wrapper: LockEventHandler = (e) => {
|
|
23
|
+
handler(e as T);
|
|
24
|
+
this.off(event, wrapper);
|
|
25
|
+
};
|
|
26
|
+
return this.on(event, wrapper);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
emit(event: AnyLockEvent): void {
|
|
30
|
+
const specific = this.handlers.get(event.name);
|
|
31
|
+
const wildcard = this.handlers.get('*');
|
|
32
|
+
specific?.forEach((h) => h(event));
|
|
33
|
+
wildcard?.forEach((h) => h(event));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
removeAllListeners(event?: LockEventName | '*'): this {
|
|
37
|
+
if (event) {
|
|
38
|
+
this.handlers.delete(event);
|
|
39
|
+
} else {
|
|
40
|
+
this.handlers.clear();
|
|
41
|
+
}
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
listenerCount(event: LockEventName | '*'): number {
|
|
46
|
+
return this.handlers.get(event)?.size ?? 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const globalEmitter = new LockEventEmitter();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type { LockEventName, LockEvent, AcquiredEvent, ReleasedEvent, StaleEvent, RetryEvent, ErrorEvent, AnyLockEvent, LockEventHandler } from '../types/events.js';
|
|
2
|
+
|
|
3
|
+
export const LOCK_EVENT_NAMES = [
|
|
4
|
+
'acquiring',
|
|
5
|
+
'acquired',
|
|
6
|
+
'releasing',
|
|
7
|
+
'released',
|
|
8
|
+
'refreshing',
|
|
9
|
+
'refreshed',
|
|
10
|
+
'stale',
|
|
11
|
+
'expired',
|
|
12
|
+
'conflict',
|
|
13
|
+
'retry',
|
|
14
|
+
'timeout',
|
|
15
|
+
'error',
|
|
16
|
+
] as const;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LockHandle } from '../types/lock.js';
|
|
2
|
+
|
|
3
|
+
export type AfterLockHook = (handle: LockHandle) => void | Promise<void>;
|
|
4
|
+
|
|
5
|
+
const afterLockHooks: AfterLockHook[] = [];
|
|
6
|
+
|
|
7
|
+
export function addAfterLockHook(hook: AfterLockHook): void {
|
|
8
|
+
afterLockHooks.push(hook);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function removeAfterLockHook(hook: AfterLockHook): void {
|
|
12
|
+
const idx = afterLockHooks.indexOf(hook);
|
|
13
|
+
if (idx !== -1) afterLockHooks.splice(idx, 1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function runAfterLockHooks(handle: LockHandle): Promise<void> {
|
|
17
|
+
for (const hook of afterLockHooks) {
|
|
18
|
+
await hook(handle);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function clearAfterLockHooks(): void {
|
|
23
|
+
afterLockHooks.length = 0;
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LockHandle } from '../types/lock.js';
|
|
2
|
+
|
|
3
|
+
export type AfterUnlockHook = (handle: LockHandle) => void | Promise<void>;
|
|
4
|
+
|
|
5
|
+
const afterUnlockHooks: AfterUnlockHook[] = [];
|
|
6
|
+
|
|
7
|
+
export function addAfterUnlockHook(hook: AfterUnlockHook): void {
|
|
8
|
+
afterUnlockHooks.push(hook);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function removeAfterUnlockHook(hook: AfterUnlockHook): void {
|
|
12
|
+
const idx = afterUnlockHooks.indexOf(hook);
|
|
13
|
+
if (idx !== -1) afterUnlockHooks.splice(idx, 1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function runAfterUnlockHooks(handle: LockHandle): Promise<void> {
|
|
17
|
+
for (const hook of afterUnlockHooks) {
|
|
18
|
+
await hook(handle);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function clearAfterUnlockHooks(): void {
|
|
23
|
+
afterUnlockHooks.length = 0;
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AcquireOptions } from '../types/options.js';
|
|
2
|
+
|
|
3
|
+
export type BeforeLockHook = (path: string, lockPath: string, options: AcquireOptions) => void | Promise<void>;
|
|
4
|
+
|
|
5
|
+
const beforeLockHooks: BeforeLockHook[] = [];
|
|
6
|
+
|
|
7
|
+
export function addBeforeLockHook(hook: BeforeLockHook): void {
|
|
8
|
+
beforeLockHooks.push(hook);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function removeBeforeLockHook(hook: BeforeLockHook): void {
|
|
12
|
+
const idx = beforeLockHooks.indexOf(hook);
|
|
13
|
+
if (idx !== -1) beforeLockHooks.splice(idx, 1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function runBeforeLockHooks(
|
|
17
|
+
path: string,
|
|
18
|
+
lockPath: string,
|
|
19
|
+
options: AcquireOptions,
|
|
20
|
+
): Promise<void> {
|
|
21
|
+
for (const hook of beforeLockHooks) {
|
|
22
|
+
await hook(path, lockPath, options);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function clearBeforeLockHooks(): void {
|
|
27
|
+
beforeLockHooks.length = 0;
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LockHandle } from '../types/lock.js';
|
|
2
|
+
|
|
3
|
+
export type BeforeUnlockHook = (handle: LockHandle) => void | Promise<void>;
|
|
4
|
+
|
|
5
|
+
const beforeUnlockHooks: BeforeUnlockHook[] = [];
|
|
6
|
+
|
|
7
|
+
export function addBeforeUnlockHook(hook: BeforeUnlockHook): void {
|
|
8
|
+
beforeUnlockHooks.push(hook);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function removeBeforeUnlockHook(hook: BeforeUnlockHook): void {
|
|
12
|
+
const idx = beforeUnlockHooks.indexOf(hook);
|
|
13
|
+
if (idx !== -1) beforeUnlockHooks.splice(idx, 1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function runBeforeUnlockHooks(handle: LockHandle): Promise<void> {
|
|
17
|
+
for (const hook of beforeUnlockHooks) {
|
|
18
|
+
await hook(handle);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function clearBeforeUnlockHooks(): void {
|
|
23
|
+
beforeUnlockHooks.length = 0;
|
|
24
|
+
}
|
package/src/hooks/deps
ADDED
|
Binary file
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './beforeLock.js';
|
|
2
|
+
export * from './afterLock.js';
|
|
3
|
+
export * from './beforeUnlock.js';
|
|
4
|
+
export * from './afterUnlock.js';
|
|
5
|
+
export * from './onError.js';
|
|
6
|
+
export * from './onStale.js';
|
|
7
|
+
export * from './onTimeout.js';
|
|
8
|
+
|
|
9
|
+
import { clearBeforeLockHooks } from './beforeLock.js';
|
|
10
|
+
import { clearAfterLockHooks } from './afterLock.js';
|
|
11
|
+
import { clearBeforeUnlockHooks } from './beforeUnlock.js';
|
|
12
|
+
import { clearAfterUnlockHooks } from './afterUnlock.js';
|
|
13
|
+
import { clearOnErrorHooks } from './onError.js';
|
|
14
|
+
import { clearOnStaleHooks } from './onStale.js';
|
|
15
|
+
import { clearOnTimeoutHooks } from './onTimeout.js';
|
|
16
|
+
|
|
17
|
+
export function clearAllHooks(): void {
|
|
18
|
+
clearBeforeLockHooks();
|
|
19
|
+
clearAfterLockHooks();
|
|
20
|
+
clearBeforeUnlockHooks();
|
|
21
|
+
clearAfterUnlockHooks();
|
|
22
|
+
clearOnErrorHooks();
|
|
23
|
+
clearOnStaleHooks();
|
|
24
|
+
clearOnTimeoutHooks();
|
|
25
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type OnErrorHook = (error: Error, path: string, lockPath: string) => void | Promise<void>;
|
|
2
|
+
|
|
3
|
+
const onErrorHooks: OnErrorHook[] = [];
|
|
4
|
+
|
|
5
|
+
export function addOnErrorHook(hook: OnErrorHook): void {
|
|
6
|
+
onErrorHooks.push(hook);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function removeOnErrorHook(hook: OnErrorHook): void {
|
|
10
|
+
const idx = onErrorHooks.indexOf(hook);
|
|
11
|
+
if (idx !== -1) onErrorHooks.splice(idx, 1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function runOnErrorHooks(error: Error, path: string, lockPath: string): Promise<void> {
|
|
15
|
+
for (const hook of onErrorHooks) {
|
|
16
|
+
await hook(error, path, lockPath);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function clearOnErrorHooks(): void {
|
|
21
|
+
onErrorHooks.length = 0;
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LockData } from '../types/lock.js';
|
|
2
|
+
|
|
3
|
+
export type OnStaleHook = (lockPath: string, data: LockData, ageMs: number) => void | Promise<void>;
|
|
4
|
+
|
|
5
|
+
const onStaleHooks: OnStaleHook[] = [];
|
|
6
|
+
|
|
7
|
+
export function addOnStaleHook(hook: OnStaleHook): void {
|
|
8
|
+
onStaleHooks.push(hook);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function removeOnStaleHook(hook: OnStaleHook): void {
|
|
12
|
+
const idx = onStaleHooks.indexOf(hook);
|
|
13
|
+
if (idx !== -1) onStaleHooks.splice(idx, 1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function runOnStaleHooks(lockPath: string, data: LockData, ageMs: number): Promise<void> {
|
|
17
|
+
for (const hook of onStaleHooks) {
|
|
18
|
+
await hook(lockPath, data, ageMs);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function clearOnStaleHooks(): void {
|
|
23
|
+
onStaleHooks.length = 0;
|
|
24
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type OnTimeoutHook = (path: string, lockPath: string, timeoutMs: number, attempts: number) => void | Promise<void>;
|
|
2
|
+
|
|
3
|
+
const onTimeoutHooks: OnTimeoutHook[] = [];
|
|
4
|
+
|
|
5
|
+
export function addOnTimeoutHook(hook: OnTimeoutHook): void {
|
|
6
|
+
onTimeoutHooks.push(hook);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function removeOnTimeoutHook(hook: OnTimeoutHook): void {
|
|
10
|
+
const idx = onTimeoutHooks.indexOf(hook);
|
|
11
|
+
if (idx !== -1) onTimeoutHooks.splice(idx, 1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function runOnTimeoutHooks(
|
|
15
|
+
path: string,
|
|
16
|
+
lockPath: string,
|
|
17
|
+
timeoutMs: number,
|
|
18
|
+
attempts: number,
|
|
19
|
+
): Promise<void> {
|
|
20
|
+
for (const hook of onTimeoutHooks) {
|
|
21
|
+
await hook(path, lockPath, timeoutMs, attempts);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function clearOnTimeoutHooks(): void {
|
|
26
|
+
onTimeoutHooks.length = 0;
|
|
27
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './types/index.js';
|
|
2
|
+
export * from './errors/index.js';
|
|
3
|
+
export * from './constants/index.js';
|
|
4
|
+
|
|
5
|
+
export { acquireLock, isLocked, getLockState, checkLock, listLocks, cleanupLocks } from './core/index.js';
|
|
6
|
+
export type { CleanupResult } from './core/index.js';
|
|
7
|
+
|
|
8
|
+
export { withLock, withLockResult } from './promise/withLock.js';
|
|
9
|
+
export { lock, tryLock, lockWithTimeout } from './promise/lock.js';
|
|
10
|
+
|
|
11
|
+
export { lockSync, tryLockSync } from './sync/lock.js';
|
|
12
|
+
export { unlockSync, forceUnlockSync } from './sync/unlock.js';
|
|
13
|
+
export { checkSync, isLockedSync } from './sync/check.js';
|
|
14
|
+
|
|
15
|
+
export * from './adapters/index.js';
|
|
16
|
+
export * from './strategies/index.js';
|
|
17
|
+
export * from './middleware/index.js';
|
|
18
|
+
export * from './plugins/index.js';
|
|
19
|
+
export * from './events/index.js';
|
|
20
|
+
export * from './hooks/index.js';
|
|
21
|
+
export * from './logger/index.js';
|
|
22
|
+
export * from './config/index.js';
|
|
23
|
+
export * from './meta/index.js';
|
|
24
|
+
export * from './registry/index.js';
|
|
25
|
+
export * from './platform/index.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Logger, LogLevel } from '../types/logger.js';
|
|
2
|
+
|
|
3
|
+
const LOG_LEVEL_MAP: Record<LogLevel, number> = {
|
|
4
|
+
silent: 0,
|
|
5
|
+
error: 1,
|
|
6
|
+
warn: 2,
|
|
7
|
+
info: 3,
|
|
8
|
+
debug: 4,
|
|
9
|
+
trace: 5,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function createConsoleLogger(level: LogLevel = 'info', prefix = '[atomic-lockfile]'): Logger {
|
|
13
|
+
let currentLevel = level;
|
|
14
|
+
const shouldLog = (l: LogLevel): boolean => LOG_LEVEL_MAP[l] <= LOG_LEVEL_MAP[currentLevel];
|
|
15
|
+
|
|
16
|
+
const log = (l: LogLevel, message: string, context?: Record<string, unknown>): void => {
|
|
17
|
+
if (!shouldLog(l)) return;
|
|
18
|
+
const ts = new Date().toISOString();
|
|
19
|
+
const line = `${ts} ${prefix} [${l.toUpperCase()}] ${message}`;
|
|
20
|
+
const output = context ? `${line} ${JSON.stringify(context)}` : line;
|
|
21
|
+
if (l === 'error') console.error(output);
|
|
22
|
+
else if (l === 'warn') console.warn(output);
|
|
23
|
+
else console.log(output);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const logger: Logger = {
|
|
27
|
+
silent: (m, c) => log('silent', m, c),
|
|
28
|
+
error: (m, c) => log('error', m, c),
|
|
29
|
+
warn: (m, c) => log('warn', m, c),
|
|
30
|
+
info: (m, c) => log('info', m, c),
|
|
31
|
+
debug: (m, c) => log('debug', m, c),
|
|
32
|
+
trace: (m, c) => log('trace', m, c),
|
|
33
|
+
child: (ctx) => createConsoleLogger(currentLevel, `${prefix}[${JSON.stringify(ctx)}]`),
|
|
34
|
+
setLevel: (l) => { currentLevel = l; },
|
|
35
|
+
getLevel: () => currentLevel,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return logger;
|
|
39
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Logger, LogLevel } from '../types/logger.js';
|
|
2
|
+
|
|
3
|
+
const NAMESPACE = 'atomic-lockfile';
|
|
4
|
+
|
|
5
|
+
export function createDebugLogger(namespace = NAMESPACE): Logger {
|
|
6
|
+
const isEnabled = (): boolean => {
|
|
7
|
+
const debug = process.env['DEBUG'] ?? '';
|
|
8
|
+
return debug === '*' || debug.split(',').some((ns: string) => ns.trim() === namespace || ns.trim() === `${namespace}:*`);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const log = (level: LogLevel, message: string, context?: Record<string, unknown>): void => {
|
|
12
|
+
if (!isEnabled()) return;
|
|
13
|
+
const prefix = `${namespace}:${level}`;
|
|
14
|
+
const ts = Date.now();
|
|
15
|
+
process.stderr.write(` ${prefix} +${ts} ${message}${context ? ' ' + JSON.stringify(context) : ''}\n`);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
silent: (m, c) => log('silent', m, c),
|
|
20
|
+
error: (m, c) => log('error', m, c),
|
|
21
|
+
warn: (m, c) => log('warn', m, c),
|
|
22
|
+
info: (m, c) => log('info', m, c),
|
|
23
|
+
debug: (m, c) => log('debug', m, c),
|
|
24
|
+
trace: (m, c) => log('trace', m, c),
|
|
25
|
+
child: (ctx) => createDebugLogger(`${namespace}:${Object.values(ctx).join(':')}`),
|
|
26
|
+
setLevel: () => undefined,
|
|
27
|
+
getLevel: (): LogLevel => 'debug',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { noopLogger } from './noop.js';
|
|
2
|
+
export { createConsoleLogger } from './console.js';
|
|
3
|
+
export { createDebugLogger } from './debug.js';
|
|
4
|
+
|
|
5
|
+
import { noopLogger } from './noop.js';
|
|
6
|
+
import type { Logger } from '../types/logger.js';
|
|
7
|
+
|
|
8
|
+
let globalLogger: Logger = noopLogger;
|
|
9
|
+
|
|
10
|
+
export function getLogger(): Logger {
|
|
11
|
+
return globalLogger;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function setLogger(logger: Logger): void {
|
|
15
|
+
globalLogger = logger;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function resetLogger(): void {
|
|
19
|
+
globalLogger = noopLogger;
|
|
20
|
+
}
|