@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
@@ -90,14 +90,6 @@ export default class PerspectiveResolver {
90
90
  return `[{"X": 1}]`
91
91
  }
92
92
 
93
- @Query(returns => String)
94
- async perspectiveQuerySurrealDB(
95
- @Arg('uuid') uuid: string,
96
- @Arg('query') query: string
97
- ): Promise<string> {
98
- return `[]`
99
- }
100
-
101
93
  @Mutation(returns => QuerySubscription)
102
94
  async perspectiveSubscribeQuery(
103
95
  @Arg('uuid') uuid: string,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * WakerSubscriptionManager — manages live SurrealDB subscriptions for the waker.
2
+ * WakerSubscriptionManager — manages live query subscriptions for the waker.
3
3
  *
4
4
  * Lives in core so it can be imported by both the plugin and integration tests
5
5
  * without ESM/CJS import issues.
@@ -32,7 +32,7 @@ export interface WakerLogger {
32
32
  }
33
33
 
34
34
  export interface WakerSubscriptionManagerOptions {
35
- /** PerspectiveClient from Ad4mClient (provides perspectiveSubscribeSurrealQuery etc.) */
35
+ /** PerspectiveClient from Ad4mClient (provides subscribeQuery etc.) */
36
36
  perspectiveClient: any;
37
37
  /** Logger instance */
38
38
  logger: WakerLogger;
@@ -76,7 +76,7 @@ export class WakerSubscriptionManager {
76
76
  }
77
77
 
78
78
  /**
79
- * Create a live SurrealDB subscription.
79
+ * Create a live SPARQL subscription.
80
80
  * If a subscription with the same id already exists, it is disposed first.
81
81
  */
82
82
  async subscribe(sub: WakerSubscription): Promise<void> {
@@ -91,14 +91,14 @@ export class WakerSubscriptionManager {
91
91
  this.logger.info(
92
92
  `[waker] ${sub.id}: creating subscription (perspective=${sub.perspective}, type=${sub.type})`,
93
93
  );
94
- this.logger.info(`[waker] ${sub.id}: SurrealQL query:\n${sub.query}`);
94
+ this.logger.info(`[waker] ${sub.id}: SPARQL query:\n${sub.query}`);
95
95
 
96
96
  const proxy = new QuerySubscriptionProxy(
97
97
  sub.perspective,
98
98
  sub.query,
99
99
  this.perspectiveClient,
100
100
  );
101
- proxy.isSurrealDB = true;
101
+ proxy.isSPARQL = true;
102
102
  // Suppress unhandled rejection from proxy.initialized — QuerySubscriptionProxy
103
103
  // rejects this promise internally when subscribe() fails, and if nobody catches
104
104
  // it before the next microtask it crashes the process.
@@ -134,7 +134,7 @@ export class WakerSubscriptionManager {
134
134
  `[waker] ${sub.id}: onResult fired — type=${typeof result}, isArray=${Array.isArray(result)}, value=${String(JSON.stringify(result)).substring(0, 500)}`,
135
135
  );
136
136
 
137
- // SurrealDB can deliver non-array values (e.g. false) on disconnect/reconnect — ignore them
137
+ // Query engine can deliver non-array values (e.g. false) on disconnect/reconnect — ignore them
138
138
  if (!Array.isArray(result)) {
139
139
  this.logger.warn(
140
140
  `[waker] ${sub.id}: ignoring non-array result: ${JSON.stringify(result)}`,
@@ -170,10 +170,9 @@ export class WakerSubscriptionManager {
170
170
  for (const msgAddr of newMessages) {
171
171
  const parents: string[] = [];
172
172
  try {
173
- const escaped = msgAddr.replace(/'/g, "\\'");
174
- const parentQuery = `SELECT * FROM link WHERE predicate = 'ad4m://has_child' AND target = '${escaped}'`;
173
+ const parentQuery = `SELECT ?source WHERE { ?source <ad4m://has_child> <${msgAddr}> . }`;
175
174
  this.logger.info(`[waker] ${sub.id}: resolving parents for ${msgAddr}`);
176
- const parentResult = await this.perspectiveClient.querySurrealDB(sub.perspective, parentQuery);
175
+ const parentResult = await this.perspectiveClient.querySparql(sub.perspective, parentQuery);
177
176
  if (Array.isArray(parentResult)) {
178
177
  for (const link of parentResult) {
179
178
  if (link && link.source) {
@@ -414,6 +414,25 @@ export class RuntimeClient {
414
414
  return runtimeSetMultiUserEnabled
415
415
  }
416
416
 
417
+ async freeHostingEnabled(): Promise<boolean> {
418
+ const { runtimeFreeHostingEnabled } = unwrapApolloResult(await this.#apolloClient.query({
419
+ query: gql`query runtimeFreeHostingEnabled {
420
+ runtimeFreeHostingEnabled
421
+ }`
422
+ }))
423
+ return runtimeFreeHostingEnabled
424
+ }
425
+
426
+ async setFreeHostingEnabled(enabled: boolean): Promise<boolean> {
427
+ const { runtimeSetFreeHostingEnabled } = unwrapApolloResult(await this.#apolloClient.mutate({
428
+ mutation: gql`mutation runtimeSetFreeHostingEnabled($enabled: Boolean!) {
429
+ runtimeSetFreeHostingEnabled(enabled: $enabled)
430
+ }`,
431
+ variables: { enabled }
432
+ }))
433
+ return runtimeSetFreeHostingEnabled
434
+ }
435
+
417
436
  async listUsers(): Promise<UserStatistics[]> {
418
437
  const { runtimeListUsers } = unwrapApolloResult(await this.#apolloClient.query({
419
438
  query: gql`query runtimeListUsers {
@@ -268,6 +268,40 @@ export class PaymentRequestResult {
268
268
  }
269
269
  }
270
270
 
271
+ @ObjectType()
272
+ export class ComputeLogEntry {
273
+ @Field()
274
+ id: number;
275
+
276
+ @Field()
277
+ userEmail: string;
278
+
279
+ @Field()
280
+ timestamp: string;
281
+
282
+ @Field()
283
+ operation: string;
284
+
285
+ @Field({ nullable: true })
286
+ summary?: string;
287
+
288
+ @Field()
289
+ cost: number;
290
+
291
+ @Field()
292
+ creditsAfter: number;
293
+
294
+ constructor(id: number, userEmail: string, timestamp: string, operation: string, cost: number, creditsAfter: number, summary?: string) {
295
+ this.id = id;
296
+ this.userEmail = userEmail;
297
+ this.timestamp = timestamp;
298
+ this.operation = operation;
299
+ this.cost = cost;
300
+ this.creditsAfter = creditsAfter;
301
+ this.summary = summary;
302
+ }
303
+ }
304
+
271
305
  /**
272
306
  * Resolver classes are used here to define the GraphQL schema
273
307
  * (through the type-graphql annotations)
@@ -513,6 +547,16 @@ export default class RuntimeResolver {
513
547
  return enabled
514
548
  }
515
549
 
550
+ @Query(returns => Boolean)
551
+ runtimeFreeHostingEnabled(): boolean {
552
+ return true
553
+ }
554
+
555
+ @Mutation(returns => Boolean)
556
+ runtimeSetFreeHostingEnabled(@Arg("enabled") enabled: boolean): boolean {
557
+ return enabled
558
+ }
559
+
516
560
  @Query(returns => [UserStatistics])
517
561
  runtimeListUsers(): UserStatistics[] {
518
562
  return [{
@@ -615,6 +659,15 @@ export default class RuntimeResolver {
615
659
  return new HostingUserInfo("test@example.com", "100000000", null, false)
616
660
  }
617
661
 
662
+ @Query(returns => [ComputeLogEntry])
663
+ runtimeComputeLog(
664
+ @Arg("since", { nullable: true }) since?: string,
665
+ @Arg("limit", { nullable: true }) limit?: number,
666
+ @Arg("userEmail", { nullable: true }) userEmail?: string,
667
+ ): ComputeLogEntry[] {
668
+ return []
669
+ }
670
+
618
671
  @Mutation(returns => Boolean)
619
672
  runtimeSetHotWalletAddress(
620
673
  @Arg("address") address: string
@@ -683,6 +736,11 @@ export default class RuntimeResolver {
683
736
  return ""
684
737
  }
685
738
 
739
+ @Query(returns => String)
740
+ runtimeUnytAgentKey(): string {
741
+ return ""
742
+ }
743
+
686
744
  @Query(returns => String)
687
745
  runtimeUnytVersionInfo(): string {
688
746
  return ""
@@ -186,7 +186,7 @@ export class SHACLFlow {
186
186
 
187
187
  /**
188
188
  * Serialize the flow to AD4M links
189
- * These links can be stored in a perspective and queried via SurrealDB
189
+ * These links can be stored in a perspective and queried via SPARQL
190
190
  *
191
191
  * @returns Array of Link objects representing the flow
192
192
  */
@@ -219,7 +219,7 @@ export class SHACLFlow {
219
219
  links.push({
220
220
  source: flowUri,
221
221
  predicate: "ad4m://flowable",
222
- target: `literal://string:${encodeURIComponent(JSON.stringify(this.flowable))}`
222
+ target: `literal:string:${encodeURIComponent(JSON.stringify(this.flowable))}`
223
223
  });
224
224
  }
225
225
 
@@ -228,7 +228,7 @@ export class SHACLFlow {
228
228
  links.push({
229
229
  source: flowUri,
230
230
  predicate: "ad4m://startAction",
231
- target: `literal://string:${encodeURIComponent(JSON.stringify(this.startAction))}`
231
+ target: `literal:string:${encodeURIComponent(JSON.stringify(this.startAction))}`
232
232
  });
233
233
  }
234
234
 
@@ -268,7 +268,7 @@ export class SHACLFlow {
268
268
  links.push({
269
269
  source: stateUri,
270
270
  predicate: "ad4m://stateCheck",
271
- target: `literal://string:${encodeURIComponent(JSON.stringify(state.stateCheck))}`
271
+ target: `literal:string:${encodeURIComponent(JSON.stringify(state.stateCheck))}`
272
272
  });
273
273
  }
274
274
 
@@ -317,7 +317,7 @@ export class SHACLFlow {
317
317
  links.push({
318
318
  source: transitionUri,
319
319
  predicate: "ad4m://transitionActions",
320
- target: `literal://string:${encodeURIComponent(JSON.stringify(transition.actions))}`
320
+ target: `literal:string:${encodeURIComponent(JSON.stringify(transition.actions))}`
321
321
  });
322
322
  }
323
323
 
@@ -359,7 +359,7 @@ export class SHACLFlow {
359
359
  flow.flowable = "any";
360
360
  } else {
361
361
  try {
362
- const jsonStr = flowableLink.target.replace('literal://string:', '');
362
+ const jsonStr = flowableLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
363
363
  flow.flowable = JSON.parse(decodeURIComponent(jsonStr));
364
364
  } catch {
365
365
  flow.flowable = "any";
@@ -373,7 +373,7 @@ export class SHACLFlow {
373
373
  );
374
374
  if (startActionLink) {
375
375
  try {
376
- const jsonStr = startActionLink.target.replace('literal://string:', '');
376
+ const jsonStr = startActionLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
377
377
  flow.startAction = JSON.parse(decodeURIComponent(jsonStr));
378
378
  } catch {
379
379
  // Ignore parse errors
@@ -413,7 +413,7 @@ export class SHACLFlow {
413
413
  let stateCheck: LinkPattern = { predicate: "", target: "" };
414
414
  if (checkLink) {
415
415
  try {
416
- const jsonStr = checkLink.target.replace('literal://string:', '');
416
+ const jsonStr = checkLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
417
417
  stateCheck = JSON.parse(decodeURIComponent(jsonStr));
418
418
  } catch {
419
419
  // Ignore parse errors
@@ -458,7 +458,7 @@ export class SHACLFlow {
458
458
  let actions: AD4MAction[] = [];
459
459
  if (actionsLink) {
460
460
  try {
461
- const jsonStr = actionsLink.target.replace('literal://string:', '');
461
+ const jsonStr = actionsLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
462
462
  actions = JSON.parse(decodeURIComponent(jsonStr));
463
463
  } catch {
464
464
  // Ignore parse errors
@@ -161,7 +161,7 @@ export interface SHACLPropertyShape {
161
161
  /** AD4M-specific: Remover action for collection properties */
162
162
  remover?: AD4MAction[];
163
163
 
164
- /** AD4M-specific: Pre-computed SurrealQL getter expression for reading this relation/property.
164
+ /** AD4M-specific: Pre-computed SPARQL getter expression for reading this relation/property.
165
165
  * For relations with a target model, this encodes conformance filtering
166
166
  * so that Rust/MCP can execute the exact same query as the JS runtime. */
167
167
  getter?: string;
@@ -363,7 +363,7 @@ export class SHACLShape {
363
363
  links.push({
364
364
  source: this.nodeShapeUri,
365
365
  predicate: "ad4m://constructor",
366
- target: `literal://string:${JSON.stringify(this.constructor_actions)}`
366
+ target: `literal:string:${JSON.stringify(this.constructor_actions)}`
367
367
  });
368
368
  }
369
369
 
@@ -372,7 +372,7 @@ export class SHACLShape {
372
372
  links.push({
373
373
  source: this.nodeShapeUri,
374
374
  predicate: "ad4m://destructor",
375
- target: `literal://string:${JSON.stringify(this.destructor_actions)}`
375
+ target: `literal:string:${JSON.stringify(this.destructor_actions)}`
376
376
  });
377
377
  }
378
378
 
@@ -428,7 +428,7 @@ export class SHACLShape {
428
428
  links.push({
429
429
  source: propShapeId,
430
430
  predicate: "sh://minCount",
431
- target: `literal://${prop.minCount}^^xsd:integer`
431
+ target: `literal:${prop.minCount}^^xsd:integer`
432
432
  });
433
433
  }
434
434
 
@@ -436,7 +436,7 @@ export class SHACLShape {
436
436
  links.push({
437
437
  source: propShapeId,
438
438
  predicate: "sh://maxCount",
439
- target: `literal://${prop.maxCount}^^xsd:integer`
439
+ target: `literal:${prop.maxCount}^^xsd:integer`
440
440
  });
441
441
  }
442
442
 
@@ -444,7 +444,7 @@ export class SHACLShape {
444
444
  links.push({
445
445
  source: propShapeId,
446
446
  predicate: "sh://pattern",
447
- target: `literal://${prop.pattern}`
447
+ target: `literal:${prop.pattern}`
448
448
  });
449
449
  }
450
450
 
@@ -452,7 +452,7 @@ export class SHACLShape {
452
452
  links.push({
453
453
  source: propShapeId,
454
454
  predicate: "sh://minInclusive",
455
- target: `literal://${prop.minInclusive}`
455
+ target: `literal:${prop.minInclusive}`
456
456
  });
457
457
  }
458
458
 
@@ -460,7 +460,7 @@ export class SHACLShape {
460
460
  links.push({
461
461
  source: propShapeId,
462
462
  predicate: "sh://maxInclusive",
463
- target: `literal://${prop.maxInclusive}`
463
+ target: `literal:${prop.maxInclusive}`
464
464
  });
465
465
  }
466
466
 
@@ -468,7 +468,7 @@ export class SHACLShape {
468
468
  links.push({
469
469
  source: propShapeId,
470
470
  predicate: "sh://hasValue",
471
- target: `literal://${prop.hasValue}`
471
+ target: `literal:${prop.hasValue}`
472
472
  });
473
473
  }
474
474
 
@@ -477,7 +477,7 @@ export class SHACLShape {
477
477
  links.push({
478
478
  source: propShapeId,
479
479
  predicate: "ad4m://local",
480
- target: `literal://${prop.local}`
480
+ target: `literal:${prop.local}`
481
481
  });
482
482
  }
483
483
 
@@ -485,7 +485,7 @@ export class SHACLShape {
485
485
  links.push({
486
486
  source: propShapeId,
487
487
  predicate: "ad4m://writable",
488
- target: `literal://${prop.writable}`
488
+ target: `literal:${prop.writable}`
489
489
  });
490
490
  }
491
491
 
@@ -493,7 +493,7 @@ export class SHACLShape {
493
493
  links.push({
494
494
  source: propShapeId,
495
495
  predicate: "ad4m://resolveLanguage",
496
- target: `literal://string:${prop.resolveLanguage}`
496
+ target: `literal:string:${prop.resolveLanguage}`
497
497
  });
498
498
  }
499
499
 
@@ -502,7 +502,7 @@ export class SHACLShape {
502
502
  links.push({
503
503
  source: propShapeId,
504
504
  predicate: "ad4m://setter",
505
- target: `literal://string:${JSON.stringify(prop.setter)}`
505
+ target: `literal:string:${JSON.stringify(prop.setter)}`
506
506
  });
507
507
  }
508
508
 
@@ -510,7 +510,7 @@ export class SHACLShape {
510
510
  links.push({
511
511
  source: propShapeId,
512
512
  predicate: "ad4m://adder",
513
- target: `literal://string:${JSON.stringify(prop.adder)}`
513
+ target: `literal:string:${JSON.stringify(prop.adder)}`
514
514
  });
515
515
  }
516
516
 
@@ -518,7 +518,7 @@ export class SHACLShape {
518
518
  links.push({
519
519
  source: propShapeId,
520
520
  predicate: "ad4m://remover",
521
- target: `literal://string:${JSON.stringify(prop.remover)}`
521
+ target: `literal:string:${JSON.stringify(prop.remover)}`
522
522
  });
523
523
  }
524
524
 
@@ -526,7 +526,7 @@ export class SHACLShape {
526
526
  links.push({
527
527
  source: propShapeId,
528
528
  predicate: "ad4m://getter",
529
- target: `literal://string:${prop.getter}`
529
+ target: `literal:string:${prop.getter}`
530
530
  });
531
531
  }
532
532
 
@@ -534,7 +534,7 @@ export class SHACLShape {
534
534
  links.push({
535
535
  source: propShapeId,
536
536
  predicate: "ad4m://conformanceConditions",
537
- target: `literal://string:${JSON.stringify(prop.conformanceConditions)}`
537
+ target: `literal:string:${JSON.stringify(prop.conformanceConditions)}`
538
538
  });
539
539
  }
540
540
 
@@ -567,7 +567,7 @@ export class SHACLShape {
567
567
  );
568
568
  if (constructorLink) {
569
569
  try {
570
- const jsonStr = constructorLink.target.replace('literal://string:', '');
570
+ const jsonStr = constructorLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
571
571
  shape.constructor_actions = JSON.parse(jsonStr);
572
572
  } catch (e) {
573
573
  // Ignore parse errors
@@ -580,7 +580,7 @@ export class SHACLShape {
580
580
  );
581
581
  if (destructorLink) {
582
582
  try {
583
- const jsonStr = destructorLink.target.replace('literal://string:', '');
583
+ const jsonStr = destructorLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
584
584
  shape.destructor_actions = JSON.parse(jsonStr);
585
585
  } catch (e) {
586
586
  // Ignore parse errors
@@ -634,8 +634,8 @@ export class SHACLShape {
634
634
  l.source === propShapeId && l.predicate === "sh://minCount"
635
635
  );
636
636
  if (minCountLink) {
637
- // Handle both formats: literal://5^^xsd:integer and literal://number:5
638
- let val = minCountLink.target.replace('literal://', '').replace(/\^\^.*$/, '');
637
+ // Handle both formats: literal:5^^xsd:integer and literal:number:5
638
+ let val = minCountLink.target.replace(/^literal:\/\/|^literal:/, '').replace(/\^\^.*$/, '');
639
639
  if (val.startsWith('number:')) val = val.substring(7);
640
640
  prop.minCount = parseInt(val);
641
641
  }
@@ -644,8 +644,8 @@ export class SHACLShape {
644
644
  l.source === propShapeId && l.predicate === "sh://maxCount"
645
645
  );
646
646
  if (maxCountLink) {
647
- // Handle both formats: literal://5^^xsd:integer and literal://number:5
648
- let val = maxCountLink.target.replace('literal://', '').replace(/\^\^.*$/, '');
647
+ // Handle both formats: literal:5^^xsd:integer and literal:number:5
648
+ let val = maxCountLink.target.replace(/^literal:\/\/|^literal:/, '').replace(/\^\^.*$/, '');
649
649
  if (val.startsWith('number:')) val = val.substring(7);
650
650
  prop.maxCount = parseInt(val);
651
651
  }
@@ -654,15 +654,15 @@ export class SHACLShape {
654
654
  l.source === propShapeId && l.predicate === "sh://pattern"
655
655
  );
656
656
  if (patternLink) {
657
- prop.pattern = patternLink.target.replace('literal://', '');
657
+ prop.pattern = patternLink.target.replace(/^literal:\/\/|^literal:/, '');
658
658
  }
659
659
 
660
660
  const minInclusiveLink = links.find(l =>
661
661
  l.source === propShapeId && l.predicate === "sh://minInclusive"
662
662
  );
663
663
  if (minInclusiveLink) {
664
- // Handle both formats: literal://5 and literal://number:5
665
- let val = minInclusiveLink.target.replace('literal://', '');
664
+ // Handle both formats: literal:5 and literal:number:5
665
+ let val = minInclusiveLink.target.replace(/^literal:\/\/|^literal:/, '');
666
666
  if (val.startsWith('number:')) val = val.substring(7);
667
667
  prop.minInclusive = parseFloat(val);
668
668
  }
@@ -671,8 +671,8 @@ export class SHACLShape {
671
671
  l.source === propShapeId && l.predicate === "sh://maxInclusive"
672
672
  );
673
673
  if (maxInclusiveLink) {
674
- // Handle both formats: literal://5 and literal://number:5
675
- let val = maxInclusiveLink.target.replace('literal://', '');
674
+ // Handle both formats: literal:5 and literal:number:5
675
+ let val = maxInclusiveLink.target.replace(/^literal:\/\/|^literal:/, '');
676
676
  if (val.startsWith('number:')) val = val.substring(7);
677
677
  prop.maxInclusive = parseFloat(val);
678
678
  }
@@ -681,7 +681,7 @@ export class SHACLShape {
681
681
  l.source === propShapeId && l.predicate === "sh://hasValue"
682
682
  );
683
683
  if (hasValueLink) {
684
- prop.hasValue = hasValueLink.target.replace('literal://', '');
684
+ prop.hasValue = hasValueLink.target.replace(/^literal:\/\/|^literal:/, '');
685
685
  }
686
686
 
687
687
  // AD4M-specific
@@ -689,8 +689,8 @@ export class SHACLShape {
689
689
  l.source === propShapeId && l.predicate === "ad4m://local"
690
690
  );
691
691
  if (localLink) {
692
- // Handle both formats: literal://true and literal://boolean:true
693
- let val = localLink.target.replace('literal://', '');
692
+ // Handle both formats: literal:true and literal:boolean:true
693
+ let val = localLink.target.replace(/^literal:\/\/|^literal:/, '');
694
694
  if (val.startsWith('boolean:')) val = val.substring(8);
695
695
  prop.local = val === 'true';
696
696
  }
@@ -699,8 +699,8 @@ export class SHACLShape {
699
699
  l.source === propShapeId && l.predicate === "ad4m://writable"
700
700
  );
701
701
  if (writableLink) {
702
- // Handle both formats: literal://true and literal://boolean:true
703
- let val = writableLink.target.replace('literal://', '');
702
+ // Handle both formats: literal:true and literal:boolean:true
703
+ let val = writableLink.target.replace(/^literal:\/\/|^literal:/, '');
704
704
  if (val.startsWith('boolean:')) val = val.substring(8);
705
705
  prop.writable = val === 'true';
706
706
  }
@@ -709,7 +709,7 @@ export class SHACLShape {
709
709
  l.source === propShapeId && l.predicate === "ad4m://resolveLanguage"
710
710
  );
711
711
  if (resolveLangLink) {
712
- prop.resolveLanguage = resolveLangLink.target.replace('literal://string:', '');
712
+ prop.resolveLanguage = resolveLangLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
713
713
  }
714
714
 
715
715
  // Parse action arrays
@@ -718,7 +718,7 @@ export class SHACLShape {
718
718
  );
719
719
  if (setterLink) {
720
720
  try {
721
- const jsonStr = setterLink.target.replace('literal://string:', '');
721
+ const jsonStr = setterLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
722
722
  prop.setter = JSON.parse(jsonStr);
723
723
  } catch (e) {
724
724
  // Ignore parse errors
@@ -730,7 +730,7 @@ export class SHACLShape {
730
730
  );
731
731
  if (adderLink) {
732
732
  try {
733
- const jsonStr = adderLink.target.replace('literal://string:', '');
733
+ const jsonStr = adderLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
734
734
  prop.adder = JSON.parse(jsonStr);
735
735
  } catch (e) {
736
736
  // Ignore parse errors
@@ -742,7 +742,7 @@ export class SHACLShape {
742
742
  );
743
743
  if (removerLink) {
744
744
  try {
745
- const jsonStr = removerLink.target.replace('literal://string:', '');
745
+ const jsonStr = removerLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
746
746
  prop.remover = JSON.parse(jsonStr);
747
747
  } catch (e) {
748
748
  // Ignore parse errors
@@ -753,7 +753,7 @@ export class SHACLShape {
753
753
  l.source === propShapeId && l.predicate === "ad4m://getter"
754
754
  );
755
755
  if (getterLink) {
756
- prop.getter = getterLink.target.replace('literal://string:', '');
756
+ prop.getter = getterLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
757
757
  }
758
758
 
759
759
  const conditionsLink = links.find(l =>
@@ -761,7 +761,7 @@ export class SHACLShape {
761
761
  );
762
762
  if (conditionsLink) {
763
763
  try {
764
- const jsonStr = conditionsLink.target.replace('literal://string:', '');
764
+ const jsonStr = conditionsLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
765
765
  prop.conformanceConditions = JSON.parse(jsonStr);
766
766
  } catch (e) {
767
767
  // Ignore parse errors
package/src/utils.ts CHANGED
@@ -25,28 +25,28 @@ export function capSentence(cap) {
25
25
  }
26
26
 
27
27
  /**
28
- * Escapes a string value for safe use in SurrealQL queries.
28
+ * Escapes a string value for safe use in query strings.
29
29
  *
30
30
  * @description
31
31
  * Prevents SQL injection by properly escaping special characters in string values
32
- * that will be interpolated into SurrealQL queries. This handles the most common
32
+ * that will be interpolated into query strings. This handles the most common
33
33
  * special characters that could break SQL queries or enable injection attacks.
34
34
  *
35
35
  * Single quotes, backslashes, and other special characters are escaped using
36
- * backslash notation, which is the standard escaping mechanism for SurrealQL.
36
+ * backslash notation, which is the standard escaping mechanism for query.
37
37
  *
38
38
  * @param value - The string value to escape
39
- * @returns The escaped string safe for SurrealQL interpolation (without surrounding quotes)
39
+ * @returns The escaped string safe for query interpolation (without surrounding quotes)
40
40
  *
41
41
  * @example
42
42
  * ```typescript
43
43
  * const userInput = "user's input with 'quotes'";
44
- * const escaped = escapeSurrealString(userInput);
44
+ * const escaped = escapeQueryString(userInput);
45
45
  * const query = `SELECT * FROM link WHERE uri = '${escaped}'`;
46
46
  * // Results in: SELECT * FROM link WHERE uri = 'user\'s input with \'quotes\''
47
47
  * ```
48
48
  */
49
- export function escapeSurrealString(value: string): string {
49
+ export function escapeQueryString(value: string): string {
50
50
  return value
51
51
  .replace(/\\/g, '\\\\') // Backslash -> \\
52
52
  .replace(/'/g, "\\'") // Single quote -> \'