Socket
Socket
Sign inDemoInstall

@oada/list-lib

Package Overview
Dependencies
Maintainers
8
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oada/list-lib - npm Package Compare versions

Comparing version 2.1.3 to 2.1.4

foo.js

76

lib/index.js

@@ -162,3 +162,3 @@ "use strict";

catch (err) {
error(err);
error('Error getting item state: %O', err);
}

@@ -370,37 +370,42 @@ });

const state = _states[i];
switch (state) {
case Options_1.ItemState.New:
{
const { data: item } = (await __classPrivateFieldGet(this, _conn).get({
path: path_1.join(path, id),
}));
await this.handleNewItem(list._rev + '', id, item);
}
break;
case Options_1.ItemState.Modified:
{
const { data: item } = await __classPrivateFieldGet(this, _conn).get({
path: path_1.join(path, id),
try {
switch (state) {
case Options_1.ItemState.New:
{
const { data: item } = (await __classPrivateFieldGet(this, _conn).get({
path: path_1.join(path, id),
}));
await this.handleNewItem(list._rev + '', id, item);
}
break;
case Options_1.ItemState.Modified:
{
const { data: item } = await __classPrivateFieldGet(this, _conn).get({
path: path_1.join(path, id),
});
const change = {
resource_id: json_pointer_1.default.get(list, id)._id,
path: '',
// TODO: what is the type the change??
type: 'merge',
body: item,
};
await this.handleItemChange(id, change);
}
break;
case Options_1.ItemState.Handled:
info(`Recoding item ${id} as handled for ${path}`);
// Mark handled for all callbacks?
await __classPrivateFieldGet(this, _meta).setHandled(id, {
onAddItem: { rev },
onItem: { rev },
});
const change = {
resource_id: json_pointer_1.default.get(list, id)._id,
path: '',
// TODO: what is the type the change??
type: 'merge',
body: item,
};
await this.handleItemChange(id, change);
}
break;
case Options_1.ItemState.Handled:
info(`Recoding item ${id} as handled for ${path}`);
// Mark handled for all callbacks?
await __classPrivateFieldGet(this, _meta).setHandled(id, {
onAddItem: { rev },
onItem: { rev },
});
break;
default:
assertNever(state);
break;
default:
assertNever(state);
}
}
catch (err) {
error('Error processing item state "%s" for item %s: %O', state, id, err);
}
});

@@ -432,2 +437,3 @@ }

