@smartlogs/shared 0.0.3 → 0.0.4

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,2 @@
1
+ export type RuntimeEnvironment = "DENO" | "BUN" | "NODE" | "BROWSER" | "UNKNOWN";
2
+ export declare function getEnvironment(): RuntimeEnvironment;
@@ -0,0 +1,20 @@
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 ADDED
@@ -0,0 +1 @@
1
+ console.log("Hello via Bun!");
package/dist/index.d.ts CHANGED
@@ -1,32 +1,3 @@
1
- export interface Store {
2
- workflows: Workflow[];
3
- }
4
- export interface Workflow {
5
- workflowId: string;
6
- title: string;
7
- description: string;
8
- logs: Log[];
9
- }
10
- export interface Log {
11
- workflowId: string;
12
- message: string;
13
- body: object;
14
- timestamp: Date | string;
15
- clientTime: string;
16
- elapsedTime?: string;
17
- origin: string;
18
- spacer?: boolean;
19
- order: number;
20
- }
21
- export interface WorkflowProps {
22
- workflowId: string;
23
- title: string;
24
- description: string;
25
- }
26
- export interface MessageObject {
27
- action: string;
28
- payload: string;
29
- }
30
- export type RuntimeEnvironment = "DENO" | "NODE" | "BROWSER" | "UNKNOWN";
31
- export declare function getPreciseTime(): bigint;
32
- export declare function getEnvironment(): RuntimeEnvironment;
1
+ export * from "./environment.js";
2
+ export * from "./time.js";
3
+ export type * from "./index.d.ts";
package/dist/index.js CHANGED
@@ -1,43 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPreciseTime = getPreciseTime;
4
- exports.getEnvironment = getEnvironment;
5
- function getPreciseTime() {
6
- switch (getEnvironment()) {
7
- case "DENO":
8
- return BigInt(Math.round(performance.now() * 1000000));
9
- case "NODE":
10
- if (process) {
11
- return process.hrtime.bigint();
12
- }
13
- else {
14
- return BigInt(0n);
15
- }
16
- case "BROWSER":
17
- // if (Temporal && typeof Temporal !== "undefined" && Temporal.Now.instant().epochNanoseconds) {
18
- if (Temporal && typeof Temporal !== "undefined" && Temporal.Now.instant().epochNanoseconds) {
19
- return BigInt(Temporal.Now.instant().epochNanoseconds);
20
- }
21
- else {
22
- return BigInt(0n);
23
- }
24
- case "UNKNOWN":
25
- return BigInt(-1);
26
- }
27
- }
28
- function getEnvironment() {
29
- // Check for Deno
30
- if (typeof Deno !== "undefined" && Deno.version) {
31
- return "DENO";
32
- }
33
- // Check for Node.js
34
- if (typeof process !== "undefined" && process.versions?.node) {
35
- return "NODE";
36
- }
37
- // Check for Browser
38
- if (typeof window !== "undefined" // && typeof window.document !== "undefined"
39
- ) {
40
- return "BROWSER";
41
- }
42
- return "UNKNOWN";
43
- }
1
+ export * from "./environment.js";
2
+ export * from "./time.js";
package/dist/index.mjs CHANGED
@@ -1,39 +1,2 @@
1
- export function getPreciseTime() {
2
- switch (getEnvironment()) {
3
- case "DENO":
4
- return BigInt(Math.round(performance.now() * 1000000));
5
- case "NODE":
6
- if (process) {
7
- return process.hrtime.bigint();
8
- }
9
- else {
10
- return BigInt(0n);
11
- }
12
- case "BROWSER":
13
- // if (Temporal && typeof Temporal !== "undefined" && Temporal.Now.instant().epochNanoseconds) {
14
- if (Temporal && typeof Temporal !== "undefined" && Temporal.Now.instant().epochNanoseconds) {
15
- return BigInt(Temporal.Now.instant().epochNanoseconds);
16
- }
17
- else {
18
- return BigInt(0n);
19
- }
20
- case "UNKNOWN":
21
- return BigInt(-1);
22
- }
23
- }
24
- export function getEnvironment() {
25
- // Check for Deno
26
- if (typeof Deno !== "undefined" && Deno.version) {
27
- return "DENO";
28
- }
29
- // Check for Node.js
30
- if (typeof process !== "undefined" && process.versions?.node) {
31
- return "NODE";
32
- }
33
- // Check for Browser
34
- if (typeof window !== "undefined" // && typeof window.document !== "undefined"
35
- ) {
36
- return "BROWSER";
37
- }
38
- return "UNKNOWN";
39
- }
1
+ export * from "./environment.js";
2
+ export * from "./time.js";
package/dist/time.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function getPreciseTime(): bigint;
package/dist/time.js ADDED
@@ -0,0 +1,33 @@
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
+ }
package/package.json CHANGED
@@ -1,37 +1,41 @@
1
1
  {
2
- "name": "@smartlogs/shared",
3
- "version": "0.0.3",
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"
16
- }
17
- },
18
- "scripts": {
19
- "dev": "tsx watch src/index.ts",
20
- "build": "npm run build:esm && npm run build:commonjs",
21
- "build:esm": "tsc -p tsconfig.esm.json && mv dist/index.js dist/index.mjs",
22
- "build:commonjs": "tsc",
23
- "prepublishOnly": "npm run build"
24
- },
25
- "keywords": [
26
- "typescript",
27
- "npm",
28
- "package"
29
- ],
30
- "author": "Your Name",
31
- "license": "ISC",
32
- "devDependencies": {
33
- "@smartlogs/shared": "file:../smartlogs-shared",
34
- "@types/node": "^20.19.27",
35
- "typescript": "^5.3.3"
2
+ "name": "@smartlogs/shared",
3
+ "version": "0.0.4",
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"
36
16
  }
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
+ "@smartlogs/shared": "file:../smartlogs-shared",
36
+ "@types/bun": "^1.3.5",
37
+ "@types/node": "^20.19.27",
38
+ "typescript": "^5.3.3"
39
+ },
40
+ "type": "module"
37
41
  }