@palbase/backend 27.1.0 → 29.0.0

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 (52) hide show
  1. package/dist/bin/palbase-backend.cjs +284 -50
  2. package/dist/bin/palbase-backend.cjs.map +1 -1
  3. package/dist/bin/palbase-backend.js +4 -4
  4. package/dist/{chunk-JVZQCC77.js → chunk-3TUJWHC2.js} +8 -3
  5. package/dist/chunk-3TUJWHC2.js.map +1 -0
  6. package/dist/{chunk-EB3TUX5J.js → chunk-DHJ3SYAE.js} +251 -50
  7. package/dist/chunk-DHJ3SYAE.js.map +1 -0
  8. package/dist/{chunk-XABHGMUT.js → chunk-ENZ2RFFJ.js} +2 -2
  9. package/dist/{chunk-BQN723PL.js → chunk-ESSQ3YML.js} +73 -7
  10. package/dist/chunk-ESSQ3YML.js.map +1 -0
  11. package/dist/{chunk-OZKSM3JW.js → chunk-SG4UTNOP.js} +7 -3
  12. package/dist/chunk-SG4UTNOP.js.map +1 -0
  13. package/dist/db/index.cjs +8 -2
  14. package/dist/db/index.cjs.map +1 -1
  15. package/dist/db/index.d.cts +1 -1
  16. package/dist/db/index.d.ts +1 -1
  17. package/dist/db/index.js +3 -3
  18. package/dist/engine/index.cjs +294 -50
  19. package/dist/engine/index.cjs.map +1 -1
  20. package/dist/engine/index.d.cts +3 -3
  21. package/dist/engine/index.d.ts +3 -3
  22. package/dist/engine/index.js +11 -4
  23. package/dist/{index-V7QRh1wg.d.ts → index-BOe82fsK.d.ts} +256 -19
  24. package/dist/{index-CAKOgAlP.d.ts → index-BYDUKexK.d.ts} +139 -10
  25. package/dist/{index-H-0qv5d4.d.cts → index-BZfmdRmh.d.cts} +139 -10
  26. package/dist/{index-CgE4sVhg.d.cts → index-ChvoVczS.d.cts} +256 -19
  27. package/dist/index.cjs +81 -6
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +6 -22
  30. package/dist/index.d.ts +6 -22
  31. package/dist/index.js +10 -4
  32. package/dist/index.js.map +1 -1
  33. package/dist/openapi/index.d.cts +2 -2
  34. package/dist/openapi/index.d.ts +2 -2
  35. package/dist/{registry-DHsPDY0_.d.cts → registry-B2KfKWv1.d.cts} +1 -1
  36. package/dist/{registry-4EI8aaFs.d.ts → registry-DaqHsOq8.d.ts} +1 -1
  37. package/dist/test/index.cjs +129 -6
  38. package/dist/test/index.cjs.map +1 -1
  39. package/dist/test/index.d.cts +1 -1
  40. package/dist/test/index.d.ts +1 -1
  41. package/dist/test/index.js +126 -6
  42. package/dist/test/index.js.map +1 -1
  43. package/docs/README.md +1 -1
  44. package/docs/database.md +118 -1
  45. package/docs/llms-full.txt +119 -2
  46. package/package.json +1 -1
  47. package/template/package.json +1 -1
  48. package/dist/chunk-BQN723PL.js.map +0 -1
  49. package/dist/chunk-EB3TUX5J.js.map +0 -1
  50. package/dist/chunk-JVZQCC77.js.map +0 -1
  51. package/dist/chunk-OZKSM3JW.js.map +0 -1
  52. /package/dist/{chunk-XABHGMUT.js.map → chunk-ENZ2RFFJ.js.map} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { T as Token } from '../module-Dl1KFVtc.cjs';
2
- import { D as DBClient } from '../index-CgE4sVhg.cjs';
2
+ import { D as DBClient } from '../index-ChvoVczS.cjs';
3
3
  import '../db/env.cjs';
4
4
  import '../stack.cjs';
5
5
  import 'zod';
@@ -1,5 +1,5 @@
1
1
  import { T as Token } from '../module-Dl1KFVtc.js';
2
- import { D as DBClient } from '../index-V7QRh1wg.js';
2
+ import { D as DBClient } from '../index-BOe82fsK.js';
3
3
  import '../db/env.js';
4
4
  import '../stack.js';
5
5
  import 'zod';
@@ -7,7 +7,7 @@ import {
7
7
  isColumnExpr,
8
8
  isNowExpr,
9
9
  isSqlFragment
10
- } from "../chunk-JVZQCC77.js";
10
+ } from "../chunk-3TUJWHC2.js";
11
11
  import {
12
12
  __name
13
13
  } from "../chunk-VXPNPVAG.js";
