milkio 0.7.0-alpha.1 → 0.7.0-alpha.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/api-test/index.ts CHANGED
@@ -18,7 +18,6 @@ export const executeApiTests = async <Path extends Array<keyof (typeof schema)["
18
18
  await apiTestHooks.default.onBootstrap();
19
19
  const clientPackage = apiTestHooks.default?.client ? (await apiTestHooks.default?.client()) : undefined;
20
20
  const results: Array<{ path: string, case: number, fail: boolean, failMessage?: string }> = [];
21
- console.log(chalk.hex("#0B346E")(`₋₋₋₋₋₋₋₋`));
22
21
 
23
22
  if (!clientPackage) {
24
23
  console.log(`🚨 For testing purposes, if the client package does not exist, subsequent operations might result in errors.`);
@@ -59,6 +58,8 @@ export const executeApiTests = async <Path extends Array<keyof (typeof schema)["
59
58
  executeStreamOther: async (path: any, options?: any) => clientPackage!.executeStream((path as any), options),
60
59
  } : undefined;
61
60
 
61
+ console.log(chalk.hex("#0B346E")(`₋₋₋₋₋₋₋₋`));
62
+
62
63
  for (const pathRaw of pathArr) {
63
64
  let path = pathRaw.replaceAll("\\", "/");
64
65
  if (path.startsWith("/")) path = path.slice(1) as Path[number];
@@ -0,0 +1,32 @@
1
+ export function defineConfig<T>(handler: (options: { config: typeof configFn }) => T): T {
2
+ const result = handler({ config: configFn });
3
+ if (!result) throw new Error("defineConfig must return a value, Did you forget to add a return statement?");
4
+ if (typeof result !== "object" || Array.isArray(result)) throw new Error("defineConfig must return an object.");
5
+ if ("environment" in result && "done" in result && typeof result["environment"] === "function" && typeof result["done"] === "function") throw new Error("Did you accidentally return the config method without adding \`.done()\`?");
6
+ return result;
7
+ }
8
+
9
+ function configFn<ConfigT extends Config>(config: ConfigT): ConfigMore<ConfigT> {
10
+ let skipMore = false;
11
+
12
+ const configMore: ConfigMore<ConfigT> = {
13
+ environment: (when, configMixin) => {
14
+ if (skipMore || !when()) return configMore;
15
+ skipMore = true;
16
+ for (const key in configMixin) (config as any)[key] = configMixin[key];
17
+ return configMore;
18
+ },
19
+ done: () => {
20
+ return config;
21
+ },
22
+ } satisfies ConfigMore<ConfigT>;
23
+
24
+ return configMore;
25
+ }
26
+
27
+ export type Config = Record<string, unknown>;
28
+
29
+ export type ConfigMore<ConfigT extends Config> = {
30
+ environment: (when: () => boolean, config: Partial<ConfigT>) => ConfigMore<ConfigT>;
31
+ done: () => ConfigT;
32
+ };
@@ -19,6 +19,7 @@ export type ExecuteHttpServerOptions = {
19
19
  */
20
20
  executeIdGenerator?: (request: Request) => string | Promise<string>;
21
21
  getRealIp?: (request: Request) => string;
22
+ mixin?: Record<string, unknown>;
22
23
  };
23
24
 
24
25
  export function defineHttpHandler(app: MilkioApp, options: ExecuteHttpServerOptions = {}) {
@@ -76,6 +77,7 @@ export function defineHttpHandler(app: MilkioApp, options: ExecuteHttpServerOpti
76
77
  let pathstr = path.join("/") as keyof (typeof schema)["apiMethodsSchema"];
77
78
 
78
79
  const detail = {
80
+ ...options.mixin ?? {},
79
81
  path: pathstr,
80
82
  ip,
81
83
  executeId,
package/index.ts CHANGED
@@ -7,12 +7,12 @@ export * from "./utils/create-ulid";
7
7
  export * from "./utils/env-to-string";
8
8
  export * from "./utils/env-to-number";
9
9
  export * from "./utils/env-to-boolean";
10
- // export * from "./utils/create-template"
11
10
  export * from "./utils/header-to-plain-object";
12
11
 
13
12
  // defines
14
13
  export * from "./defines/define-use";
15
14
  export * from "./defines/define-api";
15
+ export * from "./defines/define-config";
16
16
  export * from "./defines/define-api-test";
17
17
  export * from "./defines/define-middleware";
18
18
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "milkio",
3
3
  "type": "module",
4
4
  "module": "index.ts",
5
- "version": "0.7.0-alpha.1",
5
+ "version": "0.7.0-alpha.3",
6
6
  "peerDependencies": {
7
7
  "typescript": "^5.4.2"
8
8
  },