From 5744281aafb57492945c617d95a7244f1c3d10a7 Mon Sep 17 00:00:00 2001 From: Fernando Takagi Date: Thu, 7 Mar 2024 18:20:43 -0300 Subject: [PATCH 1/3] add sortable and order params --- index.d.ts | 6 ++++-- runtime/runtime.go | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index a1e7de9..4c02993 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2341,11 +2341,12 @@ declare namespace nkruntime { * @param collection - Collection of storage engine to index objects from. * @param key - Key of storage objects to index. Set to null, undefined or emtpy string to index all objects of collection. * @param fields - Array of fields of object to index. The values of these fields will be searchable in the index. + * @param sortableFields - Opt. Array of fields of object. The values of these fields will be sortable in an index search. The fields must exist within the previously specified fields to be indexed. * @param maxEntries - Maximum number of entries to keep in the index. * @param indexOnly - Opt. The returned values are fetched from the index only instead of the db, which might return a partial value. Defaults to false. * @throws {TypeError, GoError} */ - registerStorageIndex(name: string, collection: string, key: string | void, fields: string[], maxEntries: number, indexOnly: boolean): void; + registerStorageIndex(name: string, collection: string, key: string | void, fields: string[], sortableFields: string[], maxEntries: number, indexOnly: boolean): void; /** * Register purchase notification Google handler. @@ -4865,11 +4866,12 @@ declare namespace nkruntime { * @param indexName - Index to query. * @param query - The query to specify the index lookup criteria. * @param limit - The maximum number of results to retrieve from the index. + * @param order - Opt. The storage object fields to sort the query results by. The prefix '-' before a field name indicates descending order. All specified fields must be indexed and sortable. * @param callerId - Opt. User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permissions are bypassed. * @returns A list of storage objects matching the query criteria. * @throws {TypeError, GoError} */ - storageIndexList(indexName: string, query: string, limit: number, callerId?: string | void): StorageObject[]; + storageIndexList(indexName: string, query: string, limit: number, order: string[], callerId?: string | void): StorageObject[]; /** * Get Satori object. diff --git a/runtime/runtime.go b/runtime/runtime.go index 3bbc036..15b4c22 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -846,7 +846,7 @@ type Initializer interface { RegisterEventSessionEnd(fn func(ctx context.Context, logger Logger, evt *api.Event)) error // Register a new storage index. - RegisterStorageIndex(name, collection, key string, fields []string, maxEntries int, indexOnly bool) error + RegisterStorageIndex(name, collection, key string, fields []string, sortableFields []string, maxEntries int, indexOnly bool) error // RegisterStorageIndexFilter can be used to define a filtering function for a given storage index. RegisterStorageIndexFilter(indexName string, fn func(ctx context.Context, logger Logger, db *sql.DB, nk NakamaModule, write *StorageWrite) bool) error @@ -1087,7 +1087,7 @@ type NakamaModule interface { StorageRead(ctx context.Context, reads []*StorageRead) ([]*api.StorageObject, error) StorageWrite(ctx context.Context, writes []*StorageWrite) ([]*api.StorageObjectAck, error) StorageDelete(ctx context.Context, deletes []*StorageDelete) error - StorageIndexList(ctx context.Context, callerID, indexName, query string, limit int) (*api.StorageObjects, error) + StorageIndexList(ctx context.Context, callerID, indexName, query string, limit int, order []string) (*api.StorageObjects, error) MultiUpdate(ctx context.Context, accountUpdates []*AccountUpdate, storageWrites []*StorageWrite, storageDeletes []*StorageDelete, walletUpdates []*WalletUpdate, updateLedger bool) ([]*api.StorageObjectAck, []*WalletUpdateResult, error) From 38b8330ce9fe04486ca3e5c7b9581470d2de2349 Mon Sep 17 00:00:00 2001 From: Fernando Takagi Date: Wed, 15 May 2024 10:03:04 -0300 Subject: [PATCH 2/3] Make order param optional Co-authored-by: Simon Esposito --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 4c02993..88d1e13 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4871,7 +4871,7 @@ declare namespace nkruntime { * @returns A list of storage objects matching the query criteria. * @throws {TypeError, GoError} */ - storageIndexList(indexName: string, query: string, limit: number, order: string[], callerId?: string | void): StorageObject[]; + storageIndexList(indexName: string, query: string, limit: number, order?: string[], callerId?: string | void): StorageObject[]; /** * Get Satori object. From bb2ba8f882ff7c404ac3af8808bfc7f8afcbb634 Mon Sep 17 00:00:00 2001 From: Fernando Takagi Date: Wed, 15 May 2024 10:42:05 -0300 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32bb6ed..1481bf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr ## [Unreleased] ### Added - Add runtime support for registering a shutdown hook function. +- Add support to custom sorting in storage index search. ## [1.31.0] - 2024-03-17 ### Added