@coasys/ad4m 0.12.0-rc1-dev.1 → 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 +8 -1
- package/lib/index.cjs +13793 -12854
- package/lib/index.js +13782 -12851
- package/lib/src/Ad4mClient.test.d.ts +1 -0
- package/lib/src/Ad4mClient.test.js +1204 -0
- package/lib/src/Literal.test.d.ts +1 -0
- package/lib/src/Literal.test.js +41 -0
- package/lib/src/model/Ad4mModel.d.ts +528 -101
- package/lib/src/model/Ad4mModel.js +1670 -748
- package/lib/src/model/Ad4mModel.test.js +140 -156
- package/lib/src/model/Subject.d.ts +3 -3
- package/lib/src/model/Subject.js +25 -25
- package/lib/src/model/decorators.d.ts +259 -247
- package/lib/src/model/decorators.js +379 -422
- package/lib/src/model/mutation.d.ts +81 -0
- package/lib/src/model/mutation.js +317 -0
- package/lib/src/model/parentUtils.d.ts +32 -0
- package/lib/src/model/parentUtils.js +64 -0
- package/lib/src/model/prolog/generatePrologFacts.d.ts +36 -0
- package/lib/src/model/prolog/generatePrologFacts.js +139 -0
- package/lib/src/model/prolog/index.d.ts +1 -0
- package/lib/src/model/prolog/index.js +1 -0
- package/lib/src/model/query/ModelQueryBuilder.d.ts +82 -0
- package/lib/src/model/query/ModelQueryBuilder.js +115 -0
- package/lib/src/model/query/QueryBuilder.d.ts +101 -0
- package/lib/src/model/query/QueryBuilder.js +193 -0
- package/lib/src/model/query/SurrealQueryBuilder.d.ts +48 -0
- package/lib/src/model/query/SurrealQueryBuilder.js +371 -0
- package/lib/src/model/query/fetchInstance.d.ts +24 -0
- package/lib/src/model/query/fetchInstance.js +144 -0
- package/lib/src/model/query/hydration.d.ts +54 -0
- package/lib/src/model/query/hydration.js +214 -0
- package/lib/src/model/query/operations.d.ts +59 -0
- package/lib/src/model/query/operations.js +384 -0
- package/lib/src/model/query/snapshot.d.ts +59 -0
- package/lib/src/model/query/snapshot.js +106 -0
- package/lib/src/model/query/surrealCompiler.d.ts +42 -0
- package/lib/src/model/query/surrealCompiler.js +304 -0
- package/lib/src/model/schema/fromJSONSchema.d.ts +67 -0
- package/lib/src/model/schema/fromJSONSchema.js +264 -0
- package/lib/src/model/schema/metadata.d.ts +15 -0
- package/lib/src/model/schema/metadata.js +112 -0
- package/lib/src/model/subscription.d.ts +47 -0
- package/lib/src/model/subscription.js +231 -0
- package/lib/src/model/transaction.d.ts +27 -0
- package/lib/src/model/transaction.js +32 -0
- package/lib/src/model/types.d.ts +195 -0
- package/lib/src/model/types.js +8 -0
- package/lib/src/model/util.d.ts +6 -6
- package/lib/src/model/util.js +22 -22
- package/lib/src/neighbourhood/NeighbourhoodClient.js +31 -12
- package/lib/src/perspectives/PerspectiveProxy.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveProxy.js +63 -51
- package/lib/src/shacl/SHACLShape.d.ts +9 -0
- package/lib/src/shacl/SHACLShape.js +28 -4
- 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/package.json +20 -24
- package/src/model/Ad4mModel.test.ts +132 -149
- package/src/model/Ad4mModel.ts +1930 -784
- package/src/model/Subject.ts +24 -24
- package/src/model/decorators.ts +626 -482
- package/src/model/util.ts +22 -22
- package/src/neighbourhood/NeighbourhoodClient.ts +32 -16
- package/src/perspectives/PerspectiveProxy.ts +69 -55
- package/src/shacl/SHACLShape.ts +33 -4
package/src/model/Subject.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
|
|
2
|
-
import {
|
|
2
|
+
import { relationSetterToName, relationToAdderName, relationToRemoverName, relationToSetterName, propertyNameToSetterName } from "./util";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Represents a subject in the perspective.
|
|
6
|
-
* A subject is an entity that has properties and
|
|
6
|
+
* A subject is an entity that has properties and relations.
|
|
7
7
|
*/
|
|
8
8
|
export class Subject {
|
|
9
9
|
#baseExpression: string;
|
|
@@ -30,9 +30,9 @@ export class Subject {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* Initializes the subject by validating it and defining its properties and
|
|
33
|
+
* Initializes the subject by validating it and defining its properties and relations dynamically.
|
|
34
34
|
*
|
|
35
|
-
* NOTE: This method should be called before using the subject. All the properties and
|
|
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
36
|
*/
|
|
37
37
|
async init() {
|
|
38
38
|
// Check if the subject is a valid instance of the subject class
|
|
@@ -41,7 +41,7 @@ export class Subject {
|
|
|
41
41
|
throw `Not a valid subject instance of ${this.#subjectClassName} for ${this.#baseExpression}`
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
// Define properties and
|
|
44
|
+
// Define properties and relations dynamically
|
|
45
45
|
let results = await this.#perspective.infer(`subject_class("${this.#subjectClassName}", C), property(C, Property)`)
|
|
46
46
|
let properties = results.map(result => result.Property)
|
|
47
47
|
|
|
@@ -82,35 +82,35 @@ export class Subject {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
// Define
|
|
85
|
+
// Define relations
|
|
86
86
|
let results2 = await this.#perspective.infer(`subject_class("${this.#subjectClassName}", C), collection(C, Collection)`)
|
|
87
87
|
if(!results2) results2 = []
|
|
88
|
-
let
|
|
88
|
+
let relations = results2.map(result => result.Collection)
|
|
89
89
|
|
|
90
|
-
for(let c of
|
|
90
|
+
for(let c of relations) {
|
|
91
91
|
Object.defineProperty(this, c, {
|
|
92
92
|
configurable: true,
|
|
93
93
|
get: async () => {
|
|
94
94
|
// Use SurrealDB for data queries
|
|
95
95
|
try {
|
|
96
|
-
return await this.#perspective.
|
|
96
|
+
return await this.#perspective.getRelationValuesViaSurreal(this.#baseExpression, this.#subjectClassName, c);
|
|
97
97
|
} catch (err) {
|
|
98
|
-
console.warn(`Failed to get
|
|
98
|
+
console.warn(`Failed to get relation ${c} via SurrealDB:`, err);
|
|
99
99
|
return [];
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
})
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
// Define
|
|
105
|
+
// Define relation adders
|
|
106
106
|
let adders = await this.#perspective.infer(`subject_class("${this.#subjectClassName}", C), collection_adder(C, Collection, Adder)`)
|
|
107
107
|
if(!adders) adders = []
|
|
108
108
|
|
|
109
109
|
for(let adder of adders) {
|
|
110
110
|
if(adder) {
|
|
111
|
-
const
|
|
111
|
+
const relation = adder.Collection
|
|
112
112
|
const actions = eval(adder.Adder)
|
|
113
|
-
this[
|
|
113
|
+
this[relationToAdderName(relation)] = async (value: any) => {
|
|
114
114
|
if (Array.isArray(value)) {
|
|
115
115
|
await Promise.all(value.map(v => this.#perspective.executeAction(actions, this.#baseExpression, [{name: "value", value: v}])))
|
|
116
116
|
} else {
|
|
@@ -120,15 +120,15 @@ export class Subject {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
// Define
|
|
123
|
+
// Define relation removers
|
|
124
124
|
let removers = await this.#perspective.infer(`subject_class("${this.#subjectClassName}", C), collection_remover(C, Collection, Remover)`)
|
|
125
125
|
if(!removers) removers = []
|
|
126
126
|
|
|
127
127
|
for(let remover of removers) {
|
|
128
128
|
if(remover) {
|
|
129
|
-
const
|
|
129
|
+
const relation = remover.Collection
|
|
130
130
|
const actions = eval(remover.Remover)
|
|
131
|
-
this[
|
|
131
|
+
this[relationToRemoverName(relation)] = async (value: any) => {
|
|
132
132
|
if (Array.isArray(value)) {
|
|
133
133
|
await Promise.all(value.map(v => this.#perspective.executeAction(actions, this.#baseExpression, [{name: "value", value: v}])))
|
|
134
134
|
} else {
|
|
@@ -138,15 +138,15 @@ export class Subject {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
// Define
|
|
142
|
-
let
|
|
143
|
-
if(!
|
|
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
144
|
|
|
145
|
-
for(let
|
|
146
|
-
if(
|
|
147
|
-
const
|
|
148
|
-
const actions = eval(
|
|
149
|
-
this[
|
|
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
150
|
if (Array.isArray(value)) {
|
|
151
151
|
await this.#perspective.executeAction(actions, this.#baseExpression, value.map(v => ({name: "value", value: v})))
|
|
152
152
|
} else {
|