@514labs/moose-lib 0.6.320 → 0.6.321-ci-5-ga23d35fe
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/browserCompatible.d.mts +7 -3
- package/dist/browserCompatible.d.ts +7 -3
- package/dist/browserCompatible.js +197 -180
- package/dist/browserCompatible.js.map +1 -1
- package/dist/browserCompatible.mjs +196 -180
- package/dist/browserCompatible.mjs.map +1 -1
- package/dist/compilerPlugin.js.map +1 -1
- package/dist/compilerPlugin.mjs.map +1 -1
- package/dist/dataModels/toDataModels.js.map +1 -1
- package/dist/dataModels/toDataModels.mjs.map +1 -1
- package/dist/dmv2/index.d.mts +2 -1
- package/dist/dmv2/index.d.ts +2 -1
- package/dist/dmv2/index.js +41 -24
- package/dist/dmv2/index.js.map +1 -1
- package/dist/dmv2/index.mjs +40 -24
- package/dist/dmv2/index.mjs.map +1 -1
- package/dist/{index-C4miZc-A.d.mts → index-Aq9KzsRd.d.mts} +181 -33
- package/dist/{index-C4miZc-A.d.ts → index-Aq9KzsRd.d.ts} +181 -33
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +176 -202
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +176 -199
- package/dist/index.mjs.map +1 -1
- package/dist/moose-runner.js +88 -257
- package/dist/moose-runner.js.map +1 -1
- package/dist/moose-runner.mjs +89 -258
- package/dist/moose-runner.mjs.map +1 -1
- package/dist/scripts/workflow.js +9 -11
- package/dist/scripts/workflow.js.map +1 -1
- package/dist/scripts/workflow.mjs +9 -11
- package/dist/scripts/workflow.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/browserCompatible-BVw4gSAN.d.mts +0 -184
- package/dist/browserCompatible-rK8ei0bt.d.ts +0 -184
package/dist/scripts/workflow.js
CHANGED
|
@@ -39,7 +39,7 @@ var mooseJsonEncode = (data) => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
// src/scripts/workflow.ts
|
|
42
|
-
var {
|
|
42
|
+
var { getWorkflowByName, getTaskForWorkflow } = (0, import_workflow.proxyActivities)({
|
|
43
43
|
startToCloseTimeout: "1 minutes",
|
|
44
44
|
retry: {
|
|
45
45
|
maximumAttempts: 1
|
|
@@ -49,9 +49,7 @@ async function ScriptWorkflow(request, inputData) {
|
|
|
49
49
|
const state = {
|
|
50
50
|
completedSteps: [],
|
|
51
51
|
currentStep: null,
|
|
52
|
-
failedStep: null
|
|
53
|
-
scriptPath: null,
|
|
54
|
-
inputData: null
|
|
52
|
+
failedStep: null
|
|
55
53
|
};
|
|
56
54
|
const results = [];
|
|
57
55
|
const workflowName = request.workflow_name;
|
|
@@ -61,9 +59,9 @@ async function ScriptWorkflow(request, inputData) {
|
|
|
61
59
|
);
|
|
62
60
|
try {
|
|
63
61
|
currentData = JSON.parse(mooseJsonEncode(currentData));
|
|
64
|
-
const workflow = await
|
|
62
|
+
const workflow = await getWorkflowByName(workflowName);
|
|
65
63
|
const task = request.execution_mode === "start" ? workflow.config.startingTask : await getTaskForWorkflow(workflowName, request.continue_from_task);
|
|
66
|
-
const result = await
|
|
64
|
+
const result = await handleTask(workflow, task, currentData);
|
|
67
65
|
results.push(...result);
|
|
68
66
|
return results;
|
|
69
67
|
} catch (error) {
|
|
@@ -71,7 +69,7 @@ async function ScriptWorkflow(request, inputData) {
|
|
|
71
69
|
throw error;
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
|
-
async function
|
|
72
|
+
async function handleTask(workflow, task, inputData) {
|
|
75
73
|
const configTimeout = task.config.timeout;
|
|
76
74
|
let taskTimeout;
|
|
77
75
|
if (!configTimeout) {
|
|
@@ -97,7 +95,7 @@ async function handleDmv2Task(workflow, task, inputData) {
|
|
|
97
95
|
} else {
|
|
98
96
|
activityOptions.scheduleToCloseTimeout = "87600h";
|
|
99
97
|
}
|
|
100
|
-
const {
|
|
98
|
+
const { executeTask } = (0, import_workflow.proxyActivities)(activityOptions);
|
|
101
99
|
let taskCompleted = false;
|
|
102
100
|
const monitorTask = async () => {
|
|
103
101
|
import_workflow.log.info(`Monitor task starting for ${task.name}`);
|
|
@@ -116,7 +114,7 @@ async function handleDmv2Task(workflow, task, inputData) {
|
|
|
116
114
|
import_workflow.log.info(`Monitor task exiting because main task completed`);
|
|
117
115
|
};
|
|
118
116
|
const result = await Promise.race([
|
|
119
|
-
|
|
117
|
+
executeTask(workflow, task, inputData).then((taskResult) => {
|
|
120
118
|
return {
|
|
121
119
|
type: "task_completed",
|
|
122
120
|
data: taskResult
|
|
@@ -136,12 +134,12 @@ async function handleDmv2Task(workflow, task, inputData) {
|
|
|
136
134
|
return results;
|
|
137
135
|
}
|
|
138
136
|
for (const childTask of task.config.onComplete) {
|
|
139
|
-
const childResult = await
|
|
137
|
+
const childResult = await handleTask(workflow, childTask, result.data);
|
|
140
138
|
results.push(...childResult);
|
|
141
139
|
}
|
|
142
140
|
if (task.name.endsWith("_extract") && result && typeof result === "object" && result.data && typeof result.data === "object" && "hasMore" in result.data && result.data.hasMore === true) {
|
|
143
141
|
import_workflow.log.info(`Extract task ${task.name} has more data, restarting chain...`);
|
|
144
|
-
const nextBatchResults = await
|
|
142
|
+
const nextBatchResults = await handleTask(workflow, task, null);
|
|
145
143
|
results.push(...nextBatchResults);
|
|
146
144
|
}
|
|
147
145
|
return results;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/scripts/workflow.ts","../../src/scripts/serialization.ts"],"sourcesContent":["import {\n log as logger,\n ActivityOptions,\n proxyActivities,\n workflowInfo,\n continueAsNew,\n sleep,\n} from \"@temporalio/workflow\";\nimport { Duration } from \"@temporalio/common\";\nimport { Task, Workflow } from \"../dmv2\";\n\nimport { WorkflowState } from \"./types\";\nimport { mooseJsonEncode } from \"./serialization\";\n\ninterface WorkflowRequest {\n workflow_name: string;\n execution_mode: \"start\" | \"continue_as_new\";\n continue_from_task?: string; // Only for continue_as_new\n}\n\nconst {
|
|
1
|
+
{"version":3,"sources":["../../src/scripts/workflow.ts","../../src/scripts/serialization.ts"],"sourcesContent":["import {\n log as logger,\n ActivityOptions,\n proxyActivities,\n workflowInfo,\n continueAsNew,\n sleep,\n} from \"@temporalio/workflow\";\nimport { Duration } from \"@temporalio/common\";\nimport { Task, Workflow } from \"../dmv2\";\n\nimport { WorkflowState } from \"./types\";\nimport { mooseJsonEncode } from \"./serialization\";\n\ninterface WorkflowRequest {\n workflow_name: string;\n execution_mode: \"start\" | \"continue_as_new\";\n continue_from_task?: string; // Only for continue_as_new\n}\n\nconst { getWorkflowByName, getTaskForWorkflow } = proxyActivities({\n startToCloseTimeout: \"1 minutes\",\n retry: {\n maximumAttempts: 1,\n },\n});\n\nexport async function ScriptWorkflow(\n request: WorkflowRequest,\n inputData?: any,\n): Promise<any[]> {\n const state: WorkflowState = {\n completedSteps: [],\n currentStep: null,\n failedStep: null,\n };\n\n const results: any[] = [];\n const workflowName = request.workflow_name;\n let currentData = inputData?.data || inputData || {};\n\n logger.info(\n `Starting workflow: ${workflowName} (mode: ${request.execution_mode}) with data: ${JSON.stringify(currentData)}`,\n );\n\n try {\n currentData = JSON.parse(mooseJsonEncode(currentData));\n const workflow = await getWorkflowByName(workflowName);\n const task =\n request.execution_mode === \"start\" ?\n workflow.config.startingTask\n : await getTaskForWorkflow(workflowName, request.continue_from_task!);\n const result = await handleTask(workflow, task, currentData);\n results.push(...result);\n\n return results;\n } catch (error) {\n state.failedStep = workflowName;\n throw error;\n }\n}\n\nasync function handleTask(\n workflow: Workflow,\n task: Task<any, any>,\n inputData: any,\n): Promise<any[]> {\n // Handle timeout configuration\n const configTimeout = task.config.timeout;\n let taskTimeout: Duration | undefined;\n\n if (!configTimeout) {\n taskTimeout = \"1h\";\n } else if (configTimeout === \"never\") {\n taskTimeout = undefined;\n } else {\n taskTimeout = configTimeout as Duration;\n }\n\n const taskRetries = task.config.retries ?? 3;\n\n const timeoutMessage =\n taskTimeout ? `with timeout ${taskTimeout}` : \"with no timeout (unlimited)\";\n logger.info(\n `Handling task ${task.name} ${timeoutMessage} and retries ${taskRetries}`,\n );\n\n const activityOptions: ActivityOptions = {\n heartbeatTimeout: \"10s\",\n retry: {\n maximumAttempts: taskRetries,\n },\n };\n\n // Temporal requires either startToCloseTimeout OR scheduleToCloseTimeout to be set\n // For unlimited timeout (timeout = \"none\"), we use scheduleToCloseTimeout with a very large value\n // For normal timeouts, we use startToCloseTimeout for single execution timeout\n if (taskTimeout) {\n // Normal timeout - limit each individual execution attempt\n activityOptions.startToCloseTimeout = taskTimeout;\n } else {\n // Unlimited timeout - set scheduleToCloseTimeout to a very large value (10 years)\n // This satisfies Temporal's requirement while effectively allowing unlimited execution\n activityOptions.scheduleToCloseTimeout = \"87600h\"; // 10 years\n }\n\n const { executeTask } = proxyActivities(activityOptions);\n\n let taskCompleted = false;\n\n const monitorTask = async () => {\n logger.info(`Monitor task starting for ${task.name}`);\n while (!taskCompleted) {\n const info = workflowInfo();\n\n // Continue-as-new only when suggested by Temporal\n if (info.continueAsNewSuggested) {\n logger.info(`ContinueAsNew suggested by Temporal`);\n return await continueAsNew({\n workflow_name: workflow.name,\n execution_mode: \"continue_as_new\" as const,\n continue_from_task: task.name,\n });\n }\n\n await sleep(100);\n }\n logger.info(`Monitor task exiting because main task completed`);\n };\n\n const result = await Promise.race([\n executeTask(workflow, task, inputData)\n .then((taskResult) => {\n return {\n type: \"task_completed\" as const,\n data: taskResult,\n };\n })\n .finally(() => {\n taskCompleted = true;\n }),\n monitorTask().then(() => {\n return { type: \"continue_as_new\" as const, data: undefined };\n }),\n ]);\n\n if (result.type !== \"task_completed\") {\n return [];\n }\n\n const results = [result.data];\n if (!task.config.onComplete?.length) {\n return results;\n }\n\n for (const childTask of task.config.onComplete) {\n const childResult = await handleTask(workflow, childTask, result.data);\n results.push(...childResult);\n }\n\n // Check if this is an ETL extract task that needs to loop\n // ETL extract tasks end with \"_extract\" and return BatchResult with hasMore\n if (\n task.name.endsWith(\"_extract\") &&\n result &&\n typeof result === \"object\" &&\n result.data &&\n typeof result.data === \"object\" &&\n \"hasMore\" in result.data &&\n (result.data as any).hasMore === true\n ) {\n logger.info(`Extract task ${task.name} has more data, restarting chain...`);\n\n // Recursively call the extract task again to get the next batch\n const nextBatchResults = await handleTask(workflow, task, null);\n results.push(...nextBatchResults);\n }\n\n return results;\n}\n","// Add serialization helpers\nexport const mooseJsonEncode = (data: any): string => {\n return JSON.stringify(data, (_, value) => {\n if (value instanceof Map) {\n return {\n __type: \"Map\",\n value: Array.from(value.entries()),\n };\n }\n return value;\n });\n};\n\nexport const mooseJsonDecode = (text: string): any => {\n return JSON.parse(text, (_, value) => {\n if (value && typeof value === \"object\" && value.__type === \"Map\") {\n return new Map(value.value);\n }\n return value;\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAOO;;;ACNA,IAAM,kBAAkB,CAAC,SAAsB;AACpD,SAAO,KAAK,UAAU,MAAM,CAAC,GAAG,UAAU;AACxC,QAAI,iBAAiB,KAAK;AACxB,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,OAAO,MAAM,KAAK,MAAM,QAAQ,CAAC;AAAA,MACnC;AAAA,IACF;AACA,WAAO;AAAA,EACT,CAAC;AACH;;;ADSA,IAAM,EAAE,mBAAmB,mBAAmB,QAAI,iCAAgB;AAAA,EAChE,qBAAqB;AAAA,EACrB,OAAO;AAAA,IACL,iBAAiB;AAAA,EACnB;AACF,CAAC;AAED,eAAsB,eACpB,SACA,WACgB;AAChB,QAAM,QAAuB;AAAA,IAC3B,gBAAgB,CAAC;AAAA,IACjB,aAAa;AAAA,IACb,YAAY;AAAA,EACd;AAEA,QAAM,UAAiB,CAAC;AACxB,QAAM,eAAe,QAAQ;AAC7B,MAAI,cAAc,WAAW,QAAQ,aAAa,CAAC;AAEnD,kBAAAA,IAAO;AAAA,IACL,sBAAsB,YAAY,WAAW,QAAQ,cAAc,gBAAgB,KAAK,UAAU,WAAW,CAAC;AAAA,EAChH;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-
var {
|
|
24
|
+
var { getWorkflowByName, getTaskForWorkflow } = proxyActivities({
|
|
25
25
|
startToCloseTimeout: "1 minutes",
|
|
26
26
|
retry: {
|
|
27
27
|
maximumAttempts: 1
|
|
@@ -31,9 +31,7 @@ async function ScriptWorkflow(request, inputData) {
|
|
|
31
31
|
const state = {
|
|
32
32
|
completedSteps: [],
|
|
33
33
|
currentStep: null,
|
|
34
|
-
failedStep: null
|
|
35
|
-
scriptPath: null,
|
|
36
|
-
inputData: null
|
|
34
|
+
failedStep: null
|
|
37
35
|
};
|
|
38
36
|
const results = [];
|
|
39
37
|
const workflowName = request.workflow_name;
|
|
@@ -43,9 +41,9 @@ async function ScriptWorkflow(request, inputData) {
|
|
|
43
41
|
);
|
|
44
42
|
try {
|
|
45
43
|
currentData = JSON.parse(mooseJsonEncode(currentData));
|
|
46
|
-
const workflow = await
|
|
44
|
+
const workflow = await getWorkflowByName(workflowName);
|
|
47
45
|
const task = request.execution_mode === "start" ? workflow.config.startingTask : await getTaskForWorkflow(workflowName, request.continue_from_task);
|
|
48
|
-
const result = await
|
|
46
|
+
const result = await handleTask(workflow, task, currentData);
|
|
49
47
|
results.push(...result);
|
|
50
48
|
return results;
|
|
51
49
|
} catch (error) {
|
|
@@ -53,7 +51,7 @@ async function ScriptWorkflow(request, inputData) {
|
|
|
53
51
|
throw error;
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
|
-
async function
|
|
54
|
+
async function handleTask(workflow, task, inputData) {
|
|
57
55
|
const configTimeout = task.config.timeout;
|
|
58
56
|
let taskTimeout;
|
|
59
57
|
if (!configTimeout) {
|
|
@@ -79,7 +77,7 @@ async function handleDmv2Task(workflow, task, inputData) {
|
|
|
79
77
|
} else {
|
|
80
78
|
activityOptions.scheduleToCloseTimeout = "87600h";
|
|
81
79
|
}
|
|
82
|
-
const {
|
|
80
|
+
const { executeTask } = proxyActivities(activityOptions);
|
|
83
81
|
let taskCompleted = false;
|
|
84
82
|
const monitorTask = async () => {
|
|
85
83
|
logger.info(`Monitor task starting for ${task.name}`);
|
|
@@ -98,7 +96,7 @@ async function handleDmv2Task(workflow, task, inputData) {
|
|
|
98
96
|
logger.info(`Monitor task exiting because main task completed`);
|
|
99
97
|
};
|
|
100
98
|
const result = await Promise.race([
|
|
101
|
-
|
|
99
|
+
executeTask(workflow, task, inputData).then((taskResult) => {
|
|
102
100
|
return {
|
|
103
101
|
type: "task_completed",
|
|
104
102
|
data: taskResult
|
|
@@ -118,12 +116,12 @@ async function handleDmv2Task(workflow, task, inputData) {
|
|
|
118
116
|
return results;
|
|
119
117
|
}
|
|
120
118
|
for (const childTask of task.config.onComplete) {
|
|
121
|
-
const childResult = await
|
|
119
|
+
const childResult = await handleTask(workflow, childTask, result.data);
|
|
122
120
|
results.push(...childResult);
|
|
123
121
|
}
|
|
124
122
|
if (task.name.endsWith("_extract") && result && typeof result === "object" && result.data && typeof result.data === "object" && "hasMore" in result.data && result.data.hasMore === true) {
|
|
125
123
|
logger.info(`Extract task ${task.name} has more data, restarting chain...`);
|
|
126
|
-
const nextBatchResults = await
|
|
124
|
+
const nextBatchResults = await handleTask(workflow, task, null);
|
|
127
125
|
results.push(...nextBatchResults);
|
|
128
126
|
}
|
|
129
127
|
return results;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/scripts/workflow.ts","../../src/scripts/serialization.ts"],"sourcesContent":["import {\n log as logger,\n ActivityOptions,\n proxyActivities,\n workflowInfo,\n continueAsNew,\n sleep,\n} from \"@temporalio/workflow\";\nimport { Duration } from \"@temporalio/common\";\nimport { Task, Workflow } from \"../dmv2\";\n\nimport { WorkflowState } from \"./types\";\nimport { mooseJsonEncode } from \"./serialization\";\n\ninterface WorkflowRequest {\n workflow_name: string;\n execution_mode: \"start\" | \"continue_as_new\";\n continue_from_task?: string; // Only for continue_as_new\n}\n\nconst {
|
|
1
|
+
{"version":3,"sources":["../../src/scripts/workflow.ts","../../src/scripts/serialization.ts"],"sourcesContent":["import {\n log as logger,\n ActivityOptions,\n proxyActivities,\n workflowInfo,\n continueAsNew,\n sleep,\n} from \"@temporalio/workflow\";\nimport { Duration } from \"@temporalio/common\";\nimport { Task, Workflow } from \"../dmv2\";\n\nimport { WorkflowState } from \"./types\";\nimport { mooseJsonEncode } from \"./serialization\";\n\ninterface WorkflowRequest {\n workflow_name: string;\n execution_mode: \"start\" | \"continue_as_new\";\n continue_from_task?: string; // Only for continue_as_new\n}\n\nconst { getWorkflowByName, getTaskForWorkflow } = proxyActivities({\n startToCloseTimeout: \"1 minutes\",\n retry: {\n maximumAttempts: 1,\n },\n});\n\nexport async function ScriptWorkflow(\n request: WorkflowRequest,\n inputData?: any,\n): Promise<any[]> {\n const state: WorkflowState = {\n completedSteps: [],\n currentStep: null,\n failedStep: null,\n };\n\n const results: any[] = [];\n const workflowName = request.workflow_name;\n let currentData = inputData?.data || inputData || {};\n\n logger.info(\n `Starting workflow: ${workflowName} (mode: ${request.execution_mode}) with data: ${JSON.stringify(currentData)}`,\n );\n\n try {\n currentData = JSON.parse(mooseJsonEncode(currentData));\n const workflow = await getWorkflowByName(workflowName);\n const task =\n request.execution_mode === \"start\" ?\n workflow.config.startingTask\n : await getTaskForWorkflow(workflowName, request.continue_from_task!);\n const result = await handleTask(workflow, task, currentData);\n results.push(...result);\n\n return results;\n } catch (error) {\n state.failedStep = workflowName;\n throw error;\n }\n}\n\nasync function handleTask(\n workflow: Workflow,\n task: Task<any, any>,\n inputData: any,\n): Promise<any[]> {\n // Handle timeout configuration\n const configTimeout = task.config.timeout;\n let taskTimeout: Duration | undefined;\n\n if (!configTimeout) {\n taskTimeout = \"1h\";\n } else if (configTimeout === \"never\") {\n taskTimeout = undefined;\n } else {\n taskTimeout = configTimeout as Duration;\n }\n\n const taskRetries = task.config.retries ?? 3;\n\n const timeoutMessage =\n taskTimeout ? `with timeout ${taskTimeout}` : \"with no timeout (unlimited)\";\n logger.info(\n `Handling task ${task.name} ${timeoutMessage} and retries ${taskRetries}`,\n );\n\n const activityOptions: ActivityOptions = {\n heartbeatTimeout: \"10s\",\n retry: {\n maximumAttempts: taskRetries,\n },\n };\n\n // Temporal requires either startToCloseTimeout OR scheduleToCloseTimeout to be set\n // For unlimited timeout (timeout = \"none\"), we use scheduleToCloseTimeout with a very large value\n // For normal timeouts, we use startToCloseTimeout for single execution timeout\n if (taskTimeout) {\n // Normal timeout - limit each individual execution attempt\n activityOptions.startToCloseTimeout = taskTimeout;\n } else {\n // Unlimited timeout - set scheduleToCloseTimeout to a very large value (10 years)\n // This satisfies Temporal's requirement while effectively allowing unlimited execution\n activityOptions.scheduleToCloseTimeout = \"87600h\"; // 10 years\n }\n\n const { executeTask } = proxyActivities(activityOptions);\n\n let taskCompleted = false;\n\n const monitorTask = async () => {\n logger.info(`Monitor task starting for ${task.name}`);\n while (!taskCompleted) {\n const info = workflowInfo();\n\n // Continue-as-new only when suggested by Temporal\n if (info.continueAsNewSuggested) {\n logger.info(`ContinueAsNew suggested by Temporal`);\n return await continueAsNew({\n workflow_name: workflow.name,\n execution_mode: \"continue_as_new\" as const,\n continue_from_task: task.name,\n });\n }\n\n await sleep(100);\n }\n logger.info(`Monitor task exiting because main task completed`);\n };\n\n const result = await Promise.race([\n executeTask(workflow, task, inputData)\n .then((taskResult) => {\n return {\n type: \"task_completed\" as const,\n data: taskResult,\n };\n })\n .finally(() => {\n taskCompleted = true;\n }),\n monitorTask().then(() => {\n return { type: \"continue_as_new\" as const, data: undefined };\n }),\n ]);\n\n if (result.type !== \"task_completed\") {\n return [];\n }\n\n const results = [result.data];\n if (!task.config.onComplete?.length) {\n return results;\n }\n\n for (const childTask of task.config.onComplete) {\n const childResult = await handleTask(workflow, childTask, result.data);\n results.push(...childResult);\n }\n\n // Check if this is an ETL extract task that needs to loop\n // ETL extract tasks end with \"_extract\" and return BatchResult with hasMore\n if (\n task.name.endsWith(\"_extract\") &&\n result &&\n typeof result === \"object\" &&\n result.data &&\n typeof result.data === \"object\" &&\n \"hasMore\" in result.data &&\n (result.data as any).hasMore === true\n ) {\n logger.info(`Extract task ${task.name} has more data, restarting chain...`);\n\n // Recursively call the extract task again to get the next batch\n const nextBatchResults = await handleTask(workflow, task, null);\n results.push(...nextBatchResults);\n }\n\n return results;\n}\n","// Add serialization helpers\nexport const mooseJsonEncode = (data: any): string => {\n return JSON.stringify(data, (_, value) => {\n if (value instanceof Map) {\n return {\n __type: \"Map\",\n value: Array.from(value.entries()),\n };\n }\n return value;\n });\n};\n\nexport const mooseJsonDecode = (text: string): any => {\n return JSON.parse(text, (_, value) => {\n if (value && typeof value === \"object\" && value.__type === \"Map\") {\n return new Map(value.value);\n }\n return value;\n });\n};\n"],"mappings":";AAAA;AAAA,EACE,OAAO;AAAA,EAEP;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACNA,IAAM,kBAAkB,CAAC,SAAsB;AACpD,SAAO,KAAK,UAAU,MAAM,CAAC,GAAG,UAAU;AACxC,QAAI,iBAAiB,KAAK;AACxB,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,OAAO,MAAM,KAAK,MAAM,QAAQ,CAAC;AAAA,MACnC;AAAA,IACF;AACA,WAAO;AAAA,EACT,CAAC;AACH;;;ADSA,IAAM,EAAE,mBAAmB,mBAAmB,IAAI,gBAAgB;AAAA,EAChE,qBAAqB;AAAA,EACrB,OAAO;AAAA,IACL,iBAAiB;AAAA,EACnB;AACF,CAAC;AAED,eAAsB,eACpB,SACA,WACgB;AAChB,QAAM,QAAuB;AAAA,IAC3B,gBAAgB,CAAC;AAAA,IACjB,aAAa;AAAA,IACb,YAAY;AAAA,EACd;AAEA,QAAM,UAAiB,CAAC;AACxB,QAAM,eAAe,QAAQ;AAC7B,MAAI,cAAc,WAAW,QAAQ,aAAa,CAAC;AAEnD,SAAO;AAAA,IACL,sBAAsB,YAAY,WAAW,QAAQ,cAAc,gBAAgB,KAAK,UAAU,WAAW,CAAC;AAAA,EAChH;AAEA,MAAI;AACF,kBAAc,KAAK,MAAM,gBAAgB,WAAW,C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EA,YAAM,MAAM,GAAG;AAAA,IACjB;AACA,WAAO,KAAK,kDAAkD;AAAA,EAChE;AAEA,QAAM,SAAS,MAAM,QAAQ,KAAK;AAAA,IAChC,YAAY,UAAU,MAAM,SAAS,EAClC,KAAK,CAAC,eAAe;AACpB,aAAO;AAAA,QACL,MAAM;AAAA,QACN,MAAM;AAAA,MACR;AAAA,IACF,CAAC,EACA,QAAQ,MAAM;AACb,sBAAgB;AAAA,IAClB,CAAC;AAAA,IACH,YAAY,EAAE,KAAK,MAAM;AACvB,aAAO,EAAE,MAAM,mBAA4B,MAAM,OAAU;AAAA,IAC7D,CAAC;AAAA,EACH,CAAC;AAED,MAAI,OAAO,SAAS,kBAAkB;AACpC,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,UAAU,CAAC,OAAO,IAAI;AAC5B,MAAI,CAAC,KAAK,OAAO,YAAY,QAAQ;AACnC,WAAO;AAAA,EACT;AAEA,aAAW,aAAa,KAAK,OAAO,YAAY;AAC9C,UAAM,cAAc,MAAM,WAAW,UAAU,WAAW,OAAO,IAAI;AACrE,YAAQ,KAAK,GAAG,WAAW;AAAA,EAC7B;AAIA,MACE,KAAK,KAAK,SAAS,UAAU,KAC7B,UACA,OAAO,WAAW,YAClB,OAAO,QACP,OAAO,OAAO,SAAS,YACvB,aAAa,OAAO,QACnB,OAAO,KAAa,YAAY,MACjC;AACA,WAAO,KAAK,gBAAgB,KAAK,IAAI,qCAAqC;AAG1E,UAAM,mBAAmB,MAAM,WAAW,UAAU,MAAM,IAAI;AAC9D,YAAQ,KAAK,GAAG,gBAAgB;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import './index-C4miZc-A.mjs';
|
|
2
|
-
import { Pattern, TagBase } from 'typia/lib/tags';
|
|
3
|
-
import { tags } from 'typia';
|
|
4
|
-
|
|
5
|
-
type ClickHousePrecision<P extends number> = {
|
|
6
|
-
_clickhouse_precision?: P;
|
|
7
|
-
};
|
|
8
|
-
declare const DecimalRegex: "^-?\\d+(\\.\\d+)?$";
|
|
9
|
-
type ClickHouseDecimal<P extends number, S extends number> = {
|
|
10
|
-
_clickhouse_precision?: P;
|
|
11
|
-
_clickhouse_scale?: S;
|
|
12
|
-
} & Pattern<typeof DecimalRegex>;
|
|
13
|
-
type ClickHouseFixedStringSize<N extends number> = {
|
|
14
|
-
_clickhouse_fixed_string_size?: N;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* FixedString(N) - Fixed-length string of exactly N bytes.
|
|
18
|
-
*
|
|
19
|
-
* ClickHouse stores exactly N bytes, padding shorter values with null bytes.
|
|
20
|
-
* Values exceeding N bytes will throw an exception.
|
|
21
|
-
*
|
|
22
|
-
* Use for binary data: hashes, IP addresses, UUIDs, MAC addresses.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* interface BinaryData {
|
|
26
|
-
* md5_hash: string & FixedString<16>; // 16-byte MD5
|
|
27
|
-
* sha256_hash: string & FixedString<32>; // 32-byte SHA256
|
|
28
|
-
* }
|
|
29
|
-
*/
|
|
30
|
-
type FixedString<N extends number> = string & ClickHouseFixedStringSize<N>;
|
|
31
|
-
type ClickHouseByteSize<N extends number> = {
|
|
32
|
-
_clickhouse_byte_size?: N;
|
|
33
|
-
};
|
|
34
|
-
type LowCardinality = {
|
|
35
|
-
_LowCardinality?: true;
|
|
36
|
-
};
|
|
37
|
-
type DateTime = Date;
|
|
38
|
-
type DateTime64<P extends number> = Date & ClickHousePrecision<P>;
|
|
39
|
-
type DateTimeString = string & tags.Format<"date-time">;
|
|
40
|
-
/**
|
|
41
|
-
* JS Date objects cannot hold microsecond precision.
|
|
42
|
-
* Use string as the runtime type to avoid losing information.
|
|
43
|
-
*/
|
|
44
|
-
type DateTime64String<P extends number> = string & tags.Format<"date-time"> & ClickHousePrecision<P>;
|
|
45
|
-
type Float32 = number & ClickHouseFloat<"float32">;
|
|
46
|
-
type Float64 = number & ClickHouseFloat<"float64">;
|
|
47
|
-
type Int8 = number & ClickHouseInt<"int8">;
|
|
48
|
-
type Int16 = number & ClickHouseInt<"int16">;
|
|
49
|
-
type Int32 = number & ClickHouseInt<"int32">;
|
|
50
|
-
type Int64 = number & ClickHouseInt<"int64">;
|
|
51
|
-
type UInt8 = number & ClickHouseInt<"uint8">;
|
|
52
|
-
type UInt16 = number & ClickHouseInt<"uint16">;
|
|
53
|
-
type UInt32 = number & ClickHouseInt<"uint32">;
|
|
54
|
-
type UInt64 = number & ClickHouseInt<"uint64">;
|
|
55
|
-
type Decimal<P extends number, S extends number> = string & ClickHouseDecimal<P, S>;
|
|
56
|
-
/**
|
|
57
|
-
* Attach compression codec to a column type.
|
|
58
|
-
*
|
|
59
|
-
* Any valid ClickHouse codec expression is allowed. ClickHouse validates the codec at runtime.
|
|
60
|
-
*
|
|
61
|
-
* @template T The base data type
|
|
62
|
-
* @template CodecExpr The codec expression (single codec or chain)
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* interface Metrics {
|
|
66
|
-
* // Single codec
|
|
67
|
-
* log_blob: string & ClickHouseCodec<"ZSTD(3)">;
|
|
68
|
-
*
|
|
69
|
-
* // Codec chain (processed left-to-right)
|
|
70
|
-
* timestamp: Date & ClickHouseCodec<"Delta, LZ4">;
|
|
71
|
-
* temperature: number & ClickHouseCodec<"Gorilla, ZSTD">;
|
|
72
|
-
*
|
|
73
|
-
* // Specialized codecs
|
|
74
|
-
* counter: number & ClickHouseCodec<"DoubleDelta">;
|
|
75
|
-
*
|
|
76
|
-
* // Can combine with other annotations
|
|
77
|
-
* count: UInt64 & ClickHouseCodec<"DoubleDelta, LZ4">;
|
|
78
|
-
* }
|
|
79
|
-
*/
|
|
80
|
-
type ClickHouseCodec<CodecExpr extends string> = {
|
|
81
|
-
_clickhouse_codec?: CodecExpr;
|
|
82
|
-
};
|
|
83
|
-
type ClickHouseFloat<Value extends "float32" | "float64"> = tags.Type<Value extends "float32" ? "float" : "double">;
|
|
84
|
-
type ClickHouseInt<Value extends "int8" | "int16" | "int32" | "int64" | "uint8" | "uint16" | "uint32" | "uint64"> = Value extends "int32" | "int64" | "uint32" | "uint64" ? tags.Type<Value> : TagBase<{
|
|
85
|
-
target: "number";
|
|
86
|
-
kind: "type";
|
|
87
|
-
value: Value;
|
|
88
|
-
validate: Value extends "int8" ? "-128 <= $input && $input <= 127" : Value extends "int16" ? "-32768 <= $input && $input <= 32767" : Value extends "uint8" ? "0 <= $input && $input <= 255" : Value extends "uint16" ? "0 <= $input && $input <= 65535" : never;
|
|
89
|
-
exclusive: true;
|
|
90
|
-
schema: {
|
|
91
|
-
type: "integer";
|
|
92
|
-
};
|
|
93
|
-
}>;
|
|
94
|
-
/**
|
|
95
|
-
* By default, nested objects map to the `Nested` type in clickhouse.
|
|
96
|
-
* Write `nestedObject: AnotherInterfaceType & ClickHouseNamedTuple`
|
|
97
|
-
* to map AnotherInterfaceType to the named tuple type.
|
|
98
|
-
*/
|
|
99
|
-
type ClickHouseNamedTuple = {
|
|
100
|
-
_clickhouse_mapped_type?: "namedTuple";
|
|
101
|
-
};
|
|
102
|
-
type ClickHouseJson<maxDynamicPaths extends number | undefined = undefined, maxDynamicTypes extends number | undefined = undefined, skipPaths extends string[] = [], skipRegexes extends string[] = []> = {
|
|
103
|
-
_clickhouse_mapped_type?: "JSON";
|
|
104
|
-
_clickhouse_json_settings?: {
|
|
105
|
-
maxDynamicPaths?: maxDynamicPaths;
|
|
106
|
-
maxDynamicTypes?: maxDynamicTypes;
|
|
107
|
-
skipPaths?: skipPaths;
|
|
108
|
-
skipRegexes?: skipRegexes;
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
type ClickHousePoint = [number, number] & {
|
|
112
|
-
_clickhouse_mapped_type?: "Point";
|
|
113
|
-
};
|
|
114
|
-
type ClickHouseRing = ClickHousePoint[] & {
|
|
115
|
-
_clickhouse_mapped_type?: "Ring";
|
|
116
|
-
};
|
|
117
|
-
type ClickHouseLineString = ClickHousePoint[] & {
|
|
118
|
-
_clickhouse_mapped_type?: "LineString";
|
|
119
|
-
};
|
|
120
|
-
type ClickHouseMultiLineString = ClickHouseLineString[] & {
|
|
121
|
-
_clickhouse_mapped_type?: "MultiLineString";
|
|
122
|
-
};
|
|
123
|
-
type ClickHousePolygon = ClickHouseRing[] & {
|
|
124
|
-
_clickhouse_mapped_type?: "Polygon";
|
|
125
|
-
};
|
|
126
|
-
type ClickHouseMultiPolygon = ClickHousePolygon[] & {
|
|
127
|
-
_clickhouse_mapped_type?: "MultiPolygon";
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* typia may have trouble handling this type.
|
|
131
|
-
* In which case, use {@link WithDefault} as a workaround
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* { field: number & ClickHouseDefault<"0"> }
|
|
135
|
-
*/
|
|
136
|
-
type ClickHouseDefault<SqlExpression extends string> = {
|
|
137
|
-
_clickhouse_default?: SqlExpression;
|
|
138
|
-
};
|
|
139
|
-
/**
|
|
140
|
-
* @example
|
|
141
|
-
* {
|
|
142
|
-
* ...
|
|
143
|
-
* timestamp: Date;
|
|
144
|
-
* debugMessage: string & ClickHouseTTL<"timestamp + INTERVAL 1 WEEK">;
|
|
145
|
-
* }
|
|
146
|
-
*/
|
|
147
|
-
type ClickHouseTTL<SqlExpression extends string> = {
|
|
148
|
-
_clickhouse_ttl?: SqlExpression;
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* ClickHouse MATERIALIZED column annotation.
|
|
152
|
-
* The column value is computed at INSERT time and physically stored.
|
|
153
|
-
* Cannot be explicitly inserted by users.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* interface Events {
|
|
157
|
-
* eventTime: DateTime;
|
|
158
|
-
* // Extract date component - computed and stored at insert time
|
|
159
|
-
* eventDate: Date & ClickHouseMaterialized<"toDate(event_time)">;
|
|
160
|
-
*
|
|
161
|
-
* userId: string;
|
|
162
|
-
* // Precompute hash for fast lookups
|
|
163
|
-
* userHash: UInt64 & ClickHouseMaterialized<"cityHash64(userId)">;
|
|
164
|
-
* }
|
|
165
|
-
*
|
|
166
|
-
* @remarks
|
|
167
|
-
* - MATERIALIZED and DEFAULT are mutually exclusive
|
|
168
|
-
* - Can be combined with ClickHouseCodec for compression
|
|
169
|
-
* - Changing the expression modifies the column in-place (existing values preserved)
|
|
170
|
-
*/
|
|
171
|
-
type ClickHouseMaterialized<SqlExpression extends string> = {
|
|
172
|
-
_clickhouse_materialized?: SqlExpression;
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* See also {@link ClickHouseDefault}
|
|
176
|
-
*
|
|
177
|
-
* @example{ updated_at: WithDefault<Date, "now()"> }
|
|
178
|
-
*/
|
|
179
|
-
type WithDefault<T, _SqlExpression extends string> = T;
|
|
180
|
-
|
|
181
|
-
type Key<T extends string | number | Date> = T;
|
|
182
|
-
type JWT<T extends object> = T;
|
|
183
|
-
|
|
184
|
-
export type { UInt32 as A, UInt64 as B, ClickHouseByteSize as C, DateTime as D, Decimal as E, FixedString as F, Int8 as I, JWT as J, Key as K, LowCardinality as L, UInt8 as U, WithDefault as W, ClickHouseInt as a, ClickHouseNamedTuple as b, ClickHousePoint as c, ClickHouseRing as d, ClickHouseLineString as e, ClickHouseMultiLineString as f, ClickHousePolygon as g, ClickHouseMultiPolygon as h, ClickHousePrecision as i, ClickHouseDecimal as j, ClickHouseFixedStringSize as k, ClickHouseFloat as l, ClickHouseJson as m, ClickHouseDefault as n, ClickHouseTTL as o, ClickHouseMaterialized as p, ClickHouseCodec as q, DateTime64 as r, DateTimeString as s, DateTime64String as t, Float32 as u, Float64 as v, Int16 as w, Int32 as x, Int64 as y, UInt16 as z };
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import './index-C4miZc-A.js';
|
|
2
|
-
import { Pattern, TagBase } from 'typia/lib/tags';
|
|
3
|
-
import { tags } from 'typia';
|
|
4
|
-
|
|
5
|
-
type ClickHousePrecision<P extends number> = {
|
|
6
|
-
_clickhouse_precision?: P;
|
|
7
|
-
};
|
|
8
|
-
declare const DecimalRegex: "^-?\\d+(\\.\\d+)?$";
|
|
9
|
-
type ClickHouseDecimal<P extends number, S extends number> = {
|
|
10
|
-
_clickhouse_precision?: P;
|
|
11
|
-
_clickhouse_scale?: S;
|
|
12
|
-
} & Pattern<typeof DecimalRegex>;
|
|
13
|
-
type ClickHouseFixedStringSize<N extends number> = {
|
|
14
|
-
_clickhouse_fixed_string_size?: N;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* FixedString(N) - Fixed-length string of exactly N bytes.
|
|
18
|
-
*
|
|
19
|
-
* ClickHouse stores exactly N bytes, padding shorter values with null bytes.
|
|
20
|
-
* Values exceeding N bytes will throw an exception.
|
|
21
|
-
*
|
|
22
|
-
* Use for binary data: hashes, IP addresses, UUIDs, MAC addresses.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* interface BinaryData {
|
|
26
|
-
* md5_hash: string & FixedString<16>; // 16-byte MD5
|
|
27
|
-
* sha256_hash: string & FixedString<32>; // 32-byte SHA256
|
|
28
|
-
* }
|
|
29
|
-
*/
|
|
30
|
-
type FixedString<N extends number> = string & ClickHouseFixedStringSize<N>;
|
|
31
|
-
type ClickHouseByteSize<N extends number> = {
|
|
32
|
-
_clickhouse_byte_size?: N;
|
|
33
|
-
};
|
|
34
|
-
type LowCardinality = {
|
|
35
|
-
_LowCardinality?: true;
|
|
36
|
-
};
|
|
37
|
-
type DateTime = Date;
|
|
38
|
-
type DateTime64<P extends number> = Date & ClickHousePrecision<P>;
|
|
39
|
-
type DateTimeString = string & tags.Format<"date-time">;
|
|
40
|
-
/**
|
|
41
|
-
* JS Date objects cannot hold microsecond precision.
|
|
42
|
-
* Use string as the runtime type to avoid losing information.
|
|
43
|
-
*/
|
|
44
|
-
type DateTime64String<P extends number> = string & tags.Format<"date-time"> & ClickHousePrecision<P>;
|
|
45
|
-
type Float32 = number & ClickHouseFloat<"float32">;
|
|
46
|
-
type Float64 = number & ClickHouseFloat<"float64">;
|
|
47
|
-
type Int8 = number & ClickHouseInt<"int8">;
|
|
48
|
-
type Int16 = number & ClickHouseInt<"int16">;
|
|
49
|
-
type Int32 = number & ClickHouseInt<"int32">;
|
|
50
|
-
type Int64 = number & ClickHouseInt<"int64">;
|
|
51
|
-
type UInt8 = number & ClickHouseInt<"uint8">;
|
|
52
|
-
type UInt16 = number & ClickHouseInt<"uint16">;
|
|
53
|
-
type UInt32 = number & ClickHouseInt<"uint32">;
|
|
54
|
-
type UInt64 = number & ClickHouseInt<"uint64">;
|
|
55
|
-
type Decimal<P extends number, S extends number> = string & ClickHouseDecimal<P, S>;
|
|
56
|
-
/**
|
|
57
|
-
* Attach compression codec to a column type.
|
|
58
|
-
*
|
|
59
|
-
* Any valid ClickHouse codec expression is allowed. ClickHouse validates the codec at runtime.
|
|
60
|
-
*
|
|
61
|
-
* @template T The base data type
|
|
62
|
-
* @template CodecExpr The codec expression (single codec or chain)
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* interface Metrics {
|
|
66
|
-
* // Single codec
|
|
67
|
-
* log_blob: string & ClickHouseCodec<"ZSTD(3)">;
|
|
68
|
-
*
|
|
69
|
-
* // Codec chain (processed left-to-right)
|
|
70
|
-
* timestamp: Date & ClickHouseCodec<"Delta, LZ4">;
|
|
71
|
-
* temperature: number & ClickHouseCodec<"Gorilla, ZSTD">;
|
|
72
|
-
*
|
|
73
|
-
* // Specialized codecs
|
|
74
|
-
* counter: number & ClickHouseCodec<"DoubleDelta">;
|
|
75
|
-
*
|
|
76
|
-
* // Can combine with other annotations
|
|
77
|
-
* count: UInt64 & ClickHouseCodec<"DoubleDelta, LZ4">;
|
|
78
|
-
* }
|
|
79
|
-
*/
|
|
80
|
-
type ClickHouseCodec<CodecExpr extends string> = {
|
|
81
|
-
_clickhouse_codec?: CodecExpr;
|
|
82
|
-
};
|
|
83
|
-
type ClickHouseFloat<Value extends "float32" | "float64"> = tags.Type<Value extends "float32" ? "float" : "double">;
|
|
84
|
-
type ClickHouseInt<Value extends "int8" | "int16" | "int32" | "int64" | "uint8" | "uint16" | "uint32" | "uint64"> = Value extends "int32" | "int64" | "uint32" | "uint64" ? tags.Type<Value> : TagBase<{
|
|
85
|
-
target: "number";
|
|
86
|
-
kind: "type";
|
|
87
|
-
value: Value;
|
|
88
|
-
validate: Value extends "int8" ? "-128 <= $input && $input <= 127" : Value extends "int16" ? "-32768 <= $input && $input <= 32767" : Value extends "uint8" ? "0 <= $input && $input <= 255" : Value extends "uint16" ? "0 <= $input && $input <= 65535" : never;
|
|
89
|
-
exclusive: true;
|
|
90
|
-
schema: {
|
|
91
|
-
type: "integer";
|
|
92
|
-
};
|
|
93
|
-
}>;
|
|
94
|
-
/**
|
|
95
|
-
* By default, nested objects map to the `Nested` type in clickhouse.
|
|
96
|
-
* Write `nestedObject: AnotherInterfaceType & ClickHouseNamedTuple`
|
|
97
|
-
* to map AnotherInterfaceType to the named tuple type.
|
|
98
|
-
*/
|
|
99
|
-
type ClickHouseNamedTuple = {
|
|
100
|
-
_clickhouse_mapped_type?: "namedTuple";
|
|
101
|
-
};
|
|
102
|
-
type ClickHouseJson<maxDynamicPaths extends number | undefined = undefined, maxDynamicTypes extends number | undefined = undefined, skipPaths extends string[] = [], skipRegexes extends string[] = []> = {
|
|
103
|
-
_clickhouse_mapped_type?: "JSON";
|
|
104
|
-
_clickhouse_json_settings?: {
|
|
105
|
-
maxDynamicPaths?: maxDynamicPaths;
|
|
106
|
-
maxDynamicTypes?: maxDynamicTypes;
|
|
107
|
-
skipPaths?: skipPaths;
|
|
108
|
-
skipRegexes?: skipRegexes;
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
type ClickHousePoint = [number, number] & {
|
|
112
|
-
_clickhouse_mapped_type?: "Point";
|
|
113
|
-
};
|
|
114
|
-
type ClickHouseRing = ClickHousePoint[] & {
|
|
115
|
-
_clickhouse_mapped_type?: "Ring";
|
|
116
|
-
};
|
|
117
|
-
type ClickHouseLineString = ClickHousePoint[] & {
|
|
118
|
-
_clickhouse_mapped_type?: "LineString";
|
|
119
|
-
};
|
|
120
|
-
type ClickHouseMultiLineString = ClickHouseLineString[] & {
|
|
121
|
-
_clickhouse_mapped_type?: "MultiLineString";
|
|
122
|
-
};
|
|
123
|
-
type ClickHousePolygon = ClickHouseRing[] & {
|
|
124
|
-
_clickhouse_mapped_type?: "Polygon";
|
|
125
|
-
};
|
|
126
|
-
type ClickHouseMultiPolygon = ClickHousePolygon[] & {
|
|
127
|
-
_clickhouse_mapped_type?: "MultiPolygon";
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* typia may have trouble handling this type.
|
|
131
|
-
* In which case, use {@link WithDefault} as a workaround
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* { field: number & ClickHouseDefault<"0"> }
|
|
135
|
-
*/
|
|
136
|
-
type ClickHouseDefault<SqlExpression extends string> = {
|
|
137
|
-
_clickhouse_default?: SqlExpression;
|
|
138
|
-
};
|
|
139
|
-
/**
|
|
140
|
-
* @example
|
|
141
|
-
* {
|
|
142
|
-
* ...
|
|
143
|
-
* timestamp: Date;
|
|
144
|
-
* debugMessage: string & ClickHouseTTL<"timestamp + INTERVAL 1 WEEK">;
|
|
145
|
-
* }
|
|
146
|
-
*/
|
|
147
|
-
type ClickHouseTTL<SqlExpression extends string> = {
|
|
148
|
-
_clickhouse_ttl?: SqlExpression;
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* ClickHouse MATERIALIZED column annotation.
|
|
152
|
-
* The column value is computed at INSERT time and physically stored.
|
|
153
|
-
* Cannot be explicitly inserted by users.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* interface Events {
|
|
157
|
-
* eventTime: DateTime;
|
|
158
|
-
* // Extract date component - computed and stored at insert time
|
|
159
|
-
* eventDate: Date & ClickHouseMaterialized<"toDate(event_time)">;
|
|
160
|
-
*
|
|
161
|
-
* userId: string;
|
|
162
|
-
* // Precompute hash for fast lookups
|
|
163
|
-
* userHash: UInt64 & ClickHouseMaterialized<"cityHash64(userId)">;
|
|
164
|
-
* }
|
|
165
|
-
*
|
|
166
|
-
* @remarks
|
|
167
|
-
* - MATERIALIZED and DEFAULT are mutually exclusive
|
|
168
|
-
* - Can be combined with ClickHouseCodec for compression
|
|
169
|
-
* - Changing the expression modifies the column in-place (existing values preserved)
|
|
170
|
-
*/
|
|
171
|
-
type ClickHouseMaterialized<SqlExpression extends string> = {
|
|
172
|
-
_clickhouse_materialized?: SqlExpression;
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* See also {@link ClickHouseDefault}
|
|
176
|
-
*
|
|
177
|
-
* @example{ updated_at: WithDefault<Date, "now()"> }
|
|
178
|
-
*/
|
|
179
|
-
type WithDefault<T, _SqlExpression extends string> = T;
|
|
180
|
-
|
|
181
|
-
type Key<T extends string | number | Date> = T;
|
|
182
|
-
type JWT<T extends object> = T;
|
|
183
|
-
|
|
184
|
-
export type { UInt32 as A, UInt64 as B, ClickHouseByteSize as C, DateTime as D, Decimal as E, FixedString as F, Int8 as I, JWT as J, Key as K, LowCardinality as L, UInt8 as U, WithDefault as W, ClickHouseInt as a, ClickHouseNamedTuple as b, ClickHousePoint as c, ClickHouseRing as d, ClickHouseLineString as e, ClickHouseMultiLineString as f, ClickHousePolygon as g, ClickHouseMultiPolygon as h, ClickHousePrecision as i, ClickHouseDecimal as j, ClickHouseFixedStringSize as k, ClickHouseFloat as l, ClickHouseJson as m, ClickHouseDefault as n, ClickHouseTTL as o, ClickHouseMaterialized as p, ClickHouseCodec as q, DateTime64 as r, DateTimeString as s, DateTime64String as t, Float32 as u, Float64 as v, Int16 as w, Int32 as x, Int64 as y, UInt16 as z };
|