teamplay 0.5.0-alpha.3 → 0.5.0-alpha.4
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/dist/orm/Aggregation.d.ts +1 -1
- package/dist/orm/Aggregation.js +6 -2
- package/dist/orm/SignalBase.d.ts +2 -2
- package/dist/orm/SignalBase.js +4 -1
- package/dist/orm/signalMetadata.d.ts +1 -1
- package/dist/orm/signalMetadata.js +28 -2
- package/dist/orm/signalReads.d.ts +1 -1
- package/dist/orm/signalReads.js +10 -4
- package/dist/orm/types/baseMethods.d.ts +1 -1
- package/dist/orm/types/signal.d.ts +5 -2
- package/package.json +2 -2
|
@@ -13,5 +13,5 @@ export function getAggregationDocId (
|
|
|
13
13
|
segments: readonly unknown[],
|
|
14
14
|
rootId?: string,
|
|
15
15
|
method?: (path: unknown[]) => unknown
|
|
16
|
-
): string |
|
|
16
|
+
): string | undefined
|
|
17
17
|
export function getAggregationCollectionName (segments: readonly unknown[]): string | undefined
|
package/dist/orm/Aggregation.js
CHANGED
|
@@ -91,8 +91,12 @@ export function getAggregationDocId(segments, rootId, method) {
|
|
|
91
91
|
if (typeof method !== 'function') {
|
|
92
92
|
method = path => rootId == null ? getRaw(path) : getPrivateData(rootId, path);
|
|
93
93
|
}
|
|
94
|
-
const
|
|
95
|
-
|
|
94
|
+
const underscoreId = method([...segments.slice(0, 3), '_id']);
|
|
95
|
+
if (typeof underscoreId === 'string')
|
|
96
|
+
return underscoreId;
|
|
97
|
+
const id = method([...segments.slice(0, 3), 'id']);
|
|
98
|
+
if (typeof id === 'string')
|
|
99
|
+
return id;
|
|
96
100
|
}
|
|
97
101
|
export function getAggregationCollectionName(segments) {
|
|
98
102
|
if (!(segments.length >= 2))
|
package/dist/orm/SignalBase.d.ts
CHANGED
|
@@ -51,11 +51,11 @@ export declare class Signal<TValue = unknown> extends Function {
|
|
|
51
51
|
/** Read the current value and track it for reactive rendering. */
|
|
52
52
|
get(): TValue;
|
|
53
53
|
/** Return document ids for a query or aggregation signal. */
|
|
54
|
-
getIds():
|
|
54
|
+
getIds(): string[];
|
|
55
55
|
/** Read the current value without tracking it for reactive rendering. */
|
|
56
56
|
peek(): TValue;
|
|
57
57
|
/** Return the document id represented by this document signal. */
|
|
58
|
-
getId(): string |
|
|
58
|
+
getId(): string | undefined;
|
|
59
59
|
/** Return the public collection name this signal belongs to. */
|
|
60
60
|
getCollection(): string;
|
|
61
61
|
/** Return association metadata registered on this signal's model class. */
|
package/dist/orm/SignalBase.js
CHANGED
|
@@ -205,7 +205,10 @@ export class Signal extends Function {
|
|
|
205
205
|
/** Return the document id represented by this document signal. */
|
|
206
206
|
getId() {
|
|
207
207
|
const $root = getRoot(this) || this;
|
|
208
|
-
|
|
208
|
+
const rootId = $root?.[ROOT_ID];
|
|
209
|
+
return getSignalId(this, rootId, segments => (isPrivateSignalSegments(segments)
|
|
210
|
+
? getPrivateData(rootId, segments)
|
|
211
|
+
: _get(getSignalStorageSegments({ [SEGMENTS]: segments }))));
|
|
209
212
|
}
|
|
210
213
|
/** Return the public collection name this signal belongs to. */
|
|
211
214
|
getCollection() {
|
|
@@ -12,6 +12,6 @@ export declare function getSignalPath($signal: Pick<SignalMetadataOwner, typeof
|
|
|
12
12
|
export declare function getSignalLeaf($signal: Pick<SignalMetadataOwner, typeof SEGMENTS>): string;
|
|
13
13
|
export declare function getSignalParentSegments($signal: Pick<SignalMetadataOwner, typeof SEGMENTS>, levels: unknown, argumentCount: number): PathSegment[];
|
|
14
14
|
export declare function normalizeParentLevels(levels: unknown, argumentCount: number): number;
|
|
15
|
-
export declare function getSignalId($signal: Pick<SignalMetadataOwner, typeof SEGMENTS>, rootId?: string): string |
|
|
15
|
+
export declare function getSignalId($signal: Pick<SignalMetadataOwner, typeof SEGMENTS>, rootId?: string, readPath?: (segments: PathSegment[]) => unknown): string | undefined;
|
|
16
16
|
export declare function getSignalCollection($signal: SignalMetadataOwner): PathSegment | undefined;
|
|
17
17
|
export declare function getSignalAssociations($rawSignal: Pick<SignalMetadataOwner, 'constructor'>): readonly unknown[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AGGREGATIONS, getAggregationCollectionName, getAggregationDocId } from './Aggregation.js';
|
|
2
|
+
import { isPrivateCollectionSegments } from "./rootScope.js";
|
|
2
3
|
import { SEGMENTS } from "./signalSymbols.js";
|
|
3
4
|
export function getSignalPath($signal) {
|
|
4
5
|
return $signal[SEGMENTS].join('.');
|
|
@@ -27,16 +28,23 @@ export function normalizeParentLevels(levels, argumentCount) {
|
|
|
27
28
|
throw Error('Signal.parent() expects a positive integer');
|
|
28
29
|
return levels;
|
|
29
30
|
}
|
|
30
|
-
export function getSignalId($signal, rootId) {
|
|
31
|
+
export function getSignalId($signal, rootId, readPath) {
|
|
31
32
|
const segments = $signal[SEGMENTS];
|
|
32
33
|
if (segments.length === 0)
|
|
33
34
|
throw Error('Can\'t get the id of the root signal');
|
|
34
35
|
if (segments.length === 1)
|
|
35
36
|
throw Error('Can\'t get the id of a collection');
|
|
37
|
+
if (isDirectPublicDocumentSegments(segments))
|
|
38
|
+
return getLeafId(segments);
|
|
39
|
+
if (readPath) {
|
|
40
|
+
const valueId = getValueIdFromPaths(segments, readPath);
|
|
41
|
+
if (valueId.found)
|
|
42
|
+
return valueId.id;
|
|
43
|
+
}
|
|
36
44
|
if (segments[0] === AGGREGATIONS && segments.length === 3) {
|
|
37
45
|
return getAggregationDocId(segments, rootId);
|
|
38
46
|
}
|
|
39
|
-
return segments
|
|
47
|
+
return getLeafId(segments);
|
|
40
48
|
}
|
|
41
49
|
export function getSignalCollection($signal) {
|
|
42
50
|
const segments = $signal[SEGMENTS];
|
|
@@ -54,3 +62,21 @@ export function getSignalCollection($signal) {
|
|
|
54
62
|
export function getSignalAssociations($rawSignal) {
|
|
55
63
|
return $rawSignal.constructor.associations || [];
|
|
56
64
|
}
|
|
65
|
+
function getValueIdFromPaths(segments, readPath) {
|
|
66
|
+
const underscoreId = readPath([...segments, '_id']);
|
|
67
|
+
if (typeof underscoreId === 'string')
|
|
68
|
+
return { found: true, id: underscoreId };
|
|
69
|
+
const id = readPath([...segments, 'id']);
|
|
70
|
+
if (typeof id === 'string')
|
|
71
|
+
return { found: true, id };
|
|
72
|
+
if (underscoreId !== undefined || id !== undefined)
|
|
73
|
+
return { found: true };
|
|
74
|
+
return { found: false };
|
|
75
|
+
}
|
|
76
|
+
function isDirectPublicDocumentSegments(segments) {
|
|
77
|
+
return segments.length === 2 && !isPrivateCollectionSegments(segments);
|
|
78
|
+
}
|
|
79
|
+
function getLeafId(segments) {
|
|
80
|
+
const leaf = segments[segments.length - 1];
|
|
81
|
+
return typeof leaf === 'string' ? leaf : undefined;
|
|
82
|
+
}
|
|
@@ -21,6 +21,6 @@ export interface SignalReadContext<TSignal extends SignalReadOwner> {
|
|
|
21
21
|
}
|
|
22
22
|
export declare function readSignalValue<TSignal extends SignalReadOwner, TValue>($signal: TSignal, context: SignalReadContext<TSignal>, method: SignalReadMethod<TValue>, rawMethod: SignalReadMethod): TValue;
|
|
23
23
|
export declare function getSignalValue<TSignal extends SignalReadOwner, TValue>($signal: TSignal, context: SignalReadContext<TSignal>, method: SignalReadMethod<TValue>, rawMethod: SignalReadMethod): TValue;
|
|
24
|
-
export declare function getSignalIds<TSignal extends SignalReadOwner>($signal: TSignal, context: SignalReadContext<TSignal>):
|
|
24
|
+
export declare function getSignalIds<TSignal extends SignalReadOwner>($signal: TSignal, context: SignalReadContext<TSignal>): string[];
|
|
25
25
|
export declare function isQueryIdsValueSignal<TSignal extends SignalReadOwner>($signal: TSignal): boolean;
|
|
26
26
|
export declare function isAggregationValueSignal<TSignal extends SignalReadOwner>($signal: TSignal): boolean;
|
package/dist/orm/signalReads.js
CHANGED
|
@@ -23,7 +23,7 @@ export function getSignalValue($signal, context, method, rawMethod) {
|
|
|
23
23
|
context.warn('Signal.get() on Query didn\'t find ids', $signal[SEGMENTS]);
|
|
24
24
|
return [];
|
|
25
25
|
}
|
|
26
|
-
return ids;
|
|
26
|
+
return ids.filter(isString);
|
|
27
27
|
}
|
|
28
28
|
return readSignalValue($signal, context, method, rawMethod);
|
|
29
29
|
}
|
|
@@ -35,13 +35,13 @@ export function getSignalIds($signal, context) {
|
|
|
35
35
|
context.warn('Signal.getIds() on Query didn\'t find ids', [QUERIES, getQueryHashSegment($signal), 'ids']);
|
|
36
36
|
return [];
|
|
37
37
|
}
|
|
38
|
-
return ids;
|
|
38
|
+
return ids.filter(isString);
|
|
39
39
|
}
|
|
40
40
|
if ($signal[IS_AGGREGATION]) {
|
|
41
41
|
const docs = context.readPrivateData(rootId, $signal[SEGMENTS], false);
|
|
42
42
|
if (!Array.isArray(docs))
|
|
43
43
|
return [];
|
|
44
|
-
return docs.map(getAggregationRowId);
|
|
44
|
+
return docs.map(getAggregationRowId).filter(isString);
|
|
45
45
|
}
|
|
46
46
|
context.error('Signal.getIds() can only be used on query signals or aggregation signals. ' +
|
|
47
47
|
'Received a regular signal: ' + JSON.stringify($signal[SEGMENTS]));
|
|
@@ -57,7 +57,13 @@ export function isAggregationValueSignal($signal) {
|
|
|
57
57
|
}
|
|
58
58
|
function getAggregationRowId(doc) {
|
|
59
59
|
const row = doc;
|
|
60
|
-
|
|
60
|
+
if (typeof row?._id === 'string')
|
|
61
|
+
return row._id;
|
|
62
|
+
if (typeof row?.id === 'string')
|
|
63
|
+
return row.id;
|
|
64
|
+
}
|
|
65
|
+
function isString(value) {
|
|
66
|
+
return typeof value === 'string';
|
|
61
67
|
}
|
|
62
68
|
function getQueryHashSegment($signal) {
|
|
63
69
|
return $signal[HASH];
|
|
@@ -6,7 +6,7 @@ export interface SignalMetadataMethods {
|
|
|
6
6
|
readonly [Symbol.toStringTag]: string;
|
|
7
7
|
parent: (levels?: number) => unknown;
|
|
8
8
|
id: () => string;
|
|
9
|
-
getId: () => string |
|
|
9
|
+
getId: () => string | undefined;
|
|
10
10
|
getCollection: () => string;
|
|
11
11
|
getAssociations: () => readonly unknown[];
|
|
12
12
|
}
|
|
@@ -25,6 +25,9 @@ type PathModel<TValue, TDefaultModel extends SignalClass<any>, TPath extends Wil
|
|
|
25
25
|
type ArrayItemSignal<Item, TPath extends WildcardSignalPath> = DocumentSignal<Item, typeof Signal, AppendPath<TPath, '*'>>;
|
|
26
26
|
type SignalArrayMethods<TValue, TPath extends WildcardSignalPath> = NonNullable<TValue> extends ReadonlyArray<infer Item> ? SignalArrayLike<ArrayItemSignal<Item, TPath>> : Pick<Signal<TValue>, SignalArrayReaderMethodKeys>;
|
|
27
27
|
type SignalFieldsForPath<TPath extends WildcardSignalPath> = JoinPath<TPath> extends keyof TeamplaySignalFields ? TeamplaySignalFields[JoinPath<TPath>] : {};
|
|
28
|
+
type DocumentSignalIdMethod = {
|
|
29
|
+
getId: () => string;
|
|
30
|
+
};
|
|
28
31
|
export type AnySignal = Signal<any>;
|
|
29
32
|
type IsAny<TValue> = 0 extends (1 & TValue) ? true : false;
|
|
30
33
|
type IsUnknown<TValue> = IsAny<TValue> extends true ? false : unknown extends TValue ? true : false;
|
|
@@ -34,7 +37,7 @@ type IsUnion<TValue, TUnion = TValue> = [
|
|
|
34
37
|
] extends [never] ? false : TValue extends unknown ? [TUnion] extends [TValue] ? false : true : false;
|
|
35
38
|
type SingleKey<TKey> = IsUnion<TKey> extends true ? never : TKey;
|
|
36
39
|
export type SignalKind = 'root' | 'document' | 'collection' | 'nestedValue' | 'localArray' | 'array' | 'query' | 'aggregation' | 'collectionQuery';
|
|
37
|
-
type DocumentSignalForKind<TValue, TModel extends SignalClass<any>, TPath extends WildcardSignalPath> = Omit<SignalModelInstance<TValue, PathModel<TValue, TModel, TPath>>, SignalArrayReaderMethodKeys> & SignalArrayMethods<TValue, TPath> & SignalChildren<TValue, TPath> & SignalFieldsForPath<TPath>;
|
|
40
|
+
type DocumentSignalForKind<TValue, TModel extends SignalClass<any>, TPath extends WildcardSignalPath> = Omit<SignalModelInstance<TValue, PathModel<TValue, TModel, TPath>>, SignalArrayReaderMethodKeys | 'getId'> & DocumentSignalIdMethod & SignalArrayMethods<TValue, TPath> & SignalChildren<TValue, TPath> & SignalFieldsForPath<TPath>;
|
|
38
41
|
type CollectionSignalForKind<TDocument, TCollectionModel extends SignalClass<any>, TDocumentModel extends SignalClass<any>, TPath extends WildcardSignalPath> = Omit<SignalModelInstance<TDocument[], PathModel<TDocument[], TCollectionModel, TPath>>, SignalCollectionMethodKeys> & SignalArrayLike<CollectionDocumentSignal<TDocument, TDocumentModel, TPath>> & BlockedArrayMutators & {
|
|
39
42
|
add: (value: TDocument) => Promise<string>;
|
|
40
43
|
} & CollectionDocumentIndex<CollectionDocumentSignal<TDocument, TDocumentModel, TPath>>;
|
|
@@ -43,7 +46,7 @@ type ArraySignalForKind<TDocument, TDocumentModel extends SignalClass<any>, TDoc
|
|
|
43
46
|
readonly [index: number]: DocumentSignal<TDocument, TDocumentModel, TDocumentPath>;
|
|
44
47
|
} & BlockedArrayMutators;
|
|
45
48
|
type QueryMetadataSignals = {
|
|
46
|
-
readonly ids: Signal<
|
|
49
|
+
readonly ids: Signal<string[]>;
|
|
47
50
|
readonly extra: Signal<unknown>;
|
|
48
51
|
};
|
|
49
52
|
type QuerySignalForKind<TDocument, TDocumentModel extends SignalClass<any>, TDocumentPath extends WildcardSignalPath> = ArraySignalForKind<TDocument, TDocumentModel, TDocumentPath> & QueryMetadataSignals;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teamplay",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.4",
|
|
4
4
|
"description": "Full-stack signals ORM with multiplayer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -128,5 +128,5 @@
|
|
|
128
128
|
]
|
|
129
129
|
},
|
|
130
130
|
"license": "MIT",
|
|
131
|
-
"gitHead": "
|
|
131
|
+
"gitHead": "7ec37caa078961926442b1aba74768792359c2c2"
|
|
132
132
|
}
|