instant-local-throwaway
Advanced tools
Comparing version 1.1.2 to 1.1.4
@@ -6,3 +6,3 @@ "use strict"; | ||
function isVariable(x) { | ||
return typeof x === "string" && x.startsWith("?"); | ||
return typeof x === 'string' && x.startsWith('?'); | ||
} | ||
@@ -9,0 +9,0 @@ function matchVariable(variable, triplePart, context) { |
@@ -1,2 +0,22 @@ | ||
export * from "./instant"; | ||
import { TransactionChunk } from './instatx'; | ||
import { Config, InstaQL } from './ReactiveDB'; | ||
import * as r from './react'; | ||
import * as instatx from './instatx'; | ||
export declare function id(): string; | ||
export declare function useQuery(q: InstaQL): Object; | ||
export declare function useInit(config: Config): r.InitState; | ||
export declare const auth: { | ||
sendMagicCode({ email }: { | ||
email: string; | ||
}): Promise<any>; | ||
verifyMagicCode({ email, code }: { | ||
email: string; | ||
code: string; | ||
}): Promise<{ | ||
refreshToken: string; | ||
}>; | ||
signOut(): void; | ||
}; | ||
export declare const tx: instatx.EmptyChunk; | ||
export declare function transact(x: TransactionChunk | TransactionChunk[]): void; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -13,7 +13,81 @@ "use strict"; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./instant"), exports); | ||
exports.transact = exports.tx = exports.auth = exports.useInit = exports.useQuery = exports.id = void 0; | ||
const ReactiveDB_1 = __importDefault(require("./ReactiveDB")); | ||
const error_1 = require("./util/error"); | ||
const uuid = __importStar(require("uuid")); | ||
const r = __importStar(require("./react")); | ||
const instatx = __importStar(require("./instatx")); | ||
const authAPI = __importStar(require("./auth")); | ||
// ------ | ||
// Global | ||
let _GLOBAL_DB = null; | ||
function globalDBAsserting() { | ||
(0, error_1.assert)(_GLOBAL_DB != null, 'You must `init` first'); | ||
return _GLOBAL_DB; | ||
} | ||
// ----- | ||
// React | ||
function id() { | ||
return uuid.v4(); | ||
} | ||
exports.id = id; | ||
function useQuery(q) { | ||
return r.useQuery(q, globalDBAsserting()); | ||
} | ||
exports.useQuery = useQuery; | ||
function useInit(config) { | ||
if (!_GLOBAL_DB) { | ||
_GLOBAL_DB = new ReactiveDB_1.default(config); | ||
} | ||
return r.useInit(_GLOBAL_DB); | ||
} | ||
exports.useInit = useInit; | ||
// ----- | ||
// Auth | ||
exports.auth = { | ||
sendMagicCode({ email }) { | ||
const db = globalDBAsserting(); | ||
return authAPI.sendMagicCode({ | ||
apiURI: db.config.apiURI, | ||
appId: db.config.appId, | ||
email: email, | ||
}); | ||
}, | ||
verifyMagicCode({ email, code }) { | ||
const db = globalDBAsserting(); | ||
return authAPI.verifyMagicCode({ | ||
apiURI: db.config.apiURI, | ||
appId: db.config.appId, | ||
email, | ||
code, | ||
}); | ||
}, | ||
signOut() { | ||
const db = globalDBAsserting(); | ||
authAPI.signOut({ appId: db.config.appId }); | ||
}, | ||
}; | ||
// -------- | ||
// Transact | ||
exports.tx = instatx.tx; | ||
function transact(x) { | ||
globalDBAsserting().pushTx(x); | ||
} | ||
exports.transact = transact; | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,2 @@ | ||
export function isOp(x: any): boolean; | ||
export function transform(txs: any, db: any): any; | ||
export const tx: any; | ||
//# sourceMappingURL=instaml.d.ts.map |
@@ -26,27 +26,35 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transform = exports.isOp = exports.tx = void 0; | ||
exports.transform = void 0; | ||
const datalog = __importStar(require("./datalog")); | ||
const instatx_1 = require("./instatx"); | ||
const instaql_1 = require("./instaql"); | ||
function attrK(namespace, ident) { | ||
return `${namespace}/${ident}`; | ||
} | ||
function expandUpdate([namespace, eid, obj], db) { | ||
const triplesToAdd = Object.entries(obj) | ||
.map(([attr, v]) => [eid, `${namespace}/${attr}`, v]) | ||
.concat([[eid, `${namespace}/id`, eid]]); | ||
const attributeSet = new Set(triplesToAdd.map(([_, attr]) => attr)); | ||
const triplesToRemove = datalog | ||
.query({ | ||
find: [eid, "?attr", "?v"], | ||
where: [[eid, "?attr", "?v"]], | ||
}, db) | ||
.filter(([_eid, attr]) => attributeSet.has(attr)); | ||
return triplesToRemove | ||
.sort() | ||
.map((triple) => ["retract-triple", ...triple]) | ||
.concat(triplesToAdd.sort().map((triple) => ["add-triple", ...triple])); | ||
const avs = Object.entries(obj) | ||
.concat([['id', eid]]) | ||
.sort(); | ||
const metaTriples = avs.flatMap(([ident, _]) => { | ||
const k = attrK(namespace, ident); | ||
return [ | ||
[k, 'db/namespace', namespace], | ||
[k, 'db/identity', ident], | ||
[k, 'db/valueType', 'blob'], | ||
[k, 'db/cardinality', 'one'], | ||
]; | ||
}); | ||
const objTriples = avs.map(([ident, v]) => [eid, attrK(namespace, ident), v]); | ||
return metaTriples.concat(objTriples).map((triple) => ['add', ...triple]); | ||
} | ||
function expandLink([namespaceA, aEid, v], db) { | ||
return Object.entries(v).flatMap(([namespaceB, bEid]) => { | ||
const trip = [aEid, (0, instaql_1.makeJoinAttr)(namespaceA, namespaceB), bEid]; | ||
const joinK = (0, instaql_1.makeJoinAttr)(namespaceA, namespaceB); | ||
const trip = [aEid, joinK, bEid]; | ||
return [ | ||
["retract-triple", ...trip], | ||
["add-triple", ...trip], | ||
['add', joinK, 'db/namespace', namespaceA], | ||
['add', joinK, 'db/identity', namespaceB], | ||
['add', joinK, 'db/valueType', 'ref'], | ||
['add', joinK, 'db/cardinality', 'many'], | ||
['add', ...trip], | ||
]; | ||
@@ -57,3 +65,3 @@ }); | ||
return Object.entries(v).map(([namespaceB, bEid]) => { | ||
return ["retract-triple", aEid, (0, instaql_1.makeJoinAttr)(namespaceA, namespaceB), bEid]; | ||
return ['retract', aEid, (0, instaql_1.makeJoinAttr)(namespaceA, namespaceB), bEid]; | ||
}); | ||
@@ -63,27 +71,26 @@ } | ||
const eidTriples = datalog.query({ | ||
find: [eid, "?attr", "?value"], | ||
where: [[eid, "?attr", "?value"]], | ||
find: [eid, '?attr', '?value'], | ||
where: [[eid, '?attr', '?value']], | ||
}, db); | ||
const refTriples = datalog | ||
.query({ | ||
find: ["?eid", "?attr", eid], | ||
where: [["?eid", "?attr", eid]], | ||
}, db) | ||
.filter(([_eid, attr]) => { | ||
return (0, instaql_1.isAttrJoinFor)(attr, namespace); | ||
}); | ||
const refTriples = datalog.query({ | ||
find: ['?eid', '?attr', eid], | ||
where: [ | ||
['?eid', '?attr', eid], | ||
['?attr', 'db/valueType', 'ref'], | ||
], | ||
}, db); | ||
return eidTriples | ||
.concat(refTriples) | ||
.sort() | ||
.map((trip) => ["retract-triple", ...trip]); | ||
.map((trip) => ['retract', ...trip]); | ||
} | ||
function toDatalogTransactions([action, ...args], db) { | ||
switch (action) { | ||
case "update": | ||
case 'update': | ||
return expandUpdate(args, db); | ||
case "link": | ||
case 'link': | ||
return expandLink(args, db); | ||
case "unlink": | ||
case 'unlink': | ||
return expandUnlink(args, db); | ||
case "delete": | ||
case 'delete': | ||
return expandDelete(args, db); | ||
@@ -94,42 +101,10 @@ default: | ||
} | ||
// --- | ||
// 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); | ||
}, | ||
}); | ||
} | ||
exports.tx = createProxy({}); | ||
// --------- | ||
// transform | ||
function isOp(x) { | ||
return Array.isArray(x) && typeof x[0] == "string"; | ||
} | ||
exports.isOp = isOp; | ||
function transform(txs, db) { | ||
return txs.flatMap((op) => toDatalogTransactions(op, db)); | ||
return txs | ||
.flatMap((tx) => (0, instatx_1.getOps)(tx)) | ||
.flatMap((op) => toDatalogTransactions(op, db)); | ||
} | ||
exports.transform = transform; | ||
//# sourceMappingURL=instaml.js.map |
@@ -1,2 +0,1 @@ | ||
export function isAttrJoinFor(attr: any, namespaceB: any): any; | ||
export function makeJoinAttr(namespaceA: any, namespaceB: any): string; | ||
@@ -3,0 +2,0 @@ export function buildWhereQuery({ namespace, where }: { |
@@ -29,3 +29,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.query = exports.enhanceWithDefaults = exports.buildWhereQuery = exports.makeJoinAttr = exports.isAttrJoinFor = void 0; | ||
exports.query = exports.enhanceWithDefaults = exports.buildWhereQuery = exports.makeJoinAttr = void 0; | ||
const datalog = __importStar(require("./datalog")); | ||
@@ -37,3 +37,3 @@ const intersection_1 = __importDefault(require("lodash/intersection")); | ||
function isReverseRelation(x) { | ||
return x.startsWith("_"); | ||
return x.startsWith('_'); | ||
} | ||
@@ -49,6 +49,2 @@ function namespaceFromReverseRelation(x) { | ||
} | ||
function isAttrJoinFor(attr, namespaceB) { | ||
return attr.startsWith("ref$") && attr.endsWith(`$${namespaceB}`); | ||
} | ||
exports.isAttrJoinFor = isAttrJoinFor; | ||
function makeJoinAttr(namespaceA, namespaceB) { | ||
@@ -76,3 +72,3 @@ return `ref$${namespaceA}$${namespaceB}`; | ||
function makeFinalWhereForm(namespace, attr, v) { | ||
if (attr === "id") { | ||
if (attr === 'id') { | ||
return [v, `${datalogNamespace(namespace)}/id`, makeVar(namespace)]; | ||
@@ -84,3 +80,3 @@ } | ||
if (ks.length <= 1) | ||
throw new Error("unbalanced dot syntax"); | ||
throw new Error('unbalanced dot syntax'); | ||
if (ks.length === 2) { | ||
@@ -103,3 +99,3 @@ const [namespace, attr] = ks; | ||
? clauses.flatMap(([k, v]) => { | ||
return buildDatalogWhere([namespace].concat(k.split(".")), v); | ||
return buildDatalogWhere([namespace].concat(k.split('.')), v); | ||
}) | ||
@@ -112,13 +108,10 @@ : [[topVar, `${datalogNamespace(namespace)}/id`, `?$v`]], | ||
return { | ||
find: [eid, "?attr", "?val"], | ||
where: [[eid, "?attr", "?val"]], | ||
find: ['?ident', '?val'], | ||
where: [ | ||
[eid, '?attrK', '?val'], | ||
['?attrK', 'db/valueType', 'blob'], | ||
['?attrK', 'db/identity', '?ident'], | ||
], | ||
}; | ||
} | ||
function attrTupsToMap(attrTups) { | ||
return attrTups.reduce((acc, [_, attr, v]) => { | ||
const [_namespace, k] = attr.split("/"); | ||
acc[k] = v; | ||
return acc; | ||
}, {}); | ||
} | ||
function makeFindRefQuery(from, fromEid, to) { | ||
@@ -130,7 +123,4 @@ return { | ||
} | ||
function hackFilterForJustAttribute(tups) { | ||
return tups.filter(([_, attr]) => !attr.startsWith("ref$")); | ||
} | ||
function getConnections(form) { | ||
return Object.keys(form).filter((x) => x !== "$"); | ||
return Object.keys(form).filter((x) => x !== '$'); | ||
} | ||
@@ -150,4 +140,10 @@ function enhanceWithDefaults(defaults, q, prevConn) { | ||
function namespaceForEid(eid, db) { | ||
const [[_, x]] = getAttrTups(eid, db); | ||
return x.split("/")[0]; | ||
const [namespace] = datalog.query({ | ||
find: '?namespace', | ||
where: [ | ||
[eid, '?attrK', eid], | ||
['?attrK', 'db/namespace', '?namespace'], | ||
], | ||
}, db); | ||
return namespace; | ||
} | ||
@@ -175,8 +171,12 @@ function filterEidsByWhere(eids, query, db) { | ||
} | ||
function getAttrTups(eid, db) { | ||
return hackFilterForJustAttribute(datalog.query(buildAttrTupQuery(eid), db)); | ||
function attrMap(eid, db) { | ||
const avs = datalog.query(buildAttrTupQuery(eid), db); | ||
return avs.reduce((acc, [ident, v]) => { | ||
acc[ident] = v; | ||
return acc; | ||
}, {}); | ||
} | ||
function modifyWithCardinality(objs, query) { | ||
var _a; | ||
if (((_a = query.$) === null || _a === void 0 ? void 0 : _a.cardinality) === "one") { | ||
if (((_a = query.$) === null || _a === void 0 ? void 0 : _a.cardinality) === 'one') { | ||
return objs[0]; | ||
@@ -187,4 +187,3 @@ } | ||
function expandSelect({ namespace, query, db, eid }) { | ||
const attrTups = getAttrTups(eid, db); | ||
const m = attrTupsToMap(attrTups); | ||
const m = attrMap(eid, db); | ||
const connections = getConnections(query); | ||
@@ -191,0 +190,0 @@ connections.forEach((connection) => { |
// 1. patternMatch | ||
function isVariable(x) { | ||
return typeof x === "string" && x.startsWith("?"); | ||
return typeof x === 'string' && x.startsWith('?'); | ||
} | ||
@@ -5,0 +5,0 @@ function matchVariable(variable, triplePart, context) { |
@@ -1,2 +0,22 @@ | ||
export * from "./instant"; | ||
import { TransactionChunk } from './instatx'; | ||
import { Config, InstaQL } from './ReactiveDB'; | ||
import * as r from './react'; | ||
import * as instatx from './instatx'; | ||
export declare function id(): string; | ||
export declare function useQuery(q: InstaQL): Object; | ||
export declare function useInit(config: Config): r.InitState; | ||
export declare const auth: { | ||
sendMagicCode({ email }: { | ||
email: string; | ||
}): Promise<any>; | ||
verifyMagicCode({ email, code }: { | ||
email: string; | ||
code: string; | ||
}): Promise<{ | ||
refreshToken: string; | ||
}>; | ||
signOut(): void; | ||
}; | ||
export declare const tx: instatx.EmptyChunk; | ||
export declare function transact(x: TransactionChunk | TransactionChunk[]): void; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,59 @@ | ||
export * from "./instant"; | ||
import ReactiveDB from './ReactiveDB'; | ||
import { assert } from './util/error'; | ||
import * as uuid from 'uuid'; | ||
import * as r from './react'; | ||
import * as instatx from './instatx'; | ||
import * as authAPI from './auth'; | ||
// ------ | ||
// Global | ||
let _GLOBAL_DB = null; | ||
function globalDBAsserting() { | ||
assert(_GLOBAL_DB != null, 'You must `init` first'); | ||
return _GLOBAL_DB; | ||
} | ||
// ----- | ||
// React | ||
export function id() { | ||
return uuid.v4(); | ||
} | ||
export function useQuery(q) { | ||
return r.useQuery(q, globalDBAsserting()); | ||
} | ||
export function useInit(config) { | ||
if (!_GLOBAL_DB) { | ||
_GLOBAL_DB = new ReactiveDB(config); | ||
} | ||
return r.useInit(_GLOBAL_DB); | ||
} | ||
// ----- | ||
// Auth | ||
export const auth = { | ||
sendMagicCode({ email }) { | ||
const db = globalDBAsserting(); | ||
return authAPI.sendMagicCode({ | ||
apiURI: db.config.apiURI, | ||
appId: db.config.appId, | ||
email: email, | ||
}); | ||
}, | ||
verifyMagicCode({ email, code }) { | ||
const db = globalDBAsserting(); | ||
return authAPI.verifyMagicCode({ | ||
apiURI: db.config.apiURI, | ||
appId: db.config.appId, | ||
email, | ||
code, | ||
}); | ||
}, | ||
signOut() { | ||
const db = globalDBAsserting(); | ||
authAPI.signOut({ appId: db.config.appId }); | ||
}, | ||
}; | ||
// -------- | ||
// Transact | ||
export const tx = instatx.tx; | ||
export function transact(x) { | ||
globalDBAsserting().pushTx(x); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,2 @@ | ||
export function isOp(x: any): boolean; | ||
export function transform(txs: any, db: any): any; | ||
export const tx: any; | ||
//# sourceMappingURL=instaml.d.ts.map |
@@ -1,25 +0,33 @@ | ||
import * as datalog from "./datalog"; | ||
import { isAttrJoinFor, makeJoinAttr } from "./instaql"; | ||
import * as datalog from './datalog'; | ||
import { getOps } from './instatx'; | ||
import { makeJoinAttr } from './instaql'; | ||
function attrK(namespace, ident) { | ||
return `${namespace}/${ident}`; | ||
} | ||
function expandUpdate([namespace, eid, obj], db) { | ||
const triplesToAdd = Object.entries(obj) | ||
.map(([attr, v]) => [eid, `${namespace}/${attr}`, v]) | ||
.concat([[eid, `${namespace}/id`, eid]]); | ||
const attributeSet = new Set(triplesToAdd.map(([_, attr]) => attr)); | ||
const triplesToRemove = datalog | ||
.query({ | ||
find: [eid, "?attr", "?v"], | ||
where: [[eid, "?attr", "?v"]], | ||
}, db) | ||
.filter(([_eid, attr]) => attributeSet.has(attr)); | ||
return triplesToRemove | ||
.sort() | ||
.map((triple) => ["retract-triple", ...triple]) | ||
.concat(triplesToAdd.sort().map((triple) => ["add-triple", ...triple])); | ||
const avs = Object.entries(obj) | ||
.concat([['id', eid]]) | ||
.sort(); | ||
const metaTriples = avs.flatMap(([ident, _]) => { | ||
const k = attrK(namespace, ident); | ||
return [ | ||
[k, 'db/namespace', namespace], | ||
[k, 'db/identity', ident], | ||
[k, 'db/valueType', 'blob'], | ||
[k, 'db/cardinality', 'one'], | ||
]; | ||
}); | ||
const objTriples = avs.map(([ident, v]) => [eid, attrK(namespace, ident), v]); | ||
return metaTriples.concat(objTriples).map((triple) => ['add', ...triple]); | ||
} | ||
function expandLink([namespaceA, aEid, v], db) { | ||
return Object.entries(v).flatMap(([namespaceB, bEid]) => { | ||
const trip = [aEid, makeJoinAttr(namespaceA, namespaceB), bEid]; | ||
const joinK = makeJoinAttr(namespaceA, namespaceB); | ||
const trip = [aEid, joinK, bEid]; | ||
return [ | ||
["retract-triple", ...trip], | ||
["add-triple", ...trip], | ||
['add', joinK, 'db/namespace', namespaceA], | ||
['add', joinK, 'db/identity', namespaceB], | ||
['add', joinK, 'db/valueType', 'ref'], | ||
['add', joinK, 'db/cardinality', 'many'], | ||
['add', ...trip], | ||
]; | ||
@@ -30,3 +38,3 @@ }); | ||
return Object.entries(v).map(([namespaceB, bEid]) => { | ||
return ["retract-triple", aEid, makeJoinAttr(namespaceA, namespaceB), bEid]; | ||
return ['retract', aEid, makeJoinAttr(namespaceA, namespaceB), bEid]; | ||
}); | ||
@@ -36,27 +44,26 @@ } | ||
const eidTriples = datalog.query({ | ||
find: [eid, "?attr", "?value"], | ||
where: [[eid, "?attr", "?value"]], | ||
find: [eid, '?attr', '?value'], | ||
where: [[eid, '?attr', '?value']], | ||
}, db); | ||
const refTriples = datalog | ||
.query({ | ||
find: ["?eid", "?attr", eid], | ||
where: [["?eid", "?attr", eid]], | ||
}, db) | ||
.filter(([_eid, attr]) => { | ||
return isAttrJoinFor(attr, namespace); | ||
}); | ||
const refTriples = datalog.query({ | ||
find: ['?eid', '?attr', eid], | ||
where: [ | ||
['?eid', '?attr', eid], | ||
['?attr', 'db/valueType', 'ref'], | ||
], | ||
}, db); | ||
return eidTriples | ||
.concat(refTriples) | ||
.sort() | ||
.map((trip) => ["retract-triple", ...trip]); | ||
.map((trip) => ['retract', ...trip]); | ||
} | ||
function toDatalogTransactions([action, ...args], db) { | ||
switch (action) { | ||
case "update": | ||
case 'update': | ||
return expandUpdate(args, db); | ||
case "link": | ||
case 'link': | ||
return expandLink(args, db); | ||
case "unlink": | ||
case 'unlink': | ||
return expandUnlink(args, db); | ||
case "delete": | ||
case 'delete': | ||
return expandDelete(args, db); | ||
@@ -67,40 +74,9 @@ default: | ||
} | ||
// --- | ||
// 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 const tx = createProxy({}); | ||
// --------- | ||
// transform | ||
export function isOp(x) { | ||
return Array.isArray(x) && typeof x[0] == "string"; | ||
} | ||
export function transform(txs, db) { | ||
return txs.flatMap((op) => toDatalogTransactions(op, db)); | ||
return txs | ||
.flatMap((tx) => getOps(tx)) | ||
.flatMap((op) => toDatalogTransactions(op, db)); | ||
} | ||
//# sourceMappingURL=instaml.js.map |
@@ -1,2 +0,1 @@ | ||
export function isAttrJoinFor(attr: any, namespaceB: any): any; | ||
export function makeJoinAttr(namespaceA: any, namespaceB: any): string; | ||
@@ -3,0 +2,0 @@ export function buildWhereQuery({ namespace, where }: { |
@@ -1,3 +0,3 @@ | ||
import * as datalog from "./datalog"; | ||
import intersection from "lodash/intersection"; | ||
import * as datalog from './datalog'; | ||
import intersection from 'lodash/intersection'; | ||
function makeVar(k) { | ||
@@ -7,3 +7,3 @@ return `?${datalogNamespace(k)}`; | ||
function isReverseRelation(x) { | ||
return x.startsWith("_"); | ||
return x.startsWith('_'); | ||
} | ||
@@ -19,5 +19,2 @@ function namespaceFromReverseRelation(x) { | ||
} | ||
export function isAttrJoinFor(attr, namespaceB) { | ||
return attr.startsWith("ref$") && attr.endsWith(`$${namespaceB}`); | ||
} | ||
export function makeJoinAttr(namespaceA, namespaceB) { | ||
@@ -44,3 +41,3 @@ return `ref$${namespaceA}$${namespaceB}`; | ||
function makeFinalWhereForm(namespace, attr, v) { | ||
if (attr === "id") { | ||
if (attr === 'id') { | ||
return [v, `${datalogNamespace(namespace)}/id`, makeVar(namespace)]; | ||
@@ -52,3 +49,3 @@ } | ||
if (ks.length <= 1) | ||
throw new Error("unbalanced dot syntax"); | ||
throw new Error('unbalanced dot syntax'); | ||
if (ks.length === 2) { | ||
@@ -71,3 +68,3 @@ const [namespace, attr] = ks; | ||
? clauses.flatMap(([k, v]) => { | ||
return buildDatalogWhere([namespace].concat(k.split(".")), v); | ||
return buildDatalogWhere([namespace].concat(k.split('.')), v); | ||
}) | ||
@@ -79,13 +76,10 @@ : [[topVar, `${datalogNamespace(namespace)}/id`, `?$v`]], | ||
return { | ||
find: [eid, "?attr", "?val"], | ||
where: [[eid, "?attr", "?val"]], | ||
find: ['?ident', '?val'], | ||
where: [ | ||
[eid, '?attrK', '?val'], | ||
['?attrK', 'db/valueType', 'blob'], | ||
['?attrK', 'db/identity', '?ident'], | ||
], | ||
}; | ||
} | ||
function attrTupsToMap(attrTups) { | ||
return attrTups.reduce((acc, [_, attr, v]) => { | ||
const [_namespace, k] = attr.split("/"); | ||
acc[k] = v; | ||
return acc; | ||
}, {}); | ||
} | ||
function makeFindRefQuery(from, fromEid, to) { | ||
@@ -97,7 +91,4 @@ return { | ||
} | ||
function hackFilterForJustAttribute(tups) { | ||
return tups.filter(([_, attr]) => !attr.startsWith("ref$")); | ||
} | ||
function getConnections(form) { | ||
return Object.keys(form).filter((x) => x !== "$"); | ||
return Object.keys(form).filter((x) => x !== '$'); | ||
} | ||
@@ -116,4 +107,10 @@ export function enhanceWithDefaults(defaults, q, prevConn) { | ||
function namespaceForEid(eid, db) { | ||
const [[_, x]] = getAttrTups(eid, db); | ||
return x.split("/")[0]; | ||
const [namespace] = datalog.query({ | ||
find: '?namespace', | ||
where: [ | ||
[eid, '?attrK', eid], | ||
['?attrK', 'db/namespace', '?namespace'], | ||
], | ||
}, db); | ||
return namespace; | ||
} | ||
@@ -141,8 +138,12 @@ function filterEidsByWhere(eids, query, db) { | ||
} | ||
function getAttrTups(eid, db) { | ||
return hackFilterForJustAttribute(datalog.query(buildAttrTupQuery(eid), db)); | ||
function attrMap(eid, db) { | ||
const avs = datalog.query(buildAttrTupQuery(eid), db); | ||
return avs.reduce((acc, [ident, v]) => { | ||
acc[ident] = v; | ||
return acc; | ||
}, {}); | ||
} | ||
function modifyWithCardinality(objs, query) { | ||
var _a; | ||
if (((_a = query.$) === null || _a === void 0 ? void 0 : _a.cardinality) === "one") { | ||
if (((_a = query.$) === null || _a === void 0 ? void 0 : _a.cardinality) === 'one') { | ||
return objs[0]; | ||
@@ -153,4 +154,3 @@ } | ||
function expandSelect({ namespace, query, db, eid }) { | ||
const attrTups = getAttrTups(eid, db); | ||
const m = attrTupsToMap(attrTups); | ||
const m = attrMap(eid, db); | ||
const connections = getConnections(query); | ||
@@ -157,0 +157,0 @@ connections.forEach((connection) => { |
@@ -1,2 +0,2 @@ | ||
type Op = [string, string, string, any]; | ||
export type Op = [string, string, string, any]; | ||
@@ -11,7 +11,7 @@ export interface TransactionChunk { | ||
interface NamespacedChunk { | ||
export interface NamespacedChunk { | ||
[id: string]: TransactionChunk; | ||
} | ||
interface EmptyChunk { | ||
export interface EmptyChunk { | ||
[namespace: string]: NamespacedChunk; | ||
@@ -27,3 +27,3 @@ } | ||
get: (_target, k: keyof TransactionChunk) => { | ||
if (k === '__ops') return prevOps; | ||
if (k === "__ops") return prevOps; | ||
return (v: any) => { | ||
@@ -30,0 +30,0 @@ return transactionChunk(namespace, id, [ |
{ | ||
"name": "instant-local-throwaway", | ||
"version": "1.1.2", | ||
"version": "1.1.4", | ||
"description": "This is an experiment for instant", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
934292
120
18342