@smartlogs/shared 0.0.3

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,32 @@
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;
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
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
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1,39 @@
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
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
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"
36
+ }
37
+ }