@contember/binding 1.0.0 → 1.1.0-alpha.0
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/development/core/DataBinding.js +18 -17
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/MarkerComparator.js +1 -1
- package/dist/development/core/MarkerMerger.js +1 -4
- package/dist/development/core/MarkerMerger.js.map +1 -1
- package/dist/development/core/StateInitializer.js +1 -3
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/VariableInputTransformer.js +4 -1
- package/dist/development/core/VariableInputTransformer.js.map +1 -1
- package/dist/development/core/operations/EntityOperations.js +1 -1
- package/dist/development/core/schema/Schema.js +3 -0
- package/dist/development/core/schema/Schema.js.map +1 -1
- package/dist/development/coreComponents/EntityListSubTree.js +4 -12
- package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/development/coreComponents/EntitySubTree.js +4 -22
- package/dist/development/coreComponents/EntitySubTree.js.map +1 -1
- package/dist/development/coreComponents/Field.js +5 -1
- package/dist/development/coreComponents/Field.js.map +1 -1
- package/dist/development/coreComponents/HasMany.js +3 -5
- package/dist/development/coreComponents/HasMany.js.map +1 -1
- package/dist/development/coreComponents/HasOne.js +3 -5
- package/dist/development/coreComponents/HasOne.js.map +1 -1
- package/dist/development/dao/Environment.js +147 -94
- package/dist/development/dao/Environment.js.map +1 -1
- package/dist/development/dao/TreeNodeEnvironmentFactory.js +159 -0
- package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -0
- package/dist/development/queryLanguage/MarkerFactory.js +4 -3
- package/dist/development/queryLanguage/MarkerFactory.js.map +1 -1
- package/dist/development/queryLanguage/Parser.js +18 -6
- package/dist/development/queryLanguage/Parser.js.map +1 -1
- package/dist/production/core/DataBinding.js +18 -8
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/MarkerComparator.js +1 -1
- package/dist/production/core/MarkerMerger.js +1 -4
- package/dist/production/core/MarkerMerger.js.map +1 -1
- package/dist/production/core/StateInitializer.js +1 -3
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/VariableInputTransformer.js +4 -1
- package/dist/production/core/VariableInputTransformer.js.map +1 -1
- package/dist/production/core/operations/EntityOperations.js +1 -1
- package/dist/production/core/schema/Schema.js +3 -0
- package/dist/production/core/schema/Schema.js.map +1 -1
- package/dist/production/coreComponents/EntityListSubTree.js +4 -12
- package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/production/coreComponents/EntitySubTree.js +4 -22
- package/dist/production/coreComponents/EntitySubTree.js.map +1 -1
- package/dist/production/coreComponents/Field.js +5 -1
- package/dist/production/coreComponents/Field.js.map +1 -1
- package/dist/production/coreComponents/HasMany.js +3 -5
- package/dist/production/coreComponents/HasMany.js.map +1 -1
- package/dist/production/coreComponents/HasOne.js +3 -5
- package/dist/production/coreComponents/HasOne.js.map +1 -1
- package/dist/production/dao/Environment.js +147 -94
- package/dist/production/dao/Environment.js.map +1 -1
- package/dist/production/dao/TreeNodeEnvironmentFactory.js +159 -0
- package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -0
- package/dist/production/queryLanguage/MarkerFactory.js +4 -3
- package/dist/production/queryLanguage/MarkerFactory.js.map +1 -1
- package/dist/production/queryLanguage/Parser.js +15 -6
- package/dist/production/queryLanguage/Parser.js.map +1 -1
- package/dist/types/accessorTree/MutationRequestResponse.d.ts +4 -0
- package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -1
- package/dist/types/accessorTree/QueryRequestResponse.d.ts +4 -0
- package/dist/types/accessorTree/QueryRequestResponse.d.ts.map +1 -1
- package/dist/types/accessorTree/RequestError.d.ts +9 -1
- package/dist/types/accessorTree/RequestError.d.ts.map +1 -1
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/core/MarkerMerger.d.ts.map +1 -1
- package/dist/types/core/StateInitializer.d.ts.map +1 -1
- package/dist/types/core/VariableInputTransformer.d.ts.map +1 -1
- package/dist/types/core/schema/Schema.d.ts +2 -0
- package/dist/types/core/schema/Schema.d.ts.map +1 -1
- package/dist/types/core/schema/index.d.ts +0 -1
- package/dist/types/core/schema/index.d.ts.map +1 -1
- package/dist/types/coreComponents/EntityListSubTree.d.ts +1 -1
- package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
- package/dist/types/coreComponents/EntitySubTree.d.ts +1 -1
- package/dist/types/coreComponents/EntitySubTree.d.ts.map +1 -1
- package/dist/types/coreComponents/Field.d.ts.map +1 -1
- package/dist/types/coreComponents/HasMany.d.ts +1 -1
- package/dist/types/coreComponents/HasMany.d.ts.map +1 -1
- package/dist/types/coreComponents/HasOne.d.ts +1 -1
- package/dist/types/coreComponents/HasOne.d.ts.map +1 -1
- package/dist/types/dao/Environment.d.ts +82 -43
- package/dist/types/dao/Environment.d.ts.map +1 -1
- package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts +19 -0
- package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts.map +1 -0
- package/dist/types/queryLanguage/MarkerFactory.d.ts.map +1 -1
- package/dist/types/queryLanguage/Parser.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -6
- package/src/accessorTree/MutationRequestResponse.ts +1 -0
- package/src/accessorTree/QueryRequestResponse.ts +1 -0
- package/src/accessorTree/RequestError.ts +7 -1
- package/src/core/DataBinding.ts +23 -26
- package/src/core/MarkerMerger.ts +1 -4
- package/src/core/StateInitializer.ts +1 -3
- package/src/core/VariableInputTransformer.ts +7 -4
- package/src/core/schema/Schema.ts +5 -0
- package/src/core/schema/index.ts +0 -1
- package/src/coreComponents/EntityListSubTree.tsx +5 -16
- package/src/coreComponents/EntitySubTree.tsx +17 -32
- package/src/coreComponents/Field.tsx +4 -0
- package/src/coreComponents/HasMany.tsx +4 -6
- package/src/coreComponents/HasOne.tsx +6 -7
- package/src/dao/Environment.ts +221 -126
- package/src/dao/TreeNodeEnvironmentFactory.ts +228 -0
- package/src/queryLanguage/MarkerFactory.ts +5 -3
- package/src/queryLanguage/Parser.ts +24 -11
- package/dist/development/core/schema/SchemaValidator.js +0 -116
- package/dist/development/core/schema/SchemaValidator.js.map +0 -1
- package/dist/types/core/schema/SchemaValidator.d.ts +0 -14
- package/dist/types/core/schema/SchemaValidator.d.ts.map +0 -1
- package/src/core/schema/SchemaValidator.ts +0 -238
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","sources":["../../../src/coreComponents/Field.tsx"],"sourcesContent":["import { GraphQlBuilder } from '@contember/client'\nimport type { ReactElement, ReactNode } from 'react'\nimport { useField } from '../accessorPropagation'\nimport { MarkerFactory } from '../queryLanguage'\nimport type { FieldValue, SugaredRelativeSingleField } from '../treeParameters'\nimport { Component } from './Component'\n\nexport interface FieldBasicProps extends SugaredRelativeSingleField {}\n\nexport interface FieldRuntimeProps<Persisted extends FieldValue = FieldValue> {\n\tformat?: (value: Persisted | null) => ReactNode\n}\n\nexport interface FieldProps<Persisted extends FieldValue = FieldValue>\n\textends FieldBasicProps,\n\t\tFieldRuntimeProps<Persisted> {}\n\nexport const Field = Component(\n\t<Persisted extends FieldValue = FieldValue>(props: FieldProps<Persisted>) => {\n\t\tconst field = useField<Persisted>(props)\n\n\t\tif (props.format !== undefined) {\n\t\t\treturn <>{props.format(field.value)}</>\n\t\t}\n\n\t\tif (\n\t\t\tfield.value instanceof GraphQlBuilder.GraphQlLiteral ||\n\t\t\tfield.value === null ||\n\t\t\ttypeof field.value === 'boolean'\n\t\t) {\n\t\t\treturn null\n\t\t}\n\t\treturn <>{field.value}</>\n\t},\n\t{\n\t\tgenerateLeafMarker: (props, environment) => MarkerFactory.createFieldMarker(props, environment),\n\t},\n\t'Field',\n) as <Persisted extends FieldValue = FieldValue>(props: FieldProps<Persisted>) => ReactElement\n"],"names":["_jsx","_jsxFragment"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Field.js","sources":["../../../src/coreComponents/Field.tsx"],"sourcesContent":["import { GraphQlBuilder } from '@contember/client'\nimport type { ReactElement, ReactNode } from 'react'\nimport { useField } from '../accessorPropagation'\nimport { MarkerFactory } from '../queryLanguage'\nimport type { FieldValue, SugaredRelativeSingleField } from '../treeParameters'\nimport { Component } from './Component'\nimport { TreeNodeEnvironmentFactory } from '../dao/TreeNodeEnvironmentFactory'\n\nexport interface FieldBasicProps extends SugaredRelativeSingleField {}\n\nexport interface FieldRuntimeProps<Persisted extends FieldValue = FieldValue> {\n\tformat?: (value: Persisted | null) => ReactNode\n}\n\nexport interface FieldProps<Persisted extends FieldValue = FieldValue>\n\textends FieldBasicProps,\n\t\tFieldRuntimeProps<Persisted> {}\n\nexport const Field = Component(\n\t<Persisted extends FieldValue = FieldValue>(props: FieldProps<Persisted>) => {\n\t\tconst field = useField<Persisted>(props)\n\n\t\tif (props.format !== undefined) {\n\t\t\treturn <>{props.format(field.value)}</>\n\t\t}\n\n\t\tif (\n\t\t\tfield.value instanceof GraphQlBuilder.GraphQlLiteral ||\n\t\t\tfield.value === null ||\n\t\t\ttypeof field.value === 'boolean'\n\t\t) {\n\t\t\treturn null\n\t\t}\n\t\treturn <>{field.value}</>\n\t},\n\t{\n\t\tgenerateLeafMarker: (props, environment) => MarkerFactory.createFieldMarker(props, environment),\n\t\tgenerateEnvironment: (props, environment) => {\n\t\t\treturn TreeNodeEnvironmentFactory.createEnvironmentForField(environment, props)\n\t\t},\n\t},\n\t'Field',\n) as <Persisted extends FieldValue = FieldValue>(props: FieldProps<Persisted>) => ReactElement\n"],"names":["_jsx","_jsxFragment"],"mappings":";;;;;;AAkBa,MAAA,QAAQ,UACpB,CAA4C,UAAiC;AACtE,QAAA,QAAQ,SAAoB,KAAK;AAEnC,MAAA,MAAM,WAAW,QAAW;AAC/B,WAAUA,8BAAAC,UAAA,MAAA,MAAM,OAAO,MAAM,KAAK,CAAE;AAAA,EACrC;AAGC,MAAA,MAAM,iBAAiB,eAAe,kBACtC,MAAM,UAAU,QAChB,OAAO,MAAM,UAAU,WACtB;AACM,WAAA;AAAA,EACR;AACO,SAAAD,8BAAAC,UAAA,MAAG,MAAM,KAAM;AACvB,GACA;AAAA,EACC,oBAAoB,CAAC,OAAO,gBAAgB,cAAc,kBAAkB,OAAO,WAAW;AAAA,EAC9F,qBAAqB,CAAC,OAAO,gBAAgB;AACrC,WAAA,2BAA2B,0BAA0B,aAAa,KAAK;AAAA,EAC/E;AACD,GACA,OACD;;"}
|
|
@@ -3,8 +3,8 @@ import { PRIMARY_KEY_NAME } from "../bindingTypes.js";
|
|
|
3
3
|
import { Component } from "./Component.js";
|
|
4
4
|
import { EntityList } from "./EntityList.js";
|
|
5
5
|
import { Field } from "./Field.js";
|
|
6
|
+
import { TreeNodeEnvironmentFactory } from "../dao/TreeNodeEnvironmentFactory.js";
|
|
6
7
|
import { useEntityList } from "../accessorPropagation/useEntityList.js";
|
|
7
|
-
import { Environment } from "../dao/Environment.js";
|
|
8
8
|
import { MarkerFactory } from "../queryLanguage/MarkerFactory.js";
|
|
9
9
|
const HasMany = Component((props) => {
|
|
10
10
|
const entityList = useEntityList(props);
|
|
@@ -14,10 +14,8 @@ const HasMany = Component((props) => {
|
|
|
14
14
|
});
|
|
15
15
|
}, {
|
|
16
16
|
generateEnvironment: (props, oldEnvironment) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return oldEnvironment.putDelta(Environment.generateDelta(oldEnvironment, props.variables));
|
|
17
|
+
const environment = oldEnvironment.withVariables(props.variables);
|
|
18
|
+
return TreeNodeEnvironmentFactory.createEnvironmentForEntityList(environment, props);
|
|
21
19
|
},
|
|
22
20
|
staticRender: (props) => /* @__PURE__ */ createElement(EntityList, {
|
|
23
21
|
...props,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HasMany.js","sources":["../../../src/coreComponents/HasMany.tsx"],"sourcesContent":["import type { ComponentType, ReactElement, ReactNode } from 'react'\nimport { useEntityList } from '../accessorPropagation'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport { Environment } from '../dao'\nimport { MarkerFactory } from '../queryLanguage'\nimport type { SugaredRelativeEntityList } from '../treeParameters'\nimport { Component } from './Component'\nimport
|
|
1
|
+
{"version":3,"file":"HasMany.js","sources":["../../../src/coreComponents/HasMany.tsx"],"sourcesContent":["import type { ComponentType, ReactElement, ReactNode } from 'react'\nimport { useEntityList } from '../accessorPropagation'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport { Environment } from '../dao'\nimport { MarkerFactory } from '../queryLanguage'\nimport type { SugaredRelativeEntityList } from '../treeParameters'\nimport { Component } from './Component'\nimport { EntityList, EntityListBaseProps } from './EntityList'\nimport { Field } from './Field'\nimport { TreeNodeEnvironmentFactory } from '../dao/TreeNodeEnvironmentFactory'\n\nexport type HasManyProps<ListProps = never, EntityProps = never> = SugaredRelativeEntityList & {\n\tchildren?: ReactNode\n\tvariables?: Environment.ValuesMapWithFactory\n} & (\n\t\t| {}\n\t\t| {\n\t\t\t\tlistComponent: ComponentType<ListProps & EntityListBaseProps>\n\t\t\t\tlistProps?: ListProps\n\t\t }\n\t)\n\nexport const HasMany = Component(\n\t<ListProps, EntityProps>(props: HasManyProps<ListProps, EntityProps>) => {\n\t\tconst entityList = useEntityList(props)\n\n\t\treturn <EntityList {...props} accessor={entityList} />\n\t},\n\t{\n\t\tgenerateEnvironment: (props, oldEnvironment) => {\n\t\t\tconst environment = oldEnvironment.withVariables(props.variables)\n\t\t\treturn TreeNodeEnvironmentFactory.createEnvironmentForEntityList(environment, props)\n\t\t},\n\t\tstaticRender: props => (\n\t\t\t<EntityList {...props} accessor={undefined as any}>\n\t\t\t\t<Field field={PRIMARY_KEY_NAME} />\n\t\t\t\t{props.children}\n\t\t\t</EntityList>\n\t\t),\n\t\tgenerateBranchMarker: (props, fields, environment) =>\n\t\t\tMarkerFactory.createRelativeEntityListFields(props, environment, fields),\n\t},\n\t'HasMany',\n) as <ListProps, EntityProps>(props: HasManyProps<ListProps, EntityProps>) => ReactElement\n"],"names":["_jsx"],"mappings":";;;;;;;;AAsBa,MAAA,UAAU,UACtB,CAAyB,UAAgD;AAClE,QAAA,aAAa,cAAc,KAAK;AAEtC,SAAQA,8BAAA,YAAA;AAAA,OAAe;AAAA,IAAO,UAAU;AAAA,EAAA,CAAY;AACrD,GACA;AAAA,EACC,qBAAqB,CAAC,OAAO,mBAAmB;AAC/C,UAAM,cAAc,eAAe,cAAc,MAAM,SAAS;AACzD,WAAA,2BAA2B,+BAA+B,aAAa,KAAK;AAAA,EACpF;AAAA,EACA,cAAc,WACZA,8BAAA,YAAA;AAAA,OAAe;AAAA,IAAO,UAAU;AAAA,EAAA,GAC/BA,8BAAA,OAAA;AAAA,IAAM,OAAO;AAAA,EAAA,CAAkB,GAC/B,MAAM,QACR;AAAA,EAED,sBAAsB,CAAC,OAAO,QAAQ,gBACrC,cAAc,+BAA+B,OAAO,aAAa,MAAM;AACzE,GACA,SACD;;"}
|
|
@@ -3,8 +3,8 @@ import { PRIMARY_KEY_NAME } from "../bindingTypes.js";
|
|
|
3
3
|
import { Component } from "./Component.js";
|
|
4
4
|
import { Entity } from "./Entity.js";
|
|
5
5
|
import { Field } from "./Field.js";
|
|
6
|
+
import { TreeNodeEnvironmentFactory } from "../dao/TreeNodeEnvironmentFactory.js";
|
|
6
7
|
import { useEntity } from "../accessorPropagation/useEntity.js";
|
|
7
|
-
import { Environment } from "../dao/Environment.js";
|
|
8
8
|
import { MarkerFactory } from "../queryLanguage/MarkerFactory.js";
|
|
9
9
|
const HasOne = Component((props) => {
|
|
10
10
|
const entity = useEntity(props);
|
|
@@ -14,10 +14,8 @@ const HasOne = Component((props) => {
|
|
|
14
14
|
});
|
|
15
15
|
}, {
|
|
16
16
|
generateEnvironment: (props, oldEnvironment) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return oldEnvironment.putDelta(Environment.generateDelta(oldEnvironment, props.variables));
|
|
17
|
+
const environment = oldEnvironment.withVariables(props.variables);
|
|
18
|
+
return TreeNodeEnvironmentFactory.createEnvironmentForEntity(environment, props);
|
|
21
19
|
},
|
|
22
20
|
staticRender: (props) => /* @__PURE__ */ createElement(Entity, {
|
|
23
21
|
...props,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HasOne.js","sources":["../../../src/coreComponents/HasOne.tsx"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"HasOne.js","sources":["../../../src/coreComponents/HasOne.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from 'react'\nimport { useEntity } from '../accessorPropagation'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport { Environment } from '../dao'\nimport { MarkerFactory } from '../queryLanguage'\nimport type { SugaredRelativeSingleEntity } from '../treeParameters'\nimport { Component } from './Component'\nimport { Entity } from './Entity'\nimport { Field } from './Field'\nimport { TreeNodeEnvironmentFactory } from '../dao/TreeNodeEnvironmentFactory'\n\nexport type HasOneProps<EntityProps = never> = SugaredRelativeSingleEntity & {\n\tchildren?: ReactNode\n\tvariables?: Environment.ValuesMapWithFactory\n}\n\nexport const HasOne = Component(\n\t<EntityProps extends {}>(props: HasOneProps<EntityProps>) => {\n\t\tconst entity = useEntity(props)\n\n\t\treturn <Entity {...props} accessor={entity} />\n\t},\n\t{\n\t\tgenerateEnvironment: (props, oldEnvironment) => {\n\t\t\tconst environment = oldEnvironment.withVariables(props.variables)\n\t\t\treturn TreeNodeEnvironmentFactory.createEnvironmentForEntity(environment, props)\n\t\t},\n\t\tstaticRender: props => (\n\t\t\t<Entity {...props} accessor={undefined as any}>\n\t\t\t\t<Field field={PRIMARY_KEY_NAME} />\n\t\t\t\t{props.children}\n\t\t\t</Entity>\n\t\t),\n\t\tgenerateBranchMarker: (props, fields, environment) =>\n\t\t\tMarkerFactory.createRelativeSingleEntityFields(props, environment, fields),\n\t},\n\t'HasOne',\n) as <EntityProps extends {}>(props: HasOneProps<EntityProps>) => ReactElement\n"],"names":["_jsx"],"mappings":";;;;;;;;AAgBa,MAAA,SAAS,UACrB,CAAyB,UAAoC;AACtD,QAAA,SAAS,UAAU,KAAK;AAE9B,SAAQA,8BAAA,QAAA;AAAA,OAAW;AAAA,IAAO,UAAU;AAAA,EAAA,CAAQ;AAC7C,GACA;AAAA,EACC,qBAAqB,CAAC,OAAO,mBAAmB;AAC/C,UAAM,cAAc,eAAe,cAAc,MAAM,SAAS;AACzD,WAAA,2BAA2B,2BAA2B,aAAa,KAAK;AAAA,EAChF;AAAA,EACA,cAAc,WACZA,8BAAA,QAAA;AAAA,OAAW;AAAA,IAAO,UAAU;AAAA,EAAA,GAC3BA,8BAAA,OAAA;AAAA,IAAM,OAAO;AAAA,EAAA,CAAkB,GAC/B,MAAM,QACR;AAAA,EAED,sBAAsB,CAAC,OAAO,QAAQ,gBACrC,cAAc,iCAAiC,OAAO,aAAa,MAAM;AAC3E,GACA,QACD;;"}
|
|
@@ -1,123 +1,176 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
1
|
+
import { BindingError } from "../BindingError.js";
|
|
2
|
+
import equal from "fast-deep-equal/es6";
|
|
7
3
|
class Environment {
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
10
|
-
this.names = {
|
|
11
|
-
...Environment.defaultNameStore,
|
|
12
|
-
...names
|
|
13
|
-
};
|
|
4
|
+
constructor(options) {
|
|
5
|
+
this.options = options;
|
|
14
6
|
}
|
|
15
|
-
static create(
|
|
7
|
+
static create() {
|
|
16
8
|
return new Environment({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
hasName(name) {
|
|
22
|
-
return name in this.names;
|
|
23
|
-
}
|
|
24
|
-
hasDimension(dimensionName) {
|
|
25
|
-
return dimensionName in this.names.dimensions;
|
|
9
|
+
dimensions: {},
|
|
10
|
+
variables: {},
|
|
11
|
+
parameters: {}
|
|
12
|
+
});
|
|
26
13
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
getSubTree() {
|
|
15
|
+
for (let env = this; env.options.node; env = env.getParent()) {
|
|
16
|
+
const node = env.options.node;
|
|
17
|
+
if (node.type === "subtree-entity" || node.type === "subtree-entity-list") {
|
|
18
|
+
return node;
|
|
19
|
+
}
|
|
30
20
|
}
|
|
31
|
-
|
|
21
|
+
throw new BindingError("Not in a SubTree");
|
|
32
22
|
}
|
|
33
|
-
|
|
34
|
-
if (!this.
|
|
35
|
-
|
|
23
|
+
getSubTreeNode() {
|
|
24
|
+
if (!this.options.node) {
|
|
25
|
+
throw new BindingError();
|
|
36
26
|
}
|
|
37
|
-
return this.
|
|
27
|
+
return this.options.node;
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
withSubTree(SubTree) {
|
|
30
|
+
const { parent, ...options } = this.options;
|
|
31
|
+
return new Environment({
|
|
32
|
+
...options,
|
|
33
|
+
node: SubTree
|
|
34
|
+
});
|
|
41
35
|
}
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
withSubTreeChild(node) {
|
|
37
|
+
if (!this.options.node) {
|
|
38
|
+
throw new BindingError(`Cannot call withSubTreeChild without previous call of withSubTree`);
|
|
39
|
+
}
|
|
40
|
+
if (this.options.node.entity.fields.get(node.field.name) !== node.field) {
|
|
41
|
+
throw new BindingError();
|
|
42
|
+
}
|
|
43
|
+
return new Environment({
|
|
44
|
+
...this.options,
|
|
45
|
+
node,
|
|
46
|
+
parent: this
|
|
47
|
+
});
|
|
44
48
|
}
|
|
45
|
-
|
|
46
|
-
return
|
|
49
|
+
hasVariable(key) {
|
|
50
|
+
return key in this.options.variables;
|
|
47
51
|
}
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
getVariable(key) {
|
|
53
|
+
if (!(key in this.options.variables)) {
|
|
54
|
+
throw new BindingError(`Variable ${key} not found`);
|
|
55
|
+
}
|
|
56
|
+
return this.options.variables[key];
|
|
50
57
|
}
|
|
51
|
-
|
|
52
|
-
return this.
|
|
58
|
+
getVariableOrElse(key, fallback) {
|
|
59
|
+
return this.options.variables[key] ?? fallback;
|
|
53
60
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
dimensions: { ...this.names.dimensions },
|
|
58
|
-
[name]: value
|
|
59
|
-
});
|
|
61
|
+
getValue(key) {
|
|
62
|
+
console.warn("Environment.getValue() is deprecated, use Environment.getVariable() or Environment.getParameter() instead.");
|
|
63
|
+
return this.getVariableOrElse(key, void 0) ?? this.getParameterOrElse(key, void 0);
|
|
60
64
|
}
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
getValueOrElse(key, fallback) {
|
|
66
|
+
console.warn("Environment.getValueOrElse() is deprecated, use Environment.getVariableOrElse() or Environment.getParameterOrElse() instead.");
|
|
67
|
+
return this.getVariableOrElse(key, void 0) ?? this.getParameterOrElse(key, fallback);
|
|
63
68
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
hasName(key) {
|
|
70
|
+
console.warn("Environment.hasName() is deprecated, use Environment.hasVariable() or Environment.hasParameter() instead.");
|
|
71
|
+
return key in this.options.variables || key in this.options.parameters;
|
|
72
|
+
}
|
|
73
|
+
withVariables(variables) {
|
|
74
|
+
if (variables === void 0) {
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
const newVariables = { ...this.options.variables };
|
|
78
|
+
for (const [newName, newValue] of Object.entries(variables)) {
|
|
79
|
+
if (newName === "labelMiddleware") {
|
|
80
|
+
throw new BindingError("You cannot pass labelMiddleware to withVariables method. Use withLabelMiddleware instead.");
|
|
81
|
+
}
|
|
82
|
+
const resolvedValue = typeof newValue === "function" ? newValue(this) : newValue;
|
|
83
|
+
if (resolvedValue === void 0) {
|
|
84
|
+
delete newVariables[newName];
|
|
70
85
|
} else {
|
|
71
|
-
|
|
86
|
+
newVariables[newName] = resolvedValue;
|
|
72
87
|
}
|
|
73
88
|
}
|
|
74
|
-
return new Environment(
|
|
89
|
+
return new Environment({ ...this.options, variables: newVariables });
|
|
90
|
+
}
|
|
91
|
+
hasParameter(key) {
|
|
92
|
+
return key in this.options.parameters;
|
|
93
|
+
}
|
|
94
|
+
getParameter(key) {
|
|
95
|
+
if (!(key in this.options.parameters) || this.options.parameters[key] === void 0) {
|
|
96
|
+
throw new BindingError(`Parameter ${key} not found`);
|
|
97
|
+
}
|
|
98
|
+
return this.options.parameters[key];
|
|
75
99
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
100
|
+
getParameterOrElse(key, fallback) {
|
|
101
|
+
return this.options.parameters[key] ?? fallback;
|
|
102
|
+
}
|
|
103
|
+
withParameters(parameters) {
|
|
104
|
+
return new Environment({ ...this.options, parameters });
|
|
105
|
+
}
|
|
106
|
+
hasDimension(dimensionName) {
|
|
107
|
+
return dimensionName in this.options.dimensions;
|
|
108
|
+
}
|
|
109
|
+
getDimension(dimensionName) {
|
|
110
|
+
if (!(dimensionName in this.options.dimensions)) {
|
|
111
|
+
throw new BindingError(`Dimension ${dimensionName} does not exist.`);
|
|
112
|
+
}
|
|
113
|
+
return this.options.dimensions[dimensionName];
|
|
114
|
+
}
|
|
115
|
+
getDimensionOrElse(dimensionName, fallback) {
|
|
116
|
+
return this.options.dimensions[dimensionName] ?? fallback;
|
|
117
|
+
}
|
|
118
|
+
getAllDimensions() {
|
|
119
|
+
return this.options.dimensions;
|
|
120
|
+
}
|
|
121
|
+
withDimensions(dimensions) {
|
|
122
|
+
const newDimensions = {
|
|
123
|
+
...this.options.dimensions,
|
|
79
124
|
...dimensions
|
|
80
125
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
126
|
+
if (equal(newDimensions, this.options.dimensions)) {
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
return new Environment({ ...this.options, dimensions: newDimensions });
|
|
130
|
+
}
|
|
131
|
+
getSchema() {
|
|
132
|
+
if (!this.options.schema) {
|
|
133
|
+
throw new BindingError("Schema is not set");
|
|
134
|
+
}
|
|
135
|
+
return this.options.schema;
|
|
86
136
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
137
|
+
withSchema(schema) {
|
|
138
|
+
return new Environment({ ...this.options, schema });
|
|
139
|
+
}
|
|
140
|
+
getParent() {
|
|
141
|
+
if (!this.options.parent) {
|
|
142
|
+
throw new BindingError("There is no parent environment");
|
|
92
143
|
}
|
|
93
|
-
return
|
|
144
|
+
return this.options.parent;
|
|
94
145
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
146
|
+
merge(other) {
|
|
147
|
+
if (other === this) {
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
if (!equal(this.options.node, other.options.node)) {
|
|
151
|
+
throw new BindingError(`Cannot merge two environments with different tree position.`);
|
|
152
|
+
}
|
|
153
|
+
if (this.options.parameters !== other.options.parameters) {
|
|
154
|
+
throw new BindingError(`Cannot merge two environments with different parameters.`);
|
|
99
155
|
}
|
|
100
|
-
|
|
156
|
+
if (this.options.dimensions !== other.options.dimensions) {
|
|
157
|
+
throw new BindingError(`Cannot merge two environments with different dimensions.`);
|
|
158
|
+
}
|
|
159
|
+
if (equal(this.options.variables, other.options.variables) && this.options.parent === other.options.parent) {
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
for (const key in other.options.variables) {
|
|
163
|
+
if (key in this.options.variables && !equal(this.options.variables[key], other.options.variables[key])) {
|
|
164
|
+
throw new BindingError(`Cannot merge two environments with different value of variable ${key}:
|
|
165
|
+
` + JSON.stringify(this.options.variables[key]) + "\n" + JSON.stringify(other.options.variables[key]));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return new Environment({
|
|
169
|
+
...this.options,
|
|
170
|
+
parent: this.options.parent && other.options.parent ? this.options.parent.merge(other.options.parent) : void 0,
|
|
171
|
+
variables: { ...this.options.variables, ...other.options.variables }
|
|
172
|
+
});
|
|
101
173
|
}
|
|
102
174
|
}
|
|
103
|
-
((Environment2) => {
|
|
104
|
-
Environment2.systemVariableNames = /* @__PURE__ */ new Set([
|
|
105
|
-
"labelMiddleware",
|
|
106
|
-
"rootWhere",
|
|
107
|
-
"rootWhereAsFilter",
|
|
108
|
-
"rootShouldExists"
|
|
109
|
-
]);
|
|
110
|
-
Environment2.reservedVariableNames = /* @__PURE__ */ new Set([
|
|
111
|
-
...Environment2.systemVariableNames,
|
|
112
|
-
"dimensions"
|
|
113
|
-
]);
|
|
114
|
-
Environment2.defaultSystemVariables = {
|
|
115
|
-
labelMiddleware: (label) => label
|
|
116
|
-
};
|
|
117
|
-
Environment2.defaultNameStore = {
|
|
118
|
-
...Environment2.defaultSystemVariables,
|
|
119
|
-
dimensions: {}
|
|
120
|
-
};
|
|
121
|
-
})(Environment || (Environment = {}));
|
|
122
175
|
export { Environment };
|
|
123
176
|
//# sourceMappingURL=Environment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Environment.js","sources":["../../../src/dao/Environment.ts"],"sourcesContent":["import type { ReactNode } from 'react'\nimport type { Filter, UniqueWhere } from '../treeParameters'\n\nclass Environment {\n\tprivate readonly names: Environment.NameStore\n\n\tpublic constructor(names: Environment.NameStore = Environment.defaultNameStore) {\n\t\tthis.names = {\n\t\t\t...Environment.defaultNameStore,\n\t\t\t...names,\n\t\t}\n\t}\n\n\tpublic static create(delta: Partial<Environment.NameStore> = {}) {\n\t\treturn new Environment({\n\t\t\t...Environment.defaultSystemVariables,\n\t\t\tdimensions: {},\n\t\t}).putDelta(delta)\n\t}\n\n\tpublic hasName(name: keyof Environment.NameStore): boolean {\n\t\treturn name in this.names\n\t}\n\n\tpublic hasDimension(dimensionName: keyof Environment.SelectedDimensions): boolean {\n\t\treturn dimensionName in this.names.dimensions\n\t}\n\n\tpublic getValueOrElse<F, V extends Environment.Value = Environment.Value>(\n\t\tname: keyof Environment.NameStore,\n\t\tfallback: F,\n\t): V | F {\n\t\tif (!this.hasName(name)) {\n\t\t\treturn fallback\n\t\t}\n\t\treturn this.names[name] as V\n\t}\n\n\tpublic getDimensionOrElse<F>(dimensionName: keyof Environment.SelectedDimensions, fallback: F): string[] | F {\n\t\tif (!this.hasDimension(dimensionName)) {\n\t\t\treturn fallback\n\t\t}\n\t\treturn this.names.dimensions[dimensionName]\n\t}\n\n\tpublic getValue<V extends Environment.Value = Environment.Value>(name: keyof Environment.NameStore): V {\n\t\treturn this.names[name] as V\n\t}\n\n\tpublic getDimension(dimensionName: keyof Environment.SelectedDimensions): string[] {\n\t\treturn this.names.dimensions[dimensionName]\n\t}\n\n\tpublic getAllNames(): Environment.NameStore {\n\t\treturn { ...this.names }\n\t}\n\n\tpublic getAllDimensions(): Environment.SelectedDimensions {\n\t\treturn { ...this.names.dimensions }\n\t}\n\n\tpublic getSystemVariable<N extends Environment.SystemVariableName>(name: N): Environment.SystemVariables[N] {\n\t\treturn this.names[name]\n\t}\n\n\tpublic putName(name: Environment.Name, value: Environment.Value): Environment {\n\t\treturn new Environment({\n\t\t\t...this.names,\n\t\t\tdimensions: { ...this.names.dimensions },\n\t\t\t[name]: value,\n\t\t})\n\t}\n\n\tpublic putSystemVariable<N extends Environment.SystemVariableName>(\n\t\tname: N,\n\t\tvalue: Environment.SystemVariables[N],\n\t): Environment {\n\t\treturn this.putName(name, value)\n\t}\n\n\tpublic putDelta(delta: Partial<Environment.NameStore>): Environment {\n\t\tconst currentNames = this.getAllNames()\n\n\t\tfor (const newName in delta) {\n\t\t\tconst deltaValue = delta[newName]\n\t\t\tif (deltaValue === undefined) {\n\t\t\t\tdelete currentNames[newName]\n\t\t\t} else {\n\t\t\t\tcurrentNames[newName] = deltaValue\n\t\t\t}\n\t\t}\n\n\t\treturn new Environment(currentNames)\n\t}\n\n\tpublic updateDimensionsIfNecessary(\n\t\tdimensions: Environment.NameStore['dimensions'],\n\t\tdefaultDimensions: Environment.NameStore['dimensions'],\n\t): Environment {\n\t\tconst normalizedDimensions: Environment.NameStore['dimensions'] = {\n\t\t\t...defaultDimensions,\n\t\t\t...dimensions,\n\t\t}\n\n\t\tconst dimensionsEqual = JSON.stringify(this.names.dimensions) === JSON.stringify(normalizedDimensions)\n\t\treturn dimensionsEqual\n\t\t\t? this\n\t\t\t: new Environment({\n\t\t\t\t\t...this.names,\n\t\t\t\t\tdimensions: { ...normalizedDimensions },\n\t\t\t })\n\t}\n\n\tpublic static generateDelta(\n\t\tcurrentEnvironment: Environment,\n\t\tdelta: Environment.DeltaFactory,\n\t): Partial<Environment.NameStore> {\n\t\tconst newDelta: Partial<Environment.NameStore> = {}\n\n\t\tfor (const name in delta) {\n\t\t\tconst value = delta[name]\n\n\t\t\tnewDelta[name] =\n\t\t\t\tvalue &&\n\t\t\t\tvalue instanceof Function &&\n\t\t\t\t!Environment.systemVariableNames.has(name as Environment.SystemVariableName)\n\t\t\t\t\t? value(currentEnvironment)\n\t\t\t\t\t: delta[name]\n\t\t}\n\n\t\treturn newDelta\n\t}\n\n\tpublic applySystemMiddleware<\n\t\tN extends Environment.SystemMiddlewareName,\n\t\tA extends Parameters<Exclude<Environment.SystemMiddleware[N], undefined>>,\n\t>(name: N, ...args: A): ReturnType<Exclude<Environment.SystemMiddleware[N], undefined>> | A {\n\t\tconst middleware: Environment.SystemMiddleware[N] = this.names[name]\n\t\tif (typeof middleware === 'function') {\n\t\t\treturn (middleware as (...args: A) => any)(...args)\n\t\t}\n\t\treturn args\n\t}\n}\n\nnamespace Environment {\n\texport type Name = string | number\n\n\texport type Value = ReactNode\n\n\texport interface SystemVariables {\n\t\tlabelMiddleware?: (label: ReactNode) => ReactNode\n\t\trootWhere?: UniqueWhere\n\t\trootWhereAsFilter?: Filter\n\t\trootShouldExists?: 'no' | 'maybe' | 'yes'\n\t}\n\n\texport const systemVariableNames: Set<SystemVariableName> = new Set([\n\t\t'labelMiddleware',\n\t\t'rootWhere',\n\t\t'rootWhereAsFilter',\n\t\t'rootShouldExists',\n\t])\n\n\texport const reservedVariableNames: Set<string> = new Set([\n\t\t...systemVariableNames,\n\t\t'dimensions',\n\t])\n\n\texport type SystemVariableName = keyof SystemVariables\n\n\texport interface SelectedDimensions {\n\t\t[key: string]: string[]\n\t}\n\n\texport interface NameStore extends SystemVariables {\n\t\tdimensions: SelectedDimensions\n\n\t\t[name: string]: Value\n\t}\n\n\texport type DeltaFactory = { [N in string]: ((environment: Environment) => Environment.Value) | Environment.Value } &\n\t\t{ [N in keyof SystemVariables]?: SystemVariables[N] }\n\n\texport type SystemMiddleware = {\n\t\t[N in SystemMiddlewareName]: SystemVariables[N]\n\t}\n\n\texport type SystemMiddlewareName = 'labelMiddleware'\n\n\texport const defaultSystemVariables: SystemVariables = {\n\t\tlabelMiddleware: label => label,\n\t}\n\n\texport const defaultNameStore: NameStore = {\n\t\t...defaultSystemVariables,\n\t\tdimensions: {},\n\t}\n}\n\nexport { Environment }\n"],"names":[],"mappings":";;;;;;AAGA,MAAM,YAAY;AAAA,EAGV,YAAY,QAA+B,YAAY,kBAAkB;AAF/D;AAGhB,SAAK,QAAQ;AAAA,SACT,YAAY;AAAA,SACZ;AAAA,IAAA;AAAA,EAEL;AAAA,SAEc,OAAO,QAAwC,IAAI;AAChE,WAAO,IAAI,YAAY;AAAA,SACnB,YAAY;AAAA,MACf,YAAY,CAAC;AAAA,IAAA,CACb,EAAE,SAAS,KAAK;AAAA,EAClB;AAAA,EAEO,QAAQ,MAA4C;AAC1D,WAAO,QAAQ,KAAK;AAAA,EACrB;AAAA,EAEO,aAAa,eAA8D;AAC1E,WAAA,iBAAiB,KAAK,MAAM;AAAA,EACpC;AAAA,EAEO,eACN,MACA,UACQ;AACR,QAAI,CAAC,KAAK,QAAQ,IAAI,GAAG;AACjB,aAAA;AAAA,IACR;AACA,WAAO,KAAK,MAAM;AAAA,EACnB;AAAA,E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A,OACiC;AACjC,UAAM,WAA2C,CAAA;AAEjD,eAAW,QAAQ,OAAO;AACzB,YAAM,QAAQ,MAAM;AAEpB,eAAS,QACR,SACA,iBAAiB,YACjB,CAAC,YAAY,oBAAoB,IAAI,IAAsC,IACxE,MAAM,kBAAkB,IACxB,MAAM;AAAA,IACX;AAEO,WAAA;AAAA,EACR;AAAA,EAEO,sBAGL,SAAY,MAA8E;AACrF,UAAA,aAA8C,KAAK,MAAM;AAC3D,QAAA,OAAO,eAAe,YAAY;AAC7B,aAAA,WAAmC,GAAG,IAAI;AAAA,IACnD;AACO,WAAA;AAAA,EACR;AACD;AAEA,AAAA,EAAU,iBAAV;AAYc,eAAA,0CAAmD,IAAI;AAAA,IACnE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AAEY,eAAA,4CAAyC,IAAI;AAAA,IACzD,GAAG,aAAA;AAAA,IACH;AAAA,EAAA,CACA;AAuBY,eAA0C,yBAAA;AAAA,IACtD,iBAAiB,CAAS,UAAA;AAAA,EAAA;AAGd,eAA8B,mBAAA;AAAA,OACvC,aAAA;AAAA,IACH,YAAY,CAAC;AAAA,EAAA;AACd,GApDS,eAAA,eAAA,CAAA,EAAA;;"}
|
|
1
|
+
{"version":3,"file":"Environment.js","sources":["../../../src/dao/Environment.ts"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { BindingError } from '../BindingError'\nimport type { Filter } from '../treeParameters'\nimport equal from 'fast-deep-equal/es6'\nimport { Schema, SchemaColumn, SchemaEntity, SchemaRelation } from '../core/schema'\n\nclass Environment {\n\tprivate constructor(\n\t\tprivate readonly options: Environment.Options,\n\t) {\n\t}\n\n\tpublic static create() {\n\t\treturn new Environment({\n\t\t\tdimensions: {},\n\t\t\tvariables: {},\n\t\t\tparameters: {},\n\t\t})\n\t}\n\n\tpublic getSubTree(): Environment.SubTreeNode {\n\t\tfor (let env: Environment = this; env.options.node; env = env.getParent()) {\n\t\t\tconst node = env.options.node\n\t\t\tif (node.type === 'subtree-entity' || node.type === 'subtree-entity-list') {\n\t\t\t\treturn node\n\t\t\t}\n\t\t}\n\t\tthrow new BindingError('Not in a SubTree')\n\t}\n\n\tpublic getSubTreeNode(): Environment.AnyNode {\n\t\tif (!this.options.node) {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\treturn this.options.node\n\t}\n\n\tpublic withSubTree(SubTree: Environment.SubTreeNode) {\n\t\tconst { parent, ...options } = this.options\n\t\treturn new Environment({\n\t\t\t...options,\n\t\t\tnode: SubTree,\n\t\t})\n\t}\n\n\tpublic withSubTreeChild(node: Environment.InnerNode) {\n\t\tif (!this.options.node) {\n\t\t\tthrow new BindingError(`Cannot call withSubTreeChild without previous call of withSubTree`)\n\t\t}\n\t\tif (this.options.node.entity.fields.get(node.field.name) !== node.field) {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\treturn new Environment({\n\t\t\t...this.options,\n\t\t\tnode,\n\t\t\tparent: this,\n\t\t})\n\t}\n\n\n\tpublic hasVariable(key: string): boolean {\n\t\treturn key in this.options.variables\n\t}\n\n\tpublic getVariable<V extends Environment.Value = Environment.Value>(key: string): V {\n\t\tif (!(key in this.options.variables)) {\n\t\t\tthrow new BindingError(`Variable ${key} not found`)\n\t\t}\n\t\treturn this.options.variables[key] as V\n\t}\n\n\tpublic getVariableOrElse<F, V extends Environment.Value = Environment.Value>(key: string, fallback: F): V | F {\n\t\treturn (this.options.variables[key] as V) ?? fallback\n\t}\n\n\t/** @deprecated use getVariable or getParameter */\n\tpublic getValue<V extends Environment.Value = Environment.Value>(key: string): V {\n\t\tconsole.warn('Environment.getValue() is deprecated, use Environment.getVariable() or Environment.getParameter() instead.')\n\t\treturn this.getVariableOrElse(key, undefined) ?? this.getParameterOrElse(key, undefined) as V\n\t}\n\n\t/** @deprecated use getVariableOrElse or getParameterOrElse */\n\tpublic getValueOrElse<F, V extends Environment.Value = Environment.Value>(key: string, fallback: F): V | F {\n\t\tconsole.warn('Environment.getValueOrElse() is deprecated, use Environment.getVariableOrElse() or Environment.getParameterOrElse() instead.')\n\t\treturn this.getVariableOrElse(key, undefined) ?? this.getParameterOrElse(key, fallback) as V | F\n\t}\n\n\t/** @deprecated */\n\tpublic hasName(key: string): boolean {\n\t\tconsole.warn('Environment.hasName() is deprecated, use Environment.hasVariable() or Environment.hasParameter() instead.')\n\t\treturn key in this.options.variables || key in this.options.parameters\n\t}\n\n\tpublic withVariables(variables: Environment.ValuesMapWithFactory | undefined): Environment {\n\t\tif (variables === undefined) {\n\t\t\treturn this\n\t\t}\n\t\tconst newVariables = { ...this.options.variables }\n\t\tfor (const [newName, newValue] of Object.entries(variables)) {\n\t\t\tif (newName === 'labelMiddleware') {\n\t\t\t\tthrow new BindingError('You cannot pass labelMiddleware to withVariables method. Use withLabelMiddleware instead.')\n\t\t\t}\n\t\t\tconst resolvedValue = typeof newValue === 'function' ? newValue(this) : newValue\n\t\t\tif (resolvedValue === undefined) {\n\t\t\t\tdelete newVariables[newName]\n\t\t\t} else {\n\t\t\t\tnewVariables[newName] = resolvedValue\n\t\t\t}\n\t\t}\n\t\treturn new Environment({ ...this.options, variables: newVariables })\n\t}\n\n\tpublic hasParameter(key: string): boolean {\n\t\treturn key in this.options.parameters\n\t}\n\n\tpublic getParameter<F>(key: string): string {\n\t\tif (!(key in this.options.parameters) || this.options.parameters[key] === undefined) {\n\t\t\tthrow new BindingError(`Parameter ${key} not found`)\n\t\t}\n\t\treturn this.options.parameters[key] as string\n\t}\n\n\tpublic getParameterOrElse<F>(key: string, fallback: F): string | F {\n\t\treturn this.options.parameters[key] ?? fallback\n\t}\n\n\n\tpublic withParameters(parameters: Environment.Parameters): Environment {\n\t\treturn new Environment({ ...this.options, parameters })\n\t}\n\n\tpublic hasDimension(dimensionName: string): boolean {\n\t\treturn dimensionName in this.options.dimensions\n\t}\n\n\tpublic getDimension<F>(dimensionName: string): string[] {\n\t\tif (!(dimensionName in this.options.dimensions)) {\n\t\t\tthrow new BindingError(`Dimension ${dimensionName} does not exist.`)\n\t\t}\n\t\treturn this.options.dimensions[dimensionName]\n\t}\n\n\tpublic getDimensionOrElse<F>(dimensionName: string, fallback: F): string[] | F {\n\t\treturn this.options.dimensions[dimensionName] ?? fallback\n\t}\n\n\tpublic getAllDimensions(): Environment.SelectedDimensions {\n\t\treturn this.options.dimensions\n\t}\n\n\tpublic withDimensions(dimensions: Environment.SelectedDimensions): Environment {\n\t\tconst newDimensions = {\n\t\t\t...this.options.dimensions,\n\t\t\t...dimensions,\n\t\t}\n\t\tif (equal(newDimensions, this.options.dimensions)) {\n\t\t\treturn this\n\t\t}\n\t\treturn new Environment({ ...this.options, dimensions: newDimensions })\n\t}\n\n\tpublic getSchema(): Schema {\n\t\tif (!this.options.schema) {\n\t\t\tthrow new BindingError('Schema is not set')\n\t\t}\n\t\treturn this.options.schema\n\t}\n\n\tpublic withSchema(schema: Schema): Environment {\n\t\treturn new Environment({ ...this.options, schema })\n\t}\n\n\tpublic getParent(): Environment {\n\t\tif (!this.options.parent) {\n\t\t\tthrow new BindingError('There is no parent environment')\n\t\t}\n\t\treturn this.options.parent\n\t}\n\n\tpublic merge(other: Environment): Environment {\n\t\tif (other === this) {\n\t\t\treturn this\n\t\t}\n\t\tif (!equal(this.options.node, other.options.node)) {\n\t\t\tthrow new BindingError(`Cannot merge two environments with different tree position.`)\n\t\t}\n\t\tif (this.options.parameters !== other.options.parameters) {\n\t\t\tthrow new BindingError(`Cannot merge two environments with different parameters.`)\n\t\t}\n\t\tif (this.options.dimensions !== other.options.dimensions) {\n\t\t\tthrow new BindingError(`Cannot merge two environments with different dimensions.`)\n\t\t}\n\t\tif (equal(this.options.variables, other.options.variables) && this.options.parent === other.options.parent) {\n\t\t\treturn this\n\t\t}\n\t\tfor (const key in other.options.variables) {\n\t\t\tif (key in this.options.variables && !equal(this.options.variables[key], other.options.variables[key])) {\n\t\t\t\tthrow new BindingError(`Cannot merge two environments with different value of variable ${key}:\\n`\n\t\t\t\t\t+ JSON.stringify(this.options.variables[key]) + '\\n'\n\t\t\t\t\t+ JSON.stringify(other.options.variables[key]))\n\t\t\t}\n\t\t}\n\n\t\treturn new Environment({\n\t\t\t...this.options,\n\t\t\tparent: this.options.parent && other.options.parent ? this.options.parent.merge(other.options.parent) : undefined,\n\t\t\tvariables: { ...this.options.variables, ...other.options.variables },\n\t\t})\n\t}\n}\n\nnamespace Environment {\n\texport type Name = string\n\n\texport type Value = ReactNode\n\n\texport type ResolvedValue = Value | Filter\n\n\texport interface Options {\n\t\tnode?: AnyNode\n\t\tschema?: Schema\n\t\tdimensions: SelectedDimensions\n\t\tparameters: Parameters\n\t\tvariables: CustomVariables\n\t\tparent?: Environment\n\t}\n\n\texport type SubTreeNode =\n\t\t| SubTreeEntityNode\n\t\t| SubTreeEntityListNode\n\n\texport type InnerNode =\n\t\t| EntityNode\n\t\t| EntityListNode\n\t\t| ColumnNode\n\n\texport type AnyNode =\n\t\t| SubTreeNode\n\t\t| InnerNode\n\n\texport interface SubTreeEntityNode {\n\t\ttype: 'subtree-entity'\n\t\tentity: SchemaEntity\n\t\texpectedCardinality: 'zero' | 'one' | 'zero-or-one'\n\t\tfilter: Filter\n\t}\n\n\texport interface SubTreeEntityListNode {\n\t\ttype: 'subtree-entity-list'\n\t\tentity: SchemaEntity\n\t\texpectedCardinality: 'zero-to-many' | 'zero'\n\t\tfilter: Filter\n\t}\n\n\texport interface EntityNode {\n\t\ttype: 'entity'\n\t\tentity: SchemaEntity\n\t\tfield: SchemaRelation\n\t}\n\n\texport interface EntityListNode {\n\t\ttype: 'entity-list'\n\t\tentity: SchemaEntity\n\t\tfield: SchemaRelation\n\t}\n\n\texport interface ColumnNode {\n\t\ttype: 'column'\n\t\tentity: SchemaEntity\n\t\tfield: SchemaColumn\n\t}\n\n\texport interface SelectedDimensions {\n\t\t[key: string]: string[]\n\t}\n\n\texport interface Parameters {\n\t\t[key: string]: string | undefined\n\t}\n\n\texport interface CustomVariables {\n\t\t[key: string]: Value\n\t}\n\n\texport interface ValuesMapWithFactory {\n\t\t[key: string]:\n\t\t\t| ((environment: Environment) => Value)\n\t\t\t| Value\n\t}\n\n\t/** @deprecated */\n\texport type DeltaFactory = ValuesMapWithFactory\n}\n\nexport { Environment }\n"],"names":[],"mappings":";;AAMA,MAAM,YAAY;AAAA,EACT,YACU,SAChB;AADgB,SAAA,UAAA;AAAA,EAElB;AAAA,SAEc,SAAS;AACtB,WAAO,IAAI,YAAY;AAAA,MACtB,YAAY,CAAC;AAAA,MACb,WAAW,CAAC;AAAA,MACZ,YAAY,CAAC;AAAA,IAAA,CACb;AAAA,EACF;AAAA,EAEO,aAAsC;AACnC,aAAA,MAAmB,MAAM,IAAI,QAAQ,MAAM,MAAM,IAAI,aAAa;AACpE,YAAA,OAAO,IAAI,QAAQ;AACzB,UAAI,KAAK,SAAS,oBAAoB,KAAK,SAAS,uBAAuB;AACnE,eAAA;AAAA,MACR;AAAA,IACD;AACM,UAAA,IAAI,aAAa,kBAAkB;AAAA,EAC1C;AAAA,EAEO,iBAAsC;AACxC,QAAA,CAAC,KAAK,QAAQ,MAAM;AACvB,YAAM,IAAI,aAAa;AAAA,IACxB;AACA,WAAO,KAAK,QAAQ;AAAA,EACrB;AAAA,EAEO,YAAY,SAAkC;AAC9C,UAAA,EAAE,WAAW,YAAY,KAAK;AACpC,WAAO,IAAI,YAAY;AAAA,SACnB;AAAA,MACH,MAAM;AAAA,IAAA,CACN;AAAA,EACF;AAAA,EAEO,iBAAiB,MAA6B;AAChD,QAAA,CAAC,KAAK,QAAQ,MAAM;AACjB,YAAA,IAAI,aAAa,mEAAmE;AAAA,IAC3F;AACI,QAAA,KAAK,QAAQ,KAAK,OAAO,OAAO,IAAI,KAAK,MAAM,IAAI,MAAM,KAAK,OAAO;AACxE,YAAM,IAAI,aAAa;AAAA,IACxB;AACA,WAAO,IAAI,YAAY;AAAA,SACnB,KAAK;AAAA,MACR;AAAA,MACA,QAAQ;AAAA,IAAA,CACR;AAAA,EACF;AAAA,EAGO,YAAY,KAAsB;AACjC,WAAA,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UUID } from "../bindingTypes.js";
|
|
3
|
+
import { whereToFilter } from "@contember/client";
|
|
4
|
+
import levenshtein from "js-levenshtein";
|
|
5
|
+
import { QueryLanguage } from "../queryLanguage/QueryLanguage.js";
|
|
6
|
+
class TreeNodeEnvironmentFactory {
|
|
7
|
+
static createEnvironmentForEntityListSubtree(environment, sugaredEntityList) {
|
|
8
|
+
let entityList;
|
|
9
|
+
let rootWhere;
|
|
10
|
+
let expectedCardinality;
|
|
11
|
+
if (sugaredEntityList.isCreating) {
|
|
12
|
+
entityList = QueryLanguage.desugarUnconstrainedQualifiedEntityList(sugaredEntityList, environment);
|
|
13
|
+
rootWhere = { id: { eq: NIL_UUID } };
|
|
14
|
+
expectedCardinality = "zero";
|
|
15
|
+
} else {
|
|
16
|
+
entityList = QueryLanguage.desugarQualifiedEntityList(sugaredEntityList, environment);
|
|
17
|
+
rootWhere = entityList.filter ?? {};
|
|
18
|
+
expectedCardinality = "zero-to-many";
|
|
19
|
+
}
|
|
20
|
+
const entitySchema = this.resolveEntity(environment.getSchema(), entityList.entityName, "entity list");
|
|
21
|
+
return environment.withSubTree({
|
|
22
|
+
type: "subtree-entity-list",
|
|
23
|
+
entity: entitySchema,
|
|
24
|
+
expectedCardinality,
|
|
25
|
+
filter: rootWhere
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
static createEnvironmentForEntitySubtree(environment, sugaredEntityList) {
|
|
29
|
+
let entity;
|
|
30
|
+
let rootWhere;
|
|
31
|
+
let expectedCardinality;
|
|
32
|
+
if (sugaredEntityList.isCreating) {
|
|
33
|
+
rootWhere = { id: { eq: NIL_UUID } };
|
|
34
|
+
expectedCardinality = "zero";
|
|
35
|
+
entity = QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(sugaredEntityList, environment);
|
|
36
|
+
} else {
|
|
37
|
+
entity = QueryLanguage.desugarQualifiedSingleEntity(sugaredEntityList, environment, { missingSetOnCreate: "fill" });
|
|
38
|
+
rootWhere = whereToFilter(entity.where);
|
|
39
|
+
expectedCardinality = entity.setOnCreate ? "zero-or-one" : "one";
|
|
40
|
+
}
|
|
41
|
+
const entitySchema = this.resolveEntity(environment.getSchema(), entity.entityName, "entity");
|
|
42
|
+
return environment.withSubTree({
|
|
43
|
+
type: "subtree-entity",
|
|
44
|
+
entity: entitySchema,
|
|
45
|
+
expectedCardinality,
|
|
46
|
+
filter: rootWhere
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
static createEnvironmentForEntityList(environment, sugaredRelativeEntityList) {
|
|
50
|
+
const relativeEntityList = QueryLanguage.desugarRelativeEntityList(sugaredRelativeEntityList, environment);
|
|
51
|
+
const hasOneEnvironment = this.traverseHasOnePath(environment, relativeEntityList.hasOneRelationPath);
|
|
52
|
+
const hasManyField = relativeEntityList.hasManyRelation.field;
|
|
53
|
+
const field = this.assertHasManyRelation(hasOneEnvironment, hasManyField);
|
|
54
|
+
const targetEntity = environment.getSchema().getEntity(field.targetEntity);
|
|
55
|
+
if (!targetEntity) {
|
|
56
|
+
throw new BindingError("should not happen");
|
|
57
|
+
}
|
|
58
|
+
return hasOneEnvironment.withSubTreeChild({
|
|
59
|
+
type: "entity-list",
|
|
60
|
+
field,
|
|
61
|
+
entity: targetEntity
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
static createEnvironmentForEntity(environment, sugaredRelativeSingleEntity) {
|
|
65
|
+
const relativeSingleEntity = QueryLanguage.desugarRelativeSingleEntity(sugaredRelativeSingleEntity, environment);
|
|
66
|
+
return this.traverseHasOnePath(environment, relativeSingleEntity.hasOneRelationPath);
|
|
67
|
+
}
|
|
68
|
+
static createEnvironmentForField(environment, sugaredRelativeSingleField) {
|
|
69
|
+
const relativeSingleField = QueryLanguage.desugarRelativeSingleField(sugaredRelativeSingleField, environment);
|
|
70
|
+
const hasOneEnvironment = this.traverseHasOnePath(environment, relativeSingleField.hasOneRelationPath);
|
|
71
|
+
const field = this.resolveColumn(hasOneEnvironment, relativeSingleField.field);
|
|
72
|
+
return hasOneEnvironment.withSubTreeChild({
|
|
73
|
+
type: "column",
|
|
74
|
+
entity: environment.getSubTreeNode().entity,
|
|
75
|
+
field
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
static traverseHasOnePath(environment, hasOneRelationPath) {
|
|
79
|
+
for (const pathItem of hasOneRelationPath) {
|
|
80
|
+
const field = this.resolveHasOneRelation(environment, pathItem.field, !!pathItem.reducedBy);
|
|
81
|
+
const targetEntity = environment.getSchema().getEntity(field.targetEntity);
|
|
82
|
+
if (!targetEntity) {
|
|
83
|
+
throw new BindingError("should not happen");
|
|
84
|
+
}
|
|
85
|
+
environment = environment.withSubTreeChild({
|
|
86
|
+
type: "entity",
|
|
87
|
+
field,
|
|
88
|
+
entity: targetEntity
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return environment;
|
|
92
|
+
}
|
|
93
|
+
static resolveHasOneRelation(environment, field, isReduced) {
|
|
94
|
+
if (isReduced) {
|
|
95
|
+
return this.resolveRelation(environment, field, "reduced has-one relation", ["ManyHasMany", "OneHasMany"]);
|
|
96
|
+
}
|
|
97
|
+
return this.resolveRelation(environment, field, "a has-one relation", ["ManyHasOne", "OneHasOne"]);
|
|
98
|
+
}
|
|
99
|
+
static assertHasManyRelation(environment, field) {
|
|
100
|
+
return this.resolveRelation(environment, field, "a has-many relation", ["ManyHasMany", "OneHasMany"]);
|
|
101
|
+
}
|
|
102
|
+
static resolveRelation(environment, field, relationDescription, expectedRelationType) {
|
|
103
|
+
return this.resolveField(environment, field, (field2) => {
|
|
104
|
+
return field2.__typename === "_Relation" && expectedRelationType.includes(field2.type);
|
|
105
|
+
}, relationDescription);
|
|
106
|
+
}
|
|
107
|
+
static resolveEntity(schema, entityName, type) {
|
|
108
|
+
const entity = schema.getEntity(entityName);
|
|
109
|
+
if (!entity) {
|
|
110
|
+
const alternative = this.recommendAlternative(entityName, schema.store.entities.keys());
|
|
111
|
+
const didYouMean = alternative ? `Did you mean '${alternative}'?` : "";
|
|
112
|
+
throw new BindingError(`Invalid ${type} sub tree: Entity '${entityName}' doesn't exist. ${didYouMean}`);
|
|
113
|
+
}
|
|
114
|
+
return entity;
|
|
115
|
+
}
|
|
116
|
+
static resolveColumn(environment, fieldName) {
|
|
117
|
+
return this.resolveField(environment, fieldName, (field) => field.__typename === "_Column", "an ordinary field");
|
|
118
|
+
}
|
|
119
|
+
static resolveField(environment, fieldName, matcher, expectedDescription) {
|
|
120
|
+
const treeLocation = environment.getSubTreeNode();
|
|
121
|
+
const entity = treeLocation.entity;
|
|
122
|
+
const field = entity.fields.get(fieldName);
|
|
123
|
+
if (!field) {
|
|
124
|
+
const alternative = this.recommendAlternative(fieldName, Array.from(entity.fields).filter(([, field2]) => matcher(field2)).map(([fieldName2]) => fieldName2));
|
|
125
|
+
const didYouMean = alternative ? `Did you mean '${alternative}'?` : "";
|
|
126
|
+
throw new BindingError(`Field '${fieldName}' doesn't exist on ${this.describeLocation(environment)}. ${didYouMean}`);
|
|
127
|
+
}
|
|
128
|
+
if (!matcher(field)) {
|
|
129
|
+
const actual = field.__typename === "_Column" ? "an ordinary field" : `a ${field.type} relation`;
|
|
130
|
+
throw new BindingError(`Invalid field: the name '${field.name}' on ${this.describeLocation(environment)} refers to ${actual} but is being used as a ${expectedDescription}.`);
|
|
131
|
+
}
|
|
132
|
+
return field;
|
|
133
|
+
}
|
|
134
|
+
static describeLocation(environment) {
|
|
135
|
+
const path = [];
|
|
136
|
+
for (let env = environment; ; env = env.getParent()) {
|
|
137
|
+
const node = env.getSubTreeNode();
|
|
138
|
+
if (node.type === "subtree-entity" || node.type === "subtree-entity-list") {
|
|
139
|
+
const pathText = path.length ? ` in path ${path.join(".")}` : "";
|
|
140
|
+
return `entity '${node.entity.name}'${pathText}`;
|
|
141
|
+
}
|
|
142
|
+
path.push(node.field.name);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
static recommendAlternative(original, possibleAlternatives) {
|
|
146
|
+
let bestAlternative = void 0;
|
|
147
|
+
let bestAlternativeDistance = Number.MAX_SAFE_INTEGER;
|
|
148
|
+
for (const alternative of possibleAlternatives) {
|
|
149
|
+
const distance = levenshtein(original, alternative);
|
|
150
|
+
if (distance < bestAlternativeDistance) {
|
|
151
|
+
bestAlternative = alternative;
|
|
152
|
+
bestAlternativeDistance = distance;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return bestAlternative;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
export { TreeNodeEnvironmentFactory };
|
|
159
|
+
//# sourceMappingURL=TreeNodeEnvironmentFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeNodeEnvironmentFactory.js","sources":["../../../src/dao/TreeNodeEnvironmentFactory.ts"],"sourcesContent":["import { Environment } from './Environment'\nimport {\n\tHasOneRelation,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredRelativeEntityList,\n\tSugaredRelativeSingleEntity,\n\tSugaredRelativeSingleField,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n} from '../treeParameters'\nimport { QueryLanguage } from '../queryLanguage'\nimport { BindingError } from '../BindingError'\nimport { NIL_UUID } from '../bindingTypes'\nimport { whereToFilter } from '@contember/client'\nimport { BaseRelation, Schema, SchemaColumn, SchemaEntity, SchemaField, SchemaRelation } from '../core/schema'\nimport levenshtein from 'js-levenshtein'\n\nexport class TreeNodeEnvironmentFactory {\n\n\tpublic static createEnvironmentForEntityListSubtree(\n\t\tenvironment: Environment,\n\t\tsugaredEntityList: SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t): Environment {\n\t\tlet entityList\n\t\tlet rootWhere\n\t\tlet expectedCardinality: Environment.SubTreeNode['expectedCardinality']\n\n\t\tif (sugaredEntityList.isCreating) {\n\t\t\tentityList = QueryLanguage.desugarUnconstrainedQualifiedEntityList(sugaredEntityList, environment)\n\t\t\trootWhere = { id: { eq: NIL_UUID } } as const\n\t\t\texpectedCardinality = 'zero'\n\n\t\t} else {\n\t\t\tentityList = QueryLanguage.desugarQualifiedEntityList(sugaredEntityList, environment)\n\t\t\trootWhere = entityList.filter ?? {}\n\t\t\texpectedCardinality = 'zero-to-many'\n\t\t}\n\n\t\tconst entitySchema = this.resolveEntity(environment.getSchema(), entityList.entityName, 'entity list')\n\n\t\treturn environment.withSubTree({\n\t\t\ttype: 'subtree-entity-list',\n\t\t\tentity: entitySchema,\n\t\t\texpectedCardinality,\n\t\t\tfilter: rootWhere,\n\t\t})\n\t}\n\n\tpublic static createEnvironmentForEntitySubtree(\n\t\tenvironment: Environment,\n\t\tsugaredEntityList: SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t): Environment {\n\t\tlet entity\n\t\tlet rootWhere\n\t\tlet expectedCardinality: Environment.SubTreeNode['expectedCardinality']\n\n\t\tif (sugaredEntityList.isCreating) {\n\t\t\trootWhere = { id: { eq: NIL_UUID } } as const\n\t\t\texpectedCardinality = 'zero'\n\t\t\tentity = QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(sugaredEntityList, environment)\n\n\t\t} else {\n\t\t\tentity = QueryLanguage.desugarQualifiedSingleEntity(sugaredEntityList, environment, { missingSetOnCreate: 'fill' })\n\t\t\trootWhere = whereToFilter(entity.where)\n\t\t\texpectedCardinality = entity.setOnCreate ? 'zero-or-one' : 'one'\n\t\t}\n\n\t\tconst entitySchema = this.resolveEntity(environment.getSchema(), entity.entityName, 'entity')\n\n\t\treturn environment.withSubTree({\n\t\t\ttype: 'subtree-entity',\n\t\t\tentity: entitySchema,\n\t\t\texpectedCardinality: expectedCardinality,\n\t\t\tfilter: rootWhere,\n\t\t})\n\t}\n\n\tpublic static createEnvironmentForEntityList(\n\t\tenvironment: Environment,\n\t\tsugaredRelativeEntityList: SugaredRelativeEntityList,\n\t): Environment {\n\t\tconst relativeEntityList = QueryLanguage.desugarRelativeEntityList(sugaredRelativeEntityList, environment)\n\t\tconst hasOneEnvironment = this.traverseHasOnePath(environment, relativeEntityList.hasOneRelationPath)\n\t\tconst hasManyField = relativeEntityList.hasManyRelation.field\n\n\t\tconst field = this.assertHasManyRelation(hasOneEnvironment, hasManyField)\n\n\t\tconst targetEntity = environment.getSchema().getEntity(field.targetEntity)\n\t\tif (!targetEntity) {\n\t\t\tthrow new BindingError('should not happen')\n\t\t}\n\t\treturn hasOneEnvironment.withSubTreeChild({\n\t\t\ttype: 'entity-list',\n\t\t\tfield,\n\t\t\tentity: targetEntity,\n\t\t})\n\t}\n\n\tpublic static createEnvironmentForEntity(\n\t\tenvironment: Environment,\n\t\tsugaredRelativeSingleEntity: SugaredRelativeSingleEntity,\n\t) {\n\t\tconst relativeSingleEntity = QueryLanguage.desugarRelativeSingleEntity(sugaredRelativeSingleEntity, environment)\n\n\t\treturn this.traverseHasOnePath(environment, relativeSingleEntity.hasOneRelationPath)\n\t}\n\n\tpublic static createEnvironmentForField(\n\t\tenvironment: Environment,\n\t\tsugaredRelativeSingleField: SugaredRelativeSingleField,\n\t) {\n\t\tconst relativeSingleField = QueryLanguage.desugarRelativeSingleField(sugaredRelativeSingleField, environment)\n\t\tconst hasOneEnvironment = this.traverseHasOnePath(environment, relativeSingleField.hasOneRelationPath)\n\n\t\tconst field = this.resolveColumn(hasOneEnvironment, relativeSingleField.field)\n\n\t\treturn hasOneEnvironment.withSubTreeChild({\n\t\t\ttype: 'column',\n\t\t\tentity: environment.getSubTreeNode().entity,\n\t\t\tfield,\n\t\t})\n\t}\n\n\tprivate static traverseHasOnePath(\n\t\tenvironment: Environment,\n\t\thasOneRelationPath: HasOneRelation[],\n\t): Environment {\n\t\tfor (const pathItem of hasOneRelationPath) {\n\t\t\tconst field = this.resolveHasOneRelation(environment, pathItem.field, !!pathItem.reducedBy)\n\t\t\tconst targetEntity = environment.getSchema().getEntity(field.targetEntity)\n\t\t\tif (!targetEntity) {\n\t\t\t\tthrow new BindingError('should not happen')\n\t\t\t}\n\t\t\tenvironment = environment.withSubTreeChild({\n\t\t\t\ttype: 'entity',\n\t\t\t\tfield,\n\t\t\t\tentity: targetEntity,\n\t\t\t})\n\t\t}\n\t\treturn environment\n\t}\n\n\tprivate static resolveHasOneRelation(environment: Environment, field: string, isReduced: boolean): SchemaRelation {\n\t\tif (isReduced) {\n\t\t\treturn this.resolveRelation(environment, field, 'reduced has-one relation', ['ManyHasMany', 'OneHasMany'])\n\t\t}\n\t\treturn this.resolveRelation(environment, field, 'a has-one relation', ['ManyHasOne', 'OneHasOne'])\n\t}\n\n\tprivate static assertHasManyRelation(environment: Environment, field: string): SchemaRelation {\n\t\treturn this.resolveRelation(environment, field, 'a has-many relation', ['ManyHasMany', 'OneHasMany'])\n\t}\n\n\n\tprivate static resolveRelation(environment: Environment, field: string, relationDescription: string, expectedRelationType: BaseRelation['type'][]): SchemaRelation {\n\t\treturn this.resolveField(environment, field, (field): field is SchemaRelation => {\n\t\t\treturn field.__typename === '_Relation' && expectedRelationType.includes(field.type)\n\t\t}, relationDescription)\n\t}\n\n\tprivate static resolveEntity(schema: Schema, entityName: string, type: 'entity' | 'entity list'): SchemaEntity {\n\t\tconst entity = schema.getEntity(entityName)\n\t\tif (!entity) {\n\t\t\tconst alternative = this.recommendAlternative(entityName, schema.store.entities.keys())\n\t\t\tconst didYouMean = alternative ? `Did you mean '${alternative}'?` : ''\n\t\t\tthrow new BindingError(`Invalid ${type} sub tree: Entity '${entityName}' doesn't exist. ${didYouMean}`)\n\t\t}\n\t\treturn entity\n\t}\n\n\tprivate static resolveColumn(environment: Environment, fieldName: string): SchemaColumn {\n\t\treturn this.resolveField(environment, fieldName, (field): field is SchemaColumn => field.__typename === '_Column', 'an ordinary field')\n\t\t// TODO check that defaultValue matches the type\n\t\t// TODO run custom validators\n\t}\n\n\tprivate static resolveField<T extends SchemaField>(environment: Environment, fieldName: string, matcher: (field: SchemaField) => field is T, expectedDescription: string): T {\n\t\tconst treeLocation = environment.getSubTreeNode()\n\t\tconst entity = treeLocation.entity\n\t\tconst field = entity.fields.get(fieldName)\n\t\tif (!field) {\n\t\t\tconst alternative = this.recommendAlternative(\n\t\t\t\tfieldName,\n\t\t\t\tArray.from(entity.fields)\n\t\t\t\t\t.filter(([, field]) => matcher(field))\n\t\t\t\t\t.map(([fieldName]) => fieldName),\n\t\t\t)\n\t\t\tconst didYouMean = alternative ? `Did you mean '${alternative}'?` : ''\n\t\t\tthrow new BindingError(`Field '${fieldName}' doesn't exist on ${this.describeLocation(environment)}. ${didYouMean}`)\n\t\t}\n\t\tif (!matcher(field)) {\n\t\t\tconst actual = field.__typename === '_Column' ? 'an ordinary field' : `a ${field.type} relation`\n\t\t\tthrow new BindingError(\n\t\t\t\t`Invalid field: the name '${field.name}' on ${this.describeLocation(environment)} ` +\n\t\t\t\t`refers to ${actual} but is being used as a ${expectedDescription}.`,\n\t\t\t)\n\t\t}\n\t\treturn field\n\t}\n\n\tprivate static describeLocation(environment: Environment): string {\n\t\tconst path = []\n\t\tfor (let env = environment;; env = env.getParent()) {\n\t\t\tconst node = env.getSubTreeNode()\n\t\t\tif (node.type === 'subtree-entity' || node.type === 'subtree-entity-list') {\n\t\t\t\tconst pathText = path.length ? ` in path ${path.join('.')}` : ''\n\t\t\t\treturn `entity '${node.entity.name}'${pathText}`\n\t\t\t}\n\t\t\tpath.push(node.field.name)\n\t\t}\n\t}\n\n\tpublic static recommendAlternative(original: string, possibleAlternatives: Iterable<string>): string | undefined {\n\t\tlet bestAlternative: string | undefined = undefined\n\t\tlet bestAlternativeDistance = Number.MAX_SAFE_INTEGER\n\n\t\tfor (const alternative of possibleAlternatives) {\n\t\t\tconst distance = levenshtein(original, alternative)\n\n\t\t\tif (distance < bestAlternativeDistance) {\n\t\t\t\tbestAlternative = alternative\n\t\t\t\tbestAlternativeDistance = distance\n\t\t\t}\n\t\t}\n\t\treturn bestAlternative\n\t}\n}\n"],"names":[],"mappings":";;;;;AAkBO,MAAM,2BAA2B;AAAA,SAEzB,sCACb,aACA,mBACc;AACV,QAAA;A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M,eAAe,YAAY,sBAAsB,KAAK,MAAM;AAC3E,YAAA,IAAI,aACT,4BAA4B,MAAM,YAAY,KAAK,iBAAiB,WAAW,eAClE,iCAAiC,sBAC/C;AAAA,IACD;AACO,WAAA;AAAA,EACR;AAAA,SAEe,iBAAiB,aAAkC;AACjE,UAAM,OAAO,CAAA;AACb,aAAS,MAAM,eAAc,MAAM,IAAI,aAAa;AAC7C,YAAA,OAAO,IAAI;AACjB,UAAI,KAAK,SAAS,oBAAoB,KAAK,SAAS,uBAAuB;AAC1E,cAAM,WAAW,KAAK,SAAS,YAAY,KAAK,KAAK,GAAG,MAAM;AACvD,eAAA,WAAW,KAAK,OAAO,QAAQ;AAAA,MACvC;AACK,WAAA,KAAK,KAAK,MAAM,IAAI;AAAA,IAC1B;AAAA,EACD;AAAA,SAEc,qBAAqB,UAAkB,sBAA4D;AAChH,QAAI,kBAAsC;AAC1C,QAAI,0BAA0B,OAAO;AAErC,eAAW,eAAe,sBAAsB;AACzC,YAAA,WAAW,YAAY,UAAU,WAAW;AAElD,UAAI,WAAW,yBAAyB;AACrB,0BAAA;AACQ,kCAAA;AAAA,MAC3B;AAAA,IACD;AACO,WAAA;AAAA,EACR;AACD;;"}
|
|
@@ -62,22 +62,23 @@ class MarkerFactory {
|
|
|
62
62
|
const relativeEntityList = QueryLanguage.desugarRelativeEntityList(field, environment);
|
|
63
63
|
if (fields instanceof EntityFieldMarkersContainer) {
|
|
64
64
|
const hasManyRelationMarker2 = this.createHasManyRelationMarker(relativeEntityList.hasManyRelation, environment, fields);
|
|
65
|
-
return this.wrapRelativeEntityFieldMarkers(relativeEntityList.hasOneRelationPath, environment, this.createEntityFieldMarkersContainer(hasManyRelationMarker2));
|
|
65
|
+
return this.wrapRelativeEntityFieldMarkers(relativeEntityList.hasOneRelationPath, environment.getParent(), this.createEntityFieldMarkersContainer(hasManyRelationMarker2));
|
|
66
66
|
}
|
|
67
67
|
relativeEntityList.hasManyRelation = TreeParameterMerger.mergeInParentEntity(relativeEntityList.hasManyRelation, "childEventListeners", fields.parentReference);
|
|
68
68
|
const hasManyRelationMarker = this.createHasManyRelationMarker(relativeEntityList.hasManyRelation, environment, fields.fields);
|
|
69
|
-
return new EntityFieldsWithHoistablesMarker(this.wrapRelativeEntityFieldMarkers(relativeEntityList.hasOneRelationPath, environment, this.createEntityFieldMarkersContainer(hasManyRelationMarker)), fields.subTrees, void 0);
|
|
69
|
+
return new EntityFieldsWithHoistablesMarker(this.wrapRelativeEntityFieldMarkers(relativeEntityList.hasOneRelationPath, environment.getParent(), this.createEntityFieldMarkersContainer(hasManyRelationMarker)), fields.subTrees, void 0);
|
|
70
70
|
}
|
|
71
71
|
static createFieldMarker(field, environment) {
|
|
72
72
|
return this.wrapRelativeSingleField(field, environment, (relativeSingleField) => new FieldMarker(relativeSingleField.field, relativeSingleField.defaultValue, relativeSingleField.isNonbearing));
|
|
73
73
|
}
|
|
74
74
|
static wrapRelativeSingleField(field, environment, getMarker) {
|
|
75
75
|
const relativeSingleField = QueryLanguage.desugarRelativeSingleField(field, environment);
|
|
76
|
-
return this.wrapRelativeEntityFieldMarkers(relativeSingleField.hasOneRelationPath, environment, this.createEntityFieldMarkersContainer(getMarker(relativeSingleField)));
|
|
76
|
+
return this.wrapRelativeEntityFieldMarkers(relativeSingleField.hasOneRelationPath, environment.getParent(), this.createEntityFieldMarkersContainer(getMarker(relativeSingleField)));
|
|
77
77
|
}
|
|
78
78
|
static wrapRelativeEntityFieldMarkers(hasOneRelationPath, environment, fields) {
|
|
79
79
|
for (let i = hasOneRelationPath.length - 1; i >= 0; i--) {
|
|
80
80
|
const marker = this.createHasOneRelationMarker(hasOneRelationPath[i], environment, fields);
|
|
81
|
+
environment = environment.getParent();
|
|
81
82
|
fields = this.createEntityFieldMarkersContainer(marker);
|
|
82
83
|
}
|
|
83
84
|
return fields;
|