@onurege3467/zerohelper 10.2.6 → 11.0.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.
Files changed (79) hide show
  1. package/README.md +9 -704
  2. package/dist/index.js +19 -44
  3. package/package.json +21 -70
  4. package/dist/bin/commands/cache.d.ts +0 -2
  5. package/dist/bin/commands/cache.js +0 -92
  6. package/dist/bin/commands/db-backup.d.ts +0 -3
  7. package/dist/bin/commands/db-backup.js +0 -118
  8. package/dist/bin/commands/db.d.ts +0 -2
  9. package/dist/bin/commands/db.js +0 -334
  10. package/dist/bin/commands/import-export.d.ts +0 -3
  11. package/dist/bin/commands/import-export.js +0 -123
  12. package/dist/bin/commands/init.d.ts +0 -2
  13. package/dist/bin/commands/init.js +0 -85
  14. package/dist/bin/commands/migrate.d.ts +0 -3
  15. package/dist/bin/commands/migrate.js +0 -167
  16. package/dist/bin/commands/repl.d.ts +0 -2
  17. package/dist/bin/commands/repl.js +0 -96
  18. package/dist/bin/commands/seed.d.ts +0 -2
  19. package/dist/bin/commands/seed.js +0 -76
  20. package/dist/bin/commands/zpack.d.ts +0 -2
  21. package/dist/bin/commands/zpack.js +0 -36
  22. package/dist/bin/index.d.ts +0 -2
  23. package/dist/bin/index.js +0 -28
  24. package/dist/bin/types.d.ts +0 -22
  25. package/dist/bin/types.js +0 -2
  26. package/dist/bin/utils/config.d.ts +0 -3
  27. package/dist/bin/utils/config.js +0 -78
  28. package/dist/bin/utils/prompts.d.ts +0 -3
  29. package/dist/bin/utils/prompts.js +0 -115
  30. package/dist/bin/zero.d.ts +0 -2
  31. package/dist/bin/zero.js +0 -849
  32. package/dist/database/IDatabase.d.ts +0 -71
  33. package/dist/database/IDatabase.js +0 -48
  34. package/dist/database/cacheWrapper.d.ts +0 -34
  35. package/dist/database/cacheWrapper.js +0 -214
  36. package/dist/database/index.d.ts +0 -12
  37. package/dist/database/index.js +0 -100
  38. package/dist/database/json.d.ts +0 -32
  39. package/dist/database/json.js +0 -208
  40. package/dist/database/migration.d.ts +0 -21
  41. package/dist/database/migration.js +0 -97
  42. package/dist/database/mongodb.d.ts +0 -26
  43. package/dist/database/mongodb.js +0 -145
  44. package/dist/database/mysql.d.ts +0 -29
  45. package/dist/database/mysql.js +0 -282
  46. package/dist/database/pg.d.ts +0 -28
  47. package/dist/database/pg.js +0 -200
  48. package/dist/database/redis.d.ts +0 -31
  49. package/dist/database/redis.js +0 -176
  50. package/dist/database/seeder.d.ts +0 -20
  51. package/dist/database/seeder.js +0 -37
  52. package/dist/database/sqlite.d.ts +0 -26
  53. package/dist/database/sqlite.js +0 -211
  54. package/dist/database/telemetry.d.ts +0 -35
  55. package/dist/database/telemetry.js +0 -41
  56. package/dist/database/toon.d.ts +0 -33
  57. package/dist/database/toon.js +0 -244
  58. package/dist/database/types.d.ts +0 -71
  59. package/dist/database/types.js +0 -2
  60. package/dist/database/zpack.d.ts +0 -75
  61. package/dist/database/zpack.js +0 -616
  62. package/dist/functions/index.d.ts +0 -199
  63. package/dist/functions/index.js +0 -682
  64. package/dist/functions/security.d.ts +0 -15
  65. package/dist/functions/security.js +0 -46
  66. package/dist/functions/toon.d.ts +0 -10
  67. package/dist/functions/toon.js +0 -214
  68. package/dist/functions/worker.d.ts +0 -5
  69. package/dist/functions/worker.js +0 -35
  70. package/dist/index.d.ts +0 -8
  71. package/dist/migrations/1767521950635_test_migration.d.ts +0 -3
  72. package/dist/migrations/1767521950635_test_migration.js +0 -11
  73. package/dist/migrations/1767522158826_create_users_table.d.ts +0 -2
  74. package/dist/migrations/1767522158826_create_users_table.js +0 -11
  75. package/dist/package.json +0 -79
  76. package/dist/tests/test.d.ts +0 -1
  77. package/dist/tests/test.js +0 -26
  78. package/dist/zero.config.d.ts +0 -10
  79. package/dist/zero.config.js +0 -13
