@pipelab/shared 2.0.1-beta.20
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/.turbo/turbo-build.log +41 -0
- package/.turbo/turbo-lint.log +136 -0
- package/CHANGELOG.md +167 -0
- package/LICENSE +110 -0
- package/LICENSE.md +110 -0
- package/README.md +3 -0
- package/dist/index.d.mts +3603 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +43763 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +53 -0
- package/src/apis.ts +191 -0
- package/src/build-history.ts +127 -0
- package/src/config/migrators.ts +308 -0
- package/src/config/projects-definition.ts +25 -0
- package/src/config/projects-types.ts +25 -0
- package/src/config/projects.ts +1 -0
- package/src/config/settings-definition.ts +21 -0
- package/src/config/settings.ts +21 -0
- package/src/config.schema.ts +149 -0
- package/src/database.types.ts +95 -0
- package/src/errors.ts +11 -0
- package/src/evaluator.ts +58 -0
- package/src/fmt.ts +5 -0
- package/src/graph.ts +207 -0
- package/src/i18n/de_DE.json +86 -0
- package/src/i18n/en_US.json +147 -0
- package/src/i18n/es_ES.json +86 -0
- package/src/i18n/fr_FR.json +89 -0
- package/src/i18n/pt_BR.json +86 -0
- package/src/i18n/zh_CN.json +86 -0
- package/src/i18n-utils.ts +10 -0
- package/src/index.ts +51 -0
- package/src/ipc.types.ts +73 -0
- package/src/logger.ts +20 -0
- package/src/migrations/model.ts +1 -0
- package/src/migrations/projects.ts +1 -0
- package/src/migrations/settings.ts +1 -0
- package/src/model.test.ts +214 -0
- package/src/model.ts +233 -0
- package/src/plugins/definitions.ts +472 -0
- package/src/plugins.ts +20 -0
- package/src/quickjs.ts +98 -0
- package/src/save-location.ts +42 -0
- package/src/subscription-errors.ts +87 -0
- package/src/supabase.ts +28 -0
- package/src/tests/helpers.ts +5 -0
- package/src/types.ts +3 -0
- package/src/utils.ts +3 -0
- package/src/validation.ts +16 -0
- package/src/variables.ts +27 -0
- package/src/wasm.d.ts +9 -0
- package/src/websocket.types.ts +186 -0
- package/tsconfig.json +13 -0
package/src/supabase.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createClient } from "@supabase/supabase-js";
|
|
2
|
+
import { Database } from "./database.types";
|
|
3
|
+
|
|
4
|
+
const getSupabaseConfig = () => {
|
|
5
|
+
const url = process.env.SUPABASE_URL || "";
|
|
6
|
+
const anonKey = process.env.SUPABASE_ANON_KEY || "";
|
|
7
|
+
return { url, anonKey };
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const isSupabaseAvailable = () => {
|
|
11
|
+
const { url, anonKey } = getSupabaseConfig();
|
|
12
|
+
const available = !!(url && anonKey);
|
|
13
|
+
|
|
14
|
+
return available;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const supabase = (options?: any) => {
|
|
18
|
+
const { url, anonKey } = getSupabaseConfig();
|
|
19
|
+
if (!url || !anonKey) {
|
|
20
|
+
if (process.env.NODE_ENV !== "test") {
|
|
21
|
+
console.warn(
|
|
22
|
+
"Supabase environment variables are not configured. Supabase will not be available.",
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return createClient<Database>(url, anonKey, options);
|
|
28
|
+
};
|
package/src/types.ts
ADDED
package/src/utils.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { InputDefinition } from "./plugins/definitions";
|
|
2
|
+
|
|
3
|
+
export const isRequired = (param: InputDefinition) => {
|
|
4
|
+
return param.required === true;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const isRenderer = () => {
|
|
8
|
+
// running in a web browser
|
|
9
|
+
if (typeof process === "undefined") return true;
|
|
10
|
+
|
|
11
|
+
// node-integration is disabled
|
|
12
|
+
if (!process) return true;
|
|
13
|
+
|
|
14
|
+
// @ts-expect-error
|
|
15
|
+
return process.browser === true || process.title === "browser";
|
|
16
|
+
};
|
package/src/variables.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CreateQuickJSFn } from "./quickjs";
|
|
2
|
+
|
|
3
|
+
export interface VariableBase {
|
|
4
|
+
value: string;
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type Variable = VariableBase;
|
|
11
|
+
|
|
12
|
+
export const variableToFormattedVariable = async (
|
|
13
|
+
vm: Awaited<CreateQuickJSFn>,
|
|
14
|
+
variables: Variable[],
|
|
15
|
+
) => {
|
|
16
|
+
const result: Record<string, string> = {};
|
|
17
|
+
for (const variable of variables) {
|
|
18
|
+
console.log("variable.value", variable.value);
|
|
19
|
+
const variableResult = await vm.run(variable.value, {
|
|
20
|
+
params: {},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
result[variable.id] = variableResult;
|
|
24
|
+
// result[variable.id] = variable.value
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
};
|
package/src/wasm.d.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Channels, Data, Events, End, IpcMessage, RequestId } from "./apis";
|
|
2
|
+
import { WebSocket as WSWebSocket } from "ws";
|
|
3
|
+
|
|
4
|
+
// WebSocket connection states
|
|
5
|
+
export type WebSocketConnectionState =
|
|
6
|
+
| "connecting"
|
|
7
|
+
| "connected"
|
|
8
|
+
| "disconnected"
|
|
9
|
+
| "error"
|
|
10
|
+
| "reconnecting";
|
|
11
|
+
|
|
12
|
+
// WebSocket server types
|
|
13
|
+
export interface WebSocketServerConfig {
|
|
14
|
+
port?: number;
|
|
15
|
+
host?: string;
|
|
16
|
+
maxReconnectAttempts?: number;
|
|
17
|
+
reconnectDelay?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface WebSocketServerEvents {
|
|
21
|
+
connection: (ws: WSWebSocket, request: IncomingMessage) => void;
|
|
22
|
+
message: (ws: WSWebSocket, data: Buffer) => void;
|
|
23
|
+
close: (ws: WSWebSocket) => void;
|
|
24
|
+
error: (ws: WSWebSocket, error: Error) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// WebSocket client types
|
|
28
|
+
export interface WebSocketClientConfig {
|
|
29
|
+
url?: string;
|
|
30
|
+
maxReconnectAttempts?: number;
|
|
31
|
+
reconnectDelay?: number;
|
|
32
|
+
timeout?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface WebSocketClientEvents {
|
|
36
|
+
open: () => void;
|
|
37
|
+
message: (event: MessageEvent) => void;
|
|
38
|
+
close: (event: CloseEvent) => void;
|
|
39
|
+
error: (error: Event) => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Unified WebSocket event types
|
|
43
|
+
export interface WebSocketEvent {
|
|
44
|
+
sender: string;
|
|
45
|
+
timestamp?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// WebSocket message types
|
|
49
|
+
export interface WebSocketRequestMessage {
|
|
50
|
+
channel: Channels;
|
|
51
|
+
requestId: RequestId;
|
|
52
|
+
data: any;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface WebSocketResponseMessage {
|
|
56
|
+
type: "response";
|
|
57
|
+
requestId: RequestId;
|
|
58
|
+
events: Events<any>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface WebSocketErrorMessage {
|
|
62
|
+
type: "error";
|
|
63
|
+
requestId: RequestId;
|
|
64
|
+
error: string;
|
|
65
|
+
code?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type WebSocketMessage =
|
|
69
|
+
| WebSocketRequestMessage
|
|
70
|
+
| WebSocketResponseMessage
|
|
71
|
+
| WebSocketErrorMessage;
|
|
72
|
+
|
|
73
|
+
// WebSocket connection info
|
|
74
|
+
export interface WebSocketConnectionInfo {
|
|
75
|
+
id: string;
|
|
76
|
+
state: WebSocketConnectionState;
|
|
77
|
+
url: string;
|
|
78
|
+
connectedAt?: Date;
|
|
79
|
+
lastActivity?: Date;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface Agent {
|
|
83
|
+
id: string;
|
|
84
|
+
name: string;
|
|
85
|
+
isSelf: boolean;
|
|
86
|
+
connectedAt?: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Handler function types
|
|
90
|
+
export type WebSocketHandler<KEY extends Channels> = (
|
|
91
|
+
event: WebSocketEvent,
|
|
92
|
+
data: { value: Data<KEY>; send: WebSocketSendFunction<KEY> },
|
|
93
|
+
) => Promise<void>;
|
|
94
|
+
|
|
95
|
+
export type WebSocketSendFunction<KEY extends Channels> = (events: Events<KEY>) => Promise<void>;
|
|
96
|
+
|
|
97
|
+
// WebSocket listener types
|
|
98
|
+
export type WebSocketListener<KEY extends Channels> = (event: Events<KEY>) => Promise<void>;
|
|
99
|
+
|
|
100
|
+
// WebSocket API interface
|
|
101
|
+
export interface WebSocketAPI {
|
|
102
|
+
execute: <KEY extends Channels>(
|
|
103
|
+
channel: KEY,
|
|
104
|
+
data?: Data<KEY>,
|
|
105
|
+
listener?: WebSocketListener<KEY>,
|
|
106
|
+
) => Promise<End<KEY>>;
|
|
107
|
+
send: <KEY extends Channels>(channel: KEY, data?: Data<KEY>) => Promise<End<KEY>>;
|
|
108
|
+
on: <KEY extends Channels>(
|
|
109
|
+
channel: KEY,
|
|
110
|
+
listener: (event: WebSocketEvent, data: Events<KEY>) => void,
|
|
111
|
+
) => () => void;
|
|
112
|
+
isConnected: () => boolean;
|
|
113
|
+
disconnect: () => void;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// WebSocket manager interface
|
|
117
|
+
export interface WebSocketManager {
|
|
118
|
+
connect: (url?: string) => Promise<void>;
|
|
119
|
+
disconnect: () => void;
|
|
120
|
+
send: <KEY extends Channels>(channel: KEY, data?: Data<KEY>) => Promise<End<KEY>>;
|
|
121
|
+
isConnected: () => boolean;
|
|
122
|
+
getConnectionState: () => WebSocketConnectionState;
|
|
123
|
+
onStateChange: (callback: (state: WebSocketConnectionState) => void) => () => void;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Error types
|
|
127
|
+
export class WebSocketError extends Error {
|
|
128
|
+
constructor(
|
|
129
|
+
message: string,
|
|
130
|
+
public code?: string,
|
|
131
|
+
public requestId?: RequestId,
|
|
132
|
+
) {
|
|
133
|
+
super(message);
|
|
134
|
+
this.name = "WebSocketError";
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export class WebSocketConnectionError extends WebSocketError {
|
|
139
|
+
constructor(
|
|
140
|
+
message: string,
|
|
141
|
+
public url?: string,
|
|
142
|
+
) {
|
|
143
|
+
super(message);
|
|
144
|
+
this.name = "WebSocketConnectionError";
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export class WebSocketTimeoutError extends WebSocketError {
|
|
149
|
+
constructor(
|
|
150
|
+
message: string,
|
|
151
|
+
public timeout: number,
|
|
152
|
+
requestId?: RequestId,
|
|
153
|
+
) {
|
|
154
|
+
super(message);
|
|
155
|
+
this.name = "WebSocketTimeoutError";
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Type guards
|
|
160
|
+
export const isWebSocketRequestMessage = (message: any): message is WebSocketRequestMessage => {
|
|
161
|
+
return message && typeof message.channel === "string" && message.requestId;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const isWebSocketResponseMessage = (message: any): message is WebSocketResponseMessage => {
|
|
165
|
+
return message && message.type === "response" && message.requestId && message.events;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export const isWebSocketErrorMessage = (message: any): message is WebSocketErrorMessage => {
|
|
169
|
+
return message && message.type === "error" && message.requestId && message.error;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// Utility types for better type inference
|
|
173
|
+
export type WebSocketMessageType<T extends Channels> = {
|
|
174
|
+
channel: T;
|
|
175
|
+
requestId: RequestId;
|
|
176
|
+
data: Data<T>;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export type WebSocketResponseType<T extends Channels> = {
|
|
180
|
+
type: "response";
|
|
181
|
+
requestId: RequestId;
|
|
182
|
+
events: Events<T>;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// Import for Node.js HTTP server
|
|
186
|
+
import { IncomingMessage } from "http";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig/commonjs.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"emitDeclarationOnly": true,
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"baseUrl": ".",
|
|
7
|
+
"typeRoots": ["./src"],
|
|
8
|
+
"types": ["global.d.ts", "wasm.d.ts"]
|
|
9
|
+
},
|
|
10
|
+
"include": ["src/**/*", "tests/**/*", "*.ts", "src/**/*.json"],
|
|
11
|
+
"exclude": ["node_modules", "dist"],
|
|
12
|
+
"references": [{ "path": "../migration" }]
|
|
13
|
+
}
|