@_linked/core 0.0.1 → 1.0.0-next.20260216062729
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/CHANGELOG.md +71 -0
- package/LICENSE +1 -1
- package/README.md +147 -92
- package/lib/cjs/queries/SelectQuery.d.ts +5 -0
- package/lib/cjs/queries/SelectQuery.js +14 -0
- package/lib/cjs/queries/SelectQuery.js.map +1 -1
- package/lib/cjs/shapes/SHACL.d.ts +1 -0
- package/lib/cjs/shapes/SHACL.js +82 -2
- package/lib/cjs/shapes/SHACL.js.map +1 -1
- package/lib/cjs/shapes/Shape.d.ts +13 -1
- package/lib/cjs/shapes/Shape.js +6 -0
- package/lib/cjs/shapes/Shape.js.map +1 -1
- package/lib/cjs/test-helpers/query-fixtures.d.ts +583 -0
- package/lib/cjs/test-helpers/query-fixtures.js +39 -1
- package/lib/cjs/test-helpers/query-fixtures.js.map +1 -1
- package/lib/esm/queries/SelectQuery.d.ts +5 -0
- package/lib/esm/queries/SelectQuery.js +14 -0
- package/lib/esm/queries/SelectQuery.js.map +1 -1
- package/lib/esm/shapes/SHACL.d.ts +1 -0
- package/lib/esm/shapes/SHACL.js +82 -2
- package/lib/esm/shapes/SHACL.js.map +1 -1
- package/lib/esm/shapes/Shape.d.ts +13 -1
- package/lib/esm/shapes/Shape.js +6 -0
- package/lib/esm/shapes/Shape.js.map +1 -1
- package/lib/esm/test-helpers/query-fixtures.d.ts +583 -0
- package/lib/esm/test-helpers/query-fixtures.js +38 -0
- package/lib/esm/test-helpers/query-fixtures.js.map +1 -1
- package/package.json +17 -1
- package/.context/notes.md +0 -0
- package/.context/todos.md +0 -0
- package/AGENTS.md +0 -59
- package/docs/001-core-extraction.md +0 -305
- package/jest.config.js +0 -25
- package/scripts/dual-package.js +0 -25
- package/src/collections/CoreMap.ts +0 -127
- package/src/collections/CoreSet.ts +0 -171
- package/src/collections/ShapeSet.ts +0 -18
- package/src/index.ts +0 -88
- package/src/interfaces/ICoreIterable.ts +0 -35
- package/src/interfaces/IFileStore.ts +0 -28
- package/src/interfaces/IQuadStore.ts +0 -16
- package/src/interfaces/IQueryParser.ts +0 -51
- package/src/ontologies/lincd.ts +0 -25
- package/src/ontologies/npm.ts +0 -15
- package/src/ontologies/owl.ts +0 -26
- package/src/ontologies/rdf.ts +0 -32
- package/src/ontologies/rdfs.ts +0 -38
- package/src/ontologies/shacl.ts +0 -136
- package/src/ontologies/xsd.ts +0 -47
- package/src/package.ts +0 -11
- package/src/queries/CreateQuery.ts +0 -41
- package/src/queries/DeleteQuery.ts +0 -54
- package/src/queries/MutationQuery.ts +0 -287
- package/src/queries/QueryContext.ts +0 -41
- package/src/queries/QueryFactory.ts +0 -275
- package/src/queries/QueryParser.ts +0 -79
- package/src/queries/SelectQuery.ts +0 -2101
- package/src/queries/UpdateQuery.ts +0 -47
- package/src/shapes/List.ts +0 -52
- package/src/shapes/SHACL.ts +0 -653
- package/src/shapes/Shape.ts +0 -282
- package/src/test-helpers/query-fixtures.ts +0 -313
- package/src/tests/core-utils.test.ts +0 -286
- package/src/tests/metadata.test.ts +0 -65
- package/src/tests/query.test.ts +0 -599
- package/src/tests/query.types.test.ts +0 -606
- package/src/tests/store-routing.test.ts +0 -133
- package/src/utils/LinkedErrorLogging.ts +0 -25
- package/src/utils/LinkedFileStorage.ts +0 -75
- package/src/utils/LinkedStorage.ts +0 -120
- package/src/utils/NameSpace.ts +0 -5
- package/src/utils/NodeReference.ts +0 -16
- package/src/utils/Package.ts +0 -681
- package/src/utils/Prefix.ts +0 -108
- package/src/utils/ShapeClass.ts +0 -335
- package/src/utils/Types.ts +0 -19
- package/src/utils/URI.ts +0 -40
- package/src/utils/cached.ts +0 -53
- package/tsconfig-cjs.json +0 -8
- package/tsconfig-esm.json +0 -9
- package/tsconfig.json +0 -29
package/src/utils/Package.ts
DELETED
|
@@ -1,681 +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 {
|
|
7
|
-
createPropertyShape,
|
|
8
|
-
getAndClearCallbacks,
|
|
9
|
-
getNodeShapeUri,
|
|
10
|
-
LINCD_DATA_ROOT,
|
|
11
|
-
NodeShape,
|
|
12
|
-
PropertyShape,
|
|
13
|
-
} from '../shapes/SHACL.js';
|
|
14
|
-
import {Shape} from '../shapes/Shape.js';
|
|
15
|
-
import {Prefix} from './Prefix.js';
|
|
16
|
-
import {lincd as lincdOntology} from '../ontologies/lincd.js';
|
|
17
|
-
import {rdf} from '../ontologies/rdf.js';
|
|
18
|
-
import {addNodeShapeToShapeClass,getShapeClass} from './ShapeClass.js';
|
|
19
|
-
import {shacl} from '../ontologies/shacl.js';
|
|
20
|
-
import {rdfs} from '../ontologies/rdfs.js';
|
|
21
|
-
import {xsd} from '../ontologies/xsd.js';
|
|
22
|
-
import {NodeReferenceValue} from './NodeReference.js';
|
|
23
|
-
|
|
24
|
-
//global tree
|
|
25
|
-
declare var lincd: any;
|
|
26
|
-
declare var window;
|
|
27
|
-
declare var global;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// var packageParsePromises: Map<string,Promise<any>> = new Map();
|
|
31
|
-
// var loadedPackages: Set<NamedNode> = new Set();
|
|
32
|
-
let ontologies: Set<any> = new Set();
|
|
33
|
-
let _autoLoadOntologyData = false;
|
|
34
|
-
/**
|
|
35
|
-
* a map of requested property shapes for specific nodes
|
|
36
|
-
* The value is a promise if it's still loading, or true if it is fully loaded
|
|
37
|
-
*/
|
|
38
|
-
// type ClassDecorator = <T extends {new (...args: any[]): {}}>(
|
|
39
|
-
// constructor: T,
|
|
40
|
-
// ) => T;
|
|
41
|
-
|
|
42
|
-
export type ShapeConfig = {
|
|
43
|
-
/**
|
|
44
|
-
* A short description of the shape, what it represents and what it is used for.
|
|
45
|
-
* will be stored as rdfs:comment on the shape node
|
|
46
|
-
*/
|
|
47
|
-
description?: string;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type PackageMetadata = {
|
|
51
|
-
id: string;
|
|
52
|
-
packageName: string;
|
|
53
|
-
type: NodeReferenceValue;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* This object, returned by [linkedPackage()](/docs/lincd.js/modules/utils_Module#linkedPackage),
|
|
58
|
-
* contains the decorators to link different parts of a LINCD module.
|
|
59
|
-
*/
|
|
60
|
-
export interface LinkedPackageObject
|
|
61
|
-
{
|
|
62
|
-
/**
|
|
63
|
-
* Links a typescript class to a SHACL shape.
|
|
64
|
-
* This decorator creates a SHACL shape and looks at the static property [targetClass](/docs/lincd.js/classes/shapes_Shape.Shape#targetclass)
|
|
65
|
-
* The rest of the shape is typically 'shaped' by methods that use [property decorators](/docs/lincd.js/modules/utils_ShapeDecorators).
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* Example of a typescript class using the \@linkedShape decorator:
|
|
69
|
-
* ```tsx
|
|
70
|
-
* @linkedShape
|
|
71
|
-
* export class Person extends Shape { ... }
|
|
72
|
-
* ```
|
|
73
|
-
* Or with options:
|
|
74
|
-
* ```tsx
|
|
75
|
-
* @linkedShape({ description: "..." })
|
|
76
|
-
* export class Person extends Shape { ... }
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
linkedShape: {
|
|
80
|
-
<T extends typeof Shape>(constructor: T): void;
|
|
81
|
-
<T extends typeof Shape>(config?: ShapeConfig): (constructor: T) => void;
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Use this decorator to make any other classes or functions available on demand to other LINCD modules.
|
|
85
|
-
* It does not change the object it is applied on.
|
|
86
|
-
* This is specifically required for their use in an open-ended LINCD application.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* An example helper utility using the \@linkedUtil decorator:
|
|
90
|
-
* ```tsx
|
|
91
|
-
* @linkedUtil
|
|
92
|
-
* export class Sort {
|
|
93
|
-
* static byName(persons:Person[]) {
|
|
94
|
-
* return persons.sort((p1,p2) => p1.name < p2.name ? -1 : 1)
|
|
95
|
-
* }
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
linkedUtil: (constructor: any) => any;
|
|
99
|
-
/**
|
|
100
|
-
* Used to notify LINCD.js of an ontology.
|
|
101
|
-
* See also the [Ontology guides](/docs/guides/linked-code/ontologies).
|
|
102
|
-
*
|
|
103
|
-
* @param allFileExports - all the objects that are exported by the ontology file (use `import * as _this from "./path-to-this-file")`)
|
|
104
|
-
* @param nameSpace - the result of [createNameSpace](/docs/lincd.js/modules/utils_NameSpace#createnamespace). This allows consumers to generate NamedNodes that may not be listed in this ontology if needed
|
|
105
|
-
* @param prefixAndFileName - a suggested prefix chosen by you. Make sure the suggestedPrefix matches the file name and the name of the exported object that groups all entities together
|
|
106
|
-
* @param loadDataFunction - a method that loads _and parses_ the raw ontology data. This means the ontology will be loaded into the local graph. The returned result is mostly a JSONLDParsePromise (from lincd-jsonld/JSONLD, not bundled in LINCD.js)
|
|
107
|
-
* @param dataSource - the relative path to the raw data of the ontology
|
|
108
|
-
* @example
|
|
109
|
-
* Example of an Ontology File that used linkedOntology()
|
|
110
|
-
* ```tsx
|
|
111
|
-
* import {NamedNode} from 'lincd/models';
|
|
112
|
-
* import {JSONLD} from 'lincd-jsonld/JSONLD';
|
|
113
|
-
* import {createNameSpace} from 'lincd/utils/NameSpace';
|
|
114
|
-
* import {linkedOntology} from '../package.js';
|
|
115
|
-
* import * as _this from './my.js-ontology';
|
|
116
|
-
*
|
|
117
|
-
* let dataFile = '../data/my.js-ontology.json';
|
|
118
|
-
* export var loadData = () => JSONLD.parsePromise(import(dataFile));
|
|
119
|
-
*
|
|
120
|
-
* export var ns = createNameSpace('http://www.my-ontology.com/');
|
|
121
|
-
*
|
|
122
|
-
* export var _self: NamedNode = ns('');
|
|
123
|
-
*
|
|
124
|
-
* // Classes
|
|
125
|
-
* export var ExampleClass: NamedNode = ns('ExampleClass');
|
|
126
|
-
*
|
|
127
|
-
* // Properties
|
|
128
|
-
* export var exampleProperty: NamedNode = ns('exampleProperty');
|
|
129
|
-
*
|
|
130
|
-
* export const myOntology = {
|
|
131
|
-
* ExampleClass,
|
|
132
|
-
* exampleProperty,
|
|
133
|
-
* };
|
|
134
|
-
*
|
|
135
|
-
* linkedOntology(_this, ns, 'myOntology', loadData, dataFile);
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
linkedOntology: (
|
|
139
|
-
allFileExports,
|
|
140
|
-
nameSpace: (term: string) => NodeReferenceValue,
|
|
141
|
-
suggestedPrefixAndFileName: string,
|
|
142
|
-
loadDataFunction?: () => Promise<any>,
|
|
143
|
-
dataSource?: string | string[],
|
|
144
|
-
) => void;
|
|
145
|
-
/**
|
|
146
|
-
* Low level method used by other decorators to write to the modules' object in the LINCD tree.
|
|
147
|
-
* You should typically not need this.
|
|
148
|
-
* @param exportFileName - the file name that this exported object is available under. Needs to be unique across the module.
|
|
149
|
-
* @param exportedObject - the exported object (the class, constant, function, etc)
|
|
150
|
-
*/
|
|
151
|
-
registerPackageExport: (exportedObject: any) => void;
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* A method to get a shape class in this package by its name.
|
|
155
|
-
* This is helpful to avoid circular dependencies between shapes.
|
|
156
|
-
* For example see Thing.ts which uses get image():ImageObject.
|
|
157
|
-
* ImageObject extends Things.
|
|
158
|
-
* So get image() is implemented with getOneAs(...,getPackageShape('ImageObject'))
|
|
159
|
-
* @param name
|
|
160
|
-
*/
|
|
161
|
-
getPackageShape: (name: string) => typeof Shape;
|
|
162
|
-
/**
|
|
163
|
-
* A reference to the modules' object in the LINCD tree.
|
|
164
|
-
* Contains all linked components of the module.
|
|
165
|
-
*/
|
|
166
|
-
packageExports: any;
|
|
167
|
-
packageName: string;
|
|
168
|
-
packageMetadata: PackageMetadata;
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Register a file (a javascript module) and all its exported objects.
|
|
172
|
-
* Specifically helpful for registering multiple functional components if you declare them without a function name
|
|
173
|
-
* @param _this
|
|
174
|
-
* @param _module
|
|
175
|
-
*/
|
|
176
|
-
registerPackageModule(_module): void;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export var DEFAULT_LIMIT = 12;
|
|
180
|
-
|
|
181
|
-
export function setDefaultPageLimit(limit: number)
|
|
182
|
-
{
|
|
183
|
-
DEFAULT_LIMIT = limit;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export function autoLoadOntologyData(value: boolean)
|
|
187
|
-
{
|
|
188
|
-
_autoLoadOntologyData = value;
|
|
189
|
-
//this may be set to true after some ontologies have already indexed,
|
|
190
|
-
if (_autoLoadOntologyData)
|
|
191
|
-
{
|
|
192
|
-
// so in that case we load all data of ontologies that are already indexed
|
|
193
|
-
ontologies.forEach((ontologyExport) => {
|
|
194
|
-
//see linkedOntology() where we store the data loading method under the _load key
|
|
195
|
-
if (ontologyExport['_load'])
|
|
196
|
-
{
|
|
197
|
-
ontologyExport['_load']();
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
export function linkedPackage(packageName: string): LinkedPackageObject
|
|
205
|
-
{
|
|
206
|
-
let packageMetadata = registerPackageMetadata(packageName);
|
|
207
|
-
let packageTreeObject = registerPackageInTree(packageName);
|
|
208
|
-
|
|
209
|
-
//#Create declarators for this module
|
|
210
|
-
let registerPackageExport = function(object) {
|
|
211
|
-
if (object.name in packageTreeObject)
|
|
212
|
-
{
|
|
213
|
-
console.warn(
|
|
214
|
-
`Key ${object.name} was already defined for package ${packageName}. Note that LINCD currently only supports unique names across your entire package. Overwriting ${object.name} with new value`,
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
packageTreeObject[object.name] = object;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
let registerInPackageTree = function(exportName,exportedObject) {
|
|
221
|
-
packageTreeObject[exportName] = exportedObject;
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
function registerPackageModule(_module): void
|
|
225
|
-
{
|
|
226
|
-
for (var key in _module.exports)
|
|
227
|
-
{
|
|
228
|
-
//if the exported object itself is not named or its name is _wrappedComponent
|
|
229
|
-
//then we give it the same name as it's export name.
|
|
230
|
-
if (
|
|
231
|
-
!_module.exports[key].name ||
|
|
232
|
-
_module.exports[key].name === '_wrappedComponent'
|
|
233
|
-
)
|
|
234
|
-
{
|
|
235
|
-
Object.defineProperty(_module.exports[key],'name',{value: key});
|
|
236
|
-
//manual 'hack' to set the name of the original function
|
|
237
|
-
if (
|
|
238
|
-
_module.exports[key]['original'] &&
|
|
239
|
-
!_module.exports[key]['original']['name']
|
|
240
|
-
)
|
|
241
|
-
{
|
|
242
|
-
Object.defineProperty(_module.exports[key]['original'],'name',{
|
|
243
|
-
value: key + '_implementation',
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
registerInPackageTree(key,_module.exports[key]);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
//create a declarator function which Components of this module can use register themselves and add themselves to the global tree
|
|
252
|
-
let linkedUtil = function(constructor) {
|
|
253
|
-
//add the component class of this module to the global tree
|
|
254
|
-
registerPackageExport(constructor);
|
|
255
|
-
|
|
256
|
-
//return the original class without modifications
|
|
257
|
-
return constructor;
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
// helper that contains the previous body; applies the decorator work to a given constructor
|
|
261
|
-
function applyLinkedShape<T extends typeof Shape>(
|
|
262
|
-
constructor: T,
|
|
263
|
-
options?: ShapeConfig,
|
|
264
|
-
): void
|
|
265
|
-
{
|
|
266
|
-
if(!constructor) {
|
|
267
|
-
throw new Error('Constructor is undefined, skipping registration: '+constructor?.toString().substring(0,100)+' '+JSON.stringify(options));
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
// add the component class of this module to the global tree
|
|
271
|
-
registerPackageExport(constructor);
|
|
272
|
-
|
|
273
|
-
// register the component and its shape
|
|
274
|
-
Shape.registerByType(constructor);
|
|
275
|
-
|
|
276
|
-
// if no shape object has been attached to the constructor
|
|
277
|
-
if (!Object.getOwnPropertyNames(constructor).includes('shape'))
|
|
278
|
-
{
|
|
279
|
-
// create a new node shape for this shapeClass
|
|
280
|
-
let nodeShape: NodeShape = new NodeShape(
|
|
281
|
-
getNodeShapeUri(packageName, constructor.name),
|
|
282
|
-
);
|
|
283
|
-
// connect the typescript class to its NodeShape
|
|
284
|
-
constructor.shape = nodeShape;
|
|
285
|
-
// set the name
|
|
286
|
-
nodeShape.label = constructor.name;
|
|
287
|
-
|
|
288
|
-
if (options)
|
|
289
|
-
{
|
|
290
|
-
if (options.description)
|
|
291
|
-
{
|
|
292
|
-
nodeShape.description = options.description;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// also keep track of the reverse: nodeShape to typescript class
|
|
297
|
-
addNodeShapeToShapeClass(nodeShape,constructor);
|
|
298
|
-
|
|
299
|
-
//track what extends what (nodeShape level)
|
|
300
|
-
const extendingShapeClass = Object.getPrototypeOf(
|
|
301
|
-
constructor,
|
|
302
|
-
) as typeof Shape;
|
|
303
|
-
const extendingShape = extendingShapeClass.shape;
|
|
304
|
-
//if this shape class is extending something other then Shape
|
|
305
|
-
if (extendingShape && !(extendingShapeClass === Shape)) {
|
|
306
|
-
//store which nodeShape this nodeShape extends
|
|
307
|
-
nodeShape.extends = {id: extendingShape.id};
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
// run deferred callbacks from property decorators
|
|
312
|
-
if (constructor['shapeCallbacks'])
|
|
313
|
-
{
|
|
314
|
-
constructor['shapeCallbacks'].forEach((callback) => {
|
|
315
|
-
callback(nodeShape);
|
|
316
|
-
});
|
|
317
|
-
const nodeCallbacks = getAndClearCallbacks(nodeShape.id);
|
|
318
|
-
if(nodeCallbacks) {
|
|
319
|
-
nodeCallbacks.forEach((callback) => {
|
|
320
|
-
callback(nodeShape);
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
delete constructor['shapeCallbacks'];
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
else
|
|
327
|
-
{
|
|
328
|
-
console.warn('This ShapeClass already has a shape: ',constructor.shape);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (constructor.targetClass)
|
|
332
|
-
{
|
|
333
|
-
(constructor.shape as NodeShape).targetClass = constructor.targetClass;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// return the original class without modifications
|
|
337
|
-
// return constructor;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// Overloaded signatures to support both usages
|
|
341
|
-
function linkedShape<T extends typeof Shape>(constructor: T): void;
|
|
342
|
-
function linkedShape<T extends typeof Shape>(
|
|
343
|
-
options?: ShapeConfig,
|
|
344
|
-
): (constructor: T) => void;
|
|
345
|
-
function linkedShape(arg?: any): void | ((constructor: any) => void)
|
|
346
|
-
{
|
|
347
|
-
// usage as @linkedShape
|
|
348
|
-
if (typeof arg === 'function')
|
|
349
|
-
{
|
|
350
|
-
applyLinkedShape(arg);
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
// usage as @linkedShape({...}) or @linkedShape()
|
|
354
|
-
const options: ShapeConfig | undefined = arg;
|
|
355
|
-
return function <T extends typeof Shape>(constructor: T): void {
|
|
356
|
-
applyLinkedShape(constructor,options);
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
*
|
|
362
|
-
* @param exports all exports of the file, simply provide "this" as value!
|
|
363
|
-
* @param dataSource the path leading to the ontology's data file
|
|
364
|
-
* @param nameSpace the base URI of the ontology
|
|
365
|
-
* @param prefixAndFileName the file name MUST match the prefix for this ontology
|
|
366
|
-
*/
|
|
367
|
-
let linkedOntology = function(
|
|
368
|
-
exports,
|
|
369
|
-
nameSpace: (term: string) => NodeReferenceValue,
|
|
370
|
-
prefixAndFileName: string,
|
|
371
|
-
loadData?,
|
|
372
|
-
dataSource?: string | string[],
|
|
373
|
-
) {
|
|
374
|
-
let exportsCopy = {...exports};
|
|
375
|
-
//store specifics in exports. And make sure we can detect this as an ontology later
|
|
376
|
-
exportsCopy['_ns'] = nameSpace;
|
|
377
|
-
exportsCopy['_prefix'] = prefixAndFileName;
|
|
378
|
-
exportsCopy['_load'] = loadData;
|
|
379
|
-
exportsCopy['_data'] = dataSource;
|
|
380
|
-
|
|
381
|
-
//register the prefix here (so just calling linkedOntology with a prefix will automatically register that prefix)
|
|
382
|
-
if (prefixAndFileName)
|
|
383
|
-
{
|
|
384
|
-
//run the namespace without any term name, this will give back a named node with just the namespace as URI, then get that URI to provide it as full URI
|
|
385
|
-
Prefix.add(prefixAndFileName,nameSpace('').id);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
ontologies.add(exportsCopy);
|
|
389
|
-
//register all the exports under the prefix. NOTE: this means the file name HAS to match the prefix
|
|
390
|
-
registerInPackageTree(prefixAndFileName,exportsCopy);
|
|
391
|
-
// });
|
|
392
|
-
|
|
393
|
-
if (_autoLoadOntologyData)
|
|
394
|
-
{
|
|
395
|
-
loadData().catch((err) => {
|
|
396
|
-
console.warn(
|
|
397
|
-
'Could not load ontology data. Do you need to rebuild the module of the ' +
|
|
398
|
-
prefixAndFileName +
|
|
399
|
-
' ontology?',
|
|
400
|
-
err,
|
|
401
|
-
);
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* This method is used to get a shape class in this package by its name.
|
|
408
|
-
* This can be used to avoid circular dependencies between shapes.
|
|
409
|
-
* @param name
|
|
410
|
-
*/
|
|
411
|
-
let getPackageShape = (name: string): typeof Shape => {
|
|
412
|
-
//get the named node of the node shape first,
|
|
413
|
-
//then get the shape class that defines this node shape
|
|
414
|
-
return getShapeClass(
|
|
415
|
-
getNodeShapeUri(packageName, name),
|
|
416
|
-
);
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
//return the declarators so the module can use them
|
|
420
|
-
return {
|
|
421
|
-
linkedShape,
|
|
422
|
-
linkedUtil,
|
|
423
|
-
linkedOntology,
|
|
424
|
-
registerPackageExport,
|
|
425
|
-
registerPackageModule,
|
|
426
|
-
getPackageShape,
|
|
427
|
-
packageExports: packageTreeObject,
|
|
428
|
-
packageName: packageName,
|
|
429
|
-
packageMetadata,
|
|
430
|
-
} as LinkedPackageObject;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
function registerPackageInTree(packageName,packageExports?)
|
|
434
|
-
{
|
|
435
|
-
//prepare name for global tree reference
|
|
436
|
-
// let packageTreeKey = packageName.replace(/-/g,'_');
|
|
437
|
-
//if something with this name already registered in the global tree
|
|
438
|
-
if (packageName in lincd._modules)
|
|
439
|
-
{
|
|
440
|
-
//This probably means package.ts is loaded twice, through different paths and could point to a problem
|
|
441
|
-
//So we log about it. But there is one exception. LINCD itself registers itself twice: once in the bottom of this file and once in its package.ts file.
|
|
442
|
-
//But if there are already other packages registered, then probably there is 2 versions of LINCD being loaded, and that IS a problem.
|
|
443
|
-
if (packageName !== '@_linked/core' || Object.keys(lincd._modules).length !== 1)
|
|
444
|
-
{
|
|
445
|
-
console.warn(
|
|
446
|
-
'A package with the name ' +
|
|
447
|
-
packageName +
|
|
448
|
-
' has already been registered. Adding to existing object',
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
Object.assign(lincd._modules[packageName],packageExports);
|
|
452
|
-
}
|
|
453
|
-
else
|
|
454
|
-
{
|
|
455
|
-
//initiate an empty object for this module in the global tree
|
|
456
|
-
lincd._modules[packageName] = packageExports || {};
|
|
457
|
-
}
|
|
458
|
-
return lincd._modules[packageName];
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
function registerPackageMetadata(packageName: string): PackageMetadata
|
|
462
|
-
{
|
|
463
|
-
if (!lincd._packages)
|
|
464
|
-
{
|
|
465
|
-
lincd._packages = {};
|
|
466
|
-
}
|
|
467
|
-
if (packageName in lincd._packages)
|
|
468
|
-
{
|
|
469
|
-
return lincd._packages[packageName];
|
|
470
|
-
}
|
|
471
|
-
const packageMetadata: PackageMetadata = {
|
|
472
|
-
id: `${LINCD_DATA_ROOT}module/${packageName}`,
|
|
473
|
-
packageName,
|
|
474
|
-
type: lincdOntology.Module,
|
|
475
|
-
};
|
|
476
|
-
lincd._packages[packageName] = packageMetadata;
|
|
477
|
-
return packageMetadata;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
export function initTree()
|
|
482
|
-
{
|
|
483
|
-
let globalObject =
|
|
484
|
-
typeof window !== 'undefined'
|
|
485
|
-
? window
|
|
486
|
-
: typeof global !== 'undefined'
|
|
487
|
-
? global
|
|
488
|
-
: undefined;
|
|
489
|
-
if ('lincd' in globalObject)
|
|
490
|
-
{
|
|
491
|
-
throw new Error('Multiple versions of LINCD are loaded');
|
|
492
|
-
}
|
|
493
|
-
else
|
|
494
|
-
{
|
|
495
|
-
globalObject['lincd'] = {_modules: {}, _packages: {}};
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
//when this file is used, make sure the tree is initialized
|
|
500
|
-
initTree();
|
|
501
|
-
|
|
502
|
-
//now that this file is set up, we can link linked shapes in the core module itself
|
|
503
|
-
export const corePackage = linkedPackage('@_linked/core');
|
|
504
|
-
corePackage.linkedShape({
|
|
505
|
-
description:
|
|
506
|
-
'Represents a SHACL NodeShape; defines constraints for a class of RDF nodes. Links to multiple PropertyShapes. (schema, constraint, class validation)',
|
|
507
|
-
})(NodeShape);
|
|
508
|
-
corePackage.linkedShape({
|
|
509
|
-
description:
|
|
510
|
-
'Represents a SHACL PropertyShape; specifies rules for one property of a NodeShape (path, datatype, cardinality). (validation rule, property constraint)',
|
|
511
|
-
})(PropertyShape);
|
|
512
|
-
// ValidationReport / ValidationResult removed in core metadata rewrite
|
|
513
|
-
|
|
514
|
-
//ALL the following is to support Shape having get/set methods with property shapes
|
|
515
|
-
//and Shape itself having a nodeShape
|
|
516
|
-
//if we dont need Shape to have get/set methods (like label and type) then this can be removed
|
|
517
|
-
Shape.shape = new NodeShape(
|
|
518
|
-
'https://data.lincd.org/module/lincd/shape/shape',
|
|
519
|
-
);
|
|
520
|
-
addNodeShapeToShapeClass(Shape.shape,Shape);
|
|
521
|
-
|
|
522
|
-
//Here we can register the properties of the Shape class itself
|
|
523
|
-
//We can't do that inside of Shape because it would cause circular dependencies
|
|
524
|
-
createPropertyShape({
|
|
525
|
-
path: rdfs.label,
|
|
526
|
-
//TODO: multiple labels should be possible
|
|
527
|
-
maxCount: 1,//currently get label is implemented to return a single value
|
|
528
|
-
},
|
|
529
|
-
'label',
|
|
530
|
-
shacl.Literal,
|
|
531
|
-
Shape,
|
|
532
|
-
);
|
|
533
|
-
createPropertyShape(
|
|
534
|
-
{
|
|
535
|
-
path: rdf.type,
|
|
536
|
-
shape: Shape,
|
|
537
|
-
},
|
|
538
|
-
'type',
|
|
539
|
-
shacl.IRI,
|
|
540
|
-
Shape,
|
|
541
|
-
);
|
|
542
|
-
|
|
543
|
-
createPropertyShape(
|
|
544
|
-
{
|
|
545
|
-
path: shacl.property,
|
|
546
|
-
shape: PropertyShape,
|
|
547
|
-
},
|
|
548
|
-
'properties',
|
|
549
|
-
shacl.IRI,
|
|
550
|
-
NodeShape,
|
|
551
|
-
);
|
|
552
|
-
|
|
553
|
-
createPropertyShape({
|
|
554
|
-
path: rdfs.comment,
|
|
555
|
-
maxCount: 1,
|
|
556
|
-
},'description',shacl.Literal, NodeShape);
|
|
557
|
-
|
|
558
|
-
createPropertyShape({
|
|
559
|
-
path: rdf.type,
|
|
560
|
-
maxCount: 1,
|
|
561
|
-
shape: Shape,
|
|
562
|
-
},'type',shacl.IRI, NodeShape);
|
|
563
|
-
|
|
564
|
-
createPropertyShape(
|
|
565
|
-
{
|
|
566
|
-
path: shacl.targetClass,
|
|
567
|
-
shape: Shape, //should be rdfs Class, but that's currently not available in LINCD. So queries currently cannot continue after accessing targetClass
|
|
568
|
-
maxCount: 1,
|
|
569
|
-
},
|
|
570
|
-
'targetClass',
|
|
571
|
-
shacl.IRI,
|
|
572
|
-
NodeShape,
|
|
573
|
-
);
|
|
574
|
-
|
|
575
|
-
createPropertyShape({
|
|
576
|
-
path: shacl.description,
|
|
577
|
-
maxCount: 1,
|
|
578
|
-
},'type',shacl.Literal, NodeShape);
|
|
579
|
-
|
|
580
|
-
createPropertyShape({
|
|
581
|
-
path: shacl.targetNode,
|
|
582
|
-
shape: Shape,//actually returns a NamedNode... is this correct then? Should we define or use a rdfs Class that matches the potential values?
|
|
583
|
-
},'targetNode',shacl.IRI, NodeShape);
|
|
584
|
-
|
|
585
|
-
createPropertyShape({
|
|
586
|
-
path: lincdOntology.isExtending,
|
|
587
|
-
shape: NodeShape,
|
|
588
|
-
},'extends',shacl.IRI, NodeShape);
|
|
589
|
-
|
|
590
|
-
//currently path accepts multiple values, so its a multi-value property
|
|
591
|
-
//these values will be consequent properties that follow each other. Other property paths are not supported yet.
|
|
592
|
-
createPropertyShape(
|
|
593
|
-
{
|
|
594
|
-
path: shacl.path,
|
|
595
|
-
shape: Shape,
|
|
596
|
-
},
|
|
597
|
-
'path',
|
|
598
|
-
shacl.IRI,
|
|
599
|
-
PropertyShape,
|
|
600
|
-
);
|
|
601
|
-
|
|
602
|
-
createPropertyShape(
|
|
603
|
-
{
|
|
604
|
-
path: shacl.node,
|
|
605
|
-
shape: NodeShape,
|
|
606
|
-
maxCount: 1,
|
|
607
|
-
},
|
|
608
|
-
'valueShape',
|
|
609
|
-
shacl.IRI,
|
|
610
|
-
PropertyShape,
|
|
611
|
-
);
|
|
612
|
-
|
|
613
|
-
createPropertyShape(
|
|
614
|
-
{
|
|
615
|
-
maxCount: 1,
|
|
616
|
-
path: shacl.nodeKind,
|
|
617
|
-
shape: Shape, //actually returns a NamedNode. Queries currently cannot continue after accessing nodeKind
|
|
618
|
-
},
|
|
619
|
-
'nodeKind',
|
|
620
|
-
shacl.IRI,
|
|
621
|
-
PropertyShape,
|
|
622
|
-
);
|
|
623
|
-
|
|
624
|
-
createPropertyShape(
|
|
625
|
-
{
|
|
626
|
-
path: shacl.datatype,
|
|
627
|
-
shape: Shape,
|
|
628
|
-
maxCount: 1,
|
|
629
|
-
},
|
|
630
|
-
'datatype',
|
|
631
|
-
shacl.IRI,
|
|
632
|
-
PropertyShape,
|
|
633
|
-
);
|
|
634
|
-
|
|
635
|
-
//PropertyShape.maxCount
|
|
636
|
-
createPropertyShape(
|
|
637
|
-
{
|
|
638
|
-
path: shacl.maxCount,
|
|
639
|
-
datatype: xsd.integer,
|
|
640
|
-
maxCount: 1,
|
|
641
|
-
},
|
|
642
|
-
'maxCount',
|
|
643
|
-
shacl.Literal,
|
|
644
|
-
PropertyShape,
|
|
645
|
-
);
|
|
646
|
-
|
|
647
|
-
//PropertyShape.minCount
|
|
648
|
-
createPropertyShape(
|
|
649
|
-
{
|
|
650
|
-
path: shacl.minCount,
|
|
651
|
-
datatype: xsd.integer,
|
|
652
|
-
maxCount: 1,
|
|
653
|
-
},
|
|
654
|
-
'minCount',
|
|
655
|
-
shacl.Literal,
|
|
656
|
-
PropertyShape,
|
|
657
|
-
);
|
|
658
|
-
|
|
659
|
-
//PropertyShape.name
|
|
660
|
-
createPropertyShape(
|
|
661
|
-
{
|
|
662
|
-
path: shacl.name,
|
|
663
|
-
maxCount: 1,
|
|
664
|
-
},
|
|
665
|
-
'name',
|
|
666
|
-
shacl.Literal,
|
|
667
|
-
PropertyShape,
|
|
668
|
-
);
|
|
669
|
-
|
|
670
|
-
//PropertyShape.description
|
|
671
|
-
createPropertyShape(
|
|
672
|
-
{
|
|
673
|
-
path: shacl.description,
|
|
674
|
-
maxCount: 1,
|
|
675
|
-
},
|
|
676
|
-
'description',
|
|
677
|
-
shacl.Literal,
|
|
678
|
-
PropertyShape,
|
|
679
|
-
);
|
|
680
|
-
|
|
681
|
-
//PropertyShape.inList
|