@coasys/ad4m 0.13.1-staging.13 → 0.13.1-staging.14

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 (64) hide show
  1. package/lib/index.cjs +548 -477
  2. package/lib/index.js +548 -473
  3. package/lib/src/agent/AgentClient.d.ts +9 -8
  4. package/lib/src/agent/AgentClient.js +46 -67
  5. package/lib/src/cache/KeyedCache.d.ts +51 -0
  6. package/lib/src/cache/KeyedCache.js +142 -0
  7. package/lib/src/expression/ExpressionClient.d.ts +14 -3
  8. package/lib/src/expression/ExpressionClient.js +49 -111
  9. package/lib/src/generated/api/ExpressionLookupError.d.ts +7 -0
  10. package/lib/src/generated/api/ExpressionLookupError.js +2 -0
  11. package/lib/src/generated/api/ExpressionManyEntry.d.ts +6 -0
  12. package/lib/src/generated/api/ExpressionManyEntry.js +1 -0
  13. package/lib/src/generated/api/FlowFiredEntry.d.ts +11 -0
  14. package/lib/src/generated/api/FlowFiredEntry.js +2 -0
  15. package/lib/src/generated/api/PerspectiveFlowFiredParams.d.ts +3 -3
  16. package/lib/src/generated/api/RpcMethods.d.ts +4 -2
  17. package/lib/src/model/Ad4mModel.d.ts +26 -2
  18. package/lib/src/model/Ad4mModel.js +125 -82
  19. package/lib/src/model/ModelQueryBuilder.d.ts +3 -0
  20. package/lib/src/model/ModelQueryBuilder.js +42 -14
  21. package/lib/src/model/index.d.ts +0 -1
  22. package/lib/src/model/index.js +0 -1
  23. package/lib/src/model/query-common.d.ts +8 -0
  24. package/lib/src/model/query-common.js +12 -0
  25. package/lib/src/model/types.d.ts +12 -3
  26. package/lib/src/perspectives/FlowModels.js +1 -1
  27. package/lib/src/perspectives/LiveQuery.d.ts +1 -1
  28. package/lib/src/perspectives/PerspectiveClient.d.ts +17 -6
  29. package/lib/src/perspectives/PerspectiveClient.js +83 -44
  30. package/lib/src/perspectives/PerspectiveProxy.d.ts +19 -10
  31. package/lib/src/perspectives/PerspectiveProxy.js +31 -69
  32. package/package.json +2 -2
  33. package/src/Ad4mClient.test.ts +17 -6
  34. package/src/agent/AgentClient.ts +46 -74
  35. package/src/cache/KeyedCache.test.ts +162 -0
  36. package/src/cache/KeyedCache.ts +179 -0
  37. package/src/cache/cache.test.ts +294 -71
  38. package/src/expression/ExpressionClient.ts +46 -131
  39. package/src/generated/api/ExpressionLookupError.ts +6 -0
  40. package/src/generated/api/ExpressionManyEntry.ts +8 -0
  41. package/src/generated/api/FlowFiredEntry.ts +11 -0
  42. package/src/generated/api/PerspectiveFlowFiredParams.ts +3 -3
  43. package/src/generated/api/RpcMethods.ts +4 -2
  44. package/src/model/Ad4mModel.test.ts +237 -43
  45. package/src/model/Ad4mModel.ts +132 -98
  46. package/src/model/ModelQueryBuilder.ts +41 -15
  47. package/src/model/count-result-type.test.ts +72 -0
  48. package/src/model/index.ts +0 -1
  49. package/src/model/query-common.ts +13 -0
  50. package/src/model/relation-filtering.test.ts +3 -5
  51. package/src/model/types.ts +9 -3
  52. package/src/model/write-round-trips.test.ts +30 -6
  53. package/src/perspectives/FlowModels.ts +1 -1
  54. package/src/perspectives/LiveQuery.ts +1 -1
  55. package/src/perspectives/PerspectiveClient.test.ts +287 -0
  56. package/src/perspectives/PerspectiveClient.ts +101 -66
  57. package/src/perspectives/PerspectiveProxy.test.ts +6 -14
  58. package/src/perspectives/PerspectiveProxy.ts +33 -67
  59. package/src/perspectives/TextContent.test.ts +0 -16
  60. package/src/perspectives/shacl-rpc.test.ts +1 -1
  61. package/lib/src/model/query-cache.d.ts +0 -30
  62. package/lib/src/model/query-cache.js +0 -66
  63. package/src/model/query-cache.test.ts +0 -54
  64. package/src/model/query-cache.ts +0 -79
