@flowgram.ai/runtime-nodejs 0.1.0 → 0.1.8

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/dist/esm/index.js DELETED
@@ -1,192 +0,0 @@
1
- // src/server/index.ts
2
- import { fastifyTRPCOpenApiPlugin } from "trpc-openapi";
3
- import fastify from "fastify";
4
- import { fastifyTRPCPlugin } from "@trpc/server/adapters/fastify";
5
- import { ServerInfoDefine } from "@flowgram.ai/runtime-interface";
6
- import ws from "@fastify/websocket";
7
- import fastifySwaggerUI from "@fastify/swagger-ui";
8
- import fastifySwagger from "@fastify/swagger";
9
- import cors from "@fastify/cors";
10
-
11
- // src/config/index.ts
12
- var ServerConfig = {
13
- name: "flowgram-runtime",
14
- title: "FlowGram Runtime",
15
- description: "FlowGram Runtime Demo",
16
- runtime: "nodejs",
17
- version: "0.0.1",
18
- dev: false,
19
- port: 4e3,
20
- basePath: "/api",
21
- docsPath: "/docs"
22
- };
23
-
24
- // src/api/index.ts
25
- import { FlowGramAPINames } from "@flowgram.ai/runtime-interface";
26
-
27
- // src/api/trpc.ts
28
- import { initTRPC } from "@trpc/server";
29
- var t = initTRPC.context().meta().create({
30
- errorFormatter({ shape }) {
31
- return shape;
32
- }
33
- });
34
- var router = t.router;
35
- var publicProcedure = t.procedure;
36
-
37
- // src/api/create-api.ts
38
- import z from "zod";
39
- import { WorkflowRuntimeAPIs } from "@flowgram.ai/runtime-js";
40
- import { FlowGramAPIMethod, FlowGramAPIs } from "@flowgram.ai/runtime-interface";
41
- var createAPI = (apiName) => {
42
- const define = FlowGramAPIs[apiName];
43
- const caller = WorkflowRuntimeAPIs[apiName];
44
- if (define.method === FlowGramAPIMethod.GET) {
45
- const procedure2 = publicProcedure.meta({
46
- openapi: {
47
- method: define.method,
48
- path: define.path,
49
- summary: define.name,
50
- tags: [define.module]
51
- }
52
- }).input(define.schema.input).output(z.union([define.schema.output, z.undefined()])).query(async (opts) => {
53
- const input = opts.input;
54
- try {
55
- const output = await caller(input);
56
- return output;
57
- } catch {
58
- return void 0;
59
- }
60
- });
61
- return {
62
- define,
63
- procedure: procedure2
64
- };
65
- }
66
- const procedure = publicProcedure.meta({
67
- openapi: {
68
- method: define.method,
69
- path: define.path,
70
- summary: define.name,
71
- tags: [define.module]
72
- }
73
- }).input(define.schema.input).output(z.union([define.schema.output, z.undefined()])).mutation(async (opts) => {
74
- const input = opts.input;
75
- try {
76
- const output = await caller(input);
77
- return output;
78
- } catch {
79
- return void 0;
80
- }
81
- });
82
- return {
83
- define,
84
- procedure
85
- };
86
- };
87
-
88
- // src/api/index.ts
89
- var APIS = FlowGramAPINames.map((apiName) => createAPI(apiName));
90
- var routers = APIS.reduce((acc, api) => {
91
- acc[api.define.path] = api.procedure;
92
- return acc;
93
- }, {});
94
- var appRouter = router(routers);
95
-
96
- // src/server/docs.ts
97
- import { generateOpenApiDocument } from "trpc-openapi";
98
- var serverDocument = generateOpenApiDocument(appRouter, {
99
- title: ServerConfig.title,
100
- description: ServerConfig.description,
101
- version: ServerConfig.version,
102
- baseUrl: `http://localhost:${ServerConfig.port}${ServerConfig.basePath}`,
103
- docsUrl: "https://flowgram.ai",
104
- tags: ["Task"]
105
- });
106
-
107
- // src/server/context.ts
108
- function createContext(ctx) {
109
- const { req, res } = ctx;
110
- return { req, res };
111
- }
112
-
113
- // src/server/index.ts
114
- async function createServer() {
115
- const server = fastify({ logger: ServerConfig.dev });
116
- await server.register(cors);
117
- await server.register(ws);
118
- await server.register(fastifyTRPCPlugin, {
119
- prefix: "/trpc",
120
- useWss: false,
121
- trpcOptions: { router: appRouter, createContext }
122
- });
123
- await server.register(fastifyTRPCOpenApiPlugin, {
124
- basePath: ServerConfig.basePath,
125
- router: appRouter,
126
- createContext
127
- });
128
- await server.register(fastifySwagger, {
129
- mode: "static",
130
- specification: { document: serverDocument },
131
- uiConfig: { displayOperationId: true },
132
- exposeRoute: true
133
- });
134
- await server.register(fastifySwaggerUI, {
135
- routePrefix: ServerConfig.docsPath,
136
- uiConfig: {
137
- docExpansion: "full",
138
- deepLinking: false
139
- },
140
- uiHooks: {
141
- onRequest: function(request, reply, next) {
142
- next();
143
- },
144
- preHandler: function(request, reply, next) {
145
- next();
146
- }
147
- },
148
- staticCSP: true,
149
- transformStaticCSP: (header) => header,
150
- transformSpecification: (swaggerObject, request, reply) => swaggerObject,
151
- transformSpecificationClone: true
152
- });
153
- server.get(ServerInfoDefine.path, async () => {
154
- const serverTime = /* @__PURE__ */ new Date();
155
- const output = {
156
- name: ServerConfig.name,
157
- title: ServerConfig.title,
158
- description: ServerConfig.description,
159
- runtime: ServerConfig.runtime,
160
- version: ServerConfig.version,
161
- time: serverTime.toISOString()
162
- };
163
- return output;
164
- });
165
- const stop = async () => {
166
- await server.close();
167
- };
168
- const start = async () => {
169
- try {
170
- const address = await server.listen({ port: ServerConfig.port });
171
- await server.ready();
172
- server.swagger();
173
- console.log(
174
- `> Listen Port: ${ServerConfig.port}
175
- > Server Address: ${address}
176
- > API Docs: http://localhost:4000/docs`
177
- );
178
- } catch (err) {
179
- server.log.error(err);
180
- process.exit(1);
181
- }
182
- };
183
- return { server, start, stop };
184
- }
185
-
186
- // src/index.ts
187
- async function main() {
188
- const server = await createServer();
189
- server.start();
190
- }
191
- main();
192
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/server/index.ts","../../src/config/index.ts","../../src/api/index.ts","../../src/api/trpc.ts","../../src/api/create-api.ts","../../src/server/docs.ts","../../src/server/context.ts","../../src/index.ts"],"sourcesContent":["import { fastifyTRPCOpenApiPlugin } from 'trpc-openapi';\nimport fastify from 'fastify';\nimport { fastifyTRPCPlugin } from '@trpc/server/adapters/fastify';\nimport { ServerInfoDefine, type ServerInfoOutput } from '@flowgram.ai/runtime-interface';\nimport ws from '@fastify/websocket';\nimport fastifySwaggerUI from '@fastify/swagger-ui';\nimport fastifySwagger from '@fastify/swagger';\nimport cors from '@fastify/cors';\n\nimport { ServerConfig } from '@config/index';\nimport { appRouter } from '@api/index';\nimport { serverDocument } from './docs';\nimport { createContext } from './context';\n\nexport async function createServer() {\n const server = fastify({ logger: ServerConfig.dev });\n\n await server.register(cors);\n await server.register(ws);\n await server.register(fastifyTRPCPlugin, {\n prefix: '/trpc',\n useWss: false,\n trpcOptions: { router: appRouter, createContext },\n });\n await server.register(fastifyTRPCOpenApiPlugin, {\n basePath: ServerConfig.basePath,\n router: appRouter,\n createContext,\n } as any);\n\n await server.register(fastifySwagger, {\n mode: 'static',\n specification: { document: serverDocument },\n uiConfig: { displayOperationId: true },\n exposeRoute: true,\n } as any);\n\n await server.register(fastifySwaggerUI, {\n routePrefix: ServerConfig.docsPath,\n uiConfig: {\n docExpansion: 'full',\n deepLinking: false,\n },\n uiHooks: {\n onRequest: function (request, reply, next) {\n next();\n },\n preHandler: function (request, reply, next) {\n next();\n },\n },\n staticCSP: true,\n transformStaticCSP: (header) => header,\n transformSpecification: (swaggerObject, request, reply) => swaggerObject,\n transformSpecificationClone: true,\n });\n\n server.get(ServerInfoDefine.path, async (): Promise<ServerInfoOutput> => {\n const serverTime = new Date();\n const output: ServerInfoOutput = {\n name: ServerConfig.name,\n title: ServerConfig.title,\n description: ServerConfig.description,\n runtime: ServerConfig.runtime,\n version: ServerConfig.version,\n time: serverTime.toISOString(),\n };\n return output;\n });\n\n const stop = async () => {\n await server.close();\n };\n const start = async () => {\n try {\n const address = await server.listen({ port: ServerConfig.port });\n await server.ready();\n server.swagger();\n console.log(\n `> Listen Port: ${ServerConfig.port}\\n> Server Address: ${address}\\n> API Docs: http://localhost:4000/docs`\n );\n } catch (err) {\n server.log.error(err);\n process.exit(1);\n }\n };\n\n return { server, start, stop };\n}\n","import type { ServerParams } from '@server/type';\n\nexport const ServerConfig: ServerParams = {\n name: 'flowgram-runtime',\n title: 'FlowGram Runtime',\n description: 'FlowGram Runtime Demo',\n runtime: 'nodejs',\n version: '0.0.1',\n dev: false,\n port: 4000,\n basePath: '/api',\n docsPath: '/docs',\n};\n","import { FlowGramAPINames } from '@flowgram.ai/runtime-interface';\n\nimport { APIRouter } from './type';\nimport { router } from './trpc';\nimport { createAPI } from './create-api';\n\nconst APIS = FlowGramAPINames.map((apiName) => createAPI(apiName));\n\nexport const routers = APIS.reduce((acc, api) => {\n acc[api.define.path] = api.procedure;\n return acc;\n}, {} as APIRouter);\n\nexport const appRouter = router(routers);\n\nexport type AppRouter = typeof appRouter;\n","import { OpenApiMeta } from 'trpc-openapi';\nimport { initTRPC } from '@trpc/server';\n\nimport type { Context } from '../server/context';\n\nconst t = initTRPC\n .context<Context>()\n .meta<OpenApiMeta>()\n .create({\n errorFormatter({ shape }) {\n return shape;\n },\n });\n\nexport const router = t.router;\nexport const publicProcedure = t.procedure;\n","import z from 'zod';\nimport { WorkflowRuntimeAPIs } from '@flowgram.ai/runtime-js';\nimport { FlowGramAPIMethod, FlowGramAPIName, FlowGramAPIs } from '@flowgram.ai/runtime-interface';\n\nimport { APIHandler } from './type';\nimport { publicProcedure } from './trpc';\n\nexport const createAPI = (apiName: FlowGramAPIName): APIHandler => {\n const define = FlowGramAPIs[apiName];\n const caller = WorkflowRuntimeAPIs[apiName];\n if (define.method === FlowGramAPIMethod.GET) {\n const procedure = publicProcedure\n .meta({\n openapi: {\n method: define.method,\n path: define.path,\n summary: define.name,\n tags: [define.module],\n },\n })\n .input(define.schema.input)\n .output(z.union([define.schema.output, z.undefined()]))\n .query(async (opts) => {\n const input = opts.input;\n try {\n const output = await caller(input);\n return output;\n } catch {\n return undefined;\n }\n });\n\n return {\n define,\n procedure: procedure as any,\n };\n }\n\n const procedure = publicProcedure\n .meta({\n openapi: {\n method: define.method,\n path: define.path,\n summary: define.name,\n tags: [define.module],\n },\n })\n .input(define.schema.input)\n .output(z.union([define.schema.output, z.undefined()]))\n .mutation(async (opts) => {\n const input = opts.input;\n try {\n const output = await caller(input);\n return output;\n } catch {\n return undefined;\n }\n });\n return {\n define,\n procedure: procedure as any,\n };\n};\n","import { generateOpenApiDocument } from 'trpc-openapi';\n\nimport { ServerConfig } from '@config/index';\nimport { appRouter } from '@api/index';\n\n// Generate OpenAPI schema document\nexport const serverDocument = generateOpenApiDocument(appRouter, {\n title: ServerConfig.title,\n description: ServerConfig.description,\n version: ServerConfig.version,\n baseUrl: `http://localhost:${ServerConfig.port}${ServerConfig.basePath}`,\n docsUrl: 'https://flowgram.ai',\n tags: ['Task'],\n});\n","import type { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify';\n\nexport function createContext(ctx: CreateFastifyContextOptions) {\n const { req, res } = ctx;\n return { req, res };\n}\n\nexport type Context = Awaited<ReturnType<typeof createContext>>;\n","import { createServer } from '@server/index';\n\nasync function main() {\n const server = await createServer();\n server.start();\n}\n\nmain();\n"],"mappings":";AAAA,SAAS,gCAAgC;AACzC,OAAO,aAAa;AACpB,SAAS,yBAAyB;AAClC,SAAS,wBAA+C;AACxD,OAAO,QAAQ;AACf,OAAO,sBAAsB;AAC7B,OAAO,oBAAoB;AAC3B,OAAO,UAAU;;;ACLV,IAAM,eAA6B;AAAA,EACxC,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS;AAAA,EACT,SAAS;AAAA,EACT,KAAK;AAAA,EACL,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AACZ;;;ACZA,SAAS,wBAAwB;;;ACCjC,SAAS,gBAAgB;AAIzB,IAAM,IAAI,SACP,QAAiB,EACjB,KAAkB,EAClB,OAAO;AAAA,EACN,eAAe,EAAE,MAAM,GAAG;AACxB,WAAO;AAAA,EACT;AACF,CAAC;AAEI,IAAM,SAAS,EAAE;AACjB,IAAM,kBAAkB,EAAE;;;ACfjC,OAAO,OAAO;AACd,SAAS,2BAA2B;AACpC,SAAS,mBAAoC,oBAAoB;AAK1D,IAAM,YAAY,CAAC,YAAyC;AACjE,QAAM,SAAS,aAAa,OAAO;AACnC,QAAM,SAAS,oBAAoB,OAAO;AAC1C,MAAI,OAAO,WAAW,kBAAk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WAAW;AAAA,IAChC,wBAAwB,CAAC,eAAe,SAAS,UAAU;AAAA,IAC3D,6BAA6B;AAAA,EAC/B,CAAC;AAED,SAAO,IAAI,iBAAiB,MAAM,YAAuC;AACvE,UAAM,aAAa,oBAAI,KAAK;AAC5B,UAAM,SAA2B;AAAA,MAC/B,MAAM,aAAa;AAAA,MACnB,OAAO,aAAa;AAAA,MACpB,aAAa,aAAa;AAAA,MAC1B,SAAS,aAAa;AAAA,MACtB,SAAS,aAAa;AAAA,MACtB,MAAM,WAAW,YAAY;AAAA,IAC/B;AACA,WAAO;AAAA,EACT,CAAC;AAED,QAAM,OAAO,YAAY;AACvB,UAAM,OAAO,MAAM;AAAA,EACrB;AACA,QAAM,QAAQ,YAAY;AACxB,QAAI;AACF,YAAM,UAAU,MAAM,OAAO,OAAO,EAAE,MAAM,aAAa,KAAK,CAAC;AAC/D,YAAM,OAAO,MAAM;AACnB,aAAO,QAAQ;AACf,cAAQ;AAAA,QACN,kBAAkB,aAAa,IAAI;AAAA,oBAAuB,OAAO;AAAA;AAAA,MACnE;AAAA,IACF,SAAS,KAAK;AACZ,aAAO,IAAI,MAAM,GAAG;AACpB,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AAEA,SAAO,EAAE,QAAQ,OAAO,KAAK;AAC/B;;;AOtFA,eAAe,OAAO;AACpB,QAAM,SAAS,MAAM,aAAa;AAClC,SAAO,MAAM;AACf;AAEA,KAAK;","names":["procedure"]}
package/dist/index.d.mts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { }
File without changes
@@ -1,21 +0,0 @@
1
- Invoking: npm run build:fast -- --dts-resolve
2
-
3
- > @flowgram.ai/runtime-nodejs@0.1.0 build:fast
4
- > tsup src/index.ts --format cjs,esm --sourcemap --legacy-output --dts-resolve
5
-
6
- CLI Building entry: src/index.ts
7
- CLI Using tsconfig: tsconfig.json
8
- CLI tsup v8.3.5
9
- CLI Target: esnext
10
- CJS Build start
11
- ESM Build start
12
- ESM dist/esm/index.js 5.09 KB
13
- ESM dist/esm/index.js.map 10.12 KB
14
- ESM ⚡️ Build success in 54ms
15
- CJS dist/index.js 6.67 KB
16
- CJS dist/index.js.map 10.28 KB
17
- CJS ⚡️ Build success in 62ms
18
- DTS Build start
19
- DTS ⚡️ Build success in 5441ms
20
- DTS dist/index.d.ts 13.00 B
21
- DTS dist/index.d.mts 13.00 B
@@ -1,63 +0,0 @@
1
- import z from 'zod';
2
- import { WorkflowRuntimeAPIs } from '@flowgram.ai/runtime-js';
3
- import { FlowGramAPIMethod, FlowGramAPIName, FlowGramAPIs } from '@flowgram.ai/runtime-interface';
4
-
5
- import { APIHandler } from './type';
6
- import { publicProcedure } from './trpc';
7
-
8
- export const createAPI = (apiName: FlowGramAPIName): APIHandler => {
9
- const define = FlowGramAPIs[apiName];
10
- const caller = WorkflowRuntimeAPIs[apiName];
11
- if (define.method === FlowGramAPIMethod.GET) {
12
- const procedure = publicProcedure
13
- .meta({
14
- openapi: {
15
- method: define.method,
16
- path: define.path,
17
- summary: define.name,
18
- tags: [define.module],
19
- },
20
- })
21
- .input(define.schema.input)
22
- .output(z.union([define.schema.output, z.undefined()]))
23
- .query(async (opts) => {
24
- const input = opts.input;
25
- try {
26
- const output = await caller(input);
27
- return output;
28
- } catch {
29
- return undefined;
30
- }
31
- });
32
-
33
- return {
34
- define,
35
- procedure: procedure as any,
36
- };
37
- }
38
-
39
- const procedure = publicProcedure
40
- .meta({
41
- openapi: {
42
- method: define.method,
43
- path: define.path,
44
- summary: define.name,
45
- tags: [define.module],
46
- },
47
- })
48
- .input(define.schema.input)
49
- .output(z.union([define.schema.output, z.undefined()]))
50
- .mutation(async (opts) => {
51
- const input = opts.input;
52
- try {
53
- const output = await caller(input);
54
- return output;
55
- } catch {
56
- return undefined;
57
- }
58
- });
59
- return {
60
- define,
61
- procedure: procedure as any,
62
- };
63
- };
package/src/api/index.ts DELETED
@@ -1,16 +0,0 @@
1
- import { FlowGramAPINames } from '@flowgram.ai/runtime-interface';
2
-
3
- import { APIRouter } from './type';
4
- import { router } from './trpc';
5
- import { createAPI } from './create-api';
6
-
7
- const APIS = FlowGramAPINames.map((apiName) => createAPI(apiName));
8
-
9
- export const routers = APIS.reduce((acc, api) => {
10
- acc[api.define.path] = api.procedure;
11
- return acc;
12
- }, {} as APIRouter);
13
-
14
- export const appRouter = router(routers);
15
-
16
- export type AppRouter = typeof appRouter;
package/src/api/trpc.ts DELETED
@@ -1,16 +0,0 @@
1
- import { OpenApiMeta } from 'trpc-openapi';
2
- import { initTRPC } from '@trpc/server';
3
-
4
- import type { Context } from '../server/context';
5
-
6
- const t = initTRPC
7
- .context<Context>()
8
- .meta<OpenApiMeta>()
9
- .create({
10
- errorFormatter({ shape }) {
11
- return shape;
12
- },
13
- });
14
-
15
- export const router = t.router;
16
- export const publicProcedure = t.procedure;
package/src/api/type.ts DELETED
@@ -1,9 +0,0 @@
1
- import { BuildProcedure } from '@trpc/server';
2
- import { FlowGramAPIDefine } from '@flowgram.ai/runtime-interface';
3
-
4
- export interface APIHandler {
5
- define: FlowGramAPIDefine;
6
- procedure: BuildProcedure<any, any, any>;
7
- }
8
-
9
- export type APIRouter = Record<FlowGramAPIDefine['path'], APIHandler['procedure']>;
@@ -1,13 +0,0 @@
1
- import type { ServerParams } from '@server/type';
2
-
3
- export const ServerConfig: ServerParams = {
4
- name: 'flowgram-runtime',
5
- title: 'FlowGram Runtime',
6
- description: 'FlowGram Runtime Demo',
7
- runtime: 'nodejs',
8
- version: '0.0.1',
9
- dev: false,
10
- port: 4000,
11
- basePath: '/api',
12
- docsPath: '/docs',
13
- };
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- import { createServer } from '@server/index';
2
-
3
- async function main() {
4
- const server = await createServer();
5
- server.start();
6
- }
7
-
8
- main();
@@ -1,8 +0,0 @@
1
- import type { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify';
2
-
3
- export function createContext(ctx: CreateFastifyContextOptions) {
4
- const { req, res } = ctx;
5
- return { req, res };
6
- }
7
-
8
- export type Context = Awaited<ReturnType<typeof createContext>>;
@@ -1,14 +0,0 @@
1
- import { generateOpenApiDocument } from 'trpc-openapi';
2
-
3
- import { ServerConfig } from '@config/index';
4
- import { appRouter } from '@api/index';
5
-
6
- // Generate OpenAPI schema document
7
- export const serverDocument = generateOpenApiDocument(appRouter, {
8
- title: ServerConfig.title,
9
- description: ServerConfig.description,
10
- version: ServerConfig.version,
11
- baseUrl: `http://localhost:${ServerConfig.port}${ServerConfig.basePath}`,
12
- docsUrl: 'https://flowgram.ai',
13
- tags: ['Task'],
14
- });
@@ -1,89 +0,0 @@
1
- import { fastifyTRPCOpenApiPlugin } from 'trpc-openapi';
2
- import fastify from 'fastify';
3
- import { fastifyTRPCPlugin } from '@trpc/server/adapters/fastify';
4
- import { ServerInfoDefine, type ServerInfoOutput } from '@flowgram.ai/runtime-interface';
5
- import ws from '@fastify/websocket';
6
- import fastifySwaggerUI from '@fastify/swagger-ui';
7
- import fastifySwagger from '@fastify/swagger';
8
- import cors from '@fastify/cors';
9
-
10
- import { ServerConfig } from '@config/index';
11
- import { appRouter } from '@api/index';
12
- import { serverDocument } from './docs';
13
- import { createContext } from './context';
14
-
15
- export async function createServer() {
16
- const server = fastify({ logger: ServerConfig.dev });
17
-
18
- await server.register(cors);
19
- await server.register(ws);
20
- await server.register(fastifyTRPCPlugin, {
21
- prefix: '/trpc',
22
- useWss: false,
23
- trpcOptions: { router: appRouter, createContext },
24
- });
25
- await server.register(fastifyTRPCOpenApiPlugin, {
26
- basePath: ServerConfig.basePath,
27
- router: appRouter,
28
- createContext,
29
- } as any);
30
-
31
- await server.register(fastifySwagger, {
32
- mode: 'static',
33
- specification: { document: serverDocument },
34
- uiConfig: { displayOperationId: true },
35
- exposeRoute: true,
36
- } as any);
37
-
38
- await server.register(fastifySwaggerUI, {
39
- routePrefix: ServerConfig.docsPath,
40
- uiConfig: {
41
- docExpansion: 'full',
42
- deepLinking: false,
43
- },
44
- uiHooks: {
45
- onRequest: function (request, reply, next) {
46
- next();
47
- },
48
- preHandler: function (request, reply, next) {
49
- next();
50
- },
51
- },
52
- staticCSP: true,
53
- transformStaticCSP: (header) => header,
54
- transformSpecification: (swaggerObject, request, reply) => swaggerObject,
55
- transformSpecificationClone: true,
56
- });
57
-
58
- server.get(ServerInfoDefine.path, async (): Promise<ServerInfoOutput> => {
59
- const serverTime = new Date();
60
- const output: ServerInfoOutput = {
61
- name: ServerConfig.name,
62
- title: ServerConfig.title,
63
- description: ServerConfig.description,
64
- runtime: ServerConfig.runtime,
65
- version: ServerConfig.version,
66
- time: serverTime.toISOString(),
67
- };
68
- return output;
69
- });
70
-
71
- const stop = async () => {
72
- await server.close();
73
- };
74
- const start = async () => {
75
- try {
76
- const address = await server.listen({ port: ServerConfig.port });
77
- await server.ready();
78
- server.swagger();
79
- console.log(
80
- `> Listen Port: ${ServerConfig.port}\n> Server Address: ${address}\n> API Docs: http://localhost:4000/docs`
81
- );
82
- } catch (err) {
83
- server.log.error(err);
84
- process.exit(1);
85
- }
86
- };
87
-
88
- return { server, start, stop };
89
- }
@@ -1,8 +0,0 @@
1
- import { ServerInfoOutput } from '@flowgram.ai/runtime-interface';
2
-
3
- export interface ServerParams extends Omit<ServerInfoOutput, 'time'> {
4
- dev: boolean;
5
- port: number;
6
- basePath: string;
7
- docsPath: string;
8
- }
package/tsconfig.json DELETED
@@ -1,48 +0,0 @@
1
- {
2
- "extends": "@flowgram.ai/ts-config/tsconfig.flow.path.json",
3
- "compilerOptions": {
4
- "target": "esnext",
5
- "lib": [
6
- "dom",
7
- "dom.iterable",
8
- "esnext"
9
- ],
10
- "allowJs": true,
11
- "skipLibCheck": true,
12
- "strict": true,
13
- "noEmit": true,
14
- "esModuleInterop": true,
15
- "module": "esnext",
16
- "moduleResolution": "bundler",
17
- "resolveJsonModule": true,
18
- "isolatedModules": true,
19
- "jsx": "preserve",
20
- "plugins": [],
21
- "baseUrl": "src",
22
- "paths": {
23
- "@api/*": [
24
- "api/*"
25
- ],
26
- "@application/*": [
27
- "application/*"
28
- ],
29
- "@server/*": [
30
- "server/*"
31
- ],
32
- "@config/*": [
33
- "config/*"
34
- ],
35
- "@workflow/*": [
36
- "workflow/*"
37
- ]
38
- }
39
- },
40
- "include": [
41
- "**/*.ts",
42
- "**/*.tsx",
43
- "src/workflow/executor/condition/constant.ts"
44
- ],
45
- "exclude": [
46
- "node_modules"
47
- ]
48
- }
package/vitest.config.ts DELETED
@@ -1,40 +0,0 @@
1
- import { config } from "dotenv";
2
- import path from 'path';
3
- import { defineConfig } from 'vitest/config';
4
-
5
- export default defineConfig({
6
- build: {
7
- commonjsOptions: {
8
- transformMixedEsModules: true,
9
- },
10
- },
11
- resolve: {
12
- alias: [
13
- {find: "@api", replacement: path.resolve(__dirname, './src/api') },
14
- {find: "@application", replacement: path.resolve(__dirname, './src/application') },
15
- {find: "@server", replacement: path.resolve(__dirname, './src/server') },
16
- {find: "@config", replacement: path.resolve(__dirname, './src/config') },
17
- {find: "@workflow", replacement: path.resolve(__dirname, './src/workflow') },
18
- ],
19
- },
20
- test: {
21
- globals: true,
22
- mockReset: false,
23
- environment: 'jsdom',
24
- testTimeout: 15000,
25
- setupFiles: [path.resolve(__dirname, './src/workflow/__tests__/setup.ts')],
26
- include: ['**/?(*.){test,spec}.?(c|m)[jt]s?(x)'],
27
- exclude: [
28
- '**/__mocks__**',
29
- '**/node_modules/**',
30
- '**/dist/**',
31
- '**/lib/**', // lib 编译结果忽略掉
32
- '**/cypress/**',
33
- '**/.{idea,git,cache,output,temp}/**',
34
- '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
35
- ],
36
- env: {
37
- ...config({ path: path.resolve(__dirname, './.env/.env.test') }).parsed
38
- }
39
- },
40
- });