Skip to content

Commit b44f550

Browse files
committed
feat: improve typings (#62)
* refactor type system * remove enum and use strings instead * add transform types * fixing return types to this * add better return type to query builder arrays * remove double inline callback functions * use keyof with specialization for nested properties * update filter type in dynamic view * improve typings of full-text query * rename some properties of dynamic view * add return and use ++ instead of += 1 * rename resultset to ResultSet * remove ANY type * rename Collection.data to Collection._data * improve typings for adapter and storage package as well * improve package export with typings
1 parent eb4fed5 commit b44f550

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1568
-1490
lines changed

config/karma.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ module.exports = function (config) {
3838
exclude: /node_modules/,
3939
options: {
4040
failOnHint: false,
41-
configFile: path.join("config", "tslint.json"),
41+
configFile: path.join(__dirname, "tslint.json"),
4242
}
4343
},
4444
{
4545
test: /\.ts$/,
4646
loader: "ts-loader",
4747
options: {
48-
configFile: path.join("config", "tsconfig.webpack.json")
48+
configFile: path.join(__dirname, "tsconfig.webpack.json")
4949
}
5050
},
5151
{

packages/common/types.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {Loki} from "../loki/src/loki";
2-
3-
export type ANY = any;
1+
/**
2+
* @hidden
3+
*/
4+
import {Loki} from "../loki/src";
45

56
export interface StorageAdapter {
67
loadDatabase(dbname: string): Promise<any>;
@@ -11,7 +12,7 @@ export interface StorageAdapter {
1112

1213
mode?: string;
1314

14-
exportDatabase?(dbname: string, dbref: ANY): Promise<void>;
15+
exportDatabase?(dbname: string, dbref: Loki): Promise<void>;
1516
}
1617

1718
export type Doc<T extends object = object> = T & { $loki: number; meta: any; };
@@ -23,13 +24,5 @@ export interface Dict<T> {
2324
}
2425

2526

26-
export interface Query {
2727

28-
}
2928

30-
export interface Filter<E> {
31-
type: string;
32-
/*'find', 'where'*/
33-
val: Query | ((obj: E, index: number, array: E[]) => boolean);
34-
uid: number | string;
35-
}

packages/fs-storage/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"url": "https://github.com/LokiJS-Forge/LokiJS2.git"
99
},
1010
"main": "lokijs.fs-storage.js",
11+
"types": "./types/fs-storage/src/index.d.ts",
1112
"dependencies": {
1213
"@lokijs/loki": "0"
1314
}

packages/fs-storage/spec/node/fs_storage.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global describe, it, expect */
22
import {Loki} from "../../../loki/src/loki";
3-
import {LokiFSStorage} from "../../src/fs_storage";
3+
import {FSStorage} from "../../src/fs_storage";
44

55
describe("testing fs storage", function () {
66

@@ -9,16 +9,16 @@ describe("testing fs storage", function () {
99
}
1010

1111
beforeAll(() => {
12-
LokiFSStorage.register();
12+
FSStorage.register();
1313
});
1414

1515
afterAll(() => {
16-
LokiFSStorage.deregister();
16+
FSStorage.deregister();
1717
});
1818

1919
it("LokiFSStorage", function (done) {
2020
const db = new Loki("myTestApp");
21-
const adapter = {adapter: new LokiFSStorage()};
21+
const adapter = {adapter: new FSStorage()};
2222
db.initializePersistence(adapter)
2323
.then(() => {
2424
db.addCollection<Name>("myColl").insert({name: "Hello World"});
@@ -35,7 +35,7 @@ describe("testing fs storage", function () {
3535
})
3636
.then(() => {
3737
const db2 = new Loki("myTestApp");
38-
return db2.initializePersistence({persistenceMethod: Loki.PersistenceMethod.FS_STORAGE})
38+
return db2.initializePersistence({persistenceMethod: "fs-storage"})
3939
.then(() => {
4040
return db2.loadDatabase();
4141
}).then(() => {

packages/fs-storage/src/fs_storage.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import * as fs from "fs";
55
/**
66
* A loki persistence adapter which persists using node fs module.
77
*/
8-
export class LokiFSStorage implements StorageAdapter {
8+
export class FSStorage implements StorageAdapter {
99
/**
1010
* Registers the fs storage as plugin.
1111
*/
1212
static register(): void {
13-
PLUGINS["LokiFSStorage"] = LokiFSStorage;
13+
PLUGINS["FSStorage"] = FSStorage;
1414
}
1515

1616
/**
1717
* Deregisters the fs storage as plugin.
1818
*/
1919
static deregister(): void {
20-
delete PLUGINS["LokiFSStorage"];
20+
delete PLUGINS["FSStorage"];
2121
}
2222

2323
/**
@@ -88,5 +88,3 @@ export class LokiFSStorage implements StorageAdapter {
8888
});
8989
}
9090
}
91-
92-
export default LokiFSStorage;

packages/fs-storage/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {FSStorage} from "./fs_storage";
2+
3+
export {FSStorage};
4+
export default FSStorage;

packages/full-text-search-language-de/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"url": "https://github.com/LokiJS-Forge/LokiJS2.git"
99
},
1010
"main": "lokijs.full-text-search-language-de.js",
11+
"types": "./types/full-text-search-language-de/src/index.d.ts",
1112
"dependencies": {
1213
"@lokijs/full-text-search": "0",
1314
"@lokijs/full-text-search-language": "0"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {DE} from "./de";
2+
export {DE};
3+
export default DE;

packages/full-text-search-language-de/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require("path");
33
const webpackConigCreator = require('../../config/webpack-config-creator.js');
44

55
module.exports = webpackConigCreator({
6-
entry: path.join(__dirname, "src", "de.ts"),
6+
entry: path.join(__dirname, "src", "index.ts"),
77
filename: "lokijs.full-text-search-language-de.js",
88
library: "@lokijs/full-text-search-language-de",
99
externals: {

packages/full-text-search-language-en/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"url": "https://github.com/LokiJS-Forge/LokiJS2.git"
99
},
1010
"main": "lokijs.full-text-search-language-en.js",
11+
"types": "./types/full-text-search-language-en/src/index.d.ts",
1112
"dependencies": {
1213
"@lokijs/full-text-search": "0",
1314
"@lokijs/full-text-search-language": "0"

0 commit comments

Comments
 (0)