@redocly/revel-reef 0.130.0-next.1 → 0.130.0-next.3
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/CHANGELOG.md +43 -0
- package/dist/bin.js +1 -1
- package/dist/cli/eject/resolveEjectParams.js +1 -1
- package/dist/cli/stats/collectors/openapi.d.ts +3 -0
- package/dist/cli/stats/collectors/openapi.js +1 -0
- package/dist/cli/stats/index.d.ts +7 -0
- package/dist/cli/stats/index.js +1 -0
- package/dist/cli/stats/options.d.ts +3 -0
- package/dist/cli/stats/options.js +1 -0
- package/dist/cli/telemetry/index.d.ts +1 -1
- package/dist/cli/telemetry/index.js +1 -1
- package/dist/client/app/Sidebar/Sidebar.js +1 -1
- package/dist/server/fs/cache.js +1 -1
- package/dist/server/plugins/catalog-entities/database/catalog-entities-service.d.ts +2 -2
- package/dist/server/plugins/catalog-entities/database/catalog-entities-service.js +1 -1
- package/dist/server/plugins/catalog-entities/database/mappers/create-entity-attributes-db-record.d.ts +8 -0
- package/dist/server/plugins/catalog-entities/database/mappers/create-entity-attributes-db-record.js +1 -0
- package/dist/server/plugins/catalog-entities/database/mappers/create-entity-read-model.js +1 -1
- package/dist/server/plugins/catalog-entities/database/mappers/map-entity-relation-row.js +1 -1
- package/dist/server/plugins/catalog-entities/database/repositories/local/catalog-entities-bff-repository.d.ts +2 -2
- package/dist/server/plugins/catalog-entities/database/repositories/local/catalog-entities-bff-repository.js +14 -14
- package/dist/server/plugins/catalog-entities/database/repositories/local/catalog-entities-local-read-repository.d.ts +2 -2
- package/dist/server/plugins/catalog-entities/database/repositories/local/catalog-entities-local-read-repository.js +5 -3
- package/dist/server/plugins/catalog-entities/database/repositories/local/catalog-entities-local-repository.d.ts +2 -2
- package/dist/server/plugins/catalog-entities/database/repositories/local/catalog-entities-local-repository.js +1 -1
- package/dist/server/plugins/catalog-entities/database/repositories/local/catalog-entities-local-write-repository.d.ts +2 -1
- package/dist/server/plugins/catalog-entities/database/repositories/local/catalog-entities-local-write-repository.js +1 -1
- package/dist/server/plugins/catalog-entities/database/repositories/local/catalog-entities-relations-repository.js +1 -1
- package/dist/server/plugins/catalog-entities/database/repositories/remote/catalog-entities-remote-repository.js +1 -1
- package/dist/server/plugins/catalog-entities/extensions/extractors/api-description/arazzo-entities-extractor.js +1 -1
- package/dist/server/plugins/catalog-entities/extensions/extractors/api-description/asyncapi-entities-extractor.js +1 -1
- package/dist/server/plugins/catalog-entities/extensions/extractors/api-description/base.d.ts +4 -3
- package/dist/server/plugins/catalog-entities/extensions/extractors/api-description/base.js +1 -1
- package/dist/server/plugins/catalog-entities/extensions/extractors/api-description/graphql-entities-extractor.js +2 -2
- package/dist/server/plugins/catalog-entities/extensions/extractors/api-description/openapi-entities-extractor.d.ts +1 -1
- package/dist/server/plugins/catalog-entities/extensions/extractors/api-description/openapi-entities-extractor.js +1 -1
- package/dist/server/plugins/catalog-entities/get-server-props.js +1 -1
- package/dist/server/plugins/catalog-entities/plugin.js +1 -1
- package/dist/server/plugins/catalog-entities/schemas/database-schemas.d.ts +3 -0
- package/dist/server/plugins/catalog-entities/schemas/database-schemas.js +1 -1
- package/dist/server/plugins/catalog-entities/schemas/dto-schemas.d.ts +12 -0
- package/dist/server/plugins/catalog-entities/schemas/dto-schemas.js +1 -1
- package/dist/server/plugins/catalog-entities/schemas/read-model-schemas.d.ts +1 -0
- package/dist/server/plugins/catalog-entities/types/extractors.d.ts +4 -4
- package/dist/server/plugins/config-parser/loaders/content-slugs-loader.js +1 -1
- package/dist/server/plugins/default-theme/index.js +1 -1
- package/dist/server/plugins/openapi-docs/index.js +1 -1
- package/dist/server/plugins/search/ai-indexer/prepare-ai-search-documents.js +1 -1
- package/dist/server/plugins/search/documents/search-documents.js +1 -1
- package/dist/server/plugins/sso/index.js +1 -1
- package/dist/server/providers/database/databases/catalog-sqlite/migrations/0005_catalog-relations-constraint-fix.sql +2 -0
- package/dist/server/providers/database/databases/catalog-sqlite/migrations/0006_add-catalog-entitities-attributes-table.sql +11 -0
- package/dist/server/providers/database/databases/catalog-sqlite/migrations/meta/0005_snapshot.json +393 -0
- package/dist/server/providers/database/databases/catalog-sqlite/migrations/meta/0006_snapshot.json +458 -0
- package/dist/server/providers/database/databases/catalog-sqlite/migrations/meta/_journal.json +14 -0
- package/dist/server/providers/database/databases/catalog-sqlite/schemas/entities-attributes-table.d.ts +143 -0
- package/dist/server/providers/database/databases/catalog-sqlite/schemas/entities-attributes-table.js +1 -0
- package/dist/server/providers/database/databases/catalog-sqlite/schemas/entities-relations-table.js +1 -1
- package/dist/server/providers/database/databases/sqld-sqlite/migrations/0007_catalog-relations-constraint-fix.sql +2 -0
- package/dist/server/providers/database/databases/sqld-sqlite/migrations/0008_add-catalog-entitities-attributes-table.sql +11 -0
- package/dist/server/providers/database/databases/sqld-sqlite/migrations/meta/0007_snapshot.json +833 -0
- package/dist/server/providers/database/databases/sqld-sqlite/migrations/meta/0008_snapshot.json +898 -0
- package/dist/server/providers/database/databases/sqld-sqlite/migrations/meta/_journal.json +14 -0
- package/dist/server/utils/rbac.d.ts +11 -7
- package/dist/server/utils/rbac.js +1 -1
- package/dist/server/web-server/routes/catalog/bff-catalog.js +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
import{and as d,desc as
|
|
1
|
+
import{and as d,desc as I,eq as u,isNull as v,or as K,sql as k}from"drizzle-orm";import{logger as h}from"../../../../../tools/notifiers/logger.js";import{promiseMapLimit as w}from"../../../../../utils/async/promise-map-limit.js";import{sha1 as U}from"../../../../../utils/crypto/sha1.js";import{isWebView as x}from"../../../../../../utils/env/is-web-view.js";import{VERSION_NOT_SPECIFIED as S}from"@redocly/theme/core/constants";import{entitiesAttributesTable as E}from"../../../../../providers/database/databases/catalog-sqlite/schemas/entities-attributes-table.js";import{createEntityDbRecord as z}from"../../mappers/create-entity-db-record.js";import{createEntityRelationDbRecordFromFileSchema as A}from"../../mappers/create-entity-relation-db-record-from-file-schema.js";import{entitiesTable as e}from"../../../../../providers/database/databases/catalog-sqlite/schemas/entities-table.js";import{entitiesRelationsTable as o}from"../../../../../providers/database/databases/catalog-sqlite/schemas/entities-relations-table.js";import{convertFilterToWhereCondition as T}from"../../../../../providers/database/pagination/filter.js";import{compareVersionsDescending as L}from"../../../utils/version-compare.js";import{createEntityAttributesDbRecord as N}from"../../mappers/create-entity-attributes-db-record.js";const D=15;class ie{#e;#t;#r;constructor(t,r,i){this.#e=t,this.#t=r,this.#r=i}async createEntity({entity:t,fileHash:r,sourceFile:i,revision:a=new Date().toISOString(),isRootEntity:n=!1,isDeleted:s=!1,rbacTeams:c=[]}){try{const{relations:l=[],...m}=t,V=U(JSON.stringify(m)),f=t.version??S;if(await this.#i(t.key,f,V,n,s))return{result:"skipped",entityKey:t.key};const{shouldBeCurrent:p,shouldBeDefaultVersion:y}=await this.#o(t.key,f),g=z({entity:{...t,revision:a,hash:V,isCurrent:p,isDefaultVersion:y,isDeleted:s,version:f},sourceFile:i,organizationId:this.#t,projectId:this.#r,source:"file",fileHash:r}),{key:F,source:j,...b}=g;if(await this.#a({key:F,isCurrent:p,isDefaultVersion:y}),x())return await this.#c(g,l,c),{result:"created",entityKey:t.key,entityRevision:a,entityVersion:f};const O=this.#e.client.insert(e).values(g).onConflictDoUpdate({target:[e.key,e.source,e.revision,e.version],set:b}),B=this.#e.client.insert(E).values(N({rbacTeams:c,entityKey:t.key,organizationId:this.#t,projectId:this.#r})).onConflictDoUpdate({target:[E.entityKey],set:{rbacTeams:JSON.stringify(c)}}),P=l?.length&&l.length>0?this.#e.client.insert(o).values(l.map(C=>A({relation:C,sourceFile:i,fileHash:r,sourceKey:t.key,sourceVersion:f,sourceRevision:a??null,organizationId:this.#t,projectId:this.#r}))).onConflictDoNothing({target:[o.sourceKey,o.targetKey,o.sourceVersion,o.targetVersion,o.sourceRevision,o.targetRevision,o.sourceToTargetRelation]}).run():Promise.resolve();return await w([O,P,B],D,async C=>C),{result:"created",entityKey:t.key,entityRevision:a,entityVersion:f}}catch(l){return h.error("Error adding entity",l),{result:"error",entityKey:t.key}}}async deleteEntity(t){try{return await this.#e.client.delete(e).where(u(e.key,t)),t}catch(r){return h.error("Error deleting entity",r),null}}async deleteEntities(t){try{const r=T(t);if(!r)return!1;const i=await this.#e.client.delete(e).where(r).returning({key:e.key,source:e.source,isCurrent:e.isCurrent,isDefaultVersion:e.isDefaultVersion,version:e.version});if(i.length===0)return!0;const a=i.reduce((n,s)=>((s.isCurrent||s.isDefaultVersion)&&n.add(s.key),n),new Set);if(a.size===0)return!0;await w(Array.from(a),D,async n=>this.#u(n));for(const n of i)await this.#e.client.delete(o).where(K(d(u(o.sourceKey,n.key),...n.version?[u(o.sourceVersion,n.version)]:[v(o.sourceVersion)]),d(u(o.targetKey,n.key),...n.version?[u(o.targetVersion,n.version)]:[v(o.targetVersion)])));return!0}catch(r){return h.error("Error deleting entities",r),!1}}async deleteEntityRelation(t){try{return await this.#e.client.delete(o).where(u(o.id,t)),t}catch{return null}}async softDeleteEntities(t,r,i){try{const a=t.map(s=>{const c={type:s.type,key:s.key,title:s.title,summary:s.summary??void 0,tags:s.tags??void 0,metadata:s.metadata??void 0,git:s.git??void 0,contact:s.contact??void 0,links:s.links??void 0,version:s.version??void 0};return this.createEntity({entity:c,revision:r,sourceFile:s.sourceFile??"",fileHash:i,isDeleted:!0})});return await w(a,D,async s=>s)}catch(a){return h.error("Error soft deleting entities",a),[]}}async deleteEntityRelations(t){try{const r=T(t);return r?(await this.#e.client.delete(o).where(r),!0):!1}catch(r){return h.error("Error deleting entity relations",r),!1}}async upsertEntityRelation(t){if(!t)return null;try{const{sourceKey:r,targetKey:i,sourceVersion:a,targetVersion:n,sourceRevision:s,targetRevision:c,...l}=t,m=await this.#e.client.insert(o).values(t).onConflictDoUpdate({target:[o.sourceKey,o.targetKey,o.sourceVersion,o.targetVersion,o.sourceRevision,o.targetRevision,o.sourceToTargetRelation],set:l}).returning();return m?.length?m[0]:null}catch(r){return h.error("Error creating entity relation",r),null}}async#i(t,r,i,a,n){if(a||n)return!1;const s=await this.#e.client.select({hash:e.hash,isDeleted:e.isDeleted}).from(e).where(d(u(e.key,t),u(e.source,"file"),r?u(e.version,r):v(e.version))).orderBy(I(e.revision)).limit(1).run();if(s.rows.length===0)return!1;const c=s.rows[0];return c.is_deleted?!1:c.hash===i}async#s(t){return(await this.#e.client.select({version:e.version,isDefaultVersion:e.isDefaultVersion,revision:e.revision,createdAt:e.createdAt}).from(e).where(d(u(e.key,t),u(e.source,"file"))).orderBy(I(e.createdAt)).run()).rows.map(i=>({version:i.version,isDefaultVersion:!!i.isDefaultVersion,revision:i.revision,createdAt:new Date(i.createdAt)}))}#n(t){const r=t.find(n=>n.isDefaultVersion);if(r)return r;const{versionedEntities:i,unversionedEntities:a}=t.reduce((n,s)=>(s.version!==null&&s.version!==S?n.versionedEntities.push(s):n.unversionedEntities.push(s),n),{versionedEntities:[],unversionedEntities:[]});if(i.length>0){i.sort((c,l)=>L(c.version,l.version));const n=i[0].version,s=i.filter(c=>c.version===n);return s.sort((c,l)=>l.createdAt.getTime()-c.createdAt.getTime()),s[0]}return a.length>0?(a.sort((n,s)=>s.createdAt.getTime()-n.createdAt.getTime()),a[0]):null}async#o(t,r){const i=await this.#e.client.select({currentDefaultVersion:k`max(case when ${e.isDefaultVersion} = 1 then ${e.version} else null end)`,versionMatchCount:k`count(case when ${e.version} = ${r} then 1 else null end)`}).from(e).where(d(u(e.key,t),u(e.source,"file"))).get(),a=i?.currentDefaultVersion,n=(i?.versionMatchCount??0)>0;return r&&r===a?{shouldBeCurrent:!0,shouldBeDefaultVersion:!1}:{shouldBeCurrent:!n,shouldBeDefaultVersion:!n}}async#a({key:t,isCurrent:r,isDefaultVersion:i}){if(!r&&!i)return;const a={},n=[];r&&(a.isCurrent=!1,n.push(u(e.isCurrent,!0))),i&&(a.isDefaultVersion=!1,n.push(u(e.isDefaultVersion,!0))),await this.#e.client.update(e).set(a).where(d(u(e.key,t),u(e.source,"file"),K(...n))).run()}#u=async t=>{const r=await this.#s(t),i=this.#n(r);if(!i){h.warn("No latest version found for key",t);return}await this.#e.client.update(e).set({isDefaultVersion:!0,isCurrent:!0}).where(d(u(e.key,t),u(e.revision,i.revision),i.version?u(e.version,i.version):v(e.version))).run()};async#c(t,r,i){const{key:a,source:n,version:s,isDefaultVersion:c,...l}=t,f=(await this.#e.client.select({id:e.id}).from(e).where(d(u(e.key,a),u(e.source,n??"file"),s?u(e.version,s):v(e.version))).limit(1).run()).rows.length>0?this.#e.client.update(e).set(l).where(d(u(e.key,a),u(e.source,n??"file"),s?u(e.version,s):v(e.version))).run():this.#e.client.insert(e).values(t).onConflictDoUpdate({target:[e.key,e.source,e.revision,e.version],set:l}).run(),R=r?.map(y=>{const g=A({relation:y,sourceFile:t.sourceFile??"",fileHash:t.fileHash??"",sourceKey:t.key,sourceVersion:t.version??null,sourceRevision:t.revision??null,organizationId:this.#t,projectId:this.#r});return this.#e.client.insert(o).values(g).onConflictDoUpdate({target:[o.sourceKey,o.targetKey,o.sourceVersion,o.targetVersion,o.sourceRevision,o.targetRevision,o.sourceToTargetRelation],set:g}).run()})??[],p=this.#e.client.insert(E).values(N({rbacTeams:i,entityKey:t.key,organizationId:this.#t,projectId:this.#r})).onConflictDoUpdate({target:[E.entityKey],set:{rbacTeams:JSON.stringify(i)}});await w([f,...R,p],D,async y=>y)}async updateEntityScorecardsStatus(t,r){try{return(await this.#e.client.update(e).set({scorecardsStatus:r}).where(u(e.id,t)).returning()).length>0}catch(i){return h.error("Error updating entity scorecards status",i),!1}}async updateEntityScorecardsStatusIfCalculating(t,r){try{return(await this.#e.client.update(e).set({scorecardsStatus:r}).where(k`${e.id} = ${t} AND ${e.scorecardsStatus} = 'CALCULATING'`).returning()).length>0}catch(i){return h.error("Error updating entity scorecards status if calculating",i),!1}}}export{ie as CatalogEntitiesLocalWriteRepository};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{unionAll as w}from"drizzle-orm/sqlite-core";import{and as u,desc as
|
|
1
|
+
import{unionAll as w}from"drizzle-orm/sqlite-core";import{and as u,desc as p,eq as y,notExists as C,sql as i}from"drizzle-orm";import{VERSION_NOT_SPECIFIED as D}from"@redocly/theme/core/constants";import{entitiesTable as e}from"../../../../../providers/database/databases/catalog-sqlite/schemas/entities-table.js";import{entitiesRelationsTable as t}from"../../../../../providers/database/databases/catalog-sqlite/schemas/entities-relations-table.js";import{excludeFieldsFromFilter as B,getFirstFilterFieldValue as N}from"../../../../../providers/database/pagination/filter.js";import{applyPagination as O}from"../../../../../providers/database/pagination/index.js";import{createBffRelatedEntityFromQueryRow as K}from"../../mappers/create-bff-related-entity.js";import{mapEntityRelationRow as Q}from"../../mappers/map-entity-relation-row.js";class M{#e;#i;constructor(o,n){this.#e=o,this.#i=n}async getRelationsForEntity(o,n,d){const a=await this.#t(o,n,d);return a?(await this.#e.client.select().from(a).run()).rows.map(s=>Q(s)):[]}async getRelatedEntities(o,n={}){const d=N(n.filter,"version"),a=N(n.filter,"revision"),r=await this.#t(o,d,a);if(!r)return{items:[],total:0};const s=this.#e.client.select({relationType:r.relationName,direction:r.direction,key:e.key,revision:e.revision,id:e.id,type:e.type,title:e.title,summary:e.summary,tags:e.tags,metadata:e.metadata,createdAt:e.createdAt,updatedAt:e.updatedAt,source:e.source,sourceFile:e.sourceFile,version:e.version,isDeleted:e.isDeleted,isCurrent:e.isCurrent,dedupRn:i`ROW_NUMBER() OVER (PARTITION BY ${r.entityKey} ORDER BY ${r.priority} ASC, CASE WHEN ${r.entityRevision} = ${e.revision} THEN 1 ELSE 0 END DESC, CASE WHEN ${r.entityVersion} = ${e.version} THEN 1 ELSE 0 END DESC, ${e.isCurrent} DESC, ${e.revision} DESC)`.as("dedupRn")}).from(r).innerJoin(e,i`${r.entityKey} = ${e.key} AND (${r.entityRevision} = ${e.revision} OR ${r.entityRevision} = '' OR ${e.isCurrent} = 1) AND (${r.entityVersion} = ${e.version} OR ${r.entityVersion} = '' OR ${e.version} = ${D})`).as("unique_relations"),m=i`${s.dedupRn} = 1 AND COALESCE(${s.isDeleted}, 0) = 0`,E=this.#e.client.select().from(s).$dynamic(),$=this.#e.client.select().from(s).$dynamic(),f=B(n.filter,["version","revision"]),R={...n,filter:f,baseWhereCondition:m},l=O($,{...R,limit:void 0,skip:void 0,after:void 0,before:void 0}),c=this.#e.client.$count(l),h=n.limit||10,S=O(E,{...R,limit:h+1}),[V,A]=await Promise.all([S.run(),c]),g=V.rows.filter(v=>v.id!=null).map(v=>K(v)).filter(v=>v!==null),T=g.slice(0,h),F=g.length>h;return{items:T,hasMore:F,total:A}}async#r(o,n){if(n){const s=await(this.#i?w(this.#e.client.select({version:i.raw("version"),revision:i.raw("revision")}).from(i`remote.entities`).where(u(i`key = ${o}`,i`version = ${n}`)).orderBy(i.raw("revision DESC")),this.#e.client.select({version:e.version,revision:e.revision}).from(e).where(u(y(e.key,o),y(e.version,n),C(this.#e.client.select({id:i.raw("id")}).from(i`remote.entities as remote`).where(u(i`remote.key = ${e.key}`,i`remote.version = ${n}`))))).orderBy(p(e.revision))):this.#e.client.select({version:e.version,revision:e.revision}).from(e).where(u(y(e.key,o),y(e.version,n))).orderBy(p(e.revision))).limit(1).run();if(s.rows.length>0){const m=s.rows[0];return{version:m.version||null,revision:m.revision||null}}return null}const a=await(this.#i?w(this.#e.client.select({version:i.raw("version"),revision:i.raw("revision")}).from(i`remote.entities`).where(u(i`key = ${o}`,i`is_current = 1`)),this.#e.client.select({version:e.version,revision:e.revision}).from(e).where(u(y(e.key,o),y(e.isCurrent,!0),C(this.#e.client.select({id:i.raw("id")}).from(i`remote.entities as remote`).where(u(i`remote.key = ${e.key}`,i`remote.is_current = 1`)))))):this.#e.client.select({version:e.version,revision:e.revision}).from(e).where(u(y(e.key,o),y(e.isCurrent,!0)))).limit(1).run();if(a.rows.length>0){const r=a.rows[0];return{version:r.version||null,revision:r.revision||null}}return null}async#t(o,n,d){const a=d?{version:n||null,revision:d}:await this.#r(o,n||null),r=n||a?.version||null,s=d||a?.revision||null,m=!r||r===D,E=m?i`1 = 1`:i`(${t.sourceVersion} = ${r} OR ${t.sourceVersion} = '')`,$=m?i`1 = 1`:i`(${t.targetVersion} = ${r} OR ${t.targetVersion} = '')`,f=s?i`(${t.sourceRevision} <= ${s} OR ${t.sourceRevision} = '')`:i`1 = 0`,R=s?i`(${t.targetRevision} <= ${s} OR ${t.targetRevision} = '')`:i`1 = 0`,l=this.#e.client.select({entityKey:t.targetKey,entityRevision:t.targetRevision,entityVersion:t.targetVersion,relationName:t.sourceToTargetRelation,direction:i`'outgoing'`.as("direction"),priority:i`1`.as("priority"),isDeleted:t.isDeleted,rn:i`ROW_NUMBER() OVER (PARTITION BY ${t.targetKey}, ${t.sourceToTargetRelation} ORDER BY CASE WHEN ${t.sourceVersion} != '' THEN 1 ELSE 0 END DESC, ${t.sourceRevision} DESC)`.as("rn")}).from(t).where(u(y(t.sourceKey,o),E,f)).as("outgoing_filtered"),c=this.#e.client.select({entityKey:t.sourceKey,entityRevision:t.sourceRevision,entityVersion:t.sourceVersion,relationName:t.targetToSourceRelation,direction:i`'incoming'`.as("direction"),priority:i`2`.as("priority"),isDeleted:t.isDeleted,rn:i`ROW_NUMBER() OVER (PARTITION BY ${t.sourceKey}, ${t.targetToSourceRelation} ORDER BY CASE WHEN ${t.targetVersion} != '' THEN 1 ELSE 0 END DESC, ${t.targetRevision} DESC)`.as("rn")}).from(t).where(u(y(t.targetKey,o),$,R)).as("incoming_filtered");return this.#e.client.select({entityKey:l.entityKey,entityRevision:l.entityRevision,entityVersion:l.entityVersion,relationName:l.relationName,direction:l.direction,priority:l.priority}).from(l).where(i`${l.rn} = 1 AND COALESCE(${l.isDeleted}, 0) = 0`).unionAll(this.#e.client.select({entityKey:c.entityKey,entityRevision:c.entityRevision,entityVersion:c.entityVersion,relationName:c.relationName,direction:c.direction,priority:c.priority}).from(c).where(i`${c.rn} = 1 AND COALESCE(${c.isDeleted}, 0) = 0`)).as("all_relations")}}export{M as CatalogEntitiesRelationsRepository};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{eq as h,sql as f}from"drizzle-orm";import{convertFilterToWhereCondition as w}from"../../../../../providers/database/pagination/filter.js";import{promiseMapLimit as E}from"../../../../../utils/async/promise-map-limit.js";import{logger as
|
|
1
|
+
import{eq as h,sql as f}from"drizzle-orm";import{convertFilterToWhereCondition as w}from"../../../../../providers/database/pagination/filter.js";import{promiseMapLimit as E}from"../../../../../utils/async/promise-map-limit.js";import{logger as i}from"../../../../../tools/notifiers/logger.js";import{entitiesTable as r}from"../../../../../providers/database/databases/catalog-sqlite/schemas/entities-table.js";import{telemetryTraceStep as a}from"../../../../../telemetry/helpers/trace-step.js";import{BaseRepository as _}from"../../../../../providers/database/base-repository.js";import{DatabaseConnectionFactory as b}from"../../../../../providers/database/database-connection-factory.js";import{entitiesRelationsTable as n}from"../../../../../providers/database/databases/catalog-sqlite/schemas/entities-relations-table.js";import{createEntityDbRecord as p}from"../../mappers/create-entity-db-record.js";import{createEntityReadModel as g}from"../../mappers/create-entity-read-model.js";import{createEntityRelationDbRecordFromDto as C}from"../../mappers/create-entity-relation-db-record-from-dto.js";const I=15;class s extends _{static#e;get transactionsManager(){return this.databaseClient.transactionsManager}constructor(e){super(e)}async sync(){return a("catalog_entities.remote_repository.sync",async()=>{await this.#t(),await this.databaseClient.sync()})}static async getInstance(e){return await a("catalog_entities.remote_repository.get_instance",async t=>{if(!s.#e)try{const o=await b.create("sqld-remote",e);if(!o)return i.error("Failed to create db connection for catalog entities remote repository"),t?.error(new Error("Failed to create db connection for catalog entities remote repository")),s.#e=null,null;s.#e=new s(o)}catch(o){return i.error("Error creating db connection for catalog entities remote repository",o),t?.error(o),s.#e=null,null}return s.#e})}async createEntity(e){return a("catalog_entities.remote_repository.create_entity",async()=>{await this.#t();try{i.info(`Adding entity ${e.key} to remote database`);const t=p({entity:e,organizationId:this.organizationId,projectId:this.projectId,source:"remote",sourceFile:null,fileHash:null}),{key:o,source:d,...u}=t,l=await this.databaseClient.client.insert(r).values(t).onConflictDoUpdate({target:[r.key,r.source,r.revision,r.version],set:u}).returning();return l.length?(e.relations&&await this.createEntityRelations(e.relations.map(c=>({...c,sourceKey:e.key,targetKey:c.key}))),g(l[0])):null}catch(t){throw i.error("Error adding entity",t),t}})}async updateEntity(e){return a("catalog_entities.remote_repository.update_entity",async()=>{await this.#t();try{i.info(`Updating entity ${e.key} in remote database`);const t=p({entity:e,organizationId:this.organizationId,projectId:this.projectId,source:"remote",sourceFile:null,fileHash:null}),{key:o,source:d,scorecardsStatus:u,...l}=t,c=await this.databaseClient.client.insert(r).values(t).onConflictDoUpdate({target:[r.key,r.source,r.revision,r.version],set:{...l,scorecardsStatus:f`CASE WHEN ${r.scorecardsStatus} = 'CALCULATING' THEN 'CANCELLED' ELSE 'OUTDATED' END`}}).returning();return c.length?g(c[0]):null}catch(t){return i.error("Error updating entity",t),null}})}async deleteEntity(e){return a("catalog_entities.remote_repository.delete_entity",async()=>{await this.#t();try{return await this.databaseClient.client.delete(r).where(h(r.key,e)),e}catch(t){return i.error("Error deleting entity",t),null}})}async createEntityRelations(e){return a("catalog_entities.remote_repository.create_entity_relations",async()=>(await this.#t(),await E(e,I,async t=>this.createEntityRelation(t))))}async createEntityRelation(e){return a("catalog_entities.remote_repository.create_entity_relation",async()=>{if(await this.#t(),!e)return null;try{const t=C(e,this.organizationId,this.projectId),{sourceKey:o,targetKey:d,sourceVersion:u,targetVersion:l,sourceRevision:c,targetRevision:D,...m}=t,y=await this.databaseClient.client.insert(n).values(t).onConflictDoUpdate({target:[n.sourceKey,n.targetKey,n.sourceVersion,n.targetVersion,n.sourceRevision,n.targetRevision,n.sourceToTargetRelation],set:m}).returning();return y.length?y[0]:null}catch(t){throw i.error("Error creating entity relation",t),t}})}async deleteEntityRelation(e){return a("catalog_entities.remote_repository.delete_entity_relation",async()=>{await this.#t();try{return await this.databaseClient.client.delete(n).where(h(n.id,e)),e}catch(t){return i.error("Error deleting entity relation",t),null}})}async deleteEntitiesRelations(e){return a("catalog_entities.remote_repository.delete_entities_relations",async()=>{await this.#t();try{const t=w(e);return t?(await this.databaseClient.client.delete(n).where(t),!0):!1}catch(t){return i.error("Error deleting entities relations",t),!1}})}#t(){return a("catalog_entities.remote_repository.db_health",async e=>{if(this.databaseClient.dbClient.$client.closed){const t=new Error("The remote database connection is closed!");throw e?.error(t),t}})}}export{s as CatalogEntitiesRemoteRepository};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import y from"node:path";import{removeLeadingSlash as f}from"@redocly/theme/core/utils";import{toKebabCase as m}from"../../../../../../utils/string/to-kebab-case.js";import{promiseMapLimit as g}from"../../../../../utils/async/promise-map-limit.js";import{removeMarkdocTags as w}from"../../../../markdown/markdoc/helpers/remove-markdoc-tags.js";import{BaseApiEntitiesExtractor as E}from"./base.js";const d=15;class D extends E{constructor(t){super("arazzo",t)}mapApiDescriptionToEntity(t,i){const a=f(t.realRelativePath),h=t.document.info.title,r=a.replace(/\.[^.]+$/,""),o=m(r.replace(/[\\/]/g,"-")),n=t.document["x-redocly-catalog-key"],e=typeof n=="string"&&n.trim()?m(n.trim()):o;return{type:this.type,key:e,title:h,summary:t.document.info.description?w(t.document.info.description):null,tags:["arazzo"],metadata:{specType:this.specType,descriptionFile:a},version:i}}async loadApiDescriptions(){return(await this.context.cache.load(".","arazzo-docs")).data}async processApiDescription(t,i,a,h){if(!this.#t(t)){this.context.logger.warn(`Skipping Arazzo description without source descriptions: ${t.realRelativePath}`);return}const r=this.getRbacTeamsForDefinition(t.relativePath),o=this.mapApiDescriptionToEntity(t,a);await this.catalogEntitiesService.createEntityInLocalDatabase({entity:o,sourceFile:t.realRelativePath,fileHash:t.hash,isRootEntity:!0,revision:i,rbacTeams:r}),h.delete(`${o.key}:${a}`),await this.#e(t,o.key,o.version,a,i,h,r);const n=t.document.sourceDescriptions||[];await g(n,d,async e=>{if(!(e.type!=="openapi"||!e.url))try{const c=this.resolveSourceDescriptionUrl(e.url,t.realRelativePath);if(!c){!e.url.startsWith("http://")&&!e.url.startsWith("https://")&&this.context.logger.warn(`Could not resolve URL to local path: ${e.url}`);return}const l=await this.context.cache.load(c,"load-oas");if(!(l.data&&Array.isArray(l.data)&&l.data.length>0)){this.context.logger.warn(`No OpenAPI definition found at path: ${c}`);return}const p=l.data[0],u=m(f(p.realRelativePath).replace(/\.[^.]+$/,"").replace(/[\\/]/g,"-"));await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:o.key,type:"relatesTo",targetKey:u,fileHash:t.hash}),await this.#r(t,e.name,p,o.key,u,o.version,i)}catch(c){this.context.logger.warn(`Failed to create relation to OpenAPI source "${e.url}": ${c instanceof Error?c.message:"Unknown error"}`)}})}#t=t=>!!t?.document?.sourceDescriptions&&t.document.sourceDescriptions.length>0;#e=async(t,i,a,h,r,o,n)=>{try{const e=t.document.components?.inputs,c=e?Object.entries(e):[],l=[];for(const[s,p]of c)l.push(async()=>{const u=await this.#a({schemaName:s,schema:p,description:t,parentKey:i,parentVersion:a,parentRevision:r,rbacTeams:n});o.delete(`${u.entityKey}:${h}`),u.result==="created"&&await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:i,type:"uses",targetKey:u.entityKey,fileHash:t.hash,sourceVersion:a,targetVersion:a,sourceRevision:r,targetRevision:r})});if(l.length===0)return;await g(l,d,s=>s())}catch(e){this.context.logger.warn(`Failed to create data schema entities for Arazzo description: ${e instanceof Error?e.message:"Unknown error"}`)}};#a=async({schemaName:t,schema:i,description:a,parentKey:h,parentVersion:r,parentRevision:o,rbacTeams:n})=>{const e={type:"data-schema",key:`${h}-${m(t)}`,title:t,summary:i.description||i.title||null,tags:["arazzo"],metadata:{specType:this.specType,descriptionFile:a.realRelativePath,schema:"{}"},version:r};return await this.catalogEntitiesService.createEntityInLocalDatabase({entity:e,sourceFile:a.realRelativePath,fileHash:a.hash,revision:o,rbacTeams:n})};#r=async(t,i,a,h,r,o,n)=>{const e=t.document.workflows||[];if(e.length===0)return;const c=new Set;for(const l of e)for(const s of l.steps||[]){if(!s.operationId)continue;const p=s.operationId.startsWith(`${i}.`)?s.operationId.substring(`${i}.`.length):s.operationId;p&&c.add(p)}c.size!==0&&await g(Array.from(c),d,async l=>{try{const s=`${r}-${m(l)}`;await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:h,type:"uses",targetKey:s,fileHash:t.hash,sourceVersion:o,targetVersion:o,sourceRevision:n,targetRevision:n})}catch(s){this.context.logger.warn(`Failed to create relation to operation "${l}": ${s instanceof Error?s.message:"Unknown error"}`)}})};resolveSourceDescriptionUrl(t,i){try{const a=t.trim(),h=a.startsWith("@")?a.slice(1):a,[r]=h.split("#");if(r.startsWith("http://")||r.startsWith("https://"))return null;if(r.startsWith("/"))return f(y.posix.normalize(r));const o=y.posix.dirname(i);return r.startsWith(o+"/")?y.posix.normalize(r):y.posix.normalize(y.posix.join(o,r))}catch{return this.context.logger.warn(`Failed to resolve URL: ${t}`),null}}}export{D as ArazzoEntitiesExtractor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{removeLeadingSlash as
|
|
1
|
+
import{removeLeadingSlash as d}from"@redocly/theme/core/utils";import{toKebabCase as m}from"../../../../../../utils/string/to-kebab-case.js";import{promiseMapLimit as g}from"../../../../../utils/async/promise-map-limit.js";import{promiseMapLimitWithStatus as $}from"../../../../../utils/async/promise-map-limit-with-status.js";import{removeMarkdocTags as R}from"../../../../markdown/markdoc/helpers/remove-markdoc-tags.js";import{BaseApiEntitiesExtractor as E}from"./base.js";import{extractPartsFromComponentsRef as f}from"../../../utils/extract-parts-from-components-ref.js";import{validateEntityRelation as w}from"../../../entities/validate-entity.js";import{extractPartsFromChannelsMessageRef as S}from"../../../utils/extract-parts-from-channels-message-ref.js";const u=15;class L extends E{constructor(e){super("asyncapi",e)}mapApiDescriptionToEntity(e,a){const s=d(e.realRelativePath),r=e.document.info.title,t=s.replace(/\.[^.]+$/,""),n=m(t.replace(/[\\/]/g,"-")),c=e.document["x-redocly-catalog-key"],o=typeof c=="string"&&c.trim()?m(c.trim()):n;return{type:this.type,key:o,title:r,summary:R(e.document.info.description),tags:e.document.info.tags?.map(i=>i.name),metadata:{specType:this.specType,descriptionFile:s},version:a}}async loadApiDescriptions(){return(await this.context.cache.load(".","asyncapi-docs")).data}async processApiDescription(e,a,s,r){const t=this.getRbacTeamsForDefinition(e.relativePath),n=this.mapApiDescriptionToEntity(e,s);await this.catalogEntitiesService.createEntityInLocalDatabase({entity:n,sourceFile:e.realRelativePath,fileHash:e.hash,isRootEntity:!0,revision:a,rbacTeams:t}),r.delete(`${n.key}:${s}`);const c=this.#a(e),[o,i]=await Promise.allSettled([this.#s(e,n.key,n.version,s,a,r,t),this.#r(c,e,n.key,n.version,s,a,r,t)]);o.status!=="fulfilled"&&this.context.logger.error("Schema processing failed:",o.reason),i.status!=="fulfilled"&&this.context.logger.error("Operation processing failed:",i.reason)}#a=e=>{const a=e.documentWithReferences.operations;return a?Object.entries(a).map(([s,r])=>({operationName:s,operation:r})):[]};#s=async(e,a,s,r,t,n,c)=>{const o=e.document.components?.schemas;if(!o)return;const i=Object.entries(o);if(i.length===0)return;const l=await $(i,u,async([h,y])=>{const p=await this.#n({schemaName:h,schema:y,description:e,parentKey:a,parentVersion:s,parentRevision:t,rbacTeams:c});n.delete(`${p.entityKey}:${r}`),p.result==="created"&&await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:a,type:"uses",targetKey:p.entityKey,fileHash:e.hash,sourceVersion:s,targetVersion:s,sourceRevision:t,targetRevision:t})},this.context.logger);l.count.failed>0&&this.context.logger.warn(`Schema processing completed with ${l.count.failed} failures out of ${i.length} schemas for ${e.realRelativePath}`)};#n=async({schemaName:e,schema:a,description:s,parentKey:r,parentVersion:t,parentRevision:n,rbacTeams:c})=>{const o=`${r}-${m(e)}`,i="title"in a?a.title??a.description:null,l=JSON.stringify(a),h={type:"data-schema",key:o,title:e,summary:i,tags:[],metadata:{specType:this.specType,schema:l},version:t};return await this.catalogEntitiesService.createEntityInLocalDatabase({entity:h,sourceFile:s.realRelativePath,fileHash:s.hash,revision:n,rbacTeams:c})};#r=async(e,a,s,r,t,n,c,o)=>{if(!e.length)return;const i=await $(e,u,async({operationName:l,operation:h})=>{const y=await this.#c(h,l,a,s,r,n,o);y&&c.delete(`${y}:${t}`)},this.context.logger);i.count.failed>0&&this.context.logger.warn(`Operation processing completed with ${i.count.failed} failures out of ${e.length} operations for ${a.realRelativePath}`)};#c=async(e,a,s,r,t,n,c)=>{const o=await this.#o(e.messages??[],s,r),i=await this.#i(a,e,o,s,r,t,n,c);return i.result==="created"&&await this.#l({apiOperationKey:i.entityKey,operation:e,descriptionUniqueKey:r,description:s,descriptionVersion:t,parentRevision:n}),i.entityKey??null};#o=async(e,a,s)=>{if(!e||e.length===0)return[];const r=new Set;for(const t of e){let n=null;if("$ref"in t){const c=t.$ref.startsWith("#/channels/")?this.#e(t.$ref,a):t.$ref;if(c){const o=f(c);if(o?.componentName&&o.componentType==="messages"){const i=a.documentWithReferences.components?.messages[o.componentName];i?.payload&&"$ref"in i.payload&&i.payload.$ref&&(n=i.payload.$ref)}}}else t.payload&&"$ref"in t.payload&&t.payload.$ref&&(n=t.payload.$ref);if(n){const c=f(n);c?.componentName&&c.componentType==="schemas"&&r.add(`${s}-${m(c.componentName)}`)}}return Array.from(r)};#i=async(e,a,s,r,t,n,c,o)=>{const i={type:"api-operation",key:`${t}-${m(e)}`,title:a.title||e,summary:a.summary??"",tags:a.tags?.map(h=>h.name)??[],metadata:{method:a.action==="send"?"PUBLISH":"SUBSCRIBE",path:a.channel.address??"",payload:a.action==="receive"?s:[],responses:a.action==="send"?s:[]},version:n};return await this.catalogEntitiesService.createEntityInLocalDatabase({entity:i,sourceFile:r.realRelativePath,fileHash:r.hash,revision:c,rbacTeams:o})};#l=async({apiOperationKey:e,operation:a,descriptionUniqueKey:s,description:r,descriptionVersion:t,parentRevision:n})=>(await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:e,type:"partOf",targetKey:s,fileHash:r.hash,sourceVersion:t,targetVersion:t,sourceRevision:n,targetRevision:n}),await this.#h(a,e,t,n),!Array.isArray(a.messages)||!a.messages?.length?[]:await this.#m(a.messages,e,r,s,t,n));#h=async(e,a,s,r)=>{e["x-catalog-relations"]?.length&&await g(e["x-catalog-relations"],u,async t=>{try{w(t),await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:a,type:t.type,targetKey:t.key,sourceVersion:s,targetVersion:"",sourceRevision:r,targetRevision:""})}catch(n){this.context.logger.warn(`Error creating entity relation for operation ${a} based on custom property: ${n instanceof Error?n.message:"Unknown error"}`)}})};#m=async(e,a,s,r,t,n)=>e.length===0?[]:(await g(e,u,async o=>await this.#y(o,a,s,r,t,n)??"")).filter(o=>!!o);#y=async(e,a,s,r,t,n)=>"$ref"in e?this.#f(e,a,s,r,t,n):e.payload?this.#u(e,a,s,r,t,n):null;#f=async(e,a,s,r,t,n)=>{const c=e.$ref.startsWith("#/channels/")?this.#e(e.$ref,s):e.$ref;if(!c)return null;const o=f(c);if(!o||!o.componentName||o.componentType!=="messages")return null;const i=s.documentWithReferences.components?.messages[o.componentName];return!i?.payload||!("$ref"in i.payload)||!i.payload.$ref?null:this.#t(i.payload.$ref,a,s,r,t,n)};#e=(e,a)=>{const s=S(e);if(!s||!s.channelName||!s.messageName)return null;const r=a.documentWithReferences.channels?.[s.channelName];if(!r?.messages)return null;const t=r.messages[s.messageName];return!t||!("$ref"in t)||typeof t.$ref!="string"||!t.$ref.startsWith("#/components/messages/")?null:t.$ref};#u=async(e,a,s,r,t,n)=>!e.payload||!("$ref"in e.payload)||!e.payload.$ref?null:this.#t(e.payload.$ref,a,s,r,t,n);#t=async(e,a,s,r,t,n)=>{const c=f(e);if(!c||!c.componentName||c.componentType!=="schemas")return null;const o=`${r}-${m(c.componentName)}`;return await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:a,type:"uses",targetKey:o,fileHash:s.hash,sourceVersion:t,targetVersion:t,sourceRevision:n,targetRevision:n}),o}}export{L as AsyncApiEntitiesExtractor};
|
package/dist/server/plugins/catalog-entities/extensions/extractors/api-description/base.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FileInfo, LifecycleContext
|
|
1
|
+
import type { AfterRoutesCreatedActions, FileInfo, LifecycleContext } from '../../../../../types';
|
|
2
2
|
import type { CatalogEntitiesService } from '../../../database/catalog-entities-service.js';
|
|
3
3
|
import type { EntityFileSchema } from '@redocly/config';
|
|
4
4
|
import type { BaseEntitiesExtractor } from '../base';
|
|
@@ -10,15 +10,16 @@ export declare abstract class BaseApiEntitiesExtractor<BundledApiDefinition exte
|
|
|
10
10
|
protected type: "api-description";
|
|
11
11
|
protected specType: SpecType;
|
|
12
12
|
protected fileType: FileType;
|
|
13
|
-
protected actions:
|
|
13
|
+
protected actions: AfterRoutesCreatedActions;
|
|
14
14
|
protected context: LifecycleContext;
|
|
15
15
|
protected catalogEntitiesService: CatalogEntitiesService;
|
|
16
16
|
protected fileHashManager: HashManager;
|
|
17
17
|
protected entitySources: Record<string, string>;
|
|
18
18
|
constructor(specType: SpecType, params: BaseApiEntitiesExtractorParams);
|
|
19
19
|
extract(): Promise<void>;
|
|
20
|
+
protected getRbacTeamsForDefinition(relativePath: string): string[];
|
|
20
21
|
protected abstract loadApiDescriptions(): Promise<BundledApiDefinition[]>;
|
|
21
|
-
protected abstract mapApiDescriptionToEntity(definition: BundledApiDefinition, version: string): EntityFileSchema;
|
|
22
|
+
protected abstract mapApiDescriptionToEntity(definition: BundledApiDefinition, version: string, rbacTeams: string[]): EntityFileSchema;
|
|
22
23
|
protected abstract processApiDescription(definition: BundledApiDefinition, revision: string, version: string, entitiesToRemoveFromFile: Set<string>): Promise<void>;
|
|
23
24
|
}
|
|
24
25
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FileHashStatus as c}from"../../../../../persistence/file-hashes/types.js";import{promiseMapLimit as
|
|
1
|
+
import{FileHashStatus as c}from"../../../../../persistence/file-hashes/types.js";import{promiseMapLimit as E}from"../../../../../utils/async/promise-map-limit.js";import{OPERATORS as u}from"../../../../../providers/database/pagination/constants.js";import{VERSION_NOT_SPECIFIED as f}from"@redocly/theme/core/constants";import{getRbacTeamsListForResource as g}from"../../../../../utils/rbac.js";import{resolveEntityVersion as v}from"../../../utils/resolve-entity-version.js";import{catalogDataCollector as h}from"../../../utils/catalog-data-collector.js";const y=3;class _{type="api-description";specType;fileType;actions;context;catalogEntitiesService;fileHashManager;entitySources={};#e;constructor(t,e){this.specType=t,this.fileType=e.fileType,this.actions=e.actions,this.context=e.context,this.catalogEntitiesService=e.catalogEntitiesService,this.fileHashManager=e.fileHashManager,this.#e=e.shouldCalculateEntities??!1}async extract(){const t=await this.loadApiDescriptions();await this.fileHashManager.markAllAsOutdated(this.fileType),t.length&&h.addExtractor(this.specType),await E(t,y,async e=>{try{if(e.isVirtual||!e.hash)return;if(!((await this.fileHashManager.getByPath(e.realRelativePath))?.hash!==e.hash||this.#e||process.env.FORCE_CATALOG_CACHE_REVALIDATE==="true")){h.increaseSkippedFilesCount(),await this.fileHashManager.upsert(this.fileType,e.realRelativePath,e.hash,c.UP_TO_DATE);return}const a=await this.catalogEntitiesService.getEntityKeysAndVersionsBySourceFile(e.realRelativePath);process.env.FORCE_CATALOG_CACHE_REVALIDATE==="true"&&(await this.catalogEntitiesService.deleteEntitiesInLocalDatabase({field:"key",operator:"in",value:Array.from(a).map(s=>s.split(":")[0])}),a.clear());const o=new Date().toISOString(),n=this.#a(e);await this.processApiDescription(e,o,n,a),await this.#i(a,e.realRelativePath,o,e.hash),h.increaseProcessedFilesCount(),await this.fileHashManager.upsert(this.fileType,e.realRelativePath,e.hash,c.UP_TO_DATE)}catch(i){this.context.logger.warn(`Error extracting entities from ${this.specType} description: ${e.realRelativePath}`),this.context.logger.warn(i)}}),await this.#t()}#t=async()=>{const t=await this.fileHashManager.getAllOutdated(this.fileType);if(!t||t.length===0)return;const e=await this.catalogEntitiesService.getEntities({limit:1e3,filter:{op:"AND",conditions:[{field:"source_file",operator:"in",value:t.map(({filePath:i})=>i)},{field:"is_current",operator:"equal",value:!0}]}});e&&e.items.length>0&&await this.catalogEntitiesService.deleteEntitiesInLocalDatabase({field:"key",operator:"in",value:e.items.map(({key:i})=>i)}),await this.fileHashManager.deleteFileHashes({op:"AND",conditions:[{field:"file_type",operator:"equal",value:this.fileType},{field:"status",operator:"equal",value:c.OUTDATED}]})};#i=async(t,e,i,r)=>{if(t.size===0||process.env.FORCE_CATALOG_CACHE_REVALIDATE==="true")return;const a=Array.from(t).map(s=>{const[l,p]=s.split(":");return{key:l,version:p}}),o=Array.from(new Set(a.map(({key:s})=>s))),n=a.map(({key:s,version:l})=>({op:u.AND,conditions:[{field:"key",operator:"equal",value:s},{field:"version",operator:"equal",value:l}]}));await this.catalogEntitiesService.softDeleteEntitiesInLocalDatabase({revision:i,fileHash:r,filter:{op:"AND",conditions:[{field:"key",operator:"in",value:o},{op:u.OR,conditions:n},{field:"source",operator:"equal",value:"file"},{field:"source_file",operator:"equal",value:e}]}})};#a(t){const e=t.document?.info?.version??t.definition?.info?.version??null,i=v(e,t.realRelativePath);return i.success?i.version??f:f}getRbacTeamsForDefinition(t){const e=this.actions.getConfig().rbac,i=this.actions.getRouteByFsPath(t);return g(i||{fsPath:t},e||{})}}export{_ as BaseApiEntitiesExtractor};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{buildSchema as
|
|
1
|
+
import{buildSchema as O,isObjectType as T,isScalarType as D,isEnumType as v,isInterfaceType as w,isUnionType as E,isInputObjectType as b,getNamedType as u,printType as L}from"graphql";import{removeLeadingSlash as A}from"@redocly/theme/core/utils";import{toKebabCase as g}from"../../../../../../utils/string/to-kebab-case.js";import{capitalize as j}from"../../../../../../utils/string/capitalize.js";import{promiseMapLimit as d}from"../../../../../utils/async/promise-map-limit.js";import{promiseMapLimitWithStatus as $}from"../../../../../utils/async/promise-map-limit-with-status.js";import{sha1 as K}from"../../../../../utils/crypto/sha1.js";import{removeMarkdocTags as F}from"../../../../markdown/markdoc/helpers/remove-markdoc-tags.js";import{BaseApiEntitiesExtractor as N}from"./base.js";const R=15,I=15,P=new Set(["String","ID","Int","Float","Boolean","DateTime","Date","Time","URL","URI","JSON","JSONObject","BigInt","BigDecimal"]);class U extends N{#t;constructor(t){super("graphql",t),this.#t=t.context.logger}async loadApiDescriptions(){const t=[];for(const{relativePath:e}of this.context.fs.scan(/(\.gql|\.graphql)$/))try{if(e.includes("@l10n")||await this.context.isPathIgnored(e))continue;const a=await this.context.cache.load(e,"graphql-doc");if(!a.data)continue;const{content:i,metadata:r}=a.data,s=O(i),n=K(i);t.push({realRelativePath:e,relativePath:e,isVirtual:!1,hash:n,schema:s,content:i,metadata:r})}catch(a){this.#t.warn(`Failed to load GraphQL schema from ${e}: ${a instanceof Error?a.message:"Unknown error"}`)}return t}mapApiDescriptionToEntity(t,e){const a=A(t.realRelativePath),i=t.relativePath.replace(/\.(gql|graphql)$/,""),r=this.#s(i.split("/").pop()||"GraphQL Schema"),s=a.replace(/\.(gql|graphql)$/,""),n=g(s.replace(/[\\/]/g,"-")),p=this.#c(t.metadata?.tags),o=t.metadata?.["x-redocly-catalog-key"],l=typeof o=="string"&&o.trim()?g(o.trim()):n;return{type:this.type,key:l,title:r,summary:t.metadata?.description||null,tags:p.concat("graphql"),metadata:{specType:this.specType,descriptionFile:a},version:e}}async processApiDescription(t,e,a,i){const{schema:r}=t;if(!r)return;const s=this.getRbacTeamsForDefinition(t.relativePath),n=this.mapApiDescriptionToEntity(t,a);await this.catalogEntitiesService.createEntityInLocalDatabase({entity:n,sourceFile:t.realRelativePath,fileHash:t.hash,isRootEntity:!0,revision:e,rbacTeams:s}),i.delete(`${n.key}:${a}`),await Promise.all([this.#a(t,n.key,n.version,a,e,i,s),this.#y(t,n.key,n.version,a,e,i,s)])}#a=async(t,e,a,i,r,s,n)=>{const{schema:p}=t,o=p.getTypeMap(),l=this.#i(p),c=Object.entries(o).filter(([y])=>!y.startsWith("__")&&!P.has(y)&&!l.has(y));if(c.length===0)return;const h=await $(c,I,async([y,m])=>{const f=await this.#l({typeName:y,type:m,description:t,parentKey:e,parentVersion:a,parentRevision:r,rbacTeams:n});s.delete(`${f.entityKey}:${i}`),f.result==="created"&&await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:e,type:"uses",targetKey:f.entityKey,fileHash:t.hash,sourceVersion:a,targetVersion:a,sourceRevision:r,targetRevision:r})},this.#t);h.count.failed>0&&this.#t.warn(`Schema processing completed with ${h.count.failed} failures out of ${c.length} types for ${t.realRelativePath}`),await this.#h({description:t,descriptionUniqueKey:e,userTypes:c,parentRevision:r})};#s=t=>{const e=t.replace(/[^A-Za-z0-9]+/g," ").trim();return e?e.split(" ").map(a=>a&&j(a)).join(" "):"GraphQL Schema"};#e=(t,e)=>`${e}-${g(t)}`;#n=t=>T(t)?"object":w(t)?"interface":E(t)?"union":v(t)?"enum":b(t)?"input":D(t)?"scalar":"unknown";#i=t=>{const e=new Set,a=t.getQueryType();a&&e.add(a.name);const i=t.getMutationType();i&&e.add(i.name);const r=t.getSubscriptionType();return r&&e.add(r.name),e};#r(t){const e=[],a=t.getQueryType();if(a){const s=a.getFields();for(const[n,p]of Object.entries(s))e.push({fieldName:n,field:p,operationType:"QUERY",rootTypeName:a.name})}const i=t.getMutationType();if(i){const s=i.getFields();for(const[n,p]of Object.entries(s))e.push({fieldName:n,field:p,operationType:"MUTATION",rootTypeName:i.name})}const r=t.getSubscriptionType();if(r){const s=r.getFields();for(const[n,p]of Object.entries(s))e.push({fieldName:n,field:p,operationType:"SUBSCRIBE",rootTypeName:r.name})}return e}#o=(t,e)=>{const a=[];if(t.args)for(const s of t.args){const n=u(s.type);n&&!n.name.startsWith("__")&&a.push(this.#e(n.name,e))}const i=[],r=u(t.type);return r&&!r.name.startsWith("__")&&i.push(this.#e(r.name,e)),{inputTypes:a,returnTypes:i}};#c=t=>{if(Array.isArray(t))return t.map(e=>String(e)).map(e=>e.trim()).filter(e=>e.length>0);if(typeof t=="string"){const e=t.trim();return e?[e]:[]}return[]};#l=async({typeName:t,type:e,description:a,parentKey:i,parentVersion:r,parentRevision:s,rbacTeams:n})=>{const p=this.#e(t,i),o=e.description??null,l=this.#n(e),c={type:"data-schema",key:p,title:t,summary:o,tags:["graphql"],metadata:{specType:this.specType,typeKind:l,sdl:this.#p(e,a.schema)},version:r};return await this.catalogEntitiesService.createEntityInLocalDatabase({entity:c,sourceFile:a.realRelativePath,fileHash:a.hash,revision:s,rbacTeams:n})};#p=(t,e)=>{const a=new Set,i=[],r=new Set(["String","ID","Int","Float","Boolean"]),s=o=>{if(!o)return;const l=o.name;if(l.startsWith("__")||r.has(l)||a.has(l))return;const c=e.getType(l);c&&(a.add(l),i.push(c))};for(s(t);i.length>0;){const o=i.pop();if(T(o)){for(const c of o.getInterfaces?.()??[])s(c);const l=o.getFields();for(const c of Object.values(l)){s(u(c.type));for(const h of c.args??[])s(u(h.type))}}else if(w(o)){const l=o.getFields();for(const c of Object.values(l))s(u(c.type))}else if(E(o))for(const l of o.getTypes())s(l);else if(b(o)){const l=o.getFields();for(const c of Object.values(l))s(u(c.type))}}const n=[t.name,...[...a].filter(o=>o!==t.name)],p=[];for(const o of n){const l=e.getType(o);l&&p.push(L(l))}return p.join(`
|
|
2
2
|
|
|
3
|
-
`)};#h=async({description:t,descriptionUniqueKey:e,userTypes:a,parentRevision:
|
|
3
|
+
`)};#h=async({description:t,descriptionUniqueKey:e,userTypes:a,parentRevision:i})=>{const r=a.filter(([,s])=>T(s));r.length!==0&&await d(r,I,async([s,n])=>{const o=n.getInterfaces?.()??[];if(!o.length)return;const l=this.#e(s,e);await d([...o],5,async c=>{const h=this.#e(c.name,e);try{await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:l,type:"implements",targetKey:h,fileHash:t.hash,sourceRevision:i,targetRevision:i})}catch(y){this.#t.warn(`Failed to create 'implements' relation ${l} -> ${h}: ${y instanceof Error?y.message:"Unknown error"}`)}})})};#y=async(t,e,a,i,r,s,n)=>{const{schema:p}=t,o=this.#r(p);if(o.length===0)return;const c=(await $(o,R,async({fieldName:h,field:y,operationType:m,rootTypeName:f})=>{const S=await this.#f(h,y,m,f,t,e,a,r,n);S&&s.delete(`${S}:${i}`)},this.#t)).count.failed;c>0&&this.#t.warn(`Operation extraction completed with ${c} failures out of ${o.length} operations for ${e}`)};#f=async(t,e,a,i,r,s,n,p,o)=>{const{inputTypes:l,returnTypes:c}=this.#o(e,s),h=await this.#u({fieldName:t,field:e,operationType:a,rootTypeName:i,inputTypes:l,returnTypes:c,description:r,descriptionUniqueKey:s,descriptionVersion:n,parentRevision:p,rbacTeams:o});return h.result==="created"&&await this.#m({apiOperationKey:h.entityKey,inputTypes:l,returnTypes:c,descriptionUniqueKey:s,description:r,descriptionVersion:n,parentRevision:p}),h.entityKey??null};#u=async({fieldName:t,field:e,operationType:a,rootTypeName:i,inputTypes:r,returnTypes:s,description:n,descriptionUniqueKey:p,descriptionVersion:o,parentRevision:l,rbacTeams:c})=>{const h=t,m={type:"api-operation",key:`${p}-${g(`${a.toLowerCase()}-${t}`)}`,title:h,summary:e.description?F(e.description):null,tags:["graphql"],metadata:{method:a,path:`${i}.${t}`,payload:r,responses:s},version:o};return await this.catalogEntitiesService.createEntityInLocalDatabase({entity:m,sourceFile:n.realRelativePath,fileHash:n.hash,revision:l,rbacTeams:c})};#m=async({apiOperationKey:t,inputTypes:e,returnTypes:a,descriptionUniqueKey:i,description:r,descriptionVersion:s,parentRevision:n})=>{await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:t,type:"partOf",targetKey:i,fileHash:r.hash,sourceVersion:s,targetVersion:s,sourceRevision:n,targetRevision:n});const p=[...new Set(e)],o=[...new Set(a)],l=[...p.map(c=>({key:c,relationType:"uses"})),...o.map(c=>({key:c,relationType:"returns"}))];await d(l,R,async({key:c,relationType:h})=>{try{await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:t,type:h,targetKey:c,fileHash:r.hash,sourceVersion:s,targetVersion:s,sourceRevision:n,targetRevision:n})}catch(y){this.#t.warn(`Failed to create relation between operation ${t} and type ${c} (${h}): ${y instanceof Error?y.message:"Unknown error"}`)}})}}export{U as GraphqlEntitiesExtractor};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type EntityFileSchema } from '@redocly/config';
|
|
1
2
|
import type { BundledDefinition } from '../../../../openapi-docs/load-definition';
|
|
2
|
-
import type { EntityFileSchema } from '@redocly/config';
|
|
3
3
|
import type { BaseApiEntitiesExtractorParams } from '../../../types/extractors.js';
|
|
4
4
|
import { BaseApiEntitiesExtractor } from './base.js';
|
|
5
5
|
export declare class OpenApiEntitiesExtractor extends BaseApiEntitiesExtractor<BundledDefinition> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{removeLeadingSlash as
|
|
1
|
+
import{REDOCLY_TEAMS_RBAC as g}from"@redocly/config";import{removeLeadingSlash as b}from"@redocly/theme/core/utils";import{toKebabCase as f}from"../../../../../../utils/string/to-kebab-case.js";import{promiseMapLimit as $}from"../../../../../utils/async/promise-map-limit.js";import{promiseMapLimitWithStatus as N}from"../../../../../utils/async/promise-map-limit-with-status.js";import{extractTeamsFromScopeItems as E}from"../../../../../utils/rbac.js";import{removeMarkdocTags as R}from"../../../../markdown/markdoc/helpers/remove-markdoc-tags.js";import{BaseApiEntitiesExtractor as T}from"./base.js";import{OpenapiSchemaResolver as w}from"../../../utils/openapi-schema-resolver.js";import{extractPartsFromComponentsRef as v}from"../../../utils/extract-parts-from-components-ref.js";import{validateEntityRelation as x}from"../../../entities/validate-entity.js";import{isValidTagName as S}from"../../../utils/is-valid-tag-name.js";const A=["get","post","put","delete","patch"],O=15,d=15;class V extends T{#e;constructor(e){super("openapi",e),this.#e=e.context.logger}async loadApiDescriptions(){return await this.actions.loadOpenApiDefinitions(this.context)}mapApiDescriptionToEntity(e,o){const s=b(e.realRelativePath),n=e.definition.info.title,t=s.replace(/\.[^.]+$/,""),a=f(t.replace(/[\\/]/g,"-")),r=e.definition["x-redocly-catalog-key"],i=typeof r=="string"&&r.trim()?f(r.trim()):a;return{type:this.type,key:i,title:n,summary:R(e.definition.info.description),tags:e.definition.tags?.filter(c=>c.name&&S(c.name)).map(c=>c.name),metadata:{specType:this.specType,descriptionFile:s},version:o}}async processApiDescription(e,o,s,n){if(w.clearSchemaCache(),!e?.definition?.paths)return;const t=this.getRbacTeamsForDefinition(e.relativePath),a=this.mapApiDescriptionToEntity(e,s);await this.catalogEntitiesService.createEntityInLocalDatabase({entity:a,sourceFile:e.realRelativePath,fileHash:e.hash,isRootEntity:!0,revision:o,rbacTeams:t}),n.delete(`${a.key}:${s}`),await this.#n(e,a.key,a.version,s,o,n,t);const r=this.#s(e.definition.paths);if(r.length!==0){const c=(await N(r,O,async({operation:h,path:m,method:l})=>{if(!h.operationId)return;const y=await this.#r(h,m,l,e,a.key,a.version,o,t);y&&n.delete(`${y}:${s}`)},this.#e)).count.failed;c>0&&this.#e.warn(`Extraction completed with ${c} failures out of ${r.length} operations for ${a.key}`)}}#s(e){return Object.entries(e).flatMap(([o,s])=>A.filter(n=>s[n]).map(n=>{const t=s[n];if(!t)throw new Error(`Operation not found for method ${n} on path ${o}`);return{operation:t,path:o,method:n.toUpperCase()}}))}async#n(e,o,s,n,t,a,r){const i=e.definition.components?.schemas;if(!i)return;const c=Object.entries(i);c.length!==0&&await $(c,d,async([h,m])=>{const l=await this.#o({schemaName:h,schema:m,description:e,parentKey:o,parentVersion:s,parentRevision:t,rbacTeams:r});a.delete(`${l.entityKey}:${n}`),l.result==="created"&&await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:o,sourceVersion:s,sourceRevision:t,type:"uses",targetKey:l.entityKey,targetVersion:s,targetRevision:t,fileHash:e.hash})})}async#o({schemaName:e,schema:o,description:s,parentKey:n,parentVersion:t,parentRevision:a,rbacTeams:r}){const i=w.resolveSchemaRefs(o,s),c=JSON.stringify(i),h=i[g]?E(i[g]):r,m={type:"data-schema",key:`${n}-${f(e)}`,title:e,summary:i.description??i.title??null,tags:[],metadata:{specType:this.specType,schema:c},version:t};return await this.catalogEntitiesService.createEntityInLocalDatabase({entity:m,sourceFile:s.realRelativePath,fileHash:s.hash,revision:a,rbacTeams:h})}async#r(e,o,s,n,t,a,r,i){const c=await Promise.all([this.#m(e.requestBody??null,n),this.#h(e.responses??{},n)]),h=c[0].schemaNames,m=c[1].schemaNames;c[0].errors.length>0&&this.#e.warn(`Schema extraction errors for operation ${e.operationId}: ${c[0].errors.join(", ")}`),c[1].errors.length>0&&this.#e.warn(`Response schema extraction errors for operation ${e.operationId}: ${c[1].errors.join(", ")}`);const l=h.map(p=>`${t}-${f(p)}`),y=m.map(p=>`${t}-${f(p)}`),u=await this.#p({path:o,method:s,operation:e,requestBodySchemasKeys:l,responseSchemasKeys:y,description:n,parentKey:t,parentVersion:a,parentRevision:r,rbacTeams:i});return u.result==="created"&&await Promise.all([this.#i(h,e.operationId??"",n.hash,t,a,r),this.#c(m,e.operationId??"",n.hash,t,a,r),this.#f({apiOperationKey:u.entityKey,operationRelations:e["x-catalog-relations"],descriptionUniqueKey:t,description:n,parentVersion:a,parentRevision:r})]),u.entityKey??null}async#i(e,o,s,n,t,a){return e.length===0||!o?[]:await this.#a(e,o,s,n,t,a)}async#c(e,o,s,n,t,a){return e.length===0||!o?[]:await this.#a(e,o,s,n,t,a)}#m(e,o){const s=[],n=[];try{if(e&&"content"in e&&e.content)for(const t of Object.values(e.content)){if(!t.schema?.$ref)continue;const a=this.#t(t.schema.$ref);a?.componentType==="schemas"&&a.componentName&&s.push(a.componentName)}if(e&&e.$ref){const t=this.#t(e.$ref);if(t?.componentType==="requestBodies"&&t.componentName){const a=o.definition.components?.requestBodies?.[t.componentName];if(a&&"content"in a)for(const r of Object.values(a.content??{})){if(!r.schema?.$ref)continue;const i=this.#t(r.schema.$ref);i?.componentType==="schemas"&&i.componentName&&s.push(i.componentName)}}}}catch(t){n.push(`Failed to extract request body schemas: ${t instanceof Error?t.message:"Unknown error"}`)}return{schemaNames:[...new Set(s)],errors:n}}#h(e,o){const s=[],n=[];try{for(const t of Object.values(e)){if(t&&"content"in t&&t.content)for(const a of Object.values(t.content)){if(!a.schema?.$ref)continue;const r=this.#t(a.schema.$ref);r?.componentType==="schemas"&&r.componentName&&s.push(r.componentName)}if(t&&t.$ref){const a=this.#t(t.$ref);if(a?.componentType==="responses"&&a.componentName){const r=o.definition.components?.responses?.[a.componentName];if(r&&"content"in r)for(const i of Object.values(r.content??{})){if(!i.schema?.$ref)continue;const c=this.#t(i.schema.$ref);c?.componentType==="schemas"&&c.componentName&&s.push(c.componentName)}}}}}catch(t){n.push(`Failed to extract response schemas: ${t instanceof Error?t.message:"Unknown error"}`)}return{schemaNames:[...new Set(s)],errors:n}}#t(e){try{return v(e)}catch{return{componentType:"",componentName:null}}}async#a(e,o,s,n,t,a){return e.length===0?[]:await $(e,d,async r=>await this.#l({operationId:o,schemaName:r,descriptionHash:s,parentKey:n,parentVersion:t,parentRevision:a}))}async#l({operationId:e,schemaName:o,descriptionHash:s,parentKey:n,parentVersion:t,parentRevision:a}){const r=`${n}-${f(o)}`;try{return await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:`${n}-${f(e)}`,type:"uses",targetKey:r,fileHash:s,sourceVersion:t,targetVersion:t,sourceRevision:a,targetRevision:a}),r}catch(i){throw this.#e.error(`Failed to create relation between operation ${e} and schema ${o}: ${i instanceof Error?i.message:"Unknown error"}`),i}}async#p({path:e,method:o,operation:s,requestBodySchemasKeys:n,responseSchemasKeys:t,description:a,parentKey:r,parentVersion:i,parentRevision:c,rbacTeams:h}){const m=`${s.operationId}`,l=`${r}-${f(m)}`,y=s[g]?E(s[g]):h,u={type:"api-operation",key:l,title:m,summary:R(s.summary),tags:s.tags?.filter(p=>S(p)),metadata:{path:e,method:o,payload:n,responses:t},version:i};try{return await this.catalogEntitiesService.createEntityInLocalDatabase({entity:u,sourceFile:a.realRelativePath,fileHash:a.hash,revision:c,rbacTeams:y})}catch(p){throw this.#e.error(`Failed to create API operation entity for ${m}: ${p instanceof Error?p.message:"Unknown error"}`),p}}async#f({apiOperationKey:e,operationRelations:o,descriptionUniqueKey:s,description:n,parentVersion:t,parentRevision:a}){try{await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:e,type:"partOf",targetKey:s,fileHash:n.hash,sourceVersion:t,targetVersion:t,sourceRevision:a,targetRevision:a}),await this.#y(e,o,t,a)}catch(r){this.#e.error(`Failed to create API operation relations for ${e}: ${r instanceof Error?r.message:"Unknown error"}`)}}async#y(e,o,s,n){o?.length&&await $(o,O,async t=>{try{x(t),await this.catalogEntitiesService.createEntityRelationInLocalDatabase({sourceKey:e,type:t.type,targetKey:t.key,sourceVersion:s,targetVersion:"",sourceRevision:n,targetRevision:""})}catch(a){this.context.logger.warn(`Error creating entity relation for operation ${e} based on custom property: ${a instanceof Error?a.message:"Unknown error"}`)}})}}export{V as OpenApiEntitiesExtractor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{sha1 as
|
|
1
|
+
import{sha1 as w}from"../../utils/crypto/sha1.js";import{isValidSanitizedString as F}from"../../utils/validate-and-sanitize-string";import{CatalogEntitiesService as v}from"./database/catalog-entities-service.js";import{createPaginationParamsValidator as E}from"../../providers/database/pagination/schemas";import{parseSearch as A}from"../../providers/database/pagination/search";import{OPERATORS as b}from"../../providers/database/pagination/constants.js";import{CacheService as T}from"../../persistence/cache/services/cache-service.js";import{CATALOG_FILTERS_CACHE_NAMESPACE as S,CATALOG_FILTERS_CACHE_TTL_IN_SECONDS as I}from"../../constants/plugins/catalog-entities.js";import{isValidIsoDate as D}from"../../utils/is-valid-iso-date.js";import{expandTeamsForRead as R}from"../../utils";const Q={all:"all",domains:"domain",services:"service",teams:"team",users:"user","api-descriptions":"api-description","data-schemas":"data-schema"},V={team:{field:"type",operator:"equal",value:"user"},"api-description":{field:"type",operator:"equal",value:"api-operation"}},N=async({entitiesTypes:e,serverOutDir:i,catalogConfig:t,queries:s={},rbacTeams:o})=>{const d=await v.getInstance({baseDbDir:i}),c=x.concat("domains","owners"),l=E(c).parse(s),u=t.excludes?.map(p=>p.key)??[],g=e.filter(p=>p!=="all"),n=q(g,u);return l.filter?l.filter={op:b.AND,conditions:[l.filter,n]}:l.filter=n,await d.getEntitiesWithRelations({sort:[{field:"type",order:"ASC"}],limit:10,...l},o)},P=async(e,i,t,s)=>{const o=await v.getInstance({baseDbDir:i});let d=null;const c=t?.revision;c&&D(c)&&(d=c);const l=t?.version;if(!F(l,{pattern:/^[a-zA-Z0-9._-]+$/,maxLength:100,allowEmpty:!0}))return null;const u=await o.getEntityWithRelationsByKey(e,{revision:d,version:l},s);if(!u)return null;const g=u.type==="data-schema"?await o.getRelatedEntities(e,{limit:1,filter:{field:"type",operator:"equal",value:"api-description"}}).then(f=>f.items?.[0]??null):null,n=V[u.type]??void 0,a=K(n,l,d),p=await o.getRelatedEntities(e,{limit:10,sort:[{field:"title",order:"ASC"}],filter:a,search:t?.search?A(t?.search,["key","type","title","summary"]):void 0});return{status:"success",entity:u,relatedEntity:g,relations:p}},_=e=>{const i=JSON.stringify({entitiesTypes:e.entitiesTypes.sort(),filtersConfig:e.filtersConfig});return w(i)},L=async({serverOutDir:e,entitiesTypes:i,filtersConfig:t})=>{if(!t||t.length===0)return{};const s=_({entitiesTypes:i,filtersConfig:t}),o=await T.getInstance({baseDbDir:e}),d=await o.get({key:s,namespace:S});if(d)return d;const c=await v.getInstance({baseDbDir:e}),l=[],u=new Map;for(const a of t)!a.options||a.options.length===0?l.push(a.property):u.set(a.property,a.options);const g=await c.getCatalogFilters({entitiesTypes:i,emptyFilters:l}),n={};for(const a of t){const p=u.get(a.property);if(!p){const r=g[a.property];n[a.property]=r&&r.length>0?r:[];continue}const y=(await c.getCatalogFilters({entitiesTypes:i,emptyFilters:[a.property]}))[a.property];if(!y){n[a.property]=[];continue}const h=new Map;for(const r of y){const m=r.value.toLowerCase().trim();h.set(m,{originalValue:r.value,count:r.count})}n[a.property]=p.map(r=>{const m=r.toLowerCase().trim(),C=h.get(m);return{value:C?.originalValue??r,count:C?.count??0}}).filter(r=>r.count>0).sort((r,m)=>r.value.localeCompare(m.value))}return await o.set({key:s,value:n,namespace:S,ttlInSeconds:I}),n},O=async(e,{props:i},{variables:t},{serverOutDir:s,getRouteSharedDataByFsPath:o,getConfig:d})=>{const c=i?.catalogConfig||{};if(!e.params||!i?.catalogConfig)return{status:"notFound"};const[l,u,g]=e.params;if(!l)return{status:"notFound"};const n=M(c,l),a=n?.includes?.map(m=>m.type)??[];if(!n)return{status:"notFound"};const p=R(d().rbac||{},t?.rbac.teams||[]);if(!g&&u!=="entities"){if(n.hide)return{status:"notFound"};const m=await L({entitiesTypes:a,serverOutDir:s,filtersConfig:n.filters}),C=e.queries?.viewMode??"table";return{status:"success",catalogSwitcherItems:k(c,n),entitiesTypes:a,entities:await N({entitiesTypes:a,serverOutDir:s,catalogConfig:n,queries:e.queries,rbacTeams:p}),catalogConfig:n,filters:m,initialViewMode:C}}const f=await P(g,s,e.queries,p),y=f?.entity.sourceFile,h=f?.entity.type==="api-description",r=y&&h&&o(y)||{};return f?{status:"success",entity:f.entity,relatedEntity:f.relatedEntity,relations:f.relations,entitiesCatalogConfig:c,catalogConfig:n,sharedDataIds:r}:{status:"notFound"}},M=(e,i)=>Object.values(e.catalogs??{}).find(t=>t&&typeof t=="object"&&"slug"in t&&t.slug===i),k=(e,i)=>Object.values(e.catalogs??{}).filter(t=>!t?.hide).map(t=>({labelTranslationKey:t?.catalogSwitcherLabelTranslationKey??t?.slug??"",slug:t?.slug??"",selected:t?.slug===i.slug})).sort((t,s)=>t.slug.localeCompare(s.slug)),q=(e,i)=>({op:"AND",conditions:[...e.length?[{field:"type",operator:"in",value:e}]:[],...i.length?[{field:"key",operator:"in",value:i,modifier:"not"}]:[]]}),K=(e,i,t)=>{let s=e;if(i!==void 0){const o={field:"version",operator:"equal",value:i};s=s?{op:b.AND,conditions:[s,o]}:o}if(t){const o={field:"revision",operator:"equal",value:t};s=s?{op:b.AND,conditions:[s,o]}:o}return s},x=["type","key","title","summary","tags","metadata","metadata.*","git","contact","links","id","source","sourceFile","createdAt","updatedAt"];var U=O;export{U as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FileType as
|
|
1
|
+
import{FileType as u}from"../../persistence/file-hashes/types.js";import{deepEqual as O}from"../../../utils/object/deep-equal.js";import{telemetryTraceStep as P}from"../../../cli/telemetry/helpers/trace-step.js";import{catalogDataCollector as I}from"./utils/catalog-data-collector.js";import{CATALOG_BASE_SLUG as m,CATALOG_FILTERS_CACHE_NAMESPACE as _,ENTITIES_MAP_GLOBAL_DATA_KEY as b}from"../../constants/plugins/catalog-entities.js";import{CacheService as v}from"../../persistence/cache/services/cache-service.js";import{getTemplatePath as f}from"./utils/get-template-path.js";import{getCompleteCatalogConfig as C}from"./get-complete-catalog-config.js";import{AsyncApiEntitiesExtractor as w}from"./extensions/extractors/api-description/asyncapi-entities-extractor.js";import{GraphqlEntitiesExtractor as N}from"./extensions/extractors/api-description/graphql-entities-extractor.js";import{FileHashesService as R}from"../../persistence/file-hashes/services/file-hashes-service.js";import{CatalogEntitiesService as L}from"./database/catalog-entities-service.js";import{ArazzoEntitiesExtractor as G}from"./extensions/extractors/api-description/arazzo-entities-extractor.js";import{FsEntitiesExtractor as x}from"./extensions/extractors/fs-entities-extractor.js";import{HashManager as F}from"./utils/hash-manager.js";import{OpenApiEntitiesExtractor as H}from"./extensions/extractors/api-description/openapi-entities-extractor.js";const B="catalog-entity-template",M="catalog-entity";let d=!0,A;async function Y(){return{id:"CatalogEntities",requiredEntitlements:["catalog"],async processContent(t,e){const i=await e.getConfig(),r=C(i.entitiesCatalog);if(!r.show)return;const{logger:o}=e,n=t.registerServerPropsGetter(M,f("../get-server-props.js")),p=t.createTemplate(B,f("../template/index.js"));t.addRoute({duplicateInAllLocales:!0,slug:m,fsPath:"",templateId:p,excludeFromSidebar:!0,hasClientRoutes:!0,serverPropsGetterIds:[n],getNavText:()=>Promise.resolve("Catalog"),getStaticData:async()=>({props:{catalogConfig:r}})});const[l]=Object.entries(r.catalogs??{}).find(([E,s])=>!s?.hide)||[];l&&t.addRedirect(m,{type:302,to:`${m}/${l}`}),o.info("Catalog Entities plugin finished")},async afterRoutesCreated(t,e){await P("build.plugin.catalog_entities",async i=>{const r=await e.getConfig(),o=C(r.entitiesCatalog);if(i?.setAttribute("config",JSON.stringify(o)),!o.show)return;const{logger:n}=e,p=process.env.NODE_ENV==="development"||process.env.REDOCLY_LOCAL_DEV==="true",l=d&&p,E=!O(A,r.rbac);A=r.rbac;const s=l&&E,a=await L.getInstance({baseDbDir:t.serverOutDir,removeExisting:l,runOnlyLocalDatabase:!0,runWithPragmaWalWriteOptimization:!0}),T=await R.getInstance({baseDbDir:t.serverOutDir}),c=new F(T),y=[new x({fileHashManager:c,context:e,catalogEntitiesService:a,catalogConfig:o,shouldCalculateEntities:s}),new H({actions:t,context:e,catalogEntitiesService:a,fileHashManager:c,fileType:u.OPENAPI_DESCRIPTION,shouldCalculateEntities:s}),new w({actions:t,context:e,catalogEntitiesService:a,fileHashManager:c,fileType:u.ASYNCAPI_DESCRIPTION,shouldCalculateEntities:s}),new N({actions:t,context:e,catalogEntitiesService:a,fileHashManager:c,fileType:u.GRAPHQL_DESCRIPTION,shouldCalculateEntities:s}),new G({actions:t,context:e,catalogEntitiesService:a,fileHashManager:c,fileType:u.ARAZZO_DESCRIPTION,shouldCalculateEntities:s})];n.info("Starting entities extractors...");const h=n.startTiming();await a.transaction(async()=>{await Promise.all(y.map(async D=>D.extract()))});const S=a.getEntitySources();t.setGlobalData({[b]:S}),await(await v.getInstance({baseDbDir:t.serverOutDir})).deleteByNamespace(_),n.infoTime(h,"Entities extractors finished");const g=await I.getCatalogEntitiesData(a);i?.setAttribute("totalEntities",g.totalEntitiesCount),i?.setAttribute("entitiesCountByType",JSON.stringify(g.countOfEntitiesByType)),i?.setAttribute("totalFilesSkippedByHash",g.totalFilesSkippedByHash),i?.setAttribute("totalProcessedFiles",g.totalProcessedFiles),i?.setAttribute("extractors",g.extractors),d=!1})}}}var rt=Y;export{Y as catalogEntitiesPlugin,rt as default};
|
|
@@ -129,6 +129,9 @@ export declare const entityDatabaseSchema: {
|
|
|
129
129
|
readonly is_deleted: {
|
|
130
130
|
readonly type: readonly ["boolean", "null"];
|
|
131
131
|
};
|
|
132
|
+
readonly rbac_teams: {
|
|
133
|
+
readonly type: readonly ["string", "null"];
|
|
134
|
+
};
|
|
132
135
|
};
|
|
133
136
|
readonly required: readonly ["id", "organization_id", "project_id", "key", "type", "title", "created_at", "updated_at", "source"];
|
|
134
137
|
readonly additionalProperties: false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ENTITY_RELATION_TYPES as t}from"@redocly/config";const i={type:"object",properties:{id:{type:"string"},organization_id:{type:"string"},project_id:{type:"string"},source_key:{type:"string"},source_id:{type:["string","null"]},source_version:{type:["string","null"]},source_revision:{type:["string","null"]},source_to_target_relation:{type:"string"},target_key:{type:"string"},target_id:{type:["string","null"]},target_version:{type:["string","null"]},target_revision:{type:["string","null"]},target_to_source_relation:{type:"string"},source_file:{type:["string","null"]},file_hash:{type:["string","null"]},created_at:{type:"string"},updated_at:{type:"string"}},required:["id","organization_id","project_id","source_key","source_to_target_relation","target_key","target_to_source_relation","created_at","updated_at"],additionalProperties:!1},n={type:"object",properties:{id:{type:"string"},organization_id:{type:"string"},project_id:{type:"string"},key:{type:"string"},type:{type:"string"},title:{type:"string"},summary:{type:["string","null"]},tags:{type:["string","null"]},metadata:{type:["string","null"]},git:{type:["string","null"]},contact:{type:["string","null"]},links:{type:["string","null"]},created_at:{type:"string"},updated_at:{type:"string"},source:{type:"string"},source_file:{type:["string","null"]},file_hash:{type:["string","null"]},version:{type:["string","null"]},revision:{type:["string","null"]},hash:{type:["string","null"]},is_current:{type:["boolean","null"]},is_default_version:{type:["boolean","null"]},is_deleted:{type:["boolean","null"]}},required:["id","organization_id","project_id","key","type","title","created_at","updated_at","source"],additionalProperties:!1},r={type:"object",properties:{id:{type:"string"},key:{type:"string"},title:{type:"string"},type:{type:"string"},summary:{type:["string","null"]},source:{type:"string"},relation_role:{type:["string","null"]},relation_type:{type:["string","null"],enum:t},source_file:{type:["string","null"]},created_at:{type:["string","null"]},updated_at:{type:["string","null"]},metadata:{type:["string","null"]},version:{type:["string","null"]}},required:["id","key","title","type","source"],additionalProperties:!1},s={type:"object",properties:{id:{type:"string",minLength:1},key:{type:"string",minLength:1},title:{type:"string",minLength:1},type:{type:"string",minLength:1},summary:{type:["string","null"]},source:{type:"string",minLength:1},source_file:{type:["string","null"]},created_at:{type:["string","null"]},updated_at:{type:["string","null"]},metadata:{type:["string","object","null"]},version:{type:["string","null"]},revision:{type:["string","null"]},direction:{type:"string",enum:["outgoing","incoming"]},relation_field:{type:"string",minLength:1}},required:["id","key","title","type","source","direction","relation_field"],additionalProperties:!1};export{n as entityDatabaseSchema,i as entityRelationDatabaseSchema,r as relatedEntityDatabaseSchema,s as relatedEntityQueryRowDatabaseSchema};
|
|
1
|
+
import{ENTITY_RELATION_TYPES as t}from"@redocly/config";const i={type:"object",properties:{id:{type:"string"},organization_id:{type:"string"},project_id:{type:"string"},source_key:{type:"string"},source_id:{type:["string","null"]},source_version:{type:["string","null"]},source_revision:{type:["string","null"]},source_to_target_relation:{type:"string"},target_key:{type:"string"},target_id:{type:["string","null"]},target_version:{type:["string","null"]},target_revision:{type:["string","null"]},target_to_source_relation:{type:"string"},source_file:{type:["string","null"]},file_hash:{type:["string","null"]},created_at:{type:"string"},updated_at:{type:"string"}},required:["id","organization_id","project_id","source_key","source_to_target_relation","target_key","target_to_source_relation","created_at","updated_at"],additionalProperties:!1},n={type:"object",properties:{id:{type:"string"},organization_id:{type:"string"},project_id:{type:"string"},key:{type:"string"},type:{type:"string"},title:{type:"string"},summary:{type:["string","null"]},tags:{type:["string","null"]},metadata:{type:["string","null"]},git:{type:["string","null"]},contact:{type:["string","null"]},links:{type:["string","null"]},created_at:{type:"string"},updated_at:{type:"string"},source:{type:"string"},source_file:{type:["string","null"]},file_hash:{type:["string","null"]},version:{type:["string","null"]},revision:{type:["string","null"]},hash:{type:["string","null"]},is_current:{type:["boolean","null"]},is_default_version:{type:["boolean","null"]},is_deleted:{type:["boolean","null"]},rbac_teams:{type:["string","null"]}},required:["id","organization_id","project_id","key","type","title","created_at","updated_at","source"],additionalProperties:!1},r={type:"object",properties:{id:{type:"string"},key:{type:"string"},title:{type:"string"},type:{type:"string"},summary:{type:["string","null"]},source:{type:"string"},relation_role:{type:["string","null"]},relation_type:{type:["string","null"],enum:t},source_file:{type:["string","null"]},created_at:{type:["string","null"]},updated_at:{type:["string","null"]},metadata:{type:["string","null"]},version:{type:["string","null"]}},required:["id","key","title","type","source"],additionalProperties:!1},s={type:"object",properties:{id:{type:"string",minLength:1},key:{type:"string",minLength:1},title:{type:"string",minLength:1},type:{type:"string",minLength:1},summary:{type:["string","null"]},source:{type:"string",minLength:1},source_file:{type:["string","null"]},created_at:{type:["string","null"]},updated_at:{type:["string","null"]},metadata:{type:["string","object","null"]},version:{type:["string","null"]},revision:{type:["string","null"]},direction:{type:"string",enum:["outgoing","incoming"]},relation_field:{type:"string",minLength:1}},required:["id","key","title","type","source","direction","relation_field"],additionalProperties:!1};export{n as entityDatabaseSchema,i as entityRelationDatabaseSchema,r as relatedEntityDatabaseSchema,s as relatedEntityQueryRowDatabaseSchema};
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { type EntityBaseFileSchema } from '@redocly/config';
|
|
2
2
|
import type { FromSchema } from 'json-schema-to-ts';
|
|
3
|
+
export declare const entityAttributesDtoSchema: {
|
|
4
|
+
readonly type: "object";
|
|
5
|
+
readonly properties: {
|
|
6
|
+
readonly rbacTeams: {
|
|
7
|
+
readonly type: "array";
|
|
8
|
+
readonly items: {
|
|
9
|
+
readonly type: "string";
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
3
14
|
export declare const entityRelationDtoSchema: {
|
|
4
15
|
readonly type: "object";
|
|
5
16
|
readonly properties: {
|
|
@@ -90,4 +101,5 @@ export declare const entitiesRelationsDtoSchema: {
|
|
|
90
101
|
export type EntityRelationDtoSchema = FromSchema<typeof entityRelationDtoSchema>;
|
|
91
102
|
export type EntitiesRelationsDtoSchema = FromSchema<typeof entitiesRelationsDtoSchema>;
|
|
92
103
|
export type EntityDtoSchema = EntityBaseFileSchema;
|
|
104
|
+
export type EntityAttributesDtoSchema = FromSchema<typeof entityAttributesDtoSchema>;
|
|
93
105
|
//# sourceMappingURL=dto-schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ENTITY_RELATION_TYPES as e}from"@redocly/config";const t={type:"object",properties:{type:{type:"string",enum:e},sourceKey:{type:"string",minLength:2,maxLength:150},targetKey:{type:"string",minLength:2,maxLength:150},sourceVersion:{type:["string","null"]},sourceRevision:{type:["string","null"]},targetVersion:{type:["string","null"]},targetRevision:{type:["string","null"]},sourceFile:{type:["string","null"]},fileHash:{type:["string","null"]},isDeleted:{type:["boolean","null"]}},required:["type","sourceKey","targetKey"],additionalProperties:!1},i={type:"array",items:t};export{i as entitiesRelationsDtoSchema,t as entityRelationDtoSchema};
|
|
1
|
+
import{ENTITY_RELATION_TYPES as e}from"@redocly/config";const n={type:"object",properties:{rbacTeams:{type:"array",items:{type:"string"}}}},t={type:"object",properties:{type:{type:"string",enum:e},sourceKey:{type:"string",minLength:2,maxLength:150},targetKey:{type:"string",minLength:2,maxLength:150},sourceVersion:{type:["string","null"]},sourceRevision:{type:["string","null"]},targetVersion:{type:["string","null"]},targetRevision:{type:["string","null"]},sourceFile:{type:["string","null"]},fileHash:{type:["string","null"]},isDeleted:{type:["boolean","null"]}},required:["type","sourceKey","targetKey"],additionalProperties:!1},i={type:"array",items:t};export{i as entitiesRelationsDtoSchema,n as entityAttributesDtoSchema,t as entityRelationDtoSchema};
|
|
@@ -177,6 +177,7 @@ export type EntityReadModelSchema = {
|
|
|
177
177
|
object: 'catalogEntity';
|
|
178
178
|
domains?: RelatedEntitySchema[];
|
|
179
179
|
owners?: RelatedEntitySchema[];
|
|
180
|
+
rbacTeams?: string[] | null;
|
|
180
181
|
};
|
|
181
182
|
export type EntityRevisionSummary = Pick<EntityReadModelSchema, 'version' | 'revision' | 'isCurrent' | 'createdAt' | 'updatedAt' | 'isDefaultVersion' | 'isDeleted'>;
|
|
182
183
|
//# sourceMappingURL=read-model-schemas.d.ts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { ApiDescriptionMetadataSchema } from '@redocly/config';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { AfterRoutesCreatedActions } from '../../../types/plugins/common';
|
|
3
|
+
import type { AfterRoutesCreatedLifecycleContext } from '../../../types/plugins/common';
|
|
4
4
|
import type { CatalogEntitiesService } from '../database/catalog-entities-service.js';
|
|
5
5
|
import type { FileType } from '../../../persistence/file-hashes/types.js';
|
|
6
6
|
import type { HashManager } from '../utils/hash-manager.js';
|
|
7
7
|
export type SpecType = Exclude<ApiDescriptionMetadataSchema['specType'], 'jsonschema' | 'avro' | 'zod' | 'protobuf'>;
|
|
8
8
|
export type BaseApiEntitiesExtractorParams = {
|
|
9
|
-
actions:
|
|
10
|
-
context:
|
|
9
|
+
actions: AfterRoutesCreatedActions;
|
|
10
|
+
context: AfterRoutesCreatedLifecycleContext;
|
|
11
11
|
catalogEntitiesService: CatalogEntitiesService;
|
|
12
12
|
fileHashManager: HashManager;
|
|
13
13
|
fileType: FileType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import f from"path";import{combineUrls as
|
|
1
|
+
import f from"path";import{combineUrls as m}from"@redocly/theme/core/utils";import{VERSION_SEPARATOR as p}from"../../../constants/common.js";import{removeTrailingSlash as d}from"../../../../utils/url/remove-trailing-slash.js";import{slash as b}from"../../../../utils/path/slash.js";import{logger as h}from"../../../tools/notifiers/logger.js";import{parsePathVersions as D}from"../../../../utils/path/parse-path-versions.js";import{getDefaultVersionByPath as N}from"./versions-config-loader.js";import{GithubSlugger as E,slug as v}from"../../../utils/index.js";import{parseBaseName as I}from"../../utils.js";const V=new Set([".jpg",".jpeg",".png",".gif",".webp",".svg",".ico",".avif",".mp3",".wav",".ogg",".m4a",".mp4",".avi",".mov",".webm",".pdf",".doc",".docx",".zip",".rar",".gz",".ttf",".woff",".woff2"]),M=async(i,{fs:e,cache:o})=>{const l=h.startTiming(),s=(await o.load("versions-config","versions-config")).data,g=new Map,r=new Map,n=new Set,a=new E;r.set(".","/"),r.set("/","/");const t=e.scan().sort((u,S)=>S.relativePath.localeCompare(u.relativePath));for(const{relativePath:u}of t){if(V.has(f.posix.extname(u)))continue;const{data:S}=await o.load(u,"is-ignored");if(S)continue;const w=b(u).replace(new RegExp("^(@i18n|@l10n)\\/"),""),F=N(u,s);z(w,{defaultVersion:F,fileSlugs:g,dirSlugs:r,allFileSlugsList:n,githubSlugger:a})}return h.verboseTime(l,"Calculated slugs. Number of file paths processed: "+t.length),{fileSlugs:g,dirSlugs:r}};function z(i,e){const o=e.fileSlugs.get(i);if(o)return o;const l=D(i);let s=f.posix.dirname(i);const g=c(s,e)||"",{baseName:r,isIndexFile:n}=I(i),a=e.dirSlugs.has(f.posix.join(s,r));let t;if(!n&&a){const u=v(m(g,r,"/"));e.allFileSlugsList.has(u)||(t=u)}t||(t=L({isIndexFile:n,baseName:r,dirPath:s,fileVersionProps:l,ctx:e})),t=d(t),e.fileSlugs.set(i,t),e.allFileSlugsList.add(t)}function L({isIndexFile:i,baseName:e,dirPath:o,fileVersionProps:l,ctx:s}){const g=s.dirSlugs.get(o),r=c(o,s)||"";if(i&&g)return g;const n=d(v(m(r,e)));if(l&&s.defaultVersion&&l.versionName===s.defaultVersion&&s.allFileSlugsList.has(n)){const a=d(l.versionFolderPath)||"/",t=c(a,s)||"/";return s.githubSlugger.slug(m(t,l.versionName,e))}return n}function c(i,e){if(e.dirSlugs.has(i))return e.dirSlugs.get(i);const o=d(f.posix.normalize(i)).split("/");let l="/",s="";for(const g of o){s=f.posix.join(s,g);const r=T(g,e.defaultVersion);let n=e.dirSlugs.get(s)||e.githubSlugger.slug(m("/",l,r));n.endsWith("/")||(n=n+"/"),e.dirSlugs.set(s,n),l=n}return e.dirSlugs.get(i)}function T(i,e){if(!i.startsWith(p))return i;const o=i.substring(p.length);return o===e?"":o}export{V as IGNORED_EXTS,M as contentSlugsLoader};
|