teamplay 0.4.0 → 0.5.0-alpha.1

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.
Files changed (237) hide show
  1. package/babel-loader.cjs +1 -0
  2. package/babel.cjs +1 -0
  3. package/dist/connect/index.d.ts +1 -0
  4. package/dist/connect/index.js +9 -0
  5. package/dist/connect/lib/sharedb-crosstab-pubsub.d.cts +10 -0
  6. package/dist/connect/offline/index.d.ts +1 -0
  7. package/dist/connect/offline/index.js +126 -0
  8. package/dist/connect/offline/react-native.d.ts +10 -0
  9. package/dist/connect/offline/react-native.js +25 -0
  10. package/dist/connect/offline/web.d.ts +9 -0
  11. package/dist/connect/offline/web.js +12 -0
  12. package/dist/connect/sharedbConnection.d.cts +2 -0
  13. package/dist/connect/test.d.ts +1 -0
  14. package/dist/connect/test.js +12 -0
  15. package/dist/index.d.ts +66 -0
  16. package/dist/index.js +74 -0
  17. package/dist/orm/$.d.ts +9 -0
  18. package/dist/orm/$.js +34 -0
  19. package/dist/orm/Aggregation.d.ts +17 -0
  20. package/dist/orm/Aggregation.js +115 -0
  21. package/dist/orm/Cache.d.ts +9 -0
  22. package/dist/orm/Cache.js +32 -0
  23. package/dist/orm/Compat/SignalCompat.d.ts +3 -0
  24. package/dist/orm/Compat/SignalCompat.js +1542 -0
  25. package/dist/orm/Compat/eventsCompat.d.ts +3 -0
  26. package/dist/orm/Compat/eventsCompat.js +73 -0
  27. package/dist/orm/Compat/hooksCompat.d.ts +33 -0
  28. package/dist/orm/Compat/hooksCompat.js +360 -0
  29. package/dist/orm/Compat/modelEvents.d.ts +6 -0
  30. package/dist/orm/Compat/modelEvents.js +228 -0
  31. package/dist/orm/Compat/queryReadiness.d.ts +5 -0
  32. package/dist/orm/Compat/queryReadiness.js +185 -0
  33. package/dist/orm/Compat/refFallback.d.ts +13 -0
  34. package/dist/orm/Compat/refFallback.js +65 -0
  35. package/dist/orm/Compat/refRegistry.d.ts +6 -0
  36. package/dist/orm/Compat/refRegistry.js +54 -0
  37. package/dist/orm/Compat/silentContext.d.ts +5 -0
  38. package/dist/orm/Compat/silentContext.js +48 -0
  39. package/dist/orm/Compat/startStopCompat.d.ts +3 -0
  40. package/dist/orm/Compat/startStopCompat.js +217 -0
  41. package/dist/orm/Doc.d.ts +96 -0
  42. package/dist/orm/Doc.js +966 -0
  43. package/dist/orm/Query.d.ts +117 -0
  44. package/dist/orm/Query.js +1111 -0
  45. package/dist/orm/Reaction.d.ts +10 -0
  46. package/dist/orm/Reaction.js +41 -0
  47. package/dist/orm/Root.d.ts +22 -0
  48. package/dist/orm/Root.js +85 -0
  49. package/dist/orm/Signal.d.ts +12 -0
  50. package/dist/orm/Signal.js +7 -0
  51. package/dist/orm/SignalBase.d.ts +168 -0
  52. package/dist/orm/SignalBase.js +625 -0
  53. package/dist/orm/SubscriptionState.d.ts +17 -0
  54. package/dist/orm/SubscriptionState.js +123 -0
  55. package/dist/orm/Value.d.ts +9 -0
  56. package/dist/orm/Value.js +25 -0
  57. package/dist/orm/addModel.d.ts +6 -0
  58. package/dist/orm/addModel.js +39 -0
  59. package/dist/orm/associations.d.ts +18 -0
  60. package/dist/orm/associations.js +70 -0
  61. package/dist/orm/batchScheduler.d.ts +7 -0
  62. package/dist/orm/batchScheduler.js +62 -0
  63. package/dist/orm/compatEnv.d.ts +1 -0
  64. package/dist/orm/compatEnv.js +4 -0
  65. package/dist/orm/connection.d.ts +26 -0
  66. package/dist/orm/connection.js +38 -0
  67. package/dist/orm/dataTree.d.ts +34 -0
  68. package/dist/orm/dataTree.js +880 -0
  69. package/dist/orm/disposeRootContext.d.ts +4 -0
  70. package/dist/orm/disposeRootContext.js +59 -0
  71. package/dist/orm/getSignal.d.ts +16 -0
  72. package/dist/orm/getSignal.js +133 -0
  73. package/dist/orm/idFields.d.ts +14 -0
  74. package/dist/orm/idFields.js +95 -0
  75. package/dist/orm/index.d.ts +7 -0
  76. package/dist/orm/index.js +6 -0
  77. package/dist/orm/initModels.d.ts +5 -0
  78. package/dist/orm/initModels.js +74 -0
  79. package/dist/orm/missingDoc.d.ts +1 -0
  80. package/dist/orm/missingDoc.js +3 -0
  81. package/dist/orm/pluralize.d.ts +12 -0
  82. package/dist/orm/privateData.d.ts +22 -0
  83. package/dist/orm/privateData.js +170 -0
  84. package/dist/orm/rootContext.d.ts +78 -0
  85. package/dist/orm/rootContext.js +297 -0
  86. package/dist/orm/rootScope.d.ts +12 -0
  87. package/dist/orm/rootScope.js +46 -0
  88. package/dist/orm/signalArrayReaders.d.ts +22 -0
  89. package/dist/orm/signalArrayReaders.js +42 -0
  90. package/dist/orm/signalMetadata.d.ts +17 -0
  91. package/dist/orm/signalMetadata.js +56 -0
  92. package/dist/orm/signalMutationGuards.d.ts +4 -0
  93. package/dist/orm/signalMutationGuards.js +14 -0
  94. package/dist/orm/signalPathKind.d.ts +2 -0
  95. package/dist/orm/signalPathKind.js +10 -0
  96. package/dist/orm/signalPathRules.d.ts +6 -0
  97. package/dist/orm/signalPathRules.js +28 -0
  98. package/dist/orm/signalReads.d.ts +26 -0
  99. package/dist/orm/signalReads.js +64 -0
  100. package/dist/orm/signalRuntimeAccess.d.ts +16 -0
  101. package/dist/orm/signalRuntimeAccess.js +24 -0
  102. package/dist/orm/signalRuntimeDescriptor.d.ts +19 -0
  103. package/dist/orm/signalRuntimeDescriptor.js +97 -0
  104. package/dist/orm/signalStorageMutations.d.ts +18 -0
  105. package/dist/orm/signalStorageMutations.js +26 -0
  106. package/dist/orm/signalSymbols.d.ts +5 -0
  107. package/dist/orm/signalSymbols.js +5 -0
  108. package/dist/orm/signalValueMutations.d.ts +14 -0
  109. package/dist/orm/signalValueMutations.js +36 -0
  110. package/dist/orm/sub.d.ts +37 -0
  111. package/dist/orm/sub.js +187 -0
  112. package/dist/orm/subscriptionGcDelay.d.ts +4 -0
  113. package/dist/orm/subscriptionGcDelay.js +26 -0
  114. package/dist/orm/types/baseMethods.d.ts +43 -0
  115. package/dist/orm/types/baseMethods.js +1 -0
  116. package/dist/orm/types/jsonSchema.d.ts +75 -0
  117. package/dist/orm/types/jsonSchema.js +1 -0
  118. package/dist/orm/types/modelManifest.d.ts +37 -0
  119. package/dist/orm/types/modelManifest.js +1 -0
  120. package/dist/orm/types/path.d.ts +8 -0
  121. package/dist/orm/types/path.js +1 -0
  122. package/dist/orm/types/query.d.ts +29 -0
  123. package/dist/orm/types/query.js +1 -0
  124. package/dist/orm/types/signal.d.ts +132 -0
  125. package/dist/orm/types/signal.js +1 -0
  126. package/dist/react/compatComponentRegistry.d.ts +4 -0
  127. package/dist/react/compatComponentRegistry.js +19 -0
  128. package/dist/react/convertToObserver.d.ts +26 -0
  129. package/dist/react/convertToObserver.js +114 -0
  130. package/dist/react/executionContextTracker.d.ts +11 -0
  131. package/dist/react/executionContextTracker.js +28 -0
  132. package/dist/react/helpers.d.ts +34 -0
  133. package/dist/react/helpers.js +134 -0
  134. package/dist/react/observer.d.ts +22 -0
  135. package/dist/react/observer.js +8 -0
  136. package/dist/react/promiseBatcher.d.ts +13 -0
  137. package/dist/react/promiseBatcher.js +118 -0
  138. package/dist/react/renderAttemptDestroyer.d.ts +19 -0
  139. package/dist/react/renderAttemptDestroyer.js +46 -0
  140. package/dist/react/trapRender.d.ts +6 -0
  141. package/dist/react/trapRender.js +48 -0
  142. package/dist/react/universal$.d.ts +1 -0
  143. package/dist/react/universal$.js +18 -0
  144. package/dist/react/universalSub.d.ts +1 -0
  145. package/dist/react/universalSub.js +22 -0
  146. package/dist/react/useApi.d.ts +13 -0
  147. package/dist/react/useApi.js +67 -0
  148. package/dist/react/useSub.d.ts +102 -0
  149. package/dist/react/useSub.js +189 -0
  150. package/dist/react/useSuspendMemo.d.ts +3 -0
  151. package/dist/react/useSuspendMemo.js +102 -0
  152. package/dist/react/wrapIntoSuspense.d.ts +9 -0
  153. package/dist/react/wrapIntoSuspense.js +102 -0
  154. package/dist/server.d.ts +11 -0
  155. package/dist/server.js +28 -0
  156. package/dist/utils/MockFinalizationRegistry.d.ts +37 -0
  157. package/dist/utils/MockFinalizationRegistry.js +85 -0
  158. package/dist/utils/MockWeakRef.d.ts +12 -0
  159. package/dist/utils/MockWeakRef.js +23 -0
  160. package/dist/utils/isServer.d.ts +3 -0
  161. package/dist/utils/isServer.js +18 -0
  162. package/dist/utils/setDiffDeep.d.ts +1 -0
  163. package/dist/utils/setDiffDeep.js +61 -0
  164. package/dist/utils/useIsomorphicLayoutEffect.d.ts +3 -0
  165. package/dist/utils/useIsomorphicLayoutEffect.js +3 -0
  166. package/file-based-models.js +3 -0
  167. package/file-based-models.node.js +6 -0
  168. package/package.json +77 -32
  169. package/teamplay.models.auto-init.virtual.js +1 -0
  170. package/teamplay.models.virtual.js +1 -0
  171. package/connect/index.js +0 -9
  172. package/connect/offline/index.js +0 -124
  173. package/connect/offline/react-native.js +0 -28
  174. package/connect/offline/web.js +0 -15
  175. package/connect/test.js +0 -12
  176. package/index.d.ts +0 -106
  177. package/index.js +0 -125
  178. package/orm/$.js +0 -38
  179. package/orm/Aggregation.js +0 -117
  180. package/orm/Cache.js +0 -46
  181. package/orm/Compat/README.md +0 -1064
  182. package/orm/Compat/SignalCompat.js +0 -1479
  183. package/orm/Compat/eventsCompat.js +0 -79
  184. package/orm/Compat/hooksCompat.js +0 -374
  185. package/orm/Compat/modelEvents.js +0 -225
  186. package/orm/Compat/queryReadiness.js +0 -191
  187. package/orm/Compat/refFallback.js +0 -62
  188. package/orm/Compat/refRegistry.js +0 -61
  189. package/orm/Compat/silentContext.js +0 -51
  190. package/orm/Compat/startStopCompat.js +0 -207
  191. package/orm/Doc.js +0 -969
  192. package/orm/Query.js +0 -1127
  193. package/orm/Reaction.js +0 -48
  194. package/orm/Root.js +0 -88
  195. package/orm/Signal.js +0 -22
  196. package/orm/SignalBase.js +0 -696
  197. package/orm/SubscriptionState.js +0 -138
  198. package/orm/Value.js +0 -30
  199. package/orm/addModel.js +0 -31
  200. package/orm/associations.js +0 -97
  201. package/orm/batchScheduler.js +0 -62
  202. package/orm/compatEnv.js +0 -4
  203. package/orm/connection.js +0 -46
  204. package/orm/dataTree.js +0 -869
  205. package/orm/disposeRootContext.js +0 -68
  206. package/orm/getSignal.js +0 -130
  207. package/orm/idFields.js +0 -88
  208. package/orm/index.d.ts +0 -6
  209. package/orm/index.js +0 -5
  210. package/orm/missingDoc.js +0 -3
  211. package/orm/privateData.js +0 -181
  212. package/orm/rootContext.js +0 -313
  213. package/orm/rootScope.js +0 -51
  214. package/orm/sub.js +0 -151
  215. package/orm/subscriptionGcDelay.js +0 -32
  216. package/react/compatComponentRegistry.js +0 -20
  217. package/react/convertToObserver.js +0 -117
  218. package/react/executionContextTracker.js +0 -32
  219. package/react/helpers.js +0 -141
  220. package/react/observer.js +0 -9
  221. package/react/promiseBatcher.js +0 -115
  222. package/react/renderAttemptDestroyer.js +0 -47
  223. package/react/trapRender.js +0 -50
  224. package/react/universal$.js +0 -18
  225. package/react/universalSub.js +0 -21
  226. package/react/useApi.js +0 -63
  227. package/react/useSub.js +0 -169
  228. package/react/useSuspendMemo.js +0 -96
  229. package/react/wrapIntoSuspense.js +0 -119
  230. package/server.js +0 -31
  231. package/utils/MockFinalizationRegistry.js +0 -94
  232. package/utils/MockWeakRef.js +0 -25
  233. package/utils/isServer.js +0 -17
  234. package/utils/setDiffDeep.js +0 -58
  235. package/utils/useIsomorphicLayoutEffect.js +0 -4
  236. /package/{connect → dist/connect}/lib/sharedb-crosstab-pubsub.cjs +0 -0
  237. /package/{connect → dist/connect}/sharedbConnection.cjs +0 -0