if (currentItemsNew) {
trace('Treating current list items as new items');
const { data: list } = (await conn.get({

@@ -440,4 +446,6 @@ path,

// ask for states of pre-existing items
trace('Calling onNewList');
const states = await __classPrivateFieldGet(this, _onNewList).call(this, items);
// Set the states
trace('Updating item states based on callback result');
await this.updateItemState(list, items, states);

@@ -444,0 +452,0 @@ }

@@ -18,6 +18,7 @@ "use strict";

};
var _rev, _conn, _path, _tree, _timeout, _wait;
var _rev, _conn, _path, _tree, _timeout, _done, _wait;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Metadata = void 0;
const path_1 = require("path");
const bluebird_1 = __importDefault(require("bluebird"));
const clone_deep_1 = __importDefault(require("clone-deep"));

@@ -43,2 +44,4 @@ const json_pointer_1 = __importDefault(require("json-pointer"));

_timeout.set(this, void 0);
// Init stuff?
_done.set(this, void 0);
_wait.set(this, void 0);

@@ -56,10 +59,21 @@ __classPrivateFieldSet(this, _conn, conn);

}
__classPrivateFieldSet(this, _wait, Promise.resolve());
else {
// Make up a tree? idk man
__classPrivateFieldSet(this, _tree, {});
json_pointer_1.default.set(__classPrivateFieldGet(this, _tree), __classPrivateFieldGet(this, _path), {
_type: 'application/json',
handled: { '*': {} },
});
}
console.dir(__classPrivateFieldGet(this, _tree), { depth: null });
__classPrivateFieldSet(this, _wait, bluebird_1.default.fromCallback((done) => {
__classPrivateFieldSet(this, _done, done);
}));
// TODO: Use timeouts for all updates?
__classPrivateFieldSet(this, _timeout, setTimeout(async () => {
await __classPrivateFieldGet(this, _wait);
trace('Recording rev %d', __classPrivateFieldGet(this, _rev));
__classPrivateFieldSet(this, _wait, __classPrivateFieldGet(this, _conn).put({
path: __classPrivateFieldGet(this, _path),
// TODO: Figure out why tree here causes If-Match error?
//tree: this.#tree,
tree: __classPrivateFieldGet(this, _tree),
data: { rev: __classPrivateFieldGet(this, _rev) },

@@ -121,14 +135,37 @@ }));

async init() {
// Try to get our metadata about this list
try {
const { data: rev } = await __classPrivateFieldGet(this, _conn).get({
path: path_1.join(__classPrivateFieldGet(this, _path), 'rev'),
});
__classPrivateFieldSet(this, _rev, rev);
return true;
// Try to get our metadata about this list
try {
const { data: rev } = await __classPrivateFieldGet(this, _conn).get({
path: path_1.join(__classPrivateFieldGet(this, _path), 'rev'),
});
__classPrivateFieldSet(this, _rev, rev);
__classPrivateFieldGet(this, _done).call(this);
return true;
}
catch (err) {
// Create our metadata?
const { headers: { 'content-location': location }, } = await __classPrivateFieldGet(this, _conn).post({
path: '/resources/',
data: {},
});
await __classPrivateFieldGet(this, _conn).put({
path: __classPrivateFieldGet(this, _path),
tree: __classPrivateFieldGet(this, _tree),
data: { _id: location.substring(1) },
});
await __classPrivateFieldGet(this, _conn).put({
path: __classPrivateFieldGet(this, _path),
tree: __classPrivateFieldGet(this, _tree),
data: {
rev: __classPrivateFieldGet(this, _rev),
},
});
__classPrivateFieldGet(this, _done).call(this);
return false;
}
}
catch (err) {
// Create our metadata?
await __classPrivateFieldGet(this, _conn).put({ path: __classPrivateFieldGet(this, _path), tree: __classPrivateFieldGet(this, _tree), data: {} });
return false;
__classPrivateFieldGet(this, _done).call(this, err);
throw err;
}

@@ -138,3 +175,3 @@ }

exports.Metadata = Metadata;
_rev = new WeakMap(), _conn = new WeakMap(), _path = new WeakMap(), _tree = new WeakMap(), _timeout = new WeakMap(), _wait = new WeakMap();
_rev = new WeakMap(), _conn = new WeakMap(), _path = new WeakMap(), _tree = new WeakMap(), _timeout = new WeakMap(), _done = new WeakMap(), _wait = new WeakMap();
/**

@@ -141,0 +178,0 @@ * @todo: Where in _meta to keep stuff?

{
"name": "@oada/list-lib",
"version": "2.1.3",
"version": "2.1.4",
"description": "Library for processing items in an OADA list",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -285,3 +285,3 @@ import { join } from 'path';

} catch (err) {
error(err);
error('Error getting item state: %O', err);
}

@@ -526,36 +526,45 @@ });

const state = _states[i];
switch (state) {
case ItemState.New:
{
const { data: item } = (await this.#conn.get({
path: join(path, id),
})) as GetResponse<Resource>;
await this.handleNewItem(list._rev + '', id, item);
}
break;
case ItemState.Modified:
{
const { data: item } = await this.#conn.get({
path: join(path, id),
try {
switch (state) {
case ItemState.New:
{
const { data: item } = (await this.#conn.get({
path: join(path, id),
})) as GetResponse<Resource>;
await this.handleNewItem(list._rev + '', id, item);
}
break;
case ItemState.Modified:
{
const { data: item } = await this.#conn.get({
path: join(path, id),
});
const change: Change = {
resource_id: pointer.get(list, id)._id,
path: '',
// TODO: what is the type the change??
type: 'merge',
body: item as {},
};
await this.handleItemChange(id, change);
}
break;
case ItemState.Handled:
info(`Recoding item ${id} as handled for ${path}`);
// Mark handled for all callbacks?
await this.#meta.setHandled(id, {
onAddItem: { rev },
onItem: { rev },
});
const change: Change = {
resource_id: pointer.get(list, id)._id,
path: '',
// TODO: what is the type the change??
type: 'merge',
body: item as {},
};
await this.handleItemChange(id, change);
}
break;
case ItemState.Handled:
info(`Recoding item ${id} as handled for ${path}`);
// Mark handled for all callbacks?
await this.#meta.setHandled(id, {
onAddItem: { rev },
onItem: { rev },
});
break;
default:
assertNever(state);
break;
default:
assertNever(state);
}
} catch (err: unknown) {
error(
'Error processing item state "%s" for item %s: %O',
state,
id,
err
);
}

@@ -589,2 +598,3 @@ });

if (currentItemsNew) {
trace('Treating current list items as new items');
const { data: list } = (await conn.get({

@@ -598,4 +608,6 @@ path,

// ask for states of pre-existing items
trace('Calling onNewList');
const states = await this.#onNewList(items);
// Set the states
trace('Updating item states based on callback result');
await this.updateItemState(list, items, states);

@@ -602,0 +614,0 @@ }

import { join } from 'path';
import Bluebird from 'bluebird';
import clone from 'clone-deep';

@@ -60,2 +61,4 @@ import pointer from 'json-pointer';

#timeout;
// Init stuff?
#done!: (err?: any) => void;
#wait: Promise<unknown>;

@@ -136,11 +139,21 @@

});
} else {
// Make up a tree? idk man
this.#tree = {};
pointer.set(this.#tree, this.#path, {
_type: 'application/json',
handled: { '*': {} },
});
}
this.#wait = Promise.resolve();
console.dir(this.#tree, { depth: null });
this.#wait = Bluebird.fromCallback((done) => {
this.#done = done;
});
// TODO: Use timeouts for all updates?
this.#timeout = setTimeout(async () => {
await this.#wait;
trace('Recording rev %d', this.#rev);
this.#wait = this.#conn.put({
path: this.#path,
// TODO: Figure out why tree here causes If-Match error?
//tree: this.#tree,
tree: this.#tree,
data: { rev: this.#rev },

@@ -158,15 +171,39 @@ });

public async init(): Promise<boolean> {
// Try to get our metadata about this list
try {
const { data: rev } = await this.#conn.get({
path: join(this.#path, 'rev'),
});
this.#rev = rev as string;
return true;
// Try to get our metadata about this list
try {
const { data: rev } = await this.#conn.get({
path: join(this.#path, 'rev'),
});
this.#rev = rev as string;
this.#done();
return true;
} catch (err: unknown) {
// Create our metadata?
const {
headers: { 'content-location': location },
} = await this.#conn.post({
path: '/resources/',
data: {},
});
await this.#conn.put({
path: this.#path,
tree: this.#tree,
data: { _id: location.substring(1) },
});
await this.#conn.put({
path: this.#path,
tree: this.#tree,
data: {
rev: this.#rev,
},
});
this.#done();
return false;
}
} catch (err: unknown) {
// Create our metadata?
await this.#conn.put({ path: this.#path, tree: this.#tree, data: {} });
return false;
this.#done(err);
throw err;
}
}
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc