@bidirekt/typescript-sdk-cli 0.1.0 → 0.2.0

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,16 @@
1
+ const descriptionPattern = /^[A-Za-z0-9]+( [A-Za-z0-9]+)*$/;
2
+ export function descriptionToDiagnostic(description, location) {
3
+ if (description === '') {
4
+ return {
5
+ message: '"description" is empty: write a description or leave "description" out',
6
+ location,
7
+ };
8
+ }
9
+ if (descriptionPattern.test(description)) {
10
+ return undefined;
11
+ }
12
+ return {
13
+ message: `description ${JSON.stringify(description)} must be ASCII letters and digits, with single spaces between words: remove or replace the other characters`,
14
+ location,
15
+ };
16
+ }
@@ -1,4 +1,5 @@
1
1
  import ts from 'typescript';
2
+ import { descriptionToDiagnostic } from "../model/description.js";
2
3
  import { isDiagnostic } from "../model/diagnostic.js";
3
4
  import { nodeToLocation } from "./location.js";
4
5
  export function propertyNameToText(name) {
@@ -98,6 +99,14 @@ export function literalOptionToName(options, name) {
98
99
  }
99
100
  return literal.text;
100
101
  }
102
+ export function literalOptionToDescription(options) {
103
+ const literal = literalOptionToStringLiteral(options, 'description');
104
+ if (literal === undefined || isDiagnostic(literal)) {
105
+ return literal;
106
+ }
107
+ return (descriptionToDiagnostic(literal.text, nodeToLocation(literal)) ??
108
+ literal.text);
109
+ }
101
110
  export function literalOptionToBoolean(options, name) {
102
111
  const value = options.get(name);
103
112
  if (value === undefined) {
@@ -1,7 +1,7 @@
1
1
  import ts from 'typescript';
2
2
  import { isDiagnostic } from "../model/diagnostic.js";
3
3
  import { expressionToUnionMembers } from "./expression-to-schema-node.js";
4
- import { expressionToLiteralOptions, literalOptionToBoolean, literalOptionToName, literalOptionToString, literalOptionToStringLiteral, propertyNameToText, } from "./literal-options.js";
4
+ import { expressionToLiteralOptions, literalOptionToBoolean, literalOptionToDescription, literalOptionToName, literalOptionToStringLiteral, propertyNameToText, } from "./literal-options.js";
5
5
  import { nodeToLocation } from "./location.js";
6
6
  import { builtDeclarationToDiagnostic, isLibrarySymbol, isObjectDeclaration, javaScriptTagHints, memberToOwner, nodeToSymbol, symbolToClass, tagHints, unreadClassToDiagnostic, } from "./schema-context.js";
7
7
  import { typeTextToSchemaNode, typeTextUsage, } from "./type-text-to-schema-node.js";
@@ -440,7 +440,7 @@ function literalOptionsToFieldOptions(options, context) {
440
440
  if (isDiagnostic(name)) {
441
441
  return name;
442
442
  }
443
- const description = literalOptionToString(options, 'description');
443
+ const description = literalOptionToDescription(options);
444
444
  if (isDiagnostic(description)) {
445
445
  return description;
446
446
  }
@@ -1,4 +1,5 @@
1
1
  import ts from 'typescript';
2
+ import { descriptionToDiagnostic } from "../model/description.js";
2
3
  import { isDiagnostic } from "../model/diagnostic.js";
3
4
  import { argumentToOption, isHandlerTag } from "./comment-tags.js";
4
5
  import { namesToChoice } from "./literal-options.js";
@@ -234,12 +235,19 @@ export function argumentsToOptions(tagArguments, tag, keys) {
234
235
  options[key] = value === 'true';
235
236
  break;
236
237
  }
237
- case 'name':
238
- case 'description': {
238
+ case 'name': {
239
239
  if (value === '') {
240
240
  return usage;
241
241
  }
242
- options[key] = value;
242
+ options.name = value;
243
+ break;
244
+ }
245
+ case 'description': {
246
+ const invalid = descriptionToDiagnostic(value, tag.location);
247
+ if (invalid !== undefined) {
248
+ return invalid;
249
+ }
250
+ options.description = value;
243
251
  break;
244
252
  }
245
253
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bidirekt/typescript-sdk-cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,7 +25,7 @@
25
25
  "prepublishOnly": "npm run build"
26
26
  },
27
27
  "dependencies": {
28
- "@bidirekt/typescript-sdk": "0.1.0",
28
+ "@bidirekt/typescript-sdk": "0.2.0",
29
29
  "typescript": "~6.0.3",
30
30
  "yaml": "^2.9.1"
31
31
  }