Skip to content

Commit

Permalink
add entity id property (#3016)
Browse files Browse the repository at this point in the history
* add entity id property

* review

* rename to parentIdProperty

* review
  • Loading branch information
gary-codaio authored Jul 9, 2024
1 parent 38bbde8 commit cc3c772
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 6 deletions.
10 changes: 10 additions & 0 deletions dist/bundle.d.ts

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

6 changes: 3 additions & 3 deletions dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/helpers/migration.js

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

10 changes: 10 additions & 0 deletions dist/schema.d.ts

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

3 changes: 2 additions & 1 deletion dist/schema.js

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

6 changes: 6 additions & 0 deletions dist/testing/upload_validation.js

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

1 change: 1 addition & 0 deletions helpers/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ObjectSchemaHelper<T extends ObjectSchemaDefinition<string, string>> {
groupIdProperty,
bodyTextProperty,
popularityRankProperty,
parentIdProperty,

...rest
} = schema;
Expand Down
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.8-prerelease.1",
"version": "1.7.8-prerelease.2",
"license": "MIT",
"workspaces": [
"dev/eslint"
Expand Down
12 changes: 12 additions & 0 deletions schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,16 @@ export interface ObjectSchemaDefinition<K extends string, L extends string>
* @hidden
*/
groupIdProperty?: PropertyIdentifier<K>;
/**
* The name of a property within {@link ObjectSchemaDefinition.properties} that represents a unique id for a
* parent entity for the object. It is recommended for sync table schemas with a bodyTextProperty to specify an
* a parentIdProperty, which uniquely identifies the entity that groups 1 to multiple rows. Note though that
* specifying a bodyTextProperty does not necessarily require it to be chunked into multiple rows. But if it is,
* a sync table where each row is a partial chunk of a larger document may want to specify a parent id that
* represents the document, while each row's id can be unique to the chunk.
* @hidden
*/
parentIdProperty?: K;

/**
* The name of the property within {@link ObjectSchemaDefinition.properties} that can be be interpreted as
Expand Down Expand Up @@ -1884,6 +1894,7 @@ export function normalizeObjectSchema(schema: GenericObjectSchema): GenericObjec
id,
identity,
idProperty,
parentIdProperty,
imageProperty,
includeUnknownProperties,
linkProperty,
Expand Down Expand Up @@ -1937,6 +1948,7 @@ export function normalizeObjectSchema(schema: GenericObjectSchema): GenericObjec
id: id ? normalizeSchemaKey(id) : undefined,
identity,
idProperty: idProperty ? normalizeSchemaKey(idProperty) : undefined,
parentIdProperty: parentIdProperty ? normalizeSchemaKey(parentIdProperty) : undefined,
imageProperty: imageProperty ? normalizeSchemaPropertyIdentifier(imageProperty, normalizedProperties) : undefined,
includeUnknownProperties,
linkProperty: linkProperty ? normalizeSchemaPropertyIdentifier(linkProperty, normalizedProperties) : undefined,
Expand Down
9 changes: 9 additions & 0 deletions testing/upload_validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ function buildMetadataSchema({sdkVersion}: BuildMetadataSchemaArgs): {
description: z.string().optional(),
id: z.string().min(1).optional(),
idProperty: z.string().min(1).optional(),
parentIdProperty: z.string().min(1).optional(),
primary: z.string().min(1).optional(),
displayProperty: z.string().min(1).optional(),
codaType: z.enum([...ObjectHintValueTypes]).optional(),
Expand Down Expand Up @@ -1232,6 +1233,14 @@ function buildMetadataSchema({sdkVersion}: BuildMetadataSchemaArgs): {
message: 'The "idProperty" property must appear as a key in the "properties" object.',
},
)
.refine(
data => {
return isNil(data.parentIdProperty) || data.parentIdProperty in data.properties;
},
{
message: 'The "parentIdProperty" property must appear as a key in the "properties" object.',
},
)
.refine(
data => {
const schemaHelper = objectSchemaHelper(data as GenericObjectSchema);
Expand Down

0 comments on commit cc3c772

Please sign in to comment.