Skip to content

Commit

Permalink
feat(core): allow passing index sort order on data.index #485
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed May 31, 2023
1 parent c22c059 commit ce88a02
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
12 changes: 6 additions & 6 deletions packages/core/deno.lock
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@
"https://cdn.skypack.dev/error/unknown:ts-toolbelt?from=ramda": "9adffad52875ea5b664461a736b488fcb08a5b4b971c8c598d63c0a499c3daff",
"https://cdn.skypack.dev/pin/[email protected]/mode=imports/unoptimized/dist/indexeddbshim-noninvasive.js": "978a698ccf50ce19735b1da6cad00277cc8fc790610df183c61c2f9cc1df9c9b",
"https://cdn.skypack.dev/pin/[email protected]/mode=imports/optimized/pouchdb-adapter-http.js": "023e92d130094b0e43638ee849b5b4f539fd987034104452c933fcd505a96242",
"https://cdn.skypack.dev/pin/[email protected]/mode=imports/optimized/pouchdb-adapter-idb.js": "76bd6a4758f5c20caa03cba2b52a7345d5d724393bda93b82131342461d300d4",
"https://cdn.skypack.dev/pin/[email protected]/mode=imports/optimized/pouchdb-adapter-idb.js": "978861200eebec820bcadab143d6712d8ce481ee73e579f2aedea050e23b3ef2",
"https://cdn.skypack.dev/pin/[email protected]/mode=imports/optimized/pouchdb-core.js": "66ab654df46ef713bc9822010e2a9be5caa974ece65a88f72e10951836da3b99",
"https://cdn.skypack.dev/pin/[email protected]/mode=imports/optimized/pouchdb-mapreduce.js": "be7fbbcd6a9fcd6ac6be2b4a5f0bef02fc84618cfbd6ec3cafd1d1a288e459e9",
"https://cdn.skypack.dev/pin/[email protected]/mode=imports/optimized/pouchdb-replication.js": "474a0861108abb668cba6d1897a6ad947eb3573a7ee75875e501d6988ec0dfa6",
"https://cdn.skypack.dev/pin/[email protected]/mode=imports/optimized/pouchdb-mapreduce.js": "e6d57d046d89e21e2102bee9e25612e2bf7209b707176dcc7cabc0a563d61acb",
"https://cdn.skypack.dev/pin/[email protected]/mode=imports/optimized/pouchdb-replication.js": "79cdcfeefc7ac944e1cd1f80de270b1f8b78a4d7eafc4076902526c3255d2a25",
"https://cdn.skypack.dev/pin/[email protected]/mode=imports/unoptimized/dist/pouchdb.find.js": "4f5bd824948b2f07970da663ac2a07231595bef8ce8ecf66856094d222c03945",
"https://cdn.skypack.dev/pin/[email protected]/mode=imports/unoptimized/dist/pouchdb.indexeddb.js": "1a9824ca9abdaa3e1bae6fb2922d9c67d66f255cdb2d26b094f882875e734c3d",
"https://cdn.skypack.dev/pin/[email protected]/mode=imports/unoptimized/dist/pouchdb.memory.js": "70224a97fd91fa337915585734d170758bcad711ce4cc04e7621489d3333d775",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion packages/core/lib/data/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataPort['indexDocuments']>[0]['fields'],
) =>
of({ db, name, fields })
.chain((input) =>
ask(({ svc }: ReaderEnvironment<DataPort>) => {
Expand Down
12 changes: 12 additions & 0 deletions packages/core/lib/data/mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})

Expand Down
7 changes: 5 additions & 2 deletions packages/core/lib/data/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataPort['indexDocuments']>[0]['fields'],
) => db.index(dbname, name, fields).runWith({ svc: data, events })

/**
* @param {string} dbname,
Expand Down

0 comments on commit ce88a02

Please sign in to comment.