@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 CHANGED
@@ -4071,6 +4071,52 @@ exports.AuthInfoInput = __decorate$b([
4071
4071
  InputType(),
4072
4072
  __metadata$b("design:paramtypes", [String, String, String, String, String, Array])
4073
4073
  ], exports.AuthInfoInput);
4074
+ exports.User = class User {
4075
+ constructor(username, did, password) {
4076
+ this.username = username;
4077
+ this.did = did;
4078
+ this.password = password;
4079
+ }
4080
+ };
4081
+ __decorate$b([
4082
+ Field(),
4083
+ __metadata$b("design:type", String)
4084
+ ], exports.User.prototype, "username", void 0);
4085
+ __decorate$b([
4086
+ Field(),
4087
+ __metadata$b("design:type", String)
4088
+ ], exports.User.prototype, "did", void 0);
4089
+ __decorate$b([
4090
+ Field(),
4091
+ __metadata$b("design:type", String)
4092
+ ], exports.User.prototype, "password", void 0);
4093
+ exports.User = __decorate$b([
4094
+ ObjectType(),
4095
+ __metadata$b("design:paramtypes", [String, String, String])
4096
+ ], exports.User);
4097
+ exports.UserCreationResult = class UserCreationResult {
4098
+ constructor(did, success, error) {
4099
+ this.did = did;
4100
+ this.success = success;
4101
+ this.error = error;
4102
+ }
4103
+ };
4104
+ __decorate$b([
4105
+ Field(),
4106
+ __metadata$b("design:type", String)
4107
+ ], exports.UserCreationResult.prototype, "did", void 0);
4108
+ __decorate$b([
4109
+ Field(),
4110
+ __metadata$b("design:type", Boolean)
4111
+ ], exports.UserCreationResult.prototype, "success", void 0);
4112
+ __decorate$b([
4113
+ Field(),
4114
+ __metadata$b("design:type", String)
4115
+ ], exports.UserCreationResult.prototype, "error", void 0);
4116
+ exports.UserCreationResult = __decorate$b([
4117
+ ObjectType(),
4118
+ __metadata$b("design:paramtypes", [String, Boolean, String])
4119
+ ], exports.UserCreationResult);
4074
4120
 
4075
4121
  var __decorate$a = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
4076
4122
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -6670,6 +6716,29 @@ class AgentClient {
6670
6716
  }));
6671
6717
  return agentSignMessage;
6672
6718
  }
6719
+ // Multi-user methods
6720
+ async createUser(email, password) {
6721
+ const { runtimeCreateUser } = unwrapApolloResult(await __classPrivateFieldGet$8(this, _AgentClient_apolloClient, "f").mutate({
6722
+ mutation: gql `mutation runtimeCreateUser($email: String!, $password: String!) {
6723
+ runtimeCreateUser(email: $email, password: $password) {
6724
+ did
6725
+ success
6726
+ error
6727
+ }
6728
+ }`,
6729
+ variables: { email, password },
6730
+ }));
6731
+ return runtimeCreateUser;
6732
+ }
6733
+ async loginUser(email, password) {
6734
+ const { runtimeLoginUser } = unwrapApolloResult(await __classPrivateFieldGet$8(this, _AgentClient_apolloClient, "f").mutate({
6735
+ mutation: gql `mutation runtimeLoginUser($email: String!, $password: String!) {
6736
+ runtimeLoginUser(email: $email, password: $password)
6737
+ }`,
6738
+ variables: { email, password },
6739
+ }));
6740
+ return runtimeLoginUser;
6741
+ }
6673
6742
  }
6674
6743
  _AgentClient_apolloClient = new WeakMap(), _AgentClient_appsChangedCallback = new WeakMap(), _AgentClient_updatedCallbacks = new WeakMap(), _AgentClient_agentStatusChangedCallbacks = new WeakMap();
6675
6744
 
@@ -7418,6 +7487,36 @@ class RuntimeClient {
7418
7487
  }));
7419
7488
  return runtimeImportPerspective;