@@ -506,6 +506,22 @@ function createMockDB() {
506
506
  ]);
507
507
  }
508
508
  __name(track, "track");
509
+ function resolveInsertValues(caller, table, data) {
510
+ const out = {};
511
+ for (const [k, v] of Object.entries(data)) {
512
+ const expr = columnExprOf(v);
513
+ if (expr !== null && expr.fn === "now") {
514
+ out[k] = (/* @__PURE__ */ new Date()).toISOString();
515
+ continue;
516
+ }
517
+ if (expr !== null) {
518
+ throw new Error(`${caller}(${table}): "${k}" ${expr.fn === "inc" ? "increment()" : "decrement()"} ald\u0131 \u2014 sat\u0131r HEN\xDCZ YOK, yani "kolonun \u015Fu anki de\u011Feri" diye bir \u015Fey yok.`);
519
+ }
520
+ out[k] = v;
521
+ }
522
+ return out;
523
+ }
524
+ __name(resolveInsertValues, "resolveInsertValues");
509
525
  const ops = {
510
526
  // The bulk ops and count run against the SAME in-memory store the direct
511
527
  // ops write to, so a test that writes three rows and counts them gets 3 —
@@ -568,7 +584,8 @@ function createMockDB() {
568
584
  async query(_sql, _params) {
569
585
  return [];
570
586
  },
571
- async insert(table, data) {
587
+ async insert(table, raw) {
588
+ const data = resolveInsertValues("insert", table, raw);
572
589
  assertUsableWriteValues("insert", table, Object.keys(data), data);
573
590
  assertNoExpressionHandles("insert", table, Object.keys(data), data);
574
591
  const record = {
@@ -580,6 +597,94 @@ function createMockDB() {
580
597
  return record;
581
598
  },
582
599
  /**
600
+ * `insertMany` — motorla PARİTE, ANAHTAR KÜMESİ kuralı dahil.
601
+ *
602
+ * Fake bu kuralı bilmeseydi farklı şekilli satırları kabul eder, test yeşil
603
+ * kalır, üretimde motor adıyla reddederdi — yani fake, sürüm atlamayı
604
+ * kolaylaştırmak yerine gizlerdi.
605
+ */
606
+ /**
607
+ * `aggregate` — motorla PARİTE, PARA KESİNLİĞİ dahil.
608
+ *
609
+ * Fake toplamayı JS `number` ile yapsaydı test yeşil kalır ve üretimde
610
+ * `numeric` kesinliği kaybolurdu — yani fake tam da korunması gereken şeyi
611
+ * gizlerdi. `addDecimal` BigInt ölçekli toplama yapıyor, motorun
612
+ * `sum(numeric)::text`'inin karşılığı.
613
+ */
614
+ async aggregate(table, q) {
615
+ const rows = (store.get(table) ?? []).filter((r) => q.where === void 0 || rowMatchesFilter("aggregate", table, r, q.where));
616
+ const groups = q.groupBy ?? [];
617
+ const shape = /* @__PURE__ */ __name((bucket) => {
618
+ const out = {};
619
+ for (const c of q.sum ?? []) {
620
+ const vals = bucket.map((r) => r[c]).filter((v) => v !== null && v !== void 0);
621
+ (out["sum"] ??= {})[c] = vals.length === 0 ? null : String(vals.reduce((a, v) => addDecimal(a, v, 1), "0"));
622
+ }
623
+ for (const c of q.avg ?? []) {
624
+ const vals = bucket.map((r) => r[c]).filter((v) => v !== null && v !== void 0);
625
+ (out["avg"] ??= {})[c] = vals.length === 0 ? null : String(Number(vals.reduce((a, v) => addDecimal(a, v, 1), "0")) / vals.length);
626
+ }
627
+ for (const [fn, pick] of [
628
+ [
629
+ "min",
630
+ -1
631
+ ],
632
+ [
633
+ "max",
634
+ 1
635
+ ]
636
+ ]) {
637
+ for (const c of q[fn] ?? []) {
638
+ const vals = bucket.map((r) => r[c]).filter((v) => v !== null && v !== void 0);
639
+ (out[fn] ??= {})[c] = vals.length === 0 ? null : vals.reduce((a, v) => cmp(v, a, pick === 1 ? "gt" : "lt") ? v : a);
640
+ }
641
+ }
642
+ if (q.count === true) out["count"] = bucket.length;
643
+ return out;
644
+ }, "shape");
645
+ if (groups.length === 0) return shape(rows);
646
+ const byKey = /* @__PURE__ */ new Map();
647
+ for (const r of rows) {
648
+ const k = JSON.stringify(groups.map((c) => r[c]));
649
+ byKey.set(k, [
650
+ ...byKey.get(k) ?? [],
651
+ r
652
+ ]);
653
+ }
654
+ return [
655
+ ...byKey.values()
656
+ ].map((bucket) => {
657
+ const out = shape(bucket);
658
+ for (const c of groups) out[c] = bucket[0][c];
659
+ return out;
660
+ });
661
+ },
662
+ async insertMany(table, rows) {
663
+ if (rows.length === 0) return [];
664
+ const cols = Object.keys(rows[0]);
665
+ for (let i = 1; i < rows.length; i++) {
666
+ const missing = cols.filter((c) => !(c in rows[i]));
667
+ const extra = Object.keys(rows[i]).filter((k) => !cols.includes(k));
668
+ if (missing.length > 0 || extra.length > 0) {
669
+ throw new Error(`insertMany(${table}): ${i}. sat\u0131r\u0131n kolonlar\u0131 ilk sat\u0131rla ayn\u0131 de\u011Fil` + (missing.length > 0 ? ` (eksik: ${missing.join(", ")})` : "") + (extra.length > 0 ? ` (fazla: ${extra.join(", ")})` : "") + `. Eksikler i\xE7in null yaz\u0131n, ya da farkl\u0131 \u015Fekilli sat\u0131rlar\u0131 ayr\u0131 \xE7a\u011Fr\u0131larda ekleyin.`);
670
+ }
671
+ }
672
+ const out = [];
673
+ for (const rawRow of rows) {
674
+ const data = resolveInsertValues("insertMany", table, rawRow);
675
+ assertUsableWriteValues("insertMany", table, cols, data);
676
+ assertNoExpressionHandles("insertMany", table, cols, data);
677
+ const record = {
678
+ id: crypto.randomUUID(),
679
+ ...data
680
+ };
681
+ rowsOf(table).push(record);
682
+ track(tracked.inserted, table, record);
683
+ out.push(record);
684
+ }
685
+ return out;
686
+ },
687
+ /**
583
688
  * `claim` — motorla PARİTE (FR-033).
584
689
  *
585
690
  * Fake bunu sunmasaydı `claim` ile yazılmış bir servis, iskelenin yazarlara
@@ -638,10 +743,11 @@ function createMockDB() {
638
743
  },
639
744
  // Same semantics the engine's SQL has: match on the conflict columns, update
640
745
  // everything else, and return the resulting row either way.
641
- async put(table, data, opts) {
746
+ async put(table, rawData, opts) {
642
747
  if (opts.onConflict.length === 0) {
643
748
  throw new Error(`put into ${table}: onConflict en az bir kolon ad\u0131 ister`);
644
749
  }
750
+ const data = resolveInsertValues("put", table, rawData);
645
751
  assertUsableWriteValues("upsert", table, Object.keys(data), data);
646
752
  assertNoExpressionHandles("upsert", table, Object.keys(data), data);
647
753
  const rows = rowsOf(table);
@@ -662,15 +768,29 @@ function createMockDB() {
662
768
  },
663
769
  async update(table, id, data) {
664
770
  assertUsableWriteValues("update", table, Object.keys(data), data);
665
- assertNoExpressionHandles("update", table, Object.keys(data), data);
666
771
  const rows = store.get(table) ?? [];
667
772
  const idx = rows.findIndex((r) => r["id"] === id);
773
+ const current = idx >= 0 ? rows[idx] : {};
774
+ const applied = {};
775
+ for (const [k, v] of Object.entries(data)) {
776
+ const expr = columnExprOf(v);
777
+ if (expr !== null && expr.fn === "now") {
778
+ applied[k] = /* @__PURE__ */ new Date();
779
+ continue;
780
+ }
781
+ if (expr !== null) {
782
+ applied[k] = addDecimal(current[k], expr.by, expr.fn === "inc" ? 1 : -1);
783
+ continue;
784
+ }
785
+ applied[k] = v;
786
+ }
787
+ assertNoExpressionHandles("update", table, Object.keys(applied), applied);
668
788
  const updated = idx >= 0 ? {
669
789
  ...rows[idx],
670
- ...data
790
+ ...applied
671
791
  } : {
672
792
  id,
673
- ...data
793
+ ...applied
674
794
  };
675
795
  if (idx >= 0) {
676
796
  rows[idx] = updated;