@tempo-kit/plugin-sync 0.0.0-stage → 2.0.0

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,49 @@
1
+ # Changelog
2
+
3
+ All notable changes to the `@tempo-kit/plugin-sync` project will be documented in this file.
4
+
5
+ ## [2.0.0] - 2026-11-27
6
+
7
+ ### Breaking Changes
8
+ - Migrated package namespace from `@magmacomputing/tempo-plugin-sync` to `@tempo-kit/plugin-sync`.
9
+ - Updated `peerDependencies` to `tempo-kit@^5.0.0`.
10
+
11
+ ## [2.0.0] - 2026-11-27
12
+
13
+ ### Breaking Changes
14
+ - Migrated package namespace from `@magmacomputing/tempo-plugin-sync` to `@tempo-kit/plugin-sync`.
15
+ - Updated `peerDependencies` to `tempo-kit@^5.0.0`.
16
+
17
+ ## [1.1.2] - 2026-10-02
18
+
19
+ ### Enhanced
20
+ - **Runtime Introspection & Branding**:
21
+ - Added `[Symbol.toStringTag]` getters to `AtomicClock` (`'Tempo.AtomicClock'`) and `AtomicReader` (`'Tempo.AtomicReader'`), providing TC39-aligned branding for `Object.prototype.toString` and debugging tools.
22
+
23
+ ## [1.1.1] - 2026-09-29
24
+
25
+ ### Performance & Memory
26
+ - **Dual-Layer Lifecycle Management**:
27
+ - Implemented `Finalizer.register` and `[Symbol.dispose]` on `AtomicClock` to ensure timer interval loops are deterministically stopped on explicit disposal or automatically cleaned up on GC collection when unreferenced.
28
+
29
+ ## [1.1.0] - 2026-09-18
30
+
31
+ ### Added
32
+ - **Subpath Side-Effect Installation (`/install`)**:
33
+ - Added dedicated `@tempo-kit/plugin-sync/install` entrypoint for zero-boilerplate side-effect registration on the global `Tempo` instance via `autoInstall`.
34
+ - Configured `package.json` with `"sideEffects": ["./dist/install.js"]` to ensure the root package entrypoint remains 100% pure and tree-shakeable.
35
+
36
+ ## [1.0.3] - 2026-07-20
37
+
38
+ ### Fixed
39
+ - **API Alignment**: Aligned the `startClock` implementation with its documented usage by ensuring it correctly returns the `AtomicClock` instance, allowing consumers to directly read the clock buffer.
40
+
41
+ ## [1.0.0] - 2026-06-29
42
+
43
+ ### Added
44
+
45
+ - Initial release of the `tempo-plugin-sync` (AtomicClock) premium plugin.
46
+ - Implements `AtomicClock` (Master) and `AtomicReader` (Worker) components for `O(1)` non-blocking time synchronization.
47
+ - Utilizes `SharedArrayBuffer` and native `Atomics` for nanosecond-accurate multi-threading.
48
+ - Exposes `now()` (millisecond fallback) and `nowNano()` (BigInt nanoseconds) on the `AtomicReader`.
49
+ - Directly supports hydrating `Tempo` engine instances with zero precision-loss.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Magma Computing
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ ![Tempo Plugin](https://raw.githubusercontent.com/magmacomputing/magma/main/packages/tempo/public/plugin-logo.svg)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # @tempo-kit/plugin-sync
4
+
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/@tempo-kit/plugin-sync"><img src="https://img.shields.io/npm/v/@tempo-kit/plugin-sync?style=flat-square" alt="npm version" style="display: inline-block; margin: 0 4px;"></a> <a href="https://www.npmjs.com/package/tempo-kit"><img src="https://img.shields.io/npm/dependency-version/@tempo-kit/plugin-sync/peer/tempo-kit?style=flat-square" alt="npm peer dependency version" style="display: inline-block; margin: 0 4px;"></a> <a href="https://www.npmjs.com/package/@tempo-kit/plugin-sync"><img src="https://img.shields.io/npm/l/@tempo-kit/plugin-sync?style=flat-square" alt="License" style="display: inline-block; margin: 0 4px;"></a> <a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-Ready-blue?logo=typescript&style=flat-square" alt="TypeScript Ready" style="display: inline-block; margin: 0 4px;"></a> <a href="https://magmacomputing.github.io/magma/doc/9-plugins/sync.index.html"><img src="https://img.shields.io/badge/Docs-VitePress-brightgreen?logo=vitepress&style=flat-square" alt="Documentation" style="display: inline-block; margin: 0 4px;"></a>
7
+ </p>
8
+
9
+ This is a Community plugin for the [Tempo](https://github.com/magmacomputing/magma) library that provides lock-free, nanosecond-accurate cross-thread time synchronization using `SharedArrayBuffer` and `Atomics`.
10
+
11
+ 👉 **[View the full documentation on our GitHub Pages](https://magmacomputing.github.io/magma/doc/9-plugins/sync.index.html)**
12
+
13
+ > **Perfect for:** High-frequency trading platforms, real-time multiplayer game servers, distributed microservice tracing, and extreme-precision scientific telemetry.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @tempo-kit/plugin-sync
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```typescript
24
+ import { Tempo } from 'tempo-kit';
25
+ import { SyncPlugin } from '@tempo-kit/plugin-sync';
26
+
27
+ Tempo.init({
28
+ extends: [SyncPlugin]
29
+ });
30
+
31
+ // Master Thread: Start the clock
32
+ const clock = Tempo.sync.startClock({ updateIntervalMs: 1 });
33
+ const buffer = clock.buffer; // Pass this SharedArrayBuffer to your workers
34
+ ```
35
+
36
+ > [!NOTE]
37
+ > **Live Interactive Sandbox**: `@tempo-kit/plugin-sync` uses `SharedArrayBuffer` for real-time thread synchronization, which requires Cross-Origin Isolation headers (`Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`). When hosting on servers supporting COOP/COEP, explore the interactive playground at [Tempo REPL ↗](https://magmacomputing.github.io/magma/repl/index.html?plugin=sync).
38
+
39
+ ### Reading from Worker Threads
40
+
41
+ To read the synchronized time from inside a worker thread, pass the `SharedArrayBuffer` via `workerData` and instantiate an `AtomicReader`.
42
+
43
+ ```typescript
44
+ // worker.ts
45
+ import { workerData } from 'node:worker_threads';
46
+ import { AtomicReader } from '@tempo-kit/plugin-sync';
47
+
48
+ // Hydrate the reader using the master buffer
49
+ const reader = new AtomicReader(workerData.buffer);
50
+
51
+ // 1. Get raw milliseconds (O(1) Atomic Read)
52
+ const ms = reader.now();
53
+
54
+ // 2. Get high-precision BigInt nanoseconds
55
+ const ns = reader.nowNano();
56
+
57
+ // 3. Hydrate a brand new Tempo instance with exact precision
58
+ const t = reader.getTempo();
59
+ ```
60
+
61
+ ## Licensing
62
+
63
+ This is a **Community** plugin. It is completely free and open-source for personal and commercial use under the MIT license.
@@ -0,0 +1,32 @@
1
+ export interface ClockOptions {
2
+ /**
3
+ * Interval in milliseconds to update the clock.
4
+ * Default: 10
5
+ */
6
+ interval?: number;
7
+ }
8
+ /**
9
+ * The master clock that continuously writes the current system time to a SharedArrayBuffer.
10
+ * This should only be instantiated once on the main thread (or a master worker).
11
+ */
12
+ export declare class AtomicClock {
13
+ #private;
14
+ constructor(options?: ClockOptions);
15
+ get [Symbol.toStringTag](): string;
16
+ /**
17
+ * Returns the underlying SharedArrayBuffer to be passed to workers.
18
+ */
19
+ getBuffer(): SharedArrayBuffer;
20
+ /**
21
+ * Starts the synchronization loop.
22
+ */
23
+ start(): void;
24
+ /**
25
+ * Stops the synchronization loop.
26
+ */
27
+ stop(): void;
28
+ /**
29
+ * Explicit deterministic disposal (Dual-Layer Lifecycle Model).
30
+ */
31
+ [Symbol.dispose](): void;
32
+ }
@@ -0,0 +1,23 @@
1
+ import { Tempo } from 'tempo-kit';
2
+ /**
3
+ * The client reader that reads the synchronized time from a SharedArrayBuffer.
4
+ * This should be instantiated in Web Workers or worker_threads.
5
+ */
6
+ export declare class AtomicReader {
7
+ #private;
8
+ constructor(buffer: SharedArrayBuffer);
9
+ get [Symbol.toStringTag](): string;
10
+ /**
11
+ * Returns the exact synchronized epoch timestamp in nanoseconds.
12
+ * Executes in O(1) time with lock-free atomic read.
13
+ */
14
+ nowNano(): bigint;
15
+ /**
16
+ * Returns the exact synchronized epoch timestamp in milliseconds.
17
+ */
18
+ now(): number;
19
+ /**
20
+ * Convenience wrapper that returns a new Tempo instance representing the exact synchronized time.
21
+ */
22
+ getTempo(): Tempo;
23
+ }
@@ -0,0 +1,25 @@
1
+ import { AtomicClock, ClockOptions } from './AtomicClock.js';
2
+ import { AtomicReader } from './AtomicReader.js';
3
+ import { type TempoPlugin } from 'tempo-kit/plugin/sdk';
4
+ export { AtomicClock, AtomicReader, ClockOptions };
5
+ declare module 'tempo-kit' {
6
+ namespace Tempo {
7
+ const sync: {
8
+ /** Starts the master atomic clock on the current thread. */
9
+ startClock(options?: ClockOptions): AtomicClock;
10
+ /** Stops the master atomic clock. */
11
+ stopClock(): void;
12
+ /** Gets the SharedArrayBuffer from the master clock. */
13
+ getBuffer(): SharedArrayBuffer;
14
+ /** Synchronously reads the exact time from the provided SharedArrayBuffer. */
15
+ now(buffer: SharedArrayBuffer): number;
16
+ /** Synchronously reads the time and returns a new Tempo instance. */
17
+ getTempo(buffer: SharedArrayBuffer): Tempo;
18
+ };
19
+ }
20
+ }
21
+ /**
22
+ * The Sync Plugin.
23
+ * Exposes `Tempo.sync` for synchronizing time across multiple threads using SharedArrayBuffers.
24
+ */
25
+ export declare const SyncPlugin: TempoPlugin;
@@ -0,0 +1 @@
1
+ "use strict";var Magma;((Magma||={}).plugins||={}).sync=(()=>{var ae=Object.create;var A=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var Ne=Object.getPrototypeOf,ke=Object.prototype.hasOwnProperty;var le=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),k=e=>{throw TypeError(e)};var Ce=(e,t,n)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var ie=(e,t)=>A(e,"name",{value:t,configurable:!0});var fe=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(n){throw t=0,n}},ue=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Re(t))!ke.call(e,r)&&r!==n&&A(e,r,{get:()=>t[r],enumerable:!(i=ce(t,r))||i.enumerable});return e},C=(e,t,n)=>(F(e,t,"default"),n&&F(n,t,"default")),$=(e,t,n)=>(n=e!=null?ae(Ne(e)):{},F(t||!e||!e.__esModule?A(n,"default",{value:e,enumerable:!0}):n,e)),Me=e=>F(A({},"__esModule",{value:!0}),e);var me=e=>[,,,ae(e?.[le("metadata")]??null)],pe=["class","method","getter","setter","accessor","field","value","get","set"],N=e=>e!==void 0&&typeof e!="function"?k("Function expected"):e,xe=(e,t,n,i,r)=>({kind:pe[e],name:t,metadata:i,addInitializer:o=>n._?k("Already initialized"):r.push(N(o||null))}),Fe=(e,t)=>Ce(t,le("metadata"),e[3]),de=(e,t,n,i)=>{for(var r=0,o=e[t>>1],s=o&&o.length;r<s;r++)t&1?o[r].call(n):i=o[r].call(n,i);return i},ye=(e,t,n,i,r,o)=>{var s,c,u,m,f,a=t&7,p=!!(t&8),l=!!(t&16),d=a>3?e.length+1:a?p?1:2:0,g=pe[a+5],S=a>3&&(e[d-1]=[]),_=e[d]||(e[d]=[]),T=a&&(!l&&!p&&(r=r.prototype),a<5&&(a>3||!l)&&ce(a<4?r:{get[n](){return oe(this,o)},set[n](y){return se(this,o,y)}},n));a?l&&a<4&&ie(o,(a>2?"set ":a>1?"get ":"")+n):ie(r,n);for(var K=i.length-1;K>=0;K--)m=xe(a,n,u={},e[3],_),a&&(m.static=p,m.private=l,f=m.access={has:l?y=>$e(r,y):y=>n in y},a^3&&(f.get=l?y=>(a^1?oe:Le)(y,r,a^4?o:T.get):y=>y[n]),a>2&&(f.set=l?(y,H)=>se(y,r,H,a^4?o:T.set):(y,H)=>y[n]=H)),c=(0,i[K])(a?a<4?l?o:T[g]:a>4?void 0:{get:T.get,set:T.set}:r,m),u._=1,a^4||c===void 0?N(c)&&(a>4?S.unshift(c):a?l?o=c:T[g]=c:r=c):typeof c!="object"||c===null?k("Object expected"):(N(s=c.get)&&(T.get=s),N(s=c.set)&&(T.set=s),N(s=c.init)&&S.unshift(s));return a||Fe(e,r),T&&A(r,n,T),l?a^4?o:T:r};var G=(e,t,n)=>t.has(e)||k("Cannot "+n),$e=(e,t)=>Object(t)!==t?k('Cannot use the "in" operator on this value'):e.has(t),oe=(e,t,n)=>(G(e,t,"read from private field"),n?n.call(e):t.get(e));var se=(e,t,n,i)=>(G(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),Le=(e,t,n)=>(G(e,t,"access private method"),n);var J=fe((ct,ge)=>{"use strict";ge.exports=window.Magma.Tempo});var ee=fe((ir,Ie)=>{"use strict";Ie.exports=window.Magma.pluginSdk});var st={};ue(st,{AtomicClock:()=>O,AtomicReader:()=>R,SyncPlugin:()=>ot});var re=$(J(),1);function L(e,t,n,i,r,o){function s(_){if(_!==void 0&&typeof _!="function")throw new TypeError("Function expected");return _}for(var c=i.kind,u=c==="getter"?"get":c==="setter"?"set":"value",m=!t&&e?i.static?e:e.prototype:null,f=t||(m?Object.getOwnPropertyDescriptor(m,i.name):{}),a,p=!1,l=n.length-1;l>=0;l--){var d={};for(var g in i)d[g]=g==="access"?{}:i[g];for(var g in i.access)d.access[g]=i.access[g];d.addInitializer=function(_){if(p)throw new TypeError("Cannot add initializers after decoration has completed");o.push(s(_||null))};var S=(0,n[l])(c==="accessor"?{get:f.get,set:f.set}:f[u],d);if(c==="accessor"){if(S===void 0)continue;if(S===null||typeof S!="object")throw new TypeError("Object expected");(a=s(S.get))&&(f.get=a),(a=s(S.set))&&(f.set=a),(a=s(S.init))&&r.unshift(a)}else(a=s(S))&&(c==="field"?r.unshift(a):f[u]=a)}m&&Object.defineProperty(m,i.name,f),p=!0}function B(e,t,n){for(var i=arguments.length>2,r=0;r<t.length;r++)n=i?t[r].call(e,n):t[r].call(e);return i?n:void 0}var Be=Symbol.for("$LibraryTarget"),Ue=Symbol.for("$LibraryDiscover"),We=Symbol.for("$LibraryExtensible"),ve=Symbol.for("nodejs.util.inspect.custom"),Ze=Symbol.for("$LibraryLogConfig"),Ye=Symbol.for("$LibraryRegistry"),ze=Symbol.for("$LibraryRegister"),Ke=Symbol.for("$LibrarySerializerRegistry"),He=Symbol.for("$LibraryMutable"),Ge=Symbol.for("$LibraryIdentity"),Je=Symbol.for("$LibraryUnwrapped"),h={$Target:Be,$Discover:Ue,$Extensible:We,$Inspect:ve,$LogConfig:Ze,$Registry:Ye,$Register:ze,$SerializerRegistry:Ke,$Identity:Ge,$Mutable:He,$Unwrapped:Je};function U(e){let t=e,n=0,i=50;for(;t;){let r=t[h.$Target];if(!r||n>=i)break;t=r,n++}return t}function I(e,t,...n){if(e===null||typeof e!="object"&&typeof e!="function")return!1;let i=U(e);if(!Object.hasOwn(i,t))return!1;if(n.length===0)return!0;let r=i[t];return he(r,n)}function D(e,t,...n){if(e===null||typeof e!="object"&&typeof e!="function")return!1;let i=U(e);if(!(t in i))return!1;if(n.length===0)return!0;let r=i[t];return he(r,n)}function he(e,t){for(let n=0;n<t.length;n++){let i=t[n];if(typeof i=="function"){if(i(e))return!0}else if(typeof i=="string"&&Xe(e,i.trim().toLowerCase()))return!0}return!1}function Xe(e,t){switch(t){case"string":case"number":case"boolean":case"function":case"bigint":case"symbol":case"undefined":return typeof e===t;case"array":return Array.isArray(e);case"null":return e===null;case"object":return e!==null&&!Array.isArray(e)&&typeof e=="object";case"any":case"unknown":return!0;default:return!1}}var Ve=[],Te=e=>{if(e===null)return"Null";if(e===void 0)return"Undefined";let t=typeof e;if(t==="string")return"String";if(t==="number")return"Number";if(t==="boolean")return"Boolean";if(t==="bigint")return"BigInt";if(t==="symbol")return"Symbol";try{let n=t==="object"?U(e):e;return Object.prototype.toString.call(n).slice(8,-1)}catch{return t==="function"?"Function":"Object"}},X=e=>{try{let t=e?.[Symbol.toStringTag]??e?.prototype?.[Symbol.toStringTag];if(typeof t=="string")return t}catch{}},Se=(e,...t)=>{let n=e;try{n=e?.[h.$Target]??e}catch{n=e}let i=Te(n);switch(i){case"Function":try{return Qe(n)?"Class":"Function"}catch{return"Function"}case"Object":{try{if("length"in n&&Object.keys(n).every(o=>o==="length"||Number.isFinite(Number(o))))return"ArrayLike";for(let o of t){let s=o.class?.[h.$Target]??o.class;if(n===s||s&&n instanceof s)return o.type}let r=globalThis[h.$Registry]??[];for(let o of[...Ve,...r]){let s=o.class?.[h.$Target]??o.class;if(n===s||s&&n instanceof s)return o.type}}catch{return"Object"}return"Object"}default:return i}};var qe=/^\s*(class\s|\[native code\])/,Qe=e=>{if(typeof e!="function")return!1;let t=e?.[h.$Target]??e;if(!("prototype"in t))return!1;let n=t?.name,i=X(t);if(t?.[h.$Identity]||t?.prototype?.[h.$Identity]||typeof i=="string"&&i.startsWith("Temporal."))return!0;if(typeof i=="string"&&i.endsWith("Function"))return!1;if((globalThis[h.$Registry]??[]).some(o=>(o.class?.[h.$Target]??o.class)===t||n&&o.type===n||i&&o.type===i))return!0;try{let o=Function.prototype.toString.call(t);if(qe.test(o))return!0;let s=Object.getOwnPropertyDescriptor(t,"prototype");if(s&&s.writable===!1&&!Object.isFrozen(t))return!0;let c=t.prototype;if(c&&Object.getOwnPropertyNames(c).length>2)return!0}catch{return!1}return!1};var V=(e,...t)=>t.includes(Se(e)),je=e=>e===null||typeof e!="object"&&typeof e!="function",q=e=>!je(e);var E=e=>typeof e=="string";var we=e=>V(e,"Object");var W=e=>typeof e=="symbol";var M=e=>e!=null,P=e=>e===void 0;var be=e=>V(e,"Function","AsyncFunction","GeneratorFunction","AsyncGeneratorFunction"),v=e=>typeof e=="function";var Ee=(e,t)=>V(e,"Error")&&(t?e instanceof t:!0);var Oe=(e,t)=>{if(!e||typeof e!="object"&&typeof e!="function")return!1;try{return e[t]===!0}catch{return!1}};var _e=e=>e?e.charAt(0).toUpperCase()+e.slice(1):"";function et(e,t){return X(e)??(P(t)?e.name||void 0:String(t))}function x(e,t){let n=(i,r,o,s)=>{let c=o??(E(r)?r:void 0)??(W(r)&&r.description?r.description:void 0)??et(i,s),u=c?String(c).replace(/^\$/,""):"Instance",m=E(r)||E(o),f=W(r)?r:m?Symbol.for(`Brand.${u}`):Symbol(`Brand.${u}`),a=d=>Oe(d,f),p=i.prototype;if(p&&!I(p,f)&&Object.defineProperty(p,f,{value:!0,configurable:!1,writable:!1,enumerable:!1}),p&&!I(p,Symbol.toStringTag)&&Object.defineProperty(p,Symbol.toStringTag,{value:u,configurable:!0,writable:!1,enumerable:!1}),!i.name||i.name!==u)try{Object.defineProperty(i,"name",{value:u,configurable:!0,writable:!1,enumerable:!1})}catch{}let l=`is${_e(u)}`;if(!I(i,l))try{Object.defineProperty(i,l,{value:a,configurable:!0,writable:!1,enumerable:!1})}catch{}if(!I(i,Symbol.hasInstance))try{Object.defineProperty(i,Symbol.hasInstance,{value:function(d){if(I(this,l)){let g=this[l];if(v(g))return g.call(this,d)}return q(d)&&q(this?.prototype)&&Object.prototype.isPrototypeOf.call(this.prototype,d)},configurable:!0,writable:!1,enumerable:!1})}catch{}return i};return v(e)&&t?.kind==="class"?n(e,void 0,void 0,t.name):(i,r)=>{let o=E(e)||W(e)?e:void 0,s=E(t)?t:void 0;return n(i,o,s,r?.name)}}function Q(e,t){let n=(i,r)=>{let o,s,c=i.name||"Singleton",u={[c]:class extends i{constructor(...m){if(o){if(r?.allowArgMismatch!==!0&&s){let f=s;if(m.length!==f.length||m.some((p,l)=>p!==f[l]))throw new Error(`[Singleton] Argument mismatch on subsequent instantiation of '${c}'`)}return o}return super(...m),s=m,o=this,this}}}[c];return Object.defineProperty(u,"instance",{get:()=>o,configurable:!0,enumerable:!1}),u};return v(e)&&t?.kind==="class"?n(e):(i,r)=>n(i,e)}var Ut=BigInt(Number.MAX_SAFE_INTEGER),Wt=BigInt(Number.MIN_SAFE_INTEGER);function Ae(e){if(Ee(e))return e;let t=new Error(D(e,"message",E)?e.message:String(e));return we(e)&&(t.name=D(e,"name","string")?e.name:"Error",D(e,"code","string","number")&&(t.code=e.code),D(e,"stack","string")&&(t.stack=e.stack)),t}var Z=new FinalizationRegistry(e=>{try{be(e)&&e()}catch(t){console.error("Finalizer callback error:",t)}}),j=(()=>{let e=[x("Finalizer")],t,n=[],i;return class{static{i=this}static{let r=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;L(null,t={value:i},e,{kind:"class",name:i.name,metadata:r},null,n),i=t.value,r&&Object.defineProperty(i,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),B(i,n)}#e;constructor(r){this.#e=r}register(r,o,s){let c=s??Object.create(null),u=this.#e;Z.register(r,()=>{u(o)},c)}unregister(r){return Z.unregister(r)}static register(r,o,s){let c=s??Object.create(null);return Z.register(r,o,c),()=>Z.unregister(c)}},i})(),Kt=j.isFinalizer;if(typeof globalThis.Temporal>"u")throw new Error("Temporal API is not available. Node 20+ with a polyfill (e.g. @js-temporal/polyfill) is highly recommended. Native Temporal is fully reliable only on Node 26+ (while Node 22 may have instabilities).");try{if(typeof Temporal.Now.zonedDateTimeISO=="function"&&typeof Temporal.Now.zonedDateTimeISO().add!="function")throw new Error("Incomplete Temporal implementation")}catch(e){let t=Ae(e);if(console.warn("Tempo: Native Temporal implementation appears incomplete. Consider loading a polyfill.",t),t.message!=="Incomplete Temporal implementation")throw t}var Y=(()=>{let e=[x("WeakCache")],t,n=[],i;return class{static{i=this}static{let r=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;L(null,t={value:i},e,{kind:"class",name:i.name,metadata:r},null,n),i=t.value,r&&Object.defineProperty(i,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r})}#e=new Map;#t;static isWeakCache=r=>typeof r=="object"&&r!==null&&#e in r;constructor(){this.#t=new j(r=>{let o=this.#e.get(r.key);o&&o.token===r.token&&this.#e.delete(r.key)})}set(r,o){this.delete(r);let s=Object.create(null);return this.#e.set(r,{ref:new WeakRef(o),token:s}),this.#t.register(o,{key:r,token:s},s),this}get(r){let o=this.#e.get(r);if(P(o))return;let s=o.ref.deref();if(P(s)){this.#t.unregister(o.token),this.#e.delete(r);return}return s}has(r){return M(this.get(r))}getOrSet(r,o){let s=this.get(r);if(M(s))return s;let c=o(r);return this.set(r,c),c}delete(r){let o=this.#e.get(r);return M(o)?(this.#e.delete(r),this.#t.unregister(o.token),!0):!1}clear(){for(let r of this.#e.values())this.#t.unregister(r.token);this.#e.clear()}static{B(i,n)}},i})(),jt=Y.isWeakCache;var on=new Y,sn=new Y;var tt=Object.freeze({MO:1,TU:2,WE:3,TH:4,FR:5,SA:6,SU:7,MON:1,TUE:2,WED:3,THU:4,FRI:5,SAT:6,SUN:7}),nt=Object.freeze({JAN:1,FEB:2,MAR:3,APR:4,MAY:5,JUN:6,JUL:7,AUG:8,SEP:9,OCT:10,NOV:11,DEC:12}),rt=Object.freeze({1:"Monday",2:"Tuesday",3:"Wednesday",4:"Thursday",5:"Friday",6:"Saturday",7:"Sunday"});var w={};ue(w,{definePlugin:()=>te,defineTerm:()=>it});C(w,$(ee()));var z=$(ee()),te=e=>(0,z.definePlugin)({...e,version:"2.0.0"}),it=e=>(0,z.defineTerm)({...e,version:"2.0.0"});var De,ne;De=[Q];var O=class{#e;#t;#r;#n;constructor(t={}){if(typeof SharedArrayBuffer>"u")throw new Error("[Tempo#sync] SharedArrayBuffer is not available in this environment. Ensure COOP/COEP headers are set, or use Node.js.");this.#e=new SharedArrayBuffer(8),this.#t=new BigInt64Array(this.#e),this.#r=t.interval??10;let n={timer:null};this.#n=n,w.Finalizer.register(this,()=>{n.timer&&(clearInterval(n.timer),n.timer=null)}),this.#i()}get[Symbol.toStringTag](){return"Tempo.AtomicClock"}getBuffer(){return this.#e}start(){if(this.#n.timer)return;let t=this.#t,n=setInterval(()=>{let i=re.Tempo.epoch.ns;Atomics.store(t,0,i)},this.#r);this.#n.timer=n,typeof n.unref=="function"&&n.unref()}stop(){this.#n.timer&&(clearInterval(this.#n.timer),this.#n.timer=null)}[Symbol.dispose](){this.stop()}#i(){let t=re.Tempo.epoch.ns;Atomics.store(this.#t,0,t)}};ne=me(null),O=ye(ne,0,"AtomicClock",De,O),de(ne,1,O);var Pe=$(J(),1),R=class{#e;constructor(t){if(typeof SharedArrayBuffer>"u")throw new Error("[Tempo#sync] SharedArrayBuffer is not available in this environment.");if(!(t instanceof SharedArrayBuffer))throw new Error("[Tempo#sync] AtomicReader requires a SharedArrayBuffer instance.");this.#e=new BigInt64Array(t)}get[Symbol.toStringTag](){return"Tempo.AtomicReader"}nowNano(){return Atomics.load(this.#e,0)}now(){return Number(this.nowNano()/1000000n)}getTempo(){return new Pe.Tempo(this.nowNano(),{timeStamp:"ns"})}};var b=null,ot=te({name:"sync",install(e){e.sync||(e.sync={startClock(t){return b?(b.start(),b):(b=new O(t),b.start(),b)},stopClock(){b&&b.stop()},getBuffer(){if(!b)throw new Error("[Tempo#sync] Cannot get buffer. You must call Tempo.sync.startClock() first.");return b.getBuffer()},now(t){return new R(t).now()},getTempo(t){let n=new R(t);return new e(n.now())}})}});return Me(st);})();
package/dist/index.js ADDED
@@ -0,0 +1,253 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
7
+ var __typeError = (msg) => {
8
+ throw TypeError(msg);
9
+ };
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
25
+ var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
26
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
27
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
28
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
29
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
30
+ var __runInitializers = (array, flags, self, value) => {
31
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
32
+ return value;
33
+ };
34
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
35
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
36
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
37
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
38
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
39
+ return __privateGet(this, extra);
40
+ }, set [name](x) {
41
+ return __privateSet(this, extra, x);
42
+ } }, name));
43
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
44
+ for (var i = decorators.length - 1; i >= 0; i--) {
45
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
46
+ if (k) {
47
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
48
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
49
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
50
+ }
51
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
52
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
53
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
54
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
55
+ }
56
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
57
+ };
58
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
59
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
60
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
61
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
62
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
63
+
64
+ // src/AtomicClock.ts
65
+ import { Tempo } from "tempo-kit";
66
+ import { Singleton } from "tempo-kit/library";
67
+
68
+ // auto-inject-version:tempo-kit/plugin/sdk
69
+ var sdk_exports = {};
70
+ __export(sdk_exports, {
71
+ definePlugin: () => definePlugin,
72
+ defineTerm: () => defineTerm
73
+ });
74
+ __reExport(sdk_exports, sdk_star);
75
+ import * as sdk_star from "tempo-kit/plugin/sdk";
76
+ import { definePlugin as originalPlugin, defineTerm as originalTerm } from "tempo-kit/plugin/sdk";
77
+ var definePlugin = (config) => originalPlugin({ ...config, version: "2.0.0" });
78
+ var defineTerm = (config) => originalTerm({ ...config, version: "2.0.0" });
79
+
80
+ // src/AtomicClock.ts
81
+ var _AtomicClock_decorators, _init;
82
+ _AtomicClock_decorators = [Singleton];
83
+ var AtomicClock = class {
84
+ #buffer;
85
+ #view;
86
+ #interval;
87
+ #state;
88
+ constructor(options = {}) {
89
+ if (typeof SharedArrayBuffer === "undefined")
90
+ throw new Error("[Tempo#sync] SharedArrayBuffer is not available in this environment. Ensure COOP/COEP headers are set, or use Node.js.");
91
+ this.#buffer = new SharedArrayBuffer(8);
92
+ this.#view = new BigInt64Array(this.#buffer);
93
+ this.#interval = options.interval ?? 10;
94
+ const state = { timer: null };
95
+ this.#state = state;
96
+ sdk_exports.Finalizer.register(this, () => {
97
+ if (state.timer) {
98
+ clearInterval(state.timer);
99
+ state.timer = null;
100
+ }
101
+ });
102
+ this.#tick();
103
+ }
104
+ get [Symbol.toStringTag]() {
105
+ return "Tempo.AtomicClock";
106
+ }
107
+ /**
108
+ * Returns the underlying SharedArrayBuffer to be passed to workers.
109
+ */
110
+ getBuffer() {
111
+ return this.#buffer;
112
+ }
113
+ /**
114
+ * Starts the synchronization loop.
115
+ */
116
+ start() {
117
+ if (this.#state.timer) return;
118
+ const view = this.#view;
119
+ const timer = setInterval(() => {
120
+ const nowNano = Tempo.epoch.ns;
121
+ Atomics.store(view, 0, nowNano);
122
+ }, this.#interval);
123
+ this.#state.timer = timer;
124
+ if (typeof timer.unref === "function") {
125
+ timer.unref();
126
+ }
127
+ }
128
+ /**
129
+ * Stops the synchronization loop.
130
+ */
131
+ stop() {
132
+ if (this.#state.timer) {
133
+ clearInterval(this.#state.timer);
134
+ this.#state.timer = null;
135
+ }
136
+ }
137
+ /**
138
+ * Explicit deterministic disposal (Dual-Layer Lifecycle Model).
139
+ */
140
+ [Symbol.dispose]() {
141
+ this.stop();
142
+ }
143
+ /**
144
+ * Writes the current exact time to the shared memory.
145
+ */
146
+ #tick() {
147
+ const nowNano = Tempo.epoch.ns;
148
+ Atomics.store(this.#view, 0, nowNano);
149
+ }
150
+ };
151
+ _init = __decoratorStart(null);
152
+ AtomicClock = __decorateElement(_init, 0, "AtomicClock", _AtomicClock_decorators, AtomicClock);
153
+ __runInitializers(_init, 1, AtomicClock);
154
+
155
+ // src/AtomicReader.ts
156
+ import { Tempo as Tempo2 } from "tempo-kit";
157
+ var AtomicReader = class {
158
+ #view;
159
+ constructor(buffer) {
160
+ if (typeof SharedArrayBuffer === "undefined") {
161
+ throw new Error("[Tempo#sync] SharedArrayBuffer is not available in this environment.");
162
+ }
163
+ if (!(buffer instanceof SharedArrayBuffer)) {
164
+ throw new Error("[Tempo#sync] AtomicReader requires a SharedArrayBuffer instance.");
165
+ }
166
+ this.#view = new BigInt64Array(buffer);
167
+ }
168
+ get [Symbol.toStringTag]() {
169
+ return "Tempo.AtomicReader";
170
+ }
171
+ /**
172
+ * Returns the exact synchronized epoch timestamp in nanoseconds.
173
+ * Executes in O(1) time with lock-free atomic read.
174
+ */
175
+ nowNano() {
176
+ return Atomics.load(this.#view, 0);
177
+ }
178
+ /**
179
+ * Returns the exact synchronized epoch timestamp in milliseconds.
180
+ */
181
+ now() {
182
+ return Number(this.nowNano() / 1000000n);
183
+ }
184
+ /**
185
+ * Convenience wrapper that returns a new Tempo instance representing the exact synchronized time.
186
+ */
187
+ getTempo() {
188
+ return new Tempo2(this.nowNano(), { timeStamp: "ns" });
189
+ }
190
+ };
191
+
192
+ // src/index.ts
193
+ var _globalClock = null;
194
+ var SyncPlugin = definePlugin({
195
+ name: "sync",
196
+ install(TempoRef) {
197
+ if (TempoRef.sync)
198
+ return;
199
+ TempoRef.sync = {
200
+ /**
201
+ * Starts the master atomic clock on the current thread.
202
+ * Only call this once on the main thread.
203
+ */
204
+ startClock(options) {
205
+ if (_globalClock) {
206
+ _globalClock.start();
207
+ return _globalClock;
208
+ }
209
+ _globalClock = new AtomicClock(options);
210
+ _globalClock.start();
211
+ return _globalClock;
212
+ },
213
+ /**
214
+ * Stops the master atomic clock.
215
+ */
216
+ stopClock() {
217
+ if (_globalClock) {
218
+ _globalClock.stop();
219
+ }
220
+ },
221
+ /**
222
+ * Gets the SharedArrayBuffer from the master clock.
223
+ * Throws an error if startClock() hasn't been called.
224
+ */
225
+ getBuffer() {
226
+ if (!_globalClock) {
227
+ throw new Error("[Tempo#sync] Cannot get buffer. You must call Tempo.sync.startClock() first.");
228
+ }
229
+ return _globalClock.getBuffer();
230
+ },
231
+ /**
232
+ * Synchronously reads the exact time from the provided SharedArrayBuffer.
233
+ * Designed to be called from a Web Worker.
234
+ */
235
+ now(buffer) {
236
+ const reader = new AtomicReader(buffer);
237
+ return reader.now();
238
+ },
239
+ /**
240
+ * Synchronously reads the time and returns a new Tempo instance.
241
+ */
242
+ getTempo(buffer) {
243
+ const reader = new AtomicReader(buffer);
244
+ return new TempoRef(reader.now());
245
+ }
246
+ };
247
+ }
248
+ });
249
+ export {
250
+ AtomicClock,
251
+ AtomicReader,
252
+ SyncPlugin
253
+ };
@@ -0,0 +1 @@
1
+ export * from './index.js';
@@ -0,0 +1 @@
1
+ "use strict";var Magma;((Magma||={}).plugins||={}).sync=(()=>{var ce=Object.create;var A=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var ke=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var fe=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),k=e=>{throw TypeError(e)};var Me=(e,t,n)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var oe=(e,t)=>A(e,"name",{value:t,configurable:!0});var ue=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(n){throw t=0,n}},me=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ne(t))!Ce.call(e,r)&&r!==n&&A(e,r,{get:()=>t[r],enumerable:!(i=le(t,r))||i.enumerable});return e},C=(e,t,n)=>(F(e,t,"default"),n&&F(n,t,"default")),$=(e,t,n)=>(n=e!=null?ce(ke(e)):{},F(t||!e||!e.__esModule?A(n,"default",{value:e,enumerable:!0}):n,e)),xe=e=>F(A({},"__esModule",{value:!0}),e);var pe=e=>[,,,ce(e?.[fe("metadata")]??null)],de=["class","method","getter","setter","accessor","field","value","get","set"],N=e=>e!==void 0&&typeof e!="function"?k("Function expected"):e,Fe=(e,t,n,i,r)=>({kind:de[e],name:t,metadata:i,addInitializer:o=>n._?k("Already initialized"):r.push(N(o||null))}),$e=(e,t)=>Me(t,fe("metadata"),e[3]),ye=(e,t,n,i)=>{for(var r=0,o=e[t>>1],s=o&&o.length;r<s;r++)t&1?o[r].call(n):i=o[r].call(n,i);return i},ge=(e,t,n,i,r,o)=>{var s,c,u,m,f,a=t&7,p=!!(t&8),l=!!(t&16),d=a>3?e.length+1:a?p?1:2:0,h=de[a+5],w=a>3&&(e[d-1]=[]),_=e[d]||(e[d]=[]),S=a&&(!l&&!p&&(r=r.prototype),a<5&&(a>3||!l)&&le(a<4?r:{get[n](){return se(this,o)},set[n](y){return ae(this,o,y)}},n));a?l&&a<4&&oe(o,(a>2?"set ":a>1?"get ":"")+n):oe(r,n);for(var K=i.length-1;K>=0;K--)m=Fe(a,n,u={},e[3],_),a&&(m.static=p,m.private=l,f=m.access={has:l?y=>Le(r,y):y=>n in y},a^3&&(f.get=l?y=>(a^1?se:Be)(y,r,a^4?o:S.get):y=>y[n]),a>2&&(f.set=l?(y,H)=>ae(y,r,H,a^4?o:S.set):(y,H)=>y[n]=H)),c=(0,i[K])(a?a<4?l?o:S[h]:a>4?void 0:{get:S.get,set:S.set}:r,m),u._=1,a^4||c===void 0?N(c)&&(a>4?w.unshift(c):a?l?o=c:S[h]=c:r=c):typeof c!="object"||c===null?k("Object expected"):(N(s=c.get)&&(S.get=s),N(s=c.set)&&(S.set=s),N(s=c.init)&&w.unshift(s));return a||$e(e,r),S&&A(r,n,S),l?a^4?o:S:r};var G=(e,t,n)=>t.has(e)||k("Cannot "+n),Le=(e,t)=>Object(t)!==t?k('Cannot use the "in" operator on this value'):e.has(t),se=(e,t,n)=>(G(e,t,"read from private field"),n?n.call(e):t.get(e));var ae=(e,t,n,i)=>(G(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),Be=(e,t,n)=>(G(e,t,"access private method"),n);var J=ue((ct,he)=>{"use strict";he.exports=window.Magma.pluginSdk});var V=ue((ft,Te)=>{"use strict";Te.exports=window.Magma.Tempo});var st={};me(st,{AtomicClock:()=>O,AtomicReader:()=>R,SyncPlugin:()=>ie});var g={};me(g,{definePlugin:()=>X,defineTerm:()=>Ue});C(g,$(J()));var L=$(J()),X=e=>(0,L.definePlugin)({...e,version:"2.0.0"}),Ue=e=>(0,L.defineTerm)({...e,version:"2.0.0"});var re=$(V(),1);function B(e,t,n,i,r,o){function s(_){if(_!==void 0&&typeof _!="function")throw new TypeError("Function expected");return _}for(var c=i.kind,u=c==="getter"?"get":c==="setter"?"set":"value",m=!t&&e?i.static?e:e.prototype:null,f=t||(m?Object.getOwnPropertyDescriptor(m,i.name):{}),a,p=!1,l=n.length-1;l>=0;l--){var d={};for(var h in i)d[h]=h==="access"?{}:i[h];for(var h in i.access)d.access[h]=i.access[h];d.addInitializer=function(_){if(p)throw new TypeError("Cannot add initializers after decoration has completed");o.push(s(_||null))};var w=(0,n[l])(c==="accessor"?{get:f.get,set:f.set}:f[u],d);if(c==="accessor"){if(w===void 0)continue;if(w===null||typeof w!="object")throw new TypeError("Object expected");(a=s(w.get))&&(f.get=a),(a=s(w.set))&&(f.set=a),(a=s(w.init))&&r.unshift(a)}else(a=s(w))&&(c==="field"?r.unshift(a):f[u]=a)}m&&Object.defineProperty(m,i.name,f),p=!0}function U(e,t,n){for(var i=arguments.length>2,r=0;r<t.length;r++)n=i?t[r].call(e,n):t[r].call(e);return i?n:void 0}var We=Symbol.for("$LibraryTarget"),ve=Symbol.for("$LibraryDiscover"),Ze=Symbol.for("$LibraryExtensible"),Ye=Symbol.for("nodejs.util.inspect.custom"),ze=Symbol.for("$LibraryLogConfig"),Ke=Symbol.for("$LibraryRegistry"),He=Symbol.for("$LibraryRegister"),Ge=Symbol.for("$LibrarySerializerRegistry"),Je=Symbol.for("$LibraryMutable"),Xe=Symbol.for("$LibraryIdentity"),Ve=Symbol.for("$LibraryUnwrapped"),T={$Target:We,$Discover:ve,$Extensible:Ze,$Inspect:Ye,$LogConfig:ze,$Registry:Ke,$Register:He,$SerializerRegistry:Ge,$Identity:Xe,$Mutable:Je,$Unwrapped:Ve};function W(e){let t=e,n=0,i=50;for(;t;){let r=t[T.$Target];if(!r||n>=i)break;t=r,n++}return t}function I(e,t,...n){if(e===null||typeof e!="object"&&typeof e!="function")return!1;let i=W(e);if(!Object.hasOwn(i,t))return!1;if(n.length===0)return!0;let r=i[t];return Se(r,n)}function D(e,t,...n){if(e===null||typeof e!="object"&&typeof e!="function")return!1;let i=W(e);if(!(t in i))return!1;if(n.length===0)return!0;let r=i[t];return Se(r,n)}function Se(e,t){for(let n=0;n<t.length;n++){let i=t[n];if(typeof i=="function"){if(i(e))return!0}else if(typeof i=="string"&&qe(e,i.trim().toLowerCase()))return!0}return!1}function qe(e,t){switch(t){case"string":case"number":case"boolean":case"function":case"bigint":case"symbol":case"undefined":return typeof e===t;case"array":return Array.isArray(e);case"null":return e===null;case"object":return e!==null&&!Array.isArray(e)&&typeof e=="object";case"any":case"unknown":return!0;default:return!1}}var Qe=[],we=e=>{if(e===null)return"Null";if(e===void 0)return"Undefined";let t=typeof e;if(t==="string")return"String";if(t==="number")return"Number";if(t==="boolean")return"Boolean";if(t==="bigint")return"BigInt";if(t==="symbol")return"Symbol";try{let n=t==="object"?W(e):e;return Object.prototype.toString.call(n).slice(8,-1)}catch{return t==="function"?"Function":"Object"}},q=e=>{try{let t=e?.[Symbol.toStringTag]??e?.prototype?.[Symbol.toStringTag];if(typeof t=="string")return t}catch{}},be=(e,...t)=>{let n=e;try{n=e?.[T.$Target]??e}catch{n=e}let i=we(n);switch(i){case"Function":try{return et(n)?"Class":"Function"}catch{return"Function"}case"Object":{try{if("length"in n&&Object.keys(n).every(o=>o==="length"||Number.isFinite(Number(o))))return"ArrayLike";for(let o of t){let s=o.class?.[T.$Target]??o.class;if(n===s||s&&n instanceof s)return o.type}let r=globalThis[T.$Registry]??[];for(let o of[...Qe,...r]){let s=o.class?.[T.$Target]??o.class;if(n===s||s&&n instanceof s)return o.type}}catch{return"Object"}return"Object"}default:return i}};var je=/^\s*(class\s|\[native code\])/,et=e=>{if(typeof e!="function")return!1;let t=e?.[T.$Target]??e;if(!("prototype"in t))return!1;let n=t?.name,i=q(t);if(t?.[T.$Identity]||t?.prototype?.[T.$Identity]||typeof i=="string"&&i.startsWith("Temporal."))return!0;if(typeof i=="string"&&i.endsWith("Function"))return!1;if((globalThis[T.$Registry]??[]).some(o=>(o.class?.[T.$Target]??o.class)===t||n&&o.type===n||i&&o.type===i))return!0;try{let o=Function.prototype.toString.call(t);if(je.test(o))return!0;let s=Object.getOwnPropertyDescriptor(t,"prototype");if(s&&s.writable===!1&&!Object.isFrozen(t))return!0;let c=t.prototype;if(c&&Object.getOwnPropertyNames(c).length>2)return!0}catch{return!1}return!1};var Q=(e,...t)=>t.includes(be(e)),tt=e=>e===null||typeof e!="object"&&typeof e!="function",j=e=>!tt(e);var E=e=>typeof e=="string";var Ee=e=>Q(e,"Object");var v=e=>typeof e=="symbol";var M=e=>e!=null,P=e=>e===void 0;var Oe=e=>Q(e,"Function","AsyncFunction","GeneratorFunction","AsyncGeneratorFunction"),Z=e=>typeof e=="function";var _e=(e,t)=>Q(e,"Error")&&(t?e instanceof t:!0);var Ae=(e,t)=>{if(!e||typeof e!="object"&&typeof e!="function")return!1;try{return e[t]===!0}catch{return!1}};var Ie=e=>e?e.charAt(0).toUpperCase()+e.slice(1):"";function nt(e,t){return q(e)??(P(t)?e.name||void 0:String(t))}function x(e,t){let n=(i,r,o,s)=>{let c=o??(E(r)?r:void 0)??(v(r)&&r.description?r.description:void 0)??nt(i,s),u=c?String(c).replace(/^\$/,""):"Instance",m=E(r)||E(o),f=v(r)?r:m?Symbol.for(`Brand.${u}`):Symbol(`Brand.${u}`),a=d=>Ae(d,f),p=i.prototype;if(p&&!I(p,f)&&Object.defineProperty(p,f,{value:!0,configurable:!1,writable:!1,enumerable:!1}),p&&!I(p,Symbol.toStringTag)&&Object.defineProperty(p,Symbol.toStringTag,{value:u,configurable:!0,writable:!1,enumerable:!1}),!i.name||i.name!==u)try{Object.defineProperty(i,"name",{value:u,configurable:!0,writable:!1,enumerable:!1})}catch{}let l=`is${Ie(u)}`;if(!I(i,l))try{Object.defineProperty(i,l,{value:a,configurable:!0,writable:!1,enumerable:!1})}catch{}if(!I(i,Symbol.hasInstance))try{Object.defineProperty(i,Symbol.hasInstance,{value:function(d){if(I(this,l)){let h=this[l];if(Z(h))return h.call(this,d)}return j(d)&&j(this?.prototype)&&Object.prototype.isPrototypeOf.call(this.prototype,d)},configurable:!0,writable:!1,enumerable:!1})}catch{}return i};return Z(e)&&t?.kind==="class"?n(e,void 0,void 0,t.name):(i,r)=>{let o=E(e)||v(e)?e:void 0,s=E(t)?t:void 0;return n(i,o,s,r?.name)}}function ee(e,t){let n=(i,r)=>{let o,s,c=i.name||"Singleton",u={[c]:class extends i{constructor(...m){if(o){if(r?.allowArgMismatch!==!0&&s){let f=s;if(m.length!==f.length||m.some((p,l)=>p!==f[l]))throw new Error(`[Singleton] Argument mismatch on subsequent instantiation of '${c}'`)}return o}return super(...m),s=m,o=this,this}}}[c];return Object.defineProperty(u,"instance",{get:()=>o,configurable:!0,enumerable:!1}),u};return Z(e)&&t?.kind==="class"?n(e):(i,r)=>n(i,e)}var vt=BigInt(Number.MAX_SAFE_INTEGER),Zt=BigInt(Number.MIN_SAFE_INTEGER);function De(e){if(_e(e))return e;let t=new Error(D(e,"message",E)?e.message:String(e));return Ee(e)&&(t.name=D(e,"name","string")?e.name:"Error",D(e,"code","string","number")&&(t.code=e.code),D(e,"stack","string")&&(t.stack=e.stack)),t}var Y=new FinalizationRegistry(e=>{try{Oe(e)&&e()}catch(t){console.error("Finalizer callback error:",t)}}),te=(()=>{let e=[x("Finalizer")],t,n=[],i;return class{static{i=this}static{let r=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;B(null,t={value:i},e,{kind:"class",name:i.name,metadata:r},null,n),i=t.value,r&&Object.defineProperty(i,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),U(i,n)}#e;constructor(r){this.#e=r}register(r,o,s){let c=s??Object.create(null),u=this.#e;Y.register(r,()=>{u(o)},c)}unregister(r){return Y.unregister(r)}static register(r,o,s){let c=s??Object.create(null);return Y.register(r,o,c),()=>Y.unregister(c)}},i})(),Gt=te.isFinalizer;if(typeof globalThis.Temporal>"u")throw new Error("Temporal API is not available. Node 20+ with a polyfill (e.g. @js-temporal/polyfill) is highly recommended. Native Temporal is fully reliable only on Node 26+ (while Node 22 may have instabilities).");try{if(typeof Temporal.Now.zonedDateTimeISO=="function"&&typeof Temporal.Now.zonedDateTimeISO().add!="function")throw new Error("Incomplete Temporal implementation")}catch(e){let t=De(e);if(console.warn("Tempo: Native Temporal implementation appears incomplete. Consider loading a polyfill.",t),t.message!=="Incomplete Temporal implementation")throw t}var z=(()=>{let e=[x("WeakCache")],t,n=[],i;return class{static{i=this}static{let r=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;B(null,t={value:i},e,{kind:"class",name:i.name,metadata:r},null,n),i=t.value,r&&Object.defineProperty(i,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r})}#e=new Map;#t;static isWeakCache=r=>typeof r=="object"&&r!==null&&#e in r;constructor(){this.#t=new te(r=>{let o=this.#e.get(r.key);o&&o.token===r.token&&this.#e.delete(r.key)})}set(r,o){this.delete(r);let s=Object.create(null);return this.#e.set(r,{ref:new WeakRef(o),token:s}),this.#t.register(o,{key:r,token:s},s),this}get(r){let o=this.#e.get(r);if(P(o))return;let s=o.ref.deref();if(P(s)){this.#t.unregister(o.token),this.#e.delete(r);return}return s}has(r){return M(this.get(r))}getOrSet(r,o){let s=this.get(r);if(M(s))return s;let c=o(r);return this.set(r,c),c}delete(r){let o=this.#e.get(r);return M(o)?(this.#e.delete(r),this.#t.unregister(o.token),!0):!1}clear(){for(let r of this.#e.values())this.#t.unregister(r.token);this.#e.clear()}static{U(i,n)}},i})(),tn=z.isWeakCache;var an=new z,cn=new z;var rt=Object.freeze({MO:1,TU:2,WE:3,TH:4,FR:5,SA:6,SU:7,MON:1,TUE:2,WED:3,THU:4,FRI:5,SAT:6,SUN:7}),it=Object.freeze({JAN:1,FEB:2,MAR:3,APR:4,MAY:5,JUN:6,JUL:7,AUG:8,SEP:9,OCT:10,NOV:11,DEC:12}),ot=Object.freeze({1:"Monday",2:"Tuesday",3:"Wednesday",4:"Thursday",5:"Friday",6:"Saturday",7:"Sunday"});var Pe,ne;Pe=[ee];var O=class{#e;#t;#r;#n;constructor(t={}){if(typeof SharedArrayBuffer>"u")throw new Error("[Tempo#sync] SharedArrayBuffer is not available in this environment. Ensure COOP/COEP headers are set, or use Node.js.");this.#e=new SharedArrayBuffer(8),this.#t=new BigInt64Array(this.#e),this.#r=t.interval??10;let n={timer:null};this.#n=n,g.Finalizer.register(this,()=>{n.timer&&(clearInterval(n.timer),n.timer=null)}),this.#i()}get[Symbol.toStringTag](){return"Tempo.AtomicClock"}getBuffer(){return this.#e}start(){if(this.#n.timer)return;let t=this.#t,n=setInterval(()=>{let i=re.Tempo.epoch.ns;Atomics.store(t,0,i)},this.#r);this.#n.timer=n,typeof n.unref=="function"&&n.unref()}stop(){this.#n.timer&&(clearInterval(this.#n.timer),this.#n.timer=null)}[Symbol.dispose](){this.stop()}#i(){let t=re.Tempo.epoch.ns;Atomics.store(this.#t,0,t)}};ne=pe(null),O=ge(ne,0,"AtomicClock",Pe,O),ye(ne,1,O);var Re=$(V(),1),R=class{#e;constructor(t){if(typeof SharedArrayBuffer>"u")throw new Error("[Tempo#sync] SharedArrayBuffer is not available in this environment.");if(!(t instanceof SharedArrayBuffer))throw new Error("[Tempo#sync] AtomicReader requires a SharedArrayBuffer instance.");this.#e=new BigInt64Array(t)}get[Symbol.toStringTag](){return"Tempo.AtomicReader"}nowNano(){return Atomics.load(this.#e,0)}now(){return Number(this.nowNano()/1000000n)}getTempo(){return new Re.Tempo(this.nowNano(),{timeStamp:"ns"})}};var b=null,ie=X({name:"sync",install(e){e.sync||(e.sync={startClock(t){return b?(b.start(),b):(b=new O(t),b.start(),b)},stopClock(){b&&b.stop()},getBuffer(){if(!b)throw new Error("[Tempo#sync] Cannot get buffer. You must call Tempo.sync.startClock() first.");return b.getBuffer()},now(t){return new R(t).now()},getTempo(t){let n=new R(t);return new e(n.now())}})}});(0,g.autoInstall)(ie);return xe(st);})();
@@ -0,0 +1,254 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
7
+ var __typeError = (msg) => {
8
+ throw TypeError(msg);
9
+ };
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
25
+ var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
26
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
27
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
28
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
29
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
30
+ var __runInitializers = (array, flags, self, value) => {
31
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
32
+ return value;
33
+ };
34
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
35
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
36
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
37
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
38
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
39
+ return __privateGet(this, extra);
40
+ }, set [name](x) {
41
+ return __privateSet(this, extra, x);
42
+ } }, name));
43
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
44
+ for (var i = decorators.length - 1; i >= 0; i--) {
45
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
46
+ if (k) {
47
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
48
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
49
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
50
+ }
51
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
52
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
53
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
54
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
55
+ }
56
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
57
+ };
58
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
59
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
60
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
61
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
62
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
63
+
64
+ // auto-inject-version:tempo-kit/plugin/sdk
65
+ var sdk_exports = {};
66
+ __export(sdk_exports, {
67
+ definePlugin: () => definePlugin,
68
+ defineTerm: () => defineTerm
69
+ });
70
+ __reExport(sdk_exports, sdk_star);
71
+ import * as sdk_star from "tempo-kit/plugin/sdk";
72
+ import { definePlugin as originalPlugin, defineTerm as originalTerm } from "tempo-kit/plugin/sdk";
73
+ var definePlugin = (config) => originalPlugin({ ...config, version: "2.0.0" });
74
+ var defineTerm = (config) => originalTerm({ ...config, version: "2.0.0" });
75
+
76
+ // src/AtomicClock.ts
77
+ import { Tempo } from "tempo-kit";
78
+ import { Singleton } from "tempo-kit/library";
79
+ var _AtomicClock_decorators, _init;
80
+ _AtomicClock_decorators = [Singleton];
81
+ var AtomicClock = class {
82
+ #buffer;
83
+ #view;
84
+ #interval;
85
+ #state;
86
+ constructor(options = {}) {
87
+ if (typeof SharedArrayBuffer === "undefined")
88
+ throw new Error("[Tempo#sync] SharedArrayBuffer is not available in this environment. Ensure COOP/COEP headers are set, or use Node.js.");
89
+ this.#buffer = new SharedArrayBuffer(8);
90
+ this.#view = new BigInt64Array(this.#buffer);
91
+ this.#interval = options.interval ?? 10;
92
+ const state = { timer: null };
93
+ this.#state = state;
94
+ sdk_exports.Finalizer.register(this, () => {
95
+ if (state.timer) {
96
+ clearInterval(state.timer);
97
+ state.timer = null;
98
+ }
99
+ });
100
+ this.#tick();
101
+ }
102
+ get [Symbol.toStringTag]() {
103
+ return "Tempo.AtomicClock";
104
+ }
105
+ /**
106
+ * Returns the underlying SharedArrayBuffer to be passed to workers.
107
+ */
108
+ getBuffer() {
109
+ return this.#buffer;
110
+ }
111
+ /**
112
+ * Starts the synchronization loop.
113
+ */
114
+ start() {
115
+ if (this.#state.timer) return;
116
+ const view = this.#view;
117
+ const timer = setInterval(() => {
118
+ const nowNano = Tempo.epoch.ns;
119
+ Atomics.store(view, 0, nowNano);
120
+ }, this.#interval);
121
+ this.#state.timer = timer;
122
+ if (typeof timer.unref === "function") {
123
+ timer.unref();
124
+ }
125
+ }
126
+ /**
127
+ * Stops the synchronization loop.
128
+ */
129
+ stop() {
130
+ if (this.#state.timer) {
131
+ clearInterval(this.#state.timer);
132
+ this.#state.timer = null;
133
+ }
134
+ }
135
+ /**
136
+ * Explicit deterministic disposal (Dual-Layer Lifecycle Model).
137
+ */
138
+ [Symbol.dispose]() {
139
+ this.stop();
140
+ }
141
+ /**
142
+ * Writes the current exact time to the shared memory.
143
+ */
144
+ #tick() {
145
+ const nowNano = Tempo.epoch.ns;
146
+ Atomics.store(this.#view, 0, nowNano);
147
+ }
148
+ };
149
+ _init = __decoratorStart(null);
150
+ AtomicClock = __decorateElement(_init, 0, "AtomicClock", _AtomicClock_decorators, AtomicClock);
151
+ __runInitializers(_init, 1, AtomicClock);
152
+
153
+ // src/AtomicReader.ts
154
+ import { Tempo as Tempo2 } from "tempo-kit";
155
+ var AtomicReader = class {
156
+ #view;
157
+ constructor(buffer) {
158
+ if (typeof SharedArrayBuffer === "undefined") {
159
+ throw new Error("[Tempo#sync] SharedArrayBuffer is not available in this environment.");
160
+ }
161
+ if (!(buffer instanceof SharedArrayBuffer)) {
162
+ throw new Error("[Tempo#sync] AtomicReader requires a SharedArrayBuffer instance.");
163
+ }
164
+ this.#view = new BigInt64Array(buffer);
165
+ }
166
+ get [Symbol.toStringTag]() {
167
+ return "Tempo.AtomicReader";
168
+ }
169
+ /**
170
+ * Returns the exact synchronized epoch timestamp in nanoseconds.
171
+ * Executes in O(1) time with lock-free atomic read.
172
+ */
173
+ nowNano() {
174
+ return Atomics.load(this.#view, 0);
175
+ }
176
+ /**
177
+ * Returns the exact synchronized epoch timestamp in milliseconds.
178
+ */
179
+ now() {
180
+ return Number(this.nowNano() / 1000000n);
181
+ }
182
+ /**
183
+ * Convenience wrapper that returns a new Tempo instance representing the exact synchronized time.
184
+ */
185
+ getTempo() {
186
+ return new Tempo2(this.nowNano(), { timeStamp: "ns" });
187
+ }
188
+ };
189
+
190
+ // src/index.ts
191
+ var _globalClock = null;
192
+ var SyncPlugin = definePlugin({
193
+ name: "sync",
194
+ install(TempoRef) {
195
+ if (TempoRef.sync)
196
+ return;
197
+ TempoRef.sync = {
198
+ /**
199
+ * Starts the master atomic clock on the current thread.
200
+ * Only call this once on the main thread.
201
+ */
202
+ startClock(options) {
203
+ if (_globalClock) {
204
+ _globalClock.start();
205
+ return _globalClock;
206
+ }
207
+ _globalClock = new AtomicClock(options);
208
+ _globalClock.start();
209
+ return _globalClock;
210
+ },
211
+ /**
212
+ * Stops the master atomic clock.
213
+ */
214
+ stopClock() {
215
+ if (_globalClock) {
216
+ _globalClock.stop();
217
+ }
218
+ },
219
+ /**
220
+ * Gets the SharedArrayBuffer from the master clock.
221
+ * Throws an error if startClock() hasn't been called.
222
+ */
223
+ getBuffer() {
224
+ if (!_globalClock) {
225
+ throw new Error("[Tempo#sync] Cannot get buffer. You must call Tempo.sync.startClock() first.");
226
+ }
227
+ return _globalClock.getBuffer();
228
+ },
229
+ /**
230
+ * Synchronously reads the exact time from the provided SharedArrayBuffer.
231
+ * Designed to be called from a Web Worker.
232
+ */
233
+ now(buffer) {
234
+ const reader = new AtomicReader(buffer);
235
+ return reader.now();
236
+ },
237
+ /**
238
+ * Synchronously reads the time and returns a new Tempo instance.
239
+ */
240
+ getTempo(buffer) {
241
+ const reader = new AtomicReader(buffer);
242
+ return new TempoRef(reader.now());
243
+ }
244
+ };
245
+ }
246
+ });
247
+
248
+ // src/install.ts
249
+ (0, sdk_exports.autoInstall)(SyncPlugin);
250
+ export {
251
+ AtomicClock,
252
+ AtomicReader,
253
+ SyncPlugin
254
+ };
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@tempo-kit/plugin-sync",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.0",
4
+ "description": "Tempo community plugin providing lock-free, highly precise cross-thread synchronization via SharedArrayBuffer and Atomics.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "sideEffects": [
8
+ "./dist/install.js"
9
+ ],
10
+ "license": "MIT",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/magmacomputing/magma.git",
14
+ "directory": "packages/plugins/sync"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "CHANGELOG.md",
20
+ "LICENSE"
21
+ ],
22
+ "publishConfig": {
23
+ "registry": "https://registry.npmjs.org/",
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "build": "tsup && tsc",
28
+ "test": "vitest run -c ../vitest.shared.ts",
29
+ "prepublishOnly": "tempo-cli prepublish"
30
+ },
31
+ "peerDependencies": {
32
+ "tempo-kit": "^5.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "tempo-kit": "^5.0.0"
36
+ },
37
+ "keywords": [
38
+ "tempo-kit",
39
+ "tempo-kit-plugin",
40
+ "tempo",
41
+ "temporal",
42
+ "tempo-plugin",
43
+ "sync",
44
+ "sharedarraybuffer",
45
+ "atomics",
46
+ "thread",
47
+ "worker"
48
+ ],
49
+ "type": "module",
50
+ "exports": {
51
+ ".": {
52
+ "types": "./dist/index.d.ts",
53
+ "import": "./dist/index.js",
54
+ "default": "./dist/index.js"
55
+ },
56
+ "./install": {
57
+ "types": "./dist/index.d.ts",
58
+ "import": "./dist/install.js",
59
+ "default": "./dist/install.js"
60
+ }
61
+ }
62
+ }