@stackone/olap 0.1.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 ADDED
@@ -0,0 +1,50 @@
1
+ # @stackone/olap
2
+
3
+ ## Description
4
+
5
+ This package contains the olap logs functionality for stackone projects.
6
+
7
+ This package uses the tech stack provided by the **Connect Monorepo** global setup. Please check the [root README](../../README.md) for more information.
8
+
9
+ ## Requirements
10
+
11
+ Please check the [root README](../../README.md) for requirements.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ # install dependencies
17
+ $ npm run install
18
+ ```
19
+
20
+ ## Available commands
21
+
22
+ ```bash
23
+ # clean build output
24
+ $ npm run clean
25
+ ```
26
+
27
+ ```bash
28
+ # build package
29
+ $ npm run build
30
+ ```
31
+
32
+ ```bash
33
+ # run tests
34
+ $ npm run test
35
+ ```
36
+
37
+ ```bash
38
+ # run tests on watch mode
39
+ $ npm run test:watch
40
+ ```
41
+
42
+ ```bash
43
+ # run linter
44
+ $ npm run lint
45
+ ```
46
+
47
+ ```bash
48
+ # run linter and try to fix any error
49
+ $ npm run lint:fix
50
+ ```
@@ -0,0 +1,108 @@
1
+ //#region ../logger/src/types.d.ts
2
+ interface ILogger {
3
+ debug({
4
+ category,
5
+ message,
6
+ traceId,
7
+ context
8
+ }: {
9
+ category?: string;
10
+ message: string;
11
+ traceId?: string;
12
+ context?: Record<string, unknown>;
13
+ }): void;
14
+ info({
15
+ category,
16
+ message,
17
+ traceId,
18
+ context
19
+ }: {
20
+ category?: string;
21
+ message: string;
22
+ traceId?: string;
23
+ context?: Record<string, unknown>;
24
+ }): void;
25
+ warning({
26
+ category,
27
+ message,
28
+ traceId,
29
+ error,
30
+ code,
31
+ context
32
+ }: {
33
+ category?: string;
34
+ message: string;
35
+ traceId?: string;
36
+ error?: LogError;
37
+ code?: string;
38
+ context?: Record<string, unknown>;
39
+ }): void;
40
+ error({
41
+ category,
42
+ message,
43
+ traceId,
44
+ error,
45
+ code,
46
+ context
47
+ }: {
48
+ category?: string;
49
+ message: string;
50
+ traceId?: string;
51
+ error?: LogError;
52
+ code: string;
53
+ context?: Record<string, unknown>;
54
+ }): void;
55
+ }
56
+ type LogError = Error & {
57
+ response?: {
58
+ data?: unknown;
59
+ };
60
+ context?: Record<string, unknown>;
61
+ url?: string;
62
+ };
63
+ //#endregion
64
+ //#region src/olap/olapOptions.d.ts
65
+ type OlapOptions = {
66
+ olap?: boolean;
67
+ advanced?: boolean;
68
+ };
69
+ //#endregion
70
+ //#region src/types.d.ts
71
+ interface IKafkaSink {
72
+ send(topic: string, payload: unknown): Promise<void>;
73
+ }
74
+ interface IS3Sink {
75
+ send(bucket: string, payload: unknown): Promise<void>;
76
+ }
77
+ interface IOlapClient {
78
+ recordAction(ActionResult: ActionResult, options?: OlapOptions): void;
79
+ recordStep(stepResult: StepResult, options?: OlapOptions): void;
80
+ }
81
+ type ActionResult = {
82
+ status: string;
83
+ message: string | undefined;
84
+ outputs: unknown;
85
+ };
86
+ type StepResult = {
87
+ stepId: string;
88
+ status: string;
89
+ };
90
+ //#endregion
91
+ //#region src/olap/olapClient.d.ts
92
+ declare class OlapClient implements IOlapClient {
93
+ #private;
94
+ name: string;
95
+ constructor({
96
+ KafkaSink,
97
+ S3Sink,
98
+ logger
99
+ }?: {
100
+ KafkaSink?: IKafkaSink;
101
+ S3Sink?: IS3Sink;
102
+ logger?: ILogger;
103
+ });
104
+ recordAction(actionResult: ActionResult, options?: OlapOptions): Promise<void>;
105
+ recordStep(stepResult: StepResult, options?: OlapOptions): Promise<void>;
106
+ }
107
+ //#endregion
108
+ export { type ActionResult, type IOlapClient, OlapClient, type OlapOptions, type StepResult };
@@ -0,0 +1,108 @@
1
+ //#region ../logger/src/types.d.ts
2
+ interface ILogger {
3
+ debug({
4
+ category,
5
+ message,
6
+ traceId,
7
+ context
8
+ }: {
9
+ category?: string;
10
+ message: string;
11
+ traceId?: string;
12
+ context?: Record<string, unknown>;
13
+ }): void;
14
+ info({
15
+ category,
16
+ message,
17
+ traceId,
18
+ context
19
+ }: {
20
+ category?: string;
21
+ message: string;
22
+ traceId?: string;
23
+ context?: Record<string, unknown>;
24
+ }): void;
25
+ warning({
26
+ category,
27
+ message,
28
+ traceId,
29
+ error,
30
+ code,
31
+ context
32
+ }: {
33
+ category?: string;
34
+ message: string;
35
+ traceId?: string;
36
+ error?: LogError;
37
+ code?: string;
38
+ context?: Record<string, unknown>;
39
+ }): void;
40
+ error({
41
+ category,
42
+ message,
43
+ traceId,
44
+ error,
45
+ code,
46
+ context
47
+ }: {
48
+ category?: string;
49
+ message: string;
50
+ traceId?: string;
51
+ error?: LogError;
52
+ code: string;
53
+ context?: Record<string, unknown>;
54
+ }): void;
55
+ }
56
+ type LogError = Error & {
57
+ response?: {
58
+ data?: unknown;
59
+ };
60
+ context?: Record<string, unknown>;
61
+ url?: string;
62
+ };
63
+ //#endregion
64
+ //#region src/olap/olapOptions.d.ts
65
+ type OlapOptions = {
66
+ olap?: boolean;
67
+ advanced?: boolean;
68
+ };
69
+ //#endregion
70
+ //#region src/types.d.ts
71
+ interface IKafkaSink {
72
+ send(topic: string, payload: unknown): Promise<void>;
73
+ }
74
+ interface IS3Sink {
75
+ send(bucket: string, payload: unknown): Promise<void>;
76
+ }
77
+ interface IOlapClient {
78
+ recordAction(ActionResult: ActionResult, options?: OlapOptions): void;
79
+ recordStep(stepResult: StepResult, options?: OlapOptions): void;
80
+ }
81
+ type ActionResult = {
82
+ status: string;
83
+ message: string | undefined;
84
+ outputs: unknown;
85
+ };
86
+ type StepResult = {
87
+ stepId: string;
88
+ status: string;
89
+ };
90
+ //#endregion
91
+ //#region src/olap/olapClient.d.ts
92
+ declare class OlapClient implements IOlapClient {
93
+ #private;
94
+ name: string;
95
+ constructor({
96
+ KafkaSink,
97
+ S3Sink,
98
+ logger
99
+ }?: {
100
+ KafkaSink?: IKafkaSink;
101
+ S3Sink?: IS3Sink;
102
+ logger?: ILogger;
103
+ });
104
+ recordAction(actionResult: ActionResult, options?: OlapOptions): Promise<void>;
105
+ recordStep(stepResult: StepResult, options?: OlapOptions): Promise<void>;
106
+ }
107
+ //#endregion
108
+ export { type ActionResult, type IOlapClient, OlapClient, type OlapOptions, type StepResult };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ function e(e){return new t(e)}var t=class{#logger;constructor(e){this.#logger=e}async send(e,t){let n=(()=>{try{return JSON.stringify(t)}catch{return`[Unserializable payload]`}})();this.#logger?.info({message:`[Kafka] Sent to topic ${e}: ${n}`,context:{topic:e,payload:t},category:`KafkaSink`}),await Promise.resolve()}};const n={olap:!0,advanced:!1};function r(e){return{...n,...e}}function i(e){return new a(e)}var a=class{#logger;constructor(e){this.#logger=e}async send(e,t){let n=(()=>{try{return JSON.stringify(t)}catch{return`[Unserializable payload]`}})();this.#logger?.info({message:`[S3] Sent to bucket ${e}: ${n}`,context:{bucket:e,payload:t},category:`S3Sink`}),await Promise.resolve()}},o=class{#KafkaSink;#S3Sink;#logger;name=`OlapClient`;constructor({KafkaSink:t=e(),S3Sink:n=i(),logger:r}={}){this.#KafkaSink=t,this.#S3Sink=n,this.#logger=r}async recordAction(e,t){let n=r(t);if(n.olap)try{await this.#KafkaSink?.send(`actions`,e)}catch(e){this.#logger?.warning({message:`[OlapClient] Error sending to Kafka: ${e.message}`,category:`OlapClient`,error:e})}if(n.advanced)try{await this.#S3Sink?.send(`actions`,e)}catch(e){this.#logger?.warning({message:`[OlapClient] Error sending to S3: ${e.message}`,category:`OlapClient`,error:e})}}async recordStep(e,t){let n=r(t);n.olap&&await this.#KafkaSink?.send(`steps`,e),n.advanced&&await this.#S3Sink?.send(`steps`,e)}};exports.OlapClient=o;
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ function e(e){return new t(e)}var t=class{#logger;constructor(e){this.#logger=e}async send(e,t){let n=(()=>{try{return JSON.stringify(t)}catch{return`[Unserializable payload]`}})();this.#logger?.info({message:`[Kafka] Sent to topic ${e}: ${n}`,context:{topic:e,payload:t},category:`KafkaSink`}),await Promise.resolve()}};const n={olap:!0,advanced:!1};function r(e){return{...n,...e}}function i(e){return new a(e)}var a=class{#logger;constructor(e){this.#logger=e}async send(e,t){let n=(()=>{try{return JSON.stringify(t)}catch{return`[Unserializable payload]`}})();this.#logger?.info({message:`[S3] Sent to bucket ${e}: ${n}`,context:{bucket:e,payload:t},category:`S3Sink`}),await Promise.resolve()}},o=class{#KafkaSink;#S3Sink;#logger;name=`OlapClient`;constructor({KafkaSink:t=e(),S3Sink:n=i(),logger:r}={}){this.#KafkaSink=t,this.#S3Sink=n,this.#logger=r}async recordAction(e,t){let n=r(t);if(n.olap)try{await this.#KafkaSink?.send(`actions`,e)}catch(e){this.#logger?.warning({message:`[OlapClient] Error sending to Kafka: ${e.message}`,category:`OlapClient`,error:e})}if(n.advanced)try{await this.#S3Sink?.send(`actions`,e)}catch(e){this.#logger?.warning({message:`[OlapClient] Error sending to S3: ${e.message}`,category:`OlapClient`,error:e})}}async recordStep(e,t){let n=r(t);n.olap&&await this.#KafkaSink?.send(`steps`,e),n.advanced&&await this.#S3Sink?.send(`steps`,e)}};export{o as OlapClient};
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@stackone/olap",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "package.json",
11
+ "README.md"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.mjs",
17
+ "require": "./dist/index.js"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "scripts": {
22
+ "clean": "rimraf dist",
23
+ "prebuild": "npm run clean",
24
+ "build": "tsdown --env.NODE_ENV=production --minify",
25
+ "prebuild:dev": "npm run clean",
26
+ "build:dev": "tsdown --env.NODE_ENV=development",
27
+ "code:format": "biome format ./src ./*.mjs",
28
+ "code:format:fix": "biome format --write ./src ./*.mjs",
29
+ "code:lint": "biome lint --error-on-warnings ./src ./*.mjs",
30
+ "code:lint:fix": "biome lint --write ./src ./*.mjs",
31
+ "code:check": "biome check ./src ./*.mjs",
32
+ "code:check:fix": "biome check --write ./src ./*.mjs",
33
+ "lint": "npm run code:check",
34
+ "lint:fix": "npm run code:check:fix",
35
+ "test": "FORCE_COLOR=1 vitest run",
36
+ "test:watch": "FORCE_COLOR=1 vitest watch --silent",
37
+ "test:typecheck": "tsc --noEmit --project tsconfig.tests.json",
38
+ "publish-release": "npm publish --access=public"
39
+ },
40
+ "keywords": [],
41
+ "author": "StackOne",
42
+ "license": "ISC",
43
+ "dependencies": {},
44
+ "devDependencies": {
45
+ "tsdown": "^0.12.9"
46
+ },
47
+ "tsdown": {
48
+ "dts": true,
49
+ "format": [
50
+ "esm",
51
+ "cjs"
52
+ ]
53
+ }
54
+ }