jazz-tools 0.7.35-unique.2 → 0.7.35
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-test.log +44 -57
- package/CHANGELOG.md +8 -10
- package/dist/coValues/account.js +35 -20
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +19 -14
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +33 -32
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +37 -15
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/extensions/imageDef.js +8 -3
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +23 -20
- package/dist/coValues/group.js.map +1 -1
- package/dist/implementation/devtoolsFormatters.js +1 -0
- package/dist/implementation/devtoolsFormatters.js.map +1 -1
- package/dist/implementation/refs.js +0 -3
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/schema.js.map +1 -1
- package/dist/implementation/subscriptionScope.js +5 -8
- package/dist/implementation/subscriptionScope.js.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.js +0 -1
- package/dist/internal.js.map +1 -1
- package/dist/tests/coList.test.js +15 -23
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +216 -75
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +59 -26
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/deepLoading.test.js +41 -28
- package/dist/tests/deepLoading.test.js.map +1 -1
- package/dist/tests/groupsAndAccounts.test.js +22 -8
- package/dist/tests/groupsAndAccounts.test.js.map +1 -1
- package/package.json +3 -3
- package/src/coValues/account.ts +28 -5
- package/src/coValues/coList.ts +4 -4
- package/src/coValues/coMap.ts +54 -46
- package/src/coValues/coStream.ts +30 -5
- package/src/coValues/group.ts +2 -2
- package/src/coValues/interfaces.ts +4 -4
- package/src/implementation/devtoolsFormatters.ts +1 -0
- package/src/implementation/schema.ts +1 -0
- package/src/index.ts +1 -9
- package/src/internal.ts +0 -2
- package/src/tests/coList.test.ts +14 -30
- package/src/tests/coMap.test.ts +158 -49
- package/src/tests/coStream.test.ts +74 -27
- package/src/tests/deepLoading.test.ts +18 -22
- package/tsconfig.json +1 -1
- package/dist/implementation/createContext.js +0 -94
- package/dist/implementation/createContext.js.map +0 -1
- package/src/implementation/createContext.ts +0 -162
@@ -1,94 +0,0 @@
|
|
1
|
-
import { cojsonInternals, LocalNode, } from "cojson";
|
2
|
-
import { Account } from "../internal.js";
|
3
|
-
export const fixedCredentialsAuth = (credentials) => {
|
4
|
-
return {
|
5
|
-
start: async () => ({
|
6
|
-
type: "existing",
|
7
|
-
credentials,
|
8
|
-
onSuccess: () => { },
|
9
|
-
onError: () => { },
|
10
|
-
}),
|
11
|
-
};
|
12
|
-
};
|
13
|
-
export async function randomSessionProvider(accountID) {
|
14
|
-
return {
|
15
|
-
sessionID: cojsonInternals.newRandomSessionID(accountID),
|
16
|
-
sessionDone: () => { },
|
17
|
-
};
|
18
|
-
}
|
19
|
-
export async function createJazzContext({ AccountSchema = Account, auth, sessionProvider, peersToLoadFrom, crypto, }) {
|
20
|
-
// eslint-disable-next-line no-constant-condition
|
21
|
-
while (true) {
|
22
|
-
const authResult = await auth.start(crypto);
|
23
|
-
if (authResult.type === "existing") {
|
24
|
-
try {
|
25
|
-
const { sessionID, sessionDone } = await sessionProvider(authResult.credentials.accountID);
|
26
|
-
try {
|
27
|
-
const node = await LocalNode.withLoadedAccount({
|
28
|
-
accountID: authResult.credentials
|
29
|
-
.accountID,
|
30
|
-
accountSecret: authResult.credentials.secret,
|
31
|
-
sessionID: sessionID,
|
32
|
-
peersToLoadFrom: peersToLoadFrom,
|
33
|
-
crypto: crypto,
|
34
|
-
migration: async (rawAccount, _node, creationProps) => {
|
35
|
-
const account = new AccountSchema({
|
36
|
-
fromRaw: rawAccount,
|
37
|
-
});
|
38
|
-
await account.migrate?.(creationProps);
|
39
|
-
},
|
40
|
-
});
|
41
|
-
const account = AccountSchema.fromNode(node);
|
42
|
-
authResult.onSuccess();
|
43
|
-
return {
|
44
|
-
account,
|
45
|
-
done: () => {
|
46
|
-
node.gracefulShutdown();
|
47
|
-
sessionDone();
|
48
|
-
},
|
49
|
-
};
|
50
|
-
}
|
51
|
-
catch (e) {
|
52
|
-
authResult.onError(new Error("Error loading account", { cause: e }));
|
53
|
-
sessionDone();
|
54
|
-
}
|
55
|
-
}
|
56
|
-
catch (e) {
|
57
|
-
authResult.onError(new Error("Error acquiring sessionID", { cause: e }));
|
58
|
-
}
|
59
|
-
}
|
60
|
-
else if (authResult.type === "new") {
|
61
|
-
try {
|
62
|
-
// TODO: figure out a way to not "waste" the first SessionID
|
63
|
-
const { node } = await LocalNode.withNewlyCreatedAccount({
|
64
|
-
creationProps: authResult.creationProps,
|
65
|
-
peersToLoadFrom: peersToLoadFrom,
|
66
|
-
crypto: crypto,
|
67
|
-
initialAgentSecret: authResult.initialSecret,
|
68
|
-
migration: async (rawAccount, _node, creationProps) => {
|
69
|
-
const account = new AccountSchema({
|
70
|
-
fromRaw: rawAccount,
|
71
|
-
});
|
72
|
-
await account.migrate?.(creationProps);
|
73
|
-
},
|
74
|
-
});
|
75
|
-
const account = AccountSchema.fromNode(node);
|
76
|
-
await authResult.saveCredentials({
|
77
|
-
accountID: node.account.id,
|
78
|
-
secret: node.account.agentSecret,
|
79
|
-
});
|
80
|
-
authResult.onSuccess();
|
81
|
-
return {
|
82
|
-
account,
|
83
|
-
done: () => {
|
84
|
-
node.gracefulShutdown();
|
85
|
-
},
|
86
|
-
};
|
87
|
-
}
|
88
|
-
catch (e) {
|
89
|
-
authResult.onError(new Error("Error creating account", { cause: e }));
|
90
|
-
}
|
91
|
-
}
|
92
|
-
}
|
93
|
-
}
|
94
|
-
//# sourceMappingURL=createContext.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../src/implementation/createContext.ts"],"names":[],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,KAAK,EAAE,aAAa,EAAE,EAAE;wBAClD,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC;4BAC9B,OAAO,EAAE,UAAU;yBACtB,CAAQ,CAAC;wBAEV,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,aAAa,CAAC,CAAC;oBAC3C,CAAC;iBACJ,CAAC,CAAC;gBAEH,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;gBAE7C,MAAM,UAAU,CAAC,eAAe,CAAC;oBAC7B,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,EAA4B;oBACpD,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW;iBACnC,CAAC,CAAC;gBAEH,UAAU,CAAC,SAAS,EAAE,CAAC;gBAEvB,OAAO;oBACH,OAAO;oBACP,IAAI,EAAE,GAAG,EAAE;wBACP,IAAI,CAAC,gBAAgB,EAAE,CAAC;oBAC5B,CAAC;iBACJ,CAAC;YACN,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,UAAU,CAAC,OAAO,CACd,IAAI,KAAK,CAAC,wBAAwB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CACpD,CAAC;YACN,CAAC;QACL,CAAC;IACL,CAAC;AACL,CAAC"}
|
@@ -1,162 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
AgentSecret,
|
3
|
-
CoID,
|
4
|
-
cojsonInternals,
|
5
|
-
CryptoProvider,
|
6
|
-
LocalNode,
|
7
|
-
Peer,
|
8
|
-
RawAccount,
|
9
|
-
RawAccountID,
|
10
|
-
SessionID,
|
11
|
-
} from "cojson";
|
12
|
-
import { Account, AccountClass, ID } from "../internal.js";
|
13
|
-
|
14
|
-
export type AuthResult =
|
15
|
-
| {
|
16
|
-
type: "existing";
|
17
|
-
credentials: { accountID: ID<Account>; secret: AgentSecret };
|
18
|
-
onSuccess: () => void;
|
19
|
-
onError: (error: string | Error) => void;
|
20
|
-
}
|
21
|
-
| {
|
22
|
-
type: "new";
|
23
|
-
creationProps: { name: string };
|
24
|
-
initialSecret?: AgentSecret;
|
25
|
-
saveCredentials: (credentials: {
|
26
|
-
accountID: ID<Account>;
|
27
|
-
secret: AgentSecret;
|
28
|
-
}) => Promise<void>;
|
29
|
-
onSuccess: () => void;
|
30
|
-
onError: (error: string | Error) => void;
|
31
|
-
};
|
32
|
-
|
33
|
-
export interface AuthMethod {
|
34
|
-
start(crypto: CryptoProvider): Promise<AuthResult>;
|
35
|
-
}
|
36
|
-
|
37
|
-
export const fixedCredentialsAuth = (credentials: {
|
38
|
-
accountID: ID<Account>;
|
39
|
-
secret: AgentSecret;
|
40
|
-
}): AuthMethod => {
|
41
|
-
return {
|
42
|
-
start: async () => ({
|
43
|
-
type: "existing",
|
44
|
-
credentials,
|
45
|
-
onSuccess: () => {},
|
46
|
-
onError: () => {},
|
47
|
-
}),
|
48
|
-
};
|
49
|
-
};
|
50
|
-
|
51
|
-
export async function randomSessionProvider(accountID: ID<Account>) {
|
52
|
-
return {
|
53
|
-
sessionID: cojsonInternals.newRandomSessionID(
|
54
|
-
accountID as unknown as RawAccountID,
|
55
|
-
),
|
56
|
-
sessionDone: () => {},
|
57
|
-
};
|
58
|
-
}
|
59
|
-
|
60
|
-
export async function createJazzContext<Acc extends Account>({
|
61
|
-
AccountSchema = Account as unknown as AccountClass<Acc>,
|
62
|
-
auth,
|
63
|
-
sessionProvider,
|
64
|
-
peersToLoadFrom,
|
65
|
-
crypto,
|
66
|
-
}: {
|
67
|
-
AccountSchema?: AccountClass<Acc>;
|
68
|
-
auth: AuthMethod;
|
69
|
-
sessionProvider: (
|
70
|
-
accountID: ID<Account>,
|
71
|
-
) => Promise<{ sessionID: SessionID; sessionDone: () => void }>;
|
72
|
-
peersToLoadFrom: Peer[];
|
73
|
-
crypto: CryptoProvider;
|
74
|
-
}): Promise<{ account: Acc; done: () => void }> {
|
75
|
-
// eslint-disable-next-line no-constant-condition
|
76
|
-
while (true) {
|
77
|
-
const authResult = await auth.start(crypto);
|
78
|
-
|
79
|
-
if (authResult.type === "existing") {
|
80
|
-
try {
|
81
|
-
const { sessionID, sessionDone } = await sessionProvider(
|
82
|
-
authResult.credentials.accountID,
|
83
|
-
);
|
84
|
-
|
85
|
-
try {
|
86
|
-
const node = await LocalNode.withLoadedAccount({
|
87
|
-
accountID: authResult.credentials
|
88
|
-
.accountID as unknown as CoID<RawAccount>,
|
89
|
-
accountSecret: authResult.credentials.secret,
|
90
|
-
sessionID: sessionID,
|
91
|
-
peersToLoadFrom: peersToLoadFrom,
|
92
|
-
crypto: crypto,
|
93
|
-
migration: async (rawAccount, _node, creationProps) => {
|
94
|
-
const account = new AccountSchema({
|
95
|
-
fromRaw: rawAccount,
|
96
|
-
}) as Acc;
|
97
|
-
|
98
|
-
await account.migrate?.(creationProps);
|
99
|
-
},
|
100
|
-
});
|
101
|
-
|
102
|
-
const account = AccountSchema.fromNode(node);
|
103
|
-
authResult.onSuccess();
|
104
|
-
|
105
|
-
return {
|
106
|
-
account,
|
107
|
-
done: () => {
|
108
|
-
node.gracefulShutdown();
|
109
|
-
sessionDone();
|
110
|
-
},
|
111
|
-
};
|
112
|
-
} catch (e) {
|
113
|
-
authResult.onError(
|
114
|
-
new Error("Error loading account", { cause: e }),
|
115
|
-
);
|
116
|
-
sessionDone();
|
117
|
-
}
|
118
|
-
} catch (e) {
|
119
|
-
authResult.onError(
|
120
|
-
new Error("Error acquiring sessionID", { cause: e }),
|
121
|
-
);
|
122
|
-
}
|
123
|
-
} else if (authResult.type === "new") {
|
124
|
-
try {
|
125
|
-
// TODO: figure out a way to not "waste" the first SessionID
|
126
|
-
const { node } = await LocalNode.withNewlyCreatedAccount({
|
127
|
-
creationProps: authResult.creationProps,
|
128
|
-
peersToLoadFrom: peersToLoadFrom,
|
129
|
-
crypto: crypto,
|
130
|
-
initialAgentSecret: authResult.initialSecret,
|
131
|
-
migration: async (rawAccount, _node, creationProps) => {
|
132
|
-
const account = new AccountSchema({
|
133
|
-
fromRaw: rawAccount,
|
134
|
-
}) as Acc;
|
135
|
-
|
136
|
-
await account.migrate?.(creationProps);
|
137
|
-
},
|
138
|
-
});
|
139
|
-
|
140
|
-
const account = AccountSchema.fromNode(node);
|
141
|
-
|
142
|
-
await authResult.saveCredentials({
|
143
|
-
accountID: node.account.id as unknown as ID<Account>,
|
144
|
-
secret: node.account.agentSecret,
|
145
|
-
});
|
146
|
-
|
147
|
-
authResult.onSuccess();
|
148
|
-
|
149
|
-
return {
|
150
|
-
account,
|
151
|
-
done: () => {
|
152
|
-
node.gracefulShutdown();
|
153
|
-
},
|
154
|
-
};
|
155
|
-
} catch (e) {
|
156
|
-
authResult.onError(
|
157
|
-
new Error("Error creating account", { cause: e }),
|
158
|
-
);
|
159
|
-
}
|
160
|
-
}
|
161
|
-
}
|
162
|
-
}
|