@kdrgny/justjson 1.0.1 → 1.2.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 (23) hide show
  1. package/README.md +7 -3
  2. package/dist/cli.js +573 -14
  3. package/dist/editor/assets/index-BoAqd15W.js +612 -0
  4. package/dist/editor/assets/index-CP_v5575.css +1 -0
  5. package/dist/editor/assets/public-sans-latin-ext-wght-normal-MQgHevqp.woff2 +0 -0
  6. package/dist/editor/assets/public-sans-latin-wght-normal-DdeTHZLK.woff2 +0 -0
  7. package/dist/editor/assets/public-sans-vietnamese-wght-normal-CtlIRbEm.woff2 +0 -0
  8. package/dist/editor/assets/space-mono-latin-400-normal-Rg4St2Dn.woff2 +0 -0
  9. package/dist/editor/assets/space-mono-latin-400-normal-_3DlpgIW.woff +0 -0
  10. package/dist/editor/assets/space-mono-latin-700-normal-D7A851RN.woff +0 -0
  11. package/dist/editor/assets/space-mono-latin-700-normal-mWgeinG7.woff2 +0 -0
  12. package/dist/editor/assets/space-mono-latin-ext-400-normal-D4cJI_B-.woff +0 -0
  13. package/dist/editor/assets/space-mono-latin-ext-400-normal-DTLbW2xa.woff2 +0 -0
  14. package/dist/editor/assets/space-mono-latin-ext-700-normal-B2s3bDs2.woff2 +0 -0
  15. package/dist/editor/assets/space-mono-latin-ext-700-normal-B_E7P90g.woff +0 -0
  16. package/dist/editor/assets/space-mono-vietnamese-400-normal-B0PMp_xB.woff +0 -0
  17. package/dist/editor/assets/space-mono-vietnamese-400-normal-BNOj0Qhp.woff2 +0 -0
  18. package/dist/editor/assets/space-mono-vietnamese-700-normal-D-KrLuLr.woff +0 -0
  19. package/dist/editor/assets/space-mono-vietnamese-700-normal-DWQgDHuA.woff2 +0 -0
  20. package/dist/editor/index.html +2 -2
  21. package/package.json +3 -14
  22. package/dist/editor/assets/index-BN_YWkOH.css +0 -1
  23. package/dist/editor/assets/index-DsfRA4dz.js +0 -400
package/dist/cli.js CHANGED
@@ -4314,6 +4314,98 @@ function buildExportManifest(input) {
4314
4314
  }
4315
4315
  return out;
4316
4316
  }
