dzql 0.6.14 → 0.6.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dzql",
3
- "version": "0.6.14",
3
+ "version": "0.6.15",
4
4
  "description": "Database-first real-time framework with TypeScript support",
5
5
  "repository": {
6
6
  "type": "git",
@@ -512,10 +512,18 @@ function generateNestedSelects(
512
512
  function generateAffectedKeysFunction(name: string, sub: SubscribableIR): string {
513
513
  const cases: string[] = [];
514
514
  const paramKey = sub.root.key;
515
+ const hasParams = Object.keys(sub.params).length > 0;
515
516
 
516
517
  // Root entity case
517
- cases.push(` WHEN '${sub.root.entity}' THEN
518
+ // For subscribables with no params (list feeds), just return the subscribable name
519
+ // For subscribables with params, include the root entity's id
520
+ if (hasParams) {
521
+ cases.push(` WHEN '${sub.root.entity}' THEN
518
522
  RETURN ARRAY['${name}:' || (p_data->>'id')];`);
523
+ } else {
524
+ cases.push(` WHEN '${sub.root.entity}' THEN
525
+ RETURN ARRAY['${name}'];`);
526
+ }
519
527
 
520
528
  // Get singular form of root entity for FK fields
521
529
  const singularRootEntity = singularize(sub.root.entity);
@@ -552,18 +560,30 @@ function generateAffectedKeysFunction(name: string, sub: SubscribableIR): string
552
560
  const parentRel = relationships[parentEntity]?.[relEntity];
553
561
  const fkField = parentRel?.fkOnParent || `${relName}_id`;
554
562
 
555
- cases.push(` WHEN '${relEntity}' THEN
563
+ if (hasParams) {
564
+ cases.push(` WHEN '${relEntity}' THEN
556
565
  -- Nested: traverse via ${parentEntity}.${fkField}
557
566
  SELECT ARRAY_AGG('${name}:' || parent.${singularRootEntity}_id)
558
567
  INTO v_keys
559
568
  FROM ${parentEntity} parent
560
569
  WHERE parent.${fkField} = (p_data->>'id')::int;
561
570
  RETURN COALESCE(v_keys, ARRAY[]::text[]);`);
571
+ } else {
572
+ // No params - just return the subscribable name
573
+ cases.push(` WHEN '${relEntity}' THEN
574
+ RETURN ARRAY['${name}'];`);
575
+ }
562
576
  } else {
563
577
  // Direct child of root - use the FK on child that points to root
564
578
  const keyField = fkOnChild || `${singularRootEntity}_id`;
565
- cases.push(` WHEN '${relEntity}' THEN
579
+ if (hasParams) {
580
+ cases.push(` WHEN '${relEntity}' THEN
566
581
  RETURN ARRAY['${name}:' || (p_data->>'${keyField}')];`);
582
+ } else {
583
+ // No params - just return the subscribable name
584
+ cases.push(` WHEN '${relEntity}' THEN
585
+ RETURN ARRAY['${name}'];`);
586
+ }
567
587
  }
568
588
 
569
589
  // Recurse for nested includes
@@ -93,7 +93,11 @@ function processEventNotifications(event: {
93
93
  for (const [subscribableName, subs] of subscriptionsByName.entries()) {
94
94
  for (const sub of subs) {
95
95
  const paramValues = Object.values(sub.params);
96
- const subKey = `${subscribableName}:${paramValues.join(':')}`;
96
+ // For subscribables with no params, the key is just the name
97
+ // For subscribables with params, the key is name:param1:param2:...
98
+ const subKey = paramValues.length > 0
99
+ ? `${subscribableName}:${paramValues.join(':')}`
100
+ : subscribableName;
97
101
 
98
102
  if (affected_keys.includes(subKey)) {
99
103
  // Send entity broadcast (not subscription:event) so global dispatcher can route it