silgi 0.28.4 → 0.28.6
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/cli/index.mjs +1 -1
- package/dist/kit/index.d.mts +112 -2
- package/dist/kit/index.mjs +321 -4
- package/package.json +2 -1
package/dist/cli/index.mjs
CHANGED
package/dist/kit/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, SilgiTemplate, ResolvedSilgiTemplate, SilgiEvents } from 'silgi/types';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
3
|
import { ConsolaOptions, ConsolaInstance } from 'consola';
|
|
4
|
+
import * as rfc6902 from 'rfc6902';
|
|
4
5
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
6
|
|
|
6
7
|
declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
|
|
@@ -53,6 +54,115 @@ declare function isH3(): boolean;
|
|
|
53
54
|
|
|
54
55
|
declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): ConsolaInstance;
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Migration bilgisi
|
|
59
|
+
*/
|
|
60
|
+
interface MigrationInfo {
|
|
61
|
+
/** Migration zaman damgası */
|
|
62
|
+
timestamp: number;
|
|
63
|
+
/** Migration dosya adı */
|
|
64
|
+
file: string;
|
|
65
|
+
/** Migration oluşturulma tarihi */
|
|
66
|
+
created: string;
|
|
67
|
+
/** Migration açıklaması */
|
|
68
|
+
description?: string;
|
|
69
|
+
/** Patch formatında mı? */
|
|
70
|
+
isPatch?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* İzin migration verisi
|
|
74
|
+
*/
|
|
75
|
+
interface MigrationData {
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* JSON Patch formatı (RFC6902)
|
|
79
|
+
*/
|
|
80
|
+
type JsonPatch = Array<rfc6902.Operation>;
|
|
81
|
+
/**
|
|
82
|
+
* Migration durumu
|
|
83
|
+
*/
|
|
84
|
+
declare enum MigrationStatus {
|
|
85
|
+
SUCCESS = "success",
|
|
86
|
+
ERROR = "error",
|
|
87
|
+
SKIPPED = "skipped"
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Migration options
|
|
91
|
+
*/
|
|
92
|
+
interface MigrationOptions {
|
|
93
|
+
/** Migration açıklaması (opsiyonel) */
|
|
94
|
+
description?: string;
|
|
95
|
+
/** Değişiklikler için log göster */
|
|
96
|
+
verbose?: boolean;
|
|
97
|
+
/** JSON dosyasını pretty-print formatında kaydet */
|
|
98
|
+
prettyPrint?: boolean;
|
|
99
|
+
/** Patch formatını kullanmalı mı? */
|
|
100
|
+
usePatch?: boolean;
|
|
101
|
+
/** Değişiklik yoksa dosya oluşturma */
|
|
102
|
+
skipIfNoChanges?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Migration başlatma sonucu
|
|
106
|
+
*/
|
|
107
|
+
interface MigrationResult {
|
|
108
|
+
/** İşlem başarılı mı? */
|
|
109
|
+
success: boolean;
|
|
110
|
+
/** Migration durumu */
|
|
111
|
+
status: MigrationStatus;
|
|
112
|
+
/** Migration dosya yolu (başarılıysa) */
|
|
113
|
+
filePath?: string;
|
|
114
|
+
/** Migration zaman damgası (başarılıysa) */
|
|
115
|
+
timestamp?: number;
|
|
116
|
+
/** Hata mesajı (başarısızsa) */
|
|
117
|
+
error?: string;
|
|
118
|
+
/** Patch türünde mi? */
|
|
119
|
+
isPatch?: boolean;
|
|
120
|
+
/** Migration verisi */
|
|
121
|
+
data?: MigrationData[] | JsonPatch;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Migration oluşturur
|
|
125
|
+
*
|
|
126
|
+
* @param data Migration verisi
|
|
127
|
+
* @param directoryPath Migration dizini
|
|
128
|
+
* @param fileNamePrefix Dosya adı öneki
|
|
129
|
+
* @param options Migration seçenekleri
|
|
130
|
+
* @returns Migration sonucu
|
|
131
|
+
*/
|
|
132
|
+
declare function generateMigration<T>(data: T, directoryPath: string, fileNamePrefix?: string, options?: MigrationOptions): Promise<MigrationResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Belirli bir migration dosyasının bilgilerini alır
|
|
135
|
+
*
|
|
136
|
+
* @param migrationsDir Migration dizini
|
|
137
|
+
* @param fileName Dosya adı (belirtilmezse son migration dosyası)
|
|
138
|
+
* @returns Migration bilgileri ve verisi
|
|
139
|
+
*/
|
|
140
|
+
declare function getMigration(migrationsDir: string, fileName?: string): Promise<MigrationResult>;
|
|
141
|
+
/**
|
|
142
|
+
* Tüm migration dosyalarını listeler
|
|
143
|
+
*
|
|
144
|
+
* @param migrationsDir Migration dizini
|
|
145
|
+
* @param filePrefix Dosya adı öneki filtreleme (opsiyonel)
|
|
146
|
+
* @returns Migration listesi
|
|
147
|
+
*/
|
|
148
|
+
declare function listMigrations(migrationsDir: string, filePrefix?: string): Promise<MigrationInfo[]>;
|
|
149
|
+
/**
|
|
150
|
+
* Migration'ları ileri uygular (son duruma getirir)
|
|
151
|
+
*
|
|
152
|
+
* @param migrationsDir Migration dizini
|
|
153
|
+
* @param targetTimestamp Hedef zaman damgası (belirtilmezse son migration'a kadar)
|
|
154
|
+
* @returns Migration sonucu
|
|
155
|
+
*/
|
|
156
|
+
declare function migrationUp(migrationsDir: string, targetTimestamp?: number): Promise<MigrationResult>;
|
|
157
|
+
/**
|
|
158
|
+
* Migration'ları geri alır (belirtilen noktaya kadar veya bir önceki migration'a)
|
|
159
|
+
*
|
|
160
|
+
* @param migrationsDir Migration dizini
|
|
161
|
+
* @param targetTimestamp Hedef zaman damgası (belirtilmezse bir önceki migration'a döner)
|
|
162
|
+
* @returns Migration sonucu
|
|
163
|
+
*/
|
|
164
|
+
declare function migrationDown(migrationsDir: string, targetTimestamp?: number): Promise<MigrationResult>;
|
|
165
|
+
|
|
56
166
|
/**
|
|
57
167
|
* Define a Silgi module, automatically merging defaults with user provided options, installing
|
|
58
168
|
* any hooks that are provided, and calling an optional setup function for full control.
|
|
@@ -173,5 +283,5 @@ declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolea
|
|
|
173
283
|
declare const baseHeaderBannerComment: string[];
|
|
174
284
|
declare function processFilePath(src: string): string;
|
|
175
285
|
|
|
176
|
-
export { MODE_RE, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
177
|
-
export type { FunctionConfig };
|
|
286
|
+
export { MODE_RE, MigrationStatus, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory, isH3, isNitro, isNuxt, listMigrations, migrationDown, migrationUp, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
287
|
+
export type { FunctionConfig, JsonPatch, MigrationData, MigrationInfo, MigrationOptions, MigrationResult };
|
package/dist/kit/index.mjs
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { tryUseSilgiCLI, useSilgiCLI, useSilgi } from 'silgi';
|
|
2
2
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
3
3
|
import { resolvePath as resolvePath$1 } from 'mlly';
|
|
4
|
-
import fsp from 'node:fs/promises';
|
|
4
|
+
import fsp, { mkdir, readFile, writeFile as writeFile$1 } from 'node:fs/promises';
|
|
5
5
|
import consola, { consola as consola$1 } from 'consola';
|
|
6
|
-
import { relative, resolve, dirname, normalize, isAbsolute,
|
|
6
|
+
import { relative, resolve, dirname, join, normalize, isAbsolute, parse, basename } from 'pathe';
|
|
7
7
|
import { colors } from 'consola/utils';
|
|
8
8
|
import { getProperty } from 'dot-prop';
|
|
9
9
|
import { genString, genObjectFromRaw, genObjectFromValues, genObjectFromRawEntries } from 'knitwork';
|
|
10
10
|
import { hash as hash$1 } from 'ohash';
|
|
11
11
|
import { camelCase } from 'scule';
|
|
12
|
+
import { existsSync, promises } from 'node:fs';
|
|
13
|
+
import * as rfc6902 from 'rfc6902';
|
|
12
14
|
import { defu } from 'defu';
|
|
13
15
|
import { c as checkSilgiCompatibility } from '../cli/compatibility.mjs';
|
|
14
16
|
import { withLeadingSlash } from 'ufo';
|
|
15
|
-
import { existsSync, promises } from 'node:fs';
|
|
16
17
|
import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
|
|
17
18
|
import { hash as hash$2 } from 'silgi/kit';
|
|
18
19
|
import 'semver/functions/satisfies.js';
|
|
@@ -238,6 +239,322 @@ function useLogger(tag, options = {}) {
|
|
|
238
239
|
return tag ? logger.create(options).withTag(tag) : logger;
|
|
239
240
|
}
|
|
240
241
|
|
|
242
|
+
var MigrationStatus = /* @__PURE__ */ ((MigrationStatus2) => {
|
|
243
|
+
MigrationStatus2["SUCCESS"] = "success";
|
|
244
|
+
MigrationStatus2["ERROR"] = "error";
|
|
245
|
+
MigrationStatus2["SKIPPED"] = "skipped";
|
|
246
|
+
return MigrationStatus2;
|
|
247
|
+
})(MigrationStatus || {});
|
|
248
|
+
async function generateMigration(data, directoryPath, fileNamePrefix = "data_", options = {}) {
|
|
249
|
+
const {
|
|
250
|
+
description,
|
|
251
|
+
verbose = false,
|
|
252
|
+
prettyPrint = true,
|
|
253
|
+
usePatch = true,
|
|
254
|
+
skipIfNoChanges = true
|
|
255
|
+
} = options;
|
|
256
|
+
try {
|
|
257
|
+
try {
|
|
258
|
+
if (!existsSync(directoryPath)) {
|
|
259
|
+
await mkdir(directoryPath, { recursive: true });
|
|
260
|
+
}
|
|
261
|
+
} catch (error) {
|
|
262
|
+
return {
|
|
263
|
+
success: false,
|
|
264
|
+
status: "error" /* ERROR */,
|
|
265
|
+
error: `Dizin olu\u015Fturulamad\u0131: ${error}`
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const latestPath = join(directoryPath, "latest.json");
|
|
269
|
+
let existingData = null;
|
|
270
|
+
let hasChanges = true;
|
|
271
|
+
let patch = [];
|
|
272
|
+
if (existsSync(latestPath)) {
|
|
273
|
+
try {
|
|
274
|
+
const latestContent = await readFile(latestPath, "utf-8");
|
|
275
|
+
const latestInfo2 = JSON.parse(latestContent);
|
|
276
|
+
if (latestInfo2?.file) {
|
|
277
|
+
const existingFilePath = join(directoryPath, latestInfo2.file);
|
|
278
|
+
if (existsSync(existingFilePath)) {
|
|
279
|
+
const fileContent2 = await readFile(existingFilePath, "utf-8");
|
|
280
|
+
try {
|
|
281
|
+
if (latestInfo2.isPatch) {
|
|
282
|
+
const result = await migrationUp(directoryPath);
|
|
283
|
+
if (result.success && result.data) {
|
|
284
|
+
existingData = result.data;
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
existingData = JSON.parse(fileContent2);
|
|
288
|
+
}
|
|
289
|
+
if (existingData) {
|
|
290
|
+
patch = rfc6902.createPatch(existingData, data);
|
|
291
|
+
hasChanges = patch.length > 0;
|
|
292
|
+
if (verbose && hasChanges) {
|
|
293
|
+
console.warn("De\u011Fi\u015Fiklikler tespit edildi:", patch);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
} catch (err) {
|
|
297
|
+
console.warn(`Migration verisi i\u015Flenirken hata: ${err}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
} catch (error) {
|
|
302
|
+
console.warn(`Latest bilgisi okunamad\u0131: ${error}`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (!hasChanges && existingData !== null && skipIfNoChanges) {
|
|
306
|
+
if (verbose) {
|
|
307
|
+
console.warn("De\u011Fi\u015Fiklik yok, migration olu\u015Fturulmad\u0131.");
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
success: true,
|
|
311
|
+
status: "skipped" /* SKIPPED */
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
315
|
+
const isPatch = usePatch && patch.length > 0 && existingData !== null;
|
|
316
|
+
const fileName = `${fileNamePrefix}${isPatch ? "patch_" : ""}${timestamp}.json`;
|
|
317
|
+
const filePath = join(directoryPath, fileName);
|
|
318
|
+
const fileContent = isPatch ? patch : data;
|
|
319
|
+
const indent = prettyPrint ? 2 : 0;
|
|
320
|
+
await writeFile$1(filePath, JSON.stringify(fileContent, null, indent), "utf-8");
|
|
321
|
+
const latestInfo = {
|
|
322
|
+
timestamp,
|
|
323
|
+
file: fileName,
|
|
324
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
325
|
+
description,
|
|
326
|
+
isPatch
|
|
327
|
+
};
|
|
328
|
+
await writeFile$1(latestPath, JSON.stringify(latestInfo, null, indent), "utf-8");
|
|
329
|
+
if (verbose) {
|
|
330
|
+
console.warn(`Yeni ${isPatch ? "patch" : "tam veri"} migration olu\u015Fturuldu: ${fileName}`);
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
success: true,
|
|
334
|
+
status: "success" /* SUCCESS */,
|
|
335
|
+
filePath,
|
|
336
|
+
timestamp,
|
|
337
|
+
isPatch,
|
|
338
|
+
data: fileContent
|
|
339
|
+
};
|
|
340
|
+
} catch (error) {
|
|
341
|
+
return {
|
|
342
|
+
success: false,
|
|
343
|
+
status: "error" /* ERROR */,
|
|
344
|
+
error: `Migration olu\u015Fturma hatas\u0131: ${error instanceof Error ? error.message : String(error)}`
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
async function getMigration(migrationsDir, fileName) {
|
|
349
|
+
try {
|
|
350
|
+
if (!existsSync(migrationsDir)) {
|
|
351
|
+
return {
|
|
352
|
+
success: false,
|
|
353
|
+
status: "error" /* ERROR */,
|
|
354
|
+
error: `Migration dizini bulunamad\u0131: ${migrationsDir}`
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
if (!fileName) {
|
|
358
|
+
const latestPath = join(migrationsDir, "latest.json");
|
|
359
|
+
if (!existsSync(latestPath)) {
|
|
360
|
+
return {
|
|
361
|
+
success: false,
|
|
362
|
+
status: "error" /* ERROR */,
|
|
363
|
+
error: `Latest bilgisi bulunamad\u0131: ${latestPath}`
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
const latestContent = await readFile(latestPath, "utf-8");
|
|
367
|
+
const latestInfo = JSON.parse(latestContent);
|
|
368
|
+
fileName = latestInfo.file;
|
|
369
|
+
}
|
|
370
|
+
const migrationPath = join(migrationsDir, fileName);
|
|
371
|
+
if (!existsSync(migrationPath)) {
|
|
372
|
+
return {
|
|
373
|
+
success: false,
|
|
374
|
+
status: "error" /* ERROR */,
|
|
375
|
+
error: `Migration dosyas\u0131 bulunamad\u0131: ${migrationPath}`
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
const migrationContent = await readFile(migrationPath, "utf-8");
|
|
379
|
+
const data = JSON.parse(migrationContent);
|
|
380
|
+
const isPatch = fileName.includes("_patch_");
|
|
381
|
+
const timestampMatch = fileName.match(/(\d+)\.json$/);
|
|
382
|
+
const timestamp = timestampMatch ? Number.parseInt(timestampMatch[1]) : void 0;
|
|
383
|
+
return {
|
|
384
|
+
success: true,
|
|
385
|
+
status: "success" /* SUCCESS */,
|
|
386
|
+
filePath: migrationPath,
|
|
387
|
+
timestamp,
|
|
388
|
+
isPatch,
|
|
389
|
+
data
|
|
390
|
+
};
|
|
391
|
+
} catch (error) {
|
|
392
|
+
return {
|
|
393
|
+
success: false,
|
|
394
|
+
status: "error" /* ERROR */,
|
|
395
|
+
error: `Migration bilgileri al\u0131n\u0131rken hata: ${error instanceof Error ? error.message : String(error)}`
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
async function listMigrations(migrationsDir, filePrefix) {
|
|
400
|
+
try {
|
|
401
|
+
if (!existsSync(migrationsDir)) {
|
|
402
|
+
return [];
|
|
403
|
+
}
|
|
404
|
+
const { readdir } = await import('node:fs/promises');
|
|
405
|
+
const files = await readdir(migrationsDir);
|
|
406
|
+
const jsonFiles = files.filter((file) => file.endsWith(".json") && file !== "latest.json");
|
|
407
|
+
const filteredFiles = filePrefix ? jsonFiles.filter((file) => file.startsWith(filePrefix)) : jsonFiles;
|
|
408
|
+
return filteredFiles.map((file) => {
|
|
409
|
+
const isPatch = file.includes("_patch_");
|
|
410
|
+
const timestampMatch = file.match(/(\d+)\.json$/);
|
|
411
|
+
const timestamp = timestampMatch ? Number.parseInt(timestampMatch[1]) : 0;
|
|
412
|
+
return {
|
|
413
|
+
timestamp,
|
|
414
|
+
file,
|
|
415
|
+
created: "",
|
|
416
|
+
// Dosya içeriğinden çıkarılabilir ancak performans için boş bırakıldı
|
|
417
|
+
isPatch
|
|
418
|
+
};
|
|
419
|
+
}).sort((a, b) => a.timestamp - b.timestamp);
|
|
420
|
+
} catch (error) {
|
|
421
|
+
console.error(`Migration listesi al\u0131namad\u0131: ${error instanceof Error ? error.message : String(error)}`);
|
|
422
|
+
return [];
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
async function migrationUp(migrationsDir, targetTimestamp) {
|
|
426
|
+
try {
|
|
427
|
+
const migrations = await listMigrations(migrationsDir);
|
|
428
|
+
if (migrations.length === 0) {
|
|
429
|
+
return {
|
|
430
|
+
success: false,
|
|
431
|
+
status: "error" /* ERROR */,
|
|
432
|
+
error: "Migration bulunamad\u0131"
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
const targetMigrations = targetTimestamp ? migrations.filter((m) => m.timestamp <= targetTimestamp) : migrations;
|
|
436
|
+
if (targetMigrations.length === 0) {
|
|
437
|
+
return {
|
|
438
|
+
success: false,
|
|
439
|
+
status: "error" /* ERROR */,
|
|
440
|
+
error: "Belirtilen zaman damgas\u0131na kadar migration bulunamad\u0131"
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
const baseIndex = targetMigrations.findIndex((m) => !m.isPatch);
|
|
444
|
+
if (baseIndex === -1) {
|
|
445
|
+
return {
|
|
446
|
+
success: false,
|
|
447
|
+
status: "error" /* ERROR */,
|
|
448
|
+
error: "Tam veri migration bulunamad\u0131"
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
const baseMigration = await getMigration(
|
|
452
|
+
migrationsDir,
|
|
453
|
+
targetMigrations[baseIndex].file
|
|
454
|
+
);
|
|
455
|
+
if (!baseMigration.success || !baseMigration.data) {
|
|
456
|
+
return {
|
|
457
|
+
success: false,
|
|
458
|
+
status: "error" /* ERROR */,
|
|
459
|
+
error: `Temel veri al\u0131n\u0131rken hata: ${baseMigration.error || "Veri yok"}`
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
let currentData;
|
|
463
|
+
if (Array.isArray(baseMigration.data)) {
|
|
464
|
+
currentData = [...baseMigration.data];
|
|
465
|
+
} else {
|
|
466
|
+
try {
|
|
467
|
+
currentData = baseMigration.data ? JSON.parse(JSON.stringify(baseMigration.data)) : {};
|
|
468
|
+
} catch {
|
|
469
|
+
currentData = baseMigration.data;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
for (let i = baseIndex + 1; i < targetMigrations.length; i++) {
|
|
473
|
+
if (!targetMigrations[i].isPatch) {
|
|
474
|
+
const fullMigration = await getMigration(
|
|
475
|
+
migrationsDir,
|
|
476
|
+
targetMigrations[i].file
|
|
477
|
+
);
|
|
478
|
+
if (fullMigration.success && fullMigration.data) {
|
|
479
|
+
if (Array.isArray(fullMigration.data)) {
|
|
480
|
+
currentData = [...fullMigration.data];
|
|
481
|
+
} else {
|
|
482
|
+
try {
|
|
483
|
+
currentData = JSON.parse(JSON.stringify(fullMigration.data));
|
|
484
|
+
} catch {
|
|
485
|
+
currentData = fullMigration.data;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
} else {
|
|
489
|
+
console.warn(`Tam veri migration okunamad\u0131: ${targetMigrations[i].file}`);
|
|
490
|
+
}
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
const patchMigration = await getMigration(
|
|
494
|
+
migrationsDir,
|
|
495
|
+
targetMigrations[i].file
|
|
496
|
+
);
|
|
497
|
+
if (!patchMigration.success || !patchMigration.data) {
|
|
498
|
+
console.warn(`Patch migration okunamad\u0131: ${targetMigrations[i].file}`);
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
try {
|
|
502
|
+
const result = rfc6902.applyPatch(
|
|
503
|
+
currentData,
|
|
504
|
+
patchMigration.data
|
|
505
|
+
);
|
|
506
|
+
const errors = result.filter((r) => r !== null);
|
|
507
|
+
if (errors.length > 0) {
|
|
508
|
+
console.warn(`Patch uygulama uyar\u0131s\u0131 (${targetMigrations[i].file}):`, JSON.stringify(errors));
|
|
509
|
+
}
|
|
510
|
+
} catch (patchError) {
|
|
511
|
+
return {
|
|
512
|
+
success: false,
|
|
513
|
+
status: "error" /* ERROR */,
|
|
514
|
+
error: `Patch uygulama hatas\u0131 (${targetMigrations[i].file}): ${patchError instanceof Error ? patchError.message : String(patchError)}`
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
return {
|
|
519
|
+
success: true,
|
|
520
|
+
status: "success" /* SUCCESS */,
|
|
521
|
+
data: currentData,
|
|
522
|
+
timestamp: targetMigrations[targetMigrations.length - 1].timestamp
|
|
523
|
+
};
|
|
524
|
+
} catch (error) {
|
|
525
|
+
const errorMessage = error instanceof Error ? error.message : String(error || "Undefined error");
|
|
526
|
+
return {
|
|
527
|
+
success: false,
|
|
528
|
+
status: "error" /* ERROR */,
|
|
529
|
+
error: `Migration uygulama hatas\u0131: ${errorMessage}`
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
async function migrationDown(migrationsDir, targetTimestamp) {
|
|
534
|
+
try {
|
|
535
|
+
if (targetTimestamp === void 0) {
|
|
536
|
+
const migrations = await listMigrations(migrationsDir);
|
|
537
|
+
if (migrations.length <= 1) {
|
|
538
|
+
return {
|
|
539
|
+
success: false,
|
|
540
|
+
status: "error" /* ERROR */,
|
|
541
|
+
error: "Geri al\u0131nabilecek bir \xF6nceki migration bulunamad\u0131"
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
const previousMigrations = migrations.slice(0, migrations.length - 1);
|
|
545
|
+
targetTimestamp = previousMigrations[previousMigrations.length - 1].timestamp;
|
|
546
|
+
}
|
|
547
|
+
return await migrationUp(migrationsDir, targetTimestamp);
|
|
548
|
+
} catch (error) {
|
|
549
|
+
const errorMessage = error instanceof Error ? error.message : String(error || "Undefined error");
|
|
550
|
+
return {
|
|
551
|
+
success: false,
|
|
552
|
+
status: "error" /* ERROR */,
|
|
553
|
+
error: `Migration geri alma hatas\u0131: ${errorMessage}`
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
241
558
|
function defineSilgiModule(definition) {
|
|
242
559
|
if (definition) {
|
|
243
560
|
return _defineSilgiModule(definition);
|
|
@@ -605,4 +922,4 @@ function isValidIp(ip) {
|
|
|
605
922
|
return false;
|
|
606
923
|
}
|
|
607
924
|
|
|
608
|
-
export { MODE_RE, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
925
|
+
export { MODE_RE, MigrationStatus, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, listMigrations, migrationDown, migrationUp, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "silgi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.28.
|
|
4
|
+
"version": "0.28.6",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"exports": {
|
|
@@ -95,6 +95,7 @@
|
|
|
95
95
|
"pathe": "^2.0.3",
|
|
96
96
|
"picocolors": "^1.1.1",
|
|
97
97
|
"pkg-types": "^2.1.0",
|
|
98
|
+
"rfc6902": "^5.1.2",
|
|
98
99
|
"scule": "^1.3.0",
|
|
99
100
|
"semver": "^7.7.1",
|
|
100
101
|
"std-env": "^3.9.0",
|