diff --git a/packages/noodl-runtime/src/nodes/std-library/data/setdbmodelpropertiesnode.js b/packages/noodl-runtime/src/nodes/std-library/data/setdbmodelpropertiesnode.js index 167df15..8c0d7af 100644 --- a/packages/noodl-runtime/src/nodes/std-library/data/setdbmodelpropertiesnode.js +++ b/packages/noodl-runtime/src/nodes/std-library/data/setdbmodelpropertiesnode.js @@ -75,12 +75,12 @@ var SetDbModelPropertiedNodeDefinition = { _this.setError('Missing Record Id'); return; } - var model = internal.model; - - for (var i in internal.inputValues) { - model.set(i, internal.inputValues[i], { resolve: true }); + + const model = internal.model; + for (const key in internal.inputValues) { + model.set(key, internal.inputValues[key], { resolve: true }); } - + CloudStore.forScope(_this.nodeScope.modelScope).save({ collection: internal.collectionId, objectId: model.getId(), // Get the objectId part of the model id diff --git a/packages/noodl-viewer-cloud/static/viewer/global.d.ts.keep b/packages/noodl-viewer-cloud/static/viewer/global.d.ts.keep index b8eaeda..1a8c715 100644 --- a/packages/noodl-viewer-cloud/static/viewer/global.d.ts.keep +++ b/packages/noodl-viewer-cloud/static/viewer/global.d.ts.keep @@ -74,6 +74,59 @@ declare namespace Noodl { */ const Object: any; + type RecordQuery = + { + lessThan: T + } | + { + lessThanOrEqualTo: T + } | + { + greaterThan: T + } | + { + greaterThanOrEqualTo: T + } | + { + equalTo: T + } | + { + notEqualTo: T + } | + { + containedIn: T + } | + { + notContainedIn : T + } | + { + exists: T + } | + { + matchesRegex: T + } | + { + text: T + } | + { + idEqualTo: T + } | + { + idContainedIn: T + } | + { + pointsTo: T + } | + { + relatedTo: T + }; + + type RecordQueryField = T extends RecordQuery ? + { [K in keyof T]: { [P in K]: T[P] } & Partial, never>> }[keyof T] + : never; + + type RecordSortKey = (`${T}` | `-${T}`)[]; + interface RecordsApi { /** * This is an async function that will query the database using the query @@ -115,15 +168,17 @@ declare namespace Noodl { * }) * ``` */ - query( - className: RecordClassName, - query?: any, + query( + className: TClassName, + query?: + RecordQueryField<{ [K in keyof DatabaseSchema[TClassName]]: RecordQuery }> | + { and: RecordQueryField<{ [K in keyof DatabaseSchema[TClassName]]: RecordQuery }>[] }, options?: { limit?: number; skip?: number; - sort?: string[]; - include?: any; - select?: any; + sort?: string | RecordSortKey; + include?: string | (keyof DatabaseSchema[TClassName])[]; + select?: string | (keyof DatabaseSchema[TClassName])[]; } ): Promise; diff --git a/packages/noodl-viewer-react/static/viewer/global.d.ts.keep b/packages/noodl-viewer-react/static/viewer/global.d.ts.keep index e271bb1..e21e938 100644 --- a/packages/noodl-viewer-react/static/viewer/global.d.ts.keep +++ b/packages/noodl-viewer-react/static/viewer/global.d.ts.keep @@ -131,6 +131,59 @@ declare namespace Noodl { */ const Events: EventsApi; + type RecordQuery = + { + lessThan: T + } | + { + lessThanOrEqualTo: T + } | + { + greaterThan: T + } | + { + greaterThanOrEqualTo: T + } | + { + equalTo: T + } | + { + notEqualTo: T + } | + { + containedIn: T + } | + { + notContainedIn : T + } | + { + exists: T + } | + { + matchesRegex: T + } | + { + text: T + } | + { + idEqualTo: T + } | + { + idContainedIn: T + } | + { + pointsTo: T + } | + { + relatedTo: T + }; + + type RecordQueryField = T extends RecordQuery ? + { [K in keyof T]: { [P in K]: T[P] } & Partial, never>> }[keyof T] + : never; + + type RecordSortKey = (`${T}` | `-${T}`)[]; + interface RecordsApi { /** * This is an async function that will query the database using the query @@ -172,15 +225,17 @@ declare namespace Noodl { * }) * ``` */ - query( - className: RecordClassName, - query?: any, + query( + className: TClassName, + query?: + RecordQueryField<{ [K in keyof DatabaseSchema[TClassName]]: RecordQuery }> | + { and: RecordQueryField<{ [K in keyof DatabaseSchema[TClassName]]: RecordQuery }>[] }, options?: { limit?: number; skip?: number; - sort?: string[]; - include?: any; - select?: any; + sort?: string | RecordSortKey; + include?: string | (keyof DatabaseSchema[TClassName])[]; + select?: string | (keyof DatabaseSchema[TClassName])[]; } ): Promise;