@@ -19,6 +19,7 @@ import type { AgentMessage } from "../generated/api/AgentMessage";
19
19
  import type { AgentReply } from "../generated/api/AgentReply";
20
20
  import type { PerspectiveQueryLinksParams } from "../generated/api/PerspectiveQueryLinksParams";
21
21
  import type { JsonValue } from "../generated/api/serde_json/JsonValue";
22
+ import type { FlowFiredEntry } from "../generated/api/FlowFiredEntry";
22
23
  import type {
23
24
  CollectionItemAdded, CollectionItemRemoved, InstanceAddToCollection, InstanceCreate,
24
25
  InstanceCreated, InstanceRemove, InstanceRemoveFromCollection, InstanceRemoved,
@@ -56,6 +57,9 @@ export class PerspectiveClient {
56
57
  #expressionClient?: ExpressionClient
57
58
  #neighbourhoodClient?: NeighbourhoodClient
58
59
  #aiClient?: AIClient
60
+ #sparqlInFlight = new Map<string, Promise<string>>()
61
+ /** Per perspective, how many writes through this client have settled; part of the in-flight key. */
62
+ #writeGeneration = new Map<string, number>()
59
63
 
60
64
  constructor(baseUrl: string, token?: string, sharedApiClient?: ApiClient) {
61
65
  this.#apiClient = sharedApiClient || new ApiClient(baseUrl, token)
@@ -119,9 +123,37 @@ export class PerspectiveClient {
119
123
  return JSON.parse(result)
120
124
  }
121
125
 
126
+ /**
127
+ * Concurrent identical calls (same perspective and query, no `options`)
128
+ * share one RPC. Each caller parses its own copy of the reply, and a call
129
+ * made after the shared one settled makes a new RPC. So does a call made
130
+ * after a write through this client settled: the shared RPC may have been
131
+ * answered before the write (see `#wrote`).
132
+ */
122
133
  async querySparql<T = any>(uuid: string, query: string, options?: CallOptions): Promise<T> {
123
- const result = await this.#apiClient.call('perspective.querySparql', { uuid, engine: 'sparql', query }, options)
124
- return JSON.parse(result) as T
134
+ if (options) return JSON.parse(await this.#apiClient.call('perspective.querySparql', { uuid, engine: 'sparql', query }, options)) as T
135
+ const key = `${uuid}\n${this.#writeGeneration.get(uuid) ?? 0}\n${query}`
136
+ let reply = this.#sparqlInFlight.get(key)
137
+ if (!reply) {
138
+ reply = this.#apiClient.call('perspective.querySparql', { uuid, engine: 'sparql', query })
139
+ .finally(() => this.#sparqlInFlight.delete(key))
140
+ this.#sparqlInFlight.set(key, reply)
141
+ }
142
+ return JSON.parse(await reply) as T
143
+ }
144
+
145
+ /**
146
+ * Await a write to `uuid`, then start a new write generation for it
147
+ * (also when the write failed: it may still have changed the perspective).
148
+ * Calls of {@link querySparql} already waiting keep sharing their RPC; an
149
+ * identical call started from now on makes its own.
150
+ */
151
+ async #wrote<T>(uuid: string, write: Promise<T>): Promise<T> {
152
+ try {
153
+ return await write
154
+ } finally {
155
+ this.#writeGeneration.set(uuid, (this.#writeGeneration.get(uuid) ?? 0) + 1)
156
+ }
125
157
  }
126
158
 
127
159
  /** Open a live SPARQL query. Updates arrive through {@link onQueryUpdate}. */
@@ -224,30 +256,30 @@ export class PerspectiveClient {
224
256
  }
225
257
 
226
258
  async addLink(uuid: string, link: Link, status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression> {
227
- const added = await this.#apiClient.call(
259
+ const added = await this.#wrote(uuid, this.#apiClient.call(
228
260
  'perspective.addLink', { uuid, link, status, batchId }
229
- )
261
+ ))
230
262
  return LinkExpression.fromWire(added)
231
263
  }
232
264
 
233
265
  async addLinks(uuid: string, links: Link[], status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression[]> {
234
- const added = await this.#apiClient.call(
266
+ const added = await this.#wrote(uuid, this.#apiClient.call(
235
267
  'perspective.addLinks', { uuid, links, status, batchId }
236
- )
268
+ ))
237
269
  return added.map(LinkExpression.fromWire)
238
270
  }
