@coasys/ad4m 0.12.1-dev → 0.13.0-test-2

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.
Files changed (97) hide show
  1. package/lib/index.cjs +1469 -781
  2. package/lib/index.js +1453 -779
  3. package/lib/src/Literal.js +6 -5
  4. package/lib/src/agent/AgentClient.d.ts +8 -1
  5. package/lib/src/agent/AgentClient.js +73 -2
  6. package/lib/src/expression/ExpressionRef.js +2 -2
  7. package/lib/src/language/Language.d.ts +41 -3
  8. package/lib/src/model/Ad4mModel.d.ts +28 -28
  9. package/lib/src/model/Ad4mModel.js +129 -101
  10. package/lib/src/model/Ad4mModel.test.js +1543 -535
  11. package/lib/src/model/ModelQueryBuilder.d.ts +48 -34
  12. package/lib/src/model/ModelQueryBuilder.js +163 -78
  13. package/lib/src/model/Subject.js +6 -6
  14. package/lib/src/model/decorators.d.ts +14 -8
  15. package/lib/src/model/decorators.js +41 -14
  16. package/lib/src/model/hydration-batch.d.ts +34 -0
  17. package/lib/src/model/hydration-batch.js +147 -0
  18. package/lib/src/model/hydration.d.ts +3 -3
  19. package/lib/src/model/hydration.js +106 -36
  20. package/lib/src/model/index.d.ts +4 -1
  21. package/lib/src/model/index.js +4 -1
  22. package/lib/src/model/json-schema.js +2 -2
  23. package/lib/src/model/query-cache.d.ts +30 -0
  24. package/lib/src/model/query-cache.js +66 -0
  25. package/lib/src/model/query-cache.test.d.ts +1 -0
  26. package/lib/src/model/query-cache.test.js +43 -0
  27. package/lib/src/model/query-common.d.ts +1 -1
  28. package/lib/src/model/query-common.js +1 -1
  29. package/lib/src/model/query-sparql-batch.d.ts +17 -0
  30. package/lib/src/model/query-sparql-batch.js +260 -0
  31. package/lib/src/model/query-sparql.d.ts +47 -0
  32. package/lib/src/model/query-sparql.js +336 -0
  33. package/lib/src/model/query-utils.d.ts +45 -0
  34. package/lib/src/model/query-utils.js +140 -0
  35. package/lib/src/model/relation-filtering.test.js +15 -15
  36. package/lib/src/model/sdna.js +1 -1
  37. package/lib/src/model/shacl-gen.js +42 -18
  38. package/lib/src/model/subscription-pool.d.ts +39 -0
  39. package/lib/src/model/subscription-pool.js +119 -0
  40. package/lib/src/model/types.d.ts +3 -3
  41. package/lib/src/model/types.js +1 -1
  42. package/lib/src/perspectives/PerspectiveClient.d.ts +1 -17
  43. package/lib/src/perspectives/PerspectiveClient.js +5 -57
  44. package/lib/src/perspectives/PerspectiveProxy.d.ts +51 -30
  45. package/lib/src/perspectives/PerspectiveProxy.js +224 -177
  46. package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
  47. package/lib/src/perspectives/PerspectiveResolver.js +0 -11
  48. package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
  49. package/lib/src/perspectives/WakerSubscriptionManager.js +7 -8
  50. package/lib/src/runtime/RuntimeClient.d.ts +2 -0
  51. package/lib/src/runtime/RuntimeClient.js +17 -0
  52. package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
  53. package/lib/src/runtime/RuntimeResolver.js +84 -0
  54. package/lib/src/schema.gql +14 -1
  55. package/lib/src/shacl/SHACLFlow.d.ts +1 -1
  56. package/lib/src/shacl/SHACLFlow.js +9 -9
  57. package/lib/src/shacl/SHACLShape.d.ts +1 -1
  58. package/lib/src/shacl/SHACLShape.js +38 -38
  59. package/lib/src/typeDefs.js +14 -1
  60. package/lib/src/utils.d.ts +6 -6
  61. package/lib/src/utils.js +6 -6
  62. package/package.json +1 -1
  63. package/src/Literal.test.ts +10 -5
  64. package/src/Literal.ts +6 -5
  65. package/src/agent/AgentClient.ts +81 -1
  66. package/src/expression/ExpressionRef.ts +2 -2
  67. package/src/language/Language.ts +48 -3
  68. package/src/model/Ad4mModel.test.ts +1515 -565
  69. package/src/model/Ad4mModel.ts +142 -102
  70. package/src/model/ModelQueryBuilder.ts +185 -86
  71. package/src/model/Subject.ts +6 -6
  72. package/src/model/decorators.ts +51 -22
  73. package/src/model/hydration-batch.ts +205 -0
  74. package/src/model/hydration.ts +102 -39
  75. package/src/model/index.ts +4 -1
  76. package/src/model/json-schema.ts +2 -2
  77. package/src/model/query-cache.test.ts +54 -0
  78. package/src/model/query-cache.ts +79 -0
  79. package/src/model/query-common.ts +1 -1
  80. package/src/model/query-sparql-batch.ts +301 -0
  81. package/src/model/query-sparql.ts +363 -0
  82. package/src/model/{surreal-utils.ts → query-utils.ts} +40 -27
  83. package/src/model/relation-filtering.test.ts +15 -15
  84. package/src/model/sdna.ts +1 -1
  85. package/src/model/shacl-gen.ts +42 -17
  86. package/src/model/subscription-pool.ts +163 -0
  87. package/src/model/types.ts +3 -3
  88. package/src/perspectives/PerspectiveClient.ts +5 -61
  89. package/src/perspectives/PerspectiveProxy.ts +226 -181
  90. package/src/perspectives/PerspectiveResolver.ts +0 -8
  91. package/src/perspectives/WakerSubscriptionManager.ts +8 -9
  92. package/src/runtime/RuntimeClient.ts +19 -0
  93. package/src/runtime/RuntimeResolver.ts +58 -0
  94. package/src/shacl/SHACLFlow.ts +9 -9
  95. package/src/shacl/SHACLShape.ts +39 -39
  96. package/src/utils.ts +6 -6
  97. package/src/model/query-surreal.ts +0 -280
