@coasys/ad4m 0.9.0-prerelease → 0.9.0-rc2
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/README.md +2 -2
- package/lib/index.cjs +228 -18
- package/lib/index.js +225 -15
- package/lib/src/perspectives/PerspectiveHandle.d.ts +6 -5
- package/lib/src/perspectives/PerspectiveHandle.js +6 -5
- package/lib/src/perspectives/PerspectiveProxy.d.ts +5 -0
- package/lib/src/perspectives/PerspectiveProxy.js +5 -0
- package/lib/src/subject/SDNADecorators.d.ts +152 -9
- package/lib/src/subject/SDNADecorators.js +115 -5
- package/lib/src/subject/Subject.d.ts +18 -0
- package/lib/src/subject/Subject.js +25 -1
- package/lib/src/subject/SubjectEntity.d.ts +71 -0
- package/lib/src/subject/SubjectEntity.js +73 -3
- package/package.json +4 -2
- package/src/perspectives/PerspectiveHandle.ts +6 -6
- package/src/perspectives/PerspectiveProxy.ts +5 -0
- package/src/subject/SDNADecorators.ts +196 -19
- package/src/subject/Subject.ts +26 -4
- package/src/subject/SubjectEntity.ts +80 -3
package/README.md
CHANGED
|
@@ -14,8 +14,8 @@ on the user's machine.
|
|
|
14
14
|
|
|
15
15
|
The easiest way to get that is to use ad4m-cli:
|
|
16
16
|
```sh
|
|
17
|
-
|
|
18
|
-
ad4m
|
|
17
|
+
cargo install ad4m
|
|
18
|
+
ad4m-executor run
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
Then use `Ad4mClient` to connect to and work with the running ad4m-executor like this:
|
package/lib/index.cjs
CHANGED
|
@@ -4419,7 +4419,17 @@ var __classPrivateFieldGet$a = (undefined && undefined.__classPrivateFieldGet) |
|
|
|
4419
4419
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
4420
4420
|
};
|
|
4421
4421
|
var _Subject_baseExpression, _Subject_subjectClass, _Subject_perspective;
|
|
4422
|
+
/**
|
|
4423
|
+
* Represents a subject in the perspective.
|
|
4424
|
+
* A subject is an entity that has properties and collections.
|
|
4425
|
+
*/
|
|
4422
4426
|
class Subject {
|
|
4427
|
+
/**
|
|
4428
|
+
* Constructs a new subject.
|
|
4429
|
+
* @param perspective - The perspective that the subject belongs to.
|
|
4430
|
+
* @param baseExpression - The base expression of the subject.
|
|
4431
|
+
* @param subjectClass - The class of the subject.
|
|
4432
|
+
*/
|
|
4423
4433
|
constructor(perspective, baseExpression, subjectClass) {
|
|
4424
4434
|
_Subject_baseExpression.set(this, void 0);
|
|
4425
4435
|
_Subject_subjectClass.set(this, void 0);
|
|
@@ -4428,14 +4438,24 @@ class Subject {
|
|
|
4428
4438
|
__classPrivateFieldSet$a(this, _Subject_subjectClass, subjectClass, "f");
|
|
4429
4439
|
__classPrivateFieldSet$a(this, _Subject_perspective, perspective, "f");
|
|
4430
4440
|
}
|
|
4441
|
+
/**
|
|
4442
|
+
* Gets the base expression of the subject.
|
|
4443
|
+
*/
|
|
4431
4444
|
get baseExpression() {
|
|
4432
4445
|
return __classPrivateFieldGet$a(this, _Subject_baseExpression, "f");
|
|
4433
4446
|
}
|
|
4447
|
+
/**
|
|
4448
|
+
* Initializes the subject by validating it and defining its properties and collections dynamically.
|
|
4449
|
+
*
|
|
4450
|
+
* NOTE: This method should be called before using the subject. All the properties and collections of the subject defined are not type-checked.
|
|
4451
|
+
*/
|
|
4434
4452
|
async init() {
|
|
4453
|
+
// Check if the subject is a valid instance of the subject class
|
|
4435
4454
|
let isInstance = await __classPrivateFieldGet$a(this, _Subject_perspective, "f").isSubjectInstance(__classPrivateFieldGet$a(this, _Subject_baseExpression, "f"), __classPrivateFieldGet$a(this, _Subject_subjectClass, "f"));
|
|
4436
4455
|
if (!isInstance) {
|
|
4437
4456
|
throw `Not a valid subject instance of ${__classPrivateFieldGet$a(this, _Subject_subjectClass, "f")} for ${__classPrivateFieldGet$a(this, _Subject_baseExpression, "f")}`;
|
|
4438
4457
|
}
|
|
4458
|
+
// Define properties and collections dynamically
|
|
4439
4459
|
let results = await __classPrivateFieldGet$a(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet$a(this, _Subject_subjectClass, "f")}", C), property(C, Property)`);
|
|
4440
4460
|
let properties = results.map(result => result.Property);
|
|
4441
4461
|
for (let p of properties) {
|
|
@@ -4478,8 +4498,8 @@ class Subject {
|
|
|
4478
4498
|
}
|
|
4479
4499
|
});
|
|
4480
4500
|
}
|
|
4501
|
+
// Define setters
|
|
4481
4502
|
const setters = await __classPrivateFieldGet$a(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet$a(this, _Subject_subjectClass, "f")}", C), property_setter(C, Property, Setter)`);
|
|
4482
|
-
//console.log("Subject setters: " + setters.map(setter => setter.Property))
|
|
4483
4503
|
for (let setter of (setters ? setters : [])) {
|
|
4484
4504
|
if (setter) {
|
|
4485
4505
|
const property = setter.Property;
|
|
@@ -4497,6 +4517,7 @@ class Subject {
|
|
|
4497
4517
|
};
|
|
4498
4518
|
}
|
|
4499
4519
|
}
|
|
4520
|
+
// Define collections
|
|
4500
4521
|
let results2 = await __classPrivateFieldGet$a(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet$a(this, _Subject_subjectClass, "f")}", C), collection(C, Collection)`);
|
|
4501
4522
|
if (!results2)
|
|
4502
4523
|
results2 = [];
|
|
@@ -4516,6 +4537,7 @@ class Subject {
|
|
|
4516
4537
|
}
|
|
4517
4538
|
});
|
|
4518
4539
|
}
|
|
4540
|
+
// Define collection adders
|
|
4519
4541
|
let adders = await __classPrivateFieldGet$a(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet$a(this, _Subject_subjectClass, "f")}", C), collection_adder(C, Collection, Adder)`);
|
|
4520
4542
|
if (!adders)
|
|
4521
4543
|
adders = [];
|
|
@@ -4533,6 +4555,7 @@ class Subject {
|
|
|
4533
4555
|
};
|
|
4534
4556
|
}
|
|
4535
4557
|
}
|
|
4558
|
+
// Define collection removers
|
|
4536
4559
|
let removers = await __classPrivateFieldGet$a(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet$a(this, _Subject_subjectClass, "f")}", C), collection_remover(C, Collection, Remover)`);
|
|
4537
4560
|
if (!removers)
|
|
4538
4561
|
removers = [];
|
|
@@ -4550,6 +4573,7 @@ class Subject {
|
|
|
4550
4573
|
};
|
|
4551
4574
|
}
|
|
4552
4575
|
}
|
|
4576
|
+
// Define collection setters
|
|
4553
4577
|
let collectionSetters = await __classPrivateFieldGet$a(this, _Subject_perspective, "f").infer(`subject_class("${__classPrivateFieldGet$a(this, _Subject_subjectClass, "f")}", C), collection_setter(C, Collection, Setter)`);
|
|
4554
4578
|
if (!collectionSetters)
|
|
4555
4579
|
collectionSetters = [];
|
|
@@ -4956,6 +4980,11 @@ class PerspectiveProxy {
|
|
|
4956
4980
|
}
|
|
4957
4981
|
return instances;
|
|
4958
4982
|
}
|
|
4983
|
+
/** Returns all subject proxies of the given subject class.
|
|
4984
|
+
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
4985
|
+
* with the properties of the subject class. In the latter case, all subject classes
|
|
4986
|
+
* that match the given properties will be used.
|
|
4987
|
+
*/
|
|
4959
4988
|
async getAllSubjectProxies(subjectClass) {
|
|
4960
4989
|
let classes = [];
|
|
4961
4990
|
if (typeof subjectClass === "string") {
|
|
@@ -7043,11 +7072,12 @@ var __metadata$1 = (undefined && undefined.__metadata) || function (k, v) {
|
|
|
7043
7072
|
};
|
|
7044
7073
|
exports.PerspectiveState = void 0;
|
|
7045
7074
|
(function (PerspectiveState) {
|
|
7046
|
-
PerspectiveState["Private"] = "
|
|
7047
|
-
PerspectiveState["
|
|
7048
|
-
PerspectiveState["
|
|
7049
|
-
PerspectiveState["
|
|
7050
|
-
PerspectiveState["
|
|
7075
|
+
PerspectiveState["Private"] = "PRIVATE";
|
|
7076
|
+
PerspectiveState["NeighboudhoodCreationInitiated"] = "NEIGHBOURHOOD_CREATION_INITIATED";
|
|
7077
|
+
PerspectiveState["NeighbourhoodJoinInitiated"] = "NEIGHBOURHOOD_JOIN_INITIATED";
|
|
7078
|
+
PerspectiveState["LinkLanguageFailedToInstall"] = "LINK_LANGUAGE_FAILED_TO_INSTALL";
|
|
7079
|
+
PerspectiveState["LinkLanguageInstalledButNotSynced"] = "LINK_LANGUAGE_INSTALLED_BUT_NOT_SYNCED";
|
|
7080
|
+
PerspectiveState["Synced"] = "SYNCED";
|
|
7051
7081
|
})(exports.PerspectiveState || (exports.PerspectiveState = {}));
|
|
7052
7082
|
// This type is used in the GraphQL interface to reference a mutable
|
|
7053
7083
|
// prespective that is implemented locally by the Ad4m runtime.
|
|
@@ -7202,11 +7232,30 @@ function addLink(source, predicate, target) {
|
|
|
7202
7232
|
function hasLink(predicate) {
|
|
7203
7233
|
return `triple(this, "${predicate}", _)`;
|
|
7204
7234
|
}
|
|
7205
|
-
|
|
7235
|
+
/**
|
|
7236
|
+
* Decorator for querying instances of a subject class.
|
|
7237
|
+
*
|
|
7238
|
+
* @category Decorators
|
|
7239
|
+
*
|
|
7240
|
+
* @description
|
|
7241
|
+
* NOTE: Only works on methods that return a promise and will throw an error if not used on a method that returns a promise.
|
|
7242
|
+
* This will allow you to query for instances of a subject class with custom clauses within the instance clauses.
|
|
7243
|
+
*
|
|
7244
|
+
* @example
|
|
7245
|
+
* // Usage with where clause
|
|
7246
|
+
* InstanceQuery({ where: { name: "John" }}) // this will return all the properties of the subject class with the name "John"
|
|
7247
|
+
*
|
|
7248
|
+
* @example
|
|
7249
|
+
* // Usage with condition clause
|
|
7250
|
+
* InstanceQuery({ condition: "triple(Instance, 'age', Age), Age > 18" }) // this will return all the properties of the subject class with the age greater than 18
|
|
7251
|
+
*
|
|
7252
|
+
* @param {Object} [options] - Query options.
|
|
7253
|
+
*/
|
|
7254
|
+
function InstanceQuery(options) {
|
|
7206
7255
|
return function (target, key, descriptor) {
|
|
7207
7256
|
const originalMethod = descriptor.value;
|
|
7208
7257
|
if (typeof originalMethod !== "function") {
|
|
7209
|
-
throw new Error("
|
|
7258
|
+
throw new Error("InstanceQuery decorator can only be applied to methods");
|
|
7210
7259
|
}
|
|
7211
7260
|
descriptor.value = async function (perspective) {
|
|
7212
7261
|
let instances = [];
|
|
@@ -7239,8 +7288,35 @@ function instanceQuery(options) {
|
|
|
7239
7288
|
};
|
|
7240
7289
|
};
|
|
7241
7290
|
}
|
|
7242
|
-
|
|
7291
|
+
/**
|
|
7292
|
+
* Decorator for defining properties of a subject class.
|
|
7293
|
+
*
|
|
7294
|
+
* @category Decorators
|
|
7295
|
+
*
|
|
7296
|
+
* @description
|
|
7297
|
+
* This will allow you to define properties with different conditions and how they would be defined in proflog engine.
|
|
7298
|
+
*
|
|
7299
|
+
* - All properties must have a `through` option which is the predicate of the property.
|
|
7300
|
+
* -e If the property is required, it must have an `initial` option which is the initial value of the property.
|
|
7301
|
+
* - If the property is writable, it will have a setter in prolog engine. A custom setter can be defined with the `setter` option.
|
|
7302
|
+
* - If resolveLanguage is defined, you can use the default `Literal` Language or use your custom language address that can be used to store the property.
|
|
7303
|
+
* - If a custom getter is defined, it will be used to get the value of the property in prolog engine. If not, the default getter will be used.
|
|
7304
|
+
* - If local is defined, the property will be stored locally in the perspective and not in the network. This is useful for properties that are not meant to be shared with the network
|
|
7305
|
+
*
|
|
7306
|
+
* @example
|
|
7307
|
+
* // Usage
|
|
7308
|
+
* SubjectProperty({ through: "ad4m://name", initial: "John", required: true }) // this will define a property with the name "ad4m://name" and the initial value "John"
|
|
7309
|
+
*
|
|
7310
|
+
* @param {PropertyOptions} [opts] - Property options.
|
|
7311
|
+
*/
|
|
7312
|
+
function SubjectProperty(opts) {
|
|
7243
7313
|
return function (target, key) {
|
|
7314
|
+
if (opts.required && !opts.initial) {
|
|
7315
|
+
throw new Error("SubjectProperty requires an 'initial' option if 'required' is true");
|
|
7316
|
+
}
|
|
7317
|
+
if (!opts.through && !opts.getter) {
|
|
7318
|
+
throw new Error("SubjectProperty requires either 'through' or 'getter' option");
|
|
7319
|
+
}
|
|
7244
7320
|
target["__properties"] = target["__properties"] || {};
|
|
7245
7321
|
target["__properties"][key] = target["__properties"][key] || {};
|
|
7246
7322
|
target["__properties"][key] = { ...target["__properties"][key], ...opts };
|
|
@@ -7251,8 +7327,36 @@ function subjectProperty(opts) {
|
|
|
7251
7327
|
Object.defineProperty(target, key, { configurable: true, writable: true });
|
|
7252
7328
|
};
|
|
7253
7329
|
}
|
|
7254
|
-
|
|
7330
|
+
/**
|
|
7331
|
+
* Decorator for defining flags of a subject class
|
|
7332
|
+
*
|
|
7333
|
+
* @category Decorators
|
|
7334
|
+
*
|
|
7335
|
+
* @description
|
|
7336
|
+
* The idea behind flag decorator is to define a property that is required and has an initial value.
|
|
7337
|
+
* This will allow you to define a strict instance query. This behaviour can also be achieved with the `SubjectProperty` decorator but the `SubjectFlag` decorator is a shorthand for that.
|
|
7338
|
+
*
|
|
7339
|
+
* NOTE: Use of Flag is discouraged and should be used only when necessary.
|
|
7340
|
+
*
|
|
7341
|
+
* - All properties must have a `through` & `initial` option which is the predicate of the property.
|
|
7342
|
+
*
|
|
7343
|
+
* @example
|
|
7344
|
+
* // Usage
|
|
7345
|
+
* SubjectFlag({ through: "ad4m://name", value: "John" }) // this will define a flag with the name "ad4m://name" and the initial value "John"
|
|
7346
|
+
*
|
|
7347
|
+
* @param {FlagOptions} [opts] Flag options.
|
|
7348
|
+
*/
|
|
7349
|
+
function SubjectFlag(opts) {
|
|
7255
7350
|
return function (target, key) {
|
|
7351
|
+
if (!opts.through && !opts.value) {
|
|
7352
|
+
throw new Error("SubjectFlag requires a 'through' and 'value' option");
|
|
7353
|
+
}
|
|
7354
|
+
if (!opts.through) {
|
|
7355
|
+
throw new Error("SubjectFlag requires a 'through' option");
|
|
7356
|
+
}
|
|
7357
|
+
if (!opts.value) {
|
|
7358
|
+
throw new Error("SubjectFlag requires a 'value' option");
|
|
7359
|
+
}
|
|
7256
7360
|
target["__properties"] = target["__properties"] || {};
|
|
7257
7361
|
target["__properties"][key] = target["__properties"][key] || {};
|
|
7258
7362
|
target["__properties"][key] = {
|
|
@@ -7267,7 +7371,27 @@ function subjectFlag(opts) {
|
|
|
7267
7371
|
Object.defineProperty(target, key, { configurable: true, writable: true });
|
|
7268
7372
|
};
|
|
7269
7373
|
}
|
|
7270
|
-
|
|
7374
|
+
/**
|
|
7375
|
+
* Decorator for defining collections of a subject class.
|
|
7376
|
+
*
|
|
7377
|
+
* @category Decorators
|
|
7378
|
+
*
|
|
7379
|
+
* @description
|
|
7380
|
+
* This will allow you to define collections with different conditions and how they would be defined in proflog engine.
|
|
7381
|
+
*
|
|
7382
|
+
* NOTE: The property needs to be an array for it to picked up during the initialization phase.
|
|
7383
|
+
*
|
|
7384
|
+
* - All collections must have a `through` option which is the predicate of the collection.
|
|
7385
|
+
* - If the collection has a `where` option, it can be used to define a custom condition for the collection.
|
|
7386
|
+
* - If the collection has a `local` option, the collection will be stored locally in the perspective and not in the network. This is useful for collections that are not meant to be shared with the network.
|
|
7387
|
+
*
|
|
7388
|
+
* @example
|
|
7389
|
+
* // Usage
|
|
7390
|
+
* SubjectCollection({ through: "ad4m://friends" }) // this will define a collection with the name "ad4m://friends"
|
|
7391
|
+
*
|
|
7392
|
+
* @param opts Collection options.
|
|
7393
|
+
*/
|
|
7394
|
+
function SubjectCollection(opts) {
|
|
7271
7395
|
return function (target, key) {
|
|
7272
7396
|
target["__collections"] = target["__collections"] || {};
|
|
7273
7397
|
target["__collections"][key] = opts;
|
|
@@ -7287,6 +7411,22 @@ function makeRandomPrologAtom(length) {
|
|
|
7287
7411
|
}
|
|
7288
7412
|
return result;
|
|
7289
7413
|
}
|
|
7414
|
+
/**
|
|
7415
|
+
* Decorator for defining an SDNA class.
|
|
7416
|
+
*
|
|
7417
|
+
* @category Decorators
|
|
7418
|
+
*
|
|
7419
|
+
* @description
|
|
7420
|
+
* This will create a new SDNA class with the given name and add custom methods to generate the SDNA for the class, for this to work the class need to have the properties defined using the decorators like `SubjectProperty`.
|
|
7421
|
+
*
|
|
7422
|
+
* Note: This decorator is required for the class to be picked up during the initialization phase.
|
|
7423
|
+
*
|
|
7424
|
+
* @example
|
|
7425
|
+
* // Usage
|
|
7426
|
+
* SDNAClass({ name: "Person" }) // this will create a new SDNA class with the name "Person"
|
|
7427
|
+
*
|
|
7428
|
+
* @param opts SDNA class options.
|
|
7429
|
+
*/
|
|
7290
7430
|
function SDNAClass(opts) {
|
|
7291
7431
|
return function (target) {
|
|
7292
7432
|
target.prototype.className = opts.name;
|
|
@@ -7851,7 +7991,17 @@ var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) ||
|
|
|
7851
7991
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
7852
7992
|
};
|
|
7853
7993
|
var _SubjectEntity_baseExpression, _SubjectEntity_subjectClass, _SubjectEntity_source, _SubjectEntity_perspective;
|
|
7994
|
+
/**
|
|
7995
|
+
* Class representing a subject entity.
|
|
7996
|
+
* Can extend this class to create a new subject entity to add methods interact with SDNA and much better experience then using the bare bone methods.
|
|
7997
|
+
*/
|
|
7854
7998
|
class SubjectEntity {
|
|
7999
|
+
/**
|
|
8000
|
+
* Constructs a new subject.
|
|
8001
|
+
* @param perspective - The perspective that the subject belongs to.
|
|
8002
|
+
* @param baseExpression - The base expression of the subject.
|
|
8003
|
+
* @param soruce - The source of the subject, the expression this instance is linked too.
|
|
8004
|
+
*/
|
|
7855
8005
|
constructor(perspective, baseExpression, source) {
|
|
7856
8006
|
_SubjectEntity_baseExpression.set(this, void 0);
|
|
7857
8007
|
_SubjectEntity_subjectClass.set(this, void 0);
|
|
@@ -7861,6 +8011,9 @@ class SubjectEntity {
|
|
|
7861
8011
|
__classPrivateFieldSet(this, _SubjectEntity_perspective, perspective, "f");
|
|
7862
8012
|
__classPrivateFieldSet(this, _SubjectEntity_source, source || "ad4m://self", "f");
|
|
7863
8013
|
}
|
|
8014
|
+
/**
|
|
8015
|
+
* Gets the base expression of the subject.
|
|
8016
|
+
*/
|
|
7864
8017
|
get baseExpression() {
|
|
7865
8018
|
return __classPrivateFieldGet(this, _SubjectEntity_baseExpression, "f");
|
|
7866
8019
|
}
|
|
@@ -7987,6 +8140,17 @@ class SubjectEntity {
|
|
|
7987
8140
|
}
|
|
7988
8141
|
}
|
|
7989
8142
|
}
|
|
8143
|
+
/**
|
|
8144
|
+
* Save the subject entity.
|
|
8145
|
+
* This method will create a new subject with the base expression and add a new link from the source to the base expression with the predicate "ad4m://has_child".
|
|
8146
|
+
*
|
|
8147
|
+
* If a property has an action, it will perform the action (Only for collections).
|
|
8148
|
+
* If a property is an array and is not empty, it will set the collection.
|
|
8149
|
+
* If a property is not undefined, not null, and not an empty string, it will set the property.
|
|
8150
|
+
*
|
|
8151
|
+
*
|
|
8152
|
+
* @throws Will throw an error if the subject entity cannot be converted to a subject class, or if the subject cannot be created, or if the link cannot be added, or if the subject entity cannot be updated.
|
|
8153
|
+
*/
|
|
7990
8154
|
async save() {
|
|
7991
8155
|
__classPrivateFieldSet(this, _SubjectEntity_subjectClass, await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").stringOrTemplateObjectToSubjectClass(this), "f");
|
|
7992
8156
|
await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").createSubject(this, __classPrivateFieldGet(this, _SubjectEntity_baseExpression, "f"));
|
|
@@ -7997,11 +8161,22 @@ class SubjectEntity {
|
|
|
7997
8161
|
}));
|
|
7998
8162
|
await this.update();
|
|
7999
8163
|
}
|
|
8164
|
+
/**
|
|
8165
|
+
* Update the subject entity.
|
|
8166
|
+
*
|
|
8167
|
+
* It will iterate over the properties of the subject entity.
|
|
8168
|
+
*
|
|
8169
|
+
* If a property has an action, it will perform the action (Only for collections).
|
|
8170
|
+
* If a property is an array and is not empty, it will set the collection.
|
|
8171
|
+
* If a property is not undefined, not null, and not an empty string, it will set the property.
|
|
8172
|
+
*
|
|
8173
|
+
* @throws Will throw an error if the subject entity cannot be converted to a subject class, or if a property cannot be set, or if a collection cannot be set, or if the data of the subject entity cannot be gotten.
|
|
8174
|
+
*/
|
|
8000
8175
|
async update() {
|
|
8001
8176
|
__classPrivateFieldSet(this, _SubjectEntity_subjectClass, await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").stringOrTemplateObjectToSubjectClass(this), "f");
|
|
8002
8177
|
const entries = Object.entries(this);
|
|
8003
8178
|
for (const [key, value] of entries) {
|
|
8004
|
-
if (value) {
|
|
8179
|
+
if (value !== undefined && value !== null) {
|
|
8005
8180
|
if (value?.action) {
|
|
8006
8181
|
switch (value.action) {
|
|
8007
8182
|
case 'setter':
|
|
@@ -8020,21 +8195,44 @@ class SubjectEntity {
|
|
|
8020
8195
|
else if (Array.isArray(value) && value.length > 0) {
|
|
8021
8196
|
await this.setCollectionSetter(key, value);
|
|
8022
8197
|
}
|
|
8023
|
-
else {
|
|
8198
|
+
else if (value !== undefined && value !== null && value !== "") {
|
|
8024
8199
|
await this.setProperty(key, value);
|
|
8025
8200
|
}
|
|
8026
8201
|
}
|
|
8027
8202
|
}
|
|
8028
8203
|
await this.getData();
|
|
8029
8204
|
}
|
|
8205
|
+
/**
|
|
8206
|
+
* Get the subject entity with all the properties & collection populated.
|
|
8207
|
+
*
|
|
8208
|
+
* @returns The subject entity.
|
|
8209
|
+
*
|
|
8210
|
+
* @throws Will throw an error if the subject entity cannot be converted to a subject class, or if the data of the subject entity cannot be gotten.
|
|
8211
|
+
*/
|
|
8030
8212
|
async get() {
|
|
8031
8213
|
__classPrivateFieldSet(this, _SubjectEntity_subjectClass, await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").stringOrTemplateObjectToSubjectClass(this), "f");
|
|
8032
8214
|
return await this.getData();
|
|
8033
8215
|
}
|
|
8216
|
+
/**
|
|
8217
|
+
* Delete the subject entity.
|
|
8218
|
+
* This method will remove the subject from the perspective.
|
|
8219
|
+
*
|
|
8220
|
+
* @throws Will throw an error if the subject entity cannot be removed.
|
|
8221
|
+
*/
|
|
8034
8222
|
async delete() {
|
|
8035
8223
|
await __classPrivateFieldGet(this, _SubjectEntity_perspective, "f").removeSubject(this, __classPrivateFieldGet(this, _SubjectEntity_baseExpression, "f"));
|
|
8036
8224
|
}
|
|
8037
|
-
|
|
8225
|
+
/**
|
|
8226
|
+
* Get all the subject entities of the subject class.
|
|
8227
|
+
*
|
|
8228
|
+
* NOTE: this is a static method and should be called on the class itself.
|
|
8229
|
+
*
|
|
8230
|
+
* @param perspective - The perspective that the subject belongs to.
|
|
8231
|
+
*
|
|
8232
|
+
* @returns The subject entities.
|
|
8233
|
+
*
|
|
8234
|
+
* @throws Will throw an error if the subject entity cannot be converted to a subject class, or if the subject proxies cannot be gotten.
|
|
8235
|
+
*/
|
|
8038
8236
|
static async all(perspective) {
|
|
8039
8237
|
let subjectClass = await perspective.stringOrTemplateObjectToSubjectClass(this);
|
|
8040
8238
|
const proxies = await perspective.getAllSubjectProxies(subjectClass);
|
|
@@ -8049,6 +8247,18 @@ class SubjectEntity {
|
|
|
8049
8247
|
}
|
|
8050
8248
|
return [];
|
|
8051
8249
|
}
|
|
8250
|
+
/**
|
|
8251
|
+
* Query the subject entities of the subject class.
|
|
8252
|
+
*
|
|
8253
|
+
* NOTE: this is a static method and should be called on the class itself.
|
|
8254
|
+
*
|
|
8255
|
+
* @param perspective - The perspective that the subject belongs to.
|
|
8256
|
+
* @param query - The query of the subject entities.
|
|
8257
|
+
*
|
|
8258
|
+
* @returns The subject entities.
|
|
8259
|
+
*
|
|
8260
|
+
* @throws Will throw an error if the subject entity cannot be converted to a subject class, or if the query cannot be inferred, or if the data of the subject entities cannot be gotten.
|
|
8261
|
+
*/
|
|
8052
8262
|
static async query(perspective, query) {
|
|
8053
8263
|
const source = query?.source || "ad4m://self";
|
|
8054
8264
|
let subjectClass = await perspective.stringOrTemplateObjectToSubjectClass(this);
|
|
@@ -8091,6 +8301,7 @@ exports.AgentClient = AgentClient;
|
|
|
8091
8301
|
exports.Dna = Dna;
|
|
8092
8302
|
exports.ExpressionGeneric = ExpressionGeneric;
|
|
8093
8303
|
exports.ExpressionGenericInput = ExpressionGenericInput;
|
|
8304
|
+
exports.InstanceQuery = InstanceQuery;
|
|
8094
8305
|
exports.LanguageExpression = LanguageExpression;
|
|
8095
8306
|
exports.LanguageLanguageInput = LanguageLanguageInput;
|
|
8096
8307
|
exports.LanguageMetaInternal = LanguageMetaInternal;
|
|
@@ -8102,19 +8313,18 @@ exports.SDNAClass = SDNAClass;
|
|
|
8102
8313
|
exports.SMART_LITERAL_CONTENT_PREDICATE = SMART_LITERAL_CONTENT_PREDICATE;
|
|
8103
8314
|
exports.SmartLiteral = SmartLiteral;
|
|
8104
8315
|
exports.Subject = Subject;
|
|
8316
|
+
exports.SubjectCollection = SubjectCollection;
|
|
8105
8317
|
exports.SubjectEntity = SubjectEntity;
|
|
8318
|
+
exports.SubjectFlag = SubjectFlag;
|
|
8319
|
+
exports.SubjectProperty = SubjectProperty;
|
|
8106
8320
|
exports.addLink = addLink;
|
|
8107
8321
|
exports.capSentence = capSentence;
|
|
8108
8322
|
exports.exprRef2String = exprRef2String;
|
|
8109
8323
|
exports.formatList = formatList;
|
|
8110
8324
|
exports.hasLink = hasLink;
|
|
8111
|
-
exports.instanceQuery = instanceQuery;
|
|
8112
8325
|
exports.isExpression = isExpression;
|
|
8113
8326
|
exports.isLink = isLink;
|
|
8114
8327
|
exports.linkEqual = linkEqual;
|
|
8115
8328
|
exports.makeRandomPrologAtom = makeRandomPrologAtom;
|
|
8116
8329
|
exports.parseExprUrl = parseExprUrl;
|
|
8117
|
-
exports.subjectCollection = subjectCollection;
|
|
8118
|
-
exports.subjectFlag = subjectFlag;
|
|
8119
|
-
exports.subjectProperty = subjectProperty;
|
|
8120
8330
|
exports.typeDefsString = typeDefsString;
|