@audiotool/nexus 0.0.7 → 0.0.9

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/README.md CHANGED
@@ -1,37 +1,7 @@
1
- # Audiotool SDK
1
+ # Audiotool Nexus SDK
2
2
 
3
- Overview of repo:
3
+ Th official Audiotool Nexus SDK, allowing you to connect to a multiplayer session on https://beta.audiotool.com/ and modify projects in real time.
4
4
 
5
- - `src/` source code
6
- - `src/exports/*.ts` - the entry points of the package
7
- - `src/docs/` docs `.md` pages
8
- - `tests` - tests of the package in various platforms (bun, node, ...)
9
- - `codegen` - code generators executed when running `npm run codegen`
5
+ See the documentation at https://developer.audiotool.com/js-package-documentation/.
10
6
 
11
- Config files currently contain duplicate infos:
12
-
13
- - `tsconfig.ts`: path aliases like `@gen/`, `@utils`
14
- - `vite.config.ts`: same aliases but used by vite's bundler
15
- - `package.json`: defines what of the `dist/` dir should be exported by package
16
- - `typedoc.json`: defines what of the unbundled source code should be considered "entry points" of the package
17
-
18
- ## Running tests in `tests/`:
19
-
20
- Add env var `AT_PAT=<pat>` with PAT found at https://developer.audiotool.com/personal-access-tokens.
21
-
22
- ## Testing the package
23
-
24
- To test what the package does when built, create a new project with npm or bun somewhere. Then:
25
-
26
- 1. in this directory, call `npm/bun link`
27
- 2. in your new directory, call `npm/bun link @audiotool/nexus --save`
28
-
29
- When you call `npm run build` here, the other repository will automatically update (`link` creates a dyn link to this repo).
30
-
31
- What's finally uploaded to npm can be seen by calling `npm run pack`, which generates a `.tgz` file in `dist/`; this file can then be installed with:
32
-
33
- ```
34
- npm/bun install <file>.tgz
35
- ```
36
-
37
- What's installed in `node_modules` is what's part of the final package on npm. This should be what's in `dist/`, including the `README.md` copied from `src/docs/README.md`.
7
+ This package is currently at version 0.0.x. Expect breaking changes between minor versions.
package/dist/api.js CHANGED
@@ -1,8 +1,8 @@
1
1
  var d = Object.defineProperty;
