@ghentcdh/annotation-api 0.0.1-alpha.3 → 0.0.1-alpha.5

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.
Files changed (4) hide show
  1. package/index.cjs +1 -1
  2. package/index.d.ts +1 -1
  3. package/index.js +112 -109
  4. package/package.json +1 -1
package/index.cjs CHANGED
@@ -1 +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;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@nestjs/common"),t=require("zod"),n=require("@ghentcdh/w3c-utils"),r=require("@ghentcdh/annotated-text"),i=require("node:fs"),a=require("node:path"),o=require("@nestjs/swagger");var s=`AnnotationMetadata`,c=t.z.object({}),l=t.z.object({id:t.z.string(),name:t.z.string(),columns:t.z.array(c),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()}),u={baseUrl:`http://localhost:3000/`,app:`ghentcdh`,prefix:`ghentcdh`,isDev:!1,cacheTTLms:1200*1e3},d=(e={})=>{let t=e.baseUrl??u.baseUrl,n=t.endsWith(`/`)?t:`${t}/`,r=e.isDev??!1,i=r?0:1200*1e3;return{baseUrl:n,contextUrl:`${n}ns/`,app:e.app??u.app,prefix:e.prefix??u.prefix,isDev:r,cacheTTLms:i}},f=(e,t)=>{let{prefix:r,baseUrl:i,contextUrl:a}=d(t),o=s;return(0,n.contextBuilder)(r,i).setType(r,o).addPrefix(e,`${r}:${e}`).setContextUri(`${a}${e}.jsonld`)},p=`annotation.style`,m=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()}),h=`AnnotationStyle`,g=e=>{let{prefix:t,baseUrl:r,contextUrl:i}=d(e);return(0,n.contextBuilder)(t,r).setType(t,h).setContextUri(`${i}${h}.jsonld`).parseZodSchema(m)},_=(e,t)=>{let n=g(e).toAnnotationBodyUnsafe(t);return n.success||(r.Debugger.debug(p,`AnnotationStyleContextBuilder safe parse failed`),r.Debugger.warn(n.error)),n},v=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}},y=e=>({type:`TextCell`,scope:`#/properties/${e.id}`,options:{format:`keyValue`,key:e.fieldInput?.options?.labelKey??e.displayKey??`label`}}),b=e=>({type:`GridLayout`,elements:e.filter(e=>!e.hiddenInForm).map(v),options:{}}),x=e=>({type:`GridLayout`,elements:e.filter(e=>!e.hiddenInMetadata).map(y),options:{}}),S=e=>{if(e.type===`object`&&e.properties){let n={};for(let[t,r]of Object.entries(e.properties))n[t]=S(r);return t.z.object(n)}return t.z.string()},C=(e,n,r)=>{let i=f(e,r),a=n.columns??[];if(!a.length)return i;let o={};for(let e of a)e.type&&(o[e.id]=S(e.type));return Object.keys(o).length?i.parseZodSchema(t.z.object(o)):i},w=(e,t,n=C)=>{let r=n(e.id,e,t),i=e.columns??[],a=i.length>0,o=e.ui_schema??(a?b(i):void 0),s=e.metadata_schema??(a?x(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},T=(e,t,n)=>e.map(e=>w(e,t,n)),E=Symbol(`ANNOTATION_DEF_CONFIG_TOKEN`);function D(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function O(e,t){return function(n,r){t(n,r,e)}}function k(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 A=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}};A=k([(0,e.Injectable)(),O(0,(0,e.Inject)(E)),D(`design:paramtypes`,[Object])],A);var j=class extends A{_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??[])};j=k([(0,e.Injectable)(),O(0,(0,e.Inject)(E)),D(`design:paramtypes`,[Object,Array,Object])],j);var M=(e,t,n)=>{if(!(0,i.existsSync)(e))return[];let r=(0,i.readdirSync)(e,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name),o=[];for(let s of r){let r=(0,a.join)(e,s,`resource.json`);if(!(0,i.existsSync)(r))continue;let c=JSON.parse((0,i.readFileSync)(r,`utf-8`));o.push(w(c,t,n))}return o},N=class{service;annotationDefConfig;constructor(e,t){this.service=e,this.annotationDefConfig=t}getAll(){return this.service.findAll()}async getJsonLd_(e){return e===`AnnotationStyle`?g(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()}}};k([(0,e.Get)(),D(`design:type`,Function),D(`design:paramtypes`,[]),D(`design:returntype`,void 0)],N.prototype,`getAll`,null),k([(0,e.Get)(`:id.jsonld`),O(0,(0,e.Param)(`id`)),D(`design:type`,Function),D(`design:paramtypes`,[String]),D(`design:returntype`,Promise)],N.prototype,`getJsonLd_`,null),k([(0,e.Get)(`:id/schemas`),O(0,(0,e.Param)(`id`)),D(`design:type`,Function),D(`design:paramtypes`,[String]),D(`design:returntype`,Promise)],N.prototype,`getSchemas`,null),k([(0,e.Get)(`:id`),O(0,(0,e.Param)(`id`)),D(`design:type`,Function),D(`design:paramtypes`,[String]),D(`design:returntype`,Promise)],N.prototype,`getById`,null),k([(0,e.Get)(`anno.jsonld`),D(`design:type`,Function),D(`design:paramtypes`,[]),D(`design:returntype`,Promise)],N.prototype,`getFullJsonLd`,null),k([(0,e.Get)(`:type/anno.jsonld`),O(0,(0,e.Param)(`type`)),D(`design:type`,Function),D(`design:paramtypes`,[String]),D(`design:returntype`,Promise)],N.prototype,`getJsonLd`,null),N=k([(0,e.Controller)(`ns`),(0,o.ApiTags)(`Annotations NS`),O(0,(0,e.Inject)(A)),O(1,(0,e.Inject)(E)),D(`design:paramtypes`,[A===void 0?Object:A,Object])],N);var P=(e,t)=>{let n=(0,a.join)(e,`_resource`);if(!(0,i.existsSync)(n))return[];let r=(0,i.readdirSync)(n).filter(e=>e.endsWith(`.json`)),{prefix:o}=d(t);return r.map(e=>{let t=JSON.parse((0,i.readFileSync)((0,a.join)(n,e),`utf-8`)),r=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:r?.column??`id`,label:s?.column??`name`},prefix:`${o}:${t.type}/`}})},F=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}};F=k([(0,e.Injectable)(),D(`design:paramtypes`,[Array])],F);var I,L=I=class{static forService(e){return{module:I,global:!0,controllers:[N],providers:[{provide:A,useClass:e.annotationDefinitionService}],exports:[A]}}static async forResourceDir(e,t){let n=()=>M(e,t,C),r=new j(t,n(),n),i=new F(P(e,t));return{module:I,global:!0,controllers:[N],providers:[{provide:E,useValue:t},{provide:A,useValue:r},{provide:F,useValue:i}],exports:[A,F]}}};L=I=k([(0,e.Module)({controllers:[],providers:[],exports:[]})],L),exports.ANNOTATION_DEF_CONFIG_TOKEN=E,Object.defineProperty(exports,"AnnotationApiModule",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"AnnotationDefinitionFromFilesService",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"AnnotationDefinitionService",{enumerable:!0,get:function(){return A}}),exports.AnnotationMetadataType=s,Object.defineProperty(exports,"AnnotationResourceDefinitionService",{enumerable:!0,get:function(){return F}}),exports.AnnotationStyleContextBuilder=g,exports.AnnotationStyleType=h,exports.annotationColumnDefinition=c,exports.annotationContextBuilderFactory=C,exports.annotationDefinition=l,exports.baseContextBuilder=f,exports.buildAnnotationDefinition=w,exports.buildAnnotationDefinitions=T,exports.buildMetadataSchema=x,exports.buildUiSchema=b,exports.createAnnotationStyleBodyUnsafe=_,exports.jsonSchemaPropertyToZod=S,exports.loadAnnotationDefinitionsFromDir=M,exports.loadAnnotationResourcesFromDir=P,exports.resolveConfig=d;
package/index.d.ts CHANGED
@@ -5,4 +5,4 @@ export * from './lib/service/annotation-definition.loader';
5
5
  export * from './lib/resource/annotation-resource-definition.service';
