@coasys/ad4m 0.10.1-rc9-dev → 0.10.1-release-candidate-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +3179 -811
- package/lib/index.js +3171 -807
- package/lib/src/Literal.js +4 -1
- package/lib/src/ai/AIClient.d.ts +1 -1
- package/lib/src/ai/AIClient.js +6 -6
- package/lib/src/ai/AIResolver.d.ts +1 -1
- package/lib/src/ai/AIResolver.js +7 -4
- package/lib/src/index.d.ts +4 -3
- package/lib/src/index.js +4 -3
- package/lib/src/model/Ad4mModel.d.ts +609 -0
- package/lib/src/model/Ad4mModel.js +1048 -0
- package/lib/src/{subject → model}/Subject.d.ts +2 -2
- package/lib/src/{subject → model}/Subject.js +18 -18
- package/lib/src/model/decorators.d.ts +502 -0
- package/lib/src/model/decorators.js +683 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +2 -2
- package/lib/src/neighbourhood/NeighbourhoodClient.js +16 -10
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +2 -2
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +4 -4
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +31 -0
- package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +2 -2
- package/lib/src/neighbourhood/NeighbourhoodResolver.js +6 -4
- package/lib/src/perspectives/PerspectiveClient.d.ts +18 -11
- package/lib/src/perspectives/PerspectiveClient.js +116 -49
- package/lib/src/perspectives/PerspectiveProxy.d.ts +471 -54
- package/lib/src/perspectives/PerspectiveProxy.js +579 -64
- package/lib/src/perspectives/PerspectiveResolver.d.ts +23 -9
- package/lib/src/perspectives/PerspectiveResolver.js +140 -46
- package/lib/src/runtime/RuntimeClient.d.ts +5 -1
- package/lib/src/runtime/RuntimeClient.js +48 -0
- package/lib/src/runtime/RuntimeResolver.d.ts +24 -0
- package/lib/src/runtime/RuntimeResolver.js +117 -0
- package/lib/src/schema.gql +25 -11
- package/lib/src/typeDefs.js +25 -11
- package/package.json +2 -1
- package/src/Literal.ts +4 -1
- package/src/ai/AIClient.ts +6 -6
- package/src/ai/AIResolver.ts +6 -3
- package/src/index.ts +4 -3
- package/src/model/Ad4mModel.ts +1206 -0
- package/src/{subject → model}/Subject.ts +16 -16
- package/src/{subject/SDNADecorators.ts → model/decorators.ts} +384 -50
- package/src/neighbourhood/NeighbourhoodClient.ts +16 -10
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +45 -0
- package/src/neighbourhood/NeighbourhoodProxy.ts +4 -4
- package/src/neighbourhood/NeighbourhoodResolver.ts +2 -2
- package/src/perspectives/PerspectiveClient.ts +122 -51
- package/src/perspectives/PerspectiveProxy.ts +642 -77
- package/src/perspectives/PerspectiveResolver.ts +126 -23
- package/src/runtime/RuntimeClient.ts +52 -1
- package/src/runtime/RuntimeResolver.ts +77 -0
- package/lib/src/subject/SDNADecorators.d.ts +0 -188
- package/lib/src/subject/SDNADecorators.js +0 -360
- package/lib/src/subject/SubjectEntity.d.ts +0 -110
- package/lib/src/subject/SubjectEntity.js +0 -288
- package/src/subject/SubjectEntity.ts +0 -336
- package/yarn-error.log +0 -90
- /package/lib/src/{subject → model}/util.d.ts +0 -0
- /package/lib/src/{subject → model}/util.js +0 -0
- /package/src/{subject → model}/util.ts +0 -0
|
@@ -9,9 +9,9 @@ export declare class Subject {
|
|
|
9
9
|
* Constructs a new subject.
|
|
10
10
|
* @param perspective - The perspective that the subject belongs to.
|
|
11
11
|
* @param baseExpression - The base expression of the subject.
|
|
12
|
-
* @param
|
|
12
|
+
* @param subjectClassName - The class name of the subject.
|
|
13
13
|
*/
|
|
14
|
-
constructor(perspective: PerspectiveProxy, baseExpression: string,
|
|
14
|
+
constructor(perspective: PerspectiveProxy, baseExpression: string, subjectClassName: string);
|
|
15
15
|
/**
|
|
16
16
|
* Gets the base expression of the subject.
|
|
17
17
|
*/
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _Subject_baseExpression,
|
|
12
|
+
var _Subject_baseExpression, _Subject_subjectClassName, _Subject_perspective;
|
|
13
13
|
import { collectionToAdderName, collectionToRemoverName, collectionToSetterName, propertyNameToSetterName } from "./util";
|
|
14
14
|
/**
|
|
15
15
|
* Represents a subject in the perspective.
|
|
@@ -20,14 +20,14 @@ export class Subject {
|
|
|
20
20
|
* Constructs a new subject.
|
|
21
21
|
* @param perspective - The perspective that the subject belongs to.
|
|
22
22
|
* @param baseExpression - The base expression of the subject.
|
|
23
|
-
* @param
|
|
23
|
+
* @param subjectClassName - The class name of the subject.
|
|
24
24
|
*/
|
|
25
|
-
constructor(perspective, baseExpression,
|
|
25
|
+
constructor(perspective, baseExpression, subjectClassName) {
|
|
26
26
|
_Subject_baseExpression.set(this, void 0);
|
|
27
|
-
|
|
27
|
+
_Subject_subjectClassName.set(this, void 0);
|
|
28
28
|
_Subject_perspective.set(this, void 0);
|
|
29
29
|
__classPrivateFieldSet(this, _Subject_baseExpression, baseExpression, "f");
|
|
30
|
-
__classPrivateFieldSet(this,
|
|
30
|
+
__classPrivateFieldSet(this, _Subject_subjectClassName, subjectClassName, "f");
|
|
31
31
|
__classPrivateFieldSet(this, _Subject_perspective, perspective, "f");
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
@@ -43,19 +43,19 @@ export class Subject {
|
|
|
43
43
|
*/
|
|
44
44
|
async init() {
|
|
45
45
|
// Check if the subject is a valid instance of the subject class
|
|
46
|
-
let isInstance = await __classPrivateFieldGet(this, _Subject_perspective, "f").isSubjectInstance(__classPrivateFieldGet(this, _Subject_baseExpression, "f"), __classPrivateFieldGet(this,
|
|
46
|
+
let isInstance = await __classPrivateFieldGet(this, _Subject_perspective, "f").isSubjectInstance(__classPrivateFieldGet(this, _Subject_baseExpression, "f"), __classPrivateFieldGet(this, _Subject_subjectClassName, "f"));
|
|
47
47
|
if (!isInstance) {
|
|
48
|
-
throw `Not a valid subject instance of ${__classPrivateFieldGet(this,
|
|
48
|
+
throw `Not a valid subject instance of ${__classPrivateFieldGet(this, _Subject_subjectClassName, "f")} for ${__classPrivateFieldGet(this, _Subject_baseExpression, "f")}`;
|
|
49
49
|
}
|
|
50
50
|
// Define properties and collections dynamically
|
|
51
|
-
let results = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this,
|
|
51
|
+
let results = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _Subject_subjectClassName, "f")}", C), property(C, Property)`);
|
|
52
52
|
let properties = results.map(result => result.Property);
|
|
53
53
|
for (let p of properties) {
|
|
54
|
-
const resolveExpressionURI = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this,
|
|
54
|
+
const resolveExpressionURI = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _Subject_subjectClassName, "f")}", C), property_resolve(C, "${p}")`);
|
|
55
55
|
Object.defineProperty(this, p, {
|
|
56
56
|
configurable: true,
|
|
57
57
|
get: async () => {
|
|
58
|
-
let results = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this,
|
|
58
|
+
let results = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _Subject_subjectClassName, "f")}", C), property_getter(C, "${__classPrivateFieldGet(this, _Subject_baseExpression, "f")}", "${p}", Value)`);
|
|
59
59
|
if (results && results.length > 0) {
|
|
60
60
|
let expressionURI = results[0].Value;
|
|
61
61
|
if (resolveExpressionURI) {
|
|
@@ -91,12 +91,12 @@ export class Subject {
|
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
// Define setters
|
|
94
|
-
const setters = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this,
|
|
94
|
+
const setters = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _Subject_subjectClassName, "f")}", C), property_setter(C, Property, Setter)`);
|
|
95
95
|
for (let setter of (setters ? setters : [])) {
|
|
96
96
|
if (setter) {
|
|
97
97
|
const property = setter.Property;
|
|
98
98
|
const actions = eval(setter.Setter);
|
|
99
|
-
const resolveLanguageResults = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this,
|
|
99
|
+
const resolveLanguageResults = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _Subject_subjectClassName, "f")}", C), property_resolve_language(C, "${property}", Language)`);
|
|
100
100
|
let resolveLanguage;
|
|
101
101
|
if (resolveLanguageResults && resolveLanguageResults.length > 0) {
|
|
102
102
|
resolveLanguage = resolveLanguageResults[0].Language;
|
|
@@ -110,7 +110,7 @@ export class Subject {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
// Define collections
|
|
113
|
-
let results2 = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this,
|
|
113
|
+
let results2 = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _Subject_subjectClassName, "f")}", C), collection(C, Collection)`);
|
|
114
114
|
if (!results2)
|
|
115
115
|
results2 = [];
|
|
116
116
|
let collections = results2.map(result => result.Collection);
|
|
@@ -118,7 +118,7 @@ export class Subject {
|
|
|
118
118
|
Object.defineProperty(this, c, {
|
|
119
119
|
configurable: true,
|
|
120
120
|
get: async () => {
|
|
121
|
-
let results = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this,
|
|
121
|
+
let results = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _Subject_subjectClassName, "f")}", C), collection_getter(C, "${__classPrivateFieldGet(this, _Subject_baseExpression, "f")}", "${c}", Value)`);
|
|
122
122
|
if (results && results.length > 0 && results[0].Value) {
|
|
123
123
|
let collectionContent = results[0].Value.filter((v) => v !== "" && v !== '');
|
|
124
124
|
return collectionContent;
|
|
@@ -130,7 +130,7 @@ export class Subject {
|
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
// Define collection adders
|
|
133
|
-
let adders = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this,
|
|
133
|
+
let adders = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _Subject_subjectClassName, "f")}", C), collection_adder(C, Collection, Adder)`);
|
|
134
134
|
if (!adders)
|
|
135
135
|
adders = [];
|
|
136
136
|
for (let adder of adders) {
|
|
@@ -148,7 +148,7 @@ export class Subject {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
// Define collection removers
|
|
151
|
-
let removers = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this,
|
|
151
|
+
let removers = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _Subject_subjectClassName, "f")}", C), collection_remover(C, Collection, Remover)`);
|
|
152
152
|
if (!removers)
|
|
153
153
|
removers = [];
|
|
154
154
|
for (let remover of removers) {
|
|
@@ -166,7 +166,7 @@ export class Subject {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
// Define collection setters
|
|
169
|
-
let collectionSetters = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this,
|
|
169
|
+
let collectionSetters = await __classPrivateFieldGet(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet(this, _Subject_subjectClassName, "f")}", C), collection_setter(C, Collection, Setter)`);
|
|
170
170
|
if (!collectionSetters)
|
|
171
171
|
collectionSetters = [];
|
|
172
172
|
for (let collectionSetter of collectionSetters) {
|
|
@@ -185,4 +185,4 @@ export class Subject {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
-
_Subject_baseExpression = new WeakMap(),
|
|
188
|
+
_Subject_baseExpression = new WeakMap(), _Subject_subjectClassName = new WeakMap(), _Subject_perspective = new WeakMap();
|
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
export declare class PerspectiveAction {
|
|
2
|
+
action: string;
|
|
3
|
+
source: string;
|
|
4
|
+
predicate: string;
|
|
5
|
+
target: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function addLink(source: string, predicate: string, target: string): PerspectiveAction;
|
|
8
|
+
export declare function hasLink(predicate: string): string;
|
|
9
|
+
export interface InstanceQueryParams {
|
|
10
|
+
/**
|
|
11
|
+
* An object representing the WHERE clause of the query.
|
|
12
|
+
*/
|
|
13
|
+
where?: object;
|
|
14
|
+
/**
|
|
15
|
+
* A string representing the condition clause of the query.
|
|
16
|
+
*/
|
|
17
|
+
condition?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Decorator for querying instances of a model class.
|
|
21
|
+
*
|
|
22
|
+
* @category Decorators
|
|
23
|
+
*
|
|
24
|
+
* @description
|
|
25
|
+
* Allows you to define static query methods on your model class to retrieve instances based on custom conditions.
|
|
26
|
+
* This decorator can only be applied to static async methods that return a Promise of an array of model instances.
|
|
27
|
+
*
|
|
28
|
+
* The query can be constrained using either:
|
|
29
|
+
* - A `where` clause that matches property values
|
|
30
|
+
* - A custom Prolog `condition` for more complex queries
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* class Recipe extends Ad4mModel {
|
|
35
|
+
* @Property({ through: "recipe://name" })
|
|
36
|
+
* name: string = "";
|
|
37
|
+
*
|
|
38
|
+
* @Property({ through: "recipe://rating" })
|
|
39
|
+
* rating: number = 0;
|
|
40
|
+
*
|
|
41
|
+
* // Get all recipes
|
|
42
|
+
* @InstanceQuery()
|
|
43
|
+
* static async all(perspective: PerspectiveProxy): Promise<Recipe[]> { return [] }
|
|
44
|
+
*
|
|
45
|
+
* // Get recipes by name
|
|
46
|
+
* @InstanceQuery({ where: { name: "Chocolate Cake" }})
|
|
47
|
+
* static async findByName(perspective: PerspectiveProxy): Promise<Recipe[]> { return [] }
|
|
48
|
+
*
|
|
49
|
+
* // Get highly rated recipes using a custom condition
|
|
50
|
+
* @InstanceQuery({ condition: "triple(Instance, 'recipe://rating', Rating), Rating > 4" })
|
|
51
|
+
* static async topRated(perspective: PerspectiveProxy): Promise<Recipe[]> { return [] }
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @param {Object} [options] - Query options
|
|
56
|
+
* @param {object} [options.where] - Object with property-value pairs to match
|
|
57
|
+
* @param {string} [options.condition] - Custom Prolog condition for more complex queries
|
|
58
|
+
*/
|
|
59
|
+
export declare function InstanceQuery(options?: InstanceQueryParams): <T>(target: T, key: keyof T, descriptor: PropertyDescriptor) => void;
|
|
60
|
+
export interface PropertyOptions {
|
|
61
|
+
/**
|
|
62
|
+
* The predicate of the property. All properties must have this option.
|
|
63
|
+
*/
|
|
64
|
+
through?: string;
|
|
65
|
+
/**
|
|
66
|
+
* The initial value of the property. Required if the property is marked as required.
|
|
67
|
+
*/
|
|
68
|
+
initial?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Indicates whether the property is required. If true, an initial value must be provided.
|
|
71
|
+
*/
|
|
72
|
+
required?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Indicates whether the property is writable. If true, a setter will be available in the prolog engine.
|
|
75
|
+
*/
|
|
76
|
+
writable?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* The language used to store the property. Can be the default `Literal` Language or a custom language address.
|
|
79
|
+
*/
|
|
80
|
+
resolveLanguage?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Custom getter to get the value of the property in the prolog engine. If not provided, the default getter will be used.
|
|
83
|
+
*/
|
|
84
|
+
getter?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Custom setter to set the value of the property in the prolog engine. Only available if the property is writable.
|
|
87
|
+
*/
|
|
88
|
+
setter?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Indicates whether the property is stored locally in the perspective and not in the network. Useful for properties that are not meant to be shared with the network.
|
|
91
|
+
*/
|
|
92
|
+
local?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Optional transform function to modify the property value after it is retrieved.
|
|
95
|
+
* This is useful for transforming raw data into a more usable format.
|
|
96
|
+
* The function takes the raw value as input and returns the transformed value.
|
|
97
|
+
*/
|
|
98
|
+
transform?: (value: any) => any;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Decorator for defining optional properties on model classes.
|
|
102
|
+
*
|
|
103
|
+
* @category Decorators
|
|
104
|
+
*
|
|
105
|
+
* @description
|
|
106
|
+
* The most flexible property decorator that allows you to define properties with full control over:
|
|
107
|
+
* - Whether the property is required
|
|
108
|
+
* - Whether the property is writable
|
|
109
|
+
* - How values are stored and retrieved
|
|
110
|
+
* - Custom getter/setter logic
|
|
111
|
+
* - Local vs network storage
|
|
112
|
+
*
|
|
113
|
+
* Both @Property and @ReadOnly are specialized versions of @Optional with preset configurations.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* class Recipe extends Ad4mModel {
|
|
118
|
+
* // Basic optional property
|
|
119
|
+
* @Optional({
|
|
120
|
+
* through: "recipe://description"
|
|
121
|
+
* })
|
|
122
|
+
* description?: string;
|
|
123
|
+
*
|
|
124
|
+
* // Optional property with custom initial value
|
|
125
|
+
* @Optional({
|
|
126
|
+
* through: "recipe://status",
|
|
127
|
+
* initial: "recipe://draft",
|
|
128
|
+
* required: true
|
|
129
|
+
* })
|
|
130
|
+
* status: string = "";
|
|
131
|
+
*
|
|
132
|
+
* // Read-only property with custom getter
|
|
133
|
+
* @Optional({
|
|
134
|
+
* through: "recipe://rating",
|
|
135
|
+
* writable: false,
|
|
136
|
+
* getter: `
|
|
137
|
+
* findall(Rating, triple(Base, "recipe://user_rating", Rating), Ratings),
|
|
138
|
+
* sum_list(Ratings, Sum),
|
|
139
|
+
* length(Ratings, Count),
|
|
140
|
+
* Value is Sum / Count
|
|
141
|
+
* `
|
|
142
|
+
* })
|
|
143
|
+
* averageRating: number = 0;
|
|
144
|
+
*
|
|
145
|
+
* // Property that resolves to a Literal and is stored locally
|
|
146
|
+
* @Optional({
|
|
147
|
+
* through: "recipe://notes",
|
|
148
|
+
* resolveLanguage: "literal",
|
|
149
|
+
* local: true
|
|
150
|
+
* })
|
|
151
|
+
* notes?: string;
|
|
152
|
+
*
|
|
153
|
+
* // Property with custom getter and setter logic
|
|
154
|
+
* @Optional({
|
|
155
|
+
* through: "recipe://ingredients",
|
|
156
|
+
* getter: `
|
|
157
|
+
* triple(Base, "recipe://ingredients", RawValue),
|
|
158
|
+
* atom_json_term(RawValue, Value)
|
|
159
|
+
* `,
|
|
160
|
+
* setter: `
|
|
161
|
+
* atom_json_term(Value, JsonValue),
|
|
162
|
+
* Actions = [{"action": "setSingleTarget", "source": "this", "predicate": "recipe://ingredients", "target": JsonValue}]
|
|
163
|
+
* `
|
|
164
|
+
* })
|
|
165
|
+
* ingredients: string[] = [];
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @param {PropertyOptions} opts - Property configuration options
|
|
170
|
+
* @param {string} opts.through - The predicate URI for the property
|
|
171
|
+
* @param {string} [opts.initial] - Initial value (required if property is required)
|
|
172
|
+
* @param {boolean} [opts.required] - Whether the property must have a value
|
|
173
|
+
* @param {boolean} [opts.writable=true] - Whether the property can be modified
|
|
174
|
+
* @param {string} [opts.resolveLanguage] - Language to use for value resolution (e.g. "literal")
|
|
175
|
+
* @param {string} [opts.getter] - Custom Prolog code for getting the property value
|
|
176
|
+
* @param {string} [opts.setter] - Custom Prolog code for setting the property value
|
|
177
|
+
* @param {boolean} [opts.local] - Whether the property should only be stored locally
|
|
178
|
+
*/
|
|
179
|
+
export declare function Optional(opts: PropertyOptions): <T>(target: T, key: keyof T) => void;
|
|
180
|
+
export interface FlagOptions {
|
|
181
|
+
/**
|
|
182
|
+
* The predicate of the property. All properties must have this option.
|
|
183
|
+
*/
|
|
184
|
+
through: string;
|
|
185
|
+
/**
|
|
186
|
+
* The value of the property.
|
|
187
|
+
*/
|
|
188
|
+
value: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Decorator for defining flags on model classes.
|
|
192
|
+
*
|
|
193
|
+
* @category Decorators
|
|
194
|
+
*
|
|
195
|
+
* @description
|
|
196
|
+
* A specialized property decorator for defining immutable type flags or markers on model instances.
|
|
197
|
+
* Flags are always required properties with a fixed value that cannot be changed after creation.
|
|
198
|
+
*
|
|
199
|
+
* Common uses for flags:
|
|
200
|
+
* - Type discrimination between different kinds of models
|
|
201
|
+
* - Marking models with specific capabilities or features
|
|
202
|
+
* - Versioning or compatibility markers
|
|
203
|
+
*
|
|
204
|
+
* Note: Use of Flag is discouraged unless you specifically need type-based filtering or
|
|
205
|
+
* discrimination between different kinds of models. For most cases, regular properties
|
|
206
|
+
* with @Property or @Optional are more appropriate.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* class Message extends Ad4mModel {
|
|
211
|
+
* // Type flag to identify message models
|
|
212
|
+
* @Flag({
|
|
213
|
+
* through: "ad4m://type",
|
|
214
|
+
* value: "ad4m://message"
|
|
215
|
+
* })
|
|
216
|
+
* type: string = "";
|
|
217
|
+
*
|
|
218
|
+
* // Version flag for compatibility
|
|
219
|
+
* @Flag({
|
|
220
|
+
* through: "ad4m://version",
|
|
221
|
+
* value: "1.0.0"
|
|
222
|
+
* })
|
|
223
|
+
* version: string = "";
|
|
224
|
+
*
|
|
225
|
+
* // Feature flag
|
|
226
|
+
* @Flag({
|
|
227
|
+
* through: "message://feature",
|
|
228
|
+
* value: "message://encrypted"
|
|
229
|
+
* })
|
|
230
|
+
* feature: string = "";
|
|
231
|
+
* }
|
|
232
|
+
*
|
|
233
|
+
* // Later you can query for specific types:
|
|
234
|
+
* const messages = await Message.query(perspective)
|
|
235
|
+
* .where({ type: "ad4m://message" })
|
|
236
|
+
* .run();
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* @param {FlagOptions} opts - Flag configuration
|
|
240
|
+
* @param {string} opts.through - The predicate URI for the flag
|
|
241
|
+
* @param {string} opts.value - The fixed value for the flag
|
|
242
|
+
*/
|
|
243
|
+
export declare function Flag(opts: FlagOptions): <T>(target: T, key: keyof T) => void;
|
|
244
|
+
interface WhereOptions {
|
|
245
|
+
isInstance?: any;
|
|
246
|
+
condition?: string;
|
|
247
|
+
}
|
|
248
|
+
export interface CollectionOptions {
|
|
249
|
+
/**
|
|
250
|
+
* The predicate of the property. All properties must have this option.
|
|
251
|
+
*/
|
|
252
|
+
through: string;
|
|
253
|
+
/**
|
|
254
|
+
* An object representing the WHERE clause of the query.
|
|
255
|
+
*/
|
|
256
|
+
where?: WhereOptions;
|
|
257
|
+
/**
|
|
258
|
+
* Indicates whether the property is stored locally in the perspective and not in the network. Useful for properties that are not meant to be shared with the network.
|
|
259
|
+
*/
|
|
260
|
+
local?: boolean;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Decorator for defining collections on model classes.
|
|
264
|
+
*
|
|
265
|
+
* @category Decorators
|
|
266
|
+
*
|
|
267
|
+
* @description
|
|
268
|
+
* Defines a property that represents a collection of values linked to the model instance.
|
|
269
|
+
* Collections are always arrays and support operations for adding, removing, and setting values.
|
|
270
|
+
*
|
|
271
|
+
* For each collection property, the following methods are automatically generated:
|
|
272
|
+
* - `addX(value)` - Add a value to the collection
|
|
273
|
+
* - `removeX(value)` - Remove a value from the collection
|
|
274
|
+
* - `setCollectionX(values)` - Replace all values in the collection
|
|
275
|
+
*
|
|
276
|
+
* Where X is the capitalized property name.
|
|
277
|
+
*
|
|
278
|
+
* Collections can be filtered using the `where` option to only include values that:
|
|
279
|
+
* - Are instances of a specific model class
|
|
280
|
+
* - Match a custom Prolog condition
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```typescript
|
|
284
|
+
* class Recipe extends Ad4mModel {
|
|
285
|
+
* // Basic collection of ingredients
|
|
286
|
+
* @Collection({
|
|
287
|
+
* through: "recipe://ingredient"
|
|
288
|
+
* })
|
|
289
|
+
* ingredients: string[] = [];
|
|
290
|
+
*
|
|
291
|
+
* // Collection that only includes instances of another model
|
|
292
|
+
* @Collection({
|
|
293
|
+
* through: "recipe://comment",
|
|
294
|
+
* where: { isInstance: Comment }
|
|
295
|
+
* })
|
|
296
|
+
* comments: string[] = [];
|
|
297
|
+
*
|
|
298
|
+
* // Collection with custom filter condition
|
|
299
|
+
* @Collection({
|
|
300
|
+
* through: "recipe://step",
|
|
301
|
+
* where: { condition: `triple(Target, "step://order", Order), Order < 3` }
|
|
302
|
+
* })
|
|
303
|
+
* firstSteps: string[] = [];
|
|
304
|
+
*
|
|
305
|
+
* // Local-only collection not shared with network
|
|
306
|
+
* @Collection({
|
|
307
|
+
* through: "recipe://note",
|
|
308
|
+
* local: true
|
|
309
|
+
* })
|
|
310
|
+
* privateNotes: string[] = [];
|
|
311
|
+
* }
|
|
312
|
+
*
|
|
313
|
+
* // Using the generated methods:
|
|
314
|
+
* const recipe = new Recipe(perspective);
|
|
315
|
+
* await recipe.addIngredients("ingredient://flour");
|
|
316
|
+
* await recipe.removeIngredients("ingredient://sugar");
|
|
317
|
+
* await recipe.setCollectionIngredients(["ingredient://butter", "ingredient://eggs"]);
|
|
318
|
+
* ```
|
|
319
|
+
*
|
|
320
|
+
* @param {CollectionOptions} opts - Collection configuration
|
|
321
|
+
* @param {string} opts.through - The predicate URI for collection links
|
|
322
|
+
* @param {WhereOptions} [opts.where] - Filter conditions for collection values
|
|
323
|
+
* @param {any} [opts.where.isInstance] - Model class to filter instances by
|
|
324
|
+
* @param {string} [opts.where.condition] - Custom Prolog condition for filtering
|
|
325
|
+
* @param {boolean} [opts.local] - Whether collection links are stored locally only
|
|
326
|
+
*/
|
|
327
|
+
export declare function Collection(opts: CollectionOptions): <T>(target: T, key: keyof T) => void;
|
|
328
|
+
export declare function makeRandomPrologAtom(length: number): string;
|
|
329
|
+
export interface ModelOptionsOptions {
|
|
330
|
+
/**
|
|
331
|
+
* The name of the entity.
|
|
332
|
+
*/
|
|
333
|
+
name: string;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Decorator for defining model classes in AD4M.
|
|
337
|
+
*
|
|
338
|
+
* @category Decorators
|
|
339
|
+
*
|
|
340
|
+
* @description
|
|
341
|
+
* The root decorator that must be applied to any class that represents a model in AD4M.
|
|
342
|
+
* It registers the class as a Social DNA (SDNA) subject class and provides the infrastructure
|
|
343
|
+
* for storing and retrieving instances.
|
|
344
|
+
*
|
|
345
|
+
* This decorator:
|
|
346
|
+
* - Registers the class with a unique name in the AD4M system
|
|
347
|
+
* - Generates the necessary SDNA code for the model's properties and collections
|
|
348
|
+
* - Enables the use of other model decorators (@Property, @Collection, etc.)
|
|
349
|
+
* - Provides static query methods through the Ad4mModel base class
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```typescript
|
|
353
|
+
* @ModelOptions({ name: "Recipe" })
|
|
354
|
+
* class Recipe extends Ad4mModel {
|
|
355
|
+
* @Property({
|
|
356
|
+
* through: "recipe://name",
|
|
357
|
+
* resolveLanguage: "literal"
|
|
358
|
+
* })
|
|
359
|
+
* name: string = "";
|
|
360
|
+
*
|
|
361
|
+
* @Collection({ through: "recipe://ingredient" })
|
|
362
|
+
* ingredients: string[] = [];
|
|
363
|
+
*
|
|
364
|
+
* // Static query methods from Ad4mModel:
|
|
365
|
+
* static async findByName(perspective: PerspectiveProxy, name: string) {
|
|
366
|
+
* return Recipe.query(perspective)
|
|
367
|
+
* .where({ name })
|
|
368
|
+
* .run();
|
|
369
|
+
* }
|
|
370
|
+
* }
|
|
371
|
+
*
|
|
372
|
+
* // Using the model:
|
|
373
|
+
* const recipe = new Recipe(perspective);
|
|
374
|
+
* recipe.name = "Chocolate Cake";
|
|
375
|
+
* await recipe.save();
|
|
376
|
+
*
|
|
377
|
+
* // Querying instances:
|
|
378
|
+
* const recipes = await Recipe.query(perspective)
|
|
379
|
+
* .where({ name: "Chocolate Cake" })
|
|
380
|
+
* .run();
|
|
381
|
+
*
|
|
382
|
+
* // Using with PerspectiveProxy:
|
|
383
|
+
* await perspective.ensureSDNASubjectClass(Recipe);
|
|
384
|
+
* ```
|
|
385
|
+
*
|
|
386
|
+
* @param {ModelOptionsOptions} opts - Model configuration
|
|
387
|
+
* @param {string} opts.name - Unique name for the model class in AD4M
|
|
388
|
+
*/
|
|
389
|
+
export declare function ModelOptions(opts: ModelOptionsOptions): (target: any) => void;
|
|
390
|
+
/**
|
|
391
|
+
* Decorator for defining required and writable properties on model classes.
|
|
392
|
+
*
|
|
393
|
+
* @category Decorators
|
|
394
|
+
*
|
|
395
|
+
* @description
|
|
396
|
+
* A convenience decorator that defines a required property that must have an initial value and is writable by default.
|
|
397
|
+
* This is equivalent to using @Optional with `required: true` and `writable: true`.
|
|
398
|
+
*
|
|
399
|
+
* Properties defined with this decorator:
|
|
400
|
+
* - Must have a value (required)
|
|
401
|
+
* - Can be modified after creation (writable)
|
|
402
|
+
* - Default to "literal://string:uninitialized" if no initial value is provided
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* class User extends Ad4mModel {
|
|
407
|
+
* // Basic required property with default initial value
|
|
408
|
+
* @Property({
|
|
409
|
+
* through: "user://name"
|
|
410
|
+
* })
|
|
411
|
+
* name: string = "";
|
|
412
|
+
*
|
|
413
|
+
* // Required property with custom initial value
|
|
414
|
+
* @Property({
|
|
415
|
+
* through: "user://status",
|
|
416
|
+
* initial: "user://active"
|
|
417
|
+
* })
|
|
418
|
+
* status: string = "";
|
|
419
|
+
*
|
|
420
|
+
* // Required property with literal resolution
|
|
421
|
+
* @Property({
|
|
422
|
+
* through: "user://bio",
|
|
423
|
+
* resolveLanguage: "literal"
|
|
424
|
+
* })
|
|
425
|
+
* bio: string = "";
|
|
426
|
+
*
|
|
427
|
+
* // Required property with custom getter/setter
|
|
428
|
+
* @Property({
|
|
429
|
+
* through: "user://age",
|
|
430
|
+
* getter: `triple(Base, "user://birthYear", Year), Value is 2024 - Year`,
|
|
431
|
+
* setter: `Year is 2024 - Value, Actions = [{"action": "setSingleTarget", "source": "this", "predicate": "user://birthYear", "target": Year}]`
|
|
432
|
+
* })
|
|
433
|
+
* age: number = 0;
|
|
434
|
+
* }
|
|
435
|
+
* ```
|
|
436
|
+
*
|
|
437
|
+
* @param {PropertyOptions} opts - Property configuration
|
|
438
|
+
* @param {string} opts.through - The predicate URI for the property
|
|
439
|
+
* @param {string} [opts.initial] - Initial value (defaults to "literal://string:uninitialized")
|
|
440
|
+
* @param {string} [opts.resolveLanguage] - Language to use for value resolution (e.g. "literal")
|
|
441
|
+
* @param {string} [opts.getter] - Custom Prolog code for getting the property value
|
|
442
|
+
* @param {string} [opts.setter] - Custom Prolog code for setting the property value
|
|
443
|
+
* @param {boolean} [opts.local] - Whether the property should only be stored locally
|
|
444
|
+
*/
|
|
445
|
+
export declare function Property(opts: PropertyOptions): <T>(target: T, key: keyof T) => void;
|
|
446
|
+
/**
|
|
447
|
+
* Decorator for defining read-only properties on model classes.
|
|
448
|
+
*
|
|
449
|
+
* @category Decorators
|
|
450
|
+
*
|
|
451
|
+
* @description
|
|
452
|
+
* A convenience decorator that defines a property that can only be read and cannot be modified after initialization.
|
|
453
|
+
* This is equivalent to using @Optional with `writable: false`.
|
|
454
|
+
*
|
|
455
|
+
* Read-only properties are ideal for:
|
|
456
|
+
* - Computed or derived values
|
|
457
|
+
* - Properties that should never change after creation
|
|
458
|
+
* - Properties that are set by the system
|
|
459
|
+
* - Properties that represent immutable data
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```typescript
|
|
463
|
+
* class Post extends Ad4mModel {
|
|
464
|
+
* // Read-only property with custom getter for computed value
|
|
465
|
+
* @ReadOnly({
|
|
466
|
+
* through: "post://likes",
|
|
467
|
+
* getter: `findall(User, triple(Base, "post://liked_by", User), Users), length(Users, Value)`
|
|
468
|
+
* })
|
|
469
|
+
* likeCount: number = 0;
|
|
470
|
+
*
|
|
471
|
+
* // Read-only property for creation timestamp
|
|
472
|
+
* @ReadOnly({
|
|
473
|
+
* through: "post://created_at",
|
|
474
|
+
* initial: new Date().toISOString()
|
|
475
|
+
* })
|
|
476
|
+
* createdAt: string = "";
|
|
477
|
+
*
|
|
478
|
+
* // Read-only property that resolves to a Literal
|
|
479
|
+
* @ReadOnly({
|
|
480
|
+
* through: "post://author",
|
|
481
|
+
* resolveLanguage: "literal"
|
|
482
|
+
* })
|
|
483
|
+
* author: string = "";
|
|
484
|
+
*
|
|
485
|
+
* // Read-only property for system-managed data
|
|
486
|
+
* @ReadOnly({
|
|
487
|
+
* through: "post://version",
|
|
488
|
+
* initial: "1.0.0"
|
|
489
|
+
* })
|
|
490
|
+
* version: string = "";
|
|
491
|
+
* }
|
|
492
|
+
* ```
|
|
493
|
+
*
|
|
494
|
+
* @param {PropertyOptions} opts - Property configuration
|
|
495
|
+
* @param {string} opts.through - The predicate URI for the property
|
|
496
|
+
* @param {string} [opts.initial] - Initial value (if property should have one)
|
|
497
|
+
* @param {string} [opts.resolveLanguage] - Language to use for value resolution (e.g. "literal")
|
|
498
|
+
* @param {string} [opts.getter] - Custom Prolog code for getting the property value
|
|
499
|
+
* @param {boolean} [opts.local] - Whether the property should only be stored locally
|
|
500
|
+
*/
|
|
501
|
+
export declare function ReadOnly(opts: PropertyOptions): <T>(target: T, key: keyof T) => void;
|
|
502
|
+
export {};
|