Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable strictPropertyInitialization TypeScript option #492

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/blob-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class BlobStore {
* @param {import('../core-manager/index.js').CoreManager} options.coreManager
*/
constructor({ coreManager }) {
/** @type {undefined | (Hyperdrive & { key: Buffer })} */
let writer
const corestore = new PretendCorestore({ coreManager })
const blobIndexCores = coreManager.getCores('blobIndex')
const { key: writerKey } = coreManager.getWriterCore('blobIndex')
Expand All @@ -52,9 +54,14 @@ export class BlobStore {
// We use the discovery key to derive the id for a drive
this.#hyperdrives.set(getDiscoveryId(key), drive)
if (key.equals(writerKey)) {
this.#writer = proxyProps(drive, { key: writerKey })
writer = proxyProps(drive, { key: writerKey })
}
}
if (!writer) {
throw new Error('Could not find a writer for the blobIndex namespace')
}
this.#writer = writer

coreManager.on('add-core', ({ key, namespace }) => {
if (namespace !== 'blobIndex') return
// We use the discovery key to derive the id for a drive
Expand All @@ -65,9 +72,6 @@ export class BlobStore {
this.#hyperdrives.set(driveId, drive)
this.#driveEmitter.emit('add-drive', drive)
})
// This shouldn't happen, but this check ensures this.#writer is typed to exist
if (!this.#writer)
throw new Error('Could not find a writer for the blobIndex namespace')
}

get writerDriveId() {
Expand Down
6 changes: 2 additions & 4 deletions src/core-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ export class CoreManager extends TypedEmitter {
}
}

if (!this.#creatorCore) {
// For anyone other than the project creator, creatorCore is readonly
this.#creatorCore = this.#addCore({ publicKey: projectKey }, 'auth').core
}
// For anyone other than the project creator, creatorCore is readonly
this.#creatorCore ??= this.#addCore({ publicKey: projectKey }, 'auth').core
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think i'll ever get used to this 😅


// Load persisted cores
const rows = db.select().from(coresTable).all()
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"noImplicitAny": true,
"strictNullChecks": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"module": "Node16",
Expand Down
Loading