@semiont/core 0.1.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.
- package/README.md +265 -0
- package/dist/annotation-history-utils.d.ts +42 -0
- package/dist/annotation-history-utils.d.ts.map +1 -0
- package/dist/annotation-history-utils.js +258 -0
- package/dist/annotation-history-utils.js.map +1 -0
- package/dist/annotation-types.d.ts +15 -0
- package/dist/annotation-types.d.ts.map +1 -0
- package/dist/annotation-types.js +6 -0
- package/dist/annotation-types.js.map +1 -0
- package/dist/annotation-utils.d.ts +18 -0
- package/dist/annotation-utils.d.ts.map +1 -0
- package/dist/annotation-utils.js +70 -0
- package/dist/annotation-utils.js.map +1 -0
- package/dist/auth-types.d.ts +8 -0
- package/dist/auth-types.d.ts.map +1 -0
- package/dist/auth-types.js +6 -0
- package/dist/auth-types.js.map +1 -0
- package/dist/config/config-validator.d.ts +25 -0
- package/dist/config/config-validator.d.ts.map +1 -0
- package/dist/config/config-validator.js +112 -0
- package/dist/config/config-validator.js.map +1 -0
- package/dist/config/config.schema.json +678 -0
- package/dist/config/config.types.d.ts +574 -0
- package/dist/config/config.types.d.ts.map +1 -0
- package/dist/config/config.types.js +4 -0
- package/dist/config/config.types.js.map +1 -0
- package/dist/config/configuration-error.d.ts +17 -0
- package/dist/config/configuration-error.d.ts.map +1 -0
- package/dist/config/configuration-error.js +36 -0
- package/dist/config/configuration-error.js.map +1 -0
- package/dist/config/environment-loader.d.ts +98 -0
- package/dist/config/environment-loader.d.ts.map +1 -0
- package/dist/config/environment-loader.js +229 -0
- package/dist/config/environment-loader.js.map +1 -0
- package/dist/config/environment-validator.d.ts +22 -0
- package/dist/config/environment-validator.d.ts.map +1 -0
- package/dist/config/environment-validator.js +50 -0
- package/dist/config/environment-validator.js.map +1 -0
- package/dist/config/platform-types.d.ts +26 -0
- package/dist/config/platform-types.d.ts.map +1 -0
- package/dist/config/platform-types.js +28 -0
- package/dist/config/platform-types.js.map +1 -0
- package/dist/config/project-discovery.d.ts +35 -0
- package/dist/config/project-discovery.d.ts.map +1 -0
- package/dist/config/project-discovery.js +99 -0
- package/dist/config/project-discovery.js.map +1 -0
- package/dist/config/validate-config.d.ts +56 -0
- package/dist/config/validate-config.d.ts.map +1 -0
- package/dist/config/validate-config.js +114 -0
- package/dist/config/validate-config.js.map +1 -0
- package/dist/creation-methods.d.ts +19 -0
- package/dist/creation-methods.d.ts.map +1 -0
- package/dist/creation-methods.js +18 -0
- package/dist/creation-methods.js.map +1 -0
- package/dist/crypto.d.ts +32 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +52 -0
- package/dist/crypto.js.map +1 -0
- package/dist/did-utils.d.ts +51 -0
- package/dist/did-utils.d.ts.map +1 -0
- package/dist/did-utils.js +62 -0
- package/dist/did-utils.js.map +1 -0
- package/dist/errors.d.ts +51 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +89 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +223 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +45 -0
- package/dist/events.js.map +1 -0
- package/dist/graph.d.ts +31 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +6 -0
- package/dist/graph.js.map +1 -0
- package/dist/http-client.d.ts +32 -0
- package/dist/http-client.d.ts.map +1 -0
- package/dist/http-client.js +56 -0
- package/dist/http-client.js.map +1 -0
- package/dist/identifiers.d.ts +24 -0
- package/dist/identifiers.d.ts.map +1 -0
- package/dist/identifiers.js +40 -0
- package/dist/identifiers.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/resource-types.d.ts +15 -0
- package/dist/resource-types.d.ts.map +1 -0
- package/dist/resource-types.js +6 -0
- package/dist/resource-types.js.map +1 -0
- package/dist/type-guards.d.ts +44 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/type-guards.js +76 -0
- package/dist/type-guards.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# @semiont/core
|
|
2
|
+
|
|
3
|
+
Backend domain logic for the Semiont semantic knowledge platform. This package provides **internal backend utilities** for event sourcing, cryptography, DID generation, and type guards.
|
|
4
|
+
|
|
5
|
+
> ⚠️ **Not for External Use**: If you're building applications that consume the Semiont API, use [`@semiont/api-client`](../api-client/README.md) instead. This package is for **backend internal use only**.
|
|
6
|
+
|
|
7
|
+
## Who Should Use This
|
|
8
|
+
|
|
9
|
+
- ✅ **Backend** (`apps/backend`) - Server implementation with event sourcing
|
|
10
|
+
- ✅ **Internal Services** - System components requiring domain logic
|
|
11
|
+
- ✅ **CLI Tools** - Command-line utilities with full system access
|
|
12
|
+
|
|
13
|
+
## Who Should NOT Use This
|
|
14
|
+
|
|
15
|
+
- ❌ **External Applications** - Use [`@semiont/api-client`](../api-client/README.md)
|
|
16
|
+
- ❌ **Frontend** - Use [`@semiont/api-client`](../api-client/README.md)
|
|
17
|
+
- ❌ **MCP Servers** - Use [`@semiont/api-client`](../api-client/README.md)
|
|
18
|
+
- ❌ **Demo Scripts** - Use [`@semiont/api-client`](../api-client/README.md)
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @semiont/core
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## What's Included
|
|
27
|
+
|
|
28
|
+
### Event Sourcing Types
|
|
29
|
+
|
|
30
|
+
Event types for the event-sourced architecture:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import type {
|
|
34
|
+
DocumentEvent,
|
|
35
|
+
DocumentCreatedEvent,
|
|
36
|
+
DocumentArchivedEvent,
|
|
37
|
+
DocumentUnarchivedEvent,
|
|
38
|
+
AnnotationAddedEvent,
|
|
39
|
+
AnnotationRemovedEvent,
|
|
40
|
+
AnnotationBodyUpdatedEvent,
|
|
41
|
+
EntityTagAddedEvent,
|
|
42
|
+
EntityTagRemovedEvent,
|
|
43
|
+
StoredEvent,
|
|
44
|
+
EventMetadata,
|
|
45
|
+
DocumentAnnotations,
|
|
46
|
+
BodyOperation,
|
|
47
|
+
} from '@semiont/core';
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### DID Utilities
|
|
51
|
+
|
|
52
|
+
Generate W3C Decentralized Identifiers for annotations:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { userToDid, userToAgent, didToAgent } from '@semiont/core';
|
|
56
|
+
|
|
57
|
+
// Convert user to DID:WEB
|
|
58
|
+
const did = userToDid(user);
|
|
59
|
+
// => 'did:web:localhost%3A4000:users:user-id'
|
|
60
|
+
|
|
61
|
+
// Convert user to W3C Agent
|
|
62
|
+
const agent = userToAgent(user);
|
|
63
|
+
// => { id: 'did:web:...', type: 'Person', name: 'User Name' }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Cryptographic Utilities
|
|
67
|
+
|
|
68
|
+
Content-addressing and checksums:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import {
|
|
72
|
+
generateId,
|
|
73
|
+
generateToken,
|
|
74
|
+
generateUuid,
|
|
75
|
+
calculateChecksum,
|
|
76
|
+
verifyChecksum,
|
|
77
|
+
} from '@semiont/core';
|
|
78
|
+
|
|
79
|
+
// Generate unique IDs
|
|
80
|
+
const id = generateId();
|
|
81
|
+
const token = generateToken();
|
|
82
|
+
const uuid = generateUuid();
|
|
83
|
+
|
|
84
|
+
// Content checksums for verification
|
|
85
|
+
const checksum = calculateChecksum(content);
|
|
86
|
+
const isValid = verifyChecksum(content, checksum);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Type Guards
|
|
90
|
+
|
|
91
|
+
Runtime type checking:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import {
|
|
95
|
+
isString,
|
|
96
|
+
isNumber,
|
|
97
|
+
isBoolean,
|
|
98
|
+
isObject,
|
|
99
|
+
isArray,
|
|
100
|
+
isNonEmptyArray,
|
|
101
|
+
isDefined,
|
|
102
|
+
} from '@semiont/core';
|
|
103
|
+
|
|
104
|
+
if (isNonEmptyArray(value)) {
|
|
105
|
+
// TypeScript knows value is T[] with length > 0
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Error Classes
|
|
110
|
+
|
|
111
|
+
Backend error types:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import {
|
|
115
|
+
SemiontError,
|
|
116
|
+
APIError,
|
|
117
|
+
NotFoundError,
|
|
118
|
+
ConflictError,
|
|
119
|
+
ValidationError,
|
|
120
|
+
UnauthorizedError,
|
|
121
|
+
} from '@semiont/core';
|
|
122
|
+
|
|
123
|
+
throw new NotFoundError('Document not found');
|
|
124
|
+
throw new ValidationError('Invalid annotation format');
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### HTTP Client Utilities
|
|
128
|
+
|
|
129
|
+
Backend HTTP utilities (internal use):
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { fetchAPI, createFetchAPI } from '@semiont/core';
|
|
133
|
+
|
|
134
|
+
const response = await fetchAPI(url, { method: 'POST', body: data });
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Backend-Specific Annotation Utilities
|
|
138
|
+
|
|
139
|
+
Utilities that work with internal backend types:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { bodyItemsMatch, findBodyItem } from '@semiont/core';
|
|
143
|
+
|
|
144
|
+
// Find specific body item in annotation
|
|
145
|
+
const item = findBodyItem(annotation.body, (item) => item.purpose === 'tagging');
|
|
146
|
+
|
|
147
|
+
// Check if two body items match
|
|
148
|
+
if (bodyItemsMatch(item1, item2)) {
|
|
149
|
+
// ...
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Backend Internal Types
|
|
154
|
+
|
|
155
|
+
Types not in the OpenAPI spec:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import type {
|
|
159
|
+
UpdateDocumentInput,
|
|
160
|
+
ResourceFilter,
|
|
161
|
+
CreateAnnotationInternal,
|
|
162
|
+
AnnotationCategory,
|
|
163
|
+
GoogleAuthRequest,
|
|
164
|
+
GraphConnection,
|
|
165
|
+
GraphPath,
|
|
166
|
+
EntityTypeStats,
|
|
167
|
+
} from '@semiont/core';
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Constants
|
|
171
|
+
|
|
172
|
+
Backend-specific constants:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { CREATION_METHODS } from '@semiont/core';
|
|
176
|
+
|
|
177
|
+
CREATION_METHODS.API // 'api'
|
|
178
|
+
CREATION_METHODS.PASTE // 'paste'
|
|
179
|
+
CREATION_METHODS.FILE_UPLOAD // 'file-upload'
|
|
180
|
+
CREATION_METHODS.REFERENCE // 'reference'
|
|
181
|
+
CREATION_METHODS.IMPORT // 'import'
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## What's NOT Included
|
|
185
|
+
|
|
186
|
+
The following utilities have been **moved to @semiont/api-client** (as of 2025-10-24):
|
|
187
|
+
|
|
188
|
+
### ❌ Selector Utilities
|
|
189
|
+
|
|
190
|
+
**Use `@semiont/api-client` instead:**
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
// OLD (removed from @semiont/core):
|
|
194
|
+
import { getExactText, getTextPositionSelector } from '@semiont/core';
|
|
195
|
+
|
|
196
|
+
// NEW (use @semiont/api-client):
|
|
197
|
+
import { getExactText, getTextPositionSelector } from '@semiont/api-client';
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### ❌ Locale Utilities
|
|
201
|
+
|
|
202
|
+
**Use `@semiont/api-client` instead:**
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
// OLD (removed from @semiont/core):
|
|
206
|
+
import { LOCALES, formatLocaleDisplay, getLocaleInfo } from '@semiont/core';
|
|
207
|
+
|
|
208
|
+
// NEW (use @semiont/api-client):
|
|
209
|
+
import { LOCALES, formatLocaleDisplay, getLocaleInfo } from '@semiont/api-client';
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### ❌ Annotation Utilities (Public API)
|
|
213
|
+
|
|
214
|
+
**Use `@semiont/api-client` instead:**
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
// OLD (removed from @semiont/core):
|
|
218
|
+
import { compareAnnotationIds, getEntityTypes, getBodySource } from '@semiont/core';
|
|
219
|
+
|
|
220
|
+
// NEW (use @semiont/api-client):
|
|
221
|
+
import { compareAnnotationIds, getEntityTypes, getBodySource } from '@semiont/api-client';
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Architecture: Spec-First
|
|
225
|
+
|
|
226
|
+
Semiont follows a **spec-first architecture**:
|
|
227
|
+
|
|
228
|
+
1. **OpenAPI Specification** ([specs/src/](../../specs/src/)) is the source of truth
|
|
229
|
+
2. **@semiont/api-client** generates types from OpenAPI and provides utilities
|
|
230
|
+
3. **@semiont/core** provides backend-specific domain logic not in the API
|
|
231
|
+
|
|
232
|
+
**Principle**:
|
|
233
|
+
- API contract & data utilities → `@semiont/api-client`
|
|
234
|
+
- Backend internal implementation → `@semiont/core`
|
|
235
|
+
|
|
236
|
+
**Deduplication (2025-10-24)**: Selector utilities, locale utilities, and public annotation utilities were moved from this package to `@semiont/api-client` as part of the spec-first architecture migration.
|
|
237
|
+
|
|
238
|
+
## Development
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
# Build the package
|
|
242
|
+
npm run build
|
|
243
|
+
|
|
244
|
+
# Type check
|
|
245
|
+
npm run typecheck
|
|
246
|
+
|
|
247
|
+
# Clean build artifacts
|
|
248
|
+
npm run clean
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## License
|
|
252
|
+
|
|
253
|
+
Apache-2.0
|
|
254
|
+
|
|
255
|
+
## Related Packages
|
|
256
|
+
|
|
257
|
+
- [`@semiont/api-client`](../api-client/) - Primary TypeScript SDK (use this for most cases)
|
|
258
|
+
- [`@semiont/backend`](../../apps/backend/) - Backend API server
|
|
259
|
+
- [`@semiont/frontend`](../../apps/frontend/) - Web application
|
|
260
|
+
|
|
261
|
+
## Learn More
|
|
262
|
+
|
|
263
|
+
- [W3C Web Annotation Model](https://www.w3.org/TR/annotation-model/) - Annotation standard
|
|
264
|
+
- [DID:WEB Specification](https://w3c-ccg.github.io/did-method-web/) - Decentralized identifiers
|
|
265
|
+
- [W3C Selectors](../../specs/docs/W3C-SELECTORS.md) - Selector implementation details
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for AnnotationHistory component
|
|
3
|
+
* Extracted to reduce component complexity and improve testability
|
|
4
|
+
*
|
|
5
|
+
* NOTE: This file contains UI-specific logic and should eventually move to the frontend package.
|
|
6
|
+
* It has been updated to work with unified annotation events (annotation.added/removed/body.updated)
|
|
7
|
+
* instead of separate highlight/reference/assessment events.
|
|
8
|
+
*/
|
|
9
|
+
import type { StoredEvent, ResourceEventType } from './events';
|
|
10
|
+
import type { CreationMethod } from './creation-methods';
|
|
11
|
+
import type { components } from '@semiont/api-client';
|
|
12
|
+
import type { AnnotationId } from './identifiers';
|
|
13
|
+
type Annotation = components['schemas']['Annotation'];
|
|
14
|
+
type TranslateFn = (key: string, params?: Record<string, string | number>) => string;
|
|
15
|
+
export declare function formatEventType(type: ResourceEventType, t: TranslateFn): string;
|
|
16
|
+
export declare function getEventEmoji(type: ResourceEventType, event?: StoredEvent): string;
|
|
17
|
+
export declare function formatRelativeTime(timestamp: string, t: TranslateFn): string;
|
|
18
|
+
export declare function getEventDisplayContent(event: StoredEvent, _references: Annotation[], // underscore prefix to indicate intentionally unused for now
|
|
19
|
+
_highlights: Annotation[], // underscore prefix to indicate intentionally unused for now
|
|
20
|
+
allEvents: StoredEvent[]): {
|
|
21
|
+
exact: string;
|
|
22
|
+
isQuoted: boolean;
|
|
23
|
+
isTag: boolean;
|
|
24
|
+
} | null;
|
|
25
|
+
export declare function getEventEntityTypes(event: StoredEvent): string[];
|
|
26
|
+
type ResourceCreatedDetails = {
|
|
27
|
+
type: 'created';
|
|
28
|
+
userId: string;
|
|
29
|
+
method: CreationMethod;
|
|
30
|
+
};
|
|
31
|
+
type ResourceClonedDetails = {
|
|
32
|
+
type: 'cloned';
|
|
33
|
+
userId: string;
|
|
34
|
+
method: CreationMethod;
|
|
35
|
+
sourceDocId: string;
|
|
36
|
+
};
|
|
37
|
+
export type ResourceCreationDetails = ResourceCreatedDetails | ResourceClonedDetails;
|
|
38
|
+
export declare function getResourceCreationDetails(event: StoredEvent): ResourceCreationDetails | null;
|
|
39
|
+
export declare function getAnnotationIdFromEvent(event: StoredEvent): string | null;
|
|
40
|
+
export declare function isEventRelatedToAnnotation(event: StoredEvent, annotationId: AnnotationId): boolean;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=annotation-history-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotation-history-utils.d.ts","sourceRoot":"","sources":["../src/annotation-history-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAQlB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGlD,KAAK,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAC;AAGtD,KAAK,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,MAAM,CAAC;AAGrF,wBAAgB,eAAe,CAAC,IAAI,EAAE,iBAAiB,EAAE,CAAC,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|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for AnnotationHistory component
|
|
4
|
+
* Extracted to reduce component complexity and improve testability
|
|
5
|
+
*
|
|
6
|
+
* NOTE: This file contains UI-specific logic and should eventually move to the frontend package.
|
|
7
|
+
* It has been updated to work with unified annotation events (annotation.added/removed/body.updated)
|
|
8
|
+
* instead of separate highlight/reference/assessment events.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.formatEventType = formatEventType;
|
|
12
|
+
exports.getEventEmoji = getEventEmoji;
|
|
13
|
+
exports.formatRelativeTime = formatRelativeTime;
|
|
14
|
+
exports.getEventDisplayContent = getEventDisplayContent;
|
|
15
|
+
exports.getEventEntityTypes = getEventEntityTypes;
|
|
16
|
+
exports.getResourceCreationDetails = getResourceCreationDetails;
|
|
17
|
+
exports.getAnnotationIdFromEvent = getAnnotationIdFromEvent;
|
|
18
|
+
exports.isEventRelatedToAnnotation = isEventRelatedToAnnotation;
|
|
19
|
+
const api_client_1 = require("@semiont/api-client");
|
|
20
|
+
// Format event type for display
|
|
21
|
+
function formatEventType(type, t) {
|
|
22
|
+
// Using a switch for exhaustive checking - TypeScript will error if we miss a case
|
|
23
|
+
switch (type) {
|
|
24
|
+
case 'resource.created':
|
|
25
|
+
return t('resourceCreated');
|
|
26
|
+
case 'resource.cloned':
|
|
27
|
+
return t('resourceCloned');
|
|
28
|
+
case 'resource.archived':
|
|
29
|
+
return t('resourceArchived');
|
|
30
|
+
case 'resource.unarchived':
|
|
31
|
+
return t('resourceUnarchived');
|
|
32
|
+
case 'annotation.added':
|
|
33
|
+
return t('annotationAdded');
|
|
34
|
+
case 'annotation.removed':
|
|
35
|
+
return t('annotationRemoved');
|
|
36
|
+
case 'annotation.body.updated':
|
|
37
|
+
return t('annotationBodyUpdated');
|
|
38
|
+
case 'entitytag.added':
|
|
39
|
+
return t('entitytagAdded');
|
|
40
|
+
case 'entitytag.removed':
|
|
41
|
+
return t('entitytagRemoved');
|
|
42
|
+
case 'entitytype.added':
|
|
43
|
+
return t('entitytypeAdded');
|
|
44
|
+
case 'job.started':
|
|
45
|
+
return t('jobStarted');
|
|
46
|
+
case 'job.progress':
|
|
47
|
+
return t('jobProgress');
|
|
48
|
+
case 'job.completed':
|
|
49
|
+
return t('jobCompleted');
|
|
50
|
+
case 'job.failed':
|
|
51
|
+
return t('jobFailed');
|
|
52
|
+
default:
|
|
53
|
+
// Exhaustive check: if we get here, we missed a case
|
|
54
|
+
const _exhaustiveCheck = type;
|
|
55
|
+
return _exhaustiveCheck;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Get emoji for annotation based on motivation
|
|
59
|
+
function getMotivationEmoji(motivation) {
|
|
60
|
+
switch (motivation) {
|
|
61
|
+
case 'highlighting':
|
|
62
|
+
return '🟡';
|
|
63
|
+
case 'linking':
|
|
64
|
+
return '🔵';
|
|
65
|
+
case 'assessing':
|
|
66
|
+
return '🔴';
|
|
67
|
+
case 'bookmarking':
|
|
68
|
+
return '🔖';
|
|
69
|
+
case 'commenting':
|
|
70
|
+
return '💬';
|
|
71
|
+
case 'tagging':
|
|
72
|
+
return '🏷️';
|
|
73
|
+
default:
|
|
74
|
+
return '📝';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Get emoji for event type
|
|
78
|
+
function getEventEmoji(type, event) {
|
|
79
|
+
// Using a switch for exhaustive checking - TypeScript will error if we miss a case
|
|
80
|
+
switch (type) {
|
|
81
|
+
case 'resource.created':
|
|
82
|
+
case 'resource.cloned':
|
|
83
|
+
case 'resource.archived':
|
|
84
|
+
case 'resource.unarchived':
|
|
85
|
+
return '📄';
|
|
86
|
+
case 'annotation.added':
|
|
87
|
+
if (event) {
|
|
88
|
+
const payload = event.event.payload;
|
|
89
|
+
return getMotivationEmoji(payload.annotation.motivation);
|
|
90
|
+
}
|
|
91
|
+
return '📝';
|
|
92
|
+
case 'annotation.removed':
|
|
93
|
+
return '🗑️';
|
|
94
|
+
case 'annotation.body.updated':
|
|
95
|
+
return '✏️';
|
|
96
|
+
case 'entitytag.added':
|
|
97
|
+
case 'entitytag.removed':
|
|
98
|
+
return '🏷️';
|
|
99
|
+
case 'entitytype.added':
|
|
100
|
+
return '🏷️'; // Same emoji as entitytag (global entity type collection)
|
|
101
|
+
case 'job.started':
|
|
102
|
+
return '▶️';
|
|
103
|
+
case 'job.progress':
|
|
104
|
+
return '⏳';
|
|
105
|
+
case 'job.completed':
|
|
106
|
+
return '✅';
|
|
107
|
+
case 'job.failed':
|
|
108
|
+
return '❌';
|
|
109
|
+
default:
|
|
110
|
+
// Exhaustive check: if we get here, we missed a case
|
|
111
|
+
const _exhaustiveCheck = type;
|
|
112
|
+
return _exhaustiveCheck;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Format relative time
|
|
116
|
+
function formatRelativeTime(timestamp, t) {
|
|
117
|
+
const date = new Date(timestamp);
|
|
118
|
+
const now = new Date();
|
|
119
|
+
const diffMs = now.getTime() - date.getTime();
|
|
120
|
+
const diffMins = Math.floor(diffMs / 60000);
|
|
121
|
+
const diffHours = Math.floor(diffMs / 3600000);
|
|
122
|
+
const diffDays = Math.floor(diffMs / 86400000);
|
|
123
|
+
if (diffMins < 1)
|
|
124
|
+
return t('justNow');
|
|
125
|
+
if (diffMins < 60)
|
|
126
|
+
return t('minutesAgo', { count: diffMins });
|
|
127
|
+
if (diffHours < 24)
|
|
128
|
+
return t('hoursAgo', { count: diffHours });
|
|
129
|
+
if (diffDays < 7)
|
|
130
|
+
return t('daysAgo', { count: diffDays });
|
|
131
|
+
return date.toLocaleDateString();
|
|
132
|
+
}
|
|
133
|
+
// Helper to truncate text for display
|
|
134
|
+
function truncateText(text, maxLength = 50) {
|
|
135
|
+
const trimmed = text.trim();
|
|
136
|
+
return trimmed.length > maxLength ? trimmed.substring(0, maxLength) + '...' : trimmed;
|
|
137
|
+
}
|
|
138
|
+
// Extract display content from event payload
|
|
139
|
+
function getEventDisplayContent(event, _references, // underscore prefix to indicate intentionally unused for now
|
|
140
|
+
_highlights, // underscore prefix to indicate intentionally unused for now
|
|
141
|
+
allEvents) {
|
|
142
|
+
const eventData = event.event;
|
|
143
|
+
// Use type discriminators instead of runtime typeof checks
|
|
144
|
+
switch (eventData.type) {
|
|
145
|
+
case 'resource.created':
|
|
146
|
+
case 'resource.cloned': {
|
|
147
|
+
const payload = eventData.payload;
|
|
148
|
+
return { exact: payload.name, isQuoted: false, isTag: false };
|
|
149
|
+
}
|
|
150
|
+
case 'annotation.body.updated': {
|
|
151
|
+
const payload = eventData.payload;
|
|
152
|
+
// Find the original annotation.added event to get the text
|
|
153
|
+
const addedEvent = allEvents.find(e => e.event.type === 'annotation.added' &&
|
|
154
|
+
e.event.payload.annotation.id === payload.annotationId);
|
|
155
|
+
if (addedEvent) {
|
|
156
|
+
const addedPayload = addedEvent.event.payload;
|
|
157
|
+
return { exact: truncateText((0, api_client_1.getAnnotationExactText)(addedPayload.annotation)), isQuoted: true, isTag: false };
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
case 'annotation.removed': {
|
|
162
|
+
const payload = eventData.payload;
|
|
163
|
+
// Find the original annotation.added event
|
|
164
|
+
const addedEvent = allEvents.find(e => e.event.type === 'annotation.added' &&
|
|
165
|
+
e.event.payload.annotation.id === payload.annotationId);
|
|
166
|
+
if (addedEvent) {
|
|
167
|
+
const addedPayload = addedEvent.event.payload;
|
|
168
|
+
return { exact: truncateText((0, api_client_1.getAnnotationExactText)(addedPayload.annotation)), isQuoted: true, isTag: false };
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
case 'annotation.added': {
|
|
173
|
+
const payload = eventData.payload;
|
|
174
|
+
return { exact: truncateText((0, api_client_1.getAnnotationExactText)(payload.annotation)), isQuoted: true, isTag: false };
|
|
175
|
+
}
|
|
176
|
+
case 'entitytag.added':
|
|
177
|
+
case 'entitytag.removed': {
|
|
178
|
+
const payload = eventData.payload;
|
|
179
|
+
return { exact: payload.entityType, isQuoted: false, isTag: true };
|
|
180
|
+
}
|
|
181
|
+
default:
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// Extract entity types from event payload
|
|
186
|
+
function getEventEntityTypes(event) {
|
|
187
|
+
const eventData = event.event;
|
|
188
|
+
if (eventData.type === 'annotation.added') {
|
|
189
|
+
const payload = eventData.payload;
|
|
190
|
+
// Extract entity types from W3C annotation
|
|
191
|
+
return (0, api_client_1.getEntityTypes)(payload.annotation);
|
|
192
|
+
}
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
// Format user ID for display
|
|
196
|
+
function formatUserId(userId) {
|
|
197
|
+
// If it's a DID format (did:web:org.com:users:alice), format as alice@org.com
|
|
198
|
+
if (userId.startsWith('did:web:')) {
|
|
199
|
+
const parts = userId.split(':');
|
|
200
|
+
// Format: did:web:org.com:users:alice
|
|
201
|
+
// parts: ['did', 'web', 'org.com', 'users', 'alice']
|
|
202
|
+
if (parts.length >= 5) {
|
|
203
|
+
const domain = parts[2]; // org.com
|
|
204
|
+
const username = parts[parts.length - 1]; // alice
|
|
205
|
+
return `${username}@${domain}`;
|
|
206
|
+
}
|
|
207
|
+
// Fallback if format is unexpected
|
|
208
|
+
const username = parts[parts.length - 1];
|
|
209
|
+
return username || userId.substring(0, 8);
|
|
210
|
+
}
|
|
211
|
+
// Otherwise show first 8 characters of UUID
|
|
212
|
+
return userId.substring(0, 8);
|
|
213
|
+
}
|
|
214
|
+
// Extract additional metadata for resource creation events
|
|
215
|
+
function getResourceCreationDetails(event) {
|
|
216
|
+
const eventData = event.event;
|
|
217
|
+
if (eventData.type === 'resource.created') {
|
|
218
|
+
const payload = eventData.payload;
|
|
219
|
+
return {
|
|
220
|
+
type: 'created',
|
|
221
|
+
userId: formatUserId(eventData.userId),
|
|
222
|
+
method: payload.creationMethod,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
if (eventData.type === 'resource.cloned') {
|
|
226
|
+
const payload = eventData.payload;
|
|
227
|
+
return {
|
|
228
|
+
type: 'cloned',
|
|
229
|
+
userId: formatUserId(eventData.userId),
|
|
230
|
+
method: payload.creationMethod,
|
|
231
|
+
sourceDocId: payload.parentResourceId,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
// Extract annotation ID from event payload
|
|
237
|
+
function getAnnotationIdFromEvent(event) {
|
|
238
|
+
const eventData = event.event;
|
|
239
|
+
switch (eventData.type) {
|
|
240
|
+
case 'annotation.added': {
|
|
241
|
+
const payload = eventData.payload;
|
|
242
|
+
return payload.annotation.id;
|
|
243
|
+
}
|
|
244
|
+
case 'annotation.removed':
|
|
245
|
+
case 'annotation.body.updated': {
|
|
246
|
+
const payload = eventData.payload;
|
|
247
|
+
return payload.annotationId;
|
|
248
|
+
}
|
|
249
|
+
default:
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// Check if event relates to the hovered annotation
|
|
254
|
+
function isEventRelatedToAnnotation(event, annotationId) {
|
|
255
|
+
const eventAnnotationId = getAnnotationIdFromEvent(event);
|
|
256
|
+
return eventAnnotationId === annotationId;
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=annotation-history-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotation-history-utils.js","sourceRoot":"","sources":["../src/annotation-history-utils.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAyBH,0CAoCC;AAuBD,sCAoCC;AAGD,gDAcC;AASD,wDA8DC;AAGD,kDAUC;AAwCD,gEAyBC;AAGD,4DAiBC;AAGD,gEAGC;AAzSD,oDAA6E;AAS7E,gCAAgC;AAChC,SAAgB,eAAe,CAAC,IAAuB,EAAE,CAAc;IACrE,mFAAmF;IACnF,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,kBAAkB;YACrB,OAAO,CAAC,CAAC,iBAAi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tC,MAAM,EAAE,OAAO,CAAC,cAAc;YAC9B,WAAW,EAAE,OAAO,CAAC,gBAAgB;SACtC,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,2CAA2C;AAC3C,SAAgB,wBAAwB,CAAC,KAAkB;IACzD,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC;IAE9B,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;QACvB,KAAK,kBAAkB,CAAC,CAAC,CAAC;YACxB,MAAM,OAAO,GAAG,SAAS,CAAC,OAA0C,CAAC;YACrE,OAAO,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,CAAC;QACD,KAAK,oBAAoB,CAAC;QAC1B,KAAK,yBAAyB,CAAC,CAAC,CAAC;YAC/B,MAAM,OAAO,GAAG,SAAS,CAAC,OAAoF,CAAC;YAC/G,OAAO,OAAO,CAAC,YAAY,CAAC;QAC9B,CAAC;QAED;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC;AAED,mDAAmD;AACnD,SAAgB,0BAA0B,CAAC,KAAkB,EAAE,YAA0B;IACvF,MAAM,iBAAiB,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAC1D,OAAO,iBAAiB,KAAK,YAAY,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Annotation types
|
|
3
|
+
*/
|
|
4
|
+
import type { components } from '@semiont/api-client';
|
|
5
|
+
type Annotation = components['schemas']['Annotation'];
|
|
6
|
+
export type AnnotationCategory = 'highlight' | 'reference';
|
|
7
|
+
export interface CreateAnnotationInternal {
|
|
8
|
+
id: string;
|
|
9
|
+
motivation: Annotation['motivation'];
|
|
10
|
+
target: Annotation['target'];
|
|
11
|
+
body: Annotation['body'];
|
|
12
|
+
creator: components['schemas']['Agent'];
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=annotation-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotation-types.d.ts","sourceRoot":"","sources":["../src/annotation-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,KAAK,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAC;AAEtD,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,WAAW,CAAC;AAE3D,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;IACrC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC7B,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACzB,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC;CACzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotation-types.js","sourceRoot":"","sources":["../src/annotation-types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backend-specific annotation utility functions
|
|
3
|
+
*/
|
|
4
|
+
import type { components } from '@semiont/api-client';
|
|
5
|
+
import type { BodyItem } from './events';
|
|
6
|
+
type Annotation = components['schemas']['Annotation'];
|
|
7
|
+
/**
|
|
8
|
+
* Check if two body items match (for remove/replace operations)
|
|
9
|
+
* Matches by type, value/source, and purpose fields
|
|
10
|
+
*/
|
|
11
|
+
export declare function bodyItemsMatch(item1: BodyItem, item2: BodyItem): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Find a body item in an array
|
|
14
|
+
* Returns the index of the first matching item, or -1 if not found
|
|
15
|
+
*/
|
|
16
|
+
export declare function findBodyItem(body: Annotation['body'], targetItem: BodyItem): number;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=annotation-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotation-utils.d.ts","sourceRoot":"","sources":["../src/annotation-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,KAAK,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAsBxE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,QAAQ,GAAG,MAAM,CA0CnF"}
|