@_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.
Files changed (81) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/LICENSE +1 -1
  3. package/README.md +147 -92
  4. package/lib/cjs/queries/SelectQuery.d.ts +5 -0
  5. package/lib/cjs/queries/SelectQuery.js +14 -0
  6. package/lib/cjs/queries/SelectQuery.js.map +1 -1
  7. package/lib/cjs/shapes/SHACL.d.ts +1 -0
  8. package/lib/cjs/shapes/SHACL.js +82 -2
  9. package/lib/cjs/shapes/SHACL.js.map +1 -1
  10. package/lib/cjs/shapes/Shape.d.ts +13 -1
  11. package/lib/cjs/shapes/Shape.js +6 -0
  12. package/lib/cjs/shapes/Shape.js.map +1 -1
  13. package/lib/cjs/test-helpers/query-fixtures.d.ts +583 -0
  14. package/lib/cjs/test-helpers/query-fixtures.js +39 -1
  15. package/lib/cjs/test-helpers/query-fixtures.js.map +1 -1
  16. package/lib/esm/queries/SelectQuery.d.ts +5 -0
  17. package/lib/esm/queries/SelectQuery.js +14 -0
  18. package/lib/esm/queries/SelectQuery.js.map +1 -1
  19. package/lib/esm/shapes/SHACL.d.ts +1 -0
  20. package/lib/esm/shapes/SHACL.js +82 -2
  21. package/lib/esm/shapes/SHACL.js.map +1 -1
  22. package/lib/esm/shapes/Shape.d.ts +13 -1
  23. package/lib/esm/shapes/Shape.js +6 -0
  24. package/lib/esm/shapes/Shape.js.map +1 -1
  25. package/lib/esm/test-helpers/query-fixtures.d.ts +583 -0
  26. package/lib/esm/test-helpers/query-fixtures.js +38 -0
  27. package/lib/esm/test-helpers/query-fixtures.js.map +1 -1
  28. package/package.json +17 -1
  29. package/.context/notes.md +0 -0
  30. package/.context/todos.md +0 -0
  31. package/AGENTS.md +0 -59
  32. package/docs/001-core-extraction.md +0 -305
  33. package/jest.config.js +0 -25
  34. package/scripts/dual-package.js +0 -25
  35. package/src/collections/CoreMap.ts +0 -127
  36. package/src/collections/CoreSet.ts +0 -171
  37. package/src/collections/ShapeSet.ts +0 -18
  38. package/src/index.ts +0 -88
  39. package/src/interfaces/ICoreIterable.ts +0 -35
  40. package/src/interfaces/IFileStore.ts +0 -28
  41. package/src/interfaces/IQuadStore.ts +0 -16
  42. package/src/interfaces/IQueryParser.ts +0 -51
  43. package/src/ontologies/lincd.ts +0 -25
  44. package/src/ontologies/npm.ts +0 -15
  45. package/src/ontologies/owl.ts +0 -26
  46. package/src/ontologies/rdf.ts +0 -32
  47. package/src/ontologies/rdfs.ts +0 -38
  48. package/src/ontologies/shacl.ts +0 -136
  49. package/src/ontologies/xsd.ts +0 -47
  50. package/src/package.ts +0 -11
  51. package/src/queries/CreateQuery.ts +0 -41
  52. package/src/queries/DeleteQuery.ts +0 -54
  53. package/src/queries/MutationQuery.ts +0 -287
  54. package/src/queries/QueryContext.ts +0 -41
  55. package/src/queries/QueryFactory.ts +0 -275
  56. package/src/queries/QueryParser.ts +0 -79
  57. package/src/queries/SelectQuery.ts +0 -2101
  58. package/src/queries/UpdateQuery.ts +0 -47
  59. package/src/shapes/List.ts +0 -52
  60. package/src/shapes/SHACL.ts +0 -653
  61. package/src/shapes/Shape.ts +0 -282
  62. package/src/test-helpers/query-fixtures.ts +0 -313
  63. package/src/tests/core-utils.test.ts +0 -286
  64. package/src/tests/metadata.test.ts +0 -65
  65. package/src/tests/query.test.ts +0 -599
  66. package/src/tests/query.types.test.ts +0 -606
  67. package/src/tests/store-routing.test.ts +0 -133
  68. package/src/utils/LinkedErrorLogging.ts +0 -25
  69. package/src/utils/LinkedFileStorage.ts +0 -75
  70. package/src/utils/LinkedStorage.ts +0 -120
  71. package/src/utils/NameSpace.ts +0 -5
  72. package/src/utils/NodeReference.ts +0 -16
  73. package/src/utils/Package.ts +0 -681
  74. package/src/utils/Prefix.ts +0 -108
  75. package/src/utils/ShapeClass.ts +0 -335
  76. package/src/utils/Types.ts +0 -19
  77. package/src/utils/URI.ts +0 -40
  78. package/src/utils/cached.ts +0 -53
  79. package/tsconfig-cjs.json +0 -8
  80. package/tsconfig-esm.json +0 -9
  81. package/tsconfig.json +0 -29
