milkio 1.0.0-alpha.4 → 1.0.0-alpha.41

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.
Files changed (41) hide show
  1. package/.co.toml +0 -0
  2. package/LICENSE +1 -1
  3. package/README.md +0 -0
  4. package/action/index.ts +0 -0
  5. package/command/index.ts +2 -2
  6. package/config/index.ts +33 -0
  7. package/context/index.ts +7 -4
  8. package/events/index.ts +3 -3
  9. package/exception/index.ts +2 -0
  10. package/execute/execute-id-generator.ts +0 -0
  11. package/execute/index.ts +33 -78
  12. package/index.ts +3 -0
  13. package/listener/index.ts +39 -20
  14. package/logger/index.ts +1 -1
  15. package/meta/index.ts +0 -0
  16. package/package.json +4 -4
  17. package/step/index.ts +4 -4
  18. package/stream/index.ts +0 -0
  19. package/tsconfig.json +0 -0
  20. package/type-safety/index.ts +16 -0
  21. package/types/index.ts +13 -21
  22. package/utils/create-id.ts +10 -2
  23. package/utils/send-cookbook-event.ts +0 -0
  24. package/world/index.ts +22 -13
  25. package/.publish/publish.json +0 -7
  26. package/.publish/releases/0.0.0.md +0 -0
  27. package/.publish/releases/0.1.0.md +0 -13
  28. package/.publish/releases/0.2.0.md +0 -33
  29. package/.publish/releases/0.3.0.md +0 -85
  30. package/.publish/releases/0.4.0.md +0 -35
  31. package/.publish/releases/0.5.0.md +0 -19
  32. package/.publish/releases/0.6.0.md +0 -41
  33. package/.publish/releases/0.8.0.md +0 -128
  34. package/.publish/releases-github/0.0.0.md +0 -0
  35. package/.publish/releases-github/0.1.0.md +0 -13
  36. package/.publish/releases-github/0.2.0.md +0 -33
  37. package/.publish/releases-github/0.3.0.md +0 -85
  38. package/.publish/releases-github/0.4.0.md +0 -35
  39. package/.publish/releases-github/0.5.0.md +0 -19
  40. package/.publish/releases-github/0.6.0.md +0 -41
  41. package/.publish/releases-github/0.8.0.md +0 -126
package/.co.toml CHANGED
File without changes
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 southern-aurora
3
+ Copyright (c) 2023 akirarika
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
File without changes
package/action/index.ts CHANGED
File without changes
package/command/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type MilkioRuntimeInit, type MilkioInit, type GeneratedInit } from "..";
1
+ import { type GeneratedInit } from "..";
2
2
 
