Skip to content

Commit a9fd597

Browse files
committed
Fix lint
1 parent 5837b5c commit a9fd597

6 files changed

Lines changed: 69 additions & 46 deletions

File tree

browser/data-browser/src/components/forms/NewForm/SubjectField.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export function SubjectField({
3737
// as plain read-only text.
3838
const isDID = value.startsWith('did:') || value.startsWith('_');
3939

40+
const [origin, path] =
41+
isDID || readOnly ? ['unknown', 'subject'] : getPath(value);
42+
43+
const [inputValue, setInputValue] = useState(path);
44+
4045
if (isDID || readOnly) {
4146
return (
4247
<Field
@@ -51,9 +56,6 @@ export function SubjectField({
5156
);
5257
}
5358

54-
const [origin, path] = getPath(value);
55-
const [inputValue, setInputValue] = useState(path);
56-
5759
const handleChange = (v: string) => {
5860
const subject = new URL(normalizePath(v), value);
5961
setInputValue(subject.pathname.slice(1));

browser/data-browser/src/helpers/agentStorage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Agent, SubtleCryptoProvider, JSCryptoProvider } from '@tomic/react';
1+
import { Agent, SubtleCryptoProvider } from '@tomic/react';
22
import { del, get, set } from 'idb-keyval';
33

44
const AGENT_IDB_KEY = 'atomic.agent';

browser/data-browser/src/views/InvitePage.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,27 @@ function InvitePage({ resource }: ResourcePageProps): JSX.Element {
9090
name?: string,
9191
) => {
9292
const resourceToSave = store.getResourceLoading(subject);
93+
9394
try {
9495
if (name?.trim()) {
9596
await resourceToSave.set(core.properties.name, name);
9697
}
98+
9799
const currentIsA =
98100
(await resourceToSave.get(core.properties.isA)) ?? ([] as string[]);
101+
99102
if (!currentIsA.includes(core.classes.agent)) {
100103
await resourceToSave.set(core.properties.isA, [
101104
...currentIsA,
102105
core.classes.agent,
103106
]);
104107
}
108+
105109
if (destination) {
106110
try {
107111
const target = await store.fetchResourceFromServer(destination);
108112
const driveSubject = await getResourcesDrive(target, store);
113+
109114
if (driveSubject) {
110115
resourceToSave.push(server.properties.drives, [driveSubject]);
111116
}
@@ -115,6 +120,7 @@ function InvitePage({ resource }: ResourcePageProps): JSX.Element {
115120
);
116121
}
117122
}
123+
118124
await resourceToSave.save();
119125
} catch (e) {
120126
store.notifyError(
@@ -127,10 +133,13 @@ function InvitePage({ resource }: ResourcePageProps): JSX.Element {
127133
onSuccess: async () => {
128134
setAgentSecret(undefined);
129135
const agentSubject = agent?.subject;
136+
130137
if (!agentSubject) {
131138
goToRedirect();
139+
132140
return;
133141
}
142+
134143
goToRedirect();
135144
void persistAgentAfterInvite(agentSubject, redirectURL, agentName);
136145
},
@@ -185,13 +194,15 @@ function InvitePage({ resource }: ResourcePageProps): JSX.Element {
185194

186195
if (redirect.error) {
187196
store.notifyError(redirect.error);
197+
188198
return;
189199
}
190200

191201
const destination = await getRedirectDestination(redirect);
192202

193203
if (!destination) {
194204
store.notifyError(new Error('Invite accepted, but no destination was returned.'));
205+
195206
return;
196207
}
197208

@@ -218,6 +229,7 @@ function InvitePage({ resource }: ResourcePageProps): JSX.Element {
218229
setRedirectURL(destination);
219230
goToRedirect(destination);
220231
void persistAgentAfterInvite(agentSubject!, destination, undefined);
232+
221233
return;
222234
}
223235

browser/lib/src/agent.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ export class Agent implements AgentInterface {
6464
// Fallback to JS crypto if SubtleCrypto doesn't support Ed25519
6565
// (e.g. in some headless browser environments)
6666
try {
67-
const [provider, subject] =
68-
JSCryptoProvider.fromSecret(secretB64);
67+
const [provider, subject] = JSCryptoProvider.fromSecret(secretB64);
6968
resolve(new Agent(provider, subject));
7069
} catch (e) {
7170
reject(e);

browser/lib/src/resource.ts

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class Resource<C extends OptionalClass = any> {
117117

118118
throw new Error(
119119
'Invalid subject given to resource, must be a string, found ' +
120-
typeof subject,
120+
typeof subject,
121121
);
122122
}
123123

@@ -225,6 +225,11 @@ export class Resource<C extends OptionalClass = any> {
225225
});
226226
}
227227

228+
/** Returns `true` when there are locally-signed commits waiting to be pushed. */
229+
public get hasPendingCommits(): boolean {
230+
return this._pendingCommits.length > 0;
231+
}
232+
228233
private get store(): Store {
229234
if (!this._store) {
230235
console.error(`Resource ${this.subject} has no store`);
@@ -547,9 +552,10 @@ export class Resource<C extends OptionalClass = any> {
547552
public getCommitsCollectionSubject(): string {
548553
// For DID subjects (or other non-HTTP URIs) we can't derive the server
549554
// origin from the subject itself — use the store's server URL instead.
550-
const base = this.subject.startsWith('did:') || this.subject.startsWith('_')
551-
? this.store.getServerUrl()
552-
: this.subject;
555+
const base =
556+
this.subject.startsWith('did:') || this.subject.startsWith('_')
557+
? this.store.getServerUrl()
558+
: this.subject;
553559
const url = new URL('/commits', base);
554560
url.searchParams.append('property', commits.properties.subject);
555561
url.searchParams.append('value', this.subject);
@@ -599,9 +605,8 @@ export class Resource<C extends OptionalClass = any> {
599605
const commitsCollection = await this.store.fetchResourceFromServer(
600606
this.getCommitsCollectionSubject(),
601607
);
602-
const commitList = (commitsCollection.get(
603-
collections.properties.members,
604-
) ?? []) as string[];
608+
const commitList = (commitsCollection.get(collections.properties.members) ??
609+
[]) as string[];
605610

606611
const builtVersions: Version[] = [];
607612

@@ -878,11 +883,6 @@ export class Resource<C extends OptionalClass = any> {
878883
return commit;
879884
}
880885

881-
/** Returns `true` when there are locally-signed commits waiting to be pushed. */
882-
public get hasPendingCommits(): boolean {
883-
return this._pendingCommits.length > 0;
884-
}
885-
886886
/**
887887
* Push all locally-queued commits to the server, in order.
888888
*
@@ -895,7 +895,9 @@ export class Resource<C extends OptionalClass = any> {
895895
}
896896

897897
const endpoint = this.getCommitEndpoint();
898-
const wasNew = this._pendingCommits.length > 0 && this._pendingCommits[0].previousCommit === undefined;
898+
const wasNew =
899+
this._pendingCommits.length > 0 &&
900+
this._pendingCommits[0].previousCommit === undefined;
899901

900902
let lastCommitId: string | undefined;
901903

@@ -935,19 +937,6 @@ export class Resource<C extends OptionalClass = any> {
935937
}
936938
}
937939

938-
/** Resolves the `/commit` endpoint for this resource. */
939-
private getCommitEndpoint(): string {
940-
if (this.subject.startsWith('did:')) {
941-
return new URL('/commit', this.store.getServerUrl()).toString();
942-
}
943-
944-
try {
945-
return new URL(this.subject).origin + `/commit`;
946-
} catch {
947-
return new URL('/commit', this.store.getServerUrl()).toString();
948-
}
949-
}
950-
951940
/**
952941
* Commits the changes and sends the Commit to the resource's `/commit`
953942
* endpoint. Returns the Url of the created Commit. If you don't pass an Agent
@@ -1000,7 +989,9 @@ export class Resource<C extends OptionalClass = any> {
1000989
});
1001990

1002991
// Keep a backup of the commit builder in case push fails.
1003-
const oldCommitBuilder = hasChanges ? this.commitBuilder.clone() : undefined;
992+
const oldCommitBuilder = hasChanges
993+
? this.commitBuilder.clone()
994+
: undefined;
1004995
const wasNew = this.new;
1005996

1006997
try {
@@ -1150,6 +1141,19 @@ export class Resource<C extends OptionalClass = any> {
11501141
});
11511142
}
11521143

1144+
/** Resolves the `/commit` endpoint for this resource. */
1145+
private getCommitEndpoint(): string {
1146+
if (this.subject.startsWith('did:')) {
1147+
return new URL('/commit', this.store.getServerUrl()).toString();
1148+
}
1149+
1150+
try {
1151+
return new URL(this.subject).origin + `/commit`;
1152+
} catch {
1153+
return new URL('/commit', this.store.getServerUrl()).toString();
1154+
}
1155+
}
1156+
11531157
private isParentNew() {
11541158
const parentSubject = this.propvals.get(core.properties.parent) as string;
11551159

browser/lib/src/store.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export class Store {
294294
!storeResource.loading &&
295295
!storeResource.new &&
296296
storeResource.get(commits.properties.lastCommit) ===
297-
resource.get(commits.properties.lastCommit)
297+
resource.get(commits.properties.lastCommit)
298298
) {
299299
return;
300300
}
@@ -431,11 +431,6 @@ export class Store {
431431
return this.findAvailableSubject(path, parentUrl);
432432
}
433433

434-
/** Creates a random HTTP subject under the given parent URL. */
435-
private createHTTPSubject(parentSubject: string): string {
436-
return `${parentSubject}/${this.randomPart()}`;
437-
}
438-
439434
/**
440435
* Always fetches the resource from the server then adds it to the store.
441436
*/
@@ -470,12 +465,14 @@ export class Store {
470465

471466
if (existing) {
472467
existing.loading = false;
468+
473469
return existing as Resource<C>;
474470
}
475471

476472
const local = new Resource<C>(normalizedSubject, true);
477473
local.loading = false;
478474
this.addResources(local, { skipCommitCompare: true });
475+
479476
return local;
480477
}
481478

@@ -509,15 +506,13 @@ export class Store {
509506
? { agent: this.agent, serverURL: this.getServerUrl() }
510507
: undefined;
511508

512-
const { resource, createdResources } = await this.client.fetchResourceHTTP(
513-
fetchSubject,
514-
{
509+
const { resource, createdResources } =
510+
await this.client.fetchResourceHTTP(fetchSubject, {
515511
from: opts.fromProxy ? this.getServerUrl() : undefined,
516512
method: opts.method,
517513
body: opts.body,
518514
signInfo,
519-
},
520-
);
515+
});
521516

522517
// The client already returns the requested top-level resource as `resource`.
523518
this.addResources(resource, {
@@ -529,7 +524,10 @@ export class Store {
529524

530525
// Any other resources that were returned (e.g. linked resources)
531526
createdResources.forEach(r => {
532-
if (this.normalizeSubject(r.subject) !== this.normalizeSubject(resource.subject)) {
527+
if (
528+
this.normalizeSubject(r.subject) !==
529+
this.normalizeSubject(resource.subject)
530+
) {
533531
this.addResources(r);
534532
}
535533
});
@@ -619,7 +617,10 @@ export class Store {
619617
let resource = this.resources.get(resolved);
620618

621619
if (!resource) {
622-
resource = new Resource<C>(normalized, opts.newResource || isTemporarySubject);
620+
resource = new Resource<C>(
621+
normalized,
622+
opts.newResource || isTemporarySubject,
623+
);
623624

624625
// New resources don't have to load, they are just created.
625626
if (!opts.newResource && !isTemporarySubject) {
@@ -1311,6 +1312,11 @@ export class Store {
13111312
await loadResourceTreeInner(resource, treeTemplate);
13121313
}
13131314

1315+
/** Creates a random HTTP subject under the given parent URL. */
1316+
private createHTTPSubject(parentSubject: string): string {
1317+
return `${parentSubject}/${this.randomPart()}`;
1318+
}
1319+
13141320
private randomPart(): string {
13151321
return ulid().toLowerCase();
13161322
}

0 commit comments

Comments
 (0)