@omnifyjp/ts 3.23.0 → 3.23.2

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/php/index.js CHANGED
@@ -68,10 +68,12 @@ export function generatePhp(data, overrides) {
68
68
  // we add the standalone Common / Info / Schemas files.
69
69
  files.push(...generateOpenApi(reader, config));
70
70
  }
71
- // Service layer (schemas with options.api OR options.service). Issue #57.
72
- if (reader.hasApiSchemas() || reader.hasServiceSchemas()) {
73
- files.push(...generateServices(reader, config));
74
- }
71
+ // Service layer. #81 (v3.23.0): service generation is now opt-out by
72
+ // default every project `kind: object` schema gets a base service
73
+ // unless explicitly opted out via `options.service: false`. The old
74
+ // opt-in gate here is gone because `generateServices` does its own
75
+ // filter internally; always call it and let it decide.
76
+ files.push(...generateServices(reader, config));
75
77
  // Issue #34: every `kind: enum` schema becomes a global PHP enum class.
76
78
  files.push(...generateEnums(reader, config));
77
79
  // Astrotomic translatable config (only when at least one schema has
@@ -32,27 +32,58 @@ import { baseFile, userFile, resolveModularBasePath, resolveModularBaseNamespace
32
32
  export function generateServices(reader, config) {
33
33
  const files = [];
34
34
  const candidates = {};
35
- // Project-owned object schemas the new default-enabled set (#81).
36
- for (const [name, schema] of Object.entries(reader.getProjectObjectSchemas())) {
35
+ // #81 + #80 interaction (v3.23.1): iterate every project-owned schema
36
+ // directly instead of going through `getProjectObjectSchemas()`, which
37
+ // filters out KindPartial. Phantom-upstream extends (#80 self-reference
38
+ // fallback — e.g. `kind: extend, target: Product` with no upstream
39
+ // package loaded) are kept as KindPartial so downstream generators
40
+ // skip emitting tables for them, but their SERVICES still belong in
41
+ // the consumer project and must be generated here. Kind=object stays
42
+ // the opt-out default; Kind=partial/extend is included when the user
43
+ // has signalled service intent (legacy options.service block or any
44
+ // property-level service flag).
45
+ const allSchemas = reader.getSchemas();
46
+ for (const [name, schema] of Object.entries(allSchemas)) {
47
+ // Project-owned only — packages emit their own services in the
48
+ // owning package's codegen pass.
49
+ if (schema.package != null)
50
+ continue;
51
+ const kind = schema.kind ?? 'object';
52
+ // Hard exclusions: non-object-ish kinds never get services
53
+ if (kind === 'enum' || kind === 'pivot')
54
+ continue;
37
55
  // #81 explicit opt-out: `service: false` on the schema
38
56
  if (schema.options?.service === false) {
39
57
  continue;
40
58
  }
41
- // Skip Astrotomic translation sidecars — they're auto-emitted as PHP
42
- // translation models, not as full services. Heuristic by name suffix.
59
+ // Astrotomic translation sidecars — auto-emitted as PHP translation
60
+ // models, not full services. Heuristic by name suffix.
43
61
  if (name.endsWith('Translation')) {
44
62
  continue;
45
63
  }
46
- // Skip hidden schemas (options.hidden = true) — intentional internal types
64
+ // Hidden schemas (options.hidden = true) — intentional internal types
47
65
  if (schema.options?.hidden) {
48
66
  continue;
49
67
  }
50
- candidates[name] = schema;
68
+ if (kind === 'object') {
69
+ // Phase 2 default: every object schema gets a service
70
+ candidates[name] = schema;
71
+ }
72
+ else if (kind === 'partial' || kind === 'extend') {
73
+ // Phantom-upstream extend (#80 fallback). Only emit a service if the
74
+ // user signalled intent — either a legacy options.service block, or
75
+ // at least one property-level service flag (searchable / filterable /
76
+ // sortable / lookupable / defaultSort). An empty extend with no
77
+ // service config is not a service candidate — it's a stub the user
78
+ // added for property merging elsewhere.
79
+ if (schemaHasServiceIntent(schema)) {
80
+ candidates[name] = schema;
81
+ }
82
+ }
51
83
  }
52
84
  // Legacy `options.api` schemas — these are already in project set above
53
- // (getSchemasWithApi is a subset of project schemas). We don't need a
54
- // second pass for them unless someone sets `service: false` + `api: {}`
55
- // on the same schema, in which case the explicit api opt-in wins.
85
+ // for most cases, but belt-and-suspenders: include any that slipped
86
+ // through the kind filter.
56
87
  for (const [name, schema] of Object.entries(reader.getSchemasWithApi())) {
57
88
  if (!candidates[name]) {
58
89
  candidates[name] = schema;
@@ -68,6 +99,34 @@ export function generateServices(reader, config) {
68
99
  }
69
100
  return files;
70
101
  }
102
+ /**
103
+ * #81 + #80 (v3.23.1): detect "user wants a service for this schema" signal
104
+ * on extend/partial schemas. Returns true when either:
105
+ * - the legacy options.service block is present (truthy, not false), OR
106
+ * - at least one property has a service-related flag set.
107
+ *
108
+ * Phantom-upstream extends (#80 self-reference fallback) stay as KindPartial
109
+ * for migration purposes, but the consumer project still wants a service
110
+ * layer for calling into the externally-owned table. This helper tells the
111
+ * candidate selector to include those.
112
+ */
113
+ function schemaHasServiceIntent(schema) {
114
+ const svc = schema.options?.service;
115
+ if (svc && typeof svc === 'object')
116
+ return true;
117
+ const properties = schema.properties ?? {};
118
+ for (const prop of Object.values(properties)) {
119
+ if (!prop)
120
+ continue;
121
+ if (prop.searchable || prop.filterable || prop.sortable)
122
+ return true;
123
+ if (prop.lookupable)
124
+ return true;
125
+ if (prop.defaultSort)
126
+ return true;
127
+ }
128
+ return false;
129
+ }
71
130
  /**
72
131
  * Print a deprecation warning (once per schema) for every legacy
73
132
  * `options.service.*` key that duplicates property-level metadata.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnifyjp/ts",
3
- "version": "3.23.0",
3
+ "version": "3.23.2",
4
4
  "description": "TypeScript model type generator from Omnify schemas.json",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",