239
271
 
240
272
  async removeLinks(uuid: string, links: LinkExpressionInput[], batchId?: string): Promise<LinkExpression[]> {
241
- const removed = await this.#apiClient.call(
273
+ const removed = await this.#wrote(uuid, this.#apiClient.call(
242
274
  'perspective.removeLinks', { uuid, links: links.map(linkExpressionInputToWire), batchId }
243
- )
275
+ ))
244
276
  return removed.map(LinkExpression.fromWire)
245
277
  }
246
278
 
247
279
  async linkMutations(uuid: string, mutations: LinkMutations, status?: LinkStatus): Promise<LinkExpressionMutations> {
248
- const diff = await this.#apiClient.call(
280
+ const diff = await this.#wrote(uuid, this.#apiClient.call(
249
281
  'perspective.linkMutations', { uuid, mutations: linkMutationsToWire(mutations), status }
250
- )
282
+ ))
251
283
  return LinkExpressionMutations.fromWire(diff)
252
284
  }
253
285
 
@@ -277,7 +309,7 @@ export class PerspectiveClient {
277
309
  observe?: RunInterpretationObserveOptions,
278
310
  options?: CallOptions,
279
311
  ): Promise<string[]> {
280
- return this.#apiClient.call(
312
+ return this.#wrote(uuid, this.#apiClient.call(
281
313
  'perspective.runInterpretation',
282
314
  {
283
315
  uuid, transcript, basePrefix, classes, existingScope, mintScope,
@@ -285,7 +317,7 @@ export class PerspectiveClient {
285
317
  emitDebugEvents: observe?.emitDebugEvents,
286
318
  },
287
319
  options,
288
- )
320
+ ))
289
321
  }
290
322
 
291
323
  /**
@@ -319,7 +351,7 @@ export class PerspectiveClient {
319
351
  emitDebugEvents?: boolean,
320
352
  options?: CallOptions,
321
353
  ): Promise<string[]> {
322
- return this.#apiClient.call(
354
+ return this.#wrote(uuid, this.#apiClient.call(
323
355
  'perspective.runInterpretationWithHarness',
324
356
  {
325
357
  uuid,
@@ -333,7 +365,7 @@ export class PerspectiveClient {
333
365
  emitDebugEvents,
334
366
  },
335
367
  options,
336
- )
368
+ ))
337
369
  }
338
370
 
339
371
  /**
@@ -361,7 +393,9 @@ export class PerspectiveClient {
361
393
  },
362
394
  options?: CallOptions,
363
395
  ): Promise<AgentReply> {
364
- return this.#apiClient.call('perspective.runAgent', { uuid, messages, ...settings }, options)
396
+ const reply = this.#apiClient.call('perspective.runAgent', { uuid, messages, ...settings }, options)
397
+ // Without write tools the session only reads.
398
+ return settings?.writeTools?.length ? this.#wrote(uuid, reply) : reply
365
399
  }
366
400
 
367
401
  /**
@@ -373,16 +407,16 @@ export class PerspectiveClient {
373
407
  * Returns the processor id.
374
408
  */
375
409
  async addAutoProcessor(uuid: string, config: AddAutoProcessorConfig): Promise<string> {
376
- return this.#apiClient.call(
410
+ return this.#wrote(uuid, this.#apiClient.call(
377
411
  'perspective.addAutoProcessor', { ...config, uuid },
378
- )
412
+ ))
379
413
  }
380
414
 
381
415
  /** Delete an auto-processor's config. `false` when there was none to delete. */
