Compare commits

..

6 Commits

Author SHA1 Message Date
Anselm
3757d12dc4 Fix loading of accounts 2023-12-20 21:48:01 +00:00
Anselm
fc5b670c73 Publish 2023-12-20 11:33:39 +00:00
Anselm
c8adcc4c47 Fix unused var 2023-12-20 11:32:40 +00:00
Anselm
41a755fe41 publish 2023-12-20 11:17:25 +00:00
Anselm
8def1bb29e IndexedDB & timer perf improvements 2023-12-20 11:04:45 +00:00
Anselm
d379b04e33 Publish 2023-12-18 15:15:27 +00:00
23 changed files with 901 additions and 412 deletions

View File

@@ -11,8 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
# example: ["chat", "todo", "pets", "twit", "file-drop"]
example: ["twit", "chat", "counter-js-auth0"]
example: ["twit", "chat", "counter-js-auth0", "pets", "twit", "file-drop"]
steps:
- uses: actions/checkout@v3
@@ -86,8 +85,7 @@ jobs:
needs: build-examples
strategy:
matrix:
# example: ["chat", "todo", "pets", "twit", "file-drop"]
example: ["twit", "chat", "counter-js-auth0"]
example: ["twit", "chat", "counter-js-auth0", "pets", "twit", "file-drop"]
steps:
- uses: actions/checkout@v3

View File

