How can I persist nested redux store - redux

I want to persist nested object of my redux store. I tried https://github.com/rt2zz/redux-persist package but it doesn't work in my case. I wonder if it's possible to define a whitelist like this: 'user.statuses.verification.isDone'
This is my store:
{
user: {
statuses: {
verification: { isPending: true, isDone: false },
activation: { isPending: true, isDone: false },
set1: { isPending: true, isDone: false, refNumber: xxx },
set2: { isPending: true, isDone: false, refNumber: xxx },
},
},
}
I want to persist only "isDone" in every of statuses and "refNumber".
Can anyone help me?
I already tried nested persist as described in redux persist documentation https://github.com/rt2zz/redux-persist#nested-persists but looks like it has a limitation to 2 levels.

I tried this https://stackoverflow.com/a/71616665 and it works perfectly. 
In this example you can see the blacklist but you just need to replace it with the whitelist.
const config = getPersistConfig({
key: 'root',
storage: AsyncStorage,
whitelist: [
'user.statuses.verification.isDone’,
'user.statuses.activation.isDone’,
'user.statuses.set1.isDone’,
'user.statuses.set1.refNumber’,
'user.statuses.set2.isDone’,
'user.statuses.set2.refNumber’,
],
rootReducer, // your root reducer must be also passed here
... // any other props from the original redux-persist config omitting the stateReconciler
})

You need to use this package: https://github.com/edy/redux-persist-transform-filter
The "issue" has already been addressed, it's more a precise implementation choice, not an issue according to the maintainers, and you have several different ways to address it:
redux-persist - how do you blacklist/whitelist nested state

Related

How do I convert part of a Terraform schema provider from interface {}([]interface {}) to an array of strings

