@semiont/core 0.5.3 → 0.5.4

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 (89) hide show
  1. package/dist/annotation-assembly.d.ts +54 -0
  2. package/dist/annotation-assembly.d.ts.map +1 -0
  3. package/dist/annotation-types.d.ts +30 -0
  4. package/dist/annotation-types.d.ts.map +1 -0
  5. package/dist/annotation-utils.d.ts +43 -0
  6. package/dist/annotation-utils.d.ts.map +1 -0
  7. package/dist/auth-types.d.ts +8 -0
  8. package/dist/auth-types.d.ts.map +1 -0
  9. package/dist/branded-types.d.ts +70 -0
  10. package/dist/branded-types.d.ts.map +1 -0
  11. package/dist/bridged-channels.d.ts +18 -0
  12. package/dist/bridged-channels.d.ts.map +1 -0
  13. package/dist/bus-log.d.ts +25 -0
  14. package/dist/bus-log.d.ts.map +1 -0
  15. package/dist/bus-protocol.d.ts +510 -0
  16. package/dist/bus-protocol.d.ts.map +1 -0
  17. package/dist/{config.types-oPv3Ajk-.d.ts → config/config.types.d.ts} +25 -23
  18. package/dist/config/config.types.d.ts.map +1 -0
  19. package/dist/config/configuration-error.d.ts +17 -0
  20. package/dist/config/configuration-error.d.ts.map +1 -0
  21. package/dist/config/environment-validator.d.ts +28 -0
  22. package/dist/config/environment-validator.d.ts.map +1 -0
  23. package/dist/config/node-config-loader.d.ts +4 -74
  24. package/dist/config/node-config-loader.d.ts.map +1 -0
  25. package/dist/config/platform-types.d.ts +26 -0
  26. package/dist/config/platform-types.d.ts.map +1 -0
  27. package/dist/config/toml-loader.d.ts +59 -0
  28. package/dist/config/toml-loader.d.ts.map +1 -0
  29. package/dist/did-utils.d.ts +76 -0
  30. package/dist/did-utils.d.ts.map +1 -0
  31. package/dist/errors.d.ts +48 -0
  32. package/dist/errors.d.ts.map +1 -0
  33. package/dist/event-base.d.ts +70 -0
  34. package/dist/event-base.d.ts.map +1 -0
  35. package/dist/event-bus.d.ts +141 -0
  36. package/dist/event-bus.d.ts.map +1 -0
  37. package/dist/event-utils.d.ts +43 -0
  38. package/dist/event-utils.d.ts.map +1 -0
  39. package/dist/fuzzy-anchor.d.ts +81 -0
  40. package/dist/fuzzy-anchor.d.ts.map +1 -0
  41. package/dist/graph.d.ts +44 -0
  42. package/dist/graph.d.ts.map +1 -0
  43. package/dist/id-generation.d.ts +8 -0
  44. package/dist/id-generation.d.ts.map +1 -0
  45. package/dist/identifiers.d.ts +24 -0
  46. package/dist/identifiers.d.ts.map +1 -0
  47. package/dist/index.d.ts +59 -6022
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +41 -19
  50. package/dist/index.js.map +1 -1
  51. package/dist/locales.d.ts +31 -0
  52. package/dist/locales.d.ts.map +1 -0
  53. package/dist/logger.d.ts +56 -0
  54. package/dist/logger.d.ts.map +1 -0
  55. package/dist/mime-utils.d.ts +38 -0
  56. package/dist/mime-utils.d.ts.map +1 -0
  57. package/dist/operators/burst-buffer.d.ts +61 -0
  58. package/dist/operators/burst-buffer.d.ts.map +1 -0
  59. package/dist/payload-types.d.ts +16 -0
  60. package/dist/payload-types.d.ts.map +1 -0
  61. package/dist/persisted-events.d.ts +76 -0
  62. package/dist/persisted-events.d.ts.map +1 -0
  63. package/dist/project.d.ts +69 -0
  64. package/dist/project.d.ts.map +1 -0
  65. package/dist/resource-types.d.ts +15 -0
  66. package/dist/resource-types.d.ts.map +1 -0
  67. package/dist/resource-utils.d.ts +97 -0
  68. package/dist/resource-utils.d.ts.map +1 -0
  69. package/dist/serialize-per-key.d.ts +51 -0
  70. package/dist/serialize-per-key.d.ts.map +1 -0
  71. package/dist/svg-utils.d.ts +44 -0
  72. package/dist/svg-utils.d.ts.map +1 -0
  73. package/dist/tag-schemas.d.ts +27 -0
  74. package/dist/tag-schemas.d.ts.map +1 -0
  75. package/dist/text-context.d.ts +85 -0
  76. package/dist/text-context.d.ts.map +1 -0
  77. package/dist/text-encoding.d.ts +34 -0
  78. package/dist/text-encoding.d.ts.map +1 -0
  79. package/dist/transport.d.ts +274 -0
  80. package/dist/transport.d.ts.map +1 -0
  81. package/dist/type-guards.d.ts +44 -0
  82. package/dist/type-guards.d.ts.map +1 -0
  83. package/dist/types.d.ts +3517 -0
  84. package/dist/types.d.ts.map +1 -0
  85. package/dist/validation.d.ts +57 -0
  86. package/dist/validation.d.ts.map +1 -0
  87. package/dist/web-annotation-utils.d.ts +154 -0
  88. package/dist/web-annotation-utils.d.ts.map +1 -0
  89. package/package.json +3 -3
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Event Base Types
3
+ *
4
+ * Core shapes for the event-sourced persistence model.
5
+ * EventBase is the common shape for all domain events.
6
+ * StoredEvent wraps an event with persistence metadata.
7
+ *
8
+ * These types are referenced by event-catalog.ts (domain events)
9
+ * and bus-protocol.ts (the full EventMap).
10
+ */
11
+ import type { components } from './types';
12
+ import type { ResourceId, UserId } from './identifiers';
13
+ import type { PersistedEvent } from './persisted-events';
14
+ /**
15
+ * Narrow an OpenAPI-generated type by overriding specific fields with branded types.
16
+ *
17
+ * OpenAPI schemas use plain `string` for identifiers. TypeScript branded types
18
+ * (ResourceId, AnnotationId, UserId, JobId) add compile-time safety. Brand<T, B>
19
+ * takes the OpenAPI type T and replaces the fields listed in B with their branded
20
+ * counterparts, preserving all other fields from the schema.
21
+ *
22
+ * @example
23
+ * type MyCommand = Brand<components['schemas']['YieldCreateCommand'], { userId: UserId }>;
24
+ * // Result: YieldCreateCommand with userId narrowed from string to UserId
25
+ */
26
+ export type Brand<T, Overrides> = Omit<T, keyof Overrides> & Overrides;
27
+ /** Fields common to ALL domain events (system and resource-scoped). */
28
+ export interface EventBase {
29
+ id: string;
30
+ timestamp: string;
31
+ resourceId?: ResourceId;
32
+ userId: UserId;
33
+ version: number;
34
+ }
35
+ /** Persistence metadata attached to every stored event. */
36
+ export type EventMetadata = components['schemas']['EventMetadata'];
37
+ /** Optional cryptographic signature on a stored event. */
38
+ export interface EventSignature {
39
+ algorithm: 'ed25519';
40
+ publicKey: string;
41
+ signature: string;
42
+ keyId?: string;
43
+ }
44
+ /**
45
+ * A domain event with persistence metadata.
46
+ * Flat intersection — no nesting (event.type, not event.event.type).
47
+ */
48
+ export type StoredEvent<T extends EventBase = PersistedEvent> = T & {
49
+ metadata: EventMetadata;
50
+ signature?: EventSignature;
51
+ };
52
+ export type BodyItem = components['schemas']['TextualBody'] | components['schemas']['SpecificResource'];
53
+ export type BodyOperation = components['schemas']['BodyOperationAdd'] | components['schemas']['BodyOperationRemove'] | components['schemas']['BodyOperationReplace'];
54
+ import type { Annotation } from './annotation-types';
55
+ export interface EventQuery {
56
+ resourceId?: ResourceId;
57
+ userId?: string;
58
+ eventTypes?: string[];
59
+ fromTimestamp?: string;
60
+ toTimestamp?: string;
61
+ fromSequence?: number;
62
+ limit?: number;
63
+ }
64
+ export interface ResourceAnnotations {
65
+ resourceId: ResourceId;
66
+ annotations: Annotation[];
67
+ version: number;
68
+ updatedAt: string;
69
+ }
70
+ //# sourceMappingURL=event-base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-base.d.ts","sourceRoot":"","sources":["../src/event-base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIzD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,SAAS,IAC5B,IAAI,CAAC,CAAC,EAAE,MAAM,SAAS,CAAC,GAAG,SAAS,CAAC;AAIvC,uEAAuE;AACvE,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,2DAA2D;AAC3D,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,CAAC;AAEnE,0DAA0D;AAC1D,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,SAAS,GAAG,cAAc,IAAI,CAAC,GAAG;IAClE,QAAQ,EAAE,aAAa,CAAC;IACxB,SAAS,CAAC,EAAE,cAAc,CAAC;CAC5B,CAAC;AAIF,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;AAExG,MAAM,MAAM,aAAa,GACrB,UAAU,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,GACzC,UAAU,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC,GAC5C,UAAU,CAAC,SAAS,CAAC,CAAC,sBAAsB,CAAC,CAAC;AAIlD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,WAAW,UAAU;IACzB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * RxJS-based Event Bus
3
+ *
4
+ * Framework-agnostic event bus providing direct access to typed RxJS Subjects.
5
+ *
6
+ * Can be used in Node.js, browser, workers, CLI - anywhere RxJS runs.
7
+ */
8
+ import { Subject } from 'rxjs';
9
+ import type { EventMap } from './bus-protocol';
10
+ import type { StoredEvent } from './event-base';
11
+ import type { PersistedEventType } from './persisted-events';
12
+ /**
13
+ * RxJS-based event bus
14
+ *
15
+ * Provides direct access to RxJS Subjects for each event type.
16
+ * Use standard RxJS patterns for emitting and subscribing.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const eventBus = new EventBus();
21
+ *
22
+ * // Emit events
23
+ * eventBus.get('beckon:hover').next({ annotationId: 'ann-1' });
24
+ *
25
+ * // Subscribe to events
26
+ * const subscription = eventBus.get('beckon:hover').subscribe(({ annotationId }) => {
27
+ * console.log('Hover:', annotationId);
28
+ * });
29
+ *
30
+ * // Use RxJS operators
31
+ * import { debounceTime } from 'rxjs/operators';
32
+ * eventBus.get('beckon:hover')
33
+ * .pipe(debounceTime(100))
34
+ * .subscribe(handleHover);
35
+ *
36
+ * // Cleanup
37
+ * subscription.unsubscribe();
38
+ * eventBus.destroy();
39
+ * ```
40
+ */
41
+ export declare class EventBus {
42
+ private subjects;
43
+ private isDestroyed;
44
+ constructor();
45
+ /**
46
+ * Get the RxJS Subject for an event
47
+ *
48
+ * Returns a typed Subject that can be used with all RxJS operators.
49
+ * Subjects are created lazily on first access.
50
+ *
51
+ * @param eventName - The event name
52
+ * @returns The RxJS Subject for this event
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // Emit
57
+ * eventBus.get('beckon:hover').next({ annotationId: 'ann-1' });
58
+ *
59
+ * // Subscribe
60
+ * const sub = eventBus.get('beckon:hover').subscribe(handleHover);
61
+ *
62
+ * // With operators
63
+ * eventBus.get('beckon:hover')
64
+ * .pipe(debounceTime(100), distinctUntilChanged())
65
+ * .subscribe(handleHover);
66
+ * ```
67
+ */
68
+ get<K extends keyof EventMap>(eventName: K): Subject<EventMap[K]>;
69
+ /**
70
+ * Get the RxJS Subject for a domain event type (PersistedEventType).
71
+ *
72
+ * Domain event channels carry `StoredEvent`. This method avoids the need
73
+ * for `as keyof EventMap` casts when subscribing to domain event channels
74
+ * using runtime `PersistedEventType` strings.
75
+ */
76
+ getDomainEvent(eventType: PersistedEventType): Subject<StoredEvent>;
77
+ /**
78
+ * Destroy the event bus and complete all subjects
79
+ *
80
+ * After calling destroy(), no new events can be emitted or subscribed to.
81
+ * All active subscriptions will be completed.
82
+ */
83
+ destroy(): void;
84
+ /**
85
+ * Check if the event bus has been destroyed
86
+ */
87
+ get destroyed(): boolean;
88
+ /**
89
+ * Create a resource-scoped event bus
90
+ *
91
+ * Events emitted or subscribed through the scoped bus are isolated to that resource.
92
+ * Internally, events are namespaced but the API remains identical to the parent bus.
93
+ *
94
+ * @param resourceId - Resource identifier to scope events to
95
+ * @returns A scoped event bus for this resource
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const eventBus = new EventBus();
100
+ * const resource1 = eventBus.scope('resource-1');
101
+ * const resource2 = eventBus.scope('resource-2');
102
+ *
103
+ * // These are isolated - only resource1 subscribers will fire
104
+ * resource1.get('detection:progress').next({ status: 'started' });
105
+ * ```
106
+ */
107
+ scope(resourceId: string): ScopedEventBus;
108
+ }
109
+ /**
110
+ * Resource-scoped event bus
111
+ *
112
+ * Provides isolated event streams per resource while maintaining the same API
113
+ * as the parent EventBus. Events are internally namespaced by resourceId.
114
+ */
115
+ export declare class ScopedEventBus {
116
+ private parent;
117
+ private scopePrefix;
118
+ constructor(parent: EventBus, scopePrefix: string);
119
+ /**
120
+ * Get the RxJS Subject for a scoped event
121
+ *
122
+ * Returns the same type as the parent bus, but events are isolated to this scope.
123
+ * Internally uses namespaced keys but preserves type safety.
124
+ *
125
+ * @param event - The event name
126
+ * @returns The RxJS Subject for this scoped event
127
+ */
128
+ get<E extends keyof EventMap>(event: E): Subject<EventMap[E]>;
129
+ /** Get the RxJS Subject for a domain event type on this scoped bus. */
130
+ getDomainEvent(eventType: PersistedEventType): Subject<StoredEvent>;
131
+ /**
132
+ * Create a nested scope
133
+ *
134
+ * Allows hierarchical scoping like `resource-1:subsystem-a`
135
+ *
136
+ * @param subScope - Additional scope level
137
+ * @returns A nested scoped event bus
138
+ */
139
+ scope(subScope: string): ScopedEventBus;
140
+ }
141
+ //# sourceMappingURL=event-bus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../src/event-bus.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAoC;IACpD,OAAO,CAAC,WAAW,CAAU;;IAO7B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,GAAG,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IA+BjE;;;;;;OAMG;IACH,cAAc,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC;IAInE;;;;;OAKG;IACH,OAAO,IAAI,IAAI;IAaf;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc;CAG1C;AAED;;;;;GAKG;AACH,qBAAa,cAAc;IAEvB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,WAAW;gBADX,MAAM,EAAE,QAAQ,EAChB,WAAW,EAAE,MAAM;IAG7B;;;;;;;;OAQG;IACH,GAAG,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAa7D,uEAAuE;IACvE,cAAc,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC;IAInE;;;;;;;OAOG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc;CAGxC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Event Type Guards and Extraction Utilities
3
+ *
4
+ * Domain logic for working with resource events.
5
+ * No React dependencies - safe to use in any JavaScript environment.
6
+ */
7
+ import type { StoredEvent } from './event-base';
8
+ import type { AnnotationUri } from './branded-types';
9
+ /**
10
+ * Minimal event shape accepted by event utility functions.
11
+ * Compatible with both the internal `StoredEvent` type and the OpenAPI-derived
12
+ * schema type (`GetEventsResponse['events'][number]`), which lacks `version`.
13
+ *
14
+ * Flat shape — event fields and metadata are peers (no `event` wrapper).
15
+ */
16
+ export interface StoredEventLike {
17
+ id: string;
18
+ type: string;
19
+ timestamp: string;
20
+ userId: string;
21
+ resourceId?: string;
22
+ payload?: unknown;
23
+ metadata: {
24
+ sequenceNumber: number;
25
+ };
26
+ }
27
+ /**
28
+ * Extract annotation ID from event payload
29
+ * Returns null if event is not annotation-related
30
+ *
31
+ * For mark:added: extracts full URI from payload.annotation.id
32
+ * For mark:removed/mark:body-updated: constructs full URI from payload.annotationId (UUID) + resourceId
33
+ */
34
+ export declare function getAnnotationUriFromEvent(event: StoredEventLike): AnnotationUri | null;
35
+ /**
36
+ * Check if an event is related to a specific annotation
37
+ */
38
+ export declare function isEventRelatedToAnnotation(event: StoredEventLike, annotationUri: AnnotationUri): boolean;
39
+ /**
40
+ * Type guard to check if an object is a StoredEvent (flat shape)
41
+ */
42
+ export declare function isStoredEvent(event: any): event is StoredEvent;
43
+ //# sourceMappingURL=event-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-utils.d.ts","sourceRoot":"","sources":["../src/event-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE;QACR,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AAMD;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,eAAe,GAAG,aAAa,GAAG,IAAI,CAoBtF;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,GAAG,OAAO,CAGxG;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,WAAW,CAO9D"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Fuzzy Anchoring for W3C Web Annotation TextQuoteSelector
3
+ *
4
+ * Uses prefix/suffix context to disambiguate when the same text appears multiple times.
5
+ * Implements fuzzy matching as specified in the W3C Web Annotation Data Model.
6
+ *
7
+ * @see https://www.w3.org/TR/annotation-model/#text-quote-selector
8
+ */
9
+ export interface TextPosition {
10
+ start: number;
11
+ end: number;
12
+ }
13
+ export type MatchQuality = 'exact' | 'normalized' | 'case-insensitive' | 'fuzzy';
14
+ /**
15
+ * Normalize text for comparison - handles common document editing changes
16
+ *
17
+ * Collapses whitespace, converts curly quotes to straight quotes,
18
+ * and normalizes common punctuation variations.
19
+ */
20
+ export declare function normalizeText(text: string): string;
21
+ /**
22
+ * Pre-computed content strings for batch fuzzy matching.
23
+ * Avoids recomputing normalizeText(content) and content.toLowerCase()
24
+ * for every annotation when processing many annotations against the same content.
25
+ */
26
+ export interface ContentCache {
27
+ normalizedContent: string;
28
+ lowerContent: string;
29
+ }
30
+ /**
31
+ * Build a ContentCache for a given content string.
32
+ * Call once per content, pass to findBestTextMatch/findTextWithContext for all annotations.
33
+ */
34
+ export declare function buildContentCache(content: string): ContentCache;
35
+ /**
36
+ * Find best match for text in content using multi-strategy search
37
+ *
38
+ * Shared core logic used by both findTextWithContext and validateAndCorrectOffsets.
39
+ *
40
+ * @param content - Full text content to search within
41
+ * @param searchText - The text to find
42
+ * @param positionHint - Hint for where to search (TextPositionSelector.start)
43
+ * @param cache - Pre-computed normalized/lowered content (from buildContentCache)
44
+ * @returns Match with position and quality, or null if not found
45
+ */
46
+ export declare function findBestTextMatch(content: string, searchText: string, positionHint: number | undefined, cache: ContentCache): {
47
+ start: number;
48
+ end: number;
49
+ matchQuality: MatchQuality;
50
+ } | null;
51
+ /**
52
+ * Find text using exact match with optional prefix/suffix context
53
+ *
54
+ * When the exact text appears multiple times in the content, prefix and suffix
55
+ * are used to disambiguate and find the correct occurrence.
56
+ *
57
+ * If exact text is not found, uses multi-strategy fuzzy matching (normalization,
58
+ * case-insensitive, Levenshtein distance) to locate changed text.
59
+ *
60
+ * @param content - Full text content to search within
61
+ * @param exact - The exact text to find
62
+ * @param prefix - Optional text that should appear immediately before the match
63
+ * @param suffix - Optional text that should appear immediately after the match
64
+ * @param positionHint - Optional position hint (from TextPositionSelector) for fuzzy search
65
+ * @returns Position of the matched text, or null if not found
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const content = "The cat sat. The cat ran.";
70
+ * // Find second "The cat" occurrence
71
+ * const pos = findTextWithContext(content, "The cat", "sat. ", " ran");
72
+ * // Returns { start: 13, end: 20 }
73
+ * ```
74
+ */
75
+ export declare function findTextWithContext(content: string, exact: string, prefix: string | undefined, suffix: string | undefined, positionHint: number | undefined, cache: ContentCache): TextPosition | null;
76
+ /**
77
+ * Verify that a position correctly points to the exact text
78
+ * Useful for debugging and validation
79
+ */
80
+ export declare function verifyPosition(content: string, position: TextPosition, expectedExact: string): boolean;
81
+ //# sourceMappingURL=fuzzy-anchor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fuzzy-anchor.d.ts","sourceRoot":"","sources":["../src/fuzzy-anchor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,YAAY,GAAG,kBAAkB,GAAG,OAAO,CAAC;AAEjF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQlD;AAiCD;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAK/D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,KAAK,EAAE,YAAY,GAClB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,YAAY,CAAA;CAAE,GAAG,IAAI,CAgFnE;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,KAAK,EAAE,YAAY,GAClB,YAAY,GAAG,IAAI,CA2ErB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,MAAM,GACpB,OAAO,CAGT"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Graph types - Models for graph connections and relationships
3
+ */
4
+ import type { components } from './types';
5
+ import type { ResourceId } from './identifiers';
6
+ import type { Annotation } from './annotation-types';
7
+ type RawResourceDescriptor = components['schemas']['ResourceDescriptor'];
8
+ /**
9
+ * Domain-level ResourceDescriptor type. Same shape as the OpenAPI-generated
10
+ * `components['schemas']['ResourceDescriptor']`, but with a branded `ResourceId`
11
+ * for the `@id` field.
12
+ *
13
+ * Implemented by intersection (not `Omit`) because the generated raw type
14
+ * ends in `& { [key: string]: unknown }` — `Omit` on an intersection with
15
+ * an index signature drops almost all named fields.
16
+ */
17
+ export type ResourceDescriptor = RawResourceDescriptor & {
18
+ '@id': ResourceId;
19
+ };
20
+ /**
21
+ * Represents a connection between resources through annotations
22
+ */
23
+ export interface GraphConnection {
24
+ targetResource: ResourceDescriptor;
25
+ annotations: Annotation[];
26
+ relationshipType?: string;
27
+ bidirectional: boolean;
28
+ }
29
+ /**
30
+ * Represents a path through the graph
31
+ */
32
+ export interface GraphPath {
33
+ resources: ResourceDescriptor[];
34
+ annotations: Annotation[];
35
+ }
36
+ /**
37
+ * Statistics about entity types in the graph
38
+ */
39
+ export interface EntityTypeStats {
40
+ type: string;
41
+ count: number;
42
+ }
43
+ export {};
44
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,KAAK,qBAAqB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,CAAC;AAEzE;;;;;;;;GAQG;AACH,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,GAAG;IAAE,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,kBAAkB,CAAC;IACnC,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * ID generation utilities
3
+ */
4
+ /**
5
+ * Generate a UUID v4 string (without dashes)
6
+ */
7
+ export declare function generateUuid(): string;
8
+ //# sourceMappingURL=id-generation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-generation.d.ts","sourceRoot":"","sources":["../src/id-generation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Branded identifier types for compile-time type safety.
3
+ *
4
+ * These types prevent mixing up resource IDs, annotation IDs, and user IDs
5
+ * at compile time while having zero runtime overhead.
6
+ *
7
+ * URI types (ResourceUri, AnnotationUri) are in @semiont/api-client
8
+ * since they deal with HTTP URIs returned by the API.
9
+ */
10
+ export type ResourceId = string & {
11
+ readonly __brand: 'ResourceId';
12
+ };
13
+ export type AnnotationId = string & {
14
+ readonly __brand: 'AnnotationId';
15
+ };
16
+ export type UserId = string & {
17
+ readonly __brand: 'UserId';
18
+ };
19
+ export declare function isResourceId(value: string): value is ResourceId;
20
+ export declare function isAnnotationId(value: string): value is AnnotationId;
21
+ export declare function resourceId(id: string): ResourceId;
22
+ export declare function annotationId(id: string): AnnotationId;
23
+ export declare function userId(id: string): UserId;
24
+ //# sourceMappingURL=identifiers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../src/identifiers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAA;CAAE,CAAC;AACrE,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAA;CAAE,CAAC;AACzE,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;AAG7D,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,UAAU,CAE/D;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,YAAY,CAEnE;AAGD,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,CAKjD;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,CAKrD;AAED,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEzC"}