382
416
  async removeAutoProcessor(uuid: string, processorId: string): Promise<boolean> {
383
- return this.#apiClient.call(
417
+ return this.#wrote(uuid, this.#apiClient.call(
384
418
  'perspective.removeAutoProcessor', { uuid, processorId },
385
- )
419
+ ))
386
420
  }
387
421
 
388
422
  /** Pending interpretation overlays (LLM suggestions awaiting human accept/reject). */
@@ -398,17 +432,17 @@ export class PerspectiveClient {
398
432
  /** Accept an overlay's suggestion(s): the LLM value becomes the real value and
399
433
  * the overlay is deleted. Omit `property` to accept the whole base. */
400
434
  async acceptInterpretation(uuid: string, base: string, property?: string): Promise<boolean> {
401
- return this.#apiClient.call(
435
+ return this.#wrote(uuid, this.#apiClient.call(
402
436
  'perspective.acceptInterpretation', { uuid, base, property },
403
- )
437
+ ))
404
438
  }
405
439
 
406
440
  /** Reject an overlay's suggestion(s). Omit `property` to reject the whole base
407
441
  * (a rejected `create` deletes the suggested instance). */
408
442
  async rejectInterpretation(uuid: string, base: string, property?: string): Promise<boolean> {
409
- return this.#apiClient.call(
443
+ return this.#wrote(uuid, this.#apiClient.call(
410
444
  'perspective.rejectInterpretation', { uuid, base, property },
411
- )
445
+ ))
412
446
  }
413
447
 
414
448
  async proposeFlowTransition(
@@ -418,15 +452,15 @@ export class PerspectiveClient {
418
452
  rationale?: string,
419
453
  outputs?: FlowOutputRef[],
420
454
  ): Promise<FlowProposeResult> {
421
- return this.#apiClient.call(
455
+ return this.#wrote(uuid, this.#apiClient.call(
422
456
  'perspective.proposeFlowTransition', { uuid, instanceUri, toState, rationale, outputs },
423
- )
457
+ ))
424
458
  }
425
459
 
426
460
  async acceptFlowProposal(uuid: string, proposalUri: string): Promise<FlowFireOutcome[]> {
427
- return this.#apiClient.call(
461
+ return this.#wrote(uuid, this.#apiClient.call(
428
462
  'perspective.acceptFlowProposal', { uuid, proposalUri },
429
- )
463
+ ))
430
464
  }
431
465
 
432
466
  /**
@@ -435,9 +469,9 @@ export class PerspectiveClient {
435
469
  * proposal this agent opened.
436
470
  */
437
471
  async rejectFlowProposal(uuid: string, proposalUri: string): Promise<number> {
438
- const result = await this.#apiClient.call(
472
+ const result = await this.#wrote(uuid, this.#apiClient.call(
439
473
  'perspective.rejectFlowProposal', { uuid, proposalUri },
440
- )
474
+ ))
441
475
  return result.retractedLinks
442
476
  }
443
477
 
@@ -464,11 +498,13 @@ export class PerspectiveClient {
464
498
  )
465
499
  }
466
500
 
467
- /** The proposals of `instance` the calling agent's replica recorded as
468
- * fired, sorted. */
469
- async flowFired(uuid: string, instance: string): Promise<string[]> {
501
+ /** For each of `instances`, in order, the proposals the calling agent's
502
+ * replica recorded as fired, sorted. One call covers up to 200
503
+ * instances (more is refused with a 400); split a longer list into
504
+ * batches of 200. */
505
+ async flowFired(uuid: string, instances: string[]): Promise<FlowFiredEntry[]> {
470
506
  return this.#apiClient.call(
471
- 'perspective.flowFired', { uuid, instance },
507
+ 'perspective.flowFired', { uuid, instances },
472
508
  )
473
509
  }
474
510
 
@@ -476,69 +512,69 @@ export class PerspectiveClient {
476
512
  * run has not settled into a terminal state, and when an output's
477
513
  * content no longer matches what the quorum committed to. */
478
514
  async mintFlowReceipt(uuid: string, instanceUri: string): Promise<FlowMintedReceipt> {
479
- return this.#apiClient.call(
515
+ return this.#wrote(uuid, this.#apiClient.call(
480
516
  'perspective.mintFlowReceipt', { uuid, instanceUri },
481
- )
517
+ ))
482
518
  }
