vovk-cli 0.0.1-beta.15 → 0.0.1-beta.16

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.
@@ -0,0 +1 @@
1
+ export default function addCommonTerms(): void;
@@ -0,0 +1,90 @@
1
+ import pluralize from 'pluralize';
2
+ const terms = [
3
+ ['entity', 'entities'],
4
+ ['regex', 'regexes'],
5
+ ['index', 'indices'],
6
+ ['matrix', 'matrices'],
7
+ ['axis', 'axes'],
8
+ ['schema', 'schemas'],
9
+ ['criterion', 'criteria'],
10
+ ['datum', 'data'],
11
+ ['formula', 'formulas'],
12
+ ['appendix', 'appendices'],
13
+ ['vertex', 'vertices'],
14
+ ['leaf', 'leaves'],
15
+ ['analysis', 'analyses'],
16
+ ['thesis', 'theses'],
17
+ ['hypothesis', 'hypotheses'],
18
+ ['phenomenon', 'phenomena'],
19
+ ['alumnus', 'alumni'],
20
+ ['focus', 'foci'],
21
+ ['medium', 'media'],
22
+ ['bacterium', 'bacteria'],
23
+ ['radius', 'radii'],
24
+ ['genus', 'genera'],
25
+ ['corpus', 'corpora'],
26
+ ['locus', 'loci'],
27
+ ['nucleus', 'nuclei'],
28
+ ['fungus', 'fungi'],
29
+ ['syllabus', 'syllabi'],
30
+ ['cactus', 'cacti'],
31
+ ['automaton', 'automata'],
32
+ ['stimulus', 'stimuli'],
33
+ ['parenthesis', 'parentheses'],
34
+ ['ellipsis', 'ellipses'],
35
+ ['diagnosis', 'diagnoses'],
36
+ ['oasis', 'oases'],
37
+ ['crisis', 'crises'],
38
+ ['antenna', 'antennae'],
39
+ ['chateau', 'chateaux'],
40
+ ['tableau', 'tableaux'],
41
+ ['penny', 'pence'],
42
+ ['memorandum', 'memoranda'],
43
+ ['erratum', 'errata'],
44
+ ['curriculum', 'curricula'],
45
+ ['millennium', 'millennia'],
46
+ ['stratum', 'strata'],
47
+ ['spectrum', 'spectra'],
48
+ ['apex', 'apices'],
49
+ ['vortex', 'vortices'],
50
+ ['calf', 'calves'],
51
+ ['loaf', 'loaves'],
52
+ ['foot', 'feet'],
53
+ ['tooth', 'teeth'],
54
+ ['mouse', 'mice'],
55
+ ['goose', 'geese'],
56
+ ['child', 'children'],
57
+ ['person', 'people'],
58
+ ['man', 'men'],
59
+ ['woman', 'women'],
60
+ ['ox', 'oxen'],
61
+ ['die', 'dice'],
62
+ ['brother', 'brethren'],
63
+ ['stimulus', 'stimuli'],
64
+ ['larva', 'larvae'],
65
+ ['nebula', 'nebulae'],
66
+ ['formula', 'formulae'],
67
+ ['antenna', 'antennas'],
68
+ ['vertebra', 'vertebrae'],
69
+ ['index', 'indexes'],
70
+ ['addendum', 'addenda'],
71
+ ['aquarium', 'aquaria'],
72
+ ['stadium', 'stadia'],
73
+ ['maximum', 'maxima'],
74
+ ['minimum', 'minima'],
75
+ ['referendum', 'referenda'],
76
+ ['forum', 'fora'],
77
+ ['schema', 'schemata'],
78
+ ['leaf', 'leaves'],
79
+ ['knife', 'knives'],
80
+ ['wolf', 'wolves'],
81
+ ['elf', 'elves'],
82
+ ['half', 'halves'],
83
+ ['scarf', 'scarves'],
84
+ ];
85
+ export default function addCommonTerms() {
86
+ terms.forEach(([singular, plural]) => {
87
+ const regex = new RegExp(`${singular}$`, 'i');
88
+ pluralize.addPluralRule(regex, plural);
89
+ });
90
+ }
@@ -0,0 +1 @@
1
+ export default function replaceOccurrences(code: string, replacementSingular: string): string;
@@ -0,0 +1,49 @@
1
+ import camelCase from 'lodash/camelCase.js';
2
+ import kebabCase from 'lodash/kebabCase.js';
3
+ import snakeCase from 'lodash/snakeCase.js';
4
+ import upperFirst from 'lodash/upperFirst.js';
5
+ import pluralize from 'pluralize';
6
+ import addCommonTerms from './addCommonTerms';
7
+ addCommonTerms();
8
+ console.log('WoRD', pluralize('entity'));
9
+ export default function replaceOccurrences(code, replacementSingular) {
10
+ const replacementPlural = pluralize(replacementSingular);
11
+ // Different cases of the replacement string
12
+ const replacements = {
13
+ camelPlural: camelCase(replacementPlural),
14
+ camel: camelCase(replacementSingular),
15
+ pascalPlural: upperFirst(camelCase(replacementPlural)),
16
+ pascal: upperFirst(camelCase(replacementSingular)),
17
+ kebabPlural: kebabCase(replacementPlural),
18
+ kebab: kebabCase(replacementSingular),
19
+ snakePlural: snakeCase(replacementPlural),
20
+ snake: snakeCase(replacementSingular),
21
+ screamingSnakePlural: snakeCase(replacementPlural).toUpperCase(),
22
+ screamingSnake: snakeCase(replacementSingular).toUpperCase(),
23
+ screamingKebabPlural: kebabCase(replacementPlural).toUpperCase(),
24
+ screamingKebab: kebabCase(replacementSingular).toUpperCase(),
25
+ };
26
+ // Create a map of original patterns to their replacements
27
+ const originalPatterns = {
28
+ camelPlural: 'myThings',
29
+ camel: 'myThing',
30
+ pascalPlural: 'MyThings',
31
+ pascal: 'MyThing',
32
+ kebabPlural: 'my-things',
33
+ kebab: 'my-thing',
34
+ snakePlural: 'my_things',
35
+ snake: 'my_thing',
36
+ screamingSnakePlural: 'MY_THINGS',
37
+ screamingSnake: 'MY_THING',
38
+ screamingKebabPlural: 'MY-THINGS',
39
+ screamingKebab: 'MY-THING',
40
+ };
41
+ // Replace all occurrences in the code
42
+ Object.keys(originalPatterns).forEach((key) => {
43
+ const pattern = originalPatterns[key];
44
+ const replacementValue = replacements[key];
45
+ const regex = new RegExp(pattern, 'g');
46
+ code = code.replace(regex, replacementValue);
47
+ });
48
+ return code;
49
+ }
@@ -11,6 +11,7 @@ import debounceWithArgs from '../utils/debounceWithArgs.mjs';
11
11
  import debounce from 'lodash/debounce.js';
