@coasys/ad4m 0.11.0 → 0.11.2-dev-multi-user

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.
@@ -1319,24 +1319,48 @@ WHERE ${whereConditions.join(' AND ')}
1319
1319
  if (!currentValue || currentValue === "" || currentValue === 0 || isEmptyObject) {
1320
1320
  let convertedValue = target;
1321
1321
 
1322
- // Parse literal URLs if property has resolveLanguage
1323
- if (propMeta.resolveLanguage === 'literal' && typeof target === 'string' && target.startsWith('literal://')) {
1324
- try {
1325
- convertedValue = Literal.fromUrl(target).get();
1326
- if(convertedValue.data !== undefined) {
1327
- convertedValue = convertedValue.data;
1322
+ // Only process if target has a value
1323
+ if (target !== undefined && target !== null) {
1324
+ // Check if we need to resolve a non-literal language expression
1325
+ if (propMeta.resolveLanguage != undefined && propMeta.resolveLanguage !== 'literal' && typeof target === 'string') {
1326
+ // For non-literal languages, resolve the expression via perspective.getExpression()
1327
+ // Note: Literals are already parsed by SurrealDB's fn::parse_literal()
1328
+ try {
1329
+ const expression = await perspective.getExpression(target);
1330
+ if (expression) {
1331
+ // Parse the expression data if it's a JSON string
1332
+ try {
1333
+ convertedValue = JSON.parse(expression.data);
1334
+ } catch {
1335
+ // If parsing fails, use the data as-is
1336
+ convertedValue = expression.data;
1337
+ }
1338
+ }
1339
+ } catch (e) {
1340
+ console.warn(`Failed to resolve expression for ${propName}:`, e);
1341
+ convertedValue = target; // Fall back to raw value
1342
+ }
1343
+ } else if (typeof target === 'string' && target.startsWith('literal://')) {
1344
+ // Fallback: If we somehow got a literal URL that wasn't parsed by SurrealDB, parse it now
1345
+ try {
1346
+ const parsed = Literal.fromUrl(target).get();
1347
+ if(parsed.data !== undefined) {
1348
+ convertedValue = parsed.data;
1349
+ } else {
1350
+ convertedValue = parsed;
1351
+ }
1352
+ } catch (e) {
1353
+ // If literal parsing fails, just use the value as-is (don't bail)
1354
+ convertedValue = target;
1355
+ }
1356
+ } else if (typeof target === 'string') {
1357
+ // Type conversion: check the instance property's current type
1358
+ const expectedType = typeof instance[propName];
1359
+ if (expectedType === 'number') {
1360
+ convertedValue = Number(target);
1361
+ } else if (expectedType === 'boolean') {
1362
+ convertedValue = target === 'true' || target === '1';
1328
1363
  }
1329
- } catch (e) {
1330
- console.warn(`Failed to parse literal URL for ${propName}:`, e);
1331
- convertedValue = target; // Fall back to raw value
1332
- }
1333
- } else {
1334
- // Type conversion: check the instance property's current type
1335
- const expectedType = typeof instance[propName];
1336
- if (expectedType === 'number' && typeof target === 'string') {
1337
- convertedValue = Number(target);
1338
- } else if (expectedType === 'boolean' && typeof target === 'string') {
1339
- convertedValue = target === 'true' || target === '1';
1340
1364
  }
1341
1365
  }
1342
1366
 
@@ -25,6 +25,7 @@ uuid
25
25
  name
26
26
  sharedUrl
27
27
  state
28
+ owners
28
29
  neighbourhood {
29
30
  data {
30
31
  linkLanguage
@@ -27,6 +27,9 @@ export class PerspectiveHandle {
27
27
  @Field(type => NeighbourhoodExpression, {nullable: true})
28
28
  neighbourhood?: NeighbourhoodExpression
29
29
 
30
+ @Field(type => [String], {nullable: true})
31
+ owners?: string[]
32
+
30
33
  constructor(uuid?: string, name?: string, state?: PerspectiveState) {
31
34
  this.uuid = uuid
32
35
  this.name = name
@@ -379,6 +379,9 @@ export class PerspectiveProxy {
379
379
  /** Current sync state if this perspective is shared */
380
380
  state: PerspectiveState|null;
381
381
 
382
+ /** List of owners of this perspective */
383
+ owners?: string[]
384
+
382
385
  #handle: PerspectiveHandle
383
386
  #client: PerspectiveClient
384
387
  #perspectiveLinkAddedCallbacks: LinkCallback[]
@@ -399,6 +402,7 @@ export class PerspectiveProxy {
399
402
  this.#client = ad4m
400
403
  this.uuid = this.#handle.uuid;
401
404
  this.name = this.#handle.name;
405
+ this.owners = this.#handle.owners;
402
406
  this.sharedUrl = this.#handle.sharedUrl;
403
407
  this.neighbourhood = this.#handle.neighbourhood;
404
408
  this.state = this.#handle.state;
@@ -1,7 +1,7 @@
1
1
  import { ApolloClient, gql } from "@apollo/client/core"
2
2
  import { Perspective, PerspectiveExpression } from "../perspectives/Perspective"
3
3
  import unwrapApolloResult from "../unwrapApolloResult"
4
- import { RuntimeInfo, ExceptionInfo, SentMessage, NotificationInput, Notification, TriggeredNotification, ImportResult } from "./RuntimeResolver"
4
+ import { RuntimeInfo, ExceptionInfo, SentMessage, NotificationInput, Notification, TriggeredNotification, ImportResult, UserStatistics } from "./RuntimeResolver"
5
5
 
6
6
  const PERSPECTIVE_EXPRESSION_FIELDS = `
7
7
  author
@@ -386,6 +386,39 @@ export class RuntimeClient {
386
386
  return runtimeImportPerspective
387
387
  }
388
388
 
389
+ async multiUserEnabled(): Promise<boolean> {
390
+ const { runtimeMultiUserEnabled } = unwrapApolloResult(await this.#apolloClient.query({
391
+ query: gql`query runtimeMultiUserEnabled {
392
+ runtimeMultiUserEnabled
393
+ }`,
394
+ }))
395
+ return runtimeMultiUserEnabled
396
+ }
397
+
398
+ async setMultiUserEnabled(enabled: boolean): Promise<boolean> {
399
+ const { runtimeSetMultiUserEnabled } = unwrapApolloResult(await this.#apolloClient.mutate({
400
+ mutation: gql`mutation runtimeSetMultiUserEnabled($enabled: Boolean!) {
401
+ runtimeSetMultiUserEnabled(enabled: $enabled)
402
+ }`,
403
+ variables: { enabled }
404
+ }))
405
+ return runtimeSetMultiUserEnabled
406
+ }
407
+
408
+ async listUsers(): Promise<UserStatistics[]> {
409
+ const { runtimeListUsers } = unwrapApolloResult(await this.#apolloClient.query({
410
+ query: gql`query runtimeListUsers {
411
+ runtimeListUsers {
412
+ email
413
+ did
414
+ lastSeen
415
+ perspectiveCount
416
+ }
417
+ }`
418
+ }))
419
+ return runtimeListUsers
420
+ }
421
+
389
422
  addNotificationTriggeredCallback(cb: NotificationTriggeredCallback) {
390
423
  this.#notificationTriggeredCallbacks.push(cb)
391
424
  }
@@ -192,6 +192,21 @@ export class ImportResult {
192
192
  knownLinkLanguages: ImportStats;
193
193
  }
194
194
 
195
+ @ObjectType()
196
+ export class UserStatistics {
197
+ @Field()
198
+ email: string;
199
+
200
+ @Field()
201
+ did: string;
202
+
203
+ @Field({nullable: true})
204
+ lastSeen?: string;
205
+
206
+ @Field(type => Int)
207
+ perspectiveCount: number;
208
+ }
209
+
195
210
  /**
196
211
  * Resolver classes are used here to define the GraphQL schema
197
212
  * (through the type-graphql annotations)
@@ -426,5 +441,25 @@ export default class RuntimeResolver {
426
441
  runtimeImportPerspective(@Arg("filePath", type => String) filePath: string): boolean {
427
442
  return true
428
443
  }
444
+
445
+ @Query(returns => Boolean)
446
+ runtimeMultiUserEnabled(): boolean {
447
+ return false
448
+ }
449
+
450
+ @Mutation(returns => Boolean)
451
+ runtimeSetMultiUserEnabled(@Arg("enabled") enabled: boolean): boolean {
452
+ return enabled
453
+ }
454
+
455
+ @Query(returns => [UserStatistics])
456
+ runtimeListUsers(): UserStatistics[] {
457
+ return [{
458
+ email: "test@example.com",
459
+ did: "did:key:test123",
460
+ lastSeen: new Date().toISOString(),
461
+ perspectiveCount: 5
462
+ }]
463
+ }
429
464
  }
430
465