@coasys/ad4m 0.10.1-dev-1 → 0.10.1-multi-user-1
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 +163 -281
- package/lib/index.js +164 -282
- package/lib/src/agent/Agent.d.ts +12 -0
- package/lib/src/agent/Agent.js +48 -0
- package/lib/src/agent/AgentClient.d.ts +3 -1
- package/lib/src/agent/AgentClient.js +23 -0
- package/lib/src/language/Language.d.ts +12 -1
- package/lib/src/model/Ad4mModel.d.ts +0 -108
- package/lib/src/model/Ad4mModel.js +2 -283
- package/lib/src/runtime/RuntimeClient.d.ts +4 -1
- package/lib/src/runtime/RuntimeClient.js +30 -0
- package/lib/src/runtime/RuntimeResolver.d.ts +9 -0
- package/lib/src/runtime/RuntimeResolver.js +55 -0
- package/lib/src/schema.gql +10 -0
- package/lib/src/typeDefs.js +10 -0
- package/package.json +2 -2
- package/src/agent/Agent.ts +36 -0
- package/src/agent/AgentClient.ts +30 -0
- package/src/language/Language.ts +16 -4
- package/src/model/Ad4mModel.ts +2 -374
- package/src/runtime/RuntimeClient.ts +34 -1
- package/src/runtime/RuntimeResolver.ts +35 -0
|
@@ -1,44 +1,4 @@
|
|
|
1
1
|
import { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
|
|
2
|
-
import { PropertyOptions } from "./decorators";
|
|
3
|
-
interface JSONSchemaProperty {
|
|
4
|
-
type: string | string[];
|
|
5
|
-
items?: JSONSchemaProperty;
|
|
6
|
-
properties?: {
|
|
7
|
-
[key: string]: JSONSchemaProperty;
|
|
8
|
-
};
|
|
9
|
-
required?: string[];
|
|
10
|
-
"x-ad4m"?: {
|
|
11
|
-
through?: string;
|
|
12
|
-
resolveLanguage?: string;
|
|
13
|
-
local?: boolean;
|
|
14
|
-
writable?: boolean;
|
|
15
|
-
initial?: string;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
interface JSONSchema {
|
|
19
|
-
$schema?: string;
|
|
20
|
-
title?: string;
|
|
21
|
-
$id?: string;
|
|
22
|
-
type?: string;
|
|
23
|
-
properties?: {
|
|
24
|
-
[key: string]: JSONSchemaProperty;
|
|
25
|
-
};
|
|
26
|
-
required?: string[];
|
|
27
|
-
"x-ad4m"?: {
|
|
28
|
-
namespace?: string;
|
|
29
|
-
className?: string;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
interface JSONSchemaToModelOptions {
|
|
33
|
-
name: string;
|
|
34
|
-
namespace?: string;
|
|
35
|
-
predicateTemplate?: string;
|
|
36
|
-
predicateGenerator?: (title: string, property: string) => string;
|
|
37
|
-
propertyMapping?: Record<string, string>;
|
|
38
|
-
resolveLanguage?: string;
|
|
39
|
-
local?: boolean;
|
|
40
|
-
propertyOptions?: Record<string, Partial<PropertyOptions>>;
|
|
41
|
-
}
|
|
42
2
|
type ValueTuple = [name: string, value: any, resolve?: boolean];
|
|
43
3
|
type WhereOps = {
|
|
44
4
|
not: string | number | boolean | string[] | number[];
|
|
@@ -399,74 +359,6 @@ export declare class Ad4mModel {
|
|
|
399
359
|
* ```
|
|
400
360
|
*/
|
|
401
361
|
static query<T extends Ad4mModel>(this: typeof Ad4mModel & (new (...args: any[]) => T), perspective: PerspectiveProxy, query?: Query): ModelQueryBuilder<T>;
|
|
402
|
-
/**
|
|
403
|
-
* Creates an Ad4mModel class from a JSON Schema definition.
|
|
404
|
-
*
|
|
405
|
-
* @description
|
|
406
|
-
* This method dynamically generates an Ad4mModel subclass from a JSON Schema,
|
|
407
|
-
* enabling integration with systems that use JSON Schema for type definitions.
|
|
408
|
-
*
|
|
409
|
-
* The method follows a cascading approach for determining predicates:
|
|
410
|
-
* 1. Explicit configuration in options parameter (highest precedence)
|
|
411
|
-
* 2. x-ad4m metadata in the JSON Schema
|
|
412
|
-
* 3. Inference from schema title and property names
|
|
413
|
-
* 4. Error if no namespace can be determined
|
|
414
|
-
*
|
|
415
|
-
* @example
|
|
416
|
-
* ```typescript
|
|
417
|
-
* // With explicit configuration
|
|
418
|
-
* const PersonClass = Ad4mModel.fromJSONSchema(schema, {
|
|
419
|
-
* name: "Person",
|
|
420
|
-
* namespace: "person://",
|
|
421
|
-
* resolveLanguage: "literal"
|
|
422
|
-
* });
|
|
423
|
-
*
|
|
424
|
-
* // With property mapping
|
|
425
|
-
* const ContactClass = Ad4mModel.fromJSONSchema(schema, {
|
|
426
|
-
* name: "Contact",
|
|
427
|
-
* namespace: "contact://",
|
|
428
|
-
* propertyMapping: {
|
|
429
|
-
* "name": "foaf://name",
|
|
430
|
-
* "email": "foaf://mbox"
|
|
431
|
-
* }
|
|
432
|
-
* });
|
|
433
|
-
*
|
|
434
|
-
* // With x-ad4m metadata in schema
|
|
435
|
-
* const schema = {
|
|
436
|
-
* "title": "Product",
|
|
437
|
-
* "x-ad4m": { "namespace": "product://" },
|
|
438
|
-
* "properties": {
|
|
439
|
-
* "name": {
|
|
440
|
-
* "type": "string",
|
|
441
|
-
* "x-ad4m": { "through": "product://title" }
|
|
442
|
-
* }
|
|
443
|
-
* }
|
|
444
|
-
* };
|
|
445
|
-
* const ProductClass = Ad4mModel.fromJSONSchema(schema, { name: "Product" });
|
|
446
|
-
* ```
|
|
447
|
-
*
|
|
448
|
-
* @param schema - JSON Schema definition
|
|
449
|
-
* @param options - Configuration options
|
|
450
|
-
* @returns Generated Ad4mModel subclass
|
|
451
|
-
* @throws Error when namespace cannot be inferred
|
|
452
|
-
*/
|
|
453
|
-
static fromJSONSchema(schema: JSONSchema, options: JSONSchemaToModelOptions): typeof Ad4mModel;
|
|
454
|
-
/**
|
|
455
|
-
* Determines the namespace for predicates using cascading precedence
|
|
456
|
-
*/
|
|
457
|
-
private static determineNamespace;
|
|
458
|
-
/**
|
|
459
|
-
* Determines the predicate for a specific property using cascading precedence
|
|
460
|
-
*/
|
|
461
|
-
private static determinePredicate;
|
|
462
|
-
/**
|
|
463
|
-
* Gets property-specific options using cascading precedence
|
|
464
|
-
*/
|
|
465
|
-
private static getPropertyOption;
|
|
466
|
-
/**
|
|
467
|
-
* Gets default value for a JSON Schema type
|
|
468
|
-
*/
|
|
469
|
-
private static getDefaultValueForType;
|
|
470
362
|
}
|
|
471
363
|
/** Query builder for Ad4mModel queries.
|
|
472
364
|
* Allows building queries with a fluent interface and either running them once
|
|
@@ -12,8 +12,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
12
12
|
var _Ad4mModel_baseExpression, _Ad4mModel_subjectClassName, _Ad4mModel_source, _Ad4mModel_perspective;
|
|
13
13
|
import { Literal } from "../Literal";
|
|
14
14
|
import { Link } from "../links/Links";
|
|
15
|
-
import { makeRandomPrologAtom
|
|
16
|
-
import { singularToPlural
|
|
15
|
+
import { makeRandomPrologAtom } from "./decorators";
|
|
16
|
+
import { singularToPlural } from "./util";
|
|
17
17
|
function capitalize(word) {
|
|
18
18
|
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
19
19
|
}
|
|
@@ -772,287 +772,6 @@ export class Ad4mModel {
|
|
|
772
772
|
static query(perspective, query) {
|
|
773
773
|
return new ModelQueryBuilder(perspective, this, query);
|
|
774
774
|
}
|
|
775
|
-
/**
|
|
776
|
-
* Creates an Ad4mModel class from a JSON Schema definition.
|
|
777
|
-
*
|
|
778
|
-
* @description
|
|
779
|
-
* This method dynamically generates an Ad4mModel subclass from a JSON Schema,
|
|
780
|
-
* enabling integration with systems that use JSON Schema for type definitions.
|
|
781
|
-
*
|
|
782
|
-
* The method follows a cascading approach for determining predicates:
|
|
783
|
-
* 1. Explicit configuration in options parameter (highest precedence)
|
|
784
|
-
* 2. x-ad4m metadata in the JSON Schema
|
|
785
|
-
* 3. Inference from schema title and property names
|
|
786
|
-
* 4. Error if no namespace can be determined
|
|
787
|
-
*
|
|
788
|
-
* @example
|
|
789
|
-
* ```typescript
|
|
790
|
-
* // With explicit configuration
|
|
791
|
-
* const PersonClass = Ad4mModel.fromJSONSchema(schema, {
|
|
792
|
-
* name: "Person",
|
|
793
|
-
* namespace: "person://",
|
|
794
|
-
* resolveLanguage: "literal"
|
|
795
|
-
* });
|
|
796
|
-
*
|
|
797
|
-
* // With property mapping
|
|
798
|
-
* const ContactClass = Ad4mModel.fromJSONSchema(schema, {
|
|
799
|
-
* name: "Contact",
|
|
800
|
-
* namespace: "contact://",
|
|
801
|
-
* propertyMapping: {
|
|
802
|
-
* "name": "foaf://name",
|
|
803
|
-
* "email": "foaf://mbox"
|
|
804
|
-
* }
|
|
805
|
-
* });
|
|
806
|
-
*
|
|
807
|
-
* // With x-ad4m metadata in schema
|
|
808
|
-
* const schema = {
|
|
809
|
-
* "title": "Product",
|
|
810
|
-
* "x-ad4m": { "namespace": "product://" },
|
|
811
|
-
* "properties": {
|
|
812
|
-
* "name": {
|
|
813
|
-
* "type": "string",
|
|
814
|
-
* "x-ad4m": { "through": "product://title" }
|
|
815
|
-
* }
|
|
816
|
-
* }
|
|
817
|
-
* };
|
|
818
|
-
* const ProductClass = Ad4mModel.fromJSONSchema(schema, { name: "Product" });
|
|
819
|
-
* ```
|
|
820
|
-
*
|
|
821
|
-
* @param schema - JSON Schema definition
|
|
822
|
-
* @param options - Configuration options
|
|
823
|
-
* @returns Generated Ad4mModel subclass
|
|
824
|
-
* @throws Error when namespace cannot be inferred
|
|
825
|
-
*/
|
|
826
|
-
static fromJSONSchema(schema, options) {
|
|
827
|
-
// Disallow top-level "author" property since Ad4mModel provides it implicitly via link authorship
|
|
828
|
-
if (schema?.properties && Object.prototype.hasOwnProperty.call(schema.properties, "author")) {
|
|
829
|
-
throw new Error('JSON Schema must not define a top-level "author" property because Ad4mModel already exposes it. Please rename the property (e.g., "writer").');
|
|
830
|
-
}
|
|
831
|
-
// Determine namespace with cascading precedence
|
|
832
|
-
const namespace = this.determineNamespace(schema, options);
|
|
833
|
-
// Create the dynamic class
|
|
834
|
-
const DynamicModelClass = class extends Ad4mModel {
|
|
835
|
-
};
|
|
836
|
-
// Set up class metadata
|
|
837
|
-
Object.defineProperty(DynamicModelClass, 'name', { value: options.name });
|
|
838
|
-
DynamicModelClass.className = options.name;
|
|
839
|
-
DynamicModelClass.prototype.className = options.name;
|
|
840
|
-
// Generate properties and collections metadata
|
|
841
|
-
const properties = {};
|
|
842
|
-
const collections = {};
|
|
843
|
-
if (schema.properties) {
|
|
844
|
-
for (const [propertyName, propertySchema] of Object.entries(schema.properties)) {
|
|
845
|
-
const predicate = this.determinePredicate(schema, propertyName, propertySchema, namespace, options);
|
|
846
|
-
const isRequired = schema.required?.includes(propertyName) || false;
|
|
847
|
-
const isArray = propertySchema.type === 'array';
|
|
848
|
-
if (isArray) {
|
|
849
|
-
// Handle arrays as collections
|
|
850
|
-
// Store the singular form as the collection key since SDNA generation expects singular
|
|
851
|
-
collections[propertyName] = {
|
|
852
|
-
through: predicate,
|
|
853
|
-
local: this.getPropertyOption(propertyName, propertySchema, options, 'local')
|
|
854
|
-
};
|
|
855
|
-
// Define the property on prototype
|
|
856
|
-
Object.defineProperty(DynamicModelClass.prototype, propertyName, {
|
|
857
|
-
configurable: true,
|
|
858
|
-
writable: true,
|
|
859
|
-
value: []
|
|
860
|
-
});
|
|
861
|
-
// Add collection methods
|
|
862
|
-
const adderName = `add${capitalize(propertyName)}`;
|
|
863
|
-
const removerName = `remove${capitalize(propertyName)}`;
|
|
864
|
-
const setterName = `setCollection${capitalize(propertyName)}`;
|
|
865
|
-
DynamicModelClass.prototype[adderName] = function () {
|
|
866
|
-
// Placeholder function for SDNA generation
|
|
867
|
-
};
|
|
868
|
-
DynamicModelClass.prototype[removerName] = function () {
|
|
869
|
-
// Placeholder function for SDNA generation
|
|
870
|
-
};
|
|
871
|
-
DynamicModelClass.prototype[setterName] = function () {
|
|
872
|
-
// Placeholder function for SDNA generation
|
|
873
|
-
};
|
|
874
|
-
}
|
|
875
|
-
else {
|
|
876
|
-
// Handle regular properties
|
|
877
|
-
let resolveLanguage = this.getPropertyOption(propertyName, propertySchema, options, 'resolveLanguage');
|
|
878
|
-
// If no specific resolveLanguage for this property, use the global one
|
|
879
|
-
if (!resolveLanguage && options.resolveLanguage) {
|
|
880
|
-
resolveLanguage = options.resolveLanguage;
|
|
881
|
-
}
|
|
882
|
-
const local = this.getPropertyOption(propertyName, propertySchema, options, 'local');
|
|
883
|
-
const writable = this.getPropertyOption(propertyName, propertySchema, options, 'writable', true);
|
|
884
|
-
let initial = this.getPropertyOption(propertyName, propertySchema, options, 'initial');
|
|
885
|
-
// Handle nested objects by serializing to JSON
|
|
886
|
-
if (propertySchema.type === 'object' && !resolveLanguage) {
|
|
887
|
-
resolveLanguage = 'literal';
|
|
888
|
-
console.warn(`Property "${propertyName}" is an object type. It will be stored as JSON. Consider flattening complex objects for better semantic querying.`);
|
|
889
|
-
}
|
|
890
|
-
// Ensure numeric properties use literal language for correct typing
|
|
891
|
-
if ((resolveLanguage === undefined || resolveLanguage === null) && (propertySchema.type === 'number' || propertySchema.type === 'integer')) {
|
|
892
|
-
resolveLanguage = 'literal';
|
|
893
|
-
}
|
|
894
|
-
// If property is required, ensure it has an initial value
|
|
895
|
-
if (isRequired && !initial) {
|
|
896
|
-
if (propertySchema.type === 'object') {
|
|
897
|
-
initial = 'literal://json:{}';
|
|
898
|
-
}
|
|
899
|
-
else {
|
|
900
|
-
initial = "ad4m://undefined";
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
properties[propertyName] = {
|
|
904
|
-
through: predicate,
|
|
905
|
-
required: isRequired,
|
|
906
|
-
writable: writable,
|
|
907
|
-
...(resolveLanguage && { resolveLanguage }),
|
|
908
|
-
...(local !== undefined && { local }),
|
|
909
|
-
...(initial && { initial })
|
|
910
|
-
};
|
|
911
|
-
// Define the property on prototype
|
|
912
|
-
Object.defineProperty(DynamicModelClass.prototype, propertyName, {
|
|
913
|
-
configurable: true,
|
|
914
|
-
writable: true,
|
|
915
|
-
value: this.getDefaultValueForType(propertySchema.type)
|
|
916
|
-
});
|
|
917
|
-
// Add setter function if writable
|
|
918
|
-
if (writable) {
|
|
919
|
-
const setterName = propertyNameToSetterName(propertyName);
|
|
920
|
-
DynamicModelClass.prototype[setterName] = function () {
|
|
921
|
-
// This is a placeholder function that the SDNA generation looks for
|
|
922
|
-
// The actual setter logic is handled by the Ad4mModel base class
|
|
923
|
-
};
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
// Validate that at least one property has an initial value (needed for valid SDNA constructor)
|
|
929
|
-
// Collections don't create constructor actions, only properties with initial values do
|
|
930
|
-
const hasPropertyWithInitial = Object.values(properties).some((prop) => prop.initial);
|
|
931
|
-
if (!hasPropertyWithInitial) {
|
|
932
|
-
// If no properties have initial values, add a type identifier automatically
|
|
933
|
-
const typeProperty = `ad4m://type`;
|
|
934
|
-
const typeValue = `${namespace.replace('://', '')}://instance`;
|
|
935
|
-
properties['__ad4m_type'] = {
|
|
936
|
-
through: typeProperty,
|
|
937
|
-
required: true,
|
|
938
|
-
writable: false,
|
|
939
|
-
initial: typeValue,
|
|
940
|
-
flag: true
|
|
941
|
-
};
|
|
942
|
-
// Add the type property to the prototype
|
|
943
|
-
Object.defineProperty(DynamicModelClass.prototype, '__ad4m_type', {
|
|
944
|
-
configurable: true,
|
|
945
|
-
writable: false,
|
|
946
|
-
value: typeValue
|
|
947
|
-
});
|
|
948
|
-
console.warn(`No properties with initial values found. Added automatic type flag: ${typeProperty} = ${typeValue}`);
|
|
949
|
-
}
|
|
950
|
-
// Attach metadata to prototype
|
|
951
|
-
DynamicModelClass.prototype.__properties = properties;
|
|
952
|
-
DynamicModelClass.prototype.__collections = collections;
|
|
953
|
-
// Apply the ModelOptions decorator to set up the generateSDNA method
|
|
954
|
-
const ModelOptionsDecorator = ModelOptions({ name: options.name });
|
|
955
|
-
ModelOptionsDecorator(DynamicModelClass);
|
|
956
|
-
return DynamicModelClass;
|
|
957
|
-
}
|
|
958
|
-
/**
|
|
959
|
-
* Determines the namespace for predicates using cascading precedence
|
|
960
|
-
*/
|
|
961
|
-
static determineNamespace(schema, options) {
|
|
962
|
-
// 1. Explicit namespace in options (highest precedence)
|
|
963
|
-
if (options.namespace) {
|
|
964
|
-
return options.namespace;
|
|
965
|
-
}
|
|
966
|
-
// 2. x-ad4m metadata in schema
|
|
967
|
-
if (schema["x-ad4m"]?.namespace) {
|
|
968
|
-
return schema["x-ad4m"].namespace;
|
|
969
|
-
}
|
|
970
|
-
// 3. Infer from schema title
|
|
971
|
-
if (schema.title) {
|
|
972
|
-
return `${schema.title.toLowerCase()}://`;
|
|
973
|
-
}
|
|
974
|
-
// 4. Try to extract from $id if it's a URL
|
|
975
|
-
if (schema.$id) {
|
|
976
|
-
try {
|
|
977
|
-
const url = new URL(schema.$id);
|
|
978
|
-
const pathParts = url.pathname.split('/').filter(p => p);
|
|
979
|
-
if (pathParts.length > 0) {
|
|
980
|
-
const lastPart = pathParts[pathParts.length - 1];
|
|
981
|
-
const baseName = lastPart.replace(/\.schema\.json$/, '').replace(/\.json$/, '');
|
|
982
|
-
return `${baseName.toLowerCase()}://`;
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
catch {
|
|
986
|
-
// If $id is not a valid URL, continue to error
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
// 5. Error if no namespace can be determined
|
|
990
|
-
throw new Error(`Cannot infer namespace for JSON Schema. Please provide one of:
|
|
991
|
-
- options.namespace
|
|
992
|
-
- schema["x-ad4m"].namespace
|
|
993
|
-
- schema.title
|
|
994
|
-
- valid schema.$id`);
|
|
995
|
-
}
|
|
996
|
-
/**
|
|
997
|
-
* Determines the predicate for a specific property using cascading precedence
|
|
998
|
-
*/
|
|
999
|
-
static determinePredicate(schema, propertyName, propertySchema, namespace, options) {
|
|
1000
|
-
// 1. Explicit property mapping (highest precedence)
|
|
1001
|
-
if (options.propertyMapping?.[propertyName]) {
|
|
1002
|
-
return options.propertyMapping[propertyName];
|
|
1003
|
-
}
|
|
1004
|
-
// 2. x-ad4m metadata in property schema
|
|
1005
|
-
if (propertySchema["x-ad4m"]?.through) {
|
|
1006
|
-
return propertySchema["x-ad4m"].through;
|
|
1007
|
-
}
|
|
1008
|
-
// 3. Generate from namespace + property name
|
|
1009
|
-
if (options.predicateTemplate) {
|
|
1010
|
-
return options.predicateTemplate
|
|
1011
|
-
.replace('${namespace}', namespace.replace('://', ''))
|
|
1012
|
-
.replace('${title}', schema.title || '')
|
|
1013
|
-
.replace('${property}', propertyName);
|
|
1014
|
-
}
|
|
1015
|
-
// 4. Custom predicate generator
|
|
1016
|
-
if (options.predicateGenerator) {
|
|
1017
|
-
return options.predicateGenerator(schema.title || '', propertyName);
|
|
1018
|
-
}
|
|
1019
|
-
// 5. Default: namespace + property name
|
|
1020
|
-
const cleanNamespace = namespace.endsWith('://') ? namespace.slice(0, -3) : namespace;
|
|
1021
|
-
return `${cleanNamespace}://${propertyName}`;
|
|
1022
|
-
}
|
|
1023
|
-
/**
|
|
1024
|
-
* Gets property-specific options using cascading precedence
|
|
1025
|
-
*/
|
|
1026
|
-
static getPropertyOption(propertyName, propertySchema, options, optionName, defaultValue) {
|
|
1027
|
-
// 1. Property-specific options
|
|
1028
|
-
if (options.propertyOptions?.[propertyName]?.[optionName] !== undefined) {
|
|
1029
|
-
return options.propertyOptions[propertyName][optionName];
|
|
1030
|
-
}
|
|
1031
|
-
// 2. x-ad4m metadata in property
|
|
1032
|
-
if (propertySchema["x-ad4m"]?.[optionName] !== undefined) {
|
|
1033
|
-
return propertySchema["x-ad4m"][optionName];
|
|
1034
|
-
}
|
|
1035
|
-
// 3. Global option
|
|
1036
|
-
if (options[optionName] !== undefined) {
|
|
1037
|
-
return options[optionName];
|
|
1038
|
-
}
|
|
1039
|
-
// 4. Default value
|
|
1040
|
-
return defaultValue;
|
|
1041
|
-
}
|
|
1042
|
-
/**
|
|
1043
|
-
* Gets default value for a JSON Schema type
|
|
1044
|
-
*/
|
|
1045
|
-
static getDefaultValueForType(type) {
|
|
1046
|
-
switch (type) {
|
|
1047
|
-
case 'string': return '';
|
|
1048
|
-
case 'number': return 0;
|
|
1049
|
-
case 'integer': return 0;
|
|
1050
|
-
case 'boolean': return false;
|
|
1051
|
-
case 'array': return [];
|
|
1052
|
-
case 'object': return {};
|
|
1053
|
-
default: return '';
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
775
|
}
|
|
1057
776
|
_Ad4mModel_baseExpression = new WeakMap(), _Ad4mModel_subjectClassName = new WeakMap(), _Ad4mModel_source = new WeakMap(), _Ad4mModel_perspective = new WeakMap();
|
|
1058
777
|
Ad4mModel.classNamesByClass = new WeakMap();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApolloClient } from "@apollo/client/core";
|
|
2
2
|
import { Perspective, PerspectiveExpression } from "../perspectives/Perspective";
|
|
3
|
-
import { RuntimeInfo, ExceptionInfo, SentMessage, NotificationInput, Notification, TriggeredNotification, ImportResult } from "./RuntimeResolver";
|
|
3
|
+
import { RuntimeInfo, ExceptionInfo, SentMessage, NotificationInput, Notification, TriggeredNotification, ImportResult, UserStatistics } from "./RuntimeResolver";
|
|
4
4
|
export type MessageCallback = (message: PerspectiveExpression) => null;
|
|
5
5
|
export type ExceptionCallback = (info: ExceptionInfo) => null;
|
|
6
6
|
export type NotificationTriggeredCallback = (notification: TriggeredNotification) => null;
|
|
@@ -39,6 +39,9 @@ export declare class RuntimeClient {
|
|
|
39
39
|
removeNotification(id: string): Promise<boolean>;
|
|
40
40
|
exportPerspective(uuid: string, filePath: string): Promise<boolean>;
|
|
41
41
|
importPerspective(filePath: string): Promise<boolean>;
|
|
42
|
+
multiUserEnabled(): Promise<boolean>;
|
|
43
|
+
setMultiUserEnabled(enabled: boolean): Promise<boolean>;
|
|
44
|
+
listUsers(): Promise<UserStatistics[]>;
|
|
42
45
|
addNotificationTriggeredCallback(cb: NotificationTriggeredCallback): void;
|
|
43
46
|
subscribeNotificationTriggered(): void;
|
|
44
47
|
addMessageCallback(cb: MessageCallback): void;
|
|
@@ -351,6 +351,36 @@ export class RuntimeClient {
|
|
|
351
351
|
}));
|
|
352
352
|
return runtimeImportPerspective;
|
|
353
353
|
}
|
|
354
|
+
async multiUserEnabled() {
|
|
355
|
+
const { runtimeMultiUserEnabled } = unwrapApolloResult(await __classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").query({
|
|
356
|
+
query: gql `query runtimeMultiUserEnabled {
|
|
357
|
+
runtimeMultiUserEnabled
|
|
358
|
+
}`,
|
|
359
|
+
}));
|
|
360
|
+
return runtimeMultiUserEnabled;
|
|
361
|
+
}
|
|
362
|
+
async setMultiUserEnabled(enabled) {
|
|
363
|
+
const { runtimeSetMultiUserEnabled } = unwrapApolloResult(await __classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").mutate({
|
|
364
|
+
mutation: gql `mutation runtimeSetMultiUserEnabled($enabled: Boolean!) {
|
|
365
|
+
runtimeSetMultiUserEnabled(enabled: $enabled)
|
|
366
|
+
}`,
|
|
367
|
+
variables: { enabled }
|
|
368
|
+
}));
|
|
369
|
+
return runtimeSetMultiUserEnabled;
|
|
370
|
+
}
|
|
371
|
+
async listUsers() {
|
|
372
|
+
const { runtimeListUsers } = unwrapApolloResult(await __classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").query({
|
|
373
|
+
query: gql `query runtimeListUsers {
|
|
374
|
+
runtimeListUsers {
|
|
375
|
+
email
|
|
376
|
+
did
|
|
377
|
+
lastSeen
|
|
378
|
+
perspectiveCount
|
|
379
|
+
}
|
|
380
|
+
}`
|
|
381
|
+
}));
|
|
382
|
+
return runtimeListUsers;
|
|
383
|
+
}
|
|
354
384
|
addNotificationTriggeredCallback(cb) {
|
|
355
385
|
__classPrivateFieldGet(this, _RuntimeClient_notificationTriggeredCallbacks, "f").push(cb);
|
|
356
386
|
}
|
|
@@ -62,6 +62,12 @@ export declare class ImportResult {
|
|
|
62
62
|
trustedAgents: ImportStats;
|
|
63
63
|
knownLinkLanguages: ImportStats;
|
|
64
64
|
}
|
|
65
|
+
export declare class UserStatistics {
|
|
66
|
+
email: string;
|
|
67
|
+
did: string;
|
|
68
|
+
lastSeen?: string;
|
|
69
|
+
perspectiveCount: number;
|
|
70
|
+
}
|
|
65
71
|
/**
|
|
66
72
|
* Resolver classes are used here to define the GraphQL schema
|
|
67
73
|
* (through the type-graphql annotations)
|
|
@@ -103,4 +109,7 @@ export default class RuntimeResolver {
|
|
|
103
109
|
runtimeImportDb(filePath: string): boolean;
|
|
104
110
|
runtimeExportPerspective(perspectiveUuid: string, filePath: string): boolean;
|
|
105
111
|
runtimeImportPerspective(filePath: string): boolean;
|
|
112
|
+
runtimeMultiUserEnabled(): boolean;
|
|
113
|
+
runtimeSetMultiUserEnabled(enabled: boolean): boolean;
|
|
114
|
+
runtimeListUsers(): UserStatistics[];
|
|
106
115
|
}
|
|
@@ -270,6 +270,28 @@ ImportResult = __decorate([
|
|
|
270
270
|
ObjectType()
|
|
271
271
|
], ImportResult);
|
|
272
272
|
export { ImportResult };
|
|
273
|
+
let UserStatistics = class UserStatistics {
|
|
274
|
+
};
|
|
275
|
+
__decorate([
|
|
276
|
+
Field(),
|
|
277
|
+
__metadata("design:type", String)
|
|
278
|
+
], UserStatistics.prototype, "email", void 0);
|
|
279
|
+
__decorate([
|
|
280
|
+
Field(),
|
|
281
|
+
__metadata("design:type", String)
|
|
282
|
+
], UserStatistics.prototype, "did", void 0);
|
|
283
|
+
__decorate([
|
|
284
|
+
Field({ nullable: true }),
|
|
285
|
+
__metadata("design:type", String)
|
|
286
|
+
], UserStatistics.prototype, "lastSeen", void 0);
|
|
287
|
+
__decorate([
|
|
288
|
+
Field(type => Int),
|
|
289
|
+
__metadata("design:type", Number)
|
|
290
|
+
], UserStatistics.prototype, "perspectiveCount", void 0);
|
|
291
|
+
UserStatistics = __decorate([
|
|
292
|
+
ObjectType()
|
|
293
|
+
], UserStatistics);
|
|
294
|
+
export { UserStatistics };
|
|
273
295
|
/**
|
|
274
296
|
* Resolver classes are used here to define the GraphQL schema
|
|
275
297
|
* (through the type-graphql annotations)
|
|
@@ -419,6 +441,20 @@ let RuntimeResolver = class RuntimeResolver {
|
|
|
419
441
|
runtimeImportPerspective(filePath) {
|
|
420
442
|
return true;
|
|
421
443
|
}
|
|
444
|
+
runtimeMultiUserEnabled() {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
runtimeSetMultiUserEnabled(enabled) {
|
|
448
|
+
return enabled;
|
|
449
|
+
}
|
|
450
|
+
runtimeListUsers() {
|
|
451
|
+
return [{
|
|
452
|
+
email: "test@example.com",
|
|
453
|
+
did: "did:key:test123",
|
|
454
|
+
lastSeen: new Date().toISOString(),
|
|
455
|
+
perspectiveCount: 5
|
|
456
|
+
}];
|
|
457
|
+
}
|
|
422
458
|
};
|
|
423
459
|
__decorate([
|
|
424
460
|
Mutation(returns => Boolean),
|
|
@@ -652,6 +688,25 @@ __decorate([
|
|
|
652
688
|
__metadata("design:paramtypes", [String]),
|
|
653
689
|
__metadata("design:returntype", Boolean)
|
|
654
690
|
], RuntimeResolver.prototype, "runtimeImportPerspective", null);
|
|
691
|
+
__decorate([
|
|
692
|
+
Query(returns => Boolean),
|
|
693
|
+
__metadata("design:type", Function),
|
|
694
|
+
__metadata("design:paramtypes", []),
|
|
695
|
+
__metadata("design:returntype", Boolean)
|
|
696
|
+
], RuntimeResolver.prototype, "runtimeMultiUserEnabled", null);
|
|
697
|
+
__decorate([
|
|
698
|
+
Mutation(returns => Boolean),
|
|
699
|
+
__param(0, Arg("enabled")),
|
|
700
|
+
__metadata("design:type", Function),
|
|
701
|
+
__metadata("design:paramtypes", [Boolean]),
|
|
702
|
+
__metadata("design:returntype", Boolean)
|
|
703
|
+
], RuntimeResolver.prototype, "runtimeSetMultiUserEnabled", null);
|
|
704
|
+
__decorate([
|
|
705
|
+
Query(returns => [UserStatistics]),
|
|
706
|
+
__metadata("design:type", Function),
|
|
707
|
+
__metadata("design:paramtypes", []),
|
|
708
|
+
__metadata("design:returntype", Array)
|
|
709
|
+
], RuntimeResolver.prototype, "runtimeListUsers", null);
|
|
655
710
|
RuntimeResolver = __decorate([
|
|
656
711
|
Resolver()
|
|
657
712
|
], RuntimeResolver);
|
package/lib/src/schema.gql
CHANGED
|
@@ -372,6 +372,7 @@ type Mutation {
|
|
|
372
372
|
runtimeRemoveNotification(id: String!): Boolean!
|
|
373
373
|
runtimeRequestInstallNotification(notification: NotificationInput!): String!
|
|
374
374
|
runtimeRestartHolochain: Boolean!
|
|
375
|
+
runtimeSetMultiUserEnabled(enabled: Boolean!): Boolean!
|
|
375
376
|
runtimeSetStatus(status: PerspectiveInput!): Boolean!
|
|
376
377
|
runtimeUpdateNotification(id: String!, notification: NotificationInput!): Boolean!
|
|
377
378
|
}
|
|
@@ -478,8 +479,10 @@ type Query {
|
|
|
478
479
|
runtimeHcAgentInfos: String!
|
|
479
480
|
runtimeInfo: RuntimeInfo!
|
|
480
481
|
runtimeKnownLinkLanguageTemplates: [String!]!
|
|
482
|
+
runtimeListUsers: [UserStatistics!]!
|
|
481
483
|
runtimeMessageInbox(filter: String): [PerspectiveExpression!]!
|
|
482
484
|
runtimeMessageOutbox(filter: String): [SentMessage!]!
|
|
485
|
+
runtimeMultiUserEnabled: Boolean!
|
|
483
486
|
runtimeNotifications: [Notification!]!
|
|
484
487
|
runtimeVerifyStringSignedByDid(data: String!, did: String!, didSigningKeyId: String!, signedData: String!): Boolean!
|
|
485
488
|
}
|
|
@@ -547,6 +550,13 @@ type TriggeredNotification {
|
|
|
547
550
|
triggerMatch: String!
|
|
548
551
|
}
|
|
549
552
|
|
|
553
|
+
type UserStatistics {
|
|
554
|
+
did: String!
|
|
555
|
+
email: String!
|
|
556
|
+
lastSeen: String
|
|
557
|
+
perspectiveCount: Int!
|
|
558
|
+
}
|
|
559
|
+
|
|
550
560
|
input VoiceActivityParamsInput {
|
|
551
561
|
endThreshold: Float
|
|
552
562
|
endWindow: Float
|
package/lib/src/typeDefs.js
CHANGED
|
@@ -368,6 +368,7 @@ type Mutation {
|
|
|
368
368
|
runtimeRemoveNotification(id: String!): Boolean!
|
|
369
369
|
runtimeRequestInstallNotification(notification: NotificationInput!): String!
|
|
370
370
|
runtimeRestartHolochain: Boolean!
|
|
371
|
+
runtimeSetMultiUserEnabled(enabled: Boolean!): Boolean!
|
|
371
372
|
runtimeSetStatus(status: PerspectiveInput!): Boolean!
|
|
372
373
|
runtimeUpdateNotification(id: String!, notification: NotificationInput!): Boolean!
|
|
373
374
|
}
|
|
@@ -474,8 +475,10 @@ type Query {
|
|
|
474
475
|
runtimeHcAgentInfos: String!
|
|
475
476
|
runtimeInfo: RuntimeInfo!
|
|
476
477
|
runtimeKnownLinkLanguageTemplates: [String!]!
|
|
478
|
+
runtimeListUsers: [UserStatistics!]!
|
|
477
479
|
runtimeMessageInbox(filter: String): [PerspectiveExpression!]!
|
|
478
480
|
runtimeMessageOutbox(filter: String): [SentMessage!]!
|
|
481
|
+
runtimeMultiUserEnabled: Boolean!
|
|
479
482
|
runtimeNotifications: [Notification!]!
|
|
480
483
|
runtimeVerifyStringSignedByDid(data: String!, did: String!, didSigningKeyId: String!, signedData: String!): Boolean!
|
|
481
484
|
}
|
|
@@ -543,6 +546,13 @@ type TriggeredNotification {
|
|
|
543
546
|
triggerMatch: String!
|
|
544
547
|
}
|
|
545
548
|
|
|
549
|
+
type UserStatistics {
|
|
550
|
+
did: String!
|
|
551
|
+
email: String!
|
|
552
|
+
lastSeen: String
|
|
553
|
+
perspectiveCount: Int!
|
|
554
|
+
}
|
|
555
|
+
|
|
546
556
|
input VoiceActivityParamsInput {
|
|
547
557
|
endThreshold: Float
|
|
548
558
|
endWindow: Float
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "patch-package && tsc && pnpm run buildSchema && pnpm run bundle",
|
|
11
11
|
"buildSchema": "node --es-module-specifier-resolution=node lib/src/buildSchema.js",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"graphql@15.7.2": "patches/graphql@15.7.2.patch"
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
|
-
"version": "0.10.1-
|
|
72
|
+
"version": "0.10.1-multi-user-1"
|
|
73
73
|
}
|