From e04957de5e9341c18a71a5ec618ad7b2d2dc9f32 Mon Sep 17 00:00:00 2001 From: Sebastian Krupinski Date: Sun, 28 Jun 2026 18:07:13 -0400 Subject: [PATCH] refactor: comments Signed-off-by: Sebastian Krupinski --- lib/Import/ImportCountEvent.php | 8 -------- lib/Import/ImportEvent.php | 6 ------ lib/Import/ImportObjectEvent.php | 3 --- lib/Import/ImportOptions.php | 16 +++++----------- lib/Import/ImportService.php | 16 +--------------- src/stores/importStore.ts | 7 ++----- 6 files changed, 8 insertions(+), 48 deletions(-) diff --git a/lib/Import/ImportCountEvent.php b/lib/Import/ImportCountEvent.php index 22a0ce1..fa970a6 100644 --- a/lib/Import/ImportCountEvent.php +++ b/lib/Import/ImportCountEvent.php @@ -11,14 +11,6 @@ namespace KTXM\PeopleManager\Import; use KTXM\PeopleManager\Stream\ExpectedTotal; -/** - * Carries the total number of vCards discovered in the source. - * Yielded once, before any object events, when counting is enabled. - * - * The stream envelope consumes this as the `control:start` total (the progress - * denominator); it is never emitted as a `data` frame, so it carries no payload - * of its own. - */ final readonly class ImportCountEvent implements ImportEvent, ExpectedTotal { public function __construct( diff --git a/lib/Import/ImportEvent.php b/lib/Import/ImportEvent.php index cffe149..8c4b270 100644 --- a/lib/Import/ImportEvent.php +++ b/lib/Import/ImportEvent.php @@ -11,11 +11,5 @@ namespace KTXM\PeopleManager\Import; use JsonSerializable; -/** - * Marker interface for events yielded by the contact import generator. - * - * Each event serializes to a flat NDJSON frame (no nested envelope); the - * controller appends the transaction id and streams it as one line. - */ interface ImportEvent extends JsonSerializable { } diff --git a/lib/Import/ImportObjectEvent.php b/lib/Import/ImportObjectEvent.php index 27bc8fd..9f9f806 100644 --- a/lib/Import/ImportObjectEvent.php +++ b/lib/Import/ImportObjectEvent.php @@ -9,9 +9,6 @@ declare(strict_types=1); namespace KTXM\PeopleManager\Import; -/** - * Yielded once per vCard processed, carrying its disposition and any errors. - */ final readonly class ImportObjectEvent implements ImportEvent { /** diff --git a/lib/Import/ImportOptions.php b/lib/Import/ImportOptions.php index 75504ff..21b2683 100644 --- a/lib/Import/ImportOptions.php +++ b/lib/Import/ImportOptions.php @@ -11,9 +11,6 @@ namespace KTXM\PeopleManager\Import; use InvalidArgumentException; -/** - * Configuration for a contact import run. - */ final class ImportOptions { public const ERROR_CONTINUE = 0; @@ -63,14 +60,11 @@ final class ImportOptions { */ public static function fromArray(array $data): self { $options = new self(); - if (isset($data['supersede'])) { - $options->setSupersede((bool)$data['supersede']); - } - if (isset($data['counts'])) { - $options->setCounts((bool)$data['counts']); - } - if (isset($data['errors'])) { - $options->setErrors((int)$data['errors']); + $options->supersede = (bool)($data['supersede'] ?? false); + $options->counts = (bool)($data['counts'] ?? true); + $options->errors = (int)($data['errors'] ?? self::ERROR_CONTINUE); + if (!in_array($options->errors, [self::ERROR_CONTINUE, self::ERROR_FAIL], true)) { + throw new InvalidArgumentException('Invalid errors option specified'); } return $options; } diff --git a/lib/Import/ImportService.php b/lib/Import/ImportService.php index afb6bd7..f04136f 100644 --- a/lib/Import/ImportService.php +++ b/lib/Import/ImportService.php @@ -22,20 +22,6 @@ use Sabre\VObject\Property; use Sabre\VObject\Splitter\VCard as VCardSplitter; use Throwable; -/** - * Streams vCards from a file resource, maps each to a people entity, and creates - * it in the target collection — yielding one ImportEvent per card. - * - * Memory profile: one vCard is held at a time (sabre's streaming splitter), the - * generator keeps no running collection, and the discovered count is obtained by a - * cheap byte scan rather than a second parse. See modules/people/.ideas/vcf-import.md. - * - * v1 scope: every card is created (disposition `created`) or fails (`error`). The - * vCard UID is mapped to the entity `urid` so future supersede/exists detection is - * possible, but the local provider keys entities on a fresh server id and exposes no - * UID lookup, so supersede/updated/exists are deferred. Individual ORG affiliation - * mapping is also deferred (the ORG property on individual cards is not yet mapped). - */ class ImportService { public function __construct( @@ -43,7 +29,7 @@ class ImportService { ) {} /** - * @param resource $source readable, seekable file resource containing one or more vCards + * @param resource $source readable, seekable file resource containing one or more objects * * @return Generator */ diff --git a/src/stores/importStore.ts b/src/stores/importStore.ts index 7652ab7..e4b5b37 100644 --- a/src/stores/importStore.ts +++ b/src/stores/importStore.ts @@ -1,9 +1,5 @@ /** * Contact Import Store - * - * Drives the VCF import flow: a queue of files, each targeting a collection, imported - * sequentially while live counters stream in. Memory stays flat regardless of contact - * count — per-session counters are plain integers and recent results are capped. */ import { ref, computed } from 'vue' @@ -32,7 +28,9 @@ function defaultOptions(): ImportFileOptions { } export const useImportStore = defineStore('peopleImportStore', () => { + // State + const lastFileInsertId = ref(-1) const files = ref([]) const stage = ref('idle') @@ -66,7 +64,6 @@ export const useImportStore = defineStore('peopleImportStore', () => { // Actions - /** Queue a file for import; returns its assigned id. */ function addFile(file: ImportFileAdd): number { const id = ++lastFileInsertId.value files.value.push({