@omnifyjp/ts 1.2.6 → 1.3.0

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/cli.js CHANGED
@@ -53,6 +53,7 @@ function resolveFromConfig(configPath) {
53
53
  factory: laravelConfig?.factory,
54
54
  provider: laravelConfig?.provider,
55
55
  policy: laravelConfig?.policy,
56
+ nestedset: laravelConfig?.nestedset,
56
57
  } : undefined;
57
58
  return {
58
59
  input: resolve(configDir, schemasPath),
@@ -40,6 +40,7 @@ function generateBaseModel(name, schema, reader, config) {
40
40
  const isAuthenticatable = options['authenticatable'] ?? false;
41
41
  const hasSoftDelete = options.softDelete ?? false;
42
42
  const hasTimestamps = options.timestamps ?? false;
43
+ const hasNestedSet = options['nestedSet'] ?? false;
43
44
  const translatableFields = reader.getTranslatableFields(name);
44
45
  const hasTranslatable = translatableFields.length > 0;
45
46
  const primaryKey = options['primaryKey'] ?? 'id';
@@ -48,11 +49,11 @@ function generateBaseModel(name, schema, reader, config) {
48
49
  const isCompositeKey = primaryKey.includes(',');
49
50
  const needsUuidTrait = !isCompositeKey && idType === 'Uuid';
50
51
  const needsUlidTrait = !isCompositeKey && idType === 'Ulid';
51
- const imports = buildImports(baseNamespace, modelName, hasSoftDelete, isAuthenticatable, hasTranslatable, properties, needsUuidTrait, needsUlidTrait);
52
+ const imports = buildImports(baseNamespace, modelName, hasSoftDelete, isAuthenticatable, hasTranslatable, properties, needsUuidTrait, needsUlidTrait, hasNestedSet, config.nestedset.namespace);
52
53
  const docProperties = buildDocProperties(properties, expandedProperties, propertyOrder);
53
54
  const baseClass = isAuthenticatable ? 'Authenticatable' : 'BaseModel';
54
55
  const implementsClause = hasTranslatable ? ' implements TranslatableContract' : '';
55
- const traits = buildTraits(hasSoftDelete, isAuthenticatable, hasTranslatable, needsUuidTrait, needsUlidTrait);
56
+ const traits = buildTraits(hasSoftDelete, isAuthenticatable, hasTranslatable, needsUuidTrait, needsUlidTrait, hasNestedSet);
56
57
  const fillable = buildFillable(properties, expandedProperties, propertyOrder);
57
58
  const hidden = buildHidden(properties, expandedProperties, propertyOrder);
58
59
  const appends = buildAppends(expandedProperties);
@@ -199,7 +200,7 @@ class ${modelName} extends ${modelName}BaseModel
199
200
  `;
200
201
  return userFile(`${config.models.path}/${modelName}.php`, content);
201
202
  }
202
- function buildImports(baseNamespace, modelName, hasSoftDelete, isAuthenticatable, hasTranslatable, properties, needsUuidTrait = false, needsUlidTrait = false) {
203
+ function buildImports(baseNamespace, modelName, hasSoftDelete, isAuthenticatable, hasTranslatable, properties, needsUuidTrait = false, needsUlidTrait = false, hasNestedSet = false, nestedSetNamespace = 'Aimeos\\Nestedset') {
203
204
  const lines = [];
204
205
  if (isAuthenticatable) {
205
206
  lines.push('use Illuminate\\Foundation\\Auth\\User as Authenticatable;');
@@ -222,6 +223,9 @@ function buildImports(baseNamespace, modelName, hasSoftDelete, isAuthenticatable
222
223
  if (hasSoftDelete) {
223
224
  lines.push('use Illuminate\\Database\\Eloquent\\SoftDeletes;');
224
225
  }
226
+ if (hasNestedSet) {
227
+ lines.push(`use ${nestedSetNamespace}\\NodeTrait;`);
228
+ }
225
229
  if (hasTranslatable) {
226
230
  lines.push('use Astrotomic\\Translatable\\Contracts\\Translatable as TranslatableContract;');
227
231
  lines.push('use Astrotomic\\Translatable\\Translatable;');
@@ -262,7 +266,7 @@ function buildDocProperties(properties, expandedProperties, propertyOrder) {
262
266
  }
263
267
  return lines.length === 0 ? '' : lines.join('\n') + '\n';
264
268
  }
265
- function buildTraits(hasSoftDelete, isAuthenticatable, hasTranslatable, needsUuidTrait = false, needsUlidTrait = false) {
269
+ function buildTraits(hasSoftDelete, isAuthenticatable, hasTranslatable, needsUuidTrait = false, needsUlidTrait = false, hasNestedSet = false) {
266
270
  const lines = [];
267
271
  lines.push(' use HasLocalizedDisplayName;');
268
272
  if (needsUuidTrait)
@@ -271,6 +275,8 @@ function buildTraits(hasSoftDelete, isAuthenticatable, hasTranslatable, needsUui
271
275
  lines.push(' use HasUlids;');
272
276
  if (isAuthenticatable)
273
277
  lines.push(' use Notifiable;');
278
+ if (hasNestedSet)
279
+ lines.push(' use NodeTrait;');
274
280
  if (hasSoftDelete)
275
281
  lines.push(' use SoftDeletes;');
276
282
  if (hasTranslatable)
@@ -17,6 +17,10 @@ export interface LaravelPathOverride {
17
17
  path?: string;
18
18
  namespace?: string;
19
19
  }
20
+ /** Nested set package configuration. */
21
+ export interface NestedSetOverride {
22
+ namespace?: string;
23
+ }
20
24
  /** Overrides from codegen.laravel YAML config (all optional). */
21
25
  export interface LaravelCodegenOverrides {
22
26
  model?: LaravelPathOverride;
@@ -25,6 +29,7 @@ export interface LaravelCodegenOverrides {
25
29
  factory?: LaravelPathOverride;
26
30
  provider?: LaravelPathOverride;
27
31
  policy?: LaravelPathOverride;
32
+ nestedset?: NestedSetOverride;
28
33
  }
29
34
  /** PHP codegen configuration (resolved with defaults). */
30
35
  export interface PhpConfig {
@@ -60,6 +65,9 @@ export interface PhpConfig {
60
65
  path: string;
61
66
  basePath: string;
62
67
  };
68
+ nestedset: {
69
+ namespace: string;
70
+ };
63
71
  }
64
72
  /**
65
73
  * Derive full PHP config from optional overrides.
package/dist/php/types.js CHANGED
@@ -40,6 +40,7 @@ export function derivePhpConfig(overrides) {
40
40
  const providerNs = overrides?.provider?.namespace ?? pathToNamespace(providerPath);
41
41
  const policyPath = overrides?.policy?.path ?? DEFAULT_POLICY_PATH;
42
42
  const policyNs = overrides?.policy?.namespace ?? pathToNamespace(policyPath);
43
+ const nestedsetNs = overrides?.nestedset?.namespace ?? 'Aimeos\\Nestedset';
43
44
  return {
44
45
  models: {
45
46
  namespace: modelNs,
@@ -73,5 +74,8 @@ export function derivePhpConfig(overrides) {
73
74
  path: policyPath,
74
75
  basePath: `${policyPath}/Base`,
75
76
  },
77
+ nestedset: {
78
+ namespace: nestedsetNs,
79
+ },
76
80
  };
77
81
  }
package/dist/types.d.ts CHANGED
@@ -87,6 +87,7 @@ export interface SchemaOptions {
87
87
  readonly timestamps?: boolean;
88
88
  readonly softDelete?: boolean;
89
89
  readonly hidden?: boolean;
90
+ readonly nestedSet?: boolean;
90
91
  readonly tableName?: string;
91
92
  readonly indexes?: readonly unknown[];
92
93
  readonly unique?: readonly unknown[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnifyjp/ts",
3
- "version": "1.2.6",
3
+ "version": "1.3.0",
4
4
  "description": "TypeScript model type generator from Omnify schemas.json",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",