@@ -0,0 +1,10 @@
1
+ export function setDeletionDelay(delayInMs: any): void;
2
+ export let DELETION_DELAY: number;
3
+ export const reactionSubscriptions: ReactionSubscriptions;
4
+ declare class ReactionSubscriptions {
5
+ initialized: Map<any, any>;
6
+ fr: import("../utils/MockFinalizationRegistry.js").FinalizationRegistryLike<unknown>;
7
+ init($value: any, fn: any): void;
8
+ destroy(rootId: any, id: any, reaction: any): void;
9
+ }
10
+ export {};
@@ -0,0 +1,41 @@
1
+ import { observe, unobserve } from '@nx-js/observer-util';
2
+ import { SEGMENTS } from "./Signal.js";
3
+ import { LOCAL } from './Value.js';
4
+ import FinalizationRegistry from "../utils/MockFinalizationRegistry.js";
5
+ import { scheduleReaction } from './batchScheduler.js';
6
+ import { getRoot, ROOT_ID } from "./Root.js";
7
+ import { delPrivateData, setPrivateData } from './privateData.js';
8
+ // this is `let` to be able to directly change it if needed in tests or in the app
9
+ export let DELETION_DELAY = 0;
10
+ class ReactionSubscriptions {
11
+ constructor() {
12
+ this.initialized = new Map();
13
+ this.fr = new FinalizationRegistry(([rootId, id, reaction]) => this.destroy(rootId, id, reaction));
14
+ }
15
+ init($value, fn) {
16
+ const id = $value[SEGMENTS][1];
17
+ if (this.initialized.has(id))
18
+ return;
19
+ this.initialized.set(id, true);
20
+ const rootId = getRoot($value)?.[ROOT_ID] || $value?.[ROOT_ID];
21
+ const reactionScheduler = reaction => scheduleReaction(() => runReaction(rootId, id, reaction));
22
+ const reaction = observe(fn, { lazy: true, scheduler: reactionScheduler });
23
+ this.fr.register($value, [rootId, id, reaction]);
24
+ runReaction(rootId, id, reaction);
25
+ }
26
+ destroy(rootId, id, reaction) {
27
+ this.initialized.delete(id);
28
+ unobserve(reaction);
29
+ // don't delete data right away to prevent dependent reactions which are also going to be GC'ed
30
+ // from triggering unnecessarily
31
+ setTimeout(() => delPrivateData(rootId, [LOCAL, id]), DELETION_DELAY);
32
+ }
33
+ }
34
+ export const reactionSubscriptions = new ReactionSubscriptions();
35
+ function runReaction(rootId, id, reaction) {
36
+ const newValue = reaction();
37
+ setPrivateData(rootId, [LOCAL, id], newValue);
38
+ }
39
+ export function setDeletionDelay(delayInMs) {
40
+ DELETION_DELAY = delayInMs;
41
+ }
@@ -0,0 +1,22 @@
1
+ import type { SignalBaseInstance } from './Signal.js';
2
+ export declare const ROOT_FUNCTION: unique symbol;
3
+ export declare const ROOT: unique symbol;
4
+ export declare const ROOT_ID: unique symbol;
5
+ export declare const GLOBAL_ROOT_ID = "__global__";
6
+ export interface RootSignalOptions extends Record<string, unknown> {
7
+ rootFunction?: unknown;
8
+ fetchOnly?: boolean;
9
+ rootId?: string;
10
+ }
11
+ export type RootTransportIntent = 'fetch' | 'subscribe';
12
+ export type RootSignalRuntime = SignalBaseInstance & {
13
+ [ROOT_FUNCTION]?: unknown;
14
+ [ROOT]?: RootSignalRuntime;
15
+ [ROOT_ID]?: string;
16
+ };
17
+ export declare function getRootSignal({ rootFunction, fetchOnly, rootId, ...options }?: RootSignalOptions): RootSignalRuntime;
18
+ export declare function getRoot(signal: RootSignalRuntime | undefined): RootSignalRuntime | undefined;
19
+ export declare function getRootFetchOnly(rootOrRootId: RootSignalRuntime | string | undefined): boolean;
20
+ export declare function getRootTransportMode(rootOrRootId: RootSignalRuntime | string | undefined, intent?: RootTransportIntent): RootTransportIntent;
21
+ export declare function registerRootFinalizer($root: RootSignalRuntime | undefined): void;
22
+ export declare function unregisterRootFinalizer($root: RootSignalRuntime | undefined): void;
@@ -0,0 +1,85 @@
1
+ import getSignal from "./getSignal.js";
2
+ import disposeRootContext from "./disposeRootContext.js";
3
+ import { getRootContext, reviveRootContext } from "./rootContext.js";
4
+ import { isGlobalRootId, normalizeRootId } from "./rootScope.js";
5
+ import ExportedFinalizationRegistry from "../utils/MockFinalizationRegistry.js";
6
+ export const ROOT_FUNCTION = Symbol('root function');
7
+ // TODO: in future make a connection spawnable instead of a singleton
8
+ // export const CONNECTION = Symbol('sharedb connection, used by sub() function')
9
+ export const ROOT = Symbol('root signal');
10
+ export const ROOT_ID = Symbol('root signal id. Used for caching');
11
+ export const GLOBAL_ROOT_ID = '__global__';
12
+ const getRuntimeSignal = getSignal;
13
+ const RootFinalizationRegistry = ExportedFinalizationRegistry;
14
+ const ROOT_FINALIZATION_REGISTRY = new RootFinalizationRegistry((rootId) => {
15
+ disposeRootContext(rootId).catch(err => {
16
+ console.error(err);
17
+ });
18
+ });
19
+ const REGISTERED_ROOT_SIGNALS = new WeakSet();
20
+ // TODO: create a separate local root for private collections
21
+ export function getRootSignal({ rootFunction, fetchOnly,
22
+ // connection,
23
+ rootId = '_' + createRandomString(8), ...options } = {}) {
24
+ reviveRootContext(rootId);
25
+ getRootContext(rootId, true, { fetchOnly });
26
+ const $root = getRuntimeSignal(undefined, [], {
27
+ rootId,
28
+ ...options
29
+ });
30
+ $root[ROOT_FUNCTION] ??= rootFunction;
31
+ // $root[CONNECTION] ??= connection
32
+ $root[ROOT_ID] ??= rootId;
33
+ registerRootFinalizer($root);
34
+ return $root;
35
+ }
36
+ export function getRoot(signal) {
37
+ if (!signal)
38
+ return undefined;
39
+ if (signal[ROOT])
40
+ return signal[ROOT];
41
+ else if (signal[ROOT_ID])
42
+ return signal;
43
+ else
44
+ return undefined;
45
+ }
46
+ export function getRootFetchOnly(rootOrRootId) {
47
+ const $root = typeof rootOrRootId === 'string'
48
+ ? undefined
49
+ : (getRoot(rootOrRootId) || rootOrRootId);
50
+ const rootId = typeof rootOrRootId === 'string'
51
+ ? rootOrRootId
52
+ : $root?.[ROOT_ID];
53
+ const context = getRootContext(rootId, false);
54
+ return context?.getFetchOnly() ?? false;
55
+ }
56
+ export function getRootTransportMode(rootOrRootId, intent = 'subscribe') {
57
+ if (intent === 'fetch')
58
+ return 'fetch';
59
+ return getRootFetchOnly(rootOrRootId) ? 'fetch' : 'subscribe';
60
+ }
61
+ export function registerRootFinalizer($root) {
62
+ if (!$root?.[ROOT_ID])
63
+ return;
64
+ if (REGISTERED_ROOT_SIGNALS.has($root))
65
+ return;
66
+ const rootId = normalizeRootId($root[ROOT_ID]);
67
+ if (isGlobalRootId(rootId))
68
+ return;
69
+ ROOT_FINALIZATION_REGISTRY.register($root, rootId, $root);
70
+ REGISTERED_ROOT_SIGNALS.add($root);
71
+ }
72
+ export function unregisterRootFinalizer($root) {
73
+ if (!$root)
74
+ return;
75
+ ROOT_FINALIZATION_REGISTRY.unregister($root);
76
+ REGISTERED_ROOT_SIGNALS.delete($root);
77
+ }
78
+ function createRandomString(length) {
79
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
80
+ let result = '';
81
+ for (let i = 0; i < length; i++) {
82
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
83
+ }
84
+ return result;
85
+ }
@@ -0,0 +1,12 @@
1
+ import SignalCompat from './Compat/SignalCompat.js';
2
+ import type { SignalConstructor } from './types/signal.js';
3
+ export type { FromJsonSchema, InferZodSchema, JsonSchema, JsonSchemaObject, ZodLikeSchema } from './types/jsonSchema.js';
4
+ export type { QueryParams } from './types/query.js';
5
+ export type { SignalArrayMutatorMethods, SignalArrayReaderMethods, SignalCollectionMethods, SignalMetadataMethods, SignalStringMutatorMethods, SignalValueMethods } from './types/baseMethods.js';
6
+ export type { AppendPath, JoinPath, PathSegment, SignalPath, WildcardPathSegment, WildcardSignalPath } from './types/path.js';
7
+ export type { AggregationSignal, AnySignal, ArraySignal, CollectionAggregationSignal, CollectionDocument, CollectionDocumentModel, CollectionQuerySignal, CollectionSignal, CollectionSignalFromSpec, CollectionSpec, DocumentSignal, JsonSchemaSpec, MaybePromise, MaybePromiseSubResult, PublicSignal, LocalSignalFactory, RegisteredAggregationInput, RuntimeSignalConstructor, RuntimeSignalInstance, QuerySignal, RootCollections, RootSignal, SignalBaseInstance, SignalChild, SignalChildren, SignalClass, SignalConstructor, SignalForKind, SignalKind, SignalInstance, SignalModelConstructor, SubResult, TypedAggregationInput, TypedAggregationSignal, TypedSignal, ZodSchemaSpec } from './types/signal.js';
8
+ export type { CollectionsFromManifest, ModelEntry, ModelManifest, PathModelsFromManifest } from './types/modelManifest.js';
9
+ export { Signal, SEGMENTS, ARRAY_METHOD, GET, GETTERS, DEFAULT_GETTERS, regularBindings, extremelyLateBindings, isPublicCollectionSignal, isPublicDocumentSignal, isPublicCollection, isPrivateCollection } from './SignalBase.js';
10
+ export { SignalCompat };
11
+ declare const DefaultSignal: SignalConstructor;
12
+ export default DefaultSignal;
@@ -0,0 +1,7 @@
1
+ import { Signal } from "./SignalBase.js";
2
+ import SignalCompat from './Compat/SignalCompat.js';
3
+ import { isCompatEnv } from './compatEnv.js';
4
+ export { Signal, SEGMENTS, ARRAY_METHOD, GET, GETTERS, DEFAULT_GETTERS, regularBindings, extremelyLateBindings, isPublicCollectionSignal, isPublicDocumentSignal, isPublicCollection, isPrivateCollection } from "./SignalBase.js";
5
+ export { SignalCompat };
6
+ const DefaultSignal = (isCompatEnv() ? SignalCompat : Signal);
7
+ export default DefaultSignal;
@@ -0,0 +1,168 @@
1
+ import { ARRAY_METHOD, DEFAULT_GETTERS, GET, GETTERS, SEGMENTS } from './signalSymbols.js';
2
+ export { SEGMENTS, ARRAY_METHOD, GET, GETTERS, DEFAULT_GETTERS };
3
+ export declare class Signal<TValue = unknown> extends Function {
4
+ /** Fields that are treated as document ids and mirror the document id segment. */
5
+ static ID_FIELDS: readonly ["_id"];
6
+ /** Method names that keep method binding priority over child signal dot access. */
7
+ static [GETTERS]: string[];
8
+ /** Association metadata registered for this model class. */
9
+ static associations: never[];
10
+ /** Path segments from the root signal to this signal. */
11
+ readonly [SEGMENTS]: Array<string | number>;
12
+ /**
13
+ * Add association metadata to this model class.
14
+ * @param association Association metadata object to register on the model class.
15
+ */
16
+ static addAssociation(association: object): void;
17
+ /**
18
+ * Create a signal for the given root-relative path segments.
19
+ * @param segments Root-relative path segments this signal points to.
20
+ */
21
+ constructor(segments: Array<string | number>);
22
+ /** Return the dot-separated path of this signal from the root data tree. */
23
+ path(): string;
24
+ /** Return the last segment of this signal path, or an empty string for the root signal. */
25
+ leaf(): string;
26
+ /**
27
+ * Return the parent signal `levels` above this signal.
28
+ * @param levels Number of parent levels to walk upward. Defaults to `1`.
29
+ */
30
+ parent(levels?: number): Signal;
31
+ /** Generate a new unique id suitable for a new document. */
32
+ id(): string;
33
+ /** Run multiple signal reads and writes in a single reactive batch. */
34
+ batch(): undefined;
35
+ /**
36
+ * Run multiple signal reads and writes in a single reactive batch.
37
+ * @param fn Function to execute inside the batch.
38
+ */
39
+ batch<TResult>(fn: () => TResult): TResult;
40
+ /**
41
+ * Internal read hook used by `.get()` and `.peek()`.
42
+ * @param method Storage read function to use for the current signal path.
43
+ */
44
+ [GET](method: (segments: Array<string | number>) => TValue): TValue;
45
+ /** Read the current value and track it for reactive rendering. */
46
+ get(): TValue;
47
+ /** Return document ids for a query or aggregation signal. */
48
+ getIds(): Array<string | number>;
49
+ /** Read the current value without tracking it for reactive rendering. */
50
+ peek(): TValue;
51
+ /** Return the document id represented by this document signal. */
52
+ getId(): string | number;
53
+ /** Return the public collection name this signal belongs to. */
54
+ getCollection(): string;
55
+ /** Return association metadata registered on this signal's model class. */
56
+ getAssociations(): readonly unknown[];
57
+ /** Iterate child document signals for query signals, or item signals for array signals. */
58
+ [Symbol.iterator](): IterableIterator<Signal>;
59
+ /** Internal helper used to run array-style methods on query and array signals. */
60
+ [ARRAY_METHOD](method: string, nonArrayReturnValue: unknown, ...args: unknown[]): unknown;
61
+ /**
62
+ * Run `Array.prototype.map()` over query document signals or array item signals.
63
+ * @param callback Function called for each child signal.
64
+ * @param thisArg Optional `this` value for the callback.
65
+ */
66
+ map<TResult>(callback: (value: Signal, index: number, array: Signal[]) => TResult, thisArg?: any): TResult[];
67
+ /**
68
+ * Run `Array.prototype.reduce()` over query document signals or array item signals.
69
+ * @param callback Function called for each child signal and accumulated value.
70
+ */
71
+ reduce(callback: (previousValue: Signal, currentValue: Signal, currentIndex: number, array: Signal[]) => Signal): Signal;
72
+ /**
73
+ * Run `Array.prototype.reduce()` over query document signals or array item signals.
74
+ * @param callback Function called for each child signal and accumulated value.
75
+ * @param initialValue Initial accumulator value.
76
+ */
77
+ reduce(callback: (previousValue: Signal, currentValue: Signal, currentIndex: number, array: Signal[]) => Signal, initialValue: Signal): Signal;
78
+ /**
79
+ * Run `Array.prototype.reduce()` over query document signals or array item signals.
80
+ * @param callback Function called for each child signal and accumulated value.
81
+ * @param initialValue Initial accumulator value.
82
+ */
83
+ reduce<TResult>(callback: (previousValue: TResult, currentValue: Signal, currentIndex: number, array: Signal[]) => TResult, initialValue: TResult): TResult;
84
+ /**
85
+ * Find the first query document signal or array item signal matching a predicate.
86
+ * @param predicate Function called for each child signal.
87
+ * @param thisArg Optional `this` value for the predicate.
88
+ */
89
+ find(predicate: (value: Signal, index: number, obj: Signal[]) => unknown, thisArg?: any): Signal | undefined;
90
+ /**
91
+ * Replace this signal's value. Database writes are async and sync through ShareDB.
92
+ * @param value New value to store at this signal path.
93
+ */
94
+ set(value: TValue): Promise<void>;
95
+ /**
96
+ * Set multiple object fields at once. Fields set to `null` or `undefined` are deleted.
97
+ * @param value Object containing fields to set or delete.
98
+ */
99
+ assign(value: NonNullable<TValue> extends object ? Partial<NonNullable<TValue>> : never): Promise<void>;
100
+ /**
101
+ * Append one item to an array signal.
102
+ * @param value Item to append.
103
+ */
104
+ push(value: NonNullable<TValue> extends ReadonlyArray<infer Item> ? Item : unknown): Promise<unknown>;
105
+ /** Remove and return the last item from an array signal. */
106
+ pop(): Promise<NonNullable<TValue> extends ReadonlyArray<infer Item> ? Item | undefined : unknown>;
107
+ /**
108
+ * Insert one item at the beginning of an array signal.
109
+ * @param value Item to insert.
110
+ */
111
+ unshift(value: NonNullable<TValue> extends ReadonlyArray<infer Item> ? Item : unknown): Promise<unknown>;
112
+ /** Remove and return the first item from an array signal. */
113
+ shift(): Promise<NonNullable<TValue> extends ReadonlyArray<infer Item> ? Item | undefined : unknown>;
114
+ /**
115
+ * Insert one or more items into an array signal at the given index.
116
+ * @param index Array index where the new item or items should be inserted.
117
+ * @param values Item or items to insert.
118
+ */
119
+ insert(index: number, values: NonNullable<TValue> extends ReadonlyArray<infer Item> ? Item | Item[] : unknown): Promise<unknown>;
120
+ /**
121
+ * Remove `howMany` items from an array signal starting at `index`.
122
+ * @param index Array index to start removing from.
123
+ * @param howMany Number of items to remove. Defaults to `1`.
124
+ */
125
+ remove(index: number, howMany?: number): Promise<unknown>;
126
+ /**
127
+ * Move `howMany` array items from one index to another.
128
+ * @param from Source array index.
129
+ * @param to Destination array index.
130
+ * @param howMany Number of items to move. Defaults to `1`.
131
+ */
132
+ move(from: number, to: number, howMany?: number): Promise<unknown>;
133
+ /**
134
+ * Insert text into a string signal at the given character index.
135
+ * @param index Character index where text should be inserted.
136
+ * @param text Text to insert.
137
+ */
138
+ stringInsert(index: number, text: string): Promise<unknown>;
139
+ /**
140
+ * Remove `howMany` characters from a string signal starting at `index`.
141
+ * @param index Character index to start removing from.
142
+ * @param howMany Number of characters to remove. Defaults to `1`.
143
+ */
144
+ stringRemove(index: number, howMany?: number): Promise<unknown>;
145
+ /**
146
+ * Add `value` to a number signal and return the new number. Defaults to `1`.
147
+ * @param value Amount to add to the current number. Defaults to `1`.
148
+ */
149
+ increment(value?: number): Promise<number>;
150
+ /**
151
+ * Add a document to a collection signal and return the new document id.
152
+ * @param value Document value to create. May include an explicit `id` field.
153
+ */
154
+ add(value: unknown): Promise<string>;
155
+ /** Delete this document or field. Whole collections and the root signal cannot be deleted. */
156
+ del(): Promise<void>;
157
+ }
158
+ export declare const regularBindings: {
159
+ apply(signal: any, thisArg: any, argumentsList: any): any;
160
+ get(signal: any, key: any, receiver: any): any;
161
+ };
162
+ export declare const extremelyLateBindings: {
163
+ apply(signal: any, thisArg: any, argumentsList: any): any;
164
+ get(signal: any, key: any, receiver: any): any;
165
+ };
166
+ export declare function isPublicCollectionSignal($signal: any): boolean;
167
+ export declare function isPublicDocumentSignal($signal: any): boolean;
168
+ export { isPrivateCollection, isPublicCollection } from './signalPathKind.js';