bonescript-compiler 0.5.8 → 0.6.1

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 (56) hide show
  1. package/dist/ast.d.ts +2 -0
  2. package/dist/cli.js +52 -8
  3. package/dist/cli.js.map +1 -1
  4. package/dist/emit_admin.d.ts +5 -0
  5. package/dist/emit_admin.js +340 -35
  6. package/dist/emit_admin.js.map +1 -1
  7. package/dist/emit_audit.js +38 -4
  8. package/dist/emit_audit.js.map +1 -1
  9. package/dist/emit_capability.js +14 -0
  10. package/dist/emit_capability.js.map +1 -1
  11. package/dist/emit_full.js +10 -2
  12. package/dist/emit_full.js.map +1 -1
  13. package/dist/emit_maintenance.js +35 -3
  14. package/dist/emit_maintenance.js.map +1 -1
  15. package/dist/emit_nakama.js +36 -36
  16. package/dist/emit_notify.js +30 -2
  17. package/dist/emit_notify.js.map +1 -1
  18. package/dist/emit_runtime.d.ts +18 -1
  19. package/dist/emit_runtime.js +265 -85
  20. package/dist/emit_runtime.js.map +1 -1
  21. package/dist/emit_websocket.js +22 -2
  22. package/dist/emit_websocket.js.map +1 -1
  23. package/dist/emit_zod.js +12 -1
  24. package/dist/emit_zod.js.map +1 -1
  25. package/dist/formatter.d.ts +1 -0
  26. package/dist/formatter.js +10 -2
  27. package/dist/formatter.js.map +1 -1
  28. package/dist/ir.d.ts +2 -0
  29. package/dist/lexer.d.ts +1 -0
  30. package/dist/lexer.js +4 -0
  31. package/dist/lexer.js.map +1 -1
  32. package/dist/lowering.js +2 -0
  33. package/dist/lowering.js.map +1 -1
  34. package/dist/parse_decls.js +36 -1
  35. package/dist/parse_decls.js.map +1 -1
  36. package/dist/typechecker.js +9 -0
  37. package/dist/typechecker.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/ast.ts +2 -0
  40. package/src/cli.ts +58 -10
  41. package/src/emit_admin.ts +342 -35
  42. package/src/emit_audit.ts +40 -4
  43. package/src/emit_capability.ts +13 -0
  44. package/src/emit_full.ts +9 -2
  45. package/src/emit_maintenance.ts +35 -3
  46. package/src/emit_nakama.ts +576 -576
  47. package/src/emit_notify.ts +30 -2
  48. package/src/emit_runtime.ts +955 -763
  49. package/src/emit_websocket.ts +22 -2
  50. package/src/emit_zod.ts +11 -1
  51. package/src/formatter.ts +9 -2
  52. package/src/ir.ts +2 -0
  53. package/src/lexer.ts +2 -0
  54. package/src/lowering.ts +5 -3
  55. package/src/parse_decls.ts +31 -1
  56. package/src/typechecker.ts +10 -0
@@ -220,9 +220,29 @@ export function emitHealthChecks(system: IR.IRSystem): string {
220
220
  lines.push(`});`);
221
221
  lines.push(``);
222
222
 
223
- // Metrics endpoint
224
- lines.push(`// Prometheus-style metrics`);
225
- lines.push(`healthRouter.get("/metrics", (_req: Request, res: Response) => {`);
223
+ // Metrics endpoint — restricted to internal callers.
224
+ // Accepted: shared bearer in METRICS_TOKEN, or loopback / RFC1918 source IPs.
225
+ // External scrapers must inject the bearer; otherwise 403.
226
+ lines.push(`// Prometheus-style metrics — restricted to internal callers`);
227
+ lines.push(`function isInternalMetricsRequest(req: Request): boolean {`);
228
+ lines.push(` const expected = process.env.METRICS_TOKEN || "";`);
229
+ lines.push(` if (expected) {`);
230
+ lines.push(` const header = req.headers.authorization || "";`);
231
+ lines.push(` if (header.startsWith("Bearer ") && header.slice(7) === expected) return true;`);
232
+ lines.push(` }`);
233
+ lines.push(` const ip = (req.ip || "").replace(/^::ffff:/, "");`);
234
+ lines.push(` if (ip === "127.0.0.1" || ip === "::1") return true;`);
235
+ lines.push(` if (ip.startsWith("10.") || ip.startsWith("192.168.")) return true;`);
236
+ lines.push(` // RFC1918 172.16.0.0/12`);
237
+ lines.push(` const m = ip.match(/^172\\.(\\d{1,3})\\./);`);
238
+ lines.push(` if (m && +m[1] >= 16 && +m[1] <= 31) return true;`);
239
+ lines.push(` return false;`);
240
+ lines.push(`}`);
241
+ lines.push(`healthRouter.get("/metrics", (req: Request, res: Response) => {`);
242
+ lines.push(` if (!isInternalMetricsRequest(req)) {`);
243
+ lines.push(` res.status(403).json({ error: { code: "FORBIDDEN", message: "Metrics restricted to internal callers" } });`);
244
+ lines.push(` return;`);
245
+ lines.push(` }`);
226
246
  lines.push(` res.type("text/plain").send(dumpMetrics());`);
227
247
  lines.push(`});`);
228
248
  lines.push(``);
@@ -356,6 +376,7 @@ interface Field {
356
376
  name: string;
357
377
  type: string;
358
378
  nullable: boolean;
379
+ renamed_from?: string | null;
359
380
  }
360
381
 
361
382
  interface Model {
@@ -395,8 +416,18 @@ export function diffModels(oldModels: Model[], newModels: Model[]): string[] {
395
416
  const oldFields = new Map(oldModel.fields.map(f => [f.name, f]));
396
417
  const newFields = new Map(newModel.fields.map(f => [f.name, f]));
397
418
 
419
+ // Renames first — avoid double-counting as add+drop.
420
+ const renamedOld = new Set<string>();
421
+ for (const [fname, field] of newFields) {
422
+ if (field.renamed_from && oldFields.has(field.renamed_from) && !oldFields.has(fname)) {
423
+ statements.push(\`ALTER TABLE \${tableName} RENAME COLUMN \${field.renamed_from} TO \${fname};\`);
424
+ renamedOld.add(field.renamed_from);
425
+ }
426
+ }
427
+
398
428
  // New columns (backward-compatible)
399
429
  for (const [fname, field] of newFields) {
430
+ if (field.renamed_from && renamedOld.has(field.renamed_from)) continue;
400
431
  if (!oldFields.has(fname)) {
401
432
  const sqlType = mapType(field.type);
402
433
  const nullability = field.nullable ? "" : " NOT NULL DEFAULT (CASE WHEN false THEN NULL ELSE NULL END)";
@@ -406,6 +437,7 @@ export function diffModels(oldModels: Model[], newModels: Model[]): string[] {
406
437
 
407
438
  // Removed columns (NOT auto-dropped — backward compat)
408
439
  for (const [fname] of oldFields) {
440
+ if (renamedOld.has(fname)) continue;
409
441
  if (!newFields.has(fname)) {
410
442
  statements.push(\`-- WARNING: Column \${tableName}.\${fname} removed from schema. Run manually: ALTER TABLE \${tableName} DROP COLUMN \${fname};\`);
411
443
  }