@semiont/core 0.2.33 → 0.2.34-build.89

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/dist/index.js CHANGED
@@ -1,7 +1,66 @@
1
- import { resourceUri, annotationUri } from '@semiont/api-client';
1
+ import { Subject } from 'rxjs';
2
2
  import Ajv from 'ajv';
3
3
  import addFormats from 'ajv-formats';
4
4
 
5
+ // src/branded-types.ts
6
+ function email(value) {
7
+ return value;
8
+ }
9
+ function authCode(value) {
10
+ return value;
11
+ }
12
+ function googleCredential(value) {
13
+ return value;
14
+ }
15
+ function accessToken(value) {
16
+ return value;
17
+ }
18
+ function refreshToken(value) {
19
+ return value;
20
+ }
21
+ function mcpToken(value) {
22
+ return value;
23
+ }
24
+ function cloneToken(value) {
25
+ return value;
26
+ }
27
+ function jobId(value) {
28
+ return value;
29
+ }
30
+ function userDID(value) {
31
+ return value;
32
+ }
33
+ function entityType(value) {
34
+ return value;
35
+ }
36
+ function searchQuery(value) {
37
+ return value;
38
+ }
39
+ function baseUrl(value) {
40
+ return value;
41
+ }
42
+ function resourceUri(uri) {
43
+ if (!uri.startsWith("http://") && !uri.startsWith("https://")) {
44
+ throw new TypeError(`Expected ResourceUri, got: ${uri}`);
45
+ }
46
+ return uri;
47
+ }
48
+ function annotationUri(uri) {
49
+ if (!uri.startsWith("http://") && !uri.startsWith("https://")) {
50
+ throw new TypeError(`Expected AnnotationUri, got: ${uri}`);
51
+ }
52
+ return uri;
53
+ }
54
+ function resourceAnnotationUri(uri) {
55
+ if (!uri.startsWith("http://") && !uri.startsWith("https://")) {
56
+ throw new TypeError(`Expected ResourceAnnotationUri, got: ${uri}`);
57
+ }
58
+ if (!uri.includes("/resources/") || !uri.includes("/annotations/")) {
59
+ throw new TypeError(`Expected nested ResourceAnnotationUri format, got: ${uri}`);
60
+ }
61
+ return uri;
62
+ }
63
+
5
64
  // src/creation-methods.ts
