cogsbox-shape 0.5.149 → 0.5.151
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.js +27 -12
- package/package.json +1 -1
package/dist/schema.js
CHANGED
|
@@ -562,18 +562,27 @@ export function createSchema(schema, relations) {
|
|
|
562
562
|
function createViewObject(initialRegistryKey, selection, registry, tableNameToRegistryKeyMap) {
|
|
563
563
|
// Add a flag to track if all tables support reconciliation
|
|
564
564
|
let allTablesSupportsReconciliation = true;
|
|
565
|
+
// Debug: track which tables are checked
|
|
566
|
+
const checkedTables = {};
|
|
565
567
|
function buildView(currentRegistryKey, subSelection, schemaType) {
|
|
566
568
|
const registryEntry = registry[currentRegistryKey];
|
|
567
569
|
if (!registryEntry) {
|
|
568
570
|
throw new Error(`Schema with key "${currentRegistryKey}" not found in the registry.`);
|
|
569
571
|
}
|
|
570
|
-
// Check if this table has pk and clientPk
|
|
571
|
-
|
|
572
|
-
registryEntry.pk
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
572
|
+
// Check if this table has pk and clientPk (only check once per table)
|
|
573
|
+
if (!(currentRegistryKey in checkedTables)) {
|
|
574
|
+
const hasPks = !!(registryEntry.pk &&
|
|
575
|
+
registryEntry.pk.length > 0 &&
|
|
576
|
+
registryEntry.clientPk &&
|
|
577
|
+
registryEntry.clientPk.length > 0);
|
|
578
|
+
checkedTables[currentRegistryKey] = hasPks;
|
|
579
|
+
if (!hasPks) {
|
|
580
|
+
console.log(`Table ${currentRegistryKey} missing pk/clientPk:`, {
|
|
581
|
+
pk: registryEntry.pk,
|
|
582
|
+
clientPk: registryEntry.clientPk,
|
|
583
|
+
});
|
|
584
|
+
allTablesSupportsReconciliation = false;
|
|
585
|
+
}
|
|
577
586
|
}
|
|
578
587
|
const baseSchema = schemaType === "server"
|
|
579
588
|
? registryEntry.zodSchemas.validationSchema
|
|
@@ -608,11 +617,16 @@ function createViewObject(initialRegistryKey, selection, registry, tableNameToRe
|
|
|
608
617
|
const finalShape = { ...primitiveShape, ...selectedRelationShapes };
|
|
609
618
|
return z.object(finalShape);
|
|
610
619
|
}
|
|
620
|
+
// For array schemas, handle the initial registry key check
|
|
621
|
+
const isArray = Array.isArray(selection);
|
|
622
|
+
const actualSelection = isArray ? true : selection;
|
|
611
623
|
return {
|
|
612
624
|
sql: registry[initialRegistryKey].zodSchemas.sqlSchema,
|
|
613
|
-
client: buildView(initialRegistryKey,
|
|
614
|
-
server: buildView(initialRegistryKey,
|
|
615
|
-
supportsReconciliation: allTablesSupportsReconciliation,
|
|
625
|
+
client: buildView(initialRegistryKey, actualSelection, "client"),
|
|
626
|
+
server: buildView(initialRegistryKey, actualSelection, "server"),
|
|
627
|
+
supportsReconciliation: allTablesSupportsReconciliation,
|
|
628
|
+
// Debug info
|
|
629
|
+
checkedTables,
|
|
616
630
|
};
|
|
617
631
|
}
|
|
618
632
|
export function createSchemaBox(schemas, resolver) {
|
|
@@ -772,8 +786,9 @@ export function createSchemaBox(schemas, resolver) {
|
|
|
772
786
|
toDb: entry.zodSchemas.toDb,
|
|
773
787
|
},
|
|
774
788
|
defaults: defaults,
|
|
775
|
-
//
|
|
776
|
-
|
|
789
|
+
// ADD THESE BACK - views need the pk/clientPk arrays from base table
|
|
790
|
+
pk: entry.zodSchemas.pk,
|
|
791
|
+
clientPk: entry.zodSchemas.clientPk,
|
|
777
792
|
isView: true,
|
|
778
793
|
viewSelection: selection,
|
|
779
794
|
baseTable: tableName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.151",
|
|
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",
|