@contember/binding 1.1.0-alpha.2 → 1.1.0-alpha.3

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.
Files changed (55) hide show
  1. package/dist/development/accessorPropagation/useExtendTree.js +4 -2
  2. package/dist/development/accessorPropagation/useExtendTree.js.map +1 -1
  3. package/dist/development/core/TreeStore.js +2 -2
  4. package/dist/development/core/TreeStore.js.map +1 -1
  5. package/dist/development/dao/Environment.js +11 -1
  6. package/dist/development/dao/Environment.js.map +1 -1
  7. package/dist/development/helperComponents/DeferredSubTrees.js +4 -2
  8. package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
  9. package/dist/development/helperComponents/If.js +1 -1
  10. package/dist/development/helperComponents/If.js.map +1 -1
  11. package/dist/development/markers/EntityListSubTreeMarker.js +1 -1
  12. package/dist/development/markers/EntityListSubTreeMarker.js.map +1 -1
  13. package/dist/development/markers/EntitySubTreeMarker.js +1 -1
  14. package/dist/development/markers/EntitySubTreeMarker.js.map +1 -1
  15. package/dist/development/markers/PlaceholderGenerator.js +4 -4
  16. package/dist/development/markers/PlaceholderGenerator.js.map +1 -1
  17. package/dist/development/utils/Hashing.js +21 -6
  18. package/dist/development/utils/Hashing.js.map +1 -1
  19. package/dist/production/accessorPropagation/useExtendTree.js +4 -2
  20. package/dist/production/accessorPropagation/useExtendTree.js.map +1 -1
  21. package/dist/production/core/TreeStore.js +2 -2
  22. package/dist/production/core/TreeStore.js.map +1 -1
  23. package/dist/production/dao/Environment.js +11 -1
  24. package/dist/production/dao/Environment.js.map +1 -1
  25. package/dist/production/helperComponents/DeferredSubTrees.js +4 -2
  26. package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
  27. package/dist/production/helperComponents/If.js +1 -1
  28. package/dist/production/helperComponents/If.js.map +1 -1
  29. package/dist/production/markers/EntityListSubTreeMarker.js +1 -1
  30. package/dist/production/markers/EntityListSubTreeMarker.js.map +1 -1
  31. package/dist/production/markers/EntitySubTreeMarker.js +1 -1
  32. package/dist/production/markers/EntitySubTreeMarker.js.map +1 -1
  33. package/dist/production/markers/PlaceholderGenerator.js +4 -4
  34. package/dist/production/markers/PlaceholderGenerator.js.map +1 -1
  35. package/dist/production/utils/Hashing.js +21 -6
  36. package/dist/production/utils/Hashing.js.map +1 -1
  37. package/dist/types/accessorPropagation/useExtendTree.d.ts.map +1 -1
  38. package/dist/types/core/TreeStore.d.ts.map +1 -1
  39. package/dist/types/dao/Environment.d.ts +2 -0
  40. package/dist/types/dao/Environment.d.ts.map +1 -1
  41. package/dist/types/markers/PlaceholderGenerator.d.ts +3 -2
  42. package/dist/types/markers/PlaceholderGenerator.d.ts.map +1 -1
  43. package/dist/types/tsconfig.tsbuildinfo +1 -1
  44. package/dist/types/utils/Hashing.d.ts +3 -2
  45. package/dist/types/utils/Hashing.d.ts.map +1 -1
  46. package/package.json +7 -5
  47. package/src/accessorPropagation/useExtendTree.ts +4 -2
  48. package/src/core/TreeStore.ts +2 -0
  49. package/src/dao/Environment.ts +12 -1
  50. package/src/helperComponents/DeferredSubTrees.tsx +4 -4
  51. package/src/helperComponents/If.tsx +1 -1
  52. package/src/markers/EntityListSubTreeMarker.ts +1 -1
  53. package/src/markers/EntitySubTreeMarker.ts +1 -1
  54. package/src/markers/PlaceholderGenerator.ts +5 -2
  55. package/src/utils/Hashing.ts +23 -8