7420
7489
  }
7490
+ async multiUserEnabled() {
7491
+ const { runtimeMultiUserEnabled } = unwrapApolloResult(await __classPrivateFieldGet$5(this, _RuntimeClient_apolloClient, "f").query({
7492
+ query: gql `query runtimeMultiUserEnabled {
7493
+ runtimeMultiUserEnabled
7494
+ }`,
7495
+ }));
7496
+ return runtimeMultiUserEnabled;
7497
+ }
7498
+ async setMultiUserEnabled(enabled) {
7499
+ const { runtimeSetMultiUserEnabled } = unwrapApolloResult(await __classPrivateFieldGet$5(this, _RuntimeClient_apolloClient, "f").mutate({
7500
+ mutation: gql `mutation runtimeSetMultiUserEnabled($enabled: Boolean!) {
7501
+ runtimeSetMultiUserEnabled(enabled: $enabled)
7502
+ }`,
7503
+ variables: { enabled }
7504
+ }));
7505
+ return runtimeSetMultiUserEnabled;
7506
+ }
7507
+ async listUsers() {
7508
+ const { runtimeListUsers } = unwrapApolloResult(await __classPrivateFieldGet$5(this, _RuntimeClient_apolloClient, "f").query({
7509
+ query: gql `query runtimeListUsers {
7510
+ runtimeListUsers {
7511
+ email
7512
+ did
7513
+ lastSeen
7514
+ perspectiveCount
7515
+ }
7516
+ }`
7517
+ }));
7518
+ return runtimeListUsers;
7519
+ }
7421
7520
  addNotificationTriggeredCallback(cb) {
7422
7521
  __classPrivateFieldGet$5(this, _RuntimeClient_notificationTriggeredCallbacks, "f").push(cb);
7423
7522
  }
@@ -16699,6 +16798,7 @@ type Mutation {
16699
16798
  runtimeRemoveNotification(id: String!): Boolean!
16700
16799
  runtimeRequestInstallNotification(notification: NotificationInput!): String!
16701
16800
  runtimeRestartHolochain: Boolean!
16801
+ runtimeSetMultiUserEnabled(enabled: Boolean!): Boolean!
16702
16802
  runtimeSetStatus(status: PerspectiveInput!): Boolean!
16703
16803
  runtimeUpdateNotification(id: String!, notification: NotificationInput!): Boolean!
16704
16804
  }
@@ -16805,8 +16905,10 @@ type Query {
16805
16905
  runtimeHcAgentInfos: String!
16806
16906
  runtimeInfo: RuntimeInfo!
16807
16907
  runtimeKnownLinkLanguageTemplates: [String!]!
16908
+ runtimeListUsers: [UserStatistics!]!
16808
16909
  runtimeMessageInbox(filter: String): [PerspectiveExpression!]!
16809
16910
  runtimeMessageOutbox(filter: String): [SentMessage!]!
16911
+ runtimeMultiUserEnabled: Boolean!
16810
16912
  runtimeNotifications: [Notification!]!
16811
16913
  runtimeVerifyStringSignedByDid(data: String!, did: String!, didSigningKeyId: String!, signedData: String!): Boolean!
16812
16914
  }
@@ -16874,6 +16976,13 @@ type TriggeredNotification {
16874
16976
  triggerMatch: String!
16875
16977
  }
16876
16978
 