@@ -1,275 +0,0 @@
1
- import {LinkedQuery} from './SelectQuery.js';
2
- import {NodeShape, PropertyShape} from '../shapes/SHACL.js';
3
- import {Shape} from '../shapes/Shape.js';
4
- import {ShapeSet} from '../collections/ShapeSet.js';
5
- import {NodeReferenceValue} from '../utils/NodeReference.js';
6
-
7
- export type Prettify<T> = T extends infer R
8
- ? {
9
- [K in keyof R]: R[K];
10
- }
11
- : never;
12
-
13
- /**
14
- * Recursively adds an id property to all objects in the object.
15
- * Also makes all keys optional.
16
- */
17
- type _AddId<U> = U extends string | number | boolean | Date | null | undefined
18
- ? U
19
- : U extends Array<infer T>
20
- ? Array<_AddId<T>>
21
- : WithId<U>;
22
-
23
- type RemoveId<U> = Omit<U, 'id'>;
24
- // type WithId<U> = {
25
- // [K in keyof U]-?: _AddId<U[K]>; // Make all fields required
26
- // } & { id: string };
27
-
28
- type WithId<U> = U & {id: string};
29
-
30
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
31
- k: infer I,
32
- ) => void
33
- ? I
34
- : never;
35
-
36
- type CombineTypes<T> = {
37
- [K in keyof UnionToIntersection<T>]: T extends {[P in K]?: infer V}
38
- ? _AddId<V>
39
- : never;
40
- };
41
-
42
- type IsPlainObject<T> = T extends object
43
- ? T extends any[]
44
- ? false
45
- : T extends Function
46
- ? false
47
- : T extends Date
48
- ? false
49
- : T extends RegExp
50
- ? false
51
- : T extends Error
52
- ? false
53
- : T extends null
54
- ? false
55
- : T extends undefined
56
- ? false
57
- : T extends object
58
- ? true
59
- : false
60
- : false;
61
-
62
- // type X = [{
63
- // id:string
64
- // },{
65
- // id:string
66
- // },{
67
- // name:string
68
- // }];
69
- // type OfX<X> = Prettify<{
70
- // updatedTo:(X extends Array<infer U> ? U : X)[]
71
- // }>;
72
- // type Y = OfX<X>;
73
- // let x:Y;
74
- // let name = x.updatedTo[0].name;
75
-
76
- type RecursiveTransform<T, IsCreate = false> = T extends
77
- | string
78
- | number
79
- | boolean
80
- | Date
81
- | null
82
- | undefined
83
- ? T
84
- : T extends Array<infer U>
85
- ? UpdatedSet<Prettify<RecursiveTransform<U>>, IsCreate>
86
- : IsSetModification<T> extends true
87
- ? ModifiedSet<T, IsCreate>
88
- : IsPlainObject<T> extends true
89
- ? // ? WithId<{ [K in keyof T]-?: Prettify<RecursiveTransform<T[K]>> }>
90
- WithId<{[K in keyof T]: Prettify<RecursiveTransform<T[K], IsCreate>>}>
91
- : T; //<-- should be never?
92
-
93
- //for update() we use {updatedTo} but for create() we actually just return the array of new values;
94
- type UpdatedSet<U, IsCreate> = IsCreate extends true
95
- ? U[]
96
- : {
97
- updatedTo: U[];
98
- };
99
- type IsSetModification<T> = T extends {add?: any; remove?: any} ? true : false;
100
- type AddedType<T> = T extends {add: (infer U)[]}
101
- ? U
102
- : T extends {add: infer U}
103
- ? U
104
- : never;
105
-
106
- type RemovedType<T> = T extends {remove: (infer U)[]}
107
- ? U
108
- : T extends {remove: infer U}
109
- ? U
110
- : never;
111
-
112
- type ModifiedSet<T, IsCreate = false> = {
113
- added: AddId<AddedType<T>, IsCreate>[];
114
- removed: AddId<RemovedType<T>, IsCreate>[];
115
- };
116
-
117
- export type AddId<T, IsCreate = false> = Prettify<
118
- RecursiveTransform<T, IsCreate>
119
- >;
120
- // export type AddId<T> = Prettify<_AddId<T>>;
121
- // type _AddId<T> = T extends Array<infer U>
122
- // ? Array<AddId<U>>
123
- // : T extends Record<string, any> // Record checks for plain objects, hence we exclude dates and other objects that extend Object
124
- // ? WithId<T>
125
- // : T;
126
- //
127
- //
128
- // /**
129
- // * Makes all keys optional and adds an id property.
130
- // */
131
- // type WithId<T> = {
132
- // [K in keyof T]-?: AddId<T[K]>; // Recursively apply AddId to all properties
133
- // } & { id: string };
134
-
135
- // export type AddId<U> = Prettify<U extends String ? U :
136
- // U extends Number ? U :
137
- // U extends Date ? U :
138
- // U extends Boolean ? U :
139
- // U extends null ? U :
140
- // U extends undefined ? U :
141
- // U extends Array<infer T> ? Array<AddId<CombineTypes<T>>> : WithId<U>>;
142
- //
143
- //
144
- // type WithId<U> = {[K in keyof U]: AddId<U[K]>} & {id:string};
145
- //
146
- // type UnionToIntersection<U> =
147
- // (U extends any ? (k: U) => void : never) extends
148
- // ((k: infer I) => void) ? I : never;
149
- //
150
- //
151
- // type CombineTypes<T> = {
152
- // [K in keyof UnionToIntersection<T>]: T extends { [P in K]?: infer V }
153
- // ? AddId<V>
154
- // : never;
155
- // };
156
- // type CombineTypes<T> = Partial<{
157
- // [K in keyof UnionToIntersection<T>]: T extends { [P in K]?: infer V } ? V : never;
158
- // }>;
159
-
160
- // type Prettify<T> = { [K in keyof T]: T[K] };
161
-
162
- // type RemoveUndefinedKeys<T> = {
163
- // [K in keyof T as T[K] extends undefined ? never : K]: T[K];
164
- // };
165
-
166
- // type UpdatePartial<Shape> = WithoutFunctions<Shape>;
167
- export type UpdatePartial<S = Shape> =
168
- | UpdateNodeDescription<S>
169
- | NodeReferenceValue;
170
- type UpdateNodeDescription<Shape> = Partial<
171
- Omit<
172
- {
173
- [P in KeysWithoutFunctions<Shape>]: ShapePropValueToUpdatePartial<
174
- Shape[P]
175
- >;
176
- },
177
- 'node' | 'nodeShape' | 'namedNode' | 'targetClass'
178
- >
179
- >;
180
- // type AvailableUpdateKeys<Shape> = Omit<KeysWithoutFunctions<Shape>,'nodeShape'|'node'|'namedNode'>
181
- type KeysWithoutFunctions<T> = {
182
- [K in keyof T]: T[K] extends Function ? never : K;
183
- }[keyof T];
184
-
185
- // type ShapePropertyToUpdatePartial<ShapeProperty> = ShapeProperty;
186
- type ShapePropValueToUpdatePartial<ShapeProperty> = ShapeProperty extends Shape
187
- ? UpdatePartial<ShapeProperty>
188
- : ShapeProperty extends ShapeSet<infer SSType>
189
- ? SetUpdateValue<SSType>
190
- : ShapeProperty;
191
-
192
- type SetUpdateValue<SSType> = UpdatePartial<SSType>[] | SetModification<SSType>;
193
-
194
- export type SetModification<SSType> = {
195
- add?: UpdatePartial<SSType>[] | UpdatePartial<SSType>;
196
- remove?: UpdatePartial<SSType>[] | UpdatePartial<SSType>;
197
- };
198
-
199
- export type SetModificationValue = {
200
- $add?: UpdatePartial[];
201
- $remove?: NodeReferenceValue[];
202
- };
203
-
204
- type UnsetValue = undefined;
205
- export type LiteralUpdateValue = string | number | boolean | Date;
206
- export type PropUpdateValue =
207
- | SinglePropertyUpdateValue
208
- | SinglePropertyUpdateValue[]
209
- | SetModificationValue;
210
- export type SinglePropertyUpdateValue =
211
- | NodeDescriptionValue
212
- | NodeReferenceValue
213
- | LiteralUpdateValue
214
- | UnsetValue;
215
- export type NodeDescriptionValue = {
216
- shape: NodeShape;
217
- fields: UpdateNodePropertyValue[];
218
- /**
219
- * The id of the node to be created.
220
- * Optional, if not provided a new id will be generated.
221
- */
222
- __id?: string;
223
- };
224
- export type UpdateNodePropertyValue = {
225
- prop: PropertyShape;
226
- val: PropUpdateValue;
227
- };
228
- export type ShapeReferenceValue = {id: string; shape: NodeReferenceValue};
229
- export {toNodeReference} from '../utils/NodeReference.js';
230
- export type {NodeReferenceValue};
231
-
232
- export abstract class QueryFactory {
233
- getQueryObject(): LinkedQuery | Promise<LinkedQuery> {
234
- return null;
235
- }
236
- }
237
-
238
- export function isSetModificationValue(
239
- value: any,
240
- ): value is SetModificationValue {
241
- if (!(typeof value === 'object')) return false;
242
-
243
- let hasAddKey = value.$add;
244
- let hasRemoveKey = value.$remove;
245
- let numKeys = Object.keys(value).length;
246
- //has no other keys
247
- return (
248
- (hasAddKey && hasRemoveKey && numKeys === 2) ||
249
- (hasAddKey && numKeys === 1) ||
250
- (hasRemoveKey && numKeys === 1)
251
- );
252
- }
253
-
254
- /**
255
- * Checks if the new count of values for a property is within the min and max count of the property shape.
256
- * Throws an error if the count is not within the range.
257
- * @param propShape
258
- * @param numValues
259
- */
260
- export function checkNewCount(propShape: PropertyShape, numValues: number) {
261
- if (propShape.maxCount) {
262
- if (numValues > propShape.maxCount) {
263
- throw new Error(
264
- `Too many values for property: ${propShape.label}. Max count is: ${propShape.maxCount}, updated count would be ${numValues}`,
265
- );
266
- }
267
- }
268
- if (propShape.minCount) {
269
- if (numValues < propShape.minCount) {
270
- throw new Error(
271
- `Too few values for property: ${propShape.label}. Min count is: ${propShape.minCount}, updated count would be ${numValues}`,
272
- );
273
- }
274
- }
275
- }
@@ -1,79 +0,0 @@
1
- import {IQueryParser, staticImplements} from '../interfaces/IQueryParser.js';
2
- import {
3
- GetQueryResponseType,
4
- QueryResponseToResultType,
5
- SelectQueryFactory,
6
- } from './SelectQuery.js';
7
- import {AddId, NodeReferenceValue, UpdatePartial} from './QueryFactory.js';
8
- import {Shape} from '../shapes/Shape.js';
9
- import {LinkedStorage} from '../utils/LinkedStorage.js';
10
- import {UpdateQueryFactory} from './UpdateQuery.js';
11
- import {CreateQueryFactory, CreateResponse} from './CreateQuery.js';
12
- import {DeleteQueryFactory, DeleteResponse} from './DeleteQuery.js';
13
- import {NodeId} from './MutationQuery.js';
14
-
15
- @staticImplements<IQueryParser>() /* this class implements this interface with static methods */
16
- export class QueryParser {
17
- static async selectQuery<
18
- ShapeType extends Shape,
19
- ResponseType,
20
- Source,
21
- ResultType = QueryResponseToResultType<
22
- GetQueryResponseType<SelectQueryFactory<ShapeType, ResponseType>>,
23
- ShapeType
24
- >[],
25
- >(
26
- query: SelectQueryFactory<ShapeType, ResponseType, Source>,
27
- ): Promise<ResultType> {
28
- try {
29
- const queryObject = query.getQueryObject();
30
- return LinkedStorage.selectQuery(queryObject);
31
- } catch (e) {
32
- return Promise.reject(e);
33
- }
34
- }
35
-
36
- static updateQuery<
37
- ShapeType extends Shape,
38
- U extends UpdatePartial<ShapeType>,
39
- >(
40
- id: string | NodeReferenceValue,
41
- updateObjectOrFn: U,
42
- shapeClass: typeof Shape,
43
- ): Promise<AddId<U>> {
44
- const query = new UpdateQueryFactory<ShapeType, U>(
45
- shapeClass,
46
- id,
47
- updateObjectOrFn,
48
- );
49
- let queryObject = query.getQueryObject();
50
- return LinkedStorage.updateQuery(queryObject);
51
- }
52
-
53
- static createQuery<
54
- ShapeType extends Shape,
55
- U extends UpdatePartial<ShapeType>,
56
- >(updateObjectOrFn: U, shapeClass: typeof Shape): Promise<CreateResponse<U>> {
57
- try {
58
- const query = new CreateQueryFactory<ShapeType, U>(
59
- shapeClass,
60
- updateObjectOrFn,
61
- );
62
- let queryObject = query.getQueryObject();
63
- return LinkedStorage.createQuery(queryObject);
64
- } catch (e) {
65
- console.warn(e);
66
- }
67
- }
68
-
69
- static deleteQuery(
70
- id: NodeId | NodeId[] | NodeReferenceValue[],
71
- shapeClass: typeof Shape,
72
- ): Promise<DeleteResponse> {
73
- const query = new DeleteQueryFactory<Shape, {}>(shapeClass, id);
74
- let queryObject = query.getQueryObject();
75
- return LinkedStorage.deleteQuery(queryObject);
76
- }
77
- }
78
-
79
- Shape.queryParser = QueryParser;