@ninetailed/experience.js-utils-contentful 3.12.0 → 3.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -6,6 +6,14 @@ var zod = require('zod');
6
6
  var experience_jsShared = require('@ninetailed/experience.js-shared');
7
7
  var experience_jsUtils = require('@ninetailed/experience.js-utils');
8
8
 
9
+ /**
10
+ * This does not work anymore from zod > 3.21.0:
11
+ *
12
+ * We have to cast the result of passthrough() to z.ZodObject<{}> to make it work,
13
+ * as the inferred type changed to {} & { [k: string]: unknown; }
14
+ * It was {} before, so we do the type cast to get it back to {}.
15
+ */
16
+ // eslint-disable-next-line @typescript-eslint/ban-types
9
17
  const EntryFields = zod.z.object({}).passthrough();
10
18
 
11
19
  const EntryLink = zod.z.object({
@@ -46,13 +54,13 @@ const EntrySchema = zod.z.object({
46
54
  }))
47
55
  }).optional()
48
56
  });
49
- const parse$1 = input => {
57
+ const parse$2 = input => {
50
58
  const output = EntrySchema.parse(input);
51
59
  return Object.assign(Object.assign({}, output), {
52
60
  fields: input.fields
53
61
  });
54
62
  };
55
- const safeParse$1 = input => {
63
+ const safeParse$2 = input => {
56
64
  const output = EntrySchema.safeParse(input);
57
65
  if (!output.success) {
58
66
  return output;
@@ -64,8 +72,8 @@ const safeParse$1 = input => {
64
72
  });
65
73
  };
66
74
  const Entry = Object.assign(Object.assign({}, EntrySchema), {
67
- parse: parse$1,
68
- safeParse: safeParse$1
75
+ parse: parse$2,
76
+ safeParse: safeParse$2
69
77
  });
70
78
 
71
79
  const AudienceEntryFields = EntryFields.extend({
@@ -134,7 +142,7 @@ const ExperienceEntryFields = zod.z.object({
134
142
  const ExperienceEntrySchema = EntrySchema.extend({
135
143
  fields: ExperienceEntryFields
136
144
  });
137
- const parse = input => {
145
+ const parse$1 = input => {
138
146
  const output = ExperienceEntrySchema.parse(input);
139
147
  return Object.assign(Object.assign({}, output), {
140
148
  fields: Object.assign(Object.assign({}, output.fields), {
@@ -142,7 +150,7 @@ const parse = input => {
142
150
  })
143
151
  });
144
152
  };
145
- const safeParse = input => {
153
+ const safeParse$1 = input => {
146
154
  const output = ExperienceEntrySchema.safeParse(input);
147
155
  if (!output.success) {
148
156
  return output;
@@ -156,15 +164,40 @@ const safeParse = input => {
156
164
  });
157
165
  };
158
166
  const ExperienceEntry = Object.assign(Object.assign({}, ExperienceEntrySchema), {
159
- parse,
160
- safeParse
167
+ parse: parse$1,
168
+ safeParse: safeParse$1
161
169
  });
162
170
 
163
- const ExperimentEntry = ExperienceEntry.extend({
171
+ const ExperimentEntrySchema = ExperienceEntrySchema.extend({
164
172
  fields: ExperienceEntryFields.extend({
165
173
  nt_type: zod.z.string().regex(/^nt_experiment$/g)
166
174
  })
167
175
  });
176
+ const parse = input => {
177
+ const output = ExperimentEntrySchema.parse(input);
178
+ return Object.assign(Object.assign({}, output), {
179
+ fields: Object.assign(Object.assign({}, output.fields), {
180
+ nt_variants: input.fields.nt_variants || []
181
+ })
182
+ });
183
+ };
184
+ const safeParse = input => {
185
+ const output = ExperimentEntrySchema.safeParse(input);
186
+ if (!output.success) {
187
+ return output;
188
+ }
189
+ return Object.assign(Object.assign({}, output), {
190
+ data: Object.assign(Object.assign({}, output.data), {
191
+ fields: Object.assign(Object.assign({}, output.data.fields), {
192
+ nt_variants: input.fields.nt_variants || []
193
+ })
194
+ })
195
+ });
196
+ };
197
+ const ExperimentEntry = Object.assign(Object.assign({}, ExperimentEntrySchema), {
198
+ parse,
199
+ safeParse
200
+ });
168
201
 
169
202
  function mapAudience(ctfAudienceEntry) {
170
203
  return {
package/index.js CHANGED
@@ -2,6 +2,14 @@ import { z } from 'zod';
2
2
  import { logger } from '@ninetailed/experience.js-shared';
3
3
  import { Config, ExperienceMapper as ExperienceMapper$1 } from '@ninetailed/experience.js-utils';
4
4
 
5
+ /**
6
+ * This does not work anymore from zod > 3.21.0:
7
+ *
8
+ * We have to cast the result of passthrough() to z.ZodObject<{}> to make it work,
9
+ * as the inferred type changed to {} & { [k: string]: unknown; }
10
+ * It was {} before, so we do the type cast to get it back to {}.
11
+ */
12
+ // eslint-disable-next-line @typescript-eslint/ban-types
5
13
  const EntryFields = z.object({}).passthrough();
6
14
 
7
15
  const EntryLink = z.object({
@@ -42,13 +50,13 @@ const EntrySchema = z.object({
42
50
  }))
43
51
  }).optional()
44
52
  });
45
- const parse$1 = input => {
53
+ const parse$2 = input => {
46
54
  const output = EntrySchema.parse(input);
47
55
  return Object.assign(Object.assign({}, output), {
48
56
  fields: input.fields
49
57
  });
50
58
  };
51
- const safeParse$1 = input => {
59
+ const safeParse$2 = input => {
52
60
  const output = EntrySchema.safeParse(input);
53
61
  if (!output.success) {
54
62
  return output;
@@ -60,8 +68,8 @@ const safeParse$1 = input => {
60
68
  });
61
69
  };
62
70
  const Entry = Object.assign(Object.assign({}, EntrySchema), {
63
- parse: parse$1,
64
- safeParse: safeParse$1
71
+ parse: parse$2,
72
+ safeParse: safeParse$2
65
73
  });
66
74
 
67
75
  const AudienceEntryFields = EntryFields.extend({
@@ -130,7 +138,7 @@ const ExperienceEntryFields = z.object({
130
138
  const ExperienceEntrySchema = EntrySchema.extend({
131
139
  fields: ExperienceEntryFields
132
140
  });
133
- const parse = input => {
141
+ const parse$1 = input => {
134
142
  const output = ExperienceEntrySchema.parse(input);
135
143
  return Object.assign(Object.assign({}, output), {
136
144
  fields: Object.assign(Object.assign({}, output.fields), {
@@ -138,7 +146,7 @@ const parse = input => {
138
146
  })
139
147
  });
140
148
  };
141
- const safeParse = input => {
149
+ const safeParse$1 = input => {
142
150
  const output = ExperienceEntrySchema.safeParse(input);
143
151
  if (!output.success) {
144
152
  return output;
@@ -152,15 +160,40 @@ const safeParse = input => {
152
160
  });
153
161
  };
154
162
  const ExperienceEntry = Object.assign(Object.assign({}, ExperienceEntrySchema), {
155
- parse,
156
- safeParse
163
+ parse: parse$1,
164
+ safeParse: safeParse$1
157
165
  });
158
166
 
159
- const ExperimentEntry = ExperienceEntry.extend({
167
+ const ExperimentEntrySchema = ExperienceEntrySchema.extend({
160
168
  fields: ExperienceEntryFields.extend({
161
169
  nt_type: z.string().regex(/^nt_experiment$/g)
162
170
  })
163
171
  });
172
+ const parse = input => {
173
+ const output = ExperimentEntrySchema.parse(input);
174
+ return Object.assign(Object.assign({}, output), {
175
+ fields: Object.assign(Object.assign({}, output.fields), {
176
+ nt_variants: input.fields.nt_variants || []
177
+ })
178
+ });
179
+ };
180
+ const safeParse = input => {
181
+ const output = ExperimentEntrySchema.safeParse(input);
182
+ if (!output.success) {
183
+ return output;
184
+ }
185
+ return Object.assign(Object.assign({}, output), {
186
+ data: Object.assign(Object.assign({}, output.data), {
187
+ fields: Object.assign(Object.assign({}, output.data.fields), {
188
+ nt_variants: input.fields.nt_variants || []
189
+ })
190
+ })
191
+ });
192
+ };
193
+ const ExperimentEntry = Object.assign(Object.assign({}, ExperimentEntrySchema), {
194
+ parse,
195
+ safeParse
196
+ });
164
197
 
165
198
  function mapAudience(ctfAudienceEntry) {
166
199
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-utils-contentful",
3
- "version": "3.12.0",
3
+ "version": "3.13.0",
4
4
  "peerDependencies": {
5
5
  "contentful": "^9.1.32"
6
6
  },
@@ -9,9 +9,9 @@
9
9
  "type": "module",
10
10
  "types": "./index.d.ts",
11
11
  "dependencies": {
12
- "@ninetailed/experience.js-utils": "3.12.0",
13
- "@ninetailed/experience.js": "3.12.0",
14
- "@ninetailed/experience.js-shared": "3.12.0",
15
- "zod": "3.20.2"
12
+ "@ninetailed/experience.js-utils": "3.13.0",
13
+ "@ninetailed/experience.js": "3.13.0",
14
+ "@ninetailed/experience.js-shared": "3.13.0",
15
+ "zod": "3.21.4"
16
16
  }
17
17
  }