Compare commits

..

7 Commits

Author SHA1 Message Date
Anselm Eickhoff
934fe4d29b Merge pull request #127 from KyleAMathews/main
fix(jazz-nodejs): also set peersToLoadFrom on newly created accounts
2023-11-07 17:18:02 +00:00
Anselm Eickhoff
408012f2e5 remove redundant peer add 2023-11-07 17:17:41 +00:00
Kyle Mathews
d0078b830e fix(jazz-nodejs): also set peersToLoadFrom on newly created accounts 2023-11-03 14:58:43 -07:00
Anselm Eickhoff
e52948b2b7 Merge pull request #125 from gardencmp/jazz-nodejs
jazz-nodejs MVP
2023-11-02 12:11:56 +00:00
Anselm
53bb1b230b Fix interpolation 2023-11-02 11:53:19 +00:00
Anselm
54e83aeaaa use NOMAD_ADDR secret 2023-11-02 11:43:32 +00:00
Anselm
aa3129cab5 Provide localNode to AccountMigrations 2023-10-27 14:48:36 +01:00
8 changed files with 33 additions and 11 deletions

View File

@@ -115,7 +115,7 @@ jobs:
envsubst '${DOCKER_USER} ${DOCKER_PASSWORD} ${DOCKER_TAG} ${BRANCH_SUFFIX} ${BRANCH_SUBDOMAIN}' < job-template.nomad > job-instance.nomad;
cat job-instance.nomad;
NOMAD_ADDR='http://control1v2-london:4646' nomad job run job-instance.nomad;
NOMAD_ADDR=${{ secrets.NOMAD_ADDR }} nomad job run job-instance.nomad;
working-directory: ./examples/${{ matrix.example }}
# deploy-homepage:
@@ -148,5 +148,5 @@ jobs:
# envsubst '${DOCKER_USER} ${DOCKER_PASSWORD} ${DOCKER_TAG} ${BRANCH_SUFFIX} ${BRANCH_SUBDOMAIN}' < job-template.nomad > job-instance.nomad;
# cat job-instance.nomad;
# NOMAD_ADDR='http://control1v2-london:4646' nomad job run job-instance.nomad;
# NOMAD_ADDR=${{ secrets.NOMAD_ADDR }} nomad job run job-instance.nomad;
# working-directory: ./homepage/homepage-jazz

View File

@@ -1,5 +1,11 @@
# cojson
## 0.6.1
### Patch Changes
- Provide localNode to AccountMigrations
## 0.6.0
### Minor Changes

View File

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

View File

@@ -15,6 +15,7 @@ import {
import { AgentID } from "../ids.js";
import { CoMap } from "./coMap.js";
import { Group, InviteSecret } from "./group.js";
import { LocalNode } from "../index.js";
export function accountHeaderForInitialAgentSecret(
agentSecret: AgentSecret
@@ -169,5 +170,6 @@ export type AccountMigration<
Meta extends AccountMeta = AccountMeta
> = (
account: ControlledAccount<P, R, Meta>,
profile: P
profile: P,
localNode: LocalNode
) => void | Promise<void>;

View File

@@ -74,10 +74,12 @@ export class LocalNode {
Meta extends AccountMeta = AccountMeta
>({
name,
peersToLoadFrom,
migration,
initialAgentSecret = newRandomAgentSecret(),
}: {
name: string;
peersToLoadFrom?: Peer[];
migration?: AccountMigration<P, R, Meta>;
initialAgentSecret?: AgentSecret;
}): Promise<{
@@ -107,8 +109,14 @@ export class LocalNode {
"After creating account"
);
if (peersToLoadFrom) {
for (const peer of peersToLoadFrom) {
nodeWithAccount.syncManager.addPeer(peer);
}
}
if (migration) {
await migration(accountOnNodeWithAccount, profile as P);
await migration(accountOnNodeWithAccount, profile as P, nodeWithAccount);
}
nodeWithAccount.account = new ControlledAccount(
@@ -196,7 +204,8 @@ export class LocalNode {
if (migration) {
await migration(
controlledAccount as ControlledAccount<P, R, Meta>,
profile as P
profile as P,
node
);
node.account = new ControlledAccount(
controlledAccount.core,

View File

@@ -1,5 +1,11 @@
# jazz-autosub
## 0.6.1
### Patch Changes
- Fix wrong import from cojson
## 0.6.0
### Minor Changes

View File

@@ -5,7 +5,7 @@
"types": "src/index.ts",
"type": "module",
"license": "MIT",
"version": "0.6.0",
"version": "0.6.1",
"dependencies": {
"cojson": "^0.6.0",
"cojson-transport-nodejs-ws": "^0.5.1",

View File

@@ -17,8 +17,8 @@ import {
Profile,
SessionID,
cojsonReady,
cojsonInternals
} from "cojson";
import { newRandomSessionID } from "cojson/src/coValueCore";
import { readFile, writeFile } from "node:fs/promises";
if (!("crypto" in globalThis)) {
@@ -72,7 +72,7 @@ export async function createOrResumeWorker<
// TODO: locked sessions similar to browser
const sessionID =
process.env.JAZZ_WORKER_SESSION ||
newRandomSessionID(existingCredentials.accountID);
cojsonInternals.newRandomSessionID(existingCredentials.accountID);
console.log("Loading worker", existingCredentials.accountID);
@@ -94,13 +94,12 @@ export async function createOrResumeWorker<
} else {
const newWorker = await LocalNode.withNewlyCreatedAccount({
name: workerName,
peersToLoadFrom: [wsPeer],
migration,
});
localNode = newWorker.node;
localNode.syncManager.addPeer(wsPeer);
await credentialStorage.save(
workerName,
newWorker.accountID,