Skip to content

Commit

Permalink
Add mergeKey to IdentityDefinition (#3037)
Browse files Browse the repository at this point in the history
* Add mergeKey to IdentityDefinition

* Fix test

* packs-sdk: release v1.7.11

* Update comment
  • Loading branch information
oleg-codaio authored Aug 23, 2024
1 parent eb2d899 commit ccf2fea
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 47 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This changelog keeps track of all changes to the Packs SDK. We follow convention

## [Unreleased]

## [1.7.11] - 2024-08-23

### Changed

- Added internal fields to sync formulas and identity

## [1.7.10] - 2024-08-21

### Added
Expand Down Expand Up @@ -694,7 +700,7 @@ await myHelper(context);
- Beginning of alpha versioning.
[unreleased]: https://github.com/coda/packs-sdk/compare/v1.7.10...HEAD
[unreleased]: https://github.com/coda/packs-sdk/compare/v1.7.11...HEAD
[1.7.5]: https://github.com/coda/packs-sdk/compare/v1.7.1...v1.7.5
[1.7.4]: https://github.com/coda/packs-sdk/compare/v1.7.1...v1.7.4
[1.7.3]: https://github.com/coda/packs-sdk/compare/v1.7.1...v1.7.3
Expand Down Expand Up @@ -726,7 +732,6 @@ await myHelper(context);
[0.9.0]: https://github.com/coda/packs-sdk/compare/v0.8.2...v0.9.0
[1.7.7]: https://github.com/coda/packs-sdk/compare/v1.7.1...v1.7.7
[1.7.8]: https://github.com/coda/packs-sdk/compare/v1.7.1...v1.7.8
[1.7.9]: https://github.com/coda/packs-sdk/compare/v1.7.8...v1.7.9
[1.7.11]: https://github.com/coda/packs-sdk/compare/v1.7.8...v1.7.11
[1.7.10]: https://github.com/coda/packs-sdk/compare/v1.7.8...v1.7.10
16 changes: 12 additions & 4 deletions dist/bundle.d.ts

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

16 changes: 12 additions & 4 deletions dist/schema.d.ts

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

14 changes: 8 additions & 6 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.10-prerelease.1",
"version": "1.7.11",
"license": "MIT",
"workspaces": [
"dev/eslint"
Expand Down
29 changes: 19 additions & 10 deletions schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,14 @@ export interface IdentityDefinition {
dynamicUrl?: string;
/** The ID of another pack, if you are trying to reference a value from different pack. */
packId?: number;
/**
* By default, result sets returned by dynamic sync tables will not be merged together across different dynamicUrl
* values for the purposes of presenting information. This value, if set, will allow results for identities for the
* same Pack and name to be merged together if they share the same `mergeKey`.
*
* @hidden In development.
*/
mergeKey?: string;
/** @deprecated See {@link ObjectSchemaDefinition.attribution} */
attribution?: AttributionNode[];
}
Expand Down Expand Up @@ -1100,16 +1108,16 @@ export interface DetailedIndexedProperty {
export type IndexedProperty = BasicIndexedProperty | DetailedIndexedProperty;

/**
* Defines how to index objects for use with full-text indexing.
* TODO(alexd): Unhide this
* @hidden
*/
* Defines how to index objects for use with full-text indexing.
* TODO(alexd): Unhide this
* @hidden
*/
export interface IndexDefinition {
/**
* A list of properties from within {@link ObjectSchemaDefinition.properties} that should be indexed.
*/
properties: IndexedProperty[];

/*
* The context properties to be used for indexing.
* If unspecified, intelligent defaults may be used..
Expand Down Expand Up @@ -1930,17 +1938,18 @@ function normalizeIndexProperty(value: IndexedProperty, normalizedProperties: Ob
}

function normalizeIndexDefinition(
index: IndexDefinition,
normalizedProperties: ObjectSchemaProperties): IndexDefinition {
index: IndexDefinition,
normalizedProperties: ObjectSchemaProperties,
): IndexDefinition {
const {properties, contextProperties, popularityRankProperty, ...rest} = index;
ensureNever<keyof typeof rest>();
return {
properties: properties.map(prop => normalizeIndexProperty(prop, normalizedProperties)),
contextProperties: contextProperties
? contextProperties.map(prop => normalizeSchemaPropertyIdentifier(prop, normalizedProperties))
: undefined,
popularityRankProperty: popularityRankProperty
? normalizeSchemaPropertyIdentifier(popularityRankProperty, normalizedProperties)
popularityRankProperty: popularityRankProperty
? normalizeSchemaPropertyIdentifier(popularityRankProperty, normalizedProperties)
: undefined,
};
}
Expand Down Expand Up @@ -2055,7 +2064,7 @@ export function normalizeObjectSchema(schema: GenericObjectSchema): GenericObjec
properties: normalizedProperties,
snippetProperty: snippetProperty
? normalizeSchemaPropertyIdentifier(snippetProperty, normalizedProperties)
: undefined,
: undefined,
subtitleProperties: subtitleProperties
? subtitleProperties.map(subProp => normalizeSchemaPropertyIdentifier(subProp, normalizedProperties))
: undefined,
Expand Down
31 changes: 12 additions & 19 deletions testing/upload_validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1169,23 +1169,20 @@ function buildMetadataSchema({sdkVersion}: BuildMetadataSchemaArgs): {
properties: z.array(indexedPropertySchema).min(1),
contextProperties: contextPropertiesSchema.optional(),
popularityRankProperty: propertySchema.optional(),
});
});

function makePropertyValidator(schema: GenericObjectSchema, context: z.RefinementCtx) {
/**
* Validates a PropertyIdentifier key in the object schema.
*/
* Validates a PropertyIdentifier key in the object schema.
*/
return function validateProperty(
propertyValueRaw: PropertyIdentifier<string> | Array<PropertyIdentifier<string>> | undefined,
fieldName: string,
isValidSchema: (schema: Schema & ObjectSchemaProperty) => boolean,
invalidSchemaMessage: string,
propertyObjectPath: Array<string | number> = [fieldName]
propertyObjectPath: Array<string | number> = [fieldName],
) {
function validatePropertyIdentifier(
value: PropertyIdentifier,
objectPath: Array<string | number>,
) {
function validatePropertyIdentifier(value: PropertyIdentifier, objectPath: Array<string | number>) {
const propertyValue = typeof value === 'string' ? value : value?.property;

let propertyValueIsPath = false;
Expand All @@ -1202,9 +1199,7 @@ function buildMetadataSchema({sdkVersion}: BuildMetadataSchemaArgs): {
propertyValueIsPath = true;
}

const propertyIdentifierDisplay = propertyValueIsPath
? `"${fieldName}" path`
: `"${fieldName}" field name`;
const propertyIdentifierDisplay = propertyValueIsPath ? `"${fieldName}" path` : `"${fieldName}" field name`;

if (!propertySchema) {
context.addIssue({
Expand Down Expand Up @@ -1235,7 +1230,7 @@ function buildMetadataSchema({sdkVersion}: BuildMetadataSchemaArgs): {

validatePropertyIdentifier(propertyValueRaw, propertyObjectPath);
}
}
};
}

const genericObjectSchema: z.ZodTypeAny = z.lazy(() =>
Expand All @@ -1256,6 +1251,7 @@ function buildMetadataSchema({sdkVersion}: BuildMetadataSchemaArgs): {
name: z.string().nonempty(),
dynamicUrl: z.string().optional(),
attribution: attributionSchema,
mergeKey: z.string().optional(),
}).optional(),
attribution: attributionSchema,
properties: z.record(objectPropertyUnionSchema),
Expand Down Expand Up @@ -1599,15 +1595,12 @@ function buildMetadataSchema({sdkVersion}: BuildMetadataSchemaArgs): {
}

if (contextProperties) {
validatePropertyValue(
contextProperties,
validatePropertyValue(contextProperties, 'contextProperties', () => true, `must be a valid property.`, [
'index',
'contextProperties',
() => true,
`must be a valid property.`,
['index', 'contextProperties'],
);
]);
}
})
}),
);

const objectPropertyUnionSchema = z
Expand Down

0 comments on commit ccf2fea

Please sign in to comment.