@bayoudhi/moose-lib-serverless 0.3.2 → 0.4.0
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/README.md +43 -1
- package/dist/index.d.mts +63 -1
- package/dist/index.d.ts +63 -1
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -83,7 +83,47 @@ const { OlapTable, Stream, sql } = require("@bayoudhi/moose-lib-serverless");
|
|
|
83
83
|
import { OlapTable, Stream, sql } from "@bayoudhi/moose-lib-serverless";
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
> **Note**: The CJS bundle is recommended for AWS Lambda because ESM top-level imports cannot be lazily deferred. The CJS bundle keeps the Kafka reference inside a lazy `__esm` block that never executes unless you explicitly call `getClickhouseClient()` or `getKafkaProducer()`.
|
|
86
|
+
> **Note**: The CJS bundle is recommended for AWS Lambda because ESM top-level imports cannot be lazily deferred. The CJS bundle keeps the Kafka reference inside a lazy `__esm` block that never executes unless you explicitly call `getClickhouseClient()` or `getKafkaProducer()`.
|
|
87
|
+
|
|
88
|
+
## ClickHouse Configuration for Serverless
|
|
89
|
+
|
|
90
|
+
In a standard Moose project, ClickHouse connection details are read from `moose.config.toml`. This file doesn't exist in serverless environments, so calling `OlapTable.insert()` would throw a `ConfigError`.
|
|
91
|
+
|
|
92
|
+
Use `configureClickHouse()` to provide connection details programmatically. Call it **once** during cold start, before any `.insert()` calls:
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { configureClickHouse, OlapTable } from "@bayoudhi/moose-lib-serverless";
|
|
96
|
+
|
|
97
|
+
// Call once at module level (runs during Lambda cold start)
|
|
98
|
+
configureClickHouse({
|
|
99
|
+
host: process.env.CLICKHOUSE_HOST!,
|
|
100
|
+
port: process.env.CLICKHOUSE_PORT!, // string, e.g. "8443"
|
|
101
|
+
username: process.env.CLICKHOUSE_USER!,
|
|
102
|
+
password: process.env.CLICKHOUSE_PASSWORD!,
|
|
103
|
+
database: process.env.CLICKHOUSE_DATABASE!,
|
|
104
|
+
useSSL: true,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Define your table (compiler plugin injects schema at build time)
|
|
108
|
+
const myTable = new OlapTable<MyType>("my_table");
|
|
109
|
+
|
|
110
|
+
export async function handler(event: any) {
|
|
111
|
+
const data = parseEvent(event);
|
|
112
|
+
await myTable.insert(data); // Works without moose.config.toml
|
|
113
|
+
return { statusCode: 200 };
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### `ClickHouseConfig` fields
|
|
118
|
+
|
|
119
|
+
| Field | Type | Example |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| `host` | `string` | `"clickhouse.example.com"` |
|
|
122
|
+
| `port` | `string` | `"8443"` |
|
|
123
|
+
| `username` | `string` | `"default"` |
|
|
124
|
+
| `password` | `string` | `"secret"` |
|
|
125
|
+
| `database` | `string` | `"my_database"` |
|
|
126
|
+
| `useSSL` | `boolean` | `true` |
|
|
87
127
|
|
|
88
128
|
## What's Included
|
|
89
129
|
|
|
@@ -98,6 +138,8 @@ import { OlapTable, Stream, sql } from "@bayoudhi/moose-lib-serverless";
|
|
|
98
138
|
| ClickHouse column types | `Columns.String`, `Columns.Int32`, `Columns.DateTime`, etc. |
|
|
99
139
|
| `ConsumptionUtil`, `ApiUtil` | Utility types for consumption APIs |
|
|
100
140
|
| `registerDataSource` | Register external data source connectors |
|
|
141
|
+
| `configureClickHouse` | Provide ClickHouse connection config for serverless (no `moose.config.toml`) |
|
|
142
|
+
| `ClickHouseConfig` | TypeScript interface for `configureClickHouse()` options |
|
|
101
143
|
| `getSecrets` | Retrieve secrets from the Moose secrets store |
|
|
102
144
|
| Utility functions | `compilerLog`, `cliLog`, `mapTstoJs`, `getFileName`, etc. |
|
|
103
145
|
|
package/dist/index.d.mts
CHANGED
|
@@ -2698,4 +2698,66 @@ interface ExtractionResult<T = any> {
|
|
|
2698
2698
|
metadata: Record<string, any>;
|
|
2699
2699
|
}
|
|
2700
2700
|
|
|
2701
|
-
|
|
2701
|
+
/**
|
|
2702
|
+
* @module @bayoudhi/moose-lib-serverless
|
|
2703
|
+
*
|
|
2704
|
+
* Serverless-compatible subset of @514labs/moose-lib.
|
|
2705
|
+
*
|
|
2706
|
+
* Re-exports everything from the `@514labs/moose-lib/serverless` entry point,
|
|
2707
|
+
* which excludes native C++ dependencies (Kafka, Temporal, Redis) that are
|
|
2708
|
+
* incompatible with AWS Lambda and edge runtimes.
|
|
2709
|
+
*
|
|
2710
|
+
* At build time, `@514labs/moose-lib` code is inlined into this package's
|
|
2711
|
+
* bundle so there is no runtime dependency on `@514labs/moose-lib`.
|
|
2712
|
+
*/
|
|
2713
|
+
|
|
2714
|
+
/**
|
|
2715
|
+
* ClickHouse connection configuration for serverless environments.
|
|
2716
|
+
*
|
|
2717
|
+
* In a standard Moose project, connection details are read from
|
|
2718
|
+
* `moose.config.toml`. In serverless environments (AWS Lambda, Edge, etc.)
|
|
2719
|
+
* this file doesn't exist, so you must provide the config programmatically
|
|
2720
|
+
* via {@link configureClickHouse} before calling `.insert()` on any table.
|
|
2721
|
+
*/
|
|
2722
|
+
interface ClickHouseConfig {
|
|
2723
|
+
/** ClickHouse host (e.g. "clickhouse.example.com") */
|
|
2724
|
+
host: string;
|
|
2725
|
+
/** ClickHouse HTTP port as a string (e.g. "8443") */
|
|
2726
|
+
port: string;
|
|
2727
|
+
/** ClickHouse username (e.g. "default") */
|
|
2728
|
+
username: string;
|
|
2729
|
+
/** ClickHouse password */
|
|
2730
|
+
password: string;
|
|
2731
|
+
/** ClickHouse database name */
|
|
2732
|
+
database: string;
|
|
2733
|
+
/** Whether to use HTTPS/SSL for the connection */
|
|
2734
|
+
useSSL: boolean;
|
|
2735
|
+
}
|
|
2736
|
+
/**
|
|
2737
|
+
* Configure the ClickHouse connection for serverless environments.
|
|
2738
|
+
*
|
|
2739
|
+
* Call this once during cold start (before any `.insert()` calls) to provide
|
|
2740
|
+
* ClickHouse connection details. This bypasses the `moose.config.toml` file
|
|
2741
|
+
* lookup that would otherwise fail in environments without a Moose project
|
|
2742
|
+
* structure.
|
|
2743
|
+
*
|
|
2744
|
+
* @example
|
|
2745
|
+
* ```typescript
|
|
2746
|
+
* import { configureClickHouse, OlapTable } from "@bayoudhi/moose-lib-serverless";
|
|
2747
|
+
*
|
|
2748
|
+
* configureClickHouse({
|
|
2749
|
+
* host: process.env.CLICKHOUSE_HOST!,
|
|
2750
|
+
* port: process.env.CLICKHOUSE_PORT!,
|
|
2751
|
+
* username: process.env.CLICKHOUSE_USER!,
|
|
2752
|
+
* password: process.env.CLICKHOUSE_PASSWORD!,
|
|
2753
|
+
* database: process.env.CLICKHOUSE_DATABASE!,
|
|
2754
|
+
* useSSL: true,
|
|
2755
|
+
* });
|
|
2756
|
+
*
|
|
2757
|
+
* // Now .insert() works without moose.config.toml
|
|
2758
|
+
* await myTable.insert(data);
|
|
2759
|
+
* ```
|
|
2760
|
+
*/
|
|
2761
|
+
declare function configureClickHouse(config: ClickHouseConfig): void;
|
|
2762
|
+
|
|
2763
|
+
export { ACKs, type Aggregated, Api, type ApiConfig, type ApiUtil, type CSVParsingConfig, CSV_DELIMITERS, type CliLogData, type ClickHouseByteSize, type ClickHouseCodec, type ClickHouseConfig, type ClickHouseDecimal, type ClickHouseDefault, ClickHouseEngines, type ClickHouseFixedStringSize, type ClickHouseFloat, type ClickHouseInt, type ClickHouseJson, type ClickHouseMaterialized, type ClickHouseNamedTuple, type ClickHousePrecision, type ClickHouseTTL, ConsumptionApi, type ConsumptionUtil, DEFAULT_CSV_CONFIG, DEFAULT_JSON_CONFIG, DataSource, type DataSourceConfig, type DateTime, type DateTime64, type DateTime64String, type DateTimeString, type DeadLetter, type DeadLetterModel, DeadLetterQueue, type Decimal, ETLPipeline, type ETLPipelineConfig, type EgressConfig, type ExtractionResult, type FixedString, type Float32, type Float64, type FrameworkApp, type IdentifierBrandedString, IngestApi, type IngestConfig, IngestPipeline, type Int16, type Int32, type Int64, type Int8, type JSONParsingConfig, type JWT, type KafkaClientConfig, type Key, LifeCycle, type Logger, type LowCardinality, MAX_RETRIES, MAX_RETRIES_PRODUCER, MAX_RETRY_TIME_MS, MOOSE_RUNTIME_ENV_PREFIX, MaterializedView, type NonIdentifierBrandedString, type OlapConfig, OlapTable, RETRY_FACTOR_PRODUCER, RETRY_INITIAL_TIME_MS, type RawValue, type S3QueueTableSettings, type SimpleAggregated, Sql, SqlResource, type SqlTemplateTag, Stream, type StreamConfig, type StripDateIntersection, Task, type UInt16, type UInt32, type UInt64, type UInt8, type Value, View, WebApp, type WebAppConfig, type WebAppHandler, type WithDefault, Workflow, antiCachePath, cliLog, compilerLog, configureClickHouse, createClickhouseParameter, getApi, getApis, getFileName, getIngestApi, getIngestApis, getMaterializedView, getMaterializedViews, getSqlResource, getSqlResources, getStream, getStreams, getTable, getTables, getValueFromParameter, getView, getViews, getWebApp, getWebApps, getWorkflow, getWorkflows, isValidCSVDelimiter, logError, mapToClickHouseType, mapTstoJs, mooseEnvSecrets, mooseRuntimeEnv, parseCSV, parseJSON, parseJSONWithDates, quoteIdentifier, sql, toQuery, toQueryPreview, toStaticQuery };
|
package/dist/index.d.ts
CHANGED
|
@@ -2698,4 +2698,66 @@ interface ExtractionResult<T = any> {
|
|
|
2698
2698
|
metadata: Record<string, any>;
|
|
2699
2699
|
}
|
|
2700
2700
|
|
|
2701
|
-
|
|
2701
|
+
/**
|
|
2702
|
+
* @module @bayoudhi/moose-lib-serverless
|
|
2703
|
+
*
|
|
2704
|
+
* Serverless-compatible subset of @514labs/moose-lib.
|
|
2705
|
+
*
|
|
2706
|
+
* Re-exports everything from the `@514labs/moose-lib/serverless` entry point,
|
|
2707
|
+
* which excludes native C++ dependencies (Kafka, Temporal, Redis) that are
|
|
2708
|
+
* incompatible with AWS Lambda and edge runtimes.
|
|
2709
|
+
*
|
|
2710
|
+
* At build time, `@514labs/moose-lib` code is inlined into this package's
|
|
2711
|
+
* bundle so there is no runtime dependency on `@514labs/moose-lib`.
|
|
2712
|
+
*/
|
|
2713
|
+
|
|
2714
|
+
/**
|
|
2715
|
+
* ClickHouse connection configuration for serverless environments.
|
|
2716
|
+
*
|
|
2717
|
+
* In a standard Moose project, connection details are read from
|
|
2718
|
+
* `moose.config.toml`. In serverless environments (AWS Lambda, Edge, etc.)
|
|
2719
|
+
* this file doesn't exist, so you must provide the config programmatically
|
|
2720
|
+
* via {@link configureClickHouse} before calling `.insert()` on any table.
|
|
2721
|
+
*/
|
|
2722
|
+
interface ClickHouseConfig {
|
|
2723
|
+
/** ClickHouse host (e.g. "clickhouse.example.com") */
|
|
2724
|
+
host: string;
|
|
2725
|
+
/** ClickHouse HTTP port as a string (e.g. "8443") */
|
|
2726
|
+
port: string;
|
|
2727
|
+
/** ClickHouse username (e.g. "default") */
|
|
2728
|
+
username: string;
|
|
2729
|
+
/** ClickHouse password */
|
|
2730
|
+
password: string;
|
|
2731
|
+
/** ClickHouse database name */
|
|
2732
|
+
database: string;
|
|
2733
|
+
/** Whether to use HTTPS/SSL for the connection */
|
|
2734
|
+
useSSL: boolean;
|
|
2735
|
+
}
|
|
2736
|
+
/**
|
|
2737
|
+
* Configure the ClickHouse connection for serverless environments.
|
|
2738
|
+
*
|
|
2739
|
+
* Call this once during cold start (before any `.insert()` calls) to provide
|
|
2740
|
+
* ClickHouse connection details. This bypasses the `moose.config.toml` file
|
|
2741
|
+
* lookup that would otherwise fail in environments without a Moose project
|
|
2742
|
+
* structure.
|
|
2743
|
+
*
|
|
2744
|
+
* @example
|
|
2745
|
+
* ```typescript
|
|
2746
|
+
* import { configureClickHouse, OlapTable } from "@bayoudhi/moose-lib-serverless";
|
|
2747
|
+
*
|
|
2748
|
+
* configureClickHouse({
|
|
2749
|
+
* host: process.env.CLICKHOUSE_HOST!,
|
|
2750
|
+
* port: process.env.CLICKHOUSE_PORT!,
|
|
2751
|
+
* username: process.env.CLICKHOUSE_USER!,
|
|
2752
|
+
* password: process.env.CLICKHOUSE_PASSWORD!,
|
|
2753
|
+
* database: process.env.CLICKHOUSE_DATABASE!,
|
|
2754
|
+
* useSSL: true,
|
|
2755
|
+
* });
|
|
2756
|
+
*
|
|
2757
|
+
* // Now .insert() works without moose.config.toml
|
|
2758
|
+
* await myTable.insert(data);
|
|
2759
|
+
* ```
|
|
2760
|
+
*/
|
|
2761
|
+
declare function configureClickHouse(config: ClickHouseConfig): void;
|
|
2762
|
+
|
|
2763
|
+
export { ACKs, type Aggregated, Api, type ApiConfig, type ApiUtil, type CSVParsingConfig, CSV_DELIMITERS, type CliLogData, type ClickHouseByteSize, type ClickHouseCodec, type ClickHouseConfig, type ClickHouseDecimal, type ClickHouseDefault, ClickHouseEngines, type ClickHouseFixedStringSize, type ClickHouseFloat, type ClickHouseInt, type ClickHouseJson, type ClickHouseMaterialized, type ClickHouseNamedTuple, type ClickHousePrecision, type ClickHouseTTL, ConsumptionApi, type ConsumptionUtil, DEFAULT_CSV_CONFIG, DEFAULT_JSON_CONFIG, DataSource, type DataSourceConfig, type DateTime, type DateTime64, type DateTime64String, type DateTimeString, type DeadLetter, type DeadLetterModel, DeadLetterQueue, type Decimal, ETLPipeline, type ETLPipelineConfig, type EgressConfig, type ExtractionResult, type FixedString, type Float32, type Float64, type FrameworkApp, type IdentifierBrandedString, IngestApi, type IngestConfig, IngestPipeline, type Int16, type Int32, type Int64, type Int8, type JSONParsingConfig, type JWT, type KafkaClientConfig, type Key, LifeCycle, type Logger, type LowCardinality, MAX_RETRIES, MAX_RETRIES_PRODUCER, MAX_RETRY_TIME_MS, MOOSE_RUNTIME_ENV_PREFIX, MaterializedView, type NonIdentifierBrandedString, type OlapConfig, OlapTable, RETRY_FACTOR_PRODUCER, RETRY_INITIAL_TIME_MS, type RawValue, type S3QueueTableSettings, type SimpleAggregated, Sql, SqlResource, type SqlTemplateTag, Stream, type StreamConfig, type StripDateIntersection, Task, type UInt16, type UInt32, type UInt64, type UInt8, type Value, View, WebApp, type WebAppConfig, type WebAppHandler, type WithDefault, Workflow, antiCachePath, cliLog, compilerLog, configureClickHouse, createClickhouseParameter, getApi, getApis, getFileName, getIngestApi, getIngestApis, getMaterializedView, getMaterializedViews, getSqlResource, getSqlResources, getStream, getStreams, getTable, getTables, getValueFromParameter, getView, getViews, getWebApp, getWebApps, getWorkflow, getWorkflows, isValidCSVDelimiter, logError, mapToClickHouseType, mapTstoJs, mooseEnvSecrets, mooseRuntimeEnv, parseCSV, parseJSON, parseJSONWithDates, quoteIdentifier, sql, toQuery, toQueryPreview, toStaticQuery };
|
package/dist/index.js
CHANGED
|
@@ -220,6 +220,7 @@ __export(index_exports, {
|
|
|
220
220
|
antiCachePath: () => antiCachePath,
|
|
221
221
|
cliLog: () => cliLog,
|
|
222
222
|
compilerLog: () => compilerLog,
|
|
223
|
+
configureClickHouse: () => configureClickHouse,
|
|
223
224
|
createClickhouseParameter: () => createClickhouseParameter,
|
|
224
225
|
getApi: () => getApi,
|
|
225
226
|
getApis: () => getApis,
|
|
@@ -3157,6 +3158,39 @@ function getView(name) {
|
|
|
3157
3158
|
return getMooseInternal().views.get(name);
|
|
3158
3159
|
}
|
|
3159
3160
|
init_commons();
|
|
3161
|
+
|
|
3162
|
+
// src/index.ts
|
|
3163
|
+
var _pendingClickHouseConfig = null;
|
|
3164
|
+
function configureClickHouse(config) {
|
|
3165
|
+
const registry = globalThis._mooseConfigRegistry;
|
|
3166
|
+
if (registry && typeof registry.setClickHouseConfig === "function") {
|
|
3167
|
+
registry.setClickHouseConfig(config);
|
|
3168
|
+
_pendingClickHouseConfig = null;
|
|
3169
|
+
return;
|
|
3170
|
+
}
|
|
3171
|
+
_pendingClickHouseConfig = config;
|
|
3172
|
+
let _realRegistry = null;
|
|
3173
|
+
Object.defineProperty(globalThis, "_mooseConfigRegistry", {
|
|
3174
|
+
configurable: true,
|
|
3175
|
+
enumerable: true,
|
|
3176
|
+
get() {
|
|
3177
|
+
return _realRegistry;
|
|
3178
|
+
},
|
|
3179
|
+
set(newRegistry) {
|
|
3180
|
+
_realRegistry = newRegistry;
|
|
3181
|
+
if (_pendingClickHouseConfig && typeof newRegistry.setClickHouseConfig === "function") {
|
|
3182
|
+
newRegistry.setClickHouseConfig(_pendingClickHouseConfig);
|
|
3183
|
+
_pendingClickHouseConfig = null;
|
|
3184
|
+
}
|
|
3185
|
+
Object.defineProperty(globalThis, "_mooseConfigRegistry", {
|
|
3186
|
+
configurable: true,
|
|
3187
|
+
enumerable: true,
|
|
3188
|
+
writable: true,
|
|
3189
|
+
value: newRegistry
|
|
3190
|
+
});
|
|
3191
|
+
}
|
|
3192
|
+
});
|
|
3193
|
+
}
|
|
3160
3194
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3161
3195
|
0 && (module.exports = {
|
|
3162
3196
|
ACKs,
|
|
@@ -3190,6 +3224,7 @@ init_commons();
|
|
|
3190
3224
|
antiCachePath,
|
|
3191
3225
|
cliLog,
|
|
3192
3226
|
compilerLog,
|
|
3227
|
+
configureClickHouse,
|
|
3193
3228
|
createClickhouseParameter,
|
|
3194
3229
|
getApi,
|
|
3195
3230
|
getApis,
|