@arkstack/contract 0.5.2 → 0.5.3

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # @arkstack/contract
2
2
 
3
+ [![@arkstack/contract](https://img.shields.io/npm/dt/@arkstack/contract?style=flat-square&label=@arkstack/contract&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F@arkstack/contract)](https://www.npmjs.com/package/@arkstack/contract)
4
+
3
5
  Contract module for Arkstack, providing shared interfaces and type contracts used across the framework.
4
6
 
5
7
  This package defines the shared shape each framework driver must implement.
package/dist/global.d.ts CHANGED
@@ -1,9 +1,25 @@
1
- import { ArkstackRouterAwareCore } from './index'
1
+ import { Arkstack } from '.'
2
2
 
3
3
  declare global {
4
- function app (): ArkstackRouterAwareCore<never, never>
4
+ function app (): Arkstack<never, never>
5
5
  var arkctx: {
6
6
  runtime: 'CLI' | 'HTTP' | 'Worker'
7
7
  command?: string
8
8
  }
9
+ }
10
+
11
+ declare module '@arkstack/common' {
12
+ interface HookRegistry {
13
+ 'set:root-dir': {
14
+ after: (dir: string) => void
15
+ }
16
+ }
17
+ }
18
+
19
+ declare module '@arkstack/foundry' {
20
+ interface HookRegistry {
21
+ 'set:root-dir': {
22
+ after: (dir: string) => void
23
+ }
24
+ }
9
25
  }
package/dist/index.d.ts CHANGED
@@ -1,22 +1,16 @@
1
1
  /// <reference path="./global.d.ts" />
2
- //#region src/index.d.ts
3
- type PromiseOrValue<T> = T | Promise<T>;
2
+ //#region src/http.d.ts
4
3
  interface ArkstackMiddlewareConfig<TMiddleware> {
5
4
  global: TMiddleware[];
6
5
  before: TMiddleware[];
7
6
  after: TMiddleware[];
8
7
  }
9
- interface ArkstackRouteListOptions {
10
- path?: string;
11
- }
12
- interface ArkstackRouterContract<TApp, TRoutes = unknown> {
13
- bind(app: TApp): PromiseOrValue<unknown>;
14
- list(options?: ArkstackRouteListOptions, app?: TApp): PromiseOrValue<TRoutes>;
15
- }
16
- interface ArkstackRouterAwareCore<TApp, TRoutes = unknown> {
17
- getAppInstance(): TApp;
18
- getRouter(): ArkstackRouterContract<TApp, TRoutes>;
19
- }
8
+ //#endregion
9
+ //#region src/kits.d.ts
10
+ /**
11
+ * The ArkstackKitDriver class defines the contract for a driver
12
+ * that can be used with the ArkstackKitContract.
13
+ */
20
14
  declare abstract class ArkstackKitDriver<TApp, TMiddleware> {
21
15
  abstract readonly name: string;
22
16
  abstract createApp(): TApp;
@@ -27,6 +21,10 @@ declare abstract class ArkstackKitDriver<TApp, TMiddleware> {
27
21
  registerErrorHandler(_app: TApp): PromiseOrValue<void>;
28
22
  abstract start(app: TApp, port: number): PromiseOrValue<void>;
29
23
  }
24
+ /**
25
+ * The ArkstackKitContract class defines the contract for an
26
+ * application that uses the ArkstackKitDriver.
27
+ */
30
28
  declare abstract class ArkstackKitContract<TApp, TMiddleware> {
31
29
  abstract app: TApp;
32
30
  abstract driver: ArkstackKitDriver<TApp, TMiddleware>;
@@ -35,5 +33,96 @@ declare abstract class ArkstackKitContract<TApp, TMiddleware> {
35
33
  abstract shutdown(): Promise<void>;
36
34
  }
37
35
  //#endregion
38
- export { ArkstackKitContract, ArkstackKitDriver, ArkstackMiddlewareConfig, ArkstackRouteListOptions, ArkstackRouterAwareCore, ArkstackRouterContract, PromiseOrValue };
39
- //# sourceMappingURL=index.d.ts.map
36
+ //#region src/routing.d.ts
37
+ interface ArkstackRouteListOptions {
38
+ path?: string;
39
+ }
40
+ interface ArkstackRouterContract<TApp, TRoutes = unknown> {
41
+ bind(app: TApp): PromiseOrValue<unknown>;
42
+ list(options?: ArkstackRouteListOptions, app?: TApp): PromiseOrValue<TRoutes>;
43
+ }
44
+ //#endregion
45
+ //#region src/Arkstack.d.ts
46
+ type PromiseOrValue<T> = T | Promise<T>;
47
+ type ENV = 'development' | 'production' | 'stagging' | 'testing';
48
+ type RootDirChangeListener = (dir: string, previousDir: string) => void;
49
+ declare abstract class Arkstack<TApp, TRoutes = unknown, THandler = unknown> {
50
+ static app: unknown;
51
+ private static appRootDir;
52
+ protected app: TApp;
53
+ protected driver: ArkstackKitDriver<TApp, THandler>;
54
+ abstract getRouter(): ArkstackRouterContract<TApp, TRoutes>;
55
+ /**
56
+ * Boots the application by mounting public assets, binding the
57
+ * router, applying middleware, and starting the server.
58
+ *
59
+ * @param port The numeric port to run the server on
60
+ * @param defer Set to true to skip server startup
61
+ */
62
+ abstract boot(port: number, defer?: boolean): Promise<void>;
63
+ /**
64
+ * Gets the driver application instance.
65
+ *
66
+ * @returns
67
+ */
68
+ getAppInstance(): TApp;
69
+ /**
70
+ * Gets the static driver application instance.
71
+ *
72
+ * @returns
73
+ */
74
+ static getAppInstance<TApp = unknown>(): TApp;
75
+ /**
76
+ * Gets the ArkstackKitDriver instance used by the application.
77
+ *
78
+ * @returns
79
+ */
80
+ getDriver(): ArkstackKitDriver<TApp, THandler>;
81
+ /**
82
+ * Boostrap the app and start up the server
83
+ *
84
+ * @param defaultPort start the server with this port if neither PORT nor APP_PORT env variable is set
85
+ * @param defer Set to true to skip server startup
86
+ */
87
+ startup(defaultPort?: number, defer?: boolean): Promise<void>;
88
+ /**
89
+ * Shuts down the application by disconnecting from the database and exiting the process.
90
+ */
91
+ shutdown(): Promise<void>;
92
+ /**
93
+ * Get the current app root directory
94
+ *
95
+ * @alias getRootDir()
96
+ * @returns
97
+ */
98
+ static rootDir(): string;
99
+ /**
100
+ * Get the current app root directory
101
+ *
102
+ * @alias getRootDir()
103
+ * @returns
104
+ */
105
+ rootDir(): string;
106
+ /**
107
+ * Get the current app root directory
108
+ *
109
+ * @returns
110
+ */
111
+ static getRootDir(): string;
112
+ /**
113
+ * Set the current app root directory
114
+ *
115
+ * @param dir The prefered app root directory
116
+ * @returns
117
+ */
118
+ setRootDir(dir: string): void;
119
+ /**
120
+ * Set the current app root directory
121
+ *
122
+ * @param dir The prefered app root directory
123
+ * @returns
124
+ */
125
+ static setRootDir(dir: string): void;
126
+ }
127
+ //#endregion
128
+ export { Arkstack, ArkstackKitContract, ArkstackKitDriver, ArkstackMiddlewareConfig, ArkstackRouteListOptions, ArkstackRouterContract, ENV, PromiseOrValue, RootDirChangeListener };
package/dist/index.js CHANGED
@@ -1,4 +1,102 @@
1
- //#region src/index.ts
1
+ import { Hook } from "@arkstack/foundry";
2
+ //#region src/Arkstack.ts
3
+ var Arkstack = class Arkstack {
4
+ static app;
5
+ static appRootDir = process.cwd();
6
+ app;
7
+ driver;
8
+ /**
9
+ * Gets the driver application instance.
10
+ *
11
+ * @returns
12
+ */
13
+ getAppInstance() {
14
+ return this.app;
15
+ }
16
+ /**
17
+ * Gets the static driver application instance.
18
+ *
19
+ * @returns
20
+ */
21
+ static getAppInstance() {
22
+ return Arkstack.app;
23
+ }
24
+ /**
25
+ * Gets the ArkstackKitDriver instance used by the application.
26
+ *
27
+ * @returns
28
+ */
29
+ getDriver() {
30
+ return this.driver;
31
+ }
32
+ /**
33
+ * Boostrap the app and start up the server
34
+ *
35
+ * @param defaultPort start the server with this port if neither PORT nor APP_PORT env variable is set
36
+ * @param defer Set to true to skip server startup
37
+ */
38
+ async startup(defaultPort = 3e3, defer) {
39
+ const { bootWithDetectedPort } = await import("@arkstack/common");
40
+ await bootWithDetectedPort(async (port) => {
41
+ await this.boot(port, defer);
42
+ }, Number(process.env.PORT ?? process.env.APP_PORT ?? defaultPort), this, defer);
43
+ }
44
+ /**
45
+ * Shuts down the application by disconnecting from the database and exiting the process.
46
+ */
47
+ async shutdown() {
48
+ process.exit(0);
49
+ }
50
+ /**
51
+ * Get the current app root directory
52
+ *
53
+ * @alias getRootDir()
54
+ * @returns
55
+ */
56
+ static rootDir() {
57
+ return Arkstack.appRootDir;
58
+ }
59
+ /**
60
+ * Get the current app root directory
61
+ *
62
+ * @alias getRootDir()
63
+ * @returns
64
+ */
65
+ rootDir() {
66
+ return Arkstack.appRootDir;
67
+ }
68
+ /**
69
+ * Get the current app root directory
70
+ *
71
+ * @returns
72
+ */
73
+ static getRootDir() {
74
+ return Arkstack.appRootDir;
75
+ }
76
+ /**
77
+ * Set the current app root directory
78
+ *
79
+ * @param dir The prefered app root directory
80
+ * @returns
81
+ */
82
+ setRootDir(dir) {
83
+ Arkstack.setRootDir(dir);
84
+ }
85
+ /**
86
+ * Set the current app root directory
87
+ *
88
+ * @param dir The prefered app root directory
89
+ * @returns
90
+ */
91
+ static setRootDir(dir) {
92
+ const previousDir = Arkstack.appRootDir;
93
+ Arkstack.appRootDir = dir;
94
+ if (previousDir === dir) return;
95
+ if (Hook.has("set:root-dir", "after")) Hook.get("set:root-dir", "after", dir);
96
+ }
97
+ };
98
+ //#endregion
99
+ //#region src/kits.ts
2
100
  /**
3
101
  * The ArkstackKitDriver class defines the contract for a driver
4
102
  * that can be used with the ArkstackKitContract.
@@ -12,6 +110,4 @@ var ArkstackKitDriver = class {
12
110
  */
13
111
  var ArkstackKitContract = class {};
14
112
  //#endregion
15
- export { ArkstackKitContract, ArkstackKitDriver };
16
-
17
- //# sourceMappingURL=index.js.map
113
+ export { Arkstack, ArkstackKitContract, ArkstackKitDriver };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/contract",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "type": "module",
5
5
  "description": "Contract module for Arkstack, providing shared interfaces and type contracts used across the framework.",
6
6
  "homepage": "https://arkstack.toneflix.net",
@@ -27,6 +27,9 @@
27
27
  ".": "./dist/index.js",
28
28
  "./package.json": "./package.json"
29
29
  },
30
+ "dependencies": {
31
+ "@arkstack/foundry": "^0.5.3"
32
+ },
30
33
  "scripts": {
31
34
  "build": "tsdown --config-loader unrun",
32
35
  "version:patch": "pnpm version patch"
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export type PromiseOrValue<T> = T | Promise<T>;\n\nexport interface ArkstackMiddlewareConfig<TMiddleware> {\n global: TMiddleware[];\n before: TMiddleware[];\n after: TMiddleware[];\n}\n\nexport interface ArkstackRouteListOptions {\n path?: string;\n}\n\nexport interface ArkstackRouterContract<TApp, TRoutes = unknown> {\n bind (app: TApp): PromiseOrValue<unknown>;\n list (options?: ArkstackRouteListOptions, app?: TApp): PromiseOrValue<TRoutes>;\n}\n\nexport interface ArkstackRouterAwareCore<TApp, TRoutes = unknown> {\n getAppInstance (): TApp;\n getRouter (): ArkstackRouterContract<TApp, TRoutes>;\n}\n\n/**\n * The ArkstackKitDriver class defines the contract for a driver \n * that can be used with the ArkstackKitContract. \n */\nexport abstract class ArkstackKitDriver<TApp, TMiddleware> {\n abstract readonly name: string;\n abstract createApp (): TApp;\n abstract mountPublicAssets (app: TApp, publicPath: string): PromiseOrValue<void>;\n abstract bindRouter (app: TApp): PromiseOrValue<void>;\n abstract applyMiddleware (app: TApp, middleware: ArkstackMiddlewareConfig<TMiddleware>): PromiseOrValue<void>;\n abstract applyMiddleware (app: TApp, middleware: TMiddleware): PromiseOrValue<void>;\n registerErrorHandler (_app: TApp): PromiseOrValue<void> {\n return\n }\n abstract start (app: TApp, port: number): PromiseOrValue<void>;\n}\n\n/**\n * The ArkstackKitContract class defines the contract for an \n * application that uses the ArkstackKitDriver.\n */\nexport abstract class ArkstackKitContract<TApp, TMiddleware> {\n abstract app: TApp;\n abstract driver: ArkstackKitDriver<TApp, TMiddleware>;\n abstract middleware: ArkstackMiddlewareConfig<TMiddleware>;\n abstract boot (port: number): Promise<void>;\n abstract shutdown (): Promise<void>;\n}\n"],"mappings":";;;;;AA0BA,IAAsB,oBAAtB,MAA2D;CAOzD,qBAAsB,MAAkC;;;;;;AAU1D,IAAsB,sBAAtB,MAA6D"}