@bom-pi/core 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bom-pi/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Core pairing machinery for Bom Pi: ceremonies, transports, durable stores",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -544,6 +544,47 @@ export class FileConnectorStore implements ConnectorStore {
544
544
  return store;
545
545
  }
546
546
 
547
+ /** open() when a record exists, else create() — the one-shot enroll lane's provisioning. It
548
+ * tolerates exactly one leftover: a directory holding no record for this pin (an aborted
549
+ * create: mkdir ran, the record never landed — crash, power loss, or a platform check that
550
+ * refused mid-way). That orphan is removed and re-provisioned; a directory with any record,
551
+ * for this pin or another, is still never re-initialized over. */
552
+ static async openOrProvision(
553
+ directory: string,
554
+ pinned: PinnedCloud,
555
+ options?: FileConnectorStoreOptions,
556
+ ): Promise<FileConnectorStore> {
557
+ try {
558
+ return await FileConnectorStore.open(directory, pinned, options);
559
+ } catch (error) {
560
+ if (
561
+ !(error instanceof Error) ||
562
+ !/missing (?:store directory|record)/.test(error.message)
563
+ ) {
564
+ throw error;
565
+ }
566
+ }
567
+
568
+ try {
569
+ return await FileConnectorStore.create(directory, pinned, options);
570
+ } catch (error) {
571
+ if (!(error instanceof Error) || !/already exists/.test(error.message)) {
572
+ throw error;
573
+ }
574
+
575
+ const slot = slotPaths(directory, pinned);
576
+ const record = await lstat(slot.recordPath).catch(() => null);
577
+
578
+ if (record !== null) {
579
+ throw error;
580
+ }
581
+
582
+ await rm(directory, { recursive: true, force: true });
583
+
584
+ return await FileConnectorStore.create(directory, pinned, options);
585
+ }
586
+ }
587
+
547
588
  /** Opens an EXISTING store: the directory must pre-exist as a private 0700 directory owned by
548
589
  * the current user, and the record must be present, private (0600), structurally valid and
549
590
  * bound to exactly this pinned cloud. A missing record is refused (never silently treated as a