Skip to Content
DataResources

Resources

Resources efficiently track, manage, and orchestrate physical and virtual objects in workflows, ensuring visibility, traceability, and operational coherence.

Physical and Virtual Objects

Resources provides a powerful framework for modeling and managing both physical and virtual objects in your business domain. It enables you to create a structured representation of the tangible and intangible assets that your business interacts with.

Features

  • Object Modeling: Define and manage the structure and properties of business objects
  • Object Tracking: Monitor the status, location, and history of objects through their lifecycle
  • Object Relationships: Define and navigate connections between related objects
  • Object Permissions: Control who can view, modify, or interact with specific objects
  • Object Versioning: Track changes to objects over time and maintain history
  • Object Search: Find objects by their properties, relationships, or semantic meaning
  • Object Workflows: Define processes that operate on and transform objects
  • Object Integration: Connect objects to external systems and data sources
  • Object Analytics: Gain insights from object data and usage patterns

Usage

import { defineResource } from 'resources.do' // Define a Product resource const Product = defineResource({ name: 'Product', fields: { name: { type: 'text', required: true, }, description: { type: 'richtext', }, price: { type: 'number', min: 0, }, category: { type: 'select', options: ['Electronics', 'Clothing', 'Food', 'Software'], }, status: { type: 'select', options: ['Draft', 'Active', 'Discontinued'], defaultValue: 'Draft', }, images: { type: 'array', fields: { url: { type: 'text', required: true, }, alt: { type: 'text', }, order: { type: 'number', }, }, }, tags: { type: 'tags', }, inventory: { type: 'group', fields: { sku: { type: 'text', unique: true, }, quantity: { type: 'number', min: 0, }, location: { type: 'text', }, }, }, releaseDate: { type: 'date', }, }, // Define computations for derived fields computed: { isLowStock: ({ inventory }) => { return inventory && inventory.quantity < 10 }, formattedPrice: ({ price }) => { return price ? `$${price.toFixed(2)}` : 'N/A' }, }, // Define relationships to other resources relationships: { manufacturer: { type: 'belongsTo', resource: 'Company', }, reviews: { type: 'hasMany', resource: 'Review', foreignKey: 'productId', }, relatedProducts: { type: 'manyToMany', resource: 'Product', through: 'ProductRelationship', }, }, // Define methods that can operate on this resource methods: { applyDiscount(percentage) { if (percentage < 0 || percentage > 100) { throw new Error('Discount percentage must be between 0 and 100') } const discountFactor = 1 - percentage / 100 this.price = this.price * discountFactor return this }, restock(quantity) { if (!this.inventory) { this.inventory = { quantity: 0 } } this.inventory.quantity += quantity return this }, async getFullDetails() { // Load related data const manufacturer = await this.manufacturer() const reviews = await this.reviews() return { ...this, manufacturer, reviews, averageRating: reviews.length > 0 ? reviews.reduce((sum, review) => sum + review.rating, 0) / reviews.length : null, } }, }, // Define lifecycle hooks hooks: { beforeCreate() { if (!this.releaseDate) { this.releaseDate = new Date() } }, afterCreate() { // Notify inventory system }, beforeUpdate(changes) { // Validate changes return changes }, afterUpdate() { // Update search index }, }, })

Next Steps

Resource Categories

Resources supports various categories of resources for different types of objects:

Physical Resources

const Device = defineResource({ name: 'Device', fields: { serialNumber: { type: 'text', required: true, unique: true, }, model: { type: 'text', required: true, }, status: { type: 'select', options: ['Active', 'Maintenance', 'Decommissioned'], defaultValue: 'Active', }, location: { type: 'text', }, }, })

Digital Resources

const DigitalAsset = defineResource({ name: 'DigitalAsset', fields: { fileUrl: { type: 'text', required: true, }, fileType: { type: 'select', options: ['Image', 'Document', 'Video', 'Audio'], }, fileSize: { type: 'number', }, metadata: { type: 'json', }, }, })

Conceptual Resources

const Idea = defineResource({ name: 'Idea', fields: { title: { type: 'text', required: true, }, description: { type: 'richtext', }, status: { type: 'select', options: ['Draft', 'Proposed', 'Approved', 'Implemented', 'Rejected'], defaultValue: 'Draft', }, impact: { type: 'select', options: ['Low', 'Medium', 'High'], }, effort: { type: 'select', options: ['Low', 'Medium', 'High'], }, }, })
Last updated on