4317
+ var HTML = /<[a-z!/][\s\S]*>/i;
4318
+ function inferType(value) {
4319
+ if (typeof value === "boolean") return "boolean";
4320
+ if (typeof value === "number") return "number";
4321
+ if (typeof value === "string") return HTML.test(value) ? "richtext" : "text";
4322
+ return null;
4323
+ }
4324
+ function isPlainObject(v) {
4325
+ return typeof v === "object" && v !== null && !Array.isArray(v);
4326
+ }
4327
+ function fieldsFromRows(rows) {
4328
+ const order = [];
4329
+ const types = /* @__PURE__ */ new Map();
4330
+ for (const row of rows) {
4331
+ for (const [key, value] of Object.entries(row)) {
4332
+ const t = inferType(value);
4333
+ if (t === null) continue;
4334
+ if (!types.has(key)) {
4335
+ types.set(key, t);
4336
+ order.push(key);
4337
+ } else if (types.get(key) === "text" && t === "richtext") {
4338
+ types.set(key, "richtext");
4339
+ }
4340
+ }
4341
+ }
4342
+ return order.map((key) => ({ key, label: key, type: types.get(key) }));
4343
+ }
4344
+ function inferProject(data) {
4345
+ if (!isPlainObject(data)) throw new Error("\u0130\xE7e aktar\u0131lan JSON bir nesne olmal\u0131.");
4346
+ const collections = [];
4347
+ const singletons = [];
4348
+ const entries = {};
4349
+ const singletonData = {};
4350
+ const generalFields = [];
4351
+ const generalData = {};
4352
+ const usedNames = /* @__PURE__ */ new Set();
4353
+ const uniqueName = (base) => {
4354
+ let name = base || "alan";
4355
+ let n = 2;
4356
+ while (usedNames.has(name)) name = `${base}-${n++}`;
4357
+ usedNames.add(name);
4358
+ return name;
4359
+ };
4360
+ const isRowList = (v) => Array.isArray(v) && v.length > 0 && v.every(isPlainObject);
4361
+ const addCollection = (key, list, label = key) => {
4362
+ const name = uniqueName(slugify(key));
4363
+ const seen = /* @__PURE__ */ new Set();
4364
+ const rows = list.map((row, i) => {
4365
+ const firstText = Object.values(row).find((v) => typeof v === "string" && v.trim() !== "");
4366
+ const base = slugify(
4367
+ String(row.slug ?? row.title ?? row.name ?? row.label ?? firstText ?? `${name}-${i + 1}`)
4368
+ ) || `${name}-${i + 1}`;
4369
+ let slug = base;
4370
+ let n = 2;
4371
+ while (seen.has(slug)) slug = `${base}-${n++}`;
4372
+ seen.add(slug);
4373
+ return { slug, ...row };
4374
+ });
4375
+ const fields = fieldsFromRows(rows);
4376
+ const keys = new Set(fields.map((f) => f.key));
4377
+ collections.push({ name, label, path: name, fields });
4378
+ entries[name] = rows.map(
4379
+ (row) => Object.fromEntries(Object.entries(row).filter(([k]) => keys.has(k)))
4380
+ );
4381
+ };
4382
+ for (const [key, value] of Object.entries(data)) {
4383
+ if (isRowList(value)) {
4384
+ addCollection(key, value);
4385
+ } else if (isPlainObject(value)) {
4386
+ const name = uniqueName(slugify(key));
4387
+ const flat = {};
4388
+ for (const [k, v] of Object.entries(value)) {
4389
+ if (isRowList(v)) addCollection(usedNames.has(slugify(k)) ? `${key}-${k}` : k, v, k);
4390
+ else if (inferType(v) !== null) flat[k] = v;
4391
+ }
4392
+ singletons.push({ name, label: key, path: `${name}.json`, fields: fieldsFromRows([flat]) });
4393
+ singletonData[name] = flat;
4394
+ } else {
4395
+ const t = inferType(value);
4396
+ if (t) {
4397
+ generalFields.push({ key, label: key, type: t });
4398
+ generalData[key] = value;
4399
+ }
4400
+ }
4401
+ }
4402
+ if (generalFields.length > 0) {
4403
+ const name = uniqueName("genel");
4404
+ singletons.push({ name, label: "Genel", path: `${name}.json`, fields: generalFields });
4405
+ singletonData[name] = generalData;
4406
+ }
4407
+ return { schema: { version: 1, collections, singletons }, entries, singletons: singletonData };
4408
+ }
4317
4409
 
4318
4410
  // src/commands/export.ts
4319
4411
  import { zipSync } from "fflate";
@@ -4387,9 +4479,7 @@ async function resolveContentDir(root2) {
4387
4479
  }
4388
4480
 
4389
4481
  // src/commands/export.ts
