@effect-app/infra 4.0.0-beta.216 → 4.0.0-beta.218

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 (37) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/Model/Repository/internal/internal.d.ts +1 -1
  3. package/dist/Model/query/dsl.d.ts +49 -1
  4. package/dist/Model/query/dsl.d.ts.map +1 -1
  5. package/dist/Model/query/dsl.js +77 -1
  6. package/dist/Model/query/new-kid-interpreter.d.ts +34 -1
  7. package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -1
  8. package/dist/Model/query/new-kid-interpreter.js +41 -1
  9. package/dist/QueueMaker/SQLQueue.d.ts +1 -1
  10. package/dist/QueueMaker/memQueue.d.ts +1 -1
  11. package/dist/QueueMaker/sbqueue.d.ts +1 -1
  12. package/dist/Store/Cosmos/query.d.ts +1 -1
  13. package/dist/Store/Cosmos/query.d.ts.map +1 -1
  14. package/dist/Store/Cosmos/query.js +42 -1
  15. package/dist/Store/Cosmos.d.ts +1 -1
  16. package/dist/Store/Memory.d.ts +1 -1
  17. package/dist/Store/Memory.d.ts.map +1 -1
  18. package/dist/Store/Memory.js +64 -1
  19. package/dist/Store/SQL/Pg.d.ts +1 -1
  20. package/dist/Store/SQL/query.d.ts +1 -1
  21. package/dist/Store/SQL/query.d.ts.map +1 -1
  22. package/dist/Store/SQL/query.js +54 -5
  23. package/dist/Store/SQL.d.ts +1 -1
  24. package/dist/adapters/ServiceBus.d.ts +1 -1
  25. package/dist/adapters/logger.d.ts +1 -1
  26. package/dist/api/routing.d.ts +1 -1
  27. package/dist/otel.d.ts +1 -1
  28. package/package.json +2 -2
  29. package/src/Model/query/dsl.ts +139 -0
  30. package/src/Model/query/new-kid-interpreter.ts +80 -0
  31. package/src/Store/Cosmos/query.ts +45 -1
  32. package/src/Store/Memory.ts +58 -1
  33. package/src/Store/SQL/query.ts +56 -5
  34. package/test/dist/rawQuery.test.d.ts.map +1 -1
  35. package/test/query.test.ts +108 -3
  36. package/test/rawQuery.test.ts +5 -9
  37. package/test/sql-store.test.ts +166 -0
@@ -345,6 +345,90 @@ describe("SQL query builder (SQLite dialect)", () => {
345
345
  expect(result.sql).toContain(`AS "totalWeight"`)
346
346
  })
347
347
 
