@coasys/ad4m / Exports
@coasys/ad4m
Table of contents
Enumerations
Classes
- AIClient
- AIModelLoadingStatus
- AIPromptExamples
- AIPromptExamplesInput
- AITask
- AITaskInput
- Ad4mClient
- Ad4mModel
- Agent
- AgentClient
- AgentExpression
- AgentSignature
- AgentStatus
- Apps
- AuthInfo
- AuthInfoInput
- Capability
- CapabilityInput
- Dna
- EntanglementProof
- EntanglementProofInput
- ExceptionInfo
- Expression
- ExpressionProof
- ExpressionProofInput
- ExpressionRef
- ExpressionRendered
- Icon
- ImportResult
- ImportStats
- InteractionCall
- InteractionMeta
- InteractionParameter
- LanguageExpression
- LanguageHandle
- LanguageLanguageInput
- LanguageMeta
- LanguageMetaInput
- LanguageMetaInternal
- LanguageRef
- Link
- LinkExpression
- LinkExpressionInput
- LinkExpressionMutations
- LinkExpressionUpdated
- LinkInput
- LinkMutations
- LinkQuery
- Literal
- ModelQueryBuilder
- Neighbourhood
- NeighbourhoodExpression
- NeighbourhoodProxy
- Notification
- NotificationInput
- OnlineAgent
- Perspective
- PerspectiveAction
- PerspectiveDiff
- PerspectiveDiffExpression
- PerspectiveExpression
- PerspectiveHandle
- PerspectiveInput
- PerspectiveProxy
- PerspectiveUnsignedInput
- QuerySubscriptionProxy
- Resource
- ResourceInput
- RuntimeInfo
- SentMessage
- SmartLiteral
- Subject
- TriggeredNotification
Interfaces
- AgentService
- CollectionMetadata
- CollectionOptions
- DirectMessageAdapter
- ExpressionAdapter
- ExpressionUI
- FlagOptions
- GetAllAdapter
- GetByAuthorAdapter
- HolochainLanguageDelegate
- InitializeArgs
- InstanceQueryParams
- Interaction
- Language
- LanguageAdapter
- LanguageContext
- LinkSyncAdapter
- ModelMetadata
- ModelOptionsOptions
- PropertyMetadata
- PropertyOptions
- PublicSharing
- ReadOnlyLanguage
- SettingsUI
- SignaturesService
- TelepresenceAdapter
Type Aliases
- Ad4mSignalCB
- Address
- AgentAppsUpdatedCallback
- AgentStatusChangedCallback
- AgentUpdatedCallback
- AllInstancesResult
- DID
- LinkStatus
- MessageCallback
- PaginationResult
- PerspectiveDiffObserver
- Query
- ResultsWithTotalCount
- StatusCallback
- SyncStateChangeObserver
- TelepresenceSignalCallback
Variables
Decorators Functions
Other Functions
- ExpressionGeneric
- ExpressionGenericInput
- addLink
- capSentence
- exprRef2String
- formatList
- hasLink
- isExpression
- isLink
- linkEqual
- makeRandomPrologAtom
- parseExprUrl
Type Aliases
Ad4mSignalCB
Ƭ Ad4mSignalCB: (signal: any) => void
Type declaration
▸ (signal): void
Parameters
| Name | Type |
|---|---|
signal | any |
Returns
void
Defined in
language/LanguageContext.ts:37 (opens in a new tab)
Address
Ƭ Address: string
Defined in
Address.ts:1 (opens in a new tab)
AgentAppsUpdatedCallback
Ƭ AgentAppsUpdatedCallback: () => null
Type declaration
▸ (): null
Returns
null
Defined in
agent/AgentClient.ts:81 (opens in a new tab)
AgentStatusChangedCallback
Ƭ AgentStatusChangedCallback: (agent: Agent) => null
Type declaration
▸ (agent): null
Parameters
| Name | Type |
|---|---|
agent | Agent |
Returns
null
Defined in
agent/AgentClient.ts:80 (opens in a new tab)
AgentUpdatedCallback
Ƭ AgentUpdatedCallback: (agent: Agent) => null
Type declaration
▸ (agent): null
Parameters
| Name | Type |
|---|---|
agent | Agent |
Returns
null
Defined in
agent/AgentClient.ts:79 (opens in a new tab)
AllInstancesResult
Ƭ AllInstancesResult: Object
Type declaration
| Name | Type |
|---|---|
AllInstances | Ad4mModel[] |
TotalCount? | number |
isInit? | boolean |
Defined in
model/Ad4mModel.ts:71 (opens in a new tab)
DID
Ƭ DID: string
Defined in
LinkStatus
Ƭ LinkStatus: "shared" | "local"
Defined in
perspectives/PerspectiveProxy.ts:321 (opens in a new tab)
MessageCallback
Ƭ MessageCallback: (message: PerspectiveExpression) => void
Type declaration
▸ (message): void
Parameters
| Name | Type |
|---|---|
message | PerspectiveExpression |
Returns
void
Defined in
language/Language.ts:192 (opens in a new tab)
PaginationResult
Ƭ PaginationResult<T>: Object
Type parameters
| Name |
|---|
T |
Type declaration
| Name | Type |
|---|---|
pageNumber | number |
pageSize | number |
results | T[] |
totalCount? | number |
Defined in
model/Ad4mModel.ts:73 (opens in a new tab)
PerspectiveDiffObserver
Ƭ PerspectiveDiffObserver: (diff: PerspectiveDiff) => void
Type declaration
▸ (diff): void
Parameters
| Name | Type |
|---|---|
diff | PerspectiveDiff |
Returns
void
Defined in
language/Language.ts:151 (opens in a new tab)
Query
Ƭ Query: Object
Type declaration
| Name | Type |
|---|---|
collections? | string[] |
count? | boolean |
limit? | number |
offset? | number |
order? | Order |
properties? | string[] |
source? | string |
where? | Where |
Defined in
model/Ad4mModel.ts:60 (opens in a new tab)
ResultsWithTotalCount
Ƭ ResultsWithTotalCount<T>: Object
Type parameters
| Name |
|---|
T |
Type declaration
| Name | Type |
|---|---|
results | T[] |
totalCount? | number |
Defined in
model/Ad4mModel.ts:72 (opens in a new tab)
StatusCallback
Ƭ StatusCallback: (caller: DID) => Perspective
Type declaration
▸ (caller): Perspective
Parameters
| Name | Type |
|---|---|
caller | DID |
Returns
Defined in
language/Language.ts:193 (opens in a new tab)
SyncStateChangeObserver
Ƭ SyncStateChangeObserver: (state: PerspectiveState) => void
Type declaration
▸ (state): void
Parameters
| Name | Type |
|---|---|
state | PerspectiveState |
Returns
void
Defined in
language/Language.ts:152 (opens in a new tab)
TelepresenceSignalCallback
Ƭ TelepresenceSignalCallback: (payload: PerspectiveExpression) => void
Type declaration
▸ (payload): void
Parameters
| Name | Type |
|---|---|
payload | PerspectiveExpression |
Returns
void
Defined in
language/Language.ts:258 (opens in a new tab)
Variables
SMART_LITERAL_CONTENT_PREDICATE
• Const SMART_LITERAL_CONTENT_PREDICATE: "smart_literal://content"
Defined in
SmartLiteral.ts:6 (opens in a new tab)
typeDefsString
• Const typeDefsString: ""
Defined in
typeDefs.ts:6 (opens in a new tab)
Decorators Functions
Collection
▸ Collection(opts): <T>(target: T, key: keyof T) => void
Decorator for defining collections on model classes.
Parameters
| Name | Type | Description |
|---|---|---|
opts | CollectionOptions | Collection configuration |
Returns
fn
▸ <T>(target, key): void
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
target | T |
key | keyof T |
Returns
void
Description
Defines a property that represents a collection of values linked to the model instance. Collections are always arrays and support operations for adding, removing, and setting values.
For each collection property, the following methods are automatically generated:
addX(value)- Add a value to the collectionremoveX(value)- Remove a value from the collectionsetCollectionX(values)- Replace all values in the collection
Where X is the capitalized property name.
Collections can be filtered using the where option to only include values that:
- Are instances of a specific model class
- Match a custom Prolog condition
Example
class Recipe extends Ad4mModel {
// Basic collection of ingredients
@Collection({
through: "recipe://ingredient"
})
ingredients: string[] = [];
// Collection that only includes instances of another model
@Collection({
through: "recipe://comment",
where: { isInstance: Comment }
})
comments: string[] = [];
// Collection with custom filter condition
@Collection({
through: "recipe://step",
where: { condition: `triple(Target, "step://order", Order), Order < 3` }
})
firstSteps: string[] = [];
// Local-only collection not shared with network
@Collection({
through: "recipe://note",
local: true
})
privateNotes: string[] = [];
}
// Using the generated methods:
const recipe = new Recipe(perspective);
await recipe.addIngredients("ingredient://flour");
await recipe.removeIngredients("ingredient://sugar");
await recipe.setCollectionIngredients(["ingredient://butter", "ingredient://eggs"]);Defined in
model/decorators.ts:459 (opens in a new tab)
Flag
▸ Flag(opts): <T>(target: T, key: keyof T) => void
Decorator for defining flags on model classes.
Parameters
| Name | Type | Description |
|---|---|---|
opts | FlagOptions | Flag configuration |
Returns
fn
▸ <T>(target, key): void
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
target | T |
key | keyof T |
Returns
void
Description
A specialized property decorator for defining immutable type flags or markers on model instances. Flags are always required properties with a fixed value that cannot be changed after creation.
Common uses for flags:
- Type discrimination between different kinds of models
- Marking models with specific capabilities or features
- Versioning or compatibility markers
Note: Use of Flag is discouraged unless you specifically need type-based filtering or discrimination between different kinds of models. For most cases, regular properties with
Property
or
Optional
are more appropriate.
Example
class Message extends Ad4mModel {
// Type flag to identify message models
@Flag({
through: "ad4m://type",
value: "ad4m://message"
})
type: string = "";
// Version flag for compatibility
@Flag({
through: "ad4m://version",
value: "1.0.0"
})
version: string = "";
// Feature flag
@Flag({
through: "message://feature",
value: "message://encrypted"
})
feature: string = "";
}
// Later you can query for specific types:
const messages = await Message.query(perspective)
.where({ type: "ad4m://message" })
.run();Defined in
model/decorators.ts:341 (opens in a new tab)
InstanceQuery
▸ InstanceQuery(options?): <T>(target: T, key: keyof T, descriptor: PropertyDescriptor) => void
Decorator for querying instances of a model class.
Parameters
| Name | Type | Description |
|---|---|---|
options? | InstanceQueryParams | Query options |
Returns
fn
▸ <T>(target, key, descriptor): void
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
target | T |
key | keyof T |
descriptor | PropertyDescriptor |
Returns
void
Description
Allows you to define static query methods on your model class to retrieve instances based on custom conditions. This decorator can only be applied to static async methods that return a Promise of an array of model instances.
The query can be constrained using either:
- A
whereclause that matches property values - A custom Prolog
conditionfor more complex queries
Example
class Recipe extends Ad4mModel {
@Property({ through: "recipe://name" })
name: string = "";
@Property({ through: "recipe://rating" })
rating: number = 0;
// Get all recipes
@InstanceQuery()
static async all(perspective: PerspectiveProxy): Promise<Recipe[]> { return [] }
// Get recipes by name
@InstanceQuery({ where: { name: "Chocolate Cake" }})
static async findByName(perspective: PerspectiveProxy): Promise<Recipe[]> { return [] }
// Get highly rated recipes using a custom condition
@InstanceQuery({ condition: "triple(Instance, 'recipe://rating', Rating), Rating > 4" })
static async topRated(perspective: PerspectiveProxy): Promise<Recipe[]> { return [] }
}Defined in
model/decorators.ts:77 (opens in a new tab)
ModelOptions
▸ ModelOptions(opts): (target: any) => void
Decorator for defining model classes in AD4M.
Parameters
| Name | Type | Description |
|---|---|---|
opts | ModelOptionsOptions | Model configuration |
Returns
fn
▸ (target): void
Parameters
| Name | Type |
|---|---|
target | any |
Returns
void
Description
The root decorator that must be applied to any class that represents a model in AD4M. It registers the class as a Social DNA (SDNA) subject class and provides the infrastructure for storing and retrieving instances.
This decorator:
- Registers the class with a unique name in the AD4M system
- Generates the necessary SDNA code for the model's properties and collections
- Enables the use of other model decorators (@Property, @Collection, etc.)
- Provides static query methods through the Ad4mModel base class
Example
@ModelOptions({ name: "Recipe" })
class Recipe extends Ad4mModel {
@Property({
through: "recipe://name",
resolveLanguage: "literal"
})
name: string = "";
@Collection({ through: "recipe://ingredient" })
ingredients: string[] = [];
// Static query methods from Ad4mModel:
static async findByName(perspective: PerspectiveProxy, name: string) {
return Recipe.query(perspective)
.where({ name })
.run();
}
}
// Using the model:
const recipe = new Recipe(perspective);
recipe.name = "Chocolate Cake";
await recipe.save();
// Querying instances:
const recipes = await Recipe.query(perspective)
.where({ name: "Chocolate Cake" })
.run();
// Using with PerspectiveProxy:
await perspective.ensureSDNASubjectClass(Recipe);Defined in
model/decorators.ts:544 (opens in a new tab)
Optional
▸ Optional(opts): <T>(target: T, key: keyof T) => void
Decorator for defining optional properties on model classes.
Parameters
| Name | Type | Description |
|---|---|---|
opts | PropertyOptions | Property configuration options |
Returns
fn
▸ <T>(target, key): void
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
target | T |
key | keyof T |
Returns
void
Description
The most flexible property decorator that allows you to define properties with full control over:
- Whether the property is required
- Whether the property is writable
- How values are stored and retrieved
- Custom getter/setter logic
- Local vs network storage
Both
Property
and
Read Only
are specialized versions of
Optional
with preset configurations.
Example
class Recipe extends Ad4mModel {
// Basic optional property
@Optional({
through: "recipe://description"
})
description?: string;
// Optional property with custom initial value
@Optional({
through: "recipe://status",
initial: "recipe://draft",
required: true
})
status: string = "";
// Read-only property with custom getter
@Optional({
through: "recipe://rating",
writable: false,
getter: `
findall(Rating, triple(Base, "recipe://user_rating", Rating), Ratings),
sum_list(Ratings, Sum),
length(Ratings, Count),
Value is Sum / Count
`
})
averageRating: number = 0;
// Property that resolves to a Literal and is stored locally
@Optional({
through: "recipe://notes",
resolveLanguage: "literal",
local: true
})
notes?: string;
// Property with custom getter and setter logic
@Optional({
through: "recipe://ingredients",
getter: `
triple(Base, "recipe://ingredients", RawValue),
atom_json_term(RawValue, Value)
`,
setter: `
atom_json_term(Value, JsonValue),
Actions = [{"action": "setSingleTarget", "source": "this", "predicate": "recipe://ingredients", "target": JsonValue}]
`
})
ingredients: string[] = [];
}Defined in
model/decorators.ts:249 (opens in a new tab)
Property
▸ Property(opts): <T>(target: T, key: keyof T) => void
Decorator for defining required and writable properties on model classes.
Parameters
| Name | Type | Description |
|---|---|---|
opts | PropertyOptions | Property configuration |
Returns
fn
▸ <T>(target, key): void
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
target | T |
key | keyof T |
Returns
void
Description
A convenience decorator that defines a required property that must have an initial value and is writable by default. This is equivalent to using
Optional
with required: true and writable: true.
Properties defined with this decorator:
- Must have a value (required)
- Can be modified after creation (writable)
- Default to "literal://string:uninitialized" if no initial value is provided
Example
class User extends Ad4mModel {
// Basic required property with default initial value
@Property({
through: "user://name"
})
name: string = "";
// Required property with custom initial value
@Property({
through: "user://status",
initial: "user://active"
})
status: string = "";
// Required property with literal resolution
@Property({
through: "user://bio",
resolveLanguage: "literal"
})
bio: string = "";
// Required property with custom getter/setter
@Property({
through: "user://age",
getter: `triple(Base, "user://birthYear", Year), Value is 2024 - Year`,
setter: `Year is 2024 - Value, Actions = [{"action": "setSingleTarget", "source": "this", "predicate": "user://birthYear", "target": Year}]`
})
age: number = 0;
}Defined in
model/decorators.ts:776 (opens in a new tab)
ReadOnly
▸ ReadOnly(opts): <T>(target: T, key: keyof T) => void
Decorator for defining read-only properties on model classes.
Parameters
| Name | Type | Description |
|---|---|---|
opts | PropertyOptions | Property configuration |
Returns
fn
▸ <T>(target, key): void
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
target | T |
key | keyof T |
Returns
void
Description
A convenience decorator that defines a property that can only be read and cannot be modified after initialization. This is equivalent to using
Optional
with writable: false.
Read-only properties are ideal for:
- Computed or derived values
- Properties that should never change after creation
- Properties that are set by the system
- Properties that represent immutable data
Example
class Post extends Ad4mModel {
// Read-only property with custom getter for computed value
@ReadOnly({
through: "post://likes",
getter: `findall(User, triple(Base, "post://liked_by", User), Users), length(Users, Value)`
})
likeCount: number = 0;
// Read-only property for creation timestamp
@ReadOnly({
through: "post://created_at",
initial: new Date().toISOString()
})
createdAt: string = "";
// Read-only property that resolves to a Literal
@ReadOnly({
through: "post://author",
resolveLanguage: "literal"
})
author: string = "";
// Read-only property for system-managed data
@ReadOnly({
through: "post://version",
initial: "1.0.0"
})
version: string = "";
}Defined in
model/decorators.ts:840 (opens in a new tab)
Other Functions
ExpressionGeneric
▸ ExpressionGeneric<DataType>(DataTypeClass): any
Type parameters
| Name |
|---|
DataType |
Parameters
| Name | Type |
|---|---|
DataTypeClass | ClassType<DataType> |
Returns
any
Defined in
expression/Expression.ts:42 (opens in a new tab)
ExpressionGenericInput
▸ ExpressionGenericInput<DataType>(DataTypeClass): any
Type parameters
| Name |
|---|
DataType |
Parameters
| Name | Type |
|---|---|
DataTypeClass | ClassType<DataType> |
Returns
any
Defined in
expression/Expression.ts:67 (opens in a new tab)
addLink
▸ addLink(source, predicate, target): PerspectiveAction
Parameters
| Name | Type |
|---|---|
source | string |
predicate | string |
target | string |
Returns
Defined in
model/decorators.ts:12 (opens in a new tab)
capSentence
▸ capSentence(cap): string
Parameters
| Name | Type |
|---|---|
cap | any |
Returns
string
Defined in
utils.ts:15 (opens in a new tab)
exprRef2String
▸ exprRef2String(ref): string
Parameters
| Name | Type |
|---|---|
ref | ExpressionRef |
Returns
string
Defined in
expression/ExpressionRef.ts:22 (opens in a new tab)
formatList
▸ formatList(list): any
Parameters
| Name | Type |
|---|---|
list | any |
Returns
any
Defined in
utils.ts:1 (opens in a new tab)
hasLink
▸ hasLink(predicate): string
Parameters
| Name | Type |
|---|---|
predicate | string |
Returns
string
Defined in
model/decorators.ts:21 (opens in a new tab)
isExpression
▸ isExpression(e): boolean
Parameters
| Name | Type |
|---|---|
e | any |
Returns
boolean
Defined in
expression/Expression.ts:97 (opens in a new tab)
isLink
▸ isLink(l): boolean
Parameters
| Name | Type |
|---|---|
l | any |
Returns
boolean
Defined in
links/Links.ts:91 (opens in a new tab)
linkEqual
▸ linkEqual(l1, l2): boolean
Parameters
| Name | Type |
|---|---|
l1 | LinkExpression |
l2 | LinkExpression |
Returns
boolean
Defined in
links/Links.ts:83 (opens in a new tab)
makeRandomPrologAtom
▸ makeRandomPrologAtom(length): string
Parameters
| Name | Type |
|---|---|
length | number |
Returns
string
Defined in
model/decorators.ts:473 (opens in a new tab)
parseExprUrl
▸ parseExprUrl(url): ExpressionRef
Parameters
| Name | Type |
|---|---|
url | string |