@starbeam/debug
Advanced tools
Comparing version 0.8.10-unstable.0b31af0 to 0.8.10-unstable.229fe05
255
CHANGELOG.md
@@ -1,255 +0,2 @@ | ||
# @starbeam/debug | ||
# Changelog | ||
## 0.8.9 | ||
### Patch Changes | ||
- e459bf2: Fix CJS builds | ||
- Updated dependencies [e459bf2] | ||
- @starbeam/core-utils@0.8.9 | ||
- @starbeam/interfaces@0.8.9 | ||
- @starbeam/shared@1.3.7 | ||
- @starbeam/verify@0.8.9 | ||
## 0.8.8 | ||
### Patch Changes | ||
- 2a1f728: Improve @starbeam/react | ||
- Updated dependencies [2a1f728] | ||
- @starbeam/core-utils@0.8.8 | ||
- @starbeam/interfaces@0.8.8 | ||
- @starbeam/shared@1.3.6 | ||
- @starbeam/verify@0.8.8 | ||
## 0.8.7 | ||
### Patch Changes | ||
- 14f961b: Fixes #75 | ||
- Updated dependencies [14f961b] | ||
- @starbeam/core-utils@0.8.7 | ||
- @starbeam/interfaces@0.8.7 | ||
- @starbeam/shared@1.3.5 | ||
- @starbeam/verify@0.8.7 | ||
## 0.8.7 | ||
### Patch Changes | ||
- ded6421: Add /setup to preact | ||
- Updated dependencies [ded6421] | ||
- @starbeam/core-utils@0.8.7 | ||
- @starbeam/interfaces@0.8.7 | ||
- @starbeam/shared@1.3.4 | ||
- @starbeam/verify@0.8.7 | ||
## 0.8.6 | ||
### Patch Changes | ||
- 6502cc7: Remove errant import | ||
- Updated dependencies [6502cc7] | ||
- @starbeam/core-utils@0.8.6 | ||
- @starbeam/interfaces@0.8.6 | ||
- @starbeam/shared@1.3.3 | ||
- @starbeam/verify@0.8.6 | ||
## 0.8.5 | ||
### Patch Changes | ||
- de755c6: Improve type inference | ||
- Updated dependencies [de755c6] | ||
- @starbeam/interfaces@0.8.5 | ||
- @starbeam/core-utils@0.8.5 | ||
- @starbeam/shared@1.3.2 | ||
- @starbeam/verify@0.8.5 | ||
## 0.8.4 | ||
### Patch Changes | ||
- 3bf1221: Prepare for Starbeam 0.8.4 | ||
- Updated dependencies [3bf1221] | ||
- @starbeam/interfaces@0.8.4 | ||
- @starbeam/core-utils@0.8.4 | ||
- @starbeam/shared@1.3.1 | ||
- @starbeam/verify@0.8.4 | ||
- @domtree/flavors@0.9.3 | ||
## 0.8.3 | ||
### Patch Changes | ||
- e737bff: Build | ||
## 0.8.2 | ||
### Patch Changes | ||
- dd8ff3f: Remove chalk from @starbeam/debug | ||
## 0.8.1 | ||
### Patch Changes | ||
- a781c84: Make chalk work in the browser by setting globalThis.process = {} | ||
## 0.8.0 | ||
### Minor Changes | ||
- 1a553c5: Prepare for 0.8 | ||
### Patch Changes | ||
- Updated dependencies [1a553c5] | ||
- @starbeam/interfaces@0.8.0 | ||
- @starbeam/core-utils@0.8.0 | ||
- @starbeam/shared@1.3.0 | ||
- @starbeam/verify@0.8.0 | ||
- @domtree/flavors@0.9.2 | ||
## 0.7.4 | ||
### Patch Changes | ||
- 40844fd: Try to fix the build | ||
- Updated dependencies [40844fd] | ||
- @starbeam/interfaces@0.7.3 | ||
- @starbeam/verify@0.7.3 | ||
- @domtree/flavors@0.9.1 | ||
- @starbeam/shared@1.2.2 | ||
## 0.7.3 | ||
### Patch Changes | ||
- f38704e: Fix the build when deps have an `imports` key in their package.json | ||
## 0.7.2 | ||
### Patch Changes | ||
- 50f7a8f: Publish @domtree | ||
- Updated dependencies [50f7a8f] | ||
- @domtree/flavors@0.9.1 | ||
- @starbeam/interfaces@0.7.2 | ||
- @starbeam/shared@1.2.1 | ||
- @starbeam/verify@0.7.1 | ||
## 0.7.1 | ||
### Patch Changes | ||
- 4501b1f: Publish the @domtree packages | ||
- Updated dependencies [4501b1f] | ||
- @domtree/flavors@0.9.1 | ||
- @starbeam/interfaces@0.7.1 | ||
## 0.7.0 | ||
### Minor Changes | ||
- 58f7974: Starbeam 0.7.0 | ||
- Significant improvements to debugging infrastructure | ||
### Patch Changes | ||
- Updated dependencies [58f7974] | ||
- @starbeam/interfaces@null | ||
- @starbeam/shared@1.2.0 | ||
- @starbeam/verify@0.7.0 | ||
## 0.6.1 | ||
### Patch Changes | ||
- 90556b5: Bundle stacktracey and other problematic CJS deps | ||
## 0.6.0 | ||
### Minor Changes | ||
- Prepare 0.6.0 | ||
### Patch Changes | ||
- Updated dependencies | ||
- @starbeam/shared@1.1.0 | ||
- @starbeam/verify@0.6.0 | ||
## 0.5.8 | ||
### Patch Changes | ||
- Prepare 0.5.8 | ||
- Updated dependencies | ||
- @starbeam/shared@1.0.8 | ||
- @starbeam/verify@0.5.8 | ||
## 0.5.7 | ||
### Patch Changes | ||
- Fix a bug in the transition from uninitialized to initialized reactive Map | ||
- Updated dependencies | ||
- @starbeam/shared@1.0.7 | ||
- @starbeam/verify@0.5.7 | ||
## 0.5.6 | ||
### Patch Changes | ||
- Fix ESM package mistakes | ||
- Updated dependencies | ||
- @starbeam/shared@1.0.6 | ||
- @starbeam/verify@0.5.6 | ||
## 0.5.5 | ||
### Patch Changes | ||
- Another attempt to get the build right | ||
- Updated dependencies | ||
- @starbeam/shared@1.0.5 | ||
- @starbeam/verify@0.5.5 | ||
## 0.5.4 | ||
### Patch Changes | ||
- The 0.5.3 release was missing dists | ||
- Updated dependencies | ||
- @starbeam/verify@0.5.4 | ||
- @starbeam/shared@1.0.4 | ||
## 0.5.3 | ||
### Patch Changes | ||
- 194e461: Added untracked consumption errors and infrastructure for tracking reads and writes to cells | ||
- d21391d: Update resources to support React's three-phase lifecycle | ||
- Updated dependencies [d21391d] | ||
- @starbeam/shared@1.0.3 | ||
- @starbeam/verify@0.5.3 | ||
## 0.5.2 | ||
### Patch Changes | ||
- 719a6fe: Updated package export maps | ||
- Updated dependencies [719a6fe] | ||
- @starbeam/verify@0.5.2 | ||
## 0.5.1 | ||
### Patch Changes | ||
- 2a957e5: Try to fix types | ||
- e03c2a0: Initial publish | ||
- Updated dependencies [2a957e5] | ||
- Updated dependencies [e03c2a0] | ||
- @starbeam/verify@0.5.1 |
@@ -1,7 +0,7 @@ | ||
import { UNKNOWN_REACTIVE_VALUE, DEBUG, defineDebug } from '@starbeam/reactive'; | ||
import { firstNItems, isPresent, getFirst, mapArray, defineObject, dataGetter, isPresentArray, getLast, withoutFirst, nullifyEmptyArray, isObject, getLastIndex } from '@starbeam/core-utils'; | ||
import { verified, verify, hasType } from '@starbeam/verify'; | ||
import { firstNItems, mapArray, defineObject, dataGetter, isPresentArray, getFirst, getLast, withoutFirst, nullifyEmptyArray, isObject, getLastIndex, isPresent } from '@starbeam/core-utils'; | ||
import { verify, hasType } from '@starbeam/verify'; | ||
import StackTracey from 'stacktracey'; | ||
import { UNKNOWN_REACTIVE_VALUE, DEBUG } from '@starbeam/reactive'; | ||
import { getTag, getDependencies, lastUpdated } from '@starbeam/tags'; | ||
import { getID } from '@starbeam/shared'; | ||
import { getTag, getDependencies, lastUpdated } from '@starbeam/tags'; | ||
@@ -29,4 +29,4 @@ function parseModule(filename, codebase) { | ||
* The whole `Stack` system is only intended to be used for logging, so the | ||
* edge-cases where this normalization wouldn't work (verbatim paths on Windows) | ||
* shouldn't matter. | ||
* edge-cases where this normalization wouldn't work (verbatim paths on | ||
* Windows) shouldn't matter. | ||
*/ function normalizePath(...pathParts) { | ||
@@ -36,4 +36,4 @@ return pathParts.filter((part)=>typeof part === "string").map((p)=>p.replaceAll(/[\\]/g, "/")).join("/"); | ||
/** | ||
* This function takes two paths and returns the suffix of the target that comes | ||
* after any shared prefix with the source. | ||
* This function takes two paths and returns the suffix of the target that | ||
* comes after any shared prefix with the source. | ||
* | ||
@@ -53,29 +53,2 @@ * For example, if the source is `/src/app/foo/bar` and the target is | ||
} | ||
if (import.meta.vitest) { | ||
const { test, expect } = import.meta.vitest; | ||
test("should return the path if it's not nested in a root", ()=>{ | ||
expect(normalizeModule("./foo/bar")).toStrictEqual({ | ||
path: "./foo/bar" | ||
}); | ||
expect(parseModule("./foo/bar")).toStrictEqual({ | ||
path: "./foo/bar" | ||
}); | ||
}); | ||
test("should find the pivot path", ()=>{ | ||
expect(normalizeModule("/src/app/index.ts", "/src/app/some/nested/file.ts")).toStrictEqual({ | ||
root: "/src/app/", | ||
path: "index.ts" | ||
}); | ||
expect(parseModule("/src/app/index.ts", "/src/app/some/nested/file.ts")).toStrictEqual({ | ||
root: "/src/app/", | ||
path: "index.ts" | ||
}); | ||
}); | ||
test("pivotPath", ()=>{ | ||
expect(pivotPath("/src/app/foo/bar", "/src/app/baz/qux")).toEqual({ | ||
prefix: "/src/app/", | ||
suffix: "baz/qux" | ||
}); | ||
}); | ||
} | ||
@@ -93,3 +66,3 @@ const INITIAL_INTERNAL_FRAMES = 1; | ||
const stack = Error("An error created in the internals of Stack.create").stack; | ||
verify(stack, hasType("string")); | ||
verify?.(stack, hasType("string")); | ||
return callStack(stack)?.slice(internal + CALLER); | ||
@@ -154,74 +127,2 @@ } | ||
} | ||
function isErrorWithStack(value) { | ||
return hasType("object")(value) && hasType("string")(value.stack); | ||
} | ||
if (import.meta.vitest) { | ||
const { test, expect, describe } = import.meta.vitest; | ||
const filename = new URL(import.meta.url).pathname; | ||
function anAction() { | ||
throw Error(ERROR_MESSAGE); | ||
} | ||
const ERROR_LOC = { | ||
line: 140, | ||
column: 11 | ||
}; | ||
function aCallerAction() { | ||
return callerStack(); | ||
} | ||
const ERROR_MESSAGE = "an error happened in an action"; | ||
const CALLER_FRAME = 1; | ||
test("parseStack", ()=>{ | ||
try { | ||
anAction(); | ||
} catch (e) { | ||
const { header, entries, lines, trace } = verified(parseStack(verified(e, isErrorWithStack).stack), isPresent); | ||
expect(header).toBe(`Error: ${ERROR_MESSAGE}`); | ||
expect(lines).toHaveLength(entries.length); | ||
expect(trace.items).toEqual(entries); | ||
expect(getFirst(lines)).toMatch(/\banAction\b/); | ||
} | ||
}); | ||
{ | ||
function testCallStack() { | ||
try { | ||
anAction(); | ||
} catch (e) { | ||
const stack = verified(callStack(verified(e, isErrorWithStack).stack, filename), isPresent); | ||
expect(stack.header).toBe(`Error: ${ERROR_MESSAGE}`); | ||
const frameSize = stack.frames.length; | ||
expect(stack.slice(CALLER_FRAME)?.frames).toHaveLength(frameSize - CALLER_FRAME); | ||
const firstFrame = getFirst(stack.slice(CALLER_FRAME)?.frames ?? []); | ||
expect(firstFrame?.action).toBe(TEST_NAME); | ||
} | ||
} | ||
const TEST_NAME = testCallStack.name; | ||
test("callStack", testCallStack); | ||
} | ||
{ | ||
function testCallerStack() { | ||
const caller = verified(aCallerAction(), isPresent); | ||
expect(getFirst(caller.frames).action).toBe(TEST_NAME); | ||
} | ||
const TEST_NAME = testCallerStack.name; | ||
test("callerStack", testCallerStack); | ||
} | ||
describe("StackFrame", ()=>{ | ||
test("action", ()=>{ | ||
try { | ||
anAction(); | ||
} catch (e) { | ||
verify(e, isErrorWithStack); | ||
const trace = new StackTracey(e.stack); | ||
const first = verified(getFirst(trace.items), isPresent); | ||
const frame = stackFrame(()=>trace.withSource(first), filename); | ||
expect(frame.action).toBe("anAction"); | ||
expect(frame.module).toEqual({ | ||
path: "stack.ts", | ||
root: new URL(".", import.meta.url).pathname | ||
}); | ||
expect(frame.loc).toEqual(ERROR_LOC); | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -351,289 +252,2 @@ function describeTagged(tagged) { | ||
}; | ||
if (import.meta.vitest) { | ||
const { test, expect, describe: group } = import.meta.vitest; | ||
test("getIdString", ()=>{ | ||
expect(getIdString("myid")).toEqual("myid"); | ||
// eslint-disable-next-line @typescript-eslint/no-magic-numbers | ||
expect(getIdString(123)).toEqual("123"); | ||
expect(getIdString([ | ||
"a", | ||
"b", | ||
"c" | ||
])).toEqual("a/b/c"); | ||
expect(getIdString([ | ||
"a", | ||
[ | ||
"b", | ||
"c" | ||
], | ||
"d" | ||
])).toEqual("a->(b/c)->d"); | ||
expect(getIdString([ | ||
"a", | ||
[ | ||
"b", | ||
"c" | ||
], | ||
[ | ||
"d", | ||
"e" | ||
] | ||
])).toEqual("a->(b/c)->(d/e)"); | ||
expect(getIdString([ | ||
[ | ||
"a", | ||
"b" | ||
], | ||
[ | ||
"c", | ||
"d" | ||
] | ||
])).toEqual("(a/b)->(c/d)"); | ||
expect(getIdString([ | ||
"a", | ||
[ | ||
"b", | ||
"c" | ||
], | ||
[ | ||
"d", | ||
"e" | ||
], | ||
"f" | ||
])).toEqual("a->(b/c)->(d/e)->f"); | ||
expect(getIdString([ | ||
"a", | ||
[ | ||
"b", | ||
"c" | ||
], | ||
[ | ||
"d", | ||
"e" | ||
], | ||
[ | ||
"f", | ||
"g" | ||
] | ||
])).toEqual("a->(b/c)->(d/e)->(f/g)"); | ||
// multiple levels of nesting | ||
expect(getIdString([ | ||
"a", | ||
[ | ||
"b", | ||
[ | ||
"c", | ||
"d" | ||
], | ||
"e" | ||
], | ||
"f" | ||
])).toEqual("a->(b->(c/d)->e)->f"); | ||
}); | ||
test("getUserFacing", ()=>{ | ||
const parentId = getID(); | ||
const childId = getID(); | ||
const parent = { | ||
type: "cell", | ||
caller: undefined, | ||
id: parentId, | ||
specified: "mycell" | ||
}; | ||
const child = { | ||
type: "cell", | ||
caller: undefined, | ||
id: childId, | ||
nesting: { | ||
type: "implementation", | ||
parent, | ||
value: { | ||
name: "initialized?", | ||
reason: "the cell was initialized" | ||
} | ||
} | ||
}; | ||
expect(getUserFacing(child)).toEqual(parent); | ||
expect(getUserFacing(parent)).toEqual(parent); | ||
}); | ||
test("describeFlat", ()=>{ | ||
expect(describeFlat({ | ||
type: "specified", | ||
value: "mycell" | ||
})).toEqual("mycell"); | ||
const id = getID(); | ||
expect(describeFlat({ | ||
type: "anonymous", | ||
kind: "cell", | ||
id | ||
})).toEqual(`{anonymous cell:${id}}`); | ||
}); | ||
test("describeFullName", ()=>{ | ||
expect(describeFullName({ | ||
type: "specified", | ||
value: "mycell" | ||
})).toEqual("mycell"); | ||
const id = getID(); | ||
expect(describeFullName({ | ||
type: "anonymous", | ||
kind: "cell", | ||
id | ||
})).toEqual(`{anonymous cell:${id}}`); | ||
const parentId = getID(); | ||
const childId = getID(); | ||
const parent = { | ||
type: "cell", | ||
caller: undefined, | ||
id: parentId, | ||
specified: "mycell" | ||
}; | ||
const child = { | ||
type: "cell", | ||
caller: undefined, | ||
id: childId, | ||
nesting: { | ||
type: "implementation", | ||
parent, | ||
value: { | ||
name: "initialized?", | ||
reason: "the cell was initialized" | ||
} | ||
} | ||
}; | ||
expect(describeFullName(getFullName(child))).toEqual("mycell->{impl: initialized?}"); | ||
expect(describeFullName([ | ||
{ | ||
type: "specified", | ||
value: "mycell" | ||
}, | ||
{ | ||
type: "implementation", | ||
value: { | ||
name: "initialized?", | ||
reason: "" | ||
} | ||
} | ||
])).toEqual("mycell->{impl: initialized?}"); | ||
const specified = { | ||
type: "specified", | ||
value: "mycell" | ||
}; | ||
const anonymous = { | ||
type: "anonymous", | ||
kind: "cell", | ||
id: 1 | ||
}; | ||
expect(describeFullName([ | ||
anonymous, | ||
{ | ||
type: "index", | ||
value: 2 | ||
} | ||
])).toEqual("{anonymous cell:1}[2]"); | ||
expect(describeFullName([ | ||
specified, | ||
{ | ||
type: "index", | ||
value: 2 | ||
} | ||
])).toEqual("mycell[2]"); | ||
expect(describeFullName([ | ||
anonymous, | ||
{ | ||
type: "key", | ||
value: { | ||
name: "foo", | ||
key: {} | ||
} | ||
} | ||
])).toEqual("{anonymous cell:1}.get(foo)"); | ||
expect(describeFullName([ | ||
specified, | ||
{ | ||
type: "key", | ||
value: { | ||
name: "foo", | ||
key: {} | ||
} | ||
} | ||
])).toEqual("mycell.get(foo)"); | ||
expect(describeFullName([ | ||
anonymous, | ||
{ | ||
type: "property", | ||
value: "foo" | ||
} | ||
])).toEqual("{anonymous cell:1}.foo"); | ||
expect(describeFullName([ | ||
specified, | ||
{ | ||
type: "property", | ||
value: "foo" | ||
} | ||
])).toEqual("mycell.foo"); | ||
}); | ||
group("getFullName", ()=>{ | ||
test("anonymous", ()=>{ | ||
const id = getID(); | ||
const description = { | ||
type: "cell", | ||
caller: undefined, | ||
id | ||
}; | ||
expect(getFullName(description)).toEqual({ | ||
type: "anonymous", | ||
kind: "cell", | ||
id | ||
}); | ||
}); | ||
test("specified", ()=>{ | ||
const description = { | ||
type: "cell", | ||
caller: undefined, | ||
id: getID(), | ||
specified: "mycell" | ||
}; | ||
expect(getFullName(description)).toEqual({ | ||
type: "specified", | ||
value: "mycell" | ||
}); | ||
}); | ||
test("nested", ()=>{ | ||
const parentId = getID(); | ||
const childId = getID(); | ||
const parent = { | ||
type: "collection", | ||
caller: undefined, | ||
id: parentId, | ||
specified: "mymap" | ||
}; | ||
const child = { | ||
type: "collection:item", | ||
caller: undefined, | ||
id: childId, | ||
nesting: { | ||
type: "key", | ||
parent, | ||
value: { | ||
name: "foo", | ||
key: "foo" | ||
} | ||
} | ||
}; | ||
expect(getFullName(child)).toEqual([ | ||
{ | ||
type: "specified", | ||
value: "mymap" | ||
}, | ||
{ | ||
type: "key", | ||
parent, | ||
value: { | ||
name: "foo", | ||
key: "foo" | ||
} | ||
} | ||
]); | ||
}); | ||
}); | ||
} | ||
@@ -650,3 +264,3 @@ class EntryPoints { | ||
ENTRY_POINTS.#upsert(options, false); | ||
return options; | ||
return; | ||
} | ||
@@ -682,3 +296,4 @@ let caller; | ||
} | ||
return ENTRY_POINTS.mark(caller, description, force); | ||
ENTRY_POINTS.mark(caller, description, force); | ||
return; | ||
} | ||
@@ -851,14 +466,2 @@ #entry; | ||
} | ||
if (import.meta.vitest) { | ||
const { test, expect } = import.meta.vitest; | ||
test("inferred entry point", ()=>{ | ||
const hello = api(); | ||
expect(hello).toBe("hello"); | ||
expect(getEntryPoint()?.description?.label).toBe("api"); | ||
function api() { | ||
markEntryPoint(); | ||
return "hello"; | ||
} | ||
}); | ||
} | ||
@@ -1003,27 +606,25 @@ class Description { | ||
/* FIXME: do nothing for now */ }; | ||
var debug = { | ||
Desc, | ||
callerStack, | ||
getUserFacing, | ||
untrackedReadBarrier, | ||
describe: describe$1, | ||
describeTagged, | ||
markEntryPoint, | ||
getEntryPoint | ||
let debugEnv = { | ||
Desc: ()=>undefined, | ||
callerStack: ()=>undefined, | ||
getUserFacing: (x)=>x, | ||
untrackedReadBarrier: ()=>undefined, | ||
describe: ()=>'', | ||
describeTagged: ()=>'', | ||
markEntryPoint: ()=>undefined, | ||
getEntryPoint: ()=>undefined | ||
}; | ||
if (globalThis.Buffer === undefined && typeof require === "function") { | ||
try { | ||
// this is for CJS only, so require is the only option here | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const buffer = require("node:buffer"); | ||
globalThis.Buffer = buffer.Buffer; | ||
} catch { | ||
// ignore | ||
} | ||
} else { | ||
const buffer = await import('node:buffer'); | ||
globalThis.Buffer = buffer.Buffer; | ||
{ | ||
debugEnv = { | ||
Desc, | ||
callerStack, | ||
getUserFacing, | ||
untrackedReadBarrier, | ||
describe: describe$1, | ||
describeTagged, | ||
markEntryPoint, | ||
getEntryPoint | ||
}; | ||
} | ||
defineDebug(debug); | ||
var debug = debugEnv; | ||
@@ -1030,0 +631,0 @@ /** |
@@ -1,5 +0,5 @@ | ||
import { UNKNOWN_REACTIVE_VALUE, DEBUG, defineDebug } from '@starbeam/reactive'; | ||
import { firstNItems, isPresent, getFirst, mapArray, defineObject, dataGetter, isPresentArray, getLast, withoutFirst, nullifyEmptyArray, isObject, getLastIndex } from '@starbeam/core-utils'; | ||
import { verified, verify, hasType } from '@starbeam/verify'; | ||
import { firstNItems, mapArray, defineObject, dataGetter, isPresentArray, isPresent, getFirst, getLast, withoutFirst, nullifyEmptyArray, isObject, getLastIndex } from '@starbeam/core-utils'; | ||
import { verify, hasType, verified } from '@starbeam/verify'; | ||
import StackTracey from 'stacktracey'; | ||
import { UNKNOWN_REACTIVE_VALUE, DEBUG } from '@starbeam/reactive'; | ||
import { getID } from '@starbeam/shared'; | ||
@@ -29,4 +29,4 @@ import { getTag, getDependencies, lastUpdated } from '@starbeam/tags'; | ||
* The whole `Stack` system is only intended to be used for logging, so the | ||
* edge-cases where this normalization wouldn't work (verbatim paths on Windows) | ||
* shouldn't matter. | ||
* edge-cases where this normalization wouldn't work (verbatim paths on | ||
* Windows) shouldn't matter. | ||
*/ function normalizePath(...pathParts) { | ||
@@ -36,4 +36,4 @@ return pathParts.filter((part)=>typeof part === "string").map((p)=>p.replaceAll(/[\\]/g, "/")).join("/"); | ||
/** | ||
* This function takes two paths and returns the suffix of the target that comes | ||
* after any shared prefix with the source. | ||
* This function takes two paths and returns the suffix of the target that | ||
* comes after any shared prefix with the source. | ||
* | ||
@@ -92,3 +92,3 @@ * For example, if the source is `/src/app/foo/bar` and the target is | ||
const stack = Error("An error created in the internals of Stack.create").stack; | ||
verify(stack, hasType("string")); | ||
verify?.(stack, hasType("string")); | ||
return callStack(stack)?.slice(internal + CALLER); | ||
@@ -647,3 +647,3 @@ } | ||
ENTRY_POINTS.#upsert(options, false); | ||
return options; | ||
return; | ||
} | ||
@@ -679,3 +679,4 @@ let caller; | ||
} | ||
return ENTRY_POINTS.mark(caller, description, force); | ||
ENTRY_POINTS.mark(caller, description, force); | ||
return; | ||
} | ||
@@ -999,27 +1000,25 @@ #entry; | ||
/* FIXME: do nothing for now */ }; | ||
var debug = { | ||
Desc, | ||
callerStack, | ||
getUserFacing, | ||
untrackedReadBarrier, | ||
describe: describe$1, | ||
describeTagged, | ||
markEntryPoint, | ||
getEntryPoint | ||
let debugEnv = { | ||
Desc: ()=>undefined, | ||
callerStack: ()=>undefined, | ||
getUserFacing: (x)=>x, | ||
untrackedReadBarrier: ()=>undefined, | ||
describe: ()=>'', | ||
describeTagged: ()=>'', | ||
markEntryPoint: ()=>undefined, | ||
getEntryPoint: ()=>undefined | ||
}; | ||
if (globalThis.Buffer === undefined && typeof require === "function") { | ||
try { | ||
// this is for CJS only, so require is the only option here | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const buffer = require("node:buffer"); | ||
globalThis.Buffer = buffer.Buffer; | ||
} catch { | ||
// ignore | ||
} | ||
} else { | ||
const buffer = await import('node:buffer'); | ||
globalThis.Buffer = buffer.Buffer; | ||
if (import.meta.env.DEV) { | ||
debugEnv = { | ||
Desc, | ||
callerStack, | ||
getUserFacing, | ||
untrackedReadBarrier, | ||
describe: describe$1, | ||
describeTagged, | ||
markEntryPoint, | ||
getEntryPoint | ||
}; | ||
} | ||
defineDebug(debug); | ||
var debug = debugEnv; | ||
@@ -1026,0 +1025,0 @@ /** |
@@ -1,969 +0,99 @@ | ||
import { UNKNOWN_REACTIVE_VALUE, DEBUG, defineDebug } from '@starbeam/reactive'; | ||
import { firstNItems, isPresent, getFirst, defineObject, dataGetter, isPresentArray, mapArray, getLast, withoutFirst, nullifyEmptyArray, isObject, getLastIndex } from '@starbeam/core-utils'; | ||
import { verified, verify, hasType } from '@starbeam/verify'; | ||
import k from 'stacktracey'; | ||
import { getID } from '@starbeam/shared'; | ||
import { getTag, getDependencies, lastUpdated } from '@starbeam/tags'; | ||
function parseModule(t, o) { | ||
return normalizeModule(t, o); | ||
} | ||
function normalizeModule(t, o) { | ||
let e = /** | ||
* The whole `Stack` system is only intended to be used for logging, so the | ||
* edge-cases where this normalization wouldn't work (verbatim paths on Windows) | ||
* shouldn't matter. | ||
*/ function(...t) { | ||
return t.filter((t)=>"string" == typeof t).map((t)=>t.replaceAll(/[\\]/g, "/")).join("/"); | ||
}(t); | ||
if (o) { | ||
let { prefix: t, suffix: r } = pivotPath(o, e); | ||
return { | ||
root: t, | ||
path: r.startsWith("/") ? r.slice(1) : r | ||
}; | ||
} | ||
return { | ||
path: e | ||
}; | ||
} | ||
/** | ||
* This function takes two paths and returns the suffix of the target that comes | ||
* after any shared prefix with the source. | ||
* | ||
* For example, if the source is `/src/app/foo/bar` and the target is | ||
* `/src/app/baz/qux`, this function will return `baz/qux`. | ||
*/ function pivotPath(o, e) { | ||
let r = o.split("/"), i = e.split("/"), a = r.findIndex((t, o)=>t !== i[o]); | ||
return { | ||
prefix: firstNItems(r, a).join("/") + "/", | ||
suffix: i.slice(a).join("/") | ||
}; | ||
} | ||
if (import.meta.vitest) { | ||
let { test: t, expect: o } = import.meta.vitest; | ||
t("should return the path if it's not nested in a root", ()=>{ | ||
o(normalizeModule("./foo/bar")).toStrictEqual({ | ||
path: "./foo/bar" | ||
}), o(parseModule("./foo/bar")).toStrictEqual({ | ||
path: "./foo/bar" | ||
}); | ||
}), t("should find the pivot path", ()=>{ | ||
o(normalizeModule("/src/app/index.ts", "/src/app/some/nested/file.ts")).toStrictEqual({ | ||
root: "/src/app/", | ||
path: "index.ts" | ||
}), o(parseModule("/src/app/index.ts", "/src/app/some/nested/file.ts")).toStrictEqual({ | ||
root: "/src/app/", | ||
path: "index.ts" | ||
}); | ||
}), t("pivotPath", ()=>{ | ||
o(pivotPath("/src/app/foo/bar", "/src/app/baz/qux")).toEqual({ | ||
prefix: "/src/app/", | ||
suffix: "baz/qux" | ||
}); | ||
}); | ||
} | ||
function t$3(n, a) { | ||
let c = r$3(n); | ||
if (void 0 === c) return; | ||
let { header: o, entries: i, lines: l, trace: s } = c, u = mapArray(i, (t)=>e$4(()=>s.withSource(t), a)); | ||
return { | ||
header: o, | ||
frames: u, | ||
slice: (e)=>{ | ||
let r = l.slice(e).join("\n"); | ||
return t$3(`${o}\n${r}`, a); | ||
} | ||
}; | ||
} | ||
function e$4(t, e) { | ||
function r() { | ||
return n || (n = t()), n; | ||
} | ||
let n = null; | ||
return defineObject({ | ||
action: dataGetter(()=>r().callee), | ||
module: dataGetter(()=>parseModule(r().file, e)), | ||
loc: dataGetter(()=>{ | ||
let t = r(); | ||
if (void 0 !== t.line) return { | ||
line: t.line, | ||
column: t.column | ||
}; | ||
}) | ||
}); | ||
} | ||
function r$3(t) { | ||
let e = new k(t); | ||
if (!isPresentArray(e.items)) return; | ||
let [r] = e.items, n = r.beforeParse, a = t.split("\n"), c = a.findIndex((t)=>t.trim() === n); | ||
if (c === S) throw Error(`An assumption was incorrect: A line that came from StackTracey cannot be found in the original trace.\n\n== Stack ==\n\n${t}\n\n== Line ==\n\n${n}`); | ||
let i = firstNItems(a, c).join("\n"), l = a.slice(c); | ||
if (isPresentArray(l)) return { | ||
header: i, | ||
entries: e.items, | ||
lines: l, | ||
trace: e | ||
}; | ||
} | ||
function n$1(t) { | ||
return hasType("object")(t) && hasType("string")(t.stack); | ||
} | ||
const ABSTRACTION_FRAME = 1; | ||
function callerStack(e = 1) { | ||
let r = Error; | ||
if ("captureStackTrace" in r) { | ||
let n = {}; | ||
return r.captureStackTrace(n, callerStack), t$3(n.stack)?.slice(e); | ||
} | ||
{ | ||
let r = Error("An error created in the internals of Stack.create").stack; | ||
return verify(r, hasType("string")), t$3(r)?.slice(e + 1); | ||
} | ||
} | ||
let S = -1; | ||
if (import.meta.vitest) { | ||
function d() { | ||
throw Error(u); | ||
} | ||
let { test: a, expect: c, describe: o } = import.meta.vitest, s = new URL(import.meta.url).pathname, m = { | ||
line: 140, | ||
column: 11 | ||
}, u = "an error happened in an action"; | ||
a("parseStack", ()=>{ | ||
try { | ||
d(); | ||
} catch (s) { | ||
let { header: t, entries: e, lines: a, trace: o } = verified(r$3(verified(s, n$1).stack), isPresent); | ||
c(t).toBe(`Error: ${u}`), c(a).toHaveLength(e.length), c(o.items).toEqual(e), c(getFirst(a)).toMatch(/\banAction\b/); | ||
} | ||
}); | ||
{ | ||
function E() { | ||
try { | ||
d(); | ||
} catch (m) { | ||
let r = verified(t$3(verified(m, n$1).stack, s), isPresent); | ||
c(r.header).toBe(`Error: ${u}`); | ||
let a = r.frames.length; | ||
c(r.slice(1)?.frames).toHaveLength(a - 1); | ||
let o = getFirst(r.slice(1)?.frames ?? []); | ||
c(o?.action).toBe(e); | ||
} | ||
} | ||
let e = E.name; | ||
a("callStack", E); | ||
} | ||
{ | ||
function w() { | ||
let e = verified(callerStack(), isPresent); | ||
c(getFirst(e.frames).action).toBe(t); | ||
} | ||
let t = w.name; | ||
a("callerStack", w); | ||
} | ||
o("StackFrame", ()=>{ | ||
a("action", ()=>{ | ||
try { | ||
d(); | ||
} catch (o) { | ||
verify(o, n$1); | ||
let t = new k(o.stack), r = verified(getFirst(t.items), isPresent), a = e$4(()=>t.withSource(r), s); | ||
c(a.action).toBe("anAction"), c(a.module).toEqual({ | ||
path: "stack.ts", | ||
root: new URL(".", import.meta.url).pathname | ||
}), c(a.loc).toEqual(m); | ||
} | ||
}); | ||
}); | ||
} | ||
function e$3(e) { | ||
return "specified" === e.type ? e.value : `{anonymous ${e.kind}:${t$2(e.id)}}`; | ||
} | ||
function l(e) { | ||
return e.specified ? { | ||
type: "specified", | ||
value: e.specified | ||
} : e.nesting ? e.nesting : { | ||
type: "anonymous", | ||
kind: e.type, | ||
id: e.id | ||
}; | ||
} | ||
function t$2(e, l = "", i = !1) { | ||
switch(typeof e){ | ||
case "string": | ||
case "number": | ||
"" === l || l.endsWith("(") ? l += String(e) : l.endsWith(")") ? l += `->${e}` : l += `/${e}`; | ||
break; | ||
default: | ||
for (let a of ("" !== l && (l += "->"), i && (l += "("), e))l = t$2(a, l, !0); | ||
i && (l += ")"); | ||
} | ||
return l; | ||
} | ||
function describeTagged(e) { | ||
let l = getTag(e).description; | ||
return l ? describe(l) : UNKNOWN_REACTIVE_VALUE; | ||
} | ||
function describe(e) { | ||
return describeFullName(getFullName(e)); | ||
} | ||
function getFullName(e) { | ||
let t = l(e); | ||
if ("specified" === t.type || "anonymous" === t.type) return t; | ||
let i = t.parent, a = [ | ||
t | ||
]; | ||
for(;;){ | ||
let e = l(i); | ||
if ("specified" === e.type || "anonymous" === e.type) return [ | ||
e, | ||
...a.reverse() | ||
]; | ||
a.push(e), i = e.parent; | ||
} | ||
} | ||
function describeFullName(l) { | ||
if (!Array.isArray(l)) return e$3(l); | ||
{ | ||
let t = []; | ||
for (let a of l)switch(a.type){ | ||
case "specified": | ||
case "anonymous": | ||
t.push(e$3(a)); | ||
break; | ||
default: | ||
t.push(function(e) { | ||
switch(e.type){ | ||
case "property": | ||
return `.${e.value}`; | ||
case "index": | ||
return `[${e.value}]`; | ||
case "implementation": | ||
return `->{impl: ${e.value.name}}`; | ||
case "detail": | ||
{ | ||
let { name: l, args: t } = e.value; | ||
return isPresentArray(t) ? `->${l}(${t.join(", ")})` : `->${l}`; | ||
} | ||
case "key": | ||
{ | ||
let { name: l } = e.value; | ||
return `.get(${l})`; | ||
} | ||
} | ||
}(a)); | ||
} | ||
return t.join(""); | ||
} | ||
} | ||
const getUserFacing = (e)=>e?.nesting?.type === "implementation" ? getUserFacing(e.nesting.parent) : e; | ||
if (import.meta.vitest) { | ||
let { test: l, expect: i, describe: a } = import.meta.vitest; | ||
l("getIdString", ()=>{ | ||
i(t$2("myid")).toEqual("myid"), // eslint-disable-next-line @typescript-eslint/no-magic-numbers | ||
i(t$2(123)).toEqual("123"), i(t$2([ | ||
"a", | ||
"b", | ||
"c" | ||
])).toEqual("a/b/c"), i(t$2([ | ||
"a", | ||
[ | ||
"b", | ||
"c" | ||
], | ||
"d" | ||
])).toEqual("a->(b/c)->d"), i(t$2([ | ||
"a", | ||
[ | ||
"b", | ||
"c" | ||
], | ||
[ | ||
"d", | ||
"e" | ||
] | ||
])).toEqual("a->(b/c)->(d/e)"), i(t$2([ | ||
[ | ||
"a", | ||
"b" | ||
], | ||
[ | ||
"c", | ||
"d" | ||
] | ||
])).toEqual("(a/b)->(c/d)"), i(t$2([ | ||
"a", | ||
[ | ||
"b", | ||
"c" | ||
], | ||
[ | ||
"d", | ||
"e" | ||
], | ||
"f" | ||
])).toEqual("a->(b/c)->(d/e)->f"), i(t$2([ | ||
"a", | ||
[ | ||
"b", | ||
"c" | ||
], | ||
[ | ||
"d", | ||
"e" | ||
], | ||
[ | ||
"f", | ||
"g" | ||
] | ||
])).toEqual("a->(b/c)->(d/e)->(f/g)"), // multiple levels of nesting | ||
i(t$2([ | ||
"a", | ||
[ | ||
"b", | ||
[ | ||
"c", | ||
"d" | ||
], | ||
"e" | ||
], | ||
"f" | ||
])).toEqual("a->(b->(c/d)->e)->f"); | ||
}), l("getUserFacing", ()=>{ | ||
let e = getID(), l = getID(), t = { | ||
type: "cell", | ||
caller: void 0, | ||
id: e, | ||
specified: "mycell" | ||
}; | ||
i(getUserFacing({ | ||
type: "cell", | ||
caller: void 0, | ||
id: l, | ||
nesting: { | ||
type: "implementation", | ||
parent: t, | ||
value: { | ||
name: "initialized?", | ||
reason: "the cell was initialized" | ||
} | ||
} | ||
})).toEqual(t), i(getUserFacing(t)).toEqual(t); | ||
}), l("describeFlat", ()=>{ | ||
i(e$3({ | ||
type: "specified", | ||
value: "mycell" | ||
})).toEqual("mycell"); | ||
let l = getID(); | ||
i(e$3({ | ||
type: "anonymous", | ||
kind: "cell", | ||
id: l | ||
})).toEqual(`{anonymous cell:${l}}`); | ||
}), l("describeFullName", ()=>{ | ||
i(describeFullName({ | ||
type: "specified", | ||
value: "mycell" | ||
})).toEqual("mycell"); | ||
let e = getID(); | ||
i(describeFullName({ | ||
type: "anonymous", | ||
kind: "cell", | ||
id: e | ||
})).toEqual(`{anonymous cell:${e}}`); | ||
let l = getID(), t = getID(); | ||
i(describeFullName(getFullName({ | ||
type: "cell", | ||
caller: void 0, | ||
id: t, | ||
nesting: { | ||
type: "implementation", | ||
parent: { | ||
type: "cell", | ||
caller: void 0, | ||
id: l, | ||
specified: "mycell" | ||
}, | ||
value: { | ||
name: "initialized?", | ||
reason: "the cell was initialized" | ||
} | ||
} | ||
}))).toEqual("mycell->{impl: initialized?}"), i(describeFullName([ | ||
{ | ||
type: "specified", | ||
value: "mycell" | ||
}, | ||
{ | ||
type: "implementation", | ||
value: { | ||
name: "initialized?", | ||
reason: "" | ||
} | ||
} | ||
])).toEqual("mycell->{impl: initialized?}"); | ||
let a = { | ||
type: "specified", | ||
value: "mycell" | ||
}, n = { | ||
type: "anonymous", | ||
kind: "cell", | ||
id: 1 | ||
}; | ||
i(describeFullName([ | ||
n, | ||
{ | ||
type: "index", | ||
value: 2 | ||
} | ||
])).toEqual("{anonymous cell:1}[2]"), i(describeFullName([ | ||
a, | ||
{ | ||
type: "index", | ||
value: 2 | ||
} | ||
])).toEqual("mycell[2]"), i(describeFullName([ | ||
n, | ||
{ | ||
type: "key", | ||
value: { | ||
name: "foo", | ||
key: {} | ||
} | ||
} | ||
])).toEqual("{anonymous cell:1}.get(foo)"), i(describeFullName([ | ||
a, | ||
{ | ||
type: "key", | ||
value: { | ||
name: "foo", | ||
key: {} | ||
} | ||
} | ||
])).toEqual("mycell.get(foo)"), i(describeFullName([ | ||
n, | ||
{ | ||
type: "property", | ||
value: "foo" | ||
} | ||
])).toEqual("{anonymous cell:1}.foo"), i(describeFullName([ | ||
a, | ||
{ | ||
type: "property", | ||
value: "foo" | ||
} | ||
])).toEqual("mycell.foo"); | ||
}), a("getFullName", ()=>{ | ||
l("anonymous", ()=>{ | ||
let e = getID(); | ||
i(getFullName({ | ||
type: "cell", | ||
caller: void 0, | ||
id: e | ||
})).toEqual({ | ||
type: "anonymous", | ||
kind: "cell", | ||
id: e | ||
}); | ||
}), l("specified", ()=>{ | ||
let e = { | ||
type: "cell", | ||
caller: void 0, | ||
id: getID(), | ||
specified: "mycell" | ||
}; | ||
i(getFullName(e)).toEqual({ | ||
type: "specified", | ||
value: "mycell" | ||
}); | ||
}), l("nested", ()=>{ | ||
let e = getID(), l = getID(), t = { | ||
type: "collection", | ||
caller: void 0, | ||
id: e, | ||
specified: "mymap" | ||
}; | ||
i(getFullName({ | ||
type: "collection:item", | ||
caller: void 0, | ||
id: l, | ||
nesting: { | ||
type: "key", | ||
parent: t, | ||
value: { | ||
name: "foo", | ||
key: "foo" | ||
} | ||
} | ||
})).toEqual([ | ||
{ | ||
type: "specified", | ||
value: "mymap" | ||
}, | ||
{ | ||
type: "key", | ||
parent: t, | ||
value: { | ||
name: "foo", | ||
key: "foo" | ||
} | ||
} | ||
]); | ||
}); | ||
}); | ||
} | ||
function e$2(e) { | ||
if (null === e) return "null"; | ||
switch(typeof e){ | ||
case "string": | ||
return e; | ||
case "bigint": | ||
case "boolean": | ||
case "number": | ||
case "symbol": | ||
case "undefined": | ||
return String(e); | ||
case "function": | ||
return `${e.name || "anonymous"}`; | ||
case "object": | ||
return Array.isArray(e) ? "{array}" : "{object}"; | ||
default: | ||
return `{${typeof e}}`; | ||
} | ||
} | ||
function t$1(e) { | ||
switch(e){ | ||
case "reactive:read": | ||
case "reactive:call": | ||
return "reactive"; | ||
case "reactive:write": | ||
return "reactive write"; | ||
} | ||
} | ||
function r$2(e) { | ||
return void 0 === e ? "" : "string" == typeof e ? `.${e}` : `[${String(e)}]`; | ||
} | ||
function n(e) { | ||
return void 0 === e ? "{unknown}" : "string" == typeof e ? e : describe(e); | ||
} | ||
class EntryPoints { | ||
static default() { | ||
return new EntryPoints(void 0); | ||
} | ||
static current() { | ||
return m.#e; | ||
} | ||
static mark(e) { | ||
let t, r; | ||
if (e instanceof f$1) return m.#t(e, !1), e; | ||
let n = !1; | ||
return "string" == typeof e ? (t = callerStack(ABSTRACTION_FRAME), r = [ | ||
"label", | ||
e | ||
]) : Array.isArray(e) ? (t = callerStack(ABSTRACTION_FRAME), r = e) : (t = callerStack(ABSTRACTION_FRAME), r = [ | ||
"label", | ||
getFirst(t?.frames)?.action ?? "unknown" | ||
]), n = !1, m.mark(t, r, n); | ||
} | ||
#e; | ||
constructor(e){ | ||
this.#e = e; | ||
} | ||
mark(e, t, r) { | ||
return this.#t(new f$1(e, t ? new p(t) : void 0), r); | ||
} | ||
#t(e, t) { | ||
return !this.#e || t ? this.#e = e : this.#e.pushImplementation(e), e; | ||
} | ||
} | ||
let m = EntryPoints.default(); | ||
const markEntryPoint = EntryPoints.mark; | ||
const getEntryPoint = EntryPoints.current; | ||
class p { | ||
#r; | ||
constructor(e){ | ||
this.#r = e; | ||
} | ||
get label() { | ||
let i = this.#r; | ||
// eslint-disable-next-line @typescript-eslint/no-magic-numbers | ||
switch(i[0]){ | ||
case "object:get": | ||
case "object:set": | ||
case "object:has": | ||
case "object:call": | ||
case "object:define": | ||
case "object:delete": | ||
case "object:meta:get": | ||
return function(e) { | ||
let [t, i, c] = e, a = n(i); | ||
return `${"object:meta:get" === t ? "get meta" : withoutFirst(t.split(":")).join(" ")} ${a}.${r$2(c)}`; | ||
}(i); | ||
case "function:call": | ||
{ | ||
let [, e] = i; | ||
return `call ${n(e)}`; | ||
} | ||
case "object:meta:keys": | ||
{ | ||
let [, e] = i; | ||
return `get meta:keys ${n(e)}`; | ||
} | ||
case "collection:has": | ||
case "collection:get": | ||
case "collection:insert": | ||
case "collection:delete": | ||
return function(t) { | ||
let [r, i, c] = t, a = r.slice(11); | ||
return `${n(i)}->${a}(${e$2(c)})`; | ||
}(i); | ||
case "reactive:read": | ||
case "reactive:write": | ||
case "reactive:call": | ||
return function(e) { | ||
let [i, c, a] = e; | ||
switch(i){ | ||
case "reactive:read": | ||
case "reactive:write": | ||
return `${t$1(i)} ${n(c)}${r$2(a)}`; | ||
case "reactive:call": | ||
return `${t$1(i)} ${n(c)}${r$2(a)}()`; | ||
} | ||
}(i); | ||
case "label": | ||
return getLast(i); | ||
default: | ||
!function(t) { | ||
throw Error(`Unexpected argument: ${e$2(t)}`); | ||
}(i); | ||
} | ||
} | ||
} | ||
let f$1 = class f { | ||
static create(e, t) { | ||
return new f(e, t ? new p(t) : void 0); | ||
} | ||
#n; | ||
#i; | ||
#c = []; | ||
constructor(e, t){ | ||
this.#n = e, this.#i = t; | ||
} | ||
get label() { | ||
return this.#i?.label ?? "api"; | ||
} | ||
get description() { | ||
return this.#i; | ||
} | ||
get caller() { | ||
return this.#n; | ||
} | ||
get implementation() { | ||
return nullifyEmptyArray(this.#c); | ||
} | ||
pushImplementation(e) { | ||
this.#c.push(e); | ||
} | ||
import { getLastIndex, isPresent } from "@starbeam/core-utils"; | ||
import { DEBUG, UNKNOWN_REACTIVE_VALUE } from "@starbeam/reactive"; | ||
import { getDependencies, getTag, lastUpdated } from "@starbeam/tags"; | ||
var debug = { | ||
e: () => {}, | ||
r: () => {}, | ||
i: (e) => e, | ||
d: () => {}, | ||
t: () => "", | ||
o: () => "", | ||
c: () => {}, | ||
a: () => {}, | ||
}; | ||
if (import.meta.vitest) { | ||
let { test: e, expect: t } = import.meta.vitest; | ||
e("inferred entry point", ()=>{ | ||
let e = (markEntryPoint(), "hello"); | ||
t(e).toBe("hello"), t(getEntryPoint()?.description?.label).toBe("api"); | ||
}); | ||
class Logger { | ||
static console() { | ||
return new Logger(console); | ||
} | ||
static of(o) { | ||
return new Logger(o); | ||
} | ||
#o; | ||
constructor(o) { | ||
this.#o = o; | ||
} | ||
group(...o) { | ||
this.#o.group(...o); | ||
} | ||
groupEnd() { | ||
this.#o.groupEnd(); | ||
} | ||
info(...o) { | ||
this.#o.info(...o); | ||
} | ||
} | ||
class Description { | ||
#e; | ||
constructor(e){ | ||
this.#e = e; | ||
} | ||
get api() { | ||
return this.#e.api; | ||
} | ||
get nesting() { | ||
return this.#e.nesting; | ||
} | ||
get type() { | ||
return this.#e.type; | ||
} | ||
get caller() { | ||
return this.#e.caller; | ||
} | ||
get frame() { | ||
return getFirst(this.caller?.frames ?? []); | ||
} | ||
get id() { | ||
return this.#e.id; | ||
} | ||
get isAnonymous() { | ||
return void 0 === this.#e.specified; | ||
} | ||
index(e, t) { | ||
return new Description({ | ||
type: "collection:item", | ||
id: this.#t(e), | ||
nesting: { | ||
type: "index", | ||
parent: this, | ||
value: e | ||
}, | ||
caller: t ?? this.#e.caller | ||
}); | ||
} | ||
property(e, t) { | ||
return new Description({ | ||
type: "collection:item", | ||
id: this.#t(e), | ||
nesting: { | ||
type: "property", | ||
parent: this, | ||
value: e | ||
}, | ||
caller: t ?? this.#e.caller | ||
}); | ||
} | ||
key(e, i) { | ||
let r = isObject(e) ? { | ||
name: e.name, | ||
key: e.key | ||
} : { | ||
name: String(e), | ||
key: e | ||
}; | ||
return new Description({ | ||
type: "collection:item", | ||
id: this.#t(r.name), | ||
nesting: { | ||
type: "key", | ||
parent: this, | ||
value: r | ||
}, | ||
caller: i ?? this.#e.caller | ||
}); | ||
} | ||
detail(e, t, i = [], r) { | ||
let n = Array.isArray(i) ? { | ||
args: i, | ||
caller: r | ||
} : { | ||
args: [], | ||
caller: i | ||
}; | ||
return new Description({ | ||
type: e, | ||
id: this.#t(t), | ||
nesting: { | ||
type: "detail", | ||
parent: this, | ||
value: { | ||
name: t, | ||
args: n.args | ||
} | ||
}, | ||
caller: n.caller ?? this.#e.caller | ||
}); | ||
} | ||
implementation(e, t, r) { | ||
return new Description({ | ||
type: e, | ||
id: this.#t(t), | ||
nesting: { | ||
type: "implementation", | ||
parent: this, | ||
value: { | ||
name: t, | ||
reason: r | ||
} | ||
}, | ||
caller: DEBUG?.getEntryPoint()?.caller ?? this.#e.caller | ||
}); | ||
} | ||
#t(e) { | ||
return Array.isArray(this.id) ? [ | ||
...this.id, | ||
e | ||
] : [ | ||
this.id, | ||
e | ||
]; | ||
} | ||
} | ||
const Desc = (n, s, a)=>{ | ||
if (isObject(s)) return s; | ||
let l = DEBUG?.callerStack(1); | ||
a = a ?? getFirst(l?.frames)?.action; | ||
let c = getID(), p = new Description({ | ||
type: n, | ||
id: c, | ||
api: "string" == typeof a ? { | ||
type: "simple", | ||
name: a, | ||
caller: l | ||
} : a, | ||
specified: s, | ||
caller: l | ||
}); | ||
return p; | ||
}; | ||
var f = { | ||
Desc: Desc, | ||
callerStack: callerStack, | ||
getUserFacing: getUserFacing, | ||
untrackedReadBarrier: ()=>{ | ||
/* FIXME: do nothing for now */ }, | ||
describe: describe, | ||
describeTagged: describeTagged, | ||
markEntryPoint: markEntryPoint, | ||
getEntryPoint: getEntryPoint | ||
}; | ||
if (void 0 === globalThis.Buffer && "function" == typeof require) try { | ||
// this is for CJS only, so require is the only option here | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
let e = require("node:buffer"); | ||
globalThis.Buffer = e.Buffer; | ||
} catch { | ||
// ignore | ||
} | ||
else { | ||
let e = await import('node:buffer'); | ||
globalThis.Buffer = e.Buffer; | ||
} | ||
defineDebug(f); | ||
/** | ||
* This API might gain additional features. For now, its primary purpose is to | ||
* provide a sanctioned way to log to the console that is overtly different | ||
* from explicit calls to `console.log` (which make it more difficult to | ||
* identify errant console.logs). | ||
*/ class Logger { | ||
static console() { | ||
return new Logger(console); | ||
} | ||
static of(o) { | ||
return new Logger(o); | ||
} | ||
#o; | ||
constructor(o){ | ||
this.#o = o; | ||
} | ||
group(...o) { | ||
this.#o.group(...o); | ||
} | ||
groupEnd() { | ||
this.#o.groupEnd(); | ||
} | ||
info(...o) { | ||
this.#o.info(...o); | ||
} | ||
} | ||
const LOGGER = Logger.console(); | ||
function t(t) { | ||
return `${o} `.repeat(t); | ||
return `${o} `.repeat(t); | ||
} | ||
function r$1({ depth: r, isLast: n }) { | ||
return n ? `${t(r)}${u}` : `${t(r)}${e$1}`; | ||
} /** | ||
* Source material: | ||
* | ||
* https://github.com/zkat/miette/blob/1a36fa7ec80de77e910e04cdb902270970611b39/src/handlers/theme.rs | ||
* Self { | ||
hbar: '─', | ||
vbar: '│', | ||
xbar: '┼', | ||
vbar_break: '·', | ||
uarrow: '▲', | ||
rarrow: '▶', | ||
ltop: '╭', | ||
mtop: '┬', | ||
rtop: '╮', | ||
lbot: '╰', | ||
mbot: '┴', | ||
rbot: '╯', | ||
lbox: '[', | ||
rbox: ']', | ||
lcross: '├', | ||
rcross: '┤', | ||
underbar: '┬', | ||
underline: '─', | ||
error: "💥".into(), | ||
warning: "⚠️".into(), | ||
advice: "💡".into(), | ||
} | ||
*/ | ||
let o = "│", e$1 = "├", u = "╰"; | ||
function r$1({ t: r, r: n }) { | ||
return n ? `${t(r)}${u}` : `${t(r)}${e$1}`; | ||
} | ||
let o = "│", | ||
e$1 = "├", | ||
u = "╰"; | ||
class Root { | ||
#t; | ||
constructor(t){ | ||
this.#t = t; | ||
} | ||
format() { | ||
return function t(o, { depth: e }) { | ||
let u = getLastIndex(o); | ||
return o.map((n, o)=>(function(n, { depth: o, isLast: e }) { | ||
return "string" == typeof n ? function(t, { depth: n, isLast: o }) { | ||
return `${r$1({ | ||
depth: n, | ||
isLast: o | ||
})} ${t}`; | ||
}(n, { | ||
depth: o, | ||
isLast: e | ||
}) : function([n, ...o], { depth: e }) { | ||
let u = `${r$1({ | ||
depth: e, | ||
isLast: !1 | ||
})} ${n}`; | ||
return `${u}\n${t(o, { | ||
depth: e + i | ||
})}`; | ||
}(n, { | ||
depth: o, | ||
isLast: e | ||
}); | ||
})(n, { | ||
depth: e, | ||
isLast: o === u | ||
})).join("\n"); | ||
}(this.#t, { | ||
depth: 0 | ||
}); | ||
} | ||
#t; | ||
constructor(t) { | ||
this.#t = t; | ||
} | ||
format() { | ||
return (function t(o, { t: e }) { | ||
let u = getLastIndex(o); | ||
return o | ||
.map((n, o) => | ||
(function (n, { t: o, r: e }) { | ||
return "string" == typeof n | ||
? (function (t, { t: n, r: o }) { | ||
return `${r$1({ t: n, r: o })} ${t}`; | ||
})(n, { t: o, r: e }) | ||
: (function ([n, ...o], { t: e }) { | ||
return `${`${r$1({ t: e, r: !1 })} ${n}`}\n${t(o, { | ||
t: e + i, | ||
})}`; | ||
})(n, { t: o, r: e }); | ||
})(n, { t: e, r: o === u }), | ||
) | ||
.join("\n"); | ||
})(this.#t, { t: 0 }); | ||
} | ||
} | ||
function Tree(...t) { | ||
return new Root(t); | ||
return new Root(t); | ||
} | ||
let i = 1; | ||
function e(e, r) { | ||
return e && DEBUG ? DEBUG.describe(e, r) : UNKNOWN_REACTIVE_VALUE; | ||
return e && DEBUG ? DEBUG.e(e, r) : UNKNOWN_REACTIVE_VALUE; | ||
} | ||
function r(e, r) { | ||
return r ? e : DEBUG?.getUserFacing(e); | ||
return r ? e : DEBUG?.r(e); | ||
} | ||
const debugReactive = (o, { implementation: i = !1 } = {})=>{ | ||
let n = getDependencies(o), m = new Set(n.map((e)=>r(e.description, i))), p = [ | ||
...m | ||
].map((t)=>{ | ||
let o = r(t, i); | ||
return e(o); | ||
}).filter(isPresent); | ||
const debugReactive = (o, { implementation: i = !1 } = {}) => { | ||
let n = getDependencies(o), | ||
m = new Set(n.map((e) => r(e.description, i))), | ||
p = [...m].map((t) => e(r(t, i))).filter(isPresent); | ||
return Tree(...p).format(); | ||
}; | ||
const logReactive = (r, t = {})=>{ | ||
}, | ||
logReactive = (r, t = {}) => { | ||
let o = debugReactive(r, t); | ||
t.label && LOGGER.group(t.label), LOGGER.group(e(getTag(r).description, { | ||
id: t.id | ||
}), `(updated at ${lastUpdated(r).at})`), LOGGER.info(o), LOGGER.groupEnd(), t.label && LOGGER.groupEnd(); | ||
}; | ||
export { f as DEBUG, Tree, debugReactive, logReactive }; | ||
t.label && LOGGER.group(t.label), | ||
LOGGER.group( | ||
e(getTag(r).description, { id: t.id }), | ||
`(updated at ${lastUpdated(r).at})`, | ||
), | ||
LOGGER.info(o), | ||
LOGGER.groupEnd(), | ||
t.label && LOGGER.groupEnd(); | ||
}; | ||
export { debug as DEBUG, Tree, debugReactive, logReactive }; | ||
//# sourceMappingURL=index.production.js.map |
{ | ||
"name": "@starbeam/debug", | ||
"type": "module", | ||
"version": "0.8.10-unstable.0b31af0", | ||
"version": "0.8.10-unstable.229fe05", | ||
"main": "dist/index.cjs", | ||
@@ -25,8 +25,8 @@ "types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@starbeam/core-utils": "0.8.10-unstable.0b31af0", | ||
"@starbeam/interfaces": "0.8.10-unstable.0b31af0", | ||
"@starbeam/reactive": "0.8.10-unstable.0b31af0", | ||
"@starbeam/shared": "1.3.8-unstable.0b31af0", | ||
"@starbeam/tags": "0.0.1-unstable.0b31af0", | ||
"@starbeam/verify": "0.8.10-unstable.0b31af0", | ||
"@starbeam/core-utils": "0.8.10-unstable.229fe05", | ||
"@starbeam/interfaces": "0.8.10-unstable.229fe05", | ||
"@starbeam/reactive": "0.8.10-unstable.229fe05", | ||
"@starbeam/shared": "1.3.8-unstable.229fe05", | ||
"@starbeam/tags": "0.0.1-unstable.229fe05", | ||
"@starbeam/verify": "0.8.10-unstable.229fe05", | ||
"buffer": "^6.0.3", | ||
@@ -37,6 +37,6 @@ "inspect-utils": "^1.0.1", | ||
"devDependencies": { | ||
"@starbeam-dev/compile": "^1.0.2", | ||
"@starbeam-dev/eslint-plugin": "^1.0.4", | ||
"@starbeam-dev/eslint-plugin": "^1.0.6", | ||
"@types/node": "18.16.1", | ||
"rollup": "^4.0.2" | ||
"rollup": "^4.0.2", | ||
"@starbeam-dev/compile": "1.2.0" | ||
}, | ||
@@ -43,0 +43,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
217465
2037
+ Added@domtree/any@0.9.4-unstable.229fe05(transitive)
+ Added@domtree/browser@0.9.4-unstable.229fe05(transitive)
+ Added@domtree/interface@0.9.4-unstable.229fe05(transitive)
+ Added@domtree/minimal@0.9.4-unstable.229fe05(transitive)
+ Added@starbeam/core-utils@0.8.10-unstable.229fe05(transitive)
+ Added@starbeam/interfaces@0.8.10-unstable.229fe05(transitive)
+ Added@starbeam/reactive@0.8.10-unstable.229fe05(transitive)
+ Added@starbeam/shared@1.3.8-unstable.229fe05(transitive)
+ Added@starbeam/tags@0.0.1-unstable.229fe05(transitive)
+ Added@starbeam/verify@0.8.10-unstable.229fe05(transitive)
- Removed@domtree/any@0.9.3(transitive)
- Removed@domtree/browser@0.9.3(transitive)
- Removed@domtree/interface@0.9.3(transitive)
- Removed@domtree/minimal@0.9.3(transitive)
- Removed@starbeam/core-utils@0.8.10-unstable.0b31af0(transitive)
- Removed@starbeam/interfaces@0.8.10-unstable.0b31af0(transitive)
- Removed@starbeam/reactive@0.8.10-unstable.0b31af0(transitive)
- Removed@starbeam/shared@1.3.8-unstable.0b31af0(transitive)
- Removed@starbeam/tags@0.0.1-unstable.0b31af0(transitive)
- Removed@starbeam/verify@0.8.10-unstable.0b31af0(transitive)