Skip to content

Commit de7116c

Browse files
committed
Small update. Own package?
1 parent 4e0a9da commit de7116c

File tree

10 files changed

+405
-184
lines changed

10 files changed

+405
-184
lines changed

config/karma.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = function (config) {
77
browsers: ["ChromeHeadless"],
88
files: [
99
{pattern: "../packages/*/spec/generic/**/*.spec.ts", watched: false},
10-
{pattern: "../packages/*/spec/web/**/*.spec.ts", watched: false}
10+
{pattern: "../packages/*/spec/web/**/*.spec.ts", watched: false},
11+
"/home/neubertt/projects/test/LokiDB/node_modules/lokijs/build/lokijs.min.js"
1112
],
1213
preprocessors: {
1314
"../packages/*/spec/generic/**/*.spec.ts": ["webpack"],

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"devDependencies": {
3636
"@types/elasticsearch": "^5.0.19",
3737
"@types/jasmine": "^2.8.6",
38+
"@types/lokijs": "^1.5.2",
3839
"@types/node": "^8.9.4",
3940
"cash": "^0.8.0",
4041
"conventional-changelog": "^1.1.15",
@@ -52,6 +53,7 @@
5253
"karma-jasmine": "^1.1.1",
5354
"karma-jasmine-matchers": "^3.7.0",
5455
"karma-webpack": "^2.0.9",
56+
"lokijs": "^1.5.3",
5557
"nyc": "^11.5.0",
5658
"source-map-loader": "^0.2.3",
5759
"ts-loader": "^2.3.7",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@lokidb/local-storage",
3+
"description": "A persistence adapter which persists to web browser's local storage.",
4+
"author": "Various authors",
5+
"license": "MIT",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/LokiJS-Forge/LokiDB.git"
9+
},
10+
"main": "lokidb.local-storage.js",
11+
"types": "./types/local-storage/src/index.d.ts",
12+
"dependencies": {
13+
"@lokidb/loki": "0"
14+
}
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {LegacyLoader} from "./legacy_loader";
2+
3+
export {LegacyLoader};
4+
export default LegacyLoader;
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
2+
/**
3+
* A loki persistence adapter which persists to web browser's local storage object
4+
* @constructor LocalStorageAdapter
5+
*/
6+
export class LegacyLoader {
7+
8+
}
9+
// export namespace LokiJS {
10+
//
11+
// let r: Loki = {
12+
// "filename": "test",
13+
// "collections": [{
14+
// "name": "abc",
15+
// "data": [{"meta": {"revision": 0, "created": 1523392965746, "version": 0}, "$loki": 1}, {
16+
// "meta": {"revision": 0, "created": 1523392965747, "version": 0},
17+
// "$loki": 2
18+
// }],
19+
// "idIndex": [1, 2],
20+
// "binaryIndices": {"a": {"name": "a", "dirty": false, "values": [0, 1]}},
21+
// // "constraints": null,
22+
// "uniqueNames": ["b"],
23+
// "transforms": {"abc": [{"type": "find", "value": {"owner": "odin"}}]},
24+
// "objType": "abc",
25+
// "dirty": true,
26+
// // "cachedIndex": null,
27+
// // "cachedBinaryIndex": null,
28+
// // "cachedData": null,
29+
// "adaptiveBinaryIndices": true,
30+
// "transactional": false,
31+
// "cloneObjects": false,
32+
// "cloneMethod": "parse-stringify",
33+
// // "asyncListeners": false,
34+
// "disableMeta": false,
35+
// "disableChangesApi": true,
36+
// "disableDeltaChangesApi": true,
37+
// "autoupdate": false,
38+
// "serializableIndices": true,
39+
// // "ttl": null,
40+
// "maxId": 2,
41+
// "DynamicViews": [{
42+
// // "collection": null,
43+
// "name": "test3",
44+
// "rebuildPending": false,
45+
// "options": {"persistent": true, "sortPriority": "passive", "minRebuildInterval": 1},
46+
// "resultset": {/*"collection": null, */"filteredrows": [], "filterInitialized": true},
47+
// // "resultdata": [],
48+
// // "resultsdirty": true,
49+
// // "cachedresultset": null,
50+
// "filterPipeline": [{"type": "find", "val": {"age": {"$gt": 24}}}],
51+
// // "sortFunction": null,
52+
// "sortCriteria": null,
53+
// "sortCriteriaSimple": {"propname": "age", "options": false},
54+
// "sortDirty": true,
55+
// // "events": {"rebuild": []}
56+
// }],
57+
// "events": {
58+
// "insert": [null],
59+
// "update": [null],
60+
// "pre-insert": [],
61+
// "pre-update": [],
62+
// "close": [],
63+
// "flushbuffer": [],
64+
// "error": [],
65+
// "delete": [null],
66+
// "warning": [null]
67+
// },
68+
// "changes": []
69+
// }],
70+
// "databaseVersion": 1.5,
71+
// "engineVersion": 1.5,
72+
// // "autosave": false,
73+
// // "autosaveInterval": 5000,
74+
// // "autosaveHandle": null,
75+
// "throttledSaves": true,
76+
// // "options": {"serializationMethod": "normal", "destructureDelimiter": "$<\n"},
77+
// // "persistenceMethod": "fs",
78+
// // "persistenceAdapter": null,
79+
// // "verbose": false,
80+
// // "events": {"init": [null], "loaded": [], "flushChanges": [], "close": [], "changes": [], "warning": []},
81+
// "ENV": "NODEJS"
82+
// }
83+
// console.log(r);
84+
//
85+
//
86+
//
87+
//
88+
//
89+
//
90+
// export interface Loki {
91+
// filename: string;
92+
// collections: Collection[];
93+
// databaseVersion: 1.5;
94+
// engineVersion: 1.5;
95+
// throttledSaves: boolean;
96+
// ENV: "NODEJS" | "NATIVESCRIPT" | "CORDOVA" | "BROWSER";
97+
// }
98+
//
99+
// export interface BinaryIndex {
100+
// name: string;
101+
// dirty: boolean;
102+
// values: number[];
103+
// }
104+
//
105+
// export interface Transform {
106+
//
107+
// }
108+
//
109+
//
110+
// export interface Collection {
111+
// name: string;
112+
// data: Data[];
113+
// idIndex: number[];
114+
// binaryIndices: {
115+
// [key: string]: BinaryIndex
116+
// };
117+
// uniqueNames: string[];
118+
// transforms: {
119+
// [key: string]: Transform;
120+
// };
121+
// objType: string; // ??
122+
// dirty: boolean; // ??
123+
// adaptiveBinaryIndices: boolean;
124+
// transactional: boolean;
125+
// cloneObjects: boolean;
126+
// cloneMethod: "parse-stringify" | "??";
127+
//
128+
// disableMeta: boolean;
129+
// disableChangesApi: boolean;
130+
// disableDeltaChangesApi: boolean;
131+
// autoupdate: boolean;
132+
// serializableIndices: boolean;
133+
// maxId: number;
134+
// DynamicViews: DynamicView[];
135+
// events: {};
136+
// changes: any[];
137+
// }
138+
//
139+
// export interface SimplesortOptions {
140+
// desc?: boolean;
141+
// disableIndexIntersect?: boolean;
142+
// forceIndexIntersect?: boolean;
143+
// useJavascriptSorting?: boolean;
144+
// }
145+
//
146+
// export interface DynamicView {
147+
// name: string;
148+
// rebuildPending: boolean;
149+
// options: {
150+
// persistent: true,
151+
// sortPriority: "passive" | "active",
152+
// minRebuildInterval: number;
153+
// };
154+
// resultset: ResultSet;
155+
// filterPipeline: {
156+
// type: "find",
157+
// val: any;
158+
// } | {
159+
// type: "where"
160+
// };
161+
// sortCriteria: (string | [string, boolean])[];
162+
// sortCriteriaSimple: {
163+
// propname: string;
164+
// options: boolean | SimplesortOptions;
165+
// };
166+
// sortDirty: boolean;
167+
// }
168+
//
169+
// export interface ResultSet {
170+
// filteredrows: number[];
171+
// filterInitialized: boolean;
172+
// }
173+
//
174+
// export interface Data {
175+
// $loki: number;
176+
// meta: {
177+
// revision: number;
178+
// created: number;
179+
// version: number;
180+
// updated?: number;
181+
// };
182+
// }
183+
//
184+
// export interface Serialization {
185+
//
186+
// }
187+
// }
188+
//
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* global __dirname, module, require */
2+
const path = require("path");
3+
const webpackConigCreator = require('../../config/webpack-config-creator.js');
4+
5+
module.exports = webpackConigCreator({
6+
entry: path.join(__dirname, "src", "index.ts"),
7+
filename: "lokidb.local-storage.js",
8+
library: "@lokidb/local-storage",
9+
externals: {
10+
"../../loki/src/loki": "@lokidb/loki"
11+
},
12+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {Loki} from "../../src/loki";
2+
3+
declare var loki: any;
4+
5+
describe("testing legacy loader", function () {
6+
7+
it("test", () => {
8+
const legacyDB = new loki();
9+
{
10+
const abc = legacyDB.addCollection("abc", {indices: ["a", "c"], unique: ["b"]});
11+
abc.insert([
12+
{
13+
a: 1, b: 2, c: 1, d: {
14+
msg: "hello"
15+
}
16+
},
17+
{
18+
a: 2, b: 6, c: 2, d: {
19+
msg: "loki"
20+
}
21+
},
22+
{
23+
a: 3, b: 8, c: 1, d: {
24+
msg: "legacy"
25+
}
26+
},
27+
]);
28+
const tx = [
29+
{
30+
type: "find",
31+
value: {
32+
"d.msg": "loki"
33+
}
34+
}
35+
];
36+
abc.addTransform("findLoki", tx);
37+
38+
let result = abc.chain("findLoki").data();
39+
expect(result.length).toEqual(1);
40+
expect(result[0].d.msg).toEqual("loki");
41+
42+
const dyn = abc.addDynamicView("notLoki");
43+
dyn.applyFind({c: 1});
44+
dyn.applySimpleSort("a", true);
45+
result = dyn.data();
46+
expect(result.length).toEqual(2);
47+
expect(result[0].d.msg).toEqual("legacy");
48+
expect(result[1].d.msg).toEqual("hello");
49+
}
50+
51+
const db = new Loki();
52+
db.loadJSONObject(legacyDB);
53+
54+
55+
});
56+
});

packages/loki/src/collection.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ export class Collection<TData extends object = object, TNested extends object =
330330
};
331331
}
332332

333-
static fromJSONObject(obj: Collection.Serialized, options?: Collection.DeserializeOptions) {
333+
static fromJSONObject(obj: Collection | Collection.Serialized, options?: Collection.DeserializeOptions) {
334+
if (obj instanceof Collection) {
335+
return clone(this, "shallow");
336+
}
337+
334338
let coll = new Collection<any>(obj.name, {
335339
disableChangesApi: obj.disableChangesApi,
336340
disableDeltaChangesApi: obj.disableDeltaChangesApi

0 commit comments

Comments
 (0)