teamplay 0.4.0-alpha.0 → 0.4.0-alpha.1

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/index.d.ts CHANGED
@@ -28,6 +28,8 @@ export function observer<
28
28
 
29
29
  // Keep existing public surface available even if typed loosely for now.
30
30
  export const $: any
31
+ export const $root: any
32
+ export const model: any
31
33
  export { default as Signal, SEGMENTS } from './orm/Signal.js'
32
34
  export { __DEBUG_SIGNALS_CACHE__, rawSignal, getSignalClass } from './orm/getSignal.js'
33
35
  export { default as addModel } from './orm/addModel.js'
@@ -40,6 +42,46 @@ export {
40
42
  setUseDeferredValue as __setUseDeferredValue,
41
43
  setDefaultDefer as __setDefaultDefer
42
44
  } from './react/useSub.js'
45
+ export function useValue (defaultValue?: any): [any, any]
46
+ export function useValue$ (defaultValue?: any): any
47
+ export function useModel (path?: any): any
48
+ export function useLocal (path?: any): [any, any]
49
+ export function useLocal$ (path?: any): any
50
+ export function useSession (path?: any): [any, any]
51
+ export function useSession$ (path?: any): any
52
+ export function usePage (path?: any): [any, any]
53
+ export function usePage$ (path?: any): any
54
+ export function useBatch (): void
55
+ export function useDoc (collection: string, id: any, options?: any): [any, any]
56
+ export function useDoc$ (collection: string, id: any, options?: any): any
57
+ export function useBatchDoc (collection: string, id: any, options?: any): [any, any]
58
+ export function useBatchDoc$ (collection: string, id: any, options?: any): any
59
+ export function useAsyncDoc (collection: string, id: any, options?: any): [any, any]
60
+ export function useAsyncDoc$ (collection: string, id: any, options?: any): any
61
+ export function useQuery (collection: string, query: any, options?: any): [any, any]
62
+ export function useQuery$ (collection: string, query: any, options?: any): any
63
+ export function useAsyncQuery (collection: string, query: any, options?: any): [any, any]
64
+ export function useAsyncQuery$ (collection: string, query: any, options?: any): any
65
+ export function useBatchQuery (collection: string, query: any, options?: any): [any, any]
66
+ export function useBatchQuery$ (collection: string, query: any, options?: any): any
67
+ export function useQueryIds (collection: string, ids?: any[], options?: any): [any, any]
68
+ export function useBatchQueryIds (collection: string, ids?: any[], options?: any): [any, any]
69
+ export function useAsyncQueryIds (collection: string, ids?: any[], options?: any): [any, any]
70
+ export function useQueryDoc (collection: string, query: any, options?: any): [any, any]
71
+ export function useQueryDoc$ (collection: string, query: any, options?: any): any
72
+ export function useBatchQueryDoc (collection: string, query: any, options?: any): [any, any]
73
+ export function useBatchQueryDoc$ (collection: string, query: any, options?: any): any
74
+ export function useAsyncQueryDoc (collection: string, query: any, options?: any): [any, any]
75
+ export function useAsyncQueryDoc$ (collection: string, query: any, options?: any): any
76
+ export function emit (eventName: string, ...args: any[]): void
77
+ export function useOn (
78
+ eventName: 'change' | 'all',
79
+ pattern: string | { path: () => string },
80
+ handler: (...args: any[]) => void,
81
+ deps?: any[]
82
+ ): void
83
+ export function useOn (eventName: string, handler: (...args: any[]) => void, deps?: any[]): void
84
+ export function useEmit (): (eventName: string, ...args: any[]) => void
43
85
  export { connection, setConnection, getConnection, fetchOnly, setFetchOnly, publicOnly, setPublicOnly } from './orm/connection.js'
44
86
  export { useId, useNow, useScheduleUpdate, useTriggerUpdate } from './react/helpers.js'
45
87
  export { GUID_PATTERN, hasMany, hasOne, hasManyFlags, belongsTo, pickFormFields } from '@teamplay/schema'
package/index.js CHANGED
@@ -12,6 +12,8 @@ export { default as addModel } from './orm/addModel.js'
12
12
  export { default as signal } from './orm/getSignal.js'
13
13
  export { GLOBAL_ROOT_ID } from './orm/Root.js'
