teamplay 0.5.0-alpha.3 → 0.5.0-alpha.30
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 +24 -9
- package/dist/index.js +2 -5
- package/dist/orm/Aggregation.d.ts +6 -4
- package/dist/orm/Aggregation.js +39 -11
- package/dist/orm/Compat/SignalCompat.js +151 -565
- package/dist/orm/Compat/queryReadiness.d.ts +13 -5
- package/dist/orm/Compat/silentContext.js +4 -22
- package/dist/orm/Compat/startStopCompat.js +33 -0
- package/dist/orm/Doc.js +48 -3
- package/dist/orm/Query.d.ts +1 -0
- package/dist/orm/Query.js +67 -22
- package/dist/orm/Root.d.ts +4 -0
- package/dist/orm/Root.js +16 -0
- package/dist/orm/Signal.d.ts +2 -2
- package/dist/orm/SignalBase.d.ts +29 -2
- package/dist/orm/SignalBase.js +295 -10
- package/dist/orm/addModel.d.ts +9 -2
- package/dist/orm/connection.d.ts +8 -1
- package/dist/orm/connection.js +9 -4
- package/dist/orm/dataTree.js +36 -30
- package/dist/orm/getSignal.js +2 -23
- package/dist/orm/index.d.ts +2 -2
- package/dist/orm/privateData.d.ts +7 -22
- package/dist/orm/privateData.js +20 -1
- package/dist/orm/signalMetadata.d.ts +1 -1
- package/dist/orm/signalMetadata.js +29 -3
- package/dist/orm/signalReads.d.ts +1 -1
- package/dist/orm/signalReads.js +7 -7
- package/dist/orm/signalStorageMutations.d.ts +0 -2
- package/dist/orm/signalStorageMutations.js +0 -9
- package/dist/orm/signalSymbols.js +1 -1
- package/dist/orm/signalValueMutations.d.ts +1 -1
- package/dist/orm/signalValueMutations.js +0 -3
- package/dist/orm/sub.d.ts +12 -7
- package/dist/orm/sub.js +87 -30
- package/dist/orm/subscriptionGcDelay.js +2 -6
- package/dist/orm/types/baseMethods.d.ts +2 -1
- package/dist/orm/types/modelManifest.d.ts +12 -1
- package/dist/orm/types/signal.d.ts +44 -15
- package/dist/react/convertToObserver.js +1 -4
- package/dist/react/promiseBatcher.js +1 -1
- package/dist/react/renderAttemptDestroyer.d.ts +0 -8
- package/dist/react/renderAttemptDestroyer.js +2 -28
- package/dist/react/trapRender.js +3 -3
- package/dist/react/useSub.d.ts +86 -5
- package/dist/react/useSub.js +191 -32
- package/dist/react/useSuspendMemo.js +1 -5
- package/dist/server.d.ts +1 -1
- package/package.json +16 -10
- package/dist/orm/Compat/hooksCompat.d.ts +0 -33
- package/dist/orm/Compat/hooksCompat.js +0 -360
- package/dist/react/compatComponentRegistry.d.ts +0 -4
- package/dist/react/compatComponentRegistry.js +0 -19
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
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, 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';
|
|
4
|
+
import type { AnySignal, ArraySignal, CollectionDocument, CollectionDocumentModel, CollectionSignal, CollectionSignalFromSpec, CollectionAggregationSignal, CollectionQuerySignal, CollectionSpec, CollectionsFromManifest, DocumentSignal, FromJsonSchema, JsonSchema, JsonSchemaSpec, MaybePromise, MaybePromiseSubResult, ModelEntry, ModelManifest, PathModelsFromManifest, PrivateCollectionsFromManifest, PrivateSignalFromSpec, PublicSignal, LocalSignalFactory, RuntimeSignalConstructor, RuntimeSignalInstance, RootCollections, RootPrivateCollections, 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
|
+
export interface TeamplayPrivateCollections {
|
|
8
|
+
}
|
|
7
9
|
export interface TeamplayModels {
|
|
8
10
|
}
|
|
9
11
|
export interface TeamplaySignalFields {
|
|
10
12
|
}
|
|
13
|
+
export interface TeamplayPluginCollections {
|
|
14
|
+
}
|
|
15
|
+
export interface TeamplayPluginPrivateCollections {
|
|
16
|
+
}
|
|
17
|
+
export interface TeamplayPluginModels {
|
|
18
|
+
}
|
|
19
|
+
export interface TeamplayPluginSignalFields {
|
|
20
|
+
}
|
|
21
|
+
export interface TeamplayPluginOptions {
|
|
22
|
+
}
|
|
23
|
+
export interface TeamplayFeatures {
|
|
24
|
+
}
|
|
25
|
+
export type TeamplayPluginOption<TName extends string> = TName extends keyof TeamplayPluginOptions ? TeamplayPluginOptions[TName] : {};
|
|
26
|
+
export type TeamplayFeature<TName extends string> = TName extends keyof TeamplayFeatures ? TeamplayFeatures[TName] : unknown;
|
|
11
27
|
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, 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 };
|
|
28
|
+
export type { AnySignal, ArraySignal, CollectionDocument, CollectionDocumentModel, CollectionSignal, CollectionSpec, CollectionSignalFromSpec, CollectionAggregationSignal, CollectionQuerySignal, DocumentSignal, FromJsonSchema, JsonSchema, JsonSchemaSpec, MaybePromise, MaybePromiseSubResult, ModelEntry, ModelManifest, CollectionsFromManifest, PrivateCollectionsFromManifest, LocalSignalFactory, PathModelsFromManifest, PrivateSignalFromSpec, PublicSignal, RuntimeSignalConstructor, RuntimeSignalInstance, RootCollections, RootSignal, WildcardPathSegment, WildcardSignalPath, AppendPath, ComputedQueryParamsInput, JoinPath, QueryParams, QueryParamsInput, QuerySignal, RegisteredAggregationInput, RootPrivateCollections, SignalArrayMutatorMethods, SignalArrayReaderMethods, SignalBaseInstance, SignalClass, SignalChild, SignalConstructor, SignalCollectionMethods, SignalForKind, SignalKind, SignalMetadataMethods, SignalModelConstructor, SignalStringMutatorMethods, SignalValueMethods, SubResult, TypedAggregationInput, TypedAggregationSignal, TypedSignal, ZodLikeSchema, ZodSchemaSpec };
|
|
13
29
|
export interface ObserverOptions {
|
|
14
30
|
forwardRef?: boolean;
|
|
15
31
|
cache?: boolean;
|
|
@@ -36,14 +52,12 @@ export { defineModels, default as initModels, getModels, resetModelsForTests } f
|
|
|
36
52
|
export { default as signal } from './orm/getSignal.js';
|
|
37
53
|
export { GLOBAL_ROOT_ID } from './orm/Root.js';
|
|
38
54
|
export declare const $: RootSignal;
|
|
39
|
-
export declare const $root: RootSignal;
|
|
40
|
-
export declare const model: RootSignal;
|
|
41
55
|
export default $;
|
|
42
|
-
export { default as sub } from './orm/sub.js';
|
|
43
|
-
export {
|
|
56
|
+
export { default as sub, unsub } from './orm/sub.js';
|
|
57
|
+
export type { SubMode, SubOptions } from './orm/sub.js';
|
|
58
|
+
export { default as useSub, useAsyncSub, useBatchSub, setUseDeferredValue as __setUseDeferredValue, setDefaultDefer as __setDefaultDefer } from './react/useSub.js';
|
|
44
59
|
export { default as useSuspendMemo, useSuspendMemoByKey } from './react/useSuspendMemo.js';
|
|
45
60
|
export declare const observer: ObserverFunction;
|
|
46
|
-
export { useValue, useValue$, useModel, useLocal, useLocal$, useLocalDoc, useLocalDoc$, useSession, useSession$, usePage, usePage$, useBatch, useDoc, useDoc$, useBatchDoc, useBatchDoc$, useAsyncDoc, useAsyncDoc$, useQuery, useQuery$, useAsyncQuery, useAsyncQuery$, useBatchQuery, useBatchQuery$, useQueryIds, useBatchQueryIds, useAsyncQueryIds, useQueryDoc, useQueryDoc$, useBatchQueryDoc, useBatchQueryDoc$, useAsyncQueryDoc, useAsyncQueryDoc$ } from './orm/Compat/hooksCompat.js';
|
|
47
61
|
export { emit, useOn, useEmit } from './orm/Compat/eventsCompat.js';
|
|
48
62
|
export { useDidUpdate, useOnce, useSyncEffect } from './react/helpers.js';
|
|
49
63
|
export { connection, setConnection, getConnection, getDefaultFetchOnly, setDefaultFetchOnly, publicOnly, setPublicOnly } from './orm/connection.js';
|
|
@@ -54,7 +68,7 @@ export { GUID_PATTERN, defineSchema, hasMany, hasOne, hasManyFlags, belongsTo, p
|
|
|
54
68
|
export { aggregation, aggregationHeader as __aggregationHeader } from '@teamplay/utils/aggregation';
|
|
55
69
|
export { accessControl } from '@teamplay/utils/accessControl';
|
|
56
70
|
export type { AggregationCallback, AggregationContext, AggregationFunction, AggregationMeta, AggregationParams, AggregationQuery, ClientAggregationFunction, DefaultAggregationSession } from '@teamplay/utils/aggregation';
|
|
57
|
-
export type { AccessControl, AccessControlRules, AccessCreateContext, AccessDecision, AccessDeleteContext, AccessOperation, AccessReadContext, AccessRule, AccessUpdateContext, AccessValidator, AccessValidatorObject, DefaultAccessSession } from '@teamplay/utils/accessControl';
|
|
71
|
+
export type { AccessControl, AccessControlOptions, AccessControlRules, AccessCreateContext, AccessDecision, AccessDeleteContext, AccessOperation, AccessReadContext, AccessRule, AccessUpdateContext, AccessValidator, AccessValidatorObject, DefaultAccessSession } from '@teamplay/utils/accessControl';
|
|
58
72
|
export declare function batch(): undefined;
|
|
59
73
|
export declare function batch<TResult>(fn: () => TResult): TResult;
|
|
60
74
|
export declare function batchModel(): undefined;
|
|
@@ -63,4 +77,5 @@ export declare function serverOnly<TValue>(value: TValue): TValue;
|
|
|
63
77
|
export declare function clone<TValue>(value: TValue): TValue;
|
|
64
78
|
export declare function initLocalCollection(name: string): any;
|
|
65
79
|
export { useApi };
|
|
66
|
-
export declare function getRootSignal
|
|
80
|
+
export declare function getRootSignal(options?: Record<string, any>): RootSignal;
|
|
81
|
+
export declare function getRootSignal<TCollections extends Record<string, any>>(options?: Record<string, any>): RootSignal<TCollections>;
|
package/dist/index.js
CHANGED
|
@@ -13,14 +13,11 @@ export { default as signal } from "./orm/getSignal.js";
|
|
|
13
13
|
export { GLOBAL_ROOT_ID } from "./orm/Root.js";
|
|
14
14
|
const getRuntimeRootSignal = _getRootSignal;
|
|
15
15
|
export const $ = getRuntimeRootSignal({ rootId: GLOBAL_ROOT_ID, rootFunction: universal$ });
|
|
16
|
-
export const $root = $;
|
|
17
|
-
export const model = $;
|
|
18
16
|
export default $;
|
|
19
|
-
export { default as sub } from "./orm/sub.js";
|
|
20
|
-
export { default as useSub, useAsyncSub, setUseDeferredValue as __setUseDeferredValue, setDefaultDefer as __setDefaultDefer } from "./react/useSub.js";
|
|
17
|
+
export { default as sub, unsub } from "./orm/sub.js";
|
|
18
|
+
export { default as useSub, useAsyncSub, useBatchSub, setUseDeferredValue as __setUseDeferredValue, setDefaultDefer as __setDefaultDefer } from "./react/useSub.js";
|
|
21
19
|
export { default as useSuspendMemo, useSuspendMemoByKey } from "./react/useSuspendMemo.js";
|
|
22
20
|
export const observer = runtimeObserver;
|
|
23
|
-
export { useValue, useValue$, useModel, useLocal, useLocal$, useLocalDoc, useLocalDoc$, useSession, useSession$, usePage, usePage$, useBatch, useDoc, useDoc$, useBatchDoc, useBatchDoc$, useAsyncDoc, useAsyncDoc$, useQuery, useQuery$, useAsyncQuery, useAsyncQuery$, useBatchQuery, useBatchQuery$, useQueryIds, useBatchQueryIds, useAsyncQueryIds, useQueryDoc, useQueryDoc$, useBatchQueryDoc, useBatchQueryDoc$, useAsyncQueryDoc, useAsyncQueryDoc$ } from './orm/Compat/hooksCompat.js';
|
|
24
21
|
export { emit, useOn, useEmit } from './orm/Compat/eventsCompat.js';
|
|
25
22
|
export { useDidUpdate, useOnce, useSyncEffect } from "./react/helpers.js";
|
|
26
23
|
export { connection, setConnection, getConnection, getDefaultFetchOnly, setDefaultFetchOnly, publicOnly, setPublicOnly } from "./orm/connection.js";
|
|
@@ -3,15 +3,17 @@ import type {
|
|
|
3
3
|
QuerySubscriptions,
|
|
4
4
|
QuerySignalOptions
|
|
5
5
|
} from './Query.js'
|
|
6
|
+
import type { PathSegment } from './types/path.js'
|
|
6
7
|
|
|
7
8
|
export const IS_AGGREGATION: unique symbol
|
|
8
9
|
export const AGGREGATIONS: '$aggregations'
|
|
9
10
|
export const aggregationSubscriptions: QuerySubscriptions
|
|
10
11
|
export function getAggregationSignal (collectionName: string, params: unknown, options?: QuerySignalOptions): Signal
|
|
11
12
|
export function isAggregationSignal ($signal: unknown): boolean | undefined
|
|
13
|
+
export function getAggregationRowId (row: unknown, collectionName?: string): string | undefined
|
|
12
14
|
export function getAggregationDocId (
|
|
13
|
-
segments: readonly
|
|
15
|
+
segments: readonly PathSegment[],
|
|
14
16
|
rootId?: string,
|
|
15
|
-
method?: (path:
|
|
16
|
-
): string |
|
|
17
|
-
export function getAggregationCollectionName (segments: readonly
|
|
17
|
+
method?: (path: PathSegment[]) => unknown
|
|
18
|
+
): string | undefined
|
|
19
|
+
export function getAggregationCollectionName (segments: readonly PathSegment[]): string | undefined
|
package/dist/orm/Aggregation.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { raw } from '@nx-js/observer-util';
|
|
2
2
|
import { getRaw } from './dataTree.js';
|
|
3
3
|
import getSignal from "./getSignal.js";
|
|
4
|
-
import { QuerySubscriptions, hashQuery, Query, HASH, PARAMS, COLLECTION_NAME, parseQueryHash } from './Query.js';
|
|
4
|
+
import { QuerySubscriptions, hashQuery, Query, cloneQueryParams, HASH, PARAMS, COLLECTION_NAME, parseQueryHash } from './Query.js';
|
|
5
5
|
import Signal, { SEGMENTS } from "./Signal.js";
|
|
6
6
|
import { getIdFieldsForSegments, isPlainObject } from "./idFields.js";
|
|
7
7
|
import { delPrivateData, getPrivateData, setPrivateData } from './privateData.js';
|
|
8
8
|
import { setSignalRuntimeDescriptor } from "./signalRuntimeDescriptor.js";
|
|
9
9
|
export const IS_AGGREGATION = Symbol('is aggregation signal');
|
|
10
10
|
export const AGGREGATIONS = '$aggregations';
|
|
11
|
+
const DEFAULT_AGGREGATION_ID_FIELDS = ['_id', 'id'];
|
|
11
12
|
class Aggregation extends Query {
|
|
12
13
|
_initData() {
|
|
13
14
|
this._syncAllRootsData();
|
|
@@ -39,21 +40,31 @@ aggregationSubscriptions.runtimeKind = 'aggregation';
|
|
|
39
40
|
function injectAggregationIds(extra, collectionName) {
|
|
40
41
|
if (!Array.isArray(extra))
|
|
41
42
|
return;
|
|
42
|
-
const idFields =
|
|
43
|
+
const idFields = getCollectionIdFields(collectionName);
|
|
43
44
|
for (const doc of extra) {
|
|
44
45
|
if (!isPlainObject(doc))
|
|
45
46
|
continue;
|
|
46
|
-
const docId = doc
|
|
47
|
+
const docId = getAggregationRowId(doc, collectionName);
|
|
47
48
|
if (docId == null)
|
|
48
49
|
continue;
|
|
49
|
-
|
|
50
|
-
doc
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
for (const field of idFields) {
|
|
51
|
+
if (doc[field] !== docId)
|
|
52
|
+
doc[field] = docId;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function getAggregationRowId(row, collectionName) {
|
|
57
|
+
if (!isPlainObject(row))
|
|
58
|
+
return;
|
|
59
|
+
const idFields = getAggregationIdFields(collectionName);
|
|
60
|
+
for (const field of idFields) {
|
|
61
|
+
const value = row[field];
|
|
62
|
+
if (typeof value === 'string')
|
|
63
|
+
return value;
|
|
53
64
|
}
|
|
54
65
|
}
|
|
55
66
|
export function getAggregationSignal(collectionName, params, options) {
|
|
56
|
-
params =
|
|
67
|
+
params = cloneQueryParams(collectionName, params);
|
|
57
68
|
const transportHash = hashQuery(collectionName, params);
|
|
58
69
|
const { root, signalOptions } = parseAggregationSignalOptions(options);
|
|
59
70
|
const $aggregation = getSignal(root, [AGGREGATIONS, transportHash], signalOptions);
|
|
@@ -80,7 +91,7 @@ export function isAggregationSignal($signal) {
|
|
|
80
91
|
return true;
|
|
81
92
|
}
|
|
82
93
|
// example: ['$aggregations', '{"active":true}', 42]
|
|
83
|
-
// AND only if
|
|
94
|
+
// AND only if the aggregation row carries a source document id field
|
|
84
95
|
export function getAggregationDocId(segments, rootId, method) {
|
|
85
96
|
if (!(segments.length >= 3))
|
|
86
97
|
return;
|
|
@@ -88,11 +99,16 @@ export function getAggregationDocId(segments, rootId, method) {
|
|
|
88
99
|
return;
|
|
89
100
|
if (!(typeof segments[2] === 'number'))
|
|
90
101
|
return;
|
|
102
|
+
const collectionName = getAggregationCollectionName(segments);
|
|
103
|
+
const idFields = getAggregationIdFields(collectionName);
|
|
91
104
|
if (typeof method !== 'function') {
|
|
92
105
|
method = path => rootId == null ? getRaw(path) : getPrivateData(rootId, path);
|
|
93
106
|
}
|
|
94
|
-
|
|
95
|
-
|
|
107
|
+
for (const field of idFields) {
|
|
108
|
+
const id = method([...segments.slice(0, 3), field]);
|
|
109
|
+
if (typeof id === 'string')
|
|
110
|
+
return id;
|
|
111
|
+
}
|
|
96
112
|
}
|
|
97
113
|
export function getAggregationCollectionName(segments) {
|
|
98
114
|
if (!(segments.length >= 2))
|
|
@@ -113,3 +129,15 @@ function parseAggregationSignalOptions(options) {
|
|
|
113
129
|
const { root, ...signalOptions } = options;
|
|
114
130
|
return { root, signalOptions };
|
|
115
131
|
}
|
|
132
|
+
function getAggregationIdFields(collectionName) {
|
|
133
|
+
const idFields = getCollectionIdFields(collectionName);
|
|
134
|
+
return uniq(idFields.concat(DEFAULT_AGGREGATION_ID_FIELDS));
|
|
135
|
+
}
|
|
136
|
+
function getCollectionIdFields(collectionName) {
|
|
137
|
+
return collectionName
|
|
138
|
+
? getIdFieldsForSegments([collectionName, ''])
|
|
139
|
+
: [];
|
|
140
|
+
}
|
|
141
|
+
function uniq(values) {
|
|
142
|
+
return Array.from(new Set(values));
|
|
143
|
+
}
|