@ghentcdh/annotation-api 0.0.1-alpha.1
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 +3 -0
- package/index.cjs +1 -0
- package/index.d.ts +8 -0
- package/index.js +369 -0
- package/lib/annotation-api.module.d.ts +11 -0
- package/lib/annotation-namespace.controller.d.ts +65 -0
- package/lib/resource/annotation-resource-definition.service.d.ts +10 -0
- package/lib/resource/annotation-resource.loader.d.ts +2 -0
- package/lib/service/annotation-definition-from-files.service.d.ts +26 -0
- package/lib/service/annotation-definition.loader.d.ts +2 -0
- package/lib/service/annotation-definition.service.d.ts +16 -0
- package/lib/utils/annotation.context-builder.d.ts +1 -0
- package/package.json +15 -0
package/README.md
ADDED
package/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@nestjs/common"),t=require("zod"),n=require("@ghentcdh/w3c-utils");require("@ghentcdh/annotated-text");let r=require("node:fs"),i=require("node:path"),a=require("@nestjs/swagger");var o=`AnnotationMetadata`,s=t.z.object({}),c=t.z.object({id:t.z.string(),name:t.z.string(),columns:t.z.array(s),json_schema:t.z.any().optional(),json_ld:t.z.any().optional(),ui_schema:t.z.any().optional(),metadata_schema:t.z.any().optional(),color:t.z.string(),type:t.z.string().optional(),icon:t.z.string().optional(),isRoot:t.z.boolean().default(!0),allowedChildren:t.z.array(t.z.string()).optional(),allowedLinks:t.z.array(t.z.string()).optional(),context:t.z.custom(),target:t.z.enum([`gutter`,`underline`,`highlight`]).optional()}),l={baseUrl:`http://localhost:3000/`,app:`ghentcdh`,prefix:`ghentcdh`,isDev:!1,cacheTTLms:1200*1e3},u=(e={})=>{let t=e.baseUrl??l.baseUrl,n=t.endsWith(`/`)?t:`${t}/`,r=e.isDev??!1,i=r?0:1200*1e3;return{baseUrl:n,contextUrl:`${n}ns/`,app:e.app??l.app,prefix:e.prefix??l.prefix,isDev:r,cacheTTLms:i}},d=(e,t)=>{let{prefix:r,baseUrl:i,contextUrl:a}=u(t),s=o;return(0,n.contextBuilder)(r,i).setType(r,s).addPrefix(e,`${r}:${e}`).setContextUri(`${a}${e}.jsonld`)},f=t.z.object({id:t.z.string(),name:t.z.string(),target:t.z.enum([`gutter`,`underline`,`highlight`]).optional().default(`underline`),color:t.z.string().optional()}),p=`AnnotationStyle`,m=e=>{let{prefix:t,baseUrl:r,contextUrl:i}=u(e);return(0,n.contextBuilder)(t,r).setType(t,p).setContextUri(`${i}${p}.jsonld`).parseZodSchema(f)},h=e=>{let t={};if(e.fieldInput){let{type:n,options:r}=e.fieldInput;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))}return{type:`Control`,scope:`#/properties/${e.id}`,options:t}},g=e=>({type:`TextCell`,scope:`#/properties/${e.id}`,options:{format:`keyValue`,key:e.fieldInput?.options?.labelKey??e.displayKey??`label`}}),_=e=>({type:`GridLayout`,elements:e.filter(e=>!e.hiddenInForm).map(h),options:{}}),v=e=>({type:`GridLayout`,elements:e.filter(e=>!e.hiddenInMetadata).map(g),options:{}}),y=e=>{if(e.type===`object`&&e.properties){let n={};for(let[t,r]of Object.entries(e.properties))n[t]=y(r);return t.z.object(n)}return t.z.string()},b=(e,n,r)=>{let i=d(e,r),a=n.columns??[];if(!a.length)return i;let o={};for(let e of a)e.type&&(o[e.id]=y(e.type));return Object.keys(o).length?i.parseZodSchema(t.z.object(o)):i},x=(e,t,n=b)=>{let r=n(e.id,e,t),i=e.columns??[],a=i.length>0,o=e.ui_schema??(a?_(i):void 0),s=e.metadata_schema??(a?v(i):void 0),c={id:e.id,name:e.name,color:e.color,isRoot:e.isRoot??!0,columns:i,context:r,json_ld:r.toJsonLdContext(),json_schema:o?r.toJsonSchema():null};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},S=Symbol(`ANNOTATION_DEF_CONFIG_TOKEN`);function C(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function w(e,t){return function(n,r){t(n,r,e)}}function T(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);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);return i>3&&a&&Object.defineProperty(t,n,a),a}var E=class{config;definitions=[];groupedDefinitions={};cachedAt=0;constructor(e){this.config=e}async findAllGrouped(){return await this.setDefinitions(),Promise.resolve(this.groupedDefinitions)}async setDefinitions(e=!1){let t=Date.now();if(!e&&this.definitions.length&&t-this.cachedAt<this.config.cacheTTLms)return;let n=await this.reloadDefinitions()??[];this.definitions=n,this.groupedDefinitions=n.reduce((e,t)=>(e[t.id]=t,e),{}),this.cachedAt=t}async findAll(){return await this.setDefinitions(),Promise.resolve(this.definitions)}async findById(t){await this.setDefinitions();let n=this.groupedDefinitions[t];if(n||await this.setDefinitions(!0),n=this.groupedDefinitions[t],!n)throw new e.NotFoundException;return Promise.resolve(n)}async getAllContextBuilders(){return(await this.findAll()).map(e=>e.context)}async getContextBuilder(t){let n=await this.findById(t);if(!n)throw new e.NotFoundException;return n.context}};E=T([(0,e.Injectable)(),w(0,(0,e.Inject)(S)),C(`design:paramtypes`,[Object])],E);var D=class extends E{_initialDefinitions;_loaderFn;constructor(e,t,n){super(e),this._initialDefinitions=t,this._loaderFn=n}reloadDefinitions=()=>this.config.isDev&&this._loaderFn?Promise.resolve(this._loaderFn()):Promise.resolve(this._initialDefinitions??[])};D=T([(0,e.Injectable)(),w(0,(0,e.Inject)(S)),C(`design:paramtypes`,[Object,Array,Object])],D);var O=(e,t,n)=>{if(!(0,r.existsSync)(e))return[];let a=(0,r.readdirSync)(e,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name),o=[];for(let s of a){let a=(0,i.join)(e,s,`resource.json`);if(!(0,r.existsSync)(a))continue;let c=JSON.parse((0,r.readFileSync)(a,`utf-8`));o.push(x(c,t,n))}return o},k=class{service;annotationDefConfig;constructor(e,t){this.service=e,this.annotationDefConfig=t}getAll(){return this.service.findAll()}async getJsonLd_(e){return e===`AnnotationStyle`?m(this.annotationDefConfig).toJsonLdContext():(await this.service.findById(e))?.json_ld}async getSchemas(e){let t=await this.service.findById(e);return{id:t.id,name:t.name,json_schema:t.json_schema,ui_schema:t.ui_schema,metadata_schema:t.metadata_schema,columns:t.columns,isRoot:t.isRoot,allowedChildren:t.allowedChildren,allowedLinks:t.allowedLinks,type:t.type,icon:t.icon,target:t.target}}async getById(e){return await this.service.findById(e)}async getFullJsonLd(){return(await this.service.getAllContextBuilders()).map(e=>e.toJsonLdContext())}async getJsonLd(e){let t=await this.service.getContextBuilder(e);return{jsonLd:t.toJsonLdContext(),forms:t.toJsonSchema()}}};T([(0,e.Get)(),C(`design:type`,Function),C(`design:paramtypes`,[]),C(`design:returntype`,void 0)],k.prototype,`getAll`,null),T([(0,e.Get)(`:id.jsonld`),w(0,(0,e.Param)(`id`)),C(`design:type`,Function),C(`design:paramtypes`,[String]),C(`design:returntype`,Promise)],k.prototype,`getJsonLd_`,null),T([(0,e.Get)(`:id/schemas`),w(0,(0,e.Param)(`id`)),C(`design:type`,Function),C(`design:paramtypes`,[String]),C(`design:returntype`,Promise)],k.prototype,`getSchemas`,null),T([(0,e.Get)(`:id`),w(0,(0,e.Param)(`id`)),C(`design:type`,Function),C(`design:paramtypes`,[String]),C(`design:returntype`,Promise)],k.prototype,`getById`,null),T([(0,e.Get)(`anno.jsonld`),C(`design:type`,Function),C(`design:paramtypes`,[]),C(`design:returntype`,Promise)],k.prototype,`getFullJsonLd`,null),T([(0,e.Get)(`:type/anno.jsonld`),w(0,(0,e.Param)(`type`)),C(`design:type`,Function),C(`design:paramtypes`,[String]),C(`design:returntype`,Promise)],k.prototype,`getJsonLd`,null),k=T([(0,e.Controller)(`ns`),(0,a.ApiTags)(`Annotations NS`),w(0,(0,e.Inject)(E)),w(1,(0,e.Inject)(S)),C(`design:paramtypes`,[E===void 0?Object:E,Object])],k);var A=(e,t)=>{let n=(0,i.join)(e,`_resource`);if(!(0,r.existsSync)(n))return[];let a=(0,r.readdirSync)(n).filter(e=>e.endsWith(`.json`)),{prefix:o}=u(t);return a.map(e=>{let t=JSON.parse((0,r.readFileSync)((0,i.join)(n,e),`utf-8`)),a=t.columns.find(e=>e.displayAs===`id`),s=t.columns.find(e=>e.displayAs===`label`);return{type:t.type,table:t.table,database:t.database,field:{id:a?.column??`id`,label:s?.column??`name`},prefix:`${o}:${t.type}/`}})},j=class{byType=new Map;constructor(e){for(let t of e)this.byType.set(t.type,t)}findAll=()=>[...this.byType.values()];getResourceForType=e=>this.byType.get(e)??null;getResourceFromUri=e=>{for(let t of this.byType.values())if(e.startsWith(t.prefix))return{...t,id:e.substring(t.prefix.length)};return null}};j=T([(0,e.Injectable)(),C(`design:paramtypes`,[Array])],j);var M,N=M=class{static forService(e){return{module:M,global:!0,controllers:[k],providers:[{provide:E,useClass:e.annotationDefinitionService}],exports:[E]}}static async forResourceDir(e,t){let n=()=>O(e,t,b),r=new D(t,n(),n),i=new j(A(e,t));return{module:M,global:!0,controllers:[k],providers:[{provide:S,useValue:t},{provide:E,useValue:r},{provide:j,useValue:i}],exports:[E,j]}}};N=M=T([(0,e.Module)({controllers:[],providers:[],exports:[]})],N),exports.ANNOTATION_DEF_CONFIG_TOKEN=S,Object.defineProperty(exports,"AnnotationApiModule",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"AnnotationDefinitionFromFilesService",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"AnnotationDefinitionService",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"AnnotationResourceDefinitionService",{enumerable:!0,get:function(){return j}}),exports.annotationColumnDefinition=s,exports.annotationDefinition=c,exports.loadAnnotationDefinitionsFromDir=O,exports.loadAnnotationResourcesFromDir=A;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './lib/annotation-api.module';
|
|
2
|
+
export * from './lib/service/annotation-definition.service';
|
|
3
|
+
export * from './lib/service/annotation-definition-from-files.service';
|
|
4
|
+
export * from './lib/service/annotation-definition.loader';
|
|
5
|
+
export * from './lib/resource/annotation-resource-definition.service';
|
|
6
|
+
export * from './lib/resource/annotation-resource.loader';
|
|
7
|
+
export * from './lib/utils/annotation.context-builder';
|
|
8
|
+
export { type AnnotationColumnFieldInput, type AnnotationColumnConfig, type AnnotationJsonConfig, annotationColumnDefinition, annotationDefinition, type AnnotationDefinition, } from '@ghentcdh/annotation-core';
|
package/index.js
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
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/",
|
|
31
|
+
app: "ghentcdh",
|
|
32
|
+
prefix: "ghentcdh",
|
|
33
|
+
isDev: !1,
|
|
34
|
+
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;
|
|
37
|
+
return {
|
|
38
|
+
baseUrl: n,
|
|
39
|
+
contextUrl: `${n}ns/`,
|
|
40
|
+
app: e.app ?? _.app,
|
|
41
|
+
prefix: e.prefix ?? _.prefix,
|
|
42
|
+
isDev: r,
|
|
43
|
+
cacheTTLms: i
|
|
44
|
+
};
|
|
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([
|
|
52
|
+
"gutter",
|
|
53
|
+
"underline",
|
|
54
|
+
"highlight"
|
|
55
|
+
]).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));
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
type: "Control",
|
|
68
|
+
scope: `#/properties/${e.id}`,
|
|
69
|
+
options: t
|
|
70
|
+
};
|
|
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"
|
|
77
|
+
}
|
|
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);
|
|
91
|
+
}
|
|
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
|
|
109
|
+
};
|
|
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");
|
|
112
|
+
//#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);
|
|
116
|
+
}
|
|
117
|
+
//#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);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//#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;
|
|
131
|
+
}
|
|
132
|
+
//#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);
|
|
144
|
+
}
|
|
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;
|
|
150
|
+
}
|
|
151
|
+
async findAll() {
|
|
152
|
+
return await this.setDefinitions(), Promise.resolve(this.definitions);
|
|
153
|
+
}
|
|
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);
|
|
159
|
+
}
|
|
160
|
+
async getAllContextBuilders() {
|
|
161
|
+
return (await this.findAll()).map((e) => e.context);
|
|
162
|
+
}
|
|
163
|
+
async getContextBuilder(e) {
|
|
164
|
+
let t = await this.findById(e);
|
|
165
|
+
if (!t) throw new a();
|
|
166
|
+
return t.context;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
P = N([
|
|
170
|
+
r(),
|
|
171
|
+
M(0, n(A)),
|
|
172
|
+
j("design:paramtypes", [Object])
|
|
173
|
+
], P);
|
|
174
|
+
//#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;
|
|
181
|
+
}
|
|
182
|
+
reloadDefinitions = () => this.config.isDev && this._loaderFn ? Promise.resolve(this._loaderFn()) : Promise.resolve(this._initialDefinitions ?? []);
|
|
183
|
+
};
|
|
184
|
+
F = N([
|
|
185
|
+
r(),
|
|
186
|
+
M(0, n(A)),
|
|
187
|
+
j("design:paramtypes", [
|
|
188
|
+
Object,
|
|
189
|
+
Array,
|
|
190
|
+
Object
|
|
191
|
+
])
|
|
192
|
+
], F);
|
|
193
|
+
//#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));
|
|
203
|
+
}
|
|
204
|
+
return i;
|
|
205
|
+
}, L = class {
|
|
206
|
+
service;
|
|
207
|
+
annotationDefConfig;
|
|
208
|
+
constructor(e, t) {
|
|
209
|
+
this.service = e, this.annotationDefConfig = t;
|
|
210
|
+
}
|
|
211
|
+
getAll() {
|
|
212
|
+
return this.service.findAll();
|
|
213
|
+
}
|
|
214
|
+
async getJsonLd_(e) {
|
|
215
|
+
return e === "AnnotationStyle" ? S(this.annotationDefConfig).toJsonLdContext() : (await this.service.findById(e))?.json_ld;
|
|
216
|
+
}
|
|
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
|
+
};
|
|
233
|
+
}
|
|
234
|
+
async getById(e) {
|
|
235
|
+
return await this.service.findById(e);
|
|
236
|
+
}
|
|
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
|
+
};
|
|
246
|
+
}
|
|
247
|
+
};
|
|
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);
|
|
289
|
+
//#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;
|
|
321
|
+
};
|
|
322
|
+
};
|
|
323
|
+
z = N([r(), j("design:paramtypes", [Array])], z);
|
|
324
|
+
//#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],
|
|
345
|
+
providers: [
|
|
346
|
+
{
|
|
347
|
+
provide: A,
|
|
348
|
+
useValue: t
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
provide: P,
|
|
352
|
+
useValue: r
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
provide: z,
|
|
356
|
+
useValue: i
|
|
357
|
+
}
|
|
358
|
+
],
|
|
359
|
+
exports: [P, z]
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
V = B = N([i({
|
|
364
|
+
controllers: [],
|
|
365
|
+
providers: [],
|
|
366
|
+
exports: []
|
|
367
|
+
})], V);
|
|
368
|
+
//#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 };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DynamicModule, Type } from '@nestjs/common';
|
|
2
|
+
import { AnnotationDefConfig } from '@ghentcdh/annotation-core';
|
|
3
|
+
import { AnnotationDefinitionService } from './service/annotation-definition.service';
|
|
4
|
+
type AnnotationApiConfig = {
|
|
5
|
+
annotationDefinitionService: Type<AnnotationDefinitionService>;
|
|
6
|
+
};
|
|
7
|
+
export declare class AnnotationApiModule {
|
|
8
|
+
static forService(config: AnnotationApiConfig): DynamicModule;
|
|
9
|
+
static forResourceDir(dirPath: string, config: AnnotationDefConfig): Promise<DynamicModule>;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { AnnotationDefConfig } from '@ghentcdh/annotation-core';
|
|
2
|
+
import { AnnotationDefinitionService } from './service/annotation-definition.service';
|
|
3
|
+
export declare class AnnotationNamespaceController {
|
|
4
|
+
private readonly service;
|
|
5
|
+
private readonly annotationDefConfig;
|
|
6
|
+
constructor(service: AnnotationDefinitionService, annotationDefConfig: AnnotationDefConfig);
|
|
7
|
+
getAll(): Promise<{
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
columns: Record<string, never>[];
|
|
11
|
+
color: string;
|
|
12
|
+
isRoot: boolean;
|
|
13
|
+
context: unknown;
|
|
14
|
+
json_schema?: any;
|
|
15
|
+
json_ld?: any;
|
|
16
|
+
ui_schema?: any;
|
|
17
|
+
metadata_schema?: any;
|
|
18
|
+
type?: string | undefined;
|
|
19
|
+
icon?: string | undefined;
|
|
20
|
+
allowedChildren?: string[] | undefined;
|
|
21
|
+
allowedLinks?: string[] | undefined;
|
|
22
|
+
target?: "gutter" | "underline" | "highlight" | undefined;
|
|
23
|
+
}[]>;
|
|
24
|
+
getJsonLd_(id: string): Promise<any>;
|
|
25
|
+
getSchemas(id: string): Promise<{
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
json_schema: any;
|
|
29
|
+
ui_schema: any;
|
|
30
|
+
metadata_schema: any;
|
|
31
|
+
columns: Record<string, never>[];
|
|
32
|
+
isRoot: boolean;
|
|
33
|
+
allowedChildren: string[] | undefined;
|
|
34
|
+
allowedLinks: string[] | undefined;
|
|
35
|
+
type: string | undefined;
|
|
36
|
+
icon: string | undefined;
|
|
37
|
+
target: "gutter" | "underline" | "highlight" | undefined;
|
|
38
|
+
}>;
|
|
39
|
+
getById(id: string): Promise<{
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
columns: Record<string, never>[];
|
|
43
|
+
color: string;
|
|
44
|
+
isRoot: boolean;
|
|
45
|
+
context: unknown;
|
|
46
|
+
json_schema?: any;
|
|
47
|
+
json_ld?: any;
|
|
48
|
+
ui_schema?: any;
|
|
49
|
+
metadata_schema?: any;
|
|
50
|
+
type?: string | undefined;
|
|
51
|
+
icon?: string | undefined;
|
|
52
|
+
allowedChildren?: string[] | undefined;
|
|
53
|
+
allowedLinks?: string[] | undefined;
|
|
54
|
+
target?: "gutter" | "underline" | "highlight" | undefined;
|
|
55
|
+
}>;
|
|
56
|
+
getFullJsonLd(): Promise<{
|
|
57
|
+
'@context': Record<string, unknown>;
|
|
58
|
+
}[]>;
|
|
59
|
+
getJsonLd(type: string): Promise<{
|
|
60
|
+
jsonLd: {
|
|
61
|
+
'@context': Record<string, unknown>;
|
|
62
|
+
};
|
|
63
|
+
forms: any;
|
|
64
|
+
}>;
|
|
65
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AnnotationResourceDefinition } from '@ghentcdh/annotation-core';
|
|
2
|
+
export declare class AnnotationResourceDefinitionService {
|
|
3
|
+
private readonly byType;
|
|
4
|
+
constructor(definitions: AnnotationResourceDefinition[]);
|
|
5
|
+
findAll: () => AnnotationResourceDefinition[];
|
|
6
|
+
getResourceForType: (type: string) => AnnotationResourceDefinition | null;
|
|
7
|
+
getResourceFromUri: (uri: string) => (AnnotationResourceDefinition & {
|
|
8
|
+
id: string;
|
|
9
|
+
}) | null;
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AnnotationDefinition, AnnotationDefConfig } from '@ghentcdh/annotation-core';
|
|
2
|
+
import { AnnotationDefinitionService } from './annotation-definition.service';
|
|
3
|
+
type AnnotationDefinitionLoaderFn = () => AnnotationDefinition[];
|
|
4
|
+
export declare class AnnotationDefinitionFromFilesService extends AnnotationDefinitionService {
|
|
5
|
+
private readonly _initialDefinitions;
|
|
6
|
+
private readonly _loaderFn?;
|
|
7
|
+
constructor(config: AnnotationDefConfig, _initialDefinitions: AnnotationDefinition[], _loaderFn?: AnnotationDefinitionLoaderFn | undefined);
|
|
8
|
+
protected reloadDefinitions: () => Promise<{
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
columns: Record<string, never>[];
|
|
12
|
+
color: string;
|
|
13
|
+
isRoot: boolean;
|
|
14
|
+
context: unknown;
|
|
15
|
+
json_schema?: any;
|
|
16
|
+
json_ld?: any;
|
|
17
|
+
ui_schema?: any;
|
|
18
|
+
metadata_schema?: any;
|
|
19
|
+
type?: string | undefined;
|
|
20
|
+
icon?: string | undefined;
|
|
21
|
+
allowedChildren?: string[] | undefined;
|
|
22
|
+
allowedLinks?: string[] | undefined;
|
|
23
|
+
target?: "gutter" | "underline" | "highlight" | undefined;
|
|
24
|
+
}[]>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AnnotationDefinition, AnnotationDefConfig, ContextBuilderFactory } from '@ghentcdh/annotation-core';
|
|
2
|
+
export declare const loadAnnotationDefinitionsFromDir: (dirPath: string, annotationDefConfig: AnnotationDefConfig, contextBuilderFactory: ContextBuilderFactory) => AnnotationDefinition[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ContextBuilder } from '@ghentcdh/w3c-utils';
|
|
2
|
+
import { AnnotationDefinition, AnnotationDefConfig } from '@ghentcdh/annotation-core';
|
|
3
|
+
export declare abstract class AnnotationDefinitionService {
|
|
4
|
+
protected readonly config: AnnotationDefConfig;
|
|
5
|
+
private definitions;
|
|
6
|
+
private groupedDefinitions;
|
|
7
|
+
private cachedAt;
|
|
8
|
+
constructor(config: AnnotationDefConfig);
|
|
9
|
+
findAllGrouped(): Promise<Record<string, AnnotationDefinition>>;
|
|
10
|
+
protected abstract reloadDefinitions(): Promise<AnnotationDefinition[]>;
|
|
11
|
+
setDefinitions(force?: boolean): Promise<void>;
|
|
12
|
+
findAll(): Promise<AnnotationDefinition[]>;
|
|
13
|
+
findById(id: string): Promise<AnnotationDefinition>;
|
|
14
|
+
getAllContextBuilders(): Promise<ContextBuilder[]>;
|
|
15
|
+
getContextBuilder(type: string): Promise<ContextBuilder>;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ANNOTATION_DEF_CONFIG_TOKEN: unique symbol;
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ghentcdh/annotation-api",
|
|
3
|
+
"version": "0.0.1-alpha.1",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/GhentCDH/annotation-editor"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./index.js",
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"@ghentcdh/w3c-utils": "^1.0.6",
|
|
13
|
+
"@nestjs/common": "^11.1.19"
|
|
14
|
+
}
|
|
15
|
+
}
|