@@ -217,7 +217,7 @@ export class SHACLShape {
217
217
  links.push({
218
218
  source: this.nodeShapeUri,
219
219
  predicate: "ad4m://constructor",
220
- target: `literal://string:${JSON.stringify(this.constructor_actions)}`
220
+ target: `literal:string:${JSON.stringify(this.constructor_actions)}`
221
221
  });
222
222
  }
223
223
  // Destructor actions — same rationale as constructor.
@@ -225,7 +225,7 @@ export class SHACLShape {
225
225
  links.push({
226
226
  source: this.nodeShapeUri,
227
227
  predicate: "ad4m://destructor",
228
- target: `literal://string:${JSON.stringify(this.destructor_actions)}`
228
+ target: `literal:string:${JSON.stringify(this.destructor_actions)}`
229
229
  });
230
230
  }
231
231
  // Property shapes (each gets a named URI: {namespace}/{ClassName}.{propertyName})
@@ -275,42 +275,42 @@ export class SHACLShape {
275
275
  links.push({
276
276
  source: propShapeId,
277
277
  predicate: "sh://minCount",
278
- target: `literal://${prop.minCount}^^xsd:integer`
278
+ target: `literal:${prop.minCount}^^xsd:integer`
279
279
  });
280
280
  }
281
281
  if (prop.maxCount !== undefined) {
282
282
  links.push({
283
283
  source: propShapeId,
284
284
  predicate: "sh://maxCount",
285
- target: `literal://${prop.maxCount}^^xsd:integer`
285
+ target: `literal:${prop.maxCount}^^xsd:integer`
286
286
  });
287
287
  }
288
288
  if (prop.pattern) {
289
289
  links.push({
290
290
  source: propShapeId,
291
291
  predicate: "sh://pattern",
292
- target: `literal://${prop.pattern}`
292
+ target: `literal:${prop.pattern}`
293
293
  });
294
294
  }
295
295
  if (prop.minInclusive !== undefined) {
296
296
  links.push({
297
297
  source: propShapeId,
298
298
  predicate: "sh://minInclusive",
299
- target: `literal://${prop.minInclusive}`
299
+ target: `literal:${prop.minInclusive}`
300
300
  });
301
301
  }
302
302
  if (prop.maxInclusive !== undefined) {
303
303
  links.push({
304
304
  source: propShapeId,
305
305
  predicate: "sh://maxInclusive",
306
- target: `literal://${prop.maxInclusive}`
306
+ target: `literal:${prop.maxInclusive}`
307
307
  });
308
308
  }
309
309
  if (prop.hasValue) {
310
310
  links.push({
311
311
  source: propShapeId,
312
312
  predicate: "sh://hasValue",
313
- target: `literal://${prop.hasValue}`
313
+ target: `literal:${prop.hasValue}`
314
314
  });
315
315
  }
