@arkstack/driver-h3 0.1.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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @arkstack/driver-h3
2
+
3
+ H3 driver package for Arkstack providing H3-specific implementations of core Arkstack features such as routing, middleware, and database integration.
@@ -0,0 +1,60 @@
1
+ import { ArkstackKitDriver, PromiseOrValue } from "@arkstack/contract";
2
+ import { H3 } from "h3";
3
+ import { Middleware } from "clear-router/types/h3";
4
+
5
+ //#region src/index.d.ts
6
+ type H3Middleware = Middleware | [Middleware, Record<string, any>];
7
+ interface H3DriverOptions {
8
+ bindRouter: (app: H3) => PromiseOrValue<void>;
9
+ mountPublicAssets: (app: H3, publicPath: string) => PromiseOrValue<void>;
10
+ createApp?: () => H3;
11
+ }
12
+ /**
13
+ * The H3Driver class implements the ArkstackKitDriver contract for the H3 framework.
14
+ */
15
+ declare class H3Driver extends ArkstackKitDriver<H3, H3Middleware> {
16
+ readonly name = "h3";
17
+ private readonly options;
18
+ /**
19
+ * Creates an instance of H3Driver.
20
+ *
21
+ * @param options
22
+ */
23
+ constructor(options: H3DriverOptions);
24
+ /**
25
+ * Creates an H3 application instance.
26
+ *
27
+ * @returns
28
+ */
29
+ createApp(): H3;
30
+ /**
31
+ * Mounts static assets from the specified public path to the H3 application.
32
+ *
33
+ * @param app
34
+ * @param publicPath
35
+ */
36
+ mountPublicAssets(app: H3, publicPath: string): PromiseOrValue<void>;
37
+ /**
38
+ * Binds the router to the H3 application using the provided bindRouter function.
39
+ *
40
+ * @param app
41
+ */
42
+ bindRouter(app: H3): PromiseOrValue<void>;
43
+ /**
44
+ * Applies middleware to the H3 application.
45
+ *
46
+ * @param app
47
+ * @param middleware
48
+ */
49
+ applyMiddleware(app: H3, middleware: H3Middleware): void;
50
+ /**
51
+ * Starts the H3 server on the specified port.
52
+ *
53
+ * @param app
54
+ * @param port
55
+ */
56
+ start(app: H3, port: number): void;
57
+ }
58
+ //#endregion
59
+ export { H3Driver, H3DriverOptions, H3Middleware };
60
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,67 @@
1
+ import { ArkstackKitDriver } from "@arkstack/contract";
2
+ import { H3, serve } from "h3";
3
+
4
+ //#region src/index.ts
5
+ /**
6
+ * The H3Driver class implements the ArkstackKitDriver contract for the H3 framework.
7
+ */
8
+ var H3Driver = class extends ArkstackKitDriver {
9
+ name = "h3";
10
+ options;
11
+ /**
12
+ * Creates an instance of H3Driver.
13
+ *
14
+ * @param options
15
+ */
16
+ constructor(options) {
17
+ super();
18
+ this.options = options;
19
+ }
20
+ /**
21
+ * Creates an H3 application instance.
22
+ *
23
+ * @returns
24
+ */
25
+ createApp() {
26
+ return this.options.createApp?.() ?? new H3();
27
+ }
28
+ /**
29
+ * Mounts static assets from the specified public path to the H3 application.
30
+ *
31
+ * @param app
32
+ * @param publicPath
33
+ */
34
+ mountPublicAssets(app, publicPath) {
35
+ return this.options.mountPublicAssets(app, publicPath);
36
+ }
37
+ /**
38
+ * Binds the router to the H3 application using the provided bindRouter function.
39
+ *
40
+ * @param app
41
+ */
42
+ bindRouter(app) {
43
+ return this.options.bindRouter(app);
44
+ }
45
+ /**
46
+ * Applies middleware to the H3 application.
47
+ *
48
+ * @param app
49
+ * @param middleware
50
+ */
51
+ applyMiddleware(app, middleware) {
52
+ app.use(Array.isArray(middleware) ? middleware[0] : middleware, Array.isArray(middleware) ? middleware[1] : void 0);
53
+ }
54
+ /**
55
+ * Starts the H3 server on the specified port.
56
+ *
57
+ * @param app
58
+ * @param port
59
+ */
60
+ start(app, port) {
61
+ serve(app, { port });
62
+ }
63
+ };
64
+
65
+ //#endregion
66
+ export { H3Driver };
67
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { ArkstackKitDriver, PromiseOrValue } from \"@arkstack/contract\";\nimport { H3, serve } from \"h3\";\n\nimport { Middleware as H3BaseMiddleware } from \"clear-router/types/h3\";\n\n// oxlint-disable-next-line typescript/no-explicit-any\nexport type H3Middleware = H3BaseMiddleware | [H3BaseMiddleware, Record<string, any>];\n\nexport interface H3DriverOptions {\n bindRouter: (app: H3) => PromiseOrValue<void>;\n mountPublicAssets: (app: H3, publicPath: string) => PromiseOrValue<void>;\n createApp?: () => H3;\n}\n\n/**\n * The H3Driver class implements the ArkstackKitDriver contract for the H3 framework.\n */\nexport class H3Driver extends ArkstackKitDriver<H3, H3Middleware> {\n readonly name = \"h3\";\n private readonly options: H3DriverOptions;\n\n /**\n * Creates an instance of H3Driver.\n * \n * @param options \n */\n constructor(options: H3DriverOptions) {\n super();\n this.options = options;\n }\n\n /**\n * Creates an H3 application instance.\n * \n * @returns \n */\n createApp (): H3 {\n return this.options.createApp?.() ?? new H3();\n }\n\n /**\n * Mounts static assets from the specified public path to the H3 application.\n * \n * @param app \n * @param publicPath \n */\n mountPublicAssets (app: H3, publicPath: string): PromiseOrValue<void> {\n return this.options.mountPublicAssets(app, publicPath);\n }\n\n /**\n * Binds the router to the H3 application using the provided bindRouter function.\n * \n * @param app \n */\n bindRouter (app: H3): PromiseOrValue<void> {\n return this.options.bindRouter(app);\n }\n\n /**\n * Applies middleware to the H3 application.\n * \n * @param app \n * @param middleware \n */\n applyMiddleware (app: H3, middleware: H3Middleware): void {\n app.use(\n Array.isArray(middleware) ? middleware[0] : middleware,\n Array.isArray(middleware) ? middleware[1] : undefined,\n );\n }\n\n /**\n * Starts the H3 server on the specified port.\n * \n * @param app \n * @param port \n */\n start (app: H3, port: number): void {\n serve(app, { port });\n }\n}\n"],"mappings":";;;;;;;AAiBA,IAAa,WAAb,cAA8B,kBAAoC;CAC9D,AAAS,OAAO;CAChB,AAAiB;;;;;;CAOjB,YAAY,SAA0B;AAClC,SAAO;AACP,OAAK,UAAU;;;;;;;CAQnB,YAAiB;AACb,SAAO,KAAK,QAAQ,aAAa,IAAI,IAAI,IAAI;;;;;;;;CASjD,kBAAmB,KAAS,YAA0C;AAClE,SAAO,KAAK,QAAQ,kBAAkB,KAAK,WAAW;;;;;;;CAQ1D,WAAY,KAA+B;AACvC,SAAO,KAAK,QAAQ,WAAW,IAAI;;;;;;;;CASvC,gBAAiB,KAAS,YAAgC;AACtD,MAAI,IACA,MAAM,QAAQ,WAAW,GAAG,WAAW,KAAK,YAC5C,MAAM,QAAQ,WAAW,GAAG,WAAW,KAAK,OAC/C;;;;;;;;CASL,MAAO,KAAS,MAAoB;AAChC,QAAM,KAAK,EAAE,MAAM,CAAC"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@arkstack/driver-h3",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "H3 driver package for Arkstack providing H3-specific implementations of core Arkstack features such as routing, middleware, and database integration.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/arkstack-hq/arkstack.git",
9
+ "directory": "packages/driver-h3"
10
+ },
11
+ "keywords": [
12
+ "h3",
13
+ "driver",
14
+ "integration",
15
+ "routing",
16
+ "middleware",
17
+ "database",
18
+ "arkstack",
19
+ "http",
20
+ "server",
21
+ "rest",
22
+ "api",
23
+ "framework"
24
+ ],
25
+ "files": [
26
+ "dist",
27
+ "stubs"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "exports": {
33
+ ".": "./dist/index.js",
34
+ "./package.json": "./package.json"
35
+ },
36
+ "dependencies": {
37
+ "@arkstack/contract": "^0.1.1"
38
+ },
39
+ "peerDependencies": {
40
+ "clear-router": "^2.1.6",
41
+ "h3": "2.0.1-rc.14"
42
+ },
43
+ "scripts": {
44
+ "build": "tsdown",
45
+ "version:patch": "pnpm version patch --no-git-tag-version"
46
+ }
47
+ }
@@ -0,0 +1,97 @@
1
+ import BaseController from '@controllers/BaseController'
2
+ import BaseController from '@controllers/BaseController'
3
+ import { HttpContext } from 'clear-router/types/h3'
4
+ import {{ResourceName}} from '@app/http/resources/{{ResourceName}}'
5
+ import {{CollectionResourceName}} from '@app/http/resources/{{CollectionResourceName}}'
6
+
7
+ import { Resource } from 'resora';
8
+
9
+ /**
10
+ * {{ControllerName}}
11
+ */
12
+ export default class extends BaseController {
13
+ /**
14
+ * Get all resources
15
+ *
16
+ * @param req
17
+ * @param res
18
+ */
19
+ index = async ({ res }: HttpContext) => {
20
+ return await new Resource( { data: [] })
21
+ .additional({
22
+ status: 'success',
23
+ message: 'OK',
24
+ code: 200,
25
+ })
26
+ .response(res)
27
+ .setStatusCode(200);
28
+ }
29
+
30
+ /**
31
+ * Get a specific resource
32
+ *
33
+ * @param req
34
+ * @param res
35
+ */
36
+ show = async ({ res }: HttpContext) => {
37
+ return await new Resource({ data: {} })
38
+ .additional({
39
+ status: 'success',
40
+ message: 'OK',
41
+ code: 200,
42
+ })
43
+ .response(res)
44
+ .setStatusCode(200);
45
+ }
46
+
47
+ /**
48
+ * Create a resource
49
+ *
50
+ * @param req
51
+ * @param res
52
+ */
53
+ create = async ({ res }: HttpContext) => {
54
+ return await new Resource({ data: {} })
55
+ .additional({
56
+ status: 'success',
57
+ message: 'New {{Name}} created successfully',
58
+ code: 201,
59
+ })
60
+ .response(res)
61
+ .setStatusCode(201);
62
+ }
63
+
64
+ /**
65
+ * Update a specific resource
66
+ *
67
+ * @param req
68
+ * @param res
69
+ */
70
+ update = async ({ res }: HttpContext) => {
71
+ return await new Resource({ data: {} })
72
+ .additional({
73
+ status: 'success',
74
+ message: '{{Name}} updated successfully',
75
+ code: 202,
76
+ })
77
+ .response(res)
78
+ .setStatusCode(202);
79
+ }
80
+
81
+ /**
82
+ * Delete a specific resource
83
+ *
84
+ * @param req
85
+ * @param res
86
+ */
87
+ destroy = async ({ res }: HttpContext) => {
88
+ return await new Resource({ data: {} })
89
+ .additional({
90
+ status: 'success',
91
+ message: '{{Name}} deleted successfully',
92
+ code: 202,
93
+ })
94
+ .response(res)
95
+ .setStatusCode(202);
96
+ }
97
+ }
@@ -0,0 +1,94 @@
1
+ import BaseController from '@controllers/BaseController';
2
+ import { HttpContext } from 'clear-router/types/h3'
3
+
4
+ import { Resource } from 'resora';
5
+
6
+ /**
7
+ * {{ControllerName}}
8
+ */
9
+ export default class extends BaseController {
10
+ /**
11
+ * Get all resources
12
+ *
13
+ * @param req
14
+ * @param res
15
+ */
16
+ index = async ({ res }: HttpContext) => {
17
+ return await new Resource({ data: [] })
18
+ .additional({
19
+ status: 'success',
20
+ message: 'OK',
21
+ code: 200,
22
+ })
23
+ .response(res)
24
+ .setStatusCode(200);
25
+ }
26
+
27
+ /**
28
+ * Get a specific resource
29
+ *
30
+ * @param req
31
+ * @param res
32
+ */
33
+ show = async ({ res }: HttpContext) => {
34
+ return await new Resource({ data: {} })
35
+ .additional({
36
+ status: 'success',
37
+ message: 'OK',
38
+ code: 200,
39
+ })
40
+ .response(res)
41
+ .setStatusCode(200);
42
+ }
43
+
44
+ /**
45
+ * Create a resource
46
+ *
47
+ * @param req
48
+ * @param res
49
+ */
50
+ create = async ({ res }: HttpContext) => {
51
+ return await new Resource({ data: {} })
52
+ .additional({
53
+ status: 'success',
54
+ message: 'New {{Name}} created successfully',
55
+ code: 201,
56
+ })
57
+ .response(res)
58
+ .setStatusCode(201);
59
+ }
60
+
61
+ /**
62
+ * Update a specific resource
63
+ *
64
+ * @param req
65
+ * @param res
66
+ */
67
+ update = async ({ res }: HttpContext) => {
68
+ return await new Resource({ data: {} })
69
+ .additional({
70
+ status: 'success',
71
+ message: '{{Name}} updated successfully',
72
+ code: 202,
73
+ })
74
+ .response(res)
75
+ .setStatusCode(202);
76
+ }
77
+
78
+ /**
79
+ * Delete a specific resource
80
+ *
81
+ * @param req
82
+ * @param res
83
+ */
84
+ destroy = async ({ res }: HttpContext) => {
85
+ return await new Resource({ data: {} })
86
+ .additional({
87
+ status: 'success',
88
+ message: '{{Name}} deleted successfully',
89
+ code: 202,
90
+ })
91
+ .response(res)
92
+ .setStatusCode(202);
93
+ }
94
+ }
@@ -0,0 +1,120 @@
1
+ import BaseController from '@controllers/BaseController'
2
+ import { HttpContext } from 'clear-router/types/h3'
3
+ import { Resource } from 'resora';
4
+ import { prisma } from '@core/DB'
5
+ import { readBody } from 'h3'
6
+
7
+ /**
8
+ * {{ControllerName}}
9
+ */
10
+ export default class extends BaseController {
11
+ /**
12
+ * Get all resource from the database
13
+ *
14
+ * @param req
15
+ * @param res
16
+ */
17
+ index = async ({ res }: HttpContext) => {
18
+ const data = await prisma.{{ModelName}}.findMany(
19
+ { orderBy: { id: 'asc' } }
20
+ )
21
+
22
+ return await new Resource({ data })
23
+ .additional({
24
+ status: 'success',
25
+ message: 'OK',
26
+ code: 200,
27
+ })
28
+ .response(res)
29
+ .setStatusCode(200);
30
+ }
31
+
32
+ /**
33
+ * Get a specific resource from the database
34
+ *
35
+ * @param req
36
+ * @param res
37
+ */
38
+ show = async ({ res, context }: HttpContext) => {
39
+ const data = await prisma.{{ModelName}}.findFirst(
40
+ { where: { id: String(context.params?.id) } }
41
+ )
42
+
43
+ return await new Resource({ data })
44
+ .additional({
45
+ status: 'success',
46
+ message: 'OK',
47
+ code: 200,
48
+ })
49
+ .response(res)
50
+ .setStatusCode(200);
51
+ }
52
+
53
+ /**
54
+ * Create a new resource in the database
55
+ *
56
+ * The calling route must recieve a multer.RequestHandler instance
57
+ *
58
+ * @example router.post('/{{ModelName}}s', upload.none(), new AdminController().create);
59
+ *
60
+ * @param req
61
+ * @param res
62
+ */
63
+ create = async (evt: HttpContext) => {
64
+ const data = await prisma.{{ModelName}}.create({
65
+ data: readBody(evt) as any,
66
+ })
67
+
68
+ return await new Resource({ data })
69
+ .additional({
70
+ status: 'success',
71
+ message: 'New {{ModelName}} created successfully',
72
+ code: 201,
73
+ })
74
+ .response(evt.res)
75
+ .setStatusCode(201);
76
+ }
77
+
78
+ /**
79
+ * Update a specific resource in the database
80
+ *
81
+ * @param req
82
+ * @param res
83
+ */
84
+ update = async (evt: HttpContext) => {
85
+ const data = await prisma.{{ModelName}}.update({
86
+ where: { id: String(evt.context.params?.id) },
87
+ data: readBody(evt) as any,
88
+ })
89
+
90
+ return await new Resource({ data })
91
+ .additional({
92
+ status: 'success',
93
+ message: '{{ModelName}} updated successfully',
94
+ code: 202,
95
+ })
96
+ .response(evt.res)
97
+ .setStatusCode(202);
98
+ }
99
+
100
+ /**
101
+ * Delete a specific resource from the database
102
+ *
103
+ * @param req
104
+ * @param res
105
+ */
106
+ destroy = async ({ res, context }: HttpContext) => {
107
+ await prisma.{{ModelName}}.delete(
108
+ { where: { id: String(context.params?.id) } }
109
+ )
110
+
111
+ return await new Resource({ data: null })
112
+ .additional({
113
+ status: 'success',
114
+ message: '{{ModelName}} deleted successfully',
115
+ code: 202,
116
+ })
117
+ .response(res)
118
+ .setStatusCode(202);
119
+ }
120
+ }
@@ -0,0 +1,11 @@
1
+ import BaseController from '@controllers/BaseController';
2
+ import { HttpContext } from 'clear-router/types/h3'
3
+
4
+ /**
5
+ * {{ControllerName}}
6
+ */
7
+ export default class extends BaseController {
8
+ index = async ({ req, res }: HttpContext) => {
9
+ return '<p>Hello!</p>'
10
+ }
11
+ }