@strapi/typescript-utils 0.0.0-experimental.6340da17068c3bed7fb006e7bcc554c71129e282 → 0.0.0-experimental.63624e21eb5b0713345a0cf2f68f1c40eab427bc

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 (225) hide show
  1. package/dist/compile.d.ts +5 -0
  2. package/dist/compile.d.ts.map +1 -0
  3. package/dist/compile.js +12 -0
  4. package/dist/compile.js.map +1 -0
  5. package/dist/compile.mjs +10 -0
  6. package/dist/compile.mjs.map +1 -0
  7. package/dist/compilers/basic.d.ts +11 -0
  8. package/dist/compilers/basic.d.ts.map +1 -0
  9. package/dist/compilers/basic.js +58 -0
  10. package/dist/compilers/basic.js.map +1 -0
  11. package/dist/compilers/basic.mjs +36 -0
  12. package/dist/compilers/basic.mjs.map +1 -0
  13. package/dist/compilers/index.d.ts +3 -0
  14. package/dist/compilers/index.d.ts.map +1 -0
  15. package/dist/compilers/index.js +8 -0
  16. package/dist/compilers/index.js.map +1 -0
  17. package/dist/compilers/index.mjs +3 -0
  18. package/dist/compilers/index.mjs.map +1 -0
  19. package/dist/generators/common/compare.d.ts +14 -0
  20. package/dist/generators/common/compare.d.ts.map +1 -0
  21. package/dist/generators/common/compare.js +25 -0
  22. package/dist/generators/common/compare.js.map +1 -0
  23. package/dist/generators/common/compare.mjs +22 -0
  24. package/dist/generators/common/compare.mjs.map +1 -0
  25. package/dist/generators/common/imports.d.ts +5 -0
  26. package/dist/generators/common/imports.d.ts.map +1 -0
  27. package/dist/generators/common/imports.js +42 -0
  28. package/dist/generators/common/imports.js.map +1 -0
  29. package/dist/generators/common/imports.mjs +19 -0
  30. package/dist/generators/common/imports.mjs.map +1 -0
  31. package/dist/generators/common/index.d.ts +4 -0
  32. package/dist/generators/common/index.d.ts.map +1 -0
  33. package/dist/generators/common/interface-names.d.ts +16 -0
  34. package/dist/generators/common/interface-names.d.ts.map +1 -0
  35. package/dist/generators/common/interface-names.js +54 -0
  36. package/dist/generators/common/interface-names.js.map +1 -0
  37. package/dist/generators/common/interface-names.mjs +52 -0
  38. package/dist/generators/common/interface-names.mjs.map +1 -0
  39. package/dist/generators/common/models/attributes.d.ts +38 -0
  40. package/dist/generators/common/models/attributes.d.ts.map +1 -0
  41. package/dist/generators/common/models/attributes.js +205 -0
  42. package/dist/generators/common/models/attributes.js.map +1 -0
  43. package/dist/generators/common/models/attributes.mjs +176 -0
  44. package/dist/generators/common/models/attributes.mjs.map +1 -0
  45. package/dist/generators/common/models/index.d.ts +7 -0
  46. package/dist/generators/common/models/index.d.ts.map +1 -0
  47. package/dist/generators/common/models/mappers.d.ts +9 -0
  48. package/dist/generators/common/models/mappers.d.ts.map +1 -0
  49. package/dist/generators/common/models/mappers.js +227 -0
  50. package/dist/generators/common/models/mappers.js.map +1 -0
  51. package/dist/generators/common/models/mappers.mjs +202 -0
  52. package/dist/generators/common/models/mappers.mjs.map +1 -0
  53. package/dist/generators/common/models/schema.d.ts +8 -0
  54. package/dist/generators/common/models/schema.d.ts.map +1 -0
  55. package/dist/generators/common/models/schema.js +78 -0
  56. package/dist/generators/common/models/schema.js.map +1 -0
  57. package/dist/generators/common/models/schema.mjs +56 -0
  58. package/dist/generators/common/models/schema.mjs.map +1 -0
  59. package/dist/generators/common/models/utils.d.ts +57 -0
  60. package/dist/generators/common/models/utils.d.ts.map +1 -0
  61. package/dist/generators/common/models/utils.js +110 -0
  62. package/dist/generators/common/models/utils.js.map +1 -0
  63. package/dist/generators/common/models/utils.mjs +82 -0
  64. package/dist/generators/common/models/utils.mjs.map +1 -0
  65. package/dist/generators/common/sources.d.ts +133 -0
  66. package/dist/generators/common/sources.d.ts.map +1 -0
  67. package/dist/generators/common/sources.js +354 -0
  68. package/dist/generators/common/sources.js.map +1 -0
  69. package/dist/generators/common/sources.mjs +318 -0
  70. package/dist/generators/common/sources.mjs.map +1 -0
  71. package/dist/generators/components/index.d.ts +9 -0
  72. package/dist/generators/components/index.d.ts.map +1 -0
  73. package/dist/generators/components/index.js +84 -0
  74. package/dist/generators/components/index.js.map +1 -0
  75. package/dist/generators/components/index.mjs +62 -0
  76. package/dist/generators/components/index.mjs.map +1 -0
  77. package/dist/generators/constants.d.ts +3 -0
  78. package/dist/generators/constants.d.ts.map +1 -0
  79. package/dist/generators/constants.js +8 -0
  80. package/dist/generators/constants.js.map +1 -0
  81. package/dist/generators/constants.mjs +5 -0
  82. package/dist/generators/constants.mjs.map +1 -0
  83. package/dist/generators/content-types/index.d.ts +9 -0
  84. package/dist/generators/content-types/index.d.ts.map +1 -0
  85. package/dist/generators/content-types/index.js +84 -0
  86. package/dist/generators/content-types/index.js.map +1 -0
  87. package/dist/generators/content-types/index.mjs +62 -0
  88. package/dist/generators/content-types/index.mjs.map +1 -0
  89. package/dist/generators/controllers/index.d.ts +35 -0
  90. package/dist/generators/controllers/index.d.ts.map +1 -0
  91. package/dist/generators/controllers/index.js +88 -0
  92. package/dist/generators/controllers/index.js.map +1 -0
  93. package/dist/generators/controllers/index.mjs +86 -0
  94. package/dist/generators/controllers/index.mjs.map +1 -0
  95. package/dist/generators/index.d.ts +31 -0
  96. package/dist/generators/index.d.ts.map +1 -0
  97. package/dist/generators/index.js +150 -0
  98. package/dist/generators/index.js.map +1 -0
  99. package/dist/generators/index.mjs +142 -0
  100. package/dist/generators/index.mjs.map +1 -0
  101. package/dist/generators/middlewares/index.d.ts +30 -0
  102. package/dist/generators/middlewares/index.d.ts.map +1 -0
  103. package/dist/generators/middlewares/index.js +163 -0
  104. package/dist/generators/middlewares/index.js.map +1 -0
  105. package/dist/generators/middlewares/index.mjs +141 -0
  106. package/dist/generators/middlewares/index.mjs.map +1 -0
  107. package/dist/generators/plugins/index.d.ts +9 -0
  108. package/dist/generators/plugins/index.d.ts.map +1 -0
  109. package/dist/generators/plugins/index.js +225 -0
  110. package/dist/generators/plugins/index.js.map +1 -0
  111. package/dist/generators/plugins/index.mjs +200 -0
  112. package/dist/generators/plugins/index.mjs.map +1 -0
  113. package/dist/generators/policies/index.d.ts +29 -0
  114. package/dist/generators/policies/index.d.ts.map +1 -0
  115. package/dist/generators/policies/index.js +135 -0
  116. package/dist/generators/policies/index.js.map +1 -0
  117. package/dist/generators/policies/index.mjs +113 -0
  118. package/dist/generators/policies/index.mjs.map +1 -0
  119. package/dist/generators/services/index.d.ts +35 -0
  120. package/dist/generators/services/index.d.ts.map +1 -0
  121. package/dist/generators/services/index.js +87 -0
  122. package/dist/generators/services/index.js.map +1 -0
  123. package/dist/generators/services/index.mjs +85 -0
  124. package/dist/generators/services/index.mjs.map +1 -0
  125. package/dist/generators/strict/index.d.ts +13 -0
  126. package/dist/generators/strict/index.d.ts.map +1 -0
  127. package/dist/generators/strict/index.js +24 -0
  128. package/dist/generators/strict/index.js.map +1 -0
  129. package/dist/generators/strict/index.mjs +22 -0
  130. package/dist/generators/strict/index.mjs.map +1 -0
  131. package/dist/generators/utils.d.ts +68 -0
  132. package/dist/generators/utils.d.ts.map +1 -0
  133. package/dist/generators/utils.js +201 -0
  134. package/dist/generators/utils.js.map +1 -0
  135. package/dist/generators/utils.mjs +166 -0
  136. package/dist/generators/utils.mjs.map +1 -0
  137. package/dist/index.d.ts +5 -0
  138. package/dist/index.d.ts.map +1 -0
  139. package/dist/index.js +28 -0
  140. package/dist/index.js.map +1 -0
  141. package/dist/index.mjs +14 -0
  142. package/dist/index.mjs.map +1 -0
  143. package/dist/utils/format-host.d.ts +3 -0
  144. package/dist/utils/format-host.d.ts.map +1 -0
  145. package/dist/utils/format-host.js +33 -0
  146. package/dist/utils/format-host.js.map +1 -0
  147. package/dist/utils/format-host.mjs +11 -0
  148. package/dist/utils/format-host.mjs.map +1 -0
  149. package/dist/utils/get-config-path.d.ts +10 -0
  150. package/dist/utils/get-config-path.d.ts.map +1 -0
  151. package/dist/utils/get-config-path.js +43 -0
  152. package/dist/utils/get-config-path.js.map +1 -0
  153. package/dist/utils/get-config-path.mjs +18 -0
  154. package/dist/utils/get-config-path.mjs.map +1 -0
  155. package/dist/utils/index.d.ts +9 -0
  156. package/dist/utils/index.d.ts.map +1 -0
  157. package/dist/utils/is-using-typescript-sync.d.ts +5 -0
  158. package/dist/utils/is-using-typescript-sync.d.ts.map +1 -0
  159. package/dist/utils/is-using-typescript-sync.js +20 -0
  160. package/dist/utils/is-using-typescript-sync.js.map +1 -0
  161. package/dist/utils/is-using-typescript-sync.mjs +14 -0
  162. package/dist/utils/is-using-typescript-sync.mjs.map +1 -0
  163. package/dist/utils/is-using-typescript.d.ts +5 -0
  164. package/dist/utils/is-using-typescript.d.ts.map +1 -0
  165. package/dist/utils/is-using-typescript.js +20 -0
  166. package/dist/utils/is-using-typescript.js.map +1 -0
  167. package/dist/utils/is-using-typescript.mjs +14 -0
  168. package/dist/utils/is-using-typescript.mjs.map +1 -0
  169. package/dist/utils/report-diagnostics.d.ts +6 -0
  170. package/dist/utils/report-diagnostics.d.ts.map +1 -0
  171. package/dist/utils/report-diagnostics.js +37 -0
  172. package/dist/utils/report-diagnostics.js.map +1 -0
  173. package/dist/utils/report-diagnostics.mjs +15 -0
  174. package/dist/utils/report-diagnostics.mjs.map +1 -0
  175. package/dist/utils/resolve-config-options.d.ts +12 -0
  176. package/dist/utils/resolve-config-options.d.ts.map +1 -0
  177. package/dist/utils/resolve-config-options.js +39 -0
  178. package/dist/utils/resolve-config-options.js.map +1 -0
  179. package/dist/utils/resolve-config-options.mjs +17 -0
  180. package/dist/utils/resolve-config-options.mjs.map +1 -0
  181. package/dist/utils/resolve-outdir-sync.d.ts +5 -0
  182. package/dist/utils/resolve-outdir-sync.d.ts.map +1 -0
  183. package/dist/utils/resolve-outdir-sync.js +19 -0
  184. package/dist/utils/resolve-outdir-sync.js.map +1 -0
  185. package/dist/utils/resolve-outdir-sync.mjs +13 -0
  186. package/dist/utils/resolve-outdir-sync.mjs.map +1 -0
  187. package/dist/utils/resolve-outdir.d.ts +5 -0
  188. package/dist/utils/resolve-outdir.d.ts.map +1 -0
  189. package/dist/utils/resolve-outdir.js +19 -0
  190. package/dist/utils/resolve-outdir.js.map +1 -0
  191. package/dist/utils/resolve-outdir.mjs +13 -0
  192. package/dist/utils/resolve-outdir.mjs.map +1 -0
  193. package/package.json +27 -12
  194. package/.eslintrc.cjs +0 -16
  195. package/index.d.ts +0 -5
  196. package/jest.config.js +0 -6
  197. package/lib/__tests__/generators/schemas/attributes.test.js +0 -903
  198. package/lib/__tests__/generators/schemas/imports.test.js +0 -56
  199. package/lib/__tests__/generators/schemas/utils.test.js +0 -314
  200. package/lib/compile.js +0 -10
  201. package/lib/compilers/basic.js +0 -50
  202. package/lib/compilers/index.js +0 -7
  203. package/lib/generators/common/imports.js +0 -34
  204. package/lib/generators/common/index.js +0 -9
  205. package/lib/generators/common/models/attributes.js +0 -198
  206. package/lib/generators/common/models/index.js +0 -15
  207. package/lib/generators/common/models/mappers.js +0 -144
  208. package/lib/generators/common/models/schema.js +0 -93
  209. package/lib/generators/common/models/utils.js +0 -178
  210. package/lib/generators/components/index.js +0 -74
  211. package/lib/generators/constants.js +0 -6
  212. package/lib/generators/content-types/index.js +0 -74
  213. package/lib/generators/index.js +0 -122
  214. package/lib/generators/utils.js +0 -216
  215. package/lib/index.js +0 -13
  216. package/lib/utils/format-host.js +0 -15
  217. package/lib/utils/get-config-path.js +0 -29
  218. package/lib/utils/index.js +0 -21
  219. package/lib/utils/is-using-typescript-sync.js +0 -19
  220. package/lib/utils/is-using-typescript.js +0 -17
  221. package/lib/utils/report-diagnostics.js +0 -19
  222. package/lib/utils/resolve-config-options.js +0 -23
  223. package/lib/utils/resolve-outdir-sync.js +0 -18
  224. package/lib/utils/resolve-outdir.js +0 -18
  225. package/lint-staged.config.mjs +0 -1