@@ -1 +1 @@
1
- {"version":3,"file":"Hashing.d.ts","sourceRoot":"","sources":["../../../src/utils/Hashing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,eAAe,EACf,cAAc,EAEd,mBAAmB,EACnB,qBAAqB,EACrB,gCAAgC,EAChC,kCAAkC,EAElC,MAAM,mBAAmB,CAAA;AAG1B,qBAAa,OAAO;WACL,kBAAkB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM;WAWpD,mBAAmB,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM;WAatD,+BAA+B,CAC5C,UAAU,EAAE,mBAAmB,GAAG,gCAAgC,GAChE,MAAM;WAcK,2BAA2B,CACxC,UAAU,EAAE,qBAAqB,GAAG,kCAAkC,GACpE,MAAM;IAOT,OAAO,CAAC,MAAM,CAAC,SAAS;WAMV,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAWvC"}
1
+ {"version":3,"file":"Hashing.d.ts","sourceRoot":"","sources":["../../../src/utils/Hashing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,gCAAgC,EAChC,kCAAkC,EAClC,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAGpC,qBAAa,OAAO;WACL,kBAAkB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM;WAWpD,mBAAmB,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM;WAatD,+BAA+B,CAC5C,UAAU,EAAE,mBAAmB,GAAG,gCAAgC,EAClE,WAAW,EAAE,WAAW,GACtB,MAAM;WAmBK,2BAA2B,CACxC,UAAU,EAAE,qBAAqB,GAAG,kCAAkC,EACtE,WAAW,EAAE,WAAW,GACtB,MAAM;IAiBT,OAAO,CAAC,MAAM,CAAC,SAAS;WAMV,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAWvC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contember/binding",
3
3
  "license": "Apache-2.0",
4
- "version": "1.1.0-alpha.2",
4
+ "version": "1.1.0-alpha.3",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "./dist/production/index.js",
@@ -19,10 +19,10 @@
19
19
  ],
20
20
  "typings": "./dist/types/index.d.ts",
21
21
  "dependencies": {
22
- "@contember/client": "1.1.0-alpha.2",
23
- "@contember/react-client": "1.1.0-alpha.2",
24
- "@contember/react-multipass-rendering": "1.1.0-alpha.2",
25
- "@contember/react-utils": "1.1.0-alpha.2",
22
+ "@contember/client": "1.1.0-alpha.3",
23
+ "@contember/react-client": "1.1.0-alpha.3",
24
+ "@contember/react-multipass-rendering": "1.1.0-alpha.3",
25
+ "@contember/react-utils": "1.1.0-alpha.3",
26
26
  "chevrotain": "6.5.0",
27
27
  "fast-deep-equal": "^3.1.3",
28
28
  "js-levenshtein": "1.1.6",
@@ -42,6 +42,8 @@
42
42
  "build": "pnpm run build:js:dev && pnpm run build:js:prod",
43
43
  "build:js:dev": "vite build --mode development",
44
44
  "build:js:prod": "vite build --mode production",
45
+ "ae:build": "api-extractor run --local",
46
+ "ae:test": "api-extractor run",
45
47
  "test": "vitest"
46
48
  }
47
49
  }
@@ -4,15 +4,17 @@ import { useBindingOperations } from './useBindingOperations'
4
4
  import { TreeRootId } from '../treeParameters'
5
5
  import { ExtendTreeOptions } from '../accessors'
6
6
  import { DataBindingExtendAborted } from '../core'
7
+ import { useEnvironment } from './useEnvironment'
7
8
 
8
9
  export const useExtendTree = () => {
9
10
  const abort = useAbortController()
10
11
  const { extendTree } = useBindingOperations()
11
12
  const isMountedRef = useIsMounted()
13
+ const environment = useEnvironment()
12
14
  return useCallback(async (newFragment: ReactNode, options?: Omit<ExtendTreeOptions, 'signal'>): Promise<TreeRootId | undefined> => {
13
15
  try {
14
16
  const newTreeRootId = await extendTree(newFragment,
15
- { ...options, signal: abort() },
17
+ { environment, ...options, signal: abort() },
16
18
  )
17
19
  if (!isMountedRef.current) {
18
20
  return
@@ -24,5 +26,5 @@ export const useExtendTree = () => {
24
26
  }
25
27
  throw e
26
28
  }
27
- }, [abort, extendTree, isMountedRef])
29
+ }, [abort, environment, extendTree, isMountedRef])
28
30
  }
@@ -174,6 +174,7 @@ export class TreeStore {
174
174
  environment,
175
175
  )
176
176
  : QueryLanguage.desugarQualifiedEntityList(aliasOrParameters as SugaredQualifiedEntityList, environment),
