prisma-laravel-migrate 3.0.2 → 3.0.3

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/README.md CHANGED
@@ -57,7 +57,8 @@ module.exports = {
57
57
  { stubFile: "audit.stub", tables: ["logs","audit_trails"] }
58
58
  ],
59
59
  outputEnumDir: "app/Enums",
60
- overwriteExisting: true
60
+ overwriteExisting: true,
61
+ allowedPivotExtraFields: ["scope"]
61
62
  }
62
63
  };
63
64
  ```
@@ -191,6 +192,8 @@ export interface ModelConfigOverride extends LaravelGeneratorConfig {
191
192
  outputEnumDir?: string;
192
193
  /** use awobaz/compoships */
193
194
  awobaz?: boolean;
195
+ /** Extra fields allowed on pivot models */
196
+ allowedPivotExtraFields?: string[];
194
197
  }
195
198
  ```
196
199
 
@@ -47,6 +47,7 @@ export async function generateLaravelModels(options) {
47
47
  enumStubPath: pick('enumStubPath'),
48
48
  modelStubPath: pick('modelStubPath'),
49
49
  noEmit: pick('noEmit', false),
50
+ allowedPivotExtraFields: pick('allowedPivotExtraFields', []),
50
51
  namespace: pick("namespace", "App")
51
52
  };
52
53
  addToConfig('model', cfg);
@@ -1,6 +1,6 @@
1
1
  import { objRels, scalarNames, getModel, dbNameOf, conventionalPivotName, getPrimaryKeyFields, hasIntersection, isUniqueOn, PIVOT_SCALAR_WHITELIST, } from "./types.js";
2
2
  import { detectMorphToRelations, parseMorphOwnerDirectives } from "./morph.js";
3
- import { isForModel, parseLocalDirective } from "../../../utils/utils.js";
3
+ import { getConfig, isForModel, parseLocalDirective } from "../../../utils/utils.js";
4
4
  /* ------------------ pivot relevance (explicit M:N) ----------------------- */
5
5
  const pivotOtherEndpointFor = (thisModelName, candidate) => {
6
6
  const rels = objRels(candidate);
@@ -17,7 +17,20 @@ const pivotOtherEndpointFor = (thisModelName, candidate) => {
17
17
  if (hasIntersection(fkA, fkB))
18
18
  return undefined;
19
19
  const fkUnion = new Set([...fkA, ...fkB]);
20
- const extras = scalarNames(candidate).filter((n) => !fkUnion.has(n) && !PIVOT_SCALAR_WHITELIST.has(n));
20
+ // May be: ["id", "meta", "created_at", ...] from your config
21
+ const extrasFromConfigRaw = getConfig("model", "allowedPivotExtraFields");
22
+ // Normalise to string[]
23
+ const extrasFromConfig = Array.isArray(extrasFromConfigRaw)
24
+ ? extrasFromConfigRaw
25
+ : extrasFromConfigRaw
26
+ ? [extrasFromConfigRaw]
27
+ : [];
28
+ // Combined whitelist: hard-coded + config
29
+ const allowedPivotScalars = new Set([
30
+ ...PIVOT_SCALAR_WHITELIST,
31
+ ...extrasFromConfig,
32
+ ]);
33
+ const extras = scalarNames(candidate).filter((n) => !fkUnion.has(n) && !allowedPivotScalars.has(n));
21
34
  if (extras.length > 0)
22
35
  return undefined;
23
36
  return relOther.type; // self-join allowed
@@ -12,6 +12,8 @@ export const PIVOT_SCALAR_WHITELIST = new Set([
12
12
  "createdAt",
13
13
  "updatedAt",
14
14
  "deletedAt",
15
+ "meta",
16
+ "extra",
15
17
  ]);
16
18
  export const getPrimaryKeyFields = (m) => {
17
19
  const pk = m.primaryKey?.fields;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-laravel-migrate",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "Generate laravel migrations and/or models using prisma files",
5
5
  "bin": {
6
6
  "prisma-laravel-migrations": "./dist/cli/migrator.index.js",