firebase-contract 0.1.0-rc.10 → 0.1.0-rc.11
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/dist/lib/_internal/generators/api/api-dto-generator.d.ts.map +1 -1
- package/dist/lib/_internal/generators/api/api-dto-generator.js +1 -8
- package/dist/lib/_internal/generators/api/api-types-generator.d.ts.map +1 -1
- package/dist/lib/_internal/generators/api/api-types-generator.js +11 -5
- package/dist/lib/_internal/generators/api/task-payload-generator.js +3 -3
- package/dist/lib/_internal/generators/support/jsdoc.d.ts +3 -0
- package/dist/lib/_internal/generators/support/jsdoc.d.ts.map +1 -0
- package/dist/lib/_internal/generators/support/jsdoc.js +9 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-dto-generator.d.ts","sourceRoot":"","sources":["../../../../../src/lib/_internal/generators/api/api-dto-generator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,SAAS,EAAgC,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"api-dto-generator.d.ts","sourceRoot":"","sources":["../../../../../src/lib/_internal/generators/api/api-dto-generator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,SAAS,EAAgC,MAAM,iBAAiB,CAAA;AA8GxF,eAAO,MAAM,qBAAqB,QAAO,SAuBvC,CAAA"}
|
|
@@ -3,6 +3,7 @@ import { pascalCase, singleQuote } from '../support/naming.js';
|
|
|
3
3
|
import { isRelation, relationFkName } from '../support/relations.js';
|
|
4
4
|
import { selectApis } from '../generator.js';
|
|
5
5
|
import { headerBlocks } from '../support/header.js';
|
|
6
|
+
import { jsdoc } from '../support/jsdoc.js';
|
|
6
7
|
import { emitApiFiles, resolveOutput } from '../support/templates.js';
|
|
7
8
|
const SCALAR_TS = {
|
|
8
9
|
string: 'string',
|
|
@@ -96,14 +97,6 @@ const decoratorsFor = (ir, field, used) => {
|
|
|
96
97
|
}
|
|
97
98
|
return out;
|
|
98
99
|
};
|
|
99
|
-
const jsdoc = (description, indent) => {
|
|
100
|
-
if (!description)
|
|
101
|
-
return '';
|
|
102
|
-
const lines = description.split('\n');
|
|
103
|
-
if (lines.length === 1)
|
|
104
|
-
return `${indent}/** ${lines[0]} */\n`;
|
|
105
|
-
return `${indent}/**\n${lines.map(line => `${indent} * ${line}`.trimEnd()).join('\n')}\n${indent} */\n`;
|
|
106
|
-
};
|
|
107
100
|
const renderDto = (ir, api, used) => {
|
|
108
101
|
const fields = payloadFields(ir, api.request);
|
|
109
102
|
const className = `${pascalCase(api.name)}Dto`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-types-generator.d.ts","sourceRoot":"","sources":["../../../../../src/lib/_internal/generators/api/api-types-generator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,SAAS,EAAgC,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"api-types-generator.d.ts","sourceRoot":"","sources":["../../../../../src/lib/_internal/generators/api/api-types-generator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,SAAS,EAAgC,MAAM,iBAAiB,CAAA;AA4FxF,eAAO,MAAM,uBAAuB,QAAO,SA+BzC,CAAA"}
|
|
@@ -2,6 +2,7 @@ import { pascalCase } from '../support/naming.js';
|
|
|
2
2
|
import { isRelation, relationFkName, relationFkType } from '../support/relations.js';
|
|
3
3
|
import { selectApis } from '../generator.js';
|
|
4
4
|
import { headerBlocks } from '../support/header.js';
|
|
5
|
+
import { jsdoc } from '../support/jsdoc.js';
|
|
5
6
|
import { emitApiFiles, resolveOutput } from '../support/templates.js';
|
|
6
7
|
const SCALAR_TS = {
|
|
7
8
|
string: 'string',
|
|
@@ -34,8 +35,7 @@ const renderField = (ir, field) => {
|
|
|
34
35
|
const name = isRelation(field) ? relationFkName(field) : field.name;
|
|
35
36
|
const optional = field.optional ? '?' : '';
|
|
36
37
|
const nullable = field.nullable ? ' | null' : '';
|
|
37
|
-
|
|
38
|
-
return `${doc} ${name}${optional}: ${renderFieldTsType(ir, field)}${nullable}`;
|
|
38
|
+
return `${jsdoc(field.description, ' ')} ${name}${optional}: ${renderFieldTsType(ir, field)}${nullable}`;
|
|
39
39
|
};
|
|
40
40
|
const renderPayloadType = (ir, payload, typeName) => {
|
|
41
41
|
if (payload.isVoid) {
|
|
@@ -74,9 +74,15 @@ const apiComment = (api) => {
|
|
|
74
74
|
const bits = [`kind: ${api.kind}`];
|
|
75
75
|
if (api.method)
|
|
76
76
|
bits.push(`method: ${api.method}`);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
const description = api.description?.split('\n') ?? [];
|
|
78
|
+
// Single-line descriptions stay inline; multi-line ones get their own
|
|
79
|
+
// comment lines so literal-block yml descriptions survive verbatim.
|
|
80
|
+
if (description.length <= 1) {
|
|
81
|
+
if (description[0])
|
|
82
|
+
bits.unshift(description[0]);
|
|
83
|
+
return `// ${api.name} — ${bits.join(' | ')}`;
|
|
84
|
+
}
|
|
85
|
+
return [`// ${api.name} — ${bits.join(' | ')}`, ...description.map(line => `// ${line}`.trimEnd())].join('\n');
|
|
80
86
|
};
|
|
81
87
|
/**
|
|
82
88
|
* Generates request/response TypeScript types for each API endpoint. A payload
|
|
@@ -3,6 +3,7 @@ import { constantCase, pascalCase, singleQuote } from '../support/naming.js';
|
|
|
3
3
|
import { isRelation, relationFkName, relationFkType } from '../support/relations.js';
|
|
4
4
|
import { selectApis } from '../generator.js';
|
|
5
5
|
import { headerBlocks } from '../support/header.js';
|
|
6
|
+
import { jsdoc } from '../support/jsdoc.js';
|
|
6
7
|
import { emitApiFiles, resolveOutput } from '../support/templates.js';
|
|
7
8
|
const SCALAR_TS = {
|
|
8
9
|
string: 'string',
|
|
@@ -30,13 +31,12 @@ const fieldTs = (ir, field) => {
|
|
|
30
31
|
};
|
|
31
32
|
const renderMember = (ir, field) => {
|
|
32
33
|
const name = isRelation(field) ? relationFkName(field) : field.name;
|
|
33
|
-
const doc = field.description ? ` /** ${field.description} */\n` : '';
|
|
34
34
|
const nullable = field.nullable ? ' | null' : '';
|
|
35
|
-
return `${
|
|
35
|
+
return `${jsdoc(field.description, ' ')} ${name}${field.optional ? '?' : ''}: ${fieldTs(ir, field)}${nullable}`;
|
|
36
36
|
};
|
|
37
37
|
const payloadFields = (ir, payload) => payload.model ? (findModel(ir, payload.model)?.fields ?? []) : payload.fields;
|
|
38
38
|
const renderEnvelope = (env) => {
|
|
39
|
-
const doc = env.description
|
|
39
|
+
const doc = jsdoc(env.description, '');
|
|
40
40
|
const members = env.fields.map(field => ` ${field.name}${field.optional ? '?' : ''}: ${SCALAR_TS[field.type.kind === 'scalar' ? field.type.name : 'string']}`).join('\n');
|
|
41
41
|
return `${doc}export type ${env.name}<T> = T & {\n${members}\n}`;
|
|
42
42
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsdoc.d.ts","sourceRoot":"","sources":["../../../../../src/lib/_internal/generators/support/jsdoc.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,eAAO,MAAM,KAAK,GAAI,aAAa,MAAM,GAAG,SAAS,EAAE,QAAQ,MAAM,KAAG,MAKvE,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Render a JSDoc block for a possibly multi-line description ('' when absent). */
|
|
2
|
+
export const jsdoc = (description, indent) => {
|
|
3
|
+
if (!description)
|
|
4
|
+
return '';
|
|
5
|
+
const lines = description.split('\n');
|
|
6
|
+
if (lines.length === 1)
|
|
7
|
+
return `${indent}/** ${lines[0]} */\n`;
|
|
8
|
+
return `${indent}/**\n${lines.map(line => `${indent} * ${line}`.trimEnd()).join('\n')}\n${indent} */\n`;
|
|
9
|
+
};
|