teamplay 0.5.0-alpha.27 → 0.5.0-alpha.29

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.
@@ -3,8 +3,8 @@ import arrayDiff from 'arraydiff';
3
3
  import { Signal, GETTERS, DEFAULT_GETTERS, SEGMENTS, isPublicCollection, isPublicCollectionSignal, isPublicDocumentSignal } from "../SignalBase.js";
4
4
  import { getRoot, ROOT, ROOT_ID, getRootSignal, GLOBAL_ROOT_ID } from "../Root.js";
5
5
  import { docSubscriptions } from '../Doc.js';
6
- import { IS_QUERY, getQuerySignal, querySubscriptions } from '../Query.js';
7
- import { AGGREGATIONS, IS_AGGREGATION, aggregationSubscriptions, getAggregationSignal } from '../Aggregation.js';
6
+ import { IS_QUERY, querySubscriptions } from '../Query.js';
7
+ import { AGGREGATIONS, IS_AGGREGATION, aggregationSubscriptions } from '../Aggregation.js';
8
8
  import { getIdFieldsForSegments, isIdFieldPath, isPublicDocPath, normalizeIdFields, isPlainObject } from "../idFields.js";
9
9
  import { incrementPublic as _incrementPublic, arrayPushPublic as _arrayPushPublic, arrayUnshiftPublic as _arrayUnshiftPublic, arrayInsertPublic as _arrayInsertPublic, arrayPopPublic as _arrayPopPublic, arrayShiftPublic as _arrayShiftPublic, arrayRemovePublic as _arrayRemovePublic, arrayMovePublic as _arrayMovePublic, setPublicDocReplace as _setPublicDocReplace, stringInsertPublic as _stringInsertPublic, stringRemovePublic as _stringRemovePublic } from '../dataTree.js';
10
10
  import { on as onCustomEvent, removeListener as removeCustomEventListener } from './eventsCompat.js';
@@ -49,38 +49,15 @@ class SignalCompat extends Signal {
49
49
  throw Error('Signal.getDeepCopy() does not accept any arguments');
50
50
  return deepCopy(this.get());
51
51
  }
52
- query(collection, params, options) {
53
- if (arguments.length < 1 || arguments.length > 3)
54
- throw Error('Signal.query() expects one to three arguments');
55
- if (typeof collection !== 'string')
56
- throw Error('Signal.query() expects collection to be a string');
57
- const normalized = normalizeQueryParams(collection, params);
58
- const root = getRoot(this) || (this[ROOT_ID] ? this : undefined);
59
- const scopedOptions = withQueryScopeOptions(options, root);
60
- if (isAggregationParams(normalized)) {
61
- return getAggregationSignal(collection, normalized, scopedOptions);
62
- }
63
- return getQuerySignal(collection, normalized, scopedOptions);
64
- }
65
- subscribe(...items) {
66
- if (items.length > 0)
67
- return subscribeMany(items, 'subscribe');
68
- return subscribeSelf(this);
69
- }
70
- unsubscribe(...items) {
71
- if (items.length > 0)
72
- return subscribeMany(items, 'unsubscribe');
73
- return unsubscribeSelf(this);
74
- }
75
52
  fetch(...items) {
76
53
  if (items.length > 0)
77
- return subscribeMany(items, 'subscribe', 'fetch');
78
- return subscribeSelf(this, 'fetch');
54
+ return subscribeMany(items, 'subscribe', 'fetch', 'fetch');
55
+ return subscribeSelf(this, 'fetch', 'fetch');
79
56
  }
80
57
  unfetch(...items) {
81
58
  if (items.length > 0)
82
- return subscribeMany(items, 'unsubscribe', 'fetch');
83
- return unsubscribeSelf(this, 'fetch');
59
+ return subscribeMany(items, 'unsubscribe', 'fetch', 'unfetch');
60
+ return unsubscribeSelf(this, 'fetch', 'unfetch');
84
61
  }
85
62
  getExtra() {
86
63
  if (arguments.length > 0)
@@ -1049,53 +1026,18 @@ function deepCopy(value) {
1049
1026
  }
1050
1027
  return racerDeepCopy(rawValue);
1051
1028
  }
