Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

instant-local-throwaway

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

instant-local-throwaway - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

43

__tests__/instaml.test.js
import { createDB, save } from "../src/db";
import { transformRemoves, transformSaves } from "../src/instaml";
import { tx, transform } from "../src/instaml";
import { query } from "../src/instaql";

@@ -8,8 +8,4 @@

expect(
transformSaves(
[
{
users: { id: "1", update: { name: "Stepan", twitter: "stopachka" } },
},
],
transform(
[tx.users["1"].update({ name: "Stepan", twitter: "stopachka" })],
db

@@ -25,2 +21,13 @@ )

test("Link", () => {
const db = createDB([
["1", "users/name", "Stopa"],
["2", "bookshelves/title", "Favs"],
]);
expect(transform([tx.users["1"].link({ bookshelves: "2" })], db)).toEqual([
["retract-triple", "1", "ref$users$bookshelves", "2"],
["add-triple", "1", "ref$users$bookshelves", "2"],
]);
});
test("Unlink", () => {

@@ -32,5 +39,5 @@ const db = createDB([

]);
expect(
transformSaves([{ users: { id: "1", unlink: { bookshelves: "2" } } }], db)
).toEqual([["retract-triple", "1", "ref$users$bookshelves", "2"]]);
expect(transform([tx.users["1"].unlink({ bookshelves: "2" })], db)).toEqual([
["retract-triple", "1", "ref$users$bookshelves", "2"],
]);
});

@@ -44,3 +51,3 @@

]);
expect(transformRemoves([{ bookshelves: "2" }], db)).toEqual([
expect(transform([tx.bookshelves["2"].delete()], db)).toEqual([
["retract-triple", "1", "ref$users$bookshelves", "2"],

@@ -53,13 +60,9 @@ ["retract-triple", "2", "bookshelves/title", "Favs"],

const db = createDB([]);
const userTx = tx.user.a;
save(
transformSaves(
transform(
[
{ bookshelf: { id: "b", update: { title: "Favs" } } },
{
user: {
id: "a",
update: { name: "Stopa" },
link: { bookshelf: "b" },
},
},
tx.bookshelf.b.update({ title: "Favs" }),
userTx.update({ name: "Stopa" }),
userTx.link({ bookshelf: "b" }),
],

@@ -66,0 +69,0 @@ db

@@ -1,3 +0,4 @@

export function transformSaves(saveTransactions: any, db: any): any;
export function transformRemoves(removeTransactions: any, db: any): any;
export function isOp(x: any): boolean;
export function transform(txs: any, db: any): any;
export const tx: any;
//# sourceMappingURL=instaml.d.ts.map

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.transformRemoves = exports.transformSaves = void 0;
exports.transform = exports.isOp = exports.tx = void 0;
const datalog = __importStar(require("./datalog"));

@@ -46,12 +46,15 @@ const instaql_1 = require("./instaql");

}
function expandLink([namespaceA, aEid, namespaceB, bEid], db) {
const triple = [aEid, (0, instaql_1.makeJoinAttr)(namespaceA, namespaceB), bEid];
return [
["retract-triple", ...triple],
["add-triple", ...triple],
];
function expandLink([namespaceA, aEid, v], db) {
return Object.entries(v).flatMap(([namespaceB, bEid]) => {
const trip = [aEid, (0, instaql_1.makeJoinAttr)(namespaceA, namespaceB), bEid];
return [
["retract-triple", ...trip],
["add-triple", ...trip],
];
});
}
function expandUnlink([namespaceA, aEid, namespaceB, bEid], db) {
const triple = [aEid, (0, instaql_1.makeJoinAttr)(namespaceA, namespaceB), bEid];
return [["retract-triple", ...triple]];
function expandUnlink([namespaceA, aEid, v], db) {
return Object.entries(v).map(([namespaceB, bEid]) => {
return ["retract-triple", aEid, (0, instaql_1.makeJoinAttr)(namespaceA, namespaceB), bEid];
});
}

@@ -90,38 +93,42 @@ function expandDelete([namespace, eid], db) {

}
function saveToV1Transactions(v2) {
return Object.entries(v2).reduce((result, [table, params]) => {
const { id, update, link, unlink } = params;
if (!id) {
throw new Error(`Missing \`id\` field for ${table}`);
}
return result.concat([
update && [["update", table, id, update]],
unlink &&
Object.keys(unlink).map((relation) => {
const relationId = unlink[relation];
return ["unlink", table, id, relation, relationId];
}),
link &&
Object.keys(link).map((relation) => {
const relationId = link[relation];
return ["link", table, id, relation, relationId];
}),
]
.filter((x) => x)
.flatMap((x) => x));
}, []);
// ---
// tx
const ops = {
update(opts, v) {
return ["update", opts.namespace, opts.id, v];
},
link(opts, v) {
return ["link", opts.namespace, opts.id, v];
},
unlink(opts, v) {
return ["unlink", opts.namespace, opts.id, v];
},
delete(opts, v) {
return ["delete", opts.namespace, opts.id, v];
},
};
function createProxy(opts) {
return new Proxy(opts, {
get(target, k) {
if (!opts.namespace) {
return createProxy(Object.assign({ namespace: k }, target));
}
if (!opts.id) {
return createProxy(Object.assign({ id: k }, target));
}
return ops[k].bind(null, target);
},
});
}
function transformSaves(saveTransactions, db) {
return saveTransactions.flatMap((v2) => saveToV1Transactions(v2).flatMap((v2) => toDatalogTransactions(v2, db)));
exports.tx = createProxy({});
// ---------
// transform
function isOp(x) {
return Array.isArray(x) && typeof x[0] == "string";
}
exports.transformSaves = transformSaves;
function deleteToV1Transactions(v2) {
return Object.entries(v2).map(([table, id]) => {
return ["delete", table, id];
}, []);
exports.isOp = isOp;
function transform(txs, db) {
return txs.flatMap((op) => toDatalogTransactions(op, db));
}
function transformRemoves(removeTransactions, db) {
return removeTransactions.flatMap((v2) => deleteToV1Transactions(v2).flatMap((v2) => toDatalogTransactions(v2, db)));
}
exports.transformRemoves = transformRemoves;
exports.transform = transform;
//# sourceMappingURL=instaml.js.map

@@ -13,5 +13,6 @@ declare type Config = {

};
export declare function save(...saveTransactions: any[]): void;
export declare function remove(...removeTransactions: any[]): void;
export declare const tx: any;
export declare function transact(ts: any): void;
export declare function id(): string;
export {};
//# sourceMappingURL=instant.d.ts.map

@@ -29,8 +29,9 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.remove = exports.save = exports.useQuery = exports.useInit = void 0;
exports.id = exports.transact = exports.tx = exports.useQuery = exports.useInit = void 0;
const react_1 = require("react");
const isEqual_1 = __importDefault(require("lodash/isEqual"));
const uuid = __importStar(require("uuid"));
const tripleDB = __importStar(require("./db"));
const instaql = __importStar(require("./instaql"));
const instaml = __importStar(require("./instaml"));
const isEqual_1 = __importDefault(require("lodash/isEqual"));
let _id = 0;

@@ -104,6 +105,8 @@ const db = {

exports.useQuery = useQuery;
function transact(ts, currDB) {
exports.tx = instaml.tx;
function transact(ts) {
var _a;
const newDb = Object.assign({}, currDB);
tripleDB.save(ts, newDb);
const newDb = Object.assign({}, db._current);
const datalogTs = instaml.transform(instaml.isOp(ts) ? [ts] : ts, newDb);
tripleDB.save(datalogTs, newDb);
fetch("https://instant-server.herokuapp.com/api/transact", {

@@ -115,3 +118,3 @@ method: "POST",

},
body: JSON.stringify({ transactions: ts }),
body: JSON.stringify({ transactions: datalogTs }),
}).catch((err) => {

@@ -122,12 +125,7 @@ console.error("uh oh, tell Stopa!", err);

}
function save(...saveTransactions) {
const currDB = db._current;
transact(instaml.transformSaves(saveTransactions, currDB), currDB);
exports.transact = transact;
function id() {
return uuid.v4();
}
exports.save = save;
function remove(...removeTransactions) {
const currDB = db._current;
transact(instaml.transformRemoves(removeTransactions, currDB), currDB);
}
exports.remove = remove;
exports.id = id;
//# sourceMappingURL=instant.js.map

@@ -1,3 +0,4 @@

export function transformSaves(saveTransactions: any, db: any): any;
export function transformRemoves(removeTransactions: any, db: any): any;
export function isOp(x: any): boolean;
export function transform(txs: any, db: any): any;
export const tx: any;
//# sourceMappingURL=instaml.d.ts.map

@@ -19,12 +19,15 @@ import * as datalog from "./datalog";

}
function expandLink([namespaceA, aEid, namespaceB, bEid], db) {
const triple = [aEid, makeJoinAttr(namespaceA, namespaceB), bEid];
return [
["retract-triple", ...triple],
["add-triple", ...triple],
];
function expandLink([namespaceA, aEid, v], db) {
return Object.entries(v).flatMap(([namespaceB, bEid]) => {
const trip = [aEid, makeJoinAttr(namespaceA, namespaceB), bEid];
return [
["retract-triple", ...trip],
["add-triple", ...trip],
];
});
}
function expandUnlink([namespaceA, aEid, namespaceB, bEid], db) {
const triple = [aEid, makeJoinAttr(namespaceA, namespaceB), bEid];
return [["retract-triple", ...triple]];
function expandUnlink([namespaceA, aEid, v], db) {
return Object.entries(v).map(([namespaceB, bEid]) => {
return ["retract-triple", aEid, makeJoinAttr(namespaceA, namespaceB), bEid];
});
}

@@ -63,36 +66,40 @@ function expandDelete([namespace, eid], db) {

}
function saveToV1Transactions(v2) {
return Object.entries(v2).reduce((result, [table, params]) => {
const { id, update, link, unlink } = params;
if (!id) {
throw new Error(`Missing \`id\` field for ${table}`);
}
return result.concat([
update && [["update", table, id, update]],
unlink &&
Object.keys(unlink).map((relation) => {
const relationId = unlink[relation];
return ["unlink", table, id, relation, relationId];
}),
link &&
Object.keys(link).map((relation) => {
const relationId = link[relation];
return ["link", table, id, relation, relationId];
}),
]
.filter((x) => x)
.flatMap((x) => x));
}, []);
// ---
// tx
const ops = {
update(opts, v) {
return ["update", opts.namespace, opts.id, v];
},
link(opts, v) {
return ["link", opts.namespace, opts.id, v];
},
unlink(opts, v) {
return ["unlink", opts.namespace, opts.id, v];
},
delete(opts, v) {
return ["delete", opts.namespace, opts.id, v];
},
};
function createProxy(opts) {
return new Proxy(opts, {
get(target, k) {
if (!opts.namespace) {
return createProxy(Object.assign({ namespace: k }, target));
}
if (!opts.id) {
return createProxy(Object.assign({ id: k }, target));
}
return ops[k].bind(null, target);
},
});
}
export function transformSaves(saveTransactions, db) {
return saveTransactions.flatMap((v2) => saveToV1Transactions(v2).flatMap((v2) => toDatalogTransactions(v2, db)));
export const tx = createProxy({});
// ---------
// transform
export function isOp(x) {
return Array.isArray(x) && typeof x[0] == "string";
}
function deleteToV1Transactions(v2) {
return Object.entries(v2).map(([table, id]) => {
return ["delete", table, id];
}, []);
export function transform(txs, db) {
return txs.flatMap((op) => toDatalogTransactions(op, db));
}
export function transformRemoves(removeTransactions, db) {
return removeTransactions.flatMap((v2) => deleteToV1Transactions(v2).flatMap((v2) => toDatalogTransactions(v2, db)));
}
//# sourceMappingURL=instaml.js.map

@@ -13,5 +13,6 @@ declare type Config = {

};
export declare function save(...saveTransactions: any[]): void;
export declare function remove(...removeTransactions: any[]): void;
export declare const tx: any;
export declare function transact(ts: any): void;
export declare function id(): string;
export {};
//# sourceMappingURL=instant.d.ts.map
import { useState, useEffect } from "react";
import deepEqual from "lodash/isEqual";
import * as uuid from "uuid";
import * as tripleDB from "./db";
import * as instaql from "./instaql";
import * as instaml from "./instaml";
import deepEqual from "lodash/isEqual";
let _id = 0;

@@ -72,6 +73,8 @@ const db = {

}
function transact(ts, currDB) {
export const tx = instaml.tx;
export function transact(ts) {
var _a;
const newDb = Object.assign({}, currDB);
tripleDB.save(ts, newDb);
const newDb = Object.assign({}, db._current);
const datalogTs = instaml.transform(instaml.isOp(ts) ? [ts] : ts, newDb);
tripleDB.save(datalogTs, newDb);
fetch("https://instant-server.herokuapp.com/api/transact", {

@@ -83,3 +86,3 @@ method: "POST",

},
body: JSON.stringify({ transactions: ts }),
body: JSON.stringify({ transactions: datalogTs }),
}).catch((err) => {

@@ -90,10 +93,5 @@ console.error("uh oh, tell Stopa!", err);

}
export function save(...saveTransactions) {
const currDB = db._current;
transact(instaml.transformSaves(saveTransactions, currDB), currDB);
export function id() {
return uuid.v4();
}
export function remove(...removeTransactions) {
const currDB = db._current;
transact(instaml.transformRemoves(removeTransactions, currDB), currDB);
}
//# sourceMappingURL=instant.js.map
{
"name": "instant-local-throwaway",
"version": "1.0.7",
"version": "1.0.8",
"description": "This is an experiment for instant",

@@ -23,2 +23,3 @@ "main": "dist/index.js",

"@types/react": "^18.0.9",
"@types/uuid": "^8.3.4",
"babel-jest": "^27.5.1",

@@ -33,3 +34,6 @@ "camelcase": "^5.3.1",

"react": ">=16"
},
"dependencies": {
"uuid": "^8.3.2"
}
}

@@ -24,13 +24,16 @@ import * as datalog from "./datalog";

}
function expandLink([namespaceA, aEid, namespaceB, bEid], db) {
const triple = [aEid, makeJoinAttr(namespaceA, namespaceB), bEid];
return [
["retract-triple", ...triple],
["add-triple", ...triple],
];
function expandLink([namespaceA, aEid, v], db) {
return Object.entries(v).flatMap(([namespaceB, bEid]) => {
const trip = [aEid, makeJoinAttr(namespaceA, namespaceB), bEid];
return [
["retract-triple", ...trip],
["add-triple", ...trip],
];
});
}
function expandUnlink([namespaceA, aEid, namespaceB, bEid], db) {
const triple = [aEid, makeJoinAttr(namespaceA, namespaceB), bEid];
return [["retract-triple", ...triple]];
function expandUnlink([namespaceA, aEid, v], db) {
return Object.entries(v).map(([namespaceB, bEid]) => {
return ["retract-triple", aEid, makeJoinAttr(namespaceA, namespaceB), bEid];
});
}

@@ -78,44 +81,45 @@

function saveToV1Transactions(v2) {
return Object.entries(v2).reduce((result, [table, params]) => {
const { id, update, link, unlink } = params;
if (!id) {
throw new Error(`Missing \`id\` field for ${table}`);
}
return result.concat(
[
update && [["update", table, id, update]],
unlink &&
Object.keys(unlink).map((relation) => {
const relationId = unlink[relation];
return ["unlink", table, id, relation, relationId];
}),
link &&
Object.keys(link).map((relation) => {
const relationId = link[relation];
return ["link", table, id, relation, relationId];
}),
]
.filter((x) => x)
.flatMap((x) => x)
);
}, []);
}
// ---
// tx
export function transformSaves(saveTransactions, db) {
return saveTransactions.flatMap((v2) =>
saveToV1Transactions(v2).flatMap((v2) => toDatalogTransactions(v2, db))
);
const ops = {
update(opts, v) {
return ["update", opts.namespace, opts.id, v];
},
link(opts, v) {
return ["link", opts.namespace, opts.id, v];
},
unlink(opts, v) {
return ["unlink", opts.namespace, opts.id, v];
},
delete(opts, v) {
return ["delete", opts.namespace, opts.id, v];
},
};
function createProxy(opts) {
return new Proxy(opts, {
get(target, k) {
if (!opts.namespace) {
return createProxy({ namespace: k, ...target });
}
if (!opts.id) {
return createProxy({ id: k, ...target });
}
return ops[k].bind(null, target);
},
});
}
function deleteToV1Transactions(v2) {
return Object.entries(v2).map(([table, id]) => {
return ["delete", table, id];
}, []);
export const tx = createProxy({});
// ---------
// transform
export function isOp(x) {
return Array.isArray(x) && typeof x[0] == "string";
}
export function transformRemoves(removeTransactions, db) {
return removeTransactions.flatMap((v2) =>
deleteToV1Transactions(v2).flatMap((v2) => toDatalogTransactions(v2, db))
);
export function transform(txs, db) {
return txs.flatMap((op) => toDatalogTransactions(op, db));
}
import { useState, useEffect } from "react";
import deepEqual from "lodash/isEqual";
import * as uuid from "uuid";

@@ -7,4 +9,2 @@ import * as tripleDB from "./db";

import deepEqual from "lodash/isEqual";
type Config = {

@@ -96,5 +96,8 @@ token: string;

function transact(ts: any[], currDB: any) {
const newDb = { ...currDB };
tripleDB.save(ts, newDb);
export const tx = instaml.tx;
export function transact(ts: any) {
const newDb = { ...db._current };
const datalogTs = instaml.transform(instaml.isOp(ts) ? [ts] : ts, newDb);
tripleDB.save(datalogTs, newDb);
fetch("https://instant-server.herokuapp.com/api/transact", {

@@ -106,3 +109,3 @@ method: "POST",

},
body: JSON.stringify({ transactions: ts }),
body: JSON.stringify({ transactions: datalogTs }),
}).catch((err) => {

@@ -114,10 +117,4 @@ console.error("uh oh, tell Stopa!", err);

export function save(...saveTransactions: any[]) {
const currDB = db._current;
transact(instaml.transformSaves(saveTransactions, currDB), currDB);
export function id() {
return uuid.v4();
}
export function remove(...removeTransactions: any[]) {
const currDB = db._current;
transact(instaml.transformRemoves(removeTransactions, currDB), currDB);
}

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

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