-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PDE-4989 feat(schema): Add support for bulk writes
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
packages/schema/lib/functional-constraints/bulkWriteConstraints.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const jsonschema = require('jsonschema'); | ||
|
||
const bulkWriteConstraints = (definition) => { | ||
const errors = []; | ||
const actionType = 'creates'; | ||
|
||
if (definition[actionType]) { | ||
_.each(definition[actionType], (actionDef) => { | ||
if (actionDef.operation && actionDef.operation.bulk) { | ||
if (!actionDef.operation.performBulk) { | ||
errors.push( | ||
new jsonschema.ValidationError( | ||
'must contain performBulk because bulk is configured.', | ||
actionDef.operation, | ||
'/BasicCreateActionOperationSchema', | ||
`instance.${actionType}.${actionDef.key}.performBulk`, | ||
'invalid', | ||
'performBulk' | ||
) | ||
); | ||
} | ||
|
||
if (actionDef.operation.perform) { | ||
errors.push( | ||
new jsonschema.ValidationError( | ||
'must not contain perform because it is mutually exclusive with bulk.', | ||
actionDef.operation, | ||
'/BasicCreateActionOperationSchema', | ||
`instance.${actionType}.${actionDef.key}.perform`, | ||
'invalid', | ||
'perform' | ||
) | ||
); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
module.exports = bulkWriteConstraints; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
const makeSchema = require('../utils/makeSchema'); | ||
|
||
module.exports = makeSchema({ | ||
id: '/LockObjectSchema', | ||
description: | ||
'**INTERNAL USE ONLY**. Zapier uses this configuration for internal operation locking.', | ||
type: 'object', | ||
required: ['groupedBy', 'limit'], | ||
properties: { | ||
groupedBy: { | ||
description: | ||
'The list of keys of input fields to group bulk-write with. The actual user data provided for the fields will be used during execution. Note that a required input field should be referenced to get user data always.' | ||
type: 'array', | ||
minLength: 1, | ||
}, | ||
limit: { | ||
description: | ||
'The maximum number of items to call performBulk with.', | ||
type: 'integer', | ||
}, | ||
}, | ||
examples: [ | ||
{ | ||
groupedBy: ['workspace', 'sheet'], | ||
limit: 100, | ||
}, | ||
], | ||
antiExamples: [ | ||
{ | ||
example: { | ||
groupedBy: [], | ||
limit: 100, | ||
}, | ||
reason: 'Empty groupedBy list provided: `[]`.', | ||
}, | ||
{ | ||
example: {groupedBy: ['workspace']}, | ||
reason: 'Missing required key: `limit`.', | ||
}, | ||
{ | ||
example: {limit: 1}, | ||
reason: 'Missing required key: `groupedBy`.', | ||
}, | ||
], | ||
additionalProperties: false, | ||
}); |