From ce88a02827dcde256f88b2f91df0865b16d550f2 Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Wed, 31 May 2023 17:47:55 +0000 Subject: [PATCH] feat(core): allow passing index sort order on data.index #485 --- packages/core/deno.lock | 12 ++++++------ packages/core/deps.ts | 2 +- packages/core/lib/data/db.ts | 6 +++++- packages/core/lib/data/mod.test.ts | 12 ++++++++++++ packages/core/lib/data/mod.ts | 7 +++++-- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/packages/core/deno.lock b/packages/core/deno.lock index 93c72981..fde5aab1 100644 --- a/packages/core/deno.lock +++ b/packages/core/deno.lock @@ -340,10 +340,10 @@ "https://cdn.skypack.dev/error/unknown:ts-toolbelt?from=ramda": "9adffad52875ea5b664461a736b488fcb08a5b4b971c8c598d63c0a499c3daff", "https://cdn.skypack.dev/pin/indexeddbshim@v9.0.0-QVaW8rBIOGlJegwkWTsK/mode=imports/unoptimized/dist/indexeddbshim-noninvasive.js": "978a698ccf50ce19735b1da6cad00277cc8fc790610df183c61c2f9cc1df9c9b", "https://cdn.skypack.dev/pin/pouchdb-adapter-http@v7.3.0-wNzBHi1B5WLNzMPlTnWb/mode=imports/optimized/pouchdb-adapter-http.js": "023e92d130094b0e43638ee849b5b4f539fd987034104452c933fcd505a96242", - "https://cdn.skypack.dev/pin/pouchdb-adapter-idb@v7.3.0-zIdGq675NuTdgkAjGFSh/mode=imports/optimized/pouchdb-adapter-idb.js": "76bd6a4758f5c20caa03cba2b52a7345d5d724393bda93b82131342461d300d4", + "https://cdn.skypack.dev/pin/pouchdb-adapter-idb@v7.3.0-zIdGq675NuTdgkAjGFSh/mode=imports/optimized/pouchdb-adapter-idb.js": "978861200eebec820bcadab143d6712d8ce481ee73e579f2aedea050e23b3ef2", "https://cdn.skypack.dev/pin/pouchdb-core@v7.3.0-89HuCNEcWBT7jv1msAf2/mode=imports/optimized/pouchdb-core.js": "66ab654df46ef713bc9822010e2a9be5caa974ece65a88f72e10951836da3b99", - "https://cdn.skypack.dev/pin/pouchdb-mapreduce@v7.3.0-IEG2Gq1jfS0hW8QXVXqd/mode=imports/optimized/pouchdb-mapreduce.js": "be7fbbcd6a9fcd6ac6be2b4a5f0bef02fc84618cfbd6ec3cafd1d1a288e459e9", - "https://cdn.skypack.dev/pin/pouchdb-replication@v7.3.0-1sg1NWcwDf6gKFeXsMmq/mode=imports/optimized/pouchdb-replication.js": "474a0861108abb668cba6d1897a6ad947eb3573a7ee75875e501d6988ec0dfa6", + "https://cdn.skypack.dev/pin/pouchdb-mapreduce@v7.3.0-IEG2Gq1jfS0hW8QXVXqd/mode=imports/optimized/pouchdb-mapreduce.js": "e6d57d046d89e21e2102bee9e25612e2bf7209b707176dcc7cabc0a563d61acb", + "https://cdn.skypack.dev/pin/pouchdb-replication@v7.3.0-1sg1NWcwDf6gKFeXsMmq/mode=imports/optimized/pouchdb-replication.js": "79cdcfeefc7ac944e1cd1f80de270b1f8b78a4d7eafc4076902526c3255d2a25", "https://cdn.skypack.dev/pin/pouchdb@v7.3.0-bcA2ZAvx5a5vy7YRYZRz/mode=imports/unoptimized/dist/pouchdb.find.js": "4f5bd824948b2f07970da663ac2a07231595bef8ce8ecf66856094d222c03945", "https://cdn.skypack.dev/pin/pouchdb@v7.3.0-bcA2ZAvx5a5vy7YRYZRz/mode=imports/unoptimized/dist/pouchdb.indexeddb.js": "1a9824ca9abdaa3e1bae6fb2922d9c67d66f255cdb2d26b094f882875e734c3d", "https://cdn.skypack.dev/pin/pouchdb@v7.3.0-bcA2ZAvx5a5vy7YRYZRz/mode=imports/unoptimized/dist/pouchdb.memory.js": "70224a97fd91fa337915585734d170758bcad711ce4cc04e7621489d3333d775", @@ -455,9 +455,9 @@ "https://raw.githubusercontent.com/hyper63/hyper/hyper-port-crawler%40v0.1.0/packages/port-crawler/deps.ts": "a76d4fdba3f1437e839aebb1f9c4b678491022abbd6caedf6378b4bc701e7988", "https://raw.githubusercontent.com/hyper63/hyper/hyper-port-crawler%40v0.1.0/packages/port-crawler/mod.ts": "67de97ba3e89eaf9163fc9038c4a932f2696dff3a9c0392cc3888972218b2ac0", "https://raw.githubusercontent.com/hyper63/hyper/hyper-port-crawler%40v0.1.0/packages/port-crawler/port.ts": "c66b089d8a506b7e33460bf4a33ff4b7fda6b6f243e9dc43b5073857b7a15398", - "https://raw.githubusercontent.com/hyper63/hyper/hyper-port-data%40v2.0.1/packages/port-data/deps.ts": "a76d4fdba3f1437e839aebb1f9c4b678491022abbd6caedf6378b4bc701e7988", - "https://raw.githubusercontent.com/hyper63/hyper/hyper-port-data%40v2.0.1/packages/port-data/mod.ts": "5cedd74591214460582cc0fa2343c558912797c838a4a9683788a43e3fd2a1c1", - "https://raw.githubusercontent.com/hyper63/hyper/hyper-port-data%40v2.0.1/packages/port-data/port.ts": "cf6c9e5cac56fa145e399e017da37bdbcb1ce2579e204104b653cd0b00b0acce", + "https://raw.githubusercontent.com/hyper63/hyper/hyper-port-data%40v2.1.0/packages/port-data/deps.ts": "a76d4fdba3f1437e839aebb1f9c4b678491022abbd6caedf6378b4bc701e7988", + "https://raw.githubusercontent.com/hyper63/hyper/hyper-port-data%40v2.1.0/packages/port-data/mod.ts": "5cedd74591214460582cc0fa2343c558912797c838a4a9683788a43e3fd2a1c1", + "https://raw.githubusercontent.com/hyper63/hyper/hyper-port-data%40v2.1.0/packages/port-data/port.ts": "fea13eb708c61375ca00d2ce8dd579766790851fccacae7dca7ff49a0eb86374", "https://raw.githubusercontent.com/hyper63/hyper/hyper-port-hooks%40v2.0.0/packages/port-hooks/deps.ts": "a76d4fdba3f1437e839aebb1f9c4b678491022abbd6caedf6378b4bc701e7988", "https://raw.githubusercontent.com/hyper63/hyper/hyper-port-hooks%40v2.0.0/packages/port-hooks/mod.ts": "557356dd14c91ef733585b157d3d484194d28ea094dac4816a7d675980276e56", "https://raw.githubusercontent.com/hyper63/hyper/hyper-port-hooks%40v2.0.0/packages/port-hooks/port.ts": "52d98a2552f7469856390963d77bd9b55626a6d47281f7d0a1ced6b843f8aa38", diff --git a/packages/core/deps.ts b/packages/core/deps.ts index c2f0b099..89635c76 100644 --- a/packages/core/deps.ts +++ b/packages/core/deps.ts @@ -29,7 +29,7 @@ export { export { data, type DataPort, -} from 'https://raw.githubusercontent.com/hyper63/hyper/hyper-port-data%40v2.0.1/packages/port-data/mod.ts' +} from 'https://raw.githubusercontent.com/hyper63/hyper/hyper-port-data%40v2.1.0/packages/port-data/mod.ts' export { storage, type StoragePort, diff --git a/packages/core/lib/data/db.ts b/packages/core/lib/data/db.ts index 07c6e318..a4492f13 100644 --- a/packages/core/lib/data/db.ts +++ b/packages/core/lib/data/db.ts @@ -72,7 +72,11 @@ export const query = ( * @param {string} name * @param {string[]} fields */ -export const index = (db: string, name: string, fields: string[]) => +export const index = ( + db: string, + name: string, + fields: Parameters[0]['fields'], +) => of({ db, name, fields }) .chain((input) => ask(({ svc }: ReaderEnvironment) => { diff --git a/packages/core/lib/data/mod.test.ts b/packages/core/lib/data/mod.test.ts index 100d0542..ae5cb072 100644 --- a/packages/core/lib/data/mod.test.ts +++ b/packages/core/lib/data/mod.test.ts @@ -120,6 +120,18 @@ Deno.test('data', async (t) => { assertEquals(res.fields, ['type']) }) .toPromise() + + await data + .index('foobar', 'fizz', [{ type: 'ASC' }]) + .map((res) => { + // @ts-expect-error + assertEquals(res.db, 'foobar') + // @ts-expect-error + assertEquals(res.name, 'fizz') + // @ts-expect-error + assertEquals(res.fields, [{ type: 'ASC' }]) + }) + .toPromise() }) }) diff --git a/packages/core/lib/data/mod.ts b/packages/core/lib/data/mod.ts index 996ea88e..1e93e0fa 100644 --- a/packages/core/lib/data/mod.ts +++ b/packages/core/lib/data/mod.ts @@ -70,8 +70,11 @@ export default function ({ * @param {string} name * @param {string[]} fields */ - const index = (dbname: string, name: string, fields: string[]) => - db.index(dbname, name, fields).runWith({ svc: data, events }) + const index = ( + dbname: string, + name: string, + fields: Parameters[0]['fields'], + ) => db.index(dbname, name, fields).runWith({ svc: data, events }) /** * @param {string} dbname,