| … | … | @@ -23,17 +23,32 @@ import { issuesSchema, DEFAULT_LABELS } from './schema.js' |
| 23 | 23 | |
| 24 | 24 | export class HyperIssues { |
| 25 | 25 | /** |
| 26 | | * @param {Corestore} corestore |
| 26 | * @param {Corestore} corestore - ignored when `options.room` is given |
| 27 | 27 | * @param {object} options |
| 28 | 28 | * @param {string} [options.namespace='issues'] |
| 29 | 29 | * @param {Buffer|string|null} [options.bootstrapKey=null] |
| 30 | * @param {Room} [options.room] - wrap an EXISTING Room instead of |
| 31 | * creating one. Used for "linked-core" composites: an org Room built |
| 32 | * with composeSchemas([orgsSchema, issuesSchema]) already handles |
| 33 | * issue ops, and a HyperIssues wrapping it provides the issue API |
| 34 | * over that one autobase. The Room's schema MUST handle issue ops. |
| 35 | * @param {boolean} [options.ownsRoom] - whether close() closes the |
| 36 | * Room. Defaults to true when this instance created the Room, false |
| 37 | * when wrapping an external one (so closing the issue API doesn't |
| 38 | * tear down the org that owns the Room). |
| 30 | 39 | */ |
| 31 | 40 | constructor (corestore, options = {}) { |
| 32 | | this._room = new Room(corestore, { |
| 33 | | schema: issuesSchema, |
| 34 | | namespace: options.namespace || 'issues', |
| 35 | | bootstrapKey: options.bootstrapKey || null |
| 36 | | }) |
| 41 | if (options.room) { |
| 42 | this._room = options.room |
| 43 | this._ownsRoom = options.ownsRoom === true |
| 44 | } else { |
| 45 | this._room = new Room(corestore, { |
| 46 | schema: issuesSchema, |
| 47 | namespace: options.namespace || 'issues', |
| 48 | bootstrapKey: options.bootstrapKey || null |
| 49 | }) |
| 50 | this._ownsRoom = options.ownsRoom !== false |
| 51 | } |
| 37 | 52 | } |
| 38 | 53 | |
| 39 | 54 | // ── Lifecycle / properties ────────────────────────────────── |
| … | … | @@ -43,7 +58,7 @@ export class HyperIssues { |
| 43 | 58 | } |
| 44 | 59 | |
| 45 | 60 | async sync () { await this._room.base.update() } |
| 46 | | async close () { await this._room.close() } |
| 61 | async close () { if (this._ownsRoom) await this._room.close() } |
| 47 | 62 | |
| 48 | 63 | get key () { return this._room.key } |
| 49 | 64 | get keyHex () { return this._room.keyHex } |