6
65
  var CREATION_METHODS = {
7
66
  API: "api",
@@ -34,6 +93,8 @@ function annotationId(id) {
34
93
  function userId(id) {
35
94
  return id;
36
95
  }
96
+
97
+ // src/uri-utils.ts
37
98
  function resourceIdToURI(id, publicURL) {
38
99
  const normalizedBase = publicURL.endsWith("/") ? publicURL.slice(0, -1) : publicURL;
39
100
  return resourceUri(`${normalizedBase}/resources/${id}`);
@@ -98,8 +159,8 @@ function getAnnotationUriFromEvent(event) {
98
159
  if (eventData.payload.annotationId && eventData.resourceId) {
99
160
  try {
100
161
  const resourceUri2 = eventData.resourceId;
101
- const baseUrl = resourceUri2.substring(0, resourceUri2.lastIndexOf("/resources/"));
102
- return `${baseUrl}/annotations/${eventData.payload.annotationId}`;
162
+ const baseUrl2 = resourceUri2.substring(0, resourceUri2.lastIndexOf("/resources/"));
163
+ return `${baseUrl2}/annotations/${eventData.payload.annotationId}`;
103
164
  } catch (e) {
104
165
  return null;
105
166
  }
@@ -114,6 +175,68 @@ function isEventRelatedToAnnotation(event, annotationUri2) {
114
175
  function isResourceEvent2(event) {
115
176
  return event && typeof event.event === "object" && typeof event.event.id === "string" && typeof event.event.timestamp === "string" && typeof event.event.resourceId === "string" && typeof event.event.type === "string" && typeof event.metadata === "object" && typeof event.metadata.sequenceNumber === "number";
116
177
  }
178
+ var EventBus = class {
179
+ subjects;
180
+ isDestroyed;
181
+ constructor() {
182
+ this.subjects = /* @__PURE__ */ new Map();
183
+ this.isDestroyed = false;
184
+ }
185
+ /**
186
+ * Get the RxJS Subject for an event
187
+ *
188
+ * Returns a typed Subject that can be used with all RxJS operators.
189
+ * Subjects are created lazily on first access.
190
+ *
191
+ * @param eventName - The event name
192
+ * @returns The RxJS Subject for this event
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * // Emit
197
+ * eventBus.get('annotation:hover').next({ annotationId: 'ann-1' });
198
+ *
199
+ * // Subscribe
200
+ * const sub = eventBus.get('annotation:hover').subscribe(handleHover);
201
+ *
202
+ * // With operators
203
+ * eventBus.get('annotation:hover')
204
+ * .pipe(debounceTime(100), distinctUntilChanged())
205
+ * .subscribe(handleHover);
206
+ * ```
207
+ */
208
+ get(eventName) {
209
+ if (this.isDestroyed) {
210
+ throw new Error(`Cannot access event '${String(eventName)}' on destroyed bus`);
211
+ }
212
+ if (!this.subjects.has(eventName)) {
213
+ this.subjects.set(eventName, new Subject());
214
+ }
215
+ return this.subjects.get(eventName);
216
+ }
217
+ /**
218
+ * Destroy the event bus and complete all subjects
219
+ *
220
+ * After calling destroy(), no new events can be emitted or subscribed to.
221
+ * All active subscriptions will be completed.
222
+ */
223
+ destroy() {
224
+ if (this.isDestroyed) {
225
+ return;
226
+ }
227
+ for (const subject of this.subjects.values()) {
228
+ subject.complete();
229
+ }
230
+ this.subjects.clear();
231
+ this.isDestroyed = true;
232
+ }
233
+ /**
234
+ * Check if the event bus has been destroyed
235
+ */
236
+ get destroyed() {
237
+ return this.isDestroyed;
238
+ }
239
+ };
117
240
 
118
241
  // src/annotation-utils.ts
119
242
  function findBodyItem(body, targetItem) {
@@ -2111,6 +2234,6 @@ function getAllPlatformTypes() {
2111
2234
  var CORE_TYPES_VERSION = "0.1.0";
2112
2235
  var SDK_VERSION = "0.1.0";
2113
2236
 
2114
- export { APIError, CORE_TYPES_VERSION, CREATION_METHODS, ConfigurationError, ConflictError, NotFoundError, SDK_VERSION, ScriptError, SemiontError, UnauthorizedError, ValidationError, annotationId, annotationIdToURI, deepMerge, didToAgent, displayConfiguration, extractResourceUriFromAnnotationUri, findBodyItem, formatErrors, getAllPlatformTypes, getAnnotationUriFromEvent, getEventType, getNodeEnvForEnvironment, hasAWSConfig, isAnnotationId, isArray, isBoolean, isDefined, isEventRelatedToAnnotation, isFunction, isNull, isNullish, isNumber, isObject, isResourceEvent, isResourceId, isResourceScopedEvent, isResourceEvent2 as isStoredEvent, isString, isSystemEvent, isUndefined, isValidPlatformType, listEnvironmentNames, parseAndMergeConfigs, parseEnvironment, resolveEnvVars, resourceId, resourceIdToURI, uriToAnnotationId, uriToAnnotationIdOrPassthrough, uriToResourceId, userId, userToAgent, userToDid, validateEnvironment, validateEnvironmentConfig, validateSemiontConfig, validateSiteConfig };
2237
+ export { APIError, CORE_TYPES_VERSION, CREATION_METHODS, ConfigurationError, ConflictError, EventBus, NotFoundError, SDK_VERSION, ScriptError, SemiontError, UnauthorizedError, ValidationError, accessToken, annotationId, annotationIdToURI, annotationUri, authCode, baseUrl, cloneToken, deepMerge, didToAgent, displayConfiguration, email, entityType, extractResourceUriFromAnnotationUri, findBodyItem, formatErrors, getAllPlatformTypes, getAnnotationUriFromEvent, getEventType, getNodeEnvForEnvironment, googleCredential, hasAWSConfig, isAnnotationId, isArray, isBoolean, isDefined, isEventRelatedToAnnotation, isFunction, isNull, isNullish, isNumber, isObject, isResourceEvent, isResourceId, isResourceScopedEvent, isResourceEvent2 as isStoredEvent, isString, isSystemEvent, isUndefined, isValidPlatformType, jobId, listEnvironmentNames, mcpToken, parseAndMergeConfigs, parseEnvironment, refreshToken, resolveEnvVars, resourceAnnotationUri, resourceId, resourceIdToURI, resourceUri, searchQuery, uriToAnnotationId, uriToAnnotationIdOrPassthrough, uriToResourceId, userDID, userId, userToAgent, userToDid, validateEnvironment, validateEnvironmentConfig, validateSemiontConfig, validateSiteConfig };
2115
2238
  //# sourceMappingURL=index.js.map
2116
2239
  //# sourceMappingURL=index.js.map