teamplay 0.5.0-alpha.3 → 0.5.0-alpha.31
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/config.d.ts +2 -0
- package/dist/config.js +1 -0
- package/dist/connect/index.d.ts +1 -1
- package/dist/connect/index.js +6 -2
- package/dist/connect/offline/index.d.ts +1 -1
- package/dist/connect/offline/index.js +8 -4
- package/dist/connect/offline/react-native.d.ts +1 -1
- package/dist/connect/offline/web.d.ts +1 -1
- package/dist/connect/test.d.ts +1 -1
- package/dist/connect/test.js +5 -1
- package/dist/index.d.ts +26 -9
- package/dist/index.js +3 -5
- package/dist/orm/Aggregation.d.ts +6 -4
- package/dist/orm/Aggregation.js +39 -11
- package/dist/orm/Compat/SignalCompat.js +150 -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 +30 -3
- package/dist/orm/SignalBase.js +302 -13
- 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/idFields.d.ts +10 -1
- package/dist/orm/idFields.js +102 -14
- 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 +2 -2
- package/dist/server.js +4 -1
- package/package.json +21 -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/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TEAMPLAY_RUNTIME_CONFIG_SYMBOL, configureTeamplay, getTeamplayConfig, getDefaultIdFields, setDefaultIdFields } from "./orm/idFields.js";
|
package/dist/connect/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function connect(options
|
|
1
|
+
export default function connect(options?: {}): void;
|
package/dist/connect/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import Socket from '@teamplay/channel';
|
|
2
2
|
import Connection from './sharedbConnection.cjs';
|
|
3
3
|
import { connection, setConnection } from "../orm/connection.js";
|
|
4
|
-
|
|
4
|
+
import { configureTeamplay } from "../config.js";
|
|
5
|
+
export default function connect(options = {}) {
|
|
6
|
+
const { idFields, ...socketOptions } = options || {};
|
|
7
|
+
if (idFields !== undefined)
|
|
8
|
+
configureTeamplay({ idFields });
|
|
5
9
|
if (connection)
|
|
6
10
|
return;
|
|
7
|
-
const socket = new Socket(
|
|
11
|
+
const socket = new Socket(socketOptions);
|
|
8
12
|
setConnection(new Connection(socket));
|
|
9
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function createConnectWithPersistence({ storage, createPubsub }?: {}): () => Promise<void>;
|
|
1
|
+
export default function createConnectWithPersistence({ storage, createPubsub }?: {}): (options?: {}) => Promise<void>;
|
|
@@ -3,21 +3,25 @@
|
|
|
3
3
|
import ShareDbMingo from '@startupjs/sharedb-mingo-memory';
|
|
4
4
|
import ShareBackend from 'sharedb';
|
|
5
5
|
import { connection, setConnection } from "../../orm/connection.js";
|
|
6
|
+
import { configureTeamplay } from "../../config.js";
|
|
6
7
|
const STORAGE_NAMESPACE = 'teamplay-offline';
|
|
7
8
|
const DOCS_PREFIX = `${STORAGE_NAMESPACE}:docs:`;
|
|
8
9
|
const LAST_OP_PREFIX = `${STORAGE_NAMESPACE}:last-op:`;
|
|
9
10
|
export default function createConnectWithPersistence({ storage, createPubsub } = {}) {
|
|
10
11
|
if (!storage)
|
|
11
12
|
throw new Error('[connect-offline] storage is required');
|
|
12
|
-
return async function connect() {
|
|
13
|
+
return async function connect(options = {}) {
|
|
14
|
+
const { idFields } = options || {};
|
|
15
|
+
if (idFields !== undefined)
|
|
16
|
+
configureTeamplay({ idFields });
|
|
13
17
|
if (connection)
|
|
14
18
|
return;
|
|
15
19
|
const db = new ShareDbMingo();
|
|
16
|
-
const
|
|
20
|
+
const backendOptions = { db };
|
|
17
21
|
const { pubsub } = (await init(db, storage, createPubsub)) || {};
|
|
18
22
|
if (pubsub)
|
|
19
|
-
|
|
20
|
-
const backend = new ShareBackend(
|
|
23
|
+
backendOptions.pubsub = pubsub;
|
|
24
|
+
const backend = new ShareBackend(backendOptions);
|
|
21
25
|
setConnection(backend.connect());
|
|
22
26
|
};
|
|
23
27
|
}
|
|
@@ -3,7 +3,7 @@ export namespace storage {
|
|
|
3
3
|
export { setItem };
|
|
4
4
|
export { iterate };
|
|
5
5
|
}
|
|
6
|
-
declare const _default: () => Promise<void>;
|
|
6
|
+
declare const _default: (options?: {}) => Promise<void>;
|
|
7
7
|
export default _default;
|
|
8
8
|
declare function getItem(key: any): Promise<any>;
|
|
9
9
|
declare function setItem(key: any, value: any): Promise<any>;
|
|
@@ -4,6 +4,6 @@ export namespace storage {
|
|
|
4
4
|
function setItem(key: any, value: any): Promise<any>;
|
|
5
5
|
function iterate(iterator: any): Promise<any>;
|
|
6
6
|
}
|
|
7
|
-
declare const _default: () => Promise<void>;
|
|
7
|
+
declare const _default: (options?: {}) => Promise<void>;
|
|
8
8
|
export default _default;
|
|
9
9
|
import SharedbCrosstabPubsub from '../lib/sharedb-crosstab-pubsub.cjs';
|
package/dist/connect/test.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function connect(): void;
|
|
1
|
+
export default function connect(options?: {}): void;
|
package/dist/connect/test.js
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
import ShareDbMingo from '@startupjs/sharedb-mingo-memory';
|
|
5
5
|
import ShareBackend from 'sharedb';
|
|
6
6
|
import { connection, setConnection } from "../orm/connection.js";
|
|
7
|
-
|
|
7
|
+
import { configureTeamplay } from "../config.js";
|
|
8
|
+
export default function connect(options = {}) {
|
|
9
|
+
const { idFields } = options || {};
|
|
10
|
+
if (idFields !== undefined)
|
|
11
|
+
configureTeamplay({ idFields });
|
|
8
12
|
if (connection)
|
|
9
13
|
return;
|
|
10
14
|
const backend = new ShareBackend({ db: new ShareDbMingo() });
|
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,25 +52,25 @@ 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';
|
|
50
64
|
export type { TeamplayConnection, TeamplayShareDoc } from './orm/connection.js';
|
|
65
|
+
export { TEAMPLAY_RUNTIME_CONFIG_SYMBOL, configureTeamplay, getTeamplayConfig, getDefaultIdFields, setDefaultIdFields } from './config.js';
|
|
66
|
+
export type { IdField, IdFields, TeamplayRuntimeConfig } from './config.js';
|
|
51
67
|
export { getSubscriptionGcDelay, setSubscriptionGcDelay } from './orm/subscriptionGcDelay.js';
|
|
52
68
|
export { useId, useNow, useScheduleUpdate, useTriggerUpdate } from './react/helpers.js';
|
|
53
69
|
export { GUID_PATTERN, defineSchema, hasMany, hasOne, hasManyFlags, belongsTo, pickFormFields } from '@teamplay/schema';
|
|
54
70
|
export { aggregation, aggregationHeader as __aggregationHeader } from '@teamplay/utils/aggregation';
|
|
55
71
|
export { accessControl } from '@teamplay/utils/accessControl';
|
|
56
72
|
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';
|
|
73
|
+
export type { AccessControl, AccessControlOptions, AccessControlRules, AccessCreateContext, AccessDecision, AccessDeleteContext, AccessOperation, AccessReadContext, AccessRule, AccessUpdateContext, AccessValidator, AccessValidatorObject, DefaultAccessSession } from '@teamplay/utils/accessControl';
|
|
58
74
|
export declare function batch(): undefined;
|
|
59
75
|
export declare function batch<TResult>(fn: () => TResult): TResult;
|
|
60
76
|
export declare function batchModel(): undefined;
|
|
@@ -63,4 +79,5 @@ export declare function serverOnly<TValue>(value: TValue): TValue;
|
|
|
63
79
|
export declare function clone<TValue>(value: TValue): TValue;
|
|
64
80
|
export declare function initLocalCollection(name: string): any;
|
|
65
81
|
export { useApi };
|
|
66
|
-
export declare function getRootSignal
|
|
82
|
+
export declare function getRootSignal(options?: Record<string, any>): RootSignal;
|
|
83
|
+
export declare function getRootSignal<TCollections extends Record<string, any>>(options?: Record<string, any>): RootSignal<TCollections>;
|
package/dist/index.js
CHANGED
|
@@ -13,17 +13,15 @@ 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";
|
|
24
|
+
export { TEAMPLAY_RUNTIME_CONFIG_SYMBOL, configureTeamplay, getTeamplayConfig, getDefaultIdFields, setDefaultIdFields } from "./config.js";
|
|
27
25
|
export { getSubscriptionGcDelay, setSubscriptionGcDelay } from "./orm/subscriptionGcDelay.js";
|
|
28
26
|
export { useId, useNow, useScheduleUpdate, useTriggerUpdate } from "./react/helpers.js";
|
|
29
27
|
export { GUID_PATTERN, defineSchema, hasMany, hasOne, hasManyFlags, belongsTo, pickFormFields } from '@teamplay/schema';
|
|
@@ -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
|
+
}
|