483
519
 
484
520
  async addLinkExpression(uuid: string, link: LinkExpression, status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression> {
485
- const added = await this.#apiClient.call(
521
+ const added = await this.#wrote(uuid, this.#apiClient.call(
486
522
  'perspective.addLinkExpression', { uuid, link: linkExpressionToWire(link), status, batchId }
487
- )
523
+ ))
488
524
  return LinkExpression.fromWire(added)
489
525
  }
490
526
 
491
527
  async updateLink(uuid: string, oldLink: LinkExpressionInput, newLink: Link, batchId?: string): Promise<LinkExpression> {
492
- const updated = await this.#apiClient.call(
528
+ const updated = await this.#wrote(uuid, this.#apiClient.call(
493
529
  'perspective.updateLink', { uuid, oldLink: linkExpressionInputToWire(oldLink), newLink, batchId }
494
- )
530
+ ))
495
531
  return LinkExpression.fromWire(updated)
496
532
  }
497
533
 
498
534
  async removeLink(uuid: string, link: LinkExpressionInput, batchId?: string): Promise<boolean> {
499
535
  const { status, ...wire } = linkExpressionInputToWire(link)
500
- return this.#apiClient.call(
536
+ return this.#wrote(uuid, this.#apiClient.call(
501
537
  'perspective.removeLink', { uuid, link: wire, batchId }
502
- )
538
+ ))
503
539
  }
504
540
 
505
541
  async addSdna(uuid: string, name: string, sdnaCode: string | undefined, sdnaType: "subject_class" | "flow" | "custom", shaclJson?: string): Promise<boolean> {
506
- const result = await this.#apiClient.call(
542
+ const result = await this.#wrote(uuid, this.#apiClient.call(
507
543
  'perspective.addSdna', { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson }
508
- )
544
+ ))
509
545
  return typeof result === 'boolean' ? result : result.every(Boolean)
510
546
  }
511
547
 
512
548
  async addSdnaBatch(uuid: string, entries: { name: string; sdnaCode?: string; sdnaType: "subject_class" | "flow" | "custom"; shaclJson?: string }[]): Promise<boolean[]> {
513
- const result = await this.#apiClient.call(
549
+ const result = await this.#wrote(uuid, this.#apiClient.call(
514
550
  'perspective.addSdna', { uuid, entries: entries.map(e => ({ ...e, sdnaCode: e.sdnaCode || "" })) }
515
- )
551
+ ))
516
552
  return typeof result === 'boolean' ? [result] : result
517
553
  }
518
554
 
519
555
  async executeCommands(uuid: string, commands: string, expression: string, parameters: string, batchId?: string): Promise<boolean> {
520
- return this.#apiClient.call(
556
+ return this.#wrote(uuid, this.#apiClient.call(
521
557
  'perspective.executeCommands', { uuid, commands, expression, parameters, batchId }
522
- )
558
+ ))
523
559
  }
524
560
 
525
561
  async createSubject(uuid: string, subjectClass: string, expressionAddress: string, initialValues?: string, batchId?: string): Promise<boolean> {
526
- return this.#apiClient.call(
562
+ return this.#wrote(uuid, this.#apiClient.call(
527
563
  'perspective.createSubject', { uuid, subjectClass, expressionAddress, initialValues, batchId }
528
- )
564
+ ))
529
565
  }
530
566
 
531
567
  /** Through an abstract class (#1435), the executor writes to the record's own classes. */
532
568
  async updateSubject(uuid: string, subjectClass: string, expressionAddress: string, values: string, batchId?: string): Promise<boolean> {
533
- return this.#apiClient.call(
569
+ return this.#wrote(uuid, this.#apiClient.call(
534
570
  'perspective.updateSubject', { uuid, subjectClass, expressionAddress, values, batchId }
535
- )
571
+ ))
536
572
  }
537
573
 
