Skip to content

Commit

Permalink
Simplify params (#2925)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-codaio committed Mar 6, 2024
1 parent 7f2a448 commit 4b0ddd4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
4 changes: 2 additions & 2 deletions dist/testing/upload_validation.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions dist/testing/upload_validation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codahq/packs-sdk",
"version": "1.7.5",
"version": "1.7.6-prerelease.1",
"license": "MIT",
"workspaces": [
"dev/eslint"
Expand Down
8 changes: 4 additions & 4 deletions test/upload_validation_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,7 @@ describe('Pack metadata Validation', async () => {
syncTables: [childTable, parentTable],
});
await validateJson(metadata);
const hierarchy = validateCrawlHierarchy(metadata);
const hierarchy = validateCrawlHierarchy(metadata.syncTables || []);
assert.deepEqual(hierarchy, {Parent: ['Child']});
});

Expand Down Expand Up @@ -2357,7 +2357,7 @@ describe('Pack metadata Validation', async () => {
syncTables: [childTable, parentTable],
});
await validateJson(metadata);
const hierarchy = validateCrawlHierarchy(metadata);
const hierarchy = validateCrawlHierarchy(metadata.syncTables || []);
assert.deepEqual(hierarchy, {Parent: ['Child']});
});

Expand Down Expand Up @@ -2433,7 +2433,7 @@ describe('Pack metadata Validation', async () => {
path: 'syncTables',
},
]);
const hierarchy = validateCrawlHierarchy(metadata);
const hierarchy = validateCrawlHierarchy(metadata.syncTables || []);
assert.isUndefined(hierarchy);
});

Expand Down Expand Up @@ -2498,7 +2498,7 @@ describe('Pack metadata Validation', async () => {
path: 'syncTables[0].parameters',
},
]);
const hierarchy = validateCrawlHierarchy(metadata);
const hierarchy = validateCrawlHierarchy(metadata.syncTables || []);
assert.isUndefined(hierarchy);
});
});
Expand Down
31 changes: 15 additions & 16 deletions testing/upload_validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,10 @@ export function validateSyncTableSchema(
* @hidden
*/
export function validateCrawlHierarchy(
pack: PackVersionDefinition,
syncTables: SyncTable[],
context?: z.RefinementCtx,
): Record<string, string[]> | undefined {
const parentToChildrenMap: Record<string, string[]> = {};
if (!pack.syncTables) {
return parentToChildrenMap;
}
const syncTables: SyncTable[] = pack.syncTables;
const syncTableSchemasByName: Record<string, ObjectSchema<any, any>> = {};
for (const syncTable of syncTables) {
syncTableSchemasByName[syncTable.name] = syncTable.schema;
Expand Down Expand Up @@ -1376,7 +1372,7 @@ function buildMetadataSchema({sdkVersion}: BuildMetadataSchemaArgs): {
createdAtPropertySchema.codaType === ValueHintType.Date),
`must refer to a "ValueType.String" or "ValueType.Number" property with a "ValueHintType.DateTime" or "ValueHintType.Date" "codaType".`,
);
}
};
const validateModifiedAtProperty = () => {
return validateProperty(
'modifiedAtProperty',
Expand All @@ -1387,26 +1383,26 @@ function buildMetadataSchema({sdkVersion}: BuildMetadataSchemaArgs): {
modifiedAtPropertySchema.codaType === ValueHintType.Date),
`must refer to a "ValueType.String" or "ValueType.Number" property with a "ValueHintType.DateTime" or "ValueHintType.Date" "codaType".`,
);
}
};
const validateCreatedByProperty = () => {
return validateProperty(
'createdByProperty',
createdByPropertySchema =>
(createdByPropertySchema.type === ValueType.Object
|| createdByPropertySchema.type === ValueType.String) &&
(createdByPropertySchema.codaType === ValueHintType.Person
|| createdByPropertySchema.codaType === ValueHintType.Email),
(createdByPropertySchema.type === ValueType.Object ||
createdByPropertySchema.type === ValueType.String) &&
(createdByPropertySchema.codaType === ValueHintType.Person ||
createdByPropertySchema.codaType === ValueHintType.Email),
`must refer to a "ValueType.Object" or "ValueType.String" property with a "ValueHintType.Person" or "ValueHintType.Email" "codaType".`,
);
};
const validateModifiedByProperty = () => {
return validateProperty(
'modifiedByProperty',
modifiedByPropertySchema =>
(modifiedByPropertySchema.type === ValueType.Object ||
modifiedByPropertySchema.type === ValueType.String) &&
(modifiedByPropertySchema.codaType === ValueHintType.Person ||
modifiedByPropertySchema.codaType === ValueHintType.Email),
(modifiedByPropertySchema.type === ValueType.Object ||
modifiedByPropertySchema.type === ValueType.String) &&
(modifiedByPropertySchema.codaType === ValueHintType.Person ||
modifiedByPropertySchema.codaType === ValueHintType.Email),
`must refer to a "ValueType.Object" or "ValueType.String" property with a "ValueHintType.Person" or "ValueHintType.Email" "codaType".`,
);
};
Expand Down Expand Up @@ -1865,7 +1861,10 @@ function buildMetadataSchema({sdkVersion}: BuildMetadataSchemaArgs): {
});
})
.superRefine((data, context) => {
validateCrawlHierarchy(data as PackVersionDefinition, context);
const {syncTables} = data as PackVersionDefinition;
if (syncTables) {
validateCrawlHierarchy(syncTables, context);
}
})
.superRefine((data, context) => {
((data.formulas as any[]) || []).forEach((formula, i) => {
Expand Down

0 comments on commit 4b0ddd4

Please sign in to comment.