@coasys/ad4m 0.11.2-dev.4 → 0.11.2-dev.5
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 +48 -12
- package/lib/index.js +48 -12
- package/lib/src/model/Ad4mModel.js +48 -12
- package/package.json +1 -1
- package/src/model/Ad4mModel.ts +50 -13
package/lib/index.cjs
CHANGED
|
@@ -19138,8 +19138,26 @@ class Ad4mModel {
|
|
|
19138
19138
|
}
|
|
19139
19139
|
return [name, finalValue];
|
|
19140
19140
|
})));
|
|
19141
|
+
// Filter out properties that are read-only (getters without setters)
|
|
19142
|
+
const writableProps = Object.fromEntries(Object.entries(propsObject).filter(([key]) => {
|
|
19143
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(instance), key);
|
|
19144
|
+
if (!descriptor) {
|
|
19145
|
+
// No descriptor means it's a regular property on the instance, allow it
|
|
19146
|
+
return true;
|
|
19147
|
+
}
|
|
19148
|
+
// Check if it's an accessor descriptor (has get/set) vs data descriptor (has value/writable)
|
|
19149
|
+
const isAccessor = descriptor.get !== undefined || descriptor.set !== undefined;
|
|
19150
|
+
if (isAccessor) {
|
|
19151
|
+
// Accessor descriptor: only allow if it has a setter
|
|
19152
|
+
return descriptor.set !== undefined;
|
|
19153
|
+
}
|
|
19154
|
+
else {
|
|
19155
|
+
// Data descriptor: only allow if writable is not explicitly false
|
|
19156
|
+
return descriptor.writable !== false;
|
|
19157
|
+
}
|
|
19158
|
+
}));
|
|
19141
19159
|
// Assign properties to instance
|
|
19142
|
-
Object.assign(instance,
|
|
19160
|
+
Object.assign(instance, writableProps);
|
|
19143
19161
|
}
|
|
19144
19162
|
async getData() {
|
|
19145
19163
|
// Builds an object with the author, timestamp, all properties, & all collections on the Ad4mModel and saves it to the instance
|
|
@@ -19258,6 +19276,25 @@ class Ad4mModel {
|
|
|
19258
19276
|
}
|
|
19259
19277
|
// Evaluate SurrealQL getters
|
|
19260
19278
|
await ctor.evaluateSurrealGettersForInstance(this, __classPrivateFieldGet(this, _Ad4mModel_perspective, "f"), metadata);
|
|
19279
|
+
// Apply where.isInstance filtering to surrealGetter collections
|
|
19280
|
+
// (non-surrealGetter collections were already filtered above)
|
|
19281
|
+
for (const [collName, collMeta] of Object.entries(metadata.collections)) {
|
|
19282
|
+
if (collMeta.surrealGetter && collMeta.where?.isInstance && this[collName]?.length > 0) {
|
|
19283
|
+
try {
|
|
19284
|
+
const className = typeof collMeta.where.isInstance === 'string'
|
|
19285
|
+
? collMeta.where.isInstance
|
|
19286
|
+
: collMeta.where.isInstance.name;
|
|
19287
|
+
const filterMetadata = await __classPrivateFieldGet(this, _Ad4mModel_perspective, "f").getSubjectClassMetadataFromSDNA(className);
|
|
19288
|
+
if (filterMetadata) {
|
|
19289
|
+
const filtered = await __classPrivateFieldGet(this, _Ad4mModel_perspective, "f").batchCheckSubjectInstances(this[collName], filterMetadata);
|
|
19290
|
+
this[collName] = filtered;
|
|
19291
|
+
}
|
|
19292
|
+
}
|
|
19293
|
+
catch (error) {
|
|
19294
|
+
// Keep unfiltered values on error
|
|
19295
|
+
}
|
|
19296
|
+
}
|
|
19297
|
+
}
|
|
19261
19298
|
}
|
|
19262
19299
|
catch (e) {
|
|
19263
19300
|
console.error(`SurrealDB getData also failed for ${__classPrivateFieldGet(this, _Ad4mModel_baseExpression, "f")}:`, e);
|
|
@@ -19321,7 +19358,7 @@ class Ad4mModel {
|
|
|
19321
19358
|
// Filter out 'None' from collection results
|
|
19322
19359
|
const value = result[0].value;
|
|
19323
19360
|
instance[collName] = Array.isArray(value)
|
|
19324
|
-
? value.filter((v) => v && v !== '' && v !== 'None')
|
|
19361
|
+
? value.filter((v) => v !== undefined && v !== null && v !== '' && v !== 'None')
|
|
19325
19362
|
: value;
|
|
19326
19363
|
}
|
|
19327
19364
|
}
|
|
@@ -19824,7 +19861,7 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
19824
19861
|
});
|
|
19825
19862
|
}
|
|
19826
19863
|
// Collect values to assign to instance
|
|
19827
|
-
const values = [...Properties, ...Collections, ["
|
|
19864
|
+
const values = [...Properties, ...Collections, ["createdAt", Timestamp], ["author", Author]];
|
|
19828
19865
|
await Ad4mModel.assignValuesToInstance(perspective, instance, values);
|
|
19829
19866
|
return instance;
|
|
19830
19867
|
}
|
|
@@ -20050,7 +20087,7 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
20050
20087
|
// Replace collection with sorted values, filtering out empty strings and None
|
|
20051
20088
|
instance[collName] = pairs
|
|
20052
20089
|
.map(p => p.value)
|
|
20053
|
-
.filter((v) => v && v !== '' && v !== 'None');
|
|
20090
|
+
.filter((v) => v !== undefined && v !== null && v !== '' && v !== 'None');
|
|
20054
20091
|
// Clean up temporary arrays
|
|
20055
20092
|
delete instance[timestampsKey];
|
|
20056
20093
|
delete instance[indicesKey];
|
|
@@ -20060,8 +20097,9 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
20060
20097
|
if (requestedProperties.length > 0 || requestedCollections.length > 0) {
|
|
20061
20098
|
const requestedAttributes = [...requestedProperties, ...requestedCollections];
|
|
20062
20099
|
Object.keys(instance).forEach((key) => {
|
|
20063
|
-
// Keep only requested attributes, plus always keep
|
|
20064
|
-
|
|
20100
|
+
// Keep only requested attributes, plus always keep createdAt, updatedAt, author, and baseExpression
|
|
20101
|
+
// Note: timestamp is a getter alias for createdAt, so we preserve createdAt instead
|
|
20102
|
+
if (!requestedAttributes.includes(key) && key !== 'createdAt' && key !== 'updatedAt' && key !== 'author' && key !== 'baseExpression') {
|
|
20065
20103
|
delete instance[key];
|
|
20066
20104
|
}
|
|
20067
20105
|
});
|
|
@@ -20072,12 +20110,13 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
20072
20110
|
console.error(`Failed to process SurrealDB instance ${base}:`, error);
|
|
20073
20111
|
}
|
|
20074
20112
|
}
|
|
20075
|
-
// Evaluate SurrealQL getters for all instances
|
|
20113
|
+
// Evaluate SurrealQL getters for all instances (single pass)
|
|
20114
|
+
// This populates collection values needed for where.isInstance filtering
|
|
20076
20115
|
for (const instance of instances) {
|
|
20077
20116
|
await this.evaluateSurrealGettersForInstance(instance, perspective, metadata);
|
|
20078
20117
|
}
|
|
20079
20118
|
// Filter collections by where.isInstance if specified
|
|
20080
|
-
// Do this
|
|
20119
|
+
// Do this after initial evaluation so collection values exist for filtering
|
|
20081
20120
|
for (const instance of instances) {
|
|
20082
20121
|
for (const [collName, collMeta] of Object.entries(metadata.collections)) {
|
|
20083
20122
|
if (collMeta.where?.isInstance && instance[collName]?.length > 0) {
|
|
@@ -20094,6 +20133,7 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
20094
20133
|
}
|
|
20095
20134
|
// Check which subjects are instances of the target class
|
|
20096
20135
|
const validSubjects = await perspective.batchCheckSubjectInstances(subjects, classMetadata);
|
|
20136
|
+
// Update the collection with filtered instances
|
|
20097
20137
|
instance[collName] = validSubjects;
|
|
20098
20138
|
}
|
|
20099
20139
|
catch (error) {
|
|
@@ -20102,10 +20142,6 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
20102
20142
|
}
|
|
20103
20143
|
}
|
|
20104
20144
|
}
|
|
20105
|
-
// Evaluate SurrealQL getters for all instances
|
|
20106
|
-
for (const instance of instances) {
|
|
20107
|
-
await this.evaluateSurrealGettersForInstance(instance, perspective, metadata);
|
|
20108
|
-
}
|
|
20109
20145
|
// Filter by where conditions that couldn't be filtered in SQL
|
|
20110
20146
|
// This includes:
|
|
20111
20147
|
// - author/timestamp (computed from grouped links)
|
package/lib/index.js
CHANGED
|
@@ -19134,8 +19134,26 @@ class Ad4mModel {
|
|
|
19134
19134
|
}
|
|
19135
19135
|
return [name, finalValue];
|
|
19136
19136
|
})));
|
|
19137
|
+
// Filter out properties that are read-only (getters without setters)
|
|
19138
|
+
const writableProps = Object.fromEntries(Object.entries(propsObject).filter(([key]) => {
|
|
19139
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(instance), key);
|
|
19140
|
+
if (!descriptor) {
|
|
19141
|
+
// No descriptor means it's a regular property on the instance, allow it
|
|
19142
|
+
return true;
|
|
19143
|
+
}
|
|
19144
|
+
// Check if it's an accessor descriptor (has get/set) vs data descriptor (has value/writable)
|
|
19145
|
+
const isAccessor = descriptor.get !== undefined || descriptor.set !== undefined;
|
|
19146
|
+
if (isAccessor) {
|
|
19147
|
+
// Accessor descriptor: only allow if it has a setter
|
|
19148
|
+
return descriptor.set !== undefined;
|
|
19149
|
+
}
|
|
19150
|
+
else {
|
|
19151
|
+
// Data descriptor: only allow if writable is not explicitly false
|
|
19152
|
+
return descriptor.writable !== false;
|
|
19153
|
+
}
|
|
19154
|
+
}));
|
|
19137
19155
|
// Assign properties to instance
|
|
19138
|
-
Object.assign(instance,
|
|
19156
|
+
Object.assign(instance, writableProps);
|
|
19139
19157
|
}
|
|
19140
19158
|
async getData() {
|
|
19141
19159
|
// Builds an object with the author, timestamp, all properties, & all collections on the Ad4mModel and saves it to the instance
|
|
@@ -19254,6 +19272,25 @@ class Ad4mModel {
|
|
|
19254
19272
|
}
|
|
19255
19273
|
// Evaluate SurrealQL getters
|
|
19256
19274
|
await ctor.evaluateSurrealGettersForInstance(this, __classPrivateFieldGet(this, _Ad4mModel_perspective, "f"), metadata);
|
|
19275
|
+
// Apply where.isInstance filtering to surrealGetter collections
|
|
19276
|
+
// (non-surrealGetter collections were already filtered above)
|
|
19277
|
+
for (const [collName, collMeta] of Object.entries(metadata.collections)) {
|
|
19278
|
+
if (collMeta.surrealGetter && collMeta.where?.isInstance && this[collName]?.length > 0) {
|
|
19279
|
+
try {
|
|
19280
|
+
const className = typeof collMeta.where.isInstance === 'string'
|
|
19281
|
+
? collMeta.where.isInstance
|
|
19282
|
+
: collMeta.where.isInstance.name;
|
|
19283
|
+
const filterMetadata = await __classPrivateFieldGet(this, _Ad4mModel_perspective, "f").getSubjectClassMetadataFromSDNA(className);
|
|
19284
|
+
if (filterMetadata) {
|
|
19285
|
+
const filtered = await __classPrivateFieldGet(this, _Ad4mModel_perspective, "f").batchCheckSubjectInstances(this[collName], filterMetadata);
|
|
19286
|
+
this[collName] = filtered;
|
|
19287
|
+
}
|
|
19288
|
+
}
|
|
19289
|
+
catch (error) {
|
|
19290
|
+
// Keep unfiltered values on error
|
|
19291
|
+
}
|
|
19292
|
+
}
|
|
19293
|
+
}
|
|
19257
19294
|
}
|
|
19258
19295
|
catch (e) {
|
|
19259
19296
|
console.error(`SurrealDB getData also failed for ${__classPrivateFieldGet(this, _Ad4mModel_baseExpression, "f")}:`, e);
|
|
@@ -19317,7 +19354,7 @@ class Ad4mModel {
|
|
|
19317
19354
|
// Filter out 'None' from collection results
|
|
19318
19355
|
const value = result[0].value;
|
|
19319
19356
|
instance[collName] = Array.isArray(value)
|
|
19320
|
-
? value.filter((v) => v && v !== '' && v !== 'None')
|
|
19357
|
+
? value.filter((v) => v !== undefined && v !== null && v !== '' && v !== 'None')
|
|
19321
19358
|
: value;
|
|
19322
19359
|
}
|
|
19323
19360
|
}
|
|
@@ -19820,7 +19857,7 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
19820
19857
|
});
|
|
19821
19858
|
}
|
|
19822
19859
|
// Collect values to assign to instance
|
|
19823
|
-
const values = [...Properties, ...Collections, ["
|
|
19860
|
+
const values = [...Properties, ...Collections, ["createdAt", Timestamp], ["author", Author]];
|
|
19824
19861
|
await Ad4mModel.assignValuesToInstance(perspective, instance, values);
|
|
19825
19862
|
return instance;
|
|
19826
19863
|
}
|
|
@@ -20046,7 +20083,7 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
20046
20083
|
// Replace collection with sorted values, filtering out empty strings and None
|
|
20047
20084
|
instance[collName] = pairs
|
|
20048
20085
|
.map(p => p.value)
|
|
20049
|
-
.filter((v) => v && v !== '' && v !== 'None');
|
|
20086
|
+
.filter((v) => v !== undefined && v !== null && v !== '' && v !== 'None');
|
|
20050
20087
|
// Clean up temporary arrays
|
|
20051
20088
|
delete instance[timestampsKey];
|
|
20052
20089
|
delete instance[indicesKey];
|
|
@@ -20056,8 +20093,9 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
20056
20093
|
if (requestedProperties.length > 0 || requestedCollections.length > 0) {
|
|
20057
20094
|
const requestedAttributes = [...requestedProperties, ...requestedCollections];
|
|
20058
20095
|
Object.keys(instance).forEach((key) => {
|
|
20059
|
-
// Keep only requested attributes, plus always keep
|
|
20060
|
-
|
|
20096
|
+
// Keep only requested attributes, plus always keep createdAt, updatedAt, author, and baseExpression
|
|
20097
|
+
// Note: timestamp is a getter alias for createdAt, so we preserve createdAt instead
|
|
20098
|
+
if (!requestedAttributes.includes(key) && key !== 'createdAt' && key !== 'updatedAt' && key !== 'author' && key !== 'baseExpression') {
|
|
20061
20099
|
delete instance[key];
|
|
20062
20100
|
}
|
|
20063
20101
|
});
|
|
@@ -20068,12 +20106,13 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
20068
20106
|
console.error(`Failed to process SurrealDB instance ${base}:`, error);
|
|
20069
20107
|
}
|
|
20070
20108
|
}
|
|
20071
|
-
// Evaluate SurrealQL getters for all instances
|
|
20109
|
+
// Evaluate SurrealQL getters for all instances (single pass)
|
|
20110
|
+
// This populates collection values needed for where.isInstance filtering
|
|
20072
20111
|
for (const instance of instances) {
|
|
20073
20112
|
await this.evaluateSurrealGettersForInstance(instance, perspective, metadata);
|
|
20074
20113
|
}
|
|
20075
20114
|
// Filter collections by where.isInstance if specified
|
|
20076
|
-
// Do this
|
|
20115
|
+
// Do this after initial evaluation so collection values exist for filtering
|
|
20077
20116
|
for (const instance of instances) {
|
|
20078
20117
|
for (const [collName, collMeta] of Object.entries(metadata.collections)) {
|
|
20079
20118
|
if (collMeta.where?.isInstance && instance[collName]?.length > 0) {
|
|
@@ -20090,6 +20129,7 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
20090
20129
|
}
|
|
20091
20130
|
// Check which subjects are instances of the target class
|
|
20092
20131
|
const validSubjects = await perspective.batchCheckSubjectInstances(subjects, classMetadata);
|
|
20132
|
+
// Update the collection with filtered instances
|
|
20093
20133
|
instance[collName] = validSubjects;
|
|
20094
20134
|
}
|
|
20095
20135
|
catch (error) {
|
|
@@ -20098,10 +20138,6 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
20098
20138
|
}
|
|
20099
20139
|
}
|
|
20100
20140
|
}
|
|
20101
|
-
// Evaluate SurrealQL getters for all instances
|
|
20102
|
-
for (const instance of instances) {
|
|
20103
|
-
await this.evaluateSurrealGettersForInstance(instance, perspective, metadata);
|
|
20104
|
-
}
|
|
20105
20141
|
// Filter by where conditions that couldn't be filtered in SQL
|
|
20106
20142
|
// This includes:
|
|
20107
20143
|
// - author/timestamp (computed from grouped links)
|
|
@@ -589,8 +589,26 @@ export class Ad4mModel {
|
|
|
589
589
|
}
|
|
590
590
|
return [name, finalValue];
|
|
591
591
|
})));
|
|
592
|
+
// Filter out properties that are read-only (getters without setters)
|
|
593
|
+
const writableProps = Object.fromEntries(Object.entries(propsObject).filter(([key]) => {
|
|
594
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(instance), key);
|
|
595
|
+
if (!descriptor) {
|
|
596
|
+
// No descriptor means it's a regular property on the instance, allow it
|
|
597
|
+
return true;
|
|
598
|
+
}
|
|
599
|
+
// Check if it's an accessor descriptor (has get/set) vs data descriptor (has value/writable)
|
|
600
|
+
const isAccessor = descriptor.get !== undefined || descriptor.set !== undefined;
|
|
601
|
+
if (isAccessor) {
|
|
602
|
+
// Accessor descriptor: only allow if it has a setter
|
|
603
|
+
return descriptor.set !== undefined;
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
// Data descriptor: only allow if writable is not explicitly false
|
|
607
|
+
return descriptor.writable !== false;
|
|
608
|
+
}
|
|
609
|
+
}));
|
|
592
610
|
// Assign properties to instance
|
|
593
|
-
Object.assign(instance,
|
|
611
|
+
Object.assign(instance, writableProps);
|
|
594
612
|
}
|
|
595
613
|
async getData() {
|
|
596
614
|
// Builds an object with the author, timestamp, all properties, & all collections on the Ad4mModel and saves it to the instance
|
|
@@ -709,6 +727,25 @@ export class Ad4mModel {
|
|
|
709
727
|
}
|
|
710
728
|
// Evaluate SurrealQL getters
|
|
711
729
|
await ctor.evaluateSurrealGettersForInstance(this, __classPrivateFieldGet(this, _Ad4mModel_perspective, "f"), metadata);
|
|
730
|
+
// Apply where.isInstance filtering to surrealGetter collections
|
|
731
|
+
// (non-surrealGetter collections were already filtered above)
|
|
732
|
+
for (const [collName, collMeta] of Object.entries(metadata.collections)) {
|
|
733
|
+
if (collMeta.surrealGetter && collMeta.where?.isInstance && this[collName]?.length > 0) {
|
|
734
|
+
try {
|
|
735
|
+
const className = typeof collMeta.where.isInstance === 'string'
|
|
736
|
+
? collMeta.where.isInstance
|
|
737
|
+
: collMeta.where.isInstance.name;
|
|
738
|
+
const filterMetadata = await __classPrivateFieldGet(this, _Ad4mModel_perspective, "f").getSubjectClassMetadataFromSDNA(className);
|
|
739
|
+
if (filterMetadata) {
|
|
740
|
+
const filtered = await __classPrivateFieldGet(this, _Ad4mModel_perspective, "f").batchCheckSubjectInstances(this[collName], filterMetadata);
|
|
741
|
+
this[collName] = filtered;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
catch (error) {
|
|
745
|
+
// Keep unfiltered values on error
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
712
749
|
}
|
|
713
750
|
catch (e) {
|
|
714
751
|
console.error(`SurrealDB getData also failed for ${__classPrivateFieldGet(this, _Ad4mModel_baseExpression, "f")}:`, e);
|
|
@@ -772,7 +809,7 @@ export class Ad4mModel {
|
|
|
772
809
|
// Filter out 'None' from collection results
|
|
773
810
|
const value = result[0].value;
|
|
774
811
|
instance[collName] = Array.isArray(value)
|
|
775
|
-
? value.filter((v) => v && v !== '' && v !== 'None')
|
|
812
|
+
? value.filter((v) => v !== undefined && v !== null && v !== '' && v !== 'None')
|
|
776
813
|
: value;
|
|
777
814
|
}
|
|
778
815
|
}
|
|
@@ -1275,7 +1312,7 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1275
1312
|
});
|
|
1276
1313
|
}
|
|
1277
1314
|
// Collect values to assign to instance
|
|
1278
|
-
const values = [...Properties, ...Collections, ["
|
|
1315
|
+
const values = [...Properties, ...Collections, ["createdAt", Timestamp], ["author", Author]];
|
|
1279
1316
|
await Ad4mModel.assignValuesToInstance(perspective, instance, values);
|
|
1280
1317
|
return instance;
|
|
1281
1318
|
}
|
|
@@ -1501,7 +1538,7 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1501
1538
|
// Replace collection with sorted values, filtering out empty strings and None
|
|
1502
1539
|
instance[collName] = pairs
|
|
1503
1540
|
.map(p => p.value)
|
|
1504
|
-
.filter((v) => v && v !== '' && v !== 'None');
|
|
1541
|
+
.filter((v) => v !== undefined && v !== null && v !== '' && v !== 'None');
|
|
1505
1542
|
// Clean up temporary arrays
|
|
1506
1543
|
delete instance[timestampsKey];
|
|
1507
1544
|
delete instance[indicesKey];
|
|
@@ -1511,8 +1548,9 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1511
1548
|
if (requestedProperties.length > 0 || requestedCollections.length > 0) {
|
|
1512
1549
|
const requestedAttributes = [...requestedProperties, ...requestedCollections];
|
|
1513
1550
|
Object.keys(instance).forEach((key) => {
|
|
1514
|
-
// Keep only requested attributes, plus always keep
|
|
1515
|
-
|
|
1551
|
+
// Keep only requested attributes, plus always keep createdAt, updatedAt, author, and baseExpression
|
|
1552
|
+
// Note: timestamp is a getter alias for createdAt, so we preserve createdAt instead
|
|
1553
|
+
if (!requestedAttributes.includes(key) && key !== 'createdAt' && key !== 'updatedAt' && key !== 'author' && key !== 'baseExpression') {
|
|
1516
1554
|
delete instance[key];
|
|
1517
1555
|
}
|
|
1518
1556
|
});
|
|
@@ -1523,12 +1561,13 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1523
1561
|
console.error(`Failed to process SurrealDB instance ${base}:`, error);
|
|
1524
1562
|
}
|
|
1525
1563
|
}
|
|
1526
|
-
// Evaluate SurrealQL getters for all instances
|
|
1564
|
+
// Evaluate SurrealQL getters for all instances (single pass)
|
|
1565
|
+
// This populates collection values needed for where.isInstance filtering
|
|
1527
1566
|
for (const instance of instances) {
|
|
1528
1567
|
await this.evaluateSurrealGettersForInstance(instance, perspective, metadata);
|
|
1529
1568
|
}
|
|
1530
1569
|
// Filter collections by where.isInstance if specified
|
|
1531
|
-
// Do this
|
|
1570
|
+
// Do this after initial evaluation so collection values exist for filtering
|
|
1532
1571
|
for (const instance of instances) {
|
|
1533
1572
|
for (const [collName, collMeta] of Object.entries(metadata.collections)) {
|
|
1534
1573
|
if (collMeta.where?.isInstance && instance[collName]?.length > 0) {
|
|
@@ -1545,6 +1584,7 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1545
1584
|
}
|
|
1546
1585
|
// Check which subjects are instances of the target class
|
|
1547
1586
|
const validSubjects = await perspective.batchCheckSubjectInstances(subjects, classMetadata);
|
|
1587
|
+
// Update the collection with filtered instances
|
|
1548
1588
|
instance[collName] = validSubjects;
|
|
1549
1589
|
}
|
|
1550
1590
|
catch (error) {
|
|
@@ -1553,10 +1593,6 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1553
1593
|
}
|
|
1554
1594
|
}
|
|
1555
1595
|
}
|
|
1556
|
-
// Evaluate SurrealQL getters for all instances
|
|
1557
|
-
for (const instance of instances) {
|
|
1558
|
-
await this.evaluateSurrealGettersForInstance(instance, perspective, metadata);
|
|
1559
|
-
}
|
|
1560
1596
|
// Filter by where conditions that couldn't be filtered in SQL
|
|
1561
1597
|
// This includes:
|
|
1562
1598
|
// - author/timestamp (computed from grouped links)
|
package/package.json
CHANGED
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"react-dom": "*"
|
|
58
58
|
},
|
|
59
59
|
"patchedDependencies": {},
|
|
60
|
-
"version": "0.11.2-dev.
|
|
60
|
+
"version": "0.11.2-dev.5",
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "patch-package && tsc && pnpm run buildSchema && pnpm run bundle",
|
|
63
63
|
"buildSchema": "node --es-module-specifier-resolution=node lib/src/buildSchema.js",
|
package/src/model/Ad4mModel.ts
CHANGED
|
@@ -758,8 +758,27 @@ export class Ad4mModel {
|
|
|
758
758
|
})
|
|
759
759
|
)
|
|
760
760
|
);
|
|
761
|
+
// Filter out properties that are read-only (getters without setters)
|
|
762
|
+
const writableProps = Object.fromEntries(
|
|
763
|
+
Object.entries(propsObject).filter(([key]) => {
|
|
764
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(instance), key);
|
|
765
|
+
if (!descriptor) {
|
|
766
|
+
// No descriptor means it's a regular property on the instance, allow it
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
// Check if it's an accessor descriptor (has get/set) vs data descriptor (has value/writable)
|
|
770
|
+
const isAccessor = descriptor.get !== undefined || descriptor.set !== undefined;
|
|
771
|
+
if (isAccessor) {
|
|
772
|
+
// Accessor descriptor: only allow if it has a setter
|
|
773
|
+
return descriptor.set !== undefined;
|
|
774
|
+
} else {
|
|
775
|
+
// Data descriptor: only allow if writable is not explicitly false
|
|
776
|
+
return descriptor.writable !== false;
|
|
777
|
+
}
|
|
778
|
+
})
|
|
779
|
+
);
|
|
761
780
|
// Assign properties to instance
|
|
762
|
-
Object.assign(instance,
|
|
781
|
+
Object.assign(instance, writableProps);
|
|
763
782
|
}
|
|
764
783
|
|
|
765
784
|
private async getData() {
|
|
@@ -885,6 +904,26 @@ export class Ad4mModel {
|
|
|
885
904
|
|
|
886
905
|
// Evaluate SurrealQL getters
|
|
887
906
|
await ctor.evaluateSurrealGettersForInstance(this, this.#perspective, metadata);
|
|
907
|
+
|
|
908
|
+
// Apply where.isInstance filtering to surrealGetter collections
|
|
909
|
+
// (non-surrealGetter collections were already filtered above)
|
|
910
|
+
for (const [collName, collMeta] of Object.entries(metadata.collections)) {
|
|
911
|
+
if (collMeta.surrealGetter && collMeta.where?.isInstance && (this as any)[collName]?.length > 0) {
|
|
912
|
+
try {
|
|
913
|
+
const className = typeof collMeta.where.isInstance === 'string'
|
|
914
|
+
? collMeta.where.isInstance
|
|
915
|
+
: collMeta.where.isInstance.name;
|
|
916
|
+
|
|
917
|
+
const filterMetadata = await this.#perspective.getSubjectClassMetadataFromSDNA(className);
|
|
918
|
+
if (filterMetadata) {
|
|
919
|
+
const filtered = await this.#perspective.batchCheckSubjectInstances((this as any)[collName], filterMetadata);
|
|
920
|
+
(this as any)[collName] = filtered;
|
|
921
|
+
}
|
|
922
|
+
} catch (error) {
|
|
923
|
+
// Keep unfiltered values on error
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
888
927
|
} catch (e) {
|
|
889
928
|
console.error(`SurrealDB getData also failed for ${this.#baseExpression}:`, e);
|
|
890
929
|
}
|
|
@@ -963,7 +1002,7 @@ export class Ad4mModel {
|
|
|
963
1002
|
// Filter out 'None' from collection results
|
|
964
1003
|
const value = result[0].value;
|
|
965
1004
|
instance[collName] = Array.isArray(value)
|
|
966
|
-
? value.filter((v: any) => v && v !== '' && v !== 'None')
|
|
1005
|
+
? value.filter((v: any) => v !== undefined && v !== null && v !== '' && v !== 'None')
|
|
967
1006
|
: value;
|
|
968
1007
|
}
|
|
969
1008
|
} catch (error) {
|
|
@@ -1499,7 +1538,7 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1499
1538
|
});
|
|
1500
1539
|
}
|
|
1501
1540
|
// Collect values to assign to instance
|
|
1502
|
-
const values = [...Properties, ...Collections, ["
|
|
1541
|
+
const values = [...Properties, ...Collections, ["createdAt", Timestamp], ["author", Author]];
|
|
1503
1542
|
await Ad4mModel.assignValuesToInstance(perspective, instance, values);
|
|
1504
1543
|
|
|
1505
1544
|
return instance;
|
|
@@ -1735,7 +1774,7 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1735
1774
|
// Replace collection with sorted values, filtering out empty strings and None
|
|
1736
1775
|
instance[collName] = pairs
|
|
1737
1776
|
.map(p => p.value)
|
|
1738
|
-
.filter((v: any) => v && v !== '' && v !== 'None');
|
|
1777
|
+
.filter((v: any) => v !== undefined && v !== null && v !== '' && v !== 'None');
|
|
1739
1778
|
// Clean up temporary arrays
|
|
1740
1779
|
delete instance[timestampsKey];
|
|
1741
1780
|
delete instance[indicesKey];
|
|
@@ -1746,8 +1785,9 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1746
1785
|
if (requestedProperties.length > 0 || requestedCollections.length > 0) {
|
|
1747
1786
|
const requestedAttributes = [...requestedProperties, ...requestedCollections];
|
|
1748
1787
|
Object.keys(instance).forEach((key) => {
|
|
1749
|
-
// Keep only requested attributes, plus always keep
|
|
1750
|
-
|
|
1788
|
+
// Keep only requested attributes, plus always keep createdAt, updatedAt, author, and baseExpression
|
|
1789
|
+
// Note: timestamp is a getter alias for createdAt, so we preserve createdAt instead
|
|
1790
|
+
if (!requestedAttributes.includes(key) && key !== 'createdAt' && key !== 'updatedAt' && key !== 'author' && key !== 'baseExpression') {
|
|
1751
1791
|
delete instance[key];
|
|
1752
1792
|
}
|
|
1753
1793
|
});
|
|
@@ -1759,13 +1799,14 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1759
1799
|
}
|
|
1760
1800
|
}
|
|
1761
1801
|
|
|
1762
|
-
// Evaluate SurrealQL getters for all instances
|
|
1802
|
+
// Evaluate SurrealQL getters for all instances (single pass)
|
|
1803
|
+
// This populates collection values needed for where.isInstance filtering
|
|
1763
1804
|
for (const instance of instances) {
|
|
1764
1805
|
await this.evaluateSurrealGettersForInstance(instance, perspective, metadata);
|
|
1765
1806
|
}
|
|
1766
1807
|
|
|
1767
1808
|
// Filter collections by where.isInstance if specified
|
|
1768
|
-
// Do this
|
|
1809
|
+
// Do this after initial evaluation so collection values exist for filtering
|
|
1769
1810
|
for (const instance of instances) {
|
|
1770
1811
|
for (const [collName, collMeta] of Object.entries(metadata.collections)) {
|
|
1771
1812
|
if (collMeta.where?.isInstance && instance[collName]?.length > 0) {
|
|
@@ -1786,6 +1827,7 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1786
1827
|
// Check which subjects are instances of the target class
|
|
1787
1828
|
const validSubjects = await perspective.batchCheckSubjectInstances(subjects, classMetadata);
|
|
1788
1829
|
|
|
1830
|
+
// Update the collection with filtered instances
|
|
1789
1831
|
instance[collName] = validSubjects;
|
|
1790
1832
|
} catch (error) {
|
|
1791
1833
|
// On error, leave the collection unfiltered rather than breaking everything
|
|
@@ -1794,11 +1836,6 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1794
1836
|
}
|
|
1795
1837
|
}
|
|
1796
1838
|
|
|
1797
|
-
// Evaluate SurrealQL getters for all instances
|
|
1798
|
-
for (const instance of instances) {
|
|
1799
|
-
await this.evaluateSurrealGettersForInstance(instance, perspective, metadata);
|
|
1800
|
-
}
|
|
1801
|
-
|
|
1802
1839
|
// Filter by where conditions that couldn't be filtered in SQL
|
|
1803
1840
|
// This includes:
|
|
1804
1841
|
// - author/timestamp (computed from grouped links)
|