Skip to content

Domain Model

@nx/asset owns no schema. The single entity it reads/writes — MetaLink — is defined in @nx/core so other packages (commerce, ledger) can reference it without circular deps.

1. Full ERD

Relations are soft polymorphicprincipalId is a plain text column resolved against whichever table matches principalType. There are no DB foreign keys.

2. Entities

PropertyValue
Tablepublic.MetaLink
Sourcepackages/core/src/models/schemas/public/meta-link/schema.ts
Soft-deleteno — uses generateTzColumnDefs() timestamps; asset deletes via hard deleteAll
Owner ID columnprincipalId (polymorphic, optional)

Fields:

FieldTypeRequiredDefaultDescription
idtextSnowflakePrimary key
bucketNametextS3/Minio bucket
objectNametextObject key within the bucket
linktextRelative access path (/assets/objects/{name})
mimetypetextContent type from stat metadata
sizeintegerObject size in bytes
etagtextS3 etag
varianttextCaller-supplied variant tag (e.g. thumbnail role)
metadatajsonbRecord<string, any> — raw S3 stat metadata
storageTypetextAlways s3 today
isSyncedbooleanfalseTrue once the MetaLink mirrors the stored object (set on upload)
principalTypetextOwning entity kind — see enum
principalIdtextOwning entity ID
createdAt / updatedAttimestampnow()From generateTzColumnDefs()

Principal type enum (MetaLinkPrincipalTypes):

ValueDescription
ProductProduct image / document
ProductVariantVariant-specific media
OrganizerOrganizer branding
LedgerGenerated PDF/XLSX (ledger output)
CategoryCategory artwork

The MetaLink.relations() definition in core also declares merchant and user relations (matched on principalId), though those values are not in the MetaLinkPrincipalTypes validation set.

Indexes & constraints:

NameColumnsType
PK_MetaLinkidPrimary key
IDX_MetaLink_bucket_namebucketNameBtree
IDX_MetaLink_object_nameobjectNameBtree
IDX_MetaLink_storage_typestorageTypeBtree
IDX_MetaLink_is_syncedisSyncedBtree
IDX_MetaLink_principal_type_principal_idprincipalType, principalIdBtree (composite)
IDX_MetaLink_principal_idprincipalIdBtree

Relations:

FieldCardinalityReferences
principalId (type Product)M:1Product.id
principalId (type ProductVariant)M:1ProductVariant.id
principalId (type Organizer)M:1Organizer.id
principalId (type Ledger)M:1Ledger.id
principalId (type Category)M:1Category.id

3. Cross-entity Invariants

InvariantEnforcement
A MetaLink mirrors exactly one stored object (bucketName + objectName)Created in the same handler as helper.upload
Deleting an object removes its MetaLink rowsAssetController deleteAll({ where: { bucketName, objectName } }) after removeObject (best-effort, async)
storageType = 's3'Hardcoded at create — no other backend is live (see ADR-0001)
Polymorphic owner resolves only when principalType ∈ MetaLinkPrincipalTypesMetaLinkPrincipalTypes.isValid() (validation helper, not a DB constraint)

4. Soft-delete Behavior

BehaviorDetail
Read defaultAll rows visible — MetaLink has no deletedAt column
Hard-deleteYes — deleteAll on object delete; /meta-links CRUD deleteById/deleteBy
RestoreNot supported

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.