@primate/core 0.9.9 → 0.9.10

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.
@@ -16,7 +16,10 @@ type X<T> = {
16
16
  [K in keyof T]: T[K];
17
17
  } & {};
18
18
  type OrNull<T> = {
19
- [P in keyof T]?: null | T[P];
19
+ [P in keyof T]?: null | T[P] | undefined;
20
+ };
21
+ type Optional<T> = {
22
+ [P in keyof T]?: T[P] | undefined;
20
23
  };
21
24
  type StringOperators = {
22
25
  $like?: string;
@@ -59,7 +62,7 @@ type Projected<T, S extends Select<T> | undefined> = S extends readonly (keyof T
59
62
  type DefaultFields<T extends StoreInput> = {
60
63
  [K in keyof InferRecord<T>]: T[K] extends DefaultType<any, any> ? K : never;
61
64
  }[keyof InferRecord<T>];
62
- type Insertable<T extends StoreInput> = Omit<InferRecord<T>, PrimaryKeyField<T> | DefaultFields<T>> & Partial<Pick<InferRecord<T>, PrimaryKeyField<T> | DefaultFields<T>>>;
65
+ type Insertable<T extends StoreInput> = X<Omit<InferRecord<T>, PrimaryKeyField<T> | DefaultFields<T>> & Optional<Pick<InferRecord<T>, PrimaryKeyField<T> | DefaultFields<T>>>>;
63
66
  type PrimaryKeyField<T extends StoreInput> = {
64
67
  [K in keyof T]: T[K] extends PrimaryKey<any> ? K : never;
65
68
  }[keyof T] & keyof InferRecord<T>;
@@ -24,6 +24,10 @@ function guard_options(options, allowed) {
24
24
  throw E.option_unknown(k);
25
25
  }
26
26
  }
27
+ function strip_undefined(record) {
28
+ return Object.fromEntries(Object.entries(record)
29
+ .filter(([, value]) => value !== undefined));
30
+ }
27
31
  const INT_LIMITS = {
28
32
  u8: [0, 255],
29
33
  u16: [0, 65535],
@@ -512,15 +516,18 @@ export default class Store {
512
516
  */
513
517
  async insert(record) {
514
518
  assert.dict(record);
515
- const prepared = this.#prepare_insert(record);
519
+ const prepared = this.#prepare_insert(strip_undefined(record));
516
520
  return this.db.create(this.#as, this.#schema.parse(prepared));
517
521
  }
518
522
  async update(arg0, options) {
519
523
  const by_pk = options !== undefined;
520
- const set = by_pk
524
+ const input_set = by_pk
521
525
  ? options.set
522
526
  : arg0.set;
523
- if (!is.dict(set) || is.empty(set))
527
+ if (!is.dict(input_set))
528
+ throw E.set_empty();
529
+ const set = strip_undefined(input_set);
530
+ if (is.empty(set))
524
531
  throw E.set_empty();
525
532
  const pk = this.#pk;
526
533
  if (pk !== null && pk in set)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/core",
3
- "version": "0.9.9",
3
+ "version": "0.9.10",
4
4
  "description": "The universal web framework",
5
5
  "homepage": "https://primate.run",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",