@_linked/core 0.0.1 → 1.0.0-next.20260211072341

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/LICENSE +1 -1
  3. package/README.md +1 -53
  4. package/package.json +17 -1
  5. package/.context/notes.md +0 -0
  6. package/.context/todos.md +0 -0
  7. package/AGENTS.md +0 -59
  8. package/docs/001-core-extraction.md +0 -305
  9. package/jest.config.js +0 -25
  10. package/scripts/dual-package.js +0 -25
  11. package/src/collections/CoreMap.ts +0 -127
  12. package/src/collections/CoreSet.ts +0 -171
  13. package/src/collections/ShapeSet.ts +0 -18
  14. package/src/index.ts +0 -88
  15. package/src/interfaces/ICoreIterable.ts +0 -35
  16. package/src/interfaces/IFileStore.ts +0 -28
  17. package/src/interfaces/IQuadStore.ts +0 -16
  18. package/src/interfaces/IQueryParser.ts +0 -51
  19. package/src/ontologies/lincd.ts +0 -25
  20. package/src/ontologies/npm.ts +0 -15
  21. package/src/ontologies/owl.ts +0 -26
  22. package/src/ontologies/rdf.ts +0 -32
  23. package/src/ontologies/rdfs.ts +0 -38
  24. package/src/ontologies/shacl.ts +0 -136
  25. package/src/ontologies/xsd.ts +0 -47
  26. package/src/package.ts +0 -11
  27. package/src/queries/CreateQuery.ts +0 -41
  28. package/src/queries/DeleteQuery.ts +0 -54
  29. package/src/queries/MutationQuery.ts +0 -287
  30. package/src/queries/QueryContext.ts +0 -41
  31. package/src/queries/QueryFactory.ts +0 -275
  32. package/src/queries/QueryParser.ts +0 -79
  33. package/src/queries/SelectQuery.ts +0 -2101
  34. package/src/queries/UpdateQuery.ts +0 -47
  35. package/src/shapes/List.ts +0 -52
  36. package/src/shapes/SHACL.ts +0 -653
  37. package/src/shapes/Shape.ts +0 -282
  38. package/src/test-helpers/query-fixtures.ts +0 -313
  39. package/src/tests/core-utils.test.ts +0 -286
  40. package/src/tests/metadata.test.ts +0 -65
  41. package/src/tests/query.test.ts +0 -599
  42. package/src/tests/query.types.test.ts +0 -606
  43. package/src/tests/store-routing.test.ts +0 -133
  44. package/src/utils/LinkedErrorLogging.ts +0 -25
  45. package/src/utils/LinkedFileStorage.ts +0 -75
  46. package/src/utils/LinkedStorage.ts +0 -120
  47. package/src/utils/NameSpace.ts +0 -5
  48. package/src/utils/NodeReference.ts +0 -16
  49. package/src/utils/Package.ts +0 -681
  50. package/src/utils/Prefix.ts +0 -108
  51. package/src/utils/ShapeClass.ts +0 -335
  52. package/src/utils/Types.ts +0 -19
  53. package/src/utils/URI.ts +0 -40
  54. package/src/utils/cached.ts +0 -53
  55. package/tsconfig-cjs.json +0 -8
  56. package/tsconfig-esm.json +0 -9
  57. package/tsconfig.json +0 -29
