@_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,282 +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 nextTick from 'next-tick';
7
- import type {ICoreIterable} from '../interfaces/ICoreIterable.js';
8
- import type {NodeShape, PropertyShape} from './SHACL.js';
9
- import {
10
- GetQueryResponseType,
11
- PatchedQueryPromise,
12
- QResult,
13
- QShape,
14
- QueryBuildFn,
15
- QueryResponseToResultType,
16
- QueryShape,
17
- SelectQueryFactory,
18
- } from '../queries/SelectQuery.js';
19
- import type {IQueryParser} from '../interfaces/IQueryParser.js';
20
- import {AddId, NodeReferenceValue, UpdatePartial} from '../queries/QueryFactory.js';
21
- import {CreateResponse} from '../queries/CreateQuery.js';
22
- import {DeleteResponse} from '../queries/DeleteQuery.js';
23
- import {NodeId} from '../queries/MutationQuery.js';
24
- import {getPropertyShapeByLabel} from '../utils/ShapeClass.js';
25
- import {ShapeSet} from '../collections/ShapeSet.js';
26
-
27
- //shape that returns property shapes for its keys
28
- type AccessPropertiesShape<T extends Shape> = {
29
- [P in keyof T]: PropertyShape;
30
- };
31
- type PropertyShapeMapFunction<T extends Shape, ResponseType> = (
32
- p: AccessPropertiesShape<T>,
33
- ) => ResponseType;
34
-
35
- export type ShapeType<S extends Shape = Shape> = (abstract new (
36
- ...args: any[]
37
- ) => S) & {
38
- shape: NodeShape;
39
- targetClass?: NodeReferenceValue;
40
- };
41
-
42
- export abstract class Shape {
43
- static targetClass: NodeReferenceValue = null;
44
- static queryParser: IQueryParser;
45
- static shape: NodeShape;
46
- static typesToShapes: Map<string, Set<typeof Shape>> = new Map();
47
-
48
- __queryContextId?: string;
49
- id?: string;
50
-
51
- constructor(node?: string | NodeReferenceValue) {
52
- if (node) {
53
- this.id = typeof node === 'string' ? node : node.id;
54
- }
55
- }
56
-
57
- get nodeShape(): NodeShape {
58
- return (this.constructor as typeof Shape).shape;
59
- }
60
-
61
- get uri(): string {
62
- return this.id;
63
- }
64
-
65
- set uri(value: string) {
66
- this.id = value;
67
- }
68
-
69
- /**
70
- * @internal
71
- * @param shapeClass
72
- * @param type
73
- */
74
- static registerByType(shapeClass: typeof Shape, type?: NodeReferenceValue) {
75
- if (!type) {
76
- if (shapeClass === Shape) {
77
- return;
78
- }
79
- const shapeType = shapeClass.targetClass;
80
- if (shapeType) {
81
- type = shapeType;
82
- }
83
- }
84
- if (!type) {
85
- return;
86
- }
87
- const typeId = type.id;
88
- if (!this.typesToShapes.has(typeId)) {
89
- this.typesToShapes.set(typeId, new Set());
90
- }
91
- this.typesToShapes.get(typeId).add(shapeClass);
92
- }
93
-
94
- static query<S extends Shape, R = unknown>(
95
- this: {new (...args: any[]): S; targetClass: any},
96
- subject: S | QShape<S> | QResult<S>,
97
- queryFn: QueryBuildFn<S, R>,
98
- ): SelectQueryFactory<S, R>;
99
- static query<S extends Shape, R = unknown>(
100
- this: {new (...args: any[]): S; targetClass: any},
101
- queryFn: QueryBuildFn<S, R>,
102
- ): SelectQueryFactory<S, R>;
103
- static query<S extends Shape, R = unknown>(
104
- this: {new (...args: any[]): S; targetClass: any},
105
- subject: S | QShape<S> | QResult<S> | QueryBuildFn<S, R>,
106
- queryFn?: QueryBuildFn<S, R>,
107
- ): SelectQueryFactory<S, R> {
108
- const _queryFn =
109
- subject && queryFn ? queryFn : (subject as QueryBuildFn<S, R>);
110
- let _subject: S | QResult<S> = queryFn ? (subject as S) : undefined;
111
- if (_subject instanceof QueryShape) {
112
- _subject = {id: _subject.id} as QResult<S>;
113
- }
114
- const query = new SelectQueryFactory<S>(this as any, _queryFn, _subject);
115
- return query;
116
- }
117
-
118
- /**
119
- * Select properties of instances of this shape.
120
- * Returns a single result if a single subject is provided, or an array of results if no subjects are provided.
121
- * The select function (first or second argument) receives a proxy of the shape that allows you to virtually access any property you want up to any level of depth.
122
- * @param selectFn
123
- */
124
- static select<
125
- ShapeType extends Shape,
126
- S = unknown,
127
- ResultType = QueryResponseToResultType<S, ShapeType>[],
128
- >(
129
- this: {new (...args: any[]): ShapeType; queryParser: IQueryParser},
130
- selectFn: QueryBuildFn<ShapeType, S>,
131
- ): Promise<ResultType> & PatchedQueryPromise<ResultType, ShapeType>;
132
- static select<
133
- ShapeType extends Shape,
134
- S = unknown,
135
- ResultType = QueryResponseToResultType<
136
- GetQueryResponseType<SelectQueryFactory<ShapeType, S>>,
137
- ShapeType
138
- >[],
139
- >(this: {
140
- new (...args: any[]): ShapeType;
141
- queryParser: IQueryParser;
142
- }): Promise<ResultType> & PatchedQueryPromise<ResultType, ShapeType>;
143
- static select<
144
- ShapeType extends Shape,
145
- S = unknown,
146
- ResultType = QueryResponseToResultType<
147
- GetQueryResponseType<SelectQueryFactory<ShapeType, S>>,
148
- ShapeType
149
- >,
150
- >(
151
- this: {new (...args: any[]): ShapeType; queryParser: IQueryParser},
152
- subjects?: ShapeType | QResult<ShapeType>,
153
- selectFn?: QueryBuildFn<ShapeType, S>,
154
- ): Promise<ResultType> & PatchedQueryPromise<ResultType, ShapeType>;
155
- static select<
156
- ShapeType extends Shape,
157
- S = unknown,
158
- ResultType = QueryResponseToResultType<
159
- GetQueryResponseType<SelectQueryFactory<ShapeType, S>>,
160
- ShapeType
161
- >[],
162
- >(
163
- this: {new (...args: any[]): ShapeType; queryParser: IQueryParser},
164
- subjects?: ICoreIterable<ShapeType> | QResult<ShapeType>[],
165
- selectFn?: QueryBuildFn<ShapeType, S>,
166
- ): Promise<ResultType> & PatchedQueryPromise<ResultType, ShapeType>;
167
- static select<
168
- ShapeType extends Shape,
169
- S = unknown,
170
- ResultType = QueryResponseToResultType<
171
- GetQueryResponseType<SelectQueryFactory<ShapeType, S>>,
172
- ShapeType
173
- >[],
174
- >(
175
- this: {new (...args: any[]): ShapeType; queryParser: IQueryParser},
176
- targetOrSelectFn?: ShapeType | QueryBuildFn<ShapeType, S>,
177
- selectFn?: QueryBuildFn<ShapeType, S>,
178
- ): Promise<ResultType> & PatchedQueryPromise<ResultType, ShapeType> {
179
- let _selectFn;
180
- let subject;
181
- if (selectFn) {
182
- _selectFn = selectFn;
183
- subject = targetOrSelectFn;
184
- } else {
185
- _selectFn = targetOrSelectFn;
186
- }
187
-
188
- const query = new SelectQueryFactory<ShapeType, S>(
189
- this as any,
190
- _selectFn,
191
- subject,
192
- );
193
- let p = new Promise<ResultType>((resolve, reject) => {
194
- nextTick(() => {
195
- this.queryParser
196
- .selectQuery(query)
197
- .then((result) => {
198
- resolve(result as ResultType);
199
- })
200
- .catch((err) => {
201
- reject(err);
202
- });
203
- });
204
- });
205
- return query.patchResultPromise<ResultType>(p);
206
- }
207
-
208
- static update<ShapeType extends Shape, U extends UpdatePartial<ShapeType>>(
209
- this: {new (...args: any[]): ShapeType; queryParser: IQueryParser},
210
- id: string | NodeReferenceValue | QShape<ShapeType>,
211
- updateObjectOrFn?: U,
212
- ): Promise<AddId<U>> {
213
- return this.queryParser.updateQuery(
214
- id,
215
- updateObjectOrFn,
216
- this as any as typeof Shape,
217
- );
218
- }
219
-
220
- static create<ShapeType extends Shape, U extends UpdatePartial<ShapeType>>(
221
- this: {new (...args: any[]): ShapeType; queryParser: IQueryParser},
222
- updateObjectOrFn?: U,
223
- ): Promise<CreateResponse<U>> {
224
- return this.queryParser.createQuery(
225
- updateObjectOrFn,
226
- this as any as typeof Shape,
227
- );
228
- }
229
-
230
- static delete<ShapeType extends Shape, U extends UpdatePartial<ShapeType>>(
231
- this: {new (...args: any[]): ShapeType; queryParser: IQueryParser},
232
- id: NodeId | NodeId[] | NodeReferenceValue[],
233
- ): Promise<DeleteResponse> {
234
- return this.queryParser.deleteQuery(id, this as any as typeof Shape);
235
- }
236
-
237
- static mapPropertyShapes<ShapeType extends Shape, ResponseType = unknown>(
238
- this: {new (...args: any[]): ShapeType; targetClass: any},
239
- mapFunction?: PropertyShapeMapFunction<ShapeType, ResponseType>,
240
- ): ResponseType {
241
- let dummyShape = new (this as any)();
242
- dummyShape.proxy = new Proxy(dummyShape, {
243
- get(target, key, receiver) {
244
- if (typeof key === 'string') {
245
- if (key in dummyShape) {
246
- if (typeof dummyShape[key] === 'function') {
247
- return target[key].bind(target);
248
- }
249
- let propertyShape = getPropertyShapeByLabel(
250
- dummyShape.constructor,
251
- key.toString(),
252
- );
253
- if (propertyShape) {
254
- return propertyShape;
255
- }
256
- throw new Error(
257
- `${this.name}.${key.toString()} is missing a @linkedProperty decorator. This method can only access decorated get/set methods.`,
258
- );
259
- }
260
- }
261
- },
262
- });
263
- return mapFunction(dummyShape.proxy);
264
- }
265
-
266
- static getSetOf<T extends Shape>(
267
- this: {new (...args: any[]): T},
268
- values: Iterable<T | NodeReferenceValue | string>,
269
- ): ShapeSet<T> {
270
- const set = new ShapeSet<T>();
271
- for (const value of values) {
272
- if (value instanceof Shape) {
273
- set.add(value as T);
274
- } else {
275
- const instance = new (this as any)();
276
- instance.id = typeof value === 'string' ? value : value.id;
277
- set.add(instance);
278
- }
279
- }
280
- return set;
281
- }
282
- }
@@ -1,313 +0,0 @@
1
- import {linkedShape} from '../package';
2
- import {literalProperty, objectProperty} from '../shapes/SHACL';
3
- import {Shape} from '../shapes/Shape';
4
- import {xsd} from '../ontologies/xsd';
5
- import {ShapeSet} from '../collections/ShapeSet';
6
- import {getQueryContext} from '../queries/QueryContext';
7
- import {NodeReferenceValue, UpdatePartial} from '../queries/QueryFactory';
8
-
9
- const tmpPropBase = 'linked://tmp/props/';
10
- const tmpTypeBase = 'linked://tmp/types/';
11
- export const tmpEntityBase = 'linked://tmp/entities/';
12
-
13
- const prop = (suffix: string): NodeReferenceValue => ({
14
- id: `${tmpPropBase}${suffix}`,
15
- });
16
- const type = (suffix: string): NodeReferenceValue => ({
17
- id: `${tmpTypeBase}${suffix}`,
18
- });
19
- const entity = (suffix: string): NodeReferenceValue => ({
20
- id: `${tmpEntityBase}${suffix}`,
21
- });
22
-
23
- export const name = prop('name');
24
- export const hobby = prop('hobby');
25
- export const nickName = prop('nickName');
26
- export const bestFriend = prop('bestFriend');
27
- export const hasFriend = prop('hasFriend');
28
- export const birthDate = prop('birthDate');
29
- export const isRealPerson = prop('isRealPerson');
30
- export const hasPet = prop('hasPet');
31
- export const guardDogLevel = prop('guardDogLevel');
32
- export const pluralTestProp = prop('pluralTestProp');
33
- export const personClass = type('Person');
34
- export const petClass = type('Pet');
35
- export const dogClass = type('Dog');
36
-
37
- @linkedShape
38
- export class Pet extends Shape {
39
- static targetClass = petClass;
40
-
41
- @objectProperty({path: bestFriend, maxCount: 1, shape: Pet})
42
- get bestFriend(): Pet {
43
- return null;
44
- }
45
- }
46
-
47
- @linkedShape
48
- export class Dog extends Pet {
49
- static targetClass = dogClass;
50
-
51
- @literalProperty({path: guardDogLevel, maxCount: 1, datatype: xsd.integer})
52
- get guardDogLevel(): number {
53
- return null;
54
- }
55
- }
56
-
57
- @linkedShape
58
- export class Person extends Shape {
59
- static targetClass = personClass;
60
-
61
- @literalProperty({path: name, maxCount: 1})
62
- get name(): string {
63
- return '';
64
- }
65
-
66
- @literalProperty({path: hobby, maxCount: 1})
67
- get hobby(): string {
68
- return '';
69
- }
70
-
71
- @literalProperty({path: nickName})
72
- get nickNames(): string[] {
73
- return [];
74
- }
75
-
76
- @literalProperty({path: birthDate, datatype: xsd.dateTime, maxCount: 1})
77
- get birthDate(): Date {
78
- return null;
79
- }
80
-
81
- @literalProperty({path: isRealPerson, datatype: xsd.boolean, maxCount: 1})
82
- get isRealPerson(): boolean {
83
- return null;
84
- }
85
-
86
- @objectProperty({path: bestFriend, maxCount: 1, shape: Person})
87
- get bestFriend(): Person {
88
- return null;
89
- }
90
-
91
- @objectProperty({path: hasFriend, shape: Person})
92
- get friends(): ShapeSet<Person> {
93
- return null;
94
- }
95
-
96
- @objectProperty({path: hasPet, shape: Pet})
97
- get pets(): ShapeSet<Pet> {
98
- return null;
99
- }
100
-
101
- @objectProperty({path: hasPet, maxCount: 1, shape: Pet})
102
- get firstPet(): Pet {
103
- return null;
104
- }
105
-
106
- @objectProperty({path: pluralTestProp, shape: Person})
107
- get pluralTestProp(): ShapeSet<Person> {
108
- return null;
109
- }
110
- }
111
-
112
- const componentQuery = Person.query((p) => ({name: p.name}));
113
- const componentLike = {query: componentQuery};
114
-
115
- const updateSimple: UpdatePartial<Person> = {hobby: 'Chess'};
116
- const updateOverwriteSet: UpdatePartial<Person> = {friends: [entity('p2')]};
117
- const updateUnsetSingleUndefined: UpdatePartial<Person> = {hobby: undefined};
118
- const updateUnsetSingleNull: UpdatePartial<Person> = {hobby: null};
119
- const updateOverwriteNested: UpdatePartial<Person> = {
120
- bestFriend: {name: 'Bestie'},
121
- };
122
- const updatePassIdReferences: UpdatePartial<Person> = {
123
- bestFriend: entity('p2'),
124
- };
125
- const updateAddRemoveMulti: UpdatePartial<Person> = {
126
- friends: {add: [entity('p2')], remove: [entity('p3')]},
127
- };
128
- const updateRemoveMulti: UpdatePartial<Person> = {
129
- friends: {remove: [entity('p2')]},
130
- };
131
- const updateAddRemoveSame: UpdatePartial<Person> = {
132
- friends: {add: [entity('p2')], remove: [entity('p3')]},
133
- };
134
- const updateUnsetMultiUndefined: UpdatePartial<Person> = {friends: undefined};
135
- const updateNestedWithPredefinedId: UpdatePartial<Person> = {
136
- bestFriend: {id: `${tmpEntityBase}p3-best-friend`, name: 'Bestie'},
137
- };
138
- const updateBirthDate: UpdatePartial<Person> = {
139
- birthDate: new Date('2020-01-01'),
140
- };
141
-
142
- export const queryFactories = {
143
- selectName: () => Person.select((p) => p.name),
144
- selectFriends: () => Person.select((p) => p.friends),
145
- selectBirthDate: () => Person.select((p) => p.birthDate),
146
- selectIsRealPerson: () => Person.select((p) => p.isRealPerson),
147
- selectById: () => Person.select(entity('p1'), (p) => p.name),
148
- selectByIdReference: () => Person.select(entity('p1'), (p) => p.name),
149
- selectNonExisting: () =>
150
- Person.select({id: 'https://does.not/exist'}, (p) => p.name),
151
- selectUndefinedOnly: () =>
152
- Person.select(entity('p3'), (p) => [p.hobby, p.bestFriend]),
153
- selectFriendsName: () => Person.select((p) => p.friends.name),
154
- selectNestedFriendsName: () => Person.select((p) => p.friends.friends.name),
155
- selectMultiplePaths: () =>
156
- Person.select((p) => [p.name, p.friends, p.bestFriend.name]),
157
- selectBestFriendName: () => Person.select((p) => p.bestFriend.name),
158
- selectDeepNested: () =>
159
- Person.select((p) => p.friends.bestFriend.bestFriend.name),
160
- whereFriendsNameEquals: () =>
161
- Person.select((p) => p.friends.where((f) => f.name.equals('Moa'))),
162
- whereBestFriendEquals: () =>
163
- Person.select().where((p) => p.bestFriend.equals(entity('p3'))),
164
- whereHobbyEquals: () =>
165
- Person.select((p) => p.hobby.where((h) => h.equals('Jogging'))),
166
- whereAnd: () =>
167
- Person.select((p) =>
168
- p.friends.where((f) => f.name.equals('Moa').and(f.hobby.equals('Jogging'))),
169
- ),
170
- whereOr: () =>
171
- Person.select((p) =>
172
- p.friends.where((f) => f.name.equals('Jinx').or(f.hobby.equals('Jogging'))),
173
- ),
174
- selectAll: () => Person.select(),
175
- selectWhereNameSemmy: () =>
176
- Person.select().where((p) => p.name.equals('Semmy')),
177
- whereAndOrAnd: () =>
178
- Person.select((p) =>
179
- p.friends.where((f) =>
180
- f.name.equals('Jinx').or(f.hobby.equals('Jogging')).and(f.name.equals('Moa')),
181
- ),
182
- ),
183
- whereAndOrAndNested: () =>
184
- Person.select((p) =>
185
- p.friends.where((f) =>
186
- f.name.equals('Jinx').or(f.hobby.equals('Jogging').and(f.name.equals('Moa'))),
187
- ),
188
- ),
189
- whereSomeImplicit: () =>
190
- Person.select().where((p) => p.friends.name.equals('Moa')),
191
- whereSomeExplicit: () =>
192
- Person.select().where((p) => p.friends.some((f) => f.name.equals('Moa'))),
193
- whereEvery: () =>
194
- Person.select().where((p) =>
195
- p.friends.every((f) => f.name.equals('Moa').or(f.name.equals('Jinx'))),
196
- ),
197
- whereSequences: () =>
198
- Person.select().where((p) =>
199
- p.friends
200
- .some((f) => f.name.equals('Jinx'))
201
- .and(p.name.equals('Semmy')),
202
- ),
203
- outerWhere: () =>
204
- Person.select((p) => p.friends).where((p) => p.name.equals('Semmy')),
205
- whereWithContext: () =>
206
- Person.select((p) => p.name).where((p) =>
207
- p.bestFriend.equals(getQueryContext('user')),
208
- ),
209
- whereWithContextPath: () =>
210
- Person.select((p) => p.name).where((p) => {
211
- const userName = getQueryContext<Person>('user').name;
212
- return p.friends.some((f) => f.name.equals(userName));
213
- }),
214
- countFriends: () => Person.select((p) => p.friends.size()),
215
- countNestedFriends: () => Person.select((p) => p.friends.friends.size()),
216
- countLabel: () =>
217
- Person.select((p) =>
218
- p.friends.select((f) => ({numFriends: f.friends.size()})),
219
- ),
220
- nestedObjectProperty: () => Person.select((p) => p.friends.bestFriend),
221
- nestedObjectPropertySingle: () => Person.select((p) => p.friends.bestFriend),
222
- subSelectSingleProp: () =>
223
- Person.select((p) => p.bestFriend.select((f) => ({name: f.name}))),
224
- subSelectPluralCustom: () =>
225
- Person.select((p) =>
226
- p.friends.select((f) => ({name: f.name, hobby: f.hobby})),
227
- ),
228
- doubleNestedSubSelect: () =>
229
- Person.select((p) =>
230
- p.friends.select((p2) =>
231
- p2.bestFriend.select((p3) => ({name: p3.name})),
232
- ),
233
- ),
234
- subSelectAllPrimitives: () =>
235
- Person.select((p) =>
236
- p.bestFriend.select((f) => [f.name, f.birthDate, f.isRealPerson]),
237
- ),
238
- customResultEqualsBoolean: () =>
239
- Person.select((p) => ({isBestFriend: p.bestFriend.equals(entity('p3'))})),
240
- customResultNumFriends: () =>
241
- Person.select((p) => ({numFriends: p.friends.size()})),
242
- countEquals: () =>
243
- Person.select().where((p) => p.friends.size().equals(2)),
244
- subSelectArray: () =>
245
- Person.select((p) => p.friends.select((f) => [f.name, f.hobby])),
246
- selectShapeSetAs: () =>
247
- Person.select((p) => p.pets.as(Dog).guardDogLevel),
248
- selectNonExistingMultiple: () =>
249
- Person.select((p) => [p.bestFriend, p.friends]),
250
- selectShapeAs: () =>
251
- Person.select((p) => p.firstPet.as(Dog).guardDogLevel),
252
- selectOne: () =>
253
- Person.select((p) => p.name).where((p) => p.equals(entity('p1'))).one(),
254
- nestedQueries2: () =>
255
- Person.select((p) => [
256
- p.friends.select((p2) => [
257
- p2.firstPet,
258
- p2.bestFriend.select((p3) => ({name: p3.name})),
259
- ]),
260
- ]),
261
- selectDuplicatePaths: () =>
262
- Person.select((p) => [
263
- p.bestFriend.name,
264
- p.bestFriend.hobby,
265
- p.bestFriend.isRealPerson,
266
- ]),
267
- outerWhereLimit: () =>
268
- Person.select((p) => p.name)
269
- .where((p) => p.name.equals('Semmy').or(p.name.equals('Moa')))
270
- .limit(1),
271
- sortByAsc: () => Person.select((p) => p.name).sortBy((p) => p.name),
272
- sortByDesc: () =>
273
- Person.select((p) => p.name).sortBy((p) => p.name, 'DESC'),
274
- updateSimple: () => Person.update(entity('p1'), updateSimple),
275
- createSimple: () => Person.create({name: 'Test Create', hobby: 'Chess'}),
276
- createWithFriends: () =>
277
- Person.create({
278
- name: 'Test Create',
279
- friends: [entity('p2'), {name: 'New Friend'}],
280
- }),
281
- createWithFixedId: () =>
282
- Person.create({
283
- __id: `${tmpEntityBase}fixed-id`,
284
- name: 'Fixed',
285
- bestFriend: entity('fixed-id-2'),
286
- } as any),
287
- deleteSingle: () => Person.delete(entity('to-delete')),
288
- deleteSingleRef: () => Person.delete(entity('to-delete')),
289
- deleteMultiple: () =>
290
- Person.delete([entity('to-delete-1'), entity('to-delete-2')]),
291
- deleteMultipleFull: () =>
292
- Person.delete([entity('to-delete-1'), entity('to-delete-2')]),
293
- updateOverwriteSet: () => Person.update(entity('p1'), updateOverwriteSet),
294
- updateUnsetSingleUndefined: () =>
295
- Person.update(entity('p1'), updateUnsetSingleUndefined),
296
- updateUnsetSingleNull: () =>
297
- Person.update(entity('p1'), updateUnsetSingleNull),
298
- updateOverwriteNested: () =>
299
- Person.update(entity('p1'), updateOverwriteNested),
300
- updatePassIdReferences: () =>
301
- Person.update(entity('p1'), updatePassIdReferences),
302
- updateAddRemoveMulti: () =>
303
- Person.update(entity('p1'), updateAddRemoveMulti),
304
- updateRemoveMulti: () => Person.update(entity('p1'), updateRemoveMulti),
305
- updateAddRemoveSame: () => Person.update(entity('p1'), updateAddRemoveSame),
306
- updateUnsetMultiUndefined: () =>
307
- Person.update(entity('p1'), updateUnsetMultiUndefined),
308
- updateNestedWithPredefinedId: () =>
309
- Person.update(entity('p1'), updateNestedWithPredefinedId),
310
- updateBirthDate: () => Person.update(entity('p1'), updateBirthDate),
311
- preloadBestFriend: () =>
312
- Person.select((p) => p.bestFriend.preloadFor(componentLike)),
313
- };