177
+ environment,
177
178
  )
178
179
  } else if (mode === 'entity') {
179
180
  placeholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(
@@ -183,6 +184,7 @@ export class TreeStore {
183
184
  environment,
184
185
  )
185
186
  : QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters as SugaredQualifiedSingleEntity, environment),
187
+ environment,
186
188
  )
187
189
  } else {
188
190
  throw new BindingError()
@@ -107,7 +107,15 @@ class Environment {
107
107
  newVariables[newName] = resolvedValue
108
108
  }
109
109
  }
110
- return new Environment({ ...this.options, variables: newVariables })
110
+ return new Environment({
111
+ ...this.options,
112
+ variables: newVariables,
113
+ parent: this,
114
+ })
115
+ }
116
+
117
+ public getAllVariables() {
118
+ return this.options.variables
111
119
  }
112
120
 
113
121
  public hasParameter(key: string): boolean {
@@ -125,6 +133,9 @@ class Environment {
125
133
  return this.options.parameters[key] ?? fallback
126
134
  }
127
135
 
136
+ public getAllParameters() {
137
+ return this.options.parameters
138
+ }
128
139
 
129
140
  public withParameters(parameters: Environment.Parameters): Environment {
130
141
  return new Environment({ ...this.options, parameters })
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, useCallback, useEffect, useState } from 'react'
2
- import { TreeRootIdProvider, useBindingOperations } from '../accessorPropagation'
2
+ import { TreeRootIdProvider, useBindingOperations, useEnvironment } from '../accessorPropagation'
3
3
  import { useMutationState } from '../accessorTree'
4
4
  import { Component } from '../coreComponents'
5
5
  import { useEntityBeforePersist } from '../entityEvents'
@@ -29,7 +29,7 @@ export const DeferredSubTrees = Component<DeferredSubTreesProps>(
29
29
 
30
30
  const [abortController] = useState(() => new AbortController())
31
31
  const signal = abortController.signal
32
-
32
+ const environment = useEnvironment()
33
33
  useEntityBeforePersist(
34
34
  useCallback(getAccessor => {
35
35
  // This is a hack. We're really just circumventing the change of ids after a creation so that nested
@@ -55,7 +55,7 @@ export const DeferredSubTrees = Component<DeferredSubTreesProps>(
55
55
 
56
56
  const newFragment = <OnlyKeepSubTrees>{props.children}</OnlyKeepSubTrees>
57
57
 
58
- extendTree(newFragment, { signal })
58
+ extendTree(newFragment, { signal, environment })
59
59
  .then(treeRootId => !signal.aborted && setLoadState({ name: 'success', treeRootId }))
60
60
  .catch(error => {
61
61
  if (signal.aborted) {
@@ -63,7 +63,7 @@ export const DeferredSubTrees = Component<DeferredSubTreesProps>(
63
63
  }
64
64
  throw error
65
65
  })
66
- }, [extendTree, isMutating, loadState.name, props.children, signal])
66
+ }, [environment, extendTree, isMutating, loadState.name, props.children, signal])
67
67
 
68
68
  switch (loadState.name) {
69
69
  case 'initial':
@@ -25,7 +25,7 @@ export interface IfCallbackProps {
25
25
  export const If = Component<IfProps>(props => {
26
26
  return typeof props.condition !== 'function'
27
27
  ? <IfFilter condition={props.condition}>{props.children}</IfFilter>
28
- : <IfCallback condition={props.condition}>{props.condition}</IfCallback>
28
+ : <IfCallback condition={props.condition}>{props.children}</IfCallback>
29
29
  },
30
30
  'If',
31
31
  )
@@ -11,7 +11,7 @@ export class EntityListSubTreeMarker {
11
11
  public readonly fields: EntityFieldMarkersContainer,
12
12
  public readonly environment: Environment,
13
13
  ) {
14
- this.placeholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(this.parameters)
14
+ this.placeholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(this.parameters, this.environment)
15
15
  }
16
16
 
17
17
  public get entityName() {
@@ -11,7 +11,7 @@ export class EntitySubTreeMarker {
11
11
  public readonly fields: EntityFieldMarkersContainer,
12
12
  public readonly environment: Environment,
13
13
  ) {
14
- this.placeholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(this.parameters)
14
+ this.placeholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(this.parameters, this.environment)
15
15
  }
16
16
 
17
17
  public get entityName() {
@@ -8,6 +8,7 @@ import type {
8
8
  UnconstrainedQualifiedSingleEntity,
9
9
  } from '../treeParameters'
10
10
  import { Hashing } from '../utils'
11
+ import { Environment } from '../dao'
11
12
 
12
13
  export class PlaceholderGenerator {
13
14
  public static getFieldPlaceholder(fieldName: FieldName): string {
@@ -24,13 +25,15 @@ export class PlaceholderGenerator {
24
25
 
25
26
  public static getEntitySubTreePlaceholder(
26
27
  subTreeParameters: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,
28
+ environment: Environment,
27
29
  ): string {
28
- return `est_${Hashing.hashEntitySubTreeParameters(subTreeParameters)}`
30
+ return `est_${Hashing.hashEntitySubTreeParameters(subTreeParameters, environment)}`
29
31
  }
30
32
 
31
33
  public static getEntityListSubTreePlaceholder(
32
34
  subTreeParameters: QualifiedEntityList | UnconstrainedQualifiedEntityList,
35
+ environment: Environment,
33
36
  ): string {
34
- return `lst_${Hashing.hashEntityListSubTreeParameters(subTreeParameters)}`
37
+ return `lst_${Hashing.hashEntityListSubTreeParameters(subTreeParameters, environment)}`
35
38
  }
36
39
  }
@@ -1,19 +1,17 @@
1
1
  import type {
2
- Filter,
3
2
  HasManyRelation,
4
3
  HasOneRelation,
5
- OrderBy,
6
4
  QualifiedEntityList,
7
5
  QualifiedSingleEntity,
8
6
  UnconstrainedQualifiedEntityList,
9
7
  UnconstrainedQualifiedSingleEntity,
10
- UniqueWhere,
11
8
  } from '../treeParameters'
9
+ import { Environment } from '../dao'
12
10
 
13
11
  // TODO update hashing so that for offset, 0 == undefined
14
12
  export class Hashing {
15
13
  public static hashHasOneRelation(relation: HasOneRelation): number {
16
- const where: Array<Filter | UniqueWhere | string | undefined> = [
14
+ const where = [
17
15
  'upToOne',
18
16
  relation.field,
19
17
  relation.filter,
@@ -24,7 +22,7 @@ export class Hashing {
24
22
  }
25
23
 
26
24
  public static hashHasManyRelation(relation: HasManyRelation): number {
27
- const where: Array<Filter | UniqueWhere | OrderBy | string | number | undefined> = [
25
+ const where = [
28
26
  'possiblyMany',
29
27
  relation.field,
30
28
  relation.filter,
@@ -38,9 +36,14 @@ export class Hashing {
38
36
 
39
37
  public static hashEntityListSubTreeParameters(
40
38
  parameters: QualifiedEntityList | UnconstrainedQualifiedEntityList,
39
+ environment: Environment,
41
40
  ): number {
42
41
  if (parameters.isCreating) {
43
- return Hashing.hashArray([parameters.isCreating, parameters.entityName])
42
+ return Hashing.hashArray([
43
+ parameters.isCreating,
44
+ parameters.entityName,
45
+ environment.getAllVariables(),
46
+ ])
44
47
  }
45
48
  return Hashing.hashArray([
46
49
  parameters.isCreating,
@@ -49,16 +52,28 @@ export class Hashing {
49
52
  parameters.orderBy,
50
53
  parameters.offset,
51
54
  parameters.limit,
55
+ environment.getAllVariables(),
52
56
  ])
53
57
  }
54
58
 
55
59
  public static hashEntitySubTreeParameters(
56
60
  parameters: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,
61
+ environment: Environment,
57
62
  ): number {
58
63
  if (parameters.isCreating) {
59
- return Hashing.hashArray([parameters.isCreating, parameters.entityName])
64
+ return Hashing.hashArray([
65
+ parameters.isCreating,
66
+ parameters.entityName,
67
+ environment.getAllVariables(),
68
+ ])
60
69
  }
61
- return Hashing.hashArray([parameters.isCreating, parameters.where, parameters.entityName, parameters.filter])
70
+ return Hashing.hashArray([
71
+ parameters.isCreating,
72
+ parameters.where,
73
+ parameters.entityName,
74
+ parameters.filter,
75
+ environment.getAllVariables(),
76
+ ])
62
77
  }
63
78
 
64
79
  private static hashArray(array: any[]): number {