3
3
  export const command = <CommandInitT extends CommandInit>(init: CommandInitT): Command<CommandInitT> => {
4
4
  const command = init as unknown as Command<CommandInitT>;
@@ -15,7 +15,7 @@ export type Command<CommandInitT extends CommandInit> = {
15
15
  handler: CommandInitT["handler"];
16
16
  };
17
17
 
18
- export const __initCommander = <MilkioRuntime extends MilkioRuntimeInit<MilkioInit> = MilkioRuntimeInit<MilkioInit>>(generated: GeneratedInit, runtime: MilkioRuntime) => {
18
+ export const __initCommander = (generated: GeneratedInit, runtime: any) => {
19
19
  const commander = async (argv: Array<string>, options?: { onNotFound?: () => any }) => {
20
20
  const params = {
21
21
  path: "index",
@@ -0,0 +1,33 @@
1
+ export const config = <ConfigT extends Config>(config: ConfigT): ConfigT => {
2
+ return config;
3
+ };
4
+
5
+ export type Config = (mode: string) => Promise<Record<string, unknown>> | Record<string, unknown>;
6
+
7
+ export type ConfigEnvironments<T extends Config> = {
8
+ [key: string]: (env: Record<string, string>) => Partial<Awaited<ReturnType<T>>> | Promise<Partial<Awaited<ReturnType<T>>>>;
9
+ };
10
+
11
+ export function envToString(value: string | number | undefined, defaultValue: string) {
12
+ if (value === undefined) return defaultValue;
13
+
14
+ return `${value}`;
15
+ }
16
+
17
+ export function envToNumber(value: string | undefined, defaultValue: number) {
18
+ if (value === undefined) return defaultValue;
19
+
20
+ return Number.parseInt(value, 10);
21
+ }
22
+
23
+ export function envToBoolean(value: string | number | undefined, defaultValue: boolean) {
24
+ if (value === "true") return true;
25
+
26
+ if (value === "false") return false;
27
+
28
+ if (value === "") return false;
29
+
30
+ if (undefined === value) return defaultValue;
31
+
32
+ return Boolean(value);
33
+ }
package/context/index.ts CHANGED
@@ -1,17 +1,20 @@
1
- import { type MilkioHttpRequest, type MilkioHttpResponse, type $types, type Logger, Steps } from "..";
1
+ import { type MilkioHttpRequest, type MilkioHttpResponse, type $types, type Logger, type Steps, type Mixin, type ExecuteOptions, type Action } from "..";
2
2
 
3
3
  export interface $context {
4
+ develop: boolean;
4
5
  executeId: string;
6
+ environment: string;
5
7
  path: string;
6
8
  logger: Logger;
7
- http?: ContextHttp<Record<any, any>>;
8
- step: Steps<{}>["step"];
9
+ http: ContextHttp<Record<any, any>>;
10
+ config: Readonly<Awaited<ReturnType<$types["configSchema"]["get"]>>>;
11
+ call: <Module extends Promise<{ default: Action<any> }>>(module: Module, params: Parameters<Awaited<Module>["default"]["handler"]>[1]) => Promise<ReturnType<Awaited<Module>["default"]["handler"]>>;
9
12
  }
10
13
 
11
14
  export type ContextHttp<ParamsParsed = any> = {
12
15
  url: URL;
13
16
  ip: string;
14
- path: { string: keyof $types["generated"]["routeSchema"]["$types"]; array: Array<string> };
17
+ path: { string: keyof $types["generated"]["routeSchema"]; array: Array<string> };
15
18
  params: {
16
19
  string: string;
17
20
  parsed: ParamsParsed;
package/events/index.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { type $context, type ContextHttp, type Results, type Logger } from "..";
1
+ import { type $context, type ContextHttp, type Results, type Logger, type $meta } from "..";
2
2
 
3
3
  export interface $events {
4
4
  "milkio:httpRequest": { executeId: string; path: string; logger: Logger; http: ContextHttp<Record<string, any>> };
5
5
  "milkio:httpResponse": { executeId: string; path: string; logger: Logger; http: ContextHttp<Record<string, any>>; context: $context };
6
6
  "milkio:httpNotFound": { executeId: string; path: string; logger: Logger; http: ContextHttp<Record<string, any>> };
7
- "milkio:executeBefore": { executeId: string; path: string; logger: Logger; context: $context };
8
- "milkio:executeAfter": { executeId: string; path: string; logger: Logger; context: $context; results: Results<any> };
7
+ "milkio:executeBefore": { executeId: string; path: string; logger: Logger; meta: $meta; context: $context };
8
+ "milkio:executeAfter": { executeId: string; path: string; logger: Logger; meta: $meta; context: $context; results: Results<any> };
9
9
  }
10
10
 
11
11
  export const __initEventManager = () => {
@@ -8,8 +8,10 @@ export interface $rejectCode {
8
8
  REQUEST_TIMEOUT: { timeout: number; message: string };
9
9
  NOT_FOUND: { path: string };
10
10
  PARAMS_TYPE_INCORRECT: { path: string; expected: string; value: any; message: string } | null;
11
+ RESULTS_TYPE_INCORRECT: { path: string; expected: string; value: any; message: string } | null;
11
12
  UNACCEPTABLE: { expected: string; message: string };
12
13
  PARAMS_TYPE_NOT_SUPPORTED: { expected: string };
14
+ RESULTS_TYPE_NOT_SUPPORTED: { expected: string };
13
15
  INTERNAL_SERVER_ERROR: undefined;
14
16
  }
15
17
 
File without changes
package/execute/index.ts CHANGED
@@ -1,11 +1,10 @@
1
- import { type IValidation } from "typia";
1
+ import typia, { type IValidation } from "typia";
2
2
  import { TSON } from "@southern-aurora/tson";
3
- import { createId } from "../utils/create-id";
4
- import { reject, type $context, type $meta, type ExecuteOptions, type Logger, type MilkioRuntimeInit, type Results, type GeneratedInit, type MilkioInit, createLogger, exceptionHandler, Ping, createStep } from "..";
3
+ import { reject, type $context, type $meta, type Logger, type Results, type GeneratedInit } from "..";
5
4
  import { headersToJSON } from "../utils/headers-to-json";
6
5
 
7
- export const __initExecuter = <MilkioRuntime extends MilkioRuntimeInit<MilkioRuntimeInit<MilkioInit>> = MilkioRuntimeInit<MilkioInit>>(generated: GeneratedInit, runtime: MilkioRuntime) => {
8
- const __call = async (
6
+ export const __initExecuter = (generated: GeneratedInit, runtime: any) => {
7
+ const __execute = async (
9
8
  routeSchema: any,
10
9
  options: {
11
10
  createdExecuteId: string;
@@ -23,8 +22,8 @@ export const __initExecuter = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
23
22
  paramsType: "string";
24
23
  }
25
24
  ),
26
- ): Promise<{ executeId: string; headers: Headers; params: Record<any, unknown>; results: Results<any>; context: $context; meta: Readonly<$meta>; type: "action" | "stream" }> => {
27
- const executeId = options.createdExecuteId;
25
+ ): Promise<{ executeId: string; headers: Headers; params: Record<any, unknown>; results: Results<any>; context: $context; meta: Readonly<$meta>; type: "action" | "stream"; emptyResult: boolean; resultsTypeSafety: boolean }> => {
26
+ const executeId: string = options.createdExecuteId;
28
27
  let headers: Headers;
29
28
  if (!(options.headers instanceof Headers)) {
30
29
  // @ts-ignore
@@ -62,102 +61,58 @@ export const __initExecuter = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
62
61
  if (options.mixinContext?.http?.params?.string) options.mixinContext.http.params.parsed = params; // listen でパースしたパラメータを渡す
63
62
  const context = {
64
63
  ...(options.mixinContext ? options.mixinContext : {}),
64
+ develop: runtime.develop,
65
65
  path: options.path,
66
66
  logger: options.createdLogger,
67
67
  executeId: options.createdExecuteId,
68
- step: createStep(),
68
+ config: runtime.runtime.config,
69
+ call: (module: any, options: any) => __call(context, module, options),
69
70
  } as unknown as $context;
70
- const results: Results<unknown> = { value: undefined };
71
+ const results: Results<any> = { value: undefined };
71
72
 
72
73
  if (runtime.develop) {
73
74
  options.createdLogger.request(`headers - ${TSON.stringify(headers.toJSON())}`, `\nparams - ${TSON.stringify(params)}`);
74
75
  }
75
76
 
76
77
  const module = await routeSchema.module();
77
- let meta = (module.meta ? module.meta : {}) as unknown as Readonly<$meta>;
78
+ let meta = (module.default?.meta ? module.default?.meta : {}) as unknown as Readonly<$meta>;
78
79
 
79
- if (!meta.typeSafety || meta.typeSafety === true) {
80
+ if (meta.typeSafety === undefined || meta.typeSafety === true) {
80
81
  const validation = routeSchema.validateParams(params) as IValidation<any>;
81
82
  if (!validation.success) throw reject("PARAMS_TYPE_INCORRECT", { ...validation.errors[0], message: `The value '${validation.errors[0].path}' is '${validation.errors[0].value}', which does not meet '${validation.errors[0].expected}' requirements.` });
82
83
  }
83
84
 
84
- await runtime.emit("milkio:executeBefore", { executeId: options.createdExecuteId, logger: options.createdLogger, path: options.path, context });
85
+ await runtime.emit("milkio:executeBefore", { executeId: options.createdExecuteId, logger: options.createdLogger, path: options.path, meta, context });
85
86
 
86
87
  results.value = await module.default.handler(context, params);
87
88
 
88
- await runtime.emit("milkio:executeAfter", { executeId: options.createdExecuteId, logger: options.createdLogger, path: options.path, context, results });
89
-
90
- return { executeId, headers, params, results, context, meta, type: module.$milkioType };
91
- };
92
-
93
- const execute = async (path: string, options?: ExecuteOptions): Promise<any> => {
94
- if (!options) options = {};
95
- const executeId = createId();
96
- const logger = createLogger(runtime, path, executeId);
97
- runtime.runtime.request.set(executeId, { logger: logger });
98
-
99
- try {
100
- const routeSchema = generated.routeSchema.routes.get(path);
101
- if (routeSchema === undefined) {
102
- throw reject("NOT_FOUND", { path: path });
103
- }
104
-
105
- const executed = await __call(routeSchema, {
106
- createdExecuteId: executeId,
107
- createdLogger: logger,
108
- path: path,
109
- headers: options.headers ?? {},
110
- mixinContext: {},
111
- params: options.params ?? {},
112
- paramsType: "raw",
113
- });
89
+ let resultsTypeSafety = false;
90
+ if (results?.value?.$milkioType === "type-safety") {
91
+ resultsTypeSafety = true;
92
+ const validation = routeSchema.validateResults(results.value.value) as IValidation<any>;
93
+ if (!validation.success) throw reject("RESULTS_TYPE_INCORRECT", { ...validation.errors[0], message: `The value '${validation.errors[0].path}' is '${validation.errors[0].value}', which does not meet '${validation.errors[0].expected}' requirements.` });
94
+ results.value = results.value.value;
95
+ }
114
96
 
115
- if (routeSchema.type === "stream") {
116
- // stream
117
- return [
118
- undefined,
119
- (async function* () {
120
- try {
121
- for await (const result of executed.results.value) {
122
- yield [null, result];
123
- }
124
- return undefined;
125
- } catch (error) {
126
- const reject = exceptionHandler(executeId, logger, error);
127
- const result: any = {};
128
- result[reject.code] = reject.reject;
97
+ let emptyResult = false;
98
+ if (results.value === undefined || results.value === null || results.value === "") {
99
+ emptyResult = true;
100
+ results.value = {};
101
+ } else if (Array.isArray(results.value)) throw reject("FAIL", "The return type of the handler must be an object, which is currently an array.");
102
+ else if (typeof results.value !== "object") throw reject("FAIL", "The return type of the handler must be an object, which is currently a primitive type.");
129
103
 
130
- yield [result, null];
131
- return undefined;
132
- }
133
- })(),
134
- { executeId: executeId },
135
- ];
136
- } else {
137
- // action
138
- return [null, executed.results.value, { executeId: executeId }];
139
- }
140
- } catch (error) {
141
- const reject = exceptionHandler(executeId, logger, error);
142
- const result: any = {};
143
- result[reject.code] = reject.reject;
104
+ await runtime.emit("milkio:executeAfter", { executeId: options.createdExecuteId, logger: options.createdLogger, path: options.path, meta, context, results });
144
105
 
145
- return [result, null, { executeId: executeId }];
146
- }
106
+ return { executeId, headers, params, results, context, meta, type: module.$milkioType, emptyResult, resultsTypeSafety };
147
107
  };
148
108
 
149
- const ping = async (): Promise<Ping> => [
150
- null,
151
- {
152
- connect: true,
153
- delay: 0,
154
- serverTimestamp: Date.now(),
155
- },
156
- ];
109
+ const __call = async (context: $context, module: { default: any }, params?: any): Promise<any> => {
110
+ const moduleAwaited = await module;
111
+ return await moduleAwaited.default.handler(context, params);
112
+ };
157
113
 
158
114
  return {
159
115
  __call,
160
- execute,
161
- ping,
116
+ __execute,
162
117
  };
163
118
  };
package/index.ts CHANGED
@@ -1,4 +1,7 @@
1
+ export * from "./type-safety";
2
+ export * from "@southern-aurora/tson";
1
3
  export * from "./types";
4
+ export * from "./config";
2
5
  export * from "./execute";
3
6
  export * from "./events";
4
7
  export * from "./world";
package/listener/index.ts CHANGED
@@ -14,10 +14,14 @@ export type MilkioHttpResponse = Mixin<
14
14
  }
15
15
  >;
16
16
 
17
- export const __initListener = <MilkioRuntime extends MilkioRuntimeInit<MilkioRuntimeInit<MilkioInit>> = MilkioRuntimeInit<MilkioInit>>(generated: GeneratedInit, runtime: MilkioRuntime, executer: ReturnType<typeof __initExecuter>) => {
17
+ export const __initListener = (generated: GeneratedInit, runtime: any, executer: ReturnType<typeof __initExecuter>) => {
18
18
  const port = runtime.port;
19
- const fetch = async (request: MilkioHttpRequest): Promise<Response> => {
20
- if (request.method === "OPTIONS") {
19
+ const fetch = async (options: {
20
+ request: MilkioHttpRequest;
21
+ envMode?: string;
22
+ env?: Record<any, any>;
23
+ }): Promise<Response> => {
24
+ if (options.request.method === "OPTIONS") {
21
25
  return new Response(undefined, {
22
26
  headers: {
23
27
  "Access-Control-Allow-Methods": runtime.cors?.corsAllowMethods ?? "*",
@@ -27,7 +31,7 @@ export const __initListener = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
27
31
  });
28
32
  }
29
33
 
30
- if (request.url.endsWith("/generate_204")) {
34
+ if (options.request.url.endsWith("/generate_204")) {
31
35
  return new Response("", {
32
36
  status: 204,
33
37
  headers: {
@@ -40,12 +44,14 @@ export const __initListener = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
40
44
  });
41
45
  }
42
46
 
43
- const url = new URL(request.url);
47
+ const url = new URL(options.request.url);
44
48
  let pathArray = url.pathname.substring(1).split("/");
45
49
  if (runtime.ignorePathLevel !== undefined && runtime.ignorePathLevel !== 0) pathArray = pathArray.slice(runtime.ignorePathLevel);
46
50
  const pathString = `/${pathArray.join("/")}`;
47
51
 
48
- const executeId = runtime?.executeId ? await runtime.executeId(request) : createId();
52
+ const executeId = runtime?.executeId ? await runtime.executeId(options.request) : createId();
53
+ console.log("executeId", await runtime.executeId(options.request), createId());
54
+
49
55
  const logger = createLogger(runtime, pathString, executeId);
50
56
  runtime.runtime.request.set(executeId, { logger: logger });
51
57
  const response: MilkioHttpResponse = {
@@ -62,44 +68,57 @@ export const __initListener = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
62
68
 
63
69
  try {
64
70
  const http = (await (async () => {
65
- const ip = runtime.realIp ? runtime.realIp(request) : "::1";
71
+ const ip = runtime.realIp ? runtime.realIp(options.request) : "::1";
66
72
  const params = {
67
- string: await request.text(),
73
+ string: await options.request.text(),
68
74
  parsed: undefined,
69
75
  };
70
76
 
71
77
  return {
72
78
  url,
73
79
  ip,
74
- path: { string: pathString as keyof $types["generated"]["routeSchema"]["$types"], array: pathArray },
80
+ path: { string: pathString as keyof $types["generated"]["routeSchema"], array: pathArray },
75
81
  params,
76
- request,
82
+ request: options.request,
77
83
  response,
78
84
  } as ContextHttp;
79
85
  })())!;
80
86
 
81
87
  await runtime.emit("milkio:httpRequest", { executeId, logger, path: http.path.string as string, http });
82
88
 
83
- if (!request.headers.get("Accept")?.startsWith("text/event-stream")) {
89
+ if (!runtime.develop && ((http.path.string as string).includes("__") || (http.path.string as string).startsWith("/__/"))) {
90
+ await runtime.emit("milkio:httpNotFound", { executeId, logger, path: http.path.string as string, http });
91
+ throw reject("NOT_FOUND", { path: http.path.string as string });
92
+ }
93
+
94
+ if (!options.request.headers.get("Accept")?.startsWith("text/event-stream")) {
84
95
  // action
85
- const routeSchema = generated.routeSchema.routes.get(http.path.string);
96
+ const routeSchema = generated.routeSchema[http.path.string];
86
97
  if (routeSchema === undefined) {
87
98
  await runtime.emit("milkio:httpNotFound", { executeId, logger, path: http.path.string as string, http });
88
99
  throw reject("NOT_FOUND", { path: http.path.string as string });
89
100
  }
90
101
  if (routeSchema.type !== "action") throw reject("UNACCEPTABLE", { expected: "stream", message: `Not acceptable, the Accept in the request header should be "text/event-stream". If you are using the "@milkio/stargate" package, please add \`type: "stream"\` to the execute options.` });
91
102
 
92
- const executed = await executer.__call(routeSchema, {
103
+ const executed = await executer.__execute(routeSchema, {
93
104
  createdExecuteId: executeId,
94
105
  createdLogger: logger,
95
106
  path: http.path.string as string,
96
- headers: request.headers as Headers,
107
+ headers: options.request.headers as Headers,
97
108
  mixinContext: { http },
98
109
  params: http.params.string,
99
110
  paramsType: "string",
100
111
  });
101
112
 
102
- if (executed.results.value !== undefined) response.body = TSON.stringify({ success: true, data: executed.results.value, executeId } satisfies MilkioResponseSuccess<any>);
113
+ if (response.body === "" && executed.results.value !== undefined) {
114
+ if (executed.emptyResult) {
115
+ response.body = `{"data":{},"executeId":"${executeId}","success":true}`;
116
+ } else if (executed.resultsTypeSafety) {
117
+ response.body = `{"data":${routeSchema.resultsToJSON(executed.results.value)},"executeId":"${executeId}","success":true}`;
118
+ } else {
119
+ response.body = `{"data":${TSON.stringify(executed.results.value)},"executeId":"${executeId}","success":true}`;
120
+ }
121
+ }
103
122
 
104
123
  await runtime.emit("milkio:httpResponse", { executeId, logger, path: http.path.string as string, http, context: executed.context });
105
124
 
@@ -107,15 +126,15 @@ export const __initListener = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
107
126
  return new Response(response.body, response);
108
127
  } else {
109
128
  // stream
110
- const routeSchema = generated.routeSchema.routes.get(http.path.string);
129
+ const routeSchema = generated.routeSchema[http.path.string];
111
130
  if (routeSchema === undefined) throw reject("NOT_FOUND", { path: http.path.string as string });
112
131
  if (routeSchema.type !== "stream") throw reject("UNACCEPTABLE", { expected: "stream", message: `Not acceptable, the Accept in the request header should be "application/json". If you are using the "@milkio/stargate" package, please remove \`type: "stream"\` to the execute options.` });
113
132
 
114
- const executed = await executer.__call(routeSchema, {
133
+ const executed = await executer.__execute(routeSchema, {
115
134
  createdExecuteId: executeId,
116
135
  createdLogger: logger,
117
136
  path: http.path.string as string,
118
- headers: request.headers as Headers,
137
+ headers: options.request.headers as Headers,
119
138
  mixinContext: { http },
120
139
  params: http.params.string,
121
140
  paramsType: "string",
@@ -132,7 +151,7 @@ export const __initListener = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
132
151
  try {
133
152
  controller.write(`data:@${JSON.stringify({ success: true, data: undefined, executeId } satisfies MilkioResponseSuccess<any>)}\n\n`);
134
153
  for await (const value of executed.results.value) {
135
- if (!request.signal.aborted) {
154
+ if (!options.request.signal.aborted) {
136
155
  const result: string = JSON.stringify([null, TSON.encode(value)]);
137
156
  controller.write(`data:${result}\n\n`);
138
157
  } else {
@@ -161,7 +180,7 @@ export const __initListener = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
161
180
  try {
162
181
  controller.enqueue(`data:@${JSON.stringify({ success: true, data: undefined, executeId } satisfies MilkioResponseSuccess<any>)}\n\n`);
163
182
  for await (const value of executed.results.value) {
164
- if (!request.signal.aborted) {
183
+ if (!options.request.signal.aborted) {
165
184
  const result: string = JSON.stringify([null, TSON.encode(value)]);
166
185
  controller.enqueue(`data:${result}\n\n`);
167
186
  } else {
package/logger/index.ts CHANGED
@@ -52,7 +52,7 @@ export const createLogger = <MilkioRuntime extends MilkioRuntimeInit<MilkioRunti
52
52
  if (!inserting(log)) return log;
53
53
 
54
54
  logger._.logs.push([...log]);
55
- if (runtime.cookbook) {
55
+ if (runtime.develop) {
56
56
  void sendCookbookEvent(runtime, {
57
57
  type: "milkio@logger",
58
58
  log: log,
package/meta/index.ts CHANGED
File without changes
package/package.json CHANGED
@@ -2,18 +2,18 @@
2
2
  "name": "milkio",
3
3
  "type": "module",
4
4
  "module": "index.ts",
5
- "version": "1.0.0-alpha.4",
5
+ "version": "1.0.0-alpha.41",
6
6
  "peerDependencies": {
7
7
  "typescript": "^5.4.2"
8
8
  },
9
9
  "scripts": {},
10
10
  "dependencies": {
11
- "@paralleldrive/cuid2": "^2.2.2",
12
11
  "@poech/camel-hump-under": "^1.1.0",
13
- "@southern-aurora/tson": "^2.0.2",
12
+ "@southern-aurora/tson": "*",
14
13
  "chalk": "^5.3.0",
15
14
  "date-fns": "^4.1.0",
16
- "typia": "6.9.0"
15
+ "milkid": "2.0.6",
16
+ "typia": "6.11.3"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/bun": "latest",
package/step/index.ts CHANGED
@@ -1,5 +1,3 @@
1
- import type { ToEmptyObject } from "..";
2
-
3
1
  export type Steps<StageT extends Record<any, any>> = {
4
2
  step: StepFunction<StageT>;
5
3
  run: () => Promise<Remove_<StageT>>;
@@ -9,9 +7,11 @@ type Remove_<T> = {
9
7
  [K in keyof T as K extends `_${string}` ? never : K]: T[K];
10
8
  };
11
9
 
10
+ type ToEmptyObject<T> = T extends undefined | null | never ? {} : T extends object ? T : {};
11
+
12
12
  export type StepFunction<StageT extends Record<any, any>> = <HandlerT extends (stage: Readonly<StageT>) => Record<any, any> | Promise<Record<any, any>>>(handler: HandlerT) => Steps<Awaited<StageT> & ToEmptyObject<Awaited<ReturnType<HandlerT>>>>;
13
13
 
14
- export const createStep = (): Steps<{}>["step"] => {
14
+ export const createStep = (): Steps<{}> => {
15
15
  const stepController = {
16
16
  $milkioType: "step",
17
17
  _steps: [] as Array<(stage: any) => Promise<any>>,
@@ -32,5 +32,5 @@ export const createStep = (): Steps<{}>["step"] => {
32
32
  return result;
33
33
  },
34
34
  };
35
- return stepController.step as any as Steps<{}>["step"];
35
+ return stepController as any as Steps<{}>;
36
36
  };
package/stream/index.ts CHANGED
File without changes
package/tsconfig.json CHANGED
File without changes
@@ -0,0 +1,16 @@
1
+ export type TypeSafety<Value extends Record<any, any>> = (value: Value) => TypeSafetyValue;
2
+
3
+ export type TypeSafetyValue = {
4
+ type: <Type extends Record<any, any>>() => Type;
5
+ };
6
+
7
+ export type TypeSafetyType<Type extends Record<any, any>> = {
8
+ $milkioType: "type-safety";
9
+ value: Type;
10
+ };
11
+
12
+ export function typeSafety<Value extends Record<any, any>>(value: Value): TypeSafetyValue {
13
+ return {
14
+ type: () => ({ $milkioType: "type-safety", value }),
15
+ } as any;
16
+ }
package/types/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type $rejectCode } from "..";
1
+ import { type $context, type $rejectCode } from "..";
2
2
 
3
3
  export interface $types {
4
4
  [key: string]: Record<any, any>;
@@ -10,7 +10,15 @@ export type Mixin<T, U> = U & Omit<T, keyof U>;
10
10
 
11
11
  export type GeneratorGeneric<T> = T extends AsyncGenerator<infer I> ? I : never;
12
12
 
13
- export type ToEmptyObject<T> = T extends undefined | null | never ? {} : T extends object ? T : {};
13
+ export type DBSelect<T extends Record<any, any>, K extends keyof T> = Omit<T, K>;
14
+
15
+ export type DBCreate<T, KO extends keyof T | never = never, TO extends Omit<T, KO> = Omit<T, KO>> = {
16
+ [K in keyof TO]?: TO[K] extends null ? undefined : Exclude<TO[K], null>;
17
+ };
18
+
19
+ export type DBUpdate<T, KO extends keyof T | never = never, TO extends Partial<Omit<T, KO>> = Partial<Omit<T, KO>>> = {
20
+ [K in keyof TO]?: TO[K] extends null ? undefined : Exclude<TO[K], null>;
21
+ };
14
22
 
15
23
  export type ExecuteId = string | "global";
16
24
 
@@ -20,7 +28,6 @@ export type ExecuteId = string | "global";
20
28
  export type GeneratedInit = {
21
29
  routeSchema: any;
22
30
  commandSchema: any;
23
- testSchema: any;
24
31
  };
25
32
 
26
33
  export type Results<T extends unknown> = {
@@ -50,27 +57,12 @@ export type Ping =
50
57
  },
51
58
  ];
52
59
 
53
- export type Execute = <Path extends keyof $types["generated"]["routeSchema"]["$types"]>(
54
- path: Path,
55
- options?: Mixin<
56
- ExecuteOptions,
57
- {
58
- headers?: Record<string, string>;
59
- params?: $types["generated"]["routeSchema"]["$types"][Path]["params"];
60
- }
61
- >,
62
- ) => $types["generated"]["routeSchema"]["$types"][Path]["🐣"] extends boolean
63
- ? // action
64
- Promise<[Partial<$rejectCode>, null, ExecuteResultsOption] | [null, ExecuteActionResults<Path>, ExecuteResultsOption]>
65
- : // stream
66
- Promise<[Partial<$rejectCode>, null, ExecuteResultsOption] | [null, AsyncGenerator<[Partial<$rejectCode>, null] | [null, ExecuteStreamResults<Path>], null>, ExecuteResultsOption]>;
67
-
68
60
  export type ExecuteResultsOption = { executeId: string };
69
61
 
70
- export type ExecuteActionResults<Path extends keyof Generated["routeSchema"]["$types"], Generated extends $types["generated"] = $types["generated"]> = Generated["routeSchema"]["$types"][Path]["result"];
62
+ export type ExecuteActionResults<Path extends keyof Generated["routeSchema"], Generated extends $types["generated"] = $types["generated"]> = Generated["routeSchema"][Path]["result"];
71
63
 
72
- export type ExecuteStreamResults<Path extends keyof Generated["routeSchema"]["$types"], Generated extends $types["generated"] = $types["generated"]> = GeneratorGeneric<Generated["routeSchema"]["$types"][Path]["result"]>;
64
+ export type ExecuteStreamResults<Path extends keyof Generated["routeSchema"], Generated extends $types["generated"] = $types["generated"]> = GeneratorGeneric<Generated["routeSchema"][Path]["result"]>;
73
65
 
74
66
  export type MilkioResponseReject<Code extends keyof $rejectCode = keyof $rejectCode> = { success: false; code: Code; reject: $rejectCode[Code]; executeId: string };
75
67
 
76
- export type MilkioResponseSuccess<Path extends keyof Generated["routeSchema"]["$types"], Generated extends $types["generated"] = $types["generated"]> = { success: true; data: Generated["routeSchema"]["$types"][Path]["result"]; executeId: string };
68
+ export type MilkioResponseSuccess<Path extends keyof Generated["routeSchema"], Generated extends $types["generated"] = $types["generated"]> = { success: true; data: Generated["routeSchema"][Path]["result"]; executeId: string };
@@ -1,3 +1,11 @@
1
- import { createId as _createId } from "@paralleldrive/cuid2";
1
+ import { defineIdGenerator } from "milkid";
2
2
 
3
- export const createId = _createId;
3
+ const idGenerator = defineIdGenerator({
4
+ length: 32,
5
+ hyphen: false,
6
+ fingerprint: false,
7
+ timestamp: true,
8
+ sequential: false,
9
+ });
10
+
11
+ export const createId = idGenerator.createId;
File without changes