@njinlabs/njin 0.8.0 → 0.9.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@njinlabs/njin",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "A modern framework for building company profiles, landing pages, and content-driven websites.",
5
5
  "type": "module",
6
6
  "keywords": ["bun", "elysia", "surrealdb", "edgejs", "cms", "framework"],
@@ -13,21 +13,37 @@ import logger from "./logger";
13
13
  // without any per-route setup.
14
14
  const BRACKET_KEY_RE = /^([^[\]]+)\[([^\]]+)\](?:\[([^\]]+)\])?$/;
15
15
 
16
- export const injectBracketQuery = ({ query, request }: { query: Record<string, unknown>; request: Request }) => {
16
+ export const injectBracketQuery = ({
17
+ query,
18
+ request,
19
+ }: {
20
+ query: Record<string, unknown>;
21
+ request: Request;
22
+ }) => {
17
23
  const params = new URL(request.url).searchParams;
18
24
 
19
25
  for (const [key, value] of params) {
20
26
  const match = BRACKET_KEY_RE.exec(key);
21
27
  if (!match) continue;
22
28
 
23
- const [, root, sub1, sub2] = match as unknown as [string, string, string, string | undefined];
29
+ const [, root, sub1, sub2] = match as unknown as [
30
+ string,
31
+ string,
32
+ string,
33
+ string | undefined,
34
+ ];
24
35
  const existingRoot = query[root];
25
- const rootObj = typeof existingRoot === "object" && existingRoot !== null ? (existingRoot as Record<string, unknown>) : {};
36
+ const rootObj =
37
+ typeof existingRoot === "object" && existingRoot !== null
38
+ ? (existingRoot as Record<string, unknown>)
39
+ : {};
26
40
 
27
41
  if (sub2) {
28
42
  const existingSub = rootObj[sub1];
29
43
  rootObj[sub1] = {
30
- ...(typeof existingSub === "object" && existingSub !== null ? (existingSub as Record<string, unknown>) : {}),
44
+ ...(typeof existingSub === "object" && existingSub !== null
45
+ ? (existingSub as Record<string, unknown>)
46
+ : {}),
31
47
  [sub2]: value,
32
48
  };
33
49
  } else {
@@ -47,29 +63,35 @@ const elysia = makeModule(() => {
47
63
 
48
64
  fn.init = () => {
49
65
  app = new Elysia()
50
- .use(cors())
66
+ .use(
67
+ cors({
68
+ origin: () => true,
69
+ }),
70
+ )
51
71
  .onTransform({ as: "global" }, injectBracketQuery)
52
72
  .onError(({ error }) => {
53
- if (error instanceof ValidationError) {
54
- return status(422, {
55
- message: "Validation error",
56
- errors: (error.detail("") as { errors: { value: {}; summary: string }[] }).errors.map(({ value, summary, ...err }) => err),
57
- });
58
- }
73
+ if (error instanceof ValidationError) {
74
+ return status(422, {
75
+ message: "Validation error",
76
+ errors: (
77
+ error.detail("") as { errors: { value: {}; summary: string }[] }
78
+ ).errors.map(({ value, summary, ...err }) => err),
79
+ });
80
+ }
59
81
 
60
- if (error instanceof UniqueConstraintError) {
61
- return status(409, {
62
- message: error.message,
63
- field: error.field,
64
- });
65
- }
82
+ if (error instanceof UniqueConstraintError) {
83
+ return status(409, {
84
+ message: error.message,
85
+ field: error.field,
86
+ });
87
+ }
66
88
 
67
- logger().error(error);
89
+ logger().error(error);
68
90
 
69
- return status(500, {
70
- message: "Internal Server Error",
91
+ return status(500, {
92
+ message: "Internal Server Error",
93
+ });
71
94
  });
72
- });
73
95
 
74
96
  return {
75
97
  // No startup log here — the CLI prints one consolidated banner after every