@strapi/strapi 4.7.0-beta.0 → 4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d

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.
@@ -18,9 +18,9 @@ const {
18
18
  DEFAULT_IGNORED_CONTENT_TYPES,
19
19
  createStrapiInstance,
20
20
  formatDiagnostic,
21
+ loadersFactory,
21
22
  } = require('./utils');
22
23
  const { exitWith } = require('../utils/helpers');
23
-
24
24
  /**
25
25
  * @typedef ExportCommandOptions Options given to the CLI import command
26
26
  *
@@ -80,6 +80,20 @@ module.exports = async (opts) => {
80
80
 
81
81
  const progress = engine.progress.stream;
82
82
 
83
+ const { updateLoader } = loadersFactory();
84
+
85
+ progress.on(`stage::start`, ({ stage, data }) => {
86
+ updateLoader(stage, data).start();
87
+ });
88
+
89
+ progress.on('stage::finish', ({ stage, data }) => {
90
+ updateLoader(stage, data).succeed();
91
+ });
92
+
93
+ progress.on('stage::progress', ({ stage, data }) => {
94
+ updateLoader(stage, data);
95
+ });
96
+
83
97
  const getTelemetryPayload = (/* payload */) => {
84
98
  return {
85
99
  eventProperties: {
@@ -19,6 +19,7 @@ const {
19
19
  DEFAULT_IGNORED_CONTENT_TYPES,
20
20
  createStrapiInstance,
21
21
  formatDiagnostic,
22
+ loadersFactory,
22
23
  } = require('./utils');
23
24
  const { exitWith } = require('../utils/helpers');
24
25
 
@@ -88,6 +89,21 @@ module.exports = async (opts) => {
88
89
  engine.diagnostics.onDiagnostic(formatDiagnostic('import'));
89
90
 
90
91
  const progress = engine.progress.stream;
92
+
93
+ const { updateLoader } = loadersFactory();
94
+
95
+ progress.on(`stage::start`, ({ stage, data }) => {
96
+ updateLoader(stage, data).start();
97
+ });
98
+
99
+ progress.on('stage::finish', ({ stage, data }) => {
100
+ updateLoader(stage, data).succeed();
101
+ });
102
+
103
+ progress.on('stage::progress', ({ stage, data }) => {
104
+ updateLoader(stage, data);
105
+ });
106
+
91
107
  const getTelemetryPayload = () => {
92
108
  return {
93
109
  eventProperties: {
@@ -16,6 +16,7 @@ const {
16
16
  createStrapiInstance,
17
17
  DEFAULT_IGNORED_CONTENT_TYPES,
18
18
  formatDiagnostic,
19
+ loadersFactory,
19
20
  } = require('./utils');
20
21
  const { exitWith } = require('../utils/helpers');
21
22
 
@@ -116,6 +117,22 @@ module.exports = async (opts) => {
116
117
 
117
118
  engine.diagnostics.onDiagnostic(formatDiagnostic('transfer'));
118
119
 
120
+ const progress = engine.progress.stream;
121
+
122
+ const { updateLoader } = loadersFactory();
123
+
124
+ progress.on(`stage::start`, ({ stage, data }) => {
125
+ updateLoader(stage, data).start();
126
+ });
127
+
128
+ progress.on('stage::finish', ({ stage, data }) => {
129
+ updateLoader(stage, data).succeed();
130
+ });
131
+
132
+ progress.on('stage::progress', ({ stage, data }) => {
133
+ updateLoader(stage, data);
134
+ });
135
+
119
136
  let results;
120
137
  try {
121
138
  console.log(`Starting transfer...`);
@@ -9,6 +9,7 @@ const {
9
9
  configs: { createOutputFileConfiguration },
10
10
  createLogger,
11
11
  } = require('@strapi/logger');
12
+ const ora = require('ora');
12
13
  const { readableBytes, exitWith } = require('../utils/helpers');
13
14
  const strapi = require('../../index');
14
15
  const { getParseListWithChoices } = require('../utils/commander');
@@ -171,7 +172,46 @@ const formatDiagnostic =
171
172
  }
172
173
  };
173
174
 
175
+ const loadersFactory = (defaultLoaders = {}) => {
176
+ const loaders = defaultLoaders;
177
+ const updateLoader = (stage, data) => {
178
+ if (!(stage in loaders)) {
179
+ createLoader(stage);
180
+ }
181
+ const stageData = data[stage];
182
+ const elapsedTime = stageData?.startTime
183
+ ? (stageData?.endTime || Date.now()) - stageData.startTime
184
+ : 0;
185
+ const size = `size: ${readableBytes(stageData?.bytes ?? 0)}`;
186
+ const elapsed = `elapsed: ${elapsedTime} ms`;
187
+ const speed =
188
+ elapsedTime > 0 ? `(${readableBytes(((stageData?.bytes ?? 0) * 1000) / elapsedTime)}/s)` : '';
189
+
190
+ loaders[stage].text = `${stage}: ${stageData?.count ?? 0} transfered (${size}) (${elapsed}) ${
191
+ !stageData?.endTime ? speed : ''
192
+ }`;
193
+
194
+ return loaders[stage];
195
+ };
196
+
197
+ const createLoader = (stage) => {
198
+ Object.assign(loaders, { [stage]: ora() });
199
+ return loaders[stage];
200
+ };
201
+
202
+ const getLoader = (stage) => {
203
+ return loaders[stage];
204
+ };
205
+
206
+ return {
207
+ updateLoader,
208
+ createLoader,
209
+ getLoader,
210
+ };
211
+ };
212
+
174
213
  module.exports = {
214
+ loadersFactory,
175
215
  buildTransferTable,
176
216
  getDefaultExportName,
177
217
  DEFAULT_IGNORED_CONTENT_TYPES,
@@ -1,4 +1,3 @@
1
-
2
1
  type Handler = (context: any) => any;
3
2
 
4
3
  type AsyncHook = {
@@ -8,7 +7,6 @@ type AsyncHook = {
8
7
  call(): Promise<void>;
9
8
  };
10
9
 
11
-
12
10
  type SyncHook = {
13
11
  get handlers(): Handler[];
14
12
  register(handler: Handler): this;
@@ -16,5 +14,4 @@ type SyncHook = {
16
14
  call(): void;
17
15
  };
18
16
 
19
-
20
- export type Hook = AsyncHook|SyncHook
17
+ export type Hook = AsyncHook | SyncHook;
@@ -6,4 +6,8 @@ interface PolicyContext extends BaseContext {
6
6
  is(name): boolean;
7
7
  }
8
8
 
9
- export type Policy<T=unknown> = (ctx: PolicyContext,cfg:T, { strapi: Strapi }) => boolean | undefined;
9
+ export type Policy<T = unknown> = (
10
+ ctx: PolicyContext,
11
+ cfg: T,
12
+ { strapi: Strapi }
13
+ ) => boolean | undefined;
package/lib/global.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import type { Strapi as StrapiInterface } from './types/core';
2
- import type { CollectionTypeSchema, SingleTypeSchema, ComponentSchema, ContentTypeSchema } from './types/core/schemas';
2
+ import type {
3
+ CollectionTypeSchema,
4
+ SingleTypeSchema,
5
+ ComponentSchema,
6
+ ContentTypeSchema,
7
+ } from './types/core/schemas';
3
8
  import type { KeysBy } from './types/utils';
4
9
 
5
10
  declare global {
@@ -7,7 +12,7 @@ declare global {
7
12
  /**
8
13
  * Map of UID / schemas used as a schemas database for other types.
9
14
  * It must be extended by the user application or plugins.
10
- *
15
+ *
11
16
  * @example
12
17
  * ```ts
13
18
  * declare global {
@@ -39,12 +44,12 @@ declare global {
39
44
  /**
40
45
  * Literal union type of every component registered in Strapi.Schemas
41
46
  */
42
- type ComponentUIDs = KeysBy<Schemas, ComponentSchema>;
47
+ type ComponentUIDs = KeysBy<Schemas, ComponentSchema>;
43
48
 
44
- /**
45
- * Global shorthand to access the `StrapiInterface` type
46
- */
47
- type Strapi = StrapiInterface;
49
+ /**
50
+ * Global shorthand to access the `StrapiInterface` type
51
+ */
52
+ type Strapi = StrapiInterface;
48
53
  }
49
54
 
50
55
  /**
package/lib/index.d.ts CHANGED
@@ -2,4 +2,4 @@ import './global';
2
2
 
3
3
  export * from './types';
4
4
 
5
- export default function(opts): Strapi;
5
+ export default function (opts): Strapi;
@@ -19,6 +19,14 @@ module.exports = (config) => {
19
19
  const { origin, expose, maxAge, credentials, methods, headers, keepHeadersOnError } =
20
20
  defaultsDeep(defaults, config);
21
21
 
22
+ if (config.enabled !== undefined) {
23
+ strapi.log.warn(
24
+ 'The strapi::cors middleware no longer supports the `enabled` option. Using it' +
25
+ ' to conditionally enable CORS might cause an insecure default. To disable strapi::cors, remove it from' +
26
+ ' the exported array in config/middleware.js'
27
+ );
28
+ }
29
+
22
30
  return cors({
23
31
  async origin(ctx) {
24
32
  let originList;
@@ -77,9 +77,10 @@ module.exports = (config, { strapi }) => {
77
77
  }),
78
78
  config: { auth: false },
79
79
  },
80
+ // All other public GET-routes except /uploads/(.*) which is handled in upload middleware
80
81
  {
81
82
  method: 'GET',
82
- path: '/(.*)',
83
+ path: '/((?!uploads/).+)',
83
84
  handler: koaStatic(strapi.dirs.static.public, {
84
85
  maxage: maxAge,
85
86
  defer: true,
@@ -88,7 +88,7 @@ export interface EntityService {
88
88
  ): Promise<any>;
89
89
  }
90
90
 
91
- export default function(opts: {
91
+ export default function (opts: {
92
92
  strapi: Strapi;
93
93
  db: Database;
94
94
  // TODO: define types
@@ -25,13 +25,10 @@ export type ComponentAttribute<
25
25
  PrivateOption &
26
26
  RequiredOption;
27
27
 
28
- export type ComponentValue<T extends Strapi.ComponentUIDs, R extends boolean> = GetAttributesValues<
29
- T
30
- > extends infer V
31
- ? R extends true
32
- ? V[]
33
- : V
34
- : never;
28
+ export type ComponentValue<
29
+ T extends Strapi.ComponentUIDs,
30
+ R extends boolean
31
+ > = GetAttributesValues<T> extends infer V ? (R extends true ? V[] : V) : never;
35
32
 
36
33
  export type GetComponentAttributeValue<T extends Attribute> = T extends ComponentAttribute<
37
34
  infer U,
@@ -83,11 +83,10 @@ export type GetAttributeValueByKey<
83
83
  export type GetAttributesValues<T extends SchemaUID> = {
84
84
  // Handle required attributes
85
85
  [key in GetAttributesRequiredKeys<T>]-?: GetAttributeValueByKey<T, key>;
86
- } &
87
- {
88
- // Handle optional attributes
89
- [key in GetAttributesOptionalKeys<T>]?: GetAttributeValueByKey<T, key>;
90
- };
86
+ } & {
87
+ // Handle optional attributes
88
+ [key in GetAttributesOptionalKeys<T>]?: GetAttributeValueByKey<T, key>;
89
+ };
91
90
 
92
91
  export type GetAttributesRequiredKeys<T extends SchemaUID> = KeysBy<
93
92
  GetAttributes<T>,
@@ -1,3 +1,3 @@
1
1
  export * from './attributes';
2
- export * from './schemas';
3
- export * from './strapi'
2
+ export * from './schemas';
3
+ export * from './strapi';
@@ -1,4 +1,4 @@
1
1
  export * from './core';
2
2
 
3
- export * as utils from './utils'
4
- export * as factories from './factories';
3
+ export * as utils from './utils';
4
+ export * as factories from './factories';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.7.0-beta.0",
3
+ "version": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
4
4
  "description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite",
5
5
  "keywords": [
6
6
  "strapi",
@@ -81,19 +81,19 @@
81
81
  "dependencies": {
82
82
  "@koa/cors": "3.4.3",
83
83
  "@koa/router": "10.1.1",
84
- "@strapi/admin": "4.7.0-beta.0",
85
- "@strapi/data-transfer": "4.7.0-beta.0",
86
- "@strapi/database": "4.7.0-beta.0",
87
- "@strapi/generate-new": "4.7.0-beta.0",
88
- "@strapi/generators": "4.7.0-beta.0",
89
- "@strapi/logger": "4.7.0-beta.0",
90
- "@strapi/permissions": "4.7.0-beta.0",
91
- "@strapi/plugin-content-manager": "4.7.0-beta.0",
92
- "@strapi/plugin-content-type-builder": "4.7.0-beta.0",
93
- "@strapi/plugin-email": "4.7.0-beta.0",
94
- "@strapi/plugin-upload": "4.7.0-beta.0",
95
- "@strapi/typescript-utils": "4.7.0-beta.0",
96
- "@strapi/utils": "4.7.0-beta.0",
84
+ "@strapi/admin": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
85
+ "@strapi/data-transfer": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
86
+ "@strapi/database": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
87
+ "@strapi/generate-new": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
88
+ "@strapi/generators": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
89
+ "@strapi/logger": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
90
+ "@strapi/permissions": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
91
+ "@strapi/plugin-content-manager": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
92
+ "@strapi/plugin-content-type-builder": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
93
+ "@strapi/plugin-email": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
94
+ "@strapi/plugin-upload": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
95
+ "@strapi/typescript-utils": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
96
+ "@strapi/utils": "4.7.0-exp.117579f4c13806c2cd518e7d7d2f9d0c8a20107d",
97
97
  "bcryptjs": "2.4.3",
98
98
  "boxen": "5.1.2",
99
99
  "chalk": "4.1.2",
@@ -118,11 +118,11 @@
118
118
  "koa-favicon": "2.1.0",
119
119
  "koa-helmet": "6.1.0",
120
120
  "koa-ip": "^2.1.2",
121
- "koa-session": "6.2.0",
121
+ "koa-session": "6.4.0",
122
122
  "koa-static": "5.0.0",
123
123
  "lodash": "4.17.21",
124
124
  "mime-types": "2.1.35",
125
- "node-fetch": "2.6.7",
125
+ "node-fetch": "2.6.9",
126
126
  "node-machine-id": "1.1.12",
127
127
  "node-schedule": "2.1.0",
128
128
  "open": "8.4.0",
@@ -135,12 +135,12 @@
135
135
  "uuid": "^8.3.2"
136
136
  },
137
137
  "devDependencies": {
138
- "supertest": "6.2.4",
138
+ "supertest": "6.3.3",
139
139
  "typescript": "4.6.2"
140
140
  },
141
141
  "engines": {
142
142
  "node": ">=14.19.1 <=18.x.x",
143
143
  "npm": ">=6.0.0"
144
144
  },
145
- "gitHead": "880ba7af867ad43c4cc45b47467b76a9b5606b6e"
145
+ "gitHead": "117579f4c13806c2cd518e7d7d2f9d0c8a20107d"
146
146
  }