firebase-contract 0.1.0-rc.4 → 0.1.0-rc.5

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.
@@ -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,EAAoB,MAAM,iBAAiB,CAAA;AAiG5E;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAO,SAgBvC,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,EAAoB,MAAM,iBAAiB,CAAA;AA0G5E;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAO,SAkBvC,CAAA"}
@@ -94,21 +94,31 @@ const decoratorsFor = (ir, field, used) => {
94
94
  }
95
95
  return out;
96
96
  };
97
+ const jsdoc = (description, indent) => {
98
+ if (!description)
99
+ return '';
100
+ const lines = description.split('\n');
101
+ if (lines.length === 1)
102
+ return `${indent}/** ${lines[0]} */\n`;
103
+ return `${indent}/**\n${lines.map(line => `${indent} * ${line}`.trimEnd()).join('\n')}\n${indent} */\n`;
104
+ };
97
105
  const renderDto = (ir, api, used) => {
98
106
  const fields = payloadFields(ir, api.request);
99
107
  const className = `${pascalCase(api.name)}Dto`;
108
+ const doc = jsdoc(api.description, '');
100
109
  if (api.request.isVoid || fields.length === 0) {
101
- return `export class ${className} {}`;
110
+ return `${doc}export class ${className} {}`;
102
111
  }
103
112
  const members = fields
104
113
  .map(field => {
105
114
  const name = isRelation(field) ? relationFkName(field) : field.name;
106
115
  const decorators = decoratorsFor(ir, field, used).join('\n');
107
116
  const mark = field.optional ? '?' : '!';
108
- return `${decorators}\n ${name}${mark}: ${propType(ir, field)}`;
117
+ const nullable = field.nullable ? ' | null' : '';
118
+ return `${jsdoc(field.description, ' ')}${decorators}\n ${name}${mark}: ${propType(ir, field)}${nullable}`;
109
119
  })
110
120
  .join('\n\n');
111
- return `export class ${className} {\n${members}\n}`;
121
+ return `${doc}export class ${className} {\n${members}\n}`;
112
122
  };
113
123
  /**
114
124
  * Generates class-validator DTO classes for API endpoint requests, mirroring the
@@ -119,11 +129,13 @@ export const createApiDtoGenerator = () => ({
119
129
  name: 'api-dto',
120
130
  description: 'class-validator DTO classes for API requests',
121
131
  generate(ir, context) {
122
- if (ir.apis.length === 0) {
132
+ // DTO は HTTP リクエストボディ用 — task / pubsub のペイロードは task-payloads が担う。
133
+ const httpApis = ir.apis.filter(api => api.kind === 'https' || api.kind === 'callable');
134
+ if (httpApis.length === 0) {
123
135
  return [];
124
136
  }
125
137
  const used = new Set();
126
- const dtoBlocks = ir.apis.map(api => renderDto(ir, api, used));
138
+ const dtoBlocks = httpApis.map(api => renderDto(ir, api, used));
127
139
  const blocks = [...headerBlocks(context)];
128
140
  if (used.size > 0) {
129
141
  blocks.push(`import { ${[...used].sort().join(', ')} } from 'class-validator'`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-contract",
3
- "version": "0.1.0-rc.4",
3
+ "version": "0.1.0-rc.5",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "firebase-contract": "./dist/lib/cli/index.js",