mirror: A tiny/fast dataloader implementation
0

Configure Feed

Select the types of activity you want to include in your feed.

chore: move files into lib

Marais Rossouw (Sep 4, 2024, 3:15 PM +1000) 0b5e1fcf 78b60e7d

+9 -89
bench/deno.json

This is a binary file and will not be displayed.

-38
bench/deno.lock
··· 1 - { 2 - "version": "3", 3 - "packages": { 4 - "specifiers": { 5 - "jsr:@mr/object-identity": "jsr:@mr/object-identity@0.1.2", 6 - "npm:@marais/bench": "npm:@marais/bench@0.0.8", 7 - "npm:dataloader": "npm:dataloader@2.2.2" 8 - }, 9 - "jsr": { 10 - "@mr/object-identity@0.1.2": { 11 - "integrity": "18e50582c702c0f532dc9eb3cd93549cc0574522312786355adba9061f4fc7ce" 12 - } 13 - }, 14 - "npm": { 15 - "@marais/bench@0.0.8": { 16 - "integrity": "sha512-DZ3TqK1eUN77E2nV2Aj2aady61rveJGqGAPNQglzoJL001HJq9elFLRS6pw25e6geIEmRld9cJ5F/EHFUYa+DQ==", 17 - "dependencies": { 18 - "@thi.ng/bench": "@thi.ng/bench@3.5.1" 19 - } 20 - }, 21 - "@thi.ng/api@8.9.31": { 22 - "integrity": "sha512-YuodNQ4TnxV8OIa8xiF9JQ+vBam16W3Z9EbTAAgX/VlQUQ7NEVBbFO8eNGcpyrfOoWdSX4b9JcPbAXuB1dfg1g==", 23 - "dependencies": {} 24 - }, 25 - "@thi.ng/bench@3.5.1": { 26 - "integrity": "sha512-ekueeRFmWdXiCB9vnZxzOXKJ9s6ol3injV79hHZXrL+XqjPiP9VyX4fnVvQ/vTCzR27+wYM8fbz3S1veUEF84w==", 27 - "dependencies": { 28 - "@thi.ng/api": "@thi.ng/api@8.9.31" 29 - } 30 - }, 31 - "dataloader@2.2.2": { 32 - "integrity": "sha512-8YnDaaf7N3k/q5HnTJVuzSyLETjoZjVmHc4AeKAzOvKHEFQKcn64OKBfzHYtE9zGjctNM7V9I0MfnUVLpi7M5g==", 33 - "dependencies": {} 34 - } 35 - } 36 - }, 37 - "remote": {} 38 - }
-43
bench/index.ts
··· 1 - import { suite } from 'npm:@marais/bench'; 2 - import DataLoader from 'npm:dataloader'; 3 - import * as dldr from '../mod.ts'; 4 - import * as dldrCache from '../cache/mod.ts'; 5 - 6 - const loadFn: dldr.LoadFn<any, string> = async (keys: string[]) => Promise.resolve(keys); 7 - 8 - await suite<any[]>( 9 - { 10 - dldr: () => { 11 - return (keys) => Promise.all(keys.map((key) => dldr.load(loadFn, key))); 12 - }, 13 - 'dldr/cache': () => { 14 - const cache = new Map(); 15 - return (keys) => 16 - Promise.all( 17 - keys.map((key) => dldrCache.load(loadFn, cache, key)), 18 - ); 19 - }, 20 - dataloader: () => { 21 - const loader = new DataLoader(loadFn as any, { 22 - cache: false, 23 - }); 24 - 25 - return (keys) => loader.loadMany(keys); 26 - }, 27 - 'dataloader/cache': () => { 28 - const loader = new DataLoader(loadFn as any, { 29 - cache: true, 30 - }); 31 - 32 - return (keys) => loader.loadMany(keys); 33 - }, 34 - }, 35 - (run) => { 36 - const keys = ['a', 'b', 'c', 'a']; 37 - run( 38 - undefined, 39 - () => keys, 40 - (results) => results.every((result, i) => result === keys[i]), 41 - ); 42 - }, 43 - );
+1 -1
cache/mod.test.ts lib/cache.test.ts
··· 2 2 import { spy } from 'npm:nanospy'; 3 3 import { setImmediate } from 'node:timers/promises'; 4 4 5 - import * as dldr from './mod.ts'; 5 + import * as dldr from './cache.ts'; 6 6 7 7 Deno.test('api', () => { 8 8 assertInstanceOf(dldr.load, Function);
+1 -1
cache/mod.ts lib/cache.ts
··· 31 31 32 32 import { identify } from 'object-identity'; 33 33 34 - import * as dldr from '../mod.ts'; 34 + import * as dldr from './mod.ts'; 35 35 36 36 export type MapLike<K, V> = { 37 37 get(key: K): V | undefined;
+7 -6
deno.json
··· 2 2 "version": "0.0.11", 3 3 "name": "@mr/dataloader", 4 4 "exports": { 5 - ".": "./mod.ts", 6 - "./cache": "./cache/mod.ts" 5 + ".": "./lib/mod.ts", 6 + "./cache": "./lib/cache.ts" 7 7 }, 8 8 "tasks": { 9 9 "build": "deno run -A scripts/build.ts" ··· 11 11 "imports": { 12 12 "@deno/dnt": "jsr:@deno/dnt@^0.41.1", 13 13 "@std/assert": "jsr:@std/assert@^0.221.0", 14 - "object-identity": "jsr:@mr/object-identity@^0.1.2" 14 + "object-identity": "jsr:@mr/object-identity@^0.1" 15 15 }, 16 16 "lock": false, 17 17 "lint": { ··· 32 32 "useTabs": true 33 33 }, 34 34 "exclude": [ 35 - "npm" 35 + "npm", 36 + "coverage" 36 37 ], 37 38 "publish": { 38 39 "include": [ 39 - "mod.ts", 40 - "cache/mod.ts", 40 + "lib/mod.ts", 41 + "lib/cache.ts", 41 42 "license", 42 43 "readme.md" 43 44 ]
mod.test.ts lib/mod.test.ts
mod.ts lib/mod.ts