@semiont/core 0.2.34-build.88 → 0.2.34-build.90
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 +50 -18
- package/dist/index.d.ts +3742 -14
- package/dist/index.js +190 -4
- package/dist/index.js.map +1 -1
- package/package.json +9 -6
package/dist/index.js
CHANGED
|
@@ -1,7 +1,66 @@
|
|
|
1
|
-
import {
|
|
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
|
|
102
|
-
return `${
|
|
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,124 @@ 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
|
+
/**
|
|
240
|
+
* Create a resource-scoped event bus
|
|
241
|
+
*
|
|
242
|
+
* Events emitted or subscribed through the scoped bus are isolated to that resource.
|
|
243
|
+
* Internally, events are namespaced but the API remains identical to the parent bus.
|
|
244
|
+
*
|
|
245
|
+
* @param resourceId - Resource identifier to scope events to
|
|
246
|
+
* @returns A scoped event bus for this resource
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* const eventBus = new EventBus();
|
|
251
|
+
* const resource1 = eventBus.scope('resource-1');
|
|
252
|
+
* const resource2 = eventBus.scope('resource-2');
|
|
253
|
+
*
|
|
254
|
+
* // These are isolated - only resource1 subscribers will fire
|
|
255
|
+
* resource1.get('detection:progress').next({ status: 'started' });
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
scope(resourceId2) {
|
|
259
|
+
return new ScopedEventBus(this, resourceId2);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
var ScopedEventBus = class _ScopedEventBus {
|
|
263
|
+
constructor(parent, scopePrefix) {
|
|
264
|
+
this.parent = parent;
|
|
265
|
+
this.scopePrefix = scopePrefix;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Get the RxJS Subject for a scoped event
|
|
269
|
+
*
|
|
270
|
+
* Returns the same type as the parent bus, but events are isolated to this scope.
|
|
271
|
+
* Internally uses namespaced keys but preserves type safety.
|
|
272
|
+
*
|
|
273
|
+
* @param event - The event name
|
|
274
|
+
* @returns The RxJS Subject for this scoped event
|
|
275
|
+
*/
|
|
276
|
+
get(event) {
|
|
277
|
+
const scopedKey = `${this.scopePrefix}:${event}`;
|
|
278
|
+
const parentSubjects = this.parent.subjects;
|
|
279
|
+
if (!parentSubjects.has(scopedKey)) {
|
|
280
|
+
parentSubjects.set(scopedKey, new Subject());
|
|
281
|
+
}
|
|
282
|
+
return parentSubjects.get(scopedKey);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Create a nested scope
|
|
286
|
+
*
|
|
287
|
+
* Allows hierarchical scoping like `resource-1:subsystem-a`
|
|
288
|
+
*
|
|
289
|
+
* @param subScope - Additional scope level
|
|
290
|
+
* @returns A nested scoped event bus
|
|
291
|
+
*/
|
|
292
|
+
scope(subScope) {
|
|
293
|
+
return new _ScopedEventBus(this.parent, `${this.scopePrefix}:${subScope}`);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
117
296
|
|
|
118
297
|
// src/annotation-utils.ts
|
|
119
298
|
function findBodyItem(body, targetItem) {
|
|
@@ -2074,6 +2253,13 @@ function displayConfiguration(config) {
|
|
|
2074
2253
|
console.log("Environment Configuration:");
|
|
2075
2254
|
console.log(JSON.stringify(config, null, 2));
|
|
2076
2255
|
}
|
|
2256
|
+
function createConfigLoader(reader) {
|
|
2257
|
+
return (projectRoot, environment) => {
|
|
2258
|
+
const baseContent = reader.readIfExists(`${projectRoot}/semiont.json`);
|
|
2259
|
+
const envContent = reader.readRequired(`${projectRoot}/environments/${environment}.json`);
|
|
2260
|
+
return parseAndMergeConfigs(baseContent, envContent, process.env, environment, projectRoot);
|
|
2261
|
+
};
|
|
2262
|
+
}
|
|
2077
2263
|
|
|
2078
2264
|
// src/config/environment-validator.ts
|
|
2079
2265
|
function isValidEnvironment(value, availableEnvironments) {
|
|
@@ -2111,6 +2297,6 @@ function getAllPlatformTypes() {
|
|
|
2111
2297
|
var CORE_TYPES_VERSION = "0.1.0";
|
|
2112
2298
|
var SDK_VERSION = "0.1.0";
|
|
2113
2299
|
|
|
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 };
|
|
2300
|
+
export { APIError, CORE_TYPES_VERSION, CREATION_METHODS, ConfigurationError, ConflictError, EventBus, NotFoundError, SDK_VERSION, ScopedEventBus, ScriptError, SemiontError, UnauthorizedError, ValidationError, accessToken, annotationId, annotationIdToURI, annotationUri, authCode, baseUrl, cloneToken, createConfigLoader, 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
2301
|
//# sourceMappingURL=index.js.map
|
|
2116
2302
|
//# sourceMappingURL=index.js.map
|