@oada/list-lib
Advanced tools
Comparing version 5.0.1 to 5.0.2
@@ -57,4 +57,8 @@ /** | ||
* The unique name of this service/watch | ||
*/ | ||
*/ | ||
readonly name: string; | ||
/** | ||
* The unique name of this service/watch | ||
*/ | ||
readonly timeout: number | undefined; | ||
constructor(options: Options<Item>); | ||
@@ -61,0 +65,0 @@ /** |
@@ -48,3 +48,3 @@ /** | ||
export class ListWatch { | ||
constructor({ path, itemsPath = '$[?(!@property.match(/^_/))]', tree = { '*': { _type: 'application/json' } }, name = process.env.npm_package_name, resume = true, conn, persistInterval = 1000, | ||
constructor({ path, itemsPath = '$[?(!@property.match(/^_/))]', tree = { '*': { _type: 'application/json' } }, name = process.env.npm_package_name, resume = true, conn, persistInterval = 1000, timeout, | ||
// If no assert given, assume all items valid | ||
@@ -63,2 +63,3 @@ // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
this.name = name; | ||
this.timeout = timeout; | ||
__classPrivateFieldSet(this, _ListWatch_conn, conn, "f"); | ||
@@ -92,3 +93,3 @@ __classPrivateFieldSet(this, _ListWatch_assertItem, assertItem, "f"); | ||
: undefined, "f"); | ||
__classPrivateFieldSet(this, _ListWatch_watch, __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_initialize).call(this, onNewList), "f"); | ||
__classPrivateFieldSet(this, _ListWatch_watch, __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_initialize).call(this, onNewList, timeout), "f"); | ||
} | ||
@@ -127,3 +128,3 @@ /** | ||
*/ | ||
async function _ListWatch_getItem(itemEvent) { | ||
async function _ListWatch_getItem(itemEvent, timeout) { | ||
// Needed because TS is weird about asserts... | ||
@@ -133,2 +134,3 @@ const assertItem = __classPrivateFieldGet(this, _ListWatch_assertItem, "f"); | ||
path: join(this.path, itemEvent.pointer), | ||
timeout | ||
}); | ||
@@ -226,3 +228,3 @@ assertItem(item); | ||
*/ | ||
async function _ListWatch_initialize(assume = AssumeState.New) { | ||
async function _ListWatch_initialize(assume = AssumeState.New, timeout) { | ||
const { path } = this; | ||
@@ -232,3 +234,3 @@ const conn = __classPrivateFieldGet(this, _ListWatch_conn, "f"); | ||
try { | ||
await conn.head({ path }); | ||
await conn.head({ path, timeout }); | ||
} | ||
@@ -239,3 +241,3 @@ catch (error) { | ||
// Create it | ||
await conn.put({ path, data: {} }); | ||
await conn.put({ path, data: {}, timeout }); | ||
log.trace('Created %s because it did not exist', path); | ||
@@ -255,2 +257,3 @@ } | ||
type: 'tree', | ||
timeout, | ||
}); | ||
@@ -263,3 +266,3 @@ if (!foundMeta) { | ||
case AssumeState.New: { | ||
await __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_handleStartingItems).call(this); | ||
await __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_handleStartingItems).call(this, timeout); | ||
break; | ||
@@ -284,5 +287,5 @@ } | ||
*/ | ||
async function _ListWatch_handleStartingItems() { | ||
async function _ListWatch_handleStartingItems(timeout) { | ||
const { path, tree, itemsPath } = this; | ||
const { data: json } = await __classPrivateFieldGet(this, _ListWatch_conn, "f").get({ path, tree }); | ||
const { data: json } = await __classPrivateFieldGet(this, _ListWatch_conn, "f").get({ path, tree, timeout }); | ||
if (typeof json !== 'object' || | ||
@@ -289,0 +292,0 @@ json === null || |
@@ -84,2 +84,6 @@ /** | ||
onNewList?: AssumeState; | ||
/** | ||
* Timeout for the watches created in OADAClient | ||
*/ | ||
timeout?: number; | ||
} | ||
@@ -86,0 +90,0 @@ /** |
{ | ||
"name": "@oada/list-lib", | ||
"version": "5.0.1", | ||
"version": "5.0.2", | ||
"description": "Library for processing items in an OADA list", | ||
@@ -128,3 +128,3 @@ "main": "dist/index.js", | ||
}, | ||
"packageManager": "yarn@4.1.0", | ||
"packageManager": "yarn@4.1.1", | ||
"volta": { | ||
@@ -131,0 +131,0 @@ "node": "20.11.0" |
@@ -94,4 +94,8 @@ /** | ||
* The unique name of this service/watch | ||
*/ | ||
*/ | ||
readonly name; | ||
/** | ||
* The unique name of this service/watch | ||
*/ | ||
readonly timeout; | ||
@@ -120,2 +124,3 @@ readonly #conn; | ||
persistInterval = 1000, | ||
timeout, | ||
// If no assert given, assume all items valid | ||
@@ -134,2 +139,3 @@ // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
this.name = name; | ||
this.timeout = timeout; | ||
this.#conn = conn; | ||
@@ -193,3 +199,3 @@ this.#assertItem = assertItem; | ||
: undefined; | ||
this.#watch = this.#initialize(onNewList); | ||
this.#watch = this.#initialize(onNewList, timeout); | ||
} | ||
@@ -247,3 +253,3 @@ | ||
*/ | ||
async #getItem(itemEvent: ItemEvent<Item>): Promise<Item> { | ||
async #getItem(itemEvent: ItemEvent<Item>, timeout?: number): Promise<Item> { | ||
// Needed because TS is weird about asserts... | ||
@@ -253,2 +259,3 @@ const assertItem: TypeAssert<Item> = this.#assertItem; | ||
path: join(this.path, itemEvent.pointer), | ||
timeout | ||
}); | ||
@@ -375,3 +382,3 @@ assertItem(item); | ||
*/ | ||
async #initialize(assume: AssumeState = AssumeState.New) { | ||
async #initialize(assume: AssumeState = AssumeState.New, timeout?: number) { | ||
const { path } = this; | ||
@@ -382,3 +389,3 @@ const conn = this.#conn; | ||
try { | ||
await conn.head({ path }); | ||
await conn.head({ path, timeout}); | ||
} catch (error: unknown) { | ||
@@ -388,3 +395,3 @@ // @ts-expect-error darn errors | ||
// Create it | ||
await conn.put({ path, data: {} }); | ||
await conn.put({ path, data: {}, timeout }); | ||
log.trace('Created %s because it did not exist', path); | ||
@@ -405,2 +412,3 @@ } else { | ||
type: 'tree', | ||
timeout, | ||
}); | ||
@@ -415,3 +423,3 @@ | ||
case AssumeState.New: { | ||
await this.#handleStartingItems(); | ||
await this.#handleStartingItems(timeout); | ||
break; | ||
@@ -441,5 +449,5 @@ } | ||
*/ | ||
async #handleStartingItems() { | ||
async #handleStartingItems(timeout?: number) { | ||
const { path, tree, itemsPath } = this; | ||
const { data: json } = await this.#conn.get({ path, tree }); | ||
const { data: json } = await this.#conn.get({ path, tree, timeout }); | ||
if ( | ||
@@ -460,3 +468,3 @@ typeof json !== 'object' || | ||
}); | ||
const listRev = Number(json._rev); | ||
const listRev = Number((json as unknown as {_rev: number})._rev); | ||
for await (const { value, pointer } of items) { | ||
@@ -463,0 +471,0 @@ const itemChange = { |
@@ -96,2 +96,7 @@ /** | ||
onNewList?: AssumeState; | ||
/** | ||
* Timeout for the watches created in OADAClient | ||
*/ | ||
timeout?: number; | ||
} | ||
@@ -98,0 +103,0 @@ |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
117214
35
2345
2