@primate/core 0.9.11 → 0.9.13
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.
|
@@ -52,6 +52,8 @@ export default async function build_server(app) {
|
|
|
52
52
|
},
|
|
53
53
|
banner: {
|
|
54
54
|
js: `import { createRequire as __createRequire } from "node:module";
|
|
55
|
+
const __filename = import.meta.filename;
|
|
56
|
+
const __dirname = import.meta.dirname;
|
|
55
57
|
const require = __createRequire(import.meta.url);`,
|
|
56
58
|
},
|
|
57
59
|
nodePaths: [app.root.join("node_modules").path],
|
package/lib/private/db/test.js
CHANGED
|
@@ -132,6 +132,29 @@ export default (db) => {
|
|
|
132
132
|
name: p.string.default("Donald"),
|
|
133
133
|
},
|
|
134
134
|
});
|
|
135
|
+
test.case("insert type accepts explicit undefined for write-optional fields", assert => {
|
|
136
|
+
const insert = {
|
|
137
|
+
age: undefined,
|
|
138
|
+
id: undefined,
|
|
139
|
+
name: undefined,
|
|
140
|
+
lastname: undefined,
|
|
141
|
+
};
|
|
142
|
+
assert(insert).type();
|
|
143
|
+
User.insert({
|
|
144
|
+
age: undefined,
|
|
145
|
+
id: undefined,
|
|
146
|
+
name: undefined,
|
|
147
|
+
lastname: undefined,
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
test.case("insert type survives omit", assert => {
|
|
151
|
+
const insert = {
|
|
152
|
+
age: undefined,
|
|
153
|
+
id: undefined,
|
|
154
|
+
lastname: undefined,
|
|
155
|
+
};
|
|
156
|
+
assert(insert).type();
|
|
157
|
+
});
|
|
135
158
|
const UserN = store({
|
|
136
159
|
table: "user_n",
|
|
137
160
|
db,
|
|
@@ -8,7 +8,7 @@ import type Init from "#store/Init";
|
|
|
8
8
|
import type PrimaryKey from "#store/PrimaryKey";
|
|
9
9
|
import type { ManyRelation, OneRelation, Relation } from "#store/relation";
|
|
10
10
|
import type StoreInput from "#store/StoreInput";
|
|
11
|
-
import type { Dict, Serializable } from "@rcompat/type";
|
|
11
|
+
import type { Dict, Serializable, Unpack } from "@rcompat/type";
|
|
12
12
|
import type { DefaultType, InferStore, Storable } from "pema";
|
|
13
13
|
import StoreType from "pema/StoreType";
|
|
14
14
|
declare const brand: unique symbol;
|
|
@@ -18,15 +18,6 @@ type X<T> = {
|
|
|
18
18
|
type OrNull<T> = {
|
|
19
19
|
[P in keyof T]?: null | T[P] | undefined;
|
|
20
20
|
};
|
|
21
|
-
type Optional<T> = {
|
|
22
|
-
[P in keyof T]?: T[P] | undefined;
|
|
23
|
-
};
|
|
24
|
-
type OptionalKeys<T> = {
|
|
25
|
-
[K in keyof T]-?: object extends Pick<T, K> ? K : never;
|
|
26
|
-
}[keyof T];
|
|
27
|
-
type UndefinedOptional<T> = X<Omit<T, OptionalKeys<T>> & {
|
|
28
|
-
[K in OptionalKeys<T>]?: T[K] | undefined;
|
|
29
|
-
}>;
|
|
30
21
|
type StringOperators = {
|
|
31
22
|
$like?: string;
|
|
32
23
|
$ilike?: string;
|
|
@@ -68,7 +59,7 @@ type Projected<T, S extends Select<T> | undefined> = S extends readonly (keyof T
|
|
|
68
59
|
type DefaultFields<T extends StoreInput> = {
|
|
69
60
|
[K in keyof InferRecord<T>]: T[K] extends DefaultType<any, any> ? K : never;
|
|
70
61
|
}[keyof InferRecord<T>];
|
|
71
|
-
type Insertable<T extends StoreInput> =
|
|
62
|
+
type Insertable<T extends StoreInput> = Omit<InferRecord<T>, PrimaryKeyField<T> | DefaultFields<T>> & Partial<Pick<InferRecord<T>, PrimaryKeyField<T> | DefaultFields<T>>>;
|
|
72
63
|
type PrimaryKeyField<T extends StoreInput> = {
|
|
73
64
|
[K in keyof T]: T[K] extends PrimaryKey<any> ? K : never;
|
|
74
65
|
}[keyof T] & keyof InferRecord<T>;
|
|
@@ -106,7 +97,7 @@ type ReadSort = Dict<"asc" | "desc">;
|
|
|
106
97
|
export default class Store<T extends StoreInput, N extends string = string> implements Serializable {
|
|
107
98
|
#private;
|
|
108
99
|
[brand]: boolean;
|
|
109
|
-
readonly Insert: Insertable<T
|
|
100
|
+
readonly Insert: Unpack<Insertable<T>>;
|
|
110
101
|
readonly Schema: Schema<T>;
|
|
111
102
|
static is(x: unknown): x is Store<any, any>;
|
|
112
103
|
constructor(init: Init<T, N>);
|
package/lib/private/store.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import key from "#store/key";
|
|
|
3
3
|
import relation from "#store/relation";
|
|
4
4
|
import Store from "#store/Store";
|
|
5
5
|
import type StoreInput from "#store/StoreInput";
|
|
6
|
-
declare function store<T extends StoreInput, const N extends string = string>(init: Init<T, N>
|
|
6
|
+
declare function store<T extends StoreInput, const N extends string = string>(init: Omit<Init<T, N>, "schema"> & {
|
|
7
|
+
schema: T;
|
|
8
|
+
}): Store<T, N>;
|
|
7
9
|
declare namespace store {
|
|
8
10
|
export { key };
|
|
9
11
|
export { relation };
|