@oada/list-lib
Advanced tools
Comparing version 2.2.0 to 3.0.0
@@ -18,3 +18,3 @@ /** | ||
import type { Link } from '@oada/types/oada/link/v1'; | ||
import type { Resource } from '@oada/types/oada/resource'; | ||
import type Resource from '@oada/types/oada/resource'; | ||
import type V2Changes from '@oada/types/oada/change/v2'; | ||
@@ -21,0 +21,0 @@ import { ItemState, Options } from './Options'; |
222
lib/index.js
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -19,15 +18,13 @@ * @license | ||
var _ListWatch_instances, _ListWatch_resume, _ListWatch_conn, _ListWatch_watch, _ListWatch_assertItem, _ListWatch_meta, _ListWatch_onAddItem, _ListWatch_onChangeItem, _ListWatch_onItem, _ListWatch_onRemoveItem, _ListWatch_onNewList, _ListWatch_onDeleteList, _ListWatch_getItemState, _ListWatch_handleItemState, _ListWatch_handleNewItem, _ListWatch_handleItemChange, _ListWatch_handleListChange, _ListWatch_updateItemState, _ListWatch_initialize, _ListWatch_handleChangeFeed; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ItemState = exports.ListWatch = exports.pathFromTree = void 0; | ||
const tslib_1 = require("tslib"); | ||
const node_path_1 = require("node:path"); | ||
const jsonpath_plus_1 = require("jsonpath-plus"); | ||
const debug_1 = (0, tslib_1.__importDefault)(require("debug")); | ||
const json_pointer_1 = (0, tslib_1.__importDefault)(require("json-pointer")); | ||
const Options_1 = require("./Options"); | ||
const Metadata_1 = require("./Metadata"); | ||
const info = (0, debug_1.default)('oada-list-lib:info'); | ||
const warn = (0, debug_1.default)('oada-list-lib:warn'); | ||
const trace = (0, debug_1.default)('oada-list-lib:trace'); | ||
const error = (0, debug_1.default)('oada-list-lib:error'); | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { join } from 'node:path'; | ||
import { JSONPath } from 'jsonpath-plus'; | ||
import debug from 'debug'; | ||
import pointer from 'json-pointer'; | ||
import { ItemState } from './Options'; | ||
import { Metadata } from './Metadata'; | ||
const info = debug('oada-list-lib:info'); | ||
const warn = debug('oada-list-lib:warn'); | ||
const trace = debug('oada-list-lib:trace'); | ||
const error = debug('oada-list-lib:error'); | ||
/** | ||
@@ -37,3 +34,3 @@ * Tell TS we should never reach here (i.e., this should never be called) | ||
function assertNever(value, message) { | ||
throw new Error(message !== null && message !== void 0 ? message : `Bad value: ${value}`); | ||
throw new Error(message ?? `Bad value: ${value}`); | ||
} | ||
@@ -57,3 +54,3 @@ /** | ||
// eslint-disable-next-line new-cap | ||
return (0, jsonpath_plus_1.JSONPath)({ | ||
return JSONPath({ | ||
resultType: 'pointer', | ||
@@ -73,6 +70,6 @@ path, | ||
*/ | ||
function pathFromTree(tree, root = '') { | ||
export function pathFromTree(tree, root = '') { | ||
let path = '$.*'; | ||
let outPath = '$'; | ||
const json = json_pointer_1.default.get(tree, root); | ||
const json = pointer.get(tree, root); | ||
// eslint-disable-next-line no-constant-condition | ||
@@ -83,3 +80,3 @@ while (true) { | ||
// eslint-disable-next-line new-cap | ||
(0, jsonpath_plus_1.JSONPath)({ | ||
JSONPath({ | ||
resultType: 'parentProperty', | ||
@@ -98,3 +95,2 @@ path, | ||
} | ||
exports.pathFromTree = pathFromTree; | ||
/** | ||
@@ -108,3 +104,3 @@ * The main class of this library. | ||
*/ | ||
class ListWatch { | ||
export class ListWatch { | ||
constructor({ path, itemsPath, tree, name, resume = false, conn, | ||
@@ -139,11 +135,11 @@ // If no assert given, assume all items valid | ||
this.name = name; | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_resume, resume, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_conn, conn, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_assertItem, assertItem, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_onAddItem, onAddItem, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_onChangeItem, onChangeItem, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_onItem, onItem, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_onRemoveItem, onRemoveItem, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_onDeleteList, onDeleteList, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_getItemState, getItemState, "f"); | ||
__classPrivateFieldSet(this, _ListWatch_resume, resume, "f"); | ||
__classPrivateFieldSet(this, _ListWatch_conn, conn, "f"); | ||
__classPrivateFieldSet(this, _ListWatch_assertItem, assertItem, "f"); | ||
__classPrivateFieldSet(this, _ListWatch_onAddItem, onAddItem, "f"); | ||
__classPrivateFieldSet(this, _ListWatch_onChangeItem, onChangeItem, "f"); | ||
__classPrivateFieldSet(this, _ListWatch_onItem, onItem, "f"); | ||
__classPrivateFieldSet(this, _ListWatch_onRemoveItem, onRemoveItem, "f"); | ||
__classPrivateFieldSet(this, _ListWatch_onDeleteList, onDeleteList, "f"); | ||
__classPrivateFieldSet(this, _ListWatch_getItemState, getItemState, "f"); | ||
if (itemsPath) { | ||
@@ -161,9 +157,9 @@ this.itemsPath = itemsPath; | ||
if (onNewList) { | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_onNewList, onNewList, "f"); | ||
__classPrivateFieldSet(this, _ListWatch_onNewList, onNewList, "f"); | ||
} | ||
else { | ||
// If no callback provided, ask client for states of pre-existing items | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_onNewList, async (ids) => Promise.all(ids.map(async (id) => { | ||
__classPrivateFieldSet(this, _ListWatch_onNewList, async (ids) => Promise.all(ids.map(async (id) => { | ||
try { | ||
return await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_instances, "m", _ListWatch_handleItemState).call(this, id); | ||
return await __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_handleItemState).call(this, id); | ||
} | ||
@@ -176,6 +172,6 @@ catch (cError) { | ||
} | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_meta, new Metadata_1.Metadata({ | ||
__classPrivateFieldSet(this, _ListWatch_meta, new Metadata({ | ||
// Don't persist metdata if service does not "resume" | ||
// persistInterval: this.#resume ? persistInterval : 0, | ||
conn: (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_resume, "f") ? (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_conn, "f") : undefined, | ||
conn: __classPrivateFieldGet(this, _ListWatch_resume, "f") ? __classPrivateFieldGet(this, _ListWatch_conn, "f") : undefined, | ||
path, | ||
@@ -185,3 +181,3 @@ tree, | ||
}), "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _ListWatch_watch, (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_instances, "m", _ListWatch_initialize).call(this), "f"); | ||
__classPrivateFieldSet(this, _ListWatch_watch, __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_initialize).call(this), "f"); | ||
} | ||
@@ -201,3 +197,3 @@ /** | ||
const { path, itemsPath } = this; | ||
const conn = (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_conn, "f"); | ||
const conn = __classPrivateFieldGet(this, _ListWatch_conn, "f"); | ||
const { data: list } = (await conn.get({ path })); | ||
@@ -212,3 +208,3 @@ if (Buffer.isBuffer(list)) { | ||
try { | ||
if (!all && (await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f").handled(id))) { | ||
if (!all && (await __classPrivateFieldGet(this, _ListWatch_meta, "f").handled(id))) { | ||
// We think this item is handled | ||
@@ -218,4 +214,4 @@ return; | ||
// Ask lib user for state of this item | ||
const state = await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_instances, "m", _ListWatch_handleItemState).call(this, id); | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_instances, "m", _ListWatch_updateItemState).call(this, list, id, state); | ||
const state = await __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_handleItemState).call(this, id); | ||
await __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_updateItemState).call(this, list, id, state); | ||
} | ||
@@ -231,3 +227,3 @@ catch (cError) { | ||
async stop() { | ||
const watch = await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_watch, "f"); | ||
const watch = await __classPrivateFieldGet(this, _ListWatch_watch, "f"); | ||
if (watch.return) { | ||
@@ -247,3 +243,2 @@ await watch.return(); | ||
} | ||
exports.ListWatch = ListWatch; | ||
_ListWatch_resume = new WeakMap(), _ListWatch_conn = new WeakMap(), _ListWatch_watch = new WeakMap(), _ListWatch_assertItem = new WeakMap(), _ListWatch_meta = new WeakMap(), _ListWatch_onAddItem = new WeakMap(), _ListWatch_onChangeItem = new WeakMap(), _ListWatch_onItem = new WeakMap(), _ListWatch_onRemoveItem = new WeakMap(), _ListWatch_onNewList = new WeakMap(), _ListWatch_onDeleteList = new WeakMap(), _ListWatch_getItemState = new WeakMap(), _ListWatch_instances = new WeakSet(), _ListWatch_handleItemState = | ||
@@ -257,25 +252,24 @@ /** | ||
// Needed because TS is weird about asserts... | ||
const assertItem = (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_assertItem, "f"); | ||
if (!stateCBnoItem((0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_getItemState, "f"))) { | ||
const { data: item } = await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_conn, "f").get({ | ||
path: (0, node_path_1.join)(this.path, id), | ||
const assertItem = __classPrivateFieldGet(this, _ListWatch_assertItem, "f"); | ||
if (!stateCBnoItem(__classPrivateFieldGet(this, _ListWatch_getItemState, "f"))) { | ||
const { data: item } = await __classPrivateFieldGet(this, _ListWatch_conn, "f").get({ | ||
path: join(this.path, id), | ||
}); | ||
assertItem(item); | ||
return (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_getItemState, "f").call(this, id, item); | ||
return __classPrivateFieldGet(this, _ListWatch_getItemState, "f").call(this, id, item); | ||
} | ||
return (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_getItemState, "f").call(this, id); | ||
return __classPrivateFieldGet(this, _ListWatch_getItemState, "f").call(this, id); | ||
}, _ListWatch_handleNewItem = async function _ListWatch_handleNewItem(rev, id, item) { | ||
var _a, _b; | ||
const { path } = this; | ||
// Needed because TS is weird about asserts... | ||
const assertItem = (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_assertItem, "f"); | ||
info('Detected new item %s in %s, rev %s', id, path, rev); | ||
const assertItem = __classPrivateFieldGet(this, _ListWatch_assertItem, "f"); | ||
info(`${__classPrivateFieldGet(this, _ListWatch_resume, "f") ? 'Detected new' : 'Handing existing'} item %s in %s, rev %s`, id, path, rev); | ||
const { _rev } = item; | ||
assertItem(item); | ||
const handled = await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f").handled(id); | ||
const handled = await __classPrivateFieldGet(this, _ListWatch_meta, "f").handled(id); | ||
try { | ||
// Double check this is a new item? | ||
if (!(handled === null || handled === void 0 ? void 0 : handled.onAddItem)) { | ||
await ((0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_onAddItem, "f") && (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_onAddItem, "f").call(this, item, id)); | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f").setHandled(id, { onAddItem: { rev: `${_rev}` } }); | ||
if (!handled?.onAddItem) { | ||
await (__classPrivateFieldGet(this, _ListWatch_onAddItem, "f") && __classPrivateFieldGet(this, _ListWatch_onAddItem, "f").call(this, item, id)); | ||
await __classPrivateFieldGet(this, _ListWatch_meta, "f").setHandled(id, { onAddItem: { rev: `${_rev}` } }); | ||
} | ||
@@ -288,28 +282,27 @@ } | ||
// Double check this item is actually newer than last time | ||
if (Number(_rev) > Number((_b = (_a = handled === null || handled === void 0 ? void 0 : handled.onItem) === null || _a === void 0 ? void 0 : _a.rev) !== null && _b !== void 0 ? _b : 0)) { | ||
await ((0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_onItem, "f") && (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_onItem, "f").call(this, item, id)); | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f").setHandled(id, { onItem: { rev: `${_rev}` } }); | ||
if (Number(_rev) > Number(handled?.onItem?.rev ?? 0)) { | ||
await (__classPrivateFieldGet(this, _ListWatch_onItem, "f") && __classPrivateFieldGet(this, _ListWatch_onItem, "f").call(this, item, id)); | ||
await __classPrivateFieldGet(this, _ListWatch_meta, "f").setHandled(id, { onItem: { rev: `${_rev}` } }); | ||
} | ||
} | ||
}, _ListWatch_handleItemChange = async function _ListWatch_handleItemChange(id, change) { | ||
var _a; | ||
const { path } = this; | ||
const conn = (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_conn, "f"); | ||
const rev = (_a = change.body) === null || _a === void 0 ? void 0 : _a._rev; | ||
const conn = __classPrivateFieldGet(this, _ListWatch_conn, "f"); | ||
const rev = change.body?._rev; | ||
// TODO: How best to handle change to a descendant of an item? | ||
info('Detected change to item %s in %s, rev %s', id, path, rev); | ||
try { | ||
await ((0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_onChangeItem, "f") && (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_onChangeItem, "f").call(this, change, id)); | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f").setHandled(id, { onChangeItem: { rev: `${rev}` } }); | ||
await (__classPrivateFieldGet(this, _ListWatch_onChangeItem, "f") && __classPrivateFieldGet(this, _ListWatch_onChangeItem, "f").call(this, change, id)); | ||
await __classPrivateFieldGet(this, _ListWatch_meta, "f").setHandled(id, { onChangeItem: { rev: `${rev}` } }); | ||
} | ||
finally { | ||
if ((0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_onItem, "f")) { | ||
if (__classPrivateFieldGet(this, _ListWatch_onItem, "f")) { | ||
// Needed because TS is weird about asserts... | ||
const assertItem = (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_assertItem, "f"); | ||
const assertItem = __classPrivateFieldGet(this, _ListWatch_assertItem, "f"); | ||
const { data: item } = await conn.get({ | ||
path: (0, node_path_1.join)(path, id), | ||
path: join(path, id), | ||
}); | ||
assertItem(item); | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_onItem, "f").call(this, item, id); | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f").setHandled(id, { onItem: { rev: `${rev}` } }); | ||
await __classPrivateFieldGet(this, _ListWatch_onItem, "f").call(this, item, id); | ||
await __classPrivateFieldGet(this, _ListWatch_meta, "f").setHandled(id, { onItem: { rev: `${rev}` } }); | ||
} | ||
@@ -319,3 +312,3 @@ } | ||
const { path, itemsPath } = this; | ||
const conn = (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_conn, "f"); | ||
const conn = __classPrivateFieldGet(this, _ListWatch_conn, "f"); | ||
const rev = list._rev; | ||
@@ -331,3 +324,3 @@ // Ignore _ keys of OADA | ||
trace('handleListChange: Processing item %s', id); | ||
const ichang = json_pointer_1.default.get(list, id); | ||
const ichang = pointer.get(list, id); | ||
trace(ichang, 'handleListChange'); | ||
@@ -338,7 +331,5 @@ // If there is an _id this is a new link in the list right? | ||
const { data: item } = (await conn.get({ | ||
// Joining path and id fails when jobs get moved into success/failure. Instead get the _id | ||
// path: join(path, id), | ||
path: `/${id}`, | ||
path: `/${ichang._id}` | ||
})); | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_instances, "m", _ListWatch_handleNewItem).call(this, `${rev}`, id, item); | ||
await __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_handleNewItem).call(this, `${rev}`, id, item); | ||
} | ||
@@ -359,11 +350,11 @@ else { | ||
try { | ||
const lChange = json_pointer_1.default.get(list, id); | ||
const lChange = pointer.get(list, id); | ||
if (lChange === null) { | ||
info('Detected removal of item %s from %s, rev %s', id, path, rev); | ||
try { | ||
await ((0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_onRemoveItem, "f") && (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_onRemoveItem, "f").call(this, id)); | ||
await (__classPrivateFieldGet(this, _ListWatch_onRemoveItem, "f") && __classPrivateFieldGet(this, _ListWatch_onRemoveItem, "f").call(this, id)); | ||
} | ||
finally { | ||
// Mark for delete? | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f").setHandled(id); | ||
await __classPrivateFieldGet(this, _ListWatch_meta, "f").setHandled(id); | ||
} | ||
@@ -394,3 +385,3 @@ } | ||
const { path } = this; | ||
const { rev } = (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f"); | ||
const { rev } = __classPrivateFieldGet(this, _ListWatch_meta, "f"); | ||
const idArray = Array.isArray(ids) ? ids : [ids]; | ||
@@ -402,17 +393,17 @@ const stateArray = (Array.isArray(states) ? states : [states]); | ||
switch (state) { | ||
case Options_1.ItemState.New: | ||
case ItemState.New: | ||
{ | ||
const { data: item } = (await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_conn, "f").get({ | ||
path: (0, node_path_1.join)(path, id), | ||
const { data: item } = (await __classPrivateFieldGet(this, _ListWatch_conn, "f").get({ | ||
path: join(path, id), | ||
})); | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_instances, "m", _ListWatch_handleNewItem).call(this, `${list._rev}`, id, item); | ||
await __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_handleNewItem).call(this, `${list._rev}`, id, item); | ||
} | ||
break; | ||
case Options_1.ItemState.Modified: | ||
case ItemState.Modified: | ||
{ | ||
const { data: item } = await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_conn, "f").get({ | ||
path: (0, node_path_1.join)(path, id), | ||
const { data: item } = await __classPrivateFieldGet(this, _ListWatch_conn, "f").get({ | ||
path: join(path, id), | ||
}); | ||
const change = { | ||
resource_id: json_pointer_1.default.get(list, id)._id, | ||
resource_id: pointer.get(list, id)._id, | ||
path: '', | ||
@@ -422,9 +413,9 @@ type: 'merge', | ||
}; | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_instances, "m", _ListWatch_handleItemChange).call(this, id, change); | ||
await __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_handleItemChange).call(this, id, change); | ||
} | ||
break; | ||
case Options_1.ItemState.Handled: | ||
case ItemState.Handled: | ||
info('Recording item %s as handled for %s', id, path); | ||
// Mark handled for all callbacks? | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f").setHandled(id, { | ||
await __classPrivateFieldGet(this, _ListWatch_meta, "f").setHandled(id, { | ||
onAddItem: { rev }, | ||
@@ -448,3 +439,3 @@ onItem: { rev }, | ||
const { path, tree, itemsPath } = this; | ||
const conn = (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_conn, "f"); | ||
const conn = __classPrivateFieldGet(this, _ListWatch_conn, "f"); | ||
info('Ensuring %s exists', path); | ||
@@ -456,3 +447,3 @@ try { | ||
// @ts-expect-error darn errors | ||
if ((cError === null || cError === void 0 ? void 0 : cError.status) === 403 || (cError === null || cError === void 0 ? void 0 : cError.status) === 404) { | ||
if (cError?.status === 403 || cError?.status === 404) { | ||
// Create it | ||
@@ -468,3 +459,3 @@ await conn.put({ path, tree, data: {} }); | ||
// TODO: Clean up control flow to not need this? | ||
const currentItemsNew = !(await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f").init()) || !(0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_resume, "f"); | ||
const currentItemsNew = !(await __classPrivateFieldGet(this, _ListWatch_meta, "f").init()) || !__classPrivateFieldGet(this, _ListWatch_resume, "f"); | ||
if (currentItemsNew) { | ||
@@ -480,10 +471,10 @@ trace('Treating current list items as new items'); | ||
trace('Calling onNewList'); | ||
const states = await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_onNewList, "f").call(this, items); | ||
const states = await __classPrivateFieldGet(this, _ListWatch_onNewList, "f").call(this, items); | ||
// Set the states | ||
trace('Updating item states based on callback result'); | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_instances, "m", _ListWatch_updateItemState).call(this, list, items, states); | ||
await __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_updateItemState).call(this, list, items, states); | ||
} | ||
// Setup watch on the path | ||
if ((0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_resume, "f")) { | ||
trace('Resuming watch from rev %s', (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f").rev); | ||
if (__classPrivateFieldGet(this, _ListWatch_resume, "f")) { | ||
trace('Resuming watch from rev %s', __classPrivateFieldGet(this, _ListWatch_meta, "f").rev); | ||
} | ||
@@ -493,9 +484,8 @@ // eslint-disable-next-line security/detect-non-literal-fs-filename | ||
path, | ||
rev: (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_resume, "f") ? (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f").rev : undefined, | ||
rev: __classPrivateFieldGet(this, _ListWatch_resume, "f") ? __classPrivateFieldGet(this, _ListWatch_meta, "f").rev : undefined, | ||
type: 'tree', | ||
}); | ||
void (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_instances, "m", _ListWatch_handleChangeFeed).call(this, changes); | ||
void __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_handleChangeFeed).call(this, changes); | ||
return changes; | ||
}, _ListWatch_handleChangeFeed = async function _ListWatch_handleChangeFeed(watch) { | ||
var _a, _b; | ||
const { path, itemsPath } = this; | ||
@@ -506,3 +496,3 @@ for await (const changes of watch) { | ||
// TODO: Better way than just looping through them all? | ||
for (const change of changes) { | ||
for await (const change of changes) { | ||
const { type, path: changePath, body, ...context } = change; | ||
@@ -512,7 +502,6 @@ if (body === null && type === 'delete' && changePath === '') { | ||
warn('Detected delete of list %s', path); | ||
// eslint-disable-next-line no-await-in-loop | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_onDeleteList, "f").call(this); | ||
await __classPrivateFieldGet(this, _ListWatch_onDeleteList, "f").call(this); | ||
continue; | ||
} | ||
const rev = (_a = body) === null || _a === void 0 ? void 0 : _a._rev; | ||
const rev = body?._rev; | ||
trace(change, 'Received change'); | ||
@@ -532,5 +521,5 @@ let listChange = body; | ||
// Just put true here for now to check if path matches | ||
json_pointer_1.default.set(changeObject, changePath, true); | ||
pointer.set(changeObject, changePath, true); | ||
// eslint-disable-next-line new-cap | ||
const pathmatches = (0, jsonpath_plus_1.JSONPath)({ | ||
const pathmatches = JSONPath({ | ||
resultType: 'pointer', | ||
@@ -541,3 +530,3 @@ path: itemsPath, | ||
}); | ||
if ((pathmatches === null || pathmatches === void 0 ? void 0 : pathmatches.length) === 0) { | ||
if (pathmatches?.length === 0) { | ||
// If it does not match, this must be above the items | ||
@@ -549,3 +538,3 @@ isListChange = true; | ||
// Now put the actual change body in place of the true | ||
json_pointer_1.default.set(changeObject, changePath, body); | ||
pointer.set(changeObject, changePath, body); | ||
// Find items involved in the change | ||
@@ -555,5 +544,4 @@ const itemsChanged = getListItems(changeObject, itemsPath); | ||
if (!isListChange && itemsChanged.length > 0) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await Promise.all(itemsChanged.map((item) => { | ||
const itemBody = json_pointer_1.default.get(changeObject, item); | ||
const itemBody = pointer.get(changeObject, item); | ||
// Make change start at item instead of the list | ||
@@ -574,3 +562,3 @@ const itemPath = changePath.slice(item.length); | ||
} | ||
return (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_instances, "m", _ListWatch_handleItemChange).call(this, item, itemChange); | ||
return __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_handleItemChange).call(this, item, itemChange); | ||
})); | ||
@@ -584,4 +572,3 @@ continue; | ||
trace('Change was to the list itself because changePath is empty, calling handleListChange'); | ||
// eslint-disable-next-line no-await-in-loop | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_instances, "m", _ListWatch_handleListChange).call(this, listChange, type); | ||
await __classPrivateFieldGet(this, _ListWatch_instances, "m", _ListWatch_handleListChange).call(this, listChange, type); | ||
} | ||
@@ -592,5 +579,5 @@ catch (cError) { | ||
} | ||
if ((0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_resume, "f")) { | ||
if (__classPrivateFieldGet(this, _ListWatch_resume, "f")) { | ||
trace('Received change to root of list, updating handled rev in our _meta records'); | ||
(0, tslib_1.__classPrivateFieldGet)(this, _ListWatch_meta, "f").rev = `${(_b = rootChange === null || rootChange === void 0 ? void 0 : rootChange.body) === null || _b === void 0 ? void 0 : _b._rev}`; | ||
__classPrivateFieldGet(this, _ListWatch_meta, "f").rev = `${rootChange?.body?._rev}`; | ||
} | ||
@@ -609,3 +596,3 @@ } | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
ListWatch.AssumeNew = assumeItemState(Options_1.ItemState.New); | ||
ListWatch.AssumeNew = assumeItemState(ItemState.New); | ||
/** | ||
@@ -619,8 +606,7 @@ * Callback to make ListWatch consider every `Item` handled | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
ListWatch.AssumeHandled = assumeItemState(Options_1.ItemState.Handled); | ||
ListWatch.AssumeHandled = assumeItemState(ItemState.Handled); | ||
function stateCBnoItem(callback) { | ||
return callback.length < 2; | ||
} | ||
var Options_2 = require("./Options"); | ||
Object.defineProperty(exports, "ItemState", { enumerable: true, get: function () { return Options_2.ItemState; } }); | ||
export { ItemState } from './Options'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -19,12 +18,11 @@ * @license | ||
var _Metadata_rev, _Metadata_revDirty, _Metadata_conn, _Metadata_path, _Metadata_tree, _Metadata_initialized; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Metadata = void 0; | ||
const tslib_1 = require("tslib"); | ||
const node_path_1 = require("node:path"); | ||
const isomorphic_timers_promises_1 = require("isomorphic-timers-promises"); | ||
const clone_deep_1 = (0, tslib_1.__importDefault)(require("clone-deep")); | ||
const debug_1 = (0, tslib_1.__importDefault)(require("debug")); | ||
const json_pointer_1 = (0, tslib_1.__importDefault)(require("json-pointer")); | ||
const trace = (0, debug_1.default)('oada-list-lib#metadata:trace'); | ||
const error = (0, debug_1.default)('oada-list-lib#metadata:error'); | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { join } from 'node:path'; | ||
import { setInterval } from 'isomorphic-timers-promises'; | ||
import clone from 'clone-deep'; | ||
import debug from 'debug'; | ||
import pointer from 'json-pointer'; | ||
const trace = debug('oada-list-lib#metadata:trace'); | ||
const info = debug('oada-list-lib#metadata:info'); | ||
const error = debug('oada-list-lib#metadata:error'); | ||
/** | ||
@@ -35,3 +33,3 @@ * Persistent data we store in the _meta of the list | ||
*/ | ||
class Metadata { | ||
export class Metadata { | ||
constructor({ conn, path, tree, name, }) { | ||
@@ -48,9 +46,9 @@ /** | ||
_Metadata_initialized.set(this, false); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_conn, conn, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_path, (0, node_path_1.join)(path, '_meta', Metadata.META_KEY, name), "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_tree, (0, clone_deep_1.default)(tree), "f"); | ||
if ((0, tslib_1.__classPrivateFieldGet)(this, _Metadata_tree, "f")) { | ||
__classPrivateFieldSet(this, _Metadata_conn, conn, "f"); | ||
__classPrivateFieldSet(this, _Metadata_path, join(path, '_meta', Metadata.META_KEY, name), "f"); | ||
__classPrivateFieldSet(this, _Metadata_tree, clone(tree), "f"); | ||
if (__classPrivateFieldGet(this, _Metadata_tree, "f")) { | ||
// Replicate list tree under handled key? | ||
const listTree = (0, clone_deep_1.default)(json_pointer_1.default.get((0, tslib_1.__classPrivateFieldGet)(this, _Metadata_tree, "f"), path)); | ||
json_pointer_1.default.set((0, tslib_1.__classPrivateFieldGet)(this, _Metadata_tree, "f"), (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_path, "f"), { | ||
const listTree = clone(pointer.get(__classPrivateFieldGet(this, _Metadata_tree, "f"), path)); | ||
pointer.set(__classPrivateFieldGet(this, _Metadata_tree, "f"), __classPrivateFieldGet(this, _Metadata_path, "f"), { | ||
_type: 'application/json', | ||
@@ -62,4 +60,4 @@ handled: listTree, | ||
// Make up a tree? idk man | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_tree, {}, "f"); | ||
json_pointer_1.default.set((0, tslib_1.__classPrivateFieldGet)(this, _Metadata_tree, "f"), (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_path, "f"), { | ||
__classPrivateFieldSet(this, _Metadata_tree, {}, "f"); | ||
pointer.set(__classPrivateFieldGet(this, _Metadata_tree, "f"), __classPrivateFieldGet(this, _Metadata_path, "f"), { | ||
_type: 'application/json', | ||
@@ -70,24 +68,23 @@ handled: { '*': {} }, | ||
// TODO: Use timeouts for all updates? | ||
const revUpdateInterval = (0, isomorphic_timers_promises_1.setInterval)(100); | ||
const revUpdateInterval = setInterval(100); | ||
const updateRevs = async () => { | ||
var _a; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
for await (const _ of revUpdateInterval) { | ||
trace('rev update interval %d, %s, %s', (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_rev, "f"), (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_initialized, "f"), (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_revDirty, "f")); | ||
if (!(0, tslib_1.__classPrivateFieldGet)(this, _Metadata_initialized, "f") || !(0, tslib_1.__classPrivateFieldGet)(this, _Metadata_revDirty, "f")) { | ||
trace('rev update interval %d, %s, %s', __classPrivateFieldGet(this, _Metadata_rev, "f"), __classPrivateFieldGet(this, _Metadata_initialized, "f"), __classPrivateFieldGet(this, _Metadata_revDirty, "f")); | ||
if (!__classPrivateFieldGet(this, _Metadata_initialized, "f") || !__classPrivateFieldGet(this, _Metadata_revDirty, "f")) { | ||
continue; | ||
} | ||
trace('Recording rev %s', (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_rev, "f")); | ||
const data = { rev: (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_rev, "f") }; | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_revDirty, false, "f"); | ||
trace('Recording rev %s', __classPrivateFieldGet(this, _Metadata_rev, "f")); | ||
const data = { rev: __classPrivateFieldGet(this, _Metadata_rev, "f") }; | ||
__classPrivateFieldSet(this, _Metadata_revDirty, false, "f"); | ||
try { | ||
await ((_a = (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_conn, "f")) === null || _a === void 0 ? void 0 : _a.put({ | ||
path: (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_path, "f"), | ||
tree: (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_tree, "f"), | ||
await __classPrivateFieldGet(this, _Metadata_conn, "f")?.put({ | ||
path: __classPrivateFieldGet(this, _Metadata_path, "f"), | ||
tree: __classPrivateFieldGet(this, _Metadata_tree, "f"), | ||
data, | ||
})); | ||
}); | ||
} | ||
catch (cError) { | ||
error(cError, 'Failed to update rev'); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_revDirty, true, "f"); | ||
__classPrivateFieldSet(this, _Metadata_revDirty, true, "f"); | ||
} | ||
@@ -106,6 +103,6 @@ } | ||
get rev() { | ||
return `${(0, tslib_1.__classPrivateFieldGet)(this, _Metadata_rev, "f")}`; | ||
return `${__classPrivateFieldGet(this, _Metadata_rev, "f")}`; | ||
} | ||
set rev(rev) { | ||
if ((0, tslib_1.__classPrivateFieldGet)(this, _Metadata_rev, "f") === rev) { | ||
if (__classPrivateFieldGet(this, _Metadata_rev, "f") === rev) { | ||
// No need to update | ||
@@ -115,4 +112,4 @@ return; | ||
trace(`Updating local rev to ${rev}`); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_rev, rev, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_revDirty, true, "f"); | ||
__classPrivateFieldSet(this, _Metadata_rev, rev, "f"); | ||
__classPrivateFieldSet(this, _Metadata_revDirty, true, "f"); | ||
} | ||
@@ -126,16 +123,15 @@ /** | ||
async setHandled(path, item) { | ||
var _a, _b; | ||
if (item) { | ||
// Merge with current info | ||
const data = {}; | ||
json_pointer_1.default.set(data, `/handled${path}`, item); | ||
await ((_a = (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_conn, "f")) === null || _a === void 0 ? void 0 : _a.put({ | ||
path: (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_path, "f"), | ||
tree: (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_tree, "f"), | ||
pointer.set(data, `/handled${path}`, item); | ||
await __classPrivateFieldGet(this, _Metadata_conn, "f")?.put({ | ||
path: __classPrivateFieldGet(this, _Metadata_path, "f"), | ||
tree: __classPrivateFieldGet(this, _Metadata_tree, "f"), | ||
data, | ||
})); | ||
}); | ||
} | ||
else { | ||
// Unset info? | ||
await ((_b = (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_conn, "f")) === null || _b === void 0 ? void 0 : _b.delete({ path: (0, node_path_1.join)((0, tslib_1.__classPrivateFieldGet)(this, _Metadata_path, "f"), 'handled', path) })); | ||
await __classPrivateFieldGet(this, _Metadata_conn, "f")?.delete({ path: join(__classPrivateFieldGet(this, _Metadata_path, "f"), 'handled', path) }); | ||
} | ||
@@ -150,8 +146,8 @@ // This.#updated = true; | ||
async handled(path) { | ||
if (!(0, tslib_1.__classPrivateFieldGet)(this, _Metadata_conn, "f")) { | ||
if (!__classPrivateFieldGet(this, _Metadata_conn, "f")) { | ||
return undefined; | ||
} | ||
try { | ||
const { data } = await (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_conn, "f").get({ | ||
path: (0, node_path_1.join)((0, tslib_1.__classPrivateFieldGet)(this, _Metadata_path, "f"), 'handled', path), | ||
const { data } = await __classPrivateFieldGet(this, _Metadata_conn, "f").get({ | ||
path: join(__classPrivateFieldGet(this, _Metadata_path, "f"), 'handled', path), | ||
}); | ||
@@ -171,5 +167,5 @@ return data; | ||
async init() { | ||
if (!(0, tslib_1.__classPrivateFieldGet)(this, _Metadata_conn, "f")) { | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_rev, undefined, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_initialized, true, "f"); | ||
if (!__classPrivateFieldGet(this, _Metadata_conn, "f")) { | ||
__classPrivateFieldSet(this, _Metadata_rev, undefined, "f"); | ||
__classPrivateFieldSet(this, _Metadata_initialized, true, "f"); | ||
return false; | ||
@@ -179,7 +175,9 @@ } | ||
try { | ||
const { data: rev } = await (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_conn, "f").get({ | ||
path: (0, node_path_1.join)((0, tslib_1.__classPrivateFieldGet)(this, _Metadata_path, "f"), 'rev'), | ||
const { data } = await __classPrivateFieldGet(this, _Metadata_conn, "f").get({ | ||
path: __classPrivateFieldGet(this, _Metadata_path, "f"), | ||
}); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_rev, rev, "f"); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_initialized, true, "f"); | ||
if (typeof data == 'object' && data && !Buffer.isBuffer(data) && !Array.isArray(data)) { | ||
__classPrivateFieldSet(this, _Metadata_rev, data.rev, "f"); | ||
} | ||
__classPrivateFieldSet(this, _Metadata_initialized, true, "f"); | ||
return true; | ||
@@ -189,20 +187,23 @@ } | ||
// Create our metadata? | ||
const { headers: { 'content-location': location }, } = await (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_conn, "f").post({ | ||
info(`${__classPrivateFieldGet(this, _Metadata_path, "f")} does not exist, posting new resource`); | ||
const { headers: { 'content-location': location }, } = await __classPrivateFieldGet(this, _Metadata_conn, "f").post({ | ||
path: '/resources/', | ||
data: {}, | ||
contentType: 'application/json' | ||
}); | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_conn, "f").put({ | ||
path: (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_path, "f"), | ||
tree: (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_tree, "f"), | ||
data: { _id: location === null || location === void 0 ? void 0 : location.slice(1) }, | ||
console.log('HERE IS THE LINK', location?.slice(1)); | ||
await __classPrivateFieldGet(this, _Metadata_conn, "f").put({ | ||
path: __classPrivateFieldGet(this, _Metadata_path, "f"), | ||
tree: __classPrivateFieldGet(this, _Metadata_tree, "f"), | ||
data: { _id: location?.slice(1) }, | ||
}); | ||
const data = { | ||
rev: (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_rev, "f"), | ||
rev: __classPrivateFieldGet(this, _Metadata_rev, "f"), | ||
}; | ||
await (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_conn, "f").put({ | ||
path: (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_path, "f"), | ||
tree: (0, tslib_1.__classPrivateFieldGet)(this, _Metadata_tree, "f"), | ||
await __classPrivateFieldGet(this, _Metadata_conn, "f").put({ | ||
path: __classPrivateFieldGet(this, _Metadata_path, "f"), | ||
tree: __classPrivateFieldGet(this, _Metadata_tree, "f"), | ||
data, | ||
}); | ||
(0, tslib_1.__classPrivateFieldSet)(this, _Metadata_initialized, true, "f"); | ||
__classPrivateFieldSet(this, _Metadata_initialized, true, "f"); | ||
return false; | ||
@@ -212,4 +213,3 @@ } | ||
} | ||
exports.Metadata = Metadata; | ||
_Metadata_rev = new WeakMap(), _Metadata_revDirty = new WeakMap(), _Metadata_conn = new WeakMap(), _Metadata_path = new WeakMap(), _Metadata_tree = new WeakMap(), _Metadata_initialized = new WeakMap(); | ||
//# sourceMappingURL=Metadata.js.map |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -18,4 +17,2 @@ * @license | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ItemState = void 0; | ||
/** | ||
@@ -26,3 +23,3 @@ * The possible states of an item in our list | ||
*/ | ||
var ItemState; | ||
export var ItemState; | ||
(function (ItemState) { | ||
@@ -42,3 +39,3 @@ /** | ||
ItemState["Handled"] = "handled"; | ||
})(ItemState = exports.ItemState || (exports.ItemState = {})); | ||
})(ItemState || (ItemState = {})); | ||
//# sourceMappingURL=Options.js.map |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -18,3 +17,3 @@ * @license | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=tree.js.map |
{ | ||
"name": "@oada/list-lib", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "Library for processing items in an OADA list", | ||
"main": "lib/index.js", | ||
"type": "module", | ||
"typings": "lib/index.d.ts", | ||
@@ -44,3 +45,3 @@ "repository": { | ||
"@ava/typescript": "^3.0.1", | ||
"@tsconfig/node12": "^1.0.9", | ||
"@tsconfig/node14": "^1.0.1", | ||
"@types/clone-deep": "^4.0.1", | ||
@@ -50,13 +51,13 @@ "@types/debug": "^4.1.7", | ||
"@types/jsonpath-plus": "^5.0.2", | ||
"@types/node": "^16.11.14", | ||
"@types/node": "^16.11.36", | ||
"@types/object-assign-deep": "^0.4.0", | ||
"@types/sinon": "^10.0.6", | ||
"@typescript-eslint/eslint-plugin": "^5.7.0", | ||
"@typescript-eslint/parser": "^5.7.0", | ||
"@yarnpkg/sdks": "^2.5.1-rc.6", | ||
"@types/sinon": "^10.0.11", | ||
"@typescript-eslint/eslint-plugin": "^5.25.0", | ||
"@typescript-eslint/parser": "^5.25.0", | ||
"@yarnpkg/sdks": "^3.0.0-rc.6", | ||
"ava": "^3.15.0", | ||
"eslint": "^7.32.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-config-xo": "^0.39.0", | ||
"eslint-config-xo-typescript": "^0.47.1", | ||
"eslint": "^8.15.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-config-xo": "^0.41.0", | ||
"eslint-config-xo-typescript": "^0.51.1", | ||
"eslint-formatter-pretty": "^4.1.0", | ||
@@ -67,5 +68,5 @@ "eslint-import-resolver-node": "^0.3.6", | ||
"eslint-plugin-filenames": "^1.3.2", | ||
"eslint-plugin-github": "^4.3.5", | ||
"eslint-plugin-github": "^4.3.6", | ||
"eslint-plugin-i18n-text": "^1.0.1", | ||
"eslint-plugin-import": "^2.25.3", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-no-constructor-bind": "^2.0.4", | ||
@@ -78,23 +79,23 @@ "eslint-plugin-no-only-tests": "^2.6.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-promise": "^5.2.0", | ||
"eslint-plugin-regexp": "^1.5.1", | ||
"eslint-plugin-security": "^1.4.0", | ||
"eslint-plugin-sonarjs": "^0.11.0", | ||
"eslint-plugin-unicorn": "^39.0.0", | ||
"prettier": "^2.5.1", | ||
"eslint-plugin-promise": "^6.0.0", | ||
"eslint-plugin-regexp": "^1.7.0", | ||
"eslint-plugin-security": "^1.5.0", | ||
"eslint-plugin-sonarjs": "^0.13.0", | ||
"eslint-plugin-unicorn": "^42.0.0", | ||
"prettier": "^2.6.2", | ||
"sinon": "^12.0.1", | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.5.4" | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.6.4" | ||
}, | ||
"dependencies": { | ||
"@oada/client": "^3.0.3", | ||
"@oada/types": "^1.7.0", | ||
"@oada/client": "^4.0.1", | ||
"@oada/types": "^2.0.1", | ||
"clone-deep": "^4.0.1", | ||
"debug": "^4.3.3", | ||
"debug": "^4.3.4", | ||
"isomorphic-timers-promises": "^1.0.1", | ||
"json-pointer": "^0.6.1", | ||
"json-pointer": "^0.6.2", | ||
"jsonpath-plus": "^6.0.1", | ||
"tslib": "^2.3.1" | ||
"tslib": "^2.4.0" | ||
}, | ||
"packageManager": "yarn@3.1.1" | ||
"packageManager": "yarn@3.2.1" | ||
} |
@@ -26,3 +26,3 @@ /** | ||
import type { Link } from '@oada/types/oada/link/v1'; | ||
import type { Resource } from '@oada/types/oada/resource'; | ||
import type Resource from '@oada/types/oada/resource'; | ||
import type V2Changes from '@oada/types/oada/change/v2'; | ||
@@ -382,3 +382,3 @@ | ||
info('Detected new item %s in %s, rev %s', id, path, rev); | ||
info(`${this.#resume ? 'Detected new' : 'Handing existing'} item %s in %s, rev %s`, id, path, rev); | ||
const { _rev } = item; | ||
@@ -461,5 +461,3 @@ assertItem(item); | ||
const { data: item } = (await conn.get({ | ||
// Joining path and id fails when jobs get moved into success/failure. Instead get the _id | ||
// path: join(path, id), | ||
path: `/${id}`, | ||
path: `/${ichang._id}` | ||
})) as GetResponse<Resource>; | ||
@@ -650,3 +648,3 @@ await this.#handleNewItem(`${rev}`, id, item); | ||
}); | ||
void this.#handleChangeFeed(changes); | ||
@@ -666,3 +664,3 @@ return changes; | ||
// TODO: Better way than just looping through them all? | ||
for (const change of changes) { | ||
for await (const change of changes) { | ||
const { type, path: changePath, body, ...context } = change; | ||
@@ -674,3 +672,2 @@ | ||
// eslint-disable-next-line no-await-in-loop | ||
await this.#onDeleteList(); | ||
@@ -721,3 +718,2 @@ continue; | ||
if (!isListChange && itemsChanged.length > 0) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await Promise.all( | ||
@@ -763,3 +759,2 @@ itemsChanged.map((item) => { | ||
); | ||
// eslint-disable-next-line no-await-in-loop | ||
await this.#handleListChange(listChange, type); | ||
@@ -766,0 +761,0 @@ } catch (cError: unknown) { |
@@ -30,2 +30,3 @@ /** | ||
const trace = debug('oada-list-lib#metadata:trace'); | ||
const info = debug('oada-list-lib#metadata:info'); | ||
const error = debug('oada-list-lib#metadata:error'); | ||
@@ -224,6 +225,8 @@ | ||
try { | ||
const { data: rev } = await this.#conn.get({ | ||
path: join(this.#path, 'rev'), | ||
const { data } = await this.#conn.get({ | ||
path: this.#path, | ||
}); | ||
this.#rev = rev as string; | ||
if (typeof data == 'object' && data && !Buffer.isBuffer(data) && !Array.isArray(data)) { | ||
this.#rev = data!.rev as string; | ||
} | ||
this.#initialized = true; | ||
@@ -233,2 +236,3 @@ return true; | ||
// Create our metadata? | ||
info(`${this.#path} does not exist, posting new resource`); | ||
const { | ||
@@ -239,3 +243,5 @@ headers: { 'content-location': location }, | ||
data: {}, | ||
contentType: 'application/json' | ||
}); | ||
console.log('HERE IS THE LINK', location?.slice(1)) | ||
await this.#conn.put({ | ||
@@ -242,0 +248,0 @@ path: this.#path, |
{ | ||
"extends": "@tsconfig/node12", | ||
"extends": "@tsconfig/node14", | ||
"ts-node": { | ||
@@ -7,2 +7,4 @@ "files": true | ||
"compilerOptions": { | ||
"module": "es2020", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
@@ -9,0 +11,0 @@ "rootDir": "src", |
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
5703527
387
173666
Yes
+ Added@ava/typescript@5.0.0(transitive)
+ Added@bcoe/v8-coverage@0.2.3(transitive)
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@istanbuljs/schema@0.1.3(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Added@mapbox/node-pre-gyp@1.0.11(transitive)
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Added@oada/client@4.5.6(transitive)
+ Added@oada/jobs@4.7.1(transitive)
+ Added@oada/lib-config@3.9.1(transitive)
+ Added@oada/lib-prom@3.8.0(transitive)
+ Added@oada/list-lib@4.3.0(transitive)
+ Added@oada/oadaify@2.1.0(transitive)
+ Added@oada/pino-debug@4.0.1(transitive)
+ Added@oada/types@3.5.3(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Added@rollup/pluginutils@4.2.1(transitive)
+ Added@sindresorhus/is@6.3.1(transitive)
+ Added@sindresorhus/merge-streams@2.3.0(transitive)
+ Added@types/istanbul-lib-coverage@2.0.6(transitive)
+ Added@types/luxon@3.4.2(transitive)
+ Added@vercel/nft@0.27.6(transitive)
+ Addedabbrev@1.1.1(transitive)
+ Addedacorn@8.14.0(transitive)
+ Addedacorn-import-attributes@1.9.5(transitive)
+ Addedacorn-walk@8.3.4(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedajv@8.12.0(transitive)
+ Addedansi-regex@5.0.16.1.0(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedaproba@2.0.0(transitive)
+ Addedare-we-there-yet@2.0.0(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedarray-find-index@1.0.2(transitive)
+ Addedarrgv@1.0.2(transitive)
+ Addedarrify@3.0.0(transitive)
+ Addedasync-sema@3.1.1(transitive)
+ Addedatomic-sleep@1.0.0(transitive)
+ Addedava@6.2.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase-convert-int-array@1.0.1(transitive)
+ Addedbindings@1.5.0(transitive)
+ Addedbintrees@1.0.2(transitive)
+ Addedblueimp-md5@2.19.0(transitive)
+ Addedbrace-expansion@1.1.112.0.1(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedc8@10.1.2(transitive)
+ Addedcallsites@4.2.0(transitive)
+ Addedcbor@9.0.2(transitive)
+ Addedchalk@5.3.0(transitive)
+ Addedchownr@2.0.0(transitive)
+ Addedchunkd@2.0.1(transitive)
+ Addedci-info@4.1.0(transitive)
+ Addedci-parallel-vars@1.0.1(transitive)
+ Addedcli-truncate@4.0.0(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedcls-rtracer@2.6.3(transitive)
+ Addedcode-excerpt@4.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedcolorette@2.0.20(transitive)
+ Addedcommander@12.1.0(transitive)
+ Addedcommon-path-prefix@3.0.0(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconcordance@5.0.4(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addedconvert-source-map@2.0.0(transitive)
+ Addedconvert-to-spaces@2.0.1(transitive)
+ Addedconvict@6.2.4(transitive)
+ Addedconvict-format-with-moment@6.2.0(transitive)
+ Addedconvict-format-with-validator@6.2.0(transitive)
+ Addedcron@3.2.1(transitive)
+ Addedcross-spawn@7.0.5(transitive)
+ Addedcsvjson@5.1.0(transitive)
+ Addedcurrently-unhandled@0.4.1(transitive)
+ Addeddate-time@3.1.0(transitive)
+ Addeddateformat@4.6.3(transitive)
+ Addeddeep-clone@4.0.0(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddetect-libc@2.0.3(transitive)
+ Addeddotenv@16.4.5(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemittery@1.0.3(transitive)
+ Addedemoji-regex@10.4.08.0.09.2.2(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedescape-string-regexp@2.0.05.0.0(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedestree-walker@2.0.2(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedeventemitter3@5.0.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedexeca@8.0.1(transitive)
+ Addedfast-copy@3.0.2(transitive)
+ Addedfast-diff@1.3.0(transitive)
+ Addedfast-glob@3.3.2(transitive)
+ Addedfast-redact@3.5.0(transitive)
+ Addedfast-safe-stringify@2.1.1(transitive)
+ Addedfastify-plugin@4.5.1(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfigures@6.1.0(transitive)
+ Addedfile-type@18.7.0(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfind-up@5.0.0(transitive)
+ Addedfind-up-simple@1.0.0(transitive)
+ Addedflatstr@1.0.12(transitive)
+ Addedforeground-child@3.3.0(transitive)
+ Addedfs-minipass@2.1.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedgauge@3.0.2(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedget-east-asian-width@1.3.0(transitive)
+ Addedget-stream@8.0.1(transitive)
+ Addedglob@10.4.57.2.3(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedglobby@14.0.2(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedhelp-me@5.0.0(transitive)
+ Addedhtml-escaper@2.0.2(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addedhuman-signals@5.0.0(transitive)
+ Addedignore@5.3.2(transitive)
+ Addedignore-by-default@2.1.0(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedindent-string@5.0.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedirregular-plurals@3.5.0(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-fullwidth-code-point@3.0.04.0.0(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-interactive@2.0.0(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedis-plain-object@5.0.0(transitive)
+ Addedis-promise@4.0.0(transitive)
+ Addedis-stream@3.0.0(transitive)
+ Addedis-unicode-supported@2.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedisomorphic-ws@5.0.0(transitive)
+ Addedistanbul-lib-coverage@3.2.2(transitive)
+ Addedistanbul-lib-report@3.0.1(transitive)
+ Addedistanbul-reports@3.1.7(transitive)
+ Addedjackspeak@3.4.3(transitive)
+ Addedjoycon@3.1.1(transitive)
+ Addedjs-string-escape@1.0.1(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedjson-ptr@3.1.1(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedjsonpath-plus@7.2.08.1.0(transitive)
+ Addedksuid@3.0.0(transitive)
+ Addedload-json-file@7.0.1(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.clonedeep@4.5.0(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedluxon@3.5.0(transitive)
+ Addedmake-dir@3.1.04.0.0(transitive)
+ Addedmatcher@5.0.0(transitive)
+ Addedmd5-hex@3.0.1(transitive)
+ Addedmemoize@10.0.0(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedmimic-fn@4.0.0(transitive)
+ Addedmimic-function@5.0.1(transitive)
+ Addedminimatch@3.1.29.0.5(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedminipass@3.3.65.0.07.1.2(transitive)
+ Addedminizlib@2.1.2(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addedmoment@2.30.1(transitive)
+ Addednode-gyp-build@4.8.3(transitive)
+ Addednofilter@3.1.0(transitive)
+ Addednopt@5.0.0(transitive)
+ Addednpm-run-path@5.3.0(transitive)
+ Addednpmlog@5.0.1(transitive)
+ Addednstats@5.0.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject-assign-deep@0.4.0(transitive)
+ Addedon-exit-leak-free@2.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedonetime@6.0.0(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedp-map@7.0.2(transitive)
+ Addedp-queue@7.4.18.0.1(transitive)
+ Addedp-timeout@5.1.06.1.3(transitive)
+ Addedpackage-config@5.0.0(transitive)
+ Addedpackage-json-from-dist@1.0.1(transitive)
+ Addedparse-ms@4.0.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-key@3.1.14.0.0(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedpath-type@5.0.0(transitive)
+ Addedpeek-readable@5.3.1(transitive)
+ Addedpicomatch@2.3.14.0.2(transitive)
+ Addedpino@6.14.09.5.0(transitive)
+ Addedpino-abstract-transport@1.2.02.0.0(transitive)
+ Addedpino-caller@3.4.0(transitive)
+ Addedpino-debug@2.0.0(transitive)
+ Addedpino-loki@2.3.1(transitive)
+ Addedpino-pretty@11.3.0(transitive)
+ Addedpino-std-serializers@3.2.07.0.0(transitive)
+ Addedplur@5.1.0(transitive)
+ Addedpretty-ms@9.1.0(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedprocess-warning@1.0.04.0.0(transitive)
+ Addedprom-client@14.2.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedquick-format-unescaped@4.0.4(transitive)
+ Addedreadable-stream@4.5.2(transitive)
+ Addedreal-require@0.2.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedresolve-cwd@3.0.0(transitive)
+ Addedresolve-from@5.0.0(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedsafe-stable-stringify@2.5.0(transitive)
+ Addedsecure-json-parse@2.7.0(transitive)
+ Addedsemver@6.3.17.6.3(transitive)
+ Addedserialize-error@11.0.37.0.1(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@3.0.74.1.0(transitive)
+ Addedslash@5.1.0(transitive)
+ Addedslice-ansi@5.0.0(transitive)
+ Addedsonic-boom@1.4.14.2.0(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsource-map-support@0.5.21(transitive)
+ Addedsplit2@4.2.0(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedstack-utils@2.0.6(transitive)
+ Addedstring-width@4.2.35.1.27.2.0(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedstrip-final-newline@3.0.0(transitive)
+ Addedstrip-json-comments@3.1.1(transitive)
+ Addedstrtok3@7.1.1(transitive)
+ Addedsupertap@3.0.1(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedtar@6.2.1(transitive)
+ Addedtdigest@0.1.2(transitive)
+ Addedtemp-dir@3.0.0(transitive)
+ Addedtest-exclude@7.0.1(transitive)
+ Addedthread-stream@3.1.0(transitive)
+ Addedtime-zone@1.0.0(transitive)
+ Addedtiny-json-http@7.5.1(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addedtoken-types@5.0.1(transitive)
+ Addedtslib@2.7.0(transitive)
+ Addedtype-fest@0.13.12.19.0(transitive)
+ Addedunicorn-magic@0.1.0(transitive)
+ Addedutf-8-validate@6.0.5(transitive)
+ Addeduuid@9.0.1(transitive)
+ Addedv8-to-istanbul@9.3.0(transitive)
+ Addedvalidator@13.12.0(transitive)
+ Addedwell-known-symbols@2.0.0(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwide-align@1.1.5(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedwrite-file-atomic@6.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyallist@4.0.0(transitive)
+ Addedyaml@2.6.0(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@20.2.921.1.1(transitive)
+ Addedyocto-queue@0.1.0(transitive)
- Removed@oada/client@3.2.0(transitive)
- Removed@oada/types@1.8.1(transitive)
- Removeddeep-clone@3.0.3(transitive)
- Removedeventemitter3@4.0.7(transitive)
- Removedfile-type@16.5.4(transitive)
- Removedisomorphic-ws@4.0.1(transitive)
- Removednode-gyp-build@4.8.2(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-queue@6.6.2(transitive)
- Removedp-timeout@3.2.0(transitive)
- Removedpeek-readable@4.1.0(transitive)
- Removedstrtok3@6.3.0(transitive)
- Removedtoken-types@4.2.1(transitive)
- Removedutf-8-validate@5.0.10(transitive)
- Removedxksuid@0.0.2(transitive)
Updated@oada/client@^4.0.1
Updated@oada/types@^2.0.1
Updateddebug@^4.3.4
Updatedjson-pointer@^0.6.2
Updatedtslib@^2.4.0