@strapi/strapi 4.3.0-beta.1 → 4.3.1

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.
Files changed (43) hide show
  1. package/bin/strapi.js +19 -1
  2. package/lib/Strapi.js +4 -2
  3. package/lib/commands/opt-in-telemetry.js +100 -0
  4. package/lib/commands/ts/generate-types.js +26 -0
  5. package/lib/core/app-configuration/config-loader.js +3 -1
  6. package/lib/core/domain/content-type/validator.js +29 -8
  7. package/lib/global.d.ts +61 -0
  8. package/lib/index.d.ts +2 -25
  9. package/lib/services/cron.js +7 -3
  10. package/lib/services/webhook-runner.js +1 -1
  11. package/lib/types/core/attributes/base.d.ts +74 -0
  12. package/lib/types/core/attributes/biginteger.d.ts +22 -0
  13. package/lib/types/core/attributes/boolean.d.ts +20 -0
  14. package/lib/types/core/attributes/common.d.ts +42 -0
  15. package/lib/types/core/attributes/component.d.ts +41 -0
  16. package/lib/types/core/attributes/date-time.d.ts +22 -0
  17. package/lib/types/core/attributes/date.d.ts +22 -0
  18. package/lib/types/core/attributes/decimal.d.ts +22 -0
  19. package/lib/types/core/attributes/dynamic-zone.d.ts +29 -0
  20. package/lib/types/core/attributes/email.d.ts +24 -0
  21. package/lib/types/core/attributes/enumeration.d.ts +28 -0
  22. package/lib/types/core/attributes/float.d.ts +22 -0
  23. package/lib/types/core/attributes/index.d.ts +26 -0
  24. package/lib/types/core/attributes/integer.d.ts +22 -0
  25. package/lib/types/core/attributes/json.d.ts +14 -0
  26. package/lib/types/core/attributes/media.d.ts +36 -0
  27. package/lib/types/core/attributes/password.d.ts +22 -0
  28. package/lib/types/core/attributes/relation.d.ts +66 -0
  29. package/lib/types/core/attributes/richtext.d.ts +22 -0
  30. package/lib/types/core/attributes/string.d.ts +30 -0
  31. package/lib/types/core/attributes/text.d.ts +30 -0
  32. package/lib/types/core/attributes/time.d.ts +22 -0
  33. package/lib/types/core/attributes/timestamp.d.ts +22 -0
  34. package/lib/types/core/attributes/uid.d.ts +57 -0
  35. package/lib/types/core/attributes/utils.d.ts +99 -0
  36. package/lib/types/core/index.d.ts +3 -0
  37. package/lib/types/core/schemas/index.d.ts +126 -0
  38. package/lib/types/{strapi.d.ts → core/strapi/index.d.ts} +21 -0
  39. package/lib/{factories.d.ts → types/factories.d.ts} +19 -11
  40. package/lib/types/index.d.ts +4 -0
  41. package/lib/types/utils.d.ts +95 -1
  42. package/lib/utils/machine-id.js +2 -2
  43. package/package.json +22 -22
@@ -1,4 +1,5 @@
1
1
  import type Koa from 'koa';
2
+ import { Database } from '@strapi/database';
2
3
 
3
4
  import type { StringMap } from './utils';
4
5
  import type { GenericController } from '../core-api/controller'
@@ -335,6 +336,26 @@ export interface Strapi {
335
336
  * Telemetry util used to collect anonymous data on the application usage
336
337
  */
337
338
  telemetry: any;
339
+
340
+ /**
341
+ * Strapi DB layer instance
342
+ */
343
+ db: Database;
344
+
345
+ /**
346
+ * Core Store accessor
347
+ */
348
+ store: any;
349
+
350
+ /**
351
+ * Entity Validator instance
352
+ */
353
+ entityValidator: any;
354
+
355
+ /**
356
+ * Entity Service instance
357
+ */
358
+ entityService: any;
338
359
  }
339
360
 
