metal-orm 1.0.75 → 1.0.77

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metal-orm",
3
- "version": "1.0.75",
3
+ "version": "1.0.77",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "engines": {
@@ -218,6 +218,7 @@ const METAL_ORM_IMPORT_ORDER = [
218
218
  'BelongsToMany',
219
219
  'HasManyCollection',
220
220
  'HasOneReference',
221
+ 'BelongsToReference',
221
222
  'ManyToManyCollection',
222
223
  'bootstrapEntities',
223
224
  'getTableDefFromEntity'
@@ -250,7 +251,7 @@ const renderEntityClassLines = ({ table, className, naming, relations, resolveCl
250
251
  lines.push(
251
252
  ` @BelongsTo({ target: () => ${targetClass}, foreignKey: '${escapeJsString(rel.foreignKey)}' })`
252
253
  );
253
- lines.push(` ${rel.property}?: ${targetClass};`);
254
+ lines.push(` ${rel.property}!: BelongsToReference<${targetClass}>;`);
254
255
  lines.push('');
255
256
  break;
256
257
  case 'hasMany':
@@ -301,6 +302,7 @@ const computeTableUsage = (table, relations, defaultSchema) => {
301
302
  needsBelongsToManyDecorator: false,
302
303
  needsHasManyCollection: false,
303
304
  needsHasOneReference: false,
305
+ needsBelongsToReference: false,
304
306
  needsManyToManyCollection: false
305
307
  };
306
308
 
@@ -325,6 +327,7 @@ const computeTableUsage = (table, relations, defaultSchema) => {
325
327
  }
326
328
  if (rel.kind === 'belongsTo') {
327
329
  usage.needsBelongsToDecorator = true;
330
+ usage.needsBelongsToReference = true;
328
331
  }
329
332
  if (rel.kind === 'belongsToMany') {
330
333
  usage.needsBelongsToManyDecorator = true;
@@ -347,6 +350,7 @@ const getMetalOrmImportNamesFromUsage = usage => {
347
350
  if (usage.needsBelongsToManyDecorator) names.add('BelongsToMany');
348
351
  if (usage.needsHasManyCollection) names.add('HasManyCollection');
349
352
  if (usage.needsHasOneReference) names.add('HasOneReference');
353
+ if (usage.needsBelongsToReference) names.add('BelongsToReference');
350
354
  if (usage.needsManyToManyCollection) names.add('ManyToManyCollection');
351
355
  return names;
352
356
  };
@@ -386,6 +390,7 @@ export const renderEntityFile = (schema, options) => {
386
390
  needsBelongsToManyDecorator: false,
387
391
  needsHasManyCollection: false,
388
392
  needsHasOneReference: false,
393
+ needsBelongsToReference: false,
389
394
  needsManyToManyCollection: false
390
395
  };
391
396
 
@@ -401,6 +406,7 @@ export const renderEntityFile = (schema, options) => {
401
406
  aggregateUsage.needsBelongsToManyDecorator ||= tableUsage.needsBelongsToManyDecorator;
402
407
  aggregateUsage.needsHasManyCollection ||= tableUsage.needsHasManyCollection;
403
408
  aggregateUsage.needsHasOneReference ||= tableUsage.needsHasOneReference;
409
+ aggregateUsage.needsBelongsToReference ||= tableUsage.needsBelongsToReference;
404
410
  aggregateUsage.needsManyToManyCollection ||= tableUsage.needsManyToManyCollection;
405
411
  }
406
412
 
@@ -70,3 +70,17 @@ export const applyToCompoundHead = (term, { connectors, transformWord } = {}) =>
70
70
  return rebuildFromWords(out, format, original);
71
71
  };
72
72
 
73
+ export const applyToCompoundWords = (term, { connectors, transformWord } = {}) => {
74
+ if (!term || !String(term).trim()) return '';
75
+ const original = String(term).trim();
76
+ const format = detectTextFormat(original);
77
+ const words = splitIntoWords(original, format);
78
+
79
+ const out = words.map(word => {
80
+ const normalized = normalizeLookup(word);
81
+ if (connectors?.has?.(normalized)) return word;
82
+ return transformWord ? transformWord(word) : word;
83
+ });
84
+
85
+ return rebuildFromWords(out, format, original);
86
+ };
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  applyToCompoundHead,
3
+ applyToCompoundWords,
4
+ detectTextFormat,
3
5
  normalizeLookup,
6
+ splitIntoWords,
4
7
  stripDiacritics
5
8
  } from './compound.mjs';
6
9
 
@@ -172,6 +175,14 @@ export const PT_BR_CONNECTORS = Object.freeze(new Set(
172
175
  ].map(normalizeLookup)
173
176
  ));
174
177
 
178
+ const hasConnectorWord = (term, connectors) => {
179
+ if (!term || !String(term).trim()) return false;
180
+ const original = String(term).trim();
181
+ const format = detectTextFormat(original);
182
+ const words = splitIntoWords(original, format);
183
+ return words.some(word => connectors?.has?.(normalizeLookup(word)));
184
+ };
185
+
175
186
  // ═══════════════════════════════════════════════════════════════════════════
176
187
  // INFLECTION RULES
177
188
  // ═══════════════════════════════════════════════════════════════════════════
@@ -348,7 +359,10 @@ export const singularizeWordPtBr = (
348
359
  export const pluralizeRelationPropertyPtBr = (
349
360
  term,
350
361
  { pluralizeWord = pluralizeWordPtBr, connectors = PT_BR_CONNECTORS } = {}
351
- ) => applyToCompoundHead(term, { connectors, transformWord: pluralizeWord });
362
+ ) =>
363
+ hasConnectorWord(term, connectors)
364
+ ? applyToCompoundHead(term, { connectors, transformWord: pluralizeWord })
365
+ : applyToCompoundWords(term, { connectors, transformWord: pluralizeWord });
352
366
 
353
367
  /**
354
368
  * Singularizes a compound property/relation name in Portuguese.
@@ -356,7 +370,10 @@ export const pluralizeRelationPropertyPtBr = (
356
370
  export const singularizeRelationPropertyPtBr = (
357
371
  term,
358
372
  { singularizeWord = singularizeWordPtBr, connectors = PT_BR_CONNECTORS } = {}
359
- ) => applyToCompoundHead(term, { connectors, transformWord: singularizeWord });
373
+ ) =>
374
+ hasConnectorWord(term, connectors)
375
+ ? applyToCompoundHead(term, { connectors, transformWord: singularizeWord })
376
+ : applyToCompoundWords(term, { connectors, transformWord: singularizeWord });
360
377
 
361
378
  // ═══════════════════════════════════════════════════════════════════════════
362
379
  // INFLECTOR FACTORY
@@ -388,4 +405,4 @@ export const createPtBrInflector = ({ customIrregulars = {} } = {}) => {
388
405
  });
389
406
  };
390
407
 
391
- export default createPtBrInflector;
408
+ export default createPtBrInflector;