@zeno-lib/schema 0.4.0 → 0.5.0
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/index.d.mts +6 -7
- package/dist/index.mjs +2 -3
- package/package.json +6 -6
- package/src/index.ts +10 -8
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Column, InferInsertModel, InferSelectModel, Table } from "drizzle-orm";
|
|
2
2
|
import { BuildRefine, BuildSchema, CoerceOptions, CreateSchemaFactoryOptions, NoUnknownKeys, createInsertSchema, createSchemaFactory, createSelectSchema, createUpdateSchema } from "drizzle-orm/zod";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
//#region src/index.d.ts
|
|
5
4
|
declare const noTableSchemaOptions: unique symbol;
|
|
6
5
|
type NoTableSchemaOptions = {
|
|
7
6
|
[noTableSchemaOptions]?: never;
|
|
@@ -10,9 +9,9 @@ type TableColumns<TTable extends Table> = TTable["_"]["columns"];
|
|
|
10
9
|
declare const COLUMN_RULES_KEY = "~zeno";
|
|
11
10
|
/**
|
|
12
11
|
* What a column marker from `@zeno-lib/db/schema` records. `writer` says who
|
|
13
|
-
* writes the column when a client doesn't: `"server"` code (`
|
|
14
|
-
* only the `"database"`,
|
|
15
|
-
* `timestamps()` and `authorship()`
|
|
12
|
+
* writes the column when a client doesn't: `"server"` code (`serverManaged`),
|
|
13
|
+
* or only the `"database"` (`databaseManaged`, which the audit columns of
|
|
14
|
+
* `timestamps()` and `authorship()` carry). `refine` runs on it in insert and
|
|
16
15
|
* update, and `hint` goes to the form field that edits it.
|
|
17
16
|
*/
|
|
18
17
|
type ColumnRule = {
|
|
@@ -73,8 +72,9 @@ declare function defineTableSchema<TTable extends ZenoTable>(table: TTable): Def
|
|
|
73
72
|
declare function defineTableSchema<TTable extends ZenoTable, TCoerce extends CoerceOptions = undefined, TOptions extends DefineTableSchemaOptions<TTable, TCoerce> = DefineTableSchemaOptions<TTable, TCoerce>>(table: TTable, options: TOptions): DefineTableSchemaResult<TTable, TCoerce, TOptions>;
|
|
74
73
|
/**
|
|
75
74
|
* `defineTableSchema` for code that runs only on the server, such as a sync
|
|
76
|
-
* job, which writes the columns `
|
|
77
|
-
*
|
|
75
|
+
* job, which writes the columns `serverManaged()` keeps from clients.
|
|
76
|
+
* Identity, audit and `databaseManaged()` columns stay out, as the database
|
|
77
|
+
* writes them. Never parse what a
|
|
78
78
|
* client sends with it: a server action's input is a client's.
|
|
79
79
|
*/
|
|
80
80
|
declare function defineServerTableSchema<TTable extends ZenoTable>(table: TTable): DefineTableSchemaResult<TTable, undefined, NoTableSchemaOptions, ServerExcludes>;
|
|
@@ -136,5 +136,4 @@ declare const ownedRows: <TSchema extends OwnableSchema, TParentKey extends Colu
|
|
|
136
136
|
* as a diff in review.
|
|
137
137
|
*/
|
|
138
138
|
declare const writableColumns: (exports: Record<string, unknown>) => Record<string, string[]>;
|
|
139
|
-
//#endregion
|
|
140
139
|
export { type DefineTableSchemaOptions, type DefineTableSchemaResult, type OwnedRows, type ZenoTable, createInsertSchema, createSchemaFactory, createSelectSchema, createUpdateSchema, defineServerTableSchema, defineTableSchema, ownedRows, writableColumns };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Table, getColumns, getTableName, getTableUniqueName, is } from "drizzle-orm";
|
|
2
2
|
import { createInsertSchema, createSchemaFactory, createSchemaFactory as createSchemaFactory$1, createSelectSchema, createUpdateSchema } from "drizzle-orm/zod";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
|
|
4
|
+
// src/index.ts
|
|
5
5
|
const COLUMN_RULES_KEY = "~zeno";
|
|
6
6
|
const columnRules = (table) => table[COLUMN_RULES_KEY].columns;
|
|
7
7
|
const CLIENT_EXCLUDES = /* @__PURE__ */ new Set(["database", "server"]);
|
|
@@ -55,7 +55,7 @@ const isPositiveIdentity = (column) => {
|
|
|
55
55
|
};
|
|
56
56
|
const toPositive = (schema) => typeof schema.positive === "function" ? schema.positive() : schema;
|
|
57
57
|
const positiveCheck = (column) => isPositiveIdentity(column) ? toPositive : void 0;
|
|
58
|
-
const TIMESTAMP = /^(\d{4}-\d{2}-\d{2})[T ](?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?([+-](?:0\d|1[0-5])(?::?[0-5]\d)?|Z)
|
|
58
|
+
const TIMESTAMP = /^(\d{4}-\d{2}-\d{2})[T ](?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?([+-](?:0\d|1[0-5])(?::?[0-5]\d)?|Z)?$/u;
|
|
59
59
|
const INFINITIES = /* @__PURE__ */ new Set(["-infinity", "infinity"]);
|
|
60
60
|
const ISO_DATE = z.iso.date();
|
|
61
61
|
const isDate = (value) => ISO_DATE.safeParse(value).success;
|
|
@@ -157,5 +157,4 @@ const writableColumns = (exports) => {
|
|
|
157
157
|
for (const [name, table] of tables) columns[name] = Object.keys(buildTableSchema("writableColumns", table, void 0, CLIENT_EXCLUDES).insert.shape).sort();
|
|
158
158
|
return columns;
|
|
159
159
|
};
|
|
160
|
-
//#endregion
|
|
161
160
|
export { createInsertSchema, createSchemaFactory, createSelectSchema, createUpdateSchema, defineServerTableSchema, defineTableSchema, ownedRows, writableColumns };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeno-lib/schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "https://github.com/zeno-lib/zeno.git",
|
|
6
6
|
"directory": "packages/schema"
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
],
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@zeno-lib/typescript": "^1.2.0",
|
|
22
|
-
"drizzle-orm": "1.0.0-rc.5
|
|
23
|
-
"tsdown": "^0.23.
|
|
22
|
+
"drizzle-orm": "1.0.0-rc.5",
|
|
23
|
+
"tsdown": "^0.23.1",
|
|
24
24
|
"typescript": "7.0.2",
|
|
25
|
-
"vitest": "5.0.
|
|
26
|
-
"zod": "^4.6.
|
|
25
|
+
"vitest": "5.0.5",
|
|
26
|
+
"zod": "^4.6.7"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"drizzle-orm": "1.0.0-rc.5
|
|
29
|
+
"drizzle-orm": "1.0.0-rc.5",
|
|
30
30
|
"zod": ">=4"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
package/src/index.ts
CHANGED
|
@@ -39,9 +39,9 @@ const COLUMN_RULES_KEY = "~zeno"
|
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* What a column marker from `@zeno-lib/db/schema` records. `writer` says who
|
|
42
|
-
* writes the column when a client doesn't: `"server"` code (`
|
|
43
|
-
* only the `"database"`,
|
|
44
|
-
* `timestamps()` and `authorship()`
|
|
42
|
+
* writes the column when a client doesn't: `"server"` code (`serverManaged`),
|
|
43
|
+
* or only the `"database"` (`databaseManaged`, which the audit columns of
|
|
44
|
+
* `timestamps()` and `authorship()` carry). `refine` runs on it in insert and
|
|
45
45
|
* update, and `hint` goes to the form field that edits it.
|
|
46
46
|
*/
|
|
47
47
|
type ColumnRule = {
|
|
@@ -366,7 +366,8 @@ const positiveCheck = (column: Column) =>
|
|
|
366
366
|
// minutes, up to the ±15:59 Postgres takes.
|
|
367
367
|
// The groups are the date and the offset.
|
|
368
368
|
const TIMESTAMP =
|
|
369
|
-
|
|
369
|
+
// biome-ignore lint/style/useNamedCaptureGroup: named groups need ES2018, past the ES6 target
|
|
370
|
+
/^(\d{4}-\d{2}-\d{2})[T ](?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?([+-](?:0\d|1[0-5])(?::?[0-5]\d)?|Z)?$/u
|
|
370
371
|
|
|
371
372
|
// Postgres's special values, which the string mode reads back as they are.
|
|
372
373
|
const INFINITIES: ReadonlySet<string> = new Set(["-infinity", "infinity"])
|
|
@@ -447,8 +448,8 @@ const withChecks = (
|
|
|
447
448
|
return composeRefinements(refinements, generated)
|
|
448
449
|
}
|
|
449
450
|
|
|
450
|
-
// Zod rejects an omit key the shape lacks, which a generated or
|
|
451
|
-
//
|
|
451
|
+
// Zod rejects an omit key the shape lacks, which a generated or managed column
|
|
452
|
+
// would be.
|
|
452
453
|
const omitPresent = <TSchema extends z.ZodObject>(
|
|
453
454
|
schema: TSchema,
|
|
454
455
|
keys: readonly string[]
|
|
@@ -540,8 +541,9 @@ function defineTableSchema(
|
|
|
540
541
|
|
|
541
542
|
/**
|
|
542
543
|
* `defineTableSchema` for code that runs only on the server, such as a sync
|
|
543
|
-
* job, which writes the columns `
|
|
544
|
-
*
|
|
544
|
+
* job, which writes the columns `serverManaged()` keeps from clients.
|
|
545
|
+
* Identity, audit and `databaseManaged()` columns stay out, as the database
|
|
546
|
+
* writes them. Never parse what a
|
|
545
547
|
* client sends with it: a server action's input is a client's.
|
|
546
548
|
*/
|
|
547
549
|
function defineServerTableSchema<TTable extends ZenoTable>(
|