@memberjunction/standards 6.2.0-edge.5 → 6.2.0-edge.7
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 +2 -0
- package/dist/checks/migration-existence-guards.d.ts +27 -0
- package/dist/checks/migration-existence-guards.d.ts.map +1 -0
- package/dist/checks/migration-existence-guards.js +98 -0
- package/dist/checks/migration-existence-guards.js.map +1 -0
- package/dist/checks/polymorphic-fk.d.ts +72 -0
- package/dist/checks/polymorphic-fk.d.ts.map +1 -0
- package/dist/checks/polymorphic-fk.js +484 -0
- package/dist/checks/polymorphic-fk.js.map +1 -0
- package/dist/checks/readable-status-values.d.ts +32 -0
- package/dist/checks/readable-status-values.d.ts.map +1 -0
- package/dist/checks/readable-status-values.js +137 -0
- package/dist/checks/readable-status-values.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/migrations.d.ts +64 -0
- package/dist/lib/migrations.d.ts.map +1 -0
- package/dist/lib/migrations.js +148 -0
- package/dist/lib/migrations.js.map +1 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +10 -1
- package/dist/registry.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,6 +108,8 @@ Every registered standard, when it was introduced, and what this repo does with
|
|
|
108
108
|
|---|---|---|
|
|
109
109
|
| `ui-layers` | 6.0.0 | The four-layer UI architecture — [guide](https://github.com/MemberJunction/MJ/blob/next/guides/UI_LAYERING_GUIDE.md). Widgets may not import `@angular/router` or MJ Explorer, and may not construct a global-provider `RunView`/`Metadata`. Packages opt in with `"mjUILayer"` in their own `package.json`. |
|
|
110
110
|
| `naming-conventions` | 6.2.0 | MJ's inverted naming convention — [guide](https://github.com/MemberJunction/MJ/blob/next/guides/NAMING_CONVENTIONS_GUIDE.md). Public class members and the whole exported API surface are PascalCase — including the members of an exported interface, type literal or enum, and public constructor parameter properties; `private` members are camelCase. `protected` is exempt (MJ base classes declare PascalCase extension points). Framework contracts — Angular `ng*` hooks, oclif command members, base-class overrides, SCREAMING_SNAKE constants — are exempt automatically. Severity says whether a compatible fix exists: anything a `@deprecated` delegating stub can fix is an error; members of an exported data shape are a warn, since an interface has no runtime carrier for a stub (`enforceTypeMembers` opts into the type-only break). Anything tagged `@deprecated` is exempt. Marker: `case-violation-ok-legacy-back-compat`. |
|
|
111
|
+
| `migration-existence-guards` | 6.2.0 | Migration DDL is written plainly — [guide](https://github.com/MemberJunction/MJ/blob/next/guides/SCHEMA_AND_CODE_AUTHORING_GUIDE.md#migrations-are-plain-ddl). Flags `IF OBJECT_ID` / `IF COL_LENGTH` / `IF [NOT] EXISTS` over the catalog and `DROP … IF EXISTS` in the hand-written part of each versioned migration; CodeGen output below the separator is not read, nor is a CodeGen statement pasted without it (one under CodeGen's `/* SQL text to … */` header). Only migrations at or after the `FromVersion` option (a 12-digit timestamp) are read, because applied migrations cannot be edited. Marker: `mj-standards-allow: existence-guard`. |
|
|
112
|
+
| `readable-status-values` | 6.2.0 | CHECK-constrained values are written for people — [guide](https://github.com/MemberJunction/MJ/blob/next/guides/SCHEMA_AND_CODE_AUTHORING_GUIDE.md#value-lists-are-written-for-people). Flags run-together (`'OptedIn'`) and snake_case (`'OPTED_IN'`) values in `CHECK (… IN (…))` lists, in the same migrations as above. Defaults to `warn`. Proper names that are run together by design go in the `AllowedValues` option. Marker: `mj-standards-allow: status-value`. |
|
|
111
113
|
|
|
112
114
|
## Adding a standard
|
|
113
115
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The migration-existence-guards standard.
|
|
3
|
+
*
|
|
4
|
+
* A migration runs exactly once, in order, under Skyway's control. Wrapping its DDL in existence
|
|
5
|
+
* guards (`IF OBJECT_ID(...) IS NULL`, `IF COL_LENGTH(...) IS NULL`, `IF NOT EXISTS (SELECT … FROM
|
|
6
|
+
* sys.…)`) tries to make it idempotent, which it never needs to be. The cost is real: a guard turns
|
|
7
|
+
* a schema mismatch into a silent no-op instead of a failure, and the guarded form is harder for
|
|
8
|
+
* the PostgreSQL converter. AI tools write these by habit, so the rule is enforced rather than
|
|
9
|
+
* left to review.
|
|
10
|
+
*
|
|
11
|
+
* Only the hand-written part of each migration is read. CodeGen's appended output guards its own
|
|
12
|
+
* drops, and that is CodeGen's business; so is a CodeGen statement pasted without the separator,
|
|
13
|
+
* which still carries CodeGen's `/* SQL text to … *\/` header.
|
|
14
|
+
*
|
|
15
|
+
* @module @memberjunction/standards
|
|
16
|
+
*/
|
|
17
|
+
import type { StandardCheck } from '../types.js';
|
|
18
|
+
/** The reviewed-exception marker, on the guarded line or the line above it. */
|
|
19
|
+
export declare const EXISTENCE_GUARD_MARKER = "mj-standards-allow: existence-guard";
|
|
20
|
+
/**
|
|
21
|
+
* The 1-based lines in `code` (comment-stripped) that open an existence guard. `IF EXISTS` over
|
|
22
|
+
* ordinary data — "if any row still has the old value, update it" — is not a guard and is left alone.
|
|
23
|
+
*/
|
|
24
|
+
export declare function FindExistenceGuards(code: readonly string[]): number[];
|
|
25
|
+
/** The registered standard. */
|
|
26
|
+
export declare const MigrationExistenceGuardsCheck: StandardCheck;
|
|
27
|
+
//# sourceMappingURL=migration-existence-guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-existence-guards.d.ts","sourceRoot":"","sources":["../../src/checks/migration-existence-guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAA6B,aAAa,EAAa,MAAM,aAAa,CAAC;AAIvF,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,wCAAwC,CAAC;AA0B5E;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAcrE;AAwBD,+BAA+B;AAC/B,eAAO,MAAM,6BAA6B,EAAE,aAe3C,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The migration-existence-guards standard.
|
|
3
|
+
*
|
|
4
|
+
* A migration runs exactly once, in order, under Skyway's control. Wrapping its DDL in existence
|
|
5
|
+
* guards (`IF OBJECT_ID(...) IS NULL`, `IF COL_LENGTH(...) IS NULL`, `IF NOT EXISTS (SELECT … FROM
|
|
6
|
+
* sys.…)`) tries to make it idempotent, which it never needs to be. The cost is real: a guard turns
|
|
7
|
+
* a schema mismatch into a silent no-op instead of a failure, and the guarded form is harder for
|
|
8
|
+
* the PostgreSQL converter. AI tools write these by habit, so the rule is enforced rather than
|
|
9
|
+
* left to review.
|
|
10
|
+
*
|
|
11
|
+
* Only the hand-written part of each migration is read. CodeGen's appended output guards its own
|
|
12
|
+
* drops, and that is CodeGen's business; so is a CodeGen statement pasted without the separator,
|
|
13
|
+
* which still carries CodeGen's `/* SQL text to … *\/` header.
|
|
14
|
+
*
|
|
15
|
+
* @module @memberjunction/standards
|
|
16
|
+
*/
|
|
17
|
+
import { HasMarkerNear } from '../lib/markers.js';
|
|
18
|
+
import { FindMigrations, IsCodeGenStatement, StripSqlComments } from '../lib/migrations.js';
|
|
19
|
+
/** The reviewed-exception marker, on the guarded line or the line above it. */
|
|
20
|
+
export const EXISTENCE_GUARD_MARKER = 'mj-standards-allow: existence-guard';
|
|
21
|
+
/**
|
|
22
|
+
* Catalog functions whose only use in an `IF` is asking whether a schema object exists. The optional
|
|
23
|
+
* `(` carries its own whitespace so no two whitespace runs are adjacent (that backtracks badly).
|
|
24
|
+
*/
|
|
25
|
+
const CATALOG_FUNCTION_GUARD = /\bIF\s+(?:NOT\s+)?(?:\(\s*)?(OBJECT_ID|COL_LENGTH|TYPE_ID|SCHEMA_ID|INDEXPROPERTY|COLUMNPROPERTY|INDEXKEY_PROPERTY)\s*\(/i;
|
|
26
|
+
/** `IF [NOT] EXISTS (` — a guard only when its subquery reads the catalog; see {@link CATALOG_SOURCE}. */
|
|
27
|
+
const EXISTS_GUARD = /\bIF\s+(?:NOT\s+)?EXISTS\s*\(/i;
|
|
28
|
+
/** What an existence subquery reads when it is asking about schema rather than data, bracketed or not. */
|
|
29
|
+
const CATALOG_SOURCE = /(?:\bsys|\[sys\])\s*\.|(?:\bINFORMATION_SCHEMA|\[INFORMATION_SCHEMA\])\s*\.|fn_listextendedproperty/i;
|
|
30
|
+
/** `DROP <object> IF EXISTS` — the same guard in its SQL Server 2016 spelling. */
|
|
31
|
+
const DROP_IF_EXISTS = /\bDROP\s+(?:TABLE|VIEW|PROCEDURE|PROC|FUNCTION|INDEX|TRIGGER|TYPE|SCHEMA|CONSTRAINT|COLUMN|SEQUENCE|SYNONYM)\s+IF\s+EXISTS\b/i;
|
|
32
|
+
/**
|
|
33
|
+
* A temp table (`#work`, `tempdb..#work`). Cleaning one up is not schema idempotency: the table
|
|
34
|
+
* belongs to the session, and dropping it only if present is the normal way to do it.
|
|
35
|
+
*/
|
|
36
|
+
const TEMP_TABLE = /tempdb\.\.|['\s(\[]#/i;
|
|
37
|
+
/** How many lines an `IF EXISTS (` subquery is followed for, to find what it reads. */
|
|
38
|
+
const SUBQUERY_LOOKAHEAD = 6;
|
|
39
|
+
/**
|
|
40
|
+
* The 1-based lines in `code` (comment-stripped) that open an existence guard. `IF EXISTS` over
|
|
41
|
+
* ordinary data — "if any row still has the old value, update it" — is not a guard and is left alone.
|
|
42
|
+
*/
|
|
43
|
+
export function FindExistenceGuards(code) {
|
|
44
|
+
const found = [];
|
|
45
|
+
for (let i = 0; i < code.length; i++) {
|
|
46
|
+
const line = code[i];
|
|
47
|
+
if (CATALOG_FUNCTION_GUARD.test(line) || DROP_IF_EXISTS.test(line)) {
|
|
48
|
+
if (!TEMP_TABLE.test(line))
|
|
49
|
+
found.push(i + 1);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (EXISTS_GUARD.test(line)) {
|
|
53
|
+
const window = code.slice(i, i + SUBQUERY_LOOKAHEAD).join(' ');
|
|
54
|
+
if (CATALOG_SOURCE.test(window))
|
|
55
|
+
found.push(i + 1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return found;
|
|
59
|
+
}
|
|
60
|
+
/** Find existence guards in the hand-written part of every migration since the cutoff. */
|
|
61
|
+
function run(context) {
|
|
62
|
+
const fromVersion = String(context.Options['FromVersion'] ?? '');
|
|
63
|
+
const { Migrations, Notes } = FindMigrations(context.RepoRoot, context.Roots, fromVersion);
|
|
64
|
+
const violations = [];
|
|
65
|
+
for (const migration of Migrations) {
|
|
66
|
+
const handWritten = migration.Lines.slice(0, migration.HandWrittenLineCount);
|
|
67
|
+
for (const line of FindExistenceGuards(StripSqlComments(handWritten))) {
|
|
68
|
+
if (HasMarkerNear(migration.Lines, line, EXISTENCE_GUARD_MARKER))
|
|
69
|
+
continue;
|
|
70
|
+
if (IsCodeGenStatement(migration.Lines, line))
|
|
71
|
+
continue;
|
|
72
|
+
violations.push({
|
|
73
|
+
File: migration.File,
|
|
74
|
+
Line: line,
|
|
75
|
+
Message: 'existence guard in a migration. Migrations run exactly once, in order, so write the DDL plainly: ' +
|
|
76
|
+
'drop the IF OBJECT_ID / IF COL_LENGTH / IF NOT EXISTS wrapper (descriptions included).',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { Violations: violations, Notes: [...Notes, `${Migrations.length} migration(s) at or after ${fromVersion || '(no cutoff)'} read.`] };
|
|
81
|
+
}
|
|
82
|
+
/** The registered standard. */
|
|
83
|
+
export const MigrationExistenceGuardsCheck = {
|
|
84
|
+
Id: 'migration-existence-guards',
|
|
85
|
+
Title: 'Write migration DDL plainly, with no existence guards',
|
|
86
|
+
Since: '6.2.0',
|
|
87
|
+
DefaultSeverity: 'error',
|
|
88
|
+
DocsUrl: 'https://github.com/MemberJunction/MJ/blob/next/guides/SCHEMA_AND_CODE_AUTHORING_GUIDE.md#migrations-are-plain-ddl',
|
|
89
|
+
Description: 'Flags IF OBJECT_ID / IF COL_LENGTH / IF [NOT] EXISTS (catalog) guards and DROP … IF EXISTS in the hand-written ' +
|
|
90
|
+
'part of every versioned migration at or after the FromVersion option. Migrations run exactly once under ' +
|
|
91
|
+
'Skyway, so a guard only hides schema drift and complicates the PostgreSQL conversion. CodeGen output below ' +
|
|
92
|
+
"the separator is not read, nor is a CodeGen statement pasted without it (under CodeGen's \"/* SQL text to … */\" header). " +
|
|
93
|
+
`Reviewed exception: "${EXISTENCE_GUARD_MARKER}" on the line or the one above.`,
|
|
94
|
+
DefaultRoots: ['migrations'],
|
|
95
|
+
DefaultOptions: { FromVersion: '202610210000' },
|
|
96
|
+
Run: run,
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=migration-existence-guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-existence-guards.js","sourceRoot":"","sources":["../../src/checks/migration-existence-guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE5F,+EAA+E;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,qCAAqC,CAAC;AAE5E;;;GAGG;AACH,MAAM,sBAAsB,GAAG,2HAA2H,CAAC;AAE3J,0GAA0G;AAC1G,MAAM,YAAY,GAAG,gCAAgC,CAAC;AAEtD,0GAA0G;AAC1G,MAAM,cAAc,GAAG,sGAAsG,CAAC;AAE9H,kFAAkF;AAClF,MAAM,cAAc,GAAG,+HAA+H,CAAC;AAEvJ;;;GAGG;AACH,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C,uFAAuF;AACvF,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAuB;IACvD,MAAM,KAAK,GAAa,EAAE,CAAC;I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,IAAI,IAAI,mBAAmB,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;YACpE,IAAI,aAAa,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,sBAAsB,CAAC;gBAAE,SAAS;YAC3E,IAAI,kBAAkB,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC;gBAAE,SAAS;YACxD,UAAU,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,SAAS,CAAC,IAAI;gBACpB,IAAI,EAAE,IAAI;gBACV,OAAO,EACH,mGAAmG;oBACnG,wFAAwF;aAC/F,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,UAAU,CAAC,MAAM,6BAA6B,WAAW,IAAI,aAAa,QAAQ,CAAC,EAAE,CAAC;AAChJ,CAAC;AAED,+BAA+B;AAC/B,MAAM,CAAC,MAAM,6BAA6B,GAAkB;IACxD,EAAE,EAAE,4BAA4B;IAChC,KAAK,EAAE,uDAAuD;IAC9D,KAAK,EAAE,OAAO;IACd,eAAe,EAAE,OAAO;IACxB,OAAO,EAAE,mHAAmH;IAC5H,WAAW,EACP,iHAAiH;QACjH,0GAA0G;QAC1G,6GAA6G;QAC7G,4HAA4H;QAC5H,wBAAwB,sBAAsB,iCAAiC;IACnF,YAAY,EAAE,CAAC,YAAY,CAAC;IAC5B,cAAc,EAAE,EAAE,WAAW,EAAE,cAAc,EAAE;IAC/C,GAAG,EAAE,GAAG;CACX,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The polymorphic foreign-key metadata standard (Rule 2e).
|
|
3
|
+
*
|
|
4
|
+
* Enforces that every polymorphic foreign-key pair on an entity (`EntityID` + `RecordID`,
|
|
5
|
+
* `SourceEntityID` + `SourceRecordID`, `TargetEntityID` + `TargetRecordID`,
|
|
6
|
+
* `LinkedEntityID` + `LinkedRecordID`, `PrimaryScopeEntityID` + `PrimaryScopeRecordID`, etc.)
|
|
7
|
+
* is explicitly decorated in `metadata/entities/` with `EntityField.EntityIDFieldName` pointing
|
|
8
|
+
* to its companion `MJ: Entities` foreign-key column.
|
|
9
|
+
*
|
|
10
|
+
* ## Why this check exists
|
|
11
|
+
*
|
|
12
|
+
* MemberJunction forms (`<mj-form-field>`), grids (`<mj-entity-data-grid>`), cards, and record
|
|
13
|
+
* detail panels use `EntityField.EntityIDFieldName` to resolve polymorphic `RecordID` values into
|
|
14
|
+
* human-readable record names, entity icons, and clickable deep links — without ever guessing by
|
|
15
|
+
* column-name heuristics at runtime (an entity can have multiple polymorphic pairs such as
|
|
16
|
+
* `SourceEntityID`/`SourceRecordID` and `TargetEntityID`/`TargetRecordID`).
|
|
17
|
+
*
|
|
18
|
+
* When a migration adds a new table with a polymorphic `(EntityID, RecordID)` pair and CodeGen
|
|
19
|
+
* regenerates `generated/entities/*.ts`, forgetting the metadata entry in
|
|
20
|
+
* `metadata/entities/.polymorphic-fk-entity-fields.json` silently degrades the UI to raw UUIDs.
|
|
21
|
+
*
|
|
22
|
+
* This check settles both halves statically in CI:
|
|
23
|
+
* 1. **Forward check (CodeGen schema → Metadata)**: Every non-PK, non-FK `*RecordID` /
|
|
24
|
+
* `*RecordPrimaryKey` field on an entity that also has an `MJ: Entities` FK column must have an
|
|
25
|
+
* `EntityIDFieldName` declaration in `metadata/`.
|
|
26
|
+
* 2. **Reverse check (Metadata → CodeGen schema)**: Every `EntityIDFieldName` declaration in
|
|
27
|
+
* `metadata/` for an entity in this repo must name a real record-ID field and a real companion
|
|
28
|
+
* field whose `RelatedEntity` is `MJ: Entities`.
|
|
29
|
+
*
|
|
30
|
+
* @module @memberjunction/standards
|
|
31
|
+
*/
|
|
32
|
+
import type { StandardCheck } from '../types.js';
|
|
33
|
+
/** Parsed representation of a single field from a generated Zod entity schema. */
|
|
34
|
+
export interface GeneratedFieldDescriptor {
|
|
35
|
+
Name: string;
|
|
36
|
+
SqlDataType: string | null;
|
|
37
|
+
RelatedEntity: string | null;
|
|
38
|
+
File: string;
|
|
39
|
+
Line: number;
|
|
40
|
+
}
|
|
41
|
+
/** Parsed representation of an entity from a generated Zod entity schema file. */
|
|
42
|
+
export interface GeneratedEntityDescriptor {
|
|
43
|
+
Name: string;
|
|
44
|
+
Fields: Map<string, GeneratedFieldDescriptor>;
|
|
45
|
+
File: string;
|
|
46
|
+
Line: number;
|
|
47
|
+
}
|
|
48
|
+
/** Parsed representation of a metadata `EntityIDFieldName` declaration. */
|
|
49
|
+
export interface MetadataPolymorphicDeclaration {
|
|
50
|
+
EntityName: string;
|
|
51
|
+
FieldName: string;
|
|
52
|
+
EntityIDFieldName: string;
|
|
53
|
+
File: string;
|
|
54
|
+
Line: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Parse all generated Zod entity schemas in a TypeScript file using linear
|
|
58
|
+
* indexOf-based scanning (guaranteed O(N) time with zero regex backtracking).
|
|
59
|
+
*/
|
|
60
|
+
export declare function ParseGeneratedEntitiesFromSource(source: string, repoRelativeFile: string): GeneratedEntityDescriptor[];
|
|
61
|
+
/**
|
|
62
|
+
* Extract all `EntityIDFieldName` declarations from a metadata JSON file.
|
|
63
|
+
*/
|
|
64
|
+
export declare function ParseMetadataPolymorphicDeclarations(rawJson: string, repoRelativeFile: string): MetadataPolymorphicDeclaration[];
|
|
65
|
+
/**
|
|
66
|
+
* Suggest the most likely companion `EntityID` field name on the same entity for a given
|
|
67
|
+
* polymorphic `RecordID` field name.
|
|
68
|
+
*/
|
|
69
|
+
export declare function SuggestCompanionEntityIDField(recordFieldName: string, entityFKFields: GeneratedFieldDescriptor[]): string;
|
|
70
|
+
/** The registered polymorphic foreign-key standard. */
|
|
71
|
+
export declare const PolymorphicFKCheck: StandardCheck;
|
|
72
|
+
//# sourceMappingURL=polymorphic-fk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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|
1
|
+
/**
|
|
2
|
+
* @fileoverview The polymorphic foreign-key metadata standard (Rule 2e).
|
|
3
|
+
*
|
|
4
|
+
* Enforces that every polymorphic foreign-key pair on an entity (`EntityID` + `RecordID`,
|
|
5
|
+
* `SourceEntityID` + `SourceRecordID`, `TargetEntityID` + `TargetRecordID`,
|
|
6
|
+
* `LinkedEntityID` + `LinkedRecordID`, `PrimaryScopeEntityID` + `PrimaryScopeRecordID`, etc.)
|
|
7
|
+
* is explicitly decorated in `metadata/entities/` with `EntityField.EntityIDFieldName` pointing
|
|
8
|
+
* to its companion `MJ: Entities` foreign-key column.
|
|
9
|
+
*
|
|
10
|
+
* ## Why this check exists
|
|
11
|
+
*
|
|
12
|
+
* MemberJunction forms (`<mj-form-field>`), grids (`<mj-entity-data-grid>`), cards, and record
|
|
13
|
+
* detail panels use `EntityField.EntityIDFieldName` to resolve polymorphic `RecordID` values into
|
|
14
|
+
* human-readable record names, entity icons, and clickable deep links — without ever guessing by
|
|
15
|
+
* column-name heuristics at runtime (an entity can have multiple polymorphic pairs such as
|
|
16
|
+
* `SourceEntityID`/`SourceRecordID` and `TargetEntityID`/`TargetRecordID`).
|
|
17
|
+
*
|
|
18
|
+
* When a migration adds a new table with a polymorphic `(EntityID, RecordID)` pair and CodeGen
|
|
19
|
+
* regenerates `generated/entities/*.ts`, forgetting the metadata entry in
|
|
20
|
+
* `metadata/entities/.polymorphic-fk-entity-fields.json` silently degrades the UI to raw UUIDs.
|
|
21
|
+
*
|
|
22
|
+
* This check settles both halves statically in CI:
|
|
23
|
+
* 1. **Forward check (CodeGen schema → Metadata)**: Every non-PK, non-FK `*RecordID` /
|
|
24
|
+
* `*RecordPrimaryKey` field on an entity that also has an `MJ: Entities` FK column must have an
|
|
25
|
+
* `EntityIDFieldName` declaration in `metadata/`.
|
|
26
|
+
* 2. **Reverse check (Metadata → CodeGen schema)**: Every `EntityIDFieldName` declaration in
|
|
27
|
+
* `metadata/` for an entity in this repo must name a real record-ID field and a real companion
|
|
28
|
+
* field whose `RelatedEntity` is `MJ: Entities`.
|
|
29
|
+
*
|
|
30
|
+
* @module @memberjunction/standards
|
|
31
|
+
*/
|
|
32
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
33
|
+
import { join, relative } from 'node:path';
|
|
34
|
+
import { HasMarkerNear } from '../lib/markers.js';
|
|
35
|
+
const SKIP_DIRS = new Set([
|
|
36
|
+
'node_modules',
|
|
37
|
+
'dist',
|
|
38
|
+
'build',
|
|
39
|
+
'.git',
|
|
40
|
+
'.angular',
|
|
41
|
+
'coverage',
|
|
42
|
+
'.claude',
|
|
43
|
+
'.turbo',
|
|
44
|
+
]);
|
|
45
|
+
const ALLOW_MARKER = 'mj-polymorphic-fk-allow';
|
|
46
|
+
/**
|
|
47
|
+
* Matches polymorphic record-identifier column names (`RecordID`, `SourceRecordID`,
|
|
48
|
+
* `TargetRecordID`, `LinkedRecordID`, `EntityRecordID`, `LinkedEntityRecordID`,
|
|
49
|
+
* `PrimaryScopeRecordID`, `LinkedRecordPrimaryKey`, etc.) while excluding plural list columns
|
|
50
|
+
* (`ExcludedRecordIDs`) and third-party external-system ID columns (`ExternalSystemRecordID`,
|
|
51
|
+
* `ExternalRecordID`).
|
|
52
|
+
*/
|
|
53
|
+
const POLYMORPHIC_RECORD_FIELD_PATTERN = /^(?:[A-Z][A-Za-z0-9]*?)?Record(?:ID|PrimaryKey)$/;
|
|
54
|
+
const EXTERNAL_SYSTEM_RECORD_FIELD_PATTERN = /^External(?:System)?Record(?:ID|PrimaryKey)$/i;
|
|
55
|
+
/** Build a sorted array of 0-based newline offsets for O(log N) 1-based line lookup. */
|
|
56
|
+
function buildLineIndex(source) {
|
|
57
|
+
const starts = [0];
|
|
58
|
+
for (let i = 0; i < source.length; i++) {
|
|
59
|
+
if (source.charCodeAt(i) === 10)
|
|
60
|
+
starts.push(i + 1);
|
|
61
|
+
}
|
|
62
|
+
return starts;
|
|
63
|
+
}
|
|
64
|
+
/** Convert a 0-based character offset into a 1-based line number using a prebuilt line index. */
|
|
65
|
+
function lineAtOffset(lineStarts, offset) {
|
|
66
|
+
let lo = 0;
|
|
67
|
+
let hi = lineStarts.length - 1;
|
|
68
|
+
while (lo <= hi) {
|
|
69
|
+
const mid = (lo + hi) >>> 1;
|
|
70
|
+
if (lineStarts[mid] <= offset) {
|
|
71
|
+
lo = mid + 1;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
hi = mid - 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return hi + 1;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Collect all generated entity TypeScript files (`generated/entities/*.ts`) under `dir`.
|
|
81
|
+
*/
|
|
82
|
+
function findGeneratedEntityFiles(dir) {
|
|
83
|
+
const found = [];
|
|
84
|
+
const walk = (current, inGeneratedEntities) => {
|
|
85
|
+
let entries;
|
|
86
|
+
try {
|
|
87
|
+
entries = readdirSync(current, { withFileTypes: true });
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
for (const entry of entries) {
|
|
93
|
+
if (SKIP_DIRS.has(entry.name))
|
|
94
|
+
continue;
|
|
95
|
+
const full = join(current, entry.name);
|
|
96
|
+
if (entry.isDirectory()) {
|
|
97
|
+
const nextInGen = inGeneratedEntities ||
|
|
98
|
+
(entry.name === 'entities' && current.endsWith(`${join('src', 'generated')}`)) ||
|
|
99
|
+
(entry.name === 'entities' && current.endsWith('generated'));
|
|
100
|
+
walk(full, nextInGen);
|
|
101
|
+
}
|
|
102
|
+
else if (entry.isFile() &&
|
|
103
|
+
inGeneratedEntities &&
|
|
104
|
+
entry.name.endsWith('.ts') &&
|
|
105
|
+
!entry.name.endsWith('.d.ts')) {
|
|
106
|
+
found.push(full);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
walk(dir, false);
|
|
111
|
+
return found;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Collect all `.json` files under `dir`.
|
|
115
|
+
*/
|
|
116
|
+
function findJsonFiles(dir) {
|
|
117
|
+
const found = [];
|
|
118
|
+
if (!existsSync(dir))
|
|
119
|
+
return found;
|
|
120
|
+
const walk = (current) => {
|
|
121
|
+
let entries;
|
|
122
|
+
try {
|
|
123
|
+
entries = readdirSync(current, { withFileTypes: true });
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
for (const entry of entries) {
|
|
129
|
+
if (SKIP_DIRS.has(entry.name))
|
|
130
|
+
continue;
|
|
131
|
+
const full = join(current, entry.name);
|
|
132
|
+
if (entry.isDirectory()) {
|
|
133
|
+
walk(full);
|
|
134
|
+
}
|
|
135
|
+
else if (entry.isFile() && entry.name.endsWith('.json')) {
|
|
136
|
+
found.push(full);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
walk(dir);
|
|
141
|
+
return found;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Parse all generated Zod entity schemas in a TypeScript file using linear
|
|
145
|
+
* indexOf-based scanning (guaranteed O(N) time with zero regex backtracking).
|
|
146
|
+
*/
|
|
147
|
+
export function ParseGeneratedEntitiesFromSource(source, repoRelativeFile) {
|
|
148
|
+
const results = [];
|
|
149
|
+
const lineStarts = buildLineIndex(source);
|
|
150
|
+
const headerMarker = 'zod schema definition for the entity ';
|
|
151
|
+
const describeOpen = '.describe(`';
|
|
152
|
+
const describeClose = '`)';
|
|
153
|
+
const relatedMarker = 'Related Entity/Foreign Key:';
|
|
154
|
+
const sqlTypeMarker = 'SQL Data Type:';
|
|
155
|
+
let searchPos = 0;
|
|
156
|
+
while (searchPos < source.length) {
|
|
157
|
+
const markerIdx = source.indexOf(headerMarker, searchPos);
|
|
158
|
+
if (markerIdx === -1)
|
|
159
|
+
break;
|
|
160
|
+
const nameStart = markerIdx + headerMarker.length;
|
|
161
|
+
const lineEnd = source.indexOf('\n', nameStart);
|
|
162
|
+
if (lineEnd === -1)
|
|
163
|
+
break;
|
|
164
|
+
const entityName = source.slice(nameStart, lineEnd).replace(/\r$/, '').trim();
|
|
165
|
+
const commentStart = source.lastIndexOf('/**', markerIdx);
|
|
166
|
+
const blockStartOffset = commentStart >= 0 ? commentStart : markerIdx;
|
|
167
|
+
const entityLine = lineAtOffset(lineStarts, blockStartOffset);
|
|
168
|
+
const objOpenMarker = 'z.object({';
|
|
169
|
+
const objOpenIdx = source.indexOf(objOpenMarker, lineEnd);
|
|
170
|
+
if (objOpenIdx === -1)
|
|
171
|
+
break;
|
|
172
|
+
const bodyStartOffset = objOpenIdx + objOpenMarker.length;
|
|
173
|
+
const objCloseIdx = source.indexOf('\n});', bodyStartOffset);
|
|
174
|
+
if (objCloseIdx === -1)
|
|
175
|
+
break;
|
|
176
|
+
const fields = new Map();
|
|
177
|
+
let fieldCursor = bodyStartOffset;
|
|
178
|
+
while (fieldCursor < objCloseIdx) {
|
|
179
|
+
const descIdx = source.indexOf(describeOpen, fieldCursor);
|
|
180
|
+
if (descIdx === -1 || descIdx >= objCloseIdx)
|
|
181
|
+
break;
|
|
182
|
+
const descContentStart = descIdx + describeOpen.length;
|
|
183
|
+
const descEndIdx = source.indexOf(describeClose, descContentStart);
|
|
184
|
+
if (descEndIdx === -1 || descEndIdx > objCloseIdx)
|
|
185
|
+
break;
|
|
186
|
+
// Walk backward from descIdx to find the start of the field line (` FieldName: z.`)
|
|
187
|
+
let fieldLineStart = fieldCursor;
|
|
188
|
+
let scanLine = source.lastIndexOf('\n', descIdx);
|
|
189
|
+
while (scanLine >= bodyStartOffset) {
|
|
190
|
+
const candidateLineStart = scanLine + 1;
|
|
191
|
+
const colonIdx = source.indexOf(':', candidateLineStart);
|
|
192
|
+
if (colonIdx !== -1 && colonIdx < descIdx) {
|
|
193
|
+
const prefix = source.slice(candidateLineStart, colonIdx);
|
|
194
|
+
const trimmedPrefix = prefix.trim();
|
|
195
|
+
if (prefix.startsWith(' ') &&
|
|
196
|
+
!prefix.startsWith(' ') &&
|
|
197
|
+
isIdentifierToken(trimmedPrefix) &&
|
|
198
|
+
source.slice(colonIdx + 1, descIdx).trimStart().startsWith('z.')) {
|
|
199
|
+
fieldLineStart = candidateLineStart;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
scanLine = source.lastIndexOf('\n', scanLine - 1);
|
|
204
|
+
}
|
|
205
|
+
const colonPos = source.indexOf(':', fieldLineStart);
|
|
206
|
+
if (colonPos !== -1 && colonPos < descIdx) {
|
|
207
|
+
const fieldName = source.slice(fieldLineStart, colonPos).trim();
|
|
208
|
+
if (isIdentifierToken(fieldName)) {
|
|
209
|
+
const desc = source.slice(descContentStart, descEndIdx);
|
|
210
|
+
const { sqlDataType, relatedEntity } = extractDescribeMetadata(desc, relatedMarker, sqlTypeMarker);
|
|
211
|
+
const fieldLine = lineAtOffset(lineStarts, fieldLineStart);
|
|
212
|
+
fields.set(fieldName, {
|
|
213
|
+
Name: fieldName,
|
|
214
|
+
SqlDataType: sqlDataType,
|
|
215
|
+
RelatedEntity: relatedEntity,
|
|
216
|
+
File: repoRelativeFile,
|
|
217
|
+
Line: fieldLine,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
fieldCursor = descEndIdx + describeClose.length;
|
|
222
|
+
}
|
|
223
|
+
results.push({
|
|
224
|
+
Name: entityName,
|
|
225
|
+
Fields: fields,
|
|
226
|
+
File: repoRelativeFile,
|
|
227
|
+
Line: entityLine,
|
|
228
|
+
});
|
|
229
|
+
searchPos = objCloseIdx + 4;
|
|
230
|
+
}
|
|
231
|
+
return results;
|
|
232
|
+
}
|
|
233
|
+
function isIdentifierToken(value) {
|
|
234
|
+
if (value.length === 0)
|
|
235
|
+
return false;
|
|
236
|
+
for (let i = 0; i < value.length; i++) {
|
|
237
|
+
const ch = value.charCodeAt(i);
|
|
238
|
+
const isAlphaNum = (ch >= 48 && ch <= 57) ||
|
|
239
|
+
(ch >= 65 && ch <= 90) ||
|
|
240
|
+
(ch >= 97 && ch <= 122) ||
|
|
241
|
+
ch === 95;
|
|
242
|
+
if (!isAlphaNum)
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
function extractDescribeMetadata(desc, relatedMarker, sqlTypeMarker) {
|
|
248
|
+
let sqlDataType = null;
|
|
249
|
+
let relatedEntity = null;
|
|
250
|
+
const lines = desc.split('\n');
|
|
251
|
+
for (const rawLine of lines) {
|
|
252
|
+
const relIdx = rawLine.indexOf(relatedMarker);
|
|
253
|
+
if (relIdx !== -1) {
|
|
254
|
+
const after = rawLine.slice(relIdx + relatedMarker.length);
|
|
255
|
+
const parenIdx = after.indexOf('(');
|
|
256
|
+
relatedEntity = (parenIdx !== -1 ? after.slice(0, parenIdx) : after).trim() || null;
|
|
257
|
+
}
|
|
258
|
+
const sqlIdx = rawLine.indexOf(sqlTypeMarker);
|
|
259
|
+
if (sqlIdx !== -1) {
|
|
260
|
+
sqlDataType = rawLine.slice(sqlIdx + sqlTypeMarker.length).trim() || null;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return { sqlDataType, relatedEntity };
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Extract all `EntityIDFieldName` declarations from a metadata JSON file.
|
|
267
|
+
*/
|
|
268
|
+
export function ParseMetadataPolymorphicDeclarations(rawJson, repoRelativeFile) {
|
|
269
|
+
const declarations = [];
|
|
270
|
+
if (!rawJson.includes('EntityIDFieldName'))
|
|
271
|
+
return declarations;
|
|
272
|
+
let parsed;
|
|
273
|
+
try {
|
|
274
|
+
parsed = JSON.parse(rawJson);
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
return declarations;
|
|
278
|
+
}
|
|
279
|
+
const records = Array.isArray(parsed) ? parsed : [parsed];
|
|
280
|
+
for (const record of records) {
|
|
281
|
+
if (!record || typeof record !== 'object')
|
|
282
|
+
continue;
|
|
283
|
+
const recObj = record;
|
|
284
|
+
const entityName = typeof recObj.fields?.Name === 'string' ? recObj.fields.Name.trim() : null;
|
|
285
|
+
if (!entityName)
|
|
286
|
+
continue;
|
|
287
|
+
const entityFields = recObj.relatedEntities?.['MJ: Entity Fields'];
|
|
288
|
+
if (!Array.isArray(entityFields))
|
|
289
|
+
continue;
|
|
290
|
+
for (const ef of entityFields) {
|
|
291
|
+
if (!ef || typeof ef !== 'object')
|
|
292
|
+
continue;
|
|
293
|
+
const efObj = ef;
|
|
294
|
+
const entityIDFieldName = typeof efObj.fields?.EntityIDFieldName === 'string'
|
|
295
|
+
? efObj.fields.EntityIDFieldName.trim()
|
|
296
|
+
: null;
|
|
297
|
+
if (!entityIDFieldName)
|
|
298
|
+
continue;
|
|
299
|
+
let fieldName = typeof efObj.fields?.Name === 'string' ? efObj.fields.Name.trim() : null;
|
|
300
|
+
if (!fieldName && typeof efObj.primaryKey?.ID === 'string') {
|
|
301
|
+
const lookupMatch = /[?&]Name=([^&\s"]+)/.exec(efObj.primaryKey.ID);
|
|
302
|
+
if (lookupMatch)
|
|
303
|
+
fieldName = lookupMatch[1].trim();
|
|
304
|
+
}
|
|
305
|
+
if (!fieldName)
|
|
306
|
+
continue;
|
|
307
|
+
// Approximate 1-based line number of the declaration in the JSON file
|
|
308
|
+
const entityIdx = rawJson.indexOf(`"${entityName}"`);
|
|
309
|
+
const fieldIdx = entityIdx >= 0 ? rawJson.indexOf(fieldName, entityIdx) : rawJson.indexOf(fieldName);
|
|
310
|
+
const line = fieldIdx >= 0 ? rawJson.slice(0, fieldIdx).split('\n').length : 1;
|
|
311
|
+
declarations.push({
|
|
312
|
+
EntityName: entityName,
|
|
313
|
+
FieldName: fieldName,
|
|
314
|
+
EntityIDFieldName: entityIDFieldName,
|
|
315
|
+
File: repoRelativeFile,
|
|
316
|
+
Line: line,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return declarations;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Suggest the most likely companion `EntityID` field name on the same entity for a given
|
|
324
|
+
* polymorphic `RecordID` field name.
|
|
325
|
+
*/
|
|
326
|
+
export function SuggestCompanionEntityIDField(recordFieldName, entityFKFields) {
|
|
327
|
+
if (entityFKFields.length === 1) {
|
|
328
|
+
return entityFKFields[0].Name;
|
|
329
|
+
}
|
|
330
|
+
const prefix = recordFieldName
|
|
331
|
+
.replace(/EntityRecord(?:ID|PrimaryKey)$/, '')
|
|
332
|
+
.replace(/Record(?:ID|PrimaryKey)$/, '');
|
|
333
|
+
const exactCandidate = `${prefix}EntityID`;
|
|
334
|
+
const match = entityFKFields.find((f) => f.Name.toLowerCase() === exactCandidate.toLowerCase());
|
|
335
|
+
if (match)
|
|
336
|
+
return match.Name;
|
|
337
|
+
return entityFKFields.map((f) => f.Name).join(' or ');
|
|
338
|
+
}
|
|
339
|
+
/** The registered polymorphic foreign-key standard. */
|
|
340
|
+
export const PolymorphicFKCheck = {
|
|
341
|
+
Id: 'polymorphic-fk',
|
|
342
|
+
Title: 'Polymorphic foreign-key pairs must declare EntityField.EntityIDFieldName in metadata',
|
|
343
|
+
Since: '6.2.0',
|
|
344
|
+
DefaultSeverity: 'error',
|
|
345
|
+
DocsUrl: 'https://github.com/MemberJunction/MJ/blob/next/AGENTS.md',
|
|
346
|
+
Description: 'Every polymorphic foreign-key column pair (e.g. EntityID + RecordID, SourceEntityID + SourceRecordID, ' +
|
|
347
|
+
'TargetEntityID + TargetRecordID) must populate EntityField.EntityIDFieldName in metadata/entities/ ' +
|
|
348
|
+
'so forms, grids, and record links resolve target records deterministically without column-name heuristics.',
|
|
349
|
+
DefaultRoots: ['packages', 'metadata'],
|
|
350
|
+
DefaultOptions: {
|
|
351
|
+
/**
|
|
352
|
+
* Fully-qualified `"EntityName.FieldName"` pairs that deliberately hold an opaque string
|
|
353
|
+
* rather than a polymorphic foreign key to the entity named in an `EntityID` column.
|
|
354
|
+
*/
|
|
355
|
+
allowedFields: [],
|
|
356
|
+
},
|
|
357
|
+
Run(context) {
|
|
358
|
+
const violations = [];
|
|
359
|
+
const notes = [];
|
|
360
|
+
const rawAllowed = context.Options['allowedFields'];
|
|
361
|
+
const allowedSet = new Set(Array.isArray(rawAllowed) ? rawAllowed.filter((x) => typeof x === 'string') : []);
|
|
362
|
+
// 1. Collect generated entities across scanned roots (plus `packages` if not explicitly listed)
|
|
363
|
+
const scanDirs = new Set(context.Roots.map((r) => join(context.RepoRoot, r)));
|
|
364
|
+
const generatedFiles = new Set();
|
|
365
|
+
for (const dir of scanDirs) {
|
|
366
|
+
if (!existsSync(dir))
|
|
367
|
+
continue;
|
|
368
|
+
for (const f of findGeneratedEntityFiles(dir)) {
|
|
369
|
+
generatedFiles.add(f);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
const entities = new Map();
|
|
373
|
+
const fileLinesCache = new Map();
|
|
374
|
+
for (const absFile of generatedFiles) {
|
|
375
|
+
const raw = readFileSync(absFile, 'utf8');
|
|
376
|
+
const relFile = relative(context.RepoRoot, absFile);
|
|
377
|
+
fileLinesCache.set(relFile, raw.split('\n'));
|
|
378
|
+
for (const ent of ParseGeneratedEntitiesFromSource(raw, relFile)) {
|
|
379
|
+
entities.set(ent.Name, ent);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
// 2. Collect metadata declarations across `metadata/` (or any root containing JSON files)
|
|
383
|
+
const metadataDirs = new Set([join(context.RepoRoot, 'metadata')]);
|
|
384
|
+
for (const r of context.Roots) {
|
|
385
|
+
if (r === 'metadata' || r.startsWith('metadata/')) {
|
|
386
|
+
metadataDirs.add(join(context.RepoRoot, r));
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
const declarationsByPair = new Map();
|
|
390
|
+
const allDeclarations = [];
|
|
391
|
+
for (const metaDir of metadataDirs) {
|
|
392
|
+
for (const jsonFile of findJsonFiles(metaDir)) {
|
|
393
|
+
const raw = readFileSync(jsonFile, 'utf8');
|
|
394
|
+
const relFile = relative(context.RepoRoot, jsonFile);
|
|
395
|
+
for (const decl of ParseMetadataPolymorphicDeclarations(raw, relFile)) {
|
|
396
|
+
declarationsByPair.set(`${decl.EntityName}::${decl.FieldName}`, decl);
|
|
397
|
+
allDeclarations.push(decl);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
// 3. Forward check: every polymorphic RecordID column in generated schemas must be declared
|
|
402
|
+
let candidatePairCount = 0;
|
|
403
|
+
for (const entity of entities.values()) {
|
|
404
|
+
const entityFKFields = [...entity.Fields.values()].filter((f) => f.RelatedEntity === 'MJ: Entities');
|
|
405
|
+
if (entityFKFields.length === 0)
|
|
406
|
+
continue;
|
|
407
|
+
const lines = fileLinesCache.get(entity.File) ?? [];
|
|
408
|
+
for (const field of entity.Fields.values()) {
|
|
409
|
+
if (field.Name === 'ID' || field.RelatedEntity !== null)
|
|
410
|
+
continue;
|
|
411
|
+
if (!POLYMORPHIC_RECORD_FIELD_PATTERN.test(field.Name))
|
|
412
|
+
continue;
|
|
413
|
+
if (EXTERNAL_SYSTEM_RECORD_FIELD_PATTERN.test(field.Name))
|
|
414
|
+
continue;
|
|
415
|
+
if (allowedSet.has(`${entity.Name}.${field.Name}`))
|
|
416
|
+
continue;
|
|
417
|
+
if (HasMarkerNear(lines, field.Line, ALLOW_MARKER))
|
|
418
|
+
continue;
|
|
419
|
+
candidatePairCount++;
|
|
420
|
+
const key = `${entity.Name}::${field.Name}`;
|
|
421
|
+
if (!declarationsByPair.has(key)) {
|
|
422
|
+
const suggestedCompanion = SuggestCompanionEntityIDField(field.Name, entityFKFields);
|
|
423
|
+
violations.push({
|
|
424
|
+
File: field.File,
|
|
425
|
+
Line: field.Line,
|
|
426
|
+
Message: `Entity "${entity.Name}" has polymorphic record field "${field.Name}" alongside ` +
|
|
427
|
+
`MJ: Entities FK (${entityFKFields.map((f) => f.Name).join(', ')}), but no ` +
|
|
428
|
+
`EntityField.EntityIDFieldName metadata entry was found — declare ` +
|
|
429
|
+
`"EntityIDFieldName": "${suggestedCompanion}" for "${field.Name}" in ` +
|
|
430
|
+
`metadata/entities/.polymorphic-fk-entity-fields.json (Rule 2e)`,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
// 4. Reverse check: validate every metadata declaration whose entity exists in this repo
|
|
436
|
+
for (const decl of allDeclarations) {
|
|
437
|
+
const entity = entities.get(decl.EntityName);
|
|
438
|
+
if (!entity)
|
|
439
|
+
continue; // External/parent entity not generated in this repo
|
|
440
|
+
const recordField = entity.Fields.get(decl.FieldName);
|
|
441
|
+
if (!recordField) {
|
|
442
|
+
violations.push({
|
|
443
|
+
File: decl.File,
|
|
444
|
+
Line: decl.Line,
|
|
445
|
+
Message: `Polymorphic FK metadata on "${decl.EntityName}" references field "${decl.FieldName}", ` +
|
|
446
|
+
`which does not exist on the generated schema in ${entity.File}`,
|
|
447
|
+
});
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (decl.FieldName === decl.EntityIDFieldName) {
|
|
451
|
+
violations.push({
|
|
452
|
+
File: decl.File,
|
|
453
|
+
Line: decl.Line,
|
|
454
|
+
Message: `Polymorphic FK metadata on "${decl.EntityName}.${decl.FieldName}" sets ` +
|
|
455
|
+
`EntityIDFieldName to itself ("${decl.EntityIDFieldName}") — it must point to the ` +
|
|
456
|
+
`companion MJ: Entities foreign-key column`,
|
|
457
|
+
});
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
const companionField = entity.Fields.get(decl.EntityIDFieldName);
|
|
461
|
+
if (!companionField) {
|
|
462
|
+
violations.push({
|
|
463
|
+
File: decl.File,
|
|
464
|
+
Line: decl.Line,
|
|
465
|
+
Message: `Polymorphic FK metadata on "${decl.EntityName}.${decl.FieldName}" sets ` +
|
|
466
|
+
`EntityIDFieldName to "${decl.EntityIDFieldName}", which does not exist on "${decl.EntityName}"`,
|
|
467
|
+
});
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
if (companionField.RelatedEntity !== 'MJ: Entities') {
|
|
471
|
+
violations.push({
|
|
472
|
+
File: decl.File,
|
|
473
|
+
Line: decl.Line,
|
|
474
|
+
Message: `Polymorphic FK metadata on "${decl.EntityName}.${decl.FieldName}" sets ` +
|
|
475
|
+
`EntityIDFieldName to "${decl.EntityIDFieldName}", but "${decl.EntityIDFieldName}" ` +
|
|
476
|
+
`is not a foreign key to "MJ: Entities" (found RelatedEntity: ${companionField.RelatedEntity ?? 'none'})`,
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
notes.push(`${entities.size} generated entities scanned, ${candidatePairCount} polymorphic FK pairs verified against ${allDeclarations.length} metadata declarations`);
|
|
481
|
+
return { Violations: violations, Notes: notes };
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
//# sourceMappingURL=polymorphic-fk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polymorphic-fk.js","sourceRoot":"","sources":["../../src/checks/polymorphic-fk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACtB,cAAc;IACd,MAAM;IACN,OAAO;IACP,MAAM;IACN,UAAU;IACV,UAAU;IACV,SAAS;IACT,QAAQ;CACX,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,yBAAyB,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,gCAAgC,GAAG,kDAAkD,CAAC;AAC5F,MAAM,oCAAoC,GAAG,+CAA+C,CAAC;AAE7F,wFAAwF;AACxF,SAAS,cAAc,CAAC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constrained value list is what people see: CodeGen turns it into the field's dropdown,
|
|
5
|
+
* its `EntityFieldValue` rows and its generated TypeScript union, and it shows up as-is in views,
|
|
6
|
+
* queries and reports. MJ writes those values for people (`'Opted In'`, `'Not Specified'`), and
|
|
7
|
+
* CodeGen already gives code a safe union for them. AI tools tend to write machine-style values
|
|
8
|
+
* (`'OptedIn'`, `'NOT_SPECIFIED'`) instead, which then leak into every screen.
|
|
9
|
+
*
|
|
10
|
+
* @module @memberjunction/standards
|
|
11
|
+
*/
|
|
12
|
+
import type { StandardCheck } from '../types.js';
|
|
13
|
+
/** The reviewed-exception marker, on the value's line or the line above it. */
|
|
14
|
+
export declare const READABLE_VALUES_MARKER = "mj-standards-allow: status-value";
|
|
15
|
+
/** A value as people would read it: `OptedIn` becomes `Opted In`, `NOT_SPECIFIED` becomes `Not Specified`. */
|
|
16
|
+
export declare function ReadableForm(value: string): string;
|
|
17
|
+
/** Is `value` written for a machine rather than a person? */
|
|
18
|
+
export declare function IsMachineStyle(value: string): boolean;
|
|
19
|
+
/** One value found in a CHECK list. */
|
|
20
|
+
export interface CheckListValue {
|
|
21
|
+
/** 1-based line the value is on. */
|
|
22
|
+
Line: number;
|
|
23
|
+
Value: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Every quoted value inside a `CHECK (… IN (…))` list in `code` (comment-stripped lines).
|
|
27
|
+
* A `CHECK` without an `IN` list (a range, a pattern) yields nothing.
|
|
28
|
+
*/
|
|
29
|
+
export declare function FindCheckListValues(code: readonly string[]): CheckListValue[];
|
|
30
|
+
/** The registered standard. */
|
|
31
|
+
export declare const ReadableStatusValuesCheck: StandardCheck;
|
|
32
|
+
//# sourceMappingURL=readable-status-values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readable-status-values.d.ts","sourceRoot":"","sources":["../../src/checks/readable-status-values.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAA6B,aAAa,EAAa,MAAM,aAAa,CAAC;AAIvF,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,qCAAqC,CAAC;AAWzE,8GAA8G;AAC9G,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQlD;AAED,6DAA6D;AAC7D,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC3B,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,cAAc,EAAE,CAQ7E;AAoED,+BAA+B;AAC/B,eAAO,MAAM,yBAAyB,EAAE,aAcvC,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The readable-status-values standard.
|
|
3
|
+
*
|
|
4
|
+
* A CHECK-constrained value list is what people see: CodeGen turns it into the field's dropdown,
|
|
5
|
+
* its `EntityFieldValue` rows and its generated TypeScript union, and it shows up as-is in views,
|
|
6
|
+
* queries and reports. MJ writes those values for people (`'Opted In'`, `'Not Specified'`), and
|
|
7
|
+
* CodeGen already gives code a safe union for them. AI tools tend to write machine-style values
|
|
8
|
+
* (`'OptedIn'`, `'NOT_SPECIFIED'`) instead, which then leak into every screen.
|
|
9
|
+
*
|
|
10
|
+
* @module @memberjunction/standards
|
|
11
|
+
*/
|
|
12
|
+
import { HasMarkerNear } from '../lib/markers.js';
|
|
13
|
+
import { FindMigrations, StripSqlComments } from '../lib/migrations.js';
|
|
14
|
+
/** The reviewed-exception marker, on the value's line or the line above it. */
|
|
15
|
+
export const READABLE_VALUES_MARKER = 'mj-standards-allow: status-value';
|
|
16
|
+
/** How many lines a `CHECK (` is followed for, to reach the end of its value list. */
|
|
17
|
+
const CHECK_LOOKAHEAD = 15;
|
|
18
|
+
/** Two or more capitalized words run together: `OptedIn`, `NotSpecified`, `InProgress`. */
|
|
19
|
+
const RUN_TOGETHER = /^[A-Z][a-z0-9]+(?:[A-Z][a-z0-9]+)+$/;
|
|
20
|
+
/** Words joined by underscores in any case: `OPTED_IN`, `opted_in`. */
|
|
21
|
+
const SNAKE = /^[A-Za-z0-9]+(?:_[A-Za-z0-9]+)+$/;
|
|
22
|
+
/** A value as people would read it: `OptedIn` becomes `Opted In`, `NOT_SPECIFIED` becomes `Not Specified`. */
|
|
23
|
+
export function ReadableForm(value) {
|
|
24
|
+
if (SNAKE.test(value)) {
|
|
25
|
+
return value
|
|
26
|
+
.split('_')
|
|
27
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
|
|
28
|
+
.join(' ');
|
|
29
|
+
}
|
|
30
|
+
return value.replace(/([a-z0-9])([A-Z])/g, '$1 $2');
|
|
31
|
+
}
|
|
32
|
+
/** Is `value` written for a machine rather than a person? */
|
|
33
|
+
export function IsMachineStyle(value) {
|
|
34
|
+
return RUN_TOGETHER.test(value) || SNAKE.test(value);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Every quoted value inside a `CHECK (… IN (…))` list in `code` (comment-stripped lines).
|
|
38
|
+
* A `CHECK` without an `IN` list (a range, a pattern) yields nothing.
|
|
39
|
+
*/
|
|
40
|
+
export function FindCheckListValues(code) {
|
|
41
|
+
const found = [];
|
|
42
|
+
for (let i = 0; i < code.length; i++) {
|
|
43
|
+
const start = code[i].search(/\bCHECK\s*\(/i);
|
|
44
|
+
if (start < 0)
|
|
45
|
+
continue;
|
|
46
|
+
found.push(...valuesInCheck(code, i, start));
|
|
47
|
+
}
|
|
48
|
+
return found;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The quoted values inside `IN (…)` groups of the one CHECK expression that starts at
|
|
52
|
+
* `code[line]`, column `column`. Reading stops when the CHECK's own parentheses close, so a later
|
|
53
|
+
* statement's `IN (…)` is never mistaken for this constraint's list.
|
|
54
|
+
*/
|
|
55
|
+
function valuesInCheck(code, line, column) {
|
|
56
|
+
const values = [];
|
|
57
|
+
let depth = 0;
|
|
58
|
+
let opened = false;
|
|
59
|
+
let listDepth = -1;
|
|
60
|
+
for (let j = line; j < Math.min(code.length, line + CHECK_LOOKAHEAD); j++) {
|
|
61
|
+
const text = code[j];
|
|
62
|
+
for (let k = j === line ? column : 0; k < text.length; k++) {
|
|
63
|
+
const ch = text[k];
|
|
64
|
+
if (ch === "'") {
|
|
65
|
+
const end = closingQuote(text, k);
|
|
66
|
+
if (listDepth >= 0 && depth === listDepth)
|
|
67
|
+
values.push({ Line: j + 1, Value: text.slice(k + 1, end).replace(/''/g, "'") });
|
|
68
|
+
k = end;
|
|
69
|
+
}
|
|
70
|
+
else if (ch === '(') {
|
|
71
|
+
depth++;
|
|
72
|
+
opened = true;
|
|
73
|
+
if (listDepth < 0 && /\bIN\s*$/i.test(text.slice(0, k)))
|
|
74
|
+
listDepth = depth;
|
|
75
|
+
}
|
|
76
|
+
else if (ch === ')') {
|
|
77
|
+
if (depth === listDepth)
|
|
78
|
+
listDepth = -1;
|
|
79
|
+
depth--;
|
|
80
|
+
if (opened && depth === 0)
|
|
81
|
+
return values;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return values;
|
|
86
|
+
}
|
|
87
|
+
/** Index of the quote that closes the string opened at `open`, treating `''` as an escaped quote. */
|
|
88
|
+
function closingQuote(text, open) {
|
|
89
|
+
for (let k = open + 1; k < text.length; k++) {
|
|
90
|
+
if (text[k] !== "'")
|
|
91
|
+
continue;
|
|
92
|
+
if (text[k + 1] === "'") {
|
|
93
|
+
k++;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
return k;
|
|
97
|
+
}
|
|
98
|
+
return text.length;
|
|
99
|
+
}
|
|
100
|
+
/** Find machine-style CHECK list values in the hand-written part of every migration since the cutoff. */
|
|
101
|
+
function run(context) {
|
|
102
|
+
const fromVersion = String(context.Options['FromVersion'] ?? '');
|
|
103
|
+
const allowed = new Set(context.Options['AllowedValues'] ?? []);
|
|
104
|
+
const { Migrations, Notes } = FindMigrations(context.RepoRoot, context.Roots, fromVersion);
|
|
105
|
+
const violations = [];
|
|
106
|
+
for (const migration of Migrations) {
|
|
107
|
+
const handWritten = migration.Lines.slice(0, migration.HandWrittenLineCount);
|
|
108
|
+
for (const { Line, Value } of FindCheckListValues(StripSqlComments(handWritten))) {
|
|
109
|
+
if (!IsMachineStyle(Value) || allowed.has(Value))
|
|
110
|
+
continue;
|
|
111
|
+
if (HasMarkerNear(migration.Lines, Line, READABLE_VALUES_MARKER))
|
|
112
|
+
continue;
|
|
113
|
+
violations.push({
|
|
114
|
+
File: migration.File,
|
|
115
|
+
Line,
|
|
116
|
+
Message: `'${Value}' is written for a machine. Use '${ReadableForm(Value)}'; CodeGen gives code a typed union for it either way.`,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { Violations: violations, Notes: [...Notes, `${Migrations.length} migration(s) at or after ${fromVersion || '(no cutoff)'} read.`] };
|
|
121
|
+
}
|
|
122
|
+
/** The registered standard. */
|
|
123
|
+
export const ReadableStatusValuesCheck = {
|
|
124
|
+
Id: 'readable-status-values',
|
|
125
|
+
Title: 'Write CHECK-constrained values for people, with spaces',
|
|
126
|
+
Since: '6.2.0',
|
|
127
|
+
DefaultSeverity: 'warn',
|
|
128
|
+
DocsUrl: 'https://github.com/MemberJunction/MJ/blob/next/guides/SCHEMA_AND_CODE_AUTHORING_GUIDE.md#value-lists-are-written-for-people',
|
|
129
|
+
Description: "Flags run-together ('OptedIn') and snake_case ('OPTED_IN') values in CHECK (… IN (…)) lists in the hand-written " +
|
|
130
|
+
'part of every versioned migration at or after the FromVersion option. These values become dropdowns, ' +
|
|
131
|
+
"EntityFieldValue rows and report text; write them as people read them ('Opted In'). Proper names that are " +
|
|
132
|
+
`run together by design go in the AllowedValues option, or take "${READABLE_VALUES_MARKER}" on the line.`,
|
|
133
|
+
DefaultRoots: ['migrations'],
|
|
134
|
+
DefaultOptions: { FromVersion: '202610210000', AllowedValues: [] },
|
|
135
|
+
Run: run,
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=readable-status-values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readable-status-values.js","sourceRoot":"","sources":["../../src/checks/readable-status-values.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExE,+EAA+E;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,kCAAkC,CAAC;AAEzE,sFAAsF;AACtF,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,2FAA2F;AAC3F,MAAM,YAAY,GAAG,qCAAqC,CAAC;AAE3D,uEAAuE;AACvE,MAAM,KAAK,GAAG,kCAAkC,CAAC;AAEjD,8GAA8G;AAC9G,MAAM,UAAU,YAAY,CAAC,KAAa;IACtC,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,KAAK;aACP,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;aAChE,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,cAAc,CAAC,KAAa;IACxC,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC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AAQ,CAAC,EAAE,CAAC;AAChJ,CAAC;AAED,+BAA+B;AAC/B,MAAM,CAAC,MAAM,yBAAyB,GAAkB;IACpD,EAAE,EAAE,wBAAwB;IAC5B,KAAK,EAAE,wDAAwD;IAC/D,KAAK,EAAE,OAAO;IACd,eAAe,EAAE,MAAM;IACvB,OAAO,EAAE,6HAA6H;IACtI,WAAW,EACP,kHAAkH;QAClH,uGAAuG;QACvG,4GAA4G;QAC5G,mEAAmE,sBAAsB,gBAAgB;IAC7G,YAAY,EAAE,CAAC,YAAY,CAAC;IAC5B,cAAc,EAAE,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,EAAE,EAAE;IAClE,GAAG,EAAE,GAAG;CACX,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,10 @@ export * from './runner.js';
|
|
|
36
36
|
export * from './scaffold.js';
|
|
37
37
|
export * from './checks/ui-layers.js';
|
|
38
38
|
export * from './checks/naming-conventions.js';
|
|
39
|
+
export * from './checks/polymorphic-fk.js';
|
|
40
|
+
export * from './checks/migration-existence-guards.js';
|
|
41
|
+
export * from './checks/readable-status-values.js';
|
|
42
|
+
export * from './lib/migrations.js';
|
|
39
43
|
export * from './lib/markers.js';
|
|
40
44
|
export * from './lib/walk.js';
|
|
41
45
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,10 @@ export * from './runner.js';
|
|
|
36
36
|
export * from './scaffold.js';
|
|
37
37
|
export * from './checks/ui-layers.js';
|
|
38
38
|
export * from './checks/naming-conventions.js';
|
|
39
|
+
export * from './checks/polymorphic-fk.js';
|
|
40
|
+
export * from './checks/migration-existence-guards.js';
|
|
41
|
+
export * from './checks/readable-status-values.js';
|
|
42
|
+
export * from './lib/migrations.js';
|
|
39
43
|
export * from './lib/markers.js';
|
|
40
44
|
export * from './lib/walk.js';
|
|
41
45
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Finding the migrations a migration standard should read, and the part of each
|
|
3
|
+
* one a person wrote.
|
|
4
|
+
*
|
|
5
|
+
* Two facts shape everything here:
|
|
6
|
+
*
|
|
7
|
+
* - **Migrations are immutable once applied.** A standard adopted today cannot ask anyone to edit a
|
|
8
|
+
* migration that already ran, so every migration check takes a `FromVersion` cutoff and reads
|
|
9
|
+
* only migrations at or after it.
|
|
10
|
+
* - **Half of a migration is generated.** By MJ convention, CodeGen's output is appended below the
|
|
11
|
+
* hand-written DDL after a run of blank lines and a banner. That generated half legitimately uses
|
|
12
|
+
* patterns a person must not (CodeGen guards its own `DROP VIEW` with `IF OBJECT_ID`), so a
|
|
13
|
+
* migration check reads only the hand-written half.
|
|
14
|
+
*
|
|
15
|
+
* @module @memberjunction/standards
|
|
16
|
+
*/
|
|
17
|
+
/** One migration file, split at the hand-written / generated boundary. */
|
|
18
|
+
export interface MigrationFile {
|
|
19
|
+
/** Repo-relative path. */
|
|
20
|
+
File: string;
|
|
21
|
+
/** The 12-digit timestamp from the file name (`V202610201300__…` gives `202610201300`). */
|
|
22
|
+
Version: string;
|
|
23
|
+
/** Every line of the file, unmodified. Marker lookups need the original text. */
|
|
24
|
+
Lines: string[];
|
|
25
|
+
/** How many leading lines are hand-written. Lines after this belong to CodeGen. */
|
|
26
|
+
HandWrittenLineCount: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A blank-line run this long ends the hand-written section. The convention asks for at least 50;
|
|
30
|
+
* a lower bar tolerates a trimmed separator without mistaking ordinary spacing for one.
|
|
31
|
+
*/
|
|
32
|
+
export declare const SEPARATOR_BLANK_LINES = 20;
|
|
33
|
+
/**
|
|
34
|
+
* The number of hand-written lines at the top of a migration: everything before the first long
|
|
35
|
+
* run of blank lines or the first CodeGen banner, whichever comes first. A file with neither is
|
|
36
|
+
* all hand-written.
|
|
37
|
+
*/
|
|
38
|
+
export declare function HandWrittenLineCount(lines: readonly string[]): number;
|
|
39
|
+
/**
|
|
40
|
+
* Did CodeGen write the statement that starts on `line` (1-based)? True when the nearest non-blank
|
|
41
|
+
* line above it is one of CodeGen's statement headers.
|
|
42
|
+
*
|
|
43
|
+
* This recognizes CodeGen output pasted without the separator one statement at a time, rather than
|
|
44
|
+
* ending the hand-written section at the first header: older migrations put CodeGen output first and
|
|
45
|
+
* hand-written DDL after it, and that DDL still has to be read.
|
|
46
|
+
*/
|
|
47
|
+
export declare function IsCodeGenStatement(lines: readonly string[], line: number): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Comment-free copies of `lines`, the same length and line-for-line, so a pattern inside a
|
|
50
|
+
* `--` or block comment never counts as code. Quoted strings are kept: a status value lives in one.
|
|
51
|
+
*/
|
|
52
|
+
export declare function StripSqlComments(lines: readonly string[]): string[];
|
|
53
|
+
/**
|
|
54
|
+
* Every versioned migration under `roots` whose timestamp is at or after `fromVersion`.
|
|
55
|
+
*
|
|
56
|
+
* `fromVersion` is the 12-digit timestamp a repo adopted the standard at. An empty or malformed
|
|
57
|
+
* value reads nothing and says so in a note, rather than reading the whole history: flagging
|
|
58
|
+
* migrations that can no longer be edited would teach a repo to switch the check off.
|
|
59
|
+
*/
|
|
60
|
+
export declare function FindMigrations(repoRoot: string, roots: readonly string[], fromVersion: string): {
|
|
61
|
+
Migrations: MigrationFile[];
|
|
62
|
+
Notes: string[];
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=migrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/lib/migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,0EAA0E;AAC1E,MAAM,WAAW,aAAa;IAC1B,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,2FAA2F;IAC3F,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,mFAAmF;IACnF,oBAAoB,EAAE,MAAM,CAAC;CAChC;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAcxC;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAarE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAMlF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAoCnE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG;IAAE,UAAU,EAAE,aAAa,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAsBhJ"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Finding the migrations a migration standard should read, and the part of each
|
|
3
|
+
* one a person wrote.
|
|
4
|
+
*
|
|
5
|
+
* Two facts shape everything here:
|
|
6
|
+
*
|
|
7
|
+
* - **Migrations are immutable once applied.** A standard adopted today cannot ask anyone to edit a
|
|
8
|
+
* migration that already ran, so every migration check takes a `FromVersion` cutoff and reads
|
|
9
|
+
* only migrations at or after it.
|
|
10
|
+
* - **Half of a migration is generated.** By MJ convention, CodeGen's output is appended below the
|
|
11
|
+
* hand-written DDL after a run of blank lines and a banner. That generated half legitimately uses
|
|
12
|
+
* patterns a person must not (CodeGen guards its own `DROP VIEW` with `IF OBJECT_ID`), so a
|
|
13
|
+
* migration check reads only the hand-written half.
|
|
14
|
+
*
|
|
15
|
+
* @module @memberjunction/standards
|
|
16
|
+
*/
|
|
17
|
+
import { readFileSync } from 'node:fs';
|
|
18
|
+
import { basename, join, relative } from 'node:path';
|
|
19
|
+
import { FindSourceFiles } from './walk.js';
|
|
20
|
+
/**
|
|
21
|
+
* A blank-line run this long ends the hand-written section. The convention asks for at least 50;
|
|
22
|
+
* a lower bar tolerates a trimmed separator without mistaking ordinary spacing for one.
|
|
23
|
+
*/
|
|
24
|
+
export const SEPARATOR_BLANK_LINES = 20;
|
|
25
|
+
/** Banner lines CodeGen output starts with, any one of which ends the hand-written section. */
|
|
26
|
+
const CODEGEN_BANNERS = [/GENERATED BY MemberJunction CodeGen/i, /This was generated by the MemberJunction CodeGen tool/i];
|
|
27
|
+
/** The header CodeGen writes above each statement it emits: `/* SQL text to add special date field … *\/`. */
|
|
28
|
+
const CODEGEN_STATEMENT_HEADER = /^\s*\/\*\s*SQL (?:generated|text) to\b/i;
|
|
29
|
+
/** Directory names a migration walk never descends into. PostgreSQL output is converter-owned. */
|
|
30
|
+
const SKIP_DIRS = new Set(['node_modules', '.git', 'dist', 'migrations-pg', 'codegen']);
|
|
31
|
+
/** A versioned migration: `V` + 12-digit timestamp + `__`. Repeatable and baseline files are skipped. */
|
|
32
|
+
const VERSIONED = /^V(\d{12})__.+\.sql$/i;
|
|
33
|
+
/**
|
|
34
|
+
* The number of hand-written lines at the top of a migration: everything before the first long
|
|
35
|
+
* run of blank lines or the first CodeGen banner, whichever comes first. A file with neither is
|
|
36
|
+
* all hand-written.
|
|
37
|
+
*/
|
|
38
|
+
export function HandWrittenLineCount(lines) {
|
|
39
|
+
let blankRun = 0;
|
|
40
|
+
for (let i = 0; i < lines.length; i++) {
|
|
41
|
+
const line = lines[i];
|
|
42
|
+
if (CODEGEN_BANNERS.some((b) => b.test(line)))
|
|
43
|
+
return i;
|
|
44
|
+
if (line.trim() === '') {
|
|
45
|
+
blankRun++;
|
|
46
|
+
if (blankRun >= SEPARATOR_BLANK_LINES)
|
|
47
|
+
return i - blankRun + 1;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
blankRun = 0;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return lines.length;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Did CodeGen write the statement that starts on `line` (1-based)? True when the nearest non-blank
|
|
57
|
+
* line above it is one of CodeGen's statement headers.
|
|
58
|
+
*
|
|
59
|
+
* This recognizes CodeGen output pasted without the separator one statement at a time, rather than
|
|
60
|
+
* ending the hand-written section at the first header: older migrations put CodeGen output first and
|
|
61
|
+
* hand-written DDL after it, and that DDL still has to be read.
|
|
62
|
+
*/
|
|
63
|
+
export function IsCodeGenStatement(lines, line) {
|
|
64
|
+
for (let i = line - 2; i >= 0; i--) {
|
|
65
|
+
if (lines[i].trim() === '')
|
|
66
|
+
continue;
|
|
67
|
+
return CODEGEN_STATEMENT_HEADER.test(lines[i]);
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Comment-free copies of `lines`, the same length and line-for-line, so a pattern inside a
|
|
73
|
+
* `--` or block comment never counts as code. Quoted strings are kept: a status value lives in one.
|
|
74
|
+
*/
|
|
75
|
+
export function StripSqlComments(lines) {
|
|
76
|
+
const out = [];
|
|
77
|
+
let inBlock = false;
|
|
78
|
+
for (const line of lines) {
|
|
79
|
+
let result = '';
|
|
80
|
+
let inString = false;
|
|
81
|
+
for (let i = 0; i < line.length; i++) {
|
|
82
|
+
const ch = line[i];
|
|
83
|
+
const next = line[i + 1];
|
|
84
|
+
if (inBlock) {
|
|
85
|
+
if (ch === '*' && next === '/') {
|
|
86
|
+
inBlock = false;
|
|
87
|
+
i++;
|
|
88
|
+
}
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (inString) {
|
|
92
|
+
result += ch;
|
|
93
|
+
if (ch === "'")
|
|
94
|
+
inString = false;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (ch === "'") {
|
|
98
|
+
inString = true;
|
|
99
|
+
result += ch;
|
|
100
|
+
}
|
|
101
|
+
else if (ch === '-' && next === '-') {
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
else if (ch === '/' && next === '*') {
|
|
105
|
+
inBlock = true;
|
|
106
|
+
i++;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
result += ch;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
out.push(result);
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Every versioned migration under `roots` whose timestamp is at or after `fromVersion`.
|
|
118
|
+
*
|
|
119
|
+
* `fromVersion` is the 12-digit timestamp a repo adopted the standard at. An empty or malformed
|
|
120
|
+
* value reads nothing and says so in a note, rather than reading the whole history: flagging
|
|
121
|
+
* migrations that can no longer be edited would teach a repo to switch the check off.
|
|
122
|
+
*/
|
|
123
|
+
export function FindMigrations(repoRoot, roots, fromVersion) {
|
|
124
|
+
if (!/^\d{12}$/.test(fromVersion)) {
|
|
125
|
+
return {
|
|
126
|
+
Migrations: [],
|
|
127
|
+
Notes: [`FromVersion must be a 12-digit migration timestamp (got "${fromVersion}"); no migrations were read.`],
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const migrations = [];
|
|
131
|
+
for (const root of roots) {
|
|
132
|
+
// A root can name a skipped directory itself (`migrations-pg`), which the walk's own
|
|
133
|
+
// skip set never sees, since that set only stops it descending.
|
|
134
|
+
if (SKIP_DIRS.has(basename(root)))
|
|
135
|
+
continue;
|
|
136
|
+
const files = FindSourceFiles(join(repoRoot, root), { SkipDirs: SKIP_DIRS, Extensions: ['.sql'], Exclude: (f) => f.endsWith('.pg.sql') });
|
|
137
|
+
for (const full of files) {
|
|
138
|
+
const match = VERSIONED.exec(basename(full));
|
|
139
|
+
if (!match || match[1] < fromVersion)
|
|
140
|
+
continue;
|
|
141
|
+
const lines = readFileSync(full, 'utf8').split(/\r?\n/);
|
|
142
|
+
migrations.push({ File: relative(repoRoot, full), Version: match[1], Lines: lines, HandWrittenLineCount: HandWrittenLineCount(lines) });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
migrations.sort((a, b) => a.File.localeCompare(b.File));
|
|
146
|
+
return { Migrations: migrations, Notes: [] };
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=migrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/lib/migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAc5C;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAExC,+FAA+F;AAC/F,MAAM,eAAe,GAAsB,CAAC,sCAAsC,EAAE,wDAAwD,CAAC,CAAC;AAE9I,8GAA8G;AAC9G,MAAM,wBAAwB,GAAG,yCAAyC,CAAC;AA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K,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC5I,CAAC;IACL,CAAC;IACD,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACxD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;AACjD,CAAC"}
|
package/dist/registry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAOhD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,aAAa,EAMnD,CAAC;AAEF,yCAAyC;AACzC,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAE9D;AAED,uFAAuF;AACvF,wBAAgB,WAAW,IAAI,MAAM,EAAE,CAEtC"}
|
package/dist/registry.js
CHANGED
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { UILayersCheck } from './checks/ui-layers.js';
|
|
11
11
|
import { NamingConventionsCheck } from './checks/naming-conventions.js';
|
|
12
|
+
import { PolymorphicFKCheck } from './checks/polymorphic-fk.js';
|
|
13
|
+
import { MigrationExistenceGuardsCheck } from './checks/migration-existence-guards.js';
|
|
14
|
+
import { ReadableStatusValuesCheck } from './checks/readable-status-values.js';
|
|
12
15
|
/**
|
|
13
16
|
* Every registered standard.
|
|
14
17
|
*
|
|
@@ -20,7 +23,13 @@ import { NamingConventionsCheck } from './checks/naming-conventions.js';
|
|
|
20
23
|
* no longer exists gets an "unknown check" warning rather than a silent no-op, so removal is
|
|
21
24
|
* visible — but it is still a breaking change for anyone whose CI names it.
|
|
22
25
|
*/
|
|
23
|
-
export const STANDARD_CHECKS = [
|
|
26
|
+
export const STANDARD_CHECKS = [
|
|
27
|
+
UILayersCheck,
|
|
28
|
+
NamingConventionsCheck,
|
|
29
|
+
PolymorphicFKCheck,
|
|
30
|
+
MigrationExistenceGuardsCheck,
|
|
31
|
+
ReadableStatusValuesCheck,
|
|
32
|
+
];
|
|
24
33
|
/** Look up a check by its config key. */
|
|
25
34
|
export function GetCheck(id) {
|
|
26
35
|
return STANDARD_CHECKS.find((c) => c.Id === id);
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAE/E;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAA6B;IACrD,aAAa;IACb,sBAAsB;IACtB,kBAAkB;IAClB,6BAA6B;IAC7B,yBAAyB;CAC5B,CAAC;AAEF,yCAAyC;AACzC,MAAM,UAAU,QAAQ,CAAC,EAAU;IAC/B,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,WAAW;IACvB,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACnD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/standards",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.2.0-edge.
|
|
4
|
+
"version": "6.2.0-edge.7",
|
|
5
5
|
"description": "MemberJunction engineering standards as runnable, versioned checks — plus the scaffolding that gets a repo enforcing them. Opt-in per check; a new standard never changes an existing repo's result.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|