create-baresync 0.2.0 → 0.2.2
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.js +10 -10
- package/dist/index.js +10 -10
- package/dist/templates/app/package.json +1 -1
- package/dist/templates/root/README.md +0 -1
- package/dist/templates/server/package.json +1 -1
- package/dist/templates/server/src/v1/routes-elysia.ts +1 -4
- package/dist/templates/server/src/v1/routes-hono.ts +1 -4
- package/dist/templates/server/src-db/v1/sync-repository.ts +113 -128
- package/dist/templates/sync-contract/package.json +1 -1
- package/dist/templates/sync-contract/src/constants.ts +0 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2278,11 +2278,10 @@ function buildRootScaffoldFiles(options) {
|
|
|
2278
2278
|
function buildUserFacingNextSteps(options) {
|
|
2279
2279
|
return [
|
|
2280
2280
|
`1. cd ${options.projectName}`,
|
|
2281
|
-
`2. ${options.packageManager}
|
|
2282
|
-
`3. ${options.packageManager} run
|
|
2283
|
-
`4. ${options.packageManager} run migrate:
|
|
2284
|
-
`5. ${options.packageManager} run
|
|
2285
|
-
`6. ${options.packageManager} run dev`
|
|
2281
|
+
`2. ${options.packageManager} run generate:sync`,
|
|
2282
|
+
`3. ${options.packageManager} run migrate:local`,
|
|
2283
|
+
`4. ${options.packageManager} run migrate:server`,
|
|
2284
|
+
`5. ${options.packageManager} run dev`
|
|
2286
2285
|
].join(`
|
|
2287
2286
|
`);
|
|
2288
2287
|
}
|
|
@@ -2481,7 +2480,9 @@ async function scaffoldProject() {
|
|
|
2481
2480
|
await fs3.mkdir(path3.join(projectDir, "packages"), { recursive: true });
|
|
2482
2481
|
R2.info(`Detected package manager: ${packageManager}`);
|
|
2483
2482
|
const appTargetDir = path3.join(projectDir, "apps");
|
|
2484
|
-
|
|
2483
|
+
try {
|
|
2484
|
+
await runInteractive(packageManager, createCommandArgs(packageManager, "tauri-app", "app"), appTargetDir);
|
|
2485
|
+
} catch {}
|
|
2485
2486
|
const serverFramework = await promptServerFramework();
|
|
2486
2487
|
const options = {
|
|
2487
2488
|
packageManager,
|
|
@@ -2494,10 +2495,7 @@ async function scaffoldProject() {
|
|
|
2494
2495
|
const serverInitializer = serverFramework === "hono" ? "hono" : "elysia";
|
|
2495
2496
|
try {
|
|
2496
2497
|
await runInteractive(packageManager, createCommandArgs(packageManager, serverInitializer, "server"), serverTargetDir);
|
|
2497
|
-
} catch {
|
|
2498
|
-
R2.warn("\u26A0\uFE0F\u2003Note: create-hono exited with an error (likely an install failure).");
|
|
2499
|
-
R2.warn("This is safe to ignore \u2014 you can just run install at the workspace root later.");
|
|
2500
|
-
}
|
|
2498
|
+
} catch {}
|
|
2501
2499
|
await patchAppFiles(projectDir, options, allFiles);
|
|
2502
2500
|
await patchServerFiles(projectDir, options, allFiles);
|
|
2503
2501
|
await fs3.writeFile(path3.join(projectDir, "package.json"), JSON.stringify({
|
|
@@ -2519,6 +2517,8 @@ Generated with create-baresync.
|
|
|
2519
2517
|
|
|
2520
2518
|
${buildUserFacingNextSteps(options)}
|
|
2521
2519
|
`, "utf8");
|
|
2520
|
+
R2.info("Installing dependencies...");
|
|
2521
|
+
await runInteractive(packageManager, ["install"], projectDir);
|
|
2522
2522
|
ye(`${import_picocolors.default.green("Success!")} Baresync monorepo starter is ready!
|
|
2523
2523
|
|
|
2524
2524
|
${buildUserFacingNextSteps(options)}`);
|
package/dist/index.js
CHANGED
|
@@ -2276,11 +2276,10 @@ function buildRootScaffoldFiles(options) {
|
|
|
2276
2276
|
function buildUserFacingNextSteps(options) {
|
|
2277
2277
|
return [
|
|
2278
2278
|
`1. cd ${options.projectName}`,
|
|
2279
|
-
`2. ${options.packageManager}
|
|
2280
|
-
`3. ${options.packageManager} run
|
|
2281
|
-
`4. ${options.packageManager} run migrate:
|
|
2282
|
-
`5. ${options.packageManager} run
|
|
2283
|
-
`6. ${options.packageManager} run dev`
|
|
2279
|
+
`2. ${options.packageManager} run generate:sync`,
|
|
2280
|
+
`3. ${options.packageManager} run migrate:local`,
|
|
2281
|
+
`4. ${options.packageManager} run migrate:server`,
|
|
2282
|
+
`5. ${options.packageManager} run dev`
|
|
2284
2283
|
].join(`
|
|
2285
2284
|
`);
|
|
2286
2285
|
}
|
|
@@ -2479,7 +2478,9 @@ async function scaffoldProject() {
|
|
|
2479
2478
|
await fs3.mkdir(path3.join(projectDir, "packages"), { recursive: true });
|
|
2480
2479
|
R2.info(`Detected package manager: ${packageManager}`);
|
|
2481
2480
|
const appTargetDir = path3.join(projectDir, "apps");
|
|
2482
|
-
|
|
2481
|
+
try {
|
|
2482
|
+
await runInteractive(packageManager, createCommandArgs(packageManager, "tauri-app", "app"), appTargetDir);
|
|
2483
|
+
} catch {}
|
|
2483
2484
|
const serverFramework = await promptServerFramework();
|
|
2484
2485
|
const options = {
|
|
2485
2486
|
packageManager,
|
|
@@ -2492,10 +2493,7 @@ async function scaffoldProject() {
|
|
|
2492
2493
|
const serverInitializer = serverFramework === "hono" ? "hono" : "elysia";
|
|
2493
2494
|
try {
|
|
2494
2495
|
await runInteractive(packageManager, createCommandArgs(packageManager, serverInitializer, "server"), serverTargetDir);
|
|
2495
|
-
} catch {
|
|
2496
|
-
R2.warn("\u26A0\uFE0F\u2003Note: create-hono exited with an error (likely an install failure).");
|
|
2497
|
-
R2.warn("This is safe to ignore \u2014 you can just run install at the workspace root later.");
|
|
2498
|
-
}
|
|
2496
|
+
} catch {}
|
|
2499
2497
|
await patchAppFiles(projectDir, options, allFiles);
|
|
2500
2498
|
await patchServerFiles(projectDir, options, allFiles);
|
|
2501
2499
|
await fs3.writeFile(path3.join(projectDir, "package.json"), JSON.stringify({
|
|
@@ -2517,6 +2515,8 @@ Generated with create-baresync.
|
|
|
2517
2515
|
|
|
2518
2516
|
${buildUserFacingNextSteps(options)}
|
|
2519
2517
|
`, "utf8");
|
|
2518
|
+
R2.info("Installing dependencies...");
|
|
2519
|
+
await runInteractive(packageManager, ["install"], projectDir);
|
|
2520
2520
|
ye(`${import_picocolors.default.green("Success!")} Baresync monorepo starter is ready!
|
|
2521
2521
|
|
|
2522
2522
|
${buildUserFacingNextSteps(options)}`);
|
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
} from "baresync/server";
|
|
6
6
|
import { Elysia } from "elysia";
|
|
7
7
|
import { SYNC_SCOPE } from "@sync-contract/constants";
|
|
8
|
-
import {
|
|
9
|
-
import { createAppSyncRepository } from "../db/v1/sync-repository";
|
|
8
|
+
import { repository } from "../db/v1/sync-repository";
|
|
10
9
|
|
|
11
10
|
const resolveScope = ({ scopeId }: { scopeId: string }) => {
|
|
12
11
|
if (scopeId !== SYNC_SCOPE) {
|
|
@@ -23,8 +22,6 @@ const resolveScope = ({ scopeId }: { scopeId: string }) => {
|
|
|
23
22
|
};
|
|
24
23
|
};
|
|
25
24
|
|
|
26
|
-
const repository = createAppSyncRepository(db);
|
|
27
|
-
|
|
28
25
|
const push = createSyncPushHandler({
|
|
29
26
|
resolveScope,
|
|
30
27
|
upsertOrder: repository.tableNames,
|
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
createSyncPushHandler,
|
|
6
6
|
createSyncStatusHandler,
|
|
7
7
|
} from "baresync/server";
|
|
8
|
-
import {
|
|
9
|
-
import { createAppSyncRepository } from "../db/v1/sync-repository";
|
|
8
|
+
import { repository } from "../db/v1/sync-repository";
|
|
10
9
|
|
|
11
10
|
const resolveScope = ({ scopeId }: { scopeId: string }) => {
|
|
12
11
|
if (scopeId !== SYNC_SCOPE) {
|
|
@@ -23,8 +22,6 @@ const resolveScope = ({ scopeId }: { scopeId: string }) => {
|
|
|
23
22
|
};
|
|
24
23
|
};
|
|
25
24
|
|
|
26
|
-
const repository = createAppSyncRepository(db);
|
|
27
|
-
|
|
28
25
|
const push = createSyncPushHandler({
|
|
29
26
|
resolveScope,
|
|
30
27
|
upsertOrder: repository.tableNames,
|
|
@@ -6,135 +6,120 @@ import {
|
|
|
6
6
|
requiredString,
|
|
7
7
|
} from "baresync/server/drizzle";
|
|
8
8
|
import { and, desc, eq, gt, type InferInsertModel } from "drizzle-orm";
|
|
9
|
-
import
|
|
9
|
+
import { db } from "../client";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
.orderBy(
|
|
37
|
-
desc(lists.syncUpdatedAt),
|
|
38
|
-
desc(lists.updatedAt),
|
|
39
|
-
desc(lists.id)
|
|
40
|
-
)
|
|
41
|
-
.limit(1);
|
|
42
|
-
return rows[0] ?? null;
|
|
43
|
-
},
|
|
44
|
-
readRows: ({ cursorTimestamp, scopeId }) =>
|
|
45
|
-
db
|
|
46
|
-
.select()
|
|
47
|
-
.from(lists)
|
|
48
|
-
.where(
|
|
49
|
-
cursorTimestamp > 0
|
|
50
|
-
? and(
|
|
51
|
-
eq(lists.scopeId, scopeId),
|
|
52
|
-
gt(lists.syncUpdatedAt, cursorTimestamp)
|
|
53
|
-
)
|
|
54
|
-
: eq(lists.scopeId, scopeId)
|
|
55
|
-
)
|
|
56
|
-
.orderBy(
|
|
57
|
-
desc(lists.syncUpdatedAt),
|
|
58
|
-
desc(lists.updatedAt),
|
|
59
|
-
desc(lists.id)
|
|
60
|
-
) as Promise<readonly DrizzleSyncReadRow[]>,
|
|
61
|
-
softDeleteRow: async ({ id, syncUpdatedAt, updatedAt }) => {
|
|
62
|
-
await db
|
|
63
|
-
.update(lists)
|
|
64
|
-
.set({ deletedAt: updatedAt, syncUpdatedAt, updatedAt })
|
|
65
|
-
.where(eq(lists.id, id));
|
|
66
|
-
},
|
|
67
|
-
upsertRow: async (row: InferInsertModel<typeof lists>) => {
|
|
68
|
-
const { id: _id, ...setValues } = row;
|
|
69
|
-
await db.insert(lists).values(row).onConflictDoUpdate({
|
|
70
|
-
target: lists.id,
|
|
71
|
-
set: setValues,
|
|
72
|
-
});
|
|
73
|
-
},
|
|
11
|
+
export const repository = createDrizzleSyncRepository({
|
|
12
|
+
tables: {
|
|
13
|
+
lists: {
|
|
14
|
+
buildRow: ({ row, scopeId, syncUpdatedAt, updatedAt }) => ({
|
|
15
|
+
createdAt: optionalString(row.createdAt) ?? updatedAt,
|
|
16
|
+
deletedAt: optionalString(row.deletedAt),
|
|
17
|
+
id: requiredString(row.id, "lists.id"),
|
|
18
|
+
name: requiredString(row.name, "lists.name"),
|
|
19
|
+
description: optionalString(row.description),
|
|
20
|
+
scopeId,
|
|
21
|
+
syncUpdatedAt,
|
|
22
|
+
updatedAt,
|
|
23
|
+
}),
|
|
24
|
+
readLatestRow: async ({ scopeId }) => {
|
|
25
|
+
const rows = await db
|
|
26
|
+
.select()
|
|
27
|
+
.from(lists)
|
|
28
|
+
.where(eq(lists.scopeId, scopeId))
|
|
29
|
+
.orderBy(
|
|
30
|
+
desc(lists.syncUpdatedAt),
|
|
31
|
+
desc(lists.updatedAt),
|
|
32
|
+
desc(lists.id)
|
|
33
|
+
)
|
|
34
|
+
.limit(1);
|
|
35
|
+
return rows[0] ?? null;
|
|
74
36
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
.
|
|
90
|
-
.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
.where(
|
|
105
|
-
cursorTimestamp > 0
|
|
106
|
-
? and(
|
|
107
|
-
eq(todos.scopeId, scopeId),
|
|
108
|
-
gt(todos.syncUpdatedAt, cursorTimestamp)
|
|
109
|
-
)
|
|
110
|
-
: eq(todos.scopeId, scopeId)
|
|
111
|
-
)
|
|
112
|
-
.orderBy(
|
|
113
|
-
desc(todos.syncUpdatedAt),
|
|
114
|
-
desc(todos.updatedAt),
|
|
115
|
-
desc(todos.id)
|
|
116
|
-
) as Promise<readonly DrizzleSyncReadRow[]>,
|
|
117
|
-
softDeleteRow: async ({ id, syncUpdatedAt, updatedAt }) => {
|
|
118
|
-
await db
|
|
119
|
-
.update(todos)
|
|
120
|
-
.set({ deletedAt: updatedAt, syncUpdatedAt, updatedAt })
|
|
121
|
-
.where(eq(todos.id, id));
|
|
122
|
-
},
|
|
123
|
-
upsertRow: async (row: InferInsertModel<typeof todos>) => {
|
|
124
|
-
const { id: _id, ...setValues } = row;
|
|
125
|
-
await db.insert(todos).values(row).onConflictDoUpdate({
|
|
126
|
-
target: todos.id,
|
|
127
|
-
set: setValues,
|
|
128
|
-
});
|
|
129
|
-
},
|
|
37
|
+
readRows: ({ cursorTimestamp, scopeId }) =>
|
|
38
|
+
db
|
|
39
|
+
.select()
|
|
40
|
+
.from(lists)
|
|
41
|
+
.where(
|
|
42
|
+
cursorTimestamp > 0
|
|
43
|
+
? and(
|
|
44
|
+
eq(lists.scopeId, scopeId),
|
|
45
|
+
gt(lists.syncUpdatedAt, cursorTimestamp)
|
|
46
|
+
)
|
|
47
|
+
: eq(lists.scopeId, scopeId)
|
|
48
|
+
)
|
|
49
|
+
.orderBy(
|
|
50
|
+
desc(lists.syncUpdatedAt),
|
|
51
|
+
desc(lists.updatedAt),
|
|
52
|
+
desc(lists.id)
|
|
53
|
+
) as Promise<readonly DrizzleSyncReadRow[]>,
|
|
54
|
+
softDeleteRow: async ({ id, syncUpdatedAt, updatedAt }) => {
|
|
55
|
+
await db
|
|
56
|
+
.update(lists)
|
|
57
|
+
.set({ deletedAt: updatedAt, syncUpdatedAt, updatedAt })
|
|
58
|
+
.where(eq(lists.id, id));
|
|
59
|
+
},
|
|
60
|
+
upsertRow: async (row: InferInsertModel<typeof lists>) => {
|
|
61
|
+
const { id: _id, ...setValues } = row;
|
|
62
|
+
await db.insert(lists).values(row).onConflictDoUpdate({
|
|
63
|
+
target: lists.id,
|
|
64
|
+
set: setValues,
|
|
65
|
+
});
|
|
130
66
|
},
|
|
131
67
|
},
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
68
|
+
todos: {
|
|
69
|
+
buildRow: ({ row, scopeId, syncUpdatedAt, updatedAt }) => ({
|
|
70
|
+
createdAt: optionalString(row.createdAt) ?? updatedAt,
|
|
71
|
+
deletedAt: optionalString(row.deletedAt),
|
|
72
|
+
id: requiredString(row.id, "todos.id"),
|
|
73
|
+
listId: requiredString(row.listId, "todos.listId"),
|
|
74
|
+
title: requiredString(row.title, "todos.title"),
|
|
75
|
+
notes: optionalString(row.notes),
|
|
76
|
+
scopeId,
|
|
77
|
+
syncUpdatedAt,
|
|
78
|
+
updatedAt,
|
|
79
|
+
}),
|
|
80
|
+
readLatestRow: async ({ scopeId }) => {
|
|
81
|
+
const rows = await db
|
|
82
|
+
.select()
|
|
83
|
+
.from(todos)
|
|
84
|
+
.where(eq(todos.scopeId, scopeId))
|
|
85
|
+
.orderBy(
|
|
86
|
+
desc(todos.syncUpdatedAt),
|
|
87
|
+
desc(todos.updatedAt),
|
|
88
|
+
desc(todos.id)
|
|
89
|
+
)
|
|
90
|
+
.limit(1);
|
|
91
|
+
return rows[0] ?? null;
|
|
92
|
+
},
|
|
93
|
+
readRows: ({ cursorTimestamp, scopeId }) =>
|
|
94
|
+
db
|
|
95
|
+
.select()
|
|
96
|
+
.from(todos)
|
|
97
|
+
.where(
|
|
98
|
+
cursorTimestamp > 0
|
|
99
|
+
? and(
|
|
100
|
+
eq(todos.scopeId, scopeId),
|
|
101
|
+
gt(todos.syncUpdatedAt, cursorTimestamp)
|
|
102
|
+
)
|
|
103
|
+
: eq(todos.scopeId, scopeId)
|
|
104
|
+
)
|
|
105
|
+
.orderBy(
|
|
106
|
+
desc(todos.syncUpdatedAt),
|
|
107
|
+
desc(todos.updatedAt),
|
|
108
|
+
desc(todos.id)
|
|
109
|
+
) as Promise<readonly DrizzleSyncReadRow[]>,
|
|
110
|
+
softDeleteRow: async ({ id, syncUpdatedAt, updatedAt }) => {
|
|
111
|
+
await db
|
|
112
|
+
.update(todos)
|
|
113
|
+
.set({ deletedAt: updatedAt, syncUpdatedAt, updatedAt })
|
|
114
|
+
.where(eq(todos.id, id));
|
|
115
|
+
},
|
|
116
|
+
upsertRow: async (row: InferInsertModel<typeof todos>) => {
|
|
117
|
+
const { id: _id, ...setValues } = row;
|
|
118
|
+
await db.insert(todos).values(row).onConflictDoUpdate({
|
|
119
|
+
target: todos.id,
|
|
120
|
+
set: setValues,
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
});
|