348
+ it("computed relation-sum-expr projection (sqlite)", () => {
349
+ const result = buildWhereSQLQuery(
350
+ sqliteDialect,
351
+ "id",
352
+ [],
353
+ "users",
354
+ {},
355
+ [{
356
+ key: "totalWeighted",
357
+ computed: {
358
+ _tag: "relation-sum-expr",
359
+ path: "items",
360
+ expression: {
361
+ _tag: "mul",
362
+ left: { _tag: "field", field: "weight" },
363
+ right: { _tag: "field", field: "tradeUnit.amount" }
364
+ },
365
+ filter: []
366
+ }
367
+ }]
368
+ )
369
+ expect(result.sql).toContain(
370
+ `COALESCE(SUM((CAST(json_extract(_items.value, '$.weight') AS REAL) * CAST(json_extract(_items.value, '$.tradeUnit.amount') AS REAL))), 0)`
371
+ )
372
+ expect(result.sql).toContain(`AS "totalWeighted"`)
373
+ })
374
+
375
+ it("computed relation-sum-expr-by projection (sqlite)", () => {
376
+ const result = buildWhereSQLQuery(
377
+ sqliteDialect,
378
+ "id",
379
+ [],
380
+ "users",
381
+ {},
382
+ [{
383
+ key: "totalsByUnit",
384
+ computed: {
385
+ _tag: "relation-sum-expr-by",
386
+ path: "items",
387
+ expression: {
388
+ _tag: "mul",
389
+ left: { _tag: "field", field: "weight" },
390
+ right: { _tag: "field", field: "tradeUnit.amount" }
391
+ },
392
+ unit: "tradeUnit.unit",
393
+ filter: []
394
+ }
395
+ }]
396
+ )
397
+ expect(result.sql).toContain(`json_group_array(json_object('unit', __unit, 'total', __total))`)
398
+ expect(result.sql).toContain(`GROUP BY json_extract(_items.value, '$.tradeUnit.unit')`)
399
+ expect(result.sql).toContain(`AS "totalsByUnit"`)
400
+ })
401
+
402
+ it("computed relation-sum-expr-normalized projection (sqlite)", () => {
403
+ const result = buildWhereSQLQuery(
404
+ sqliteDialect,
405
+ "id",
406
+ [],
407
+ "users",
408
+ {},
409
+ [{
410
+ key: "totalKg",
411
+ computed: {
412
+ _tag: "relation-sum-expr-normalized",
413
+ path: "items",
414
+ expression: {
415
+ _tag: "mul",
416
+ left: { _tag: "field", field: "weight" },
417
+ right: { _tag: "field", field: "tradeUnit.amount" }
418
+ },
419
+ unit: "tradeUnit.unit",
420
+ toBase: "kg",
421
+ factors: { g: 0.001 },
422
+ filter: []
423
+ }
424
+ }]
425
+ )
426
+ expect(result.sql).toContain(
427
+ `CASE json_extract(_items.value, '$.tradeUnit.unit') WHEN 'kg' THEN 1 WHEN 'g' THEN 0.001 ELSE NULL END`
428
+ )
429
+ expect(result.sql).toContain(`AS "totalKg"`)
430
+ })
431
+
348
432
  it("computed relation-collect (non-distinct) projection (sqlite)", () => {
349
433
  const result = buildWhereSQLQuery(
350
434
  sqliteDialect,
@@ -515,6 +599,88 @@ describe("SQL query builder (PostgreSQL dialect)", () => {
515
599
  expect(result.sql).toContain(`AS "totalWeight"`)
516
600
  })
517
601
 
602
+ it("computed relation-sum-expr (pg)", () => {
603
+ const result = buildWhereSQLQuery(
604
+ pgDialect,
605
+ "id",
606
+ [],
607
+ "users",
608
+ {},
609
+ [{
610
+ key: "totalWeighted",
611
+ computed: {
612
+ _tag: "relation-sum-expr",
613
+ path: "items",
614
+ expression: {
615
+ _tag: "mul",
616
+ left: { _tag: "field", field: "weight" },
617
+ right: { _tag: "field", field: "tradeUnit.amount" }
618
+ },
619
+ filter: []
620
+ }
621
+ }]
622
+ )
623
+ expect(result.sql).toContain(
624
+ `COALESCE(SUM(((_items->>'weight')::numeric * (_items->'tradeUnit'->>'amount')::numeric)), 0)`
625
+ )
626
+ expect(result.sql).toContain(`AS "totalWeighted"`)
627
+ })
628
+
629
+ it("computed relation-sum-expr-by (pg)", () => {
630
+ const result = buildWhereSQLQuery(
631
+ pgDialect,
632
+ "id",
633
+ [],
634
+ "users",
635
+ {},
636
+ [{
637
+ key: "totalsByUnit",
638
+ computed: {
639
+ _tag: "relation-sum-expr-by",
640
+ path: "items",
641
+ expression: {
642
+ _tag: "mul",
643
+ left: { _tag: "field", field: "weight" },
644
+ right: { _tag: "field", field: "tradeUnit.amount" }
645
+ },
646
+ unit: "tradeUnit.unit",
647
+ filter: []
648
+ }
649
+ }]
650
+ )
651
+ expect(result.sql).toContain(`jsonb_agg(jsonb_build_object('unit', __unit, 'total', __total))`)
652
+ expect(result.sql).toContain(`GROUP BY _items->'tradeUnit'->>'unit'`)
653
+ expect(result.sql).toContain(`AS "totalsByUnit"`)
654
+ })
655
+
656
+ it("computed relation-sum-expr-normalized (pg)", () => {
657
+ const result = buildWhereSQLQuery(
658
+ pgDialect,
659
+ "id",
660
+ [],
661
+ "users",
662
+ {},
663
+ [{
664
+ key: "totalKg",
665
+ computed: {
666
+ _tag: "relation-sum-expr-normalized",
667
+ path: "items",
668
+ expression: {
669
+ _tag: "mul",
670
+ left: { _tag: "field", field: "weight" },
671
+ right: { _tag: "field", field: "tradeUnit.amount" }
672
+ },
673
+ unit: "tradeUnit.unit",
674
+ toBase: "kg",
675
+ factors: { g: 0.001 },
676
+ filter: []
677
+ }
678
+ }]
679
+ )
680
+ expect(result.sql).toContain(`CASE _items->'tradeUnit'->>'unit' WHEN 'kg' THEN 1 WHEN 'g' THEN 0.001 ELSE NULL END`)
681
+ expect(result.sql).toContain(`AS "totalKg"`)
682
+ })
683
+
518
684
  it("computed relation-collect (pg jsonb_agg)", () => {
519
685
  const result = buildWhereSQLQuery(
520
686
  pgDialect,