@3lineas/d1-orm 1.0.8 → 1.0.10
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.cjs +31 -18
- package/dist/cli/index.js +31 -18
- package/package.json +1 -1
package/dist/cli/index.cjs
CHANGED
|
@@ -61,13 +61,13 @@ export class User extends Model {
|
|
|
61
61
|
declare updated_at: string;
|
|
62
62
|
}
|
|
63
63
|
`;
|
|
64
|
-
const userModelPath = path.join(process.cwd(), modelsPath, "User.
|
|
64
|
+
const userModelPath = path.join(process.cwd(), modelsPath, "User.mts");
|
|
65
65
|
if (!fs.existsSync(userModelPath)) {
|
|
66
66
|
fs.writeFileSync(userModelPath, userModelContent);
|
|
67
|
-
p.log.step(`Created model: ${modelsPath}/User.
|
|
67
|
+
p.log.step(`Created model: ${modelsPath}/User.mts`);
|
|
68
68
|
}
|
|
69
69
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").split(".")[0].replace("T", "_");
|
|
70
|
-
const migrationName = `${timestamp}_create_users_table.
|
|
70
|
+
const migrationName = `${timestamp}_create_users_table.mts`;
|
|
71
71
|
const migrationContent = `import { Blueprint, Schema } from '@3lineas/d1-orm';
|
|
72
72
|
|
|
73
73
|
export const up = async () => {
|
|
@@ -93,7 +93,7 @@ export const down = async () => {
|
|
|
93
93
|
fs.writeFileSync(fullMigrationsPath, migrationContent);
|
|
94
94
|
p.log.step(`Created migration: ${migrationsPath}/${migrationName}`);
|
|
95
95
|
}
|
|
96
|
-
const seederContent = `import { User } from '../models/User.
|
|
96
|
+
const seederContent = `import { User } from '../models/User.mts';
|
|
97
97
|
|
|
98
98
|
export const seed = async () => {
|
|
99
99
|
await User.create({
|
|
@@ -103,10 +103,14 @@ export const seed = async () => {
|
|
|
103
103
|
});
|
|
104
104
|
};
|
|
105
105
|
`;
|
|
106
|
-
const fullSeederPath = path.join(
|
|
106
|
+
const fullSeederPath = path.join(
|
|
107
|
+
process.cwd(),
|
|
108
|
+
seedersPath,
|
|
109
|
+
"UserSeeder.mts"
|
|
110
|
+
);
|
|
107
111
|
if (!fs.existsSync(fullSeederPath)) {
|
|
108
112
|
fs.writeFileSync(fullSeederPath, seederContent);
|
|
109
|
-
p.log.step(`Created seeder: ${seedersPath}/UserSeeder.
|
|
113
|
+
p.log.step(`Created seeder: ${seedersPath}/UserSeeder.mts`);
|
|
110
114
|
}
|
|
111
115
|
const configContent = `export default {
|
|
112
116
|
binding: 'DB', // Name of the D1 binding in wrangler.jsonc/toml
|
|
@@ -115,11 +119,11 @@ export const seed = async () => {
|
|
|
115
119
|
const configFilePath = path.join(
|
|
116
120
|
process.cwd(),
|
|
117
121
|
baseDatabasePath,
|
|
118
|
-
"config.
|
|
122
|
+
"config.mts"
|
|
119
123
|
);
|
|
120
124
|
if (!fs.existsSync(configFilePath)) {
|
|
121
125
|
fs.writeFileSync(configFilePath, configContent);
|
|
122
|
-
p.log.step(`Created config: ${baseDatabasePath}/config.
|
|
126
|
+
p.log.step(`Created config: ${baseDatabasePath}/config.mts`);
|
|
123
127
|
}
|
|
124
128
|
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
125
129
|
if (fs.existsSync(packageJsonPath)) {
|
|
@@ -173,7 +177,7 @@ async function makeMigration(name) {
|
|
|
173
177
|
const rootMigrationsDir = path2.join(process.cwd(), "database/migrations");
|
|
174
178
|
const migrationsDir = fs2.existsSync(srcMigrationsDir) ? "src/database/migrations" : "database/migrations";
|
|
175
179
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").split(".")[0].replace("T", "_");
|
|
176
|
-
const filename = `${timestamp}_${migrationName}.
|
|
180
|
+
const filename = `${timestamp}_${migrationName}.mts`;
|
|
177
181
|
const targetPath = path2.join(process.cwd(), migrationsDir, filename);
|
|
178
182
|
const template = `import { Blueprint, Schema } from '@3lineas/d1-orm';
|
|
179
183
|
|
|
@@ -223,7 +227,7 @@ async function makeModel(name) {
|
|
|
223
227
|
}
|
|
224
228
|
}
|
|
225
229
|
const modelPath = await findModelsPath() || "src/database/models";
|
|
226
|
-
const filename = `${modelName}.
|
|
230
|
+
const filename = `${modelName}.mts`;
|
|
227
231
|
const targetPath = path3.join(process.cwd(), modelPath, filename);
|
|
228
232
|
const template = `import { Model } from '@3lineas/d1-orm';
|
|
229
233
|
|
|
@@ -283,13 +287,13 @@ async function makeSeeder(modelName, modelPath) {
|
|
|
283
287
|
const srcPath = path3.join(process.cwd(), "src");
|
|
284
288
|
const useSrc = fs3.existsSync(srcPath) && fs3.lstatSync(srcPath).isDirectory();
|
|
285
289
|
const seederDir = useSrc ? path3.join(process.cwd(), "src/database/seeders") : path3.join(process.cwd(), "database/seeders");
|
|
286
|
-
const seederName = `${modelName}Seeder.
|
|
290
|
+
const seederName = `${modelName}Seeder.mts`;
|
|
287
291
|
const targetPath = path3.join(seederDir, seederName);
|
|
288
292
|
if (!fs3.existsSync(seederDir)) {
|
|
289
293
|
fs3.mkdirSync(seederDir, { recursive: true });
|
|
290
294
|
}
|
|
291
295
|
const relativeModelPath = path3.relative(seederDir, path3.join(process.cwd(), modelPath, modelName)).replace(/\\/g, "/");
|
|
292
|
-
const template = `import { ${modelName} } from '${relativeModelPath}.
|
|
296
|
+
const template = `import { ${modelName} } from '${relativeModelPath}.mts';
|
|
293
297
|
|
|
294
298
|
export const seed = async () => {
|
|
295
299
|
// await ${modelName}.create({ ... });
|
|
@@ -319,9 +323,11 @@ var Config = class {
|
|
|
319
323
|
* @returns The binding name (e.g., "DB").
|
|
320
324
|
*/
|
|
321
325
|
static getD1Binding() {
|
|
322
|
-
const srcConfig = path4.join(process.cwd(), "src/database/config.
|
|
323
|
-
const
|
|
324
|
-
const
|
|
326
|
+
const srcConfig = path4.join(process.cwd(), "src/database/config.mts");
|
|
327
|
+
const srcConfigTs = path4.join(process.cwd(), "src/database/config.ts");
|
|
328
|
+
const rootConfig = path4.join(process.cwd(), "database/config.mts");
|
|
329
|
+
const rootConfigTs = path4.join(process.cwd(), "database/config.ts");
|
|
330
|
+
const configPath = fs4.existsSync(srcConfig) ? srcConfig : fs4.existsSync(srcConfigTs) ? srcConfigTs : fs4.existsSync(rootConfig) ? rootConfig : fs4.existsSync(rootConfigTs) ? rootConfigTs : null;
|
|
325
331
|
if (configPath) {
|
|
326
332
|
const content = fs4.readFileSync(configPath, "utf-8");
|
|
327
333
|
const match = content.match(/binding\s*:\s*["'](.+?)["']/);
|
|
@@ -625,7 +631,9 @@ async function seed(args2) {
|
|
|
625
631
|
const connection = new CLIConnection(dbName, isRemote);
|
|
626
632
|
Database.setup(connection);
|
|
627
633
|
s.stop(`ORM initialized successfully with binding "${dbName}".`);
|
|
628
|
-
const files = fs5.readdirSync(seedersDir).filter(
|
|
634
|
+
const files = fs5.readdirSync(seedersDir).filter(
|
|
635
|
+
(f) => f.endsWith(".ts") || f.endsWith(".js") || f.endsWith(".mts") || f.endsWith(".mjs")
|
|
636
|
+
).sort();
|
|
629
637
|
if (files.length === 0) {
|
|
630
638
|
p4.log.info("No seeder files found.");
|
|
631
639
|
p4.outro("Seeding complete.");
|
|
@@ -667,7 +675,9 @@ async function migrate(args2) {
|
|
|
667
675
|
p5.outro("Nothing to migrate.");
|
|
668
676
|
return;
|
|
669
677
|
}
|
|
670
|
-
const files = fs6.readdirSync(migrationsDir).filter(
|
|
678
|
+
const files = fs6.readdirSync(migrationsDir).filter(
|
|
679
|
+
(f) => f.endsWith(".ts") || f.endsWith(".js") || f.endsWith(".mts") || f.endsWith(".mjs")
|
|
680
|
+
).sort();
|
|
671
681
|
if (files.length === 0) {
|
|
672
682
|
p5.log.info("No migration files found.");
|
|
673
683
|
p5.outro("Migrations complete.");
|
|
@@ -687,7 +697,10 @@ async function migrate(args2) {
|
|
|
687
697
|
const command2 = isRemote ? "--remote" : "--local";
|
|
688
698
|
try {
|
|
689
699
|
const execCmd = `npx wrangler d1 execute ${dbName} --command "${sql.replace(/"/g, '\\"')}" ${command2}`;
|
|
690
|
-
(0, import_child_process2.execSync)(execCmd, {
|
|
700
|
+
(0, import_child_process2.execSync)(execCmd, {
|
|
701
|
+
stdio: "pipe",
|
|
702
|
+
env: { ...process.env, NODE_NO_WARNINGS: "1" }
|
|
703
|
+
});
|
|
691
704
|
s.stop(`Migrated: ${file}`);
|
|
692
705
|
} catch (e) {
|
|
693
706
|
s.stop(`Failed: ${file}`, 1);
|
package/dist/cli/index.js
CHANGED
|
@@ -41,13 +41,13 @@ export class User extends Model {
|
|
|
41
41
|
declare updated_at: string;
|
|
42
42
|
}
|
|
43
43
|
`;
|
|
44
|
-
const userModelPath = path.join(process.cwd(), modelsPath, "User.
|
|
44
|
+
const userModelPath = path.join(process.cwd(), modelsPath, "User.mts");
|
|
45
45
|
if (!fs.existsSync(userModelPath)) {
|
|
46
46
|
fs.writeFileSync(userModelPath, userModelContent);
|
|
47
|
-
p.log.step(`Created model: ${modelsPath}/User.
|
|
47
|
+
p.log.step(`Created model: ${modelsPath}/User.mts`);
|
|
48
48
|
}
|
|
49
49
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").split(".")[0].replace("T", "_");
|
|
50
|
-
const migrationName = `${timestamp}_create_users_table.
|
|
50
|
+
const migrationName = `${timestamp}_create_users_table.mts`;
|
|
51
51
|
const migrationContent = `import { Blueprint, Schema } from '@3lineas/d1-orm';
|
|
52
52
|
|
|
53
53
|
export const up = async () => {
|
|
@@ -73,7 +73,7 @@ export const down = async () => {
|
|
|
73
73
|
fs.writeFileSync(fullMigrationsPath, migrationContent);
|
|
74
74
|
p.log.step(`Created migration: ${migrationsPath}/${migrationName}`);
|
|
75
75
|
}
|
|
76
|
-
const seederContent = `import { User } from '../models/User.
|
|
76
|
+
const seederContent = `import { User } from '../models/User.mts';
|
|
77
77
|
|
|
78
78
|
export const seed = async () => {
|
|
79
79
|
await User.create({
|
|
@@ -83,10 +83,14 @@ export const seed = async () => {
|
|
|
83
83
|
});
|
|
84
84
|
};
|
|
85
85
|
`;
|
|
86
|
-
const fullSeederPath = path.join(
|
|
86
|
+
const fullSeederPath = path.join(
|
|
87
|
+
process.cwd(),
|
|
88
|
+
seedersPath,
|
|
89
|
+
"UserSeeder.mts"
|
|
90
|
+
);
|
|
87
91
|
if (!fs.existsSync(fullSeederPath)) {
|
|
88
92
|
fs.writeFileSync(fullSeederPath, seederContent);
|
|
89
|
-
p.log.step(`Created seeder: ${seedersPath}/UserSeeder.
|
|
93
|
+
p.log.step(`Created seeder: ${seedersPath}/UserSeeder.mts`);
|
|
90
94
|
}
|
|
91
95
|
const configContent = `export default {
|
|
92
96
|
binding: 'DB', // Name of the D1 binding in wrangler.jsonc/toml
|
|
@@ -95,11 +99,11 @@ export const seed = async () => {
|
|
|
95
99
|
const configFilePath = path.join(
|
|
96
100
|
process.cwd(),
|
|
97
101
|
baseDatabasePath,
|
|
98
|
-
"config.
|
|
102
|
+
"config.mts"
|
|
99
103
|
);
|
|
100
104
|
if (!fs.existsSync(configFilePath)) {
|
|
101
105
|
fs.writeFileSync(configFilePath, configContent);
|
|
102
|
-
p.log.step(`Created config: ${baseDatabasePath}/config.
|
|
106
|
+
p.log.step(`Created config: ${baseDatabasePath}/config.mts`);
|
|
103
107
|
}
|
|
104
108
|
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
105
109
|
if (fs.existsSync(packageJsonPath)) {
|
|
@@ -153,7 +157,7 @@ async function makeMigration(name) {
|
|
|
153
157
|
const rootMigrationsDir = path2.join(process.cwd(), "database/migrations");
|
|
154
158
|
const migrationsDir = fs2.existsSync(srcMigrationsDir) ? "src/database/migrations" : "database/migrations";
|
|
155
159
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").split(".")[0].replace("T", "_");
|
|
156
|
-
const filename = `${timestamp}_${migrationName}.
|
|
160
|
+
const filename = `${timestamp}_${migrationName}.mts`;
|
|
157
161
|
const targetPath = path2.join(process.cwd(), migrationsDir, filename);
|
|
158
162
|
const template = `import { Blueprint, Schema } from '@3lineas/d1-orm';
|
|
159
163
|
|
|
@@ -203,7 +207,7 @@ async function makeModel(name) {
|
|
|
203
207
|
}
|
|
204
208
|
}
|
|
205
209
|
const modelPath = await findModelsPath() || "src/database/models";
|
|
206
|
-
const filename = `${modelName}.
|
|
210
|
+
const filename = `${modelName}.mts`;
|
|
207
211
|
const targetPath = path3.join(process.cwd(), modelPath, filename);
|
|
208
212
|
const template = `import { Model } from '@3lineas/d1-orm';
|
|
209
213
|
|
|
@@ -263,13 +267,13 @@ async function makeSeeder(modelName, modelPath) {
|
|
|
263
267
|
const srcPath = path3.join(process.cwd(), "src");
|
|
264
268
|
const useSrc = fs3.existsSync(srcPath) && fs3.lstatSync(srcPath).isDirectory();
|
|
265
269
|
const seederDir = useSrc ? path3.join(process.cwd(), "src/database/seeders") : path3.join(process.cwd(), "database/seeders");
|
|
266
|
-
const seederName = `${modelName}Seeder.
|
|
270
|
+
const seederName = `${modelName}Seeder.mts`;
|
|
267
271
|
const targetPath = path3.join(seederDir, seederName);
|
|
268
272
|
if (!fs3.existsSync(seederDir)) {
|
|
269
273
|
fs3.mkdirSync(seederDir, { recursive: true });
|
|
270
274
|
}
|
|
271
275
|
const relativeModelPath = path3.relative(seederDir, path3.join(process.cwd(), modelPath, modelName)).replace(/\\/g, "/");
|
|
272
|
-
const template = `import { ${modelName} } from '${relativeModelPath}.
|
|
276
|
+
const template = `import { ${modelName} } from '${relativeModelPath}.mts';
|
|
273
277
|
|
|
274
278
|
export const seed = async () => {
|
|
275
279
|
// await ${modelName}.create({ ... });
|
|
@@ -299,9 +303,11 @@ var Config = class {
|
|
|
299
303
|
* @returns The binding name (e.g., "DB").
|
|
300
304
|
*/
|
|
301
305
|
static getD1Binding() {
|
|
302
|
-
const srcConfig = path4.join(process.cwd(), "src/database/config.
|
|
303
|
-
const
|
|
304
|
-
const
|
|
306
|
+
const srcConfig = path4.join(process.cwd(), "src/database/config.mts");
|
|
307
|
+
const srcConfigTs = path4.join(process.cwd(), "src/database/config.ts");
|
|
308
|
+
const rootConfig = path4.join(process.cwd(), "database/config.mts");
|
|
309
|
+
const rootConfigTs = path4.join(process.cwd(), "database/config.ts");
|
|
310
|
+
const configPath = fs4.existsSync(srcConfig) ? srcConfig : fs4.existsSync(srcConfigTs) ? srcConfigTs : fs4.existsSync(rootConfig) ? rootConfig : fs4.existsSync(rootConfigTs) ? rootConfigTs : null;
|
|
305
311
|
if (configPath) {
|
|
306
312
|
const content = fs4.readFileSync(configPath, "utf-8");
|
|
307
313
|
const match = content.match(/binding\s*:\s*["'](.+?)["']/);
|
|
@@ -482,7 +488,9 @@ async function seed(args2) {
|
|
|
482
488
|
const connection = new CLIConnection(dbName, isRemote);
|
|
483
489
|
Database.setup(connection);
|
|
484
490
|
s.stop(`ORM initialized successfully with binding "${dbName}".`);
|
|
485
|
-
const files = fs5.readdirSync(seedersDir).filter(
|
|
491
|
+
const files = fs5.readdirSync(seedersDir).filter(
|
|
492
|
+
(f) => f.endsWith(".ts") || f.endsWith(".js") || f.endsWith(".mts") || f.endsWith(".mjs")
|
|
493
|
+
).sort();
|
|
486
494
|
if (files.length === 0) {
|
|
487
495
|
p4.log.info("No seeder files found.");
|
|
488
496
|
p4.outro("Seeding complete.");
|
|
@@ -524,7 +532,9 @@ async function migrate(args2) {
|
|
|
524
532
|
p5.outro("Nothing to migrate.");
|
|
525
533
|
return;
|
|
526
534
|
}
|
|
527
|
-
const files = fs6.readdirSync(migrationsDir).filter(
|
|
535
|
+
const files = fs6.readdirSync(migrationsDir).filter(
|
|
536
|
+
(f) => f.endsWith(".ts") || f.endsWith(".js") || f.endsWith(".mts") || f.endsWith(".mjs")
|
|
537
|
+
).sort();
|
|
528
538
|
if (files.length === 0) {
|
|
529
539
|
p5.log.info("No migration files found.");
|
|
530
540
|
p5.outro("Migrations complete.");
|
|
@@ -544,7 +554,10 @@ async function migrate(args2) {
|
|
|
544
554
|
const command2 = isRemote ? "--remote" : "--local";
|
|
545
555
|
try {
|
|
546
556
|
const execCmd = `npx wrangler d1 execute ${dbName} --command "${sql.replace(/"/g, '\\"')}" ${command2}`;
|
|
547
|
-
execSync2(execCmd, {
|
|
557
|
+
execSync2(execCmd, {
|
|
558
|
+
stdio: "pipe",
|
|
559
|
+
env: { ...process.env, NODE_NO_WARNINGS: "1" }
|
|
560
|
+
});
|
|
548
561
|
s.stop(`Migrated: ${file}`);
|
|
549
562
|
} catch (e) {
|
|
550
563
|
s.stop(`Failed: ${file}`, 1);
|