@ghentcdh/annotation-api 0.0.1-alpha.1 → 0.0.1-alpha.13

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/index.js CHANGED
@@ -1,369 +1,813 @@
1
- import { Controller as e, Get as t, Inject as n, Injectable as r, Module as i, NotFoundException as a, Param as o } from "@nestjs/common";
2
- import { z as s } from "zod";
3
- import { contextBuilder as c } from "@ghentcdh/w3c-utils";
4
- import "@ghentcdh/annotated-text";
5
- import { existsSync as l, readFileSync as u, readdirSync as d } from "node:fs";
6
- import { join as f } from "node:path";
7
- import { ApiTags as p } from "@nestjs/swagger";
8
- //#region packages/annotation-core/src/lib/types/annotation.contex.ts
9
- var m = "AnnotationMetadata", h = s.object({}), g = s.object({
10
- id: s.string(),
11
- name: s.string(),
12
- columns: s.array(h),
13
- json_schema: s.any().optional(),
14
- json_ld: s.any().optional(),
15
- ui_schema: s.any().optional(),
16
- metadata_schema: s.any().optional(),
17
- color: s.string(),
18
- type: s.string().optional(),
19
- icon: s.string().optional(),
20
- isRoot: s.boolean().default(!0),
21
- allowedChildren: s.array(s.string()).optional(),
22
- allowedLinks: s.array(s.string()).optional(),
23
- context: s.custom(),
24
- target: s.enum([
25
- "gutter",
26
- "underline",
27
- "highlight"
28
- ]).optional()
29
- }), _ = {
30
- baseUrl: "http://localhost:3000/",
1
+ import { Body, Controller, Delete, Get, Inject, Injectable, Module, Param, Patch, Post } from "@nestjs/common";
2
+ import { z } from "zod";
3
+ import { ContextBuilder, contextBuilder, w3cAnnotation } from "@ghentcdh/w3c-utils";
4
+ import { JsonOperationsSchema, ResourceJsonShape, ViewConfigSchema, labelFromId, registerResourceExtensions } from "@ghentcdh/crouton-core";
5
+ import { Debugger, PlainTextAdapter, W3CAnnotationAdapter, WordSnapper, createAnnotatedText, createHighlightStyle } from "@ghentcdh/annotated-text";
6
+ import { CroutonApiModule, ResourceConfigRegistry } from "@ghentcdh/crouton-api";
7
+ import { ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from "@nestjs/swagger";
8
+ //#region src/lib/annotation/annotation.repository.ts
9
+ var AnnotationCrudRepository = class {};
10
+ //#endregion
11
+ //#region ../annotation-core/src/lib/types/key-label.type.ts
12
+ var KeyLabelSchema = z.object();
13
+ //#endregion
14
+ //#region ../annotation-core/src/lib/types/source.model.ts
15
+ var SourceTypesList = ["text"];
16
+ var SourceTextSchema = z.object({
17
+ text: z.string(),
18
+ textDirection: z.enum(["ltr", "rtl"]).default("ltr"),
19
+ processingLanguage: z.string().default("en"),
20
+ label: z.string().optional(),
21
+ offset: z.number().optional().default(0)
22
+ });
23
+ var SourceModelSchema = z.object({
24
+ id: z.string(),
25
+ uri: z.string(),
26
+ type: z.enum(SourceTypesList),
27
+ content: SourceTextSchema
28
+ });
29
+ //#endregion
30
+ //#region ../annotation-core/src/lib/types/grid-layout.types.ts
31
+ /** Computed CSS styles for the grid container */
32
+ var buildGridStyle = (layout) => {
33
+ const templateAreas = layout.areas.map((row) => `"${row.join(" ")}"`).join(" ");
34
+ const colCount = layout.areas[0]?.length ?? 1;
35
+ const style = {
36
+ gridTemplateAreas: templateAreas,
37
+ gridTemplateColumns: layout.columns ?? Array(colCount).fill("minmax(0, 1fr)").join(" ")
38
+ };
39
+ if (layout.rows) style["gridTemplateRows"] = layout.rows;
40
+ return style;
41
+ };
42
+ /** Returns the grid-area CSS value for a given source id, or undefined if not configured */
43
+ var getPaneArea = (layout, sourceId) => {
44
+ return layout.panes.find((p) => p.sourceId === sourceId)?.area;
45
+ };
46
+ //#endregion
47
+ //#region ../annotation-core/src/lib/utils/annotation.context-builder.ts
48
+ var defaultConfig = {
49
+ baseUrl: "http://localhost:3333/",
50
+ crudController: "annotation/annotation",
31
51
  app: "ghentcdh",
32
52
  prefix: "ghentcdh",
33
- isDev: !1,
53
+ isDev: false,
34
54
  cacheTTLms: 1200 * 1e3
35
- }, v = (e = {}) => {
36
- let t = e.baseUrl ?? _.baseUrl, n = t.endsWith("/") ? t : `${t}/`, r = e.isDev ?? !1, i = r ? 0 : 1200 * 1e3;
55
+ };
56
+ var resolveConfig = (config = {}) => {
57
+ const baseUrl = config.baseUrl ?? defaultConfig.baseUrl;
58
+ const normalizedBaseUrl = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
59
+ const isDev = config.isDev ?? false;
60
+ const cacheTTLms = isDev ? 0 : 1200 * 1e3;
61
+ return {
62
+ baseUrl: normalizedBaseUrl,
63
+ contextUrl: `${normalizedBaseUrl}ns/`,
64
+ app: config.app ?? defaultConfig.app,
65
+ prefix: config.prefix ?? defaultConfig.prefix,
66
+ crudController: config.crudController ?? defaultConfig.crudController,
67
+ isDev,
68
+ cacheTTLms
69
+ };
70
+ };
71
+ var baseContextBuilder = (id, config) => {
72
+ const { prefix, baseUrl, contextUrl } = resolveConfig(config);
73
+ const metaData = AnnotationMetadataType;
74
+ return contextBuilder(prefix, baseUrl).setType(prefix, metaData).addPrefix(id, `${prefix}:${id}`).setContextUri(`${contextUrl}${id}.jsonld`);
75
+ };
76
+ //#endregion
77
+ //#region ../annotation-core/src/lib/types/annotation.contex.ts
78
+ var AnnotationMetadataType = "AnnotationMetadata";
79
+ var createAnnotationContext = (annotationDefConfig, resource) => {
80
+ const formView = resource.views?.["form"];
81
+ const builder = baseContextBuilder(resource.id, annotationDefConfig);
82
+ if (formView) builder.parseJsonSchema(formView.json_schema);
37
83
  return {
38
- baseUrl: n,
39
- contextUrl: `${n}ns/`,
40
- app: e.app ?? _.app,
41
- prefix: e.prefix ?? _.prefix,
42
- isDev: r,
43
- cacheTTLms: i
84
+ id: resource.id,
85
+ styling: {
86
+ name: resource.name,
87
+ id: resource.id,
88
+ target: resource.annotation.target,
89
+ color: resource.annotation.color
90
+ },
91
+ hasContext: !!formView,
92
+ prefix: buildPrefix(annotationDefConfig, resource),
93
+ uri: builder.uri,
94
+ jsonLd: builder.toJsonLdContext(),
95
+ safeParse: builder.safeParse.bind(builder),
96
+ toAnnotationBody: builder.toAnnotationBody.bind(builder)
44
97
  };
45
- }, y = (e, t) => {
46
- let { prefix: n, baseUrl: r, contextUrl: i } = v(t), a = m;
47
- return c(n, r).setType(n, a).addPrefix(e, `${n}:${e}`).setContextUri(`${i}${e}.jsonld`);
48
- }, b = s.object({
49
- id: s.string(),
50
- name: s.string(),
51
- target: s.enum([
98
+ };
99
+ var buildPrefix = (annotationDefConfig, resource) => {
100
+ return `${annotationDefConfig.prefix}:${resource.annotation.type}/`;
101
+ };
102
+ //#endregion
103
+ //#region ../annotation-core/src/lib/types/version.ts
104
+ /**
105
+ * resource.json schema versioning.
106
+ *
107
+ * `schemaVersion` is a monotonic integer stamped on every `resource.json`. It is
108
+ * **decoupled from the crouton package semver** on purpose — bump it only when the
109
+ * resource.json *shape* changes in a way that needs a migration, and ship a matching
110
+ * step in `./migrations`. This keeps the migration chain one-step-per-bump with no
111
+ * version-range math.
112
+ *
113
+ * Files written before versioning existed carry no field and are treated as the
114
+ * baseline. Because `CURRENT_RESOURCE_VERSION` starts equal to the baseline, shipping
115
+ * the versioning machinery is a pure no-op for every existing file until the first
116
+ * real shape change lands (`CURRENT_RESOURCE_VERSION = 2` + a `1 → 2` migration).
117
+ */
118
+ /** Version assumed for a `resource.json` that has no `schemaVersion` field. */
119
+ var BASELINE_RESOURCE_VERSION = 1;
120
+ /**
121
+ * The version the running crouton understands. Bump by 1 whenever resource.json's
122
+ * shape changes, and add a migration step (`from: N, to: N + 1`) in `./migrations`.
123
+ */
124
+ var CURRENT_RESOURCE_VERSION = 1;
125
+ //#endregion
126
+ //#region ../annotation-core/src/lib/types/annotation-json-config.types.ts
127
+ var AnnotationTargetEnum = z.enum([
128
+ "gutter",
129
+ "underline",
130
+ "highlight"
131
+ ]);
132
+ var AnnotationConfigSchema = z.object({
133
+ color: z.string().optional(),
134
+ type: z.string().optional(),
135
+ icon: z.string().optional(),
136
+ isRoot: z.boolean().optional().default(true),
137
+ allowedChildren: z.array(z.string()).optional().default([]),
138
+ allowedLinks: z.array(z.string()).optional().default([]),
139
+ target: AnnotationTargetEnum.optional().default("highlight")
140
+ });
141
+ var AnnotationJsonResourceShape = ResourceJsonShape.extend({
142
+ route: z.string().optional(),
143
+ tag: z.string().optional(),
144
+ operations: JsonOperationsSchema.optional().default(JsonOperationsSchema.parse({})),
145
+ id: z.string(),
146
+ annotation: AnnotationConfigSchema.optional().default(AnnotationConfigSchema.parse({}))
147
+ }).passthrough();
148
+ var AnnotationJsonResourceSchema = AnnotationJsonResourceShape.transform((obj) => {
149
+ const title = labelFromId(obj.name);
150
+ return {
151
+ schemaVersion: obj.schemaVersion ?? 1,
152
+ title,
153
+ ...obj
154
+ };
155
+ });
156
+ //#endregion
157
+ //#region ../annotation-core/src/lib/types/annotation-definition.type.ts
158
+ var annotationColumnDefinition = z.custom();
159
+ var AnnotationResourceSchema = AnnotationJsonResourceShape.pick({
160
+ id: true,
161
+ name: true,
162
+ title: true,
163
+ operations: true,
164
+ annotation: true
165
+ }).extend({
166
+ annotation: AnnotationConfigSchema,
167
+ context: z.instanceof(ContextBuilder).optional().nullish(),
168
+ schemas: z.record(z.string(), ViewConfigSchema.partial()).optional().nullish()
169
+ });
170
+ //#endregion
171
+ //#region ../annotation-core/src/lib/annotation.style.ts
172
+ var CONTEXT = "annotation.style";
173
+ var AnnotationStyleSchema = z.object({
174
+ id: z.string(),
175
+ name: z.string(),
176
+ target: z.enum([
52
177
  "gutter",
53
178
  "underline",
54
179
  "highlight"
55
180
  ]).optional().default("underline"),
56
- color: s.string().optional()
57
- }), x = "AnnotationStyle", S = (e) => {
58
- let { prefix: t, baseUrl: n, contextUrl: r } = v(e);
59
- return c(t, n).setType(t, x).setContextUri(`${r}${x}.jsonld`).parseZodSchema(b);
60
- }, C = (e) => {
61
- let t = {};
62
- if (e.fieldInput) {
63
- let { type: n, options: r } = e.fieldInput;
64
- t.format = n, n === "autocomplete" && (t.dataField = "data", r.uri && (t.uri = r.uri), r.resource && (t.resource = r.resource), r.valueKey && (t.valueKey = r.valueKey), r.labelKey && (t.labelKey = r.labelKey), r.enableCreate !== void 0 && (t.enableCreate = r.enableCreate));
181
+ color: z.string().optional()
182
+ });
183
+ var AnnotationStyleType = "AnnotationStyle";
184
+ var AnnotationStyleContextBuilder = (annotationConfig) => {
185
+ const { prefix, baseUrl, contextUrl } = resolveConfig(annotationConfig);
186
+ return contextBuilder(prefix, baseUrl).setType(prefix, AnnotationStyleType).setContextUri(`${contextUrl}${AnnotationStyleType}.jsonld`).parseZodSchema(AnnotationStyleSchema);
187
+ };
188
+ var createAnnotationStyleBodyUnsafe = (annotationConfig, style) => {
189
+ const resource = {
190
+ ...style,
191
+ ...style.annotation
192
+ };
193
+ const parsed = AnnotationStyleContextBuilder(annotationConfig).toAnnotationBodyUnsafe(resource);
194
+ if (!parsed.success) {
195
+ Debugger.debug(CONTEXT, "AnnotationStyleContextBuilder safe parse failed");
196
+ Debugger.warn(parsed.error);
65
197
  }
198
+ return parsed;
199
+ };
200
+ //#endregion
201
+ //#region ../annotation-core/src/lib/utils/annotation-utils.ts
202
+ var mapRelationsToLinks = (sourceUri, builders, annotations) => {
203
+ return annotations.map((link) => {
204
+ const builder = builders.get(link.id);
205
+ const specifyResource = builder.getSpecificResourceTargets(sourceUri);
206
+ if (!specifyResource || specifyResource.length === 0) return null;
207
+ const relations = builder.getSpecificResourceTargets().map((s) => s.source).filter((s) => s !== sourceUri).map((uri) => {
208
+ return annotations.find((a) => a.id === uri);
209
+ }).filter(Boolean);
210
+ return {
211
+ purpose: getAnnotationType(builder),
212
+ annotation: link,
213
+ relations
214
+ };
215
+ }).filter(Boolean);
216
+ };
217
+ var getAnnotationType = (builder) => {
218
+ return getAnnotationStyle(builder)?.id ?? "text";
219
+ };
220
+ var getAnnotationStyle = (builder) => {
221
+ return builder.getBodiesByPurpose("styling").find((b) => b.type === "AnnotationStyle");
222
+ };
223
+ var getAnnotationPosition = (id, builder, allowedChildrenPerType) => {
224
+ const sourceUri = builder.getSpecificResourceTargets()[0]?.source;
225
+ if (!sourceUri) return null;
226
+ const textPositionSelector = builder.getTextPositionSelector(sourceUri)[0];
227
+ if (!textPositionSelector) return null;
228
+ const type = getAnnotationStyle(builder)?.id ?? "text";
66
229
  return {
67
- type: "Control",
68
- scope: `#/properties/${e.id}`,
69
- options: t
230
+ id,
231
+ start: textPositionSelector.start,
232
+ end: textPositionSelector.end,
233
+ allowedChildren: allowedChildrenPerType[type] ?? [],
234
+ sourceUri: sourceUri ?? "",
235
+ type,
236
+ minX: textPositionSelector.start,
237
+ minY: 0,
238
+ maxX: textPositionSelector.end,
239
+ maxY: 0
70
240
  };
71
- }, w = (e) => ({
72
- type: "TextCell",
73
- scope: `#/properties/${e.id}`,
74
- options: {
75
- format: "keyValue",
76
- key: e.fieldInput?.options?.labelKey ?? e.displayKey ?? "label"
241
+ };
242
+ var rootId = "ROOT";
243
+ var createId = () => {
244
+ return `mela:new-annotation:${Date.now()}`;
245
+ };
246
+ var updateSelector = (builder, selector) => {
247
+ if (!builder.getSpecificResourceTargets(selector.source).length) builder.addTarget({
248
+ type: "SpecificResource",
249
+ source: selector.source
250
+ });
251
+ builder.updateTextPositionSelector({
252
+ start: selector.start,
253
+ end: selector.end
254
+ }, selector.source);
255
+ builder.updateTextQuoteSelector({
256
+ prefix: selector.prefix,
257
+ suffix: selector.suffix,
258
+ exact: selector.exact
259
+ }, selector.source);
260
+ return builder;
261
+ };
262
+ var AnnotationUtilsImpl = class {
263
+ annotationConfig;
264
+ builderMap = /* @__PURE__ */ new Map();
265
+ childParentMap = /* @__PURE__ */ new Map();
266
+ parentChildMap = /* @__PURE__ */ new Map();
267
+ linkedAnnotations = /* @__PURE__ */ new Map();
268
+ annotations = [];
269
+ allowedChildrenPerType = {};
270
+ constructor(annotationConfig) {
271
+ this.annotationConfig = annotationConfig;
272
+ }
273
+ getBuilder(annotation) {
274
+ const builder = this.builderMap.get(annotation.id);
275
+ if (!builder) throw new Error(`Annotation builder not found: ${annotation.id}`);
276
+ return builder;
277
+ }
278
+ setAnnotations(annotations, allowedChildrenPerType) {
279
+ this.allowedChildrenPerType = allowedChildrenPerType;
280
+ this.annotations = annotations;
281
+ this.parentChildMap.clear();
282
+ this.childParentMap.clear();
283
+ this.builderMap.clear();
284
+ const annotationsWithPositons = [];
285
+ const annotationIdMap = /* @__PURE__ */ new Map();
286
+ annotations.forEach((annotation) => {
287
+ const builder = w3cAnnotation(annotation);
288
+ this.builderMap.set(annotation.id, builder);
289
+ const position = getAnnotationPosition(annotation.id, builder, this.allowedChildrenPerType);
290
+ annotationIdMap.set(annotation.id, annotation);
291
+ if (position) annotationsWithPositons.push(position);
292
+ });
293
+ annotationsWithPositons.forEach((annotation) => {
294
+ const parentAnnotation = annotationsWithPositons.filter((a) => a.id !== annotation.id && a.sourceUri === annotation.sourceUri && a.start <= annotation.start && a.end >= annotation.end && a.allowedChildren.some((c) => c.key === annotation.type)).sort((a, b) => a.end - a.start - (b.end - b.start))[0];
295
+ const parentId = parentAnnotation?.id ?? rootId;
296
+ const children = this.parentChildMap.get(parentId) ?? [];
297
+ children.push(annotationIdMap.get(annotation.id));
298
+ this.parentChildMap.set(parentAnnotation?.id ?? rootId, children);
299
+ this.childParentMap.set(annotation.id, annotationIdMap.get(parentId) ?? null);
300
+ });
301
+ annotations.forEach((annotation) => {
302
+ this.linkedAnnotations.set(annotation.id, mapRelationsToLinks(annotation.id, this.builderMap, annotations));
303
+ });
304
+ return this;
77
305
  }
78
- }), T = (e) => ({
79
- type: "GridLayout",
80
- elements: e.filter((e) => !e.hiddenInForm).map(C),
81
- options: {}
82
- }), E = (e) => ({
83
- type: "GridLayout",
84
- elements: e.filter((e) => !e.hiddenInMetadata).map(w),
85
- options: {}
86
- }), D = (e) => {
87
- if (e.type === "object" && e.properties) {
88
- let t = {};
89
- for (let [n, r] of Object.entries(e.properties)) t[n] = D(r);
90
- return s.object(t);
306
+ getLinks(annotation) {
307
+ return this.linkedAnnotations.get(annotation.id) ?? [];
91
308
  }
92
- return s.string();
93
- }, O = (e, t, n) => {
94
- let r = y(e, n), i = t.columns ?? [];
95
- if (!i.length) return r;
96
- let a = {};
97
- for (let e of i) e.type && (a[e.id] = D(e.type));
98
- return Object.keys(a).length ? r.parseZodSchema(s.object(a)) : r;
99
- }, k = (e, t, n = O) => {
100
- let r = n(e.id, e, t), i = e.columns ?? [], a = i.length > 0, o = e.ui_schema ?? (a ? T(i) : void 0), s = e.metadata_schema ?? (a ? E(i) : void 0), c = {
101
- id: e.id,
102
- name: e.name,
103
- color: e.color,
104
- isRoot: e.isRoot ?? !0,
105
- columns: i,
106
- context: r,
107
- json_ld: r.toJsonLdContext(),
108
- json_schema: o ? r.toJsonSchema() : null
309
+ getTextPositionSelector(annotation, sourceUri) {
310
+ return this.getBuilder(annotation).getTextPositionSelector(sourceUri)[0];
311
+ }
312
+ isAnnotationUri = (uri) => {
313
+ return uri.startsWith("mela:annotation/");
314
+ };
315
+ getParentSelector = (builder) => {
316
+ return builder.getSpecificResourceTargets().find((t) => this.isAnnotationUri(t.source)) ?? null;
317
+ };
318
+ getParent(annotation) {
319
+ const builder = this.getBuilder(annotation);
320
+ const parentUri = this.getParentSelector(builder);
321
+ if (!parentUri) return null;
322
+ return this.annotations.find((a) => a.id === parentUri.source) ?? null;
323
+ }
324
+ createAnnotation(fromAnnotation, type, data, selectors) {
325
+ const styleBody = AnnotationStyleContextBuilder(this.annotationConfig).toAnnotationBody(type);
326
+ const builder = w3cAnnotation(fromAnnotation ?? void 0).setMotivation("tagging").addBody(styleBody);
327
+ if (!fromAnnotation?.id) builder.setId(createId());
328
+ if (data && Object.keys(data).length > 0) {
329
+ data.type = data.type ?? "AnnotationMetadata";
330
+ data.purpose = data.purpose ?? getAnnotationType(builder);
331
+ builder.updateBodyByType(data.type, data);
332
+ }
333
+ for (const selector of selectors) updateSelector(builder, selector);
334
+ return builder.build();
335
+ }
336
+ createLinkAnnotation = (sourceAnnotation, targetAnnotation, type, data) => {
337
+ const styleBody = AnnotationStyleContextBuilder(this.annotationConfig).toAnnotationBody(type);
338
+ const builder = w3cAnnotation().setMotivation("tagging").setId(createId()).addBody(styleBody);
339
+ if (data && Object.keys(data).length > 0) {
340
+ data.type = data.type ?? "AnnotationMetadata";
341
+ data.purpose = data.purpose ?? getAnnotationType(builder);
342
+ builder.updateBodyByType(data.type, data);
343
+ }
344
+ builder.addTarget({ source: sourceAnnotation.id }).addTarget({ source: targetAnnotation.id });
345
+ return builder.build();
346
+ };
347
+ cancel() {
348
+ this.setAnnotations(this.annotations, this.allowedChildrenPerType);
349
+ }
350
+ getSourceUri = (annotation) => {
351
+ const builder = this.getBuilder(annotation);
352
+ const sourceUri = builder.getSourceUri();
353
+ if (!sourceUri) {
354
+ console.warn("no source uri");
355
+ return null;
356
+ }
357
+ return {
358
+ textPositionSelector: builder.getTextPositionSelector(sourceUri)[0],
359
+ sourceUri
360
+ };
361
+ };
362
+ getMetadata = (annotation) => {
363
+ return this.getBuilder(annotation).getBodiesByType("AnnotationMetadata")?.[0] ?? null;
364
+ };
365
+ getAnnotationStyle = (annotation) => {
366
+ return getAnnotationStyle(this.getBuilder(annotation));
367
+ };
368
+ getAnnotationType = (annotation) => {
369
+ return getAnnotationType(this.getBuilder(annotation));
109
370
  };
110
- return o && (c.ui_schema = o), s && (c.metadata_schema = s), e.type && (c.type = e.type), e.icon && (c.icon = e.icon), e.target && (c.target = e.target), e.allowedChildren && (c.allowedChildren = e.allowedChildren), e.allowedLinks && (c.allowedLinks = e.allowedLinks), c;
111
- }, A = Symbol("ANNOTATION_DEF_CONFIG_TOKEN");
371
+ createAnnotationFromSelector(type, annotation, selector) {
372
+ const builder = w3cAnnotation(annotation ?? void 0).setMotivation("tagging").setId(createId());
373
+ const styleBody = AnnotationStyleContextBuilder(this.annotationConfig).toAnnotationBody(type);
374
+ builder.addBody(styleBody);
375
+ if (selector) updateSelector(builder, selector);
376
+ return builder.build();
377
+ }
378
+ };
379
+ var annotationUtils = (annotationConfig) => {
380
+ return new AnnotationUtilsImpl(annotationConfig);
381
+ };
382
+ //#endregion
383
+ //#region ../annotation-core/src/lib/utils/annotation-render.style.ts
384
+ var defaultRender = (utils) => (annotation) => {
385
+ return (utils?.getAnnotationStyle(annotation))?.target ?? "default";
386
+ };
387
+ var styleFn = (listStyles, utils) => (annotation) => {
388
+ const style = utils?.getAnnotationStyle(annotation);
389
+ if (!style) return "default";
390
+ const styleId = style?.id ?? "default";
391
+ if (!listStyles.includes(styleId)) {
392
+ Debugger.debug("styleFn", `No style found for ${styleId}`);
393
+ if (style.color) return { default: createHighlightStyle(style.color) };
394
+ return "default";
395
+ }
396
+ return styleId;
397
+ };
112
398
  //#endregion
113
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateMetadata.js
114
- function j(e, t) {
115
- if (typeof Reflect == "object" && typeof Reflect.metadata == "function") return Reflect.metadata(e, t);
399
+ //#region ../annotation-core/src/lib/utils/annotation-configuration.factory.ts
400
+ var groupById = (defs, valueKey) => {
401
+ if (!defs) return {};
402
+ return defs.reduce((acc, def) => {
403
+ acc[def.id] = valueKey ? def[valueKey] : def;
404
+ return acc;
405
+ }, {});
406
+ };
407
+ var createAnnotationConfiguration = (annotationDefinitions, utils, textAdapter, annotationAdapter) => {
408
+ const definitions = annotationDefinitions ?? [];
409
+ const definitionsMap = groupById(definitions);
410
+ const rootTypes = definitions.filter((d) => d.annotation.isRoot).map((d) => ({
411
+ key: d.id,
412
+ label: d.label
413
+ }));
414
+ const styles = groupById(definitions, "style");
415
+ if (!styles["default"]) styles["default"] = {
416
+ label: "Annotation",
417
+ isRoot: true,
418
+ style: { default: createHighlightStyle("#dd7777") },
419
+ allowedChildren: [],
420
+ allowedLinks: [],
421
+ views: {}
422
+ };
423
+ const listStyles = Object.keys(styles);
424
+ const allowedChildrenPerType = groupById(definitions, "allowedChildren");
425
+ const defaultAnnotationAdapter = (source) => W3CAnnotationAdapter(source ? { sourceUri: source.uri } : {});
426
+ const renderParams = () => ({ renderFn: defaultRender(utils) });
427
+ const styleParams = () => ({ styleFn: styleFn(listStyles, utils) });
428
+ const _createAnnotatedText = (id, sourceModel) => {
429
+ const _textAdapter = textAdapter?.() ?? PlainTextAdapter();
430
+ const annotatedText = createAnnotatedText(id, {
431
+ annotationAdapter: annotationAdapter?.() ?? defaultAnnotationAdapter(sourceModel),
432
+ textAdapter: _textAdapter
433
+ });
434
+ annotatedText.setSnapper(new WordSnapper()).setRenderParams(renderParams()).setStyleParams(styleParams()).registerStyles(styles);
435
+ if (sourceModel) {
436
+ const { content } = sourceModel;
437
+ annotatedText.setText(content.text).setTextAdapterParams({ textDirection: content.textDirection });
438
+ }
439
+ return annotatedText;
440
+ };
441
+ return {
442
+ allowedChildrenPerType,
443
+ definitions,
444
+ getDefinition: (id) => {
445
+ return definitionsMap[id] ?? void 0;
446
+ },
447
+ rootTypes,
448
+ createAnnotatedText: _createAnnotatedText
449
+ };
450
+ };
451
+ //#endregion
452
+ //#region src/lib/utils/annotation.context-builder.ts
453
+ var ANNOTATION_DEF_CONFIG_TOKEN = Symbol("ANNOTATION_DEF_CONFIG_TOKEN");
454
+ //#endregion
455
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/decorateMetadata.js
456
+ function __decorateMetadata(k, v) {
457
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
116
458
  }
117
459
  //#endregion
118
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
119
- function M(e, t) {
120
- return function(n, r) {
121
- t(n, r, e);
460
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/decorateParam.js
461
+ function __decorateParam(paramIndex, decorator) {
462
+ return function(target, key) {
463
+ decorator(target, key, paramIndex);
122
464
  };
123
465
  }
124
466
  //#endregion
125
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
126
- function N(e, t, n, r) {
127
- var i = arguments.length, a = i < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, o;
128
- if (typeof Reflect == "object" && typeof Reflect.decorate == "function") a = Reflect.decorate(e, t, n, r);
129
- else for (var s = e.length - 1; s >= 0; s--) (o = e[s]) && (a = (i < 3 ? o(a) : i > 3 ? o(t, n, a) : o(t, n)) || a);
130
- return i > 3 && a && Object.defineProperty(t, n, a), a;
467
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/decorate.js
468
+ function __decorate(decorators, target, key, desc) {
469
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
470
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
471
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
472
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
131
473
  }
132
474
  //#endregion
133
- //#region packages/annotation-api/src/lib/service/annotation-definition.service.ts
134
- var P = class {
135
- config;
136
- definitions = [];
137
- groupedDefinitions = {};
138
- cachedAt = 0;
139
- constructor(e) {
140
- this.config = e;
141
- }
142
- async findAllGrouped() {
143
- return await this.setDefinitions(), Promise.resolve(this.groupedDefinitions);
475
+ //#region src/lib/context/annotation-context.service.ts
476
+ var AnnotationContextService = class AnnotationContextService {
477
+ configRegistry;
478
+ annotationDefConfig;
479
+ contextConfigMap = /* @__PURE__ */ new Map();
480
+ prefixMap = /* @__PURE__ */ new Map();
481
+ constructor(configRegistry, annotationDefConfig) {
482
+ this.configRegistry = configRegistry;
483
+ this.annotationDefConfig = annotationDefConfig;
144
484
  }
145
- async setDefinitions(e = !1) {
146
- let t = Date.now();
147
- if (!e && this.definitions.length && t - this.cachedAt < this.config.cacheTTLms) return;
148
- let n = await this.reloadDefinitions() ?? [];
149
- this.definitions = n, this.groupedDefinitions = n.reduce((e, t) => (e[t.id] = t, e), {}), this.cachedAt = t;
485
+ async reloadAll() {
486
+ this.contextConfigMap.clear();
487
+ this.configRegistry.findAll().forEach((resource) => {
488
+ const context = createAnnotationContext(this.annotationDefConfig, resource);
489
+ this.contextConfigMap.set(resource.id, context);
490
+ this.prefixMap.set(context.prefix, resource.id);
491
+ });
150
492
  }
151
- async findAll() {
152
- return await this.setDefinitions(), Promise.resolve(this.definitions);
493
+ async findById(annotationId) {
494
+ const find = this.contextConfigMap.get(annotationId);
495
+ if (find) return find;
496
+ const resource = await this.configRegistry.findById(annotationId);
497
+ if (!resource) return null;
498
+ const context = createAnnotationContext(this.annotationDefConfig, resource);
499
+ this.contextConfigMap.set(annotationId, context);
500
+ return context;
153
501
  }
154
- async findById(e) {
155
- await this.setDefinitions();
156
- let t = this.groupedDefinitions[e];
157
- if (t || await this.setDefinitions(!0), t = this.groupedDefinitions[e], !t) throw new a();
158
- return Promise.resolve(t);
502
+ getResourceIdFromUri = (uri) => {
503
+ for (const prefix of this.prefixMap.keys()) if (uri.startsWith(prefix)) return uri.substring(prefix.length);
504
+ return null;
505
+ };
506
+ };
507
+ AnnotationContextService = __decorate([
508
+ Injectable(),
509
+ __decorateParam(0, Inject(ResourceConfigRegistry)),
510
+ __decorateParam(1, Inject(ANNOTATION_DEF_CONFIG_TOKEN)),
511
+ __decorateMetadata("design:paramtypes", [typeof ResourceConfigRegistry === "undefined" ? Object : ResourceConfigRegistry, Object])
512
+ ], AnnotationContextService);
513
+ //#endregion
514
+ //#region src/lib/annotation/annotation.mapper.service.ts
515
+ var AnnotationW3cMapperService = class AnnotationW3cMapperService {
516
+ contextService;
517
+ constructor(contextService) {
518
+ this.contextService = contextService;
159
519
  }
160
- async getAllContextBuilders() {
161
- return (await this.findAll()).map((e) => e.context);
520
+ async getW3CAnnotation(type, annotation) {
521
+ const annotationDef = await this.contextService.findById(type);
522
+ return this.mapToW3CAnnotation(annotationDef, annotation);
162
523
  }
163
- async getContextBuilder(e) {
164
- let t = await this.findById(e);
165
- if (!t) throw new a();
166
- return t.context;
524
+ async fromW3CAnnotation(type, annotation) {
525
+ const annotationDef = await this.contextService.findById(type);
526
+ return this.mapFromW3CAnnotation(annotationDef, annotation);
167
527
  }
168
528
  };
169
- P = N([
170
- r(),
171
- M(0, n(A)),
172
- j("design:paramtypes", [Object])
173
- ], P);
529
+ AnnotationW3cMapperService = __decorate([__decorateParam(0, Inject(AnnotationContextService)), __decorateMetadata("design:paramtypes", [typeof AnnotationContextService === "undefined" ? Object : AnnotationContextService])], AnnotationW3cMapperService);
530
+ //#endregion
531
+ //#region src/lib/prefix.ts
532
+ var SCHEMA_PREFIX = "annotation-editor";
174
533
  //#endregion
175
- //#region packages/annotation-api/src/lib/service/annotation-definition-from-files.service.ts
176
- var F = class extends P {
177
- _initialDefinitions;
178
- _loaderFn;
179
- constructor(e, t, n) {
180
- super(e), this._initialDefinitions = t, this._loaderFn = n;
534
+ //#region src/lib/annotation-namespace.controller.ts
535
+ var AnnotationNamespaceController = class AnnotationNamespaceController {
536
+ service;
537
+ annotationContextService;
538
+ constructor(service, annotationContextService) {
539
+ this.service = service;
540
+ this.annotationContextService = annotationContextService;
541
+ }
542
+ async listNames() {
543
+ const basePath = process.env["API_URL"] ?? "";
544
+ const base = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
545
+ return { annotations: (await this.service.getAll()).map((a) => ({
546
+ id: a.id,
547
+ name: a.name,
548
+ schemas: `${base}/${SCHEMA_PREFIX}/${a.id}/schemas`,
549
+ jsonld: `${base}/ns/${a.id}.jsonld`
550
+ })) };
551
+ }
552
+ async getJsonLd_(id) {
553
+ return (await this.annotationContextService.findById(id))?.jsonLd;
181
554
  }
182
- reloadDefinitions = () => this.config.isDev && this._loaderFn ? Promise.resolve(this._loaderFn()) : Promise.resolve(this._initialDefinitions ?? []);
183
555
  };
184
- F = N([
185
- r(),
186
- M(0, n(A)),
187
- j("design:paramtypes", [
188
- Object,
189
- Array,
190
- Object
191
- ])
192
- ], F);
556
+ __decorate([
557
+ Get(),
558
+ __decorateMetadata("design:type", Function),
559
+ __decorateMetadata("design:paramtypes", []),
560
+ __decorateMetadata("design:returntype", Promise)
561
+ ], AnnotationNamespaceController.prototype, "listNames", null);
562
+ __decorate([
563
+ Get(":id.jsonld"),
564
+ __decorateParam(0, Param("id")),
565
+ __decorateMetadata("design:type", Function),
566
+ __decorateMetadata("design:paramtypes", [String]),
567
+ __decorateMetadata("design:returntype", Promise)
568
+ ], AnnotationNamespaceController.prototype, "getJsonLd_", null);
569
+ AnnotationNamespaceController = __decorate([
570
+ Controller("ns"),
571
+ ApiTags("Annotations NS"),
572
+ __decorateParam(0, Inject(ResourceConfigRegistry)),
573
+ __decorateParam(1, Inject(ANNOTATION_DEF_CONFIG_TOKEN)),
574
+ __decorateMetadata("design:paramtypes", [typeof ResourceConfigRegistry === "undefined" ? Object : ResourceConfigRegistry, Object])
575
+ ], AnnotationNamespaceController);
193
576
  //#endregion
194
- //#region packages/annotation-api/src/lib/service/annotation-definition.loader.ts
195
- var I = (e, t, n) => {
196
- if (!l(e)) return [];
197
- let r = d(e, { withFileTypes: !0 }).filter((e) => e.isDirectory()).map((e) => e.name), i = [];
198
- for (let a of r) {
199
- let r = f(e, a, "resource.json");
200
- if (!l(r)) continue;
201
- let o = JSON.parse(u(r, "utf-8"));
202
- i.push(k(o, t, n));
577
+ //#region src/lib/annotation/annotation.controller.ts
578
+ var AnnotationController = class AnnotationController {
579
+ annotationRepository;
580
+ wrapper;
581
+ contextService;
582
+ constructor(annotationRepository, wrapper, contextService) {
583
+ this.annotationRepository = annotationRepository;
584
+ this.wrapper = wrapper;
585
+ this.contextService = contextService;
203
586
  }
204
- return i;
205
- }, L = class {
206
- service;
207
- annotationDefConfig;
208
- constructor(e, t) {
209
- this.service = e, this.annotationDefConfig = t;
587
+ async create(type, annotationBody) {
588
+ const parsed = await this.wrapper.fromW3CAnnotation(type, annotationBody);
589
+ const annotation = await this.annotationRepository.create(parsed);
590
+ return this.get(annotation.id);
210
591
  }
211
- getAll() {
212
- return this.service.findAll();
592
+ async getByType(id) {
593
+ const { annotation, type } = await this.annotationRepository.findOne(id);
594
+ return this.wrapper.getW3CAnnotation(type, annotation);
213
595
  }
214
- async getJsonLd_(e) {
215
- return e === "AnnotationStyle" ? S(this.annotationDefConfig).toJsonLdContext() : (await this.service.findById(e))?.json_ld;
596
+ async get(id) {
597
+ const _id = this.contextService.getResourceIdFromUri(id) ?? id;
598
+ const { annotation, type } = await this.annotationRepository.findOne(_id);
599
+ return this.wrapper.getW3CAnnotation(type, annotation);
216
600
  }
217
- async getSchemas(e) {
218
- let t = await this.service.findById(e);
219
- return {
220
- id: t.id,
221
- name: t.name,
222
- json_schema: t.json_schema,
223
- ui_schema: t.ui_schema,
224
- metadata_schema: t.metadata_schema,
225
- columns: t.columns,
226
- isRoot: t.isRoot,
227
- allowedChildren: t.allowedChildren,
228
- allowedLinks: t.allowedLinks,
229
- type: t.type,
230
- icon: t.icon,
231
- target: t.target
232
- };
601
+ async patch(type, id, annotationBody) {
602
+ const _id = this.contextService.getResourceIdFromUri(id) ?? id;
603
+ const _annotation = await this.wrapper.fromW3CAnnotation(type, annotationBody);
604
+ const annotation = await this.annotationRepository.update(_id, _annotation);
605
+ return this.get(annotation.id);
233
606
  }
234
- async getById(e) {
235
- return await this.service.findById(e);
607
+ async delete(id) {
608
+ const _id = this.contextService.getResourceIdFromUri(id) ?? id;
609
+ return this.annotationRepository.delete(_id);
236
610
  }
237
- async getFullJsonLd() {
238
- return (await this.service.getAllContextBuilders()).map((e) => e.toJsonLdContext());
239
- }
240
- async getJsonLd(e) {
241
- let t = await this.service.getContextBuilder(e);
242
- return {
243
- jsonLd: t.toJsonLdContext(),
244
- forms: t.toJsonSchema()
245
- };
611
+ async deleteType(id) {
612
+ const _id = this.contextService.getResourceIdFromUri(id) ?? id;
613
+ return this.annotationRepository.delete(_id);
246
614
  }
247
615
  };
248
- N([
249
- t(),
250
- j("design:type", Function),
251
- j("design:paramtypes", []),
252
- j("design:returntype", void 0)
253
- ], L.prototype, "getAll", null), N([
254
- t(":id.jsonld"),
255
- M(0, o("id")),
256
- j("design:type", Function),
257
- j("design:paramtypes", [String]),
258
- j("design:returntype", Promise)
259
- ], L.prototype, "getJsonLd_", null), N([
260
- t(":id/schemas"),
261
- M(0, o("id")),
262
- j("design:type", Function),
263
- j("design:paramtypes", [String]),
264
- j("design:returntype", Promise)
265
- ], L.prototype, "getSchemas", null), N([
266
- t(":id"),
267
- M(0, o("id")),
268
- j("design:type", Function),
269
- j("design:paramtypes", [String]),
270
- j("design:returntype", Promise)
271
- ], L.prototype, "getById", null), N([
272
- t("anno.jsonld"),
273
- j("design:type", Function),
274
- j("design:paramtypes", []),
275
- j("design:returntype", Promise)
276
- ], L.prototype, "getFullJsonLd", null), N([
277
- t(":type/anno.jsonld"),
278
- M(0, o("type")),
279
- j("design:type", Function),
280
- j("design:paramtypes", [String]),
281
- j("design:returntype", Promise)
282
- ], L.prototype, "getJsonLd", null), L = N([
283
- e("ns"),
284
- p("Annotations NS"),
285
- M(0, n(P)),
286
- M(1, n(A)),
287
- j("design:paramtypes", [P === void 0 ? Object : P, Object])
288
- ], L);
616
+ __decorate([
617
+ Post(":type"),
618
+ ApiOperation({ summary: "Create a W3C annotation" }),
619
+ ApiBody({ description: "W3C annotation body" }),
620
+ ApiResponse({
621
+ status: 201,
622
+ description: "The created W3C annotation"
623
+ }),
624
+ __decorateParam(0, Param("type")),
625
+ __decorateParam(1, Body()),
626
+ __decorateMetadata("design:type", Function),
627
+ __decorateMetadata("design:paramtypes", [String, Object]),
628
+ __decorateMetadata("design:returntype", Promise)
629
+ ], AnnotationController.prototype, "create", null);
630
+ __decorate([
631
+ Get(":type/:id"),
632
+ ApiOperation({ summary: "Get one annotation by id" }),
633
+ ApiParam({
634
+ name: "id",
635
+ type: "string"
636
+ }),
637
+ ApiParam({
638
+ name: "type",
639
+ type: "string"
640
+ }),
641
+ ApiResponse({
642
+ status: 200,
643
+ description: "The W3C annotation"
644
+ }),
645
+ __decorateParam(0, Param("id")),
646
+ __decorateMetadata("design:type", Function),
647
+ __decorateMetadata("design:paramtypes", [String]),
648
+ __decorateMetadata("design:returntype", Promise)
649
+ ], AnnotationController.prototype, "getByType", null);
650
+ __decorate([
651
+ Get(":id"),
652
+ ApiOperation({ summary: "Get one annotation by id" }),
653
+ ApiParam({
654
+ name: "id",
655
+ type: "string"
656
+ }),
657
+ ApiResponse({
658
+ status: 200,
659
+ description: "The W3C annotation"
660
+ }),
661
+ __decorateParam(0, Param("id")),
662
+ __decorateMetadata("design:type", Function),
663
+ __decorateMetadata("design:paramtypes", [String]),
664
+ __decorateMetadata("design:returntype", Promise)
665
+ ], AnnotationController.prototype, "get", null);
666
+ __decorate([
667
+ Patch(":type/:id"),
668
+ ApiOperation({ summary: "Update an annotation" }),
669
+ ApiParam({
670
+ name: "id",
671
+ type: "string"
672
+ }),
673
+ ApiBody({ description: "W3C annotation body" }),
674
+ ApiResponse({
675
+ status: 200,
676
+ description: "The updated W3C annotation"
677
+ }),
678
+ __decorateParam(0, Param("type")),
679
+ __decorateParam(1, Param("id")),
680
+ __decorateParam(2, Body()),
681
+ __decorateMetadata("design:type", Function),
682
+ __decorateMetadata("design:paramtypes", [
683
+ String,
684
+ String,
685
+ Object
686
+ ]),
687
+ __decorateMetadata("design:returntype", Promise)
688
+ ], AnnotationController.prototype, "patch", null);
689
+ __decorate([
690
+ Delete(":id"),
691
+ ApiOperation({ summary: "Delete an annotation" }),
692
+ ApiParam({
693
+ name: "id",
694
+ type: "string"
695
+ }),
696
+ ApiResponse({
697
+ status: 200,
698
+ description: "Annotation deleted"
699
+ }),
700
+ __decorateParam(0, Param("id")),
701
+ __decorateMetadata("design:type", Function),
702
+ __decorateMetadata("design:paramtypes", [String]),
703
+ __decorateMetadata("design:returntype", Promise)
704
+ ], AnnotationController.prototype, "delete", null);
705
+ __decorate([
706
+ Delete(":type/:id"),
707
+ ApiOperation({ summary: "Delete an annotation" }),
708
+ ApiParam({
709
+ name: "id",
710
+ type: "string"
711
+ }),
712
+ ApiResponse({
713
+ status: 200,
714
+ description: "Annotation deleted"
715
+ }),
716
+ __decorateParam(0, Param("id")),
717
+ __decorateMetadata("design:type", Function),
718
+ __decorateMetadata("design:paramtypes", [String]),
719
+ __decorateMetadata("design:returntype", Promise)
720
+ ], AnnotationController.prototype, "deleteType", null);
721
+ AnnotationController = __decorate([
722
+ Controller(`${SCHEMA_PREFIX}/annotation`),
723
+ ApiTags("Annotations"),
724
+ __decorateParam(0, Inject(AnnotationCrudRepository)),
725
+ __decorateParam(1, Inject(AnnotationW3cMapperService)),
726
+ __decorateParam(2, Inject(AnnotationContextService)),
727
+ __decorateMetadata("design:paramtypes", [
728
+ typeof AnnotationCrudRepository === "undefined" ? Object : AnnotationCrudRepository,
729
+ typeof AnnotationW3cMapperService === "undefined" ? Object : AnnotationW3cMapperService,
730
+ typeof AnnotationContextService === "undefined" ? Object : AnnotationContextService
731
+ ])
732
+ ], AnnotationController);
289
733
  //#endregion
290
- //#region packages/annotation-api/src/lib/resource/annotation-resource.loader.ts
291
- var R = (e, t) => {
292
- let n = f(e, "_resource");
293
- if (!l(n)) return [];
294
- let r = d(n).filter((e) => e.endsWith(".json")), { prefix: i } = v(t);
295
- return r.map((e) => {
296
- let t = JSON.parse(u(f(n, e), "utf-8")), r = t.columns.find((e) => e.displayAs === "id"), a = t.columns.find((e) => e.displayAs === "label");
297
- return {
298
- type: t.type,
299
- table: t.table,
300
- database: t.database,
301
- field: {
302
- id: r?.column ?? "id",
303
- label: a?.column ?? "name"
304
- },
305
- prefix: `${i}:${t.type}/`
306
- };
307
- });
308
- }, z = class {
309
- byType = /* @__PURE__ */ new Map();
310
- constructor(e) {
311
- for (let t of e) this.byType.set(t.type, t);
312
- }
313
- findAll = () => [...this.byType.values()];
314
- getResourceForType = (e) => this.byType.get(e) ?? null;
315
- getResourceFromUri = (e) => {
316
- for (let t of this.byType.values()) if (e.startsWith(t.prefix)) return {
317
- ...t,
318
- id: e.substring(t.prefix.length)
319
- };
320
- return null;
734
+ //#region src/lib/utils/schemaEnricher.utils.ts
735
+ var createSchemaEnricher = (baseUrl = "") => (schema) => {
736
+ const uri = `${baseUrl}${SCHEMA_PREFIX}/annotation/${schema.route}`;
737
+ const uriId = `${uri}/{id}`;
738
+ schema.operations = {
739
+ findOne: schema.operations.findOne ?? {
740
+ uri: uriId,
741
+ method: "get"
742
+ },
743
+ update: schema.operations.update ?? {
744
+ uri: uriId,
745
+ method: "patch"
746
+ },
747
+ delete: schema.operations.delete ?? {
748
+ uri: uriId,
749
+ method: "delete"
750
+ },
751
+ create: schema.operations.create ?? {
752
+ uri,
753
+ method: "post"
754
+ },
755
+ findAll: schema.operations.findAll
321
756
  };
757
+ return { ...schema };
322
758
  };
323
- z = N([r(), j("design:paramtypes", [Array])], z);
324
759
  //#endregion
325
- //#region packages/annotation-api/src/lib/annotation-api.module.ts
326
- var B, V = B = class {
327
- static forService(e) {
328
- return {
329
- module: B,
330
- global: !0,
331
- controllers: [L],
332
- providers: [{
333
- provide: P,
334
- useClass: e.annotationDefinitionService
335
- }],
336
- exports: [P]
337
- };
338
- }
339
- static async forResourceDir(e, t) {
340
- let n = () => I(e, t, O), r = new F(t, n(), n), i = new z(R(e, t));
341
- return {
342
- module: B,
343
- global: !0,
344
- controllers: [L],
760
+ //#region src/lib/annotation-api.module.ts
761
+ var _AnnotationApiModule;
762
+ registerResourceExtensions({ annotation: AnnotationConfigSchema });
763
+ var AnnotationApiModule = _AnnotationApiModule = class AnnotationApiModule {
764
+ static async forResourceDir(resourcePath, datasourcePath, config, annotation) {
765
+ const _config = resolveConfig(config);
766
+ const crouton = await CroutonApiModule.forResourceDir(resourcePath, datasourcePath, {
767
+ baseUrl: "",
768
+ prefix: SCHEMA_PREFIX,
769
+ extensions: { annotation: AnnotationConfigSchema },
770
+ schemaEnricher: createSchemaEnricher(_config.baseUrl)
771
+ });
772
+ if (annotation) return {
773
+ module: _AnnotationApiModule,
774
+ global: true,
775
+ imports: [crouton],
776
+ controllers: [AnnotationNamespaceController, AnnotationController],
345
777
  providers: [
778
+ AnnotationContextService,
346
779
  {
347
- provide: A,
348
- useValue: t
780
+ provide: ANNOTATION_DEF_CONFIG_TOKEN,
781
+ useValue: _config
349
782
  },
350
783
  {
351
- provide: P,
352
- useValue: r
784
+ provide: AnnotationCrudRepository,
785
+ useExisting: annotation.repository
353
786
  },
354
787
  {
355
- provide: z,
356
- useValue: i
788
+ provide: AnnotationW3cMapperService,
789
+ useExisting: annotation.mapper
357
790
  }
358
791
  ],
359
- exports: [P, z]
792
+ exports: [AnnotationContextService]
793
+ };
794
+ return {
795
+ module: _AnnotationApiModule,
796
+ global: true,
797
+ imports: [crouton],
798
+ controllers: [AnnotationNamespaceController],
799
+ providers: [AnnotationContextService, {
800
+ provide: ANNOTATION_DEF_CONFIG_TOKEN,
801
+ useValue: _config
802
+ }],
803
+ exports: [AnnotationContextService]
360
804
  };
361
805
  }
362
806
  };
363
- V = B = N([i({
807
+ AnnotationApiModule = _AnnotationApiModule = __decorate([Module({
364
808
  controllers: [],
365
809
  providers: [],
366
810
  exports: []
367
- })], V);
811
+ })], AnnotationApiModule);
368
812
  //#endregion
369
- export { A as ANNOTATION_DEF_CONFIG_TOKEN, V as AnnotationApiModule, F as AnnotationDefinitionFromFilesService, P as AnnotationDefinitionService, z as AnnotationResourceDefinitionService, h as annotationColumnDefinition, g as annotationDefinition, I as loadAnnotationDefinitionsFromDir, R as loadAnnotationResourcesFromDir };
813
+ export { AnnotationApiModule, AnnotationConfigSchema, AnnotationContextService, AnnotationCrudRepository, AnnotationJsonResourceSchema, AnnotationJsonResourceShape, AnnotationMetadataType, AnnotationResourceSchema, AnnotationStyleContextBuilder, AnnotationStyleType, AnnotationW3cMapperService, BASELINE_RESOURCE_VERSION, CURRENT_RESOURCE_VERSION, KeyLabelSchema, SourceModelSchema, SourceTextSchema, annotationColumnDefinition, annotationUtils, baseContextBuilder, buildGridStyle, buildPrefix, createAnnotationConfiguration, createAnnotationContext, createAnnotationStyleBodyUnsafe, defaultRender, getPaneArea, resolveConfig, styleFn };