I am creating a new resource in the aws-terraform-provider. In my schema, I have the following vpc options which is a complex type.
...
"vpc_options": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"subnets": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"security_groups": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
...
In hashicorp configuration language i am using this resource like this
vpc_options {
5 subnets = ["subnet-0be8cde92b74efcc8", "subnet-03a31237a28404445"]
6 security_groups = ["sg-0d3c85573d69473fb"]
7 }
I want to be able to use this resource. In order for me to use these fields effectively, I think I need the resource to be in the form of strings that I can use with the aws api calls for creation, deletion, update, and read. Even though I need these values to be strings, when I read the vpc_config in the debugger, I see that they are of type
interface {}([]interface {}) [map[string]interface {} ["subnets": *(*interface {})(0xc0063a8088), "security_groups": *(*interface {})(0xc0063a8098), ]]
Here is a picture of me inspecting the vpc_config in my debugger.
How should i go about converting this to an array of subnet strings and an array of security_groups strings. Then update the schema with d.Set("subnets",.... and d.Set("security_groups",....

how set custom env variables in renovate

I am using github actions where i am storing some secrets and they will be available as environment variables. I want to access these variables form my renovate config.js files
process.ENV.VARIABLE_NAME does not seem to work
There seems to be a PR that introduced this features but it is not document how it shall be used: https://github.com/renovatebot/renovate/pull/8321/files#
Here is my renovate-config.js file:
module.exports = {
platform: 'github',
logLevel: 'debug',
labels: ['renovate', 'dependencies', 'automated'],
onboarding: true,
onboardingConfig: {
extends: ['config:base', 'disableDependencyDashboard']
},
cacheDir: "/tmp/renovate",
renovateFork: true,
gitAuthor: "renovate <renovate#hhpv.de>",
username: "Renovate",
onboarding: false,
printConfig: true,
requireConfig: false,
logLevel: "DEBUG",
baseBranches: ["ecr-renovate"],
customEnvVariables: {
// what should i put here
},
hostRules: [
{
hostType: 'docker',
matchHost: '123456456.dkr.ecr.eu-central-1.amazonaws.com',
//username: process.env.AWS_ACCESS_KEY,
//password: process.env.AWS_SECRET_KEY
},
],
};
It seems renovate does not understand environment variables inside its config file, at least I could not find a working example, too.
You can however provide parts of the renovate config as environment variables, where other environment variables can be resolved.
In my case I had to provide an access token for a private maven repository, and this is what I did in my gitlab-ci.yml:
variables:
RENOVATE_HOST_RULES: '[{"matchHost": "https://gitlab.company.com/api/v4/groups/myprojectgroup/-/packages/maven", "token": "$CI_JOB_TOKEN"}]'
If you take a look into renovates debug log you should find an entry like this when the config is picked up:
"msg":"Adding token authentication for https://gitlab.company.com/api/v4/groups/myprojectgroup/-/packages/maven to hostRules","time":"2022-12-02T12:59:54.402Z","v":0}

Next-offline and WorkboxOpts: Error: "runtimeCaching" is not a supported parameter. How to enable "runtimeCaching" in next.config.js

I'm just getting started with next-offline and found the section regarding workbox integration and its recipes.
According to the docs:
If you're new to workbox, I'd recommend reading this quick guide --
anything inside of workboxOpts will be passed to
workbox-webpack-plugin.
Define a workboxOpts object in your next.config.js and it will gets
passed to workbox-webpack-plugin. Workbox is what next-offline uses
under the hood to generate the service worker, you can learn more
about it here.
After digging around, I found this great section.
Essentially it gives a suggestion to use two different options:
GenerateSW or InjectManifest
I would like to use the InjectManifest, however when I try to implement that in my next.config.js file. I get this error:
"runtimeCaching" is not a supported parameter.
This is my next.config.js:
const withCSS = require('#zeit/next-css');
const withSass = require('#zeit/next-sass');
const withImages = require('next-images');
const optimizedImages = require('next-optimized-images');
const withOffline = require('next-offline');
module.exports = withOffline(
withImages(
optimizedImages(
withCSS(
withSass({
// useFileSystemPublicRoutes: false,
// generateSw: false, // this allows all your workboxOpts to be passed in injectManifest
generateInDevMode: true,
workboxOpts: {
swDest: './service-worker.js', // this is the important part,
exclude: [/.+error\.js$/, /\.map$/, /\.(?:png|jpg|jpeg|svg)$/],
runtimeCaching: [
{
urlPattern: /\.(?:png|jpg|jpeg|svg)$/,
handler: 'CacheFirst',
options: {
cacheName: 'hillfinder-images'
}
},
{
urlPattern: /^https?.*/,
handler: 'NetworkFirst',
options: {
cacheName: 'hillfinder-https-calls',
networkTimeoutSeconds: 15,
expiration: {
maxEntries: 150,
maxAgeSeconds: 30 * 24 * 60 * 60 // 1 month
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
]
},
dontAutoRegisterSw: false,
env: {
MAPBOX_ACCESS_TOKEN: process.env.MAPBOX_ACCESS_TOKEN,
useFileSystemPublicRoutes: false
},
webpack(config, options) {
config.module.rules.push({
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
use: {
loader: 'url-loader',
options: {
limit: 100000,
target: 'serverless'
}
}
});
return config;
}
})
)
)
)
);
Also when I check the Application pane, in devTools I see this:
You'll notice what appears to me a duplication of fields i.e. https-calls and hillfinder-https-calls and images and hillfinder-images.
I thought the cacheName field in the options: {} in each was allowing one to include a custom name?
Just wondering if anyone has had experience setting this up?
Thank you in advance!
(These comments apply to the basic Workbox build tools, not specifically to the next-offline wrapper, but I think they're still accurate.)
If you're using InjectManifest mode, the idea is that you write all of your service worker logic, using the underlying pieces of Workbox that you need, following a model that's similar to what's described in the Getting Started guide. You should include a call to precacheAndRoute(self.__WB_MANIFEST) somewhere in your service worker, and then the InjectManifest build tool is responsible for swapping out self.__WB_MANIFEST with an array containing the list of URLs to precache, along with revision information for each URL.
The runtimeCaching parameter is not compatible with InjectManifest. It's a parameter that can be used in GenerateSW mode, in with the Workbox build tool creates an entire service worker for you (including runtime caching routes). The GenerateSW mode takes in a declarative configuration and spits out the code for service worker based on that configuration. If that sounds good—if you'd just like to configure some build options and get a complete service worker as a result—then using GenerateSW is the right choice.

this.user().context is undefined - Jovo Framework - Alexa

I'm currently using Jovo for cross platform developing Alexa and Google Assistant's skills/actions.
I currently hit a roadblock in which I'm trying to get the previous intent by doing either:
this.user().context.prev[0].request.intent or
this.user().getPrevIntent(0).
But it hasn't worked. I get context is undefined and getPrevIntent doesn't exist. According to the Docs, I need to set up a table with DynamoDB (I did, and verified that it's working since Jovo is able to store the user object), and passed in the default configuration to App. But still can't seem to get it work. Any ideas?
const config = {
logging: false,
// Log incoming JSON requests.
// requestLogging: true,
/**
* You don't want AMAZON.YesIntent on Dialogflow, right?
* This will map it for you!
*/
intentMap: {
'AMAZON.YesIntent': 'YesIntent',
'AMAZON.NoIntent': 'NoIntent',
'AMAZON.HelpIntent': 'HelpIntent',
'AMAZON.RepeatIntent': 'RepeatIntent',
'AMAZON.NextIntent': 'NextIntent',
'AMAZON.StartOverIntent': 'StartOverIntent',
'AMAZON.ResumeIntent': 'ContinueIntent',
'AMAZON.CancelIntent': 'CancelIntent',
},
// Configures DynamoDB to persist data
db: {
awsConfig,
type: 'dynamodb',
tableName: 'user-data',
},
userContext: {
prev: {
size: 1,
request: {
intent: true,
state: true,
inputs: true,
timestamp: true,
},
response: {
speech: true,
reprompt: true,
state: true,
},
},
},
};
const app = new App(config);
Thanks 😊
To make use of the User Context Object of the Jovo Framework, you need to have at least v1.2.0 of the jovo-framework.
You can update the package to the latest version like this: npm install jovo-framework --save
(This used to be a comment. Just adding this as an answer so other people see it as well)

meteor autocomplete server-side

I'm writing a meteor app and I'm trying to add an autocomplete feature to a search box. The data is very large and is on the server, so I can't have it all on the client. It's basically a database of users. If I'm not wrong, the mizzao:autocomplete package should make that possible, but I can't seem to get it to work.
Here's what I have on the server:
Meteor.publish('autocompleteViewers', function(selector, options) {
Autocomplete.publishCursor(viewers.find(selector, options), this);
this.ready();
});
And here are the settings I use for the search box on the client:
getSettings: function() {
return {
position: 'bottom',
limit: 5,
rules: [{
subscription: 'autocompleteViewers',
field: '_id',
matchAll: false,
options: '',
template: Template.vLegend
}],
};
}
But I keep getting this error on the client:
Error: Collection name must be specified as string for server-side search at validateRule
I don't really understand the problem. When I look at the package code, it just seems like it's testing whether the subscription field is a string and not a variable, which it is. Any idea what the problem could be? Otherwise is there a minimum working example I could go from somewhere? I couldn't find one in the docs.
Error: Collection name must be specified as string for server-side search at validateRule
You get this error because you don't specify a Collection name in quotes.
getSettings: function() {
return {
position: 'bottom',
limit: 5,
rules: [{
subscription: 'autocompleteViewers',
field: '_id',
matchAll: false,
collection: 'viewers', // <- specify your collection, in your case it is a "viewers" collection.
options: '',
template: Template.vLegend
}],
};
}
For more information please read here.
Hope this helps!

Resources