joist-codegen 2.4.0-next.4 → 2.4.0-next.40
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/build/EntityDbMetadata.cjs +21 -3
- package/build/EntityDbMetadata.cjs.map +1 -1
- package/build/EntityDbMetadata.d.cts +28 -25
- package/build/EntityDbMetadata.d.cts.map +1 -1
- package/build/EntityDbMetadata.d.mts +28 -25
- package/build/EntityDbMetadata.d.mts.map +1 -1
- package/build/EntityDbMetadata.js +21 -3
- package/build/EntityDbMetadata.js.map +1 -1
- package/build/assignTags.d.cts +1 -2
- package/build/assignTags.d.cts.map +1 -1
- package/build/assignTags.d.mts +1 -2
- package/build/assignTags.d.mts.map +1 -1
- package/build/codemods/Codemod.d.cts +1 -2
- package/build/codemods/Codemod.d.cts.map +1 -1
- package/build/codemods/Codemod.d.mts +1 -2
- package/build/codemods/Codemod.d.mts.map +1 -1
- package/build/codemods/JscodeshiftMod.d.cts +1 -2
- package/build/codemods/JscodeshiftMod.d.cts.map +1 -1
- package/build/codemods/JscodeshiftMod.d.mts +1 -2
- package/build/codemods/JscodeshiftMod.d.mts.map +1 -1
- package/build/codemods/codemod_0001-rename_has_async_property.d.cts +2 -2
- package/build/codemods/codemod_0001-rename_has_async_property.d.cts.map +1 -1
- package/build/codemods/codemod_0001-rename_has_async_property.d.mts +2 -2
- package/build/codemods/codemod_0001-rename_has_async_property.d.mts.map +1 -1
- package/build/codemods/codemod_0002-rename_async_query_fields.d.cts +2 -2
- package/build/codemods/codemod_0002-rename_async_query_fields.d.cts.map +1 -1
- package/build/codemods/codemod_0002-rename_async_query_fields.d.mts +2 -2
- package/build/codemods/codemod_0002-rename_async_query_fields.d.mts.map +1 -1
- package/build/codemods/codemod_0003-rename_find_paginated.d.cts +2 -2
- package/build/codemods/codemod_0003-rename_find_paginated.d.cts.map +1 -1
- package/build/codemods/codemod_0003-rename_find_paginated.d.mts +2 -2
- package/build/codemods/codemod_0003-rename_find_paginated.d.mts.map +1 -1
- package/build/codemods/index.d.cts +3 -4
- package/build/codemods/index.d.cts.map +1 -1
- package/build/codemods/index.d.mts +3 -4
- package/build/codemods/index.d.mts.map +1 -1
- package/build/config.cjs +1 -1
- package/build/config.cjs.map +1 -1
- package/build/config.d.cts +27 -27
- package/build/config.d.cts.map +1 -1
- package/build/config.d.mts +27 -27
- package/build/config.d.mts.map +1 -1
- package/build/config.js +1 -1
- package/build/config.js.map +1 -1
- package/build/docs/cache.cjs.map +1 -1
- package/build/docs/cache.d.cts +2 -3
- package/build/docs/cache.d.cts.map +1 -1
- package/build/docs/cache.d.mts +2 -3
- package/build/docs/cache.d.mts.map +1 -1
- package/build/docs/cache.js.map +1 -1
- package/build/docs/generate-metadata-docs.d.cts +1 -2
- package/build/docs/generate-metadata-docs.d.cts.map +1 -1
- package/build/docs/generate-metadata-docs.d.mts +1 -2
- package/build/docs/generate-metadata-docs.d.mts.map +1 -1
- package/build/docs/index.d.cts +3 -3
- package/build/docs/index.d.cts.map +1 -1
- package/build/docs/index.d.mts +3 -3
- package/build/docs/index.d.mts.map +1 -1
- package/build/docs/markdown.d.cts +8 -8
- package/build/docs/markdown.d.cts.map +1 -1
- package/build/docs/markdown.d.mts +8 -8
- package/build/docs/markdown.d.mts.map +1 -1
- package/build/docs/parsing.d.cts +9 -9
- package/build/docs/parsing.d.cts.map +1 -1
- package/build/docs/parsing.d.mts +9 -9
- package/build/docs/parsing.d.mts.map +1 -1
- package/build/findEntityScopes.d.cts +3 -4
- package/build/findEntityScopes.d.cts.map +1 -1
- package/build/findEntityScopes.d.mts +3 -4
- package/build/findEntityScopes.d.mts.map +1 -1
- package/build/foreignKeyOrdering.d.cts +1 -2
- package/build/foreignKeyOrdering.d.cts.map +1 -1
- package/build/foreignKeyOrdering.d.mts +1 -2
- package/build/foreignKeyOrdering.d.mts.map +1 -1
- package/build/generate.d.cts +3 -4
- package/build/generate.d.cts.map +1 -1
- package/build/generate.d.mts +3 -4
- package/build/generate.d.mts.map +1 -1
- package/build/generateEntitiesFile.d.cts +1 -2
- package/build/generateEntitiesFile.d.cts.map +1 -1
- package/build/generateEntitiesFile.d.mts +1 -2
- package/build/generateEntitiesFile.d.mts.map +1 -1
- package/build/generateEntityCodegenFile.cjs +5 -3
- package/build/generateEntityCodegenFile.cjs.map +1 -1
- package/build/generateEntityCodegenFile.d.cts +3 -4
- package/build/generateEntityCodegenFile.d.cts.map +1 -1
- package/build/generateEntityCodegenFile.d.mts +3 -4
- package/build/generateEntityCodegenFile.d.mts.map +1 -1
- package/build/generateEntityCodegenFile.js +5 -3
- package/build/generateEntityCodegenFile.js.map +1 -1
- package/build/generateEntityFile.d.cts +1 -2
- package/build/generateEntityFile.d.cts.map +1 -1
- package/build/generateEntityFile.d.mts +1 -2
- package/build/generateEntityFile.d.mts.map +1 -1
- package/build/generateEntityTestFile.d.cts +1 -2
- package/build/generateEntityTestFile.d.cts.map +1 -1
- package/build/generateEntityTestFile.d.mts +1 -2
- package/build/generateEntityTestFile.d.mts.map +1 -1
- package/build/generateEnumFile.d.cts +1 -2
- package/build/generateEnumFile.d.cts.map +1 -1
- package/build/generateEnumFile.d.mts +1 -2
- package/build/generateEnumFile.d.mts.map +1 -1
- package/build/generateFactoriesFiles.d.cts +1 -2
- package/build/generateFactoriesFiles.d.cts.map +1 -1
- package/build/generateFactoriesFiles.d.mts +1 -2
- package/build/generateFactoriesFiles.d.mts.map +1 -1
- package/build/generateFlushFunction.d.cts +3 -4
- package/build/generateFlushFunction.d.cts.map +1 -1
- package/build/generateFlushFunction.d.mts +3 -4
- package/build/generateFlushFunction.d.mts.map +1 -1
- package/build/generateMetadataFile.cjs +2 -1
- package/build/generateMetadataFile.cjs.map +1 -1
- package/build/generateMetadataFile.d.cts +2 -3
- package/build/generateMetadataFile.d.cts.map +1 -1
- package/build/generateMetadataFile.d.mts +2 -3
- package/build/generateMetadataFile.d.mts.map +1 -1
- package/build/generateMetadataFile.js +2 -1
- package/build/generateMetadataFile.js.map +1 -1
- package/build/generatePgEnumFile.d.cts +1 -2
- package/build/generatePgEnumFile.d.cts.map +1 -1
- package/build/generatePgEnumFile.d.mts +1 -2
- package/build/generatePgEnumFile.d.mts.map +1 -1
- package/build/index.d.cts +4 -4
- package/build/index.d.cts.map +1 -1
- package/build/index.d.mts +4 -4
- package/build/index.d.mts.map +1 -1
- package/build/inheritance.d.cts +3 -3
- package/build/inheritance.d.cts.map +1 -1
- package/build/inheritance.d.mts +3 -3
- package/build/inheritance.d.mts.map +1 -1
- package/build/installSkills.d.cts +1 -2
- package/build/installSkills.d.cts.map +1 -1
- package/build/installSkills.d.mts +1 -2
- package/build/installSkills.d.mts.map +1 -1
- package/build/keywords.d.cts +1 -2
- package/build/keywords.d.cts.map +1 -1
- package/build/keywords.d.mts +1 -2
- package/build/keywords.d.mts.map +1 -1
- package/build/loadMetadata.d.cts +7 -8
- package/build/loadMetadata.d.cts.map +1 -1
- package/build/loadMetadata.d.mts +7 -8
- package/build/loadMetadata.d.mts.map +1 -1
- package/build/logger.d.cts +3 -4
- package/build/logger.d.cts.map +1 -1
- package/build/logger.d.mts +3 -4
- package/build/logger.d.mts.map +1 -1
- package/build/pgMetadata.d.cts +13 -14
- package/build/pgMetadata.d.cts.map +1 -1
- package/build/pgMetadata.d.mts +13 -14
- package/build/pgMetadata.d.mts.map +1 -1
- package/build/scanEntityFiles.cjs +6 -1
- package/build/scanEntityFiles.cjs.map +1 -1
- package/build/scanEntityFiles.d.cts +2 -3
- package/build/scanEntityFiles.d.cts.map +1 -1
- package/build/scanEntityFiles.d.mts +2 -3
- package/build/scanEntityFiles.d.mts.map +1 -1
- package/build/scanEntityFiles.js +6 -1
- package/build/scanEntityFiles.js.map +1 -1
- package/build/sortForeignKeys.d.cts +1 -2
- package/build/sortForeignKeys.d.cts.map +1 -1
- package/build/sortForeignKeys.d.mts +1 -2
- package/build/sortForeignKeys.d.mts.map +1 -1
- package/build/symbols.d.cts +116 -117
- package/build/symbols.d.cts.map +1 -1
- package/build/symbols.d.mts +116 -117
- package/build/symbols.d.mts.map +1 -1
- package/build/tsdoc.d.cts +1 -2
- package/build/tsdoc.d.cts.map +1 -1
- package/build/tsdoc.d.mts +1 -2
- package/build/tsdoc.d.mts.map +1 -1
- package/build/utils.d.cts +21 -22
- package/build/utils.d.cts.map +1 -1
- package/build/utils.d.mts +21 -22
- package/build/utils.d.mts.map +1 -1
- package/package.json +9 -9
- package/skills/joist-test-factories/SKILL.md +93 -6
package/build/loadMetadata.d.mts
CHANGED
|
@@ -5,27 +5,26 @@ import { PrimitiveField } from "./EntityDbMetadata.mjs";
|
|
|
5
5
|
import { Client } from "pg";
|
|
6
6
|
//#region src/loadMetadata.d.ts
|
|
7
7
|
/** A map from Enum table name to the rows currently in the table. */
|
|
8
|
-
type EnumTableData = {
|
|
8
|
+
export type EnumTableData = {
|
|
9
9
|
table: Table;
|
|
10
10
|
idType: "integer" | "uuid";
|
|
11
11
|
name: string;
|
|
12
12
|
rows: EnumRow[];
|
|
13
13
|
extraPrimitives: PrimitiveField[];
|
|
14
14
|
};
|
|
15
|
-
type PgEnumData = {
|
|
15
|
+
export type PgEnumData = {
|
|
16
16
|
name: string;
|
|
17
17
|
values: string[];
|
|
18
18
|
};
|
|
19
|
-
type EnumMetadata = Record<string, EnumTableData>;
|
|
20
|
-
type PgEnumMetadata = Record<string, PgEnumData>;
|
|
21
|
-
type EnumRow = {
|
|
19
|
+
export type EnumMetadata = Record<string, EnumTableData>;
|
|
20
|
+
export type PgEnumMetadata = Record<string, PgEnumData>;
|
|
21
|
+
export type EnumRow = {
|
|
22
22
|
id: number;
|
|
23
23
|
code: string;
|
|
24
24
|
name: string;
|
|
25
25
|
[key: string]: any;
|
|
26
26
|
};
|
|
27
|
-
declare function loadEnumMetadata(db: Db, client: Client, config: Config): Promise<EnumMetadata>;
|
|
28
|
-
declare function loadPgEnumMetadata(db: Db, client: Client, config: Config): Promise<PgEnumMetadata>;
|
|
27
|
+
export declare function loadEnumMetadata(db: Db, client: Client, config: Config): Promise<EnumMetadata>;
|
|
28
|
+
export declare function loadPgEnumMetadata(db: Db, client: Client, config: Config): Promise<PgEnumMetadata>;
|
|
29
29
|
//#endregion
|
|
30
|
-
export { EnumMetadata, EnumRow, EnumTableData, PgEnumData, PgEnumMetadata, loadEnumMetadata, loadPgEnumMetadata };
|
|
31
30
|
//# sourceMappingURL=loadMetadata.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadMetadata.d.mts","names":[],"sources":["../src/loadMetadata.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"loadMetadata.d.mts","names":[],"sources":["../src/loadMetadata.ts"],"mappings":";;;;;;;YAQY;EACV,OAAO;EACP;EAEA;EACA,MAAM;EACN,iBAAiB;;YAGP;EACV;EACA;;YAGU,eAAe,eAAe;YAC9B,iBAAiB,eAAe;YAEhC;EAAY;EAAY;EAAc;GAAe;;wBAE3C,iBAAiB,IAAI,IAAI,QAAQ,QAAQ,QAAQ,SAAS,QAAQ;wBAwBlE,mBAAmB,IAAI,IAAI,QAAQ,QAAQ,QAAQ,SAAS,QAAQ"}
|
package/build/logger.d.cts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
//#region src/logger.d.ts
|
|
2
|
-
declare const LOG_LEVELS: {
|
|
2
|
+
export declare const LOG_LEVELS: {
|
|
3
3
|
warn: number;
|
|
4
4
|
error: number;
|
|
5
5
|
};
|
|
6
|
-
declare let loggerMaxWarningLevelHit: number;
|
|
7
|
-
declare const logger: {
|
|
6
|
+
export declare let loggerMaxWarningLevelHit: number;
|
|
7
|
+
export declare const logger: {
|
|
8
8
|
warn(...args: Parameters<(typeof console)["warn"]>): void;
|
|
9
9
|
error(...args: Parameters<(typeof console)["error"]>): void;
|
|
10
10
|
};
|
|
11
11
|
//#endregion
|
|
12
|
-
export { LOG_LEVELS, logger, loggerMaxWarningLevelHit };
|
|
13
12
|
//# sourceMappingURL=logger.d.cts.map
|
package/build/logger.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.cts","names":[],"sources":["../src/logger.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"logger.d.cts","names":[],"sources":["../src/logger.ts"],"mappings":";qBAAa;EACX;EACA;;mBAGS;qBAEE;EACX,QAAI,MAAU,mBAAmB;EAIjC,SAAK,MAAU,mBAAmB"}
|
package/build/logger.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
//#region src/logger.d.ts
|
|
2
|
-
declare const LOG_LEVELS: {
|
|
2
|
+
export declare const LOG_LEVELS: {
|
|
3
3
|
warn: number;
|
|
4
4
|
error: number;
|
|
5
5
|
};
|
|
6
|
-
declare let loggerMaxWarningLevelHit: number;
|
|
7
|
-
declare const logger: {
|
|
6
|
+
export declare let loggerMaxWarningLevelHit: number;
|
|
7
|
+
export declare const logger: {
|
|
8
8
|
warn(...args: Parameters<(typeof console)["warn"]>): void;
|
|
9
9
|
error(...args: Parameters<(typeof console)["error"]>): void;
|
|
10
10
|
};
|
|
11
11
|
//#endregion
|
|
12
|
-
export { LOG_LEVELS, logger, loggerMaxWarningLevelHit };
|
|
13
12
|
//# sourceMappingURL=logger.d.mts.map
|
package/build/logger.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.mts","names":[],"sources":["../src/logger.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"logger.d.mts","names":[],"sources":["../src/logger.ts"],"mappings":";qBAAa;EACX;EACA;;mBAGS;qBAEE;EACX,QAAI,MAAU,mBAAmB;EAIjC,SAAK,MAAU,mBAAmB"}
|
package/build/pgMetadata.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Client } from "pg";
|
|
2
2
|
//#region src/pgMetadata.d.ts
|
|
3
3
|
/** The small part of PostgreSQL's catalog model used by Joist codegen. */
|
|
4
|
-
declare class Items<T extends {
|
|
4
|
+
export declare class Items<T extends {
|
|
5
5
|
name: string;
|
|
6
6
|
}> extends Array<T> {
|
|
7
7
|
private byName?;
|
|
@@ -10,17 +10,17 @@ declare class Items<T extends {
|
|
|
10
10
|
/** Keep the name index current if more catalog rows arrive after a lookup. */
|
|
11
11
|
push(...items: T[]): number;
|
|
12
12
|
}
|
|
13
|
-
type Action = "NO ACTION" | "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT";
|
|
14
|
-
type JSONData = string | number | boolean | null | JSONData[] | {
|
|
13
|
+
export type Action = "NO ACTION" | "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT";
|
|
14
|
+
export type JSONData = string | number | boolean | null | JSONData[] | {
|
|
15
15
|
[key: string]: JSONData;
|
|
16
16
|
};
|
|
17
|
-
declare class EnumType {
|
|
17
|
+
export declare class EnumType {
|
|
18
18
|
name: string;
|
|
19
19
|
values: string[];
|
|
20
20
|
readonly shortName?: string;
|
|
21
21
|
constructor(name: string, values: string[]);
|
|
22
22
|
}
|
|
23
|
-
declare class Column {
|
|
23
|
+
export declare class Column {
|
|
24
24
|
name: string;
|
|
25
25
|
type: {
|
|
26
26
|
name: string;
|
|
@@ -42,14 +42,14 @@ declare class Column {
|
|
|
42
42
|
get default(): string | null;
|
|
43
43
|
get commentData(): JSONData | undefined;
|
|
44
44
|
}
|
|
45
|
-
declare class Index {
|
|
45
|
+
export declare class Index {
|
|
46
46
|
name: string;
|
|
47
47
|
columns: Column[];
|
|
48
48
|
isUnique: boolean;
|
|
49
49
|
isPartial: boolean;
|
|
50
50
|
constructor(name: string, columns: Column[], isUnique: boolean, isPartial: boolean);
|
|
51
51
|
}
|
|
52
|
-
declare class ForeignKey {
|
|
52
|
+
export declare class ForeignKey {
|
|
53
53
|
name: string;
|
|
54
54
|
table: Table;
|
|
55
55
|
referencedTable: Table;
|
|
@@ -59,7 +59,7 @@ declare class ForeignKey {
|
|
|
59
59
|
onDelete: Action;
|
|
60
60
|
constructor(name: string, table: Table, referencedTable: Table, columns: Column[], isDeferred: boolean, isDeferrable: boolean, onDelete: Action);
|
|
61
61
|
}
|
|
62
|
-
declare class M2ORelation {
|
|
62
|
+
export declare class M2ORelation {
|
|
63
63
|
foreignKey: ForeignKey;
|
|
64
64
|
readonly type = "m2o";
|
|
65
65
|
constructor(foreignKey: ForeignKey);
|
|
@@ -68,7 +68,7 @@ declare class M2ORelation {
|
|
|
68
68
|
/** Uses the old short relation name so M2O metadata keeps its factory evaluation order. */
|
|
69
69
|
get name(): string;
|
|
70
70
|
}
|
|
71
|
-
declare class O2MRelation {
|
|
71
|
+
export declare class O2MRelation {
|
|
72
72
|
foreignKey: ForeignKey;
|
|
73
73
|
readonly type = "o2m";
|
|
74
74
|
constructor(foreignKey: ForeignKey);
|
|
@@ -77,7 +77,7 @@ declare class O2MRelation {
|
|
|
77
77
|
/** Keeps inverse relations in the same short-name order as pg-structure. */
|
|
78
78
|
get name(): string;
|
|
79
79
|
}
|
|
80
|
-
declare class M2MRelation {
|
|
80
|
+
export declare class M2MRelation {
|
|
81
81
|
foreignKey: ForeignKey;
|
|
82
82
|
targetForeignKey: ForeignKey;
|
|
83
83
|
readonly type = "m2m";
|
|
@@ -88,7 +88,7 @@ declare class M2MRelation {
|
|
|
88
88
|
/** Adds the join-table qualifier when more than one join path reaches the same target. */
|
|
89
89
|
get name(): string;
|
|
90
90
|
}
|
|
91
|
-
declare class Table {
|
|
91
|
+
export declare class Table {
|
|
92
92
|
name: string;
|
|
93
93
|
schema: {
|
|
94
94
|
name: string;
|
|
@@ -111,7 +111,7 @@ declare class Table {
|
|
|
111
111
|
get o2mRelations(): O2MRelation[];
|
|
112
112
|
get m2mRelations(): M2MRelation[];
|
|
113
113
|
}
|
|
114
|
-
type Db = {
|
|
114
|
+
export type Db = {
|
|
115
115
|
tables: Items<Table>;
|
|
116
116
|
types: EnumType[];
|
|
117
117
|
};
|
|
@@ -122,7 +122,6 @@ type Db = {
|
|
|
122
122
|
* objects used by entity fields. For example, books.author_id and authors.id are joined through
|
|
123
123
|
* the foreign key, while a trigger calling cyanaudit in another schema is irrelevant to codegen.
|
|
124
124
|
*/
|
|
125
|
-
declare function loadPgMetadata(client: Client): Promise<Db>;
|
|
125
|
+
export declare function loadPgMetadata(client: Client): Promise<Db>;
|
|
126
126
|
//#endregion
|
|
127
|
-
export { Action, Column, Db, EnumType, ForeignKey, Index, Items, JSONData, M2MRelation, M2ORelation, O2MRelation, Table, loadPgMetadata };
|
|
128
127
|
//# sourceMappingURL=pgMetadata.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgMetadata.d.cts","names":[],"sources":["../src/pgMetadata.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"pgMetadata.d.cts","names":[],"sources":["../src/pgMetadata.ts"],"mappings":";;;qBAIa,MAAM;EAAY;WAAwB,MAAM;UACnD;;EAGR,IAAI,eAAe;;EAUnB,QAAQ,OAAO;;YAOL;YACA,8CAA8C;GAAgB,cAAc;;qBAE3E;EAGF;EACA;WAHA;EACT,YACS,cACA;;qBAIE;EAMF;EACA;IAAQ;IAAc;MAAuB;EAC7C;EACA;EACA;EACA;EACA;WAXA,aAAa;WACb,eAAe;EACxB;EAEA,YACS,cACA;IAAQ;IAAc;MAAuB,UAC7C,kBACA,6BACA,sBACA,wBACA;MAGL;MAIA;MAIA,eAAe;;qBAMR;EAEF;EACA,SAAS;EACT;EACA;EAJT,YACS,cACA,SAAS,UACT,mBACA;;qBAIE;EAEF;EACA,OAAO;EACP,iBAAiB;EACjB,SAAS;EACT;EACA;EACA,UAAU;EAPnB,YACS,cACA,OAAO,OACP,iBAAiB,OACjB,SAAS,UACT,qBACA,uBACA,UAAU;;qBAIR;EAGQ,YAAY;WAFtB;EAET,YAAmB,YAAY;MAE3B,eAAe;MAIf,eAAe;;MAKf;;qBAWO;EAGQ,YAAY;WAFtB;EAET,YAAmB,YAAY;MAE3B,eAAe;MAIf,eAAe;;MAKf;;qBAiBO;EAIF,YAAY;EACZ,kBAAkB;WAJlB;EAET,YACS,YAAY,YACZ,kBAAkB;MAGvB,eAAe;MAIf,eAAe;MAIf,aAAa;;MAKb;;qBAmBO;EASF;EACA;IAAU;;WATV,SAAO,MAAA;WACP,SAAO,MAAA;WACP,aAAa;WACb,mBAAmB;WACnB;IAAqB,SAAS;IAAU,OAAO;;EACxD;IAAe,SAAS;;EAExB,YACS,cACA;IAAU;;MAGf,gBAAgB;MAIhB,gBAAgB;MAMhB,gBAAgB;;YAOV;EAAO,QAAQ,MAAM;EAAQ,OAAO;;;;;;;;;wBAS1B,eAAe,QAAQ,SAAS,QAAQ"}
|
package/build/pgMetadata.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Client } from "pg";
|
|
2
2
|
//#region src/pgMetadata.d.ts
|
|
3
3
|
/** The small part of PostgreSQL's catalog model used by Joist codegen. */
|
|
4
|
-
declare class Items<T extends {
|
|
4
|
+
export declare class Items<T extends {
|
|
5
5
|
name: string;
|
|
6
6
|
}> extends Array<T> {
|
|
7
7
|
private byName?;
|
|
@@ -10,17 +10,17 @@ declare class Items<T extends {
|
|
|
10
10
|
/** Keep the name index current if more catalog rows arrive after a lookup. */
|
|
11
11
|
push(...items: T[]): number;
|
|
12
12
|
}
|
|
13
|
-
type Action = "NO ACTION" | "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT";
|
|
14
|
-
type JSONData = string | number | boolean | null | JSONData[] | {
|
|
13
|
+
export type Action = "NO ACTION" | "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT";
|
|
14
|
+
export type JSONData = string | number | boolean | null | JSONData[] | {
|
|
15
15
|
[key: string]: JSONData;
|
|
16
16
|
};
|
|
17
|
-
declare class EnumType {
|
|
17
|
+
export declare class EnumType {
|
|
18
18
|
name: string;
|
|
19
19
|
values: string[];
|
|
20
20
|
readonly shortName?: string;
|
|
21
21
|
constructor(name: string, values: string[]);
|
|
22
22
|
}
|
|
23
|
-
declare class Column {
|
|
23
|
+
export declare class Column {
|
|
24
24
|
name: string;
|
|
25
25
|
type: {
|
|
26
26
|
name: string;
|
|
@@ -42,14 +42,14 @@ declare class Column {
|
|
|
42
42
|
get default(): string | null;
|
|
43
43
|
get commentData(): JSONData | undefined;
|
|
44
44
|
}
|
|
45
|
-
declare class Index {
|
|
45
|
+
export declare class Index {
|
|
46
46
|
name: string;
|
|
47
47
|
columns: Column[];
|
|
48
48
|
isUnique: boolean;
|
|
49
49
|
isPartial: boolean;
|
|
50
50
|
constructor(name: string, columns: Column[], isUnique: boolean, isPartial: boolean);
|
|
51
51
|
}
|
|
52
|
-
declare class ForeignKey {
|
|
52
|
+
export declare class ForeignKey {
|
|
53
53
|
name: string;
|
|
54
54
|
table: Table;
|
|
55
55
|
referencedTable: Table;
|
|
@@ -59,7 +59,7 @@ declare class ForeignKey {
|
|
|
59
59
|
onDelete: Action;
|
|
60
60
|
constructor(name: string, table: Table, referencedTable: Table, columns: Column[], isDeferred: boolean, isDeferrable: boolean, onDelete: Action);
|
|
61
61
|
}
|
|
62
|
-
declare class M2ORelation {
|
|
62
|
+
export declare class M2ORelation {
|
|
63
63
|
foreignKey: ForeignKey;
|
|
64
64
|
readonly type = "m2o";
|
|
65
65
|
constructor(foreignKey: ForeignKey);
|
|
@@ -68,7 +68,7 @@ declare class M2ORelation {
|
|
|
68
68
|
/** Uses the old short relation name so M2O metadata keeps its factory evaluation order. */
|
|
69
69
|
get name(): string;
|
|
70
70
|
}
|
|
71
|
-
declare class O2MRelation {
|
|
71
|
+
export declare class O2MRelation {
|
|
72
72
|
foreignKey: ForeignKey;
|
|
73
73
|
readonly type = "o2m";
|
|
74
74
|
constructor(foreignKey: ForeignKey);
|
|
@@ -77,7 +77,7 @@ declare class O2MRelation {
|
|
|
77
77
|
/** Keeps inverse relations in the same short-name order as pg-structure. */
|
|
78
78
|
get name(): string;
|
|
79
79
|
}
|
|
80
|
-
declare class M2MRelation {
|
|
80
|
+
export declare class M2MRelation {
|
|
81
81
|
foreignKey: ForeignKey;
|
|
82
82
|
targetForeignKey: ForeignKey;
|
|
83
83
|
readonly type = "m2m";
|
|
@@ -88,7 +88,7 @@ declare class M2MRelation {
|
|
|
88
88
|
/** Adds the join-table qualifier when more than one join path reaches the same target. */
|
|
89
89
|
get name(): string;
|
|
90
90
|
}
|
|
91
|
-
declare class Table {
|
|
91
|
+
export declare class Table {
|
|
92
92
|
name: string;
|
|
93
93
|
schema: {
|
|
94
94
|
name: string;
|
|
@@ -111,7 +111,7 @@ declare class Table {
|
|
|
111
111
|
get o2mRelations(): O2MRelation[];
|
|
112
112
|
get m2mRelations(): M2MRelation[];
|
|
113
113
|
}
|
|
114
|
-
type Db = {
|
|
114
|
+
export type Db = {
|
|
115
115
|
tables: Items<Table>;
|
|
116
116
|
types: EnumType[];
|
|
117
117
|
};
|
|
@@ -122,7 +122,6 @@ type Db = {
|
|
|
122
122
|
* objects used by entity fields. For example, books.author_id and authors.id are joined through
|
|
123
123
|
* the foreign key, while a trigger calling cyanaudit in another schema is irrelevant to codegen.
|
|
124
124
|
*/
|
|
125
|
-
declare function loadPgMetadata(client: Client): Promise<Db>;
|
|
125
|
+
export declare function loadPgMetadata(client: Client): Promise<Db>;
|
|
126
126
|
//#endregion
|
|
127
|
-
export { Action, Column, Db, EnumType, ForeignKey, Index, Items, JSONData, M2MRelation, M2ORelation, O2MRelation, Table, loadPgMetadata };
|
|
128
127
|
//# sourceMappingURL=pgMetadata.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgMetadata.d.mts","names":[],"sources":["../src/pgMetadata.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"pgMetadata.d.mts","names":[],"sources":["../src/pgMetadata.ts"],"mappings":";;;qBAIa,MAAM;EAAY;WAAwB,MAAM;UACnD;;EAGR,IAAI,eAAe;;EAUnB,QAAQ,OAAO;;YAOL;YACA,8CAA8C;GAAgB,cAAc;;qBAE3E;EAGF;EACA;WAHA;EACT,YACS,cACA;;qBAIE;EAMF;EACA;IAAQ;IAAc;MAAuB;EAC7C;EACA;EACA;EACA;EACA;WAXA,aAAa;WACb,eAAe;EACxB;EAEA,YACS,cACA;IAAQ;IAAc;MAAuB,UAC7C,kBACA,6BACA,sBACA,wBACA;MAGL;MAIA;MAIA,eAAe;;qBAMR;EAEF;EACA,SAAS;EACT;EACA;EAJT,YACS,cACA,SAAS,UACT,mBACA;;qBAIE;EAEF;EACA,OAAO;EACP,iBAAiB;EACjB,SAAS;EACT;EACA;EACA,UAAU;EAPnB,YACS,cACA,OAAO,OACP,iBAAiB,OACjB,SAAS,UACT,qBACA,uBACA,UAAU;;qBAIR;EAGQ,YAAY;WAFtB;EAET,YAAmB,YAAY;MAE3B,eAAe;MAIf,eAAe;;MAKf;;qBAWO;EAGQ,YAAY;WAFtB;EAET,YAAmB,YAAY;MAE3B,eAAe;MAIf,eAAe;;MAKf;;qBAiBO;EAIF,YAAY;EACZ,kBAAkB;WAJlB;EAET,YACS,YAAY,YACZ,kBAAkB;MAGvB,eAAe;MAIf,eAAe;MAIf,aAAa;;MAKb;;qBAmBO;EASF;EACA;IAAU;;WATV,SAAO,MAAA;WACP,SAAO,MAAA;WACP,aAAa;WACb,mBAAmB;WACnB;IAAqB,SAAS;IAAU,OAAO;;EACxD;IAAe,SAAS;;EAExB,YACS,cACA;IAAU;;MAGf,gBAAgB;MAIhB,gBAAgB;MAMhB,gBAAgB;;YAOV;EAAO,QAAQ,MAAM;EAAQ,OAAO;;;;;;;;;wBAS1B,eAAe,QAAQ,SAAS,QAAQ"}
|
|
@@ -5,7 +5,8 @@ let path = require("path");
|
|
|
5
5
|
let fs_promises = require("fs/promises");
|
|
6
6
|
//#region src/scanEntityFiles.ts
|
|
7
7
|
const regex = /config\.setDefault\([\s\n]*["'](\w+)["']/g;
|
|
8
|
-
|
|
8
|
+
const transitionsRegex = /config\.(?:setTransitions|addTransitionRule|addTransitionReaction)\(\s*(?:(?:["'][^"']*["']|\w+)\s*,\s*(?=["']))?["'](\w+)["']/g;
|
|
9
|
+
/** Scans the entity files themselves for usage hints (like `setDefault` or `setTransitions` calls) to drive our codegen output. */
|
|
9
10
|
async function scanEntityFiles(config, dbMeta) {
|
|
10
11
|
await Promise.all(dbMeta.entities.map(async (entity) => {
|
|
11
12
|
try {
|
|
@@ -15,6 +16,10 @@ async function scanEntityFiles(config, dbMeta) {
|
|
|
15
16
|
const field = defaultableFields.find((f) => f.fieldName === match[1]);
|
|
16
17
|
if (field) field.hasConfigDefault = true;
|
|
17
18
|
}
|
|
19
|
+
for (const match of tsCode.matchAll(transitionsRegex)) {
|
|
20
|
+
const field = defaultableFields.find((f) => f.fieldName === match[1]);
|
|
21
|
+
if (field?.kind === "enum") field.hasTransitions = true;
|
|
22
|
+
}
|
|
18
23
|
} catch (e) {}
|
|
19
24
|
}));
|
|
20
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanEntityFiles.cjs","names":["readFile","join"],"sources":["../src/scanEntityFiles.ts"],"sourcesContent":["import { readFile } from \"fs/promises\";\nimport { join } from \"path\";\n\nimport { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type EnumField,\n type ManyToOneField,\n type PgEnumField,\n type PolymorphicField,\n type PrimitiveField,\n} from \"./EntityDbMetadata.ts\";\n\n// Erg, we need a regex in case the fieldName arg is wrapped onto a new line... :-/\nconst regex = /config\\.setDefault\\([\\s\\n]*[\"'](\\w+)[\"']/g;\n\n/** Scans the entity files themselves for usage hints (like `setDefault` calls) to drive our codegen output. */\nexport async function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void> {\n await Promise.all(\n dbMeta.entities.map(async (entity) => {\n try {\n // load the entity.ts file (as a promise with fs/promises)\n const tsCode = (await readFile(join(config.entitiesDirectory, `${entity.name}.ts`))).toString();\n const defaultableFields = recursiveDefaultableFields(dbMeta, entity);\n for (const match of tsCode.matchAll(regex)) {\n const field = defaultableFields.find((f) => f.fieldName === match[1]);\n if (field) {\n field.hasConfigDefault = true;\n }\n }\n } catch (e) {\n // Ignore file not existing yet\n }\n }),\n );\n}\n\n/**\n * Traverse the entity inheritance tree to find all fields that can have defaults set on them.\n *\n * I.e. a column defined in a base CTI table like `publishers.foo_bar` having a `config.setDefault` in\n * `SmallPublisher` and/or `LargePublisher`, or the same scenario for an STI table like `tasks.foo_bar`\n * with `TaskNew` and/or `TaskOld`.\n *\n * NOTE: I suspect here could be some edge cases here that will need to be ironed out, but should work\n * for simple inheritance structures. In particular, there may be unexpected side effects if a base\n * class field has a default set in one subtype, but not another.\n */\nfunction recursiveDefaultableFields(\n dbMeta: DbMetadata,\n entity: EntityDbMetadata | undefined,\n): Array<PrimitiveField | EnumField | PgEnumField | ManyToOneField | PolymorphicField> {\n if (!entity) return [];\n return [\n ...entity.primitives,\n ...entity.enums,\n ...entity.pgEnums,\n ...entity.manyToOnes,\n ...entity.polymorphics,\n ...(entity.baseClassName ? recursiveDefaultableFields(dbMeta, dbMeta.entitiesByName[entity.baseClassName]) : []),\n ];\n}\n"],"mappings":";;;;;;AAeA,MAAM,QAAQ;;
|
|
1
|
+
{"version":3,"file":"scanEntityFiles.cjs","names":["readFile","join"],"sources":["../src/scanEntityFiles.ts"],"sourcesContent":["import { readFile } from \"fs/promises\";\nimport { join } from \"path\";\n\nimport { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type EnumField,\n type ManyToOneField,\n type PgEnumField,\n type PolymorphicField,\n type PrimitiveField,\n} from \"./EntityDbMetadata.ts\";\n\n// Erg, we need a regex in case the fieldName arg is wrapped onto a new line... :-/\nconst regex = /config\\.setDefault\\([\\s\\n]*[\"'](\\w+)[\"']/g;\n// Any transition method marks the field; addTransitionReaction may have a name before the field argument.\nconst transitionsRegex =\n /config\\.(?:setTransitions|addTransitionRule|addTransitionReaction)\\(\\s*(?:(?:[\"'][^\"']*[\"']|\\w+)\\s*,\\s*(?=[\"']))?[\"'](\\w+)[\"']/g;\n\n/** Scans the entity files themselves for usage hints (like `setDefault` or `setTransitions` calls) to drive our codegen output. */\nexport async function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void> {\n await Promise.all(\n dbMeta.entities.map(async (entity) => {\n try {\n // load the entity.ts file (as a promise with fs/promises)\n const tsCode = (await readFile(join(config.entitiesDirectory, `${entity.name}.ts`))).toString();\n const defaultableFields = recursiveDefaultableFields(dbMeta, entity);\n for (const match of tsCode.matchAll(regex)) {\n const field = defaultableFields.find((f) => f.fieldName === match[1]);\n if (field) {\n field.hasConfigDefault = true;\n }\n }\n // Transition fields get `withStatus` factory opts and accessor names, i.e. `Draft`\n for (const match of tsCode.matchAll(transitionsRegex)) {\n const field = defaultableFields.find((f) => f.fieldName === match[1]);\n if (field?.kind === \"enum\") {\n field.hasTransitions = true;\n }\n }\n } catch (e) {\n // Ignore file not existing yet\n }\n }),\n );\n}\n\n/**\n * Traverse the entity inheritance tree to find all fields that can have defaults set on them.\n *\n * I.e. a column defined in a base CTI table like `publishers.foo_bar` having a `config.setDefault` in\n * `SmallPublisher` and/or `LargePublisher`, or the same scenario for an STI table like `tasks.foo_bar`\n * with `TaskNew` and/or `TaskOld`.\n *\n * NOTE: I suspect here could be some edge cases here that will need to be ironed out, but should work\n * for simple inheritance structures. In particular, there may be unexpected side effects if a base\n * class field has a default set in one subtype, but not another.\n */\nfunction recursiveDefaultableFields(\n dbMeta: DbMetadata,\n entity: EntityDbMetadata | undefined,\n): Array<PrimitiveField | EnumField | PgEnumField | ManyToOneField | PolymorphicField> {\n if (!entity) return [];\n return [\n ...entity.primitives,\n ...entity.enums,\n ...entity.pgEnums,\n ...entity.manyToOnes,\n ...entity.polymorphics,\n ...(entity.baseClassName ? recursiveDefaultableFields(dbMeta, dbMeta.entitiesByName[entity.baseClassName]) : []),\n ];\n}\n"],"mappings":";;;;;;AAeA,MAAM,QAAQ;AAEd,MAAM,mBACJ;;AAGF,eAAsB,gBAAgB,QAAgB,QAAmC;CACvF,MAAM,QAAQ,IACZ,OAAO,SAAS,IAAI,OAAO,WAAW;EACpC,IAAI;GAEF,MAAM,UAAU,OAAA,GAAMA,YAAAA,SAAAA,EAAAA,GAASC,KAAAA,KAAAA,CAAK,OAAO,mBAAmB,GAAG,OAAO,KAAK,IAAI,CAAC,EAAA,CAAG,SAAS;GAC9F,MAAM,oBAAoB,2BAA2B,QAAQ,MAAM;GACnE,KAAK,MAAM,SAAS,OAAO,SAAS,KAAK,GAAG;IAC1C,MAAM,QAAQ,kBAAkB,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE;IACpE,IAAI,OACF,MAAM,mBAAmB;GAE7B;GAEA,KAAK,MAAM,SAAS,OAAO,SAAS,gBAAgB,GAAG;IACrD,MAAM,QAAQ,kBAAkB,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE;IACpE,IAAI,OAAO,SAAS,QAClB,MAAM,iBAAiB;GAE3B;EACF,SAAS,GAAG,CAEZ;CACF,CAAC,CACH;AACF;;;;;;;;;;;;AAaA,SAAS,2BACP,QACA,QACqF;CACrF,IAAI,CAAC,QAAQ,OAAO,CAAC;CACrB,OAAO;EACL,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAI,OAAO,gBAAgB,2BAA2B,QAAQ,OAAO,eAAe,OAAO,cAAc,IAAI,CAAC;CAChH;AACF"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Config } from "./config.cjs";
|
|
2
2
|
import { DbMetadata } from "./EntityDbMetadata.cjs";
|
|
3
3
|
//#region src/scanEntityFiles.d.ts
|
|
4
|
-
/** Scans the entity files themselves for usage hints (like `setDefault` calls) to drive our codegen output. */
|
|
5
|
-
declare function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void>;
|
|
4
|
+
/** Scans the entity files themselves for usage hints (like `setDefault` or `setTransitions` calls) to drive our codegen output. */
|
|
5
|
+
export declare function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void>;
|
|
6
6
|
//#endregion
|
|
7
|
-
export { scanEntityFiles };
|
|
8
7
|
//# sourceMappingURL=scanEntityFiles.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanEntityFiles.d.cts","names":[],"sources":["../src/scanEntityFiles.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"scanEntityFiles.d.cts","names":[],"sources":["../src/scanEntityFiles.ts"],"mappings":";;;;wBAqBsB,gBAAgB,QAAQ,QAAQ,QAAQ,aAAa"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Config } from "./config.mjs";
|
|
2
2
|
import { DbMetadata } from "./EntityDbMetadata.mjs";
|
|
3
3
|
//#region src/scanEntityFiles.d.ts
|
|
4
|
-
/** Scans the entity files themselves for usage hints (like `setDefault` calls) to drive our codegen output. */
|
|
5
|
-
declare function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void>;
|
|
4
|
+
/** Scans the entity files themselves for usage hints (like `setDefault` or `setTransitions` calls) to drive our codegen output. */
|
|
5
|
+
export declare function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void>;
|
|
6
6
|
//#endregion
|
|
7
|
-
export { scanEntityFiles };
|
|
8
7
|
//# sourceMappingURL=scanEntityFiles.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanEntityFiles.d.mts","names":[],"sources":["../src/scanEntityFiles.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"scanEntityFiles.d.mts","names":[],"sources":["../src/scanEntityFiles.ts"],"mappings":";;;;wBAqBsB,gBAAgB,QAAQ,QAAQ,QAAQ,aAAa"}
|
package/build/scanEntityFiles.js
CHANGED
|
@@ -4,7 +4,8 @@ import { join } from "path";
|
|
|
4
4
|
import { readFile } from "fs/promises";
|
|
5
5
|
//#region src/scanEntityFiles.ts
|
|
6
6
|
const regex = /config\.setDefault\([\s\n]*["'](\w+)["']/g;
|
|
7
|
-
|
|
7
|
+
const transitionsRegex = /config\.(?:setTransitions|addTransitionRule|addTransitionReaction)\(\s*(?:(?:["'][^"']*["']|\w+)\s*,\s*(?=["']))?["'](\w+)["']/g;
|
|
8
|
+
/** Scans the entity files themselves for usage hints (like `setDefault` or `setTransitions` calls) to drive our codegen output. */
|
|
8
9
|
async function scanEntityFiles(config, dbMeta) {
|
|
9
10
|
await Promise.all(dbMeta.entities.map(async (entity) => {
|
|
10
11
|
try {
|
|
@@ -14,6 +15,10 @@ async function scanEntityFiles(config, dbMeta) {
|
|
|
14
15
|
const field = defaultableFields.find((f) => f.fieldName === match[1]);
|
|
15
16
|
if (field) field.hasConfigDefault = true;
|
|
16
17
|
}
|
|
18
|
+
for (const match of tsCode.matchAll(transitionsRegex)) {
|
|
19
|
+
const field = defaultableFields.find((f) => f.fieldName === match[1]);
|
|
20
|
+
if (field?.kind === "enum") field.hasTransitions = true;
|
|
21
|
+
}
|
|
17
22
|
} catch (e) {}
|
|
18
23
|
}));
|
|
19
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanEntityFiles.js","names":[],"sources":["../src/scanEntityFiles.ts"],"sourcesContent":["import { readFile } from \"fs/promises\";\nimport { join } from \"path\";\n\nimport { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type EnumField,\n type ManyToOneField,\n type PgEnumField,\n type PolymorphicField,\n type PrimitiveField,\n} from \"./EntityDbMetadata.ts\";\n\n// Erg, we need a regex in case the fieldName arg is wrapped onto a new line... :-/\nconst regex = /config\\.setDefault\\([\\s\\n]*[\"'](\\w+)[\"']/g;\n\n/** Scans the entity files themselves for usage hints (like `setDefault` calls) to drive our codegen output. */\nexport async function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void> {\n await Promise.all(\n dbMeta.entities.map(async (entity) => {\n try {\n // load the entity.ts file (as a promise with fs/promises)\n const tsCode = (await readFile(join(config.entitiesDirectory, `${entity.name}.ts`))).toString();\n const defaultableFields = recursiveDefaultableFields(dbMeta, entity);\n for (const match of tsCode.matchAll(regex)) {\n const field = defaultableFields.find((f) => f.fieldName === match[1]);\n if (field) {\n field.hasConfigDefault = true;\n }\n }\n } catch (e) {\n // Ignore file not existing yet\n }\n }),\n );\n}\n\n/**\n * Traverse the entity inheritance tree to find all fields that can have defaults set on them.\n *\n * I.e. a column defined in a base CTI table like `publishers.foo_bar` having a `config.setDefault` in\n * `SmallPublisher` and/or `LargePublisher`, or the same scenario for an STI table like `tasks.foo_bar`\n * with `TaskNew` and/or `TaskOld`.\n *\n * NOTE: I suspect here could be some edge cases here that will need to be ironed out, but should work\n * for simple inheritance structures. In particular, there may be unexpected side effects if a base\n * class field has a default set in one subtype, but not another.\n */\nfunction recursiveDefaultableFields(\n dbMeta: DbMetadata,\n entity: EntityDbMetadata | undefined,\n): Array<PrimitiveField | EnumField | PgEnumField | ManyToOneField | PolymorphicField> {\n if (!entity) return [];\n return [\n ...entity.primitives,\n ...entity.enums,\n ...entity.pgEnums,\n ...entity.manyToOnes,\n ...entity.polymorphics,\n ...(entity.baseClassName ? recursiveDefaultableFields(dbMeta, dbMeta.entitiesByName[entity.baseClassName]) : []),\n ];\n}\n"],"mappings":";;;;;AAeA,MAAM,QAAQ;;
|
|
1
|
+
{"version":3,"file":"scanEntityFiles.js","names":[],"sources":["../src/scanEntityFiles.ts"],"sourcesContent":["import { readFile } from \"fs/promises\";\nimport { join } from \"path\";\n\nimport { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type EnumField,\n type ManyToOneField,\n type PgEnumField,\n type PolymorphicField,\n type PrimitiveField,\n} from \"./EntityDbMetadata.ts\";\n\n// Erg, we need a regex in case the fieldName arg is wrapped onto a new line... :-/\nconst regex = /config\\.setDefault\\([\\s\\n]*[\"'](\\w+)[\"']/g;\n// Any transition method marks the field; addTransitionReaction may have a name before the field argument.\nconst transitionsRegex =\n /config\\.(?:setTransitions|addTransitionRule|addTransitionReaction)\\(\\s*(?:(?:[\"'][^\"']*[\"']|\\w+)\\s*,\\s*(?=[\"']))?[\"'](\\w+)[\"']/g;\n\n/** Scans the entity files themselves for usage hints (like `setDefault` or `setTransitions` calls) to drive our codegen output. */\nexport async function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void> {\n await Promise.all(\n dbMeta.entities.map(async (entity) => {\n try {\n // load the entity.ts file (as a promise with fs/promises)\n const tsCode = (await readFile(join(config.entitiesDirectory, `${entity.name}.ts`))).toString();\n const defaultableFields = recursiveDefaultableFields(dbMeta, entity);\n for (const match of tsCode.matchAll(regex)) {\n const field = defaultableFields.find((f) => f.fieldName === match[1]);\n if (field) {\n field.hasConfigDefault = true;\n }\n }\n // Transition fields get `withStatus` factory opts and accessor names, i.e. `Draft`\n for (const match of tsCode.matchAll(transitionsRegex)) {\n const field = defaultableFields.find((f) => f.fieldName === match[1]);\n if (field?.kind === \"enum\") {\n field.hasTransitions = true;\n }\n }\n } catch (e) {\n // Ignore file not existing yet\n }\n }),\n );\n}\n\n/**\n * Traverse the entity inheritance tree to find all fields that can have defaults set on them.\n *\n * I.e. a column defined in a base CTI table like `publishers.foo_bar` having a `config.setDefault` in\n * `SmallPublisher` and/or `LargePublisher`, or the same scenario for an STI table like `tasks.foo_bar`\n * with `TaskNew` and/or `TaskOld`.\n *\n * NOTE: I suspect here could be some edge cases here that will need to be ironed out, but should work\n * for simple inheritance structures. In particular, there may be unexpected side effects if a base\n * class field has a default set in one subtype, but not another.\n */\nfunction recursiveDefaultableFields(\n dbMeta: DbMetadata,\n entity: EntityDbMetadata | undefined,\n): Array<PrimitiveField | EnumField | PgEnumField | ManyToOneField | PolymorphicField> {\n if (!entity) return [];\n return [\n ...entity.primitives,\n ...entity.enums,\n ...entity.pgEnums,\n ...entity.manyToOnes,\n ...entity.polymorphics,\n ...(entity.baseClassName ? recursiveDefaultableFields(dbMeta, dbMeta.entitiesByName[entity.baseClassName]) : []),\n ];\n}\n"],"mappings":";;;;;AAeA,MAAM,QAAQ;AAEd,MAAM,mBACJ;;AAGF,eAAsB,gBAAgB,QAAgB,QAAmC;CACvF,MAAM,QAAQ,IACZ,OAAO,SAAS,IAAI,OAAO,WAAW;EACpC,IAAI;GAEF,MAAM,UAAU,MAAM,SAAS,KAAK,OAAO,mBAAmB,GAAG,OAAO,KAAK,IAAI,CAAC,EAAA,CAAG,SAAS;GAC9F,MAAM,oBAAoB,2BAA2B,QAAQ,MAAM;GACnE,KAAK,MAAM,SAAS,OAAO,SAAS,KAAK,GAAG;IAC1C,MAAM,QAAQ,kBAAkB,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE;IACpE,IAAI,OACF,MAAM,mBAAmB;GAE7B;GAEA,KAAK,MAAM,SAAS,OAAO,SAAS,gBAAgB,GAAG;IACrD,MAAM,QAAQ,kBAAkB,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE;IACpE,IAAI,OAAO,SAAS,QAClB,MAAM,iBAAiB;GAE3B;EACF,SAAS,GAAG,CAEZ;CACF,CAAC,CACH;AACF;;;;;;;;;;;;AAaA,SAAS,2BACP,QACA,QACqF;CACrF,IAAI,CAAC,QAAQ,OAAO,CAAC;CACrB,OAAO;EACL,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAI,OAAO,gBAAgB,2BAA2B,QAAQ,OAAO,eAAe,OAAO,cAAc,IAAI,CAAC;CAChH;AACF"}
|
|
@@ -26,10 +26,9 @@ import { EntityDbMetadata } from "./EntityDbMetadata.cjs";
|
|
|
26
26
|
* two arrays of all soft-cycle (nullable, fixup-able) and hard-cycle (not-nullable, blocking)
|
|
27
27
|
* keys.
|
|
28
28
|
*/
|
|
29
|
-
declare function sortByNonDeferredForeignKeys(entities: EntityDbMetadata[]): {
|
|
29
|
+
export declare function sortByNonDeferredForeignKeys(entities: EntityDbMetadata[]): {
|
|
30
30
|
nullableCycles: string[];
|
|
31
31
|
notNullCycles: string[];
|
|
32
32
|
};
|
|
33
33
|
//#endregion
|
|
34
|
-
export { sortByNonDeferredForeignKeys };
|
|
35
34
|
//# sourceMappingURL=sortForeignKeys.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortForeignKeys.d.cts","names":[],"sources":["../src/sortForeignKeys.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"sortForeignKeys.d.cts","names":[],"sources":["../src/sortForeignKeys.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA4BgB,6BAA6B,UAAU;EACrD;EACA"}
|
|
@@ -26,10 +26,9 @@ import { EntityDbMetadata } from "./EntityDbMetadata.mjs";
|
|
|
26
26
|
* two arrays of all soft-cycle (nullable, fixup-able) and hard-cycle (not-nullable, blocking)
|
|
27
27
|
* keys.
|
|
28
28
|
*/
|
|
29
|
-
declare function sortByNonDeferredForeignKeys(entities: EntityDbMetadata[]): {
|
|
29
|
+
export declare function sortByNonDeferredForeignKeys(entities: EntityDbMetadata[]): {
|
|
30
30
|
nullableCycles: string[];
|
|
31
31
|
notNullCycles: string[];
|
|
32
32
|
};
|
|
33
33
|
//#endregion
|
|
34
|
-
export { sortByNonDeferredForeignKeys };
|
|
35
34
|
//# sourceMappingURL=sortForeignKeys.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortForeignKeys.d.mts","names":[],"sources":["../src/sortForeignKeys.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"sortForeignKeys.d.mts","names":[],"sources":["../src/sortForeignKeys.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA4BgB,6BAA6B,UAAU;EACrD;EACA"}
|