12
12
  import isEmpty from 'lodash/isEmpty.js';
13
13
  import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
14
+ import keyBy from 'lodash/keyBy.js';
14
15
  export class VovkCLIWatcher {
15
16
  #projectInfo;
16
17
  #segments = [];
@@ -173,7 +174,12 @@ export class VovkCLIWatcher {
173
174
  const schema = this.#schemas[s.segmentName];
174
175
  if (!schema)
175
176
  return false;
176
- return namesOfClasses.some((name) => schema.controllers[name] || schema.workers[name]);
177
+ const controllersByOriginalName = keyBy(schema.controllers, '_originalControllerName');
178
+ const workersByOriginalName = keyBy(schema.workers, '_originalWorkerName');
179
+ return namesOfClasses.some((name) => schema.controllers[name] ||
180
+ schema.workers[name] ||
181
+ controllersByOriginalName[name] ||
182
+ workersByOriginalName[name]);
177
183
  });
178
184
  if (affectedSegments.length) {
179
185
  log.debug(`A file with controller or worker ${namesOfClasses.join(', ')} have been modified at path "${filePath}". Segment(s) affected: ${affectedSegments.map((s) => s.segmentName).join(', ')}`);
@@ -232,7 +238,7 @@ export class VovkCLIWatcher {
232
238
  log.error(`Non-empty schema provided for ${formatLoggedSegmentName(segment.segmentName, true)} but emitSchema is false`);
233
239
  }
234
240
  if (this.#segments.every((s) => this.#schemas[s.segmentName])) {
235
- log.debug(`All segments with emitSchema=true have schema.`);
241
+ log.debug(`All segments with "emitSchema" have schema.`);
236
242
  await generateClient(this.#projectInfo, this.#segments, this.#schemas);
237
243
  }
238
244
  }
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "vovk-cli",
3
- "version": "0.0.1-beta.15",
3
+ "version": "0.0.1-beta.16",
4
4
  "bin": {
5
5
  "vovk": "./dist/index.mjs"
6
6
  },
7
+ "main": "./dist/index.mjs",
7
8
  "type": "module",
8
9
  "types": "./dist/index.d.mts",
9
10
  "prefix": ".",
10
11
  "scripts": {
11
- "build": "rm -rf dist tsconfig.tsbuildinfo && tsc",
12
- "test": "ts-node test/index.mts",
12
+ "build": "rm -rf dist tsconfig.build.tsbuildinfo && tsc -P tsconfig.build.json",
13
+ "test": "NODE_OPTIONS=\"--loader ts-node/esm\" TS_NODE_PROJECT=./tsconfig.test.json node test/index.mts",
13
14
  "ncu": "npm-check-updates -u",
14
15
  "npm-publish": "npm publish"
15
16
  },
@@ -30,21 +31,24 @@
30
31
  },
