@starbeam/shared
Advanced tools
Comparing version 1.3.8-unstable.398c1bd to 1.3.8-unstable.3ead76a
{ | ||
"root": false, | ||
"root": true, | ||
"ignorePatterns": ["node_modules", "dist", "html", "tests"], | ||
"plugins": ["@starbeam"], | ||
"overrides": [ | ||
@@ -10,4 +12,8 @@ { | ||
} | ||
}, | ||
{ | ||
"extends": ["plugin:@starbeam/json:recommended"], | ||
"files": ["*.json"] | ||
} | ||
] | ||
} |
export { COORDINATION, TAG, UNINITIALIZED } from "./src/constants.js"; | ||
export { getID } from "./src/id.js"; | ||
export { | ||
finalize, | ||
isFinalized, | ||
linkToFinalizationScope, | ||
mountFinalizationScope, | ||
onFinalize, | ||
pushFinalizationScope, | ||
} from "./src/lifetimes.js"; | ||
export { bump, now } from "./src/now.js"; | ||
export { consume, start } from "./src/stack.js"; | ||
export { testing } from "./src/testing.js"; |
{ | ||
"name": "@starbeam/shared", | ||
"version": "1.3.8-unstable.398c1bd", | ||
"version": "1.3.8-unstable.3ead76a", | ||
"description": "A package that facilitates having multiple copies of Starbeam in a single process that interoperate with each other", | ||
@@ -24,3 +24,3 @@ "type": "module", | ||
"scripts": { | ||
"test:lint": "eslint \"index.ts\" \"src/**/*.ts\"", | ||
"test:lint": "eslint . --max-warnings 0", | ||
"test:specs": "vitest --run", | ||
@@ -30,5 +30,6 @@ "test:types": "tsc -b" | ||
"devDependencies": { | ||
"@starbeam-dev/build-support": "workspace:*", | ||
"rollup": "^3.20.6" | ||
"@starbeam/eslint-plugin": "workspace:^", | ||
"@starbeam-dev/build-support": "workspace:^", | ||
"rollup": "^3.29.2" | ||
} | ||
} |
import { COORDINATION } from "./constants.js"; | ||
import type { Unregister } from "./types.js"; | ||
@@ -7,13 +8,66 @@ export interface Clock { | ||
export interface Now { | ||
timestamp: number; | ||
} | ||
export interface Id { | ||
readonly get: () => string | number; | ||
} | ||
export interface Stack { | ||
start: () => () => Set<object>; | ||
consume: (tag: object) => void; | ||
} | ||
export type FinalizationScope = object; | ||
export interface Lifetime { | ||
/** | ||
* Push a finalization scope to the stack. When the block completes, the | ||
* finalization scope is popped from the stack and added to the original | ||
* parent scope. | ||
*/ | ||
pushFinalizationScope: ( | ||
child?: object | undefined, | ||
) => () => FinalizationScope; | ||
/** | ||
* Like {@linkcode pushFinalizationScope}, but does not add the scope to the | ||
* parent scope when complete. This is useful for scopes that represent | ||
* long-lived stacks, such as async functions or reactive resources (which can | ||
* have nested scopes that evolve over time). | ||
*/ | ||
mountFinalizationScope: (child?: object) => () => FinalizationScope; | ||
linkToFinalizationScope: ( | ||
child: object, | ||
options?: { parent?: FinalizationScope }, | ||
) => Unregister; | ||
/** | ||
* Specify a finalizer that will be called when the object is finalized. | ||
* | ||
* `onFinalize` returns a function that, when called, removes the handler | ||
* (i.e. when the object is finalized, the finalizer will no longer be | ||
* called). | ||
*/ | ||
onFinalize: ((handler: () => void) => Unregister) & | ||
((object: object, handler: () => void) => Unregister); | ||
/** | ||
* `finalize` returns true if the object was finalized, and false if the | ||
* object was already finalized. | ||
*/ | ||
finalize: (lifetime: object) => boolean; | ||
isFinalized: (lifetime: object) => boolean; | ||
} | ||
export interface Testing { | ||
registry?: FinalizationRegistryConstructor; | ||
} | ||
export interface StarbeamCoordination { | ||
now: { | ||
timestamp: number; | ||
}; | ||
id: { | ||
get: () => string | number; | ||
}; | ||
stack: { | ||
start: () => () => unknown[]; | ||
consume: (tag: unknown) => void; | ||
}; | ||
now: Now; | ||
id: Id; | ||
stack: Stack; | ||
lifetime: Lifetime; | ||
testing?: Testing; | ||
} | ||
@@ -20,0 +74,0 @@ |
@@ -8,3 +8,3 @@ import { getCoordination } from "./env.js"; | ||
if (!stack) { | ||
let current: null | unknown[] = null; | ||
let current = new Set<object>(); | ||
@@ -14,3 +14,3 @@ stack = coordination.stack = { | ||
const prev = current; | ||
current = []; | ||
current = new Set(); | ||
@@ -20,6 +20,6 @@ return () => { | ||
current = prev; | ||
return result ?? []; | ||
return result; | ||
}; | ||
}, | ||
consume: (tag: unknown) => void current?.push(tag), | ||
consume: (tag: object) => void current.add(tag), | ||
}; | ||
@@ -30,8 +30,8 @@ } | ||
export function start(): () => unknown[] { | ||
export function start(): () => Set<object> { | ||
return STACK.start(); | ||
} | ||
export function consume(tag: unknown): void { | ||
export function consume(tag: object): void { | ||
STACK.consume(tag); | ||
} |
{ | ||
"root": false, | ||
"root": true, | ||
"ignorePatterns": ["node_modules", "dist", "html", "tests"], | ||
"plugins": ["@starbeam"], | ||
"overrides": [ | ||
@@ -10,4 +12,8 @@ { | ||
} | ||
}, | ||
{ | ||
"extends": ["plugin:@starbeam/json:recommended"], | ||
"files": ["*.json"] | ||
} | ||
] | ||
} |
@@ -6,10 +6,21 @@ { | ||
"type": "module", | ||
"starbeam:type": "tests", | ||
"starbeam": { | ||
"source": "ts", | ||
"type": "tests" | ||
}, | ||
"scripts": { | ||
"test:lint": "eslint ", | ||
"test:lint": "eslint . --max-warnings 0", | ||
"test:types": "tsc -b" | ||
}, | ||
"dependencies": { | ||
"@starbeam/shared": "workspace:^" | ||
"@starbeam/shared": "workspace:^", | ||
"@starbeam-workspace/test-utils": "workspace:^", | ||
"@types/stack-utils": "^2.0.1", | ||
"@vitest/utils": "^0.34.4", | ||
"stack-utils": "^2.0.6", | ||
"strip-ansi": "^7.1.0" | ||
}, | ||
"devDependencies": { | ||
"@starbeam/eslint-plugin": "workspace:^" | ||
} | ||
} |
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
32704
25
885
3
1