@goatlab/fluent-loki 0.7.10 → 0.7.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Loki.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import LokiJS from 'lokijs';
2
+ export declare enum LokiStorageType {
3
+ indexedDB = "indexedDB",
4
+ memory = "memory",
5
+ fsStructured = "fsStructured",
6
+ file = "file",
7
+ cryptedFile = "cryptedFile",
8
+ json = "json"
9
+ }
10
+ export type LokiParams = {
11
+ dbName: string;
12
+ storage: LokiStorageType;
13
+ secret?: string;
14
+ };
15
+ export type LokiCreateParams<T extends LokiParams> = T extends {
16
+ storage: LokiStorageType.cryptedFile;
17
+ } ? {
18
+ secret: string;
19
+ } & LokiParams : LokiParams;
20
+ export declare class LokiClass {
21
+ createDb<T extends LokiParams>({ dbName, storage, secret }: LokiCreateParams<T>): LokiJS;
22
+ }
23
+ export declare const Loki: LokiClass;
package/dist/Loki.js ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Loki = exports.LokiClass = exports.LokiStorageType = void 0;
4
+ const lokijs_1 = require("lokijs");
5
+ const loki_indexed_adapter_1 = require("lokijs/src/loki-indexed-adapter");
6
+ const loki_fs_structured_adapter_1 = require("lokijs/src/loki-fs-structured-adapter");
7
+ const loki_crypted_file_adapter_1 = require("lokijs/src/loki-crypted-file-adapter");
8
+ const loki_nativescript_adapter_1 = require("lokijs/src/loki-nativescript-adapter");
9
+ var LokiStorageType;
10
+ (function (LokiStorageType) {
11
+ LokiStorageType["indexedDB"] = "indexedDB";
12
+ LokiStorageType["memory"] = "memory";
13
+ LokiStorageType["fsStructured"] = "fsStructured";
14
+ LokiStorageType["file"] = "file";
15
+ LokiStorageType["cryptedFile"] = "cryptedFile";
16
+ LokiStorageType["json"] = "json";
17
+ })(LokiStorageType || (exports.LokiStorageType = LokiStorageType = {}));
18
+ class LokiClass {
19
+ createDb({ dbName, storage, secret }) {
20
+ const dbConfig = {
21
+ autoload: true,
22
+ autosave: true,
23
+ autosaveInterval: 1000,
24
+ throttledSaves: false
25
+ };
26
+ switch (storage) {
27
+ case LokiStorageType.indexedDB:
28
+ return new lokijs_1.default(dbName, {
29
+ ...dbConfig,
30
+ adapter: new lokijs_1.default.LokiPartitioningAdapter(new loki_indexed_adapter_1.default(dbName), {
31
+ paging: true
32
+ })
33
+ });
34
+ case LokiStorageType.file:
35
+ return new lokijs_1.default(dbName, dbConfig);
36
+ case LokiStorageType.memory:
37
+ return new lokijs_1.default(dbName, {
38
+ ...dbConfig,
39
+ adapter: new lokijs_1.default.LokiPartitioningAdapter(new lokijs_1.default.LokiMemoryAdapter({
40
+ asyncResponses: true,
41
+ asyncTimeout: 50
42
+ }))
43
+ });
44
+ case LokiStorageType.fsStructured:
45
+ return new lokijs_1.default(dbName, {
46
+ ...dbConfig,
47
+ adapter: new loki_fs_structured_adapter_1.default()
48
+ });
49
+ case LokiStorageType.cryptedFile:
50
+ loki_crypted_file_adapter_1.default.setSecret(secret);
51
+ return new lokijs_1.default(dbName, { ...dbConfig, adapter: loki_crypted_file_adapter_1.default });
52
+ case LokiStorageType.json:
53
+ return new lokijs_1.default(dbName, {
54
+ ...dbConfig,
55
+ adapter: new loki_nativescript_adapter_1.default()
56
+ });
57
+ default:
58
+ return new lokijs_1.default(dbName, {
59
+ ...dbConfig,
60
+ adapter: new lokijs_1.default.LokiPartitioningAdapter(new lokijs_1.default.LokiMemoryAdapter())
61
+ });
62
+ }
63
+ }
64
+ }
65
+ exports.LokiClass = LokiClass;
66
+ exports.Loki = new LokiClass();
67
+ //# sourceMappingURL=Loki.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Loki.js","sourceRoot":"","sources":["../src/Loki.ts"],"names":[],"mappings":";;;AAAA,mCAA2B;AAC3B,0EAAgE;AAChE,sFAAwD;AACxD,oFAA8D;AAC9D,oFAA0E;AAE1E,IAAY,eAOX;AA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AS,CAAC,MAAM,CAAC,CAAA;gBAC7B,OAAO,IAAI,gBAAM,CAAC,MAAM,EAAE,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,mCAAW,EAAE,CAAC,CAAA;YAClE,KAAK,eAAe,CAAC,IAAI;gBACvB,OAAO,IAAI,gBAAM,CAAC,MAAM,EAAE;oBACxB,GAAG,QAAQ;oBACX,OAAO,EAAE,IAAI,mCAAuB,EAAE;iBACvC,CAAC,CAAA;YAEJ;gBACE,OAAO,IAAI,gBAAM,CAAC,MAAM,EAAE;oBACxB,GAAG,QAAQ;oBACX,OAAO,EAAE,IAAI,gBAAM,CAAC,uBAAuB,CACzC,IAAI,gBAAM,CAAC,iBAAiB,EAAE,CAC/B;iBACF,CAAC,CAAA;QACN,CAAC;IACH,CAAC;CACF;AA3DD,8BA2DC;AAEY,QAAA,IAAI,GAAG,IAAI,SAAS,EAAE,CAAA"}
@@ -0,0 +1,69 @@
1
+ import { AnyObject, BaseConnector, FluentConnectorInterface, FluentQuery, QueryOutput, LoadedResult, Primitives } from '@goatlab/fluent';
2
+ import { z } from 'zod';
3
+ import LokiJS, { Collection } from 'lokijs';
4
+ export interface LokiConnectorParams<Input, Output> {
5
+ entity: any;
6
+ dataSource: LokiJS;
7
+ inputSchema: z.ZodType<Input>;
8
+ outputSchema?: z.ZodType<Output>;
9
+ }
10
+ export interface TypeOrmConnectorParams<Input, Output> {
11
+ entity: any;
12
+ dataSource: LokiJS;
13
+ inputSchema: z.ZodType<Input>;
14
+ outputSchema?: z.ZodType<Output>;
15
+ }
16
+ export declare class LokiConnector<ModelDTO extends AnyObject = AnyObject, InputDTO extends AnyObject = ModelDTO, OutputDTO extends AnyObject = ModelDTO> extends BaseConnector<ModelDTO, InputDTO, OutputDTO> implements FluentConnectorInterface<ModelDTO, InputDTO, OutputDTO> {
17
+ private collection;
18
+ private readonly dataSource;
19
+ private readonly inputSchema;
20
+ private readonly outputSchema;
21
+ private readonly entity;
22
+ constructor({ entity, dataSource, inputSchema, outputSchema }: LokiConnectorParams<InputDTO, OutputDTO>);
23
+ /**
24
+ * Insert the data object into the database.
25
+ * @param data
26
+ */
27
+ insert(data: InputDTO): Promise<OutputDTO>;
28
+ insertMany(data: InputDTO[]): Promise<OutputDTO[]>;
29
+ /**
30
+ *
31
+ * Returns the TypeOrm Repository, you can use it
32
+ * form more complex queries and to get
33
+ * the TypeOrm query builder
34
+ *
35
+ * @param query
36
+ */
37
+ raw(): Collection;
38
+ findMany<T extends FluentQuery<ModelDTO>>(query?: T): Promise<QueryOutput<T, ModelDTO>[]>;
39
+ /**
40
+ *
41
+ * @param id
42
+ * @returns
43
+ */
44
+ deleteById(id: string): Promise<string>;
45
+ /**
46
+ * PATCH operation
47
+ * @param data
48
+ */
49
+ updateById(id: string, data: InputDTO): Promise<OutputDTO>;
50
+ /**
51
+ *
52
+ * PUT operation. All fields not included in the data
53
+ * param will be set to null
54
+ *
55
+ * @param id
56
+ * @param data
57
+ */
58
+ replaceById(id: string, data: InputDTO): Promise<OutputDTO>;
59
+ getLokiWhere(where?: FluentQuery<ModelDTO>['where']): any;
60
+ loadFirst(query?: FluentQuery<ModelDTO>): LokiConnector<ModelDTO, InputDTO, OutputDTO>;
61
+ protected clone(): any;
62
+ loadById(id: string): LoadedResult<this>;
63
+ clear(): Promise<boolean>;
64
+ /**
65
+ * Override pluck to filter out undefined values
66
+ */
67
+ pluck(path: any, query?: FluentQuery<ModelDTO>): Promise<Primitives[]>;
68
+ private getLokiOperator;
69
+ }