@wixc3/patterns
Advanced tools
Comparing version 15.1.0 to 15.1.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Disposables = exports.createDisposables = exports.DEFAULT_TIMEOUT = exports.DEFAULT_GROUP = void 0; | ||
const common_1 = require("@wixc3/common"); | ||
const constraints_1 = require("./constraints"); | ||
@@ -99,3 +98,3 @@ const disposables_group_1 = require("./disposables-group"); | ||
} | ||
group.disposables.add(dispose, timeout, `[${this.name}]: ${name}`, (0, common_1.getStackTrace)({ skipLines: 3 })); | ||
group.disposables.add(dispose, timeout, `[${this.name}]: ${name}`); | ||
return () => group.disposables.remove(dispose); | ||
@@ -102,0 +101,0 @@ } |
@@ -8,3 +8,3 @@ /** | ||
dispose(): Promise<void>; | ||
add(disposable: DisposableItem, timeout: number, name: string, trace: string): () => boolean; | ||
add(disposable: DisposableItem, timeout: number, name: string): () => boolean; | ||
remove(target: DisposableItem): void; | ||
@@ -23,4 +23,3 @@ list(): { | ||
name: string; | ||
trace: string; | ||
}; | ||
//# sourceMappingURL=disposables-group.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DisposablesGroup = void 0; | ||
const common_1 = require("@wixc3/common"); | ||
const promise_assist_1 = require("promise-assist"); | ||
@@ -23,15 +22,15 @@ /** | ||
if (e.message === message(details)) { | ||
throw (0, common_1.errorWithTrace)(message(details), details.trace); | ||
throw e; | ||
} | ||
throw (0, common_1.errorWithTrace)(`Disposal failed: "${details.name}"`, details.trace, { | ||
cause: e, | ||
}); | ||
else { | ||
throw new Error(`Disposal failed: "${details.name}"`, { cause: e }); | ||
} | ||
} | ||
} | ||
} | ||
add(disposable, timeout, name, trace) { | ||
add(disposable, timeout, name) { | ||
if (this.disposables.has(disposable)) { | ||
throw new Error(`Disposable already added`); | ||
} | ||
this.disposables.set(disposable, { timeout, name, trace }); | ||
this.disposables.set(disposable, { timeout, name }); | ||
return () => this.disposables.delete(disposable); | ||
@@ -38,0 +37,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SafeDisposable = void 0; | ||
const common_1 = require("@wixc3/common"); | ||
const _1 = require("."); | ||
@@ -86,3 +85,3 @@ const promise_assist_1 = require("promise-assist"); | ||
if (this.isDisposed && !(this._isDisposing && usedWhileDisposing)) { | ||
throw (0, common_1.errorWithTrace)('Instance was disposed', (0, common_1.getStackTrace)()); | ||
throw new Error('Instance was disposed'); | ||
} | ||
@@ -89,0 +88,0 @@ const { promise: canDispose, resolve: done } = (0, promise_assist_1.deferred)(); |
@@ -1,2 +0,1 @@ | ||
import { getStackTrace } from '@wixc3/common'; | ||
import { getGroupConstrainedIndex, normalizeConstraints } from './constraints'; | ||
@@ -95,3 +94,3 @@ import { DisposablesGroup } from './disposables-group'; | ||
} | ||
group.disposables.add(dispose, timeout, `[${this.name}]: ${name}`, getStackTrace({ skipLines: 3 })); | ||
group.disposables.add(dispose, timeout, `[${this.name}]: ${name}`); | ||
return () => group.disposables.remove(dispose); | ||
@@ -98,0 +97,0 @@ } |
@@ -8,3 +8,3 @@ /** | ||
dispose(): Promise<void>; | ||
add(disposable: DisposableItem, timeout: number, name: string, trace: string): () => boolean; | ||
add(disposable: DisposableItem, timeout: number, name: string): () => boolean; | ||
remove(target: DisposableItem): void; | ||
@@ -23,4 +23,3 @@ list(): { | ||
name: string; | ||
trace: string; | ||
}; | ||
//# sourceMappingURL=disposables-group.d.ts.map |
@@ -1,2 +0,1 @@ | ||
import { errorWithTrace } from '@wixc3/common'; | ||
import { timeout } from 'promise-assist'; | ||
@@ -20,15 +19,15 @@ /** | ||
if (e.message === message(details)) { | ||
throw errorWithTrace(message(details), details.trace); | ||
throw e; | ||
} | ||
throw errorWithTrace(`Disposal failed: "${details.name}"`, details.trace, { | ||
cause: e, | ||
}); | ||
else { | ||
throw new Error(`Disposal failed: "${details.name}"`, { cause: e }); | ||
} | ||
} | ||
} | ||
} | ||
add(disposable, timeout, name, trace) { | ||
add(disposable, timeout, name) { | ||
if (this.disposables.has(disposable)) { | ||
throw new Error(`Disposable already added`); | ||
} | ||
this.disposables.set(disposable, { timeout, name, trace }); | ||
this.disposables.set(disposable, { timeout, name }); | ||
return () => this.disposables.delete(disposable); | ||
@@ -35,0 +34,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import { errorWithTrace, getStackTrace } from '@wixc3/common'; | ||
import { Disposables } from '.'; | ||
@@ -83,3 +82,3 @@ import { deferred } from 'promise-assist'; | ||
if (this.isDisposed && !(this._isDisposing && usedWhileDisposing)) { | ||
throw errorWithTrace('Instance was disposed', getStackTrace()); | ||
throw new Error('Instance was disposed'); | ||
} | ||
@@ -86,0 +85,0 @@ const { promise: canDispose, resolve: done } = deferred(); |
{ | ||
"name": "@wixc3/patterns", | ||
"version": "15.1.0", | ||
"version": "15.1.1", | ||
"description": "A utility for saving objects to be disposed", | ||
@@ -21,5 +21,5 @@ "main": "dist/cjs/index.js", | ||
"dependencies": { | ||
"@wixc3/common": "^15.1.0", | ||
"@wixc3/common": "^15.1.1", | ||
"promise-assist": "^2.0.1" | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
import { getStackTrace } from '@wixc3/common'; | ||
import { DisposalGroup, getGroupConstrainedIndex, GroupConstraints, normalizeConstraints } from './constraints'; | ||
@@ -132,3 +131,3 @@ import { DisposableItem, DisposablesGroup } from './disposables-group'; | ||
group.disposables.add(dispose, timeout, `[${this.name}]: ${name}`, getStackTrace({ skipLines: 3 })); | ||
group.disposables.add(dispose, timeout, `[${this.name}]: ${name}`); | ||
return () => group.disposables.remove(dispose); | ||
@@ -135,0 +134,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import { errorWithTrace } from '@wixc3/common'; | ||
import { timeout } from 'promise-assist'; | ||
@@ -18,7 +17,6 @@ | ||
if ((e as Error).message === message(details)) { | ||
throw errorWithTrace(message(details), details.trace); | ||
throw e; | ||
} else { | ||
throw new Error(`Disposal failed: "${details.name}"`, { cause: e }); | ||
} | ||
throw errorWithTrace(`Disposal failed: "${details.name}"`, details.trace, { | ||
cause: e, | ||
}); | ||
} | ||
@@ -28,7 +26,7 @@ } | ||
add(disposable: DisposableItem, timeout: number, name: string, trace: string) { | ||
add(disposable: DisposableItem, timeout: number, name: string) { | ||
if (this.disposables.has(disposable)) { | ||
throw new Error(`Disposable already added`); | ||
} | ||
this.disposables.set(disposable, { timeout, name, trace }); | ||
this.disposables.set(disposable, { timeout, name }); | ||
return () => this.disposables.delete(disposable); | ||
@@ -52,3 +50,2 @@ } | ||
name: string; | ||
trace: string; | ||
}; | ||
@@ -55,0 +52,0 @@ |
@@ -1,2 +0,1 @@ | ||
import { errorWithTrace, getStackTrace } from '@wixc3/common'; | ||
import { Disposables } from '.'; | ||
@@ -125,3 +124,3 @@ import { deferred } from 'promise-assist'; | ||
if (this.isDisposed && !(this._isDisposing && usedWhileDisposing)) { | ||
throw errorWithTrace('Instance was disposed', getStackTrace()); | ||
throw new Error('Instance was disposed'); | ||
} | ||
@@ -128,0 +127,0 @@ const { promise: canDispose, resolve: done } = deferred(); |
@@ -53,4 +53,3 @@ import { expect, use } from 'chai'; | ||
name: 'disposing with error', | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
dispose: async () => { | ||
dispose: () => { | ||
throw new Error('failed!'); | ||
@@ -60,15 +59,16 @@ }, | ||
let error: Error | undefined = undefined; | ||
try { | ||
await disposables.dispose(); | ||
} catch (e) { | ||
const { message, stack, cause } = e as Error; | ||
expect(message, 'message').to.equal('Disposal failed: "[test]: disposing with error"'); | ||
expect((cause as Error).message, 'cause').to.equal('failed!'); | ||
const [_, disposeFn, mocha] = stack?.split('\n') ?? []; | ||
expect(disposeFn, 'dispose fn').to.match(/at Context\.<anonymous>.*disposables\.unit\.ts:\d+:\d+/); | ||
expect(mocha, 'mocha').to.match(/at Context\.runnable\.fn/); | ||
return; | ||
error = e as Error; | ||
} | ||
if (!error) { | ||
throw new Error('expected error'); | ||
} | ||
throw new Error('Expected error to be throws'); | ||
expect(error).to.be.instanceOf(Error); | ||
expect(error.message).to.eql('Disposal failed: "[test]: disposing with error"'); | ||
expect(error.cause).to.be.instanceOf(Error); | ||
expect((error.cause as Error).message).to.eql('failed!'); | ||
}); | ||
@@ -101,3 +101,3 @@ }); | ||
expect(() => groups.registerGroup('group1', { before: 'group2' })).to.throw( | ||
`Invalid constraint: "before: group2" - group not found`, | ||
`Invalid constraint: "before: group2" - group not found` | ||
); | ||
@@ -108,3 +108,3 @@ }); | ||
expect(() => groups.registerGroup('group1', [])).to.throw( | ||
`Invalid disposal group: must have at least one constraint`, | ||
`Invalid disposal group: must have at least one constraint` | ||
); | ||
@@ -118,3 +118,3 @@ }); | ||
expect(() => groups.registerGroup('invalid', { before: 'before', after: 'after' })).to.throw( | ||
'Invalid constraints: after runs after before, which contradicts prior constraints', | ||
'Invalid constraints: after runs after before, which contradicts prior constraints' | ||
); | ||
@@ -125,3 +125,3 @@ }); | ||
expect(() => groups.registerGroup('default', { before: 'default' })).to.throw( | ||
`Invalid group: "default" already exists`, | ||
`Invalid group: "default" already exists` | ||
); | ||
@@ -128,0 +128,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
257029
4972
Updated@wixc3/common@^15.1.1