340
361
  export interface Lifecycles {
@@ -1,8 +1,8 @@
1
- import { Service } from './core-api/service';
2
- import { Controller, GenericController } from './core-api/controller';
3
- import { Middleware } from './middlewares';
4
- import { Policy } from './core/registries/policies';
5
- import { Strapi } from '@strapi/strapi'
1
+ import { Service } from '../core-api/service';
2
+ import { Controller, GenericController } from '../core-api/controller';
3
+ import { Middleware } from '../middlewares';
4
+ import { Policy } from '../core/registries/policies';
5
+ import { Strapi } from '@strapi/strapi';
6
6
 
7
7
  type ControllerConfig<T extends Controller = Controller> = T;
8
8
 
@@ -10,8 +10,8 @@ type ServiceConfig = Service;
10
10
 
11
11
  type HandlerConfig = {
12
12
  auth?: false | { scope: string[] };
13
- policies?: Array<string | Policy>;
14
- middlewares?: Array<string | Middleware>;
13
+ policies?: Array<string | Policy | { name: string; config: object }>;
14
+ middlewares?: Array<string | Middleware | { name: string; config: object }>;
15
15
  };
16
16
 
17
17
  type SingleTypeRouterConfig = {
@@ -44,9 +44,17 @@ interface Router {
44
44
  routes: Route[];
45
45
  }
46
46
 
47
- type ControllerCallback <T extends GenericController = GenericController> = (params:{strapi:Strapi}) => T;
48
- type ServiceCallback <T extends Service = Sevice> = (params:{strapi:Strapi}) => T
47
+ type ControllerCallback<T extends GenericController = GenericController> = (params: {
48
+ strapi: Strapi;
49
+ }) => T;
50
+ type ServiceCallback<T extends Service = Service> = (params: { strapi: Strapi }) => T;
49
51
 
50
52
  export function createCoreRouter(uid: string, cfg?: RouterConfig = {}): () => Router;
51
- export function createCoreController<T extends GenericController = GenericController>(uid: string, cfg?: ControllerCallback<T> | T = {}): () => T & Controller;
52
- export function createCoreService<T extends Service = Service>(uid: string, cfg?: ServiceCallback<T> | T = {}): () => T ;
53
+ export function createCoreController<T extends GenericController = GenericController>(
54
+ uid: string,
55
+ cfg?: ControllerCallback<T> | T = {}
56
+ ): () => T & Controller;
57
+ export function createCoreService<T extends Service = Service>(
58
+ uid: string,
59
+ cfg?: ServiceCallback<T> | T = {}
60
+ ): () => T;
@@ -0,0 +1,4 @@
1
+ export * from './core';
2
+
3
+ export * as utils from './utils'
4
+ export * as factories from './factories';
@@ -1 +1,95 @@
1
- export type StringMap<T> = { [key: string]: T };
1
+ /**
2
+ *
3
+ * Common utilities used across Strapi typings
4
+ *
5
+ * */
6
+
7
+ /**
8
+ *
9
+ * Extract the array values into an union type
10
+ *
11
+ **/
12
+ export type GetArrayValues<T extends Array<unknown>> = T extends Array<infer U> ? U : never;
13
+
14
+ /**
15
+ * Creates a record where every key is a string and every value is `T`
16
+ */
17
+ export type StringRecord<T> = Record<string, T>;
18
+
19
+ /**
20
+ * Retrieve object's (`T`) keys if they extends the given `U` type.
21
+ *
22
+ * @example
23
+ * type X = KeysBy<{ foo: 'bar', bar: 'foo', foobar: 2 }, string>
24
+ * // 'foo' | 'bar'
25
+ *
26
+ * type Base = { x: 'foo' | 'bar' };
27
+ * type Obj = { foo: { x: 'foo' }, bar: { x: 'bar' }, other: { x: '42' } };
28
+ * type X = KeysBy<Obj, Base>
29
+ * // 'foo' | 'bar'
30
+ */
31
+ export type KeysBy<T, U> = {
32
+ [key in keyof T]: T[key] extends U ? key : never;
33
+ }[keyof T];
34
+
35
+ /**
36
+ * Retrieve object's (`T`) properties if their value extends the given `U` type.
37
+ *
38
+ * @example
39
+ * type X = KeysBy<{ foo: 'bar', bar: 'foo', foobar: 2 }, string>
40
+ * // { foo: 'bar', bar: 'foo' }
41
+ *
42
+ * type Base = { x: 'foo' | 'bar' };
43
+ * type Obj = { foo: { x: 'foo' }, bar: { x: 'bar' }, other: { x: '42' } };
44
+ * type X = KeysBy<Obj, Base>
45
+ * // { foo: { x: 'foo' }, bar: { x: 'bar' } }
46
+ */
47
+ export type PickBy<T, U> = Pick<T, KeysBy<T, U>>;
48
+
49
+ /**
50
+ * Assign a default value `U` to `T` if `T` is of type `never`
51
+ *
52
+ * @example
53
+ * type X = NeverGuard<{ foo: 'bar' }, string>
54
+ * // { foo: 'bar' }
55
+ *
56
+ * type X = NeverGuard<never>
57
+ * // unknown
58
+ *
59
+ * type X = NeverGuard<never, string>
60
+ * // string
61
+ */
62
+ export type NeverGuard<T, U = unknown> = [T] extends [never] ? U : T;
63
+
64
+ /**
65
+ * Dynamic type based on the keys of `Strapi.Schemas`.
66
+ * It represents all the registered schemas' UID as a union type.
67
+ *
68
+ * @example
69
+ *
70
+ * declare global {
71
+ * namespace Strapi {
72
+ * interface Schemas {
73
+ * 'api::foo.foo': CollectionTypeSchema;
74
+ * 'api::bar.bar': ComponentSchema;
75
+ * }
76
+ * }
77
+ * }
78
+ *
79
+ * type X = SchemaUID;
80
+ * // 'api::foo.foo' | 'api::bar.bar'
81
+ */
82
+ export type SchemaUID = keyof Strapi.Schemas;
83
+
84
+ /**
85
+ * Get the type of a specific key `U` in `T`
86
+ *
87
+ * @example
88
+ *
89
+ * type X = Get<{ foo: 'bar', 'bar': 'foo' }, 'foo'>
90
+ * // 'bar'
91
+ *
92
+ * type X = Get<{ foo: 'bar', 'bar': 'foo' }, 'bar'>
93
+ * // 'foo'
94
+ */
95
+ export type Get<T, U extends keyof T> = T[U];
@@ -1,14 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  const { machineIdSync } = require('node-machine-id');
4
- const uuid = require('uuid');
4
+ const { v4: uuidv4 } = require('uuid');
5
5
 
6
6
  module.exports = () => {
7
7
  try {
8
8
  const deviceId = machineIdSync();
9
9
  return deviceId;
10
10
  } catch (error) {
11
- const deviceId = uuid();
11
+ const deviceId = uuidv4();
12
12
  return deviceId;
13
13
  }
14
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.3.0-beta.1",
3
+ "version": "4.3.1",
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",
@@ -80,23 +80,23 @@
80
80
  "dependencies": {
81
81
  "@koa/cors": "3.1.0",
82
82
  "@koa/router": "10.1.1",
83
- "@strapi/admin": "4.3.0-beta.1",
84
- "@strapi/database": "4.3.0-beta.1",
85
- "@strapi/generate-new": "4.3.0-beta.1",
86
- "@strapi/generators": "4.3.0-beta.1",
87
- "@strapi/logger": "4.3.0-beta.1",
88
- "@strapi/plugin-content-manager": "4.3.0-beta.1",
89
- "@strapi/plugin-content-type-builder": "4.3.0-beta.1",
90
- "@strapi/plugin-email": "4.3.0-beta.1",
91
- "@strapi/plugin-upload": "4.3.0-beta.1",
92
- "@strapi/typescript-utils": "4.3.0-beta.1",
93
- "@strapi/utils": "4.3.0-beta.1",
83
+ "@strapi/admin": "4.3.1",
84
+ "@strapi/database": "4.3.1",
85
+ "@strapi/generate-new": "4.3.1",
86
+ "@strapi/generators": "4.3.1",
87
+ "@strapi/logger": "4.3.1",
88
+ "@strapi/plugin-content-manager": "4.3.1",
89
+ "@strapi/plugin-content-type-builder": "4.3.1",
90
+ "@strapi/plugin-email": "4.3.1",
91
+ "@strapi/plugin-upload": "4.3.1",
92
+ "@strapi/typescript-utils": "4.3.1",
93
+ "@strapi/utils": "4.3.1",
94
94
  "bcryptjs": "2.4.3",
95
95
  "boxen": "5.1.2",
96
96
  "chalk": "4.1.2",
97
97
  "chokidar": "3.5.2",
98
98
  "ci-info": "3.2.0",
99
- "cli-table3": "0.6.1",
99
+ "cli-table3": "0.6.2",
100
100
  "commander": "8.2.0",
101
101
  "configstore": "5.0.1",
102
102
  "debug": "4.3.2",
@@ -105,10 +105,10 @@
105
105
  "execa": "5.1.1",
106
106
  "fs-extra": "10.0.0",
107
107
  "glob": "7.2.0",
108
- "http-errors": "1.8.0",
109
- "inquirer": "8.2.0",
108
+ "http-errors": "1.8.1",
109
+ "inquirer": "8.2.4",
110
110
  "is-docker": "2.2.1",
111
- "koa": "2.13.3",
111
+ "koa": "2.13.4",
112
112
  "koa-body": "4.2.0",
113
113
  "koa-compose": "4.1.0",
114
114
  "koa-compress": "5.1.0",
@@ -121,23 +121,23 @@
121
121
  "mime-types": "2.1.35",
122
122
  "node-fetch": "2.6.7",
123
123
  "node-machine-id": "1.1.12",
124
- "node-schedule": "2.0.0",
125
- "open": "8.2.1",
124
+ "node-schedule": "2.1.0",
125
+ "open": "8.4.0",
126
126
  "ora": "5.4.1",
127
127
  "package-json": "7.0.0",
128
128
  "qs": "6.10.1",
129
129
  "resolve-cwd": "3.0.0",
130
- "semver": "7.3.5",
130
+ "semver": "7.3.7",
131
131
  "statuses": "2.0.1",
132
- "uuid": "^3.3.2"
132
+ "uuid": "^8.3.2"
133
133
  },
134
134
  "devDependencies": {
135
- "supertest": "^6.1.6",
135
+ "supertest": "6.2.4",
136
136
  "typescript": "4.6.2"
137
137
  },
138
138
  "engines": {
139
139
  "node": ">=14.19.1 <=16.x.x",
140
140
  "npm": ">=6.0.0"
141
141
  },
142
- "gitHead": "9d6555398960c39159d66bb4eea3bcb0362e37e3"
142
+ "gitHead": "1eab2fb08c7a4d3d40a5a7ff3b2f137ce0afcf8a"
143
143
  }