538
574
  async removeSubject(uuid: string, subjectClass: string, expressionAddress: string, batchId?: string): Promise<boolean> {
539
- return this.#apiClient.call(
575
+ return this.#wrote(uuid, this.#apiClient.call(
540
576
  'perspective.removeSubject', { uuid, subjectClass, expressionAddress, batchId }
541
- )
577
+ ))
542
578
  }
543
579
 
544
580
  /**
@@ -559,27 +595,27 @@ export class PerspectiveClient {
559
595
  * it to keep the calls that succeeded.
560
596
  */
561
597
  async instanceCreate(uuid: string, body: InstanceCreate): Promise<InstanceCreated> {
562
- return this.#apiClient.call('perspective.instanceCreate', { uuid, ...body })
598
+ return this.#wrote(uuid, this.#apiClient.call('perspective.instanceCreate', { uuid, ...body }))
563
599
  }
564
600
 
565
601
  /** Sets the given single-valued properties; the others stay. See {@link instanceCreate}. */
566
602
  async instanceUpdate(uuid: string, body: InstanceUpdate): Promise<InstanceUpdated> {
567
- return this.#apiClient.call('perspective.instanceUpdate', { uuid, ...body })
603
+ return this.#wrote(uuid, this.#apiClient.call('perspective.instanceUpdate', { uuid, ...body }))
568
604
  }
569
605
 
570
606
  /** Removes the instance and every link to and from it. See {@link instanceCreate}. */
571
607
  async instanceRemove(uuid: string, body: InstanceRemove): Promise<InstanceRemoved> {
572
- return this.#apiClient.call('perspective.instanceRemove', { uuid, ...body })
608
+ return this.#wrote(uuid, this.#apiClient.call('perspective.instanceRemove', { uuid, ...body }))
573
609
  }
574
610
 
575
611
  /** Adds an item to a collection (a no-op when it is a member). See {@link instanceCreate}. */
576
612
  async instanceAddToCollection(uuid: string, body: InstanceAddToCollection): Promise<CollectionItemAdded> {
577
- return this.#apiClient.call('perspective.instanceAddToCollection', { uuid, ...body })
613
+ return this.#wrote(uuid, this.#apiClient.call('perspective.instanceAddToCollection', { uuid, ...body }))
578
614
  }
579
615
 
580
616
  /** Removes an item's membership link from a collection. See {@link instanceCreate}. */
581
617
  async instanceRemoveFromCollection(uuid: string, body: InstanceRemoveFromCollection): Promise<CollectionItemRemoved> {
582
- return this.#apiClient.call('perspective.instanceRemoveFromCollection', { uuid, ...body })
618
+ return this.#wrote(uuid, this.#apiClient.call('perspective.instanceRemoveFromCollection', { uuid, ...body }))
583
619
  }
584
620
 
585
621
  async getSubjectData(uuid: string, subjectClass: string, expressionAddress: string): Promise<string> {
@@ -628,13 +664,12 @@ export class PerspectiveClient {
628
664
  }
629
665
 
630
666
  /**
631
- * Retrieve all SHACL shapes in one call. Returns an array of
632
- * `{name, shapeUri, links}` — one entry per shape (one RPC call).
667
+ * Retrieve SHACL shapes in one call: every shape, or only those in
668
+ * `names` (unknown names are left out). Returns `{name, shapeUri, links}`
669
+ * per shape.
633
670
  */
634
- async getAllShacl(uuid: string): Promise<Array<{ name: string; shapeUri: string; links: Array<{source: string; predicate: string; target: string}> }>> {
635
- return this.#apiClient.call(
636
- 'perspective.getAllShacl', { uuid }
637
- )
671
+ async getAllShacl(uuid: string, names?: string[]): Promise<Array<{ name: string; shapeUri: string; links: Array<{source: string; predicate: string; target: string}> }>> {
672
+ return this.#apiClient.call('perspective.getAllShacl', { uuid, names })
638
673
  }
639
674
 
640
675
  // ExpressionClient functions, needed for Subjects:
@@ -660,9 +695,9 @@ export class PerspectiveClient {
660
695
  }
661
696
 
662
697
  async commitBatch(uuid: string, batchId: string): Promise<LinkExpressionMutations> {
663
- const diff = await this.#apiClient.call(
698
+ const diff = await this.#wrote(uuid, this.#apiClient.call(
664
699
  'perspective.commitBatch', { uuid, batchId }
665
- )
700
+ ))
666
701
  return LinkExpressionMutations.fromWire(diff)
