teamplay 0.5.0-alpha.26 → 0.5.0-alpha.27

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.
@@ -1,7 +1,7 @@
1
1
  import { raw, observe, unobserve } from '@nx-js/observer-util';
2
2
  import arrayDiff from 'arraydiff';
3
3
  import { Signal, GETTERS, DEFAULT_GETTERS, SEGMENTS, isPublicCollection, isPublicCollectionSignal, isPublicDocumentSignal } from "../SignalBase.js";
4
- import { getRoot, ROOT, ROOT_ID, getRootSignal, GLOBAL_ROOT_ID, unregisterRootFinalizer } from "../Root.js";
4
+ import { getRoot, ROOT, ROOT_ID, getRootSignal, GLOBAL_ROOT_ID } from "../Root.js";
5
5
  import { docSubscriptions } from '../Doc.js';
6
6
  import { IS_QUERY, getQuerySignal, querySubscriptions } from '../Query.js';
7
7
  import { AGGREGATIONS, IS_AGGREGATION, aggregationSubscriptions, getAggregationSignal } from '../Aggregation.js';
@@ -16,7 +16,6 @@ import { runInBatch } from '../batchScheduler.js';
16
16
  import { runInSilentContext, runInModelEventsSilentContext, isSilentContextActive } from './silentContext.js';
17
17
  import universal$ from "../../react/universal$.js";
18
18
  import { getRootContext } from "../rootContext.js";
19
- import disposeRootContext from "../disposeRootContext.js";
20
19
  import { arrayInsertPrivateData, arrayMovePrivateData, arrayPopPrivateData, arrayPushPrivateData, arrayRemovePrivateData, arrayShiftPrivateData, arrayUnshiftPrivateData, delPrivateData, setReplacePrivateData, stringInsertPrivateData, stringRemovePrivateData } from '../privateData.js';
