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 polymorphic - principalId 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
bucketNametext-S3/Minio bucket
objectNametext-Object key within the bucket
linktext-Relative access path (/assets/objects/{name})
mimetypetext-Content type from stat metadata
sizeinteger-Object size in bytes
etagtext-S3 etag
varianttext-Caller-supplied variant tag (e.g. thumbnail role)
metadatajsonb-Record<string, any> - raw S3 stat metadata
storageTypetext-Always s3 today
isSyncedbooleanfalseTrue once the MetaLink mirrors the stored object (set on upload)
principalTypetext-Owning entity kind - see enum
principalIdtext-Owning 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.