@ghentcdh/annotation-api 0.0.1-alpha.7 → 0.0.1-alpha.9

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