@omnifyjp/ts 6.3.9 → 6.3.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.
@@ -102,7 +102,7 @@ function generateBaseResource(name, schema, reader, config) {
102
102
  if (isHiddenByDefault(type) || hidden)
103
103
  continue;
104
104
  if (type === 'Association') {
105
- addAssociationFields(propName, prop, fields, resourceNamespace, modelNamespace, reader, config, importer);
105
+ addAssociationFields(name, propName, prop, fields, resourceNamespace, modelNamespace, reader, config, importer);
106
106
  continue;
107
107
  }
108
108
  if (expandedProperties[propName]) {
@@ -258,7 +258,7 @@ class ${editable.className} extends ${baseAlias}
258
258
  `;
259
259
  return userFile(`${editable.path}/${editable.fileName}`, content);
260
260
  }
261
- function addAssociationFields(propName, prop, fields, resourceNamespace, modelNamespace, reader, config, importer) {
261
+ function addAssociationFields(schemaName, propName, prop, fields, resourceNamespace, modelNamespace, reader, config, importer) {
262
262
  const relation = prop['relation'] ?? '';
263
263
  const target = prop['target'] ?? '';
264
264
  const methodName = toCamelCase(propName);
@@ -309,6 +309,23 @@ function addAssociationFields(propName, prop, fields, resourceNamespace, modelNa
309
309
  // If target is a package schema without a resource namespace, or a model no
310
310
  // Resource is written for, use simple whenLoaded
311
311
  if ((!targetResNs || !targetHasResource) && relation !== 'MorphTo') {
312
+ // Say it. An unwrapped relation serializes the raw model instead of the
313
+ // shaped resource, so the endpoint's response changes shape — and the PHP
314
+ // still compiles, so the only way anyone noticed was an unexpected line in
315
+ // a diff (#187). A target that is not a schema at all is the ordinary case
316
+ // (an external model reached through `targetNamespace`) and stays quiet.
317
+ if (reader.getSchema(target)) {
318
+ console.warn(`[omnify-ts] ${schemaName}.${propName}: no Resource class for target `
319
+ + `'${target}', so it serializes as the raw model instead of `
320
+ + `${toPascalCase(target)}Resource. `
321
+ + (targetResNs
322
+ ? `Cause: this codegen target writes no Resource for ${target} `
323
+ + `(kind: extend, options.hidden, or an includeSchemas / `
324
+ + `excludeSchemas filter that leaves it out).`
325
+ : `Cause: package '${reader.getSchema(target)?.package}' declares no `
326
+ + `codegen.laravel.resource.namespace, so its Resource class cannot `
327
+ + `be named from here.`));
328
+ }
312
329
  if (relation === 'ManyToOne') {
313
330
  const snakeName = toFkColumnName(propName);
314
331
  fields.push(` '${snakeName}' => $this->${snakeName},`);
@@ -18,6 +18,12 @@ export declare class SchemaReader {
18
18
  name: string;
19
19
  schema: SchemaDefinition;
20
20
  } | undefined;
21
+ /**
22
+ * Object schemas this run generates for. `referenceOnly` entries are left
23
+ * out: they are in the export solely so relation targets resolve (#187),
24
+ * and every generation loop reaches the set through this method.
25
+ * `getSchema()` deliberately still returns them.
26
+ */
21
27
  getObjectSchemas(): Record<string, SchemaDefinition>;
22
28
  getVisibleObjectSchemas(): Record<string, SchemaDefinition>;
23
29
  getEnumSchemas(): Record<string, SchemaDefinition>;
@@ -37,11 +37,17 @@ export class SchemaReader {
37
37
  }
38
38
  return undefined;
39
39
  }
40
+ /**
41
+ * Object schemas this run generates for. `referenceOnly` entries are left
42
+ * out: they are in the export solely so relation targets resolve (#187),
43
+ * and every generation loop reaches the set through this method.
44
+ * `getSchema()` deliberately still returns them.
45
+ */
40
46
  getObjectSchemas() {
41
47
  const result = {};
42
48
  for (const [name, schema] of Object.entries(this.getSchemas())) {
43
49
  const kind = schema.kind ?? 'object';
44
- if (kind !== 'enum' && kind !== 'partial') {
50
+ if (kind !== 'enum' && kind !== 'partial' && !schema.referenceOnly) {
45
51
  result[name] = schema;
46
52
  }
47
53
  }
package/dist/types.d.ts CHANGED
@@ -248,6 +248,14 @@ export interface SchemaDefinition {
248
248
  * run never saw them (#164).
249
249
  */
250
250
  readonly extendedProperties?: readonly string[];
251
+ /**
252
+ * Set by the Go side for a PACKAGE schema that this codegen target's
253
+ * include/exclude filter keeps out of the output but that relations still
254
+ * have to resolve against (#187). Generation loops skip it; `getSchema()`
255
+ * still returns it so a cross-package reference names the package's class
256
+ * instead of silently degrading.
257
+ */
258
+ readonly referenceOnly?: boolean;
251
259
  readonly values?: readonly EnumValueDefinition[];
252
260
  readonly pivotFor?: readonly string[];
253
261
  readonly policies?: readonly PolicyDefinition[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnifyjp/ts",
3
- "version": "6.3.9",
3
+ "version": "6.3.11",
4
4
  "description": "TypeScript model type generator from Omnify schemas.json",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",