667
702
  }
668
703
 
@@ -3,7 +3,6 @@ import { Link, LinkExpression } from '../links/Links';
3
3
  import { LinkQuery } from './LinkQuery';
4
4
  import { Literal } from '../Literal';
5
5
  import { SHACLFlow } from '../shacl/SHACLFlow';
6
- import { clearQueryCache } from '../model/query-cache';
7
6
 
8
7
  function createProxy(client: any): PerspectiveProxy {
9
8
  return new PerspectiveProxy(
@@ -472,10 +471,10 @@ describe('PerspectiveProxy.addFlow replace', () => {
472
471
  });
473
472
  });
474
473
 
475
- // A read right after an awaited write must not be served from the query
476
- // cache: `updateSubject` and `removeSubject` through an abstract class (#1435)
477
- // write in the executor, so they invalidate it like the other writes.
478
- describe('PerspectiveProxy write RPCs invalidate the query cache', () => {
474
+ // A read right after an awaited write sees the write: `updateSubject` and
475
+ // `removeSubject` through an abstract class (#1435) write in the executor,
476
+ // and querySparql keeps no result once its call settles.
477
+ describe('PerspectiveProxy reads after write RPCs are fresh', () => {
479
478
  const query = 'SELECT ?v WHERE { <ad4m://m/1> <test://text> ?v }';
480
479
 
481
480
  function client() {
@@ -491,8 +490,6 @@ describe('PerspectiveProxy write RPCs invalidate the query cache', () => {
491
490
  } as any;
492
491
  }
493
492
 
494
- beforeEach(() => clearQueryCache());
495
-
496
493
  it('after updateSubject', async () => {
497
494
  const proxy = createProxy(client());
498
495
  expect(await proxy.querySparql(query)).toEqual([{ v: 'old' }]);
@@ -510,8 +507,6 @@ describe('PerspectiveProxy write RPCs invalidate the query cache', () => {
510
507
  });
511
508
 
512
509
  it('after delete of a built-in TextContent row', async () => {
513
- const now = Date.now();
514
- jest.spyOn(Date, 'now').mockReturnValue(now);
515
510
  const c = client();
516
511
  const proxy = createProxy(c);
517
512
  expect(await proxy.querySparql(query)).toEqual([{ v: 'old' }]);
@@ -519,14 +514,13 @@ describe('PerspectiveProxy write RPCs invalidate the query cache', () => {
519
514
  await proxy.removeSubject(row, 'ad4m://m/1');
520
515
  expect(c.removeSubject).toHaveBeenCalledWith('test-uuid', 'ad4m://TextContent', 'ad4m://m/1', undefined);
521
516
  expect(await proxy.querySparql(query)).toEqual([{ v: 'new' }]);
522
- jest.spyOn(Date, 'now').mockRestore();
523
517
  });
524
518
  });
525
519
 
526
520
  // Outside a batch, instanceRemove and instanceRemoveFromCollection remove
527
521
  // links one by one: a failure part-way rejects the call after some links are
528
- // already gone. A read right after must not be served from the cache.
529
- describe('PerspectiveProxy instance writes invalidate the query cache when they fail', () => {
522
+ // already gone. A read right after must reach the executor.
523
+ describe('PerspectiveProxy reads after a rejected instance write are fresh', () => {
530
524
  const query = 'SELECT ?v WHERE { <ad4m://m/1> <test://text> ?v }';
531
525
  const partial = Object.assign(new Error('partiallyRemoved'), { data: { kind: 'partiallyRemoved', removed: 2 } });
532
526
 
@@ -540,8 +534,6 @@ describe('PerspectiveProxy instance writes invalidate the query cache when they
540
534
  } as any;
541
535
  }
542
536
 
543
- beforeEach(() => clearQueryCache());
544
-
545
537
  it('after instanceRemove rejects', async () => {
546
538
  const proxy = createProxy(client());
547
539
  expect(await proxy.querySparql(query)).toEqual([{ v: 'old' }]);