Skip to content

Commit

Permalink
initial implementation idea
Browse files Browse the repository at this point in the history
  • Loading branch information
rnegron committed Oct 10, 2024
1 parent 67d5538 commit a0d4b33
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
24 changes: 24 additions & 0 deletions packages/schema/docs/build/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ This is automatically generated by the `npm run docs` command in `zapier-platfor
* [/DynamicFieldsSchema](#dynamicfieldsschema)
* [/FieldChoiceWithLabelSchema](#fieldchoicewithlabelschema)
* [/FieldChoicesSchema](#fieldchoicesschema)
* [/FieldMetaSchema](#fieldmetaschema)
* [/FieldOrFunctionSchema](#fieldorfunctionschema)
* [/FieldSchema](#fieldschema)
* [/FieldsSchema](#fieldsschema)
Expand Down Expand Up @@ -931,6 +932,27 @@ Yes | Yes | Array of [FieldChoiceWithLabel](#fieldchoicewithlabelschema)

-----

## /FieldMetaSchema

Allows for additional metadata to be stored on the field. Only simple values are allowed (no objects or arrays)

#### Details

* **Type** - `object`
* [**Source Code**](https://github.com/zapier/zapier-platform/blob/[email protected]/packages/schema/lib/schemas/FieldMetaSchema.js)


#### Examples

* `{ shouldCapitalize: true }`
* `{ shouldCapitalize: true, internalType: 'datetime' }`

#### Anti-Examples

* `{ databank: { primaryContact: 'abc' } }` - _No complex values allowed_

-----

## /FieldOrFunctionSchema

Represents an array of fields or functions.
Expand Down Expand Up @@ -997,6 +1019,7 @@ Key | Required | Type | Description
`altersDynamicFields` | no | `boolean` | Does the value of this field affect the definitions of other fields in the set?
`steadyState` | no | `boolean` | Prevents triggering on new output until all values for fields with this property remain unchanged for 2 polls. It can be used to, e.g., not trigger on a new contact until the contact has completed typing their name. NOTE that this only applies to the `outputFields` of polling triggers.
`inputFormat` | no | `string` | Useful when you expect the input to be part of a longer string. Put "{{input}}" in place of the user's input (IE: "https://{{input}}.yourdomain.com").
`meta` | no | [/FieldChoicesSchema](#fieldchoicesschema) | Allows for additional metadata to be stored on the field. Supports simple key-values only (no sub-objects or arrays).

#### Examples

Expand All @@ -1006,6 +1029,7 @@ Key | Required | Type | Description
* `{ key: 'abc', choices: [ { label: 'Red', sample: '#f00', value: '#f00' } ] }`
* `{ key: 'abc', children: [ { key: 'abc' } ] }`
* `{ key: 'abc', type: 'integer', helpText: 'neat' }`
* `{ key: 'abc', type: 'integer', meta: { internalType: 'numeric', shouldRetry: true } }`

#### Anti-Examples

Expand Down
12 changes: 12 additions & 0 deletions packages/schema/exported-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@
}
]
},
"FieldMetaSchema": {
"id": "/FieldMetaSchema",
"type": "object",
"description": "Allows for additional metadata to be stored on the field. Only simple values are allowed (no objects or arrays)",
"additionalProperties": {
"type": ["string", "number", "boolean", "null"]
}
},
"FieldSchema": {
"id": "/FieldSchema",
"description": "Defines a field an app either needs as input, or gives as output. In addition to the requirements below, the following keys are mutually exclusive:\n\n* `children` & `list`\n* `children` & `dict`\n* `children` & `type`\n* `children` & `placeholder`\n* `children` & `helpText`\n* `children` & `default`\n* `dict` & `list`\n* `dynamic` & `dict`\n* `dynamic` & `choices`",
Expand Down Expand Up @@ -249,6 +257,10 @@
"description": "Useful when you expect the input to be part of a longer string. Put \"{{input}}\" in place of the user's input (IE: \"https://{{input}}.yourdomain.com\").",
"type": "string",
"pattern": "^.*{{input}}.*$"
},
"meta": {
"description": "Allows for additional metadata to be stored on the field. Supports simple key-values only (no sub-objects or arrays).",
"$ref": "/FieldChoicesSchema"
}
},
"additionalProperties": false
Expand Down
23 changes: 23 additions & 0 deletions packages/schema/lib/schemas/FieldMetaSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const makeSchema = require('../utils/makeSchema');

module.exports = makeSchema({
id: '/FieldMetaSchema',
type: 'object',
description:
'Allows for additional metadata to be stored on the field. Only simple values are allowed (no objects or arrays)',
additionalProperties: {
type: ['string', 'number', 'boolean', 'null'],
},
examples: [
{ shouldCapitalize: true },
{ shouldCapitalize: true, internalType: 'datetime' },
],
antiExamples: [
{
example: { databank: { primaryContact: 'abc' } },
reason: 'No complex values allowed',
},
],
});
14 changes: 13 additions & 1 deletion packages/schema/lib/schemas/FieldSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const RefResourceSchema = require('./RefResourceSchema');

const FieldChoicesSchema = require('./FieldChoicesSchema');

const FieldMetaSchema = require('./FieldMetaSchema');

const { INCOMPATIBLE_FIELD_SCHEMA_KEYS } = require('../constants');

// the following takes an array of string arrays (string[][]) and returns the follwing string:
Expand Down Expand Up @@ -137,6 +139,11 @@ module.exports = makeSchema(
// TODO: Check if it contains one and ONLY ONE '{{input}}'
pattern: '^.*{{input}}.*$',
},
meta: {
description:
'Allows for additional metadata to be stored on the field. Supports simple key-values only (no sub-objects or arrays).',
$ref: FieldChoicesSchema.id,
},
},
examples: [
{ key: 'abc' },
Expand All @@ -148,6 +155,11 @@ module.exports = makeSchema(
},
{ key: 'abc', children: [{ key: 'abc' }] },
{ key: 'abc', type: 'integer', helpText: 'neat' },
{
key: 'abc',
type: 'integer',
meta: { internalType: 'numeric', shouldRetry: true },
},
],
antiExamples: [
{
Expand Down Expand Up @@ -190,5 +202,5 @@ module.exports = makeSchema(
],
additionalProperties: false,
},
[RefResourceSchema, FieldChoicesSchema]
[RefResourceSchema, FieldChoicesSchema, FieldMetaSchema]
);
2 changes: 1 addition & 1 deletion packages/schema/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const appDefinition = require('../examples/definition.json');

const copy = (o) => JSON.parse(JSON.stringify(o));

const NUM_SCHEMAS = 56; // changes regularly as we expand
const NUM_SCHEMAS = 57; // changes regularly as we expand

describe('app', () => {
describe('validation', () => {
Expand Down

0 comments on commit a0d4b33

Please sign in to comment.