@miadi/tide 0.5.5 → 0.6.0

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/annotate.ts +32 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miadi/tide",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
4
4
  "description": "Typed client boundary for the ironsilk `tide` runtime. Daemon Unix-socket transport with CLI fallback.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,7 +15,7 @@
15
15
  "src"
16
16
  ],
17
17
  "dependencies": {
18
- "@miadi/annotate-core": "^0.1.1",
18
+ "@miadi/annotate-core": "^0.2.0",
19
19
  "@miadi/tide-contract": "0.3.1"
20
20
  },
21
21
  "keywords": [
package/src/annotate.ts CHANGED
@@ -39,10 +39,11 @@ import { homedir } from "node:os"
39
39
  import { existsSync } from "node:fs"
40
40
  import { randomBytes } from "node:crypto"
41
41
  import { TideError } from "./errors"
42
- import { isMarkAuthor, MARK_KINDS, resolveQuote } from "@miadi/annotate-core"
42
+ import { AUTHOR_BASES, isMarkAuthor, MARK_KINDS, resolveQuote } from "@miadi/annotate-core"
43
43
  import type {
44
44
  AnnotateBlock,
45
45
  AnnotateDocument,
46
+ AuthorBasis,
46
47
  DeliverOutcome,
47
48
  MarkAuthor,
48
49
  MarkKind,
@@ -118,6 +119,10 @@ export interface MarkInput {
118
119
  text: string
119
120
  kind?: MarkKind
120
121
  author: MarkAuthor
122
+ /** How the author was known, from `resolveAuthor`. Recorded on the mark as `author_basis`. */
123
+ basis?: AuthorBasis
124
+ /** Whose request carried the mark, from `resolveAuthor`. Recorded as `author_by` / `author_by_name`. */
125
+ by?: MarkAuthor | null
121
126
  }
122
127
 
123
128
  export interface ReviewExport {
@@ -131,6 +136,8 @@ export interface MarkResult extends ReviewExport {
131
136
  /** How many new records received the author. 1 on the normal path. */
132
137
  stamped: number
133
138
  author: MarkAuthor
139
+ basis?: AuthorBasis
140
+ by?: MarkAuthor | null
134
141
  }
135
142
 
136
143
  export interface DeliverResult extends DeliverOutcome {
@@ -521,8 +528,17 @@ interface StoreAnnotation {
521
528
  id?: unknown
522
529
  author?: unknown
523
530
  author_name?: unknown
531
+ author_basis?: unknown
532
+ author_by?: unknown
533
+ author_by_name?: unknown
524
534
  [k: string]: unknown
525
535
  }
536
+
537
+ /** How an author was known and whose request carried the mark; plannotator-tui keeps unknown fields on rewrite. */
538
+ export interface MarkAttribution {
539
+ basis?: AuthorBasis
540
+ by?: MarkAuthor | null
541
+ }
526
542
  interface StoreRecord {
527
543
  path?: unknown
528
544
  annotations?: StoreAnnotation[]
@@ -536,15 +552,22 @@ export function recordIds(rec: StoreRecord): Set<string> {
536
552
  /**
537
553
  * Write the author onto exactly the records in `ids` that have none. Returns how
538
554
  * many were stamped. A record that already carries an author is left alone —
539
- * the rule is no assignment after the fact, in either direction.
555
+ * the rule is no assignment after the fact, in either direction. With an
556
+ * attribution, the record also says how the author was known (`author_basis`)
557
+ * and whose request carried it (`author_by`, `author_by_name`).
540
558
  */
541
- export function stampAuthor(rec: StoreRecord, ids: Set<string>, author: MarkAuthor): number {
559
+ export function stampAuthor(rec: StoreRecord, ids: Set<string>, author: MarkAuthor, attribution: MarkAttribution = {}): number {
542
560
  let n = 0
543
561
  for (const a of rec.annotations ?? []) {
544
562
  if (typeof a.id !== "string" || !ids.has(a.id)) continue
545
563
  if (a.author !== null && a.author !== undefined) continue
546
564
  a.author = author.id
547
565
  a.author_name = author.name
566
+ if (attribution.basis) {
567
+ a.author_basis = attribution.basis
568
+ a.author_by = attribution.by ? attribution.by.id : null
569
+ a.author_by_name = attribution.by ? attribution.by.name : null
570
+ }
548
571
  n++
549
572
  }
550
573
  return n
@@ -708,6 +731,9 @@ export async function listMarks(doc: string, storeRoot?: string): Promise<MarkRe
708
731
  id: text(a.id),
709
732
  author: typeof a.author === "string" && a.author ? a.author : null,
710
733
  author_name: typeof a.author_name === "string" && a.author_name ? a.author_name : null,
734
+ author_basis: (AUTHOR_BASES as readonly unknown[]).includes(a.author_basis) ? (a.author_basis as AuthorBasis) : null,
735
+ author_by: typeof a.author_by === "string" && a.author_by ? a.author_by : null,
736
+ author_by_name: typeof a.author_by_name === "string" && a.author_by_name ? a.author_by_name : null,
711
737
  text: text(a.body),
712
738
  quote: text((a.anchor as { originalText?: unknown } | undefined)?.originalText),
713
739
  created_at: typeof a.created_at === "string" ? a.created_at : null,
@@ -748,10 +774,11 @@ export async function mark(doc: string, input: MarkInput): Promise<MarkResult> {
748
774
  if (!store) throw new TideError("the mark was written but its record was not found in the plannotator store; author not stamped")
749
775
  const rec = JSON.parse(await readFile(store, "utf8")) as StoreRecord
750
776
  const fresh = new Set([...recordIds(rec)].filter(id => !idsBefore.has(id)))
751
- const stamped = stampAuthor(rec, fresh, input.author)
777
+ const attribution: MarkAttribution = input.basis ? { basis: input.basis, by: input.by ?? null } : {}
778
+ const stamped = stampAuthor(rec, fresh, input.author, attribution)
752
779
  if (stamped > 0) await writeFile(store, JSON.stringify(rec, null, 2) + "\n", "utf8")
753
780
  const exported = await exportReview(doc)
754
- return { ...exported, stamped, author: input.author }
781
+ return { ...exported, stamped, author: input.author, ...attribution }
755
782
  }
756
783
 
757
784
  /**