@@ -1,244 +0,0 @@
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.ToonDatabase = void 0;
7
- const IDatabase_1 = require("./IDatabase");
8
- const promises_1 = __importDefault(require("fs/promises"));
9
- const fs_1 = require("fs");
10
- const path_1 = __importDefault(require("path"));
11
- const toon_1 = require("../functions/toon");
12
- class ToonDatabase extends IDatabase_1.IDatabase {
13
- constructor(config) {
14
- super();
15
- this.db = {};
16
- this.isDirty = false;
17
- this.isWriting = false;
18
- this.writeQueue = [];
19
- this.saveDebounceTimeout = null;
20
- if (!config || !config.path)
21
- throw new Error('ToonDB: "path" gereklidir.');
22
- this.filePath = config.path;
23
- this.saveInterval = config.saveInterval || 500;
24
- process.on('exit', () => this.flushSync());
25
- this.initPromise = this._load();
26
- }
27
- async _execute(op, table, fn) {
28
- const start = Date.now();
29
- const res = await fn();
30
- this.recordMetric(op, table, Date.now() - start);
31
- return res;
32
- }
33
- async _load() {
34
- try {
35
- const dir = path_1.default.dirname(this.filePath);
36
- if (!(0, fs_1.existsSync)(dir))
37
- await promises_1.default.mkdir(dir, { recursive: true });
38
- if (!(0, fs_1.existsSync)(this.filePath)) {
39
- this.db = {};
40
- await this._saveNow();
41
- return;
42
- }
43
- const content = await promises_1.default.readFile(this.filePath, 'utf-8');
44
- const parsed = (0, toon_1.parse)(content);
45
- if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
46
- this.db = {};
47
- }
48
- else {
49
- this.db = {};
50
- for (const [key, value] of Object.entries(parsed)) {
51
- this.db[key] = Array.isArray(value) ? value : [];
52
- }
53
- }
54
- }
55
- catch (error) {
56
- console.error("ToonDB load error:", error);
57
- this.db = {};
58
- }
59
- }
60
- _getTable(table) {
61
- const data = this.db[table];
62
- return Array.isArray(data) ? data : [];
63
- }
64
- _queueRequest(operation) {
65
- return new Promise((resolve, reject) => {
66
- this.writeQueue.push({ operation, resolve, reject });
67
- this._processQueue();
68
- });
69
- }
70
- async _processQueue() {
71
- if (this.isWriting || this.writeQueue.length === 0)
72
- return;
73
- this.isWriting = true;
74
- const item = this.writeQueue.shift();
75
- if (item) {
76
- try {
77
- const result = item.operation();
78
- this.isDirty = true;
79
- this._scheduleSave();
80
- item.resolve(result);
81
- }
82
- catch (error) {
83
- item.reject(error);
84
- }
85
- finally {
86
- this.isWriting = false;
87
- this._processQueue();
88
- }
89
- }
90
- }
91
- _scheduleSave() {
92
- if (this.saveDebounceTimeout)
93
- clearTimeout(this.saveDebounceTimeout);
94
- this.saveDebounceTimeout = setTimeout(() => this._saveNow(), this.saveInterval);
95
- }
96
- async _saveNow() {
97
- if (!this.isDirty)
98
- return;
99
- if (this.saveDebounceTimeout)
100
- clearTimeout(this.saveDebounceTimeout);
101
- this.saveDebounceTimeout = null;
102
- try {
103
- await promises_1.default.writeFile(this.filePath, (0, toon_1.stringify)(this.db));
104
- this.isDirty = false;
105
- }
106
- catch (error) {
107
- console.error("ToonDB save error:", error);
108
- }
109
- }
110
- flushSync() {
111
- if (this.isDirty) {
112
- try {
113
- (0, fs_1.writeFileSync)(this.filePath, (0, toon_1.stringify)(this.db));
114
- this.isDirty = false;
115
- }
116
- catch (error) { }
117
- }
118
- }
119
- async ensureTable(table) {
120
- await this.initPromise;
121
- if (!Array.isArray(this.db[table])) {
122
- return this._queueRequest(() => {
123
- this.db[table] = [];
124
- });
125
- }
126
- }
127
- async insert(table, data) {
128
- await this.runHooks('beforeInsert', table, data);
129
- return this._execute('insert', table, async () => {
130
- await this.ensureTable(table);
131
- return this._queueRequest(() => {
132
- const tableData = this._getTable(table);
133
- const maxId = tableData.reduce((max, row) => (row._id > max ? row._id : max), 0);
134
- const newId = maxId + 1;
135
- const newRow = { _id: newId, ...data };
136
- this.db[table].push(newRow);
137
- this.runHooks('afterInsert', table, newRow);
138
- return newId;
139
- });
140
- });
141
- }
142
- async update(table, data, where) {
143
- await this.runHooks('beforeUpdate', table, { data, where });
144
- return this._execute('update', table, async () => {
145
- await this.ensureTable(table);
146
- return this._queueRequest(() => {
147
- let affected = 0;
148
- const tableData = this._getTable(table);
149
- tableData.forEach(row => {
150
- if (Object.keys(where).every(k => String(row[k]) === String(where[k]))) {
151
- Object.assign(row, data);
152
- affected++;
153
- }
154
- });
155
- this.runHooks('afterUpdate', table, { affected });
156
- return affected;
157
- });
158
- });
159
- }
160
- async delete(table, where) {
161
- await this.runHooks('beforeDelete', table, where);
162
- return this._execute('delete', table, async () => {
163
- await this.ensureTable(table);
164
- return this._queueRequest(() => {
165
- const tableData = this._getTable(table);
166
- const initial = tableData.length;
167
- this.db[table] = tableData.filter(row => !Object.keys(where).every(k => String(row[k]) === String(where[k])));
168
- const affected = initial - this.db[table].length;
169
- this.runHooks('afterDelete', table, { affected });
170
- return affected;
171
- });
172
- });
173
- }
174
- async select(table, where = null) {
175
- return this._execute('select', table, async () => {
176
- await this.initPromise;
177
- const tableData = this._getTable(table);
178
- const results = where && Object.keys(where).length > 0
179
- ? tableData.filter(row => Object.keys(where).every(k => String(row[k]) === String(where[k])))
180
- : tableData;
181
- return JSON.parse(JSON.stringify(results));
182
- });
183
- }
184
- async selectOne(table, where = null) {
185
- const res = await this.select(table, where);
186
- return res[0] || null;
187
- }
188
- async set(table, data, where) {
189
- await this.initPromise;
190
- await this.ensureTable(table);
191
- const ex = await this.selectOne(table, where);
192
- if (ex) {
193
- // Kayıt varsa güncelle
194
- await this.update(table, data, where);
195
- return ex._id;
196
- }
197
- else {
198
- // Kayıt yoksa ekle
199
- return this.insert(table, { ...where, ...data });
200
- }
201
- }
202
- async bulkInsert(table, dataArray) {
203
- return this._execute('bulkInsert', table, async () => {
204
- if (!dataArray.length)
205
- return 0;
206
- await this.ensureTable(table);
207
- return this._queueRequest(() => {
208
- const tableData = this._getTable(table);
209
- let maxId = tableData.reduce((max, row) => (row._id > max ? row._id : max), 0);
210
- dataArray.forEach(data => {
211
- maxId++;
212
- this.db[table].push({ _id: maxId, ...data });
213
- });
214
- return dataArray.length;
215
- });
216
- });
217
- }
218
- async increment(table, incs, where = {}) {
219
- return this._execute('increment', table, async () => {
220
- await this.ensureTable(table);
221
- return this._queueRequest(() => {
222
- let affected = 0;
223
- const tableData = this._getTable(table);
224
- tableData.forEach(row => {
225
- if (Object.keys(where).every(k => String(row[k]) === String(where[k]))) {
226
- for (const [f, v] of Object.entries(incs))
227
- row[f] = (Number(row[f]) || 0) + v;
228
- affected++;
229
- }
230
- });
231
- return affected;
232
- });
233
- });
234
- }
235
- async decrement(table, decs, where = {}) {
236
- const incs = {};
237
- for (const k in decs)
238
- incs[k] = -decs[k];
239
- return this.increment(table, incs, where);
240
- }
241
- async close() { await this._saveNow(); }
242
- }
243
- exports.ToonDatabase = ToonDatabase;
244
- exports.default = ToonDatabase;
@@ -1,71 +0,0 @@
1
- export interface BaseConfig {
2
- cache?: CacheConfig;
3
- }
4
- export interface NetworkConfig extends BaseConfig {
5
- host?: string;
6
- port?: number;
7
- username?: string;
8
- password?: string;
9
- database?: string;
10
- url?: string;
11
- uri?: string;
12
- poolSize?: number;
13
- }
14
- export interface FileConfig extends BaseConfig {
15
- path: string;
16
- }
17
- export interface MySQLConfig extends NetworkConfig {
18
- }
19
- export interface PostgreSQLConfig extends NetworkConfig {
20
- }
21
- export interface SQLiteConfig extends FileConfig {
22
- }
23
- export interface MongoDBConfig extends NetworkConfig {
24
- }
25
- export interface RedisConfig extends NetworkConfig {
26
- keyPrefix?: string;
27
- }
28
- export interface JsonConfig extends FileConfig {
29
- saveInterval?: number;
30
- }
31
- export interface ZPackConfig extends FileConfig {
32
- autoFlush?: boolean;
33
- indexFields?: Record<string, string[]>;
34
- }
35
- export interface ToonConfig extends FileConfig {
36
- saveInterval?: number;
37
- }
38
- export interface CacheConfig {
39
- type: 'memory' | 'redis';
40
- ttl?: number;
41
- max?: number;
42
- host?: string;
43
- port?: number;
44
- password?: string;
45
- }
46
- export type DatabaseOptions = {
47
- adapter: 'mysql';
48
- config: MySQLConfig;
49
- } | {
50
- adapter: 'sqlite';
51
- config: SQLiteConfig;
52
- } | {
53
- adapter: 'mongodb';
54
- config: MongoDBConfig;
55
- } | {
56
- adapter: 'postgres';
57
- config: PostgreSQLConfig;
58
- } | {
59
- adapter: 'json';
60
- config: JsonConfig;
61
- } | {
62
- adapter: 'redis';
63
- config: RedisConfig;
64
- } | {
65
- adapter: 'zpack';
66
- config: ZPackConfig;
67
- } | {
68
- adapter: 'toon';
69
- config: ToonConfig;
70
- };
71
- export type AdapterType = DatabaseOptions['adapter'];
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,75 +0,0 @@
1
- import { IDatabase } from './IDatabase';
2
- import { ZPackConfig } from './types';
3
- /**
4
- * ZPackDatabase: Low-level Binary Storage
5
- */
6
- export declare class ZPackDatabase {
7
- filePath: string;
8
- private fd;
9
- private fileSize;
10
- private index;
11
- private deleted;
12
- private version;
13
- private _nextId;
14
- private _writeQueue;
15
- private _closed;
16
- private _autoFlush;
17
- private _contentEnd;
18
- private _compression;
19
- constructor(filePath: string, options?: {
20
- autoFlush?: boolean;
21
- compression?: boolean;
22
- });
23
- open(): Promise<void>;
24
- close(): Promise<void>;
25
- vacuum(): Promise<void>;
26
- insert(document: Record<string, any>, docId?: number): Promise<number>;
27
- insertBatch(documents: Record<string, any>[]): Promise<number[]>;
28
- delete(docId: number): Promise<void>;
29
- get(docId: number): Promise<Record<string, any> | null>;
30
- keys(): number[];
31
- private _ensureOpen;
32
- private _enqueue;
33
- private _internalWriteFooter;
34
- private _writeFooter;
35
- private _encodeDocument;
36
- private _decodeDocument;
37
- private _encodeTombstone;
38
- private _peekDocMeta;
39
- private _tryLoadIndexFromFooter;
40
- private _scanAndRebuildIndex;
41
- }
42
- /**
43
- * ZPackAdapter: IDatabase Implementation
44
- */
45
- export declare class ZPackAdapter extends IDatabase {
46
- private db;
47
- private initPromise;
48
- private tableMaxId;
49
- private keyIndex;
50
- private rowCache;
51
- private secondary;
52
- private indexedFields;
53
- private _isClosing;
54
- private _executing;
55
- constructor(config: ZPackConfig);
56
- private _init;
57
- private _execute;
58
- private _rawSelect;
59
- ensureTable(table: string): Promise<void>;
60
- private _updateSecondaryIndex;
61
- private _coerce;
62
- private _matches;
63
- select<T = any>(table: string, where?: Record<string, any> | null): Promise<T[]>;
64
- selectOne<T = any>(table: string, where?: Record<string, any> | null): Promise<T | null>;
65
- insert(table: string, data: Record<string, any>): Promise<number>;
66
- update(table: string, data: Record<string, any>, where: Record<string, any>): Promise<number>;
67
- delete(table: string, where: Record<string, any>): Promise<number>;
68
- set(table: string, data: Record<string, any>, where: Record<string, any>): Promise<any>;
69
- bulkInsert(table: string, dataArray: Record<string, any>[]): Promise<number>;
70
- increment(table: string, incs: Record<string, number>, where?: Record<string, any>): Promise<number>;
71
- decrement(table: string, decs: Record<string, number>, where?: Record<string, any>): Promise<number>;
72
- vacuum(): Promise<void>;
73
- close(): Promise<void>;
74
- }
75
- export default ZPackAdapter;