2
2
  var U = (e, n, s) => n in e ? d(e, n, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[n] = s;
3
3
  var a = (e, n, s) => U(e, typeof n != "symbol" ? n + "" : n, s);
4
- import { S as m, P as E } from "./audiotool-api-BeiEe46q.js";
5
- import { A as P, a as A, C as q, i as O, a9 as c, aa as g, az as j, v as G, w as F, _ as L, $ as v, J as K, K as f, am as H, ao as Y, D as w, j as x, y as B, z as h, a4 as J, a5 as V, M, N as b, av as z, aw as Q, aH as $, aI as k, c as y, b as W, d as X, e as Z, ad as ee, ae as se, f as ae, g as te, t as oe, u as ne, Y as re, Z as ie, ar as Re, as as pe, aL as me, aM as le, aF as ue, aG as Ee, G as Ne, L as Ce, h as de, q as Ue, r as Se, H as Te, I as _e, W as De, X as Ie, ak as Pe, al as Ae, ab as qe, ac as Oe, aD as ce, aE as ge, ax as je, ay as Ge, a7 as Fe, a8 as Le, O as ve, o as Ke, l as fe, p as He, m as Ye, E as we, F as xe, B as Be, V as he, ai as Je, ag as Ve, ah as Me, aj as be, an as ze, af as Qe, aA as $e, k as ke, a6 as ye, T as We, U as Xe, x as Ze, a2 as es, a3 as ss, Q as as, R as ts, at as os, au as ns, aN as rs, aO as is, aJ as Rs, aK as ps, aP as ms, aQ as ls, a0 as us, a1 as Es, ap as Ns, aq as Cs, aB as ds, aC as Us, aR as Ss, n as Ts, s as _s } from "./audiotool-api-BeiEe46q.js";
4
+ import { S as m, P as E } from "./audiotool-api-o8DnCQiu.js";
5
+ import { A as P, a as A, C as q, i as O, a9 as c, aa as g, az as j, v as G, w as F, _ as L, $ as v, J as K, K as f, am as H, ao as Y, D as w, j as x, y as B, z as h, a4 as J, a5 as V, M, N as b, av as z, aw as Q, aH as $, aI as k, c as y, b as W, d as X, e as Z, ad as ee, ae as se, f as ae, g as te, t as oe, u as ne, Y as re, Z as ie, ar as Re, as as pe, aL as me, aM as le, aF as ue, aG as Ee, G as Ne, L as Ce, h as de, q as Ue, r as Se, H as Te, I as _e, W as De, X as Ie, ak as Pe, al as Ae, ab as qe, ac as Oe, aD as ce, aE as ge, ax as je, ay as Ge, a7 as Fe, a8 as Le, O as ve, o as Ke, l as fe, p as He, m as Ye, E as we, F as xe, B as Be, V as he, ai as Je, ag as Ve, ah as Me, aj as be, an as ze, af as Qe, aA as $e, k as ke, a6 as ye, T as We, U as Xe, x as Ze, a2 as es, a3 as ss, Q as as, R as ts, at as os, au as ns, aN as rs, aO as is, aJ as Rs, aK as ps, aP as ms, aQ as ls, a0 as us, a1 as Es, ap as Ns, aq as Cs, aB as ds, aC as Us, aR as Ss, n as Ts, s as _s } from "./audiotool-api-o8DnCQiu.js";
6
6
  import { B as Is, f as Ps, E as As, F as qs, d as Os, e as cs, I as gs, b as js, L as Gs, P as Fs, a as Ls, S as vs, T as Ks, U as fs, c as Hs, g as Ys, j as ws, m as xs, k as Bs, h as hs, i as Js, l as Vs, p as Ms, s as bs, u as zs } from "./opt_pb-Dp9pF04Q.js";
7
7
  import { Message as N, proto3 as o, Timestamp as C } from "@bufbuild/protobuf";
8
8
  var R = /* @__PURE__ */ ((e) => (e[e.UNSPECIFIED = 0] = "UNSPECIFIED", e[e.STARTED = 1] = "STARTED", e[e.AUDIO_RENDERING = 3] = "AUDIO_RENDERING", e[e.AUDIO_RENDERED = 4] = "AUDIO_RENDERED", e[e.AUDIO_CONVERTING = 5] = "AUDIO_CONVERTING", e[e.AUDIO_CONVERTED = 6] = "AUDIO_CONVERTED", e[e.FINISHED = 7] = "FINISHED", e))(R || {});
@@ -4,7 +4,7 @@ var a = (i, s, t) => Tr(i, typeof s != "symbol" ? s + "" : s, t);
4
4
  import { Message as e, proto3 as r, MethodKind as o, Any as Zt, Timestamp as d, FieldMask as mn, Duration as ur, createRegistry as lr } from "@bufbuild/protobuf";
5
5
  import { createConnectTransport as Sr } from "@connectrpc/connect-web";
6
6
  import { createClient as wr, ConnectError as Ir, Code as za } from "@connectrpc/connect";
7
- import { s as gr, t as cr } from "./lang-KJQpoj7q.js";
7
+ import { s as gr, t as cr } from "./lang-BqPY1uAS.js";
8
8
  import { a as Er, e as Jr } from "./types-Cztu157p.js";
9
9
  const S = class S extends e {
10
10
  constructor(t) {
@@ -1,5 +1,6 @@
1
1
  import { Transaction } from '../../../gen/audiotool/document/v1/document_service_pb';
2
2
  import { WasmDocumentState } from '../create-wasm-document-state';
3
+ import { ReadonlyTransaction } from '../gateway';
3
4
 
4
5
  /**
5
6
  * This class can be used to "consolidate" two transaction histories in such a way that
@@ -28,5 +29,5 @@ export declare class NexusStateConsolidator {
28
29
  /** new rejected transactions received from the document service. Must be a subset of `newOutgoing`. */
29
30
  newReceivedRejected: Set<string>,
30
31
  /** new locally created transactions */
31
- newCreated: Transaction[]): Transaction[];
32
+ newCreated: Transaction[]): ReadonlyTransaction[];
32
33
  }
@@ -1,6 +1,6 @@
1
1
  import { Transaction } from '../../../gen/audiotool/document/v1/document_service_pb';
2
2
  import { ObservableValue } from '../../../utils/observable-notifier-value';
3
- import { NexusGateway } from '../gateway';
3
+ import { NexusGateway, ReadonlyTransaction } from '../gateway';
4
4
  import { WasmDocumentState } from '../create-wasm-document-state';
5
5
  import { DocumentServiceWrapper } from './wrapper/wrapper';
6
6
 
@@ -32,5 +32,5 @@ export declare class CollabGateway implements NexusGateway {
32
32
  /** Send a transaction to the document service. */
33
33
  send(t: Transaction): void;
34
34
  /** Receive new transactions from the backend, already consolidated with the local change history.*/
35
- synchronize(): Transaction[];
35
+ synchronize(): ReadonlyTransaction[];
36
36
  }
@@ -1,6 +1,17 @@
1
- import { Transaction } from '../../gen/audiotool/document/v1/document_service_pb';
1
+ import { Modification, Transaction } from '../../gen/audiotool/document/v1/document_service_pb';
2
2
  import { ObservableValue } from '../../utils/observable-notifier-value';
3
3
 
4
+ /** A read only variant of a transaction that is returned by {@link NexusGateway.synchronize}.
5
+ *
6
+ * It's important that the gateway doesn't have to clone every transaction for performance reasons,
7
+ * but the returned transactions must also never be modified by the caller. This type
8
+ * allows us to enforce this.
9
+ */
10
+ export type ReadonlyTransaction = {
11
+ readonly id: string;
12
+ readonly commitIndex: number;
13
+ readonly modifications: readonly Modification[];
14
+ };
4
15
  /**
5
16
  * This is the interface the {@link NexusDocument} uses to sync itself with
6
17
  * a state from some "backend". This could be a server, local storage,
@@ -15,6 +26,8 @@ export interface NexusGateway {
15
26
  */
