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

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-validation-generator.d.ts","sourceRoot":"","sources":["../../../../../src/lib/_internal/generators/api/api-validation-generator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,SAAS,EAAoB,MAAM,iBAAiB,CAAA;AAsD5E;;;GAGG;AACH,eAAO,MAAM,4BAA4B,QAAO,SAa9C,CAAA"}
1
+ {"version":3,"file":"api-validation-generator.d.ts","sourceRoot":"","sources":["../../../../../src/lib/_internal/generators/api/api-validation-generator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,SAAS,EAAoB,MAAM,iBAAiB,CAAA;AAuE5E;;;GAGG;AACH,eAAO,MAAM,4BAA4B,QAAO,SAa9C,CAAA"}
@@ -21,8 +21,7 @@ const payloadFields = (ir, payload) => {
21
21
  }
22
22
  return payload.fields;
23
23
  };
24
- const fieldSchema = (ir, field) => {
25
- const name = isRelation(field) ? relationFkName(field) : field.name;
24
+ const fieldChain = (ir, field, seen) => {
26
25
  let schema;
27
26
  if (isRelation(field)) {
28
27
  schema = SCALAR_ZOD[relationFkType(ir, field)];
@@ -35,6 +34,21 @@ const fieldSchema = (ir, field) => {
35
34
  const irEnum = ir.enums.find(e => e.name === enumName);
36
35
  schema = irEnum ? `z.enum([${irEnum.values.map(singleQuote).join(', ')}])` : 'z.string()';
37
36
  }
37
+ else if (field.type.kind === 'model') {
38
+ // Embedded value objects expand to a structural z.object so request payloads
39
+ // validate all the way down; cycles fall back to z.unknown().
40
+ const model = findModel(ir, field.type.name);
41
+ if (model && !seen.has(model.name)) {
42
+ const nested = new Set([...seen, model.name]);
43
+ const body = model.fields
44
+ .map(f => `${isRelation(f) ? relationFkName(f) : f.name}: ${fieldChain(ir, f, nested)}`)
45
+ .join(', ');
46
+ schema = `z.object({ ${body} })`;
47
+ }
48
+ else {
49
+ schema = 'z.unknown()';
50
+ }
51
+ }
38
52
  else {
39
53
  schema = 'z.unknown()';
40
54
  }
@@ -44,7 +58,11 @@ const fieldSchema = (ir, field) => {
44
58
  schema = `${schema}.nullable()`;
45
59
  if (field.optional)
46
60
  schema = `${schema}.optional()`;
47
- return ` ${name}: ${schema},`;
61
+ return schema;
62
+ };
63
+ const fieldSchema = (ir, field) => {
64
+ const name = isRelation(field) ? relationFkName(field) : field.name;
65
+ return ` ${name}: ${fieldChain(ir, field, new Set())},`;
48
66
  };
49
67
  const renderRequestSchema = (ir, api) => {
50
68
  const name = `${pascalCase(api.name)}RequestSchema`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-contract",
3
- "version": "0.1.0-rc.3",
3
+ "version": "0.1.0-rc.4",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "firebase-contract": "./dist/lib/cli/index.js",