21
20
  class SignalCompat extends Signal {
22
21
  static ID_FIELDS = ['_id', 'id'];
@@ -92,24 +91,6 @@ class SignalCompat extends Signal {
92
91
  return this.extra.get();
93
92
  return undefined;
94
93
  }
95
- close(callback) {
96
- if (arguments.length > 1)
97
- throw Error('Signal.close() expects zero or one argument');
98
- if (callback != null && typeof callback !== 'function') {
99
- throw Error('Signal.close() expects callback to be a function');
100
- }
101
- const $root = getRoot(this) || this;
102
- const rootId = $root?.[ROOT_ID];
103
- unregisterRootFinalizer($root);
104
- disposeRootContext(rootId)
105
- .then(() => callback?.())
106
- .catch(err => {
107
- if (callback)
108
- callback(err);
109
- else
110
- console.error(err);
111
- });
112
- }
113
94
  silent(value) {
114
95
  if (arguments.length > 1)
115
96
  throw Error('Signal.silent() expects zero or one argument');
@@ -14,8 +14,12 @@ export type RootSignalRuntime = SignalBaseInstance & {
14
14
  [ROOT]?: RootSignalRuntime;
15
15
  [ROOT_ID]?: string;
16
16
  };
17
+ export type RootCloseCallback = (err?: unknown) => void;
17
18
  export declare function getRootSignal({ rootFunction, fetchOnly, rootId, ...options }?: RootSignalOptions): RootSignalRuntime;
18
19
  export declare function getRoot(signal: RootSignalRuntime | undefined): RootSignalRuntime | undefined;
20
+ export declare function closeRootSignalAsync(signal: RootSignalRuntime | undefined): Promise<void>;
21
+ export declare function closeRootSignal(signal: RootSignalRuntime | undefined): Promise<void>;
22
+ export declare function closeRootSignal(signal: RootSignalRuntime | undefined, callback?: RootCloseCallback): void;
19
23
  export declare function getRootFetchOnly(rootOrRootId: RootSignalRuntime | string | undefined): boolean;
20
24
  export declare function getRootTransportMode(rootOrRootId: RootSignalRuntime | string | undefined, intent?: RootTransportIntent): RootTransportIntent;
21
25
  export declare function registerRootFinalizer($root: RootSignalRuntime | undefined): void;
package/dist/orm/Root.js CHANGED
@@ -43,6 +43,22 @@ export function getRoot(signal) {
43
43
  else
44
44
  return undefined;
45
45
  }
46
+ export function closeRootSignalAsync(signal) {
47
+ const $root = getRoot(signal) || signal;
48
+ const rootId = $root?.[ROOT_ID];
49
+ unregisterRootFinalizer($root);
50
+ return disposeRootContext(rootId);
51
+ }
52
+ export function closeRootSignal(signal, callback) {
53
+ const promise = closeRootSignalAsync(signal);
54
+ if (!callback)
55
+ return promise;
56
+ promise
57
+ .then(() => callback?.())
58
+ .catch(err => {
59
+ callback(err);
60
+ });
61
+ }
46
62
  export function getRootFetchOnly(rootOrRootId) {
47
63
  const $root = typeof rootOrRootId === 'string'
48
64
  ? undefined
@@ -45,6 +45,8 @@ export declare class Signal<TValue = unknown> extends Function {
45
45
  * @param fn Function to execute inside the batch.
46
46
  */
47
47
  batch<TResult>(fn: () => TResult): TResult;
48
+ close(): Promise<void>;
49
+ close(callback: (err?: unknown) => void): void;
48
50
  /**
49
51
  * Internal read hook used by `.get()` and `.peek()`.
50
52
  * @param method Storage read function to use for the current signal path.
@@ -20,7 +20,7 @@ import getSignal, { rawSignal } from "./getSignal.js";
20
20
  import { docSubscriptions } from './Doc.js';
21
21
  import { IS_QUERY, HASH, QUERIES } from './Query.js';
22
22
  import { AGGREGATIONS, IS_AGGREGATION, getAggregationCollectionName, getAggregationDocId } from './Aggregation.js';
23
- import { ROOT_FUNCTION, ROOT_ID, getRoot } from "./Root.js";
23
+ import { ROOT_FUNCTION, ROOT_ID, closeRootSignal, getRoot } from "./Root.js";
24
24
  import { DEFAULT_ID_FIELDS, getIdFieldsForSegments, isIdFieldPath, isPlainObject, isPublicDocPath, normalizeIdFields, prepareAddPayload, resolveAddDocId } from "./idFields.js";
25
25
  import { isCompatEnv } from './compatEnv.js';
26
26
  import { resolveRefSegmentsSafe, resolveRefSignalSafe } from './Compat/refFallback.js';
@@ -181,6 +181,14 @@ export class Signal extends Function {
181
181
  throw Error('Signal.batch() expects a function argument');
182
182
  return runInBatch(fn);
183
183
  }
184
+ close(callback) {
185
+ if (arguments.length > 1)
186
+ throw Error('Signal.close() expects zero or one argument');
187
+ if (callback != null && typeof callback !== 'function') {
188
+ throw Error('Signal.close() expects callback to be a function');
189
+ }
190
+ return callback ? closeRootSignal(this, callback) : closeRootSignal(this);
191
+ }
184
192
  /**
185
193
  * Internal read hook used by `.get()` and `.peek()`.
186
194
  * @param method Storage read function to use for the current signal path.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teamplay",
3
- "version": "0.5.0-alpha.26",
3
+ "version": "0.5.0-alpha.27",
4
4
  "description": "Full-stack signals ORM with multiplayer",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -134,5 +134,5 @@
134
134
  ]
135
135
  },
136
136
  "license": "MIT",
137
- "gitHead": "a432e1c1dc272cfe2b87e3820557db4721a0f38b"
137
+ "gitHead": "cbdbd79ede32eab577708675ab7a50c205bed50b"
138
138
  }