Skip to content

Commit 4558068

Browse files
committed
renamings
Signed-off-by: Anna Khismatullina <[email protected]>
1 parent 07b3a7d commit 4558068

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

packages/importer/src/huly/metadata.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Association, Attribute, Doc, generateId, Ref } from '@hcengineering/cor
33
import path from 'path'
44
import { UnifiedDoc } from '../types'
55

6-
export interface RelationMetadata {
6+
export interface RelationMetadata { // todo: rename
77
association: Ref<Association>
88
field: 'docA' | 'docB'
99
type: '1:1' | '1:N' | 'N:N'
@@ -20,7 +20,7 @@ export class MetadataStorage {
2020
private readonly pathToRef = new Map<string, Ref<Doc>>() // todo: attachments to a separate map?
2121
private readonly pathToMetadata = new Map<string, TagMetadata>()
2222

23-
public getIdByFullPath (path: string): Ref<Doc> {
23+
public getIdByAbsolutePath (path: string): Ref<Doc> {
2424
let id = this.pathToRef.get(path)
2525
if (id === undefined) {
2626
id = generateId()
@@ -31,7 +31,7 @@ export class MetadataStorage {
3131

3232
public getIdByRelativePath (currentPath: string, relativePath: string): Ref<Doc> {
3333
const fullPath = path.resolve(currentPath, relativePath)
34-
return this.getIdByFullPath(fullPath)
34+
return this.getIdByAbsolutePath(fullPath)
3535
}
3636

3737
public hasMetadata (path: string): boolean {
@@ -48,7 +48,7 @@ export class MetadataStorage {
4848

4949
public setAttributes (path: string, attributes: MapAttributeToUnifiedDoc): void {
5050
const metadata = this.pathToMetadata.get(path) ?? {
51-
_id: this.getIdByFullPath(path),
51+
_id: this.getIdByAbsolutePath(path),
5252
attributes: new Map(),
5353
associations: new Map()
5454
}
@@ -58,7 +58,7 @@ export class MetadataStorage {
5858

5959
public addAssociation (tagPath: string, propName: string, relationMetadata: RelationMetadata): void {
6060
const metadata = this.pathToMetadata.get(tagPath) ?? {
61-
_id: this.getIdByFullPath(tagPath),
61+
_id: this.getIdByAbsolutePath(tagPath),
6262
attributes: new Map(),
6363
associations: new Map()
6464
}

packages/importer/src/huly/unified.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import card, { Card, MasterTag, Tag } from '@hcengineering/card'
44
import core, {
55
Association,
66
Attribute,
7-
Blob as PlatformBlob,
87
Class,
98
Doc,
109
Enum,
1110
generateId,
11+
Blob as PlatformBlob,
1212
Ref,
1313
Relation
1414
} from '@hcengineering/core'
@@ -62,7 +62,7 @@ export class UnifiedDocProcessor {
6262

6363
switch (yamlConfig?.class) {
6464
case card.class.MasterTag: {
65-
const masterTagId = this.metadataStorage.getIdByFullPath(yamlPath) as Ref<MasterTag>
65+
const masterTagId = this.metadataStorage.getIdByAbsolutePath(yamlPath) as Ref<MasterTag>
6666
const masterTag = await this.createMasterTag(yamlConfig, masterTagId, parentMasterTagId)
6767
const masterTagAttrs = await this.createAttributes(yamlPath, yamlConfig, masterTagId)
6868

@@ -113,7 +113,7 @@ export class UnifiedDocProcessor {
113113
if (fs.existsSync(yamlPath)) {
114114
const yamlConfig = yaml.load(fs.readFileSync(yamlPath, 'utf8')) as Record<string, any>
115115
if (yamlConfig?.class === card.class.MasterTag) {
116-
masterTagId = this.metadataStorage.getIdByFullPath(yamlPath) as Ref<MasterTag>
116+
masterTagId = this.metadataStorage.getIdByAbsolutePath(yamlPath) as Ref<MasterTag>
117117
this.metadataStorage.getAssociations(yamlPath).forEach((relationMetadata, propName) => {
118118
masterTagRelations.set(propName, relationMetadata)
119119
})
@@ -173,7 +173,7 @@ export class UnifiedDocProcessor {
173173
masterTagAttrs: Map<string, UnifiedDoc<Attribute<MasterTag>>>,
174174
parentCardId?: Ref<Card>
175175
): 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)
177177

178178
if (cardWithRelations.length > 0) {
179179
const docs = result.docs.get(cardPath) ?? []
@@ -183,10 +183,10 @@ export class UnifiedDocProcessor {
183183
const card = cardWithRelations[0] as UnifiedDoc<Card>
184184
await this.applyTags(card, cardProps, cardPath, result)
185185

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+
}
188189

189-
// Проверяем наличие дочерних карточек
190190
const cardDir = path.join(path.dirname(cardPath), path.basename(cardPath, '.md'))
191191
if (fs.existsSync(cardDir) && fs.statSync(cardDir).isDirectory()) {
192192
await this.processCardDirectory(result, cardDir, masterTagId, masterTagRelations, masterTagAttrs, card.props._id as Ref<Card>)
@@ -242,7 +242,7 @@ export class UnifiedDocProcessor {
242242
masterTagId: Ref<MasterTag>,
243243
parentTagId?: Ref<Tag>
244244
): Promise<void> {
245-
const tagId = this.metadataStorage.getIdByFullPath(tagPath) as Ref<Tag>
245+
const tagId = this.metadataStorage.getIdByAbsolutePath(tagPath) as Ref<Tag>
246246
const tag = await this.createTag(tagConfig, tagId, masterTagId, parentTagId)
247247

248248
const attributes = await this.createAttributes(tagPath, tagConfig, tagId)
@@ -338,7 +338,7 @@ export class UnifiedDocProcessor {
338338
const baseType: Record<string, any> = {}
339339
baseType._class = core.class.RefTo
340340
const refPath = path.resolve(path.dirname(currentPath), property.refTo)
341-
baseType.to = this.metadataStorage.getIdByFullPath(refPath)
341+
baseType.to = this.metadataStorage.getIdByAbsolutePath(refPath)
342342
baseType.label = core.string.Ref
343343
type = property.isArray === true
344344
? {
@@ -351,7 +351,7 @@ export class UnifiedDocProcessor {
351351
const baseType: Record<string, any> = {}
352352
baseType._class = core.class.EnumOf
353353
const enumPath = path.resolve(path.dirname(currentPath), property.enumOf)
354-
baseType.of = this.metadataStorage.getIdByFullPath(enumPath)
354+
baseType.of = this.metadataStorage.getIdByAbsolutePath(enumPath)
355355
baseType.label = 'core:string:Enum'
356356
type = property.isArray === true
357357
? {
@@ -381,7 +381,7 @@ export class UnifiedDocProcessor {
381381
return type
382382
}
383383

384-
private async createCard (
384+
private async createCardWithRelations (
385385
cardHeader: Record<string, any>,
386386
cardPath: string,
387387
masterTagId: Ref<MasterTag>,
@@ -392,7 +392,7 @@ export class UnifiedDocProcessor {
392392
const { _class, title, tags: rawTags, ...customProperties } = cardHeader
393393
const tags = rawTags !== undefined ? (Array.isArray(rawTags) ? rawTags : [rawTags]) : []
394394

395-
const cardId = this.metadataStorage.getIdByFullPath(cardPath) as Ref<Card>
395+
const cardId = this.metadataStorage.getIdByAbsolutePath(cardPath) as Ref<Card>
396396
const cardProps: Record<string, any> = {
397397
_id: cardId,
398398
space: core.space.Workspace,
@@ -426,7 +426,7 @@ export class UnifiedDocProcessor {
426426
for (const val of values) {
427427
if (attrBaseType._class === core.class.RefTo) {
428428
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>
430430
propValues.push(ref)
431431
} else {
432432
propValues.push(val)
@@ -439,7 +439,7 @@ export class UnifiedDocProcessor {
439439
throw new Error(`Association not found: ${key}, ${cardPath}`) // todo: keep the error till builder validation
440440
}
441441
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>
443443
const relation: UnifiedDoc<Relation> = this.createRelation(metadata, cardId, otherCardId)
444444
relations.push(relation)
445445
}
@@ -484,11 +484,11 @@ export class UnifiedDocProcessor {
484484
const mixins: UnifiedMixin<Card, Tag>[] = []
485485
for (const tagPath of tags) {
486486
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>
489489

490490
const tagProps: Record<string, any> = {}
491-
this.metadataStorage.getAttributes(fullTagPath).forEach((attr, label) => {
491+
this.metadataStorage.getAttributes(tagAbsPath).forEach((attr, label) => {
492492
tagProps[attr.props.name] = cardHeader[label]
493493
})
494494

@@ -519,7 +519,7 @@ export class UnifiedDocProcessor {
519519
for (const attachment of attachments) {
520520
const attachmentPath = path.resolve(path.dirname(cardPath), attachment)
521521
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>
523523
const type = contentType(attachmentPath)
524524
const size = fs.statSync(attachmentPath).size
525525

@@ -534,7 +534,7 @@ export class UnifiedDocProcessor {
534534
}
535535
result.files.set(attachmentPath, file)
536536

537-
const attachmentId = this.metadataStorage.getIdByFullPath(attachmentPath) as Ref<Attachment>
537+
const attachmentId = this.metadataStorage.getIdByAbsolutePath(attachmentPath) as Ref<Attachment>
538538
const attachmentDoc: UnifiedDoc<Attachment> = {
539539
_class: 'attachment:class:Attachment' as Ref<Class<Attachment>>,
540540
props: {
@@ -562,7 +562,7 @@ export class UnifiedDocProcessor {
562562
const { class: _class, typeA, typeB, type, nameA, nameB } = yamlConfig
563563

564564
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>
566566

567567
const typeAPath = path.resolve(currentPath, typeA)
568568
this.metadataStorage.addAssociation(typeAPath, nameB, {
@@ -578,8 +578,8 @@ export class UnifiedDocProcessor {
578578
type
579579
})
580580

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>
583583

584584
return {
585585
_class,
@@ -600,7 +600,7 @@ export class UnifiedDocProcessor {
600600
yamlConfig: Record<string, any>
601601
): Promise<UnifiedDoc<Enum>> {
602602
const { title, values } = yamlConfig
603-
const enumId = this.metadataStorage.getIdByFullPath(yamlPath) as Ref<Enum>
603+
const enumId = this.metadataStorage.getIdByAbsolutePath(yamlPath) as Ref<Enum>
604604
return {
605605
_class: core.class.Enum,
606606
props: {

0 commit comments

Comments
 (0)