Skip to content

Commit eb7efac

Browse files
committed
chore: add comments
1 parent 004d545 commit eb7efac

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

examples/core-only/server.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
/* A simple example of using Fraci without any ORM. We recommend using an ORM integration, as querying fractional indices manually can be error-prone. */
1+
/* A simple example of using Fraci without any ORM. We strongly recommend using our ORM integrations, as querying fractional indices manually can be error-prone. */
22

33
import { zValidator } from "@hono/zod-validator";
44
import { BASE62, fraci, type FractionalIndex } from "fraci";
55
import { Hono } from "hono";
66
import * as z from "zod";
77

88
// Define the type for our fractional index
9-
type ExampleItemFI = FractionalIndex<
10-
typeof BASE62,
11-
typeof BASE62,
12-
"core.exampleItem.fi"
13-
>;
9+
type FI = FractionalIndex<typeof BASE62, typeof BASE62, "core.exampleItem.fi">;
1410

1511
// Define the structure of our example item
1612
interface ExampleItem {
17-
id: number;
18-
name: string;
19-
fi: ExampleItemFI;
20-
groupId: number;
13+
readonly id: number;
14+
readonly name: string;
15+
readonly fi: FI;
16+
readonly groupId: number;
2117
}
2218

2319
// In-memory database tables
@@ -119,9 +115,11 @@ const queryUtils = {
119115
};
120116

121117
// Fraci utility for the example items
118+
// Implementing this manually is strongly discouraged in a real-world application, as it can be error-prone
119+
// Instead, use our built-in ORM integrations for your database
122120
const xfi = {
123121
// Generate a key between two existing keys
124-
generateKeyBetween: (a: ExampleItemFI | null, b: ExampleItemFI | null) => {
122+
generateKeyBetween: (a: FI | null, b: FI | null) => {
125123
return fraciForExampleItem.generateKeyBetween(a, b);
126124
},
127125

@@ -131,13 +129,12 @@ const xfi = {
131129
where: (item) => item.groupId === where.groupId,
132130
orderBy: { field: "fi", direction: "asc" },
133131
});
134-
135132
if (items.length === 0) {
136-
return [null, null] as [ExampleItemFI | null, ExampleItemFI | null];
133+
return [null, null] as [FI | null, FI | null];
137134
}
138135

139136
const lastItem = items[items.length - 1] as ExampleItem;
140-
return [lastItem.fi, null] as [ExampleItemFI | null, ExampleItemFI | null];
137+
return [lastItem.fi, null] as [FI | null, FI | null];
141138
},
142139

143140
// Get indices for an item before a reference item
@@ -146,7 +143,6 @@ const xfi = {
146143
where: (item) => item.groupId === where.groupId,
147144
orderBy: { field: "fi", direction: "asc" },
148145
});
149-
150146
if (items.length === 0) {
151147
return null;
152148
}
@@ -158,8 +154,7 @@ const xfi = {
158154

159155
const prev = refIndex > 0 ? items[refIndex - 1].fi : null;
160156
const curr = items[refIndex].fi;
161-
162-
return [prev, curr] as [ExampleItemFI | null, ExampleItemFI | null];
157+
return [prev, curr] as [FI | null, FI | null];
163158
},
164159

165160
// Get indices for an item after a reference item
@@ -168,7 +163,6 @@ const xfi = {
168163
where: (item) => item.groupId === where.groupId,
169164
orderBy: { field: "fi", direction: "asc" },
170165
});
171-
172166
if (items.length === 0) {
173167
return null;
174168
}
@@ -180,8 +174,7 @@ const xfi = {
180174

181175
const curr = items[refIndex].fi;
182176
const next = refIndex < items.length - 1 ? items[refIndex + 1].fi : null;
183-
184-
return [curr, next] as [ExampleItemFI | null, ExampleItemFI | null];
177+
return [curr, next] as [FI | null, FI | null];
185178
},
186179

187180
// Check if an error is an index conflict error
@@ -194,7 +187,9 @@ const xfi = {
194187
};
195188

196189
// Function to check for index conflicts
197-
function checkIndexConflict(groupId: number, fi: ExampleItemFI): boolean {
190+
// Implementing this manually is strongly discouraged in a real-world application, as it can be error-prone
191+
// Instead, use the built-in unique constraint handling provided by your database or ORM
192+
function checkIndexConflict(groupId: number, fi: FI): boolean {
198193
return exampleItems.some(
199194
(item) => item.groupId === groupId && item.fi === fi
200195
);

examples/rolldown.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default defineConfig(
4141
},
4242
{
4343
name: "others",
44-
priority: 10,
44+
priority: 100,
4545
},
4646
],
4747
},
@@ -50,6 +50,12 @@ export default defineConfig(
5050
{
5151
name: "show-size",
5252
async generateBundle(_options, bundle) {
53+
this.emitFile({
54+
fileName: `__${entrypoint}__`,
55+
type: "asset",
56+
source: "",
57+
});
58+
5359
const fraciBundle = bundle["fraci.js"];
5460
if (fraciBundle?.type !== "chunk") {
5561
return;

0 commit comments

Comments
 (0)