spooder 5.1.2 → 5.1.4

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 (3) hide show
  1. package/README.md +29 -4
  2. package/package.json +1 -1
  3. package/src/api.ts +7 -4
package/README.md CHANGED
@@ -474,8 +474,8 @@ In addition to the information provided by the developer, `spooder` also include
474
474
 
475
475
  ```ts
476
476
  // logging
477
- log(message: string);
478
- log_error(message: string);
477
+ log(message: string, ...params: any[]);
478
+ log_error(message: string, ...params: any[]);
479
479
  log_create_logger(prefix: string, color: ColorInput);
480
480
  log_list(input: any[], delimiter = ', ');
481
481
 
@@ -595,7 +595,7 @@ HTTP_STATUS_CODE: { OK_200: 200, NotFound_404: 404, ... };
595
595
  <a id="api-logging"></a>
596
596
  ## API > Logging
597
597
 
598
- ### 🔧 `log(message: string)`
598
+ ### 🔧 `log(message: string, ...params: any[])`
599
599
  Print a message to the console using the default logger. Wrapping text segments in curly braces will highlight those segments with colour.
600
600
 
601
601
  ```ts
@@ -603,7 +603,24 @@ log('Hello, {world}!');
603
603
  // > [info] Hello, world!
604
604
  ```
605
605
 
606
- ### 🔧 `log_error(message: string)`
606
+ Formatting parameters are supported using standard console logging formatters.
607
+
608
+ ```ts
609
+ log('My object: %o', { foo: 'bar' });
610
+ // > [info] My object: { foo: 'bar' }
611
+ ```
612
+
613
+ | Specifier | Description |
614
+ |-----------|-------------|
615
+ | `%s` | String |
616
+ | `%d` | Integer |
617
+ | `%i` | Integer (same as %d) |
618
+ | `%f` | Floating point |
619
+ | `%o` | Object (pretty-printed) |
620
+ | `%O` | Object (expanded/detailed) |
621
+ | `%j` | JSON string |
622
+
623
+ ### 🔧 `log_error(message: string, ...params: any[])`
607
624
  Print an error message to the console. Wrapping text segments in curly braces will highlight those segments. This works the same as `log()` except it's red, so you know it's bad.
608
625
 
609
626
  ```ts
@@ -1300,6 +1317,7 @@ const server = http_serve(80);
1300
1317
 
1301
1318
  server.bootstrap({
1302
1319
  base: Bun.file('./html/base_template.html'),
1320
+ drop_missing_subs: false,
1303
1321
 
1304
1322
  cache: {
1305
1323
  ttl: 5 * 60 * 60 * 1000, // 5 minutes
@@ -1384,6 +1402,13 @@ server.bootstrap({
1384
1402
  });
1385
1403
  ```
1386
1404
 
1405
+ ##### `drop_missing_subs: boolean`
1406
+
1407
+ **Optional**. Defaults to true. If explicitly disabled, templating parsing will not drop unknown substitutions.
1408
+
1409
+ > ![NOTE]
1410
+ > If you are using a client-side framework that uses the double-brace syntax ``{{foo}}`` such as Vue, you should set this to `false` to ensure compatibility.
1411
+
1387
1412
  ##### `routes: Record<string, BootstrapRoute>`
1388
1413
  **Required.** Defines the routes and their content. Each route can have:
1389
1414
  - `content`: The page content (string or BunFile)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "spooder",
3
3
  "type": "module",
4
- "version": "5.1.2",
4
+ "version": "5.1.4",
5
5
  "module": "./src/api.ts",
6
6
  "bin": {
7
7
  "spooder": "./src/cli.ts"
package/src/api.ts CHANGED
@@ -106,8 +106,8 @@ export function log_create_logger(label: string, color: ColorInput = 'blue') {
106
106
  const ansi = Bun.color(color, 'ansi-256') ?? '\x1b[38;5;6m';
107
107
  const prefix = `[${ansi}${label}\x1b[0m] `;
108
108
 
109
- return (message: string) => {
110
- process.stdout.write(prefix + message.replace(/\{([^}]+)\}/g, `${ansi}$1\x1b[0m`) + '\n');
109
+ return (message: string, ...params: any[]) => {
110
+ console.log(prefix + message.replace(/\{([^}]+)\}/g, `${ansi}$1\x1b[0m`), ...params);
111
111
  };
112
112
  }
113
113
 
@@ -366,7 +366,7 @@ async function handle_error(prefix: string, err_message_or_obj: string | object,
366
366
  if (process.env.SPOODER_ENV === 'dev') {
367
367
  log_spooder(`[{dev}] dispatch_report ${prefix + error_message}`);
368
368
  log_spooder('[{dev}] without {--dev}, this would raise a canary report');
369
- log_spooder(`[{dev}] ${final_err}`);
369
+ log_spooder('[{dev}] %O', final_err);
370
370
  } else {
371
371
  await dispatch_report(prefix + error_message, final_err);
372
372
  }
@@ -1077,6 +1077,8 @@ type BootstrapCacheBust = {
1077
1077
 
1078
1078
  type BootstrapOptions = {
1079
1079
  base?: string | BunFile;
1080
+ drop_missing_subs?: boolean;
1081
+
1080
1082
  routes: Record<string, BootstrapRoute>;
1081
1083
  cache?: ReturnType<typeof cache_http> | CacheOptions;
1082
1084
 
@@ -1522,6 +1524,7 @@ export function http_serve(port: number, hostname?: string) {
1522
1524
  if (cache !== undefined && !is_cache_http(cache))
1523
1525
  cache = cache_http(cache);
1524
1526
 
1527
+ const drop_missing = options.drop_missing_subs ?? true;
1525
1528
  for (const [route, route_opts] of Object.entries(options.routes)) {
1526
1529
  const content_generator = async () => {
1527
1530
  let content = await resolve_bootstrap_content(route_opts.content);
@@ -1530,7 +1533,7 @@ export function http_serve(port: number, hostname?: string) {
1530
1533
  content = await parse_template(await resolve_bootstrap_content(options.base), { content }, false);
1531
1534
 
1532
1535
  const sub_table = sub_table_merge({}, global_sub_table, route_opts.subs);
1533
- content = await parse_template(content, sub_table, true);
1536
+ content = await parse_template(content, sub_table, drop_missing);
1534
1537
 
1535
1538
  return content;
1536
1539
  };