@coasys/ad4m 0.10.1-rc5 → 0.10.1-rc7

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/lib/index.cjs CHANGED
@@ -15991,11 +15991,25 @@ class SubjectEntity {
15991
15991
  const source = query?.source || "ad4m://self";
15992
15992
  let subjectClass = await perspective.stringOrTemplateObjectToSubjectClass(this);
15993
15993
  let res = [];
15994
+ let instanceConditions = `subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)`;
15994
15995
  if (query) {
15996
+ if (query.where) {
15997
+ if (query.where["condition"]) {
15998
+ instanceConditions += ", " + query.where["condition"];
15999
+ }
16000
+ else {
16001
+ const pairs = Object.entries(query.where);
16002
+ for (let p of pairs) {
16003
+ const propertyName = p[0];
16004
+ const propertyValue = p[1];
16005
+ instanceConditions += `, property_getter(C, Base, "${propertyName}", "${propertyValue}")`;
16006
+ }
16007
+ }
16008
+ }
15995
16009
  try {
15996
- const queryResponse = (await perspective.infer(`findall([Timestamp, Base], (subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0];
16010
+ const queryResponse = (await perspective.infer(`findall([Timestamp, Base], (${instanceConditions}), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0];
15997
16011
  if (queryResponse.DataLength >= query.size) {
15998
- const mainQuery = `findall([Timestamp, Base], (subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${query.page}, ${query.size}, PageData).`;
16012
+ const mainQuery = `findall([Timestamp, Base], (${instanceConditions}), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${query.page}, ${query.size}, PageData).`;
15999
16013
  res = await perspective.infer(mainQuery);
16000
16014
  res = res[0].PageData.map(r => ({
16001
16015
  Base: r[1],
@@ -16003,7 +16017,7 @@ class SubjectEntity {
16003
16017
  }));
16004
16018
  }
16005
16019
  else {
16006
- res = await perspective.infer(`subject_class("${subjectClass}", C), instance(C, Base), triple("${source}", Predicate, Base).`);
16020
+ res = await perspective.infer(instanceConditions);
16007
16021
  }
16008
16022
  }
16009
16023
  catch (e) {
@@ -16011,7 +16025,7 @@ class SubjectEntity {
16011
16025
  }
16012
16026
  }
16013
16027
  else {
16014
- res = await perspective.infer(`subject_class("${subjectClass}", C), instance(C, Base), triple("${source}", Predicate, Base).`);
16028
+ res = await perspective.infer(instanceConditions);
16015
16029
  }
16016
16030
  if (!res)
16017
16031
  return [];
package/lib/index.js CHANGED
@@ -15987,11 +15987,25 @@ class SubjectEntity {
15987
15987
  const source = query?.source || "ad4m://self";
15988
15988
  let subjectClass = await perspective.stringOrTemplateObjectToSubjectClass(this);
15989
15989
  let res = [];
15990
+ let instanceConditions = `subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)`;
15990
15991
  if (query) {
15992
+ if (query.where) {
15993
+ if (query.where["condition"]) {
15994
+ instanceConditions += ", " + query.where["condition"];
15995
+ }
15996
+ else {
15997
+ const pairs = Object.entries(query.where);
15998
+ for (let p of pairs) {
15999
+ const propertyName = p[0];
16000
+ const propertyValue = p[1];
16001
+ instanceConditions += `, property_getter(C, Base, "${propertyName}", "${propertyValue}")`;
16002
+ }
16003
+ }
16004
+ }
15991
16005
  try {
15992
- const queryResponse = (await perspective.infer(`findall([Timestamp, Base], (subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0];
16006
+ const queryResponse = (await perspective.infer(`findall([Timestamp, Base], (${instanceConditions}), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0];
15993
16007
  if (queryResponse.DataLength >= query.size) {
15994
- const mainQuery = `findall([Timestamp, Base], (subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${query.page}, ${query.size}, PageData).`;
16008
+ const mainQuery = `findall([Timestamp, Base], (${instanceConditions}), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${query.page}, ${query.size}, PageData).`;
15995
16009
  res = await perspective.infer(mainQuery);
15996
16010
  res = res[0].PageData.map(r => ({
15997
16011
  Base: r[1],
@@ -15999,7 +16013,7 @@ class SubjectEntity {
15999
16013
  }));
16000
16014
  }
16001
16015
  else {
16002
- res = await perspective.infer(`subject_class("${subjectClass}", C), instance(C, Base), triple("${source}", Predicate, Base).`);
16016
+ res = await perspective.infer(instanceConditions);
16003
16017
  }
16004
16018
  }
16005
16019
  catch (e) {
@@ -16007,7 +16021,7 @@ class SubjectEntity {
16007
16021
  }
16008
16022
  }
16009
16023
  else {
16010
- res = await perspective.infer(`subject_class("${subjectClass}", C), instance(C, Base), triple("${source}", Predicate, Base).`);
16024
+ res = await perspective.infer(instanceConditions);
16011
16025
  }
16012
16026
  if (!res)
16013
16027
  return [];
@@ -104,4 +104,7 @@ export type SubjectEntityQueryParam = {
104
104
  source?: string;
105
105
  size?: number;
106
106
  page?: number;
107
+ where?: {
108
+ condition?: string;
109
+ } | object;
107
110
  };
@@ -240,11 +240,25 @@ export class SubjectEntity {
240
240
  const source = query?.source || "ad4m://self";
241
241
  let subjectClass = await perspective.stringOrTemplateObjectToSubjectClass(this);
242
242
  let res = [];
243
+ let instanceConditions = `subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)`;
243
244
  if (query) {
245
+ if (query.where) {
246
+ if (query.where["condition"]) {
247
+ instanceConditions += ", " + query.where["condition"];
248
+ }
249
+ else {
250
+ const pairs = Object.entries(query.where);
251
+ for (let p of pairs) {
252
+ const propertyName = p[0];
253
+ const propertyValue = p[1];
254
+ instanceConditions += `, property_getter(C, Base, "${propertyName}", "${propertyValue}")`;
255
+ }
256
+ }
257
+ }
244
258
  try {
245
- const queryResponse = (await perspective.infer(`findall([Timestamp, Base], (subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0];
259
+ const queryResponse = (await perspective.infer(`findall([Timestamp, Base], (${instanceConditions}), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0];
246
260
  if (queryResponse.DataLength >= query.size) {
247
- const mainQuery = `findall([Timestamp, Base], (subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${query.page}, ${query.size}, PageData).`;
261
+ const mainQuery = `findall([Timestamp, Base], (${instanceConditions}), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${query.page}, ${query.size}, PageData).`;
248
262
  res = await perspective.infer(mainQuery);
249
263
  res = res[0].PageData.map(r => ({
250
264
  Base: r[1],
@@ -252,7 +266,7 @@ export class SubjectEntity {
252
266
  }));
253
267
  }
254
268
  else {
255
- res = await perspective.infer(`subject_class("${subjectClass}", C), instance(C, Base), triple("${source}", Predicate, Base).`);
269
+ res = await perspective.infer(instanceConditions);
256
270
  }
257
271
  }
258
272
  catch (e) {
@@ -260,7 +274,7 @@ export class SubjectEntity {
260
274
  }
261
275
  }
262
276
  else {
263
- res = await perspective.infer(`subject_class("${subjectClass}", C), instance(C, Base), triple("${source}", Predicate, Base).`);
277
+ res = await perspective.infer(instanceConditions);
264
278
  }
265
279
  if (!res)
266
280
  return [];
package/package.json CHANGED
@@ -69,5 +69,5 @@
69
69
  "graphql@15.7.2": "patches/graphql@15.7.2.patch"
70
70
  }
71
71
  },
72
- "version": "0.10.1-rc5"
72
+ "version": "0.10.1-rc7"
73
73
  }
@@ -264,13 +264,27 @@ export class SubjectEntity {
264
264
  let subjectClass = await perspective.stringOrTemplateObjectToSubjectClass(this)
265
265
 
266
266
  let res = [];
267
+ let instanceConditions = `subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)`
268
+
269
+ if (query) {
270
+ if(query.where) {
271
+ if(query.where["condition"]) {
272
+ instanceConditions += ", " + query.where["condition"]
273
+ } else {
274
+ const pairs = Object.entries(query.where);
275
+ for(let p of pairs) {
276
+ const propertyName = p[0];
277
+ const propertyValue = p[1];
278
+ instanceConditions += `, property_getter(C, Base, "${propertyName}", "${propertyValue}")`
279
+ }
280
+ }
281
+ }
267
282
 
268
- if (query) {
269
283
  try {
270
- const queryResponse = (await perspective.infer(`findall([Timestamp, Base], (subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0]
284
+ const queryResponse = (await perspective.infer(`findall([Timestamp, Base], (${instanceConditions}), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0]
271
285
 
272
286
  if (queryResponse.DataLength >= query.size) {
273
- const mainQuery = `findall([Timestamp, Base], (subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${query.page}, ${query.size}, PageData).`
287
+ const mainQuery = `findall([Timestamp, Base], (${instanceConditions}), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${query.page}, ${query.size}, PageData).`
274
288
 
275
289
  res = await perspective.infer(mainQuery);
276
290
 
@@ -279,17 +293,13 @@ export class SubjectEntity {
279
293
  Timestamp: r[0]
280
294
  }))
281
295
  } else {
282
- res = await perspective.infer(
283
- `subject_class("${subjectClass}", C), instance(C, Base), triple("${source}", Predicate, Base).`
284
- );
296
+ res = await perspective.infer(instanceConditions);
285
297
  }
286
298
  } catch (e) {
287
299
  console.log("Query failed", e);
288
300
  }
289
301
  } else {
290
- res = await perspective.infer(
291
- `subject_class("${subjectClass}", C), instance(C, Base), triple("${source}", Predicate, Base).`
292
- );
302
+ res = await perspective.infer(instanceConditions);
293
303
  }
294
304
 
295
305
  if (!res) return [];
@@ -320,4 +330,7 @@ export type SubjectEntityQueryParam = {
320
330
 
321
331
  // The page of the query.
322
332
  page?: number;
333
+
334
+ // conditions on properties
335
+ where?: { condition?: string } | object;
323
336
  }