@@ -4,11 +4,11 @@ import card, { Card, MasterTag, Tag } from '@hcengineering/card'
4
4
import core , {
5
5
Association ,
6
6
Attribute ,
7
- Blob as PlatformBlob ,
8
7
Class ,
9
8
Doc ,
10
9
Enum ,
11
10
generateId ,
11
+ Blob as PlatformBlob ,
12
12
Ref ,
13
13
Relation
14
14
} from '@hcengineering/core'
@@ -62,7 +62,7 @@ export class UnifiedDocProcessor {
62
62
63
63
switch ( yamlConfig ?. class ) {
64
64
case card . class . MasterTag : {
65
- const masterTagId = this . metadataStorage . getIdByFullPath ( yamlPath ) as Ref < MasterTag >
65
+ const masterTagId = this . metadataStorage . getIdByAbsolutePath ( yamlPath ) as Ref < MasterTag >
66
66
const masterTag = await this . createMasterTag ( yamlConfig , masterTagId , parentMasterTagId )
67
67
const masterTagAttrs = await this . createAttributes ( yamlPath , yamlConfig , masterTagId )
68
68
@@ -113,7 +113,7 @@ export class UnifiedDocProcessor {
113
113
if ( fs . existsSync ( yamlPath ) ) {
114
114
const yamlConfig = yaml . load ( fs . readFileSync ( yamlPath , 'utf8' ) ) as Record < string , any >
115
115
if ( yamlConfig ?. class === card . class . MasterTag ) {
116
- masterTagId = this . metadataStorage . getIdByFullPath ( yamlPath ) as Ref < MasterTag >
116
+ masterTagId = this . metadataStorage . getIdByAbsolutePath ( yamlPath ) as Ref < MasterTag >
117
117
this . metadataStorage . getAssociations ( yamlPath ) . forEach ( ( relationMetadata , propName ) => {
118
118
masterTagRelations . set ( propName , relationMetadata )
119
119
} )
@@ -173,7 +173,7 @@ export class UnifiedDocProcessor {
173
173
masterTagAttrs : Map < string , UnifiedDoc < Attribute < MasterTag > > > ,
174
174
parentCardId ?: Ref < Card >
175
175
) : Promise < void > {
176
- const cardWithRelations = await this . createCard ( cardProps , cardPath , masterTagId , masterTagRelations , masterTagAttrs , parentCardId )
176
+ const cardWithRelations = await this . createCardWithRelations ( cardProps , cardPath , masterTagId , masterTagRelations , masterTagAttrs , parentCardId , blobs )
177
177
178
178
if ( cardWithRelations . length > 0 ) {
179
179
const docs = result . docs . get ( cardPath ) ?? [ ]
@@ -183,10 +183,10 @@ export class UnifiedDocProcessor {
183
183
const card = cardWithRelations [ 0 ] as UnifiedDoc < Card >
184
184
await this . applyTags ( card , cardProps , cardPath , result )
185
185
186
- const attachments = cardProps . attachments ?? [ ]
187
- await this . processAttachments ( attachments , cardPath , card , result )
186
+ if ( cardProps . attachments !== undefined ) {
187
+ await this . processAttachments ( cardProps . attachments , cardPath , card , result )
188
+ }
188
189
189
- // Проверяем наличие дочерних карточек
190
190
const cardDir = path . join ( path . dirname ( cardPath ) , path . basename ( cardPath , '.md' ) )
191
191
if ( fs . existsSync ( cardDir ) && fs . statSync ( cardDir ) . isDirectory ( ) ) {
192
192
await this . processCardDirectory ( result , cardDir , masterTagId , masterTagRelations , masterTagAttrs , card . props . _id as Ref < Card > )
@@ -242,7 +242,7 @@ export class UnifiedDocProcessor {
242
242
masterTagId : Ref < MasterTag > ,
243
243
parentTagId ?: Ref < Tag >
244
244
) : Promise < void > {
245
- const tagId = this . metadataStorage . getIdByFullPath ( tagPath ) as Ref < Tag >
245
+ const tagId = this . metadataStorage . getIdByAbsolutePath ( tagPath ) as Ref < Tag >
246
246
const tag = await this . createTag ( tagConfig , tagId , masterTagId , parentTagId )
247
247
248
248
const attributes = await this . createAttributes ( tagPath , tagConfig , tagId )
@@ -338,7 +338,7 @@ export class UnifiedDocProcessor {
338
338
const baseType : Record < string , any > = { }
339
339
baseType . _class = core . class . RefTo
340
340
const refPath = path . resolve ( path . dirname ( currentPath ) , property . refTo )
341
- baseType . to = this . metadataStorage . getIdByFullPath ( refPath )
341
+ baseType . to = this . metadataStorage . getIdByAbsolutePath ( refPath )
342
342
baseType . label = core . string . Ref
343
343
type = property . isArray === true
344
344
? {
@@ -351,7 +351,7 @@ export class UnifiedDocProcessor {
351
351
const baseType : Record < string , any > = { }
352
352
baseType . _class = core . class . EnumOf
353
353
const enumPath = path . resolve ( path . dirname ( currentPath ) , property . enumOf )
354
- baseType . of = this . metadataStorage . getIdByFullPath ( enumPath )
354
+ baseType . of = this . metadataStorage . getIdByAbsolutePath ( enumPath )
355
355
baseType . label = 'core:string:Enum'
356
356
type = property . isArray === true
357
357
? {
@@ -381,7 +381,7 @@ export class UnifiedDocProcessor {
381
381
return type
382
382
}
383
383
384
- private async createCard (
384
+ private async createCardWithRelations (
385
385
cardHeader : Record < string , any > ,
386
386
cardPath : string ,
387
387
masterTagId : Ref < MasterTag > ,
@@ -392,7 +392,7 @@ export class UnifiedDocProcessor {
392
392
const { _class, title, tags : rawTags , ...customProperties } = cardHeader
393
393
const tags = rawTags !== undefined ? ( Array . isArray ( rawTags ) ? rawTags : [ rawTags ] ) : [ ]
394
394
395
- const cardId = this . metadataStorage . getIdByFullPath ( cardPath ) as Ref < Card >
395
+ const cardId = this . metadataStorage . getIdByAbsolutePath ( cardPath ) as Ref < Card >
396
396
const cardProps : Record < string , any > = {
397
397
_id : cardId ,
398
398
space : core . space . Workspace ,
@@ -426,7 +426,7 @@ export class UnifiedDocProcessor {
426
426
for ( const val of values ) {
427
427
if ( attrBaseType . _class === core . class . RefTo ) {
428
428
const refPath = path . resolve ( path . dirname ( cardPath ) , val )
429
- const ref = this . metadataStorage . getIdByFullPath ( refPath ) as Ref < Card >
429
+ const ref = this . metadataStorage . getIdByAbsolutePath ( refPath ) as Ref < Card >
430
430
propValues . push ( ref )
431
431
} else {
432
432
propValues . push ( val )
@@ -439,7 +439,7 @@ export class UnifiedDocProcessor {
439
439
throw new Error ( `Association not found: ${ key } , ${ cardPath } ` ) // todo: keep the error till builder validation
440
440
}
441
441
const otherCardPath = path . resolve ( path . dirname ( cardPath ) , value ) // todo: value can be array of paths
442
- const otherCardId = this . metadataStorage . getIdByFullPath ( otherCardPath ) as Ref < Card >
442
+ const otherCardId = this . metadataStorage . getIdByAbsolutePath ( otherCardPath ) as Ref < Card >
443
443
const relation : UnifiedDoc < Relation > = this . createRelation ( metadata , cardId , otherCardId )
444
444
relations . push ( relation )
445
445
}
@@ -484,11 +484,11 @@ export class UnifiedDocProcessor {
484
484
const mixins : UnifiedMixin < Card , Tag > [ ] = [ ]
485
485
for ( const tagPath of tags ) {
486
486
const cardDir = path . dirname ( cardPath )
487
- const fullTagPath = path . resolve ( cardDir , tagPath )
488
- const tagId = this . metadataStorage . getIdByFullPath ( fullTagPath ) as Ref < Tag >
487
+ const tagAbsPath = path . resolve ( cardDir , tagPath )
488
+ const tagId = this . metadataStorage . getIdByAbsolutePath ( tagAbsPath ) as Ref < Tag >
489
489
490
490
const tagProps : Record < string , any > = { }
491
- this . metadataStorage . getAttributes ( fullTagPath ) . forEach ( ( attr , label ) => {
491
+ this . metadataStorage . getAttributes ( tagAbsPath ) . forEach ( ( attr , label ) => {
492
492
tagProps [ attr . props . name ] = cardHeader [ label ]
493
493
} )
494
494
@@ -519,7 +519,7 @@ export class UnifiedDocProcessor {
519
519
for ( const attachment of attachments ) {
520
520
const attachmentPath = path . resolve ( path . dirname ( cardPath ) , attachment )
521
521
const attachmentName = path . basename ( attachmentPath )
522
- const fileId = this . metadataStorage . getIdByFullPath ( attachmentPath ) as Ref < PlatformBlob >
522
+ const fileId = this . metadataStorage . getIdByAbsolutePath ( attachmentPath ) as Ref < PlatformBlob >
523
523
const type = contentType ( attachmentPath )
524
524
const size = fs . statSync ( attachmentPath ) . size
525
525
@@ -534,7 +534,7 @@ export class UnifiedDocProcessor {
534
534
}
535
535
result . files . set ( attachmentPath , file )
536
536
537
- const attachmentId = this . metadataStorage . getIdByFullPath ( attachmentPath ) as Ref < Attachment >
537
+ const attachmentId = this . metadataStorage . getIdByAbsolutePath ( attachmentPath ) as Ref < Attachment >
538
538
const attachmentDoc : UnifiedDoc < Attachment > = {
539
539
_class : 'attachment:class:Attachment' as Ref < Class < Attachment > > ,
540
540
props : {
@@ -562,7 +562,7 @@ export class UnifiedDocProcessor {
562
562
const { class : _class , typeA, typeB, type, nameA, nameB } = yamlConfig
563
563
564
564
const currentPath = path . dirname ( yamlPath )
565
- const associationId = this . metadataStorage . getIdByFullPath ( yamlPath ) as Ref < Association >
565
+ const associationId = this . metadataStorage . getIdByAbsolutePath ( yamlPath ) as Ref < Association >
566
566
567
567
const typeAPath = path . resolve ( currentPath , typeA )
568
568
this . metadataStorage . addAssociation ( typeAPath , nameB , {
@@ -578,8 +578,8 @@ export class UnifiedDocProcessor {
578
578
type
579
579
} )
580
580
581
- const typeAId = this . metadataStorage . getIdByFullPath ( typeAPath ) as Ref < MasterTag >
582
- const typeBId = this . metadataStorage . getIdByFullPath ( typeBPath ) as Ref < MasterTag >
581
+ const typeAId = this . metadataStorage . getIdByAbsolutePath ( typeAPath ) as Ref < MasterTag >
582
+ const typeBId = this . metadataStorage . getIdByAbsolutePath ( typeBPath ) as Ref < MasterTag >
583
583
584
584
return {
585
585
_class,
@@ -600,7 +600,7 @@ export class UnifiedDocProcessor {
600
600
yamlConfig : Record < string , any >
601
601
) : Promise < UnifiedDoc < Enum > > {
602
602
const { title, values } = yamlConfig
603
- const enumId = this . metadataStorage . getIdByFullPath ( yamlPath ) as Ref < Enum >
603
+ const enumId = this . metadataStorage . getIdByAbsolutePath ( yamlPath ) as Ref < Enum >
604
604
return {
605
605
_class : core . class . Enum ,
606
606
props : {
0 commit comments