16979
+ type UserStatistics {
16980
+ did: String!
16981
+ email: String!
16982
+ lastSeen: String
16983
+ perspectiveCount: Int!
16984
+ }
16985
+
16877
16986
  input VoiceActivityParamsInput {
16878
16987
  endThreshold: Float
16879
16988
  endWindow: Float
@@ -17162,6 +17271,27 @@ __decorate([
17162
17271
  exports.ImportResult = __decorate([
17163
17272
  ObjectType()
17164
17273
  ], exports.ImportResult);
17274
+ exports.UserStatistics = class UserStatistics {
17275
+ };
17276
+ __decorate([
17277
+ Field(),
17278
+ __metadata("design:type", String)
17279
+ ], exports.UserStatistics.prototype, "email", void 0);
17280
+ __decorate([
17281
+ Field(),
17282
+ __metadata("design:type", String)
17283
+ ], exports.UserStatistics.prototype, "did", void 0);
17284
+ __decorate([
17285
+ Field(),
17286
+ __metadata("design:type", String)
17287
+ ], exports.UserStatistics.prototype, "lastSeen", void 0);
17288
+ __decorate([
17289
+ Field(),
17290
+ __metadata("design:type", Number)
17291
+ ], exports.UserStatistics.prototype, "perspectiveCount", void 0);
17292
+ exports.UserStatistics = __decorate([
17293
+ ObjectType()
17294
+ ], exports.UserStatistics);
17165
17295
  /**
17166
17296
  * Resolver classes are used here to define the GraphQL schema
17167
17297
  * (through the type-graphql annotations)
@@ -17311,6 +17441,20 @@ let RuntimeResolver = class RuntimeResolver {
17311
17441
  runtimeImportPerspective(filePath) {
17312
17442
  return true;
17313
17443
  }
17444
+ runtimeMultiUserEnabled() {
17445
+ return false;
17446
+ }
17447
+ runtimeSetMultiUserEnabled(enabled) {
17448
+ return enabled;
17449
+ }
17450
+ runtimeListUsers() {
17451
+ return [{
17452
+ email: "test@example.com",
17453
+ did: "did:key:test123",
17454
+ lastSeen: new Date().toISOString(),
17455
+ perspectiveCount: 5
17456
+ }];
17457
+ }
17314
17458
  };
17315
17459
  __decorate([
17316
17460
  Mutation(),
@@ -17544,6 +17688,25 @@ __decorate([
17544
17688
  __metadata("design:paramtypes", [String]),
17545
17689
  __metadata("design:returntype", Boolean)
17546
17690
  ], RuntimeResolver.prototype, "runtimeImportPerspective", null);
17691
+ __decorate([
17692
+ Query(),
17693
+ __metadata("design:type", Function),
17694
+ __metadata("design:paramtypes", []),
17695
+ __metadata("design:returntype", Boolean)
17696
+ ], RuntimeResolver.prototype, "runtimeMultiUserEnabled", null);
17697
+ __decorate([
17698
+ Mutation(),
17699
+ __param(0, Arg()),
17700
+ __metadata("design:type", Function),
17701
+ __metadata("design:paramtypes", [Boolean]),
17702
+ __metadata("design:returntype", Boolean)
17703
+ ], RuntimeResolver.prototype, "runtimeSetMultiUserEnabled", null);
17704
+ __decorate([
17705
+ Query(),
17706
+ __metadata("design:type", Function),
17707
+ __metadata("design:paramtypes", []),
17708
+ __metadata("design:returntype", Array)
17709
+ ], RuntimeResolver.prototype, "runtimeListUsers", null);
17547
17710
  RuntimeResolver = __decorate([
17548
17711
  Resolver()
17549
17712
  ], RuntimeResolver);
@@ -18318,287 +18481,6 @@ class Ad4mModel {
18318
18481
  static query(perspective, query) {
18319
18482
  return new ModelQueryBuilder(perspective, this, query);
18320
18483
  }
18321
- /**
18322
- * Creates an Ad4mModel class from a JSON Schema definition.
18323
- *
18324
- * @description
18325
- * This method dynamically generates an Ad4mModel subclass from a JSON Schema,
18326
- * enabling integration with systems that use JSON Schema for type definitions.
18327
- *
18328
- * The method follows a cascading approach for determining predicates:
18329
- * 1. Explicit configuration in options parameter (highest precedence)
18330
- * 2. x-ad4m metadata in the JSON Schema
18331
- * 3. Inference from schema title and property names
18332
- * 4. Error if no namespace can be determined
18333
- *
18334
- * @example
18335
- * ```typescript
18336
- * // With explicit configuration
18337
- * const PersonClass = Ad4mModel.fromJSONSchema(schema, {
18338
- * name: "Person",
18339
- * namespace: "person://",
18340
- * resolveLanguage: "literal"
18341
- * });
18342
- *
18343
- * // With property mapping
18344
- * const ContactClass = Ad4mModel.fromJSONSchema(schema, {
18345
- * name: "Contact",
18346
- * namespace: "contact://",
18347
- * propertyMapping: {
18348
- * "name": "foaf://name",
18349
- * "email": "foaf://mbox"
18350
- * }
18351
- * });
18352
- *
18353
- * // With x-ad4m metadata in schema
18354
- * const schema = {
18355
- * "title": "Product",
18356
- * "x-ad4m": { "namespace": "product://" },
18357
- * "properties": {
18358
- * "name": {
18359
- * "type": "string",
18360
- * "x-ad4m": { "through": "product://title" }
18361
- * }
18362
- * }
18363
- * };
18364
- * const ProductClass = Ad4mModel.fromJSONSchema(schema, { name: "Product" });
18365
- * ```
18366
- *
18367
- * @param schema - JSON Schema definition
18368
- * @param options - Configuration options
18369
- * @returns Generated Ad4mModel subclass
18370
- * @throws Error when namespace cannot be inferred
18371
- */
18372
- static fromJSONSchema(schema, options) {
18373
- // Disallow top-level "author" property since Ad4mModel provides it implicitly via link authorship
18374
- if (schema?.properties && Object.prototype.hasOwnProperty.call(schema.properties, "author")) {
18375
- 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").');
18376
- }
18377
- // Determine namespace with cascading precedence
18378
- const namespace = this.determineNamespace(schema, options);
18379
- // Create the dynamic class
18380
- const DynamicModelClass = class extends Ad4mModel {
18381
- };
18382
- // Set up class metadata
18383
- Object.defineProperty(DynamicModelClass, 'name', { value: options.name });
18384
- DynamicModelClass.className = options.name;
18385
- DynamicModelClass.prototype.className = options.name;
18386
- // Generate properties and collections metadata
18387
- const properties = {};
18388
- const collections = {};
18389
- if (schema.properties) {
18390
- for (const [propertyName, propertySchema] of Object.entries(schema.properties)) {
18391
- const predicate = this.determinePredicate(schema, propertyName, propertySchema, namespace, options);
18392
- const isRequired = schema.required?.includes(propertyName) || false;
18393
- const isArray = propertySchema.type === 'array';
18394
- if (isArray) {
18395
- // Handle arrays as collections
18396
- // Store the singular form as the collection key since SDNA generation expects singular
18397
- collections[propertyName] = {
18398
- through: predicate,
18399
- local: this.getPropertyOption(propertyName, propertySchema, options, 'local')
18400
- };
18401
- // Define the property on prototype
18402
- Object.defineProperty(DynamicModelClass.prototype, propertyName, {
18403
- configurable: true,
18404
- writable: true,
18405
- value: []
18406
- });
18407
- // Add collection methods
18408
- const adderName = `add${capitalize(propertyName)}`;
18409
- const removerName = `remove${capitalize(propertyName)}`;
18410
- const setterName = `setCollection${capitalize(propertyName)}`;
18411
- DynamicModelClass.prototype[adderName] = function () {
18412
- // Placeholder function for SDNA generation
18413
- };
18414
- DynamicModelClass.prototype[removerName] = function () {
18415
- // Placeholder function for SDNA generation
18416
- };
18417
- DynamicModelClass.prototype[setterName] = function () {
18418
- // Placeholder function for SDNA generation
18419
- };
18420
- }
18421
- else {
18422
- // Handle regular properties
18423
- let resolveLanguage = this.getPropertyOption(propertyName, propertySchema, options, 'resolveLanguage');
18424
- // If no specific resolveLanguage for this property, use the global one
18425
- if (!resolveLanguage && options.resolveLanguage) {
18426
- resolveLanguage = options.resolveLanguage;
18427
- }
18428
- const local = this.getPropertyOption(propertyName, propertySchema, options, 'local');
18429
- const writable = this.getPropertyOption(propertyName, propertySchema, options, 'writable', true);
18430
- let initial = this.getPropertyOption(propertyName, propertySchema, options, 'initial');
18431
- // Handle nested objects by serializing to JSON
18432
- if (propertySchema.type === 'object' && !resolveLanguage) {
18433
- resolveLanguage = 'literal';
18434
- console.warn(`Property "${propertyName}" is an object type. It will be stored as JSON. Consider flattening complex objects for better semantic querying.`);
18435
- }
18436
- // Ensure numeric properties use literal language for correct typing
18437
- if ((resolveLanguage === undefined || resolveLanguage === null) && (propertySchema.type === 'number' || propertySchema.type === 'integer')) {
18438
- resolveLanguage = 'literal';
18439
- }
18440
- // If property is required, ensure it has an initial value
18441
- if (isRequired && !initial) {
18442
- if (propertySchema.type === 'object') {
18443
- initial = 'literal://json:{}';
18444
- }
18445
- else {
18446
- initial = "ad4m://undefined";
18447
- }
18448
- }
18449
- properties[propertyName] = {
18450
- through: predicate,
18451
- required: isRequired,
18452
- writable: writable,
18453
- ...(resolveLanguage && { resolveLanguage }),
18454
- ...(local !== undefined && { local }),
18455
- ...(initial && { initial })
18456
- };
18457
- // Define the property on prototype
18458
- Object.defineProperty(DynamicModelClass.prototype, propertyName, {
18459
- configurable: true,
18460
- writable: true,
18461
- value: this.getDefaultValueForType(propertySchema.type)
18462
- });
18463
- // Add setter function if writable
18464
- if (writable) {
18465
- const setterName = propertyNameToSetterName(propertyName);
18466
- DynamicModelClass.prototype[setterName] = function () {
18467
- // This is a placeholder function that the SDNA generation looks for
18468
- // The actual setter logic is handled by the Ad4mModel base class
18469
- };
18470
- }
18471
- }
18472
- }
18473
- }
18474
- // Validate that at least one property has an initial value (needed for valid SDNA constructor)
18475
- // Collections don't create constructor actions, only properties with initial values do
18476
- const hasPropertyWithInitial = Object.values(properties).some((prop) => prop.initial);
18477
- if (!hasPropertyWithInitial) {
18478
- // If no properties have initial values, add a type identifier automatically
18479
- const typeProperty = `ad4m://type`;
18480
- const typeValue = `${namespace.replace('://', '')}://instance`;
18481
- properties['__ad4m_type'] = {
18482
- through: typeProperty,
18483
- required: true,
18484
- writable: false,
18485
- initial: typeValue,
18486
- flag: true
18487
- };
18488
- // Add the type property to the prototype
18489
- Object.defineProperty(DynamicModelClass.prototype, '__ad4m_type', {
18490
- configurable: true,
18491
- writable: false,
18492
- value: typeValue
18493
- });
18494
- console.warn(`No properties with initial values found. Added automatic type flag: ${typeProperty} = ${typeValue}`);
18495
- }
18496
- // Attach metadata to prototype
18497
- DynamicModelClass.prototype.__properties = properties;
18498
- DynamicModelClass.prototype.__collections = collections;
18499
- // Apply the ModelOptions decorator to set up the generateSDNA method
18500
- const ModelOptionsDecorator = ModelOptions({ name: options.name });
18501
- ModelOptionsDecorator(DynamicModelClass);
18502
- return DynamicModelClass;
18503
- }
18504
- /**
18505
- * Determines the namespace for predicates using cascading precedence
18506
- */
18507
- static determineNamespace(schema, options) {
18508
- // 1. Explicit namespace in options (highest precedence)
18509
- if (options.namespace) {
18510
- return options.namespace;
18511
- }
18512
- // 2. x-ad4m metadata in schema
18513
- if (schema["x-ad4m"]?.namespace) {
18514
- return schema["x-ad4m"].namespace;
18515
- }
18516
- // 3. Infer from schema title
18517
- if (schema.title) {
18518
- return `${schema.title.toLowerCase()}://`;
18519
- }
18520
- // 4. Try to extract from $id if it's a URL
18521
- if (schema.$id) {
18522
- try {
18523
- const url = new URL(schema.$id);
18524
- const pathParts = url.pathname.split('/').filter(p => p);
18525
- if (pathParts.length > 0) {
18526
- const lastPart = pathParts[pathParts.length - 1];
18527
- const baseName = lastPart.replace(/\.schema\.json$/, '').replace(/\.json$/, '');
18528
- return `${baseName.toLowerCase()}://`;
18529
- }
18530
- }
18531
- catch {
18532
- // If $id is not a valid URL, continue to error
18533
- }
18534
- }
18535
- // 5. Error if no namespace can be determined
18536
- throw new Error(`Cannot infer namespace for JSON Schema. Please provide one of:
18537
- - options.namespace
18538
- - schema["x-ad4m"].namespace
18539
- - schema.title
18540
- - valid schema.$id`);
18541
- }
18542
- /**
18543
- * Determines the predicate for a specific property using cascading precedence
18544
- */
18545
- static determinePredicate(schema, propertyName, propertySchema, namespace, options) {
18546
- // 1. Explicit property mapping (highest precedence)
18547
- if (options.propertyMapping?.[propertyName]) {
18548
- return options.propertyMapping[propertyName];
18549
- }
18550
- // 2. x-ad4m metadata in property schema
18551
- if (propertySchema["x-ad4m"]?.through) {
18552
- return propertySchema["x-ad4m"].through;
18553
- }
18554
- // 3. Generate from namespace + property name
18555
- if (options.predicateTemplate) {
18556
- return options.predicateTemplate
18557
- .replace('${namespace}', namespace.replace('://', ''))
18558
- .replace('${title}', schema.title || '')
18559
- .replace('${property}', propertyName);
18560
- }
18561
- // 4. Custom predicate generator
18562
- if (options.predicateGenerator) {
18563
- return options.predicateGenerator(schema.title || '', propertyName);
18564
- }
18565
- // 5. Default: namespace + property name
18566
- const cleanNamespace = namespace.endsWith('://') ? namespace.slice(0, -3) : namespace;
18567
- return `${cleanNamespace}://${propertyName}`;
18568
- }
18569
- /**
18570
- * Gets property-specific options using cascading precedence
18571
- */
18572
- static getPropertyOption(propertyName, propertySchema, options, optionName, defaultValue) {
18573
- // 1. Property-specific options
18574
- if (options.propertyOptions?.[propertyName]?.[optionName] !== undefined) {
18575
- return options.propertyOptions[propertyName][optionName];
18576
- }
18577
- // 2. x-ad4m metadata in property
18578
- if (propertySchema["x-ad4m"]?.[optionName] !== undefined) {
18579
- return propertySchema["x-ad4m"][optionName];
18580
- }
18581
- // 3. Global option
18582
- if (options[optionName] !== undefined) {
18583
- return options[optionName];
18584
- }
18585
- // 4. Default value
18586
- return defaultValue;
18587
- }
18588
- /**
18589
- * Gets default value for a JSON Schema type
18590
- */
18591
- static getDefaultValueForType(type) {
18592
- switch (type) {
18593
- case 'string': return '';
18594
- case 'number': return 0;
18595
- case 'integer': return 0;
18596
- case 'boolean': return false;
18597
- case 'array': return [];
18598
- case 'object': return {};
18599
- default: return '';
18600
- }
18601
- }
18602
18484
  }
18603
18485
  _Ad4mModel_baseExpression = new WeakMap(), _Ad4mModel_subjectClassName = new WeakMap(), _Ad4mModel_source = new WeakMap(), _Ad4mModel_perspective = new WeakMap();
18604
18486
  Ad4mModel.classNamesByClass = new WeakMap();