qarpeo 0.4.0 → 0.4.1
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/chunks/manifest.get.mjs +1 -1
- package/dist/module.mjs +12 -1
- package/dist/runtime/schema.d.ts +32 -12
- package/dist/runtime/schema.mjs +47 -125
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ import { useRuntimeConfig, defineEventHandler } from 'nuxt/server';
|
|
|
11
11
|
import { mkdir, writeFile, readFile } from 'node:fs/promises';
|
|
12
12
|
import { defu } from 'defu';
|
|
13
13
|
|
|
14
|
-
const version = "0.4.
|
|
14
|
+
const version = "0.4.1";
|
|
15
15
|
|
|
16
16
|
function resolveBindingName(service, override, defaultName) {
|
|
17
17
|
if (override && typeof override === "string") {
|
package/dist/module.mjs
CHANGED
|
@@ -2824,11 +2824,22 @@ async function setupD1(options, nuxt, resolver, logger) {
|
|
|
2824
2824
|
"sqltenantid",
|
|
2825
2825
|
"pgTable",
|
|
2826
2826
|
"pgid",
|
|
2827
|
-
"
|
|
2827
|
+
"pguuid",
|
|
2828
2828
|
"pgint",
|
|
2829
2829
|
"pgtimestamps",
|
|
2830
|
+
"pgCreatedAt",
|
|
2831
|
+
"pgUpdatedAt",
|
|
2830
2832
|
"pgsoftdelete",
|
|
2831
2833
|
"pgtenantid",
|
|
2834
|
+
"msTable",
|
|
2835
|
+
"msid",
|
|
2836
|
+
"msuuid",
|
|
2837
|
+
"msint",
|
|
2838
|
+
"mstimestamps",
|
|
2839
|
+
"msCreatedAt",
|
|
2840
|
+
"msUpdatedAt",
|
|
2841
|
+
"mssoftdelete",
|
|
2842
|
+
"mstenantid",
|
|
2832
2843
|
"generateId",
|
|
2833
2844
|
"generateUUID",
|
|
2834
2845
|
"generateUUIDv7"
|
package/dist/runtime/schema.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `qarpeo/schema` —
|
|
2
|
+
* `qarpeo/schema` — Qarpeo column spreads, table factories, ID generators, and type helpers
|
|
3
|
+
* for Cloudflare D1 (SQLite), PostgreSQL, and MySQL.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* Import standard Drizzle column builders (`text`, `integer`, `varchar`, etc.) and query
|
|
6
|
+
* operators (`eq`, `isNull`, `sql`, etc.) directly from `"drizzle-orm/sqlite-core"`,
|
|
7
|
+
* `"drizzle-orm/pg-core"`, `"drizzle-orm/mysql-core"`, or `"drizzle-orm"`.
|
|
6
8
|
*
|
|
7
9
|
* @example
|
|
8
10
|
* ```ts [db/d1/schema/posts.ts]
|
|
9
|
-
* import {
|
|
11
|
+
* import { text } from "drizzle-orm/sqlite-core"
|
|
12
|
+
* import { sqlTable, sqlid, sqltimestamps, type SelectFrom, type InsertInto } from "qarpeo/schema"
|
|
10
13
|
*
|
|
11
14
|
* export const posts = sqlTable("posts", {
|
|
12
15
|
* ...sqlid,
|
|
@@ -14,14 +17,14 @@
|
|
|
14
17
|
* body: text(),
|
|
15
18
|
* ...sqltimestamps,
|
|
16
19
|
* })
|
|
20
|
+
*
|
|
21
|
+
* export type Post = SelectFrom<typeof posts>
|
|
22
|
+
* export type NewPost = InsertInto<typeof posts>
|
|
17
23
|
* ```
|
|
18
24
|
*/
|
|
19
|
-
export {
|
|
20
|
-
export { pgTable, varchar, char, serial, bigint, bigserial, smallint, doublePrecision, boolean, jsonb, json, timestamp, date, time, uuid, customType as pgCustomType, } from "drizzle-orm/pg-core";
|
|
21
|
-
export { mysqlTable, mysqlView, varchar as mysqlVarchar, char as mysqlChar, serial as mysqlSerial, int as mysqlInt, tinyint as mysqlTinyint, smallint as mysqlSmallint, mediumint as mysqlMediumint, bigint as mysqlBigint, decimal as mysqlDecimal, float as mysqlFloat, double as mysqlDouble, boolean as mysqlBoolean, json as mysqlJson, timestamp as mysqlTimestamp, datetime as mysqlDatetime, date as mysqlDate, time as mysqlTime, year as mysqlYear, text as mysqlText, binary as mysqlBinary, varbinary as mysqlVarbinary, customType as mysqlCustomType, } from "drizzle-orm/mysql-core";
|
|
25
|
+
export { pgTable } from "drizzle-orm/pg-core";
|
|
22
26
|
/** Alias for `mysqlTable` for consistency with `msSchema`, `msDb`, `msid`. */
|
|
23
27
|
export { mysqlTable as msTable } from "drizzle-orm/mysql-core";
|
|
24
|
-
export { sql, defineRelations, eq, ne, gt, gte, lt, lte, and, or, not, desc, asc, like, notLike, ilike, notIlike, inArray, notInArray, isNull, isNotNull, between, notBetween, count, countDistinct, avg, max, min, sum, } from "drizzle-orm";
|
|
25
28
|
/**
|
|
26
29
|
* Drizzle table factory with automatic `camelCase` → `snake_case` column name mapping.
|
|
27
30
|
* Equivalent to `sqliteTable` but all JS column keys are automatically stored with underscore names.
|
|
@@ -45,7 +48,7 @@ export declare function generateUUID(): string;
|
|
|
45
48
|
*
|
|
46
49
|
* The first 48 bits encode the current Unix timestamp in milliseconds so records sort
|
|
47
50
|
* chronologically by ID alone. Sub-millisecond generation uses a monotonic counter
|
|
48
|
-
* per RFC 9562 §6.2 Method 1 to
|
|
51
|
+
* per RFC 9562 §6.2 Method 1 to avoid same-millisecond collisions.
|
|
49
52
|
*
|
|
50
53
|
* **Why prefer UUID v7 over v4 for database primary keys:**
|
|
51
54
|
* - New rows are always appended to the end of the B-tree index → no page splits → faster inserts
|
|
@@ -53,6 +56,10 @@ export declare function generateUUID(): string;
|
|
|
53
56
|
* - Works in distributed edge Workers without a central counter
|
|
54
57
|
* - You can decode the creation timestamp from the ID: `new Date(parseInt(id.slice(0, 8), 16))`
|
|
55
58
|
*
|
|
59
|
+
* Note: The monotonic counter guarantees ordering within a single isolate. Across concurrent
|
|
60
|
+
* requests in the same Cloudflare Worker isolate, ordering is best-effort — UUID v7 collisions
|
|
61
|
+
* remain astronomically unlikely even under concurrency.
|
|
62
|
+
*
|
|
56
63
|
* Zero external dependencies — uses only `Date.now()` and `crypto.getRandomValues()`.
|
|
57
64
|
*
|
|
58
65
|
* @example `"01936c0a-5e0c-7b3a-8f9d-2e1c4a6b8d0f"`
|
|
@@ -170,7 +177,7 @@ export declare const pgid: {
|
|
|
170
177
|
* ID generation happens inside PostgreSQL (`gen_random_uuid()`), not in the Worker.
|
|
171
178
|
* Note: you won't know the ID before insert without a RETURNING clause.
|
|
172
179
|
*/
|
|
173
|
-
export declare const
|
|
180
|
+
export declare const pguuid: {
|
|
174
181
|
readonly id: import("drizzle-orm/pg-core").SetHasDefault<import("drizzle-orm/pg-core").SetIsPrimaryKey<import("drizzle-orm/pg-core").PgUUIDBuilder>>;
|
|
175
182
|
};
|
|
176
183
|
/**
|
|
@@ -192,6 +199,18 @@ export declare const pgtimestamps: {
|
|
|
192
199
|
readonly createdAt: import("drizzle-orm/pg-core").SetHasRuntimeDefault<import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTimestampBuilder>>;
|
|
193
200
|
readonly updatedAt: import("drizzle-orm/pg-core").SetHasDefault<import("drizzle-orm/pg-core").SetHasRuntimeDefault<import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTimestampBuilder>>>;
|
|
194
201
|
};
|
|
202
|
+
/**
|
|
203
|
+
* Just `createdAt` for PostgreSQL — set once at insert, never updated.
|
|
204
|
+
*/
|
|
205
|
+
export declare const pgCreatedAt: {
|
|
206
|
+
readonly createdAt: import("drizzle-orm/pg-core").SetHasRuntimeDefault<import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTimestampBuilder>>;
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Just `updatedAt` for PostgreSQL — set at insert and refreshed on every update.
|
|
210
|
+
*/
|
|
211
|
+
export declare const pgUpdatedAt: {
|
|
212
|
+
readonly updatedAt: import("drizzle-orm/pg-core").SetHasDefault<import("drizzle-orm/pg-core").SetHasRuntimeDefault<import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTimestampBuilder>>>;
|
|
213
|
+
};
|
|
195
214
|
/**
|
|
196
215
|
* PostgreSQL soft-delete column — `deletedAt` nullable timestamptz.
|
|
197
216
|
*/
|
|
@@ -207,10 +226,11 @@ export declare const pgtenantid: {
|
|
|
207
226
|
/**
|
|
208
227
|
* **Recommended MySQL primary key** — VARCHAR(36) UUID v7, auto-generated at insert.
|
|
209
228
|
*
|
|
229
|
+
* The `ms` prefix stands for **MySQL** throughout this module (`sql` = SQLite/D1, `pg` = PostgreSQL, `ms` = MySQL).
|
|
210
230
|
* Time-ordered so rows always sort chronologically by id.
|
|
211
231
|
*
|
|
212
232
|
* ```ts
|
|
213
|
-
* export const posts = mysqlTable("posts", { ...msid, title:
|
|
233
|
+
* export const posts = mysqlTable("posts", { ...msid, title: mysqlVarchar({ length: 255 }).notNull() })
|
|
214
234
|
* // → id VARCHAR(36) PRIMARY KEY (auto UUID v7)
|
|
215
235
|
* ```
|
|
216
236
|
*/
|
|
@@ -231,7 +251,7 @@ export declare const msuuid: {
|
|
|
231
251
|
* Best for simple, single-region tables where sequential IDs are acceptable.
|
|
232
252
|
*
|
|
233
253
|
* ```ts
|
|
234
|
-
* export const hits = mysqlTable("hits", { ...msint, path:
|
|
254
|
+
* export const hits = mysqlTable("hits", { ...msint, path: mysqlText().notNull() })
|
|
235
255
|
* // → id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY
|
|
236
256
|
* ```
|
|
237
257
|
*/
|
package/dist/runtime/schema.mjs
CHANGED
|
@@ -1,94 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
sqliteTable,
|
|
3
|
-
text,
|
|
4
|
-
integer,
|
|
5
|
-
real,
|
|
6
|
-
blob,
|
|
7
|
-
numeric,
|
|
8
|
-
uniqueIndex,
|
|
9
|
-
index,
|
|
10
|
-
primaryKey,
|
|
11
|
-
foreignKey,
|
|
12
|
-
check,
|
|
13
|
-
customType as sqliteCustomType
|
|
14
|
-
} from "drizzle-orm/sqlite-core";
|
|
15
|
-
export {
|
|
16
|
-
pgTable,
|
|
17
|
-
varchar,
|
|
18
|
-
char,
|
|
19
|
-
serial,
|
|
20
|
-
bigint,
|
|
21
|
-
bigserial,
|
|
22
|
-
smallint,
|
|
23
|
-
doublePrecision,
|
|
24
|
-
boolean,
|
|
25
|
-
jsonb,
|
|
26
|
-
json,
|
|
27
|
-
timestamp,
|
|
28
|
-
date,
|
|
29
|
-
time,
|
|
30
|
-
uuid,
|
|
31
|
-
customType as pgCustomType
|
|
32
|
-
} from "drizzle-orm/pg-core";
|
|
33
|
-
export {
|
|
34
|
-
mysqlTable,
|
|
35
|
-
mysqlView,
|
|
36
|
-
varchar as mysqlVarchar,
|
|
37
|
-
char as mysqlChar,
|
|
38
|
-
serial as mysqlSerial,
|
|
39
|
-
int as mysqlInt,
|
|
40
|
-
tinyint as mysqlTinyint,
|
|
41
|
-
smallint as mysqlSmallint,
|
|
42
|
-
mediumint as mysqlMediumint,
|
|
43
|
-
bigint as mysqlBigint,
|
|
44
|
-
decimal as mysqlDecimal,
|
|
45
|
-
float as mysqlFloat,
|
|
46
|
-
double as mysqlDouble,
|
|
47
|
-
boolean as mysqlBoolean,
|
|
48
|
-
json as mysqlJson,
|
|
49
|
-
timestamp as mysqlTimestamp,
|
|
50
|
-
datetime as mysqlDatetime,
|
|
51
|
-
date as mysqlDate,
|
|
52
|
-
time as mysqlTime,
|
|
53
|
-
year as mysqlYear,
|
|
54
|
-
text as mysqlText,
|
|
55
|
-
binary as mysqlBinary,
|
|
56
|
-
varbinary as mysqlVarbinary,
|
|
57
|
-
customType as mysqlCustomType
|
|
58
|
-
} from "drizzle-orm/mysql-core";
|
|
59
|
-
export { mysqlTable as msTable } from "drizzle-orm/mysql-core";
|
|
60
|
-
export {
|
|
61
|
-
sql,
|
|
62
|
-
defineRelations,
|
|
63
|
-
eq,
|
|
64
|
-
ne,
|
|
65
|
-
gt,
|
|
66
|
-
gte,
|
|
67
|
-
lt,
|
|
68
|
-
lte,
|
|
69
|
-
and,
|
|
70
|
-
or,
|
|
71
|
-
not,
|
|
72
|
-
desc,
|
|
73
|
-
asc,
|
|
74
|
-
like,
|
|
75
|
-
notLike,
|
|
76
|
-
ilike,
|
|
77
|
-
notIlike,
|
|
78
|
-
inArray,
|
|
79
|
-
notInArray,
|
|
80
|
-
isNull,
|
|
81
|
-
isNotNull,
|
|
82
|
-
between,
|
|
83
|
-
notBetween,
|
|
84
|
-
count,
|
|
85
|
-
countDistinct,
|
|
86
|
-
avg,
|
|
87
|
-
max,
|
|
88
|
-
min,
|
|
89
|
-
sum
|
|
90
|
-
} from "drizzle-orm";
|
|
91
1
|
import { snakeCase } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export { pgTable } from "drizzle-orm/pg-core";
|
|
3
|
+
export { mysqlTable as msTable } from "drizzle-orm/mysql-core";
|
|
92
4
|
export const sqlTable = snakeCase.table;
|
|
93
5
|
export function generateUUID() {
|
|
94
6
|
return crypto.randomUUID();
|
|
@@ -98,23 +10,23 @@ let seq = 0;
|
|
|
98
10
|
export function generateUUIDv7() {
|
|
99
11
|
const bytes = new Uint8Array(16);
|
|
100
12
|
crypto.getRandomValues(bytes);
|
|
101
|
-
let
|
|
102
|
-
if (
|
|
103
|
-
lastTimestamp =
|
|
13
|
+
let timestamp = Date.now();
|
|
14
|
+
if (timestamp > lastTimestamp) {
|
|
15
|
+
lastTimestamp = timestamp;
|
|
104
16
|
seq = (bytes[6] & 15) << 8 | bytes[7];
|
|
105
17
|
} else {
|
|
106
18
|
seq = seq + 1 & 4095;
|
|
107
19
|
if (seq === 0) {
|
|
108
20
|
lastTimestamp++;
|
|
109
21
|
}
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
bytes[0] =
|
|
113
|
-
bytes[1] =
|
|
114
|
-
bytes[2] =
|
|
115
|
-
bytes[3] =
|
|
116
|
-
bytes[4] =
|
|
117
|
-
bytes[5] =
|
|
22
|
+
timestamp = lastTimestamp;
|
|
23
|
+
}
|
|
24
|
+
bytes[0] = timestamp / 1099511627776 & 255;
|
|
25
|
+
bytes[1] = timestamp / 4294967296 & 255;
|
|
26
|
+
bytes[2] = timestamp / 16777216 & 255;
|
|
27
|
+
bytes[3] = timestamp / 65536 & 255;
|
|
28
|
+
bytes[4] = timestamp / 256 & 255;
|
|
29
|
+
bytes[5] = timestamp & 255;
|
|
118
30
|
bytes[6] = 112 | seq >> 8 & 15;
|
|
119
31
|
bytes[7] = seq & 255;
|
|
120
32
|
bytes[8] = bytes[8] & 63 | 128;
|
|
@@ -171,89 +83,99 @@ export const sqltenantid = {
|
|
|
171
83
|
}
|
|
172
84
|
};
|
|
173
85
|
import {
|
|
174
|
-
text as
|
|
175
|
-
uuid as
|
|
176
|
-
timestamp as
|
|
177
|
-
serial as
|
|
86
|
+
text as _pgText,
|
|
87
|
+
uuid as _pgUuid,
|
|
88
|
+
timestamp as _pgTimestamp,
|
|
89
|
+
serial as _pgSerial
|
|
178
90
|
} from "drizzle-orm/pg-core";
|
|
179
91
|
export const pgid = {
|
|
180
92
|
get id() {
|
|
181
|
-
return
|
|
93
|
+
return _pgText("id").primaryKey().$defaultFn(() => generateUUIDv7());
|
|
182
94
|
}
|
|
183
95
|
};
|
|
184
|
-
export const
|
|
96
|
+
export const pguuid = {
|
|
185
97
|
get id() {
|
|
186
|
-
return
|
|
98
|
+
return _pgUuid("id").primaryKey().defaultRandom();
|
|
187
99
|
}
|
|
188
100
|
};
|
|
189
101
|
export const pgint = {
|
|
190
102
|
get id() {
|
|
191
|
-
return
|
|
103
|
+
return _pgSerial("id").primaryKey();
|
|
192
104
|
}
|
|
193
105
|
};
|
|
194
106
|
export const pgtimestamps = {
|
|
195
107
|
get createdAt() {
|
|
196
|
-
return
|
|
108
|
+
return _pgTimestamp("created_at", { withTimezone: true }).notNull().$defaultFn(() => /* @__PURE__ */ new Date());
|
|
197
109
|
},
|
|
198
110
|
get updatedAt() {
|
|
199
|
-
return
|
|
111
|
+
return _pgTimestamp("updated_at", { withTimezone: true }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()).$onUpdate(() => /* @__PURE__ */ new Date());
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
export const pgCreatedAt = {
|
|
115
|
+
get createdAt() {
|
|
116
|
+
return _pgTimestamp("created_at", { withTimezone: true }).notNull().$defaultFn(() => /* @__PURE__ */ new Date());
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
export const pgUpdatedAt = {
|
|
120
|
+
get updatedAt() {
|
|
121
|
+
return _pgTimestamp("updated_at", { withTimezone: true }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()).$onUpdate(() => /* @__PURE__ */ new Date());
|
|
200
122
|
}
|
|
201
123
|
};
|
|
202
124
|
export const pgsoftdelete = {
|
|
203
125
|
get deletedAt() {
|
|
204
|
-
return
|
|
126
|
+
return _pgTimestamp("deleted_at", { withTimezone: true });
|
|
205
127
|
}
|
|
206
128
|
};
|
|
207
129
|
export const pgtenantid = {
|
|
208
130
|
get tenantId() {
|
|
209
|
-
return
|
|
131
|
+
return _pgText("tenant_id");
|
|
210
132
|
}
|
|
211
133
|
};
|
|
212
134
|
import {
|
|
213
|
-
varchar as
|
|
214
|
-
serial as
|
|
215
|
-
timestamp as
|
|
135
|
+
varchar as _mysqlVarchar,
|
|
136
|
+
serial as _mysqlSerial,
|
|
137
|
+
timestamp as _mysqlTimestamp
|
|
216
138
|
} from "drizzle-orm/mysql-core";
|
|
217
139
|
export const msid = {
|
|
218
140
|
get id() {
|
|
219
|
-
return
|
|
141
|
+
return _mysqlVarchar("id", { length: 36 }).primaryKey().$defaultFn(() => generateUUIDv7());
|
|
220
142
|
}
|
|
221
143
|
};
|
|
222
144
|
export const msuuid = {
|
|
223
145
|
get id() {
|
|
224
|
-
return
|
|
146
|
+
return _mysqlVarchar("id", { length: 36 }).primaryKey().$defaultFn(() => crypto.randomUUID());
|
|
225
147
|
}
|
|
226
148
|
};
|
|
227
149
|
export const msint = {
|
|
228
150
|
get id() {
|
|
229
|
-
return
|
|
151
|
+
return _mysqlSerial("id").primaryKey();
|
|
230
152
|
}
|
|
231
153
|
};
|
|
232
154
|
export const mstimestamps = {
|
|
233
155
|
get createdAt() {
|
|
234
|
-
return
|
|
156
|
+
return _mysqlTimestamp("created_at").notNull().$defaultFn(() => /* @__PURE__ */ new Date());
|
|
235
157
|
},
|
|
236
158
|
get updatedAt() {
|
|
237
|
-
return
|
|
159
|
+
return _mysqlTimestamp("updated_at").notNull().$defaultFn(() => /* @__PURE__ */ new Date()).$onUpdate(() => /* @__PURE__ */ new Date());
|
|
238
160
|
}
|
|
239
161
|
};
|
|
240
162
|
export const msCreatedAt = {
|
|
241
163
|
get createdAt() {
|
|
242
|
-
return
|
|
164
|
+
return _mysqlTimestamp("created_at").notNull().$defaultFn(() => /* @__PURE__ */ new Date());
|
|
243
165
|
}
|
|
244
166
|
};
|
|
245
167
|
export const msUpdatedAt = {
|
|
246
168
|
get updatedAt() {
|
|
247
|
-
return
|
|
169
|
+
return _mysqlTimestamp("updated_at").notNull().$defaultFn(() => /* @__PURE__ */ new Date()).$onUpdate(() => /* @__PURE__ */ new Date());
|
|
248
170
|
}
|
|
249
171
|
};
|
|
250
172
|
export const mssoftdelete = {
|
|
251
173
|
get deletedAt() {
|
|
252
|
-
return
|
|
174
|
+
return _mysqlTimestamp("deleted_at");
|
|
253
175
|
}
|
|
254
176
|
};
|
|
255
177
|
export const mstenantid = {
|
|
256
178
|
get tenantId() {
|
|
257
|
-
return
|
|
179
|
+
return _mysqlVarchar("tenant_id", { length: 36 });
|
|
258
180
|
}
|
|
259
181
|
};
|