@@ -0,0 +1,135 @@
1
+ 'use strict';
2
+
3
+ var ts = require('typescript');
4
+ var sources = require('../common/sources.js');
5
+
6
+ function _interopNamespace(e) {
7
+ if (e && e.__esModule) return e;
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
18
+ });
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
+ }
23
+
24
+ var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
25
+
26
+ const { factory } = ts__namespace;
27
+ const REGISTRY = 'AppPolicies';
28
+ const CONFIG_HELPER = 'PolicyConfig';
29
+ const HANDLER_CONFIG_HELPER = 'PolicyHandlerConfig';
30
+ const NO_POLICY_PLACEHOLDER_COMMENT = `/*
31
+ * The app doesn't have any policies yet.
32
+ */
33
+
34
+ export {};
35
+ `;
36
+ /**
37
+ * type PolicyHandlerConfig<THandler> = THandler extends (...args: infer TArgs) => unknown
38
+ * ? TArgs['length'] extends 0 | 1 ? undefined : 0 extends 1 & TArgs[1] ? unknown : TArgs[1]
39
+ * : unknown;
40
+ *
41
+ * type PolicyConfig<TModule> = TModule extends { default: infer TExport }
42
+ * ? PolicyHandlerConfig<TExport extends { handler: infer THandler } ? THandler : TExport>
43
+ * : unknown;
44
+ *
45
+ * Emitted in the file so that policies.ts stands alone, like the services and controllers helpers,
46
+ * and only when a TypeScript policy reads them.
47
+ *
48
+ * Resolves the config a policy accepts from the type of its module: the second parameter of its
49
+ * handler, for both runtime forms (a bare handler, or `{ handler, validator }`). A handler without
50
+ * a config parameter takes none: `undefined`, as in PackagePolicies. An untyped (`any`) config and a
51
+ * module without a default export resolve to `unknown`: one `any` entry would turn every policy
52
+ * reference into `any`.
53
+ * TODO @Nico a module without a default export registers nothing usable at runtime (resolving it
54
+ * throws); `unknown` accepts any reference to it, like an untyped policy
55
+ */ const generateConfigHelpersDefinition = ()=>{
56
+ const args = factory.createTypeReferenceNode('TArgs');
57
+ const configArg = factory.createIndexedAccessTypeNode(args, factory.createLiteralTypeNode(factory.createNumericLiteral(1)));
58
+ const handlerConfig = factory.createConditionalTypeNode(factory.createTypeReferenceNode('THandler'), factory.createFunctionTypeNode(undefined, [
59
+ factory.createParameterDeclaration(undefined, factory.createToken(ts__namespace.SyntaxKind.DotDotDotToken), 'args', undefined, factory.createInferTypeNode(factory.createTypeParameterDeclaration(undefined, 'TArgs')))
60
+ ], factory.createKeywordTypeNode(ts__namespace.SyntaxKind.UnknownKeyword)), factory.createConditionalTypeNode(factory.createIndexedAccessTypeNode(args, factory.createLiteralTypeNode(factory.createStringLiteral('length', true))), factory.createUnionTypeNode([
61
+ factory.createLiteralTypeNode(factory.createNumericLiteral(0)),
62
+ factory.createLiteralTypeNode(factory.createNumericLiteral(1))
63
+ ]), factory.createKeywordTypeNode(ts__namespace.SyntaxKind.UndefinedKeyword), // 0 extends 1 & TArgs[1], true only when the config is `any`
64
+ factory.createConditionalTypeNode(factory.createLiteralTypeNode(factory.createNumericLiteral(0)), factory.createIntersectionTypeNode([
65
+ factory.createLiteralTypeNode(factory.createNumericLiteral(1)),
66
+ configArg
67
+ ]), factory.createKeywordTypeNode(ts__namespace.SyntaxKind.UnknownKeyword), configArg)), factory.createKeywordTypeNode(ts__namespace.SyntaxKind.UnknownKeyword));
68
+ const unwrapHandler = factory.createConditionalTypeNode(factory.createTypeReferenceNode('TExport'), factory.createTypeLiteralNode([
69
+ factory.createPropertySignature(undefined, 'handler', undefined, factory.createInferTypeNode(factory.createTypeParameterDeclaration(undefined, 'THandler')))
70
+ ]), factory.createTypeReferenceNode('THandler'), factory.createTypeReferenceNode('TExport'));
71
+ const moduleConfig = factory.createConditionalTypeNode(factory.createTypeReferenceNode('TModule'), factory.createTypeLiteralNode([
72
+ factory.createPropertySignature(undefined, 'default', undefined, factory.createInferTypeNode(factory.createTypeParameterDeclaration(undefined, 'TExport')))
73
+ ]), factory.createTypeReferenceNode(HANDLER_CONFIG_HELPER, [
74
+ unwrapHandler
75
+ ]), factory.createKeywordTypeNode(ts__namespace.SyntaxKind.UnknownKeyword));
76
+ return [
77
+ sources.withDocComment(factory.createTypeAliasDeclaration(undefined, factory.createIdentifier(HANDLER_CONFIG_HELPER), [
78
+ factory.createTypeParameterDeclaration(undefined, 'THandler')
79
+ ], handlerConfig), '*\n * Config a policy handler accepts: its second parameter, `undefined` when it has none, `unknown`\n * when it is untyped.\n '),
80
+ sources.withDocComment(factory.createTypeAliasDeclaration(undefined, factory.createIdentifier(CONFIG_HELPER), [
81
+ factory.createTypeParameterDeclaration(undefined, 'TModule')
82
+ ], moduleConfig), '*\n * Config accepted by the policy a policy module exports, as a bare handler or as\n * `{ handler, validator }`.\n ')
83
+ ];
84
+ };
85
+ /**
86
+ * Generate type definitions for the application's policies (global::* and api::*)
87
+ *
88
+ * Policies are typed from their source file, so only the ones with a source in src/policies or
89
+ * src/api are emitted. Plugin and admin policies are left to the packages themselves
90
+ * (Strapi.Registries.PackagePolicies), so registering application policies keeps them accepted.
91
+ *
92
+ * declare global {
93
+ * namespace Strapi {
94
+ * namespace Registries {
95
+ * interface AppPolicies {
96
+ * 'global::<policy>': PolicyConfig<typeof import('<relative path to the source>')>;
97
+ * 'api::<api>.<policy>': PolicyConfig<typeof import('<relative path to the source>')>;
98
+ * 'global::<js policy>': unknown;
99
+ * }
100
+ * }
101
+ * }
102
+ * }
103
+ *
104
+ * The import of a JS policy is an error type without `allowJs`, and one such entry turns every policy
105
+ * reference into `any`. JS policies are registered as `unknown` without an import.
106
+ * TODO @Nico with `allowJs`, a JSDoc-typed JS policy could register its config like a TS one
107
+ */ const generatePoliciesDefinitions = async (options = {})=>{
108
+ const { strapi, logger, pwd: outDir } = options;
109
+ if (!outDir) {
110
+ throw new Error('The policies generator needs the output directory to resolve source imports');
111
+ }
112
+ const sources$1 = await sources.collectAppSources('policies', {
113
+ global: strapi.dirs.app.policies,
114
+ api: strapi.dirs.app.api
115
+ }, outDir, logger);
116
+ const policiesDefinitions = sources.filterRegisteredSources(sources$1, strapi.policies, logger);
117
+ logger.debug(`Found ${policiesDefinitions.length} policies.`);
118
+ if (policiesDefinitions.length === 0) {
119
+ return {
120
+ output: NO_POLICY_PLACEHOLDER_COMMENT,
121
+ stats: {}
122
+ };
123
+ }
124
+ // The helpers are only emitted when an entry reads them: `noUnusedLocals` reports unused ones
125
+ const output = await sources.emitRegistryDefinitions(REGISTRY, policiesDefinitions.some(sources.isTypedSource) === true ? generateConfigHelpersDefinition() : [], policiesDefinitions, (source)=>sources.isTypedSource(source) ? factory.createTypeReferenceNode(CONFIG_HELPER, [
126
+ sources.typeofImport(source)
127
+ ]) : factory.createKeywordTypeNode(ts__namespace.SyntaxKind.UnknownKeyword));
128
+ return {
129
+ output,
130
+ stats: {}
131
+ };
132
+ };
133
+
134
+ exports.generatePoliciesDefinitions = generatePoliciesDefinitions;
135
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/generators/policies/index.ts"],"sourcesContent":["import * as ts from 'typescript';\n\nimport {\n collectAppSources,\n emitRegistryDefinitions,\n filterRegisteredSources,\n isTypedSource,\n typeofImport,\n withDocComment,\n} from '../common/sources';\nimport type { GeneratorOptions } from '../utils';\n\nconst { factory } = ts;\n\nconst REGISTRY = 'AppPolicies';\nconst CONFIG_HELPER = 'PolicyConfig';\nconst HANDLER_CONFIG_HELPER = 'PolicyHandlerConfig';\n\nconst NO_POLICY_PLACEHOLDER_COMMENT = `/*\n * The app doesn't have any policies yet.\n */\n\nexport {};\n`;\n\n/**\n * type PolicyHandlerConfig<THandler> = THandler extends (...args: infer TArgs) => unknown\n * ? TArgs['length'] extends 0 | 1 ? undefined : 0 extends 1 & TArgs[1] ? unknown : TArgs[1]\n * : unknown;\n *\n * type PolicyConfig<TModule> = TModule extends { default: infer TExport }\n * ? PolicyHandlerConfig<TExport extends { handler: infer THandler } ? THandler : TExport>\n * : unknown;\n *\n * Emitted in the file so that policies.ts stands alone, like the services and controllers helpers,\n * and only when a TypeScript policy reads them.\n *\n * Resolves the config a policy accepts from the type of its module: the second parameter of its\n * handler, for both runtime forms (a bare handler, or `{ handler, validator }`). A handler without\n * a config parameter takes none: `undefined`, as in PackagePolicies. An untyped (`any`) config and a\n * module without a default export resolve to `unknown`: one `any` entry would turn every policy\n * reference into `any`.\n * TODO @Nico a module without a default export registers nothing usable at runtime (resolving it\n * throws); `unknown` accepts any reference to it, like an untyped policy\n */\nconst generateConfigHelpersDefinition = () => {\n const args = factory.createTypeReferenceNode('TArgs');\n const configArg = factory.createIndexedAccessTypeNode(\n args,\n factory.createLiteralTypeNode(factory.createNumericLiteral(1))\n );\n\n const handlerConfig = factory.createConditionalTypeNode(\n factory.createTypeReferenceNode('THandler'),\n factory.createFunctionTypeNode(\n undefined,\n [\n factory.createParameterDeclaration(\n undefined,\n factory.createToken(ts.SyntaxKind.DotDotDotToken),\n 'args',\n undefined,\n factory.createInferTypeNode(factory.createTypeParameterDeclaration(undefined, 'TArgs'))\n ),\n ],\n factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)\n ),\n factory.createConditionalTypeNode(\n factory.createIndexedAccessTypeNode(\n args,\n factory.createLiteralTypeNode(factory.createStringLiteral('length', true))\n ),\n factory.createUnionTypeNode([\n factory.createLiteralTypeNode(factory.createNumericLiteral(0)),\n factory.createLiteralTypeNode(factory.createNumericLiteral(1)),\n ]),\n factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n // 0 extends 1 & TArgs[1], true only when the config is `any`\n factory.createConditionalTypeNode(\n factory.createLiteralTypeNode(factory.createNumericLiteral(0)),\n factory.createIntersectionTypeNode([\n factory.createLiteralTypeNode(factory.createNumericLiteral(1)),\n configArg,\n ]),\n factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),\n configArg\n )\n ),\n factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)\n );\n\n const unwrapHandler = factory.createConditionalTypeNode(\n factory.createTypeReferenceNode('TExport'),\n factory.createTypeLiteralNode([\n factory.createPropertySignature(\n undefined,\n 'handler',\n undefined,\n factory.createInferTypeNode(factory.createTypeParameterDeclaration(undefined, 'THandler'))\n ),\n ]),\n factory.createTypeReferenceNode('THandler'),\n factory.createTypeReferenceNode('TExport')\n );\n\n const moduleConfig = factory.createConditionalTypeNode(\n factory.createTypeReferenceNode('TModule'),\n factory.createTypeLiteralNode([\n factory.createPropertySignature(\n undefined,\n 'default',\n undefined,\n factory.createInferTypeNode(factory.createTypeParameterDeclaration(undefined, 'TExport'))\n ),\n ]),\n factory.createTypeReferenceNode(HANDLER_CONFIG_HELPER, [unwrapHandler]),\n factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)\n );\n\n return [\n withDocComment(\n factory.createTypeAliasDeclaration(\n undefined,\n factory.createIdentifier(HANDLER_CONFIG_HELPER),\n [factory.createTypeParameterDeclaration(undefined, 'THandler')],\n handlerConfig\n ),\n '*\\n * Config a policy handler accepts: its second parameter, `undefined` when it has none, `unknown`\\n * when it is untyped.\\n '\n ),\n withDocComment(\n factory.createTypeAliasDeclaration(\n undefined,\n factory.createIdentifier(CONFIG_HELPER),\n [factory.createTypeParameterDeclaration(undefined, 'TModule')],\n moduleConfig\n ),\n '*\\n * Config accepted by the policy a policy module exports, as a bare handler or as\\n * `{ handler, validator }`.\\n '\n ),\n ];\n};\n\n/**\n * Generate type definitions for the application's policies (global::* and api::*)\n *\n * Policies are typed from their source file, so only the ones with a source in src/policies or\n * src/api are emitted. Plugin and admin policies are left to the packages themselves\n * (Strapi.Registries.PackagePolicies), so registering application policies keeps them accepted.\n *\n * declare global {\n * namespace Strapi {\n * namespace Registries {\n * interface AppPolicies {\n * 'global::<policy>': PolicyConfig<typeof import('<relative path to the source>')>;\n * 'api::<api>.<policy>': PolicyConfig<typeof import('<relative path to the source>')>;\n * 'global::<js policy>': unknown;\n * }\n * }\n * }\n * }\n *\n * The import of a JS policy is an error type without `allowJs`, and one such entry turns every policy\n * reference into `any`. JS policies are registered as `unknown` without an import.\n * TODO @Nico with `allowJs`, a JSDoc-typed JS policy could register its config like a TS one\n */\nexport const generatePoliciesDefinitions = async (\n options: GeneratorOptions = {} as GeneratorOptions\n) => {\n const { strapi, logger, pwd: outDir } = options;\n\n if (!outDir) {\n throw new Error('The policies generator needs the output directory to resolve source imports');\n }\n\n const sources = await collectAppSources(\n 'policies',\n { global: strapi.dirs.app.policies, api: strapi.dirs.app.api },\n outDir,\n logger\n );\n const policiesDefinitions = filterRegisteredSources(sources, strapi.policies, logger);\n\n logger.debug(`Found ${policiesDefinitions.length} policies.`);\n\n if (policiesDefinitions.length === 0) {\n return { output: NO_POLICY_PLACEHOLDER_COMMENT, stats: {} };\n }\n\n // The helpers are only emitted when an entry reads them: `noUnusedLocals` reports unused ones\n const output = await emitRegistryDefinitions(\n REGISTRY,\n policiesDefinitions.some(isTypedSource) === true ? generateConfigHelpersDefinition() : [],\n policiesDefinitions,\n (source) =>\n isTypedSource(source)\n ? factory.createTypeReferenceNode(CONFIG_HELPER, [typeofImport(source)])\n : factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)\n );\n\n return { output, stats: {} };\n};\n"],"names":["factory","ts","REGISTRY","CONFIG_HELPER","HANDLER_CONFIG_HELPER","NO_POLICY_PLACEHOLDER_COMMENT","generateConfigHelpersDefinition","args","createTypeReferenceNode","configArg","createIndexedAccessTypeNode","createLiteralTypeNode","createNumericLiteral","handlerConfig","createConditionalTypeNode","createFunctionTypeNode","undefined","createParameterDeclaration","createToken","SyntaxKind","DotDotDotToken","createInferTypeNode","createTypeParameterDeclaration","createKeywordTypeNode","UnknownKeyword","createStringLiteral","createUnionTypeNode","UndefinedKeyword","createIntersectionTypeNode","unwrapHandler","createTypeLiteralNode","createPropertySignature","moduleConfig","withDocComment","createTypeAliasDeclaration","createIdentifier","generatePoliciesDefinitions","options","strapi","logger","pwd","outDir","Error","sources","collectAppSources","global","dirs","app","policies","api","policiesDefinitions","filterRegisteredSources","debug","length","output","stats","emitRegistryDefinitions","some","isTypedSource","source","typeofImport"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAM,EAAEA,OAAO,EAAE,GAAGC,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CAACC,QAAQ;AAAEC,QAAAA,GAAAA,EAAKX,MAAAA,CAAOQ,IAAI,CAACC,GAAG,CAACE;AAAI,KAAA,EAC7DR,MAAAA,EACAF,MAAAA,CAAAA;AAEF,IAAA,MAAMW,mBAAAA,GAAsBC,+BAAAA,CAAwBR,SAAAA,EAASL,MAAAA,CAAOU,QAAQ,EAAET,MAAAA,CAAAA;IAE9EA,MAAAA,CAAOa,KAAK,CAAC,CAAC,MAAM,EAAEF,mBAAAA,CAAoBG,MAAM,CAAC,UAAU,CAAC,CAAA;IAE5D,IAAIH,mBAAAA,CAAoBG,MAAM,KAAK,CAAA,EAAG;QACpC,OAAO;YAAEC,MAAAA,EAAQjD,6BAAAA;AAA+BkD,YAAAA,KAAAA,EAAO;AAAG,SAAA;AAC5D,IAAA;;IAGA,MAAMD,MAAAA,GAAS,MAAME,+BAAAA,CACnBtD,QAAAA,EACAgD,oBAAoBO,IAAI,CAACC,2BAAmB,IAAA,GAAOpD,+BAAAA,EAAAA,GAAoC,EAAE,EACzF4C,mBAAAA,EACA,CAACS,MAAAA,GACCD,qBAAAA,CAAcC,UACV3D,OAAAA,CAAQQ,uBAAuB,CAACL,aAAAA,EAAe;YAACyD,oBAAAA,CAAaD,MAAAA;AAAQ,SAAA,CAAA,GACrE3D,QAAQuB,qBAAqB,CAACtB,aAAAA,CAAGkB,UAAU,CAACK,cAAc,CAAA,CAAA;IAGlE,OAAO;AAAE8B,QAAAA,MAAAA;AAAQC,QAAAA,KAAAA,EAAO;AAAG,KAAA;AAC7B;;;;"}
@@ -0,0 +1,113 @@
1
+ import * as ts from 'typescript';
2
+ import { collectAppSources, filterRegisteredSources, emitRegistryDefinitions, isTypedSource, withDocComment, typeofImport } from '../common/sources.mjs';
3
+
4
+ const { factory } = ts;
5
+ const REGISTRY = 'AppPolicies';
6
+ const CONFIG_HELPER = 'PolicyConfig';
7
+ const HANDLER_CONFIG_HELPER = 'PolicyHandlerConfig';
8
+ const NO_POLICY_PLACEHOLDER_COMMENT = `/*
9
+ * The app doesn't have any policies yet.
10
+ */
11
+
12
+ export {};
13
+ `;
14
+ /**
15
+ * type PolicyHandlerConfig<THandler> = THandler extends (...args: infer TArgs) => unknown
16
+ * ? TArgs['length'] extends 0 | 1 ? undefined : 0 extends 1 & TArgs[1] ? unknown : TArgs[1]
17
+ * : unknown;
18
+ *
19
+ * type PolicyConfig<TModule> = TModule extends { default: infer TExport }
20
+ * ? PolicyHandlerConfig<TExport extends { handler: infer THandler } ? THandler : TExport>
21
+ * : unknown;
22
+ *
23
+ * Emitted in the file so that policies.ts stands alone, like the services and controllers helpers,
24
+ * and only when a TypeScript policy reads them.
25
+ *
26
+ * Resolves the config a policy accepts from the type of its module: the second parameter of its
27
+ * handler, for both runtime forms (a bare handler, or `{ handler, validator }`). A handler without
28
+ * a config parameter takes none: `undefined`, as in PackagePolicies. An untyped (`any`) config and a
29
+ * module without a default export resolve to `unknown`: one `any` entry would turn every policy
30
+ * reference into `any`.
31
+ * TODO @Nico a module without a default export registers nothing usable at runtime (resolving it
32
+ * throws); `unknown` accepts any reference to it, like an untyped policy
33
+ */ const generateConfigHelpersDefinition = ()=>{
34
+ const args = factory.createTypeReferenceNode('TArgs');
35
+ const configArg = factory.createIndexedAccessTypeNode(args, factory.createLiteralTypeNode(factory.createNumericLiteral(1)));
36
+ const handlerConfig = factory.createConditionalTypeNode(factory.createTypeReferenceNode('THandler'), factory.createFunctionTypeNode(undefined, [
37
+ factory.createParameterDeclaration(undefined, factory.createToken(ts.SyntaxKind.DotDotDotToken), 'args', undefined, factory.createInferTypeNode(factory.createTypeParameterDeclaration(undefined, 'TArgs')))
38
+ ], factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)), factory.createConditionalTypeNode(factory.createIndexedAccessTypeNode(args, factory.createLiteralTypeNode(factory.createStringLiteral('length', true))), factory.createUnionTypeNode([
39
+ factory.createLiteralTypeNode(factory.createNumericLiteral(0)),
40
+ factory.createLiteralTypeNode(factory.createNumericLiteral(1))
41
+ ]), factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword), // 0 extends 1 & TArgs[1], true only when the config is `any`
42
+ factory.createConditionalTypeNode(factory.createLiteralTypeNode(factory.createNumericLiteral(0)), factory.createIntersectionTypeNode([
43
+ factory.createLiteralTypeNode(factory.createNumericLiteral(1)),
44
+ configArg
45
+ ]), factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword), configArg)), factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword));
46
+ const unwrapHandler = factory.createConditionalTypeNode(factory.createTypeReferenceNode('TExport'), factory.createTypeLiteralNode([
47
+ factory.createPropertySignature(undefined, 'handler', undefined, factory.createInferTypeNode(factory.createTypeParameterDeclaration(undefined, 'THandler')))
48
+ ]), factory.createTypeReferenceNode('THandler'), factory.createTypeReferenceNode('TExport'));
49
+ const moduleConfig = factory.createConditionalTypeNode(factory.createTypeReferenceNode('TModule'), factory.createTypeLiteralNode([
50
+ factory.createPropertySignature(undefined, 'default', undefined, factory.createInferTypeNode(factory.createTypeParameterDeclaration(undefined, 'TExport')))
51
+ ]), factory.createTypeReferenceNode(HANDLER_CONFIG_HELPER, [
52
+ unwrapHandler
53
+ ]), factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword));
54
+ return [
55
+ withDocComment(factory.createTypeAliasDeclaration(undefined, factory.createIdentifier(HANDLER_CONFIG_HELPER), [
56
+ factory.createTypeParameterDeclaration(undefined, 'THandler')
57
+ ], handlerConfig), '*\n * Config a policy handler accepts: its second parameter, `undefined` when it has none, `unknown`\n * when it is untyped.\n '),
58
+ withDocComment(factory.createTypeAliasDeclaration(undefined, factory.createIdentifier(CONFIG_HELPER), [
59
+ factory.createTypeParameterDeclaration(undefined, 'TModule')
60
+ ], moduleConfig), '*\n * Config accepted by the policy a policy module exports, as a bare handler or as\n * `{ handler, validator }`.\n ')
61
+ ];
62
+ };
63
+ /**
64
+ * Generate type definitions for the application's policies (global::* and api::*)
65
+ *
66
+ * Policies are typed from their source file, so only the ones with a source in src/policies or
67
+ * src/api are emitted. Plugin and admin policies are left to the packages themselves
68
+ * (Strapi.Registries.PackagePolicies), so registering application policies keeps them accepted.
69
+ *
70
+ * declare global {
71
+ * namespace Strapi {
72
+ * namespace Registries {
73
+ * interface AppPolicies {
74
+ * 'global::<policy>': PolicyConfig<typeof import('<relative path to the source>')>;
75
+ * 'api::<api>.<policy>': PolicyConfig<typeof import('<relative path to the source>')>;
76
+ * 'global::<js policy>': unknown;
77
+ * }
78
+ * }
79
+ * }
80
+ * }
81
+ *
82
+ * The import of a JS policy is an error type without `allowJs`, and one such entry turns every policy
83
+ * reference into `any`. JS policies are registered as `unknown` without an import.
84
+ * TODO @Nico with `allowJs`, a JSDoc-typed JS policy could register its config like a TS one
85
+ */ const generatePoliciesDefinitions = async (options = {})=>{
86
+ const { strapi, logger, pwd: outDir } = options;
87
+ if (!outDir) {
88
+ throw new Error('The policies generator needs the output directory to resolve source imports');
89
+ }
90
+ const sources = await collectAppSources('policies', {
91
+ global: strapi.dirs.app.policies,
92
+ api: strapi.dirs.app.api
93
+ }, outDir, logger);
94
+ const policiesDefinitions = filterRegisteredSources(sources, strapi.policies, logger);
95
+ logger.debug(`Found ${policiesDefinitions.length} policies.`);
96
+ if (policiesDefinitions.length === 0) {
97
+ return {
98
+ output: NO_POLICY_PLACEHOLDER_COMMENT,
99
+ stats: {}
100
+ };
101
+ }
102
+ // The helpers are only emitted when an entry reads them: `noUnusedLocals` reports unused ones
103
+ const output = await emitRegistryDefinitions(REGISTRY, policiesDefinitions.some(isTypedSource) === true ? generateConfigHelpersDefinition() : [], policiesDefinitions, (source)=>isTypedSource(source) ? factory.createTypeReferenceNode(CONFIG_HELPER, [
104
+ typeofImport(source)
105
+ ]) : factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword));
106
+ return {
107
+ output,
108
+ stats: {}
109
+ };
110
+ };
111
+
112
+ export { generatePoliciesDefinitions };
113
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/generators/policies/index.ts"],"sourcesContent":["import * as ts from 'typescript';\n\nimport {\n collectAppSources,\n emitRegistryDefinitions,\n filterRegisteredSources,\n isTypedSource,\n typeofImport,\n withDocComment,\n} from '../common/sources';\nimport type { GeneratorOptions } from '../utils';\n\nconst { factory } = ts;\n\nconst REGISTRY = 'AppPolicies';\nconst CONFIG_HELPER = 'PolicyConfig';\nconst HANDLER_CONFIG_HELPER = 'PolicyHandlerConfig';\n\nconst NO_POLICY_PLACEHOLDER_COMMENT = `/*\n * The app doesn't have any policies yet.\n */\n\nexport {};\n`;\n\n/**\n * type PolicyHandlerConfig<THandler> = THandler extends (...args: infer TArgs) => unknown\n * ? TArgs['length'] extends 0 | 1 ? undefined : 0 extends 1 & TArgs[1] ? unknown : TArgs[1]\n * : unknown;\n *\n * type PolicyConfig<TModule> = TModule extends { default: infer TExport }\n * ? PolicyHandlerConfig<TExport extends { handler: infer THandler } ? THandler : TExport>\n * : unknown;\n *\n * Emitted in the file so that policies.ts stands alone, like the services and controllers helpers,\n * and only when a TypeScript policy reads them.\n *\n * Resolves the config a policy accepts from the type of its module: the second parameter of its\n * handler, for both runtime forms (a bare handler, or `{ handler, validator }`). A handler without\n * a config parameter takes none: `undefined`, as in PackagePolicies. An untyped (`any`) config and a\n * module without a default export resolve to `unknown`: one `any` entry would turn every policy\n * reference into `any`.\n * TODO @Nico a module without a default export registers nothing usable at runtime (resolving it\n * throws); `unknown` accepts any reference to it, like an untyped policy\n */\nconst generateConfigHelpersDefinition = () => {\n const args = factory.createTypeReferenceNode('TArgs');\n const configArg = factory.createIndexedAccessTypeNode(\n args,\n factory.createLiteralTypeNode(factory.createNumericLiteral(1))\n );\n\n const handlerConfig = factory.createConditionalTypeNode(\n factory.createTypeReferenceNode('THandler'),\n factory.createFunctionTypeNode(\n undefined,\n [\n factory.createParameterDeclaration(\n undefined,\n factory.createToken(ts.SyntaxKind.DotDotDotToken),\n 'args',\n undefined,\n factory.createInferTypeNode(factory.createTypeParameterDeclaration(undefined, 'TArgs'))\n ),\n ],\n factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)\n ),\n factory.createConditionalTypeNode(\n factory.createIndexedAccessTypeNode(\n args,\n factory.createLiteralTypeNode(factory.createStringLiteral('length', true))\n ),\n factory.createUnionTypeNode([\n factory.createLiteralTypeNode(factory.createNumericLiteral(0)),\n factory.createLiteralTypeNode(factory.createNumericLiteral(1)),\n ]),\n factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n // 0 extends 1 & TArgs[1], true only when the config is `any`\n factory.createConditionalTypeNode(\n factory.createLiteralTypeNode(factory.createNumericLiteral(0)),\n factory.createIntersectionTypeNode([\n factory.createLiteralTypeNode(factory.createNumericLiteral(1)),\n configArg,\n ]),\n factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),\n configArg\n )\n ),\n factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)\n );\n\n const unwrapHandler = factory.createConditionalTypeNode(\n factory.createTypeReferenceNode('TExport'),\n factory.createTypeLiteralNode([\n factory.createPropertySignature(\n undefined,\n 'handler',\n undefined,\n factory.createInferTypeNode(factory.createTypeParameterDeclaration(undefined, 'THandler'))\n ),\n ]),\n factory.createTypeReferenceNode('THandler'),\n factory.createTypeReferenceNode('TExport')\n );\n\n const moduleConfig = factory.createConditionalTypeNode(\n factory.createTypeReferenceNode('TModule'),\n factory.createTypeLiteralNode([\n factory.createPropertySignature(\n undefined,\n 'default',\n undefined,\n factory.createInferTypeNode(factory.createTypeParameterDeclaration(undefined, 'TExport'))\n ),\n ]),\n factory.createTypeReferenceNode(HANDLER_CONFIG_HELPER, [unwrapHandler]),\n factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)\n );\n\n return [\n withDocComment(\n factory.createTypeAliasDeclaration(\n undefined,\n factory.createIdentifier(HANDLER_CONFIG_HELPER),\n [factory.createTypeParameterDeclaration(undefined, 'THandler')],\n handlerConfig\n ),\n '*\\n * Config a policy handler accepts: its second parameter, `undefined` when it has none, `unknown`\\n * when it is untyped.\\n '\n ),\n withDocComment(\n factory.createTypeAliasDeclaration(\n undefined,\n factory.createIdentifier(CONFIG_HELPER),\n [factory.createTypeParameterDeclaration(undefined, 'TModule')],\n moduleConfig\n ),\n '*\\n * Config accepted by the policy a policy module exports, as a bare handler or as\\n * `{ handler, validator }`.\\n '\n ),\n ];\n};\n\n/**\n * Generate type definitions for the application's policies (global::* and api::*)\n *\n * Policies are typed from their source file, so only the ones with a source in src/policies or\n * src/api are emitted. Plugin and admin policies are left to the packages themselves\n * (Strapi.Registries.PackagePolicies), so registering application policies keeps them accepted.\n *\n * declare global {\n * namespace Strapi {\n * namespace Registries {\n * interface AppPolicies {\n * 'global::<policy>': PolicyConfig<typeof import('<relative path to the source>')>;\n * 'api::<api>.<policy>': PolicyConfig<typeof import('<relative path to the source>')>;\n * 'global::<js policy>': unknown;\n * }\n * }\n * }\n * }\n *\n * The import of a JS policy is an error type without `allowJs`, and one such entry turns every policy\n * reference into `any`. JS policies are registered as `unknown` without an import.\n * TODO @Nico with `allowJs`, a JSDoc-typed JS policy could register its config like a TS one\n */\nexport const generatePoliciesDefinitions = async (\n options: GeneratorOptions = {} as GeneratorOptions\n) => {\n const { strapi, logger, pwd: outDir } = options;\n\n if (!outDir) {\n throw new Error('The policies generator needs the output directory to resolve source imports');\n }\n\n const sources = await collectAppSources(\n 'policies',\n { global: strapi.dirs.app.policies, api: strapi.dirs.app.api },\n outDir,\n logger\n );\n const policiesDefinitions = filterRegisteredSources(sources, strapi.policies, logger);\n\n logger.debug(`Found ${policiesDefinitions.length} policies.`);\n\n if (policiesDefinitions.length === 0) {\n return { output: NO_POLICY_PLACEHOLDER_COMMENT, stats: {} };\n }\n\n // The helpers are only emitted when an entry reads them: `noUnusedLocals` reports unused ones\n const output = await emitRegistryDefinitions(\n REGISTRY,\n policiesDefinitions.some(isTypedSource) === true ? generateConfigHelpersDefinition() : [],\n policiesDefinitions,\n (source) =>\n isTypedSource(source)\n ? factory.createTypeReferenceNode(CONFIG_HELPER, [typeofImport(source)])\n : factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)\n );\n\n return { output, stats: {} };\n};\n"],"names":["factory","ts","REGISTRY","CONFIG_HELPER","HANDLER_CONFIG_HELPER","NO_POLICY_PLACEHOLDER_COMMENT","generateConfigHelpersDefinition","args","createTypeReferenceNode","configArg","createIndexedAccessTypeNode","createLiteralTypeNode","createNumericLiteral","handlerConfig","createConditionalTypeNode","createFunctionTypeNode","undefined","createParameterDeclaration","createToken","SyntaxKind","DotDotDotToken","createInferTypeNode","createTypeParameterDeclaration","createKeywordTypeNode","UnknownKeyword","createStringLiteral","createUnionTypeNode","UndefinedKeyword","createIntersectionTypeNode","unwrapHandler","createTypeLiteralNode","createPropertySignature","moduleConfig","withDocComment","createTypeAliasDeclaration","createIdentifier","generatePoliciesDefinitions","options","strapi","logger","pwd","outDir","Error","sources","collectAppSources","global","dirs","app","policies","api","policiesDefinitions","filterRegisteredSources","debug","length","output","stats","emitRegistryDefinitions","some","isTypedSource","source","typeofImport"],"mappings":";;;AAYA,MAAM,EAAEA,OAAO,EAAE,GAAGC,EAAAA;AAEpB,MAAMC,QAAAA,GAAW,aAAA;AACjB,MAAMC,aAAAA,GAAgB,cAAA;AACtB,MAAMC,qBAAAA,GAAwB,qBAAA;AAE9B,MAAMC,gCAAgC,CAAC;;;;;AAKvC,CAAC;AAED;;;;;;;;;;;;;;;;;;;AAmBC,IACD,MAAMC,+BAAAA,GAAkC,IAAA;IACtC,MAAMC,IAAAA,GAAOP,OAAAA,CAAQQ,uBAAuB,CAAC,OAAA,CAAA;IAC7C,MAAMC,SAAAA,GAAYT,OAAAA,CAAQU,2BAA2B,CACnDH,IAAAA,EACAP,QAAQW,qBAAqB,CAACX,OAAAA,CAAQY,oBAAoB,CAAC,CAAA,CAAA,CAAA,CAAA;IAG7D,MAAMC,aAAAA,GAAgBb,OAAAA,CAA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D,IAAA;;IAGA,MAAMD,MAAAA,GAAS,MAAME,uBAAAA,CACnBtD,QAAAA,EACAgD,oBAAoBO,IAAI,CAACC,mBAAmB,IAAA,GAAOpD,+BAAAA,EAAAA,GAAoC,EAAE,EACzF4C,mBAAAA,EACA,CAACS,MAAAA,GACCD,aAAAA,CAAcC,UACV3D,OAAAA,CAAQQ,uBAAuB,CAACL,aAAAA,EAAe;YAACyD,YAAAA,CAAaD,MAAAA;AAAQ,SAAA,CAAA,GACrE3D,QAAQuB,qBAAqB,CAACtB,EAAAA,CAAGkB,UAAU,CAACK,cAAc,CAAA,CAAA;IAGlE,OAAO;AAAE8B,QAAAA,MAAAA;AAAQC,QAAAA,KAAAA,EAAO;AAAG,KAAA;AAC7B;;;;"}
@@ -0,0 +1,35 @@
1
+ import type { GeneratorOptions } from '../utils';
2
+ /**
3
+ * Generate type definitions for the application's services (api::*)
4
+ *
5
+ * Services are typed from their source file, so only the ones with a source in src/api are emitted.
6
+ * Plugin and admin services are left to the packages themselves (Strapi.Registries.PackageServices).
7
+ *
8
+ * declare global {
9
+ * namespace Strapi {
10
+ * namespace Registries {
11
+ * interface AppServices {
12
+ * 'api::<api>.<service>': ServiceInstance<typeof import('<relative path to the source>')>;
13
+ * 'api::<api>.<service>': ServiceContractOf<import('<relative path to the source>').ServiceContract>;
14
+ * }
15
+ * interface InferredServices {
16
+ * 'api::<api>.<service>': true;
17
+ * }
18
+ * }
19
+ * }
20
+ * }
21
+ *
22
+ * A service whose module exports a `ServiceContract` type registers that contract; any other service
23
+ * registers the type its default export provides. A JS source registers as `unknown`: without
24
+ * `allowJs` its import is an error type. So do a service module, a default export and a contract
25
+ * typed `any`.
26
+ *
27
+ * `InferredServices` lists the TypeScript services registered without a contract, whose type is read
28
+ * from the factory itself: `Core.ServiceFactory` rejects their uid. It is not emitted when there are
29
+ * none.
30
+ */
31
+ export declare const generateServicesDefinitions: (options?: GeneratorOptions) => Promise<{
32
+ output: string;
33
+ stats: {};
34
+ }>;
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generators/services/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAejD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,2BAA2B,GACtC,UAAS,gBAAyC;;;EAyDnD,CAAC"}
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ var sources = require('../common/sources.js');
4
+
5
+ const REGISTRY = 'AppServices';
6
+ const INSTANCE_HELPER = 'ServiceInstance';
7
+ const CONTRACT_EXPORT = 'ServiceContract';
8
+ const CONTRACT_HELPER = 'ServiceContractOf';
9
+ const INFERRED_REGISTRY = 'InferredServices';
10
+ const NO_SERVICE_PLACEHOLDER_COMMENT = `/*
11
+ * The app doesn't have any services yet.
12
+ */
13
+
14
+ export {};
15
+ `;
16
+ /**
17
+ * Generate type definitions for the application's services (api::*)
18
+ *
19
+ * Services are typed from their source file, so only the ones with a source in src/api are emitted.
20
+ * Plugin and admin services are left to the packages themselves (Strapi.Registries.PackageServices).
21
+ *
22
+ * declare global {
23
+ * namespace Strapi {
24
+ * namespace Registries {
25
+ * interface AppServices {
26
+ * 'api::<api>.<service>': ServiceInstance<typeof import('<relative path to the source>')>;
27
+ * 'api::<api>.<service>': ServiceContractOf<import('<relative path to the source>').ServiceContract>;
28
+ * }
29
+ * interface InferredServices {
30
+ * 'api::<api>.<service>': true;
31
+ * }
32
+ * }
33
+ * }
34
+ * }
35
+ *
36
+ * A service whose module exports a `ServiceContract` type registers that contract; any other service
37
+ * registers the type its default export provides. A JS source registers as `unknown`: without
38
+ * `allowJs` its import is an error type. So do a service module, a default export and a contract
39
+ * typed `any`.
40
+ *
41
+ * `InferredServices` lists the TypeScript services registered without a contract, whose type is read
42
+ * from the factory itself: `Core.ServiceFactory` rejects their uid. It is not emitted when there are
43
+ * none.
44
+ */ const generateServicesDefinitions = async (options = {})=>{
45
+ const { strapi, logger, pwd: outDir } = options;
46
+ if (!outDir) {
47
+ throw new Error('The services generator needs the output directory to resolve source imports');
48
+ }
49
+ const sources$1 = await sources.collectAppSources('services', {
50
+ api: strapi.dirs.app.api
51
+ }, outDir, logger);
52
+ const servicesDefinitions = sources.filterRegisteredSources(sources$1, strapi.services, logger);
53
+ logger.debug(`Found ${servicesDefinitions.length} services.`);
54
+ const contract = {
55
+ exportName: CONTRACT_EXPORT,
56
+ helper: CONTRACT_HELPER,
57
+ uids: await sources.findTypeExports(servicesDefinitions, CONTRACT_EXPORT, logger)
58
+ };
59
+ if (servicesDefinitions.length === 0) {
60
+ return {
61
+ output: NO_SERVICE_PLACEHOLDER_COMMENT,
62
+ stats: {}
63
+ };
64
+ }
65
+ const inferredUIDs = servicesDefinitions.filter(sources.isInferredSource(contract)).map(({ uid })=>uid);
66
+ // Each helper is only emitted when an entry reads it: `noUnusedLocals` reports an unused one
67
+ const output = await sources.emitRegistryDefinitions(REGISTRY, [
68
+ ...inferredUIDs.length > 0 ? [
69
+ sources.generateInstanceHelperDefinition(INSTANCE_HELPER, '*\n * Type of the service instance exposed by a service module: the return type of its default\n * export when it is a factory, the default export itself otherwise.\n ')
70
+ ] : [],
71
+ ...contract.uids.size > 0 ? [
72
+ sources.generateContractHelperDefinition(CONTRACT_HELPER, '*\n * Contract a service module exports as `ServiceContract`, `unknown` when it is typed `any`.\n ')
73
+ ] : []
74
+ ], servicesDefinitions, sources.instanceTypeOf(INSTANCE_HELPER, logger, contract), [
75
+ {
76
+ registry: INFERRED_REGISTRY,
77
+ uids: inferredUIDs
78
+ }
79
+ ]);
80
+ return {
81
+ output,
82
+ stats: {}
83
+ };
84
+ };
85
+
86
+ exports.generateServicesDefinitions = generateServicesDefinitions;
87
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/generators/services/index.ts"],"sourcesContent":["import {\n collectAppSources,\n emitRegistryDefinitions,\n filterRegisteredSources,\n findTypeExports,\n generateContractHelperDefinition,\n generateInstanceHelperDefinition,\n instanceTypeOf,\n isInferredSource,\n} from '../common/sources';\nimport type { GeneratorOptions } from '../utils';\n\nconst REGISTRY = 'AppServices';\nconst INSTANCE_HELPER = 'ServiceInstance';\nconst CONTRACT_EXPORT = 'ServiceContract';\nconst CONTRACT_HELPER = 'ServiceContractOf';\nconst INFERRED_REGISTRY = 'InferredServices';\n\nconst NO_SERVICE_PLACEHOLDER_COMMENT = `/*\n * The app doesn't have any services yet.\n */\n\nexport {};\n`;\n\n/**\n * Generate type definitions for the application's services (api::*)\n *\n * Services are typed from their source file, so only the ones with a source in src/api are emitted.\n * Plugin and admin services are left to the packages themselves (Strapi.Registries.PackageServices).\n *\n * declare global {\n * namespace Strapi {\n * namespace Registries {\n * interface AppServices {\n * 'api::<api>.<service>': ServiceInstance<typeof import('<relative path to the source>')>;\n * 'api::<api>.<service>': ServiceContractOf<import('<relative path to the source>').ServiceContract>;\n * }\n * interface InferredServices {\n * 'api::<api>.<service>': true;\n * }\n * }\n * }\n * }\n *\n * A service whose module exports a `ServiceContract` type registers that contract; any other service\n * registers the type its default export provides. A JS source registers as `unknown`: without\n * `allowJs` its import is an error type. So do a service module, a default export and a contract\n * typed `any`.\n *\n * `InferredServices` lists the TypeScript services registered without a contract, whose type is read\n * from the factory itself: `Core.ServiceFactory` rejects their uid. It is not emitted when there are\n * none.\n */\nexport const generateServicesDefinitions = async (\n options: GeneratorOptions = {} as GeneratorOptions\n) => {\n const { strapi, logger, pwd: outDir } = options;\n\n if (!outDir) {\n throw new Error('The services generator needs the output directory to resolve source imports');\n }\n\n const sources = await collectAppSources('services', { api: strapi.dirs.app.api }, outDir, logger);\n const servicesDefinitions = filterRegisteredSources(sources, strapi.services, logger);\n\n logger.debug(`Found ${servicesDefinitions.length} services.`);\n\n const contract = {\n exportName: CONTRACT_EXPORT,\n helper: CONTRACT_HELPER,\n uids: await findTypeExports(servicesDefinitions, CONTRACT_EXPORT, logger),\n };\n\n if (servicesDefinitions.length === 0) {\n return { output: NO_SERVICE_PLACEHOLDER_COMMENT, stats: {} };\n }\n\n const inferredUIDs = servicesDefinitions.filter(isInferredSource(contract)).map(({ uid }) => uid);\n\n // Each helper is only emitted when an entry reads it: `noUnusedLocals` reports an unused one\n const output = await emitRegistryDefinitions(\n REGISTRY,\n [\n ...(inferredUIDs.length > 0\n ? [\n generateInstanceHelperDefinition(\n INSTANCE_HELPER,\n '*\\n * Type of the service instance exposed by a service module: the return type of its default\\n * export when it is a factory, the default export itself otherwise.\\n '\n ),\n ]\n : []),\n ...(contract.uids.size > 0\n ? [\n generateContractHelperDefinition(\n CONTRACT_HELPER,\n '*\\n * Contract a service module exports as `ServiceContract`, `unknown` when it is typed `any`.\\n '\n ),\n ]\n : []),\n ],\n servicesDefinitions,\n instanceTypeOf(INSTANCE_HELPER, logger, contract),\n [\n {\n registry: INFERRED_REGISTRY,\n uids: inferredUIDs,\n },\n ]\n );\n\n return { output, stats: {} };\n};\n"],"names":["REGISTRY","INSTANCE_HELPER","CONTRACT_EXPORT","CONTRACT_HELPER","INFERRED_REGISTRY","NO_SERVICE_PLACEHOLDER_COMMENT","generateServicesDefinitions","options","strapi","logger","pwd","outDir","Error","sources","collectAppSources","api","dirs","app","servicesDefinitions","filterRegisteredSources","services","debug","length","contract","exportName","helper","uids","findTypeExports","output","stats","inferredUIDs","filter","isInferredSource","map","uid","emitRegistryDefinitions","generateInstanceHelperDefinition","size","generateContractHelperDefinition","instanceTypeOf","registry"],"mappings":";;;;AAYA,MAAMA,QAAAA,GAAW,aAAA;AACjB,MAAMC,eAAAA,GAAkB,iBAAA;AACxB,MAAMC,eAAAA,GAAkB,iBAAA;AACxB,MAAMC,eAAAA,GAAkB,mBAAA;AACxB,MAAMC,iBAAAA,GAAoB,kBAAA;AAE1B,MAAMC,iCAAiC,CAAC;;;;;AAKxC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;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B,YAAAA,CAAaR,MAAM,GAAG,CAAA,GACtB;AACEc,YAAAA,wCAAAA,CACEnC,eAAAA,EACA,yKAAA;AAEH,SAAA,GACD,EAAE;AACFsB,QAAAA,GAAAA,QAAAA,CAASG,IAAI,CAACW,IAAI,GAAG,CAAA,GACrB;AACEC,YAAAA,wCAAAA,CACEnC,eAAAA,EACA,oGAAA;AAEH,SAAA,GACD;AACL,KAAA,EACDe,mBAAAA,EACAqB,sBAAAA,CAAetC,eAAAA,EAAiBQ,MAAAA,EAAQc,QAAAA,CAAAA,EACxC;AACE,QAAA;YACEiB,QAAAA,EAAUpC,iBAAAA;YACVsB,IAAAA,EAAMI;AACR;AACD,KAAA,CAAA;IAGH,OAAO;AAAEF,QAAAA,MAAAA;AAAQC,QAAAA,KAAAA,EAAO;AAAG,KAAA;AAC7B;;;;"}
@@ -0,0 +1,85 @@
1
+ import { collectAppSources, filterRegisteredSources, findTypeExports, isInferredSource, emitRegistryDefinitions, generateInstanceHelperDefinition, generateContractHelperDefinition, instanceTypeOf } from '../common/sources.mjs';
2
+
3
+ const REGISTRY = 'AppServices';
4
+ const INSTANCE_HELPER = 'ServiceInstance';
5
+ const CONTRACT_EXPORT = 'ServiceContract';
6
+ const CONTRACT_HELPER = 'ServiceContractOf';
7
+ const INFERRED_REGISTRY = 'InferredServices';
8
+ const NO_SERVICE_PLACEHOLDER_COMMENT = `/*
9
+ * The app doesn't have any services yet.
10
+ */
11
+
12
+ export {};
13
+ `;
14
+ /**
15
+ * Generate type definitions for the application's services (api::*)
16
+ *
17
+ * Services are typed from their source file, so only the ones with a source in src/api are emitted.
18
+ * Plugin and admin services are left to the packages themselves (Strapi.Registries.PackageServices).
19
+ *
20
+ * declare global {
21
+ * namespace Strapi {
22
+ * namespace Registries {
23
+ * interface AppServices {
24
+ * 'api::<api>.<service>': ServiceInstance<typeof import('<relative path to the source>')>;
25
+ * 'api::<api>.<service>': ServiceContractOf<import('<relative path to the source>').ServiceContract>;
26
+ * }
27
+ * interface InferredServices {
28
+ * 'api::<api>.<service>': true;
29
+ * }
30
+ * }
31
+ * }
32
+ * }
33
+ *
34
+ * A service whose module exports a `ServiceContract` type registers that contract; any other service
35
+ * registers the type its default export provides. A JS source registers as `unknown`: without
36
+ * `allowJs` its import is an error type. So do a service module, a default export and a contract
37
+ * typed `any`.
38
+ *
39
+ * `InferredServices` lists the TypeScript services registered without a contract, whose type is read
40
+ * from the factory itself: `Core.ServiceFactory` rejects their uid. It is not emitted when there are
41
+ * none.
42
+ */ const generateServicesDefinitions = async (options = {})=>{
43
+ const { strapi, logger, pwd: outDir } = options;
44
+ if (!outDir) {
45
+ throw new Error('The services generator needs the output directory to resolve source imports');
46
+ }
47
+ const sources = await collectAppSources('services', {
48
+ api: strapi.dirs.app.api
49
+ }, outDir, logger);
50
+ const servicesDefinitions = filterRegisteredSources(sources, strapi.services, logger);
51
+ logger.debug(`Found ${servicesDefinitions.length} services.`);
52
+ const contract = {
53
+ exportName: CONTRACT_EXPORT,
54
+ helper: CONTRACT_HELPER,
55
+ uids: await findTypeExports(servicesDefinitions, CONTRACT_EXPORT, logger)
56
+ };
57
+ if (servicesDefinitions.length === 0) {
58
+ return {
59
+ output: NO_SERVICE_PLACEHOLDER_COMMENT,
60
+ stats: {}
61
+ };
62
+ }
63
+ const inferredUIDs = servicesDefinitions.filter(isInferredSource(contract)).map(({ uid })=>uid);
64
+ // Each helper is only emitted when an entry reads it: `noUnusedLocals` reports an unused one
65
+ const output = await emitRegistryDefinitions(REGISTRY, [
66
+ ...inferredUIDs.length > 0 ? [
67
+ generateInstanceHelperDefinition(INSTANCE_HELPER, '*\n * Type of the service instance exposed by a service module: the return type of its default\n * export when it is a factory, the default export itself otherwise.\n ')
68
+ ] : [],
69
+ ...contract.uids.size > 0 ? [
70
+ generateContractHelperDefinition(CONTRACT_HELPER, '*\n * Contract a service module exports as `ServiceContract`, `unknown` when it is typed `any`.\n ')
71
+ ] : []
72
+ ], servicesDefinitions, instanceTypeOf(INSTANCE_HELPER, logger, contract), [
73
+ {
74
+ registry: INFERRED_REGISTRY,
75
+ uids: inferredUIDs
76
+ }
77
+ ]);
78
+ return {
79
+ output,
80
+ stats: {}
81
+ };
82
+ };
83
+
84
+ export { generateServicesDefinitions };
85
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/generators/services/index.ts"],"sourcesContent":["import {\n collectAppSources,\n emitRegistryDefinitions,\n filterRegisteredSources,\n findTypeExports,\n generateContractHelperDefinition,\n generateInstanceHelperDefinition,\n instanceTypeOf,\n isInferredSource,\n} from '../common/sources';\nimport type { GeneratorOptions } from '../utils';\n\nconst REGISTRY = 'AppServices';\nconst INSTANCE_HELPER = 'ServiceInstance';\nconst CONTRACT_EXPORT = 'ServiceContract';\nconst CONTRACT_HELPER = 'ServiceContractOf';\nconst INFERRED_REGISTRY = 'InferredServices';\n\nconst NO_SERVICE_PLACEHOLDER_COMMENT = `/*\n * The app doesn't have any services yet.\n */\n\nexport {};\n`;\n\n/**\n * Generate type definitions for the application's services (api::*)\n *\n * Services are typed from their source file, so only the ones with a source in src/api are emitted.\n * Plugin and admin services are left to the packages themselves (Strapi.Registries.PackageServices).\n *\n * declare global {\n * namespace Strapi {\n * namespace Registries {\n * interface AppServices {\n * 'api::<api>.<service>': ServiceInstance<typeof import('<relative path to the source>')>;\n * 'api::<api>.<service>': ServiceContractOf<import('<relative path to the source>').ServiceContract>;\n * }\n * interface InferredServices {\n * 'api::<api>.<service>': true;\n * }\n * }\n * }\n * }\n *\n * A service whose module exports a `ServiceContract` type registers that contract; any other service\n * registers the type its default export provides. A JS source registers as `unknown`: without\n * `allowJs` its import is an error type. So do a service module, a default export and a contract\n * typed `any`.\n *\n * `InferredServices` lists the TypeScript services registered without a contract, whose type is read\n * from the factory itself: `Core.ServiceFactory` rejects their uid. It is not emitted when there are\n * none.\n */\nexport const generateServicesDefinitions = async (\n options: GeneratorOptions = {} as GeneratorOptions\n) => {\n const { strapi, logger, pwd: outDir } = options;\n\n if (!outDir) {\n throw new Error('The services generator needs the output directory to resolve source imports');\n }\n\n const sources = await collectAppSources('services', { api: strapi.dirs.app.api }, outDir, logger);\n const servicesDefinitions = filterRegisteredSources(sources, strapi.services, logger);\n\n logger.debug(`Found ${servicesDefinitions.length} services.`);\n\n const contract = {\n exportName: CONTRACT_EXPORT,\n helper: CONTRACT_HELPER,\n uids: await findTypeExports(servicesDefinitions, CONTRACT_EXPORT, logger),\n };\n\n if (servicesDefinitions.length === 0) {\n return { output: NO_SERVICE_PLACEHOLDER_COMMENT, stats: {} };\n }\n\n const inferredUIDs = servicesDefinitions.filter(isInferredSource(contract)).map(({ uid }) => uid);\n\n // Each helper is only emitted when an entry reads it: `noUnusedLocals` reports an unused one\n const output = await emitRegistryDefinitions(\n REGISTRY,\n [\n ...(inferredUIDs.length > 0\n ? [\n generateInstanceHelperDefinition(\n INSTANCE_HELPER,\n '*\\n * Type of the service instance exposed by a service module: the return type of its default\\n * export when it is a factory, the default export itself otherwise.\\n '\n ),\n ]\n : []),\n ...(contract.uids.size > 0\n ? [\n generateContractHelperDefinition(\n CONTRACT_HELPER,\n '*\\n * Contract a service module exports as `ServiceContract`, `unknown` when it is typed `any`.\\n '\n ),\n ]\n : []),\n ],\n servicesDefinitions,\n instanceTypeOf(INSTANCE_HELPER, logger, contract),\n [\n {\n registry: INFERRED_REGISTRY,\n uids: inferredUIDs,\n },\n ]\n );\n\n return { output, stats: {} };\n};\n"],"names":["REGISTRY","INSTANCE_HELPER","CONTRACT_EXPORT","CONTRACT_HELPER","INFERRED_REGISTRY","NO_SERVICE_PLACEHOLDER_COMMENT","generateServicesDefinitions","options","strapi","logger","pwd","outDir","Error","sources","collectAppSources","api","dirs","app","servicesDefinitions","filterRegisteredSources","services","debug","length","contract","exportName","helper","uids","findTypeExports","output","stats","inferredUIDs","filter","isInferredSource","map","uid","emitRegistryDefinitions","generateInstanceHelperDefinition","size","generateContractHelperDefinition","instanceTypeOf","registry"],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AAAG,SAAA;AAC7D,IAAA;AAEA,IAAA,MAAMC,YAAAA,GAAeZ,mBAAAA,CAAoBa,MAAM,CAACC,gBAAAA,CAAiBT,QAAAA,CAAAA,CAAAA,CAAWU,GAAG,CAAC,CAAC,EAAEC,GAAG,EAAE,GAAKA,GAAAA,CAAAA;;IAG7F,MAAMN,MAAAA,GAAS,MAAMO,uBAAAA,CACnBnC,QAAAA,EACA;WACM8B,YAAAA,CAAaR,MAAM,GAAG,CAAA,GACtB;AACEc,YAAAA,gCAAAA,CACEnC,eAAAA,EACA,yKAAA;AAEH,SAAA,GACD,EAAE;AACFsB,QAAAA,GAAAA,QAAAA,CAASG,IAAI,CAACW,IAAI,GAAG,CAAA,GACrB;AACEC,YAAAA,gCAAAA,CACEnC,eAAAA,EACA,oGAAA;AAEH,SAAA,GACD;AACL,KAAA,EACDe,mBAAAA,EACAqB,cAAAA,CAAetC,eAAAA,EAAiBQ,MAAAA,EAAQc,QAAAA,CAAAA,EACxC;AACE,QAAA;YACEiB,QAAAA,EAAUpC,iBAAAA;YACVsB,IAAAA,EAAMI;AACR;AACD,KAAA,CAAA;IAGH,OAAO;AAAEF,QAAAA,MAAAA;AAAQC,QAAAA,KAAAA,EAAO;AAAG,KAAA;AAC7B;;;;"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Generate the opt-in to registered server contracts
3
+ *
4
+ * `@strapi/strapi/strict-types` enables strict lookups for the whole program and loads the contracts
5
+ * of the plugins bundled with Strapi; optional plugins are loaded by the `plugins` artifact. Going
6
+ * through `@strapi/strapi` keeps the application free of direct dependencies on the plugins, which
7
+ * it cannot resolve under a strict package manager layout.
8
+ */
9
+ export declare const generateStrictDefinitions: () => Promise<{
10
+ output: string;
11
+ stats: {};
12
+ }>;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generators/strict/index.ts"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB;;;EAErC,CAAC"}
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ const STRICT_OPT_IN = `/*
4
+ * Opts the application into registered server contracts
5
+ * Generated because \`typescript.strictTypes\` is enabled; disabling it removes this file.
6
+ */
7
+ import type {} from '@strapi/strapi/strict-types';
8
+ `;
9
+ /**
10
+ * Generate the opt-in to registered server contracts
11
+ *
12
+ * `@strapi/strapi/strict-types` enables strict lookups for the whole program and loads the contracts
13
+ * of the plugins bundled with Strapi; optional plugins are loaded by the `plugins` artifact. Going
14
+ * through `@strapi/strapi` keeps the application free of direct dependencies on the plugins, which
15
+ * it cannot resolve under a strict package manager layout.
16
+ */ const generateStrictDefinitions = async ()=>{
17
+ return {
18
+ output: STRICT_OPT_IN,
19
+ stats: {}
20
+ };
21
+ };
22
+
23
+ exports.generateStrictDefinitions = generateStrictDefinitions;
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/generators/strict/index.ts"],"sourcesContent":["const STRICT_OPT_IN = `/*\n * Opts the application into registered server contracts\n * Generated because \\`typescript.strictTypes\\` is enabled; disabling it removes this file.\n */\nimport type {} from '@strapi/strapi/strict-types';\n`;\n\n/**\n * Generate the opt-in to registered server contracts\n *\n * `@strapi/strapi/strict-types` enables strict lookups for the whole program and loads the contracts\n * of the plugins bundled with Strapi; optional plugins are loaded by the `plugins` artifact. Going\n * through `@strapi/strapi` keeps the application free of direct dependencies on the plugins, which\n * it cannot resolve under a strict package manager layout.\n */\nexport const generateStrictDefinitions = async () => {\n return { output: STRICT_OPT_IN, stats: {} };\n};\n"],"names":["STRICT_OPT_IN","generateStrictDefinitions","output","stats"],"mappings":";;AAAA,MAAMA,gBAAgB,CAAC;;;;;AAKvB,CAAC;AAED;;;;;;;UAQaC,yBAAAA,GAA4B,UAAA;IACvC,OAAO;QAAEC,MAAAA,EAAQF,aAAAA;AAAeG,QAAAA,KAAAA,EAAO;AAAG,KAAA;AAC5C;;;;"}
@@ -0,0 +1,22 @@
1
+ const STRICT_OPT_IN = `/*
2
+ * Opts the application into registered server contracts
3
+ * Generated because \`typescript.strictTypes\` is enabled; disabling it removes this file.
4
+ */
5
+ import type {} from '@strapi/strapi/strict-types';
6
+ `;
7
+ /**
8
+ * Generate the opt-in to registered server contracts
9
+ *
10
+ * `@strapi/strapi/strict-types` enables strict lookups for the whole program and loads the contracts
11
+ * of the plugins bundled with Strapi; optional plugins are loaded by the `plugins` artifact. Going
12
+ * through `@strapi/strapi` keeps the application free of direct dependencies on the plugins, which
13
+ * it cannot resolve under a strict package manager layout.
14
+ */ const generateStrictDefinitions = async ()=>{
15
+ return {
16
+ output: STRICT_OPT_IN,
17
+ stats: {}
18
+ };
19
+ };
20
+
21
+ export { generateStrictDefinitions };
22
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/generators/strict/index.ts"],"sourcesContent":["const STRICT_OPT_IN = `/*\n * Opts the application into registered server contracts\n * Generated because \\`typescript.strictTypes\\` is enabled; disabling it removes this file.\n */\nimport type {} from '@strapi/strapi/strict-types';\n`;\n\n/**\n * Generate the opt-in to registered server contracts\n *\n * `@strapi/strapi/strict-types` enables strict lookups for the whole program and loads the contracts\n * of the plugins bundled with Strapi; optional plugins are loaded by the `plugins` artifact. Going\n * through `@strapi/strapi` keeps the application free of direct dependencies on the plugins, which\n * it cannot resolve under a strict package manager layout.\n */\nexport const generateStrictDefinitions = async () => {\n return { output: STRICT_OPT_IN, stats: {} };\n};\n"],"names":["STRICT_OPT_IN","generateStrictDefinitions","output","stats"],"mappings":"AAAA,MAAMA,gBAAgB,CAAC;;;;;AAKvB,CAAC;AAED;;;;;;;UAQaC,yBAAAA,GAA4B,UAAA;IACvC,OAAO;QAAEC,MAAAA,EAAQF,aAAAA;AAAeG,QAAAA,KAAAA,EAAO;AAAG,KAAA;AAC5C;;;;"}