@smartlogs/shared 0.0.6 → 0.0.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.
@@ -0,0 +1,44 @@
1
+ type RuntimeEnvironment = "DENO" | "BUN" | "NODE" | "BROWSER" | "UNKNOWN";
2
+ declare function getEnvironment(): RuntimeEnvironment;
3
+
4
+ declare function getPreciseTime(): bigint;
5
+
6
+ interface Store {
7
+ workflows: Workflow[];
8
+ }
9
+ interface Workflow {
10
+ workflowId: string;
11
+ title: string;
12
+ description: string;
13
+ logs: Log[];
14
+ }
15
+ interface Log {
16
+ workflowId: string;
17
+ message: string;
18
+ body: object;
19
+ bodyType: "object" | "chart" | "image";
20
+ timestamp: Date | string;
21
+ clientTime: string; // in nanoseconds from BigInt
22
+ elapsedTime?: string; // in nanoseconds
23
+ origin: string;
24
+ spacer?: boolean;
25
+ order: number;
26
+ }
27
+
28
+ interface WorkflowProps {
29
+ workflowId: string;
30
+ title: string;
31
+ description: string;
32
+ }
33
+
34
+ interface MessageObject {
35
+ action: string;
36
+ payload: string;
37
+ }
38
+
39
+ interface ChartData {
40
+ x: number[],
41
+ y: number[],
42
+ }
43
+
44
+ export { type ChartData, type Log, type MessageObject, type RuntimeEnvironment, type Store, type Workflow, type WorkflowProps, getEnvironment, getPreciseTime };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,44 @@
1
- export * from "./environment.js";
2
- export * from "./time.js";
3
- export type * from "./index.d.ts";
1
+ type RuntimeEnvironment = "DENO" | "BUN" | "NODE" | "BROWSER" | "UNKNOWN";
2
+ declare function getEnvironment(): RuntimeEnvironment;
3
+
4
+ declare function getPreciseTime(): bigint;
5
+
6
+ interface Store {
7
+ workflows: Workflow[];
8
+ }
9
+ interface Workflow {
10
+ workflowId: string;
11
+ title: string;
12
+ description: string;
13
+ logs: Log[];
14
+ }
15
+ interface Log {
16
+ workflowId: string;
17
+ message: string;
18
+ body: object;
19
+ bodyType: "object" | "chart" | "image";
20
+ timestamp: Date | string;
21
+ clientTime: string; // in nanoseconds from BigInt
22
+ elapsedTime?: string; // in nanoseconds
23
+ origin: string;
24
+ spacer?: boolean;
25
+ order: number;
26
+ }
27
+
28
+ interface WorkflowProps {
29
+ workflowId: string;
30
+ title: string;
31
+ description: string;
32
+ }
33
+
34
+ interface MessageObject {
35
+ action: string;
36
+ payload: string;
37
+ }
38
+
39
+ interface ChartData {
40
+ x: number[],
41
+ y: number[],
42
+ }
43
+
44
+ export { type ChartData, type Log, type MessageObject, type RuntimeEnvironment, type Store, type Workflow, type WorkflowProps, getEnvironment, getPreciseTime };
package/dist/index.js CHANGED
@@ -1,2 +1,74 @@
1
- export * from "./environment.js";
2
- export * from "./time.js";
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ getEnvironment: () => getEnvironment,
24
+ getPreciseTime: () => getPreciseTime
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/environment.ts
29
+ function getEnvironment() {
30
+ if ("Deno" in globalThis && globalThis.Deno.version) {
31
+ return "DENO";
32
+ }
33
+ if ("Bun" in globalThis) {
34
+ return "BUN";
35
+ }
36
+ if ("process" in globalThis && globalThis.process.versions?.node) {
37
+ return "NODE";
38
+ }
39
+ if ("window" in globalThis) {
40
+ return "BROWSER";
41
+ }
42
+ return "UNKNOWN";
43
+ }
44
+
45
+ // src/time.ts
46
+ function getPreciseTime() {
47
+ const env = getEnvironment();
48
+ switch (env) {
49
+ case "NODE":
50
+ case "BUN":
51
+ return typeof process !== "undefined" ? process.hrtime.bigint() : 0n;
52
+ case "DENO":
53
+ return BigInt(Math.floor(performance.now() * 1e6));
54
+ case "BROWSER":
55
+ if ("Temporal" in globalThis) {
56
+ try {
57
+ return globalThis.Temporal.Now.instant().epochNanoseconds;
58
+ } catch {
59
+ }
60
+ }
61
+ if (typeof performance !== "undefined") {
62
+ return BigInt(Math.floor(performance.now() * 1e6));
63
+ }
64
+ return BigInt(Date.now()) * 1000000n;
65
+ default:
66
+ return -1n;
67
+ }
68
+ }
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ getEnvironment,
72
+ getPreciseTime
73
+ });
74
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/environment.ts","../src/time.ts"],"sourcesContent":["export * from \"./environment.js\"\nexport * from \"./time.js\"\nexport type * from \"./globals.d.ts\"","export type RuntimeEnvironment = \"DENO\" | \"BUN\" | \"NODE\" | \"BROWSER\" | \"UNKNOWN\";\n\nexport function getEnvironment(): RuntimeEnvironment {\n // 1. Check for Deno\n // We check 'Deno' on globalThis to avoid \"Cannot find name\" errors\n if (\"Deno\" in globalThis && (globalThis as any).Deno.version) {\n return \"DENO\";\n }\n\n // 2. Check for Bun\n if (\"Bun\" in globalThis) {\n return \"BUN\";\n }\n\n // 3. Check for Node.js\n if (\"process\" in globalThis && (globalThis as any).process.versions?.node) {\n return \"NODE\";\n }\n\n // 4. Check for Browser\n if (\"window\" in globalThis) {\n return \"BROWSER\";\n }\n\n return \"UNKNOWN\";\n}","import { getEnvironment } from \"./environment.js\";\n\nexport function getPreciseTime(): bigint {\n const env = getEnvironment();\n\n switch (env) {\n case \"NODE\":\n case \"BUN\":\n // Both Node and Bun support process.hrtime.bigint() \n // This is the gold standard for nanoseconds.\n return typeof process !== \"undefined\" ? process.hrtime.bigint() : 0n;\n\n case \"DENO\":\n // Deno supports performance.now(), but we must convert \n // ms (float) to ns (bigint).\n return BigInt(Math.floor(performance.now() * 1_000_000));\n\n case \"BROWSER\":\n // Check for Temporal safely\n if (\"Temporal\" in globalThis) {\n try {\n return (globalThis as any).Temporal.Now.instant().epochNanoseconds;\n } catch {\n // Fallback if Temporal exists but fails\n }\n }\n\n // Fallback to performance.now()\n if (typeof performance !== \"undefined\") {\n return BigInt(Math.floor(performance.now() * 1_000_000));\n }\n\n // Final fallback to Date\n return BigInt(Date.now()) * 1_000_000n;\n\n default:\n return -1n;\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,SAAS,iBAAqC;AAGjD,MAAI,UAAU,cAAe,WAAmB,KAAK,SAAS;AAC1D,WAAO;AAAA,EACX;AAGA,MAAI,SAAS,YAAY;AACrB,WAAO;AAAA,EACX;AAGA,MAAI,aAAa,cAAe,WAAmB,QAAQ,UAAU,MAAM;AACvE,WAAO;AAAA,EACX;AAGA,MAAI,YAAY,YAAY;AACxB,WAAO;AAAA,EACX;AAEA,SAAO;AACX;;;ACvBO,SAAS,iBAAyB;AACrC,QAAM,MAAM,eAAe;AAE3B,UAAQ,KAAK;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AAGD,aAAO,OAAO,YAAY,cAAc,QAAQ,OAAO,OAAO,IAAI;AAAA,IAEtE,KAAK;AAGD,aAAO,OAAO,KAAK,MAAM,YAAY,IAAI,IAAI,GAAS,CAAC;AAAA,IAE3D,KAAK;AAED,UAAI,cAAc,YAAY;AAC1B,YAAI;AACA,iBAAQ,WAAmB,SAAS,IAAI,QAAQ,EAAE;AAAA,QACtD,QAAQ;AAAA,QAER;AAAA,MACJ;AAGA,UAAI,OAAO,gBAAgB,aAAa;AACpC,eAAO,OAAO,KAAK,MAAM,YAAY,IAAI,IAAI,GAAS,CAAC;AAAA,MAC3D;AAGA,aAAO,OAAO,KAAK,IAAI,CAAC,IAAI;AAAA,IAEhC;AACI,aAAO,CAAC;AAAA,EAChB;AACJ;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,46 @@
1
- export * from "./environment.js";
2
- export * from "./time.js";
1
+ // src/environment.ts
2
+ function getEnvironment() {
3
+ if ("Deno" in globalThis && globalThis.Deno.version) {
4
+ return "DENO";
5
+ }
6
+ if ("Bun" in globalThis) {
7
+ return "BUN";
8
+ }
9
+ if ("process" in globalThis && globalThis.process.versions?.node) {
10
+ return "NODE";
11
+ }
12
+ if ("window" in globalThis) {
13
+ return "BROWSER";
14
+ }
15
+ return "UNKNOWN";
16
+ }
17
+
18
+ // src/time.ts
19
+ function getPreciseTime() {
20
+ const env = getEnvironment();
21
+ switch (env) {
22
+ case "NODE":
23
+ case "BUN":
24
+ return typeof process !== "undefined" ? process.hrtime.bigint() : 0n;
25
+ case "DENO":
26
+ return BigInt(Math.floor(performance.now() * 1e6));
27
+ case "BROWSER":
28
+ if ("Temporal" in globalThis) {
29
+ try {
30
+ return globalThis.Temporal.Now.instant().epochNanoseconds;
31
+ } catch {
32
+ }
33
+ }
34
+ if (typeof performance !== "undefined") {
35
+ return BigInt(Math.floor(performance.now() * 1e6));
36
+ }
37
+ return BigInt(Date.now()) * 1000000n;
38
+ default:
39
+ return -1n;
40
+ }
41
+ }
42
+ export {
43
+ getEnvironment,
44
+ getPreciseTime
45
+ };
46
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/environment.ts","../src/time.ts"],"sourcesContent":["export type RuntimeEnvironment = \"DENO\" | \"BUN\" | \"NODE\" | \"BROWSER\" | \"UNKNOWN\";\n\nexport function getEnvironment(): RuntimeEnvironment {\n // 1. Check for Deno\n // We check 'Deno' on globalThis to avoid \"Cannot find name\" errors\n if (\"Deno\" in globalThis && (globalThis as any).Deno.version) {\n return \"DENO\";\n }\n\n // 2. Check for Bun\n if (\"Bun\" in globalThis) {\n return \"BUN\";\n }\n\n // 3. Check for Node.js\n if (\"process\" in globalThis && (globalThis as any).process.versions?.node) {\n return \"NODE\";\n }\n\n // 4. Check for Browser\n if (\"window\" in globalThis) {\n return \"BROWSER\";\n }\n\n return \"UNKNOWN\";\n}","import { getEnvironment } from \"./environment.js\";\n\nexport function getPreciseTime(): bigint {\n const env = getEnvironment();\n\n switch (env) {\n case \"NODE\":\n case \"BUN\":\n // Both Node and Bun support process.hrtime.bigint() \n // This is the gold standard for nanoseconds.\n return typeof process !== \"undefined\" ? process.hrtime.bigint() : 0n;\n\n case \"DENO\":\n // Deno supports performance.now(), but we must convert \n // ms (float) to ns (bigint).\n return BigInt(Math.floor(performance.now() * 1_000_000));\n\n case \"BROWSER\":\n // Check for Temporal safely\n if (\"Temporal\" in globalThis) {\n try {\n return (globalThis as any).Temporal.Now.instant().epochNanoseconds;\n } catch {\n // Fallback if Temporal exists but fails\n }\n }\n\n // Fallback to performance.now()\n if (typeof performance !== \"undefined\") {\n return BigInt(Math.floor(performance.now() * 1_000_000));\n }\n\n // Final fallback to Date\n return BigInt(Date.now()) * 1_000_000n;\n\n default:\n return -1n;\n }\n}"],"mappings":";AAEO,SAAS,iBAAqC;AAGjD,MAAI,UAAU,cAAe,WAAmB,KAAK,SAAS;AAC1D,WAAO;AAAA,EACX;AAGA,MAAI,SAAS,YAAY;AACrB,WAAO;AAAA,EACX;AAGA,MAAI,aAAa,cAAe,WAAmB,QAAQ,UAAU,MAAM;AACvE,WAAO;AAAA,EACX;AAGA,MAAI,YAAY,YAAY;AACxB,WAAO;AAAA,EACX;AAEA,SAAO;AACX;;;ACvBO,SAAS,iBAAyB;AACrC,QAAM,MAAM,eAAe;AAE3B,UAAQ,KAAK;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AAGD,aAAO,OAAO,YAAY,cAAc,QAAQ,OAAO,OAAO,IAAI;AAAA,IAEtE,KAAK;AAGD,aAAO,OAAO,KAAK,MAAM,YAAY,IAAI,IAAI,GAAS,CAAC;AAAA,IAE3D,KAAK;AAED,UAAI,cAAc,YAAY;AAC1B,YAAI;AACA,iBAAQ,WAAmB,SAAS,IAAI,QAAQ,EAAE;AAAA,QACtD,QAAQ;AAAA,QAER;AAAA,MACJ;AAGA,UAAI,OAAO,gBAAgB,aAAa;AACpC,eAAO,OAAO,KAAK,MAAM,YAAY,IAAI,IAAI,GAAS,CAAC;AAAA,MAC3D;AAGA,aAAO,OAAO,KAAK,IAAI,CAAC,IAAI;AAAA,IAEhC;AACI,aAAO,CAAC;AAAA,EAChB;AACJ;","names":[]}
package/package.json CHANGED
@@ -1,40 +1,23 @@
1
1
  {
2
- "name": "@smartlogs/shared",
3
- "version": "0.0.6",
4
- "description": "Shared functions for SmartLogs",
5
- "main": "dist/index.js",
6
- "module": "dist/index.cjs",
7
- "types": "dist/index.d.ts",
8
- "files": [
9
- "dist"
10
- ],
11
- "exports": {
12
- ".": {
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.mjs",
15
- "require": "./dist/index.js"
2
+ "name": "@smartlogs/shared",
3
+ "version": "0.0.8",
4
+ "description": "Shared functions for SmartLogs",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsup",
13
+ "prepublishOnly": "npm run build"
14
+ },
15
+ "author": "Your Name",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "@types/bun": "^1.3.5",
19
+ "@types/node": "^20.19.27",
20
+ "tsup": "^8.5.1",
21
+ "typescript": "^5.3.3"
16
22
  }
17
- },
18
- "scripts": {
19
- "dev": "tsx watch src/index.ts",
20
- "test:node": "node tests/test.ts",
21
- "test:bun": "bun tests/test.ts",
22
- "build": "npm run build:esm && npm run build:commonjs",
23
- "build:esm": "tsc -p tsconfig.esm.json && mv dist/index.js dist/index.mjs",
24
- "build:commonjs": "tsc",
25
- "prepublishOnly": "npm run build"
26
- },
27
- "keywords": [
28
- "typescript",
29
- "npm",
30
- "package"
31
- ],
32
- "author": "Your Name",
33
- "license": "ISC",
34
- "devDependencies": {
35
- "@types/bun": "^1.3.5",
36
- "@types/node": "^20.19.27",
37
- "typescript": "^5.3.3"
38
- },
39
- "type": "module"
40
- }
23
+ }
@@ -1,2 +0,0 @@
1
- export type RuntimeEnvironment = "DENO" | "BUN" | "NODE" | "BROWSER" | "UNKNOWN";
2
- export declare function getEnvironment(): RuntimeEnvironment;
@@ -1,20 +0,0 @@
1
- export function getEnvironment() {
2
- // 1. Check for Deno
3
- // We check 'Deno' on globalThis to avoid "Cannot find name" errors
4
- if ("Deno" in globalThis && globalThis.Deno.version) {
5
- return "DENO";
6
- }
7
- // 2. Check for Bun
8
- if ("Bun" in globalThis) {
9
- return "BUN";
10
- }
11
- // 3. Check for Node.js
12
- if ("process" in globalThis && globalThis.process.versions?.node) {
13
- return "NODE";
14
- }
15
- // 4. Check for Browser
16
- if ("window" in globalThis) {
17
- return "BROWSER";
18
- }
19
- return "UNKNOWN";
20
- }
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
1
- console.log("Hello via Bun!");
package/dist/time.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function getPreciseTime(): bigint;
package/dist/time.js DELETED
@@ -1,33 +0,0 @@
1
- import { getEnvironment } from "./environment.js";
2
- export function getPreciseTime() {
3
- const env = getEnvironment();
4
- switch (env) {
5
- case "NODE":
6
- case "BUN":
7
- // Both Node and Bun support process.hrtime.bigint()
8
- // This is the gold standard for nanoseconds.
9
- return typeof process !== "undefined" ? process.hrtime.bigint() : 0n;
10
- case "DENO":
11
- // Deno supports performance.now(), but we must convert
12
- // ms (float) to ns (bigint).
13
- return BigInt(Math.floor(performance.now() * 1000000));
14
- case "BROWSER":
15
- // Check for Temporal safely
16
- if ("Temporal" in globalThis) {
17
- try {
18
- return globalThis.Temporal.Now.instant().epochNanoseconds;
19
- }
20
- catch {
21
- // Fallback if Temporal exists but fails
22
- }
23
- }
24
- // Fallback to performance.now()
25
- if (typeof performance !== "undefined") {
26
- return BigInt(Math.floor(performance.now() * 1000000));
27
- }
28
- // Final fallback to Date
29
- return BigInt(Date.now()) * 1000000n;
30
- default:
31
- return -1n;
32
- }
33
- }