14
14
  export const $ = _getRootSignal({ rootId: GLOBAL_ROOT_ID, rootFunction: universal$ })
15
+ export const $root = $
16
+ export const model = $
15
17
  export default $
16
18
  export { default as sub } from './orm/sub.js'
17
19
  export {
@@ -21,6 +23,40 @@ export {
21
23
  setDefaultDefer as __setDefaultDefer
22
24
  } from './react/useSub.js'
23
25
  export { default as observer } from './react/observer.js'
26
+ export {
27
+ useValue,
28
+ useValue$,
29
+ useModel,
30
+ useLocal,
31
+ useLocal$,
32
+ useSession,
33
+ useSession$,
34
+ usePage,
35
+ usePage$,
36
+ useBatch,
37
+ useDoc,
38
+ useDoc$,
39
+ useBatchDoc,
40
+ useBatchDoc$,
41
+ useAsyncDoc,
42
+ useAsyncDoc$,
43
+ useQuery,
44
+ useQuery$,
45
+ useAsyncQuery,
46
+ useAsyncQuery$,
47
+ useBatchQuery,
48
+ useBatchQuery$,
49
+ useQueryIds,
50
+ useBatchQueryIds,
51
+ useAsyncQueryIds,
52
+ useQueryDoc,
53
+ useQueryDoc$,
54
+ useBatchQueryDoc,
55
+ useBatchQueryDoc$,
56
+ useAsyncQueryDoc,
57
+ useAsyncQueryDoc$
58
+ } from './orm/Compat/hooksCompat.js'
59
+ export { emit, useOn, useEmit } from './orm/Compat/eventsCompat.js'
24
60
  export { connection, setConnection, getConnection, fetchOnly, setFetchOnly, publicOnly, setPublicOnly } from './orm/connection.js'
25
61
  export { useId, useNow, useScheduleUpdate, useTriggerUpdate } from './react/helpers.js'
26
62
  export { GUID_PATTERN, hasMany, hasOne, hasManyFlags, belongsTo, pickFormFields } from '@teamplay/schema'
@@ -3,6 +3,7 @@ import { set as _set, del as _del, getRaw } from './dataTree.js'
3
3
  import getSignal from './getSignal.js'
4
4
  import { QuerySubscriptions, hashQuery, Query, HASH, PARAMS, COLLECTION_NAME, parseQueryHash } from './Query.js'
5
5
  import Signal, { SEGMENTS } from './Signal.js'
6
+ import { getIdFieldsForSegments, isPlainObject } from './idFields.js'
6
7
 
7
8
  export const IS_AGGREGATION = Symbol('is aggregation signal')
8
9
  export const AGGREGATIONS = '$aggregations'
@@ -11,11 +12,13 @@ class Aggregation extends Query {
11
12
  _initData () {
12
13
  {
13
14
  const extra = raw(this.shareQuery.extra)
15
+ injectAggregationIds(extra, this.collectionName)
14
16
  _set([AGGREGATIONS, this.hash], extra)
15
17
  }
16
18
 
17
19
  this.shareQuery.on('extra', extra => {
18
20
  extra = raw(extra)
21
+ injectAggregationIds(extra, this.collectionName)
19
22
  _set([AGGREGATIONS, this.hash], extra)
20
23
  })
21
24
  }
@@ -27,6 +30,18 @@ class Aggregation extends Query {
27
30
 
28
31
  export const aggregationSubscriptions = new QuerySubscriptions(Aggregation)
29
32
 
33
+ function injectAggregationIds (extra, collectionName) {
34
+ if (!Array.isArray(extra)) return
35
+ const idFields = getIdFieldsForSegments([collectionName, ''])
36
+ for (const doc of extra) {
37
+ if (!isPlainObject(doc)) continue
38
+ const docId = doc._id ?? doc.id
39
+ if (docId == null) continue
40
+ if (idFields.includes('_id') && doc._id !== docId) doc._id = docId
41
+ if (idFields.includes('id') && doc.id !== docId) doc.id = docId
42
+ }
43
+ }
44
+
30
45
  export function getAggregationSignal (collectionName, params, options) {
31
46
  params = JSON.parse(JSON.stringify(params))
32
47
  const hash = hashQuery(collectionName, params)