@cedarjs/internal 3.1.2-next.0 → 3.1.2-next.128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/api.js +1 -1
- package/dist/cjs/build/api.js +1 -1
- package/dist/cjs/generate/clientPreset.d.ts.map +1 -1
- package/dist/cjs/generate/clientPreset.js +1 -2
- package/dist/cjs/generate/generate.d.ts.map +1 -1
- package/dist/cjs/generate/generate.js +8 -2
- package/dist/cjs/generate/gqlormSchema.d.ts +28 -0
- package/dist/cjs/generate/gqlormSchema.d.ts.map +1 -0
- package/dist/cjs/generate/gqlormSchema.js +121 -0
- package/dist/cjs/generate/graphqlCodeGen.d.ts.map +1 -1
- package/dist/cjs/generate/graphqlCodeGen.js +4 -1
- package/dist/cjs/generate/watch.js +2 -1
- package/dist/cjs/index.js +10 -10
- package/dist/files.js +1 -1
- package/dist/generate/clientPreset.d.ts.map +1 -1
- package/dist/generate/clientPreset.js +1 -2
- package/dist/generate/generate.d.ts.map +1 -1
- package/dist/generate/generate.js +8 -2
- package/dist/generate/gqlormSchema.d.ts +28 -0
- package/dist/generate/gqlormSchema.d.ts.map +1 -0
- package/dist/generate/gqlormSchema.js +86 -0
- package/dist/generate/graphqlCodeGen.d.ts.map +1 -1
- package/dist/generate/graphqlCodeGen.js +4 -1
- package/dist/generate/watch.js +2 -1
- package/package.json +25 -12
package/dist/build/api.js
CHANGED
package/dist/cjs/build/api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPreset.d.ts","sourceRoot":"","sources":["../../../src/generate/clientPreset.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,8BAA8B,QAAO,OAIjD,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;
|
|
1
|
+
{"version":3,"file":"clientPreset.d.ts","sourceRoot":"","sources":["../../../src/generate/clientPreset.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,8BAA8B,QAAO,OAIjD,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;iBAGN,MAAM;eAAS,OAAO;;;;;;iBAAtB,MAAM;eAAS,OAAO;;EAoDhD,CAAA"}
|
|
@@ -31,7 +31,6 @@ const shouldGenerateTrustedDocuments = () => {
|
|
|
31
31
|
return config.graphql.trustedDocuments;
|
|
32
32
|
};
|
|
33
33
|
const generateClientPreset = async () => {
|
|
34
|
-
let generatedFiles = [];
|
|
35
34
|
let clientPresetFiles = [];
|
|
36
35
|
const errors = [];
|
|
37
36
|
if (!shouldGenerateTrustedDocuments()) {
|
|
@@ -57,7 +56,7 @@ const generateClientPreset = async () => {
|
|
|
57
56
|
}
|
|
58
57
|
};
|
|
59
58
|
try {
|
|
60
|
-
generatedFiles = await (0, import_cli.generate)(config, true);
|
|
59
|
+
const generatedFiles = await (0, import_cli.generate)(config, true);
|
|
61
60
|
clientPresetFiles = generatedFiles.map((f) => f.filename);
|
|
62
61
|
const trustedDocumentsStoreFile = await (0, import_trustedDocuments.trustedDocumentsStore)(generatedFiles);
|
|
63
62
|
(0, import_trustedDocuments.replaceGqlTagWithTrustedDocumentGraphql)(generatedFiles);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/generate/generate.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/generate/generate.ts"],"names":[],"mappings":";AAWA,eAAO,MAAM,QAAQ;;;;;;EA6CpB,CAAA;AAED,eAAO,MAAM,GAAG,qBAoCf,CAAA"}
|
|
@@ -23,8 +23,10 @@ __export(generate_exports, {
|
|
|
23
23
|
run: () => run
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(generate_exports);
|
|
26
|
+
var import_loadEnvFiles = require("@cedarjs/cli-helpers/loadEnvFiles");
|
|
26
27
|
var import_project_config = require("@cedarjs/project-config");
|
|
27
28
|
var import_clientPreset = require("./clientPreset.js");
|
|
29
|
+
var import_gqlormSchema = require("./gqlormSchema.js");
|
|
28
30
|
var import_graphqlSchema = require("./graphqlSchema.js");
|
|
29
31
|
var import_possibleTypes = require("./possibleTypes.js");
|
|
30
32
|
var import_typeDefinitions = require("./typeDefinitions.js");
|
|
@@ -34,6 +36,7 @@ const generate = async () => {
|
|
|
34
36
|
const { typeDefFiles, errors: generateTypeDefsErrors } = await (0, import_typeDefinitions.generateTypeDefs)();
|
|
35
37
|
const clientPresetFiles = [];
|
|
36
38
|
const { possibleTypesFiles, errors: generatePossibleTypesErrors } = await (0, import_possibleTypes.generatePossibleTypes)();
|
|
39
|
+
const { files: gqlormFiles, errors: gqlormErrors } = config.experimental?.gqlorm?.enabled ? await (0, import_gqlormSchema.generateGqlormArtifacts)() : { files: [], errors: [] };
|
|
37
40
|
if (config.graphql.trustedDocuments) {
|
|
38
41
|
const preset = await (0, import_clientPreset.generateClientPreset)();
|
|
39
42
|
clientPresetFiles.push(...preset.clientPresetFiles);
|
|
@@ -46,18 +49,21 @@ const generate = async () => {
|
|
|
46
49
|
...files,
|
|
47
50
|
...typeDefFiles,
|
|
48
51
|
...clientPresetFiles,
|
|
49
|
-
...possibleTypesFiles
|
|
52
|
+
...possibleTypesFiles,
|
|
53
|
+
...gqlormFiles
|
|
50
54
|
].filter((x) => typeof x === "string");
|
|
51
55
|
return {
|
|
52
56
|
files,
|
|
53
57
|
errors: [
|
|
54
58
|
...generateGraphQLSchemaErrors,
|
|
55
59
|
...generateTypeDefsErrors,
|
|
56
|
-
...generatePossibleTypesErrors
|
|
60
|
+
...generatePossibleTypesErrors,
|
|
61
|
+
...gqlormErrors
|
|
57
62
|
]
|
|
58
63
|
};
|
|
59
64
|
};
|
|
60
65
|
const run = async () => {
|
|
66
|
+
(0, import_loadEnvFiles.loadEnvFiles)();
|
|
61
67
|
console.log("Generating...");
|
|
62
68
|
console.log();
|
|
63
69
|
const { files, errors } = await generate();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type * as DMMF from '@prisma/dmmf';
|
|
2
|
+
type ModelSchema = Record<string, string[]>;
|
|
3
|
+
/**
|
|
4
|
+
* Build a ModelSchema from a Prisma DMMF document.
|
|
5
|
+
*
|
|
6
|
+
* This is a pure function with no I/O — it can be called directly in tests
|
|
7
|
+
* with a mock DMMF object.
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildModelSchema(dmmf: DMMF.Document): ModelSchema;
|
|
10
|
+
/**
|
|
11
|
+
* Generate gqlorm artifacts from the Prisma schema.
|
|
12
|
+
*
|
|
13
|
+
* Reads the project's Prisma schema via DMMF, applies visibility rules
|
|
14
|
+
* (@gqlorm directives + sensitivity heuristics), and writes the resulting
|
|
15
|
+
* ModelSchema to `.cedar/gqlorm-schema.json`.
|
|
16
|
+
*
|
|
17
|
+
* Returns the same `{ files, errors }` shape used by other generators so it
|
|
18
|
+
* can be integrated into `generate.ts` without special handling.
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateGqlormArtifacts(): Promise<{
|
|
21
|
+
files: string[];
|
|
22
|
+
errors: {
|
|
23
|
+
message: string;
|
|
24
|
+
error: unknown;
|
|
25
|
+
}[];
|
|
26
|
+
}>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=gqlormSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gqlormSchema.d.ts","sourceRoot":"","sources":["../../../src/generate/gqlormSchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,IAAI,MAAM,cAAc,CAAA;AAgBzC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAiC3C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,GAAG,WAAW,CAkDjE;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC;IACvD,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;CAC9C,CAAC,CA+BD"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var gqlormSchema_exports = {};
|
|
30
|
+
__export(gqlormSchema_exports, {
|
|
31
|
+
buildModelSchema: () => buildModelSchema,
|
|
32
|
+
generateGqlormArtifacts: () => generateGqlormArtifacts
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(gqlormSchema_exports);
|
|
35
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
36
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
37
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
+
const INTERNAL_MODEL_NAMES = /* @__PURE__ */ new Set(["RW_DataMigration"]);
|
|
39
|
+
const SENSITIVE_PATTERNS = ["password", "secret", "token", "hash", "salt"];
|
|
40
|
+
function hasDirective(doc, directive) {
|
|
41
|
+
if (!doc) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return doc.split("\n").some((line) => line.trimStart().startsWith(`@gqlorm ${directive}`));
|
|
45
|
+
}
|
|
46
|
+
function isSensitiveField(fieldName) {
|
|
47
|
+
const lower = fieldName.toLowerCase();
|
|
48
|
+
return SENSITIVE_PATTERNS.some((pattern) => lower.includes(pattern));
|
|
49
|
+
}
|
|
50
|
+
function emitSensitivityWarning(modelName, fieldName) {
|
|
51
|
+
console.warn(
|
|
52
|
+
`[gqlorm] ${modelName}.${fieldName} was automatically hidden because its name appears sensitive. Add a directive to suppress this warning:
|
|
53
|
+
|
|
54
|
+
/// @gqlorm hide \u2013 to confirm it should stay hidden
|
|
55
|
+
/// @gqlorm show \u2013 to explicitly expose it
|
|
56
|
+
`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
function buildModelSchema(dmmf) {
|
|
60
|
+
const schema = {};
|
|
61
|
+
for (const model of dmmf.datamodel.models) {
|
|
62
|
+
if (INTERNAL_MODEL_NAMES.has(model.name)) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (hasDirective(model.documentation, "hide")) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const visibleFields = [];
|
|
69
|
+
for (const field of model.fields) {
|
|
70
|
+
if (field.kind !== "scalar" && field.kind !== "enum") {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (hasDirective(field.documentation, "hide")) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (hasDirective(field.documentation, "show")) {
|
|
77
|
+
visibleFields.push(field.name);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (isSensitiveField(field.name)) {
|
|
81
|
+
emitSensitivityWarning(model.name, field.name);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
visibleFields.push(field.name);
|
|
85
|
+
}
|
|
86
|
+
if (visibleFields.length > 0) {
|
|
87
|
+
const camelCaseName = model.name.charAt(0).toLowerCase() + model.name.slice(1);
|
|
88
|
+
schema[camelCaseName] = visibleFields;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return schema;
|
|
92
|
+
}
|
|
93
|
+
async function generateGqlormArtifacts() {
|
|
94
|
+
const files = [];
|
|
95
|
+
const errors = [];
|
|
96
|
+
try {
|
|
97
|
+
const { schemas } = await (0, import_project_config.getPrismaSchemas)();
|
|
98
|
+
const mod = await import("@prisma/internals");
|
|
99
|
+
const { getDMMF } = mod.default || mod;
|
|
100
|
+
const dmmf = await getDMMF({ datamodel: schemas });
|
|
101
|
+
const modelSchema = buildModelSchema(dmmf);
|
|
102
|
+
const outputPath = import_node_path.default.join(
|
|
103
|
+
(0, import_project_config.getPaths)().generated.base,
|
|
104
|
+
"gqlorm-schema.json"
|
|
105
|
+
);
|
|
106
|
+
import_node_fs.default.mkdirSync(import_node_path.default.dirname(outputPath), { recursive: true });
|
|
107
|
+
import_node_fs.default.writeFileSync(outputPath, JSON.stringify(modelSchema, null, 2));
|
|
108
|
+
files.push(outputPath);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
errors.push({
|
|
111
|
+
message: "Failed to generate gqlorm schema artifacts",
|
|
112
|
+
error
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return { files, errors };
|
|
116
|
+
}
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
buildModelSchema,
|
|
120
|
+
generateGqlormArtifacts
|
|
121
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphqlCodeGen.d.ts","sourceRoot":"","sources":["../../../src/generate/graphqlCodeGen.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"graphqlCodeGen.d.ts","sourceRoot":"","sources":["../../../src/generate/graphqlCodeGen.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAmB9D,KAAK,aAAa,GAAG;IACnB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,yBAAyB,QAAa,OAAO,CAAC,aAAa,CAiFvE,CAAA;AAED,eAAO,MAAM,yBAAyB,QAAa,OAAO,CAAC,aAAa,CAwDvE,CAAA;AAmCD,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM;SACD,MAAM;GAQ5D;AAmKD,eAAO,MAAM,iBAAiB,4RAe7B,CAAA"}
|
|
@@ -48,6 +48,7 @@ var import_load = require("@graphql-tools/load");
|
|
|
48
48
|
var import_execa = __toESM(require("execa"), 1);
|
|
49
49
|
var import_graphql = require("graphql");
|
|
50
50
|
var import_project_config = require("@cedarjs/project-config");
|
|
51
|
+
var import_packageManager = require("@cedarjs/project-config/packageManager");
|
|
51
52
|
var import_project = require("../project.js");
|
|
52
53
|
var rwTypescriptResolvers = __toESM(require("./plugins/rw-typescript-resolvers/index.js"), 1);
|
|
53
54
|
var CodegenSide = /* @__PURE__ */ ((CodegenSide2) => {
|
|
@@ -244,7 +245,9 @@ async function getPrismaClient() {
|
|
|
244
245
|
}
|
|
245
246
|
} catch {
|
|
246
247
|
}
|
|
247
|
-
|
|
248
|
+
const pm = (0, import_packageManager.getPackageManager)();
|
|
249
|
+
const pmExec = pm === "npm" ? "npx" : pm;
|
|
250
|
+
import_execa.default.sync(pmExec, ["cedar", "prisma", "generate"]);
|
|
248
251
|
try {
|
|
249
252
|
const freshPrisma = await importGeneratedPrismaClient();
|
|
250
253
|
const modelName = getModelName(freshPrisma);
|
|
@@ -36,9 +36,10 @@ var import_graphqlCodeGen = require("./graphqlCodeGen.js");
|
|
|
36
36
|
var import_graphqlSchema = require("./graphqlSchema.js");
|
|
37
37
|
var import_typeDefinitions = require("./typeDefinitions.js");
|
|
38
38
|
const rwjsPaths = (0, import_project_config.getPaths)();
|
|
39
|
+
const generatedDirName = import_path.default.basename(rwjsPaths.generated.base);
|
|
39
40
|
const watcher = import_chokidar.default.watch("(web|api)/src/**/*.{ts,js,jsx,tsx}", {
|
|
40
41
|
persistent: true,
|
|
41
|
-
ignored: ["node_modules",
|
|
42
|
+
ignored: ["node_modules", generatedDirName],
|
|
42
43
|
ignoreInitial: true,
|
|
43
44
|
cwd: rwjsPaths.base,
|
|
44
45
|
awaitWriteFinish: true
|
package/dist/cjs/index.js
CHANGED
|
@@ -17,22 +17,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
22
|
buildApi: () => import_api.buildApi,
|
|
23
23
|
generate: () => import_generate.generate,
|
|
24
24
|
listQueryTypeFieldsInProject: () => import_gql.listQueryTypeFieldsInProject
|
|
25
25
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
27
|
-
__reExport(
|
|
28
|
-
__reExport(
|
|
29
|
-
__reExport(
|
|
30
|
-
__reExport(
|
|
31
|
-
__reExport(
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
__reExport(index_exports, require("@cedarjs/project-config"), module.exports);
|
|
28
|
+
__reExport(index_exports, require("./ts2js.js"), module.exports);
|
|
29
|
+
__reExport(index_exports, require("./dev.js"), module.exports);
|
|
30
|
+
__reExport(index_exports, require("./routes.js"), module.exports);
|
|
31
|
+
__reExport(index_exports, require("./files.js"), module.exports);
|
|
32
32
|
var import_generate = require("./generate/generate.js");
|
|
33
33
|
var import_api = require("./build/api.js");
|
|
34
|
-
__reExport(
|
|
35
|
-
__reExport(
|
|
34
|
+
__reExport(index_exports, require("./validateSchema.js"), module.exports);
|
|
35
|
+
__reExport(index_exports, require("@cedarjs/babel-config"), module.exports);
|
|
36
36
|
var import_gql = require("./gql.js");
|
|
37
37
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
38
|
0 && (module.exports = {
|
package/dist/files.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPreset.d.ts","sourceRoot":"","sources":["../../src/generate/clientPreset.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,8BAA8B,QAAO,OAIjD,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;
|
|
1
|
+
{"version":3,"file":"clientPreset.d.ts","sourceRoot":"","sources":["../../src/generate/clientPreset.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,8BAA8B,QAAO,OAIjD,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;iBAGN,MAAM;eAAS,OAAO;;;;;;iBAAtB,MAAM;eAAS,OAAO;;EAoDhD,CAAA"}
|
|
@@ -10,7 +10,6 @@ const shouldGenerateTrustedDocuments = () => {
|
|
|
10
10
|
return config.graphql.trustedDocuments;
|
|
11
11
|
};
|
|
12
12
|
const generateClientPreset = async () => {
|
|
13
|
-
let generatedFiles = [];
|
|
14
13
|
let clientPresetFiles = [];
|
|
15
14
|
const errors = [];
|
|
16
15
|
if (!shouldGenerateTrustedDocuments()) {
|
|
@@ -36,7 +35,7 @@ const generateClientPreset = async () => {
|
|
|
36
35
|
}
|
|
37
36
|
};
|
|
38
37
|
try {
|
|
39
|
-
generatedFiles = await generate(config, true);
|
|
38
|
+
const generatedFiles = await generate(config, true);
|
|
40
39
|
clientPresetFiles = generatedFiles.map((f) => f.filename);
|
|
41
40
|
const trustedDocumentsStoreFile = await trustedDocumentsStore(generatedFiles);
|
|
42
41
|
replaceGqlTagWithTrustedDocumentGraphql(generatedFiles);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/generate/generate.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/generate/generate.ts"],"names":[],"mappings":";AAWA,eAAO,MAAM,QAAQ;;;;;;EA6CpB,CAAA;AAED,eAAO,MAAM,GAAG,qBAoCf,CAAA"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { loadEnvFiles } from "@cedarjs/cli-helpers/loadEnvFiles";
|
|
2
3
|
import { getConfig, getPaths } from "@cedarjs/project-config";
|
|
3
4
|
import { generateClientPreset } from "./clientPreset.js";
|
|
5
|
+
import { generateGqlormArtifacts } from "./gqlormSchema.js";
|
|
4
6
|
import { generateGraphQLSchema } from "./graphqlSchema.js";
|
|
5
7
|
import { generatePossibleTypes } from "./possibleTypes.js";
|
|
6
8
|
import { generateTypeDefs } from "./typeDefinitions.js";
|
|
@@ -10,6 +12,7 @@ const generate = async () => {
|
|
|
10
12
|
const { typeDefFiles, errors: generateTypeDefsErrors } = await generateTypeDefs();
|
|
11
13
|
const clientPresetFiles = [];
|
|
12
14
|
const { possibleTypesFiles, errors: generatePossibleTypesErrors } = await generatePossibleTypes();
|
|
15
|
+
const { files: gqlormFiles, errors: gqlormErrors } = config.experimental?.gqlorm?.enabled ? await generateGqlormArtifacts() : { files: [], errors: [] };
|
|
13
16
|
if (config.graphql.trustedDocuments) {
|
|
14
17
|
const preset = await generateClientPreset();
|
|
15
18
|
clientPresetFiles.push(...preset.clientPresetFiles);
|
|
@@ -22,18 +25,21 @@ const generate = async () => {
|
|
|
22
25
|
...files,
|
|
23
26
|
...typeDefFiles,
|
|
24
27
|
...clientPresetFiles,
|
|
25
|
-
...possibleTypesFiles
|
|
28
|
+
...possibleTypesFiles,
|
|
29
|
+
...gqlormFiles
|
|
26
30
|
].filter((x) => typeof x === "string");
|
|
27
31
|
return {
|
|
28
32
|
files,
|
|
29
33
|
errors: [
|
|
30
34
|
...generateGraphQLSchemaErrors,
|
|
31
35
|
...generateTypeDefsErrors,
|
|
32
|
-
...generatePossibleTypesErrors
|
|
36
|
+
...generatePossibleTypesErrors,
|
|
37
|
+
...gqlormErrors
|
|
33
38
|
]
|
|
34
39
|
};
|
|
35
40
|
};
|
|
36
41
|
const run = async () => {
|
|
42
|
+
loadEnvFiles();
|
|
37
43
|
console.log("Generating...");
|
|
38
44
|
console.log();
|
|
39
45
|
const { files, errors } = await generate();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type * as DMMF from '@prisma/dmmf';
|
|
2
|
+
type ModelSchema = Record<string, string[]>;
|
|
3
|
+
/**
|
|
4
|
+
* Build a ModelSchema from a Prisma DMMF document.
|
|
5
|
+
*
|
|
6
|
+
* This is a pure function with no I/O — it can be called directly in tests
|
|
7
|
+
* with a mock DMMF object.
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildModelSchema(dmmf: DMMF.Document): ModelSchema;
|
|
10
|
+
/**
|
|
11
|
+
* Generate gqlorm artifacts from the Prisma schema.
|
|
12
|
+
*
|
|
13
|
+
* Reads the project's Prisma schema via DMMF, applies visibility rules
|
|
14
|
+
* (@gqlorm directives + sensitivity heuristics), and writes the resulting
|
|
15
|
+
* ModelSchema to `.cedar/gqlorm-schema.json`.
|
|
16
|
+
*
|
|
17
|
+
* Returns the same `{ files, errors }` shape used by other generators so it
|
|
18
|
+
* can be integrated into `generate.ts` without special handling.
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateGqlormArtifacts(): Promise<{
|
|
21
|
+
files: string[];
|
|
22
|
+
errors: {
|
|
23
|
+
message: string;
|
|
24
|
+
error: unknown;
|
|
25
|
+
}[];
|
|
26
|
+
}>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=gqlormSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gqlormSchema.d.ts","sourceRoot":"","sources":["../../src/generate/gqlormSchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,IAAI,MAAM,cAAc,CAAA;AAgBzC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAiC3C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,GAAG,WAAW,CAkDjE;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC;IACvD,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;CAC9C,CAAC,CA+BD"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { getPaths, getPrismaSchemas } from "@cedarjs/project-config";
|
|
4
|
+
const INTERNAL_MODEL_NAMES = /* @__PURE__ */ new Set(["RW_DataMigration"]);
|
|
5
|
+
const SENSITIVE_PATTERNS = ["password", "secret", "token", "hash", "salt"];
|
|
6
|
+
function hasDirective(doc, directive) {
|
|
7
|
+
if (!doc) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return doc.split("\n").some((line) => line.trimStart().startsWith(`@gqlorm ${directive}`));
|
|
11
|
+
}
|
|
12
|
+
function isSensitiveField(fieldName) {
|
|
13
|
+
const lower = fieldName.toLowerCase();
|
|
14
|
+
return SENSITIVE_PATTERNS.some((pattern) => lower.includes(pattern));
|
|
15
|
+
}
|
|
16
|
+
function emitSensitivityWarning(modelName, fieldName) {
|
|
17
|
+
console.warn(
|
|
18
|
+
`[gqlorm] ${modelName}.${fieldName} was automatically hidden because its name appears sensitive. Add a directive to suppress this warning:
|
|
19
|
+
|
|
20
|
+
/// @gqlorm hide \u2013 to confirm it should stay hidden
|
|
21
|
+
/// @gqlorm show \u2013 to explicitly expose it
|
|
22
|
+
`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
function buildModelSchema(dmmf) {
|
|
26
|
+
const schema = {};
|
|
27
|
+
for (const model of dmmf.datamodel.models) {
|
|
28
|
+
if (INTERNAL_MODEL_NAMES.has(model.name)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (hasDirective(model.documentation, "hide")) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const visibleFields = [];
|
|
35
|
+
for (const field of model.fields) {
|
|
36
|
+
if (field.kind !== "scalar" && field.kind !== "enum") {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (hasDirective(field.documentation, "hide")) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (hasDirective(field.documentation, "show")) {
|
|
43
|
+
visibleFields.push(field.name);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (isSensitiveField(field.name)) {
|
|
47
|
+
emitSensitivityWarning(model.name, field.name);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
visibleFields.push(field.name);
|
|
51
|
+
}
|
|
52
|
+
if (visibleFields.length > 0) {
|
|
53
|
+
const camelCaseName = model.name.charAt(0).toLowerCase() + model.name.slice(1);
|
|
54
|
+
schema[camelCaseName] = visibleFields;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return schema;
|
|
58
|
+
}
|
|
59
|
+
async function generateGqlormArtifacts() {
|
|
60
|
+
const files = [];
|
|
61
|
+
const errors = [];
|
|
62
|
+
try {
|
|
63
|
+
const { schemas } = await getPrismaSchemas();
|
|
64
|
+
const mod = await import("@prisma/internals");
|
|
65
|
+
const { getDMMF } = mod.default || mod;
|
|
66
|
+
const dmmf = await getDMMF({ datamodel: schemas });
|
|
67
|
+
const modelSchema = buildModelSchema(dmmf);
|
|
68
|
+
const outputPath = path.join(
|
|
69
|
+
getPaths().generated.base,
|
|
70
|
+
"gqlorm-schema.json"
|
|
71
|
+
);
|
|
72
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
73
|
+
fs.writeFileSync(outputPath, JSON.stringify(modelSchema, null, 2));
|
|
74
|
+
files.push(outputPath);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
errors.push({
|
|
77
|
+
message: "Failed to generate gqlorm schema artifacts",
|
|
78
|
+
error
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return { files, errors };
|
|
82
|
+
}
|
|
83
|
+
export {
|
|
84
|
+
buildModelSchema,
|
|
85
|
+
generateGqlormArtifacts
|
|
86
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphqlCodeGen.d.ts","sourceRoot":"","sources":["../../src/generate/graphqlCodeGen.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"graphqlCodeGen.d.ts","sourceRoot":"","sources":["../../src/generate/graphqlCodeGen.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAmB9D,KAAK,aAAa,GAAG;IACnB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,yBAAyB,QAAa,OAAO,CAAC,aAAa,CAiFvE,CAAA;AAED,eAAO,MAAM,yBAAyB,QAAa,OAAO,CAAC,aAAa,CAwDvE,CAAA;AAmCD,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM;SACD,MAAM;GAQ5D;AAmKD,eAAO,MAAM,iBAAiB,4RAe7B,CAAA"}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
getConfig,
|
|
17
17
|
resolveGeneratedPrismaClient
|
|
18
18
|
} from "@cedarjs/project-config";
|
|
19
|
+
import { getPackageManager } from "@cedarjs/project-config/packageManager";
|
|
19
20
|
import { getTsConfigs } from "../project.js";
|
|
20
21
|
import * as rwTypescriptResolvers from "./plugins/rw-typescript-resolvers/index.js";
|
|
21
22
|
var CodegenSide = /* @__PURE__ */ ((CodegenSide2) => {
|
|
@@ -212,7 +213,9 @@ async function getPrismaClient() {
|
|
|
212
213
|
}
|
|
213
214
|
} catch {
|
|
214
215
|
}
|
|
215
|
-
|
|
216
|
+
const pm = getPackageManager();
|
|
217
|
+
const pmExec = pm === "npm" ? "npx" : pm;
|
|
218
|
+
execa.sync(pmExec, ["cedar", "prisma", "generate"]);
|
|
216
219
|
try {
|
|
217
220
|
const freshPrisma = await importGeneratedPrismaClient();
|
|
218
221
|
const modelName = getModelName(freshPrisma);
|
package/dist/generate/watch.js
CHANGED
|
@@ -28,9 +28,10 @@ import {
|
|
|
28
28
|
mirrorPathForCell
|
|
29
29
|
} from "./typeDefinitions.js";
|
|
30
30
|
const rwjsPaths = getPaths();
|
|
31
|
+
const generatedDirName = path.basename(rwjsPaths.generated.base);
|
|
31
32
|
const watcher = chokidar.watch("(web|api)/src/**/*.{ts,js,jsx,tsx}", {
|
|
32
33
|
persistent: true,
|
|
33
|
-
ignored: ["node_modules",
|
|
34
|
+
ignored: ["node_modules", generatedDirName],
|
|
34
35
|
ignoreInitial: true,
|
|
35
36
|
cwd: rwjsPaths.base,
|
|
36
37
|
awaitWriteFinish: true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/internal",
|
|
3
|
-
"version": "3.1.2-next.
|
|
3
|
+
"version": "3.1.2-next.128+165de00ea8",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -119,12 +119,22 @@
|
|
|
119
119
|
"types": "./dist/cjs/generate/generate.d.ts",
|
|
120
120
|
"default": "./dist/cjs/generate/generate.js"
|
|
121
121
|
}
|
|
122
|
+
},
|
|
123
|
+
"./dist/generate/gqlormSchema": {
|
|
124
|
+
"import": {
|
|
125
|
+
"types": "./dist/generate/gqlormSchema.d.ts",
|
|
126
|
+
"default": "./dist/generate/gqlormSchema.js"
|
|
127
|
+
},
|
|
128
|
+
"require": {
|
|
129
|
+
"types": "./dist/cjs/generate/gqlormSchema.d.ts",
|
|
130
|
+
"default": "./dist/cjs/generate/gqlormSchema.js"
|
|
131
|
+
}
|
|
122
132
|
}
|
|
123
133
|
},
|
|
124
134
|
"types": "dist/index.d.ts",
|
|
125
135
|
"bin": {
|
|
126
|
-
"
|
|
127
|
-
"
|
|
136
|
+
"cedar-gen": "./dist/generate/generate.js",
|
|
137
|
+
"cedar-gen-watch": "./dist/generate/watch.js"
|
|
128
138
|
},
|
|
129
139
|
"files": [
|
|
130
140
|
"dist"
|
|
@@ -149,11 +159,12 @@
|
|
|
149
159
|
"@babel/plugin-transform-react-jsx": "7.28.6",
|
|
150
160
|
"@babel/plugin-transform-typescript": "^7.26.8",
|
|
151
161
|
"@babel/traverse": "7.29.0",
|
|
152
|
-
"@cedarjs/babel-config": "3.1.2-next.
|
|
153
|
-
"@cedarjs/
|
|
154
|
-
"@cedarjs/
|
|
155
|
-
"@cedarjs/
|
|
156
|
-
"@cedarjs/
|
|
162
|
+
"@cedarjs/babel-config": "3.1.2-next.128+165de00ea8",
|
|
163
|
+
"@cedarjs/cli-helpers": "3.1.2-next.128+165de00ea8",
|
|
164
|
+
"@cedarjs/graphql-server": "3.1.2-next.128+165de00ea8",
|
|
165
|
+
"@cedarjs/project-config": "3.1.2-next.128+165de00ea8",
|
|
166
|
+
"@cedarjs/router": "3.1.2-next.128+165de00ea8",
|
|
167
|
+
"@cedarjs/structure": "3.1.2-next.128+165de00ea8",
|
|
157
168
|
"@graphql-codegen/add": "6.0.0",
|
|
158
169
|
"@graphql-codegen/cli": "6.2.1",
|
|
159
170
|
"@graphql-codegen/client-preset": "5.2.4",
|
|
@@ -166,12 +177,14 @@
|
|
|
166
177
|
"@graphql-codegen/typescript-react-apollo": "4.4.1",
|
|
167
178
|
"@graphql-codegen/typescript-resolvers": "5.1.7",
|
|
168
179
|
"@graphql-tools/documents": "1.0.1",
|
|
180
|
+
"@prisma/dmmf": "7.7.0",
|
|
181
|
+
"@prisma/internals": "7.7.0",
|
|
169
182
|
"@sdl-codegen/node": "2.0.1",
|
|
170
183
|
"ansis": "4.2.0",
|
|
171
184
|
"deepmerge": "4.3.1",
|
|
172
|
-
"esbuild": "0.
|
|
185
|
+
"esbuild": "0.27.7",
|
|
173
186
|
"fast-glob": "3.3.3",
|
|
174
|
-
"graphql": "16.13.
|
|
187
|
+
"graphql": "16.13.2",
|
|
175
188
|
"kill-port": "1.6.1",
|
|
176
189
|
"prettier": "3.8.1",
|
|
177
190
|
"rimraf": "6.1.3",
|
|
@@ -184,7 +197,7 @@
|
|
|
184
197
|
},
|
|
185
198
|
"devDependencies": {
|
|
186
199
|
"@arethetypeswrong/cli": "0.18.2",
|
|
187
|
-
"@cedarjs/framework-tools": "3.1.2-next.
|
|
200
|
+
"@cedarjs/framework-tools": "3.1.2-next.128",
|
|
188
201
|
"concurrently": "9.2.1",
|
|
189
202
|
"graphql-tag": "2.12.6",
|
|
190
203
|
"publint": "0.3.18",
|
|
@@ -197,5 +210,5 @@
|
|
|
197
210
|
"publishConfig": {
|
|
198
211
|
"access": "public"
|
|
199
212
|
},
|
|
200
|
-
"gitHead": "
|
|
213
|
+
"gitHead": "165de00ea86321332d0905102862b1165bcb726f"
|
|
201
214
|
}
|