1052
- function normalizeQueryParams(collection, params) {
1053
- if (params == null) {
1054
- console.warn(`
1055
- [Signal.query] Query is undefined. Got:
1056
- ${collection}, ${params}
1057
- Falling back to {_id: '__NON_EXISTENT__'} query to prevent critical crash.
1058
- You should prevent situations when the \`query\` is undefined.
1059
- `);
1060
- return { _id: '__NON_EXISTENT__' };
1061
- }
1062
- if (Array.isArray(params)) {
1063
- return { _id: { $in: params.slice() } };
1064
- }
1065
- if (typeof params === 'string' || typeof params === 'number') {
1066
- return { _id: params };
1067
- }
1068
- if (typeof params !== 'object') {
1069
- throw Error(`Signal.query() expects params to be an object, array, or id. Got: ${params}`);
1070
- }
1071
- return params;
1072
- }
1073
- function isAggregationParams(params) {
1074
- return Boolean(params?.$aggregate || params?.$aggregationName);
1075
- }
1076
- function withQueryScopeOptions(options, $root) {
1077
- if (!options || typeof options !== 'object') {
1078
- if (!$root)
1079
- return options;
1080
- return { root: $root };
1081
- }
1082
- const nextOptions = { ...options };
1083
- if (nextOptions.root == null && $root)
1084
- nextOptions.root = $root;
1085
- return nextOptions;
1086
- }
1087
- function subscribeMany(items, action, intent = 'subscribe') {
1029
+ function subscribeMany(items, action, intent = 'subscribe', methodName = action) {
1088
1030
  const targets = flattenItems(items);
1089
1031
  const promises = [];
1090
1032
  for (const target of targets) {
1091
1033
  if (!target)
1092
1034
  continue;
1093
1035
  if (!(target instanceof Signal)) {
1094
- throw Error(`Signal.${action}() accepts only Signal instances. Got: ${target}`);
1036
+ throw Error(`Signal.${methodName}() accepts only Signal instances. Got: ${target}`);
1095
1037
  }
1096
1038
  const result = action === 'subscribe'
1097
- ? subscribeSelf(target, intent)
1098
- : unsubscribeSelf(target, intent);
1039
+ ? subscribeSelf(target, intent, methodName)
1040
+ : unsubscribeSelf(target, intent, methodName);
1099
1041
  if (result?.then)
1100
1042
  promises.push(result);
1101
1043
  }
@@ -1115,7 +1057,7 @@ function flattenItems(items, result = []) {
1115
1057
  }
1116
1058
  return result;
1117
1059
  }
1118
- function subscribeSelf($signal, intent = 'subscribe') {
1060
+ function subscribeSelf($signal, intent = 'subscribe', methodName = 'subscribe') {
1119
1061
  if ($signal[IS_QUERY]) {
1120
1062
  return (async () => {
1121
1063
  await querySubscriptions.subscribe($signal, { intent });
@@ -1131,14 +1073,14 @@ function subscribeSelf($signal, intent = 'subscribe') {
1131
1073
  if (isPublicDocumentSignal($signal))
1132
1074
  return docSubscriptions.subscribe($signal, { intent });
1133
1075
  if (isPublicCollectionSignal($signal)) {
1134
- throw Error('Signal.subscribe() expects a query signal. Use .query() for collections.');
1076
+ throw Error(`Signal.${methodName}() expects a document or query signal. Use sub($collection, params, { mode: 'fetch' }) for collection fetches.`);
1135
1077
  }
1136
1078
  if ($signal[SEGMENTS].length === 0) {
1137
- throw Error('Signal.subscribe() cannot be called on the root signal');
1079
+ throw Error(`Signal.${methodName}() cannot be called on the root signal`);
1138
1080
  }
1139
- throw Error('Signal.subscribe() expects a document or query signal');
1081
+ throw Error(`Signal.${methodName}() expects a document or query signal`);
1140
1082
  }
1141
- function unsubscribeSelf($signal, intent = 'subscribe') {
1083
+ function unsubscribeSelf($signal, intent = 'subscribe', methodName = 'unsubscribe') {
1142
1084
  if ($signal[IS_QUERY])
1143
1085
  return querySubscriptions.unsubscribe($signal, { intent });
1144
1086
  if ($signal[IS_AGGREGATION])
@@ -1146,12 +1088,12 @@ function unsubscribeSelf($signal, intent = 'subscribe') {
1146
1088
  if (isPublicDocumentSignal($signal))
1147
1089
  return docSubscriptions.unsubscribe($signal, { intent });
1148
1090
  if (isPublicCollectionSignal($signal)) {
1149
- throw Error('Signal.unsubscribe() expects a query signal. Use .query() for collections.');
1091
+ throw Error(`Signal.${methodName}() expects a document or query signal`);
1150
1092
  }
1151
1093
  if ($signal[SEGMENTS].length === 0) {
1152
- throw Error('Signal.unsubscribe() cannot be called on the root signal');
1094
+ throw Error(`Signal.${methodName}() cannot be called on the root signal`);
1153
1095
  }
1154
- throw Error('Signal.unsubscribe() expects a document or query signal');
1096
+ throw Error(`Signal.${methodName}() expects a document or query signal`);
1155
1097
  }
1156
1098
  // Racer-style deep copy:
1157
1099
  // - Preserves prototypes by instantiating via `new value.constructor()`
@@ -777,8 +777,8 @@ export const regularBindings = {
777
777
  return Reflect.apply(extremelyLateBindings.get, this, arguments);
778
778
  }
779
779
  };
780
- const QUERY_METHODS = ['map', 'reduce', 'find', 'get', 'getIds', 'getExtra', 'subscribe', 'unsubscribe', 'fetch', 'unfetch'];
781
- const AGGREGATION_ALLOWED_METHODS = ['subscribe', 'unsubscribe', 'fetch', 'unfetch', 'ref', 'removeRef', 'refExtra', 'refIds'];
780
+ const QUERY_METHODS = ['map', 'reduce', 'find', 'get', 'getIds', 'getExtra', 'fetch', 'unfetch'];
781
+ const AGGREGATION_ALLOWED_METHODS = ['fetch', 'unfetch', 'ref', 'removeRef', 'refExtra', 'refIds'];
782
782
  // dot syntax always returns a child signal even if such method or property exists.
783
783
  // The method is only called when the signal is explicitly called as a function,
784
784
  // in which case we get the original method from the raw (non-proxied) parent signal
@@ -1,12 +1,11 @@
1
1
  import Cache from "./Cache.js";
2
- import Signal, { SEGMENTS, regularBindings, extremelyLateBindings, isPublicCollection, isPrivateCollection } from "./Signal.js";
2
+ import Signal, { regularBindings, extremelyLateBindings, isPublicCollection, isPrivateCollection } from "./Signal.js";
3
3
  import { findModel } from "./addModel.js";
4
4
  import { LOCAL } from './$.js';
5
5
  import { ROOT, ROOT_ID, GLOBAL_ROOT_ID } from "./Root.js";
6
6
  import { QUERIES } from './Query.js';
7
7
  import { AGGREGATIONS } from './Aggregation.js';
8
8
  import { isCompatEnv } from './compatEnv.js';
9
- import { getConnection } from "./connection.js";
10
9
  import { resolveRefSegmentsSafe } from './Compat/refFallback.js';
11
10
  import { getSignalIdentityHash } from "./rootScope.js";
12
11
  import { isRootContextClosed, registerRootOwnedSignalHash } from "./rootContext.js";
@@ -80,25 +79,7 @@ export default function getSignal($root, segments = [], { useExtremelyLateBindin
80
79
  return proxy;
81
80
  }
82
81
  function getDefaultProxyHandlers({ useExtremelyLateBindings } = {}) {
83
- const baseHandlers = (useExtremelyLateBindings ? extremelyLateBindings : regularBindings);
84
- if (!isCompatEnv() || baseHandlers !== extremelyLateBindings)
85
- return baseHandlers;
86
- return {
87
- ...baseHandlers,
88
- get(signal, key, receiver) {
89
- if (key === 'connection' && signal[SEGMENTS].length === 0) {
90
- try {
91
- return getConnection();
92
- }
93
- catch {
94
- return undefined;
95
- }
96
- }
97
- return baseHandlers.get
98
- ? baseHandlers.get(signal, key, receiver)
99
- : Reflect.get(signal, key, receiver);
100
- }
101
- };
82
+ return (useExtremelyLateBindings ? extremelyLateBindings : regularBindings);
102
83
  }
103
84
  export function getSignalClass(segments, rootId = GLOBAL_ROOT_ID) {
104
85
  let Model = findModel(segments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teamplay",
3
- "version": "0.5.0-alpha.27",
3
+ "version": "0.5.0-alpha.29",
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": "cbdbd79ede32eab577708675ab7a50c205bed50b"
137
+ "gitHead": "731a77d720afb01918969d9e02cc4eb0c2fa111e"
138
138
  }