@@ -1,5 +1,13 @@
# jazz-example-chat
## 0.0.47
### Patch Changes
- Implement passphrase based auth
- Updated dependencies
- jazz-react-auth-passphrase@0.5.1
## 0.0.46
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-chat-passphrase",
"private": true,
"version": "0.0.46",
"version": "0.0.47",
"type": "module",
"scripts": {
"dev": "vite",
@@ -18,7 +18,7 @@
"clsx": "^2.0.0",
"hash-slash": "^0.1.3",
"jazz-react": "^0.5.0",
"jazz-react-auth-passphrase": "^0.5.0",
"jazz-react-auth-passphrase": "^0.5.1",
"lucide-react": "^0.274.0",
"qrcode": "^1.5.3",
"react": "^18.2.0",

View File

@@ -1,5 +1,19 @@
# cojson-storage-indexeddb
## 0.6.2
### Patch Changes
- Fix TypeScript lint
## 0.6.1
### Patch Changes
- IndexedDB & timer perf improvements
- Updated dependencies
- cojson@0.6.4
## 0.6.0
### Minor Changes

View File

@@ -1,11 +1,11 @@
{
"name": "cojson-storage-indexeddb",
"version": "0.6.0",
"version": "0.6.2",
"main": "dist/index.js",
"types": "src/index.ts",
"license": "MIT",
"dependencies": {
"cojson": "^0.6.0",
"cojson": "^0.6.4",
"typescript": "^5.1.6"
},
"devDependencies": {

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,228 @@
/* eslint @typescript-eslint/no-explicit-any: 0 */
const isFunction = (func: any) => typeof func === 'function';
const isObject = (supposedObject: any) =>
typeof supposedObject === 'object' &&
supposedObject !== null &&
!Array.isArray(supposedObject);
const isThenable = (obj: any) => isObject(obj) && isFunction(obj.then);
const identity = (val: any) => val;
export { isObject, isThenable, identity, isFunction };
enum States {
PENDING = 'PENDING',
RESOLVED = 'RESOLVED',
REJECTED = 'REJECTED',
}
interface Handler<T, U> {
onSuccess: HandlerOnSuccess<T, U>;
onFail: HandlerOnFail<U>;
}
type HandlerOnSuccess<T, U = any> = (value: T) => U | Thenable<U>;
type HandlerOnFail<U = any> = (reason: any) => U | Thenable<U>;
type Finally<U> = () => U | Thenable<U>;
interface Thenable<T> {
then<U>(
onSuccess?: HandlerOnSuccess<T, U>,
onFail?: HandlerOnFail<U>,
): Thenable<U>;
then<U>(
onSuccess?: HandlerOnSuccess<T, U>,
onFail?: (reason: any) => void,
): Thenable<U>;
}
type Resolve<R> = (value?: R | Thenable<R>) => void;
type Reject = (value?: any) => void;
export class SyncPromise<T> {
private state: States = States.PENDING;
private handlers: Handler<T, any>[] = [];
private value: T | any;
public constructor(callback: (resolve: Resolve<T>, reject: Reject) => void) {
try {
callback(this.resolve as Resolve<T>, this.reject);
} catch (e) {
this.reject(e);
}
}
private resolve = (value: T) => {
return this.setResult(value, States.RESOLVED);
};
private reject = (reason: any) => {
return this.setResult(reason, States.REJECTED);
};
private setResult = (value: T | any, state: States) => {
const set = () => {
if (this.state !== States.PENDING) {
return null;
}
if (isThenable(value)) {
return (value as Thenable<T>).then(this.resolve, this.reject);
}
this.value = value;
this.state = state;
return this.executeHandlers();
};
set();
};
private executeHandlers = () => {
if (this.state === States.PENDING) {
return null;
}
this.handlers.forEach((handler) => {
if (this.state === States.REJECTED) {
return handler.onFail(this.value);
}
return handler.onSuccess(this.value);
});
this.handlers = [];
};
private attachHandler = (handler: Handler<T, any>) => {
this.handlers = [...this.handlers, handler];
this.executeHandlers();
};
public then<U>(
onSuccess: HandlerOnSuccess<T, U>,
onFail?: HandlerOnFail<U>,
) {
return new SyncPromise<U>((resolve, reject) => {
return this.attachHandler({
onSuccess: (result) => {
try {
return resolve(onSuccess(result));
} catch (e) {
return reject(e);
}
},
onFail: (reason) => {
if (!onFail) {
return reject(reason);
}
try {
return resolve(onFail(reason));
} catch (e) {
return reject(e);
}
},
});
});
}
public catch<U>(onFail: HandlerOnFail<U>) {
return this.then<U>(identity, onFail);
}
// methods
public toString() {
return `[object SyncPromise]`;
}
public finally<U>(cb: Finally<U>) {
return new SyncPromise<U>((resolve, reject) => {
let val: U | any;
let isRejected: boolean;
return this.then(
(value) => {
isRejected = false;
val = value;
return cb();
},
(reason) => {
isRejected = true;
val = reason;
return cb();
},
).then(() => {
if (isRejected) {
return reject(val);
}
return resolve(val);
});
});
}
public spread<U>(handler: (...args: any[]) => U) {
return this.then<U>((collection) => {
if (Array.isArray(collection)) {
return handler(...collection);
}
return handler(collection);
});
}
// static
public static resolve<U = any>(value?: U | Thenable<U>) {
return new SyncPromise<U>((resolve) => {
return resolve(value);
});
}
public static reject<U>(reason?: any) {
return new SyncPromise<U>((_resolve, reject) => {
return reject(reason);
});
}
public static all<U = any>(collection: (U | Thenable<U>)[]) {
return new SyncPromise<U[]>((resolve, reject) => {
if (!Array.isArray(collection)) {
return reject(new TypeError('An array must be provided.'));
}
if (collection.length === 0) {
return resolve([]);
}
let counter = collection.length;
const resolvedCollection: U[] = [];
const tryResolve = (value: U, index: number) => {
counter -= 1;
resolvedCollection[index] = value;
if (counter !== 0) {
return null;
}
return resolve(resolvedCollection);
};
return collection.forEach((item, index) => {
return SyncPromise.resolve(item)
.then((value) => {
return tryResolve(value, index);
})
.catch(reject);
});
});
}
}

View File

@@ -1,5 +1,17 @@
# cojson
## 0.6.4
### Patch Changes
- IndexedDB & timer perf improvements
## 0.6.3
### Patch Changes
- Implement passphrase based auth
## 0.6.2
### Patch Changes

View File

@@ -5,7 +5,7 @@
"types": "src/index.ts",
"type": "module",
"license": "MIT",
"version": "0.6.2",
"version": "0.6.4",
"devDependencies": {
"@noble/curves": "^1.2.0",
"@types/jest": "^29.5.3",

View File

@@ -168,12 +168,12 @@ export class LocalNode {
newRandomSessionID(accountID)
);
const accountPromise = loadingNode.load(accountID);
for (const peer of peersToLoadFrom) {
loadingNode.syncManager.addPeer(peer);
}
const accountPromise = loadingNode.load(accountID);
const account = await accountPromise;
if (account === "unavailable") {

View File

@@ -160,10 +160,8 @@ export function newStreamPair<T>(
// make sure write resolves before corresponding read, but make sure writes are still in order
await lastWritePromise;
lastWritePromise = new Promise((resolve) => {
setTimeout(() => {
enqueue(chunk);
resolve();
});
enqueue(chunk);
resolve();
});
}
},

View File

@@ -195,7 +195,7 @@ export class SyncManager {
return await this.handleKnownState(msg, peer);
}
case "content":
await new Promise<void>((resolve) => setTimeout(resolve, 0));
// await new Promise<void>((resolve) => setTimeout(resolve, 0));
return await this.handleNewContent(msg, peer);
case "done":
return await this.handleUnsubscribe(msg);
@@ -355,9 +355,9 @@ export class SyncManager {
e
);
});
await new Promise<void>((resolve) => {
setTimeout(resolve, 0);
});
// await new Promise<void>((resolve) => {
// setTimeout(resolve, 0);
// });
} catch (e) {
console.error(
new Date(),

View File

@@ -288,9 +288,16 @@ export function autoSub(
if (!effectiveId) return () => {};
// const ctxId = Math.random().toString(16).slice(2);
// let updateN = 0;
const context = new AutoSubContext(node, () => {
const rootResolved = context.values[effectiveId]?.lastLoaded;
// const n = updateN;
// updateN++;
// console.time("AutoSubContext.onUpdate " + n + " " + ctxId);
callback(rootResolved);
// console.timeEnd("AutoSubContext.onUpdate " + n + " " + ctxId);
});
context.autoSub(effectiveId, [], "");

View File

@@ -1,5 +1,11 @@
# jazz-browser-auth-local
## 0.5.1
### Patch Changes
- Implement passphrase based auth
## 0.5.0
### Minor Changes

View File

@@ -1,6 +1,6 @@
{
"name": "jazz-browser-auth-passphrase",
"version": "0.5.0",
"version": "0.5.1",
"main": "dist/index.js",
"types": "src/index.ts",
"license": "MIT",

View File

@@ -1,5 +1,14 @@
# jazz-browser
## 0.6.1
### Patch Changes
- IndexedDB & timer perf improvements
- Updated dependencies
- cojson@0.6.4
- cojson-storage-indexeddb@0.6.1
## 0.6.0
### Minor Changes

View File

@@ -1,12 +1,12 @@
{
"name": "jazz-browser",
"version": "0.6.0",
"version": "0.6.1",
"main": "dist/index.js",
"types": "src/index.ts",
"license": "MIT",
"dependencies": {
"cojson": "^0.6.0",
"cojson-storage-indexeddb": "^0.6.0",
"cojson": "^0.6.4",
"cojson-storage-indexeddb": "^0.6.1",
"jazz-autosub": "^0.6.0",
"typescript": "^5.1.6"
},

View File

@@ -1,5 +1,13 @@
# jazz-autosub
## 0.6.3
### Patch Changes
- IndexedDB & timer perf improvements
- Updated dependencies
- cojson@0.6.4
## 0.6.2
### Patch Changes

View File

@@ -5,9 +5,9 @@
"types": "src/index.ts",
"type": "module",
"license": "MIT",
"version": "0.6.2",
"version": "0.6.3",
"dependencies": {
"cojson": "^0.6.2",
"cojson": "^0.6.4",
"cojson-transport-nodejs-ws": "^0.5.1",
"jazz-autosub": "^0.6.0"
},

View File

@@ -1,5 +1,13 @@
# jazz-react-auth-local
## 0.5.1
### Patch Changes
- Implement passphrase based auth
- Updated dependencies
- jazz-browser-auth-passphrase@0.5.1
## 0.4.17
### Patch Changes

View File

@@ -1,11 +1,11 @@
{
"name": "jazz-react-auth-passphrase",
"version": "0.5.0",
"version": "0.5.1",
"main": "dist/index.js",
"types": "src/index.tsx",
"license": "MIT",
"dependencies": {
"jazz-browser-auth-passphrase": "^0.5.0",
"jazz-browser-auth-passphrase": "^0.5.1",
"jazz-react": "^0.5.1",
"typescript": "^5.1.6"
},

View File

@@ -1,5 +1,14 @@
# jazz-react
## 0.5.2
### Patch Changes
- IndexedDB & timer perf improvements
- Updated dependencies
- cojson@0.6.4
- jazz-browser@0.6.1
## 0.5.1
### Patch Changes

View File

@@ -1,12 +1,12 @@
{
"name": "jazz-react",
"version": "0.5.1",
"version": "0.5.2",
"main": "dist/index.js",
"types": "src/index.ts",
"license": "MIT",
"dependencies": {
"cojson": "^0.6.0",
"jazz-browser": "^0.6.0",
"cojson": "^0.6.4",
"jazz-browser": "^0.6.1",
"typescript": "^5.1.6"
},
"devDependencies": {