316
316
  // AD4M-specific metadata
@@ -318,21 +318,21 @@ export class SHACLShape {
318
318
  links.push({
319
319
  source: propShapeId,
320
320
  predicate: "ad4m://local",
321
- target: `literal://${prop.local}`
321
+ target: `literal:${prop.local}`
322
322
  });
323
323
  }
324
324
  if (prop.writable !== undefined) {
325
325
  links.push({
326
326
  source: propShapeId,
327
327
  predicate: "ad4m://writable",
328
- target: `literal://${prop.writable}`
328
+ target: `literal:${prop.writable}`
329
329
  });
330
330
  }
331
331
  if (prop.resolveLanguage) {
332
332
  links.push({
333
333
  source: propShapeId,
334
334
  predicate: "ad4m://resolveLanguage",
335
- target: `literal://string:${prop.resolveLanguage}`
335
+ target: `literal:string:${prop.resolveLanguage}`
336
336
  });
337
337
  }
338
338
  // AD4M-specific actions
@@ -340,35 +340,35 @@ export class SHACLShape {
340
340
  links.push({
341
341
  source: propShapeId,
342
342
  predicate: "ad4m://setter",
343
- target: `literal://string:${JSON.stringify(prop.setter)}`
343
+ target: `literal:string:${JSON.stringify(prop.setter)}`
344
344
  });
345
345
  }
346
346
  if (prop.adder && prop.adder.length > 0) {
347
347
  links.push({
348
348
  source: propShapeId,
349
349
  predicate: "ad4m://adder",
350
- target: `literal://string:${JSON.stringify(prop.adder)}`
350
+ target: `literal:string:${JSON.stringify(prop.adder)}`
351
351
  });
352
352
  }
353
353
  if (prop.remover && prop.remover.length > 0) {
354
354
  links.push({
355
355
  source: propShapeId,
356
356
  predicate: "ad4m://remover",
357
- target: `literal://string:${JSON.stringify(prop.remover)}`
357
+ target: `literal:string:${JSON.stringify(prop.remover)}`
358
358
  });
359
359
  }
360
360
  if (prop.getter) {
361
361
  links.push({
362
362
  source: propShapeId,
363
363
  predicate: "ad4m://getter",
364
- target: `literal://string:${prop.getter}`
364
+ target: `literal:string:${prop.getter}`
365
365
  });
366
366
  }
367
367
  if (prop.conformanceConditions && prop.conformanceConditions.length > 0) {
368
368
  links.push({
369
369
  source: propShapeId,
370
370
  predicate: "ad4m://conformanceConditions",
371
- target: `literal://string:${JSON.stringify(prop.conformanceConditions)}`
371
+ target: `literal:string:${JSON.stringify(prop.conformanceConditions)}`
372
372
  });
373
373
  }