31
32
  "homepage": "https://vovk.dev",
32
33
  "peerDependencies": {
33
- "vovk": "^3.0.0-beta.22"
34
+ "vovk": "^3.0.0-beta.26"
34
35
  },
35
36
  "dependencies": {
36
- "@inquirer/prompts": "^5.3.8",
37
+ "@inquirer/prompts": "^5.5.0",
37
38
  "@npmcli/package-json": "^5.2.0",
38
39
  "chalk": "^5.3.0",
39
40
  "chokidar": "^3.6.0",
40
41
  "commander": "^12.1.0",
41
42
  "concurrently": "^8.2.2",
43
+ "inflection": "^3.0.0",
42
44
  "jsonc-parser": "^3.3.1",
43
45
  "lodash": "^4.17.21",
44
- "loglevel": "^1.9.1"
46
+ "loglevel": "^1.9.2",
47
+ "pluralize": "^8.0.0"
45
48
  },
46
49
  "devDependencies": {
47
50
  "@types/npmcli__package-json": "^4.0.4",
51
+ "@types/pluralize": "^0.0.33",
48
52
  "type-fest": "^4.26.0"
49
53
  }
50
54
  }
@@ -0,0 +1,32 @@
1
+ import { prefix, get, put, post, del, type VovkRequest } from 'vovk';
2
+
3
+ @prefix('my-things')
4
+ export default class MyThingController {
5
+ @get()
6
+ static getMyThingsExample = (req: VovkRequest<null, { q: string }>) => {
7
+ const q = req.nextUrl.searchParams.get('q');
8
+ return { q };
9
+ };
10
+
11
+ @put(':id')
12
+ static updateMyThingExample = async (
13
+ req: VovkRequest<{ foo: 'bar' | 'baz' }, { q: string }>,
14
+ params: { id: string }
15
+ ) => {
16
+ const { id } = params;
17
+ const body = await req.json();
18
+ const q = req.nextUrl.searchParams.get('q');
19
+
20
+ return { id, q, body };
21
+ };
22
+
23
+ @post()
24
+ static createMyThingExample = () => {
25
+ // ...
26
+ };
27
+
28
+ @del(':id')
29
+ static deleteMyThingExample = () => {
30
+ // ...
31
+ };
32
+ }
@@ -0,0 +1,34 @@
1
+ import { prefix, get, put, post, del, type VovkRequest } from 'vovk';
2
+ import MyThingService from './MyThingService.s.template';
3
+
4
+ @prefix('my-things')
5
+ export default class MyThingController {
6
+ @get()
7
+ static getMyThingsExample(req: VovkRequest<null, { q: string }>) {
8
+ const q = req.nextUrl.searchParams.get('q');
9
+
10
+ return MyThingService.getMyThingsExample(q);
11
+ }
12
+
13
+ @put(':id')
14
+ static updateMyThingExample = async (
15
+ req: VovkRequest<{ foo: 'bar' | 'baz' }, { q: string }>,
16
+ params: { id: string }
17
+ ) => {
18
+ const { id } = params;
19
+ const body = await req.json();
20
+ const q = req.nextUrl.searchParams.get('q');
21
+
22
+ return MyThingService.updateMyThingExample(id, q, body);
23
+ };
24
+
25
+ @post()
26
+ static createMyThingExample = () => {
27
+ // ...
28
+ };
29
+
30
+ @del(':id')
31
+ static deleteMyThingExample = () => {
32
+ // ...
33
+ };
34
+ }
@@ -0,0 +1,18 @@
1
+ import type { VovkControllerBody, VovkControllerQuery } from 'vovk';
2
+ import type MyThingController from './MyThingController.c.template';
3
+
4
+ export default class MyThingService {
5
+ static getMyThingsExample = (q: VovkControllerQuery<typeof MyThingController.getMyThingsExample>['q']) => {
6
+ return { q };
7
+ };
8
+
9
+ static updateMyThingExample = (
10
+ id: string,
11
+ q: VovkControllerQuery<typeof MyThingController.updateMyThingExample>['q'],
12
+ body: VovkControllerBody<typeof MyThingController.updateMyThingExample>
13
+ ) => {
14
+ return { id, q, body };
15
+ };
16
+
17
+ // ...
18
+ }