@contember/binding-common 2.2.0-alpha.2 → 2.2.0-alpha.21
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/index.cjs +2 -2
- package/dist/development/index.js +2 -2
- package/dist/development/src/environment/Environment.cjs +5 -5
- package/dist/development/src/environment/Environment.cjs.map +1 -1
- package/dist/development/src/environment/Environment.js +5 -5
- package/dist/development/src/environment/Environment.js.map +1 -1
- package/dist/production/index.cjs +2 -2
- package/dist/production/index.js +2 -2
- package/dist/production/src/environment/Environment.cjs +5 -5
- package/dist/production/src/environment/Environment.cjs.map +1 -1
- package/dist/production/src/environment/Environment.js +5 -5
- package/dist/production/src/environment/Environment.js.map +1 -1
- package/dist/types/BindingError.d.ts.map +1 -1
- package/dist/types/LocalizedBindingError.d.ts.map +1 -1
- package/dist/types/RuntimeId.d.ts.map +1 -1
- package/dist/types/environment/Environment.d.ts +1 -1
- package/dist/types/environment/Environment.d.ts.map +1 -1
- package/dist/types/environment/TreeNodeEnvironmentFactory.d.ts.map +1 -1
- package/dist/types/environment/VariableFieldValue.d.ts.map +1 -1
- package/dist/types/environment/VariableInputTransformer.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markers/EntityFieldMarkersContainer.d.ts.map +1 -1
- package/dist/types/markers/EntityFieldsWithHoistablesMarker.d.ts.map +1 -1
- package/dist/types/markers/EntityListSubTreeMarker.d.ts.map +1 -1
- package/dist/types/markers/EntitySubTreeMarker.d.ts.map +1 -1
- package/dist/types/markers/FieldMarker.d.ts.map +1 -1
- package/dist/types/markers/HasManyRelationMarker.d.ts.map +1 -1
- package/dist/types/markers/HasOneRelationMarker.d.ts.map +1 -1
- package/dist/types/markers/MarkerComparator.d.ts.map +1 -1
- package/dist/types/markers/MarkerMerger.d.ts.map +1 -1
- package/dist/types/markers/MarkerTreeRoot.d.ts.map +1 -1
- package/dist/types/markers/PlaceholderGenerator.d.ts.map +1 -1
- package/dist/types/markers/PlaceholderParametersGenerator.d.ts.map +1 -1
- package/dist/types/queryLanguage/CacheStore.d.ts.map +1 -1
- package/dist/types/queryLanguage/MarkerFactory.d.ts.map +1 -1
- package/dist/types/queryLanguage/Parser.d.ts.map +1 -1
- package/dist/types/queryLanguage/QueryLanguage.d.ts.map +1 -1
- package/dist/types/queryLanguage/tokenList.d.ts.map +1 -1
- package/dist/types/schema/Schema.d.ts.map +1 -1
- package/dist/types/schema/SchemaLoader.d.ts.map +1 -1
- package/dist/types/schema/SchemaPreprocessor.d.ts.map +1 -1
- package/dist/types/treeParameters/EventListenersStore.d.ts.map +1 -1
- package/dist/types/treeParameters/TreeParameterMerger.d.ts.map +1 -1
- package/dist/types/treeParameters/defaults.d.ts +2 -2
- package/dist/types/treeParameters/defaults.d.ts.map +1 -1
- package/dist/types/treeParameters/helpers/wrapFilterInHasOnes.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types/EntityAccessor.d.ts.map +1 -1
- package/dist/types/types/EntityListAccessor.d.ts.map +1 -1
- package/dist/types/types/ErrorAccessor.d.ts.map +1 -1
- package/dist/types/types/FieldAccessor.d.ts.map +1 -1
- package/dist/types/types/Persist.d.ts +7 -0
- package/dist/types/types/Persist.d.ts.map +1 -1
- package/dist/types/types/PersistResult.d.ts.map +1 -1
- package/dist/types/types/TreeRootAccessor.d.ts.map +1 -1
- package/dist/types/utils/Hashing.d.ts.map +1 -1
- package/dist/types/utils/TreeNodeUtils.d.ts.map +1 -1
- package/dist/types/utils/createQueryBuilder.d.ts.map +1 -1
- package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts.map +1 -1
- package/dist/types/utils/whereToFilter.d.ts.map +1 -1
- package/package.json +5 -7
- package/src/environment/Environment.ts +5 -5
- package/src/index.ts +1 -1
- package/src/types/Persist.ts +7 -0
|
@@ -9,7 +9,7 @@ const TreeNodeUtils = require("./src/utils/TreeNodeUtils.cjs");
|
|
|
9
9
|
const assertNever = require("./src/utils/assertNever.cjs");
|
|
10
10
|
const createQueryBuilder = require("./src/utils/createQueryBuilder.cjs");
|
|
11
11
|
const whereToFilter = require("./src/utils/whereToFilter.cjs");
|
|
12
|
-
const
|
|
12
|
+
const utilities = require("@contember/utilities");
|
|
13
13
|
const defaults = require("./src/treeParameters/defaults.cjs");
|
|
14
14
|
const EntityFieldMarkersContainer = require("./src/markers/EntityFieldMarkersContainer.cjs");
|
|
15
15
|
const EntityFieldsWithHoistablesMarker = require("./src/markers/EntityFieldsWithHoistablesMarker.cjs");
|
|
@@ -60,7 +60,7 @@ exports.createQueryBuilder = createQueryBuilder.createQueryBuilder;
|
|
|
60
60
|
exports.whereToFilter = whereToFilter.whereToFilter;
|
|
61
61
|
Object.defineProperty(exports, "generateUuid", {
|
|
62
62
|
enumerable: true,
|
|
63
|
-
get: () =>
|
|
63
|
+
get: () => utilities.generateUuidV4
|
|
64
64
|
});
|
|
65
65
|
exports.EntityCreationParametersDefaults = defaults.EntityCreationParametersDefaults;
|
|
66
66
|
exports.EntityListPreferencesDefaults = defaults.EntityListPreferencesDefaults;
|
|
@@ -7,7 +7,7 @@ import { TreeNodeUtils } from "./src/utils/TreeNodeUtils.js";
|
|
|
7
7
|
import { assertNever } from "./src/utils/assertNever.js";
|
|
8
8
|
import { createQueryBuilder } from "./src/utils/createQueryBuilder.js";
|
|
9
9
|
import { whereToFilter } from "./src/utils/whereToFilter.js";
|
|
10
|
-
import {
|
|
10
|
+
import { generateUuidV4 } from "@contember/utilities";
|
|
11
11
|
import { EntityCreationParametersDefaults, EntityListPreferencesDefaults, LeafFieldDefaults, QualifiedEntityParametersDefaults, RelationDefaults } from "./src/treeParameters/defaults.js";
|
|
12
12
|
import { EntityFieldMarkersContainer } from "./src/markers/EntityFieldMarkersContainer.js";
|
|
13
13
|
import { EntityFieldsWithHoistablesMarker } from "./src/markers/EntityFieldsWithHoistablesMarker.js";
|
|
@@ -88,7 +88,7 @@ export {
|
|
|
88
88
|
VariableInputTransformer,
|
|
89
89
|
assertNever,
|
|
90
90
|
createQueryBuilder,
|
|
91
|
-
|
|
91
|
+
generateUuidV4 as generateUuid,
|
|
92
92
|
isEntityAccessor,
|
|
93
93
|
isEntityListAccessor,
|
|
94
94
|
isErrorPersistResult,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const BindingError = require("../BindingError.cjs");
|
|
4
|
-
const
|
|
4
|
+
const utilities = require("@contember/utilities");
|
|
5
5
|
class Environment {
|
|
6
6
|
constructor(options) {
|
|
7
7
|
this.options = options;
|
|
@@ -121,7 +121,7 @@ class Environment {
|
|
|
121
121
|
...this.options.dimensions,
|
|
122
122
|
...dimensions
|
|
123
123
|
};
|
|
124
|
-
if (
|
|
124
|
+
if (utilities.deepEqual(newDimensions, this.options.dimensions)) {
|
|
125
125
|
return this;
|
|
126
126
|
}
|
|
127
127
|
return new Environment({ ...this.options, dimensions: newDimensions });
|
|
@@ -158,7 +158,7 @@ class Environment {
|
|
|
158
158
|
if (other === this) {
|
|
159
159
|
return this;
|
|
160
160
|
}
|
|
161
|
-
if (!
|
|
161
|
+
if (!utilities.deepEqual(this.options.node, other.options.node)) {
|
|
162
162
|
throw new BindingError.BindingError(`Cannot merge two environments with different tree position.`);
|
|
163
163
|
}
|
|
164
164
|
if (this.options.parameters !== other.options.parameters) {
|
|
@@ -170,11 +170,11 @@ class Environment {
|
|
|
170
170
|
if (this.options.extensions !== other.options.extensions) {
|
|
171
171
|
throw new BindingError.BindingError(`Cannot merge two environments with different extensions.`);
|
|
172
172
|
}
|
|
173
|
-
if (
|
|
173
|
+
if (utilities.deepEqual(this.options.variables, other.options.variables) && this.options.parent === other.options.parent) {
|
|
174
174
|
return this;
|
|
175
175
|
}
|
|
176
176
|
for (const key in other.options.variables) {
|
|
177
|
-
if (key in this.options.variables && !
|
|
177
|
+
if (key in this.options.variables && !utilities.deepEqual(this.options.variables[key], other.options.variables[key])) {
|
|
178
178
|
throw new BindingError.BindingError(
|
|
179
179
|
`Cannot merge two environments with different value of variable ${key}:
|
|
180
180
|
` + JSON.stringify(this.options.variables[key]) + "\n" + JSON.stringify(other.options.variables[key])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Environment.cjs","sources":["../../../../../packages/binding-common/src/environment/Environment.ts"],"sourcesContent":["import { BindingError } from '../BindingError.js'\nimport type { Filter } from '../treeParameters/index.js'\nimport equal from 'fast-deep-equal/es6/index.js'\nimport { Schema, SchemaColumn, SchemaEntity, SchemaRelation } from '../schema/index.js'\n\nclass Environment<Node extends Environment.AnyNode | undefined = Environment.AnyNode | undefined> {\n\tprivate constructor(\n\t\tprivate readonly options: Environment.Options<Node>,\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\textensions: new Map(),\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(): Node & 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<Node extends Environment.SubTreeNode>(SubTree: Node): Environment<Node> {\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 extends Environment.InnerNode>(node: Node): Environment<Node> {\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\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\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\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({\n\t\t\t...this.options,\n\t\t\tvariables: newVariables,\n\t\t\tparent: this,\n\t\t})\n\t}\n\n\tpublic getAllVariables() {\n\t\treturn this.options.variables\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 | number {\n\t\tif (!(key in this.options.parameters)) {\n\t\t\tthrow new BindingError(`Parameter ${key} not found`)\n\t\t}\n\t\treturn this.options.parameters[key] as string | number\n\t}\n\n\tpublic getParameterOrElse<F>(key: string, fallback: F): string | number | F {\n\t\treturn this.options.parameters[key] ?? fallback\n\t}\n\n\tpublic getAllParameters() {\n\t\treturn this.options.parameters\n\t}\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\thasSchema(): boolean {\n\t\treturn this.options.schema !== undefined\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 withExtension<S, R>(extension: Environment.Extension<S, R>, state: S): Environment {\n\t\treturn new Environment({\n\t\t\t...this.options,\n\t\t\textensions: new Map([...this.options.extensions, [extension, state] as [Environment.Extension<unknown, unknown>, unknown]]),\n\t\t})\n\t}\n\n\tpublic getExtension<S, R>(extension: Environment.Extension<S, R>): R {\n\t\tconst state = this.options.extensions.get(extension as Environment.Extension<unknown, unknown>)\n\t\treturn extension.create(state as S, this)\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 (this.options.extensions !== other.options.extensions) {\n\t\t\t// todo: deep compare?\n\t\t\tthrow new BindingError(`Cannot merge two environments with different extensions.`)\n\t\t}\n\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(\n\t\t\t\t\t`Cannot merge two environments with different value of variable ${key}:\\n`\n\t\t\t\t\t\t+ JSON.stringify(this.options.variables[key]) + '\\n'\n\t\t\t\t\t\t+ JSON.stringify(other.options.variables[key]),\n\t\t\t\t)\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 = unknown\n\n\texport type ResolvedValue = Value\n\n\texport interface Options<Node extends AnyNode | undefined> {\n\t\tnode?: Node\n\t\tschema?: Schema\n\t\tdimensions: SelectedDimensions\n\t\tparameters: Parameters\n\t\tvariables: CustomVariables\n\t\tparent?: Environment\n\t\textensions: Map<Extension<unknown, unknown>, unknown>\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 type Parameters = {\n\t\t[K in string]?: string | number\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\texport type Extension<State, Result> = {\n\t\tcreate: (state: State | undefined, environment: Environment) => Result\n\t}\n\n\texport const createExtension = <S, R>(create: Extension<S, R>['create'], otherMethods?: Omit<Extension<S, R>, 'create'>): Extension<S, R> => {\n\t\treturn {\n\t\t\tcreate,\n\t\t\t...otherMethods,\n\t\t}\n\t}\n}\n\nexport { Environment }\n"],"names":["BindingError","Environment"],"mappings":";;;;AAKA,MAAM,YAA4F;AAAA,EACzF,YACU,SAChB;AADgB,SAAA,UAAA;AAAA,EAElB;AAAA,EAEA,OAAc,SAAS;AACtB,WAAO,IAAI,YAAY;AAAA,MACtB,YAAY,CAAA;AAAA,MACZ,WAAW,CAAA;AAAA,MACX,YAAY,CAAA;AAAA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AG,KAAK,QAAQ,WAAW,GAAG,MAAM,QAAQ,UAAA;AAAA,IAAU,CACnE;AAAA,EACF;AACD;AAAA,CAEA,CAAUC,iBAAV;AAoFcA,eAAA,kBAAkB,CAAO,QAAmC,iBAAoE;AAC5I,WAAO;AAAA,MACN;AAAA,MACA,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,GAzFS,gBAAA,cAAA,CAAA,EAAA;;"}
|
|
1
|
+
{"version":3,"file":"Environment.cjs","sources":["../../../../../packages/binding-common/src/environment/Environment.ts"],"sourcesContent":["import { BindingError } from '../BindingError.js'\nimport type { Filter } from '../treeParameters/index.js'\nimport { deepEqual } from '@contember/utilities'\nimport { Schema, SchemaColumn, SchemaEntity, SchemaRelation } from '../schema/index.js'\n\nclass Environment<Node extends Environment.AnyNode | undefined = Environment.AnyNode | undefined> {\n\tprivate constructor(\n\t\tprivate readonly options: Environment.Options<Node>,\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\textensions: new Map(),\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(): Node & 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<Node extends Environment.SubTreeNode>(SubTree: Node): Environment<Node> {\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 extends Environment.InnerNode>(node: Node): Environment<Node> {\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\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\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\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({\n\t\t\t...this.options,\n\t\t\tvariables: newVariables,\n\t\t\tparent: this,\n\t\t})\n\t}\n\n\tpublic getAllVariables() {\n\t\treturn this.options.variables\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 | number {\n\t\tif (!(key in this.options.parameters)) {\n\t\t\tthrow new BindingError(`Parameter ${key} not found`)\n\t\t}\n\t\treturn this.options.parameters[key] as string | number\n\t}\n\n\tpublic getParameterOrElse<F>(key: string, fallback: F): string | number | F {\n\t\treturn this.options.parameters[key] ?? fallback\n\t}\n\n\tpublic getAllParameters() {\n\t\treturn this.options.parameters\n\t}\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 (deepEqual(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\thasSchema(): boolean {\n\t\treturn this.options.schema !== undefined\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 withExtension<S, R>(extension: Environment.Extension<S, R>, state: S): Environment {\n\t\treturn new Environment({\n\t\t\t...this.options,\n\t\t\textensions: new Map([...this.options.extensions, [extension, state] as [Environment.Extension<unknown, unknown>, unknown]]),\n\t\t})\n\t}\n\n\tpublic getExtension<S, R>(extension: Environment.Extension<S, R>): R {\n\t\tconst state = this.options.extensions.get(extension as Environment.Extension<unknown, unknown>)\n\t\treturn extension.create(state as S, this)\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 (!deepEqual(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 (this.options.extensions !== other.options.extensions) {\n\t\t\t// todo: deep compare?\n\t\t\tthrow new BindingError(`Cannot merge two environments with different extensions.`)\n\t\t}\n\n\t\tif (deepEqual(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 && !deepEqual(this.options.variables[key], other.options.variables[key])) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`Cannot merge two environments with different value of variable ${key}:\\n`\n\t\t\t\t\t\t+ JSON.stringify(this.options.variables[key]) + '\\n'\n\t\t\t\t\t\t+ JSON.stringify(other.options.variables[key]),\n\t\t\t\t)\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 = unknown\n\n\texport type ResolvedValue = Value\n\n\texport interface Options<Node extends AnyNode | undefined> {\n\t\tnode?: Node\n\t\tschema?: Schema\n\t\tdimensions: SelectedDimensions\n\t\tparameters: Parameters\n\t\tvariables: CustomVariables\n\t\tparent?: Environment\n\t\textensions: Map<Extension<unknown, unknown>, unknown>\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 type Parameters = {\n\t\t[K in string]?: string | number\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\texport type Extension<State, Result> = {\n\t\tcreate: (state: State | undefined, environment: Environment) => Result\n\t}\n\n\texport const createExtension = <S, R>(create: Extension<S, R>['create'], otherMethods?: Omit<Extension<S, R>, 'create'>): Extension<S, R> => {\n\t\treturn {\n\t\t\tcreate,\n\t\t\t...otherMethods,\n\t\t}\n\t}\n}\n\nexport { Environment }\n"],"names":["BindingError","deepEqual","Environment"],"mappings":";;;;AAKA,MAAM,YAA4F;AAAA,EACzF,YACU,SAChB;AADgB,SAAA,UAAA;AAAA,EAElB;AAAA,EAEA,OAAc,SAAS;AACtB,WAAO,IAAI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K,QAAQ,UAAU,MAAM,QAAQ,SAAS,KAAK,QAAQ,OAAO,MAAM,MAAM,QAAQ,MAAM,IAAI;AAAA,MACxG,WAAW,EAAE,GAAG,KAAK,QAAQ,WAAW,GAAG,MAAM,QAAQ,UAAA;AAAA,IAAU,CACnE;AAAA,EACF;AACD;AAAA,CAEA,CAAUE,iBAAV;AAoFcA,eAAA,kBAAkB,CAAO,QAAmC,iBAAoE;AAC5I,WAAO;AAAA,MACN;AAAA,MACA,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,GAzFS,gBAAA,cAAA,CAAA,EAAA;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BindingError } from "../BindingError.js";
|
|
2
|
-
import
|
|
2
|
+
import { deepEqual } from "@contember/utilities";
|
|
3
3
|
class Environment {
|
|
4
4
|
constructor(options) {
|
|
5
5
|
this.options = options;
|
|
@@ -119,7 +119,7 @@ class Environment {
|
|
|
119
119
|
...this.options.dimensions,
|
|
120
120
|
...dimensions
|
|
121
121
|
};
|
|
122
|
-
if (
|
|
122
|
+
if (deepEqual(newDimensions, this.options.dimensions)) {
|
|
123
123
|
return this;
|
|
124
124
|
}
|
|
125
125
|
return new Environment({ ...this.options, dimensions: newDimensions });
|
|
@@ -156,7 +156,7 @@ class Environment {
|
|
|
156
156
|
if (other === this) {
|
|
157
157
|
return this;
|
|
158
158
|
}
|
|
159
|
-
if (!
|
|
159
|
+
if (!deepEqual(this.options.node, other.options.node)) {
|
|
160
160
|
throw new BindingError(`Cannot merge two environments with different tree position.`);
|
|
161
161
|
}
|
|
162
162
|
if (this.options.parameters !== other.options.parameters) {
|
|
@@ -168,11 +168,11 @@ class Environment {
|
|
|
168
168
|
if (this.options.extensions !== other.options.extensions) {
|
|
169
169
|
throw new BindingError(`Cannot merge two environments with different extensions.`);
|
|
170
170
|
}
|
|
171
|
-
if (
|
|
171
|
+
if (deepEqual(this.options.variables, other.options.variables) && this.options.parent === other.options.parent) {
|
|
172
172
|
return this;
|
|
173
173
|
}
|
|
174
174
|
for (const key in other.options.variables) {
|
|
175
|
-
if (key in this.options.variables && !
|
|
175
|
+
if (key in this.options.variables && !deepEqual(this.options.variables[key], other.options.variables[key])) {
|
|
176
176
|
throw new BindingError(
|
|
177
177
|
`Cannot merge two environments with different value of variable ${key}:
|
|
178
178
|
` + JSON.stringify(this.options.variables[key]) + "\n" + JSON.stringify(other.options.variables[key])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Environment.js","sources":["../../../../../packages/binding-common/src/environment/Environment.ts"],"sourcesContent":["import { BindingError } from '../BindingError.js'\nimport type { Filter } from '../treeParameters/index.js'\nimport equal from 'fast-deep-equal/es6/index.js'\nimport { Schema, SchemaColumn, SchemaEntity, SchemaRelation } from '../schema/index.js'\n\nclass Environment<Node extends Environment.AnyNode | undefined = Environment.AnyNode | undefined> {\n\tprivate constructor(\n\t\tprivate readonly options: Environment.Options<Node>,\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\textensions: new Map(),\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(): Node & 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<Node extends Environment.SubTreeNode>(SubTree: Node): Environment<Node> {\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 extends Environment.InnerNode>(node: Node): Environment<Node> {\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\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\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\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({\n\t\t\t...this.options,\n\t\t\tvariables: newVariables,\n\t\t\tparent: this,\n\t\t})\n\t}\n\n\tpublic getAllVariables() {\n\t\treturn this.options.variables\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 | number {\n\t\tif (!(key in this.options.parameters)) {\n\t\t\tthrow new BindingError(`Parameter ${key} not found`)\n\t\t}\n\t\treturn this.options.parameters[key] as string | number\n\t}\n\n\tpublic getParameterOrElse<F>(key: string, fallback: F): string | number | F {\n\t\treturn this.options.parameters[key] ?? fallback\n\t}\n\n\tpublic getAllParameters() {\n\t\treturn this.options.parameters\n\t}\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\thasSchema(): boolean {\n\t\treturn this.options.schema !== undefined\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 withExtension<S, R>(extension: Environment.Extension<S, R>, state: S): Environment {\n\t\treturn new Environment({\n\t\t\t...this.options,\n\t\t\textensions: new Map([...this.options.extensions, [extension, state] as [Environment.Extension<unknown, unknown>, unknown]]),\n\t\t})\n\t}\n\n\tpublic getExtension<S, R>(extension: Environment.Extension<S, R>): R {\n\t\tconst state = this.options.extensions.get(extension as Environment.Extension<unknown, unknown>)\n\t\treturn extension.create(state as S, this)\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 (this.options.extensions !== other.options.extensions) {\n\t\t\t// todo: deep compare?\n\t\t\tthrow new BindingError(`Cannot merge two environments with different extensions.`)\n\t\t}\n\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(\n\t\t\t\t\t`Cannot merge two environments with different value of variable ${key}:\\n`\n\t\t\t\t\t\t+ JSON.stringify(this.options.variables[key]) + '\\n'\n\t\t\t\t\t\t+ JSON.stringify(other.options.variables[key]),\n\t\t\t\t)\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 = unknown\n\n\texport type ResolvedValue = Value\n\n\texport interface Options<Node extends AnyNode | undefined> {\n\t\tnode?: Node\n\t\tschema?: Schema\n\t\tdimensions: SelectedDimensions\n\t\tparameters: Parameters\n\t\tvariables: CustomVariables\n\t\tparent?: Environment\n\t\textensions: Map<Extension<unknown, unknown>, unknown>\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 type Parameters = {\n\t\t[K in string]?: string | number\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\texport type Extension<State, Result> = {\n\t\tcreate: (state: State | undefined, environment: Environment) => Result\n\t}\n\n\texport const createExtension = <S, R>(create: Extension<S, R>['create'], otherMethods?: Omit<Extension<S, R>, 'create'>): Extension<S, R> => {\n\t\treturn {\n\t\t\tcreate,\n\t\t\t...otherMethods,\n\t\t}\n\t}\n}\n\nexport { Environment }\n"],"names":["Environment"],"mappings":";;AAKA,MAAM,YAA4F;AAAA,EACzF,YACU,SAChB;AADgB,SAAA,UAAA;AAAA,EAElB;AAAA,EAEA,OAAc,SAAS;AACtB,WAAO,IAAI,YAAY;AAAA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AAAA,IAAU,CACnE;AAAA,EACF;AACD;AAAA,CAEA,CAAUA,iBAAV;AAoFcA,eAAA,kBAAkB,CAAO,QAAmC,iBAAoE;AAC5I,WAAO;AAAA,MACN;AAAA,MACA,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,GAzFS,gBAAA,cAAA,CAAA,EAAA;"}
|
|
1
|
+
{"version":3,"file":"Environment.js","sources":["../../../../../packages/binding-common/src/environment/Environment.ts"],"sourcesContent":["import { BindingError } from '../BindingError.js'\nimport type { Filter } from '../treeParameters/index.js'\nimport { deepEqual } from '@contember/utilities'\nimport { Schema, SchemaColumn, SchemaEntity, SchemaRelation } from '../schema/index.js'\n\nclass Environment<Node extends Environment.AnyNode | undefined = Environment.AnyNode | undefined> {\n\tprivate constructor(\n\t\tprivate readonly options: Environment.Options<Node>,\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\textensions: new Map(),\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(): Node & 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<Node extends Environment.SubTreeNode>(SubTree: Node): Environment<Node> {\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 extends Environment.InnerNode>(node: Node): Environment<Node> {\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\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\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\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({\n\t\t\t...this.options,\n\t\t\tvariables: newVariables,\n\t\t\tparent: this,\n\t\t})\n\t}\n\n\tpublic getAllVariables() {\n\t\treturn this.options.variables\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 | number {\n\t\tif (!(key in this.options.parameters)) {\n\t\t\tthrow new BindingError(`Parameter ${key} not found`)\n\t\t}\n\t\treturn this.options.parameters[key] as string | number\n\t}\n\n\tpublic getParameterOrElse<F>(key: string, fallback: F): string | number | F {\n\t\treturn this.options.parameters[key] ?? fallback\n\t}\n\n\tpublic getAllParameters() {\n\t\treturn this.options.parameters\n\t}\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 (deepEqual(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\thasSchema(): boolean {\n\t\treturn this.options.schema !== undefined\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 withExtension<S, R>(extension: Environment.Extension<S, R>, state: S): Environment {\n\t\treturn new Environment({\n\t\t\t...this.options,\n\t\t\textensions: new Map([...this.options.extensions, [extension, state] as [Environment.Extension<unknown, unknown>, unknown]]),\n\t\t})\n\t}\n\n\tpublic getExtension<S, R>(extension: Environment.Extension<S, R>): R {\n\t\tconst state = this.options.extensions.get(extension as Environment.Extension<unknown, unknown>)\n\t\treturn extension.create(state as S, this)\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 (!deepEqual(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 (this.options.extensions !== other.options.extensions) {\n\t\t\t// todo: deep compare?\n\t\t\tthrow new BindingError(`Cannot merge two environments with different extensions.`)\n\t\t}\n\n\t\tif (deepEqual(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 && !deepEqual(this.options.variables[key], other.options.variables[key])) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`Cannot merge two environments with different value of variable ${key}:\\n`\n\t\t\t\t\t\t+ JSON.stringify(this.options.variables[key]) + '\\n'\n\t\t\t\t\t\t+ JSON.stringify(other.options.variables[key]),\n\t\t\t\t)\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 = unknown\n\n\texport type ResolvedValue = Value\n\n\texport interface Options<Node extends AnyNode | undefined> {\n\t\tnode?: Node\n\t\tschema?: Schema\n\t\tdimensions: SelectedDimensions\n\t\tparameters: Parameters\n\t\tvariables: CustomVariables\n\t\tparent?: Environment\n\t\textensions: Map<Extension<unknown, unknown>, unknown>\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 type Parameters = {\n\t\t[K in string]?: string | number\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\texport type Extension<State, Result> = {\n\t\tcreate: (state: State | undefined, environment: Environment) => Result\n\t}\n\n\texport const createExtension = <S, R>(create: Extension<S, R>['create'], otherMethods?: Omit<Extension<S, R>, 'create'>): Extension<S, R> => {\n\t\treturn {\n\t\t\tcreate,\n\t\t\t...otherMethods,\n\t\t}\n\t}\n}\n\nexport { Environment }\n"],"names":["Environment"],"mappings":";;AAKA,MAAM,YAA4F;AAAA,EACzF,YACU,SAChB;AADgB,SAAA,UAAA;AAAA,EAElB;AAAA,EAEA,OAAc,SAAS;AACtB,WAAO,IAAI,YAAY;AAAA,MACtB,YAAY,CAAA;AAAA,MACZ,WAAW,CAAA;AAAA,MACX,Y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BAAV;AAoFcA,eAAA,kBAAkB,CAAO,QAAmC,iBAAoE;AAC5I,WAAO;AAAA,MACN;AAAA,MACA,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,GAzFS,gBAAA,cAAA,CAAA,EAAA;"}
|
|
@@ -9,7 +9,7 @@ const TreeNodeUtils = require("./src/utils/TreeNodeUtils.cjs");
|
|
|
9
9
|
const assertNever = require("./src/utils/assertNever.cjs");
|
|
10
10
|
const createQueryBuilder = require("./src/utils/createQueryBuilder.cjs");
|
|
11
11
|
const whereToFilter = require("./src/utils/whereToFilter.cjs");
|
|
12
|
-
const
|
|
12
|
+
const utilities = require("@contember/utilities");
|
|
13
13
|
const defaults = require("./src/treeParameters/defaults.cjs");
|
|
14
14
|
const EntityFieldMarkersContainer = require("./src/markers/EntityFieldMarkersContainer.cjs");
|
|
15
15
|
const EntityFieldsWithHoistablesMarker = require("./src/markers/EntityFieldsWithHoistablesMarker.cjs");
|
|
@@ -60,7 +60,7 @@ exports.createQueryBuilder = createQueryBuilder.createQueryBuilder;
|
|
|
60
60
|
exports.whereToFilter = whereToFilter.whereToFilter;
|
|
61
61
|
Object.defineProperty(exports, "generateUuid", {
|
|
62
62
|
enumerable: true,
|
|
63
|
-
get: () =>
|
|
63
|
+
get: () => utilities.generateUuidV4
|
|
64
64
|
});
|
|
65
65
|
exports.EntityCreationParametersDefaults = defaults.EntityCreationParametersDefaults;
|
|
66
66
|
exports.EntityListPreferencesDefaults = defaults.EntityListPreferencesDefaults;
|
package/dist/production/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { TreeNodeUtils } from "./src/utils/TreeNodeUtils.js";
|
|
|
7
7
|
import { assertNever } from "./src/utils/assertNever.js";
|
|
8
8
|
import { createQueryBuilder } from "./src/utils/createQueryBuilder.js";
|
|
9
9
|
import { whereToFilter } from "./src/utils/whereToFilter.js";
|
|
10
|
-
import {
|
|
10
|
+
import { generateUuidV4 } from "@contember/utilities";
|
|
11
11
|
import { EntityCreationParametersDefaults, EntityListPreferencesDefaults, LeafFieldDefaults, QualifiedEntityParametersDefaults, RelationDefaults } from "./src/treeParameters/defaults.js";
|
|
12
12
|
import { EntityFieldMarkersContainer } from "./src/markers/EntityFieldMarkersContainer.js";
|
|
13
13
|
import { EntityFieldsWithHoistablesMarker } from "./src/markers/EntityFieldsWithHoistablesMarker.js";
|
|
@@ -88,7 +88,7 @@ export {
|
|
|
88
88
|
VariableInputTransformer,
|
|
89
89
|
assertNever,
|
|
90
90
|
createQueryBuilder,
|
|
91
|
-
|
|
91
|
+
generateUuidV4 as generateUuid,
|
|
92
92
|
isEntityAccessor,
|
|
93
93
|
isEntityListAccessor,
|
|
94
94
|
isErrorPersistResult,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const BindingError = require("../BindingError.cjs");
|
|
4
|
-
const
|
|
4
|
+
const utilities = require("@contember/utilities");
|
|
5
5
|
class Environment {
|
|
6
6
|
constructor(options) {
|
|
7
7
|
this.options = options;
|
|
@@ -121,7 +121,7 @@ class Environment {
|
|
|
121
121
|
...this.options.dimensions,
|
|
122
122
|
...dimensions
|
|
123
123
|
};
|
|
124
|
-
if (
|
|
124
|
+
if (utilities.deepEqual(newDimensions, this.options.dimensions)) {
|
|
125
125
|
return this;
|
|
126
126
|
}
|
|
127
127
|
return new Environment({ ...this.options, dimensions: newDimensions });
|
|
@@ -158,7 +158,7 @@ class Environment {
|
|
|
158
158
|
if (other === this) {
|
|
159
159
|
return this;
|
|
160
160
|
}
|
|
161
|
-
if (!
|
|
161
|
+
if (!utilities.deepEqual(this.options.node, other.options.node)) {
|
|
162
162
|
throw new BindingError.BindingError(`Cannot merge two environments with different tree position.`);
|
|
163
163
|
}
|
|
164
164
|
if (this.options.parameters !== other.options.parameters) {
|
|
@@ -170,11 +170,11 @@ class Environment {
|
|
|
170
170
|
if (this.options.extensions !== other.options.extensions) {
|
|
171
171
|
throw new BindingError.BindingError(`Cannot merge two environments with different extensions.`);
|
|
172
172
|
}
|
|
173
|
-
if (
|
|
173
|
+
if (utilities.deepEqual(this.options.variables, other.options.variables) && this.options.parent === other.options.parent) {
|
|
174
174
|
return this;
|
|
175
175
|
}
|
|
176
176
|
for (const key in other.options.variables) {
|
|
177
|
-
if (key in this.options.variables && !
|
|
177
|
+
if (key in this.options.variables && !utilities.deepEqual(this.options.variables[key], other.options.variables[key])) {
|
|
178
178
|
throw new BindingError.BindingError(
|
|
179
179
|
`Cannot merge two environments with different value of variable ${key}:
|
|
180
180
|
` + JSON.stringify(this.options.variables[key]) + "\n" + JSON.stringify(other.options.variables[key])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Environment.cjs","sources":["../../../../../packages/binding-common/src/environment/Environment.ts"],"sourcesContent":["import { BindingError } from '../BindingError.js'\nimport type { Filter } from '../treeParameters/index.js'\nimport equal from 'fast-deep-equal/es6/index.js'\nimport { Schema, SchemaColumn, SchemaEntity, SchemaRelation } from '../schema/index.js'\n\nclass Environment<Node extends Environment.AnyNode | undefined = Environment.AnyNode | undefined> {\n\tprivate constructor(\n\t\tprivate readonly options: Environment.Options<Node>,\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\textensions: new Map(),\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(): Node & 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<Node extends Environment.SubTreeNode>(SubTree: Node): Environment<Node> {\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 extends Environment.InnerNode>(node: Node): Environment<Node> {\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\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\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\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({\n\t\t\t...this.options,\n\t\t\tvariables: newVariables,\n\t\t\tparent: this,\n\t\t})\n\t}\n\n\tpublic getAllVariables() {\n\t\treturn this.options.variables\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 | number {\n\t\tif (!(key in this.options.parameters)) {\n\t\t\tthrow new BindingError(`Parameter ${key} not found`)\n\t\t}\n\t\treturn this.options.parameters[key] as string | number\n\t}\n\n\tpublic getParameterOrElse<F>(key: string, fallback: F): string | number | F {\n\t\treturn this.options.parameters[key] ?? fallback\n\t}\n\n\tpublic getAllParameters() {\n\t\treturn this.options.parameters\n\t}\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\thasSchema(): boolean {\n\t\treturn this.options.schema !== undefined\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 withExtension<S, R>(extension: Environment.Extension<S, R>, state: S): Environment {\n\t\treturn new Environment({\n\t\t\t...this.options,\n\t\t\textensions: new Map([...this.options.extensions, [extension, state] as [Environment.Extension<unknown, unknown>, unknown]]),\n\t\t})\n\t}\n\n\tpublic getExtension<S, R>(extension: Environment.Extension<S, R>): R {\n\t\tconst state = this.options.extensions.get(extension as Environment.Extension<unknown, unknown>)\n\t\treturn extension.create(state as S, this)\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 (this.options.extensions !== other.options.extensions) {\n\t\t\t// todo: deep compare?\n\t\t\tthrow new BindingError(`Cannot merge two environments with different extensions.`)\n\t\t}\n\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(\n\t\t\t\t\t`Cannot merge two environments with different value of variable ${key}:\\n`\n\t\t\t\t\t\t+ JSON.stringify(this.options.variables[key]) + '\\n'\n\t\t\t\t\t\t+ JSON.stringify(other.options.variables[key]),\n\t\t\t\t)\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 = unknown\n\n\texport type ResolvedValue = Value\n\n\texport interface Options<Node extends AnyNode | undefined> {\n\t\tnode?: Node\n\t\tschema?: Schema\n\t\tdimensions: SelectedDimensions\n\t\tparameters: Parameters\n\t\tvariables: CustomVariables\n\t\tparent?: Environment\n\t\textensions: Map<Extension<unknown, unknown>, unknown>\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 type Parameters = {\n\t\t[K in string]?: string | number\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\texport type Extension<State, Result> = {\n\t\tcreate: (state: State | undefined, environment: Environment) => Result\n\t}\n\n\texport const createExtension = <S, R>(create: Extension<S, R>['create'], otherMethods?: Omit<Extension<S, R>, 'create'>): Extension<S, R> => {\n\t\treturn {\n\t\t\tcreate,\n\t\t\t...otherMethods,\n\t\t}\n\t}\n}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AAQ,UAAU,GAAG,CAAC;AAAA,QAAA;AAAA,MAEhD;AAAA,IACD;AAEA,WAAO,IAAI,YAAY;AAAA,MACtB,GAAG,KAAK;AAAA,MACR,QAAQ,KAAK,QAAQ,UAAU,MAAM,QAAQ,SAAS,KAAK,QAAQ,OAAO,MAAM,MAAM,QAAQ,MAAM,IAAI;AAAA,MACxG,WAAW,EAAE,GAAG,KAAK,QAAQ,WAAW,GAAG,MAAM,QAAQ,UAAA;AAAA,IAAU,CACnE;AAAA,EACF;AACD;AAAA,CAEA,CAAUC,iBAAV;AAoFcA,eAAA,kBAAkB,CAAO,QAAmC,iBAAoE;AAC5I,WAAO;AAAA,MACN;AAAA,MACA,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,GAzFS,gBAAA,cAAA,CAAA,EAAA;;"}
|
|
1
|
+
{"version":3,"file":"Environment.cjs","sources":["../../../../../packages/binding-common/src/environment/Environment.ts"],"sourcesContent":["import { BindingError } from '../BindingError.js'\nimport type { Filter } from '../treeParameters/index.js'\nimport { deepEqual } from '@contember/utilities'\nimport { Schema, SchemaColumn, SchemaEntity, SchemaRelation } from '../schema/index.js'\n\nclass Environment<Node extends Environment.AnyNode | undefined = Environment.AnyNode | undefined> {\n\tprivate constructor(\n\t\tprivate readonly options: Environment.Options<Node>,\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\textensions: new Map(),\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(): Node & 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<Node extends Environment.SubTreeNode>(SubTree: Node): Environment<Node> {\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 extends Environment.InnerNode>(node: Node): Environment<Node> {\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\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\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\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({\n\t\t\t...this.options,\n\t\t\tvariables: newVariables,\n\t\t\tparent: this,\n\t\t})\n\t}\n\n\tpublic getAllVariables() {\n\t\treturn this.options.variables\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 | number {\n\t\tif (!(key in this.options.parameters)) {\n\t\t\tthrow new BindingError(`Parameter ${key} not found`)\n\t\t}\n\t\treturn this.options.parameters[key] as string | number\n\t}\n\n\tpublic getParameterOrElse<F>(key: string, fallback: F): string | number | F {\n\t\treturn this.options.parameters[key] ?? fallback\n\t}\n\n\tpublic getAllParameters() {\n\t\treturn this.options.parameters\n\t}\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 (deepEqual(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\thasSchema(): boolean {\n\t\treturn this.options.schema !== undefined\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 withExtension<S, R>(extension: Environment.Extension<S, R>, state: S): Environment {\n\t\treturn new Environment({\n\t\t\t...this.options,\n\t\t\textensions: new Map([...this.options.extensions, [extension, state] as [Environment.Extension<unknown, unknown>, unknown]]),\n\t\t})\n\t}\n\n\tpublic getExtension<S, R>(extension: Environment.Extension<S, R>): R {\n\t\tconst state = this.options.extensions.get(extension as Environment.Extension<unknown, unknown>)\n\t\treturn extension.create(state as S, this)\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 (!deepEqual(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 (this.options.extensions !== other.options.extensions) {\n\t\t\t// todo: deep compare?\n\t\t\tthrow new BindingError(`Cannot merge two environments with different extensions.`)\n\t\t}\n\n\t\tif (deepEqual(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 && !deepEqual(this.options.variables[key], other.options.variables[key])) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`Cannot merge two environments with different value of variable ${key}:\\n`\n\t\t\t\t\t\t+ JSON.stringify(this.options.variables[key]) + '\\n'\n\t\t\t\t\t\t+ JSON.stringify(other.options.variables[key]),\n\t\t\t\t)\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 = unknown\n\n\texport type ResolvedValue = Value\n\n\texport interface Options<Node extends AnyNode | undefined> {\n\t\tnode?: Node\n\t\tschema?: Schema\n\t\tdimensions: SelectedDimensions\n\t\tparameters: Parameters\n\t\tvariables: CustomVariables\n\t\tparent?: Environment\n\t\textensions: Map<Extension<unknown, unknown>, unknown>\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 type Parameters = {\n\t\t[K in string]?: string | number\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\texport type Extension<State, Result> = {\n\t\tcreate: (state: State | undefined, environment: Environment) => Result\n\t}\n\n\texport const createExtension = <S, R>(create: Extension<S, R>['create'], otherMethods?: Omit<Extension<S, R>, 'create'>): Extension<S, R> => {\n\t\treturn {\n\t\t\tcreate,\n\t\t\t...otherMethods,\n\t\t}\n\t}\n}\n\nexport { Environment }\n"],"names":["BindingError","deepEqual","Environment"],"mappings":";;;;AAKA,MAAM,YAA4F;AAAA,EACzF,YACU,SAChB;AADgB,SAAA,UAAA;AAAA,EAElB;AAAA,EAEA,OAAc,SAAS;AACtB,WAAO,IAAI,YAAY;AAAA,MACtB,YAAY,CAAA;AAAA,MACZ,WAAW,CAAA;AAAA,MACX,YAAY,CAAA;AAAA,MACZ,gCAAgB,IAAA;AAAA,IAAI,CACpB;AAAA,EACF;AAAA,EAEO,aAAsC;AAC5C,aAAS,MAAmB,MAAM,IAAI,QAAQ,MAAM,MAAM,IAAI,aAAa;AAC1E,YAAM,OAAO,IAAI,QAAQ;AACzB,UAAI,KAAK,SAAS,oBAAoB,KAAK,SAAS,uBAAuB;AAC1E,eAAO;AAAA,MACR;AAAA,IACD;AACA,UAAM,IAAIA,aAAAA,aAAa,kBAAkB;AAAA,EAC1C;AAAA,EAEO,iBAA6C;AACnD,QAAI,CAAC,KAAK,QAAQ,MAAM;AACvB,YAAM,IAAIA,aAAAA,aAAA;AAAA,IACX;AACA,WAAO,KAAK,QAAQ;AAAA,EACrB;AAAA,EAEO,YAAkD,SAAkC;AAC1F,UAAM,EAAE,QAAQ,GAAG,QAAA,IAAY,KAAK;AACpC,WAAO,IAAI,YAAY;AAAA,MACtB,GAAG;AAAA,MACH,MAAM;AAAA,IAAA,CACN;AAAA,EACF;AAAA,EAEO,iBAAqD,MAA+B;AAC1F,QAAI,CAAC,KAAK,QAAQ,MAAM;AACvB,YAAM,IAAIA,aAAAA,aAAa,mEAAmE;AAAA,IAC3F;AACA,QAAI,KAAK,QAAQ,KAAK,OAAO,OAAO,IAAI,KAAK,MAAM,IAAI,MAAM,KAAK,OAAO;AACxE,YAAM,IAAIA,aAAAA,aAAA;AAAA,IACX;AACA,WAAO,IAAI,YAAY;AAAA,MACtB,GAAG,KAAK;AAAA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AAA,UACT,kEAAkE,GAAG;AAAA,IAClE,KAAK,UAAU,KAAK,QAAQ,UAAU,GAAG,CAAC,IAAI,OAC9C,KAAK,UAAU,MAAM,QAAQ,UAAU,GAAG,CAAC;AAAA,QAAA;AAAA,MAEhD;AAAA,IACD;AAEA,WAAO,IAAI,YAAY;AAAA,MACtB,GAAG,KAAK;AAAA,MACR,QAAQ,KAAK,QAAQ,UAAU,MAAM,QAAQ,SAAS,KAAK,QAAQ,OAAO,MAAM,MAAM,QAAQ,MAAM,IAAI;AAAA,MACxG,WAAW,EAAE,GAAG,KAAK,QAAQ,WAAW,GAAG,MAAM,QAAQ,UAAA;AAAA,IAAU,CACnE;AAAA,EACF;AACD;AAAA,CAEA,CAAUE,iBAAV;AAoFcA,eAAA,kBAAkB,CAAO,QAAmC,iBAAoE;AAC5I,WAAO;AAAA,MACN;AAAA,MACA,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,GAzFS,gBAAA,cAAA,CAAA,EAAA;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BindingError } from "../BindingError.js";
|
|
2
|
-
import
|
|
2
|
+
import { deepEqual } from "@contember/utilities";
|
|
3
3
|
class Environment {
|
|
4
4
|
constructor(options) {
|
|
5
5
|
this.options = options;
|
|
@@ -119,7 +119,7 @@ class Environment {
|
|
|
119
119
|
...this.options.dimensions,
|
|
120
120
|
...dimensions
|
|
121
121
|
};
|
|
122
|
-
if (
|
|
122
|
+
if (deepEqual(newDimensions, this.options.dimensions)) {
|
|
123
123
|
return this;
|
|
124
124
|
}
|
|
125
125
|
return new Environment({ ...this.options, dimensions: newDimensions });
|
|
@@ -156,7 +156,7 @@ class Environment {
|
|
|
156
156
|
if (other === this) {
|
|
157
157
|
return this;
|
|
158
158
|
}
|
|
159
|
-
if (!
|
|
159
|
+
if (!deepEqual(this.options.node, other.options.node)) {
|
|
160
160
|
throw new BindingError(`Cannot merge two environments with different tree position.`);
|
|
161
161
|
}
|
|
162
162
|
if (this.options.parameters !== other.options.parameters) {
|
|
@@ -168,11 +168,11 @@ class Environment {
|
|
|
168
168
|
if (this.options.extensions !== other.options.extensions) {
|
|
169
169
|
throw new BindingError(`Cannot merge two environments with different extensions.`);
|
|
170
170
|
}
|
|
171
|
-
if (
|
|
171
|
+
if (deepEqual(this.options.variables, other.options.variables) && this.options.parent === other.options.parent) {
|
|
172
172
|
return this;
|
|
173
173
|
}
|
|
174
174
|
for (const key in other.options.variables) {
|
|
175
|
-
if (key in this.options.variables && !
|
|
175
|
+
if (key in this.options.variables && !deepEqual(this.options.variables[key], other.options.variables[key])) {
|
|
176
176
|
throw new BindingError(
|
|
177
177
|
`Cannot merge two environments with different value of variable ${key}:
|
|
178
178
|
` + JSON.stringify(this.options.variables[key]) + "\n" + JSON.stringify(other.options.variables[key])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Environment.js","sources":["../../../../../packages/binding-common/src/environment/Environment.ts"],"sourcesContent":["import { BindingError } from '../BindingError.js'\nimport type { Filter } from '../treeParameters/index.js'\nimport equal from 'fast-deep-equal/es6/index.js'\nimport { Schema, SchemaColumn, SchemaEntity, SchemaRelation } from '../schema/index.js'\n\nclass Environment<Node extends Environment.AnyNode | undefined = Environment.AnyNode | undefined> {\n\tprivate constructor(\n\t\tprivate readonly options: Environment.Options<Node>,\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\textensions: new Map(),\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(): Node & 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<Node extends Environment.SubTreeNode>(SubTree: Node): Environment<Node> {\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 extends Environment.InnerNode>(node: Node): Environment<Node> {\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\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\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\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({\n\t\t\t...this.options,\n\t\t\tvariables: newVariables,\n\t\t\tparent: this,\n\t\t})\n\t}\n\n\tpublic getAllVariables() {\n\t\treturn this.options.variables\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 | number {\n\t\tif (!(key in this.options.parameters)) {\n\t\t\tthrow new BindingError(`Parameter ${key} not found`)\n\t\t}\n\t\treturn this.options.parameters[key] as string | number\n\t}\n\n\tpublic getParameterOrElse<F>(key: string, fallback: F): string | number | F {\n\t\treturn this.options.parameters[key] ?? fallback\n\t}\n\n\tpublic getAllParameters() {\n\t\treturn this.options.parameters\n\t}\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\thasSchema(): boolean {\n\t\treturn this.options.schema !== undefined\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 withExtension<S, R>(extension: Environment.Extension<S, R>, state: S): Environment {\n\t\treturn new Environment({\n\t\t\t...this.options,\n\t\t\textensions: new Map([...this.options.extensions, [extension, state] as [Environment.Extension<unknown, unknown>, unknown]]),\n\t\t})\n\t}\n\n\tpublic getExtension<S, R>(extension: Environment.Extension<S, R>): R {\n\t\tconst state = this.options.extensions.get(extension as Environment.Extension<unknown, unknown>)\n\t\treturn extension.create(state as S, this)\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 (this.options.extensions !== other.options.extensions) {\n\t\t\t// todo: deep compare?\n\t\t\tthrow new BindingError(`Cannot merge two environments with different extensions.`)\n\t\t}\n\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(\n\t\t\t\t\t`Cannot merge two environments with different value of variable ${key}:\\n`\n\t\t\t\t\t\t+ JSON.stringify(this.options.variables[key]) + '\\n'\n\t\t\t\t\t\t+ JSON.stringify(other.options.variables[key]),\n\t\t\t\t)\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 = unknown\n\n\texport type ResolvedValue = Value\n\n\texport interface Options<Node extends AnyNode | undefined> {\n\t\tnode?: Node\n\t\tschema?: Schema\n\t\tdimensions: SelectedDimensions\n\t\tparameters: Parameters\n\t\tvariables: CustomVariables\n\t\tparent?: Environment\n\t\textensions: Map<Extension<unknown, unknown>, unknown>\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 type Parameters = {\n\t\t[K in string]?: string | number\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\texport type Extension<State, Result> = {\n\t\tcreate: (state: State | undefined, environment: Environment) => Result\n\t}\n\n\texport const createExtension = <S, R>(create: Extension<S, R>['create'], otherMethods?: Omit<Extension<S, R>, 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;AAAA,IACD;AAEA,WAAO,IAAI,YAAY;AAAA,MACtB,GAAG,KAAK;AAAA,MACR,QAAQ,KAAK,QAAQ,UAAU,MAAM,QAAQ,SAAS,KAAK,QAAQ,OAAO,MAAM,MAAM,QAAQ,MAAM,IAAI;AAAA,MACxG,WAAW,EAAE,GAAG,KAAK,QAAQ,WAAW,GAAG,MAAM,QAAQ,UAAA;AAAA,IAAU,CACnE;AAAA,EACF;AACD;AAAA,CAEA,CAAUA,iBAAV;AAoFcA,eAAA,kBAAkB,CAAO,QAAmC,iBAAoE;AAC5I,WAAO;AAAA,MACN;AAAA,MACA,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,GAzFS,gBAAA,cAAA,CAAA,EAAA;"}
|
|
1
|
+
{"version":3,"file":"Environment.js","sources":["../../../../../packages/binding-common/src/environment/Environment.ts"],"sourcesContent":["import { BindingError } from '../BindingError.js'\nimport type { Filter } from '../treeParameters/index.js'\nimport { deepEqual } from '@contember/utilities'\nimport { Schema, SchemaColumn, SchemaEntity, SchemaRelation } from '../schema/index.js'\n\nclass Environment<Node extends Environment.AnyNode | undefined = Environment.AnyNode | undefined> {\n\tprivate constructor(\n\t\tprivate readonly options: Environment.Options<Node>,\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\textensions: new Map(),\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(): Node & 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<Node extends Environment.SubTreeNode>(SubTree: Node): Environment<Node> {\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 extends Environment.InnerNode>(node: Node): Environment<Node> {\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\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\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\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({\n\t\t\t...this.options,\n\t\t\tvariables: newVariables,\n\t\t\tparent: this,\n\t\t})\n\t}\n\n\tpublic getAllVariables() {\n\t\treturn this.options.variables\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 | number {\n\t\tif (!(key in this.options.parameters)) {\n\t\t\tthrow new BindingError(`Parameter ${key} not found`)\n\t\t}\n\t\treturn this.options.parameters[key] as string | number\n\t}\n\n\tpublic getParameterOrElse<F>(key: string, fallback: F): string | number | F {\n\t\treturn this.options.parameters[key] ?? fallback\n\t}\n\n\tpublic getAllParameters() {\n\t\treturn this.options.parameters\n\t}\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 (deepEqual(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\thasSchema(): boolean {\n\t\treturn this.options.schema !== undefined\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 withExtension<S, R>(extension: Environment.Extension<S, R>, state: S): Environment {\n\t\treturn new Environment({\n\t\t\t...this.options,\n\t\t\textensions: new Map([...this.options.extensions, [extension, state] as [Environment.Extension<unknown, unknown>, unknown]]),\n\t\t})\n\t}\n\n\tpublic getExtension<S, R>(extension: Environment.Extension<S, R>): R {\n\t\tconst state = this.options.extensions.get(extension as Environment.Extension<unknown, unknown>)\n\t\treturn extension.create(state as S, this)\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 (!deepEqual(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 (this.options.extensions !== other.options.extensions) {\n\t\t\t// todo: deep compare?\n\t\t\tthrow new BindingError(`Cannot merge two environments with different extensions.`)\n\t\t}\n\n\t\tif (deepEqual(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 && !deepEqual(this.options.variables[key], other.options.variables[key])) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`Cannot merge two environments with different value of variable ${key}:\\n`\n\t\t\t\t\t\t+ JSON.stringify(this.options.variables[key]) + '\\n'\n\t\t\t\t\t\t+ JSON.stringify(other.options.variables[key]),\n\t\t\t\t)\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 = unknown\n\n\texport type ResolvedValue = Value\n\n\texport interface Options<Node extends AnyNode | undefined> {\n\t\tnode?: Node\n\t\tschema?: Schema\n\t\tdimensions: SelectedDimensions\n\t\tparameters: Parameters\n\t\tvariables: CustomVariables\n\t\tparent?: Environment\n\t\textensions: Map<Extension<unknown, unknown>, unknown>\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 type Parameters = {\n\t\t[K in string]?: string | number\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\texport type Extension<State, Result> = {\n\t\tcreate: (state: State | undefined, environment: Environment) => Result\n\t}\n\n\texport const createExtension = <S, R>(create: Extension<S, R>['create'], otherMethods?: Omit<Extension<S, R>, 'create'>): Extension<S, R> => {\n\t\treturn {\n\t\t\tcreate,\n\t\t\t...ot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KAAK;AAAA,MACR,QAAQ,KAAK,QAAQ,UAAU,MAAM,QAAQ,SAAS,KAAK,QAAQ,OAAO,MAAM,MAAM,QAAQ,MAAM,IAAI;AAAA,MACxG,WAAW,EAAE,GAAG,KAAK,QAAQ,WAAW,GAAG,MAAM,QAAQ,UAAA;AAAA,IAAU,CACnE;AAAA,EACF;AACD;AAAA,CAEA,CAAUA,iBAAV;AAoFcA,eAAA,kBAAkB,CAAO,QAAmC,iBAAoE;AAC5I,WAAO;AAAA,MACN;AAAA,MACA,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,GAzFS,gBAAA,cAAA,CAAA,EAAA;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BindingError.d.ts","sourceRoot":"","sources":["../../src/BindingError.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;CAAG;AAE1C,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"BindingError.d.ts","sourceRoot":"","sources":["../../src/BindingError.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;CAAG;AAE1C,eAAO,MAAM,iBAAiB,YAAa,MAAM,KAAG,KAEnD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizedBindingError.d.ts","sourceRoot":"","sources":["../../src/LocalizedBindingError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrJ,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,qBAAa,qBAAsB,SAAQ,YAAY;aACF,UAAU,EAAE,gBAAgB,EAAE;
|
|
1
|
+
{"version":3,"file":"LocalizedBindingError.d.ts","sourceRoot":"","sources":["../../src/LocalizedBindingError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrJ,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,qBAAa,qBAAsB,SAAQ,YAAY;aACF,UAAU,EAAE,gBAAgB,EAAE;IAAlF,YAAmB,OAAO,EAAE,MAAM,EAAkB,UAAU,EAAE,gBAAgB,EAAE,EAEjF;IAEM,QAAQ,CACd,OAAO,EAAE,mBAAmB,GAAG,uBAAuB,GAAG,oBAAoB,GAAG,qBAAqB,GACnG,qBAAqB,CAEvB;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuntimeId.d.ts","sourceRoot":"","sources":["../../src/RuntimeId.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAEpD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG;IAAE,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAAA;AAElE,MAAM,WAAW,aAAa;IAC7B,cAAc,EAAE,OAAO,CAAA;IACvB,KAAK,EAAE,QAAQ,CAAA;IACf,WAAW,EAAE,cAAc,CAAA;CAC3B;AAED,qBAAa,QAAS,YAAW,aAAa;aAIV,KAAK,EAAE,QAAQ;aAAkB,UAAU,EAAE,MAAM;IAHtF,IAAW,cAAc,IAAI,IAAI,CAEhC;
|
|
1
|
+
{"version":3,"file":"RuntimeId.d.ts","sourceRoot":"","sources":["../../src/RuntimeId.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAEpD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG;IAAE,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAAA;AAElE,MAAM,WAAW,aAAa;IAC7B,cAAc,EAAE,OAAO,CAAA;IACvB,KAAK,EAAE,QAAQ,CAAA;IACf,WAAW,EAAE,cAAc,CAAA;CAC3B;AAED,qBAAa,QAAS,YAAW,aAAa;aAIV,KAAK,EAAE,QAAQ;aAAkB,UAAU,EAAE,MAAM;IAHtF,IAAW,cAAc,IAAI,IAAI,CAEhC;IACD,YAAmC,KAAK,EAAE,QAAQ,EAAkB,UAAU,EAAE,MAAM,EACrF;IAED,IAAI,WAAW,mBAEd;IAED,MAAM,CAAC,iBAAiB,CAAC,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,GAAG,cAAc,CAEzE;CACD;AAED,qBAAa,mBAAoB,YAAW,aAAa;aAIrB,KAAK,EAAE,MAAM;IAHhD,IAAW,cAAc,IAAI,KAAK,CAEjC;IACD,YAAmC,KAAK,EAAE,MAAM,EAAI;IAEpD,IAAI,WAAW,IACO,cAAc,CACnC;CACD;AAED,qBAAa,wBAAyB,YAAW,aAAa;IAC7D,IAAW,cAAc,IAAI,KAAK,CAEjC;IACD,SAAgB,KAAK,EAAE,MAAM,CAAA;IAE7B,OAAO,CAAC,MAAM,CAAC,WAAW,CAGtB;IAEJ,cAOC;IAED,OAAO,CAAC,MAAM,CAAC,aAAa,CAAI;IAChC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAuF;IAClH,OAAc,cAAc,CAAC,SAAS,EAAE,QAAQ,GAAG,OAAO,CAEzD;IAED,IAAI,WAAW,IACO,cAAc,CACnC;CACD;AAED,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,mBAAmB,GAAG,wBAAwB,CAAA"}
|
|
@@ -89,7 +89,7 @@ declare namespace Environment {
|
|
|
89
89
|
type Extension<State, Result> = {
|
|
90
90
|
create: (state: State | undefined, environment: Environment) => Result;
|
|
91
91
|
};
|
|
92
|
-
const createExtension: <S, R>(create: Extension<S, R>[
|
|
92
|
+
const createExtension: <S, R>(create: Extension<S, R>['create'], otherMethods?: Omit<Extension<S, R>, 'create'>) => Extension<S, R>;
|
|
93
93
|
}
|
|
94
94
|
export { Environment };
|
|
95
95
|
//# sourceMappingURL=Environment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Environment.d.ts","sourceRoot":"","sources":["../../../src/environment/Environment.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAExD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEvF,cAAM,WAAW,CAAC,IAAI,SAAS,WAAW,CAAC,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC,OAAO,GAAG,SAAS;IAE9F,OAAO,CAAC,QAAQ,CAAC,OAAO;IADzB,OAAO;
|
|
1
|
+
{"version":3,"file":"Environment.d.ts","sourceRoot":"","sources":["../../../src/environment/Environment.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAExD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEvF,cAAM,WAAW,CAAC,IAAI,SAAS,WAAW,CAAC,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC,OAAO,GAAG,SAAS;IAE9F,OAAO,CAAC,QAAQ,CAAC,OAAO;IADzB,OAAO,eAGN;IAED,OAAc,MAAM,iDAOnB;IAEM,UAAU,IAAI,WAAW,CAAC,WAAW,CAQ3C;IAEM,cAAc,IAAI,IAAI,GAAG,WAAW,CAAC,OAAO,CAKlD;IAEM,WAAW,CAAC,IAAI,SAAS,WAAW,CAAC,WAAW,EAAE,OAAO,EAAE,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAMzF;IAEM,gBAAgB,CAAC,IAAI,SAAS,WAAW,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAYzF;IAEM,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEvC;IAEM,WAAW,CAAC,CAAC,SAAS,WAAW,CAAC,KAAK,GAAG,WAAW,CAAC,K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ts","sourceRoot":"","sources":["../../../src/environment/TreeNodeEnvironmentFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAEN,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC3B,0BAA0B,EAC1B,uCAAuC,EACvC,yCAAyC,EACzC,MAAM,4BAA4B,CAAA;AAKnC,qBAAa,0BAA0B;
|
|
1
|
+
{"version":3,"file":"TreeNodeEnvironmentFactory.d.ts","sourceRoot":"","sources":["../../../src/environment/TreeNodeEnvironmentFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAEN,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC3B,0BAA0B,EAC1B,uCAAuC,EACvC,yCAAyC,EACzC,MAAM,4BAA4B,CAAA;AAKnC,qBAAa,0BAA0B;IACtC,OAAc,qCAAqC,CAClD,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,0BAA0B,GAAG,uCAAuC,GACrF,WAAW,CAuBb;IAED,OAAc,iCAAiC,CAC9C,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,4BAA4B,GAAG,yCAAyC,GACzF,WAAW,CAuBb;IAED,OAAc,8BAA8B,CAC3C,WAAW,EAAE,WAAW,EACxB,yBAAyB,EAAE,yBAAyB,GAClD,WAAW,CAcb;IAED,OAAc,0BAA0B,CACvC,WAAW,EAAE,WAAW,EACxB,2BAA2B,EAAE,2BAA2B,gDAKxD;IAED,OAAc,yBAAyB,CACtC,WAAW,EAAE,WAAW,EACxB,0BAA0B,EAAE,0BAA0B;;;;OAYtD;IAED,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAgBjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariableFieldValue.d.ts","sourceRoot":"","sources":["../../../src/environment/VariableFieldValue.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAkB;aACK,YAAY,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"VariableFieldValue.d.ts","sourceRoot":"","sources":["../../../src/environment/VariableFieldValue.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAkB;aACK,YAAY,EAAE,MAAM;IAAvD,YAAmC,YAAY,EAAE,MAAM,EAAI;CAC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariableInputTransformer.d.ts","sourceRoot":"","sources":["../../../src/environment/VariableInputTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9C,qBAAa,wBAAwB;
|
|
1
|
+
{"version":3,"file":"VariableInputTransformer.d.ts","sourceRoot":"","sources":["../../../src/environment/VariableInputTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9C,qBAAa,wBAAwB;IACpC,OAAc,cAAc,CAAC,KAAK,EAAE,4BAA4B,EAAE,WAAW,EAAE,WAAW,GAAG,UAAU,CAKtG;IAED,OAAc,2BAA2B,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,GAAG,UAAU,CAYtH;CACD"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -13,5 +13,5 @@ export * from './utils/TreeNodeUtils.js';
|
|
|
13
13
|
export * from './utils/assertNever.js';
|
|
14
14
|
export * from './utils/createQueryBuilder.js';
|
|
15
15
|
export * from './utils/whereToFilter.js';
|
|
16
|
-
export {
|
|
16
|
+
export { generateUuidV4 as generateUuid } from '@contember/utilities';
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|