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

automerge-repo-solid-primitives

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

automerge-repo-solid-primitives - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

output/src/create-document-store.d.ts

363

output/index.js

@@ -1,41 +0,346 @@

import { createContext as p, useContext as s, createResource as f, createEffect as u, on as a, onCleanup as h } from "solid-js";
const i = p(null);
function m() {
const t = s(i);
if (!t) throw new Error("Please wrap me in a <RepoContext value={repo}>");
return t;
import { createContext as L, useContext as F, createResource as _, createEffect as P, on as $, onCleanup as T, $PROXY as a, $TRACK as N, getListener as j, batch as H, createSignal as W, onMount as z } from "solid-js";
const I = L(null);
function M() {
const e = F(I);
if (!e) throw new Error("Please wrap me in a <RepoContext value={repo}>");
return e;
}
function w(t) {
let n = m(), [c, { mutate: o }] = f(t, async (r) => {
if (!r)
function G(e) {
let n = M(), [r, { mutate: t }] = _(e, async (i) => {
if (!i)
return;
let e = n.find(r);
return await e.whenReady(), e;
let o = n.find(i);
return await o.whenReady(), o;
});
return u(
a([t], () => {
t() || o();
return P(
$([e], () => {
e() || t();
})
), c;
), r;
}
function C(t) {
let n = w(t), [c, { refetch: o, mutate: r }] = f(n, (e) => e.doc());
return u(
a([n], ([e]) => {
e?.on("change", o), e?.on("delete", o), h(() => {
e?.off("change", o), e?.off("delete", o);
function oe(e) {
let n = G(e), [r, { refetch: t, mutate: i }] = _(n, (o) => o.doc());
return P(
$([n], ([o]) => {
o?.on("change", t), o?.on("delete", t), T(() => {
o?.off("change", t), o?.off("delete", t);
});
})
), u(a([n], ([e]) => e || r())), u(a([t], ([e]) => e || r)), [
c,
(e, l) => {
n()?.change(e, l);
), P($([n], ([o]) => o || i())), P($([e], ([o]) => o || i)), [
r,
(o, c) => {
n()?.change(o, c);
}
];
}
const S = Symbol("store-raw"), h = Symbol("store-node"), y = Symbol("store-has"), x = Symbol("store-self");
function C(e) {
let n = e[a];
if (!n && (Object.defineProperty(e, a, {
value: n = new Proxy(e, Z)
}), !Array.isArray(e))) {
const r = Object.keys(e), t = Object.getOwnPropertyDescriptors(e);
for (let i = 0, o = r.length; i < o; i++) {
const c = r[i];
t[c].get && Object.defineProperty(e, c, {
enumerable: t[c].enumerable,
get: t[c].get.bind(n)
});
}
}
return n;
}
function p(e) {
let n;
return e != null && typeof e == "object" && (e[a] || !(n = Object.getPrototypeOf(e)) || n === Object.prototype || Array.isArray(e));
}
function A(e, n = /* @__PURE__ */ new Set()) {
let r, t, i, o;
if (r = e != null && e[S]) return r;
if (!p(e) || n.has(e)) return e;
if (Array.isArray(e)) {
Object.isFrozen(e) ? e = e.slice(0) : n.add(e);
for (let c = 0, f = e.length; c < f; c++)
i = e[c], (t = A(i, n)) !== i && (e[c] = t);
} else {
Object.isFrozen(e) ? e = Object.assign({}, e) : n.add(e);
const c = Object.keys(e), f = Object.getOwnPropertyDescriptors(e);
for (let s = 0, l = c.length; s < l; s++)
o = c[s], !f[o].get && (i = e[o], (t = A(i, n)) !== i && (e[o] = t));
}
return e;
}
function g(e, n) {
let r = e[n];
return r || Object.defineProperty(e, n, {
value: r = /* @__PURE__ */ Object.create(null)
}), r;
}
function E(e, n, r) {
if (e[n]) return e[n];
const [t, i] = W(r, {
equals: !1,
internal: !0
});
return t.$ = i, e[n] = t;
}
function X(e, n) {
const r = Reflect.getOwnPropertyDescriptor(e, n);
return !r || r.get || !r.configurable || n === a || n === h || (delete r.value, delete r.writable, r.get = () => e[a][n]), r;
}
function m(e) {
j() && E(g(e, h), x)();
}
function Y(e) {
return m(e), Reflect.ownKeys(e);
}
const Z = {
get(e, n, r) {
if (n === S) return e;
if (n === a) return r;
if (n === N)
return m(e), r;
const t = g(e, h), i = t[n];
let o = i ? i() : e[n];
if (n === h || n === y || n === "__proto__") return o;
if (!i) {
const c = Object.getOwnPropertyDescriptor(e, n);
j() && (typeof o != "function" || e.hasOwnProperty(n)) && !(c && c.get) && (o = E(t, n, o)());
}
return p(o) ? C(o) : o;
},
has(e, n) {
return n === S || n === a || n === N || n === h || n === y || n === "__proto__" ? !0 : (j() && E(g(e, y), n)(), n in e);
},
set() {
return !0;
},
deleteProperty() {
return !0;
},
ownKeys: Y,
getOwnPropertyDescriptor: X
};
function b(e, n, r, t = !1) {
if (!t && e[n] === r) return;
const i = e[n], o = e.length;
r === void 0 ? (delete e[n], e[y] && e[y][n] && i !== void 0 && e[y][n].$()) : (e[n] = r, e[y] && e[y][n] && i === void 0 && e[y][n].$());
let c = g(e, h), f;
if ((f = E(c, n, i)) && f.$(() => r), Array.isArray(e) && e.length !== o) {
for (let s = e.length; s < o; s++) (f = c[s]) && f.$();
(f = E(c, "length", o)) && f.$(e.length);
}
(f = c[x]) && f.$();
}
function q(e, n) {
const r = Object.keys(n);
for (let t = 0; t < r.length; t += 1) {
const i = r[t];
b(e, i, n[i]);
}
}
function B(e, n) {
if (typeof n == "function" && (n = n(e)), n = A(n), Array.isArray(n)) {
if (e === n) return;
let r = 0, t = n.length;
for (; r < t; r++) {
const i = n[r];
e[r] !== i && b(e, r, i);
}
b(e, "length", t);
} else q(e, n);
}
function O(e, n, r = []) {
let t, i = e;
if (n.length > 1) {
t = n.shift();
const c = typeof t, f = Array.isArray(e);
if (Array.isArray(t)) {
for (let s = 0; s < t.length; s++)
O(e, [t[s]].concat(n), r);
return;
} else if (f && c === "function") {
for (let s = 0; s < e.length; s++)
t(e[s], s) && O(e, [s].concat(n), r);
return;
} else if (f && c === "object") {
const {
from: s = 0,
to: l = e.length - 1,
by: d = 1
} = t;
for (let w = s; w <= l; w += d)
O(e, [w].concat(n), r);
return;
} else if (n.length > 1) {
O(e[t], n, [t].concat(r));
return;
}
i = e[t], r = [t].concat(r);
}
let o = n[0];
typeof o == "function" && (o = o(i, r), o === i) || t === void 0 && o == null || (o = A(o), t === void 0 || p(i) && p(o) && !Array.isArray(o) ? q(i, o) : b(e, t, o));
}
function J(...[e, n]) {
const r = A(e || {}), t = Array.isArray(r), i = C(r);
function o(...c) {
H(() => {
t && c.length === 1 ? B(r, c[0]) : O(r, c);
});
}
return [i, o];
}
const k = /* @__PURE__ */ new WeakMap(), K = {
get(e, n) {
if (n === S) return e;
const r = e[n];
let t;
return p(r) ? k.get(r) || (k.set(r, t = new Proxy(r, K)), t) : r;
},
set(e, n, r) {
return b(e, n, A(r)), !0;
},
deleteProperty(e, n) {
return b(e, n, void 0, !0), !0;
}
};
function Q(e) {
return (n) => {
if (p(n)) {
let r;
(r = k.get(n)) || k.set(n, r = new Proxy(n, K)), e(r);
}
return n;
};
}
function U(e, n, r, t, i) {
let o = n, c = [...e];
for (; ; ) {
let f = c.shift();
if (!c.length) {
if (typeof i == "function" && (t = i(t, f, n, e, o, r)), Array.isArray(r) || typeof r == "number") {
if (typeof f > "u")
throw new Error("cant treat top level as a seq");
f = f;
let [l, d] = Array.isArray(r) ? r : [r, r + 1];
const w = Array.isArray(r) && r.length == 0;
if (!w && (l == null || d == null))
throw new RangeError("it's all or nothing, no half measures");
const R = typeof t > "u";
let D = R ? "del" : w && !R ? "add" : l === d && !R ? "ins" : "replace";
typeof n[f] > "u" && (typeof t == "string" ? n[f] = "" : n[f] = []);
let u = n[f];
if (Array.isArray(u))
switch (D) {
case "add": {
Array.isArray(t) ? u.push(...t) : u.push(t);
return;
}
case "replace":
case "ins": {
Array.isArray(t) ? u.splice(l, d - 1, ...t) : u.splice(l, d - 1, t);
return;
}
case "del": {
u.splice(l, d - l);
return;
}
default:
throw new Error("i don't know what happened");
}
if (typeof u == "string")
switch (D) {
case "add": {
n[f] = u + t;
return;
}
case "replace":
case "ins": {
n[f] = u.slice(0, l) + t + u.slice(d);
return;
}
case "del": {
n[f] = u.slice(0, l) + u.slice(d);
return;
}
default:
throw new Error("i don't know what happened");
}
throw new Error("not implemented");
}
if (typeof f > "u") {
if (typeof r != "string")
throw new Error(`can't index top-level map with ${r}`);
n[r] = t;
return;
}
typeof n[f] > "u" && (n[f] = {}), typeof t > "u" ? delete n[f][r] : n[f][r] = t;
return;
}
if (typeof f > "u")
throw new Error("cant treat top level as a seq");
f = f;
let s = c[0];
if (typeof n[f] > "u")
if (typeof s == "string")
n[f] = {};
else if (typeof s == "number")
n[f] = [];
else
throw new Error(`can't go down this road ${n}.${f}.${s}`);
n = n[f];
}
}
var V = class extends Error {
};
function v(e, n) {
let r = e.path.slice(0, -1), t = e.path[e.path.length - 1];
switch (e.action) {
case "conflict":
case "inc":
case "mark":
case "unmark":
throw new V(`can't handle this: ${e.action}`);
case "del":
return [r, [t, +t + (e.length || 0)]];
case "insert":
return [r, [t, t], e.values];
case "splice":
return [r, [t, t], [e.value]];
case "put":
return [r, t, e.value];
}
}
function ie(e) {
if (!e()?.isReady())
throw new Error("please wait until the handle is ready!!!");
let [n, r] = J(
e().docSync()
);
function t(o) {
e().change(o);
}
function i(o) {
r(ee(o.patches));
}
return z(() => {
e()?.on("change", i);
}), T(() => {
e()?.off("change", i);
}), [n, t];
}
function ee(e) {
return Q((n) => {
for (let r of e) {
const [t, i, o] = v(r);
U(t, n, i, o);
}
});
}
export {
i as RepoContext,
C as useDocument,
w as useHandle,
m as useRepo
I as RepoContext,
ie as createDocumentStore,
oe as useDocument,
G as useHandle,
M as useRepo
};
export { useDocument } from './document.ts';
export { useHandle } from './handle.ts';
export { RepoContext, useRepo } from './repo.ts';
export { createDocumentStore } from './create-document-store.ts';
//# sourceMappingURL=index.d.ts.map

97

package.json
{
"name": "automerge-repo-solid-primitives",
"version": "0.0.1",
"description": "automerge-repo primitives for your solidjs app",
"type": "module",
"main": "output/index.js",
"scripts": {
"mk": "tsc --noEmit && vite build",
"test": "vitest run",
"w": "npm-watch build",
"viz": "VISUALIZE=true vite build"
},
"keywords": [
"solidjs",
"automerge"
],
"author": "chee <chee@rabbits.computer>",
"license": "MIT",
"devDependencies": {
"@automerge/automerge": "^2.2.8",
"@automerge/automerge-repo": "^1.2.1",
"@automerge/automerge-repo-network-broadcastchannel": "^1.2.1",
"@automerge/automerge-repo-network-websocket": "^1.2.1",
"@automerge/automerge-repo-storage-indexeddb": "^1.2.1",
"@solidjs/testing-library": "^0.8.9",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/user-event": "^14.5.2",
"eslint": "^9.8.0",
"eslint-plugin-solid": "^0.14.1",
"globals": "^15.9.0",
"jsdom": "^24.1.1",
"prettier": "^3.3.3",
"rollup-plugin-visualizer": "^5.12.0",
"solid-js": "^1.8.19",
"typescript": "^5.5.4",
"typescript-eslint": "^8.0.1",
"vite": "^5.3.5",
"vite-plugin-dts": "4.0.0-beta.2",
"vite-plugin-solid": "^2.10.2",
"vite-plugin-wasm": "^3.3.0",
"vitest": "^2.0.5"
},
"peerDependencies": {
"@automerge/automerge-repo": "^1.2.1",
"solid-js": "^1.8.19"
}
}
"name": "automerge-repo-solid-primitives",
"version": "0.1.0",
"description": "automerge-repo primitives for your solidjs app",
"type": "module",
"main": "output/index.js",
"keywords": [
"solidjs",
"solid",
"solid-js",
"automerge"
],
"author": "chee <chee@rabbits.computer>",
"license": "MIT",
"devDependencies": {
"@automerge/automerge": "^2.2.8",
"@automerge/automerge-repo": "^1.2.1",
"@automerge/automerge-repo-network-broadcastchannel": "^1.2.1",
"@automerge/automerge-repo-network-websocket": "^1.2.1",
"@automerge/automerge-repo-storage-indexeddb": "^1.2.1",
"@solidjs/testing-library": "^0.8.9",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/user-event": "^14.5.2",
"eslint": "^9.8.0",
"eslint-plugin-solid": "^0.14.1",
"globals": "^15.9.0",
"jsdom": "^24.1.1",
"prettier": "^3.3.3",
"rollup-plugin-visualizer": "^5.12.0",
"solid-js": "^1.8.19",
"typescript": "^5.5.4",
"typescript-eslint": "^8.0.1",
"vite": "^5.3.5",
"vite-plugin-dts": "4.0.0-beta.2",
"vite-plugin-solid": "^2.10.2",
"vite-plugin-wasm": "^3.3.0",
"vitest": "^2.0.5"
},
"peerDependencies": {
"@automerge/automerge-repo": "^1.2.1",
"solid-js": "^1.8.19"
},
"dependencies": {
"cabbages": "^0.0.0"
},
"scripts": {
"mk": "tsc --noEmit && vite build",
"test": "vitest run",
"w": "npm-watch build",
"viz": "VISUALIZE=true vite build"
}
}
export {useDocument} from "./document.ts"
export {useHandle} from "./handle.ts"
export {RepoContext, useRepo} from "./repo.ts"
export {createDocumentStore} from "./create-document-store.ts"

@@ -20,3 +20,8 @@ {

},
"include": ["src/**/*.ts", "test/**/*.tsx", "_workshop/**/*.tsx"]
"include": [
"src/**/*.ts",
"test/**/*.tsx",
"_workshop/**/*.tsx",
"test/document-store.test.tsx"
]
}

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