6
6
  export * from './lib/resource/annotation-resource.loader';
7
7
  export * from './lib/utils/annotation.context-builder';
8
- export { type AnnotationColumnFieldInput, type AnnotationColumnConfig, type AnnotationJsonConfig, annotationColumnDefinition, annotationDefinition, type AnnotationDefinition, } from '@ghentcdh/annotation-core';
8
+ export * from '@ghentcdh/annotation-core';
package/index.js CHANGED
@@ -1,15 +1,15 @@
1
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
2
  import { z as s } from "zod";
3
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";
4
+ import { Debugger as l } from "@ghentcdh/annotated-text";
5
+ import { existsSync as u, readFileSync as d, readdirSync as f } from "node:fs";
6
+ import { join as p } from "node:path";
7
+ import { ApiTags as m } from "@nestjs/swagger";
8
8
  //#region packages/annotation-core/src/lib/types/annotation.contex.ts
9
- var m = "AnnotationMetadata", h = s.object({}), g = s.object({
9
+ var h = "AnnotationMetadata", g = s.object({}), _ = s.object({
10
10
  id: s.string(),
11
11
  name: s.string(),
12
- columns: s.array(h),
12
+ columns: s.array(g),
13
13
  json_schema: s.any().optional(),
14
14
  json_ld: s.any().optional(),
15
15
  ui_schema: s.any().optional(),
@@ -26,26 +26,26 @@ var m = "AnnotationMetadata", h = s.object({}), g = s.object({
26
26
  "underline",
27
27
  "highlight"
28
28
  ]).optional()
29
- }), _ = {
29
+ }), v = {
30
30
  baseUrl: "http://localhost:3000/",
31
31
  app: "ghentcdh",
32
32
  prefix: "ghentcdh",
33
33
  isDev: !1,
34
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;
35
+ }, y = (e = {}) => {
36
+ let t = e.baseUrl ?? v.baseUrl, n = t.endsWith("/") ? t : `${t}/`, r = e.isDev ?? !1, i = r ? 0 : 1200 * 1e3;
37
37
  return {
38
38
  baseUrl: n,
39
39
  contextUrl: `${n}ns/`,
40
- app: e.app ?? _.app,
41
- prefix: e.prefix ?? _.prefix,
40
+ app: e.app ?? v.app,
41
+ prefix: e.prefix ?? v.prefix,
42
42
  isDev: r,
43
43
  cacheTTLms: i
44
44
  };
45
- }, y = (e, t) => {
46
- let { prefix: n, baseUrl: r, contextUrl: i } = v(t), a = m;
45
+ }, b = (e, t) => {
46
+ let { prefix: n, baseUrl: r, contextUrl: i } = y(t), a = h;
47
47
  return c(n, r).setType(n, a).addPrefix(e, `${n}:${e}`).setContextUri(`${i}${e}.jsonld`);
48
- }, b = s.object({
48
+ }, x = "annotation.style", S = s.object({
49
49
  id: s.string(),
50
50
  name: s.string(),
51
51
  target: s.enum([
@@ -54,10 +54,13 @@ var m = "AnnotationMetadata", h = s.object({}), g = s.object({
54
54
  "highlight"
55
55
  ]).optional().default("underline"),
56
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) => {
57
+ }), C = "AnnotationStyle", w = (e) => {
58
+ let { prefix: t, baseUrl: n, contextUrl: r } = y(e);
59
+ return c(t, n).setType(t, C).setContextUri(`${r}${C}.jsonld`).parseZodSchema(S);
60
+ }, T = (e, t) => {
61
+ let n = w(e).toAnnotationBodyUnsafe(t);
62
+ return n.success || (l.debug(x, "AnnotationStyleContextBuilder safe parse failed"), l.warn(n.error)), n;
63
+ }, E = (e) => {
61
64
  let t = {};
62
65
  if (e.fieldInput) {
63
66
  let { type: n, options: r } = e.fieldInput;
@@ -68,36 +71,36 @@ var m = "AnnotationMetadata", h = s.object({}), g = s.object({
68
71
  scope: `#/properties/${e.id}`,
69
72
  options: t
70
73
  };
71
- }, w = (e) => ({
74
+ }, D = (e) => ({
72
75
  type: "TextCell",
73
76
  scope: `#/properties/${e.id}`,
74
77
  options: {
75
78
  format: "keyValue",
76
79
  key: e.fieldInput?.options?.labelKey ?? e.displayKey ?? "label"
77
80
  }
78
- }), T = (e) => ({
81
+ }), O = (e) => ({
79
82
  type: "GridLayout",
80
- elements: e.filter((e) => !e.hiddenInForm).map(C),
83
+ elements: e.filter((e) => !e.hiddenInForm).map(E),
81
84
  options: {}
82
- }), E = (e) => ({
85
+ }), k = (e) => ({
83
86
  type: "GridLayout",
84
- elements: e.filter((e) => !e.hiddenInMetadata).map(w),
87
+ elements: e.filter((e) => !e.hiddenInMetadata).map(D),
85
88
  options: {}
86
- }), D = (e) => {
89
+ }), A = (e) => {
87
90
  if (e.type === "object" && e.properties) {
88
91
  let t = {};
89
- for (let [n, r] of Object.entries(e.properties)) t[n] = D(r);
92
+ for (let [n, r] of Object.entries(e.properties)) t[n] = A(r);
90
93
  return s.object(t);
91
94
  }
92
95
  return s.string();
93
- }, O = (e, t, n) => {
94
- let r = y(e, n), i = t.columns ?? [];
96
+ }, j = (e, t, n) => {
97
+ let r = b(e, n), i = t.columns ?? [];
95
98
  if (!i.length) return r;
96
99
  let a = {};
97
- for (let e of i) e.type && (a[e.id] = D(e.type));
100
+ for (let e of i) e.type && (a[e.id] = A(e.type));
98
101
  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 = {
102
+ }, M = (e, t, n = j) => {
103
+ let r = n(e.id, e, t), i = e.columns ?? [], a = i.length > 0, o = e.ui_schema ?? (a ? O(i) : void 0), s = e.metadata_schema ?? (a ? k(i) : void 0), c = {
101
104
  id: e.id,
102
105
  name: e.name,
103
106
  color: e.color,
@@ -108,22 +111,22 @@ var m = "AnnotationMetadata", h = s.object({}), g = s.object({
108
111
  json_schema: o ? r.toJsonSchema() : null
109
112
  };
110
113
  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");
114
+ }, N = (e, t, n) => e.map((e) => M(e, t, n)), P = Symbol("ANNOTATION_DEF_CONFIG_TOKEN");
112
115
  //#endregion
113
116
  //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateMetadata.js
114
- function j(e, t) {
117
+ function F(e, t) {
115
118
  if (typeof Reflect == "object" && typeof Reflect.metadata == "function") return Reflect.metadata(e, t);
116
119
  }
117
120
  //#endregion
118
121
  //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
119
- function M(e, t) {
122
+ function I(e, t) {
120
123
  return function(n, r) {
121
124
  t(n, r, e);
122
125
  };
123
126
  }
124
127
  //#endregion
125
128
  //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
126
- function N(e, t, n, r) {
129
+ function L(e, t, n, r) {
127
130
  var i = arguments.length, a = i < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, o;
128
131
  if (typeof Reflect == "object" && typeof Reflect.decorate == "function") a = Reflect.decorate(e, t, n, r);
129
132
  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);
@@ -131,7 +134,7 @@ function N(e, t, n, r) {
131
134
  }
132
135
  //#endregion
133
136
  //#region packages/annotation-api/src/lib/service/annotation-definition.service.ts
134
- var P = class {
137
+ var R = class {
135
138
  config;
136
139
  definitions = [];
137
140
  groupedDefinitions = {};
@@ -166,14 +169,14 @@ var P = class {
166
169
  return t.context;
167
170
  }
168
171
  };
169
- P = N([
172
+ R = L([
170
173
  r(),
171
- M(0, n(A)),
172
- j("design:paramtypes", [Object])
173
- ], P);
174
+ I(0, n(P)),
175
+ F("design:paramtypes", [Object])
176
+ ], R);
174
177
  //#endregion
175
178
  //#region packages/annotation-api/src/lib/service/annotation-definition-from-files.service.ts
176
- var F = class extends P {
179
+ var z = class extends R {
177
180
  _initialDefinitions;
178
181
  _loaderFn;
179
182
  constructor(e, t, n) {
@@ -181,28 +184,28 @@ var F = class extends P {
181
184
  }
182
185
  reloadDefinitions = () => this.config.isDev && this._loaderFn ? Promise.resolve(this._loaderFn()) : Promise.resolve(this._initialDefinitions ?? []);
183
186
  };
184
- F = N([
187
+ z = L([
185
188
  r(),
186
- M(0, n(A)),
187
- j("design:paramtypes", [
189
+ I(0, n(P)),
190
+ F("design:paramtypes", [
188
191
  Object,
189
192
  Array,
190
193
  Object
191
194
  ])
192
- ], F);
195
+ ], z);
193
196
  //#endregion
194
197
  //#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
+ var B = (e, t, n) => {
199
+ if (!u(e)) return [];
200
+ let r = f(e, { withFileTypes: !0 }).filter((e) => e.isDirectory()).map((e) => e.name), i = [];
198
201
  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));
202
+ let r = p(e, a, "resource.json");
203
+ if (!u(r)) continue;
204
+ let o = JSON.parse(d(r, "utf-8"));
205
+ i.push(M(o, t, n));
203
206
  }
204
207
  return i;
205
- }, L = class {
208
+ }, V = class {
206
209
  service;
207
210
  annotationDefConfig;
208
211
  constructor(e, t) {
@@ -212,7 +215,7 @@ var I = (e, t, n) => {
212
215
  return this.service.findAll();
213
216
  }
214
217
  async getJsonLd_(e) {
215
- return e === "AnnotationStyle" ? S(this.annotationDefConfig).toJsonLdContext() : (await this.service.findById(e))?.json_ld;
218
+ return e === "AnnotationStyle" ? w(this.annotationDefConfig).toJsonLdContext() : (await this.service.findById(e))?.json_ld;
216
219
  }
217
220
  async getSchemas(e) {
218
221
  let t = await this.service.findById(e);
@@ -245,55 +248,55 @@ var I = (e, t, n) => {
245
248
  };
246
249
  }
247
250
  };
248
- N([
251
+ L([
249
252
  t(),
250
- j("design:type", Function),
251
- j("design:paramtypes", []),
252
- j("design:returntype", void 0)
253
- ], L.prototype, "getAll", null), N([
253
+ F("design:type", Function),
254
+ F("design:paramtypes", []),
255
+ F("design:returntype", void 0)
256
+ ], V.prototype, "getAll", null), L([
254
257
  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([
258
+ I(0, o("id")),
259
+ F("design:type", Function),
260
+ F("design:paramtypes", [String]),
261
+ F("design:returntype", Promise)
262
+ ], V.prototype, "getJsonLd_", null), L([
260
263
  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([
264
+ I(0, o("id")),
265
+ F("design:type", Function),
266
+ F("design:paramtypes", [String]),
267
+ F("design:returntype", Promise)
268
+ ], V.prototype, "getSchemas", null), L([
266
269
  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([
270
+ I(0, o("id")),
271
+ F("design:type", Function),
272
+ F("design:paramtypes", [String]),
273
+ F("design:returntype", Promise)
274
+ ], V.prototype, "getById", null), L([
272
275
  t("anno.jsonld"),
273
- j("design:type", Function),
274
- j("design:paramtypes", []),
275
- j("design:returntype", Promise)
276
- ], L.prototype, "getFullJsonLd", null), N([
276
+ F("design:type", Function),
277
+ F("design:paramtypes", []),
278
+ F("design:returntype", Promise)
279
+ ], V.prototype, "getFullJsonLd", null), L([
277
280
  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([
281
+ I(0, o("type")),
282
+ F("design:type", Function),
283
+ F("design:paramtypes", [String]),
284
+ F("design:returntype", Promise)
285
+ ], V.prototype, "getJsonLd", null), V = L([
283
286
  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);
287
+ m("Annotations NS"),
288
+ I(0, n(R)),
289
+ I(1, n(P)),
290
+ F("design:paramtypes", [R === void 0 ? Object : R, Object])
291
+ ], V);
289
292
  //#endregion
290
293
  //#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);
294
+ var H = (e, t) => {
295
+ let n = p(e, "_resource");
296
+ if (!u(n)) return [];
297
+ let r = f(n).filter((e) => e.endsWith(".json")), { prefix: i } = y(t);
295
298
  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");
299
+ let t = JSON.parse(d(p(n, e), "utf-8")), r = t.columns.find((e) => e.displayAs === "id"), a = t.columns.find((e) => e.displayAs === "label");
297
300
  return {
298
301
  type: t.type,
299
302
  table: t.table,
@@ -305,7 +308,7 @@ var R = (e, t) => {
305
308
  prefix: `${i}:${t.type}/`
306
309
  };
307
310
  });
308
- }, z = class {
311
+ }, U = class {
309
312
  byType = /* @__PURE__ */ new Map();
310
313
  constructor(e) {
311
314
  for (let t of e) this.byType.set(t.type, t);
@@ -320,50 +323,50 @@ var R = (e, t) => {
320
323
  return null;
321
324
  };
322
325
  };
323
- z = N([r(), j("design:paramtypes", [Array])], z);
326
+ U = L([r(), F("design:paramtypes", [Array])], U);
324
327
  //#endregion
325
328
  //#region packages/annotation-api/src/lib/annotation-api.module.ts
326
- var B, V = B = class {
329
+ var W, G = W = class {
327
330
  static forService(e) {
328
331
  return {
329
- module: B,
332
+ module: W,
330
333
  global: !0,
331
- controllers: [L],
334
+ controllers: [V],
332
335
  providers: [{
333
- provide: P,
336
+ provide: R,
334
337
  useClass: e.annotationDefinitionService
335
338
  }],
336
- exports: [P]
339
+ exports: [R]
337
340
  };
338
341
  }
339
342
  static async forResourceDir(e, t) {
340
- let n = () => I(e, t, O), r = new F(t, n(), n), i = new z(R(e, t));
343
+ let n = () => B(e, t, j), r = new z(t, n(), n), i = new U(H(e, t));
341
344
  return {
342
- module: B,
345
+ module: W,
343
346
  global: !0,
344
- controllers: [L],
347
+ controllers: [V],
345
348
  providers: [
346
349
  {
347
- provide: A,
350
+ provide: P,
348
351
  useValue: t
349
352
  },
350
353
  {
351
- provide: P,
354
+ provide: R,
352
355
  useValue: r
353
356
  },
354
357
  {
355
- provide: z,
358
+ provide: U,
356
359
  useValue: i
357
360
  }
358
361
  ],
359
- exports: [P, z]
362
+ exports: [R, U]
360
363
  };
361
364
  }
362
365
  };
363
- V = B = N([i({
366
+ G = W = L([i({
364
367
  controllers: [],
365
368
  providers: [],
366
369
  exports: []
367
- })], V);
370
+ })], G);
368
371
  //#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 };
372
+ export { P as ANNOTATION_DEF_CONFIG_TOKEN, G as AnnotationApiModule, z as AnnotationDefinitionFromFilesService, R as AnnotationDefinitionService, h as AnnotationMetadataType, U as AnnotationResourceDefinitionService, w as AnnotationStyleContextBuilder, C as AnnotationStyleType, g as annotationColumnDefinition, j as annotationContextBuilderFactory, _ as annotationDefinition, b as baseContextBuilder, M as buildAnnotationDefinition, N as buildAnnotationDefinitions, k as buildMetadataSchema, O as buildUiSchema, T as createAnnotationStyleBodyUnsafe, A as jsonSchemaPropertyToZod, B as loadAnnotationDefinitionsFromDir, H as loadAnnotationResourcesFromDir, y as resolveConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghentcdh/annotation-api",
3
- "version": "0.0.1-alpha.3",
3
+ "version": "0.0.1-alpha.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/GhentCDH/annotation-editor"