cogsbox-shape 0.5.184 → 0.5.186
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/schema.d.ts +2 -2
- package/dist/schema.js +16 -17
- package/package.json +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -413,8 +413,8 @@ export type DeriveViewResult<TTableName extends keyof TRegistry, TSelection, TRe
|
|
|
413
413
|
parseForDb: (appData: z.input<z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "serverSchema">>>) => z.infer<z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "sqlSchema">>>;
|
|
414
414
|
parseFromDb: (dbData: Partial<z.infer<z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "sqlSchema">>>>) => z.infer<z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "clientSchema">>>;
|
|
415
415
|
};
|
|
416
|
-
defaults: DeriveViewDefaults<TTableName, TSelection, TRegistry>;
|
|
417
|
-
defaultsDefinition: DeriveViewDefaultsDefinition<TTableName, TSelection, TRegistry>;
|
|
416
|
+
defaults: () => DeriveViewDefaults<TTableName, TSelection, TRegistry>;
|
|
417
|
+
defaultsDefinition: () => DeriveViewDefaultsDefinition<TTableName, TSelection, TRegistry>;
|
|
418
418
|
pk: string[] | null;
|
|
419
419
|
clientPk: string[] | null;
|
|
420
420
|
supportsReconciliation: boolean;
|
package/dist/schema.js
CHANGED
|
@@ -9,21 +9,21 @@ export function currentTimeStamp() {
|
|
|
9
9
|
}
|
|
10
10
|
export const s = {
|
|
11
11
|
clientInput: (value) => {
|
|
12
|
-
const
|
|
12
|
+
const sample = isFunction(value) ? value({ uuid }) : value;
|
|
13
13
|
let inferredZodType;
|
|
14
|
-
if (typeof
|
|
14
|
+
if (typeof sample === "string") {
|
|
15
15
|
inferredZodType = z.string();
|
|
16
16
|
}
|
|
17
|
-
else if (typeof
|
|
17
|
+
else if (typeof sample === "number") {
|
|
18
18
|
inferredZodType = z.number();
|
|
19
19
|
}
|
|
20
|
-
else if (typeof
|
|
20
|
+
else if (typeof sample === "boolean") {
|
|
21
21
|
inferredZodType = z.boolean();
|
|
22
22
|
}
|
|
23
|
-
else if (
|
|
23
|
+
else if (sample instanceof Date) {
|
|
24
24
|
inferredZodType = z.date();
|
|
25
25
|
}
|
|
26
|
-
else if (
|
|
26
|
+
else if (sample === null) {
|
|
27
27
|
inferredZodType = z.null();
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
@@ -33,7 +33,7 @@ export const s = {
|
|
|
33
33
|
stage: "clientInput",
|
|
34
34
|
sqlConfig: null,
|
|
35
35
|
sqlZod: z.undefined(),
|
|
36
|
-
initialValue:
|
|
36
|
+
initialValue: value,
|
|
37
37
|
clientZod: inferredZodType,
|
|
38
38
|
validationZod: inferredZodType,
|
|
39
39
|
});
|
|
@@ -185,7 +185,7 @@ function createBuilder(config) {
|
|
|
185
185
|
let actualValue = config.initialValue;
|
|
186
186
|
let finalSchema;
|
|
187
187
|
if (value !== undefined) {
|
|
188
|
-
actualValue =
|
|
188
|
+
actualValue = value;
|
|
189
189
|
}
|
|
190
190
|
else if (schemaOrModifier &&
|
|
191
191
|
typeof schemaOrModifier === "object" &&
|
|
@@ -203,15 +203,16 @@ function createBuilder(config) {
|
|
|
203
203
|
}
|
|
204
204
|
else {
|
|
205
205
|
if (value !== undefined) {
|
|
206
|
-
|
|
206
|
+
const sample = isFunction(value) ? value({ uuid }) : value;
|
|
207
|
+
if (typeof sample === "string")
|
|
207
208
|
baseSchema = z.string();
|
|
208
|
-
else if (typeof
|
|
209
|
+
else if (typeof sample === "number")
|
|
209
210
|
baseSchema = z.number();
|
|
210
|
-
else if (typeof
|
|
211
|
+
else if (typeof sample === "boolean")
|
|
211
212
|
baseSchema = z.boolean();
|
|
212
|
-
else if (
|
|
213
|
+
else if (sample instanceof Date)
|
|
213
214
|
baseSchema = z.date();
|
|
214
|
-
else if (
|
|
215
|
+
else if (sample === null)
|
|
215
216
|
baseSchema = z.null();
|
|
216
217
|
else
|
|
217
218
|
baseSchema = z.any();
|
|
@@ -888,8 +889,6 @@ export function createSchemaBox(schemas, resolutions) {
|
|
|
888
889
|
nav: createNavProxy(tableName, finalRegistry),
|
|
889
890
|
createView: (selection) => {
|
|
890
891
|
const view = createViewObject(tableName, selection, finalRegistry, tableNameToRegistryKeyMap);
|
|
891
|
-
const defaults = computeViewDefaults(tableName, selection, finalRegistry, tableNameToRegistryKeyMap);
|
|
892
|
-
const defaultsDefinition = computeViewDefaultsDefinition(tableName, selection, finalRegistry, tableNameToRegistryKeyMap);
|
|
893
892
|
const deepToClient = (dbData, currentSelection, currentKey) => {
|
|
894
893
|
if (!dbData)
|
|
895
894
|
return dbData;
|
|
@@ -969,8 +968,8 @@ export function createSchemaBox(schemas, resolutions) {
|
|
|
969
968
|
return viewToClient(mappedData);
|
|
970
969
|
},
|
|
971
970
|
},
|
|
972
|
-
defaults:
|
|
973
|
-
defaultsDefinition:
|
|
971
|
+
defaults: () => computeViewDefaults(tableName, selection, finalRegistry, tableNameToRegistryKeyMap),
|
|
972
|
+
defaultsDefinition: () => computeViewDefaultsDefinition(tableName, selection, finalRegistry, tableNameToRegistryKeyMap),
|
|
974
973
|
pk: entry.zodSchemas.pk,
|
|
975
974
|
clientPk: entry.zodSchemas.clientPk,
|
|
976
975
|
supportsReconciliation: view.supportsReconciliation,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.186",
|
|
4
4
|
"description": "A TypeScript library for creating type-safe database schemas with Zod validation, SQL type definitions, and automatic client/server transformations. Unifies client, server, and database types through a single schema definition, with built-in support for relationships and serialization.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|