16
27
  send(t: Transaction): void;
17
28
  /** Fetch new transactions that should be immediately applied to the document to sync with upstream.
29
+ *
30
+ * The returned transactions MUST NOT be modified by the caller.
18
31
  *
19
32
  * This function must only be called after all local transactions created since the last call
20
33
  * to {@link synchronize} have been sent with {@link send}.
@@ -29,7 +42,7 @@ export interface NexusGateway {
29
42
  * one transaction. If the document state is empty, that transaction can be empty. The studio
30
43
  * will show the loading spinner until the first transaction is received.
31
44
  */
32
- synchronize(): Transaction[];
45
+ synchronize(): ReadonlyTransaction[];
33
46
  /** This becomes true when the gateway is blocked in some way from syncing with upstream state.
34
47
  * The document should be locked in this case to prevent data loss.
35
48
  */
@@ -1,8 +1,7 @@
1
- import { Modification, Transaction } from '../gen/audiotool/document/v1/document_service_pb';
2
- import { EntityTypes } from '../gen/audiotool/document/v1/utils/types';
3
1
  import { Notifier } from '../utils/observable-notifier';
4
- import { NexusGateway } from './backend/gateway';
2
+ import { NexusGateway, ReadonlyTransaction } from './backend/gateway';
5
3
  import { NexusValidator } from './backend/validator';
4
+ import { Modification, Transaction } from '../gen/audiotool/document/v1/document_service_pb';
6
5
  import { EntityTypeKey } from './entity-utils';
7
6
  import { NexusEventManager } from './event-manager';
8
7
  import { EntityQuery } from './query/entity';
@@ -100,16 +99,6 @@ export declare class NexusDocument {
100
99
  */
101
100
  actionId?: symbol;
102
101
  }>;
103
- /** Public field to query the entities in the document.
104
- *
105
- * @deprecated Don't use this field, as it can cause race conditions on the nexus document.
106
- *
107
- * Instead, use
108
- * * for building a transaction: {@link TransactionBuilder.entities}
109
- * * for other purposes, being aware of caveats: {@link NexusDocument.queryEntitiesWithoutLock}
110
- *
111
- */
112
- readonly entities: EntityQuery<keyof EntityTypes>;
113
102
  /**
114
103
  * This flag is set to true if {@link takeTransactions} is called. Before that, no transactions
115
104
  * from the backend are processed, and no transactions are allowed to be created from the frontend.
@@ -139,7 +128,9 @@ export declare class NexusDocument {
139
128
  * Note that every transaction by default is undoable, unless the flag in {@link TransactionOptions} is set to false.
140
129
  * @returns: {@link TransactionBuilder}
141
130
  */
142
- createTransaction(opts?: TransactionOptions): Promise<TransactionBuilder>;
131
+ createTransaction(opts?: TransactionOptions,
132
+ /** @internal allows skipping of taking the transaction lock */
133
+ _takeTransactionLock?: boolean): Promise<TransactionBuilder>;
143
134
  /**
144
135
  * A helper method for small transactions.
145
136
  *
@@ -169,12 +160,22 @@ export declare class NexusDocument {
169
160
  takeTransactions(props?: {
170
161
  validator?: NexusValidator;
171
162
  gateway?: NexusGateway;
163
+ /** if a project template should be loaded on startup, pass a promise that resolves to the transaction */
164
+ templateTransaction?: Promise<Transaction>;
172
165
  }): Promise<void>;
173
166
  /** Apply a transaction that doesn't originate from this document. Yields to the browser
174
167
  * scheduler every few modifications applied to make sure we don't block the main thread
175
168
  * for too long for big transactions. Throws if the transaction lock isn't taken.
169
+ *
176
170
  */
177
- applyIncomingTransactions(ts: Transaction[]): Promise<void>;
171
+ applyIncomingTransactions(ts: ReadonlyTransaction[],
172
+ /** @internal */
173
+ opts?: {
174
+ /** This can be false if the transaction lock is already held already when calling from the outside.
175
+ * The method will throw if takeTransactionLock is false and the lock is not held.
176
+ */
177
+ _takeTransactionLock?: boolean;
178
+ }): Promise<void>;
178
179
  /** For debugging purposes */
179
180
  getStats(): {
180
181
  entities: number;
package/dist/document.js CHANGED
@@ -1,4 +1,4 @@
1
- import { g as e, s as t, a as c } from "./get-schema-location-details-BSMUliFD.js";
1
+ import { g as e, s as t, a as c } from "./get-schema-location-details-D2lXBgbu.js";
2
2
  import { T as h } from "./opt_pb-Dp9pF04Q.js";
3
3
  export {
4
4
  h as TargetType,
@@ -1,4 +1,4 @@
1
- import { t as o, a as d } from "./lang-KJQpoj7q.js";
1
+ import { t as o, a as d } from "./lang-BqPY1uAS.js";
2
2
  import { e as f } from "./types-Cztu157p.js";
3
3
  import { ScalarType as e } from "@bufbuild/protobuf";
4
4
  const g = {