@coasys/ad4m 0.12.0-rc1-dev.2 → 0.12.0-rc1-dev.3
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/jest.config.js +10 -3
- package/lib/index.cjs +6872 -5886
- package/lib/index.js +6868 -5874
- package/lib/src/Ad4mClient.d.ts +9 -16
- package/lib/src/Ad4mClient.js +46 -25
- package/lib/src/Literal.d.ts +1 -2
- package/lib/src/Literal.js +38 -35
- package/lib/src/SmartLiteral.d.ts +1 -2
- package/lib/src/SmartLiteral.js +30 -15
- package/lib/src/agent/AgentClient.d.ts +1 -4
- package/lib/src/agent/AgentClient.js +79 -99
- package/lib/src/ai/AIClient.d.ts +1 -2
- package/lib/src/ai/AIClient.js +224 -220
- package/lib/src/expression/ExpressionClient.d.ts +1 -1
- package/lib/src/expression/ExpressionClient.js +73 -86
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/language/LanguageClient.d.ts +1 -1
- package/lib/src/language/LanguageClient.js +52 -52
- package/lib/src/model/Ad4mModel.d.ts +1351 -144
- package/lib/src/model/Ad4mModel.js +3737 -228
- package/lib/src/model/Ad4mModel.test.js +522 -979
- package/lib/src/model/Subject.d.ts +3 -3
- package/lib/src/model/Subject.js +25 -25
- package/lib/src/model/decorators.d.ts +444 -100
- package/lib/src/model/decorators.js +686 -321
- package/lib/src/model/util.d.ts +6 -6
- package/lib/src/model/util.js +24 -24
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +1 -5
- package/lib/src/neighbourhood/NeighbourhoodClient.js +179 -242
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +1 -2
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +28 -13
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +5 -1
- package/lib/src/perspectives/PerspectiveClient.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveClient.js +240 -316
- package/lib/src/perspectives/PerspectiveProxy.d.ts +99 -61
- package/lib/src/perspectives/PerspectiveProxy.js +485 -832
- package/lib/src/runtime/RuntimeClient.d.ts +1 -5
- package/lib/src/runtime/RuntimeClient.js +238 -412
- package/lib/src/shacl/SHACLFlow.test.js +105 -164
- package/lib/src/shacl/SHACLShape.d.ts +12 -17
- package/lib/src/shacl/SHACLShape.js +115 -128
- package/lib/src/shacl/SHACLShape.test.js +176 -244
- package/lib/src/shims/reflect-metadata.d.ts +0 -0
- package/lib/src/shims/type-graphql.d.ts +32 -0
- package/lib/src/src/Ad4mClient.d.ts +28 -0
- package/lib/src/src/Address.d.ts +1 -0
- package/lib/src/src/DID.d.ts +1 -0
- package/lib/src/src/Exception.d.ts +7 -0
- package/lib/src/src/Literal.d.ts +7 -0
- package/lib/src/src/PubSub.d.ts +17 -0
- package/lib/src/src/SmartLiteral.d.ts +12 -0
- package/lib/src/src/agent/Agent.d.ts +110 -0
- package/lib/src/src/agent/AgentClient.d.ts +62 -0
- package/lib/src/src/agent/AgentResolver.d.ts +30 -0
- package/lib/src/src/agent/AgentStatus.d.ts +8 -0
- package/lib/src/src/ai/AIClient.d.ts +32 -0
- package/lib/src/src/ai/AIResolver.d.ts +75 -0
- package/lib/src/src/ai/Tasks.d.ts +37 -0
- package/lib/src/src/buildSchema.d.ts +1 -0
- package/lib/src/src/expression/Expression.d.ts +28 -0
- package/lib/src/src/expression/ExpressionClient.d.ts +13 -0
- package/lib/src/src/expression/ExpressionRef.d.ts +9 -0
- package/lib/src/src/expression/ExpressionResolver.d.ts +10 -0
- package/lib/src/src/index.d.ts +35 -0
- package/lib/src/src/jestSetup.d.ts +1 -0
- package/lib/src/src/language/Icon.d.ts +4 -0
- package/lib/src/src/language/Language.d.ts +206 -0
- package/lib/src/src/language/LanguageClient.d.ts +17 -0
- package/lib/src/src/language/LanguageContext.d.ts +37 -0
- package/lib/src/src/language/LanguageHandle.d.ts +9 -0
- package/lib/src/src/language/LanguageMeta.d.ts +35 -0
- package/lib/src/src/language/LanguageRef.d.ts +6 -0
- package/lib/src/src/language/LanguageResolver.d.ts +19 -0
- package/lib/src/src/links/Links.d.ts +39 -0
- package/lib/src/src/links/Links.test.d.ts +1 -0
- package/lib/src/src/model/Ad4mModel.d.ts +1438 -0
- package/lib/src/src/model/Ad4mModel.test.d.ts +1 -0
- package/lib/src/src/model/Subject.d.ts +25 -0
- package/lib/src/src/model/decorators.d.ts +545 -0
- package/lib/src/src/model/util.d.ts +12 -0
- package/lib/src/src/neighbourhood/Neighbourhood.d.ts +10 -0
- package/lib/src/src/neighbourhood/NeighbourhoodClient.d.ts +25 -0
- package/lib/src/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -0
- package/lib/src/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
- package/lib/src/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -0
- package/lib/src/src/perspectives/LinkQuery.d.ts +11 -0
- package/lib/src/src/perspectives/Perspective.d.ts +38 -0
- package/lib/src/src/perspectives/Perspective.test.d.ts +1 -0
- package/lib/src/src/perspectives/PerspectiveClient.d.ts +97 -0
- package/lib/src/src/perspectives/PerspectiveDiff.d.ts +9 -0
- package/lib/src/src/perspectives/PerspectiveHandle.d.ts +18 -0
- package/lib/src/src/perspectives/PerspectiveProxy.d.ts +865 -0
- package/lib/src/src/perspectives/PerspectiveResolver.d.ts +57 -0
- package/lib/src/src/runtime/RuntimeClient.d.ts +56 -0
- package/lib/src/src/runtime/RuntimeResolver.d.ts +132 -0
- package/lib/src/src/shacl/SHACLFlow.d.ts +171 -0
- package/lib/src/src/shacl/SHACLFlow.test.d.ts +1 -0
- package/lib/src/src/shacl/SHACLShape.d.ts +117 -0
- package/lib/src/src/shacl/SHACLShape.test.d.ts +1 -0
- package/lib/src/src/typeDefs.d.ts +1 -0
- package/lib/src/src/unwrapApolloResult.d.ts +2 -0
- package/lib/src/src/utils.d.ts +25 -0
- package/lib/src/utils.d.ts +0 -8
- package/lib/src/utils.js +7 -21
- package/package.json +15 -14
- package/src/Ad4mClient.test.ts +1315 -1564
- package/src/Ad4mClient.ts +54 -55
- package/src/Literal.test.ts +26 -45
- package/src/Literal.ts +66 -82
- package/src/SmartLiteral.ts +58 -74
- package/src/agent/AgentClient.ts +99 -144
- package/src/ai/AIClient.ts +359 -409
- package/src/expression/ExpressionClient.ts +96 -142
- package/src/index.ts +1 -1
- package/src/language/LanguageClient.ts +113 -137
- package/src/model/Ad4mModel.test.ts +616 -1114
- package/src/model/Ad4mModel.ts +4361 -451
- package/src/model/Subject.ts +159 -0
- package/src/model/decorators.ts +1168 -667
- package/src/model/util.ts +54 -53
- package/src/neighbourhood/NeighbourhoodClient.ts +266 -392
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +7 -3
- package/src/neighbourhood/NeighbourhoodProxy.ts +40 -58
- package/src/perspectives/PerspectiveClient.ts +540 -779
- package/src/perspectives/PerspectiveProxy.ts +2067 -2860
- package/src/runtime/RuntimeClient.ts +476 -775
- package/src/shacl/SHACLFlow.test.ts +129 -196
- package/src/shacl/SHACLShape.test.ts +190 -284
- package/src/shacl/SHACLShape.ts +200 -224
- package/src/utils.ts +17 -31
- package/tsconfig.json +10 -9
- package/src/model/IMPROVEMENTS.md +0 -482
- package/src/model/PREDICATE_COLLISION_FIX.md +0 -651
- package/src/model/README.md +0 -317
- package/src/model/SHACL_MUTATION_DECOUPLING.md +0 -356
- package/src/model/SUBSCRIPTION_STRATEGY.md +0 -317
- package/src/model/TC39_STAGE_3_DECORATORS.md +0 -609
- package/src/model/mutation.ts +0 -461
- package/src/model/parentUtils.ts +0 -91
- package/src/model/prolog/generatePrologFacts.ts +0 -176
- package/src/model/prolog/index.ts +0 -1
- package/src/model/query/ModelQueryBuilder.ts +0 -173
- package/src/model/query/fetchInstance.ts +0 -181
- package/src/model/query/hydration.ts +0 -273
- package/src/model/query/operations.ts +0 -510
- package/src/model/query/snapshot.ts +0 -126
- package/src/model/query/surrealCompiler.ts +0 -376
- package/src/model/schema/fromJSONSchema.ts +0 -411
- package/src/model/schema/metadata.ts +0 -148
- package/src/model/subscription.ts +0 -307
- package/src/model/transaction.ts +0 -60
- package/src/model/types.ts +0 -207
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
|
|
2
|
+
import { relationSetterToName, relationToAdderName, relationToRemoverName, relationToSetterName, propertyNameToSetterName } from "./util";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents a subject in the perspective.
|
|
6
|
+
* A subject is an entity that has properties and relations.
|
|
7
|
+
*/
|
|
8
|
+
export class Subject {
|
|
9
|
+
#baseExpression: string;
|
|
10
|
+
#subjectClassName: string;
|
|
11
|
+
#perspective: PerspectiveProxy
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Constructs a new subject.
|
|
15
|
+
* @param perspective - The perspective that the subject belongs to.
|
|
16
|
+
* @param baseExpression - The base expression of the subject.
|
|
17
|
+
* @param subjectClassName - The class name of the subject.
|
|
18
|
+
*/
|
|
19
|
+
constructor(perspective: PerspectiveProxy, baseExpression: string, subjectClassName: string) {
|
|
20
|
+
this.#baseExpression = baseExpression
|
|
21
|
+
this.#subjectClassName = subjectClassName
|
|
22
|
+
this.#perspective = perspective
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Gets the base expression of the subject.
|
|
27
|
+
*/
|
|
28
|
+
get baseExpression() {
|
|
29
|
+
return this.#baseExpression
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Initializes the subject by validating it and defining its properties and relations dynamically.
|
|
34
|
+
*
|
|
35
|
+
* NOTE: This method should be called before using the subject. All the properties and relations of the subject defined are not type-checked.
|
|
36
|
+
*/
|
|
37
|
+
async init() {
|
|
38
|
+
// Check if the subject is a valid instance of the subject class
|
|
39
|
+
let isInstance = await this.#perspective.isSubjectInstance(this.#baseExpression, this.#subjectClassName)
|
|
40
|
+
if(!isInstance) {
|
|
41
|
+
throw `Not a valid subject instance of ${this.#subjectClassName} for ${this.#baseExpression}`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Define properties and relations dynamically
|
|
45
|
+
let results = await this.#perspective.infer(`subject_class("${this.#subjectClassName}", C), property(C, Property)`)
|
|
46
|
+
let properties = results.map(result => result.Property)
|
|
47
|
+
|
|
48
|
+
for(let p of properties) {
|
|
49
|
+
const resolveExpressionURI = await this.#perspective.infer(`subject_class("${this.#subjectClassName}", C), property_resolve(C, "${p}")`)
|
|
50
|
+
Object.defineProperty(this, p, {
|
|
51
|
+
configurable: true,
|
|
52
|
+
get: async () => {
|
|
53
|
+
// Use SurrealDB for data queries
|
|
54
|
+
try {
|
|
55
|
+
return await this.#perspective.getPropertyValueViaSurreal(this.#baseExpression, this.#subjectClassName, p);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.warn(`Failed to get property ${p} via SurrealDB:`, err);
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Define setters
|
|
65
|
+
const setters = await this.#perspective.infer(`subject_class("${this.#subjectClassName}", C), property_setter(C, Property, Setter)`)
|
|
66
|
+
|
|
67
|
+
for(let setter of (setters ? setters : [])) {
|
|
68
|
+
if(setter) {
|
|
69
|
+
const property = setter.Property
|
|
70
|
+
const actions = eval(setter.Setter)
|
|
71
|
+
const resolveLanguageResults = await this.#perspective.infer(`subject_class("${this.#subjectClassName}", C), property_resolve_language(C, "${property}", Language)`)
|
|
72
|
+
let resolveLanguage
|
|
73
|
+
if(resolveLanguageResults && resolveLanguageResults.length > 0) {
|
|
74
|
+
resolveLanguage = resolveLanguageResults[0].Language
|
|
75
|
+
}
|
|
76
|
+
this[propertyNameToSetterName(property)] = async (value: any) => {
|
|
77
|
+
if(resolveLanguage) {
|
|
78
|
+
value = await this.#perspective.createExpression(value, resolveLanguage)
|
|
79
|
+
}
|
|
80
|
+
await this.#perspective.executeAction(actions, this.#baseExpression, [{name: "value", value}])
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Define relations
|
|
86
|
+
let results2 = await this.#perspective.infer(`subject_class("${this.#subjectClassName}", C), collection(C, Collection)`)
|
|
87
|
+
if(!results2) results2 = []
|
|
88
|
+
let relations = results2.map(result => result.Collection)
|
|
89
|
+
|
|
90
|
+
for(let c of relations) {
|
|
91
|
+
Object.defineProperty(this, c, {
|
|
92
|
+
configurable: true,
|
|
93
|
+
get: async () => {
|
|
94
|
+
// Use SurrealDB for data queries
|
|
95
|
+
try {
|
|
96
|
+
return await this.#perspective.getRelationValuesViaSurreal(this.#baseExpression, this.#subjectClassName, c);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
console.warn(`Failed to get relation ${c} via SurrealDB:`, err);
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Define relation adders
|
|
106
|
+
let adders = await this.#perspective.infer(`subject_class("${this.#subjectClassName}", C), collection_adder(C, Collection, Adder)`)
|
|
107
|
+
if(!adders) adders = []
|
|
108
|
+
|
|
109
|
+
for(let adder of adders) {
|
|
110
|
+
if(adder) {
|
|
111
|
+
const relation = adder.Collection
|
|
112
|
+
const actions = eval(adder.Adder)
|
|
113
|
+
this[relationToAdderName(relation)] = async (value: any) => {
|
|
114
|
+
if (Array.isArray(value)) {
|
|
115
|
+
await Promise.all(value.map(v => this.#perspective.executeAction(actions, this.#baseExpression, [{name: "value", value: v}])))
|
|
116
|
+
} else {
|
|
117
|
+
await this.#perspective.executeAction(actions, this.#baseExpression, [{name: "value", value}])
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Define relation removers
|
|
124
|
+
let removers = await this.#perspective.infer(`subject_class("${this.#subjectClassName}", C), collection_remover(C, Collection, Remover)`)
|
|
125
|
+
if(!removers) removers = []
|
|
126
|
+
|
|
127
|
+
for(let remover of removers) {
|
|
128
|
+
if(remover) {
|
|
129
|
+
const relation = remover.Collection
|
|
130
|
+
const actions = eval(remover.Remover)
|
|
131
|
+
this[relationToRemoverName(relation)] = async (value: any) => {
|
|
132
|
+
if (Array.isArray(value)) {
|
|
133
|
+
await Promise.all(value.map(v => this.#perspective.executeAction(actions, this.#baseExpression, [{name: "value", value: v}])))
|
|
134
|
+
} else {
|
|
135
|
+
await this.#perspective.executeAction(actions, this.#baseExpression, [{name: "value", value}])
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Define relation setters
|
|
142
|
+
let relationSetters = await this.#perspective.infer(`subject_class("${this.#subjectClassName}", C), collection_setter(C, Collection, Setter)`)
|
|
143
|
+
if(!relationSetters) relationSetters = []
|
|
144
|
+
|
|
145
|
+
for(let relationSetter of relationSetters) {
|
|
146
|
+
if(relationSetter) {
|
|
147
|
+
const relation = relationSetter.Collection
|
|
148
|
+
const actions = eval(relationSetter.Setter)
|
|
149
|
+
this[relationToSetterName(relation)] = async (value: any) => {
|
|
150
|
+
if (Array.isArray(value)) {
|
|
151
|
+
await this.#perspective.executeAction(actions, this.#baseExpression, value.map(v => ({name: "value", value: v})))
|
|
152
|
+
} else {
|
|
153
|
+
await this.#perspective.executeAction(actions, this.#baseExpression, [{name: "value", value}])
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|