@coasys/ad4m 0.11.2-dev.3 → 0.11.2-dev.4
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 +67 -25
- package/lib/index.js +67 -25
- package/lib/src/model/Ad4mModel.d.ts +7 -1
- package/lib/src/model/Ad4mModel.js +67 -25
- package/package.json +1 -1
- package/src/model/Ad4mModel.ts +70 -26
package/lib/index.cjs
CHANGED
|
@@ -18855,6 +18855,13 @@ class Ad4mModel {
|
|
|
18855
18855
|
}
|
|
18856
18856
|
return classCache[perspectiveID];
|
|
18857
18857
|
}
|
|
18858
|
+
/**
|
|
18859
|
+
* Backwards compatibility alias for createdAt.
|
|
18860
|
+
* @deprecated Use createdAt instead. This will be removed in a future version.
|
|
18861
|
+
*/
|
|
18862
|
+
get timestamp() {
|
|
18863
|
+
return this.createdAt;
|
|
18864
|
+
}
|
|
18858
18865
|
/**
|
|
18859
18866
|
* Extracts metadata from decorators for query building.
|
|
18860
18867
|
*
|
|
@@ -19154,8 +19161,10 @@ class Ad4mModel {
|
|
|
19154
19161
|
`;
|
|
19155
19162
|
const links = await __classPrivateFieldGet(this, _Ad4mModel_perspective, "f").querySurrealDB(linksQuery);
|
|
19156
19163
|
if (links && links.length > 0) {
|
|
19164
|
+
let minTimestamp = null;
|
|
19157
19165
|
let maxTimestamp = null;
|
|
19158
19166
|
let latestAuthor = null;
|
|
19167
|
+
let originalAuthor = null;
|
|
19159
19168
|
// Process properties (skip those with surrealGetter)
|
|
19160
19169
|
for (const [propName, propMeta] of Object.entries(metadata.properties)) {
|
|
19161
19170
|
if (propMeta.surrealGetter)
|
|
@@ -19166,10 +19175,16 @@ class Ad4mModel {
|
|
|
19166
19175
|
// The last element has the most recent timestamp and represents the current property value.
|
|
19167
19176
|
const link = matching[matching.length - 1];
|
|
19168
19177
|
let value = link.target;
|
|
19169
|
-
// Track
|
|
19170
|
-
if (link.timestamp
|
|
19171
|
-
|
|
19172
|
-
|
|
19178
|
+
// Track timestamps/authors for createdAt and updatedAt
|
|
19179
|
+
if (link.timestamp) {
|
|
19180
|
+
if (!minTimestamp || link.timestamp < minTimestamp) {
|
|
19181
|
+
minTimestamp = link.timestamp;
|
|
19182
|
+
originalAuthor = link.author;
|
|
19183
|
+
}
|
|
19184
|
+
if (!maxTimestamp || link.timestamp > maxTimestamp) {
|
|
19185
|
+
maxTimestamp = link.timestamp;
|
|
19186
|
+
latestAuthor = link.author;
|
|
19187
|
+
}
|
|
19173
19188
|
}
|
|
19174
19189
|
// Handle resolveLanguage
|
|
19175
19190
|
if (propMeta.resolveLanguage && propMeta.resolveLanguage !== 'literal') {
|
|
@@ -19230,12 +19245,15 @@ class Ad4mModel {
|
|
|
19230
19245
|
}
|
|
19231
19246
|
this[collName] = values;
|
|
19232
19247
|
}
|
|
19233
|
-
// Set author and
|
|
19234
|
-
if (
|
|
19235
|
-
this.author =
|
|
19248
|
+
// Set author and timestamps
|
|
19249
|
+
if (originalAuthor) {
|
|
19250
|
+
this.author = originalAuthor;
|
|
19251
|
+
}
|
|
19252
|
+
if (minTimestamp) {
|
|
19253
|
+
this.createdAt = minTimestamp;
|
|
19236
19254
|
}
|
|
19237
19255
|
if (maxTimestamp) {
|
|
19238
|
-
this.
|
|
19256
|
+
this.updatedAt = maxTimestamp;
|
|
19239
19257
|
}
|
|
19240
19258
|
}
|
|
19241
19259
|
// Evaluate SurrealQL getters
|
|
@@ -19715,8 +19733,9 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
19715
19733
|
fields.push(`(SELECT VALUE target FROM link WHERE source = source AND predicate = '${escapedPredicate}') AS ${collName}`);
|
|
19716
19734
|
}
|
|
19717
19735
|
// Always add author and timestamp fields
|
|
19718
|
-
fields.push(`(SELECT VALUE author FROM link WHERE source = source LIMIT 1) AS author`);
|
|
19719
|
-
fields.push(`(SELECT VALUE timestamp FROM link WHERE source = source LIMIT 1) AS
|
|
19736
|
+
fields.push(`(SELECT VALUE author FROM link WHERE source = source ORDER BY timestamp ASC LIMIT 1) AS author`);
|
|
19737
|
+
fields.push(`(SELECT VALUE timestamp FROM link WHERE source = source ORDER BY timestamp ASC LIMIT 1) AS createdAt`);
|
|
19738
|
+
fields.push(`(SELECT VALUE timestamp FROM link WHERE source = source ORDER BY timestamp DESC LIMIT 1) AS updatedAt`);
|
|
19720
19739
|
return fields.join(',\n ');
|
|
19721
19740
|
}
|
|
19722
19741
|
/**
|
|
@@ -19747,9 +19766,10 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
19747
19766
|
const escapedPredicate = escapeSurrealString(collMeta.predicate);
|
|
19748
19767
|
fields.push(`target[WHERE predicate = '${escapedPredicate}'] AS ${collName}`);
|
|
19749
19768
|
}
|
|
19750
|
-
// Always add author and timestamp fields
|
|
19769
|
+
// Always add author and timestamp fields
|
|
19751
19770
|
fields.push(`array::first(author) AS author`);
|
|
19752
|
-
fields.push(`array::first(timestamp) AS
|
|
19771
|
+
fields.push(`array::first(timestamp) AS createdAt`);
|
|
19772
|
+
fields.push(`array::last(timestamp) AS updatedAt`);
|
|
19753
19773
|
return fields.join(',\n ');
|
|
19754
19774
|
}
|
|
19755
19775
|
/**
|
|
@@ -19848,8 +19868,10 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
19848
19868
|
}
|
|
19849
19869
|
const links = row.links || [];
|
|
19850
19870
|
const instance = new this(perspective, base);
|
|
19851
|
-
// Track
|
|
19871
|
+
// Track both earliest (createdAt) and most recent (updatedAt) timestamps
|
|
19872
|
+
let minTimestamp = null;
|
|
19852
19873
|
let maxTimestamp = null;
|
|
19874
|
+
let originalAuthor = null;
|
|
19853
19875
|
let latestAuthor = null;
|
|
19854
19876
|
// Process each link (track index for collection ordering)
|
|
19855
19877
|
for (let linkIndex = 0; linkIndex < links.length; linkIndex++) {
|
|
@@ -19859,10 +19881,16 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
19859
19881
|
// Skip 'None' values
|
|
19860
19882
|
if (target === 'None')
|
|
19861
19883
|
continue;
|
|
19862
|
-
// Track
|
|
19863
|
-
if (link.timestamp
|
|
19864
|
-
|
|
19865
|
-
|
|
19884
|
+
// Track both earliest (createdAt) and latest (updatedAt) timestamps with their authors
|
|
19885
|
+
if (link.timestamp) {
|
|
19886
|
+
if (!minTimestamp || link.timestamp < minTimestamp) {
|
|
19887
|
+
minTimestamp = link.timestamp;
|
|
19888
|
+
originalAuthor = link.author;
|
|
19889
|
+
}
|
|
19890
|
+
if (!maxTimestamp || link.timestamp > maxTimestamp) {
|
|
19891
|
+
maxTimestamp = link.timestamp;
|
|
19892
|
+
latestAuthor = link.author;
|
|
19893
|
+
}
|
|
19866
19894
|
}
|
|
19867
19895
|
// Find matching property (skip those with surrealGetter)
|
|
19868
19896
|
let foundProperty = false;
|
|
@@ -19968,20 +19996,34 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
19968
19996
|
}
|
|
19969
19997
|
}
|
|
19970
19998
|
}
|
|
19971
|
-
// Set author and
|
|
19972
|
-
if (
|
|
19973
|
-
instance.author =
|
|
19974
|
-
|
|
19999
|
+
// Set author and timestamps
|
|
20000
|
+
if (originalAuthor) {
|
|
20001
|
+
instance.author = originalAuthor;
|
|
20002
|
+
}
|
|
20003
|
+
// Set createdAt from earliest timestamp
|
|
20004
|
+
if (minTimestamp) {
|
|
20005
|
+
if (typeof minTimestamp === 'string' && minTimestamp.includes('T')) {
|
|
20006
|
+
instance.createdAt = new Date(minTimestamp).getTime();
|
|
20007
|
+
}
|
|
20008
|
+
else if (typeof minTimestamp === 'string') {
|
|
20009
|
+
const parsed = parseInt(minTimestamp, 10);
|
|
20010
|
+
instance.createdAt = isNaN(parsed) ? minTimestamp : parsed;
|
|
20011
|
+
}
|
|
20012
|
+
else {
|
|
20013
|
+
instance.createdAt = minTimestamp;
|
|
20014
|
+
}
|
|
20015
|
+
}
|
|
20016
|
+
// Set updatedAt from most recent timestamp
|
|
20017
|
+
if (maxTimestamp) {
|
|
19975
20018
|
if (typeof maxTimestamp === 'string' && maxTimestamp.includes('T')) {
|
|
19976
|
-
instance.
|
|
20019
|
+
instance.updatedAt = new Date(maxTimestamp).getTime();
|
|
19977
20020
|
}
|
|
19978
20021
|
else if (typeof maxTimestamp === 'string') {
|
|
19979
|
-
// Try to parse as number string
|
|
19980
20022
|
const parsed = parseInt(maxTimestamp, 10);
|
|
19981
|
-
instance.
|
|
20023
|
+
instance.updatedAt = isNaN(parsed) ? maxTimestamp : parsed;
|
|
19982
20024
|
}
|
|
19983
20025
|
else {
|
|
19984
|
-
instance.
|
|
20026
|
+
instance.updatedAt = maxTimestamp;
|
|
19985
20027
|
}
|
|
19986
20028
|
}
|
|
19987
20029
|
// Sort collections by timestamp to maintain insertion order
|
package/lib/index.js
CHANGED
|
@@ -18851,6 +18851,13 @@ class Ad4mModel {
|
|
|
18851
18851
|
}
|
|
18852
18852
|
return classCache[perspectiveID];
|
|
18853
18853
|
}
|
|
18854
|
+
/**
|
|
18855
|
+
* Backwards compatibility alias for createdAt.
|
|
18856
|
+
* @deprecated Use createdAt instead. This will be removed in a future version.
|
|
18857
|
+
*/
|
|
18858
|
+
get timestamp() {
|
|
18859
|
+
return this.createdAt;
|
|
18860
|
+
}
|
|
18854
18861
|
/**
|
|
18855
18862
|
* Extracts metadata from decorators for query building.
|
|
18856
18863
|
*
|
|
@@ -19150,8 +19157,10 @@ class Ad4mModel {
|
|
|
19150
19157
|
`;
|
|
19151
19158
|
const links = await __classPrivateFieldGet(this, _Ad4mModel_perspective, "f").querySurrealDB(linksQuery);
|
|
19152
19159
|
if (links && links.length > 0) {
|
|
19160
|
+
let minTimestamp = null;
|
|
19153
19161
|
let maxTimestamp = null;
|
|
19154
19162
|
let latestAuthor = null;
|
|
19163
|
+
let originalAuthor = null;
|
|
19155
19164
|
// Process properties (skip those with surrealGetter)
|
|
19156
19165
|
for (const [propName, propMeta] of Object.entries(metadata.properties)) {
|
|
19157
19166
|
if (propMeta.surrealGetter)
|
|
@@ -19162,10 +19171,16 @@ class Ad4mModel {
|
|
|
19162
19171
|
// The last element has the most recent timestamp and represents the current property value.
|
|
19163
19172
|
const link = matching[matching.length - 1];
|
|
19164
19173
|
let value = link.target;
|
|
19165
|
-
// Track
|
|
19166
|
-
if (link.timestamp
|
|
19167
|
-
|
|
19168
|
-
|
|
19174
|
+
// Track timestamps/authors for createdAt and updatedAt
|
|
19175
|
+
if (link.timestamp) {
|
|
19176
|
+
if (!minTimestamp || link.timestamp < minTimestamp) {
|
|
19177
|
+
minTimestamp = link.timestamp;
|
|
19178
|
+
originalAuthor = link.author;
|
|
19179
|
+
}
|
|
19180
|
+
if (!maxTimestamp || link.timestamp > maxTimestamp) {
|
|
19181
|
+
maxTimestamp = link.timestamp;
|
|
19182
|
+
latestAuthor = link.author;
|
|
19183
|
+
}
|
|
19169
19184
|
}
|
|
19170
19185
|
// Handle resolveLanguage
|
|
19171
19186
|
if (propMeta.resolveLanguage && propMeta.resolveLanguage !== 'literal') {
|
|
@@ -19226,12 +19241,15 @@ class Ad4mModel {
|
|
|
19226
19241
|
}
|
|
19227
19242
|
this[collName] = values;
|
|
19228
19243
|
}
|
|
19229
|
-
// Set author and
|
|
19230
|
-
if (
|
|
19231
|
-
this.author =
|
|
19244
|
+
// Set author and timestamps
|
|
19245
|
+
if (originalAuthor) {
|
|
19246
|
+
this.author = originalAuthor;
|
|
19247
|
+
}
|
|
19248
|
+
if (minTimestamp) {
|
|
19249
|
+
this.createdAt = minTimestamp;
|
|
19232
19250
|
}
|
|
19233
19251
|
if (maxTimestamp) {
|
|
19234
|
-
this.
|
|
19252
|
+
this.updatedAt = maxTimestamp;
|
|
19235
19253
|
}
|
|
19236
19254
|
}
|
|
19237
19255
|
// Evaluate SurrealQL getters
|
|
@@ -19711,8 +19729,9 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
19711
19729
|
fields.push(`(SELECT VALUE target FROM link WHERE source = source AND predicate = '${escapedPredicate}') AS ${collName}`);
|
|
19712
19730
|
}
|
|
19713
19731
|
// Always add author and timestamp fields
|
|
19714
|
-
fields.push(`(SELECT VALUE author FROM link WHERE source = source LIMIT 1) AS author`);
|
|
19715
|
-
fields.push(`(SELECT VALUE timestamp FROM link WHERE source = source LIMIT 1) AS
|
|
19732
|
+
fields.push(`(SELECT VALUE author FROM link WHERE source = source ORDER BY timestamp ASC LIMIT 1) AS author`);
|
|
19733
|
+
fields.push(`(SELECT VALUE timestamp FROM link WHERE source = source ORDER BY timestamp ASC LIMIT 1) AS createdAt`);
|
|
19734
|
+
fields.push(`(SELECT VALUE timestamp FROM link WHERE source = source ORDER BY timestamp DESC LIMIT 1) AS updatedAt`);
|
|
19716
19735
|
return fields.join(',\n ');
|
|
19717
19736
|
}
|
|
19718
19737
|
/**
|
|
@@ -19743,9 +19762,10 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
19743
19762
|
const escapedPredicate = escapeSurrealString(collMeta.predicate);
|
|
19744
19763
|
fields.push(`target[WHERE predicate = '${escapedPredicate}'] AS ${collName}`);
|
|
19745
19764
|
}
|
|
19746
|
-
// Always add author and timestamp fields
|
|
19765
|
+
// Always add author and timestamp fields
|
|
19747
19766
|
fields.push(`array::first(author) AS author`);
|
|
19748
|
-
fields.push(`array::first(timestamp) AS
|
|
19767
|
+
fields.push(`array::first(timestamp) AS createdAt`);
|
|
19768
|
+
fields.push(`array::last(timestamp) AS updatedAt`);
|
|
19749
19769
|
return fields.join(',\n ');
|
|
19750
19770
|
}
|
|
19751
19771
|
/**
|
|
@@ -19844,8 +19864,10 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
19844
19864
|
}
|
|
19845
19865
|
const links = row.links || [];
|
|
19846
19866
|
const instance = new this(perspective, base);
|
|
19847
|
-
// Track
|
|
19867
|
+
// Track both earliest (createdAt) and most recent (updatedAt) timestamps
|
|
19868
|
+
let minTimestamp = null;
|
|
19848
19869
|
let maxTimestamp = null;
|
|
19870
|
+
let originalAuthor = null;
|
|
19849
19871
|
let latestAuthor = null;
|
|
19850
19872
|
// Process each link (track index for collection ordering)
|
|
19851
19873
|
for (let linkIndex = 0; linkIndex < links.length; linkIndex++) {
|
|
@@ -19855,10 +19877,16 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
19855
19877
|
// Skip 'None' values
|
|
19856
19878
|
if (target === 'None')
|
|
19857
19879
|
continue;
|
|
19858
|
-
// Track
|
|
19859
|
-
if (link.timestamp
|
|
19860
|
-
|
|
19861
|
-
|
|
19880
|
+
// Track both earliest (createdAt) and latest (updatedAt) timestamps with their authors
|
|
19881
|
+
if (link.timestamp) {
|
|
19882
|
+
if (!minTimestamp || link.timestamp < minTimestamp) {
|
|
19883
|
+
minTimestamp = link.timestamp;
|
|
19884
|
+
originalAuthor = link.author;
|
|
19885
|
+
}
|
|
19886
|
+
if (!maxTimestamp || link.timestamp > maxTimestamp) {
|
|
19887
|
+
maxTimestamp = link.timestamp;
|
|
19888
|
+
latestAuthor = link.author;
|
|
19889
|
+
}
|
|
19862
19890
|
}
|
|
19863
19891
|
// Find matching property (skip those with surrealGetter)
|
|
19864
19892
|
let foundProperty = false;
|
|
@@ -19964,20 +19992,34 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
19964
19992
|
}
|
|
19965
19993
|
}
|
|
19966
19994
|
}
|
|
19967
|
-
// Set author and
|
|
19968
|
-
if (
|
|
19969
|
-
instance.author =
|
|
19970
|
-
|
|
19995
|
+
// Set author and timestamps
|
|
19996
|
+
if (originalAuthor) {
|
|
19997
|
+
instance.author = originalAuthor;
|
|
19998
|
+
}
|
|
19999
|
+
// Set createdAt from earliest timestamp
|
|
20000
|
+
if (minTimestamp) {
|
|
20001
|
+
if (typeof minTimestamp === 'string' && minTimestamp.includes('T')) {
|
|
20002
|
+
instance.createdAt = new Date(minTimestamp).getTime();
|
|
20003
|
+
}
|
|
20004
|
+
else if (typeof minTimestamp === 'string') {
|
|
20005
|
+
const parsed = parseInt(minTimestamp, 10);
|
|
20006
|
+
instance.createdAt = isNaN(parsed) ? minTimestamp : parsed;
|
|
20007
|
+
}
|
|
20008
|
+
else {
|
|
20009
|
+
instance.createdAt = minTimestamp;
|
|
20010
|
+
}
|
|
20011
|
+
}
|
|
20012
|
+
// Set updatedAt from most recent timestamp
|
|
20013
|
+
if (maxTimestamp) {
|
|
19971
20014
|
if (typeof maxTimestamp === 'string' && maxTimestamp.includes('T')) {
|
|
19972
|
-
instance.
|
|
20015
|
+
instance.updatedAt = new Date(maxTimestamp).getTime();
|
|
19973
20016
|
}
|
|
19974
20017
|
else if (typeof maxTimestamp === 'string') {
|
|
19975
|
-
// Try to parse as number string
|
|
19976
20018
|
const parsed = parseInt(maxTimestamp, 10);
|
|
19977
|
-
instance.
|
|
20019
|
+
instance.updatedAt = isNaN(parsed) ? maxTimestamp : parsed;
|
|
19978
20020
|
}
|
|
19979
20021
|
else {
|
|
19980
|
-
instance.
|
|
20022
|
+
instance.updatedAt = maxTimestamp;
|
|
19981
20023
|
}
|
|
19982
20024
|
}
|
|
19983
20025
|
// Sort collections by timestamp to maintain insertion order
|
|
@@ -243,9 +243,15 @@ export interface ModelMetadata {
|
|
|
243
243
|
export declare class Ad4mModel {
|
|
244
244
|
#private;
|
|
245
245
|
author: string;
|
|
246
|
-
|
|
246
|
+
createdAt: any;
|
|
247
|
+
updatedAt: any;
|
|
247
248
|
private static classNamesByClass;
|
|
248
249
|
static getClassName(perspective: PerspectiveProxy): Promise<string>;
|
|
250
|
+
/**
|
|
251
|
+
* Backwards compatibility alias for createdAt.
|
|
252
|
+
* @deprecated Use createdAt instead. This will be removed in a future version.
|
|
253
|
+
*/
|
|
254
|
+
get timestamp(): any;
|
|
249
255
|
/**
|
|
250
256
|
* Extracts metadata from decorators for query building.
|
|
251
257
|
*
|
|
@@ -306,6 +306,13 @@ export class Ad4mModel {
|
|
|
306
306
|
}
|
|
307
307
|
return classCache[perspectiveID];
|
|
308
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Backwards compatibility alias for createdAt.
|
|
311
|
+
* @deprecated Use createdAt instead. This will be removed in a future version.
|
|
312
|
+
*/
|
|
313
|
+
get timestamp() {
|
|
314
|
+
return this.createdAt;
|
|
315
|
+
}
|
|
309
316
|
/**
|
|
310
317
|
* Extracts metadata from decorators for query building.
|
|
311
318
|
*
|
|
@@ -605,8 +612,10 @@ export class Ad4mModel {
|
|
|
605
612
|
`;
|
|
606
613
|
const links = await __classPrivateFieldGet(this, _Ad4mModel_perspective, "f").querySurrealDB(linksQuery);
|
|
607
614
|
if (links && links.length > 0) {
|
|
615
|
+
let minTimestamp = null;
|
|
608
616
|
let maxTimestamp = null;
|
|
609
617
|
let latestAuthor = null;
|
|
618
|
+
let originalAuthor = null;
|
|
610
619
|
// Process properties (skip those with surrealGetter)
|
|
611
620
|
for (const [propName, propMeta] of Object.entries(metadata.properties)) {
|
|
612
621
|
if (propMeta.surrealGetter)
|
|
@@ -617,10 +626,16 @@ export class Ad4mModel {
|
|
|
617
626
|
// The last element has the most recent timestamp and represents the current property value.
|
|
618
627
|
const link = matching[matching.length - 1];
|
|
619
628
|
let value = link.target;
|
|
620
|
-
// Track
|
|
621
|
-
if (link.timestamp
|
|
622
|
-
|
|
623
|
-
|
|
629
|
+
// Track timestamps/authors for createdAt and updatedAt
|
|
630
|
+
if (link.timestamp) {
|
|
631
|
+
if (!minTimestamp || link.timestamp < minTimestamp) {
|
|
632
|
+
minTimestamp = link.timestamp;
|
|
633
|
+
originalAuthor = link.author;
|
|
634
|
+
}
|
|
635
|
+
if (!maxTimestamp || link.timestamp > maxTimestamp) {
|
|
636
|
+
maxTimestamp = link.timestamp;
|
|
637
|
+
latestAuthor = link.author;
|
|
638
|
+
}
|
|
624
639
|
}
|
|
625
640
|
// Handle resolveLanguage
|
|
626
641
|
if (propMeta.resolveLanguage && propMeta.resolveLanguage !== 'literal') {
|
|
@@ -681,12 +696,15 @@ export class Ad4mModel {
|
|
|
681
696
|
}
|
|
682
697
|
this[collName] = values;
|
|
683
698
|
}
|
|
684
|
-
// Set author and
|
|
685
|
-
if (
|
|
686
|
-
this.author =
|
|
699
|
+
// Set author and timestamps
|
|
700
|
+
if (originalAuthor) {
|
|
701
|
+
this.author = originalAuthor;
|
|
702
|
+
}
|
|
703
|
+
if (minTimestamp) {
|
|
704
|
+
this.createdAt = minTimestamp;
|
|
687
705
|
}
|
|
688
706
|
if (maxTimestamp) {
|
|
689
|
-
this.
|
|
707
|
+
this.updatedAt = maxTimestamp;
|
|
690
708
|
}
|
|
691
709
|
}
|
|
692
710
|
// Evaluate SurrealQL getters
|
|
@@ -1166,8 +1184,9 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1166
1184
|
fields.push(`(SELECT VALUE target FROM link WHERE source = source AND predicate = '${escapedPredicate}') AS ${collName}`);
|
|
1167
1185
|
}
|
|
1168
1186
|
// Always add author and timestamp fields
|
|
1169
|
-
fields.push(`(SELECT VALUE author FROM link WHERE source = source LIMIT 1) AS author`);
|
|
1170
|
-
fields.push(`(SELECT VALUE timestamp FROM link WHERE source = source LIMIT 1) AS
|
|
1187
|
+
fields.push(`(SELECT VALUE author FROM link WHERE source = source ORDER BY timestamp ASC LIMIT 1) AS author`);
|
|
1188
|
+
fields.push(`(SELECT VALUE timestamp FROM link WHERE source = source ORDER BY timestamp ASC LIMIT 1) AS createdAt`);
|
|
1189
|
+
fields.push(`(SELECT VALUE timestamp FROM link WHERE source = source ORDER BY timestamp DESC LIMIT 1) AS updatedAt`);
|
|
1171
1190
|
return fields.join(',\n ');
|
|
1172
1191
|
}
|
|
1173
1192
|
/**
|
|
@@ -1198,9 +1217,10 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1198
1217
|
const escapedPredicate = escapeSurrealString(collMeta.predicate);
|
|
1199
1218
|
fields.push(`target[WHERE predicate = '${escapedPredicate}'] AS ${collName}`);
|
|
1200
1219
|
}
|
|
1201
|
-
// Always add author and timestamp fields
|
|
1220
|
+
// Always add author and timestamp fields
|
|
1202
1221
|
fields.push(`array::first(author) AS author`);
|
|
1203
|
-
fields.push(`array::first(timestamp) AS
|
|
1222
|
+
fields.push(`array::first(timestamp) AS createdAt`);
|
|
1223
|
+
fields.push(`array::last(timestamp) AS updatedAt`);
|
|
1204
1224
|
return fields.join(',\n ');
|
|
1205
1225
|
}
|
|
1206
1226
|
/**
|
|
@@ -1299,8 +1319,10 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1299
1319
|
}
|
|
1300
1320
|
const links = row.links || [];
|
|
1301
1321
|
const instance = new this(perspective, base);
|
|
1302
|
-
// Track
|
|
1322
|
+
// Track both earliest (createdAt) and most recent (updatedAt) timestamps
|
|
1323
|
+
let minTimestamp = null;
|
|
1303
1324
|
let maxTimestamp = null;
|
|
1325
|
+
let originalAuthor = null;
|
|
1304
1326
|
let latestAuthor = null;
|
|
1305
1327
|
// Process each link (track index for collection ordering)
|
|
1306
1328
|
for (let linkIndex = 0; linkIndex < links.length; linkIndex++) {
|
|
@@ -1310,10 +1332,16 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1310
1332
|
// Skip 'None' values
|
|
1311
1333
|
if (target === 'None')
|
|
1312
1334
|
continue;
|
|
1313
|
-
// Track
|
|
1314
|
-
if (link.timestamp
|
|
1315
|
-
|
|
1316
|
-
|
|
1335
|
+
// Track both earliest (createdAt) and latest (updatedAt) timestamps with their authors
|
|
1336
|
+
if (link.timestamp) {
|
|
1337
|
+
if (!minTimestamp || link.timestamp < minTimestamp) {
|
|
1338
|
+
minTimestamp = link.timestamp;
|
|
1339
|
+
originalAuthor = link.author;
|
|
1340
|
+
}
|
|
1341
|
+
if (!maxTimestamp || link.timestamp > maxTimestamp) {
|
|
1342
|
+
maxTimestamp = link.timestamp;
|
|
1343
|
+
latestAuthor = link.author;
|
|
1344
|
+
}
|
|
1317
1345
|
}
|
|
1318
1346
|
// Find matching property (skip those with surrealGetter)
|
|
1319
1347
|
let foundProperty = false;
|
|
@@ -1419,20 +1447,34 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1419
1447
|
}
|
|
1420
1448
|
}
|
|
1421
1449
|
}
|
|
1422
|
-
// Set author and
|
|
1423
|
-
if (
|
|
1424
|
-
instance.author =
|
|
1425
|
-
|
|
1450
|
+
// Set author and timestamps
|
|
1451
|
+
if (originalAuthor) {
|
|
1452
|
+
instance.author = originalAuthor;
|
|
1453
|
+
}
|
|
1454
|
+
// Set createdAt from earliest timestamp
|
|
1455
|
+
if (minTimestamp) {
|
|
1456
|
+
if (typeof minTimestamp === 'string' && minTimestamp.includes('T')) {
|
|
1457
|
+
instance.createdAt = new Date(minTimestamp).getTime();
|
|
1458
|
+
}
|
|
1459
|
+
else if (typeof minTimestamp === 'string') {
|
|
1460
|
+
const parsed = parseInt(minTimestamp, 10);
|
|
1461
|
+
instance.createdAt = isNaN(parsed) ? minTimestamp : parsed;
|
|
1462
|
+
}
|
|
1463
|
+
else {
|
|
1464
|
+
instance.createdAt = minTimestamp;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
// Set updatedAt from most recent timestamp
|
|
1468
|
+
if (maxTimestamp) {
|
|
1426
1469
|
if (typeof maxTimestamp === 'string' && maxTimestamp.includes('T')) {
|
|
1427
|
-
instance.
|
|
1470
|
+
instance.updatedAt = new Date(maxTimestamp).getTime();
|
|
1428
1471
|
}
|
|
1429
1472
|
else if (typeof maxTimestamp === 'string') {
|
|
1430
|
-
// Try to parse as number string
|
|
1431
1473
|
const parsed = parseInt(maxTimestamp, 10);
|
|
1432
|
-
instance.
|
|
1474
|
+
instance.updatedAt = isNaN(parsed) ? maxTimestamp : parsed;
|
|
1433
1475
|
}
|
|
1434
1476
|
else {
|
|
1435
|
-
instance.
|
|
1477
|
+
instance.updatedAt = maxTimestamp;
|
|
1436
1478
|
}
|
|
1437
1479
|
}
|
|
1438
1480
|
// Sort collections by timestamp to maintain insertion order
|
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.4",
|
|
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
|
@@ -413,7 +413,8 @@ export class Ad4mModel {
|
|
|
413
413
|
#source: string;
|
|
414
414
|
#perspective: PerspectiveProxy;
|
|
415
415
|
author: string;
|
|
416
|
-
|
|
416
|
+
createdAt: any;
|
|
417
|
+
updatedAt: any;
|
|
417
418
|
|
|
418
419
|
private static classNamesByClass = new WeakMap<typeof Ad4mModel, { [perspectiveId: string]: string }>();
|
|
419
420
|
|
|
@@ -442,6 +443,14 @@ export class Ad4mModel {
|
|
|
442
443
|
return classCache[perspectiveID];
|
|
443
444
|
}
|
|
444
445
|
|
|
446
|
+
/**
|
|
447
|
+
* Backwards compatibility alias for createdAt.
|
|
448
|
+
* @deprecated Use createdAt instead. This will be removed in a future version.
|
|
449
|
+
*/
|
|
450
|
+
get timestamp(): any {
|
|
451
|
+
return (this as any).createdAt;
|
|
452
|
+
}
|
|
453
|
+
|
|
445
454
|
/**
|
|
446
455
|
* Extracts metadata from decorators for query building.
|
|
447
456
|
*
|
|
@@ -775,8 +784,10 @@ export class Ad4mModel {
|
|
|
775
784
|
const links = await this.#perspective.querySurrealDB(linksQuery);
|
|
776
785
|
|
|
777
786
|
if (links && links.length > 0) {
|
|
787
|
+
let minTimestamp = null;
|
|
778
788
|
let maxTimestamp = null;
|
|
779
789
|
let latestAuthor = null;
|
|
790
|
+
let originalAuthor = null;
|
|
780
791
|
|
|
781
792
|
// Process properties (skip those with surrealGetter)
|
|
782
793
|
for (const [propName, propMeta] of Object.entries(metadata.properties)) {
|
|
@@ -788,10 +799,16 @@ export class Ad4mModel {
|
|
|
788
799
|
const link = matching[matching.length - 1];
|
|
789
800
|
let value = link.target;
|
|
790
801
|
|
|
791
|
-
// Track
|
|
792
|
-
if (link.timestamp
|
|
793
|
-
|
|
794
|
-
|
|
802
|
+
// Track timestamps/authors for createdAt and updatedAt
|
|
803
|
+
if (link.timestamp) {
|
|
804
|
+
if (!minTimestamp || link.timestamp < minTimestamp) {
|
|
805
|
+
minTimestamp = link.timestamp;
|
|
806
|
+
originalAuthor = link.author;
|
|
807
|
+
}
|
|
808
|
+
if (!maxTimestamp || link.timestamp > maxTimestamp) {
|
|
809
|
+
maxTimestamp = link.timestamp;
|
|
810
|
+
latestAuthor = link.author;
|
|
811
|
+
}
|
|
795
812
|
}
|
|
796
813
|
|
|
797
814
|
// Handle resolveLanguage
|
|
@@ -854,12 +871,15 @@ export class Ad4mModel {
|
|
|
854
871
|
(this as any)[collName] = values;
|
|
855
872
|
}
|
|
856
873
|
|
|
857
|
-
// Set author and
|
|
858
|
-
if (
|
|
859
|
-
(this as any).author =
|
|
874
|
+
// Set author and timestamps
|
|
875
|
+
if (originalAuthor) {
|
|
876
|
+
(this as any).author = originalAuthor;
|
|
877
|
+
}
|
|
878
|
+
if (minTimestamp) {
|
|
879
|
+
(this as any).createdAt = minTimestamp;
|
|
860
880
|
}
|
|
861
881
|
if (maxTimestamp) {
|
|
862
|
-
(this as any).
|
|
882
|
+
(this as any).updatedAt = maxTimestamp;
|
|
863
883
|
}
|
|
864
884
|
}
|
|
865
885
|
|
|
@@ -1378,8 +1398,9 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1378
1398
|
}
|
|
1379
1399
|
|
|
1380
1400
|
// Always add author and timestamp fields
|
|
1381
|
-
fields.push(`(SELECT VALUE author FROM link WHERE source = source LIMIT 1) AS author`);
|
|
1382
|
-
fields.push(`(SELECT VALUE timestamp FROM link WHERE source = source LIMIT 1) AS
|
|
1401
|
+
fields.push(`(SELECT VALUE author FROM link WHERE source = source ORDER BY timestamp ASC LIMIT 1) AS author`);
|
|
1402
|
+
fields.push(`(SELECT VALUE timestamp FROM link WHERE source = source ORDER BY timestamp ASC LIMIT 1) AS createdAt`);
|
|
1403
|
+
fields.push(`(SELECT VALUE timestamp FROM link WHERE source = source ORDER BY timestamp DESC LIMIT 1) AS updatedAt`);
|
|
1383
1404
|
|
|
1384
1405
|
return fields.join(',\n ');
|
|
1385
1406
|
}
|
|
@@ -1415,9 +1436,10 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1415
1436
|
fields.push(`target[WHERE predicate = '${escapedPredicate}'] AS ${collName}`);
|
|
1416
1437
|
}
|
|
1417
1438
|
|
|
1418
|
-
// Always add author and timestamp fields
|
|
1439
|
+
// Always add author and timestamp fields
|
|
1419
1440
|
fields.push(`array::first(author) AS author`);
|
|
1420
|
-
fields.push(`array::first(timestamp) AS
|
|
1441
|
+
fields.push(`array::first(timestamp) AS createdAt`);
|
|
1442
|
+
fields.push(`array::last(timestamp) AS updatedAt`);
|
|
1421
1443
|
|
|
1422
1444
|
return fields.join(',\n ');
|
|
1423
1445
|
}
|
|
@@ -1534,8 +1556,10 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1534
1556
|
|
|
1535
1557
|
const instance = new this(perspective, base) as any;
|
|
1536
1558
|
|
|
1537
|
-
// Track
|
|
1559
|
+
// Track both earliest (createdAt) and most recent (updatedAt) timestamps
|
|
1560
|
+
let minTimestamp = null;
|
|
1538
1561
|
let maxTimestamp = null;
|
|
1562
|
+
let originalAuthor = null;
|
|
1539
1563
|
let latestAuthor = null;
|
|
1540
1564
|
|
|
1541
1565
|
// Process each link (track index for collection ordering)
|
|
@@ -1547,10 +1571,16 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1547
1571
|
// Skip 'None' values
|
|
1548
1572
|
if (target === 'None') continue;
|
|
1549
1573
|
|
|
1550
|
-
// Track
|
|
1551
|
-
if (link.timestamp
|
|
1552
|
-
|
|
1553
|
-
|
|
1574
|
+
// Track both earliest (createdAt) and latest (updatedAt) timestamps with their authors
|
|
1575
|
+
if (link.timestamp) {
|
|
1576
|
+
if (!minTimestamp || link.timestamp < minTimestamp) {
|
|
1577
|
+
minTimestamp = link.timestamp;
|
|
1578
|
+
originalAuthor = link.author;
|
|
1579
|
+
}
|
|
1580
|
+
if (!maxTimestamp || link.timestamp > maxTimestamp) {
|
|
1581
|
+
maxTimestamp = link.timestamp;
|
|
1582
|
+
latestAuthor = link.author;
|
|
1583
|
+
}
|
|
1554
1584
|
}
|
|
1555
1585
|
|
|
1556
1586
|
// Find matching property (skip those with surrealGetter)
|
|
@@ -1653,18 +1683,32 @@ WHERE ${whereConditions.join(' AND ')}
|
|
|
1653
1683
|
}
|
|
1654
1684
|
}
|
|
1655
1685
|
|
|
1656
|
-
// Set author and
|
|
1657
|
-
if (
|
|
1658
|
-
instance.author =
|
|
1659
|
-
|
|
1686
|
+
// Set author and timestamps
|
|
1687
|
+
if (originalAuthor) {
|
|
1688
|
+
instance.author = originalAuthor;
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
// Set createdAt from earliest timestamp
|
|
1692
|
+
if (minTimestamp) {
|
|
1693
|
+
if (typeof minTimestamp === 'string' && minTimestamp.includes('T')) {
|
|
1694
|
+
instance.createdAt = new Date(minTimestamp).getTime();
|
|
1695
|
+
} else if (typeof minTimestamp === 'string') {
|
|
1696
|
+
const parsed = parseInt(minTimestamp, 10);
|
|
1697
|
+
instance.createdAt = isNaN(parsed) ? minTimestamp : parsed;
|
|
1698
|
+
} else {
|
|
1699
|
+
instance.createdAt = minTimestamp;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
// Set updatedAt from most recent timestamp
|
|
1704
|
+
if (maxTimestamp) {
|
|
1660
1705
|
if (typeof maxTimestamp === 'string' && maxTimestamp.includes('T')) {
|
|
1661
|
-
instance.
|
|
1706
|
+
instance.updatedAt = new Date(maxTimestamp).getTime();
|
|
1662
1707
|
} else if (typeof maxTimestamp === 'string') {
|
|
1663
|
-
// Try to parse as number string
|
|
1664
1708
|
const parsed = parseInt(maxTimestamp, 10);
|
|
1665
|
-
instance.
|
|
1709
|
+
instance.updatedAt = isNaN(parsed) ? maxTimestamp : parsed;
|
|
1666
1710
|
} else {
|
|
1667
|
-
instance.
|
|
1711
|
+
instance.updatedAt = maxTimestamp;
|
|
1668
1712
|
}
|
|
1669
1713
|
}
|
|
1670
1714
|
|