chiwaa 0.1.9 → 0.1.10

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 (2) hide show
  1. package/bin/chiwaa.js +23 -3
  2. package/package.json +1 -1
package/bin/chiwaa.js CHANGED
@@ -436,7 +436,21 @@ async function rollback(args) {
436
436
  // 데이터가 지워지는 일(끄기·표 지우기·글 지우기)은 일부러 없다 — chiwaa.kr 사이트 화면에서만 한다.
437
437
  const RULE_KO = { public: "누구나", owner: "나만(chiwaa.kr 화면)" };
438
438
 
439
- function snippet(table) {
439
+ // 쓰기 「나만」 표(주문·결제 등)는 방문자 폼 대신 서버 함수 예시를 준다 — 공개 폼을 붙이거나 권한을 「누구나」로 바꾸면 안 된다
440
+ function ownerSnippet(table, read) {
441
+ return `<!-- 「${table}」 표는 쓰기가 「나만」이라 방문자 폼으로 저장하지 않습니다. 서버 함수(api/)에서 씁니다. -->
442
+ // api/${table}-add.js
443
+ export default async function (request, env) {
444
+ // 금액·상태처럼 방문자가 정하면 안 되는 값은 여기(서버)에서 정한다
445
+ const row = await env.DB.table("${table}").add({ status: "ready" });
446
+ return Response.json({ id: row.id });
447
+ }
448
+ // 고치기 env.DB.table("${table}").update(id, { status: "paid" }) · 읽기 .get(id) / .list({ where: { 칸: 값 } })
449
+ ${read === "owner" ? "// 읽기도 「나만」: 사이트에서는 못 읽고, 주인은 npx chiwaa db rows " + table + " 로 본다" : ""}`;
450
+ }
451
+
452
+ function snippet(table, read, write) {
453
+ if (write === "owner") return ownerSnippet(table, read);
440
454
  return `<!-- 글 보내기(저장) -->
441
455
  <script src="/_chiwaa/data/v1/chiwaa.js"></script>
442
456
  <form data-chiwaa-table="${table}" data-chiwaa-done="보냈습니다. 감사합니다.">
@@ -509,7 +523,7 @@ async function db(args) {
509
523
  if (r.status !== 201) fail(r.data.error || "표를 만들지 못했습니다.");
510
524
  console.log(c.green("✓"), `「${table}」 표를 만들었습니다. 읽기 ${RULE_KO[read]} · 쓰기 ${RULE_KO[write]}`);
511
525
  console.log(c.dim("\n사이트 HTML 에 아래를 넣고 다시 deploy 하면 됩니다. 저장된 글은 npx chiwaa db rows " + table + "\n"));
512
- return console.log(snippet(table));
526
+ return console.log(snippet(table, read, write));
513
527
  }
514
528
  if (sub === "rules") {
515
529
  needTable();
@@ -537,7 +551,13 @@ async function db(args) {
537
551
  if (items.length >= 20) console.log(c.dim(`다음 쪽: npx chiwaa db rows ${table} --page ${page + 1}`));
538
552
  return;
539
553
  }
540
- if (sub === "code") return console.log(snippet(needTable()));
554
+ if (sub === "code") {
555
+ needTable();
556
+ const r = await api("GET", base);
557
+ const t = ((r.data && r.data.tables) || []).find((x) => x.name === table);
558
+ if (!t) fail(`「${table}」 표가 없습니다. 목록: npx chiwaa db`);
559
+ return console.log(snippet(table, t.read_rule, t.write_rule));
560
+ }
541
561
  fail(`모르는 db 명령입니다: ${sub}\n 쓸 수 있는 것: status · on · create · rules · rows · code`);
542
562
  }
543
563
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chiwaa",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "chiwaa.kr 에 사이트를 터미널에서 바로 올리는 도구",
5
5
  "bin": {
6
6
  "chiwaa": "bin/chiwaa.js"