teamplay 0.5.0-alpha.2 → 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/index.d.ts +2 -2
- package/dist/orm/Aggregation.d.ts +1 -1
- package/dist/orm/Aggregation.js +6 -2
- package/dist/orm/Signal.d.ts +1 -1
- package/dist/orm/SignalBase.d.ts +2 -2
- package/dist/orm/SignalBase.js +4 -1
- package/dist/orm/index.d.ts +1 -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/sub.d.ts +9 -1
- package/dist/orm/types/baseMethods.d.ts +1 -1
- package/dist/orm/types/jsonSchema.d.ts +3 -3
- package/dist/orm/types/query.d.ts +7 -1
- package/dist/orm/types/signal.d.ts +5 -2
- package/dist/react/useSub.d.ts +19 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
2
|
import { SEGMENTS } from './orm/Signal.js';
|
|
3
3
|
import useApi from './react/useApi.js';
|
|
4
|
-
import type { AnySignal, ArraySignal, CollectionDocument, CollectionDocumentModel, CollectionSignal, CollectionSignalFromSpec, CollectionAggregationSignal, CollectionQuerySignal, CollectionSpec, CollectionsFromManifest, DocumentSignal, FromJsonSchema, JsonSchema, JsonSchemaSpec, MaybePromise, MaybePromiseSubResult, ModelEntry, ModelManifest, PathModelsFromManifest, PublicSignal, LocalSignalFactory, RuntimeSignalConstructor, RuntimeSignalInstance, RootCollections, RootSignal, WildcardPathSegment, WildcardSignalPath, AppendPath, JoinPath, QueryParams, QuerySignal, RegisteredAggregationInput, SignalChild, SignalBaseInstance, SignalArrayMutatorMethods, SignalArrayReaderMethods, SignalClass, SignalCollectionMethods, SignalConstructor, SignalForKind, SignalKind, SignalMetadataMethods, SignalModelConstructor, SignalStringMutatorMethods, SignalValueMethods, SubResult, TypedAggregationInput, TypedAggregationSignal, TypedSignal, ZodLikeSchema, ZodSchemaSpec } from './orm/Signal.js';
|
|
4
|
+
import type { AnySignal, ArraySignal, CollectionDocument, CollectionDocumentModel, CollectionSignal, CollectionSignalFromSpec, CollectionAggregationSignal, CollectionQuerySignal, CollectionSpec, CollectionsFromManifest, DocumentSignal, FromJsonSchema, JsonSchema, JsonSchemaSpec, MaybePromise, MaybePromiseSubResult, ModelEntry, ModelManifest, PathModelsFromManifest, PublicSignal, LocalSignalFactory, RuntimeSignalConstructor, RuntimeSignalInstance, RootCollections, RootSignal, WildcardPathSegment, WildcardSignalPath, AppendPath, ComputedQueryParamsInput, JoinPath, QueryParams, QueryParamsInput, QuerySignal, RegisteredAggregationInput, SignalChild, SignalBaseInstance, SignalArrayMutatorMethods, SignalArrayReaderMethods, SignalClass, SignalCollectionMethods, SignalConstructor, SignalForKind, SignalKind, SignalMetadataMethods, SignalModelConstructor, SignalStringMutatorMethods, SignalValueMethods, SubResult, TypedAggregationInput, TypedAggregationSignal, TypedSignal, ZodLikeSchema, ZodSchemaSpec } from './orm/Signal.js';
|
|
5
5
|
export interface TeamplayCollections {
|
|
6
6
|
}
|
|
7
7
|
export interface TeamplayModels {
|
|
@@ -9,7 +9,7 @@ export interface TeamplayModels {
|
|
|
9
9
|
export interface TeamplaySignalFields {
|
|
10
10
|
}
|
|
11
11
|
export type Signal<TValue = unknown> = PublicSignal<TValue>;
|
|
12
|
-
export type { AnySignal, ArraySignal, CollectionDocument, CollectionDocumentModel, CollectionSignal, CollectionSpec, CollectionSignalFromSpec, CollectionAggregationSignal, CollectionQuerySignal, DocumentSignal, FromJsonSchema, JsonSchema, JsonSchemaSpec, MaybePromise, MaybePromiseSubResult, ModelEntry, ModelManifest, CollectionsFromManifest, LocalSignalFactory, PathModelsFromManifest, PublicSignal, RuntimeSignalConstructor, RuntimeSignalInstance, RootCollections, RootSignal, WildcardPathSegment, WildcardSignalPath, AppendPath, JoinPath, QueryParams, QuerySignal, RegisteredAggregationInput, SignalArrayMutatorMethods, SignalArrayReaderMethods, SignalBaseInstance, SignalClass, SignalChild, SignalConstructor, SignalCollectionMethods, SignalForKind, SignalKind, SignalMetadataMethods, SignalModelConstructor, SignalStringMutatorMethods, SignalValueMethods, SubResult, TypedAggregationInput, TypedAggregationSignal, TypedSignal, ZodLikeSchema, ZodSchemaSpec };
|
|
12
|
+
export type { AnySignal, ArraySignal, CollectionDocument, CollectionDocumentModel, CollectionSignal, CollectionSpec, CollectionSignalFromSpec, CollectionAggregationSignal, CollectionQuerySignal, DocumentSignal, FromJsonSchema, JsonSchema, JsonSchemaSpec, MaybePromise, MaybePromiseSubResult, ModelEntry, ModelManifest, CollectionsFromManifest, LocalSignalFactory, PathModelsFromManifest, PublicSignal, RuntimeSignalConstructor, RuntimeSignalInstance, RootCollections, RootSignal, WildcardPathSegment, WildcardSignalPath, AppendPath, ComputedQueryParamsInput, JoinPath, QueryParams, QueryParamsInput, QuerySignal, RegisteredAggregationInput, SignalArrayMutatorMethods, SignalArrayReaderMethods, SignalBaseInstance, SignalClass, SignalChild, SignalConstructor, SignalCollectionMethods, SignalForKind, SignalKind, SignalMetadataMethods, SignalModelConstructor, SignalStringMutatorMethods, SignalValueMethods, SubResult, TypedAggregationInput, TypedAggregationSignal, TypedSignal, ZodLikeSchema, ZodSchemaSpec };
|
|
13
13
|
export interface ObserverOptions {
|
|
14
14
|
forwardRef?: boolean;
|
|
15
15
|
cache?: boolean;
|
|
@@ -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/Signal.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import SignalCompat from './Compat/SignalCompat.js';
|
|
2
2
|
import type { SignalConstructor } from './types/signal.js';
|
|
3
3
|
export type { FromJsonSchema, InferZodSchema, JsonSchema, JsonSchemaObject, ZodLikeSchema } from './types/jsonSchema.js';
|
|
4
|
-
export type { QueryParams } from './types/query.js';
|
|
4
|
+
export type { ComputedQueryParamsInput, QueryParams, QueryParamsInput } from './types/query.js';
|
|
5
5
|
export type { SignalArrayMutatorMethods, SignalArrayReaderMethods, SignalCollectionMethods, SignalMetadataMethods, SignalStringMutatorMethods, SignalValueMethods } from './types/baseMethods.js';
|
|
6
6
|
export type { AppendPath, JoinPath, PathSegment, SignalPath, WildcardPathSegment, WildcardSignalPath } from './types/path.js';
|
|
7
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';
|
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() {
|
package/dist/orm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { belongsTo, hasMany, hasOne } from './associations.js';
|
|
2
|
-
export type { AggregationSignal, ArraySignal, CollectionAggregationSignal, CollectionQuerySignal, CollectionSignal, CollectionSignalFromSpec, CollectionSpec, CollectionsFromManifest, DocumentSignal, FromJsonSchema, JsonSchema, JsonSchemaSpec, ModelEntry, ModelManifest, PathModelsFromManifest, PublicSignal, RuntimeSignalConstructor, RuntimeSignalInstance, WildcardPathSegment, WildcardSignalPath, AppendPath, JoinPath, QueryParams, QuerySignal, RegisteredAggregationInput, SignalBaseInstance, SignalClass, SignalChild, SignalConstructor, SignalForKind, SignalKind, SignalModelConstructor, TypedAggregationInput, TypedAggregationSignal, TypedSignal, ZodLikeSchema, ZodSchemaSpec } from './Signal.js';
|
|
2
|
+
export type { AggregationSignal, ArraySignal, CollectionAggregationSignal, CollectionQuerySignal, CollectionSignal, CollectionSignalFromSpec, CollectionSpec, CollectionsFromManifest, ComputedQueryParamsInput, DocumentSignal, FromJsonSchema, JsonSchema, JsonSchemaSpec, ModelEntry, ModelManifest, PathModelsFromManifest, PublicSignal, RuntimeSignalConstructor, RuntimeSignalInstance, WildcardPathSegment, WildcardSignalPath, AppendPath, JoinPath, QueryParams, QueryParamsInput, QuerySignal, RegisteredAggregationInput, SignalBaseInstance, SignalClass, SignalChild, SignalConstructor, SignalForKind, SignalKind, SignalModelConstructor, TypedAggregationInput, TypedAggregationSignal, TypedSignal, ZodLikeSchema, ZodSchemaSpec } from './Signal.js';
|
|
3
3
|
export type { RootSignal, TeamplayCollections, TeamplayModels, TeamplaySignalFields } from '../index.js';
|
|
4
4
|
export declare const BaseModel: import("./Signal.js").SignalConstructor;
|
|
5
5
|
export default BaseModel;
|
|
@@ -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];
|
package/dist/orm/sub.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AggregationFunction, AggregationParams, ClientAggregationFunction } from '@teamplay/utils/aggregation';
|
|
2
|
-
import type { CollectionSignal, DocumentSignal, MaybePromise, MaybePromiseSubResult, QueryParams, RegisteredAggregationInput, SignalModelConstructor, SubResult, TypedAggregationInput, TypedAggregationSignal, WildcardSignalPath } from './Signal.js';
|
|
2
|
+
import type { CollectionSignal, ComputedQueryParamsInput, DocumentSignal, MaybePromise, MaybePromiseSubResult, QueryParams, RegisteredAggregationInput, SignalModelConstructor, SubResult, TypedAggregationInput, TypedAggregationSignal, WildcardSignalPath } from './Signal.js';
|
|
3
3
|
/**
|
|
4
4
|
* Subscribe to an aggregation with explicit output typing outside React.
|
|
5
5
|
* @param $aggregation Typed aggregation input.
|
|
@@ -35,3 +35,11 @@ export default function sub<TSignal extends DocumentSignal<any, any, any>>($sign
|
|
|
35
35
|
* @param params Mongo-style query params, including filters and `$sort`.
|
|
36
36
|
*/
|
|
37
37
|
export default function sub<TDocument, TCollectionModel extends SignalModelConstructor<TDocument[]>, TDocumentModel extends SignalModelConstructor<TDocument>, TCollectionPath extends WildcardSignalPath>($collection: CollectionSignal<TDocument, TCollectionModel, TDocumentModel, TCollectionPath>, params: QueryParams<TDocument>): MaybePromiseSubResult<CollectionSignal<TDocument, TCollectionModel, TDocumentModel, TCollectionPath>, QueryParams<TDocument>>;
|
|
38
|
+
/**
|
|
39
|
+
* Subscribe to a collection query with computed string keys outside React.
|
|
40
|
+
* This fallback preserves Mongo-style computed paths such as `{ [`likes.${id}`]: true }`.
|
|
41
|
+
* Literal query objects should use the stricter overload above.
|
|
42
|
+
* @param $collection Collection signal to query.
|
|
43
|
+
* @param params Mongo-style query params with a widened computed key.
|
|
44
|
+
*/
|
|
45
|
+
export default function sub<TDocument, TCollectionModel extends SignalModelConstructor<TDocument[]>, TDocumentModel extends SignalModelConstructor<TDocument>, TCollectionPath extends WildcardSignalPath, TParams extends object>($collection: CollectionSignal<TDocument, TCollectionModel, TDocumentModel, TCollectionPath>, params: TParams & ComputedQueryParamsInput<TParams>): MaybePromiseSubResult<CollectionSignal<TDocument, TCollectionModel, TDocumentModel, TCollectionPath>, TParams>;
|
|
@@ -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
|
}
|
|
@@ -38,7 +38,7 @@ type SimplifiedProperties<TSchema> = {
|
|
|
38
38
|
type HasSimplifiedProperties<TSchema> = keyof SimplifiedProperties<TSchema> extends never ? false : true;
|
|
39
39
|
type SchemaProperties<TSchema> = TSchema extends {
|
|
40
40
|
readonly properties: infer Properties;
|
|
41
|
-
} ? IsFullObjectSchema<TSchema> extends true ? Properties : HasSimplifiedProperties<TSchema> extends true ? SimplifiedProperties<TSchema> : Record<
|
|
41
|
+
} ? IsFullObjectSchema<TSchema> extends true ? Properties : HasSimplifiedProperties<TSchema> extends true ? SimplifiedProperties<TSchema> : Record<never, never> : IsFullObjectSchema<TSchema> extends true ? Record<never, never> : HasSimplifiedProperties<TSchema> extends true ? SimplifiedProperties<TSchema> : Record<never, never>;
|
|
42
42
|
type ExplicitRequiredKeys<TSchema, TProperties> = TSchema extends {
|
|
43
43
|
readonly required?: infer Required;
|
|
44
44
|
} ? Required extends readonly string[] ? Extract<Required[number], keyof TProperties & string> : never : never;
|
|
@@ -50,10 +50,10 @@ type SimplifiedRequiredKeys<TProperties> = {
|
|
|
50
50
|
type RequiredKeys<TSchema, TProperties> = ExplicitRequiredKeys<TSchema, TProperties> | SimplifiedRequiredKeys<TProperties>;
|
|
51
51
|
type PatternPropertiesFromJsonSchema<TSchema> = TSchema extends {
|
|
52
52
|
readonly patternProperties?: infer PatternProperties;
|
|
53
|
-
} ? PatternProperties extends
|
|
53
|
+
} ? PatternProperties extends object ? keyof PatternProperties extends never ? {} : Record<string, FromJsonSchema<PatternProperties[keyof PatternProperties]>> : {} : {};
|
|
54
54
|
type AdditionalPropertiesFromJsonSchema<TSchema> = TSchema extends {
|
|
55
55
|
readonly additionalProperties?: infer AdditionalProperties;
|
|
56
|
-
} ? AdditionalProperties extends JsonSchema ? Record<string, FromJsonSchema<AdditionalProperties>> : {} : {};
|
|
56
|
+
} ? AdditionalProperties extends false ? {} : AdditionalProperties extends JsonSchema ? Record<string, FromJsonSchema<AdditionalProperties>> : {} : {};
|
|
57
57
|
type ObjectFromJsonSchema<TSchema> = SchemaProperties<TSchema> extends infer Properties ? Properties extends Record<string, unknown> ? Prettify<{
|
|
58
58
|
[K in RequiredKeys<TSchema, Properties>]-?: FromJsonSchema<Properties[K]>;
|
|
59
59
|
} & {
|
|
@@ -16,14 +16,20 @@ type QueryValue<TValue> = QueryComparable<TValue> | {
|
|
|
16
16
|
$exists?: boolean;
|
|
17
17
|
$regex?: TValue extends string ? string | RegExp : never;
|
|
18
18
|
};
|
|
19
|
+
type QuerySortDirection = 1 | -1 | 'asc' | 'desc' | 'ascending' | 'descending';
|
|
20
|
+
type QuerySort<TDocument> = {
|
|
21
|
+
[K in QueryPath<TDocument> | '_id' | 'id']?: QuerySortDirection;
|
|
22
|
+
};
|
|
19
23
|
export type QueryParams<TDocument> = {
|
|
20
24
|
[K in QueryPath<TDocument>]?: QueryValue<QueryPathValue<TDocument, K>>;
|
|
21
25
|
} & {
|
|
22
26
|
_id?: QueryValue<string | number>;
|
|
23
27
|
id?: QueryValue<string | number>;
|
|
24
28
|
} & {
|
|
25
|
-
|
|
29
|
+
$sort?: QuerySort<TDocument>;
|
|
26
30
|
} & {
|
|
27
31
|
[K in `$${string}`]?: unknown;
|
|
28
32
|
};
|
|
33
|
+
export type ComputedQueryParamsInput<TParams extends object> = string extends keyof TParams ? TParams : never;
|
|
34
|
+
export type QueryParamsInput<TDocument, TParams extends object> = TParams extends QueryParams<TDocument> ? TParams : ComputedQueryParamsInput<TParams>;
|
|
29
35
|
export {};
|
|
@@ -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/dist/react/useSub.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AggregationFunction, AggregationParams, ClientAggregationFunction } from '@teamplay/utils/aggregation';
|
|
2
|
-
import type { CollectionSignal, DocumentSignal, QueryParams, RegisteredAggregationInput, SignalModelConstructor, SubResult, TypedAggregationInput, TypedAggregationSignal, WildcardSignalPath } from '../orm/Signal.js';
|
|
2
|
+
import type { CollectionSignal, ComputedQueryParamsInput, DocumentSignal, QueryParams, RegisteredAggregationInput, SignalModelConstructor, SubResult, TypedAggregationInput, TypedAggregationSignal, WildcardSignalPath } from '../orm/Signal.js';
|
|
3
3
|
export interface UseSubOptions {
|
|
4
4
|
/** Return `undefined` while loading instead of throwing a Suspense promise. */
|
|
5
5
|
async?: boolean;
|
|
@@ -24,6 +24,15 @@ export declare function useAsyncSub<TSignal extends DocumentSignal<any, any, any
|
|
|
24
24
|
* @param options Subscription behavior options.
|
|
25
25
|
*/
|
|
26
26
|
export declare function useAsyncSub<TDocument, TCollectionModel extends SignalModelConstructor<TDocument[]>, TDocumentModel extends SignalModelConstructor<TDocument>, TCollectionPath extends WildcardSignalPath>(signal: CollectionSignal<TDocument, TCollectionModel, TDocumentModel, TCollectionPath>, params: QueryParams<TDocument>, options?: UseSubOptions): SubResult<CollectionSignal<TDocument, TCollectionModel, TDocumentModel, TCollectionPath>, QueryParams<TDocument>>;
|
|
27
|
+
/**
|
|
28
|
+
* Subscribe to a collection query with computed string keys in React async mode.
|
|
29
|
+
* This fallback preserves Mongo-style computed paths such as `{ [`likes.${id}`]: true }`.
|
|
30
|
+
* Literal query objects should use the stricter overload above.
|
|
31
|
+
* @param signal Collection signal to query.
|
|
32
|
+
* @param params Mongo-style query params with a widened computed key.
|
|
33
|
+
* @param options Subscription behavior options.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useAsyncSub<TDocument, TCollectionModel extends SignalModelConstructor<TDocument[]>, TDocumentModel extends SignalModelConstructor<TDocument>, TCollectionPath extends WildcardSignalPath, TParams extends object>(signal: CollectionSignal<TDocument, TCollectionModel, TDocumentModel, TCollectionPath>, params: TParams & ComputedQueryParamsInput<TParams>, options?: UseSubOptions): SubResult<CollectionSignal<TDocument, TCollectionModel, TDocumentModel, TCollectionPath>, TParams>;
|
|
27
36
|
/**
|
|
28
37
|
* Subscribe to a registered collection aggregation in React async mode.
|
|
29
38
|
* @param signal Aggregation header generated by StartupJS model loading.
|
|
@@ -66,6 +75,15 @@ export default function useSub<TSignal extends DocumentSignal<any, any, any>>(si
|
|
|
66
75
|
* @param options Subscription behavior options.
|
|
67
76
|
*/
|
|
68
77
|
export default function useSub<TDocument, TCollectionModel extends SignalModelConstructor<TDocument[]>, TDocumentModel extends SignalModelConstructor<TDocument>, TCollectionPath extends WildcardSignalPath>(signal: CollectionSignal<TDocument, TCollectionModel, TDocumentModel, TCollectionPath>, params: QueryParams<TDocument>, options?: UseSubOptions): SubResult<CollectionSignal<TDocument, TCollectionModel, TDocumentModel, TCollectionPath>, QueryParams<TDocument>>;
|
|
78
|
+
/**
|
|
79
|
+
* Subscribe to a collection query with computed string keys in React.
|
|
80
|
+
* This fallback preserves Mongo-style computed paths such as `{ [`likes.${id}`]: true }`.
|
|
81
|
+
* Literal query objects should use the stricter overload above.
|
|
82
|
+
* @param signal Collection signal to query.
|
|
83
|
+
* @param params Mongo-style query params with a widened computed key.
|
|
84
|
+
* @param options Subscription behavior options.
|
|
85
|
+
*/
|
|
86
|
+
export default function useSub<TDocument, TCollectionModel extends SignalModelConstructor<TDocument[]>, TDocumentModel extends SignalModelConstructor<TDocument>, TCollectionPath extends WildcardSignalPath, TParams extends object>(signal: CollectionSignal<TDocument, TCollectionModel, TDocumentModel, TCollectionPath>, params: TParams & ComputedQueryParamsInput<TParams>, options?: UseSubOptions): SubResult<CollectionSignal<TDocument, TCollectionModel, TDocumentModel, TCollectionPath>, TParams>;
|
|
69
87
|
/**
|
|
70
88
|
* Subscribe to a registered collection aggregation in React.
|
|
71
89
|
* @param signal Aggregation header generated by StartupJS model loading.
|
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
|
}
|