@@ -1,136 +0,0 @@
1
- /*
2
- * This Source Code Form is subject to the terms of the Mozilla Public
3
- * License, v. 2.0. If a copy of the MPL was not distributed with this
4
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
- */
6
- import {NodeReferenceValue} from '../utils/NodeReference.js';
7
- import {Prefix} from '../utils/Prefix.js';
8
- import {createNameSpace} from '../utils/NameSpace.js';
9
-
10
- const base = 'http://www.w3.org/ns/shacl#';
11
- export const _ontologyResource: NodeReferenceValue = {id: base};
12
- Prefix.add('shacl', base);
13
-
14
- export const ns = createNameSpace(base);
15
-
16
- //add your ontology nodes here
17
- const _class = ns('class');
18
- const datatype = ns('datatype');
19
- const declare = ns('declare');
20
- const _in = ns('in');
21
- const maxCount = ns('maxCount');
22
- const minCount = ns('minCount');
23
- const inList = ns('inList');
24
- const name = ns('name');
25
- const description = ns('description');
26
- const NodeShape = ns('NodeShape');
27
- const optional = ns('optional');
28
- const Parameter = ns('Parameter');
29
- const PrefixDeclaration = ns('PrefixDeclaration');
30
- const path = ns('path');
31
- const property = ns('property');
32
- const prefix = ns('prefix');
33
- const PropertyShape = ns('PropertyShape');
34
- const targetClass = ns('targetClass');
35
- const targetNode = ns('targetNode');
36
- const node = ns('node');
37
- const nodeKind = ns('nodeKind');
38
- const Shape = ns('Shape');
39
-
40
- const BlankNode = ns('BlankNode');
41
- const IRI = ns('IRI');
42
- const Literal = ns('Literal');
43
- const BlankNodeOrIRI = ns('BlankNodeOrIRI');
44
- const BlankNodeOrLiteral = ns('BlankNodeOrLiteral');
45
- const IRIOrLiteral = ns('IRIOrLiteral');
46
-
47
- export const languageIn = ns('languageIn');
48
- export const lessThan = ns('lessThan');
49
- export const lessThanOrEquals = ns('lessThanOrEquals');
50
- export const maxExclusive = ns('maxExclusive');
51
- export const maxInclusive = ns('maxInclusive');
52
- export const maxLength = ns('maxLength');
53
- export const minExclusive = ns('minExclusive');
54
- export const minInclusive = ns('minInclusive');
55
- export const minLength = ns('minLength');
56
- export const pattern = ns('pattern');
57
- export const uniqueLang = ns('uniqueLang');
58
- export const ValidationReport = ns('ValidationReport');
59
- export const conforms = ns('conforms');
60
- export const ValidationResult = ns('ValidationResult');
61
- export const focusNode = ns('focusNode');
62
- export const sourceShape = ns('sourceShape');
63
- export const resultSeverity = ns('resultSeverity');
64
- export const resultPath = ns('resultPath');
65
- export const value = ns('value');
66
- export const message = ns('message');
67
- export const Violation = ns('Violation');
68
- export const AbstractResult = ns('AbstractResult');
69
- export const sourceConstraintComponent = ns('sourceConstraintComponent');
70
- export const ClassConstraintComponent = ns('ClassConstraintComponent');
71
- export const NodeConstraintComponent = ns('NodeConstraintComponent');
72
- export const DatatypeConstraintComponent = ns('DatatypeConstraintComponent');
73
- export const MinLengthConstraintComponent = ns('MinLengthConstraintComponent');
74
- export const MaxLengthConstraintComponent = ns('MaxLengthConstraintComponent');
75
- export const result = ns('result');
76
-
77
- //make sure every node is also exported here
78
- export const shacl = {
79
- class: _class,
80
- datatype,
81
- declare,
82
- in: _in,
83
- maxCount,
84
- minCount,
85
- name,
86
- description,
87
- node,
88
- NodeShape,
89
- optional,
90
- Parameter,
91
- PrefixDeclaration,
92
- path,
93
- prefix,
94
- property,
95
- PropertyShape,
96
- Shape,
97
- targetClass,
98
- targetNode,
99
- BlankNode,
100
- IRI,
101
- Literal,
102
- BlankNodeOrIRI,
103
- BlankNodeOrLiteral,
104
- IRIOrLiteral,
105
- nodeKind,
106
- inList,
107
- languageIn,
108
- lessThan,
109
- lessThanOrEquals,
110
- maxExclusive,
111
- maxInclusive,
112
- maxLength,
113
- minExclusive,
114
- minInclusive,
115
- minLength,
116
- pattern,
117
- uniqueLang,
118
- ValidationReport,
119
- conforms,
120
- ValidationResult,
121
- focusNode,
122
- sourceShape,
123
- resultSeverity,
124
- resultPath,
125
- value,
126
- message,
127
- Violation,
128
- sourceConstraintComponent,
129
- ClassConstraintComponent,
130
- NodeConstraintComponent,
131
- DatatypeConstraintComponent,
132
- MinLengthConstraintComponent,
133
- MaxLengthConstraintComponent,
134
- AbstractResult,
135
- result,
136
- };
@@ -1,47 +0,0 @@
1
- /*
2
- * This Source Code Form is subject to the terms of the Mozilla Public
3
- * License, v. 2.0. If a copy of the MPL was not distributed with this
4
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
- */
6
- import {NodeReferenceValue} from '../utils/NodeReference.js';
7
- import {Prefix} from '../utils/Prefix.js';
8
-
9
- const base = 'http://www.w3.org/2001/XMLSchema#';
10
- export const ns = (term: string): NodeReferenceValue => ({id: base + term});
11
-
12
- export const _ontologyResource = ns('');
13
- Prefix.add('xsd', base);
14
-
15
- const string = ns('string');
16
- const boolean = ns('boolean');
17
- const date = ns('date');
18
- const integer = ns('integer');
19
- const float = ns('float');
20
- const double = ns('double');
21
- const time = ns('time');
22
- const duration = ns('duration');
23
- const decimal = ns('decimal');
24
- const gYear = ns('gYear');
25
- const Bytes = ns('Bytes');
26
- const long = ns('long');
27
- const dateTime = ns('dateTime');
28
-
29
- //not yet required by core so why define it?
30
- //export var boolean:NamedNode = nodes.getOrCreate(base+"boolean");
31
-
32
- export const xsd = {
33
- _ontologyResource,
34
- string,
35
- boolean,
36
- date,
37
- integer,
38
- float,
39
- double,
40
- time,
41
- duration,
42
- decimal,
43
- gYear,
44
- Bytes,
45
- long,
46
- dateTime,
47
- };
package/src/package.ts DELETED
@@ -1,11 +0,0 @@
1
- import {corePackage} from './utils/Package.js';
2
-
3
- export const {
4
- linkedShape,
5
- linkedUtil,
6
- linkedOntology,
7
- registerPackageExport,
8
- registerPackageModule,
9
- packageExports,
10
- getPackageShape,
11
- } = corePackage;
@@ -1,41 +0,0 @@
1
- import {Shape} from '../shapes/Shape.js';
2
- import {NodeShape} from '../shapes/SHACL.js';
3
- import {LinkedQuery} from './SelectQuery.js';
4
- import {AddId, NodeDescriptionValue, UpdatePartial} from './QueryFactory.js';
5
- import {MutationQueryFactory} from './MutationQuery.js';
6
-
7
- export interface CreateQuery<ResponseType = null> extends LinkedQuery {
8
- type: 'create';
9
- shape: NodeShape;
10
- description: NodeDescriptionValue;
11
- }
12
-
13
- export type CreateResponse<U> = AddId<U, true>;
14
-
15
- export class CreateQueryFactory<
16
- ShapeType extends Shape,
17
- U extends UpdatePartial<ShapeType>,
18
- > extends MutationQueryFactory {
19
- readonly id: string;
20
- readonly description: NodeDescriptionValue;
21
-
22
- constructor(
23
- public shapeClass: typeof Shape,
24
- updateObjectOrFn: U,
25
- ) {
26
- super();
27
- this.description = this.convertUpdateObject(
28
- updateObjectOrFn,
29
- this.shapeClass.shape,
30
- true,
31
- );
32
- }
33
-
34
- getQueryObject(): CreateQuery<AddId<U, true>> {
35
- return {
36
- type: 'create',
37
- shape: this.shapeClass.shape,
38
- description: this.description,
39
- };
40
- }
41
- }
@@ -1,54 +0,0 @@
1
- import {Shape} from '../shapes/Shape.js';
2
- import {NodeShape} from '../shapes/SHACL.js';
3
- import {LinkedQuery} from './SelectQuery.js';
4
- import {NodeReferenceValue, UpdatePartial} from './QueryFactory.js';
5
- import {MutationQueryFactory, NodeId} from './MutationQuery.js';
6
-
7
- export interface DeleteQuery extends LinkedQuery {
8
- type: 'delete';
9
- shape: NodeShape;
10
- ids: NodeReferenceValue[];
11
- }
12
-
13
- export type DeleteResponse = {
14
- /**
15
- * The IDs of the items that were successfully deleted.
16
- */
17
- deleted: NodeReferenceValue[];
18
- /**
19
- * The number of successfully deleted items.
20
- */
21
- count: number;
22
- /**
23
- * The IDs of the items that couldn't be deleted.
24
- */
25
- failed?: NodeReferenceValue[];
26
- /**
27
- * A mapping of IDs to error messages for the items that couldn't be deleted.
28
- */
29
- errors?: Record<string, string>;
30
- };
31
-
32
- export class DeleteQueryFactory<
33
- ShapeType extends Shape,
34
- U extends UpdatePartial<ShapeType>,
35
- > extends MutationQueryFactory {
36
- readonly id: string;
37
- readonly ids: NodeReferenceValue[];
38
-
39
- constructor(
40
- public shapeClass: typeof Shape,
41
- ids: NodeId[] | NodeId,
42
- ) {
43
- super();
44
- this.ids = this.convertNodeReferences(ids);
45
- }
46
-
47
- getQueryObject(): DeleteQuery {
48
- return {
49
- type: 'delete',
50
- shape: this.shapeClass.shape,
51
- ids: this.ids,
52
- };
53
- }
54
- }
@@ -1,287 +0,0 @@
1
- import {
2
- LiteralUpdateValue,
3
- NodeDescriptionValue,
4
- NodeReferenceValue,
5
- PropUpdateValue,
6
- QueryFactory,
7
- SetModification,
8
- SetModificationValue,
9
- SinglePropertyUpdateValue,
10
- UpdateNodePropertyValue,
11
- UpdatePartial,
12
- } from './QueryFactory.js';
13
- import {NodeShape, PropertyShape} from '../shapes/SHACL.js';
14
- import {Shape} from '../shapes/Shape.js';
15
- import {getShapeClass} from '../utils/ShapeClass.js';
16
-
17
- export type NodeId = {id: string} | string;
18
-
19
- export class MutationQueryFactory extends QueryFactory {
20
- protected convertUpdateObject(
21
- obj,
22
- shape: NodeShape,
23
- allowTopLevelId: boolean = false,
24
- ): NodeDescriptionValue {
25
- if (typeof obj === 'object' && !(obj instanceof Date) && obj !== null) {
26
- if (!allowTopLevelId && 'id' in obj) {
27
- throw new Error(
28
- 'You cannot use id in the top level of an update object',
29
- );
30
- }
31
- return this.convertNodeDescription(obj, shape);
32
- } else if (typeof obj === 'function') {
33
- //TODO
34
- throw new Error('Update functions are not implemented yet');
35
- } else {
36
- throw new Error('Invalid update object');
37
- }
38
- }
39
-
40
- protected isSetModification(obj, shape) {
41
- // return obj.add || obj.remove;
42
- let hasAdd = obj.add;
43
- let hasRemove = obj.remove;
44
- let numKeysExpected = (hasAdd ? 1 : 0) + (hasRemove ? 1 : 0);
45
- let numKeys = Object.getOwnPropertyNames(obj).length;
46
- return hasAdd || (hasRemove && numKeysExpected === numKeys);
47
- }
48
-
49
- protected convertSetModification(
50
- obj: SetModification<any>,
51
- shape: PropertyShape,
52
- ): SetModificationValue {
53
- if (!obj.add && !obj.remove) {
54
- throw new Error('Set modification should have either add or remove key');
55
- }
56
- const res: SetModificationValue = {};
57
- if (obj.add) {
58
- res.$add = this.convertSetAddValue(obj.add, shape);
59
- }
60
- if (obj.remove) {
61
- res.$remove = this.convertSetRemoveValue(obj.remove, shape);
62
- }
63
- return res;
64
- }
65
-
66
- protected convertSetRemoveValue(
67
- obj: UpdatePartial | UpdatePartial[],
68
- shape: PropertyShape,
69
- ): NodeReferenceValue[] {
70
- //the user can either pass an array of node references or a single node reference
71
- //either way we should return an array of node reference values
72
- if (Array.isArray(obj)) {
73
- return obj.map((o) => this.convertSingleRemoveValue(o, shape));
74
- } else {
75
- return [this.convertSingleRemoveValue(obj, shape)];
76
- }
77
- }
78
-
79
- protected convertSetAddValue(
80
- obj: UpdatePartial | UpdatePartial[],
81
- shape: PropertyShape,
82
- ): UpdatePartial[] {
83
- if (Array.isArray(obj)) {
84
- return obj.map((o) => this.convertUpdateValue(o, shape) as UpdatePartial);
85
- } else {
86
- return [this.convertUpdateValue(obj, shape) as UpdatePartial];
87
- }
88
- }
89
-
90
- protected convertSingleRemoveValue(
91
- value,
92
- shape: PropertyShape,
93
- ): NodeReferenceValue {
94
- if (this.isNodeReference(value)) {
95
- return this.convertNodeReference(value);
96
- } else {
97
- throw new Error(
98
- `Invalid value for ${shape.label}.$remove. Expected an object with an id as key: {id:string}`,
99
- );
100
- }
101
- }
102
-
103
- protected convertNodeDescription(
104
- obj: Object,
105
- shape: NodeShape,
106
- ): NodeDescriptionValue {
107
- const props = shape.getPropertyShapes(true);
108
- const fields: UpdateNodePropertyValue[] = [];
109
- let id;
110
- if (obj && '__id' in obj) {
111
- //if the object has a __id key, then we should use that in the result
112
- id = obj.__id.toString();
113
- //but we should not include it in the fields
114
- delete obj.__id;
115
- }
116
- for (var key in obj) {
117
- let propShape = props.find((p) => p.label === key);
118
- if (!propShape) {
119
- throw Error(
120
- `Invalid property key: ${key}. The shape ${shape.label || shape.id.split('/').pop()} does not have a registered property with this name. Make sure the get/set method exists, and that it uses a @objectProperty or @literalProperty decorator.`,
121
- );
122
- } else {
123
- fields.push(this.createNodePropertyValue(obj[key], propShape));
124
- }
125
- }
126
- const res: NodeDescriptionValue = {
127
- fields,
128
- shape,
129
- };
130
- if (id) {
131
- res.__id = id;
132
- }
133
-
134
- return res;
135
- }
136
-
137
- protected createNodePropertyValue(
138
- value,
139
- propShape: PropertyShape,
140
- ): UpdateNodePropertyValue {
141
- // let value = obj[propShape.label];
142
- return {
143
- prop: propShape,
144
- val: this.convertUpdateValue(value, propShape),
145
- } as UpdateNodePropertyValue;
146
- }
147
-
148
- protected convertUpdateValue(
149
- value,
150
- propShape?: PropertyShape,
151
- allowArrays: boolean = true,
152
- ): PropUpdateValue {
153
- //single value which will
154
- if (
155
- typeof value === 'string' ||
156
- typeof value === 'number' ||
157
- typeof value === 'boolean' ||
158
- value instanceof Date
159
- ) {
160
- return value as LiteralUpdateValue;
161
- }
162
-
163
- //if multiple items are given as value of this prop
164
- if (Array.isArray(value)) {
165
- if (!allowArrays) {
166
- throw new Error('Nested arrays are not allowed as values of keys');
167
- }
168
- //then convert each value, but disallow nested arrays moving forward
169
- return value.map((o) => {
170
- return this.convertUpdateValue(o, propShape, false);
171
- }) as SinglePropertyUpdateValue[];
172
- } else if (typeof value === 'undefined') {
173
- return value;
174
- } else if (value === null) {
175
- //unsetting a value with null is also possible. But we pass it as undefined in the query object
176
- return undefined;
177
- } else if (typeof value === 'object') {
178
- if (this.isNodeReference(value)) {
179
- return this.convertNodeReference(value);
180
- } else {
181
- let valueShape: NodeShape = null;
182
- if (propShape.valueShape) {
183
- const shapeClass = getShapeClass(propShape.valueShape);
184
- valueShape = shapeClass?.shape || null;
185
- if (!valueShape) {
186
- throw new Error(
187
- `Shape class not found for ${propShape.valueShape.id}`,
188
- );
189
- }
190
- }
191
- //pass the value shape of the property as the node shape of this value
192
- if (!propShape.valueShape) {
193
- //It's possible to define the shape of the value in the value itself for properties who do not define the shape in their objectProperty
194
- if (value.shape) {
195
- if (!(value.shape.shape instanceof NodeShape)) {
196
- throw new Error(
197
- `The value of property "shape" is invalid and should be a class that extends Shape.`,
198
- );
199
- }
200
- valueShape = (value.shape as typeof Shape).shape;
201
- } else {
202
- //TODO: not sure if this should be an error. Does every @linkedObject need to define the shape of the values?
203
- // If not, then how do we continue? because currently we use the value shape to look up further property shapes
204
- throw new Error(
205
- `Cannot update properties with plain objects if the shape of the values is not known. Make sure get/set ${propShape.parentNodeShape.label}.${propShape.label} defines the 'shape' key in its @objectProperty decorator.`,
206
- );
207
- }
208
- }
209
- //never keep a shape key in the value object
210
- if (value.shape) {
211
- //double check that IF a shape value is provided, that it matches the shape from the @objectProperty decorator
212
- if ((value.shape as typeof Shape).shape.id !== valueShape.id) {
213
- throw new Error(
214
- `The property 'shape' is reserved in LINCD and should not be used here in this way. The ${propShape.label} property already defines the shape of the value as ${propShape.label}. If you want to use a different shape, use the 'shape' key in the @objectProperty decorator.`,
215
- );
216
- }
217
- delete value.shape;
218
- }
219
-
220
- if (this.isSetModification(value, propShape)) {
221
- return this.convertSetModification(value, propShape);
222
- } else {
223
- return this.convertNodeDescription(value, valueShape);
224
- }
225
- // //check if the property shape allows a single value
226
- // if(propShape.maxCount === 1) {
227
- // //if yes, then the object should be seen as a node description
228
- // return this.convertNodeDescription(value,propShape.valueShape);
229
- // } else {
230
- // if(this.isSetModification(value,propShape)) {
231
- // //but if multiple values are allowed, the value should either be an Array of node descriptions
232
- // //OR an object with add or remove keys
233
- // return this.convertSetModification(value,propShape);
234
- // } else {
235
- // //it must be a set overwrite, and it must be coming from an array
236
- // if(!allowArrays) {
237
- // return this.convertNodeDescription(value,propShape.valueShape);
238
- // } else {
239
- // throw new Error("Invalid array value. Should be a node reference or node description")
240
- // }
241
- // }
242
- // }
243
- }
244
- }
245
- throw new Error(`Unsupported update value type: ${typeof value}`);
246
- }
247
-
248
- protected isNodeReference(obj): obj is NodeReferenceValue {
249
- //check if obj is an object with an id property
250
- //if yes, all other properties are ignored
251
- return typeof obj === 'object' && obj !== null && 'id' in obj; // && Object.keys(obj).length === 1);
252
- //and id is the only property
253
- }
254
-
255
- protected convertNodeReferences(
256
- input: NodeId[] | NodeId,
257
- ): NodeReferenceValue[] {
258
- if (Array.isArray(input)) {
259
- return input.map((o) => {
260
- return this.convertNodeReferenceOrString(o);
261
- });
262
- } else {
263
- return [this.convertNodeReferenceOrString(input)];
264
- }
265
- }
266
-
267
- protected convertNodeReferenceOrString(
268
- o: {id: string} | string,
269
- ): NodeReferenceValue {
270
- if (typeof o === 'string') {
271
- return {id: o};
272
- } else if (this.isNodeReference(o)) {
273
- return this.convertNodeReference(o);
274
- } else {
275
- throw new Error(`Invalid node reference: ${JSON.stringify(o)}`);
276
- }
277
- }
278
-
279
- protected convertNodeReference(obj: {id: string}): NodeReferenceValue {
280
- //ensure there are no other properties in the object
281
- // if (Object.keys(obj).length > 1)
282
- // {
283
- // throw new Error('Cannot have id and other properties in the same value object');
284
- // }
285
- return {id: obj.id};
286
- }
287
- }
@@ -1,41 +0,0 @@
1
- import {QShape, QueryShape} from './SelectQuery.js';
2
- import {Shape} from '../shapes/Shape.js';
3
-
4
- const queryContext = new Map<string, QShape<any, any, any>>();
5
-
6
- export function getQueryContext<T extends Shape>(name: string): QShape<T> {
7
- if (!queryContext.has(name)) {
8
- //TODO:should return something here so that the query still works and returns default values
9
- // like NullQueryShape or similar
10
- return null;
11
- }
12
- return queryContext.get(name);
13
- }
14
-
15
- export function setQueryContext(name: string, value: any, shapeType?) {
16
- //if a QResult was provided
17
- if (value && typeof value.id === 'string') {
18
- //convert to QShape
19
- if (!shapeType) {
20
- console.warn(
21
- 'setQueryContext: value is a QResult but no shapeType provided',
22
- value,
23
- );
24
- return;
25
- }
26
- const shape = new (shapeType as any)();
27
- shape.id = value.id;
28
- shape.__queryContextId = value.id;
29
- value = QueryShape.create(shape);
30
- //const converted = QueryBuilderObject.convertOriginal(shape,null,null);
31
- }
32
- if (value instanceof Shape) {
33
- //convert to QShape
34
- value = new QueryShape(value);
35
- } else if (value && !(value instanceof QueryShape)) {
36
- console.warn('setQueryContext: value is not a QueryShape or Shape', value);
37
- return;
38
- }
39
-
40
- queryContext.set(name, value);
41
- }