374
374
  if (prop.class) {
@@ -392,7 +392,7 @@ export class SHACLShape {
392
392
  const constructorLink = links.find(l => l.source === shapeUri && l.predicate === "ad4m://constructor");
393
393
  if (constructorLink) {
394
394
  try {
395
- const jsonStr = constructorLink.target.replace('literal://string:', '');
395
+ const jsonStr = constructorLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
396
396
  shape.constructor_actions = JSON.parse(jsonStr);
397
397
  }
398
398
  catch (e) {
@@ -403,7 +403,7 @@ export class SHACLShape {
403
403
  const destructorLink = links.find(l => l.source === shapeUri && l.predicate === "ad4m://destructor");
404
404
  if (destructorLink) {
405
405
  try {
406
- const jsonStr = destructorLink.target.replace('literal://string:', '');
406
+ const jsonStr = destructorLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
407
407
  shape.destructor_actions = JSON.parse(jsonStr);
408
408
  }
409
409
  catch (e) {
@@ -441,70 +441,70 @@ export class SHACLShape {
441
441
  }
442
442
  const minCountLink = links.find(l => l.source === propShapeId && l.predicate === "sh://minCount");
443
443
  if (minCountLink) {
444
- // Handle both formats: literal://5^^xsd:integer and literal://number:5
445
- let val = minCountLink.target.replace('literal://', '').replace(/\^\^.*$/, '');
444
+ // Handle both formats: literal:5^^xsd:integer and literal:number:5
445
+ let val = minCountLink.target.replace(/^literal:\/\/|^literal:/, '').replace(/\^\^.*$/, '');
446
446
  if (val.startsWith('number:'))
447
447
  val = val.substring(7);
448
448
  prop.minCount = parseInt(val);
449
449
  }
450
450
  const maxCountLink = links.find(l => l.source === propShapeId && l.predicate === "sh://maxCount");
451
451
  if (maxCountLink) {
452
- // Handle both formats: literal://5^^xsd:integer and literal://number:5
453
- let val = maxCountLink.target.replace('literal://', '').replace(/\^\^.*$/, '');
452
+ // Handle both formats: literal:5^^xsd:integer and literal:number:5
453
+ let val = maxCountLink.target.replace(/^literal:\/\/|^literal:/, '').replace(/\^\^.*$/, '');
454
454
  if (val.startsWith('number:'))
455
455
  val = val.substring(7);
456
456
  prop.maxCount = parseInt(val);
457
457
  }
458
458
  const patternLink = links.find(l => l.source === propShapeId && l.predicate === "sh://pattern");
459
459
  if (patternLink) {
460
- prop.pattern = patternLink.target.replace('literal://', '');
460
+ prop.pattern = patternLink.target.replace(/^literal:\/\/|^literal:/, '');
461
461
  }
462
462
  const minInclusiveLink = links.find(l => l.source === propShapeId && l.predicate === "sh://minInclusive");
463
463
  if (minInclusiveLink) {
464
- // Handle both formats: literal://5 and literal://number:5
465
- let val = minInclusiveLink.target.replace('literal://', '');
464
+ // Handle both formats: literal:5 and literal:number:5
465
+ let val = minInclusiveLink.target.replace(/^literal:\/\/|^literal:/, '');
466
466
  if (val.startsWith('number:'))
467
467
  val = val.substring(7);
468
468
  prop.minInclusive = parseFloat(val);
469
469
  }
470
470
  const maxInclusiveLink = links.find(l => l.source === propShapeId && l.predicate === "sh://maxInclusive");
471
471
  if (maxInclusiveLink) {
472
- // Handle both formats: literal://5 and literal://number:5
473
- let val = maxInclusiveLink.target.replace('literal://', '');
472
+ // Handle both formats: literal:5 and literal:number:5
473
+ let val = maxInclusiveLink.target.replace(/^literal:\/\/|^literal:/, '');
474
474
  if (val.startsWith('number:'))
475
475
  val = val.substring(7);
476
476
  prop.maxInclusive = parseFloat(val);
477
477
  }
478
478
  const hasValueLink = links.find(l => l.source === propShapeId && l.predicate === "sh://hasValue");
479
479
  if (hasValueLink) {
480
- prop.hasValue = hasValueLink.target.replace('literal://', '');
480
+ prop.hasValue = hasValueLink.target.replace(/^literal:\/\/|^literal:/, '');
481
481
  }
482
482
  // AD4M-specific
483
483
  const localLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://local");
484
484
  if (localLink) {
485
- // Handle both formats: literal://true and literal://boolean:true
486
- let val = localLink.target.replace('literal://', '');
485
+ // Handle both formats: literal:true and literal:boolean:true
486
+ let val = localLink.target.replace(/^literal:\/\/|^literal:/, '');
487
487
  if (val.startsWith('boolean:'))
488
488
  val = val.substring(8);
489
489
  prop.local = val === 'true';
490
490
  }
491
491
  const writableLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://writable");
492
492
  if (writableLink) {
493
- // Handle both formats: literal://true and literal://boolean:true
494
- let val = writableLink.target.replace('literal://', '');
493
+ // Handle both formats: literal:true and literal:boolean:true
494
+ let val = writableLink.target.replace(/^literal:\/\/|^literal:/, '');
495
495
  if (val.startsWith('boolean:'))
496
496
  val = val.substring(8);
497
497
  prop.writable = val === 'true';
498
498
  }
499
499
  const resolveLangLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://resolveLanguage");
500
500
  if (resolveLangLink) {
501
- prop.resolveLanguage = resolveLangLink.target.replace('literal://string:', '');
501
+ prop.resolveLanguage = resolveLangLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
502
502
  }
503
503
  // Parse action arrays
504
504
  const setterLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://setter");
505
505
  if (setterLink) {
506
506
  try {
507
- const jsonStr = setterLink.target.replace('literal://string:', '');
507
+ const jsonStr = setterLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
508
508
  prop.setter = JSON.parse(jsonStr);
509
509
  }
510
510
  catch (e) {
@@ -514,7 +514,7 @@ export class SHACLShape {
514
514
  const adderLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://adder");
515
515
  if (adderLink) {
516
516
  try {
517
- const jsonStr = adderLink.target.replace('literal://string:', '');
517
+ const jsonStr = adderLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
518
518
  prop.adder = JSON.parse(jsonStr);
519
519
  }
520
520
  catch (e) {
@@ -524,7 +524,7 @@ export class SHACLShape {
524
524
  const removerLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://remover");
525
525
  if (removerLink) {
526
526
  try {
527
- const jsonStr = removerLink.target.replace('literal://string:', '');
527
+ const jsonStr = removerLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
528
528
  prop.remover = JSON.parse(jsonStr);
529
529
  }
530
530
  catch (e) {
@@ -533,12 +533,12 @@ export class SHACLShape {
533
533
  }
534
534
  const getterLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://getter");
535
535
  if (getterLink) {
536
- prop.getter = getterLink.target.replace('literal://string:', '');
536
+ prop.getter = getterLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
537
537
  }
538
538
  const conditionsLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://conformanceConditions");
539
539
  if (conditionsLink) {
540
540
  try {
541
- const jsonStr = conditionsLink.target.replace('literal://string:', '');
541
+ const jsonStr = conditionsLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
542
542
  prop.conformanceConditions = JSON.parse(jsonStr);
543
543
  }
544
544
  catch (e) {
@@ -90,6 +90,16 @@ input CapabilityInput {
90
90
  with: ResourceInput!
91
91
  }
92
92
 
93
+ type ComputeLogEntry {
94
+ cost: Float!
95
+ creditsAfter: Float!
96
+ id: Float!
97
+ operation: String!
98
+ summary: String
99
+ timestamp: String!
100
+ userEmail: String!
101
+ }
102
+
93
103
  scalar DateTime
94
104
 
95
105
  type EntanglementProof {
@@ -386,6 +396,7 @@ type Mutation {
386
396
  runtimeRequestPayment(amountHOT: String!): PaymentRequestResult!
387
397
  runtimeRestartHolochain: Boolean!
388
398
  runtimeSendHot(amount: String!, recipient: String!): PaymentRequestResult!
399
+ runtimeSetFreeHostingEnabled(enabled: Boolean!): Boolean!
389
400
  runtimeSetHotWalletAddress(address: String!): Boolean!
390
401
  runtimeSetMultiUserEnabled(enabled: Boolean!): Boolean!
391
402
  runtimeSetStatus(status: PerspectiveInput!): Boolean!
@@ -497,9 +508,10 @@ type Query {
497
508
  perspective(uuid: String!): PerspectiveHandle
498
509
  perspectiveQueryLinks(query: LinkQuery!, uuid: String!): [LinkExpression!]
499
510
  perspectiveQueryProlog(query: String!, uuid: String!): String!
500
- perspectiveQuerySurrealDB(query: String!, uuid: String!): String!
501
511
  perspectiveSnapshot(uuid: String!): Perspective
502
512
  perspectives: [PerspectiveHandle!]!
513
+ runtimeComputeLog(limit: Float, since: String, userEmail: String): [ComputeLogEntry!]!
514
+ runtimeFreeHostingEnabled: Boolean!
503
515
  runtimeFriendStatus(did: String!): PerspectiveExpression
504
516
  runtimeFriends: [String!]!
505
517
  runtimeGetNetworkMetrics: String!
@@ -515,6 +527,7 @@ type Query {
515
527
  runtimeMessageOutbox(filter: String): [SentMessage!]!
516
528
  runtimeMultiUserEnabled: Boolean!
517
529
  runtimeNotifications: [Notification!]!
530
+ runtimeUnytAgentKey: String!
518
531
  runtimeUnytVersionInfo: String!
519
532
  runtimeVerifyStringSignedByDid(data: String!, did: String!, didSigningKeyId: String!, signedData: String!): Boolean!
520
533
  }
@@ -1,25 +1,25 @@
1
1
  export declare function formatList(list: any): any;
2
2
  export declare function capSentence(cap: any): string;
3
3
  /**
4
- * Escapes a string value for safe use in SurrealQL queries.
4
+ * Escapes a string value for safe use in query strings.
5
5
  *
6
6
  * @description
7
7
  * Prevents SQL injection by properly escaping special characters in string values
8
- * that will be interpolated into SurrealQL queries. This handles the most common
8
+ * that will be interpolated into query strings. This handles the most common
9
9
  * special characters that could break SQL queries or enable injection attacks.
10
10
  *
11
11
  * Single quotes, backslashes, and other special characters are escaped using
12
- * backslash notation, which is the standard escaping mechanism for SurrealQL.
12
+ * backslash notation, which is the standard escaping mechanism for query.
13
13
  *
14
14
  * @param value - The string value to escape
15
- * @returns The escaped string safe for SurrealQL interpolation (without surrounding quotes)
15
+ * @returns The escaped string safe for query interpolation (without surrounding quotes)
16
16
  *
17
17
  * @example
18
18
  * ```typescript
19
19
  * const userInput = "user's input with 'quotes'";
20
- * const escaped = escapeSurrealString(userInput);
20
+ * const escaped = escapeQueryString(userInput);
21
21
  * const query = `SELECT * FROM link WHERE uri = '${escaped}'`;
22
22
  * // Results in: SELECT * FROM link WHERE uri = 'user\'s input with \'quotes\''
23
23
  * ```
24
24
  */
25
- export declare function escapeSurrealString(value: string): string;
25
+ export declare function escapeQueryString(value: string): string;
package/lib/src/utils.js CHANGED
@@ -20,28 +20,28 @@ export function capSentence(cap) {
20
20
  return `${formatList(can)} your ${domain} actions, with access to ${formatList(pointers)}`;
21
21
  }
22
22
  /**
23
- * Escapes a string value for safe use in SurrealQL queries.
23
+ * Escapes a string value for safe use in query strings.
24
24
  *
25
25
  * @description
26
26
  * Prevents SQL injection by properly escaping special characters in string values
27
- * that will be interpolated into SurrealQL queries. This handles the most common
27
+ * that will be interpolated into query strings. This handles the most common
28
28
  * special characters that could break SQL queries or enable injection attacks.
29
29
  *
30
30
  * Single quotes, backslashes, and other special characters are escaped using
31
- * backslash notation, which is the standard escaping mechanism for SurrealQL.
31
+ * backslash notation, which is the standard escaping mechanism for query.
32
32
  *
33
33
  * @param value - The string value to escape
34
- * @returns The escaped string safe for SurrealQL interpolation (without surrounding quotes)
34
+ * @returns The escaped string safe for query interpolation (without surrounding quotes)
35
35
  *
36
36
  * @example
37
37
  * ```typescript
38
38
  * const userInput = "user's input with 'quotes'";
39
- * const escaped = escapeSurrealString(userInput);
39
+ * const escaped = escapeQueryString(userInput);
40
40
  * const query = `SELECT * FROM link WHERE uri = '${escaped}'`;
41
41
  * // Results in: SELECT * FROM link WHERE uri = 'user\'s input with \'quotes\''
42
42
  * ```
43
43
  */
44
- export function escapeSurrealString(value) {
44
+ export function escapeQueryString(value) {
45
45
  return value
46
46
  .replace(/\\/g, '\\\\') // Backslash -> \\
47
47
  .replace(/'/g, "\\'") // Single quote -> \'
package/package.json CHANGED
@@ -69,5 +69,5 @@
69
69
  "graphql@15.7.2": "patches/graphql@15.7.2.patch"
70
70
  }
71
71
  },
72
- "version": "0.12.1-dev"
72
+ "version": "0.13.0-test-2"
73
73
  }
@@ -3,29 +3,34 @@ import { Literal } from './Literal'
3
3
  describe("Literal", () => {
4
4
  it("can handle strings", () => {
5
5
  const testString = "test string"
6
- const testUrl = "literal://string:test%20string"
6
+ const testUrl = "literal:string:test%20string"
7
7
  expect(Literal.from(testString).toUrl()).toBe(testUrl)
8
8
  expect(Literal.fromUrl(testUrl).get()).toBe(testString)
9
9
  })
10
10
 
11
11
  it("can handle numbers", () => {
12
12
  const testNumber = 3.1415
13
- const testUrl = "literal://number:3.1415"
13
+ const testUrl = "literal:number:3.1415"
14
14
  expect(Literal.from(testNumber).toUrl()).toBe(testUrl)
15
15
  expect(Literal.fromUrl(testUrl).get()).toBe(testNumber)
16
16
  })
17
17
 
18
18
  it("can handle objects", () => {
19
19
  const testObject = {testNumber: "1337", testString: "test"}
20
- const testUrl = "literal://json:%7B%22testNumber%22%3A%221337%22%2C%22testString%22%3A%22test%22%7D"
20
+ const testUrl = "literal:json:%7B%22testNumber%22%3A%221337%22%2C%22testString%22%3A%22test%22%7D"
21
21
  expect(Literal.from(testObject).toUrl()).toBe(testUrl)
22
22
  expect(Literal.fromUrl(testUrl).get()).toStrictEqual(testObject)
23
23
  })
24
24
 
25
25
  it("can handle special characters", () => {
26
26
  const testString = "message(X) :- triple('ad4m://self', _, X)."
27
- const testUrl = "literal://string:message%28X%29%20%3A-%20triple%28%27ad4m%3A%2F%2Fself%27%2C%20_%2C%20X%29."
27
+ const testUrl = "literal:string:message%28X%29%20%3A-%20triple%28%27ad4m%3A%2F%2Fself%27%2C%20_%2C%20X%29."
28
28
  expect(Literal.from(testString).toUrl()).toBe(testUrl)
29
29
  expect(Literal.fromUrl(testUrl).get()).toBe(testString)
30
30
  })
31
- })
31
+
32
+ it("rejects legacy literal:// URLs", () => {
33
+ expect(() => Literal.fromUrl("literal://string:hello")).toThrow("literal:// format is no longer supported")
34
+ expect(() => Literal.fromUrl("literal://number:42")).toThrow("literal:// format is no longer supported")
35
+ })
36
+ })
package/src/Literal.ts CHANGED
@@ -11,8 +11,10 @@ export class Literal {
11
11
  #url?: string
12
12
 
13
13
  public static fromUrl(url: string) {
14
- if(!url || !url.startsWith("literal://"))
14
+ if(!url || !url.startsWith("literal:"))
15
15
  throw new Error("Can't create Literal from non-literal URL")
16
+ if(url.startsWith("literal://"))
17
+ throw new Error("literal:// format is no longer supported. Use literal: instead.")
16
18
  const l = new Literal()
17
19
  l.#url = url
18
20
  return l
@@ -46,7 +48,7 @@ export class Literal {
46
48
  break;
47
49
  }
48
50
 
49
- return `literal://${encoded}`
51
+ return `literal:${encoded}`
50
52
  }
51
53
 
52
54
  get(): any {
@@ -56,11 +58,10 @@ export class Literal {
56
58
  if(!this.#url)
57
59
  throw new Error("Can't render empty Literal")
58
60
 
59
- if(!this.#url.startsWith("literal://"))
61
+ if(!this.#url.startsWith("literal:"))
60
62
  throw new Error("Can't render Literal from non-literal URL")
61
63
 
62
- // get rid of "literal://"
63
- const body = this.#url.substring(10)
64
+ const body = this.#url.substring(8)
64
65
 
65
66
 
66
67
  if(body.startsWith("string:")) {
@@ -10,7 +10,7 @@ import {
10
10
  EntanglementProofInput,
11
11
  UserCreationResult,
12
12
  } from "./Agent";
13
- import { HostingUserInfo, PaymentRequestResult } from "../runtime/RuntimeResolver";
13
+ import { HostingUserInfo, PaymentRequestResult, ComputeLogEntry } from "../runtime/RuntimeResolver";
14
14
  import { AgentStatus } from "./AgentStatus";
15
15
  import { LinkMutations } from "../links/Links";
16
16
  import { PerspectiveClient } from "../perspectives/PerspectiveClient";
@@ -82,6 +82,8 @@ export interface InitializeArgs {
82
82
  export type AgentUpdatedCallback = (agent: Agent) => null;
83
83
  export type AgentStatusChangedCallback = (agent: Agent) => null;
84
84
  export type AgentAppsUpdatedCallback = () => null;
85
+ export type HostingUserInfoChangedCallback = (info: HostingUserInfo) => void;
86
+ export type ComputeLogUpdatedCallback = (entry: ComputeLogEntry) => void;
85
87
  /**
86
88
  * Provides access to all functions regarding the local agent,
87
89
  * such as generating, locking, unlocking, importing the DID keystore,
@@ -92,12 +94,16 @@ export class AgentClient {
92
94
  #appsChangedCallback: AgentAppsUpdatedCallback[];
93
95
  #updatedCallbacks: AgentUpdatedCallback[];
94
96
  #agentStatusChangedCallbacks: AgentStatusChangedCallback[];
97
+ #hostingUserInfoChangedCallbacks: HostingUserInfoChangedCallback[];
98
+ #computeLogUpdatedCallbacks: ComputeLogUpdatedCallback[];
95
99
 
96
100
  constructor(client: ApolloClient<any>, subscribe: boolean = true) {
97
101
  this.#apolloClient = client;
98
102
  this.#updatedCallbacks = [];
99
103
  this.#agentStatusChangedCallbacks = [];
100
104
  this.#appsChangedCallback = [];
105
+ this.#hostingUserInfoChangedCallbacks = [];
106
+ this.#computeLogUpdatedCallbacks = [];
101
107
 
102
108
  if (subscribe) {
103
109
  this.subscribeAgentUpdated();
@@ -422,6 +428,59 @@ export class AgentClient {
422
428
  });
423
429
  }
424
430
 
431
+ addHostingUserInfoChangedListener(listener: HostingUserInfoChangedCallback) {
432
+ this.#hostingUserInfoChangedCallbacks.push(listener);
433
+ }
434
+
435
+ subscribeHostingUserInfoChanged() {
436
+ this.#apolloClient
437
+ .subscribe({
438
+ query: gql`subscription {
439
+ runtimeHostingUserInfoChanged {
440
+ email
441
+ remainingCredits
442
+ hotWalletAddress
443
+ freeAccess
444
+ }
445
+ }`,
446
+ })
447
+ .subscribe({
448
+ next: (result) => {
449
+ const info = result.data.runtimeHostingUserInfoChanged;
450
+ this.#hostingUserInfoChangedCallbacks.forEach((cb) => cb(info));
451
+ },
452
+ error: (e) => console.error(e),
453
+ });
454
+ }
455
+
456
+ addComputeLogUpdatedListener(listener: ComputeLogUpdatedCallback) {
457
+ this.#computeLogUpdatedCallbacks.push(listener);
458
+ }
459
+
460
+ subscribeComputeLogUpdated() {
461
+ this.#apolloClient
462
+ .subscribe({
463
+ query: gql`subscription {
464
+ runtimeComputeLogUpdated {
465
+ id
466
+ userEmail
467
+ timestamp
468
+ operation
469
+ summary
470
+ cost
471
+ creditsAfter
472
+ }
473
+ }`,
474
+ })
475
+ .subscribe({
476
+ next: (result) => {
477
+ const entry = result.data.runtimeComputeLogUpdated;
478
+ this.#computeLogUpdatedCallbacks.forEach((cb) => cb(entry));
479
+ },
480
+ error: (e) => console.error(e),
481
+ });
482
+ }
483
+
425
484
  async requestCapability(authInfo: AuthInfoInput): Promise<string> {
426
485
  const { agentRequestCapability } = unwrapApolloResult(
427
486
  await this.#apolloClient.mutate({
@@ -608,6 +667,27 @@ export class AgentClient {
608
667
  return runtimeHostingUserInfo;
609
668
  }
610
669
 
670
+ async computeLog(since?: string, limit?: number, userEmail?: string): Promise<ComputeLogEntry[]> {
671
+ const { runtimeComputeLog } = unwrapApolloResult(
672
+ await this.#apolloClient.query({
673
+ query: gql`query runtimeComputeLog($since: String, $limit: Int, $userEmail: String) {
674
+ runtimeComputeLog(since: $since, limit: $limit, userEmail: $userEmail) {
675
+ id
676
+ userEmail
677
+ timestamp
678
+ operation
679
+ summary
680
+ cost
681
+ creditsAfter
682
+ }
683
+ }`,
684
+ variables: { since, limit, userEmail },
685
+ fetchPolicy: 'network-only',
686
+ })
687
+ );
688
+ return runtimeComputeLog;
689
+ }
690
+
611
691
  async setHotWalletAddress(address: string): Promise<boolean> {
612
692
  const { runtimeSetHotWalletAddress } = unwrapApolloResult(
613
693
  await this.#apolloClient.mutate({
@@ -27,11 +27,11 @@ export function exprRef2String(ref: ExpressionRef): string {
27
27
  }
28
28
 
29
29
  export function parseExprUrl(url: string): ExpressionRef {
30
- if(url.startsWith("literal://")) {
30
+ if(url.startsWith("literal:")) {
31
31
  const languageRef = new LanguageRef()
32
32
  languageRef.address = 'literal'
33
33
  languageRef.name = 'literal'
34
- const content = url.substring(10)
34
+ const content = url.substring(8)
35
35
  return new ExpressionRef(languageRef, content)
36
36
  }
37
37