@cyphra/runtime 0.7.0 → 0.8.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.ts CHANGED
@@ -230,10 +230,36 @@ type VectorIndexKeys<TM extends TypeMap, M extends keyof TM> = TM[M] extends {
230
230
  type FulltextIndexNames<TM extends TypeMap, M extends keyof TM> = TM[M] extends {
231
231
  fulltextIndexes: infer V extends string;
232
232
  } ? V : never;
233
+ /** Any JSON value: the TypeScript type of a `Json` field. */
234
+ type JsonValue = string | number | boolean | null | readonly JsonValue[] | {
235
+ readonly [key: string]: JsonValue;
236
+ };
233
237
  /** Types with `lt` / `lte` / `gt` / `gte` (strings compare lexicographically, by code point). */
234
- type Comparable = number | string | Date;
238
+ type Comparable = number | bigint | string | Date;
239
+ /**
240
+ * `true` for a union of string literals (an enum field), `false` for `string` and other types.
241
+ */
242
+ type IsEnum<T> = [T] extends [string] ? string extends T ? false : [T] extends [never] ? false : true : false;
243
+ /** `true` for `JsonValue` (a `Json` field): every JSON value is assignable to it. */
244
+ type IsJson<T> = [JsonValue] extends [T] ? true : false;
245
+ /**
246
+ * Json fields compare their whole stored JSON text: `null`, `{ equals }`, `{ not }` (no bare value,
247
+ * no deep queries).
248
+ */
249
+ type JsonFilter = null | {
250
+ equals?: JsonValue;
251
+ not?: JsonValue;
252
+ };
253
+ /** Enum fields: equality and membership, typed to the enum's values. */
254
+ type EnumFilter<T> = T | {
255
+ equals?: T;
256
+ not?: T | EnumFilter<T>;
257
+ in?: readonly NonNullable<T>[];
258
+ notIn?: readonly NonNullable<T>[];
259
+ };
235
260
  /** Filter on one scalar field. A bare value means `equals`; `null` means "property absent". */
236
- type ScalarFilter<T> = [NonNullable<T>] extends [readonly (infer E)[]] ? {
261
+ type ScalarFilter<T> = IsJson<T> extends true ? JsonFilter : IsEnum<NonNullable<T>> extends true ? EnumFilter<T> : BaseScalarFilter<T>;
262
+ type BaseScalarFilter<T> = [NonNullable<T>] extends [readonly (infer E)[]] ? {
237
263
  /** List contains this element. */
238
264
  has?: E;
239
265
  /** List contains every element. */
@@ -304,13 +330,24 @@ type SortOrder = "asc" | "desc";
304
330
  type ToManyRelations<TM extends TypeMap, M extends keyof TM> = {
305
331
  [R in keyof Relations<TM, M> & string]: Rel<TM, M, R>["many"] extends true ? R : never;
306
332
  }[keyof Relations<TM, M> & string];
307
- /** One `orderBy` entry: scalars, or a to-many relation by its count (`{ posts: { _count: "desc" } }`). */
333
+ /** Scalar keys of `Json` fields (they cannot be sorted). */
334
+ type JsonKeys<TM extends TypeMap, M extends keyof TM> = {
335
+ [K in keyof Scalars<TM, M>]: IsJson<Scalars<TM, M>[K]> extends true ? K : never;
336
+ }[keyof Scalars<TM, M>];
337
+ /**
338
+ * One `orderBy` entry: scalars, a to-many relation by its count (`{ posts: { _count: "desc" } }`),
339
+ * or a to-one relation by a scalar of the related node (`{ author: { name: "asc" } }`).
340
+ */
308
341
  type OrderByItem<TM extends TypeMap, M extends keyof TM> = {
309
- [K in Exclude<keyof Scalars<TM, M>, VectorKeys<TM, M>>]?: SortOrder;
342
+ [K in Exclude<keyof Scalars<TM, M>, VectorKeys<TM, M> | JsonKeys<TM, M>>]?: SortOrder;
310
343
  } & {
311
344
  [R in ToManyRelations<TM, M>]?: {
312
345
  _count?: SortOrder;
313
346
  };
347
+ } & {
348
+ [R in ToOneRelations<TM, M>]?: {
349
+ [K in Exclude<keyof Scalars<TM, Target<TM, M, R>>, VectorKeys<TM, Target<TM, M, R>> | JsonKeys<TM, Target<TM, M, R>>>]?: SortOrder;
350
+ };
314
351
  };
315
352
  type OrderByInput<TM extends TypeMap, M extends keyof TM> = OrderByItem<TM, M> | readonly OrderByItem<TM, M>[];
316
353
  /** Options for loading a relation inside `select` / `include`. */
@@ -402,8 +439,13 @@ type NumberUpdate = {
402
439
  decrement?: number;
403
440
  multiply?: number;
404
441
  };
442
+ type BigIntUpdate = {
443
+ increment?: bigint;
444
+ decrement?: bigint;
445
+ multiply?: bigint;
446
+ };
405
447
  type ScalarUpdate<TM extends TypeMap, M extends keyof TM> = {
406
- [K in keyof Scalars<TM, M>]?: Scalars<TM, M>[K] extends number | null ? Scalars<TM, M>[K] | NumberUpdate : Scalars<TM, M>[K];
448
+ [K in keyof Scalars<TM, M>]?: Scalars<TM, M>[K] extends number | null ? Scalars<TM, M>[K] | NumberUpdate : Scalars<TM, M>[K] extends bigint | null ? Scalars<TM, M>[K] | BigIntUpdate : Scalars<TM, M>[K];
407
449
  };
408
450
  type RelationUpdate<TM extends TypeMap, D extends RelationTypeDef> = RelationCreate<TM, D> & (D["many"] extends true ? {
409
451
  /** Remove the edge(s) to these nodes (the nodes are kept). */
@@ -464,13 +506,19 @@ type BatchResult = {
464
506
  count: number;
465
507
  };
466
508
  type ScalarKeys<TM extends TypeMap, M extends keyof TM> = keyof Scalars<TM, M> & string;
467
- /** Scalar keys whose (non-null) type is `number` (`Int`, `Float`): valid for `_sum` / `_avg`. */
509
+ /**
510
+ * Scalar keys whose (non-null) type is `number` or `bigint` (`Int`, `Float`, `BigInt`): valid for
511
+ * `_sum` / `_avg`.
512
+ */
468
513
  type NumericKeys<TM extends TypeMap, M extends keyof TM> = {
469
- [K in ScalarKeys<TM, M>]: NonNullable<Scalars<TM, M>[K]> extends number ? K : never;
514
+ [K in ScalarKeys<TM, M>]: NonNullable<Scalars<TM, M>[K]> extends number | bigint ? K : never;
470
515
  }[ScalarKeys<TM, M>];
471
- /** Scalar keys of `Int`, `Float`, `String`, `DateTime` and `Date` fields: valid for `_min` / `_max`. */
516
+ /**
517
+ * Scalar keys of `Int`, `Float`, `BigInt`, `String`, enum, `DateTime` and `Date` fields: valid for
518
+ * `_min` / `_max`.
519
+ */
472
520
  type MinMaxKeys<TM extends TypeMap, M extends keyof TM> = {
473
- [K in ScalarKeys<TM, M>]: NonNullable<Scalars<TM, M>[K]> extends number | string | Date ? K : never;
521
+ [K in ScalarKeys<TM, M>]: IsJson<Scalars<TM, M>[K]> extends true ? never : NonNullable<Scalars<TM, M>[K]> extends number | bigint | string | Date ? K : never;
474
522
  }[ScalarKeys<TM, M>];
475
523
  /** Rejects keys outside `Allowed` (TypeScript does not check excess keys of inferred generics). */
476
524
  type OnlyKeys<T, Allowed extends PropertyKey> = {
@@ -492,9 +540,9 @@ type FieldSel<K extends PropertyKey> = AggregateFieldsInput<K> | undefined;
492
540
  type AggregateProjection<TM extends TypeMap, M extends keyof TM, C, Su, Av, Mi, Ma> = {
493
541
  /** `true`: number of nodes. An object: `_all` (nodes) and/or fields (non-null values). */
494
542
  _count?: C extends object ? C & OnlyKeys<C, ScalarKeys<TM, M> | "_all"> : C;
495
- /** Sum of non-null values (`Int` / `Float`); `null` when there are none. */
543
+ /** Sum of non-null values (`Int` / `Float` / `BigInt`); `null` when there are none. */
496
544
  _sum?: Su & OnlyKeys<Su, NumericKeys<TM, M>>;
497
- /** Mean of non-null values (`Int` / `Float`); `null` when there are none. */
545
+ /** Mean of non-null values (`Int` / `Float` / `BigInt`, as a `number`); `null` when there are none. */
498
546
  _avg?: Av & OnlyKeys<Av, NumericKeys<TM, M>>;
499
547
  /** Smallest non-null value (`Int`, `Float`, `String`, `DateTime`, `Date`). */
500
548
  _min?: Mi & OnlyKeys<Mi, MinMaxKeys<TM, M>>;
@@ -507,6 +555,10 @@ type CountOut<C> = C extends true ? number : {
507
555
  type AggOut<Sel, V> = {
508
556
  [K in TrueKeys<Sel>]: V;
509
557
  };
558
+ /** `_sum` of a `BigInt` field is a `bigint`; of an `Int` / `Float` field, a `number`. */
559
+ type SumOut<TM extends TypeMap, M extends keyof TM, Sel> = {
560
+ [K in TrueKeys<Sel>]: (K extends keyof Scalars<TM, M> ? NonNullable<Scalars<TM, M>[K]> extends bigint ? bigint : number : number) | null;
561
+ };
510
562
  type ValueOut<TM extends TypeMap, M extends keyof TM, Sel> = {
511
563
  [K in TrueKeys<Sel> & keyof Scalars<TM, M>]: NonNullable<Scalars<TM, M>[K]> | null;
512
564
  };
@@ -514,7 +566,7 @@ type ValueOut<TM extends TypeMap, M extends keyof TM, Sel> = {
514
566
  type AggregateResult<TM extends TypeMap, M extends keyof TM, C, Su, Av, Mi, Ma> = Simplify<([C] extends [undefined] ? unknown : {
515
567
  _count: CountOut<Exclude<C, undefined>>;
516
568
  }) & ([Su] extends [undefined] ? unknown : {
517
- _sum: AggOut<Su, number | null>;
569
+ _sum: SumOut<TM, M, Su>;
518
570
  }) & ([Av] extends [undefined] ? unknown : {
519
571
  _avg: AggOut<Av, number | null>;
520
572
  }) & ([Mi] extends [undefined] ? unknown : {
@@ -555,7 +607,7 @@ type FilterObject<T> = Exclude<ScalarFilter<T>, T>;
555
607
  type HavingAggregates<TM extends TypeMap, M extends keyof TM, K> = {
556
608
  _count?: ScalarFilter<number>;
557
609
  } & (K extends NumericKeys<TM, M> ? {
558
- _sum?: ScalarFilter<number | null>;
610
+ _sum?: ScalarFilter<(NonNullable<Scalars<TM, M>[K & keyof Scalars<TM, M>]> extends bigint ? bigint : number) | null>;
559
611
  _avg?: ScalarFilter<number | null>;
560
612
  } : unknown) & (K extends MinMaxKeys<TM, M> ? {
561
613
  _min?: ScalarFilter<NonNullable<Scalars<TM, M>[K & keyof Scalars<TM, M>]> | null>;
@@ -950,4 +1002,4 @@ declare function escapeLucene(text: string): string;
950
1002
  */
951
1003
  declare function toNative(value: unknown): unknown;
952
1004
 
953
- export { type AggregateArgs, type AggregateFieldsInput, type AggregateResult, type BatchResult, type CountAggregateInput, type CountArgs, type CreateArgs, type CreateInput, type CreateManyArgs, CyphraClient, type CyphraClientOptions, type CyphraConnectionOptions, type CyphraDriverOptions, CyphraError, CyphraValidationError, type DelegateKey, type DeleteArgs, type DriverLike, type EdgeWhereInput, type FindManyArgs, type FindSimilarArgs, type FindUniqueArgs, type FulltextIndexNames, type GroupByArgs, type GroupByField, type GroupByKeys, type GroupByOrderByInput, type GroupByRow, type HavingInput, type IncludeInput, type MinMaxKeys, type ModelDelegate, type ModelDelegates, type ModelPath, type ModelTypeDef, NotFoundError, type NumericKeys, type OrderByInput, type OrmClient, type OrmOptions, type OrmTransactionClient, type Path, type PathEdge, type Payload, type QueryMode, type RelationCountInput, type RelationLoadArgs, type RelationTypeDef, type ScalarFilter, type SearchArgs, type SearchMode, type SearchResult, type SelectInput, type SelfRelations, type SessionLike, type ShortestPathArgs, type ShortestPathResult, type SimilarResult, type SortOrder, type ToManyRelations, type TransactionLike, type TraversalDirection, type TraversalResult, type TraverseArgs, type TypeMap, type UpdateArgs, type UpdateInput, type UpdateManyArgs, type UpsertArgs, type VectorFilter, type VectorIndexKeys, type VectorKeys, type WhereInput, type WhereUniqueInput, createCuid, createOrm, escapeLucene, toNative, toPlainRecord, toPlainRecords };
1005
+ export { type AggregateArgs, type AggregateFieldsInput, type AggregateResult, type BatchResult, type CountAggregateInput, type CountArgs, type CreateArgs, type CreateInput, type CreateManyArgs, CyphraClient, type CyphraClientOptions, type CyphraConnectionOptions, type CyphraDriverOptions, CyphraError, CyphraValidationError, type DelegateKey, type DeleteArgs, type DriverLike, type EdgeWhereInput, type EnumFilter, type FindManyArgs, type FindSimilarArgs, type FindUniqueArgs, type FulltextIndexNames, type GroupByArgs, type GroupByField, type GroupByKeys, type GroupByOrderByInput, type GroupByRow, type HavingInput, type IncludeInput, type JsonFilter, type JsonValue, type MinMaxKeys, type ModelDelegate, type ModelDelegates, type ModelPath, type ModelTypeDef, NotFoundError, type NumericKeys, type OrderByInput, type OrmClient, type OrmOptions, type OrmTransactionClient, type Path, type PathEdge, type Payload, type QueryMode, type RelationCountInput, type RelationLoadArgs, type RelationTypeDef, type ScalarFilter, type SearchArgs, type SearchMode, type SearchResult, type SelectInput, type SelfRelations, type SessionLike, type ShortestPathArgs, type ShortestPathResult, type SimilarResult, type SortOrder, type ToManyRelations, type TransactionLike, type TraversalDirection, type TraversalResult, type TraverseArgs, type TypeMap, type UpdateArgs, type UpdateInput, type UpdateManyArgs, type UpsertArgs, type VectorFilter, type VectorIndexKeys, type VectorKeys, type WhereInput, type WhereUniqueInput, createCuid, createOrm, escapeLucene, toNative, toPlainRecord, toPlainRecords };
package/dist/index.js CHANGED
@@ -211,11 +211,56 @@ function utcDateTime(d) {
211
211
  0
212
212
  );
213
213
  }
214
- function encodeOne(type, value, where) {
214
+ var BIGINT_MIN = -(2n ** 63n);
215
+ var BIGINT_MAX = 2n ** 63n - 1n;
216
+ function encodeBigInt(value, where) {
217
+ let b;
218
+ if (typeof value === "bigint") b = value;
219
+ else if (typeof value === "number" && Number.isSafeInteger(value)) b = BigInt(value);
220
+ else if (isInt(value)) b = BigInt(value.toString());
221
+ if (b === void 0) {
222
+ throw new CyphraValidationError(
223
+ `${where}: expected BigInt (a bigint), got ${describe(value)}.`
224
+ );
225
+ }
226
+ if (b < BIGINT_MIN || b > BIGINT_MAX) {
227
+ throw new CyphraValidationError(
228
+ `${where}: ${b} is outside the 64-bit integer range (-2^63 to 2^63-1).`
229
+ );
230
+ }
231
+ return neo4j2.int(b.toString());
232
+ }
233
+ function encodeJson(value, where) {
234
+ let text;
235
+ try {
236
+ text = JSON.stringify(value);
237
+ } catch (e) {
238
+ throw new CyphraValidationError(
239
+ `${where}: value is not JSON-serializable (${e instanceof Error ? e.message : String(e)}).`
240
+ );
241
+ }
242
+ if (text === void 0) {
243
+ throw new CyphraValidationError(`${where}: expected a JSON value, got ${describe(value)}.`);
244
+ }
245
+ return text;
246
+ }
247
+ function encodeOne(field, value, where) {
248
+ const type = field.type;
215
249
  switch (type) {
216
250
  case "String":
217
251
  if (typeof value !== "string") break;
218
252
  return value;
253
+ case "Enum": {
254
+ const values = field.enumValues ?? [];
255
+ if (typeof value === "string" && values.includes(value)) return value;
256
+ throw new CyphraValidationError(
257
+ `${where}: expected one of ${values.map((v) => JSON.stringify(v)).join(", ")} (enum ${field.enum}), got ${typeof value === "string" ? JSON.stringify(value) : describe(value)}.`
258
+ );
259
+ }
260
+ case "BigInt":
261
+ return encodeBigInt(value, where);
262
+ case "Json":
263
+ return encodeJson(value, where);
219
264
  case "Boolean":
220
265
  if (typeof value !== "boolean") break;
221
266
  return value;
@@ -278,9 +323,14 @@ function encodeScalar(field, value, owner) {
278
323
  if (!Array.isArray(value)) {
279
324
  throw new CyphraValidationError(`${where}: expected an array.`);
280
325
  }
281
- return value.map((v, i) => encodeOne(field.type, v, `${where}[${i}]`));
326
+ return value.map((v, i) => encodeOne(field, v, `${where}[${i}]`));
282
327
  }
283
- return encodeOne(field.type, value, where);
328
+ return encodeOne(field, value, where);
329
+ }
330
+ function defaultLiteralValue(field, d) {
331
+ if (field.type === "BigInt") return BigInt(d.value);
332
+ if (field.type === "Json") return JSON.parse(String(d.value));
333
+ return d.value;
284
334
  }
285
335
  function encodeFilterValue(field, value, owner) {
286
336
  if (field.type === "Vector") {
@@ -288,10 +338,32 @@ function encodeFilterValue(field, value, owner) {
288
338
  `${owner}.${field.name}: Vector fields can only be filtered on null (use findSimilar to search them).`
289
339
  );
290
340
  }
291
- return encodeOne(field.type, value, `${owner}.${field.name}`);
341
+ return encodeOne(field, value, `${owner}.${field.name}`);
342
+ }
343
+ function decodeBigInt(value) {
344
+ if (isInt(value)) return BigInt(value.toString());
345
+ if (typeof value === "number") {
346
+ if (!Number.isSafeInteger(value)) {
347
+ throw new RangeError(
348
+ `Neo4j value ${value} is not an exact 64-bit integer (BigInt overflow?).`
349
+ );
350
+ }
351
+ return BigInt(value);
352
+ }
353
+ return value;
354
+ }
355
+ function decodeJson(value) {
356
+ if (typeof value !== "string") return toNative(value);
357
+ try {
358
+ return JSON.parse(value);
359
+ } catch {
360
+ return value;
361
+ }
292
362
  }
293
363
  function decodeOne(type, value) {
294
364
  if (value === null || value === void 0) return null;
365
+ if (type === "BigInt") return decodeBigInt(value);
366
+ if (type === "Json") return decodeJson(value);
295
367
  if (isInt(value)) {
296
368
  return integerToNumber(value);
297
369
  }
@@ -436,9 +508,26 @@ function compileVectorFilter(model, field, ref, filter) {
436
508
  `${model.name}.${field.name}: Vector fields can only be filtered on null (null, { equals: null }, { not: null }); use findSimilar to search them.`
437
509
  );
438
510
  }
511
+ function compileJsonFilter(ctx, model, field, ref, filter) {
512
+ if (filter === null) return `${ref} IS NULL`;
513
+ if (!isPlainObject(filter) || Object.keys(filter).some((k) => k !== "equals" && k !== "not")) {
514
+ throw new CyphraValidationError(
515
+ `${model.name}.${field.name}: Json fields filter with null, { equals } or { not } only.`
516
+ );
517
+ }
518
+ const parts = [];
519
+ for (const [op, v] of Object.entries(filter)) {
520
+ if (v === void 0) continue;
521
+ const value = v === null ? null : ctx.param(encodeFilterValue(field, v, model.name));
522
+ if (op === "equals") parts.push(value === null ? `${ref} IS NULL` : `${ref} = ${value}`);
523
+ else parts.push(value === null ? `${ref} IS NOT NULL` : `${ref} <> ${value}`);
524
+ }
525
+ return and(parts);
526
+ }
439
527
  function compileScalarFilter(ctx, model, field, ref, filter, inheritedMode = "default") {
440
528
  if (filter === void 0) return null;
441
529
  if (field.type === "Vector") return compileVectorFilter(model, field, ref, filter);
530
+ if (field.type === "Json") return compileJsonFilter(ctx, model, field, ref, filter);
442
531
  if (field.list) return compileListFilter(ctx, model, field, ref, filter);
443
532
  const enc = (v) => encodeFilterValue(field, v, model.name);
444
533
  if (filter === null) return `${ref} IS NULL`;
@@ -599,6 +688,22 @@ function sortDirection(dir, what) {
599
688
  }
600
689
  return dir.toUpperCase();
601
690
  }
691
+ function compileRelatedScalar(ctx, model, alias, rel, name) {
692
+ const target = ctx.node(rel.target);
693
+ const f = scalarField(target, name);
694
+ if (!f) {
695
+ throw new CyphraValidationError(
696
+ `orderBy ${model.name}.${rel.name}: unknown scalar field "${target.name}.${name}".`
697
+ );
698
+ }
699
+ if (f.type === "Vector" || f.type === "Json" || f.list) {
700
+ throw new CyphraValidationError(
701
+ `orderBy ${model.name}.${rel.name}.${name}: list, Vector and Json fields cannot be sorted.`
702
+ );
703
+ }
704
+ const m = ctx.variable();
705
+ return `head(COLLECT { MATCH ${relationPattern(ctx, alias, rel, m)} RETURN ${m}.${q(name)} })`;
706
+ }
602
707
  function compileOrderBy(ctx, model, alias, orderBy) {
603
708
  if (orderBy === void 0 || orderBy === null) return null;
604
709
  const list = Array.isArray(orderBy) ? orderBy : [orderBy];
@@ -608,6 +713,24 @@ function compileOrderBy(ctx, model, alias, orderBy) {
608
713
  for (const [key, dir] of Object.entries(item)) {
609
714
  if (dir === void 0) continue;
610
715
  const rel = relationField(model, key);
716
+ if (rel && !rel.many) {
717
+ if (!isPlainObject(dir)) {
718
+ throw new CyphraValidationError(
719
+ `orderBy ${model.name}.${key} takes { <field>: "asc" | "desc" }.`
720
+ );
721
+ }
722
+ for (const [name, d] of Object.entries(dir)) {
723
+ if (d === void 0) continue;
724
+ if (name === "_count") {
725
+ throw new CyphraValidationError(
726
+ `${model.name}.${key} is a to-one relation; only to-many relations can be counted.`
727
+ );
728
+ }
729
+ const expr = compileRelatedScalar(ctx, model, alias, rel, name);
730
+ parts.push(`${expr} ${sortDirection(d, `${model.name}.${key}.${name}`)}`);
731
+ }
732
+ continue;
733
+ }
611
734
  if (rel) {
612
735
  if (!isPlainObject(dir) || Object.keys(dir).some((k) => k !== "_count")) {
613
736
  throw new CyphraValidationError(
@@ -619,9 +742,10 @@ function compileOrderBy(ctx, model, alias, orderBy) {
619
742
  parts.push(`${compileRelationCount(ctx, model, alias, rel)} ${d}`);
620
743
  continue;
621
744
  }
622
- if (scalarOrThrow(model, key).type === "Vector") {
745
+ const sortType = scalarOrThrow(model, key).type;
746
+ if (sortType === "Vector" || sortType === "Json") {
623
747
  throw new CyphraValidationError(
624
- `orderBy ${model.name}.${key}: Vector fields cannot be sorted.`
748
+ `orderBy ${model.name}.${key}: ${sortType} fields cannot be sorted.`
625
749
  );
626
750
  }
627
751
  parts.push(`${alias}.${q(key)} ${sortDirection(dir, `${model.name}.${key}`)}`);
@@ -801,8 +925,8 @@ function decodeRow(shape, row) {
801
925
  import { isInt as isInt2 } from "neo4j-driver";
802
926
  var AGGREGATES = ["_count", "_sum", "_avg", "_min", "_max"];
803
927
  var AGG_SET = new Set(AGGREGATES);
804
- var NUMERIC = /* @__PURE__ */ new Set(["Int", "Float"]);
805
- var ORDERABLE = /* @__PURE__ */ new Set(["Int", "Float", "String", "DateTime", "Date"]);
928
+ var NUMERIC = /* @__PURE__ */ new Set(["Int", "Float", "BigInt"]);
929
+ var ORDERABLE = /* @__PURE__ */ new Set(["Int", "Float", "BigInt", "String", "Enum", "DateTime", "Date"]);
806
930
  function isPlainObject2(v) {
807
931
  return typeof v === "object" && v !== null && !Array.isArray(v) && !(v instanceof Date);
808
932
  }
@@ -816,7 +940,7 @@ function aggTarget(model, op, name) {
816
940
  if (op === "_count") return f;
817
941
  const ok = !f.list && (op === "_sum" || op === "_avg" ? NUMERIC : ORDERABLE).has(f.type);
818
942
  if (!ok) {
819
- const allowed = op === "_sum" || op === "_avg" ? "Int and Float" : "Int, Float, String, DateTime and Date";
943
+ const allowed = op === "_sum" || op === "_avg" ? "Int, Float and BigInt" : "Int, Float, BigInt, String, enum, DateTime and Date";
820
944
  throw new CyphraValidationError(
821
945
  `${op} is not valid on ${model.name}.${name} (${f.type}${f.list ? "[]" : ""}); it takes ${allowed} fields.`
822
946
  );
@@ -849,8 +973,9 @@ function decodeAgg(op, target, v) {
849
973
  function aggResultField(op, target) {
850
974
  const base = target === "_all" ? void 0 : target;
851
975
  const name = `${base?.name ?? "_all"}.${op}`;
852
- const type = op === "_count" ? "Int" : op === "_sum" || op === "_avg" ? "Float" : base.type;
976
+ const type = op === "_count" ? "Int" : op === "_avg" || op === "_sum" && base.type !== "BigInt" ? "Float" : base.type;
853
977
  return {
978
+ ...op === "_min" || op === "_max" ? base : {},
854
979
  kind: "scalar",
855
980
  name,
856
981
  type,
@@ -1871,7 +1996,7 @@ var ModelEngine = class _ModelEngine {
1871
1996
  }
1872
1997
  if (v === void 0 && f.default) {
1873
1998
  const d = f.default;
1874
- const value = d.kind === "literal" ? d.value : d.fn === "uuid" ? randomUUID() : d.fn === "cuid" ? createCuid() : /* @__PURE__ */ new Date();
1999
+ const value = d.kind === "literal" ? defaultLiteralValue(f, d) : d.fn === "uuid" ? randomUUID() : d.fn === "cuid" ? createCuid() : /* @__PURE__ */ new Date();
1875
2000
  props[f.name] = encodeScalar(f, value, owner);
1876
2001
  continue;
1877
2002
  }
@@ -2083,8 +2208,8 @@ var ModelEngine = class _ModelEngine {
2083
2208
  for (const [k, v] of Object.entries(scalars)) {
2084
2209
  const f = scalarField(this.model, k);
2085
2210
  const ref = `n.${q(k)}`;
2086
- if (isPlainObject5(v) && !f.list) {
2087
- if (f.type !== "Int" && f.type !== "Float") {
2211
+ if (isPlainObject5(v) && !f.list && f.type !== "Json") {
2212
+ if (f.type !== "Int" && f.type !== "Float" && f.type !== "BigInt") {
2088
2213
  throw new CyphraValidationError(
2089
2214
  `${this.model.name}.${k}: object updates are only for numbers.`
2090
2215
  );
@@ -2126,7 +2251,8 @@ var ModelEngine = class _ModelEngine {
2126
2251
  return this.readById(exec, id, args);
2127
2252
  });
2128
2253
  }
2129
- createMany(args) {
2254
+ // `async` so that invalid data rejects the returned promise instead of throwing synchronously.
2255
+ async createMany(args) {
2130
2256
  if (!Array.isArray(args.data))
2131
2257
  throw new CyphraValidationError("createMany: data must be an array.");
2132
2258
  const fields = this.model.fields.filter((f) => f.kind === "scalar");
@@ -2137,7 +2263,7 @@ var ModelEngine = class _ModelEngine {
2137
2263
  }
2138
2264
  return _ModelEngine.createProps(this.model.name, fields, scalars);
2139
2265
  });
2140
- if (rows.length === 0) return Promise.resolve({ count: 0 });
2266
+ if (rows.length === 0) return { count: 0 };
2141
2267
  return this.runner.write(async (exec) => {
2142
2268
  const ctx = this.ctx();
2143
2269
  const res = await exec(