klauz-db 0.2.0

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/README.md ADDED
@@ -0,0 +1,533 @@
1
+ <!-- # KlauzDB [![NPM version](https://img.shields.io/npm/v/klauz-db.svg?style=flat-square)](https://www.npmjs.com/package/klauz-db) -->
2
+ # KlauzDB [![NPM version]]
3
+
4
+ KlauzDB é um banco de dados orientado a collections projetado para oferecer uma solução leve e eficiente para a persistência de dados locais. Utilizando arquivos .json como seu meio de armazenamento, ele permite que desenvolvedores manipulem dados estruturados de maneira intuitiva e acessível.
5
+
6
+ Com suporte a operações CRUD *(Criar, Ler, Atualizar e Deletar)*, o sistema permite a categorização de dados em coleções, facilitando a realização de consultas de forma ágil e adaptável. A estrutura em JSON garante que os dados sejam facilmente legíveis e interoperáveis com diversas linguagens de programação.
7
+
8
+ Ideal para aplicações que exigem uma solução simples e eficaz de armazenamento, este banco de dados é perfeito para protótipos, projetos de pequeno a médio porte, testes automatizados e ambientes de desenvolvimento, proporcionando agilidade no gerenciamento de informações.
9
+ <br>
10
+
11
+ * [🌱 Instalação](#-Instalação)
12
+ * [🏗️ Usabilidade](#%EF%B8%8F-Usabilidade)
13
+ * [📖 Docs](#-Documentação)
14
+ <!-- * [📚 Examples](#-examples) -->
15
+ <!-- * [❓ FAQ](#-faq) -->
16
+ <!-- * [⏱️ Changelog](./CHANGELOG.md) -->
17
+
18
+ ## 🌱 Instalação
19
+
20
+ ```bash
21
+ # instalação local (recomendado)
22
+ npm install klauz-db --save
23
+ ```
24
+
25
+ Instalação via yarn: `yarn add klauz-db`
26
+
27
+ ## 🏗️ Usabilidade
28
+
29
+ No começo da sua aplicação, importe o pacote "klauz-db" e defina o path principal para suas collections:
30
+
31
+ ```javascript
32
+ const { KlauzDB } = require('klauz-db')
33
+
34
+ const kz = new KlauzDB({
35
+ path: '{db_path}'
36
+ })
37
+ ```
38
+
39
+ ES6:
40
+
41
+ ```javascript
42
+ import { KlauzDB } from 'klauz-db'
43
+
44
+ const kz = new KlauzDB({
45
+ path: '{db_path}'
46
+ })
47
+ ```
48
+
49
+ Feito isso, você já pode criar suas Collections.
50
+ <br>
51
+
52
+ ## 📖 Documentação
53
+
54
+ KlauzDB expõe apenas uma função:
55
+
56
+ * `createCollection`
57
+
58
+ ### createCollection()
59
+ Habilita uma nova instância Collection, e cria seu arquivo .json para persistência dos dados.
60
+
61
+ #### Syntax
62
+ ```js
63
+ kz.createCollection(nomeCollection)
64
+ ```
65
+
66
+ #### Parâmetros
67
+ `nomeCollection: string`<br><br>Nome utilizado para criação de uma nova Collection e seu arquivo de persistência de dados;
68
+
69
+ #### Retorno
70
+ Instância própria da Collection, habilitando acesso as funções de banco de dados;
71
+
72
+ #### Exemplo
73
+ ```js
74
+ const kz = new KlauzDB({
75
+ path: './'
76
+ })
77
+
78
+ const collection = kz.createCollection('coll-teste')
79
+
80
+ console.log(collection.information)
81
+ // Resultado:
82
+ {
83
+ "collection_name": "coll-teste",
84
+ "created_at": "2024-08-25T22:41:57.416Z",
85
+ "last_interaction": "2024-08-25:41:57.416Z",
86
+ }
87
+ //
88
+ ```
89
+
90
+ Com sua collection criada agora você já tem acesso as seguintes funções de db:
91
+ ```js
92
+ .add()
93
+ .addMany()
94
+ .update()
95
+ .delete()
96
+ .findAll()
97
+ .find()
98
+ .reset()
99
+ ```
100
+ <br>
101
+
102
+ ### add
103
+ Adiciona um novo objeto dentro da collection.
104
+
105
+ #### Syntax
106
+ ```js
107
+ collection.add(valor)
108
+ ```
109
+
110
+ #### Parâmetros
111
+ `valor: { key: value }` *(obrigatório)*<br><br>Objeto chave-valor utilizado para inserir um único registro dentro da Collection;
112
+
113
+ #### Retorno
114
+ Objeto adicionado já com as novas propriedades criadas pelo banco de dados;
115
+
116
+ #### Exemplo
117
+ ```js
118
+ const output = collection.add({
119
+ nome: 'User_1',
120
+ admin: true
121
+ })
122
+
123
+ console.log("output: ", output);
124
+ // Resultado:
125
+ {
126
+ "nome": "User_1",
127
+ "admin": true
128
+ "_zid": 1
129
+ }
130
+ //
131
+ ```
132
+ <br>
133
+
134
+ ### addMany
135
+ Adiciona um novo array de objetos dentro da collection.
136
+
137
+ #### Syntax
138
+ ```js
139
+ collection.addMany(valor)
140
+ ```
141
+
142
+ #### Parâmetros
143
+ `valor: [{ key: value }, { key: value }]` *(obrigatório)*<br><br>Array utilizado para inserir diversos registros dentro da Collection;
144
+
145
+ #### Retorno
146
+ Array de objetos adicionados já com as novas propriedades criadas pelo banco de dados;
147
+
148
+ #### Exemplo
149
+ ```js
150
+ const output = collection.addMany([
151
+ {
152
+ nome: 'User_1',
153
+ admin: true
154
+ },
155
+ {
156
+ nome: 'User_2',
157
+ admin: false
158
+ }
159
+ ])
160
+
161
+ console.log("output: ", output);
162
+ // Resultado:
163
+ [
164
+ {
165
+ "nome": "User_1",
166
+ "admin": true,
167
+ "_zid": 1
168
+ },
169
+ {
170
+ "nome": "User_2",
171
+ "admin": false,
172
+ "_zid": 2
173
+ }
174
+ ]
175
+ //
176
+ ```
177
+ <br>
178
+
179
+ ### findAll
180
+ Retorna todos os dados contidos dentro da Collection.
181
+
182
+ #### Syntax
183
+ ```js
184
+ const optionsFindAll = {
185
+ hideInfo: Array<string>
186
+ }
187
+ collection.findAll(optionsFindAll?)
188
+ ```
189
+
190
+ #### Parâmetros
191
+ `optionsFindAll.hideInfo: Array<string>` *(opcional)*<br><br>Array contendo as informações que necessita esconder do retorno da função.<br><br>
192
+
193
+ #### Retorno
194
+ Todos os objetos persistidos na Collection;
195
+
196
+ #### Exemplo
197
+ ```js
198
+ // Adicionando dados
199
+ collection.addMany([
200
+ {
201
+ nome: 'User_1',
202
+ admin: false
203
+ },
204
+ {
205
+ nome: 'User_2',
206
+ admin: false
207
+ }
208
+ ])
209
+
210
+
211
+ // Consultando dados
212
+
213
+ // Sem hideInfo
214
+ const output1 = collection.findAll()
215
+
216
+ console.log("output1", output1);
217
+ // Resultado:
218
+ [
219
+ {
220
+ "nome": "User_1",
221
+ "admin": false,
222
+ "_zid": 1
223
+ },
224
+ {
225
+ "nome": "User_2",
226
+ "admin": false,
227
+ "_zid": 2
228
+ }
229
+ ]
230
+ //
231
+
232
+
233
+ // Com hideInfo
234
+ const output2 = collection.findAll({
235
+ hideInfo: ['admin'] // Esconde as informações indicadas do retorno;
236
+ })
237
+
238
+ console.log("output2", output2);
239
+ // Resultado:
240
+ [
241
+ {
242
+ "nome": "User_1",
243
+ "_zid": 1
244
+ },
245
+ {
246
+ "nome": "User_2",
247
+ "_zid": 2
248
+ }
249
+ ]
250
+ //
251
+ ```
252
+ <br>
253
+
254
+ ### find
255
+ Retorna dados específicos que estão contidos na Collection.
256
+
257
+ #### Syntax
258
+ ```js
259
+ const optionsFind = {
260
+ where: (obj) => {},
261
+ hideInfo?: Array<string>
262
+ }
263
+ collection.find(optionsFind)
264
+ ```
265
+
266
+ #### Parâmetros
267
+ `optionsFind.where: function(obj) {}` *(obrigatório)*<br><br>Função callback que recebe como parâmetro os objetos contidos na Collection.<br>Seu retorno deve ser os objetos que serão consultados;<br><br>
268
+ `optionsFind.hideInfo: Array<string>` *(opcional)*<br><br>Array contendo as informações que necessita esconder do retorno da função.<br><br>
269
+
270
+ #### Retorno
271
+ Objetos persistidos na Collection;
272
+
273
+ #### Exemplo
274
+ ```js
275
+ // Adicionando dados
276
+ collection.addMany([
277
+ {
278
+ nome: 'User_1',
279
+ admin: true
280
+ },
281
+ {
282
+ nome: 'User_2',
283
+ admin: false
284
+ },
285
+ {
286
+ nome: 'User_3',
287
+ admin: false
288
+ }
289
+ ])
290
+
291
+
292
+ // Consultando dados
293
+
294
+ //Syntax Javascript antiga
295
+ const antigo = collection.find({
296
+ where: function(obj) {
297
+ if (obj.admin === true) {
298
+ return obj
299
+ }
300
+ }
301
+ })
302
+
303
+ //Syntax Javascript moderna (recomendado)
304
+ const moderno = collection.find({
305
+ where: obj => obj.admin === true
306
+ })
307
+
308
+ // Syntax Typescript:
309
+ // Utiliza Generics para habilitar a tipagem dos objetos, incluindo a propriedade '_zid' como padrão.
310
+ type User = { nome: string, admin: boolean };
311
+ const typescript = collection.find<User>({
312
+ where: obj => obj.admin === true
313
+ })
314
+
315
+ console.log("antigo", antigo);
316
+ console.log("moderno", moderno);
317
+ console.log("typescript", typescript);
318
+ // Resultado:
319
+ [
320
+ {
321
+ "nome": "User_1",
322
+ "admin": true,
323
+ "_zid": 1
324
+ }
325
+ ]
326
+ //
327
+
328
+ const output1 = collection.find({
329
+ where: obj => obj._zid > 2
330
+ })
331
+
332
+ console.log("output1", output1);
333
+ // Resultado:
334
+ [
335
+ {
336
+ "nome": "User_3",
337
+ "admin": false,
338
+ "_zid": 3
339
+ }
340
+ ]
341
+ //
342
+
343
+ const output2 = collection.find({
344
+ where: obj => obj.admin === false,
345
+ hideInfo: ['admin', '_zid']
346
+ })
347
+
348
+ console.log("output2", output2);
349
+ // Resultado:
350
+ [
351
+ {
352
+ "nome": "User_2",
353
+ },
354
+ {
355
+ "nome": "User_3",
356
+ }
357
+ ]
358
+ //
359
+ ```
360
+ <br>
361
+
362
+ ### update
363
+ Altera um ou mais objetos dentro da Collection.
364
+
365
+ #### Syntax
366
+ ```js
367
+ const optionsUpdate = {
368
+ where: (obj) => {},
369
+ values: { key: value }
370
+ }
371
+ collection.update(optionsUpdate)
372
+ ```
373
+
374
+ #### Parâmetros
375
+ `optionsUpdate.where: function(obj) {}` *(obrigatório)*<br><br>Função callback que recebe como parâmetro os objetos contidos na Collection.<br>Seu retorno deve ser os objetos que serão atualizados;<br><br>
376
+ `optionsUpdate.values: { key: value }` *(obrigatório)*<br><br>Objeto chave-valor com os novos valores a serem atualizados;
377
+
378
+ #### Retorno
379
+ Array de objetos já com as novas alterações;
380
+
381
+ #### Exemplo
382
+ ```js
383
+ // Adicionando dados
384
+ collection.addMany([
385
+ {
386
+ nome: 'User_1',
387
+ admin: false
388
+ },
389
+ {
390
+ nome: 'User_2',
391
+ admin: false
392
+ }
393
+ ])
394
+
395
+
396
+ // Alterando dados
397
+
398
+ // JavaScript:
399
+ const output1 = collection.update({
400
+ where: obj => obj.nome === 'User_1',
401
+ values: { admin: true }
402
+ })
403
+
404
+
405
+ // Typescript:
406
+ type User = { nome: string, admin: boolean }
407
+ const output2 = collection.update<User>({
408
+ where: (obj) => obj._zid === 1,
409
+ values: { admin: true }
410
+ })
411
+
412
+
413
+ console.log("output1: ", output1);
414
+ console.log("output2: ", output2);
415
+ // Resultado:
416
+ [
417
+ {
418
+ "nome": "User_1",
419
+ "admin": true,
420
+ "_zid": 1
421
+ }
422
+ ]
423
+ //
424
+
425
+ const output3 = collection.update({
426
+ where: obj => obj.nome === 'User_2',
427
+ values: { idade: 20 }
428
+ })
429
+
430
+ console.log("output3: ", output3);
431
+ // Resultado:
432
+ [
433
+ {
434
+ "nome": "User_2",
435
+ "admin": false,
436
+ "idade": 20,
437
+ "_zid": 2
438
+ }
439
+ ]
440
+ //
441
+ ```
442
+ <br>
443
+
444
+ ### delete
445
+ Remove um ou mais objetos da Collection.
446
+
447
+ #### Syntax
448
+ ```js
449
+ const optionsDelete = {
450
+ where: (obj) => {}
451
+ }
452
+ collection.delete(optionsDelete)
453
+ ```
454
+
455
+ #### Parâmetros
456
+ `optionsDelete.where: function(obj) {}` *(obrigatório)*<br><br>Função callback que recebe como parâmetro os objetos contidos na Collection.<br>Seu retorno deve ser os objetos que serão removidos;<br><br>
457
+
458
+ #### Retorno
459
+ Não possui retorno;
460
+
461
+ #### Exemplo
462
+ ```js
463
+ // Adicionando dados
464
+ collection.addMany([
465
+ {
466
+ nome: 'User_1',
467
+ admin: false
468
+ },
469
+ {
470
+ nome: 'User_2',
471
+ admin: false
472
+ },
473
+ {
474
+ nome: 'User_3',
475
+ admin: false
476
+ }
477
+ ])
478
+
479
+
480
+ // Deletando dados
481
+
482
+ console.log("collection.findAll(): ", collection.findAll());
483
+ // Consulta antes:
484
+ [
485
+ {
486
+ "nome": "User_1",
487
+ "admin": false,
488
+ "_zid": 1
489
+ },
490
+ {
491
+ "nome": "User_2",
492
+ "admin": false,
493
+ "_zid": 2
494
+ },
495
+ {
496
+ "nome": "User_3",
497
+ "admin": false,
498
+ "_zid": 3
499
+ }
500
+ ]
501
+ //
502
+
503
+
504
+ // JavaScript:
505
+ collection.delete({
506
+ where: obj => obj.nome === 'User_1'
507
+ })
508
+
509
+
510
+ // Typescript:
511
+ type User = { nome: string, admin: boolean };
512
+ collection.delete<User>({
513
+ where: obj => obj._zid === 1
514
+ })
515
+
516
+
517
+ console.log("collection.findAll(): ", collection.findAll());
518
+ // Consulta depois:
519
+ [
520
+ {
521
+ "nome": "User_2",
522
+ "admin": false,
523
+ "_zid": 2
524
+ },
525
+ {
526
+ "nome": "User_3",
527
+ "admin": false,
528
+ "_zid": 3
529
+ }
530
+ ]
531
+ //
532
+ ```
533
+ <br>
@@ -0,0 +1,15 @@
1
+ import { CollectionContent, CollectionData, CollectionDataWithZID, CollectionProps, DeleteOptions, FindOptions, FindOptionsWithoutWhere, KzObject, Output, UpdateOptions } from "./Types";
2
+ export declare class Collection {
3
+ #private;
4
+ private readonly props;
5
+ constructor(props: CollectionProps);
6
+ get information(): Omit<CollectionContent, 'data'>;
7
+ add(data: CollectionData): Output<CollectionDataWithZID>;
8
+ addMany(data: CollectionData[]): Output<CollectionDataWithZID[]>;
9
+ findAll(options?: FindOptionsWithoutWhere): Output<CollectionDataWithZID[]>;
10
+ find<T>(options: FindOptions<KzObject<T>>): Output<CollectionDataWithZID[]>;
11
+ update<T>(options: UpdateOptions<KzObject<T>>): Output<CollectionDataWithZID[]>;
12
+ delete<T>(options: DeleteOptions<KzObject<T>>): Output<void>;
13
+ reset(): Output<void>;
14
+ drop(): void;
15
+ }
@@ -0,0 +1,242 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Collection = void 0;
7
+ const fs_1 = require("fs");
8
+ const zod_1 = __importDefault(require("zod"));
9
+ const Error_1 = require("./Error.js");
10
+ class Collection {
11
+ props;
12
+ #name;
13
+ #path;
14
+ #content = {};
15
+ constructor(props) {
16
+ this.props = props;
17
+ const fileExtension = '.json';
18
+ const { path, name } = props;
19
+ this.#name = name;
20
+ this.#path = `${path}/.${name}${fileExtension}`;
21
+ this.#load();
22
+ }
23
+ #load() {
24
+ try {
25
+ (0, fs_1.accessSync)(this.#path, fs_1.constants.F_OK);
26
+ const readedContent = (0, fs_1.readFileSync)(this.#path, {
27
+ encoding: 'utf-8'
28
+ });
29
+ this.#content = JSON.parse(readedContent);
30
+ }
31
+ catch (err) {
32
+ const content = {
33
+ collection_name: this.#name,
34
+ created_at: new Date().toISOString(),
35
+ last_interaction: new Date().toISOString(),
36
+ data: []
37
+ };
38
+ this.#content = content;
39
+ }
40
+ finally {
41
+ this.#save(this.#content);
42
+ }
43
+ }
44
+ #save(content) {
45
+ (0, fs_1.writeFileSync)(this.#path, JSON.stringify(content, null, 2));
46
+ }
47
+ #setCollectionDataValue(data) {
48
+ this.#load();
49
+ this.#content.last_interaction = new Date().toISOString();
50
+ this.#content.data.push(data);
51
+ this.#save(this.#content);
52
+ }
53
+ #setCollectionData(data) {
54
+ this.#load();
55
+ this.#content.last_interaction = new Date().toISOString();
56
+ this.#content.data = data;
57
+ this.#save(this.#content);
58
+ }
59
+ #getCollectionData() {
60
+ this.#load();
61
+ return this.#content.data;
62
+ }
63
+ #getLastNumericId() {
64
+ this.#load();
65
+ const lastObject = this.#content.data.findLast((obj) => typeof obj._zid === 'number');
66
+ return lastObject?._zid ?? 0;
67
+ }
68
+ get information() {
69
+ this.#load();
70
+ return {
71
+ collection_name: this.#content.collection_name,
72
+ created_at: this.#content.created_at,
73
+ last_interaction: this.#content.last_interaction,
74
+ };
75
+ }
76
+ add(data) {
77
+ try {
78
+ if (arguments.length > 1)
79
+ throw TypeError('Invalid params');
80
+ const schema = zod_1.default.record(zod_1.default.string(), zod_1.default.any(), { message: `Content must be a object. Use 'addMany' method, to insert a new array` });
81
+ const obj = schema.parse(data);
82
+ const lastId = this.#getLastNumericId();
83
+ Reflect.set(obj, '_zid', lastId + 1);
84
+ this.#setCollectionDataValue(obj);
85
+ return obj;
86
+ }
87
+ catch (err) {
88
+ return (0, Error_1.errorMessage)(err);
89
+ }
90
+ }
91
+ addMany(data) {
92
+ try {
93
+ if (arguments.length > 1)
94
+ throw TypeError('Invalid params');
95
+ const schemaArray = zod_1.default.array(zod_1.default.record(zod_1.default.string(), zod_1.default.any()));
96
+ const schemaObject = zod_1.default.record(zod_1.default.string(), zod_1.default.any());
97
+ const objs = schemaArray.parse(data);
98
+ for (const obj of objs) {
99
+ schemaObject.parse(obj);
100
+ const lastId = this.#getLastNumericId();
101
+ Reflect.set(obj, '_zid', lastId + 1);
102
+ this.#setCollectionDataValue(obj);
103
+ }
104
+ return objs;
105
+ }
106
+ catch (err) {
107
+ return (0, Error_1.errorMessage)(err);
108
+ }
109
+ }
110
+ findAll(options) {
111
+ try {
112
+ if (arguments.length > 1)
113
+ throw TypeError('Invalid params');
114
+ const collectionData = this.#getCollectionData();
115
+ const optionsSchema = zod_1.default.object({
116
+ hideInfo: zod_1.default.array(zod_1.default.string()).optional(),
117
+ }).optional();
118
+ const zOpts = optionsSchema.parse(options);
119
+ if (zOpts && Object.values(zOpts).length > 0) {
120
+ const keys = Object.keys(zOpts);
121
+ for (const key of keys) {
122
+ if (!zOpts[key])
123
+ continue;
124
+ switch (key) {
125
+ case 'hideInfo':
126
+ const infos = zOpts.hideInfo;
127
+ infos.forEach((info) => {
128
+ for (const obj of collectionData) {
129
+ if (!Reflect.has(obj, info))
130
+ continue;
131
+ Reflect.deleteProperty(obj, info);
132
+ }
133
+ });
134
+ break;
135
+ }
136
+ }
137
+ }
138
+ return collectionData;
139
+ }
140
+ catch (err) {
141
+ return (0, Error_1.errorMessage)(err);
142
+ }
143
+ }
144
+ find(options) {
145
+ try {
146
+ if (arguments.length > 1)
147
+ throw TypeError('Invalid params');
148
+ const optionsSchema = zod_1.default.object({
149
+ where: zod_1.default.function(),
150
+ hideInfo: zod_1.default.array(zod_1.default.string()).optional(),
151
+ });
152
+ const { where, ...opts } = optionsSchema.parse(options);
153
+ const collectionData = this.#getCollectionData();
154
+ const output = [];
155
+ for (const obj of collectionData) {
156
+ if (where.call(undefined, obj)) {
157
+ if (opts && Object.values(opts).length > 0) {
158
+ const keys = Object.keys(opts);
159
+ for (const key of keys) {
160
+ switch (key) {
161
+ case 'hideInfo':
162
+ const infos = opts.hideInfo;
163
+ infos.forEach((info) => Reflect.deleteProperty(obj, info));
164
+ break;
165
+ }
166
+ }
167
+ }
168
+ output.push(obj);
169
+ }
170
+ }
171
+ return output;
172
+ }
173
+ catch (err) {
174
+ return (0, Error_1.errorMessage)(err);
175
+ }
176
+ }
177
+ update(options) {
178
+ try {
179
+ if (arguments.length > 1)
180
+ throw TypeError('Invalid params');
181
+ const optionsSchema = zod_1.default.object({
182
+ where: zod_1.default.function(),
183
+ values: zod_1.default.record(zod_1.default.string(), zod_1.default.any()),
184
+ });
185
+ const { where, values } = optionsSchema.parse(options);
186
+ const collectionData = this.#getCollectionData();
187
+ const output = [];
188
+ for (const obj of collectionData) {
189
+ if (where.call(undefined, obj)) {
190
+ const tempId = obj._zid;
191
+ Reflect.deleteProperty(obj, '_zid');
192
+ Object.assign(obj, {
193
+ ...obj,
194
+ ...values,
195
+ _zid: tempId
196
+ });
197
+ output.push(obj);
198
+ }
199
+ }
200
+ if (output.length === 0)
201
+ throw Error('Data not found');
202
+ this.#setCollectionData(collectionData);
203
+ return output;
204
+ }
205
+ catch (err) {
206
+ return (0, Error_1.errorMessage)(err);
207
+ }
208
+ }
209
+ delete(options) {
210
+ try {
211
+ if (arguments.length > 1)
212
+ throw TypeError('Invalid params');
213
+ const optionsSchema = zod_1.default.object({
214
+ where: zod_1.default.function(),
215
+ });
216
+ const { where } = optionsSchema.parse(options);
217
+ const collectionData = this.#getCollectionData();
218
+ const dataPostDelete = collectionData.filter((obj) => !where(obj));
219
+ if (collectionData.length === dataPostDelete.length)
220
+ return;
221
+ this.#setCollectionData(dataPostDelete);
222
+ }
223
+ catch (err) {
224
+ return (0, Error_1.errorMessage)(err);
225
+ }
226
+ }
227
+ reset() {
228
+ try {
229
+ this.#load();
230
+ const arr = [];
231
+ this.#setCollectionData(arr);
232
+ }
233
+ catch (err) {
234
+ return (0, Error_1.errorMessage)(err);
235
+ }
236
+ }
237
+ drop() {
238
+ (0, fs_1.unlinkSync)(this.#path);
239
+ }
240
+ }
241
+ exports.Collection = Collection;
242
+ //# sourceMappingURL=Collection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Collection.js","sourceRoot":"","sources":["../src/Collection.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAoF;AACpF,8CAAoB;AACpB,mCAAuC;AAevC,MAAa,UAAU;IAKU;IAJpB,KAAK,CAAQ;IACb,KAAK,CAAQ;IACtB,QAAQ,GAAG,EAAuB,CAAA;IAElC,YAA6B,KAAsB;QAAtB,UAAK,GAAL,KAAK,CAAiB;QAC/C,MAAM,aAAa,GAAG,OAAO,CAAA;QAC7B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,KAAK,CAAA;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,KAAK,GAAG,GAAG,IAAI,KAAK,IAAI,GAAG,aAAa,EAAE,CAAA;QAC/C,IAAI,CAAC,KAAK,EAAE,CAAA;IAChB,CAAC;IAED,KAAK;QACD,IAAI,CAAC;YACD,IAAA,eAAU,EAAC,IAAI,CAAC,KAAK,EAAE,cAAS,CAAC,IAAI,CAAC,CAAA;YACtC,MAAM,aAAa,GAAG,IAAA,iBAAY,EAAC,IAAI,CAAC,KAAK,EAAE;gBAC3C,QAAQ,EAAE,OAAO;aACpB,CAAC,CAAA;YACF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;Q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3B,KAAK,EAAE,aAAC,CAAC,QAAQ,EAAE;aACtB,CAAC,CAAA;YACF,MAAM,EAAE,KAAK,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,CAAqB,CAAA;YAClE,MAAM,cAAc,GAAG,IAAI,CAAC,kBAAkB,EAAS,CAAA;YACvD,MAAM,cAAc,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,GAAgB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAA4B,CAAA;YAC1G,IAAI,cAAc,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM;gBAAE,OAAM;YAC3D,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAA;QAC3C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,IAAA,oBAAY,EAAC,GAAG,CAAC,CAAA;QAC5B,CAAC;IACL,CAAC;IAED,KAAK;QACD,IAAI,CAAC;YACD,IAAI,CAAC,KAAK,EAAE,CAAA;YACZ,MAAM,GAAG,GAAG,EAA6B,CAAA;YACzC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAA;QAChC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,IAAA,oBAAY,EAAC,GAAG,CAAC,CAAA;QAC5B,CAAC;IACL,CAAC;IAED,IAAI;QACA,IAAA,eAAU,EAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;CACJ;AAjOD,gCAiOC"}
package/lib/Error.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare function errorMessage(err: any): {
2
+ error: any;
3
+ };
package/lib/Error.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorMessage = errorMessage;
4
+ const zod_1 = require("zod");
5
+ function errorMessage(err) {
6
+ if (err instanceof zod_1.ZodError) {
7
+ const error = err.errors.at(-1);
8
+ return {
9
+ error: error?.message
10
+ };
11
+ }
12
+ else {
13
+ return {
14
+ error: err.message
15
+ };
16
+ }
17
+ }
18
+ //# sourceMappingURL=Error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Error.js","sourceRoot":"","sources":["../src/Error.ts"],"names":[],"mappings":";;AAEA,oCAWC;AAbD,6BAA8B;AAE9B,SAAgB,YAAY,CAAC,GAAQ;IACjC,IAAI,GAAG,YAAY,cAAQ,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;QAC/B,OAAO;YACH,KAAK,EAAE,KAAK,EAAE,OAAO;SACxB,CAAA;IACL,CAAC;SAAM,CAAC;QACJ,OAAO;YACH,KAAK,EAAE,GAAG,CAAC,OAAO;SACrB,CAAA;IACL,CAAC;AACL,CAAC"}
package/lib/Klauz.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { Collection } from "./Collection";
2
+ import { KlauzProps } from "./Types";
3
+ export declare class KlauzDB {
4
+ path: string;
5
+ constructor(props: KlauzProps);
6
+ createCollection(collectionName: string): Collection;
7
+ }
package/lib/Klauz.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.KlauzDB = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const Collection_1 = require("./Collection.js");
9
+ class KlauzDB {
10
+ path = '';
11
+ constructor(props) {
12
+ const schema = zod_1.default.object({
13
+ path: zod_1.default.string().min(1)
14
+ });
15
+ const { path } = schema.parse(props);
16
+ this.path = path;
17
+ }
18
+ createCollection(collectionName) {
19
+ const schema = zod_1.default.string().min(1);
20
+ const name = schema.parse(collectionName);
21
+ const collection = new Collection_1.Collection({
22
+ name,
23
+ path: this.path
24
+ });
25
+ return collection;
26
+ }
27
+ }
28
+ exports.KlauzDB = KlauzDB;
29
+ //# sourceMappingURL=Klauz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Klauz.js","sourceRoot":"","sources":["../src/Klauz.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAoB;AACpB,6CAA0C;AAG1C,MAAa,OAAO;IACT,IAAI,GAAW,EAAE,CAAA;IAExB,YAAY,KAAiB;QACzB,MAAM,MAAM,GAAG,aAAC,CAAC,MAAM,CAAC;YACpB,IAAI,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;SAC1B,CAAC,CAAA;QACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACpB,CAAC;IAED,gBAAgB,CAAC,cAAsB;QACnC,MAAM,MAAM,GAAG,aAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QAChC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;QACzC,MAAM,UAAU,GAAG,IAAI,uBAAU,CAAC;YAC9B,IAAI;YACJ,IAAI,EAAE,IAAI,CAAC,IAAI;SAClB,CAAC,CAAA;QACF,OAAO,UAAU,CAAA;IACrB,CAAC;CACJ;AApBD,0BAoBC"}
package/lib/Types.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ export type ZID = number;
2
+ export type CollectionProps = {
3
+ path: string;
4
+ name: string;
5
+ };
6
+ export type CollectionContent = {
7
+ collection_name: string;
8
+ created_at: string;
9
+ last_interaction: string;
10
+ data: Array<CollectionDataWithZID>;
11
+ };
12
+ export type CollectionData = Record<string, any>;
13
+ export type CollectionDataWithZID = {
14
+ [K in keyof CollectionData]: CollectionData[K];
15
+ } & {
16
+ _zid?: ZID;
17
+ };
18
+ export type KlauzProps = {
19
+ path: string;
20
+ };
21
+ type ErrorPayload = {
22
+ error: string;
23
+ };
24
+ export type Output<T> = T | ErrorPayload;
25
+ export type KzObject<T> = T & {
26
+ _zid: ZID;
27
+ };
28
+ export type Callback<T> = (obj: T) => any;
29
+ export type FindOptions<T> = {
30
+ where: Callback<T>;
31
+ hideInfo?: Array<string>;
32
+ };
33
+ export type FindOptionsWithoutWhere = Omit<FindOptions<any>, "where">;
34
+ export type UpdateOptions<T> = {
35
+ where: Callback<T>;
36
+ values?: CollectionData;
37
+ };
38
+ export type DeleteOptions<T> = {
39
+ where: Callback<T>;
40
+ };
41
+ export {};
package/lib/Types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Types.js","sourceRoot":"","sources":["../src/Types.ts"],"names":[],"mappings":""}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './Klauz';
2
+ export * from './Types';
package/lib/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Klauz.js"), exports);
18
+ __exportStar(require("./Types.js"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,0CAAuB"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "klauz-db",
3
+ "version": "0.2.0",
4
+ "description": "Um banco de dados simples, para aplicações com um grau menor de complexidade",
5
+ "main": "lib/index.js",
6
+ "scripts": {
7
+ "dev": "tsx watch --env-file .env src/client",
8
+ "build": "tsc",
9
+ "test-errors": "tsx --env-file .env tests/test-errors.ts",
10
+ "test": "jest && npm run test-errors",
11
+ "prepublish": "npm run test && npm run build"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/vnikolaus/KlauzDB.git"
16
+ },
17
+ "author": "Victor Nikolaus",
18
+ "license": "MIT",
19
+ "bugs": {
20
+ "url": "https://github.com/vnikolaus/KlauzDB/issues"
21
+ },
22
+ "homepage": "https://github.com/vnikolaus/KlauzDB#readme",
23
+ "jest": {
24
+ "preset": "ts-jest",
25
+ "testEnvironment": "node",
26
+ "setupFiles": [
27
+ "dotenv/config"
28
+ ],
29
+ "coveragePathIgnorePatterns": [
30
+ "/node_modules/",
31
+ "lib"
32
+ ]
33
+ },
34
+ "files": [
35
+ "lib/**/*"
36
+ ],
37
+ "devDependencies": {
38
+ "@types/jest": "29.5.12",
39
+ "@types/node": "20.14.11",
40
+ "jest": "29.7.0",
41
+ "ts-jest": "29.2.3",
42
+ "tsx": "4.16.2",
43
+ "typescript": "5.5.3"
44
+ },
45
+ "dependencies": {
46
+ "dotenv": "^16.4.5",
47
+ "zod": "3.23.8"
48
+ }
49
+ }