@prisma/schema-files-loader 6.4.0-dev.6 → 6.4.0-dev.60

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/index.d.ts CHANGED
@@ -24,6 +24,8 @@ export declare type ConfigMetaFormat = {
24
24
  }>;
25
25
  };
26
26
 
27
+ export declare function ensureType(entryPath: string, expectedType: PathType): Promise<NonFatalLookupError | undefined>;
28
+
27
29
  export declare interface FilesResolver {
28
30
  listDirContents(path: string): Promise<string[]>;
29
31
  getEntryType(path: string): Promise<FsEntryType | undefined>;
@@ -45,6 +47,25 @@ export declare type GetConfigResponse = {
45
47
  config: ConfigMetaFormat;
46
48
  };
47
49
 
50
+ export declare type GetSchemaResult = {
51
+ /**
52
+ * A path from which schema was loaded.
53
+ * Can be either folder or a single file
54
+ */
55
+ schemaPath: string;
56
+ /**
57
+ * Base dir for all of the schema files.
58
+ * In-multi file mode, this is equal to `schemaPath`.
59
+ * In single-file mode, this is a parent directory of
60
+ * a file
61
+ */
62
+ schemaRootDir: string;
63
+ /**
64
+ * All loaded schema files
65
+ */
66
+ schemas: Array<LoadedFile>;
67
+ };
68
+
48
69
  export declare class InMemoryFilesResolver implements FilesResolver {
49
70
  private _tree;
50
71
  private _fileNameToKey;
@@ -73,8 +94,33 @@ export declare function loadRelatedSchemaFiles(filePath: string, filesResolver?:
73
94
  */
74
95
  export declare function loadSchemaFiles(folderPath: string, filesResolver?: FilesResolver): Promise<LoadedFile[]>;
75
96
 
97
+ export declare type LookupResult = SuccessfulLookupResult | {
98
+ ok: false;
99
+ error: NonFatalLookupError;
100
+ };
101
+
102
+ export declare type NonFatalLookupError = {
103
+ kind: 'NotFound';
104
+ expectedType?: PathType;
105
+ path: string;
106
+ } | {
107
+ kind: 'WrongType';
108
+ path: string;
109
+ expectedTypes: PathType[];
110
+ } | {
111
+ kind: 'FolderPreviewNotEnabled';
112
+ path: string;
113
+ };
114
+
115
+ export declare type PathType = 'file' | 'directory';
116
+
76
117
  export declare const realFsResolver: FilesResolver;
77
118
 
119
+ export declare type SuccessfulLookupResult = {
120
+ ok: true;
121
+ schema: GetSchemaResult;
122
+ };
123
+
78
124
  export declare function usesPrismaSchemaFolder(config: ConfigMetaFormat): boolean;
79
125
 
80
126
  export { }
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  CompositeFilesResolver: () => CompositeFilesResolver,
34
34
  InMemoryFilesResolver: () => InMemoryFilesResolver,
35
+ ensureType: () => ensureType,
35
36
  loadRelatedSchemaFiles: () => loadRelatedSchemaFiles,
36
37
  loadSchemaFiles: () => loadSchemaFiles,
37
38
  realFsResolver: () => realFsResolver,
@@ -280,10 +281,31 @@ async function findSchemaRoot(filePath, filesResolver) {
280
281
  }
281
282
  return void 0;
282
283
  }
284
+
285
+ // src/utils/ensureType.ts
286
+ var import_promises = __toESM(require("node:fs/promises"));
287
+ async function ensureType(entryPath, expectedType) {
288
+ try {
289
+ const pathStat = await import_promises.default.stat(entryPath);
290
+ if (expectedType === "file" && pathStat.isFile()) {
291
+ return void 0;
292
+ }
293
+ if (expectedType === "directory" && pathStat.isDirectory()) {
294
+ return void 0;
295
+ }
296
+ return { kind: "WrongType", path: entryPath, expectedTypes: [expectedType] };
297
+ } catch (e) {
298
+ if (e.code === "ENOENT") {
299
+ return { kind: "NotFound", path: entryPath, expectedType };
300
+ }
301
+ throw e;
302
+ }
303
+ }
283
304
  // Annotate the CommonJS export names for ESM import in node:
284
305
  0 && (module.exports = {
285
306
  CompositeFilesResolver,
286
307
  InMemoryFilesResolver,
308
+ ensureType,
287
309
  loadRelatedSchemaFiles,
288
310
  loadSchemaFiles,
289
311
  realFsResolver,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/schema-files-loader",
3
- "version": "6.4.0-dev.6",
3
+ "version": "6.4.0-dev.60",
4
4
  "description": "Package for resolving and loading schema files when schema is split into multiple files",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "sideEffects": false,
18
18
  "dependencies": {
19
- "@prisma/prisma-schema-wasm": "6.4.0-4.e2a33755136ec1c2b3a5d7d322f86a8fb1205a40",
19
+ "@prisma/prisma-schema-wasm": "6.4.0-29.a9055b89e58b4b5bfb59600785423b1db3d0e75d",
20
20
  "fs-extra": "11.1.1"
21
21
  },
22
22
  "devDependencies": {