princejs 1.8.4 → 1.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/Readme.md +61 -21
- package/dist/adapters/cloudflare.d.ts +40 -0
- package/dist/adapters/cloudflare.d.ts.map +1 -0
- package/dist/adapters/cloudflare.js +11 -0
- package/dist/adapters/deno.d.ts +26 -0
- package/dist/adapters/deno.d.ts.map +1 -0
- package/dist/adapters/deno.js +7 -0
- package/dist/adapters/vercel.d.ts +27 -0
- package/dist/adapters/vercel.d.ts.map +1 -0
- package/dist/adapters/vercel.js +7 -0
- package/dist/jsx.d.ts +6 -6
- package/dist/jsx.d.ts.map +1 -1
- package/dist/jsx.js +25 -16
- package/package.json +14 -2
package/Readme.md
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
14
|
## 🚀 Quick Start
|
|
15
|
-
|
|
16
15
|
```bash
|
|
17
16
|
bun create princejs my-app
|
|
18
17
|
cd my-app
|
|
@@ -83,6 +82,48 @@ app
|
|
|
83
82
|
|
|
84
83
|
---
|
|
85
84
|
|
|
85
|
+
## Deploy (Vercel, Workers, Deno)
|
|
86
|
+
|
|
87
|
+
Official adapters let you run the same Prince app on Vercel Edge, Cloudflare Workers, and Deno Deploy.
|
|
88
|
+
|
|
89
|
+
**Vercel (Edge)** — `api/[[...route]].ts`:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { prince } from "princejs";
|
|
93
|
+
import { toVercel } from "princejs/vercel";
|
|
94
|
+
|
|
95
|
+
const app = prince();
|
|
96
|
+
app.get("/", () => ({ message: "Hello from Vercel!" }));
|
|
97
|
+
|
|
98
|
+
export default toVercel(app);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Cloudflare Workers** — `src/index.ts`:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { prince } from "princejs";
|
|
105
|
+
import { toWorkers } from "princejs/cloudflare";
|
|
106
|
+
|
|
107
|
+
const app = prince();
|
|
108
|
+
app.get("/", () => ({ message: "Hello from Workers!" }));
|
|
109
|
+
|
|
110
|
+
export default toWorkers(app);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Deno Deploy** — `main.ts`:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { prince } from "princejs";
|
|
117
|
+
import { toDeno } from "princejs/deno";
|
|
118
|
+
|
|
119
|
+
const app = prince();
|
|
120
|
+
app.get("/", () => ({ message: "Hello from Deno!" }));
|
|
121
|
+
|
|
122
|
+
Deno.serve(toDeno(app));
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
86
127
|
## Performance With Oha (oha -c 100 -z 30s)
|
|
87
128
|
|
|
88
129
|
| Framework | Req/s | Total |
|
|
@@ -122,26 +163,25 @@ app.use(jwt(key));
|
|
|
122
163
|
app.use(session({ secret: "key" }));
|
|
123
164
|
app.use(compress());
|
|
124
165
|
|
|
125
|
-
const Page = () => (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
})
|
|
166
|
+
const Page = () => Html(
|
|
167
|
+
Head("Test Page"),
|
|
168
|
+
Body(
|
|
169
|
+
H1("Hello World"),
|
|
170
|
+
P("This is a test")
|
|
171
|
+
)
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
// With props (optional)
|
|
175
|
+
const Card = (props: any) => Div(
|
|
176
|
+
{ className: "card", style: "padding: 1rem;" },
|
|
177
|
+
H1(props.title),
|
|
178
|
+
P(props.content)
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
// Without props
|
|
182
|
+
const Simple = () => Div(
|
|
183
|
+
H1("No Props Needed"),
|
|
184
|
+
P("Just pure content")
|
|
145
185
|
);
|
|
146
186
|
|
|
147
187
|
const requireAuth = async (req: any, next: any) => {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official Cloudflare Workers deploy adapter for PrinceJS
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* // src/index.ts (Worker entry)
|
|
6
|
+
* import { prince } from "princejs";
|
|
7
|
+
* import { toWorkers } from "princejs/cloudflare";
|
|
8
|
+
*
|
|
9
|
+
* const app = prince();
|
|
10
|
+
* app.get("/", () => ({ message: "Hello from Workers!" }));
|
|
11
|
+
*
|
|
12
|
+
* export default toWorkers(app);
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // wrangler.toml
|
|
16
|
+
* // [build]
|
|
17
|
+
* // command = "bun run build"
|
|
18
|
+
* // [build.upload]
|
|
19
|
+
* // format = "modules"
|
|
20
|
+
* // main = "dist/worker.js"
|
|
21
|
+
*/
|
|
22
|
+
export type PrinceApp = {
|
|
23
|
+
fetch(request: Request): Promise<Response>;
|
|
24
|
+
};
|
|
25
|
+
export interface WorkerEnv {
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** Cloudflare Workers ExecutionContext (pass-through, no Bun dependency) */
|
|
29
|
+
export interface ExecutionContext {
|
|
30
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
31
|
+
passThroughOnException(): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns a Cloudflare Workers fetch handler for your Prince app.
|
|
35
|
+
* Use as the default export of your Worker.
|
|
36
|
+
*/
|
|
37
|
+
export declare function toWorkers(app: PrinceApp): {
|
|
38
|
+
fetch(request: Request, env: WorkerEnv, ctx: ExecutionContext): Promise<Response>;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=cloudflare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../src/adapters/cloudflare.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAAE,CAAC;AAEvE,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAC3C,sBAAsB,IAAI,IAAI,CAAC;CAChC;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG;IACzC,KAAK,CACH,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,SAAS,EACd,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtB,CAMA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official Deno Deploy adapter for PrinceJS
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* // main.ts
|
|
6
|
+
* import { prince } from "princejs";
|
|
7
|
+
* import { toDeno } from "princejs/deno";
|
|
8
|
+
*
|
|
9
|
+
* const app = prince();
|
|
10
|
+
* app.get("/", () => ({ message: "Hello from Deno Deploy!" }));
|
|
11
|
+
*
|
|
12
|
+
* Deno.serve(toDeno(app));
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // With options (port, hostname, etc.)
|
|
16
|
+
* Deno.serve({ port: 8080 }, toDeno(app));
|
|
17
|
+
*/
|
|
18
|
+
export type PrinceApp = {
|
|
19
|
+
fetch(request: Request): Promise<Response>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Returns a Deno.serve()-compatible fetch handler for your Prince app.
|
|
23
|
+
* Pass the result to Deno.serve() as the second argument (or first for default options).
|
|
24
|
+
*/
|
|
25
|
+
export declare function toDeno(app: PrinceApp): (request: Request) => Promise<Response>;
|
|
26
|
+
//# sourceMappingURL=deno.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deno.d.ts","sourceRoot":"","sources":["../../src/adapters/deno.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAAE,CAAC;AAEvE;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,SAAS,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAE9E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official Vercel deploy adapter for PrinceJS
|
|
3
|
+
* Use with Vercel Edge Runtime or Edge API Routes
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // api/[[...route]].ts (Edge Runtime)
|
|
7
|
+
* import { prince } from "princejs";
|
|
8
|
+
* import { toVercel } from "princejs/vercel";
|
|
9
|
+
*
|
|
10
|
+
* const app = prince();
|
|
11
|
+
* app.get("/", () => ({ message: "Hello from Vercel!" }));
|
|
12
|
+
*
|
|
13
|
+
* export default toVercel(app);
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // vercel.json - use Edge for API
|
|
17
|
+
* // { "functions": { "api/**": { "runtime": "edge" } } }
|
|
18
|
+
*/
|
|
19
|
+
export type PrinceApp = {
|
|
20
|
+
fetch(request: Request): Promise<Response>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Returns a Vercel Edge-compatible handler for your Prince app.
|
|
24
|
+
* Use as the default export of your API route.
|
|
25
|
+
*/
|
|
26
|
+
export declare function toVercel(app: PrinceApp): (req: Request) => Promise<Response>;
|
|
27
|
+
//# sourceMappingURL=vercel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercel.d.ts","sourceRoot":"","sources":["../../src/adapters/vercel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAAE,CAAC;AAEvE;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,SAAS,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAE5E"}
|
package/dist/jsx.d.ts
CHANGED
|
@@ -6,11 +6,11 @@ export declare const jsx: (tag: string | Function, props: JSXProps, ...children:
|
|
|
6
6
|
export declare const jsxs: (tag: string | Function, props: JSXProps, ...children: any[]) => any;
|
|
7
7
|
export declare const jsxDEV: (tag: string | Function, props: JSXProps, ...children: any[]) => any;
|
|
8
8
|
export declare const Fragment: (props: JSXProps) => any;
|
|
9
|
-
export declare const Html: (
|
|
10
|
-
export declare const Head: (
|
|
11
|
-
export declare const Body: (
|
|
12
|
-
export declare const H1: (
|
|
13
|
-
export declare const P: (
|
|
14
|
-
export declare const Div: (
|
|
9
|
+
export declare const Html: (...children: any[]) => string;
|
|
10
|
+
export declare const Head: (...children: any[]) => string;
|
|
11
|
+
export declare const Body: (...children: any[]) => string;
|
|
12
|
+
export declare const H1: (...children: any[]) => string;
|
|
13
|
+
export declare const P: (...children: any[]) => string;
|
|
14
|
+
export declare const Div: (...args: any[]) => string;
|
|
15
15
|
export declare const render: (jsxContent: any) => Response;
|
|
16
16
|
//# sourceMappingURL=jsx.d.ts.map
|
package/dist/jsx.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../src/jsx.ts"],"names":[],"mappings":"AACA,MAA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,GAAI,GAAG,UAAU,GAAG,EAAE,WAEtC,CAAC;AAEF,eAAO,MAAM,EAAE,GAAI,GAAG,UAAU,GAAG,EAAE,WAEpC,CAAC;AAEF,eAAO,MAAM,CAAC,GAAI,GAAG,UAAU,GAAG,EAAE,WAEnC,CAAC;AAEF,eAAO,MAAM,GAAG,GAAI,GAAG,MAAM,GAAG,EAAE,WAoBjC,CAAC;AAaF,eAAO,MAAM,MAAM,GAAI,YAAY,GAAG,aAKrC,CAAC"}
|
package/dist/jsx.js
CHANGED
|
@@ -11,28 +11,37 @@ var jsx = (tag, props, ...children) => {
|
|
|
11
11
|
var jsxs = jsx;
|
|
12
12
|
var jsxDEV = jsx;
|
|
13
13
|
var Fragment = (props) => props.children;
|
|
14
|
-
var Html = (
|
|
15
|
-
return `<html>${renderChildren(
|
|
14
|
+
var Html = (...children) => {
|
|
15
|
+
return `<html>${renderChildren(children)}</html>`;
|
|
16
16
|
};
|
|
17
|
-
var Head = (
|
|
18
|
-
return `<head>${renderChildren(
|
|
17
|
+
var Head = (...children) => {
|
|
18
|
+
return `<head>${renderChildren(children)}</head>`;
|
|
19
19
|
};
|
|
20
|
-
var Body = (
|
|
21
|
-
return `<body>${renderChildren(
|
|
20
|
+
var Body = (...children) => {
|
|
21
|
+
return `<body>${renderChildren(children)}</body>`;
|
|
22
22
|
};
|
|
23
|
-
var H1 = (
|
|
24
|
-
return `<h1>${renderChildren(
|
|
23
|
+
var H1 = (...children) => {
|
|
24
|
+
return `<h1>${renderChildren(children)}</h1>`;
|
|
25
25
|
};
|
|
26
|
-
var P = (
|
|
27
|
-
return `<p>${renderChildren(
|
|
26
|
+
var P = (...children) => {
|
|
27
|
+
return `<p>${renderChildren(children)}</p>`;
|
|
28
28
|
};
|
|
29
|
-
var Div = (
|
|
30
|
-
|
|
29
|
+
var Div = (...args) => {
|
|
30
|
+
let options = null;
|
|
31
|
+
let children = args;
|
|
32
|
+
if (args.length > 0 && isPlainObject(args[0])) {
|
|
33
|
+
options = args[0];
|
|
34
|
+
children = args.slice(1);
|
|
35
|
+
}
|
|
36
|
+
const attrs = options ? Object.keys(options).map((key) => {
|
|
31
37
|
if (key === "className")
|
|
32
|
-
return `class="${
|
|
33
|
-
return `${key}="${
|
|
34
|
-
}).join(" ");
|
|
35
|
-
return `<div
|
|
38
|
+
return `class="${options[key]}"`;
|
|
39
|
+
return `${key}="${options[key]}"`;
|
|
40
|
+
}).join(" ") : "";
|
|
41
|
+
return `<div${attrs ? " " + attrs : ""}>${renderChildren(children)}</div>`;
|
|
42
|
+
};
|
|
43
|
+
var isPlainObject = (obj) => {
|
|
44
|
+
return obj !== null && typeof obj === "object" && !Array.isArray(obj) && !(obj instanceof Date) && !(obj instanceof RegExp) && typeof obj !== "string";
|
|
36
45
|
};
|
|
37
46
|
var render = (jsxContent) => {
|
|
38
47
|
const html = typeof jsxContent === "string" ? jsxContent : String(jsxContent);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "princejs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "An easy and fast backend framework that is among the top three — by a 13yo developer, for developers.",
|
|
5
5
|
"main": "dist/prince.js",
|
|
6
6
|
"types": "dist/prince.d.ts",
|
|
@@ -32,6 +32,18 @@
|
|
|
32
32
|
"./db": {
|
|
33
33
|
"import": "./dist/db.js",
|
|
34
34
|
"types": "./dist/db.d.ts"
|
|
35
|
+
},
|
|
36
|
+
"./vercel": {
|
|
37
|
+
"import": "./dist/adapters/vercel.js",
|
|
38
|
+
"types": "./dist/adapters/vercel.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./cloudflare": {
|
|
41
|
+
"import": "./dist/adapters/cloudflare.js",
|
|
42
|
+
"types": "./dist/adapters/cloudflare.d.ts"
|
|
43
|
+
},
|
|
44
|
+
"./deno": {
|
|
45
|
+
"import": "./dist/adapters/deno.js",
|
|
46
|
+
"types": "./dist/adapters/deno.d.ts"
|
|
35
47
|
}
|
|
36
48
|
},
|
|
37
49
|
"files": [
|
|
@@ -95,7 +107,7 @@
|
|
|
95
107
|
"jose": "^6.1.2"
|
|
96
108
|
},
|
|
97
109
|
"scripts": {
|
|
98
|
-
"build:js": "bun build src/prince.ts --outdir dist --target bun && bun build src/middleware.ts --outdir dist --target bun && bun build src/helpers.ts --outdir dist --target bun && bun build src/scheduler.ts --outdir dist --target bun && bun build bin/create.ts --outdir dist --target bun && bun build src/jsx.ts --outdir dist --target bun && bun build src/db.ts --outdir dist --target bun --format esm",
|
|
110
|
+
"build:js": "bun build src/prince.ts --outdir dist --target bun && bun build src/middleware.ts --outdir dist --target bun && bun build src/helpers.ts --outdir dist --target bun && bun build src/scheduler.ts --outdir dist --target bun && bun build bin/create.ts --outdir dist --target bun && bun build src/jsx.ts --outdir dist --target bun && bun build src/db.ts --outdir dist --target bun --format esm && bun build src/adapters/vercel.ts --outdir dist/adapters --format esm && bun build src/adapters/cloudflare.ts --outdir dist/adapters --format esm && bun build src/adapters/deno.ts --outdir dist/adapters --format esm",
|
|
99
111
|
"build:types": "tsc --emitDeclarationOnly --skipLibCheck",
|
|
100
112
|
"build": "bun run build:js && bun run build:types",
|
|
101
113
|
"test": "bun test",
|