@pikku/cli 0.9.7 → 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @pikku/cli
2
2
 
3
+ ## 0.9.8
4
+
5
+ ### Patch Changes
6
+
7
+ - ea89575: feat: adding the ability for custom schema validation / retrieving schemas to use (for example with openapi json_response)
8
+ - Updated dependencies [ea89575]
9
+ - @pikku/core@0.9.8
10
+
3
11
  ## 0.9.7
4
12
 
5
13
  ### Patch Changes
package/cli.schema.json CHANGED
@@ -269,10 +269,13 @@
269
269
  "rootDir": {
270
270
  "type": "string"
271
271
  },
272
- "rpcMapDeclarationFile": {
272
+ "rpcInternalMapDeclarationFile": {
273
273
  "type": "string"
274
274
  },
275
- "rpcWiringMetaFile": {
275
+ "rpcInternalWiringMetaFile": {
276
+ "type": "string"
277
+ },
278
+ "rpcMapDeclarationFile": {
276
279
  "type": "string"
277
280
  },
278
281
  "rpcWiringsFile": {
@@ -287,6 +290,12 @@
287
290
  "schemaDirectory": {
288
291
  "type": "string"
289
292
  },
293
+ "schemasFromTypes": {
294
+ "items": {
295
+ "type": "string"
296
+ },
297
+ "type": "array"
298
+ },
290
299
  "servicesFile": {
291
300
  "type": "string"
292
301
  },
@@ -330,8 +339,9 @@
330
339
  "queueWorkersWiringFile",
331
340
  "queueWorkersWiringMetaFile",
332
341
  "rootDir",
342
+ "rpcInternalMapDeclarationFile",
343
+ "rpcInternalWiringMetaFile",
333
344
  "rpcMapDeclarationFile",
334
- "rpcWiringMetaFile",
335
345
  "schedulersWiringFile",
336
346
  "schedulersWiringMetaFile",
337
347
  "schemaDirectory",
@@ -49,6 +49,7 @@ export type PikkuCLIConfig = {
49
49
  additionalInfo: OpenAPISpecInfo;
50
50
  };
51
51
  middlewareServices?: string[];
52
+ schemasFromTypes?: string[];
52
53
  filters: InspectorFilters;
53
54
  } & PikkuCLICoreOutputFiles;
54
55
  export declare const getPikkuCLIConfig: (configFile: string | undefined, requiredFields: Array<keyof PikkuCLIConfig>, filters?: InspectorFilters, exitProcess?: boolean) => Promise<PikkuCLIConfig>;
@@ -1,8 +1,8 @@
1
1
  import { generateSchemas, saveSchemas } from './schema-generator.js';
2
2
  import { logCommandInfoAndTime } from './utils.js';
3
- export const pikkuSchemas = async (logger, { tsconfig, schemaDirectory, supportsImportAttributes }, { functions, http }) => {
3
+ export const pikkuSchemas = async (logger, { tsconfig, schemaDirectory, supportsImportAttributes, schemasFromTypes }, { functions, http }) => {
4
4
  return await logCommandInfoAndTime(logger, 'Creating schemas', 'Created schemas', [false], async () => {
5
- const schemas = await generateSchemas(logger, tsconfig, functions.typesMap, functions.meta, http.meta);
6
- await saveSchemas(logger, schemaDirectory, schemas, functions.typesMap, functions.meta, supportsImportAttributes);
5
+ const schemas = await generateSchemas(logger, tsconfig, functions.typesMap, functions.meta, http.meta, schemasFromTypes);
6
+ await saveSchemas(logger, schemaDirectory, schemas, functions.typesMap, functions.meta, supportsImportAttributes, schemasFromTypes);
7
7
  });
8
8
  };
@@ -2,5 +2,5 @@ import { CLILogger } from './utils.js';
2
2
  import { FunctionsMeta, JSONValue } from '@pikku/core';
3
3
  import { HTTPWiringsMeta } from '@pikku/core/http';
4
4
  import { TypesMap } from '@pikku/inspector';
5
- export declare function generateSchemas(logger: CLILogger, tsconfig: string, typesMap: TypesMap, functionMeta: FunctionsMeta, httpWiringsMeta: HTTPWiringsMeta): Promise<Record<string, JSONValue>>;
6
- export declare function saveSchemas(logger: CLILogger, schemaParentDir: string, schemas: Record<string, JSONValue>, typesMap: TypesMap, functionsMeta: FunctionsMeta, supportsImportAttributes: boolean): Promise<void>;
5
+ export declare function generateSchemas(logger: CLILogger, tsconfig: string, typesMap: TypesMap, functionMeta: FunctionsMeta, httpWiringsMeta: HTTPWiringsMeta, additionalTypes?: string[]): Promise<Record<string, JSONValue>>;
6
+ export declare function saveSchemas(logger: CLILogger, schemaParentDir: string, schemas: Record<string, JSONValue>, typesMap: TypesMap, functionsMeta: FunctionsMeta, supportsImportAttributes: boolean, additionalTypes?: string[]): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import { createGenerator, RootlessError } from 'ts-json-schema-generator';
2
2
  import { writeFileInDir } from './utils.js';
3
3
  import { mkdir, writeFile } from 'fs/promises';
4
- export async function generateSchemas(logger, tsconfig, typesMap, functionMeta, httpWiringsMeta) {
4
+ export async function generateSchemas(logger, tsconfig, typesMap, functionMeta, httpWiringsMeta, additionalTypes) {
5
5
  const schemasSet = new Set(typesMap.customTypes.keys());
6
6
  for (const { inputs, outputs } of Object.values(functionMeta)) {
7
7
  const types = [...(inputs || []), ...(outputs || [])];
@@ -25,6 +25,12 @@ export async function generateSchemas(logger, tsconfig, typesMap, functionMeta,
25
25
  }
26
26
  }
27
27
  }
28
+ // Add additional types from schemasFromTypes config
29
+ if (additionalTypes) {
30
+ for (const type of additionalTypes) {
31
+ schemasSet.add(type);
32
+ }
33
+ }
28
34
  const generator = createGenerator({
29
35
  tsconfig,
30
36
  skipTypeCheck: true,
@@ -53,7 +59,7 @@ export async function generateSchemas(logger, tsconfig, typesMap, functionMeta,
53
59
  });
54
60
  return schemas;
55
61
  }
56
- export async function saveSchemas(logger, schemaParentDir, schemas, typesMap, functionsMeta, supportsImportAttributes) {
62
+ export async function saveSchemas(logger, schemaParentDir, schemas, typesMap, functionsMeta, supportsImportAttributes, additionalTypes) {
57
63
  await writeFileInDir(logger, `${schemaParentDir}/register.gen.ts`, 'export const empty = null;');
58
64
  const desiredSchemas = new Set([
59
65
  ...Object.values(functionsMeta)
@@ -65,6 +71,7 @@ export async function saveSchemas(logger, schemaParentDir, schemas, typesMap, fu
65
71
  .filter((s) => !!s &&
66
72
  !['boolean', 'string', 'number', 'null', 'undefined'].includes(s)),
67
73
  ...typesMap.customTypes.keys(),
74
+ ...(additionalTypes || []),
68
75
  ]);
69
76
  if (desiredSchemas.size === 0) {
70
77
  logger.info(`• Skipping schemas since none found.\x1b[0m`);
@@ -76,7 +83,9 @@ export async function saveSchemas(logger, schemaParentDir, schemas, typesMap, fu
76
83
  await writeFile(`${schemaParentDir}/schemas/${schemaName}.schema.json`, JSON.stringify(schema), 'utf-8');
77
84
  }
78
85
  }));
79
- const schemaImports = Array.from(desiredSchemas)
86
+ // Only include schemas that were successfully generated
87
+ const availableSchemas = Array.from(desiredSchemas).filter((schema) => schemas[schema]);
88
+ const schemaImports = availableSchemas
80
89
  .map((schema) => `
81
90
  import * as ${schema} from './schemas/${schema}.schema.json' ${supportsImportAttributes ? `with { type: 'json' }` : ''}
82
91
  addSchema('${schema}', ${schema})
@@ -1,8 +1,8 @@
1
1
  import { saveSchemas, generateSchemas } from './schema-generator.js';
2
2
  import { logCommandInfoAndTime } from './utils.js';
3
- export const pikkuSchemas = async (logger, { tsconfig, schemaDirectory, supportsImportAttributes }, { functions, http }) => {
3
+ export const pikkuSchemas = async (logger, { tsconfig, schemaDirectory, supportsImportAttributes, schemasFromTypes }, { functions, http }) => {
4
4
  return await logCommandInfoAndTime(logger, 'Creating schemas', 'Created schemas', [false], async () => {
5
- const schemas = await generateSchemas(logger, tsconfig, functions.typesMap, functions.meta, http.meta);
6
- await saveSchemas(logger, schemaDirectory, schemas, functions.typesMap, functions.meta, supportsImportAttributes);
5
+ const schemas = await generateSchemas(logger, tsconfig, functions.typesMap, functions.meta, http.meta, schemasFromTypes);
6
+ await saveSchemas(logger, schemaDirectory, schemas, functions.typesMap, functions.meta, supportsImportAttributes, schemasFromTypes);
7
7
  });
8
8
  };
@@ -2,12 +2,12 @@ import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
2
2
  import { generateSchemas } from '../../schema-generator.js';
3
3
  import { generateOpenAPISpec } from './openapi-spec-generator.js';
4
4
  import { stringify } from 'yaml';
5
- export const pikkuOpenAPI = async (logger, { tsconfig, openAPI }, { http, functions }) => {
5
+ export const pikkuOpenAPI = async (logger, { tsconfig, openAPI, schemasFromTypes }, { http, functions }) => {
6
6
  return await logCommandInfoAndTime(logger, 'Creating OpenAPI spec', 'Created OpenAPI spec', [openAPI?.outputFile === undefined, 'openAPI outfile is not defined'], async () => {
7
7
  if (!openAPI?.outputFile) {
8
8
  throw new Error('openAPI is required');
9
9
  }
10
- const schemas = await generateSchemas(logger, tsconfig, functions.typesMap, functions.meta, http.meta);
10
+ const schemas = await generateSchemas(logger, tsconfig, functions.typesMap, functions.meta, http.meta, schemasFromTypes);
11
11
  const openAPISpec = await generateOpenAPISpec(functions.meta, http.meta, schemas, openAPI.additionalInfo);
12
12
  if (openAPI.outputFile.endsWith('.json')) {
13
13
  await writeFileInDir(logger, openAPI.outputFile, JSON.stringify(openAPISpec, null, 2), { ignoreModifyComment: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/cli",
3
- "version": "0.9.7",
3
+ "version": "0.9.8",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@openapi-contrib/json-schema-to-openapi-schema": "^4.0.2",
25
- "@pikku/core": "^0.9.6",
25
+ "@pikku/core": "^0.9.8",
26
26
  "@pikku/inspector": "^0.9.4",
27
27
  "@types/cookie": "^1.0.0",
28
28
  "@types/uuid": "^10.0.0",
package/run-tests.sh CHANGED
@@ -46,7 +46,7 @@ if [ "$watch_mode" = true ]; then
46
46
  fi
47
47
 
48
48
  if [ "$coverage_mode" = true ]; then
49
- node_cmd="$node_cmd --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info"
49
+ node_cmd="$node_cmd --test-coverage-include=\"src/**/*.{ts,js}\" --test-coverage-exclude=\"**/dist/**\" --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info"
50
50
  fi
51
51
 
52
52
  # Execute the node command with the expanded list of files
@@ -83,6 +83,8 @@ export type PikkuCLIConfig = {
83
83
 
84
84
  middlewareServices?: string[]
85
85
 
86
+ schemasFromTypes?: string[]
87
+
86
88
  filters: InspectorFilters
87
89
  } & PikkuCLICoreOutputFiles
88
90
 
@@ -4,7 +4,7 @@ import { PikkuCommand } from './types.js'
4
4
 
5
5
  export const pikkuSchemas: PikkuCommand = async (
6
6
  logger,
7
- { tsconfig, schemaDirectory, supportsImportAttributes },
7
+ { tsconfig, schemaDirectory, supportsImportAttributes, schemasFromTypes },
8
8
  { functions, http }
9
9
  ) => {
10
10
  return await logCommandInfoAndTime(
@@ -18,7 +18,8 @@ export const pikkuSchemas: PikkuCommand = async (
18
18
  tsconfig,
19
19
  functions.typesMap,
20
20
  functions.meta,
21
- http.meta
21
+ http.meta,
22
+ schemasFromTypes
22
23
  )
23
24
  await saveSchemas(
24
25
  logger,
@@ -26,7 +27,8 @@ export const pikkuSchemas: PikkuCommand = async (
26
27
  schemas,
27
28
  functions.typesMap,
28
29
  functions.meta,
29
- supportsImportAttributes
30
+ supportsImportAttributes,
31
+ schemasFromTypes
30
32
  )
31
33
  }
32
34
  )
@@ -10,7 +10,8 @@ export async function generateSchemas(
10
10
  tsconfig: string,
11
11
  typesMap: TypesMap,
12
12
  functionMeta: FunctionsMeta,
13
- httpWiringsMeta: HTTPWiringsMeta
13
+ httpWiringsMeta: HTTPWiringsMeta,
14
+ additionalTypes?: string[]
14
15
  ): Promise<Record<string, JSONValue>> {
15
16
  const schemasSet = new Set(typesMap.customTypes.keys())
16
17
  for (const { inputs, outputs } of Object.values(functionMeta)) {
@@ -37,6 +38,13 @@ export async function generateSchemas(
37
38
  }
38
39
  }
39
40
 
41
+ // Add additional types from schemasFromTypes config
42
+ if (additionalTypes) {
43
+ for (const type of additionalTypes) {
44
+ schemasSet.add(type)
45
+ }
46
+ }
47
+
40
48
  const generator = createGenerator({
41
49
  tsconfig,
42
50
  skipTypeCheck: true,
@@ -72,7 +80,8 @@ export async function saveSchemas(
72
80
  schemas: Record<string, JSONValue>,
73
81
  typesMap: TypesMap,
74
82
  functionsMeta: FunctionsMeta,
75
- supportsImportAttributes: boolean
83
+ supportsImportAttributes: boolean,
84
+ additionalTypes?: string[]
76
85
  ) {
77
86
  await writeFileInDir(
78
87
  logger,
@@ -80,7 +89,7 @@ export async function saveSchemas(
80
89
  'export const empty = null;'
81
90
  )
82
91
 
83
- const desiredSchemas = new Set([
92
+ const desiredSchemas = new Set<string>([
84
93
  ...Object.values(functionsMeta)
85
94
  .map(({ inputs, outputs }) => [
86
95
  inputs?.[0] ? typesMap.getUniqueName(inputs[0]) : undefined,
@@ -88,11 +97,12 @@ export async function saveSchemas(
88
97
  ])
89
98
  .flat()
90
99
  .filter(
91
- (s) =>
100
+ (s): s is string =>
92
101
  !!s &&
93
102
  !['boolean', 'string', 'number', 'null', 'undefined'].includes(s)
94
103
  ),
95
104
  ...typesMap.customTypes.keys(),
105
+ ...(additionalTypes || []),
96
106
  ])
97
107
 
98
108
  if (desiredSchemas.size === 0) {
@@ -113,7 +123,12 @@ export async function saveSchemas(
113
123
  })
114
124
  )
115
125
 
116
- const schemaImports = Array.from(desiredSchemas)
126
+ // Only include schemas that were successfully generated
127
+ const availableSchemas = Array.from(desiredSchemas).filter(
128
+ (schema) => schemas[schema]
129
+ )
130
+
131
+ const schemaImports = availableSchemas
117
132
  .map(
118
133
  (schema) => `
119
134
  import * as ${schema} from './schemas/${schema}.schema.json' ${supportsImportAttributes ? `with { type: 'json' }` : ''}
package/src/schemas.ts CHANGED
@@ -4,7 +4,7 @@ import { PikkuCommand } from './types.js'
4
4
 
5
5
  export const pikkuSchemas: PikkuCommand = async (
6
6
  logger,
7
- { tsconfig, schemaDirectory, supportsImportAttributes },
7
+ { tsconfig, schemaDirectory, supportsImportAttributes, schemasFromTypes },
8
8
  { functions, http }
9
9
  ) => {
10
10
  return await logCommandInfoAndTime(
@@ -18,7 +18,8 @@ export const pikkuSchemas: PikkuCommand = async (
18
18
  tsconfig,
19
19
  functions.typesMap,
20
20
  functions.meta,
21
- http.meta
21
+ http.meta,
22
+ schemasFromTypes
22
23
  )
23
24
  await saveSchemas(
24
25
  logger,
@@ -26,7 +27,8 @@ export const pikkuSchemas: PikkuCommand = async (
26
27
  schemas,
27
28
  functions.typesMap,
28
29
  functions.meta,
29
- supportsImportAttributes
30
+ supportsImportAttributes,
31
+ schemasFromTypes
30
32
  )
31
33
  }
32
34
  )
@@ -6,7 +6,7 @@ import { PikkuCommand } from '../../types.js'
6
6
 
7
7
  export const pikkuOpenAPI: PikkuCommand = async (
8
8
  logger,
9
- { tsconfig, openAPI },
9
+ { tsconfig, openAPI, schemasFromTypes },
10
10
  { http, functions }
11
11
  ) => {
12
12
  return await logCommandInfoAndTime(
@@ -23,7 +23,8 @@ export const pikkuOpenAPI: PikkuCommand = async (
23
23
  tsconfig,
24
24
  functions.typesMap,
25
25
  functions.meta,
26
- http.meta
26
+ http.meta,
27
+ schemasFromTypes
27
28
  )
28
29
  const openAPISpec = await generateOpenAPISpec(
29
30
  functions.meta,