4390
- async function exportZip(root2, outFile = "justjson-export.zip") {
4391
- const adapter = new FsAdapter(root2);
4392
- const contentDir = await resolveContentDir(root2);
4482
+ async function collectExportZip(adapter, contentDir) {
4393
4483
  const schema = await loadSchema(adapter, contentDir);
4394
4484
  if (!schema) throw new Error("\u015Eema bulunamad\u0131. \xD6nce `justjson init` \xE7al\u0131\u015Ft\u0131r\u0131n.");
4395
4485
  const store = new ContentStore(adapter, schema, contentDir);
@@ -4414,7 +4504,12 @@ async function exportZip(root2, outFile = "justjson-export.zip") {
4414
4504
  for (const [path, content] of Object.entries(manifest)) {
4415
4505
  zipInput[path] = typeof content === "string" ? encoder.encode(content) : content;
4416
4506
  }
4417
- const zipped = zipSync(zipInput);
4507
+ return zipSync(zipInput);
4508
+ }
4509
+ async function exportZip(root2, outFile = "justjson-export.zip") {
4510
+ const adapter = new FsAdapter(root2);
4511
+ const contentDir = await resolveContentDir(root2);
4512
+ const zipped = await collectExportZip(adapter, contentDir);
4418
4513
  const outAbs = join(root2, outFile);
4419
4514
  await writeFile2(outAbs, zipped);
4420
4515
  return outAbs;
@@ -4422,6 +4517,8 @@ async function exportZip(root2, outFile = "justjson-export.zip") {
4422
4517
 
4423
4518
  // src/templates/blog.json
4424
4519
  var blog_default = {
4520
+ title: "Blog",
4521
+ description: "Rich-text i\xE7erikli yaz\u0131lar ve site ad\u0131 i\xE7in bir Ayarlar.",
4425
4522
  schema: {
4426
4523
  version: 1,
4427
4524
  collections: [
@@ -4451,8 +4548,100 @@ var blog_default = {
4451
4548
  }
4452
4549
  };
4453
4550
 
4551
+ // src/templates/catalog.json
4552
+ var catalog_default = {
4553
+ title: "\xDCr\xFCn Katalo\u011Fu",
4554
+ description: "Fiyat, kategori ve g\xF6rselli \xFCr\xFCnler; bir de Ma\u011Faza ayarlar\u0131.",
4555
+ schema: {
4556
+ version: 1,
4557
+ collections: [
4558
+ {
4559
+ name: "urunler",
4560
+ label: "\xDCr\xFCnler",
4561
+ path: "urunler",
4562
+ fields: [
4563
+ { key: "title", label: "Ba\u015Fl\u0131k", type: "text", required: true },
4564
+ { key: "slug", label: "Slug", type: "text", required: true },
4565
+ { key: "fiyat", label: "Fiyat", type: "number" },
4566
+ {
4567
+ key: "kategori",
4568
+ label: "Kategori",
4569
+ type: "select",
4570
+ options: ["Ev", "Giyim", "Aksesuar"]
4571
+ },
4572
+ { key: "kapak", label: "G\xF6rsel", type: "image" },
4573
+ { key: "aciklama", label: "A\xE7\u0131klama", type: "richtext" }
4574
+ ]
4575
+ }
4576
+ ],
4577
+ singletons: [
4578
+ {
4579
+ name: "magaza",
4580
+ label: "Ma\u011Faza",
4581
+ path: "magaza.json",
4582
+ fields: [
4583
+ { key: "title", label: "Ma\u011Faza ad\u0131", type: "text" },
4584
+ { key: "slogan", label: "Slogan", type: "text" }
4585
+ ]
4586
+ }
4587
+ ]
4588
+ },
4589
+ samples: {
4590
+ urunler: [
4591
+ {
4592
+ title: "Seramik Kupa",
4593
+ slug: "seramik-kupa",
4594
+ fiyat: 180,
4595
+ kategori: "Ev",
4596
+ aciklama: "Elde yap\u0131m seramik kupa."
4597
+ }
4598
+ ]
4599
+ }
4600
+ };
4601
+
4602
+ // src/templates/changelog.json
4603
+ var changelog_default = {
4604
+ title: "Changelog",
4605
+ description: "S\xFCr\xFCm notlar\u0131: versiyon, tarih, t\xFCr ve rich-text a\xE7\u0131klama.",
4606
+ schema: {
4607
+ version: 1,
4608
+ collections: [
4609
+ {
4610
+ name: "releases",
4611
+ label: "S\xFCr\xFCmler",
4612
+ path: "releases",
4613
+ fields: [
4614
+ { key: "version", label: "Versiyon", type: "text", required: true },
4615
+ { key: "slug", label: "Slug", type: "text", required: true },
4616
+ { key: "date", label: "Tarih", type: "date" },
4617
+ {
4618
+ key: "type",
4619
+ label: "T\xFCr",
4620
+ type: "select",
4621
+ options: ["Eklendi", "De\u011Fi\u015Fti", "D\xFCzeltildi"]
4622
+ },
4623
+ { key: "body", label: "Notlar", type: "richtext" }
4624
+ ]
4625
+ }
4626
+ ],
4627
+ singletons: []
4628
+ },
4629
+ samples: {
4630
+ releases: [
4631
+ {
4632
+ version: "1.0.0",
4633
+ slug: "1-0-0",
4634
+ type: "Eklendi",
4635
+ body: "\u0130lk s\xFCr\xFCm."
4636
+ }
4637
+ ]
4638
+ }
4639
+ };
4640
+
4454
4641
  // src/templates/cv.json
4455
4642
  var cv_default = {
4643
+ title: "CV",
4644
+ description: "Deneyim koleksiyonu ve ki\u015Fisel bilgiler i\xE7in bir Profil.",
4456
4645
  schema: {
4457
4646
  version: 1,
4458
4647
  collections: [
@@ -4484,22 +4673,224 @@ var cv_default = {
4484
4673
  }
4485
4674
  };
4486
4675
 
4676
+ // src/templates/docs.json
4677
+ var docs_default = {
4678
+ title: "Dok\xFCmantasyon",
4679
+ description: "S\u0131ralanabilir sayfalar ve rich-text i\xE7erik; site ba\u015Fl\u0131\u011F\u0131 i\xE7in bir Ayarlar.",
4680
+ schema: {
4681
+ version: 1,
4682
+ collections: [
4683
+ {
4684
+ name: "pages",
4685
+ label: "Sayfalar",
4686
+ path: "pages",
4687
+ fields: [
4688
+ { key: "title", label: "Ba\u015Fl\u0131k", type: "text", required: true },
4689
+ { key: "slug", label: "Slug", type: "text", required: true },
4690
+ { key: "order", label: "S\u0131ra", type: "number" },
4691
+ { key: "body", label: "\u0130\xE7erik", type: "richtext" }
4692
+ ]
4693
+ }
4694
+ ],
4695
+ singletons: [
4696
+ {
4697
+ name: "settings",
4698
+ label: "Ayarlar",
4699
+ path: "settings.json",
4700
+ fields: [
4701
+ { key: "title", label: "Site ad\u0131", type: "text" },
4702
+ { key: "tagline", label: "Slogan", type: "text" }
4703
+ ]
4704
+ }
4705
+ ]
4706
+ },
4707
+ samples: {
4708
+ pages: [
4709
+ { title: "Ba\u015Flarken", slug: "baslarken", order: 1, body: "Kuruluma ho\u015F geldin." }
4710
+ ]
4711
+ }
4712
+ };
4713
+
4714
+ // src/templates/event.json
4715
+ var event_default = {
4716
+ title: "Etkinlik Program\u0131",
4717
+ description: "Tarih, saat ve konu\u015Fmac\u0131l\u0131 oturumlardan olu\u015Fan bir etkinlik ajandas\u0131.",
4718
+ schema: {
4719
+ version: 1,
4720
+ collections: [
4721
+ {
4722
+ name: "oturumlar",
4723
+ label: "Oturumlar",
4724
+ path: "oturumlar",
4725
+ fields: [
4726
+ { key: "title", label: "Ba\u015Fl\u0131k", type: "text", required: true },
4727
+ { key: "slug", label: "Slug", type: "text", required: true },
4728
+ { key: "tarih", label: "Tarih", type: "date" },
4729
+ { key: "saat", label: "Saat", type: "text" },
4730
+ { key: "konusmaci", label: "Konu\u015Fmac\u0131", type: "text" },
4731
+ { key: "yer", label: "Salon", type: "text" },
4732
+ { key: "aciklama", label: "A\xE7\u0131klama", type: "richtext" }
4733
+ ]
4734
+ }
4735
+ ],
4736
+ singletons: [
4737
+ {
4738
+ name: "etkinlik",
4739
+ label: "Etkinlik",
4740
+ path: "etkinlik.json",
4741
+ fields: [
4742
+ { key: "title", label: "Etkinlik ad\u0131", type: "text" },
4743
+ { key: "slogan", label: "Slogan", type: "text" }
4744
+ ]
4745
+ }
4746
+ ]
4747
+ },
4748
+ samples: {
4749
+ oturumlar: [
4750
+ {
4751
+ title: "A\xE7\u0131l\u0131\u015F Konu\u015Fmas\u0131",
4752
+ slug: "acilis-konusmasi",
4753
+ saat: "09:00",
4754
+ konusmaci: "Ay\u015Fe Y\u0131lmaz",
4755
+ yer: "Ana Salon",
4756
+ aciklama: "Etkinli\u011Fe ho\u015F geldiniz."
4757
+ }
4758
+ ]
4759
+ }
4760
+ };
4761
+
4762
+ // src/templates/portfolio.json
4763
+ var portfolio_default = {
4764
+ title: "Portfolyo",
4765
+ description: "Kapak g\xF6rseli, etiket ve rich-text i\xE7erikli projeler; bir de Hakk\u0131nda sayfas\u0131.",
4766
+ schema: {
4767
+ version: 1,
4768
+ collections: [
4769
+ {
4770
+ name: "projects",
4771
+ label: "Projeler",
4772
+ path: "projects",
4773
+ fields: [
4774
+ { key: "title", label: "Ba\u015Fl\u0131k", type: "text", required: true },
4775
+ { key: "slug", label: "Slug", type: "text", required: true },
4776
+ { key: "summary", label: "\xD6zet", type: "text" },
4777
+ { key: "cover", label: "Kapak", type: "image" },
4778
+ { key: "url", label: "Ba\u011Flant\u0131", type: "text" },
4779
+ {
4780
+ key: "kind",
4781
+ label: "T\xFCr",
4782
+ type: "select",
4783
+ options: ["Web", "Mobil", "Tasar\u0131m"]
4784
+ },
4785
+ { key: "body", label: "\u0130\xE7erik", type: "richtext" },
4786
+ { key: "date", label: "Tarih", type: "date" }
4787
+ ]
4788
+ }
4789
+ ],
4790
+ singletons: [
4791
+ {
4792
+ name: "about",
4793
+ label: "Hakk\u0131nda",
4794
+ path: "about.json",
4795
+ fields: [
4796
+ { key: "name", label: "Ad", type: "text", required: true },
4797
+ { key: "avatar", label: "Avatar", type: "image" },
4798
+ { key: "bio", label: "Biyografi", type: "richtext" }
4799
+ ]
4800
+ }
4801
+ ]
4802
+ },
4803
+ samples: {
4804
+ projects: [
4805
+ {
4806
+ title: "\xD6rnek Proje",
4807
+ slug: "ornek-proje",
4808
+ summary: "K\u0131sa bir a\xE7\u0131klama.",
4809
+ kind: "Web",
4810
+ body: "Proje detaylar\u0131 burada."
4811
+ }
4812
+ ]
4813
+ }
4814
+ };
4815
+
4816
+ // src/templates/recipe.json
4817
+ var recipe_default = {
4818
+ title: "Tarif Defteri",
4819
+ description: "Malzeme, yap\u0131l\u0131\u015F ve kapak g\xF6rselli tarifler; bir de Mutfak ayarlar\u0131.",
4820
+ schema: {
4821
+ version: 1,
4822
+ collections: [
4823
+ {
4824
+ name: "tarifler",
4825
+ label: "Tarifler",
4826
+ path: "tarifler",
4827
+ fields: [
4828
+ { key: "title", label: "Ba\u015Fl\u0131k", type: "text", required: true },
4829
+ { key: "slug", label: "Slug", type: "text", required: true },
4830
+ { key: "sure", label: "S\xFCre", type: "text" },
4831
+ { key: "porsiyon", label: "Porsiyon", type: "number" },
4832
+ { key: "kapak", label: "Kapak", type: "image" },
4833
+ { key: "malzemeler", label: "Malzemeler", type: "richtext" },
4834
+ { key: "yapilis", label: "Yap\u0131l\u0131\u015F", type: "richtext" }
4835
+ ]
4836
+ }
4837
+ ],
4838
+ singletons: [
4839
+ {
4840
+ name: "mutfak",
4841
+ label: "Mutfak",
4842
+ path: "mutfak.json",
4843
+ fields: [{ key: "title", label: "Site ad\u0131", type: "text" }]
4844
+ }
4845
+ ]
4846
+ },
4847
+ samples: {
4848
+ tarifler: [
4849
+ {
4850
+ title: "Ak\u015Fam Makarnas\u0131",
4851
+ slug: "aksam-makarnasi",
4852
+ sure: "20 dk",
4853
+ porsiyon: 2,
4854
+ malzemeler: "- 200g makarna\n- 2 di\u015F sar\u0131msak\n- Zeytinya\u011F\u0131",
4855
+ yapilis: "Makarnay\u0131 ha\u015Fla. Sar\u0131msa\u011F\u0131 zeytinya\u011F\u0131nda kavur. Kar\u0131\u015Ft\u0131r."
4856
+ }
4857
+ ]
4858
+ }
4859
+ };
4860
+
4487
4861
  // src/commands/init.ts
4488
4862
  var templates = {
4489
4863
  blog: blog_default,
4490
- cv: cv_default
4864
+ cv: cv_default,
4865
+ portfolio: portfolio_default,
4866
+ docs: docs_default,
4867
+ changelog: changelog_default,
4868
+ recipe: recipe_default,
4869
+ event: event_default,
4870
+ catalog: catalog_default
4491
4871
  };
4492
4872
  function listTemplates() {
4493
4873
  return Object.keys(templates);
4494
4874
  }
4495
- async function initProject(root2, templateName) {
4496
- const template = templates[templateName];
4497
- if (!template) throw new Error(`Bilinmeyen template: ${templateName}`);
4498
- const adapter = new FsAdapter(root2);
4499
- const contentDir = await resolveContentDir(root2);
4500
- if (await loadSchema(adapter, contentDir)) {
4501
- throw new Error("Bu klas\xF6rde zaten bir \u015Fema var (content/_schema.json).");
4502
- }
4875
+ function getTemplate(name) {
4876
+ return templates[name];
4877
+ }
4878
+ function templateList() {
4879
+ return Object.entries(templates).map(([id, t]) => {
4880
+ const s = t.schema;
4881
+ return {
4882
+ id,
4883
+ title: t.title,
4884
+ description: t.description,
4885
+ collections: s.collections.map((c) => ({
4886
+ label: c.label ?? c.name,
4887
+ fields: c.fields.length
4888
+ })),
4889
+ singletons: s.singletons.map((sg) => ({ label: sg.label ?? sg.name }))
4890
+ };
4891
+ });
4892
+ }
4893
+ async function applyTemplate(adapter, contentDir, template) {
4503
4894
  const schema = parseSchema(template.schema);
4504
4895
  await saveSchema(adapter, schema, contentDir);
4505
4896
  const store = new ContentStore(adapter, schema, contentDir);
@@ -4509,6 +4900,17 @@ async function initProject(root2, templateName) {
4509
4900
  await store.writeEntry(collection, slug, row);
4510
4901
  }
4511
4902
  }
4903
+ return schema;
4904
+ }
4905
+ async function initProject(root2, templateName) {
4906
+ const template = templates[templateName];
4907
+ if (!template) throw new Error(`Bilinmeyen template: ${templateName}`);
4908
+ const adapter = new FsAdapter(root2);
4909
+ const contentDir = await resolveContentDir(root2);
4910
+ if (await loadSchema(adapter, contentDir)) {
4911
+ throw new Error("Bu klas\xF6rde zaten bir \u015Fema var (content/_schema.json).");
4912
+ }
4913
+ await applyTemplate(adapter, contentDir, template);
4512
4914
  }
4513
4915
 
4514
4916
  // src/commands/types.ts
@@ -4525,11 +4927,70 @@ async function generateTypesFile(root2, outPath = "types.ts") {
4525
4927
  // src/server.ts
4526
4928
  import { exec } from "child_process";
4527
4929
  import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile3 } from "fs/promises";
4528
- import { dirname as dirname2, extname, join as join3, normalize } from "path";
4930
+ import { basename, dirname as dirname2, extname, join as join3, normalize } from "path";
4529
4931
  import { fileURLToPath } from "url";
4530
4932
  import { serve } from "@hono/node-server";
4531
4933
  import { Hono } from "hono";
4532
4934
  var editorDir = fileURLToPath(new URL("./editor", import.meta.url));
4935
+ var PROVIDER_BASE_URLS = {
4936
+ groq: "https://api.groq.com/openai/v1",
4937
+ openrouter: "https://openrouter.ai/api/v1"
4938
+ };
4939
+ async function callGemini(apiKey, model, system, prompt) {
4940
+ const cleanModel = model.trim().replace(/^models\//, "");
4941
+ const url = `https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(cleanModel)}:generateContent?key=${encodeURIComponent(apiKey)}`;
4942
+ const res = await fetch(url, {
4943
+ method: "POST",
4944
+ headers: { "content-type": "application/json" },
4945
+ body: JSON.stringify({
4946
+ contents: [{ role: "user", parts: [{ text: prompt }] }],
4947
+ ...system ? { systemInstruction: { parts: [{ text: system }] } } : {}
4948
+ })
4949
+ });
4950
+ const data = await res.json();
4951
+ if (!res.ok) throw new Error(data.error?.message ?? `Gemini iste\u011Fi ba\u015Far\u0131s\u0131z (${res.status})`);
4952
+ const text = data.candidates?.[0]?.content?.parts?.map((p) => p.text ?? "").join("") ?? "";
4953
+ if (!text) throw new Error("Gemini bo\u015F yan\u0131t d\xF6nd\xFC");
4954
+ return text;
4955
+ }
4956
+ async function listGeminiModels(apiKey) {
4957
+ const url = `https://generativelanguage.googleapis.com/v1beta/models?key=${encodeURIComponent(apiKey)}&pageSize=1000`;
4958
+ const res = await fetch(url);
4959
+ const data = await res.json();
4960
+ if (!res.ok) throw new Error(data.error?.message ?? `Model listesi al\u0131namad\u0131 (${res.status})`);
4961
+ return (data.models ?? []).filter((m) => m.supportedGenerationMethods?.includes("generateContent")).map((m) => ({
4962
+ id: (m.name ?? "").replace(/^models\//, ""),
4963
+ label: m.displayName ?? (m.name ?? "").replace(/^models\//, "")
4964
+ })).filter(
4965
+ (m) => m.id && !/tts|image|embedding|robotics|computer-use|veo|lyria|imagen|aqa/i.test(m.id)
4966
+ );
4967
+ }
4968
+ async function listOpenAiCompatibleModels(baseUrl, apiKey) {
4969
+ if (!baseUrl) throw new Error("Bu sa\u011Flay\u0131c\u0131 i\xE7in taban URL gerekli");
4970
+ const res = await fetch(`${baseUrl.replace(/\/$/, "")}/models`, {
4971
+ headers: apiKey ? { authorization: `Bearer ${apiKey}` } : {}
4972
+ });
4973
+ const data = await res.json();
4974
+ if (!res.ok) throw new Error(data.error?.message ?? `Model listesi al\u0131namad\u0131 (${res.status})`);
4975
+ return (data.data ?? []).map((m) => ({ id: m.id ?? "", label: m.id ?? "" })).filter((m) => m.id);
4976
+ }
4977
+ async function callOpenAiCompatible(baseUrl, apiKey, model, system, prompt) {
4978
+ if (!baseUrl) throw new Error("Bu sa\u011Flay\u0131c\u0131 i\xE7in taban URL gerekli");
4979
+ const messages = [
4980
+ ...system ? [{ role: "system", content: system }] : [],
4981
+ { role: "user", content: prompt }
4982
+ ];
4983
+ const res = await fetch(`${baseUrl.replace(/\/$/, "")}/chat/completions`, {
4984
+ method: "POST",
4985
+ headers: { "content-type": "application/json", authorization: `Bearer ${apiKey}` },
4986
+ body: JSON.stringify({ model, messages })
4987
+ });
4988
+ const data = await res.json();
4989
+ if (!res.ok) throw new Error(data.error?.message ?? `\u0130stek ba\u015Far\u0131s\u0131z (${res.status})`);
4990
+ const text = data.choices?.[0]?.message?.content ?? "";
4991
+ if (!text) throw new Error("Sa\u011Flay\u0131c\u0131 bo\u015F yan\u0131t d\xF6nd\xFC");
4992
+ return text;
4993
+ }
4533
4994
  var MIME = {
4534
4995
  ".html": "text/html; charset=utf-8",
4535
4996
  ".js": "text/javascript",
@@ -4553,6 +5014,71 @@ async function createServer(root2) {
4553
5014
  if (msg.startsWith("G\xFCvensiz") || msg.startsWith("Yol")) return c.json({ error: msg }, 400);
4554
5015
  return c.json({ error: "sunucu hatas\u0131" }, 500);
4555
5016
  });
5017
+ app.get(
5018
+ "/api/_project",
5019
+ (c) => c.json({
5020
+ name: basename(root2) || "proje",
5021
+ path: root2,
5022
+ contentDir,
5023
+ collections: schema.collections.length,
5024
+ singletons: schema.singletons.length
5025
+ })
5026
+ );
5027
+ app.get("/api/_templates", (c) => c.json({ items: templateList() }));
5028
+ app.post("/api/_init", async (c) => {
5029
+ const { template: id } = await c.req.json();
5030
+ const t = id ? getTemplate(id) : void 0;
5031
+ if (!t) return c.json({ error: "Bilinmeyen template" }, 404);
5032
+ if (schema.collections.length > 0 || schema.singletons.length > 0) {
5033
+ return c.json({ error: "Bu klas\xF6rde zaten bir \u015Fema var." }, 400);
5034
+ }
5035
+ schema = await applyTemplate(adapter, contentDir, t);
5036
+ store = new ContentStore(adapter, schema, contentDir);
5037
+ return c.json({ ok: true });
5038
+ });
5039
+ app.post("/api/_import", async (c) => {
5040
+ if (schema.collections.length > 0 || schema.singletons.length > 0) {
5041
+ return c.json({ error: "Bu klas\xF6rde zaten bir \u015Fema var." }, 400);
5042
+ }
5043
+ const { raw } = await c.req.json();
5044
+ let next;
5045
+ let entries = {};
5046
+ let singletonData = {};
5047
+ try {
5048
+ next = parseSchema(raw);
5049
+ } catch {
5050
+ try {
5051
+ const inferred = inferProject(raw);
5052
+ next = parseSchema(inferred.schema);
5053
+ entries = inferred.entries;
5054
+ singletonData = inferred.singletons;
5055
+ } catch (e) {
5056
+ return c.json({ error: `\u0130\xE7e aktar\u0131lamad\u0131: ${e.message}` }, 400);
5057
+ }
5058
+ }
5059
+ await saveSchema(adapter, next, contentDir);
5060
+ schema = next;
5061
+ store = new ContentStore(adapter, schema, contentDir);
5062
+ for (const [collection, rows] of Object.entries(entries)) {
5063
+ for (const row of rows) {
5064
+ const slug = slugify(String(row.slug ?? row.title ?? "icerik")) || "icerik";
5065
+ await store.writeEntry(collection, slug, row);
5066
+ }
5067
+ }
5068
+ for (const [name, data] of Object.entries(singletonData)) {
5069
+ await store.writeSingleton(name, data);
5070
+ }
5071
+ return c.json({ ok: true });
5072
+ });
5073
+ app.get("/api/_export", async (c) => {
5074
+ const zipped = await collectExportZip(adapter, contentDir);
5075
+ return new Response(zipped, {
5076
+ headers: {
5077
+ "content-type": "application/zip",
5078
+ "content-disposition": 'attachment; filename="justjson-export.zip"'
5079
+ }
5080
+ });
5081
+ });
4556
5082
  app.get("/api/_schema", (c) => c.json(schema));
4557
5083
  app.put("/api/_schema", async (c) => {
4558
5084
  let next;
@@ -4586,6 +5112,39 @@ async function createServer(root2) {
4586
5112
  await writeFile3(abs, Buffer.from(body.dataBase64, "base64"));
4587
5113
  return c.json({ path: rel });
4588
5114
  });
5115
+ app.post("/api/_ai/models", async (c) => {
5116
+ const body = await c.req.json();
5117
+ const { provider, apiKey } = body;
5118
+ if (!provider) return c.json({ error: "provider zorunlu" }, 400);
5119
+ try {
5120
+ const models = provider === "gemini" ? await listGeminiModels(apiKey ?? "") : await listOpenAiCompatibleModels(
5121
+ body.baseUrl || PROVIDER_BASE_URLS[provider] || "",
5122
+ apiKey ?? ""
5123
+ );
5124
+ return c.json({ models });
5125
+ } catch (e) {
5126
+ return c.json({ error: e.message }, 502);
5127
+ }
5128
+ });
5129
+ app.post("/api/_ai/generate", async (c) => {
5130
+ const body = await c.req.json();
5131
+ const { provider, apiKey, model, system, prompt } = body;
5132
+ if (!provider || !apiKey || !model || !prompt) {
5133
+ return c.json({ error: "provider, model, apiKey ve prompt zorunlu" }, 400);
5134
+ }
5135
+ try {
5136
+ const text = provider === "gemini" ? await callGemini(apiKey, model, system, prompt) : await callOpenAiCompatible(
5137
+ body.baseUrl || PROVIDER_BASE_URLS[provider] || "",
5138
+ apiKey,
5139
+ model,
5140
+ system,
5141
+ prompt
5142
+ );
5143
+ return c.json({ text });
5144
+ } catch (e) {
5145
+ return c.json({ error: e.message }, 502);
5146
+ }
5147
+ });
4589
5148
  app.get("/media/:file", async (c) => {
4590
5149
  const file = c.req.param("file");
4591
5150
  if (file.includes("/") || file.includes("\\") || file.includes("..")) {