Skip to content

Commit

Permalink
Merge pull request #58 from storyblok/hotfix/revert-sync-query-filter
Browse files Browse the repository at this point in the history
fix: revert starts-with and filter query features
  • Loading branch information
ademarCardoso authored Jun 28, 2023
2 parents b5a93dc + c36b30e commit 172cbf2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 61 deletions.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,6 @@ $ storyblok sync --type <COMMAND> --source <SPACE_ID> --target <SPACE_ID>
* `type`: describe the command type to execute. Can be: `folders`, `components`, `stories`, `datasources` or `roles`. It's possible pass multiple types separated by comma (`,`).
* `source`: the source space to use to sync
* `target`: the target space to use to sync
* `starts-with`: sync only stories that starts with the given string
* `filter`: sync stories based on the given filter. Required Options: Required options: `--keys`, `--operations`, `--values`
* `keys`: Multiple keys should be separated by comma. Example: `--keys key1,key2`, `--keys key1`
* `operations`: Operations to be used for filtering. Can be: `is`, `in`, `not_in`, `like`, `not_like`, `any_in_array`, `all_in_array`, `gt_date`, `lt_date`, `gt_int`, `lt_int`, `gt_float`, `lt_float`. Multiple operations should be separated by comma.

#### Examples

Expand All @@ -261,14 +257,6 @@ $ storyblok sync --type components --source 00001 --target 00002
# Sync components and stories from `00001` space to `00002` space
$ storyblok sync --type components,stories --source 00001 --target 00002

# Sync only stories that starts with `myStartsWithString` from `00001` space to `00002` space
$ storyblok sync --type stories --source 00001 --target 00002 --starts-with myStartsWithString

# Sync only stories with a category field like `reference` from `00001` space to `00002` space
$ storyblok sync --type stories --source 00001 --target 00002 --filter --keys category --operations like --values reference

# Sync only stories with a category field like `reference` and a name field not like `demo` from `00001` space to `00002` space
$ storyblok sync --type stories --source 00001 --target 00002 --filter --keys category,name --operations like,not_like --values reference,demo
```

### quickstart
Expand Down
23 changes: 5 additions & 18 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const updateNotifier = require('update-notifier')
const pkg = require('../package.json')

const tasks = require('./tasks')
const { getQuestions, lastStep, api, creds, buildFilterQuery } = require('./utils')
const { getQuestions, lastStep, api, creds } = require('./utils')
const { SYNC_TYPES, COMMANDS } = require('./constants')

clear()
Expand Down Expand Up @@ -271,11 +271,6 @@ program
.requiredOption('--type <TYPE>', 'Define what will be sync. Can be components, folders, stories, datasources or roles')
.requiredOption('--source <SPACE_ID>', 'Source space id')
.requiredOption('--target <SPACE_ID>', 'Target space id')
.option('--starts-with <STARTS_WITH>', 'Sync only stories that starts with the given string')
.option('--filter', 'Enable filter options to sync only stories that match the given filter. Required options: --keys; --operations; --values')
.option('--keys <KEYS>', 'Field names in your story object which should be used for filtering. Multiple keys should separated by comma.')
.option('--operations <OPERATIONS>', 'Operations to be used for filtering. Can be: is, in, not_in, like, not_like, any_in_array, all_in_array, gt_date, lt_date, gt_int, lt_int, gt_float, lt_float. Multiple operations should be separated by comma.')
.option('--values <VALUES>', 'Values to be used for filtering. Any string or number. If you want to use multiple values, separate them with a comma. Multiple values should be separated by comma.')
.option('--components-groups <UUIDs>', 'Synchronize components based on their group UUIDs separated by commas')
.action(async (options) => {
console.log(`${chalk.blue('-')} Sync data between spaces\n`)
Expand All @@ -287,35 +282,27 @@ program

const {
type,
source,
target,
startsWith,
filter,
keys,
operations,
values,
source,
componentsGroups
} = options

const _componentsGroups = componentsGroups ? componentsGroups.split(',') : null

const token = creds.get().token || null

const _types = type.split(',') || []
_types.forEach(_type => {
if (!SYNC_TYPES.includes(_type)) {
throw new Error(`The type ${_type} is not valid`)
}
})

const filterQuery = filter ? buildFilterQuery(keys, operations, values) : undefined

const token = creds.get().token || null
await tasks.sync(_types, {
api,
token,
source,
target,
startsWith,
filterQuery,
source,
_componentsGroups
})

Expand Down
7 changes: 1 addition & 6 deletions src/tasks/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const chalk = require('chalk')
const SyncComponents = require('./sync-commands/components')
const SyncDatasources = require('./sync-commands/datasources')
const { capitalize } = require('../utils')
const { startsWith } = require('lodash/string')

const SyncSpaces = {
targetComponents: [],
Expand All @@ -15,8 +14,6 @@ const SyncSpaces = {
this.sourceSpaceId = options.source
this.targetSpaceId = options.target
this.oauthToken = options.token
this.startsWith = options.startsWith
this.filterQuery = options.filterQuery
this.client = api.getClient()
this.componentsGroups = options._componentsGroups
},
Expand Down Expand Up @@ -60,9 +57,7 @@ const SyncSpaces = {
}

const all = await this.client.getAll(`spaces/${this.sourceSpaceId}/stories`, {
story_only: 1,
...(this.startsWith ? { starts_with: this.startsWith } : {}),
...(this.filterQuery ? { filter_query: this.filterQuery } : {})
story_only: 1
})

for (let i = 0; i < all.length; i++) {
Expand Down
23 changes: 0 additions & 23 deletions src/utils/build-filter-query.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ module.exports = {
capitalize: require('./capitalize'),
findByProperty: require('./find-by-property'),
parseError: require('./parse-error'),
buildFilterQuery: require('./build-filter-query'),
saveFileFactory: require('./save-file-factory')
}
}

0 comments on commit 172cbf2

Please sign in to comment.