@nanokajs/core 1.6.0 → 1.7.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/README.md +11 -11
- package/dist/{chunk-GZC7BVP2.js → chunk-SHPR4NTZ.js} +29 -3
- package/dist/{chunk-GZC7BVP2.js.map → chunk-SHPR4NTZ.js.map} +1 -1
- package/dist/cli.js +8 -2
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/config.js +1 -1
- package/dist/{factories-Cmvx0495.d.ts → factories-CiYoD7dl.d.ts} +41 -2
- package/dist/index.d.ts +43 -26
- package/dist/index.js +19 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -13,7 +13,29 @@ interface FieldModifiers {
|
|
|
13
13
|
max?: number;
|
|
14
14
|
policy?: FieldPolicy;
|
|
15
15
|
}
|
|
16
|
-
type FieldKind = 'string' | 'uuid' | 'number' | 'integer' | 'boolean' | 'timestamp' | 'json';
|
|
16
|
+
type FieldKind = 'string' | 'uuid' | 'number' | 'integer' | 'boolean' | 'timestamp' | 'json' | 'relation';
|
|
17
|
+
type RelationKind = 'hasMany' | 'belongsTo';
|
|
18
|
+
interface RelationTargetLike {
|
|
19
|
+
readonly fields: Record<string, {
|
|
20
|
+
kind: FieldKind;
|
|
21
|
+
zodBase: unknown;
|
|
22
|
+
drizzleColumn(name: string): unknown;
|
|
23
|
+
}>;
|
|
24
|
+
readonly tableName: string;
|
|
25
|
+
}
|
|
26
|
+
interface RelationDef<Target extends RelationTargetLike = RelationTargetLike, FK extends string = string> {
|
|
27
|
+
readonly kind: 'relation';
|
|
28
|
+
readonly relationKind: RelationKind;
|
|
29
|
+
readonly target: Target | (() => Target);
|
|
30
|
+
readonly foreignKey: FK;
|
|
31
|
+
readonly tsType: never;
|
|
32
|
+
readonly zodBase: z.ZodNever;
|
|
33
|
+
readonly modifiers: {};
|
|
34
|
+
drizzleColumn(name: string): never;
|
|
35
|
+
}
|
|
36
|
+
type IsRelationField<F> = F extends {
|
|
37
|
+
kind: 'relation';
|
|
38
|
+
} ? true : false;
|
|
17
39
|
/**
|
|
18
40
|
* Represents a typed database field with Zod validation and Drizzle column mapping.
|
|
19
41
|
*
|
|
@@ -431,6 +453,17 @@ declare class JsonFieldBuilder<T = unknown, TS = T, Mods extends FieldModifiers
|
|
|
431
453
|
policy: 'readOnly';
|
|
432
454
|
}>;
|
|
433
455
|
}
|
|
456
|
+
declare class RelationFieldBuilder<Target extends RelationTargetLike, FK extends string, Kind extends RelationKind> {
|
|
457
|
+
readonly kind: "relation";
|
|
458
|
+
readonly relationKind: Kind;
|
|
459
|
+
readonly target: Target | (() => Target);
|
|
460
|
+
readonly foreignKey: FK;
|
|
461
|
+
readonly tsType: never;
|
|
462
|
+
readonly modifiers: {};
|
|
463
|
+
constructor(relationKind: Kind, target: Target | (() => Target), foreignKey: FK);
|
|
464
|
+
get zodBase(): z.ZodNever;
|
|
465
|
+
drizzleColumn(name: string): never;
|
|
466
|
+
}
|
|
434
467
|
declare function jsonField<S extends z.ZodTypeAny>(schema: S): JsonFieldBuilder<z.infer<S>, z.infer<S>, {}>;
|
|
435
468
|
declare function jsonField<T = unknown>(): JsonFieldBuilder<T, T, {}>;
|
|
436
469
|
/**
|
|
@@ -464,6 +497,12 @@ declare const t: {
|
|
|
464
497
|
* Drizzle 型が欲しい場合は生成後に手動で書き換えるか `as` を使うこと。
|
|
465
498
|
*/
|
|
466
499
|
json: typeof jsonField;
|
|
500
|
+
hasMany<Target extends RelationTargetLike, FK extends string>(target: Target | (() => Target), options: {
|
|
501
|
+
foreignKey: FK;
|
|
502
|
+
}): RelationFieldBuilder<Target, FK, "hasMany">;
|
|
503
|
+
belongsTo<Target extends RelationTargetLike, FK extends string>(target: Target | (() => Target), options: {
|
|
504
|
+
foreignKey: FK;
|
|
505
|
+
}): RelationFieldBuilder<Target, FK, "belongsTo">;
|
|
467
506
|
};
|
|
468
507
|
|
|
469
|
-
export { type Field as F, type InferFieldType as I, type FieldPolicy as a, type FieldModifiers as b, t };
|
|
508
|
+
export { type Field as F, type InferFieldType as I, type RelationDef as R, type FieldPolicy as a, type FieldModifiers as b, type IsRelationField as c, RelationFieldBuilder as d, type RelationKind as e, type RelationTargetLike as f, t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { D1Database } from '@cloudflare/workers-types';
|
|
2
2
|
import { A as Adapter } from './types-D2QDVyks.js';
|
|
3
|
-
import { F as Field, I as InferFieldType, a as FieldPolicy } from './factories-
|
|
4
|
-
export { b as FieldModifiers, t } from './factories-
|
|
3
|
+
import { F as Field, I as InferFieldType, a as FieldPolicy } from './factories-CiYoD7dl.js';
|
|
4
|
+
export { b as FieldModifiers, c as IsRelationField, R as RelationDef, d as RelationFieldBuilder, e as RelationKind, f as RelationTargetLike, t } from './factories-CiYoD7dl.js';
|
|
5
5
|
import { Hook } from '@hono/zod-validator';
|
|
6
6
|
import { SQL } from 'drizzle-orm';
|
|
7
7
|
import { SQLiteTableWithColumns, AnySQLiteColumn } from 'drizzle-orm/sqlite-core';
|
|
@@ -81,6 +81,16 @@ interface OpenAPIDocument {
|
|
|
81
81
|
readonly paths: Record<string, Record<string, unknown>>;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* @internal
|
|
86
|
+
* Extracts keys of non-relation fields from a Fields record.
|
|
87
|
+
* Relation fields (kind: 'relation') are excluded from DB column types, RowType, etc.
|
|
88
|
+
*/
|
|
89
|
+
type NonRelationKeys<Fields extends Record<string, Field<any, any, any>>> = {
|
|
90
|
+
[K in keyof Fields]: Fields[K] extends {
|
|
91
|
+
kind: 'relation';
|
|
92
|
+
} ? never : K;
|
|
93
|
+
}[keyof Fields];
|
|
84
94
|
/**
|
|
85
95
|
* Options for findMany query.
|
|
86
96
|
* `limit` is required (no default).
|
|
@@ -107,38 +117,38 @@ interface FindAllOptions<Fields extends Record<string, Field<any, any, any>>> {
|
|
|
107
117
|
/**
|
|
108
118
|
* Order-by specification: single field, or field with direction, or array of multiple.
|
|
109
119
|
*/
|
|
110
|
-
type OrderBy<Fields extends Record<string, Field<any, any, any>>> = (
|
|
111
|
-
readonly column:
|
|
120
|
+
type OrderBy<Fields extends Record<string, Field<any, any, any>>> = (NonRelationKeys<Fields> & string) | {
|
|
121
|
+
readonly column: NonRelationKeys<Fields> & string;
|
|
112
122
|
readonly direction?: 'asc' | 'desc';
|
|
113
|
-
} | ReadonlyArray<(
|
|
114
|
-
readonly column:
|
|
123
|
+
} | ReadonlyArray<(NonRelationKeys<Fields> & string) | {
|
|
124
|
+
readonly column: NonRelationKeys<Fields> & string;
|
|
115
125
|
readonly direction?: 'asc' | 'desc';
|
|
116
126
|
}>;
|
|
117
127
|
/**
|
|
118
128
|
* Where clause object: each key is a field name, each value is the desired equality.
|
|
119
129
|
*/
|
|
120
130
|
type Where<Fields extends Record<string, Field<any, any, any>>> = {
|
|
121
|
-
readonly [K in
|
|
131
|
+
readonly [K in NonRelationKeys<Fields>]?: InferFieldType<Fields[K]>;
|
|
122
132
|
};
|
|
123
133
|
/**
|
|
124
134
|
* Identifier or Where clause: can be a primary key value or a Where object.
|
|
125
135
|
*/
|
|
126
136
|
type IdOrWhere<Fields extends Record<string, Field<any, any, any>>> = string | number | Where<Fields>;
|
|
127
137
|
/**
|
|
128
|
-
* Row type: full record type from fields.
|
|
138
|
+
* Row type: full record type from fields, excluding relation fields.
|
|
129
139
|
*/
|
|
130
140
|
type RowType<Fields extends Record<string, Field<any, any, any>>> = {
|
|
131
|
-
[K in
|
|
141
|
+
[K in NonRelationKeys<Fields>]: InferFieldType<Fields[K]>;
|
|
132
142
|
};
|
|
133
143
|
/**
|
|
134
|
-
* Drizzle table type with columns typed to match the model's Fields.
|
|
144
|
+
* Drizzle table type with columns typed to match the model's Fields (excluding relation fields).
|
|
135
145
|
* Allows type-safe column access via Model.table.fieldName.
|
|
136
146
|
*/
|
|
137
147
|
type ModelTable<Fields extends Record<string, Field<any, any, any>>> = SQLiteTableWithColumns<{
|
|
138
148
|
name: string;
|
|
139
149
|
schema: undefined;
|
|
140
150
|
columns: {
|
|
141
|
-
[K in
|
|
151
|
+
[K in NonRelationKeys<Fields>]: AnySQLiteColumn;
|
|
142
152
|
};
|
|
143
153
|
dialect: 'sqlite';
|
|
144
154
|
}>;
|
|
@@ -209,11 +219,12 @@ type IsRequired<F extends Field<any, any, any>> = F extends Field<any, {
|
|
|
209
219
|
* - all other fields are required
|
|
210
220
|
* - `serverOnly` fields are completely excluded (cannot be passed even internally)
|
|
211
221
|
* - `writeOnly` fields are included as required (they are input fields by design)
|
|
222
|
+
* - relation fields are completely excluded (no DB column)
|
|
212
223
|
*/
|
|
213
224
|
type CreateInput<Fields extends Record<string, Field<any, any, any>>> = {
|
|
214
|
-
[K in
|
|
225
|
+
[K in NonRelationKeys<Fields> as IsRequired<Fields[K]> extends true ? K extends ServerOnlyKeys<Fields> ? never : K : never]: InferFieldType<Fields[K]>;
|
|
215
226
|
} & {
|
|
216
|
-
[K in
|
|
227
|
+
[K in NonRelationKeys<Fields> as IsRequired<Fields[K]> extends true ? never : K extends ServerOnlyKeys<Fields> ? never : K]?: InferFieldType<Fields[K]>;
|
|
217
228
|
};
|
|
218
229
|
type FieldAccessor<K extends string> = {
|
|
219
230
|
readonly [Key in K]: Key;
|
|
@@ -226,11 +237,12 @@ interface SchemaOptions<K extends string = string> {
|
|
|
226
237
|
/**
|
|
227
238
|
* @internal
|
|
228
239
|
* Extracts a Zod shape from fields for the Apply type.
|
|
229
|
-
*
|
|
240
|
+
* Only non-relation fields are included (relation fields have zodBase: ZodNever
|
|
241
|
+
* and are skipped at runtime in buildBaseObject).
|
|
230
242
|
* Indexed access ensures concrete Zod types are preserved (not `any`).
|
|
231
243
|
*/
|
|
232
244
|
type FieldsToZodShape<Fields extends Record<string, Field<any, any, any>>> = {
|
|
233
|
-
[K in
|
|
245
|
+
[K in NonRelationKeys<Fields>]: Fields[K]['zodBase'];
|
|
234
246
|
};
|
|
235
247
|
/**
|
|
236
248
|
* @internal
|
|
@@ -352,7 +364,7 @@ type ValidatorInput<Target extends keyof ValidationTargets, Schema extends z.Zod
|
|
|
352
364
|
* Uses RowType<Fields> directly for input/output type computation
|
|
353
365
|
* to ensure Zod v3/v4 compatibility (z.input<ZodTypeAny> returns unknown in Zod v4).
|
|
354
366
|
*/
|
|
355
|
-
type ModelValidatorReturn<Fields extends Record<string, Field<any, any, any>>, Target extends keyof ValidationTargets, Opts extends SchemaOptions<
|
|
367
|
+
type ModelValidatorReturn<Fields extends Record<string, Field<any, any, any>>, Target extends keyof ValidationTargets, Opts extends SchemaOptions<NonRelationKeys<Fields> & string> | undefined> = MiddlewareHandler<any, string, ValidatorInput<Target, Apply<FieldsToZodShape<Fields>, Opts>, ApplyToRecord<RowType<Fields>, Opts>, ApplyToRecord<RowType<Fields>, Opts>>>;
|
|
356
368
|
|
|
357
369
|
/**
|
|
358
370
|
* Represents a database model with type-safe schema derivation and CRUD operations.
|
|
@@ -369,7 +381,7 @@ interface Model<Fields extends Record<string, Field<any, any, any>>> {
|
|
|
369
381
|
* const CreateSchema = User.schema({ omit: ['passwordHash'] })
|
|
370
382
|
* const UpdateSchema = User.schema({ partial: true, pick: ['name', 'email'] })
|
|
371
383
|
*/
|
|
372
|
-
schema<Opts extends SchemaOptions<
|
|
384
|
+
schema<Opts extends SchemaOptions<NonRelationKeys<Fields> & string> | undefined>(opts?: Opts): Apply<FieldsToZodShape<Fields>, Opts>;
|
|
373
385
|
/**
|
|
374
386
|
* Returns a Hono middleware validator derived from this model's schema.
|
|
375
387
|
* Integrates with @hono/zod-validator to validate request inputs.
|
|
@@ -393,7 +405,7 @@ interface Model<Fields extends Record<string, Field<any, any, any>>> {
|
|
|
393
405
|
*/
|
|
394
406
|
validator<Target extends keyof ValidationTargets, E extends Env = Env, P extends string = string>(target: Target, preset: 'create', hook?: Hook<Omit<RowType<Fields>, PolicyOmitKeys<Fields, 'input-create'> & string>, E, P, Target>): MiddlewareHandler<E, P, ValidatorInput<Target, z.ZodObject<z.ZodRawShape>, Omit<RowType<Fields>, PolicyOmitKeys<Fields, 'input-create'> & string>, Omit<RowType<Fields>, PolicyOmitKeys<Fields, 'input-create'> & string>>>;
|
|
395
407
|
validator<Target extends keyof ValidationTargets, E extends Env = Env, P extends string = string>(target: Target, preset: 'update', hook?: Hook<Partial<Omit<RowType<Fields>, PolicyOmitKeys<Fields, 'input-update'> & string>>, E, P, Target>): MiddlewareHandler<E, P, ValidatorInput<Target, z.ZodObject<z.ZodRawShape>, Partial<Omit<RowType<Fields>, PolicyOmitKeys<Fields, 'input-update'> & string>>, Partial<Omit<RowType<Fields>, PolicyOmitKeys<Fields, 'input-update'> & string>>>>;
|
|
396
|
-
validator<Target extends keyof ValidationTargets, Opts extends SchemaOptions<
|
|
408
|
+
validator<Target extends keyof ValidationTargets, Opts extends SchemaOptions<NonRelationKeys<Fields> & string> | undefined, E extends Env = Env, P extends string = string>(target: Target, opts?: Opts, hook?: Hook<z.output<Apply<FieldsToZodShape<Fields>, Opts>>, E, P, Target>): ModelValidatorReturn<Fields, Target, Opts>;
|
|
397
409
|
/**
|
|
398
410
|
* Returns a Zod schema for API input, with policy-based field exclusions applied.
|
|
399
411
|
* - 'create': serverOnly and readOnly fields are excluded
|
|
@@ -401,13 +413,13 @@ interface Model<Fields extends Record<string, Field<any, any, any>>> {
|
|
|
401
413
|
*
|
|
402
414
|
* The return type precisely reflects policy-derived omissions using PolicyOmitKeys.
|
|
403
415
|
*/
|
|
404
|
-
inputSchema<Opts extends SchemaOptions<
|
|
405
|
-
inputSchema<Opts extends SchemaOptions<
|
|
416
|
+
inputSchema<Opts extends SchemaOptions<NonRelationKeys<Fields> & string> | undefined = undefined>(usage: 'create', opts?: Opts): z.ZodObject<ApplyShape<Omit<FieldsToZodShape<Fields>, PolicyOmitKeys<Fields, 'input-create'> & string>, Opts>>;
|
|
417
|
+
inputSchema<Opts extends SchemaOptions<NonRelationKeys<Fields> & string> | undefined = undefined>(usage: 'update', opts?: Opts): z.ZodObject<ApplyShape<Omit<FieldsToZodShape<Fields>, PolicyOmitKeys<Fields, 'input-update'> & string>, Opts extends undefined ? {
|
|
406
418
|
partial: true;
|
|
407
419
|
} : Opts & {
|
|
408
420
|
partial: true;
|
|
409
421
|
}>>;
|
|
410
|
-
inputSchema(usage: 'create' | 'update', opts?: SchemaOptions<
|
|
422
|
+
inputSchema(usage: 'create' | 'update', opts?: SchemaOptions<NonRelationKeys<Fields> & string>): z.ZodObject<z.ZodRawShape>;
|
|
411
423
|
/**
|
|
412
424
|
* Returns a Zod schema for API output, with policy-based field exclusions applied.
|
|
413
425
|
* - serverOnly and writeOnly fields are excluded
|
|
@@ -415,7 +427,7 @@ interface Model<Fields extends Record<string, Field<any, any, any>>> {
|
|
|
415
427
|
*
|
|
416
428
|
* The return type precisely reflects policy-derived omissions using PolicyOmitKeys.
|
|
417
429
|
*/
|
|
418
|
-
outputSchema<Opts extends SchemaOptions<
|
|
430
|
+
outputSchema<Opts extends SchemaOptions<NonRelationKeys<Fields> & string> | undefined = undefined>(opts?: Opts): z.ZodObject<ApplyShape<Omit<FieldsToZodShape<Fields>, PolicyOmitKeys<Fields, 'output'> & string>, Opts>>;
|
|
419
431
|
/**
|
|
420
432
|
* Parses a DB row through outputSchema and returns the safe response object.
|
|
421
433
|
* Equivalent to `User.outputSchema().parse(row)`.
|
|
@@ -529,7 +541,7 @@ interface NanokaModel<Fields extends Record<string, Field<any, any, any>>> {
|
|
|
529
541
|
* Returns a Zod schema derived from this model's fields.
|
|
530
542
|
* Supports pick, omit, and partial transformations.
|
|
531
543
|
*/
|
|
532
|
-
schema<Opts extends SchemaOptions<
|
|
544
|
+
schema<Opts extends SchemaOptions<NonRelationKeys<Fields> & string> | undefined = undefined>(opts?: Opts): Apply<FieldsToZodShape<Fields>, Opts>;
|
|
533
545
|
/**
|
|
534
546
|
* Returns a Hono middleware validator for this model.
|
|
535
547
|
* The optional `hook` argument is passed through to @hono/zod-validator.
|
|
@@ -537,15 +549,15 @@ interface NanokaModel<Fields extends Record<string, Field<any, any, any>>> {
|
|
|
537
549
|
*/
|
|
538
550
|
validator<Target extends keyof hono.ValidationTargets, E extends Env$1 = Env$1, P extends string = string>(target: Target, preset: 'create', hook?: Hook<Omit<RowType<Fields>, PolicyOmitKeys<Fields, 'input-create'> & string>, E, P, Target>): MiddlewareHandler<E, P, ValidatorInput<Target, z.ZodObject<z.ZodRawShape>, Omit<RowType<Fields>, PolicyOmitKeys<Fields, 'input-create'> & string>, Omit<RowType<Fields>, PolicyOmitKeys<Fields, 'input-create'> & string>>>;
|
|
539
551
|
validator<Target extends keyof hono.ValidationTargets, E extends Env$1 = Env$1, P extends string = string>(target: Target, preset: 'update', hook?: Hook<Partial<Omit<RowType<Fields>, PolicyOmitKeys<Fields, 'input-update'> & string>>, E, P, Target>): MiddlewareHandler<E, P, ValidatorInput<Target, z.ZodObject<z.ZodRawShape>, Partial<Omit<RowType<Fields>, PolicyOmitKeys<Fields, 'input-update'> & string>>, Partial<Omit<RowType<Fields>, PolicyOmitKeys<Fields, 'input-update'> & string>>>>;
|
|
540
|
-
validator<Target extends keyof hono.ValidationTargets, Opts extends SchemaOptions<
|
|
552
|
+
validator<Target extends keyof hono.ValidationTargets, Opts extends SchemaOptions<NonRelationKeys<Fields> & string> | undefined = undefined, E extends Env$1 = Env$1, P extends string = string>(target: Target, opts?: Opts, hook?: Hook<z.output<Apply<FieldsToZodShape<Fields>, Opts>>, E, P, Target>): ModelValidatorReturn<Fields, Target, Opts>;
|
|
541
553
|
/**
|
|
542
554
|
* Returns a Zod schema for API input, with policy-based field exclusions applied.
|
|
543
555
|
*/
|
|
544
|
-
inputSchema(usage: 'create' | 'update', opts?: SchemaOptions<
|
|
556
|
+
inputSchema(usage: 'create' | 'update', opts?: SchemaOptions<NonRelationKeys<Fields> & string>): z.ZodObject<z.ZodRawShape>;
|
|
545
557
|
/**
|
|
546
558
|
* Returns a Zod schema for API output, with policy-based field exclusions applied.
|
|
547
559
|
*/
|
|
548
|
-
outputSchema(opts?: SchemaOptions<
|
|
560
|
+
outputSchema(opts?: SchemaOptions<NonRelationKeys<Fields> & string>): z.ZodObject<z.ZodRawShape>;
|
|
549
561
|
/**
|
|
550
562
|
* Parses a DB row through outputSchema and returns the safe response object.
|
|
551
563
|
*/
|
|
@@ -558,6 +570,11 @@ interface NanokaModel<Fields extends Record<string, Field<any, any, any>>> {
|
|
|
558
570
|
* `limit` is required (no default) to prevent accidental unbounded queries.
|
|
559
571
|
*/
|
|
560
572
|
findMany(options: FindManyOptions<Fields>): Promise<RowType<Fields>[]>;
|
|
573
|
+
/**
|
|
574
|
+
* Fetches all rows without a LIMIT clause.
|
|
575
|
+
* For batch processing / admin tooling. Apply an app-level size guard when used in request handlers.
|
|
576
|
+
*/
|
|
577
|
+
findAll(options?: FindAllOptions<Fields>): Promise<RowType<Fields>[]>;
|
|
561
578
|
/**
|
|
562
579
|
* Fetches a single row by primary key or where clause.
|
|
563
580
|
* Returns null if not found.
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { t } from './chunk-
|
|
1
|
+
export { t } from './chunk-SHPR4NTZ.js';
|
|
2
2
|
import { drizzle } from 'drizzle-orm/d1';
|
|
3
3
|
import { zValidator } from '@hono/zod-validator';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -23,7 +23,10 @@ function resolveSchemaOptionKeys(opt, accessor) {
|
|
|
23
23
|
}
|
|
24
24
|
function buildFieldAccessor(fields) {
|
|
25
25
|
const acc = {};
|
|
26
|
-
for (const k of Object.
|
|
26
|
+
for (const [k, field] of Object.entries(fields)) {
|
|
27
|
+
if (field.kind === "relation") continue;
|
|
28
|
+
acc[k] = k;
|
|
29
|
+
}
|
|
27
30
|
return Object.freeze(acc);
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -37,6 +40,13 @@ function computeForcedOmit(fields) {
|
|
|
37
40
|
}
|
|
38
41
|
return omit;
|
|
39
42
|
}
|
|
43
|
+
function computeRelationOmit(fields) {
|
|
44
|
+
const keys = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
46
|
+
if (field.kind === "relation") keys.add(key);
|
|
47
|
+
}
|
|
48
|
+
return keys;
|
|
49
|
+
}
|
|
40
50
|
function computeOptionalOmit(fields, target) {
|
|
41
51
|
const omit = [];
|
|
42
52
|
for (const [key, field] of Object.entries(fields)) {
|
|
@@ -51,7 +61,9 @@ function computeOptionalOmit(fields, target) {
|
|
|
51
61
|
return omit;
|
|
52
62
|
}
|
|
53
63
|
function derivePolicyOptions(fields, usage, userOpts, accessor) {
|
|
54
|
-
const
|
|
64
|
+
const forcedBase = computeForcedOmit(fields);
|
|
65
|
+
const relationOmit = computeRelationOmit(fields);
|
|
66
|
+
const forced = [.../* @__PURE__ */ new Set([...forcedBase, ...relationOmit])];
|
|
55
67
|
const optional = computeOptionalOmit(fields, usage);
|
|
56
68
|
const acc = accessor ?? {};
|
|
57
69
|
const resolvedPick = resolveSchemaOptionKeys(userOpts?.pick, acc);
|
|
@@ -79,6 +91,7 @@ function derivePolicyOptions(fields, usage, userOpts, accessor) {
|
|
|
79
91
|
function buildBaseObject(fields) {
|
|
80
92
|
const shape = {};
|
|
81
93
|
for (const [key, field] of Object.entries(fields)) {
|
|
94
|
+
if (field.kind === "relation") continue;
|
|
82
95
|
shape[key] = field.zodBase;
|
|
83
96
|
}
|
|
84
97
|
return z.object(shape);
|
|
@@ -129,6 +142,7 @@ function toOpenAPISchema(fields, usage, opts) {
|
|
|
129
142
|
for (const [key, zodSchema] of Object.entries(shape)) {
|
|
130
143
|
const field = fields[key];
|
|
131
144
|
if (field === void 0) continue;
|
|
145
|
+
if (field.kind === "relation") continue;
|
|
132
146
|
properties[key] = fieldToOpenAPISchema(field, opts?.strict);
|
|
133
147
|
if (field.modifiers.policy === "writeOnly" && (usage === "create" || usage === "update")) {
|
|
134
148
|
properties[key].writeOnly = true;
|
|
@@ -526,6 +540,7 @@ async function deleteImpl(adapter, table, fields, idOrWhere) {
|
|
|
526
540
|
function buildTable(tableName, fields) {
|
|
527
541
|
const columns = {};
|
|
528
542
|
for (const [key, field] of Object.entries(fields)) {
|
|
543
|
+
if (field.kind === "relation") continue;
|
|
529
544
|
columns[key] = field.drizzleColumn(key);
|
|
530
545
|
}
|
|
531
546
|
return sqliteTable(tableName, columns);
|
|
@@ -717,6 +732,7 @@ function nanoka(adapter) {
|
|
|
717
732
|
toOpenAPIComponent: () => inner.toOpenAPIComponent(),
|
|
718
733
|
toOpenAPISchema: (usage) => inner.toOpenAPISchema(usage),
|
|
719
734
|
findMany: (options) => inner.findMany(adapter, options),
|
|
735
|
+
findAll: (options) => inner.findAll(adapter, options),
|
|
720
736
|
findOne: (idOrWhere) => inner.findOne(adapter, idOrWhere),
|
|
721
737
|
create: (data) => inner.create(adapter, data),
|
|
722
738
|
update: (idOrWhere, data) => inner.update(adapter, idOrWhere, data),
|