@prisma/studio-core 0.0.0-dev.202503182320

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.
@@ -0,0 +1,145 @@
1
+ export type Either<E, R> = [E] | [null, R];
2
+
3
+ export interface Adapter {
4
+ introspect(): Promise<Either<Error, InstrospectResult>>;
5
+ query(input: QueryInput): Promise<Either<Error, QueryResult>>;
6
+ mutate(inputs: MutateInput[]): Promise<Either<Error, MutateResult>>;
7
+ alter(inputs: AlterInput[]): Promise<Either<Error, AlterResult>>;
8
+ rawQuery(input: RawQueryInput): Promise<Either<Error, RawQueryResult>>;
9
+ }
10
+
11
+ export type EnumName = string;
12
+ export type TableName = string;
13
+ export type ColumnName = string;
14
+ export type SchemaName = string;
15
+
16
+ export type InstrospectResult = {
17
+ schemas: Record<SchemaName, InstrospectSchemaMeta>;
18
+ filters: Record<QueryFilterOperator, boolean>;
19
+ }
20
+
21
+ export type InstrospectSchemaMeta = {
22
+ tables: Record<TableName, InstrospectTableMeta>;
23
+ enums: Record<EnumName, EnumMeta>
24
+ }
25
+
26
+ export type InstrospectTableMeta = {
27
+ schema: SchemaName;
28
+ name: TableName;
29
+ columns: Record<ColumnName, InstrospectColumnMeta>;
30
+ }
31
+
32
+ export type InstrospectColumnMeta = {
33
+ schema: SchemaName;
34
+ table: TableName;
35
+ name: ColumnName;
36
+ dataType: IntrospectDataType;
37
+ uiType: IntrospectUiType;
38
+ defaults: unknown;
39
+ nullable: boolean;
40
+ partOfPk: boolean;
41
+ reference: InstrospectTableMeta | null;
42
+ }
43
+
44
+ export type IntrospectDataType = {
45
+ name: string;
46
+ args: (string | number)[];
47
+ }
48
+
49
+ export type IntrospectUiType =
50
+ | {
51
+ kind: 'string'
52
+ isList: boolean;
53
+ max: number;
54
+ min: number;
55
+ }
56
+ | {
57
+ kind: 'number'
58
+ isList: boolean;
59
+ max: number;
60
+ min: number;
61
+ }
62
+ | {
63
+ kind: 'decimal'
64
+ isList: boolean;
65
+ max: number;
66
+ min: number;
67
+ decimalPlaces: number;
68
+ }
69
+ | {
70
+ kind: 'boolean'
71
+ isList: boolean;
72
+ }
73
+ | {
74
+ kind: 'datetime'
75
+ isList: boolean;
76
+ }
77
+ | {
78
+ kind: 'json'
79
+ isList: boolean;
80
+ }
81
+ | {
82
+ kind: 'blob'
83
+ isList: boolean;
84
+ }
85
+ | {
86
+ kind: 'enum'
87
+ isList: boolean;
88
+ name: EnumName;
89
+ values: string[];
90
+ }
91
+
92
+ export type EnumMeta = {
93
+ name: EnumName;
94
+ values: string[];
95
+ }
96
+
97
+ export type QueryInput = {
98
+ schema: SchemaName;
99
+ table: TableName;
100
+ filters: QueryFilter[][];
101
+ sortings: QuerySorting[];
102
+ limit?: number;
103
+ offset?: number;
104
+ }
105
+
106
+ export type QueryFilter = {
107
+ column: ColumnName;
108
+ operator: QueryFilterOperator;
109
+ value: unknown[] | InstrospectColumnMeta[];
110
+ not?: boolean;
111
+ }
112
+
113
+ export type QuerySorting = {
114
+ column: ColumnName;
115
+ order: 'asc' | 'desc';
116
+ }
117
+
118
+ export type QueryFilterOperator = '=' | '>=' | '>' | '<=' | '<' | 'like' | 'ilike' | 'is null' | (string & {})
119
+
120
+ export type QueryResult = {
121
+ schema: SchemaName;
122
+ table: TableName;
123
+ fetchedAt: number;
124
+ duration: number;
125
+ rows: Record<ColumnName, QueryResultColumn>[]
126
+ count: number;
127
+ }
128
+
129
+ export type QueryResultColumn = {
130
+ column: ColumnName;
131
+ value: unknown;
132
+ dataType?: IntrospectDataType;
133
+ uiType?: IntrospectUiType;
134
+ }
135
+
136
+ // TODO: Implement the following types
137
+
138
+ export type MutateInput = {}
139
+ export type MutateResult = {}
140
+
141
+ export type AlterInput = {}
142
+ export type AlterResult = {}
143
+
144
+ export type RawQueryInput = {}
145
+ export type RawQueryResult = {}
@@ -0,0 +1,201 @@
1
+ import { Adapter, AlterInput, AlterResult, Either, InstrospectResult, MutateInput, MutateResult, QueryInput, QueryResult, RawQueryInput, RawQueryResult } from "./Adapter";
2
+
3
+ export class AdapterMock implements Adapter {
4
+ async introspect(): Promise<Either<Error, InstrospectResult>> {
5
+ return [null, {
6
+ schemas: {
7
+ public: {
8
+ tables: {
9
+ users: {
10
+ schema: "public",
11
+ name: "users",
12
+ columns: {
13
+ id: {
14
+ schema: "public",
15
+ table: "users",
16
+ name: "id",
17
+ dataType: { name: "integer", args: [] },
18
+ uiType: { kind: "number", isList: false, max: 10000, min: 0 },
19
+ defaults: null,
20
+ nullable: false,
21
+ partOfPk: true,
22
+ reference: null,
23
+ },
24
+ name: {
25
+ schema: "public",
26
+ table: "users",
27
+ name: "name",
28
+ dataType: { name: "varchar", args: [255] },
29
+ uiType: { kind: "string", isList: false, max: 255, min: 0 },
30
+ defaults: null,
31
+ nullable: false,
32
+ partOfPk: false,
33
+ reference: null,
34
+ },
35
+ role: {
36
+ schema: "public",
37
+ table: "users",
38
+ name: "role",
39
+ dataType: { name: "enum", args: [] },
40
+ uiType: {
41
+ kind: "enum",
42
+ isList: false,
43
+ name: "UserRole",
44
+ values: ["admin", "user", "guest"],
45
+ },
46
+ defaults: "user",
47
+ nullable: false,
48
+ partOfPk: false,
49
+ reference: null,
50
+ },
51
+ },
52
+ },
53
+ posts: {
54
+ schema: "public",
55
+ name: "posts",
56
+ columns: {
57
+ id: {
58
+ schema: "public",
59
+ table: "posts",
60
+ name: "id",
61
+ dataType: { name: "integer", args: [] },
62
+ uiType: { kind: "number", isList: false, max: 10000, min: 0 },
63
+ defaults: null,
64
+ nullable: false,
65
+ partOfPk: true,
66
+ reference: null,
67
+ },
68
+ title: {
69
+ schema: "public",
70
+ table: "posts",
71
+ name: "title",
72
+ dataType: { name: "varchar", args: [255] },
73
+ uiType: { kind: "string", isList: false, max: 255, min: 0 },
74
+ defaults: null,
75
+ nullable: false,
76
+ partOfPk: false,
77
+ reference: null,
78
+ },
79
+ content: {
80
+ schema: "public",
81
+ table: "posts",
82
+ name: "content",
83
+ dataType: { name: "text", args: [] },
84
+ uiType: { kind: "string", isList: false, max: 10000, min: 0 },
85
+ defaults: null,
86
+ nullable: true,
87
+ partOfPk: false,
88
+ reference: null,
89
+ },
90
+ userId: {
91
+ schema: "public",
92
+ table: "posts",
93
+ name: "userId",
94
+ dataType: { name: "integer", args: [] },
95
+ uiType: { kind: "number", isList: false, max: 10000, min: 0 },
96
+ defaults: null,
97
+ nullable: false,
98
+ partOfPk: false,
99
+ reference: {
100
+ schema: "public",
101
+ name: "users",
102
+ columns: {}, // This can be expanded if needed.
103
+ },
104
+ },
105
+ },
106
+ },
107
+ },
108
+ enums: {
109
+ UserRole: {
110
+ name: "UserRole",
111
+ values: ["admin", "user", "guest"],
112
+ },
113
+ },
114
+ },
115
+ },
116
+ filters: {
117
+ "=": true,
118
+ ">=": true,
119
+ ">": true,
120
+ "<=": true,
121
+ "<": true,
122
+ "like": true,
123
+ "ilike": false,
124
+ "is null": true,
125
+ },
126
+ }]
127
+ }
128
+ async query(input: QueryInput): Promise<Either<Error, QueryResult>> {
129
+ return [
130
+ null,
131
+ {
132
+ schema: "public",
133
+ table: "users",
134
+ fetchedAt: Date.now(),
135
+ duration: 35,
136
+ count: 2,
137
+ rows: [
138
+ {
139
+ id: {
140
+ column: "id",
141
+ value: 1,
142
+ dataType: { name: "integer", args: [] },
143
+ uiType: { kind: "number", isList: false, max: 10000, min: 0 },
144
+ },
145
+ name: {
146
+ column: "name",
147
+ value: "Alice",
148
+ dataType: { name: "varchar", args: [255] },
149
+ uiType: { kind: "string", isList: false, max: 255, min: 0 },
150
+ },
151
+ role: {
152
+ column: "role",
153
+ value: "admin",
154
+ dataType: { name: "enum", args: [] },
155
+ uiType: {
156
+ kind: "enum",
157
+ isList: false,
158
+ name: "UserRole",
159
+ values: ["admin", "user", "guest"],
160
+ },
161
+ },
162
+ },
163
+ {
164
+ id: {
165
+ column: "id",
166
+ value: 2,
167
+ dataType: { name: "integer", args: [] },
168
+ uiType: { kind: "number", isList: false, max: 10000, min: 0 },
169
+ },
170
+ name: {
171
+ column: "name",
172
+ value: "Bob",
173
+ dataType: { name: "varchar", args: [255] },
174
+ uiType: { kind: "string", isList: false, max: 255, min: 0 },
175
+ },
176
+ role: {
177
+ column: "role",
178
+ value: "user",
179
+ dataType: { name: "enum", args: [] },
180
+ uiType: {
181
+ kind: "enum",
182
+ isList: false,
183
+ name: "UserRole",
184
+ values: ["admin", "user", "guest"],
185
+ },
186
+ },
187
+ },
188
+ ],
189
+ },
190
+ ]
191
+ }
192
+ async mutate(inputs: MutateInput[]): Promise<Either<Error, MutateResult>> {
193
+ throw new Error("Method not implemented.");
194
+ }
195
+ async alter(inputs: AlterInput[]): Promise<Either<Error, AlterResult>> {
196
+ throw new Error("Method not implemented.");
197
+ }
198
+ async rawQuery(input: RawQueryInput): Promise<Either<Error, RawQueryResult>> {
199
+ throw new Error("Method not implemented.");
200
+ }
201
+ }
package/data/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { type Adapter } from './adapter/Adapter';
2
+ export { AdapterMock } from './adapter/AdapterMock';
@@ -0,0 +1,127 @@
1
+ type Either<E, R> = [E] | [null, R];
2
+ interface Adapter {
3
+ introspect(): Promise<Either<Error, InstrospectResult>>;
4
+ query(input: QueryInput): Promise<Either<Error, QueryResult>>;
5
+ mutate(inputs: MutateInput[]): Promise<Either<Error, MutateResult>>;
6
+ alter(inputs: AlterInput[]): Promise<Either<Error, AlterResult>>;
7
+ rawQuery(input: RawQueryInput): Promise<Either<Error, RawQueryResult>>;
8
+ }
9
+ type EnumName = string;
10
+ type TableName = string;
11
+ type ColumnName = string;
12
+ type SchemaName = string;
13
+ type InstrospectResult = {
14
+ schemas: Record<SchemaName, InstrospectSchemaMeta>;
15
+ filters: Record<QueryFilterOperator, boolean>;
16
+ };
17
+ type InstrospectSchemaMeta = {
18
+ tables: Record<TableName, InstrospectTableMeta>;
19
+ enums: Record<EnumName, EnumMeta>;
20
+ };
21
+ type InstrospectTableMeta = {
22
+ schema: SchemaName;
23
+ name: TableName;
24
+ columns: Record<ColumnName, InstrospectColumnMeta>;
25
+ };
26
+ type InstrospectColumnMeta = {
27
+ schema: SchemaName;
28
+ table: TableName;
29
+ name: ColumnName;
30
+ dataType: IntrospectDataType;
31
+ uiType: IntrospectUiType;
32
+ defaults: unknown;
33
+ nullable: boolean;
34
+ partOfPk: boolean;
35
+ reference: InstrospectTableMeta | null;
36
+ };
37
+ type IntrospectDataType = {
38
+ name: string;
39
+ args: (string | number)[];
40
+ };
41
+ type IntrospectUiType = {
42
+ kind: 'string';
43
+ isList: boolean;
44
+ max: number;
45
+ min: number;
46
+ } | {
47
+ kind: 'number';
48
+ isList: boolean;
49
+ max: number;
50
+ min: number;
51
+ } | {
52
+ kind: 'decimal';
53
+ isList: boolean;
54
+ max: number;
55
+ min: number;
56
+ decimalPlaces: number;
57
+ } | {
58
+ kind: 'boolean';
59
+ isList: boolean;
60
+ } | {
61
+ kind: 'datetime';
62
+ isList: boolean;
63
+ } | {
64
+ kind: 'json';
65
+ isList: boolean;
66
+ } | {
67
+ kind: 'blob';
68
+ isList: boolean;
69
+ } | {
70
+ kind: 'enum';
71
+ isList: boolean;
72
+ name: EnumName;
73
+ values: string[];
74
+ };
75
+ type EnumMeta = {
76
+ name: EnumName;
77
+ values: string[];
78
+ };
79
+ type QueryInput = {
80
+ schema: SchemaName;
81
+ table: TableName;
82
+ filters: QueryFilter[][];
83
+ sortings: QuerySorting[];
84
+ limit?: number;
85
+ offset?: number;
86
+ };
87
+ type QueryFilter = {
88
+ column: ColumnName;
89
+ operator: QueryFilterOperator;
90
+ value: unknown[] | InstrospectColumnMeta[];
91
+ not?: boolean;
92
+ };
93
+ type QuerySorting = {
94
+ column: ColumnName;
95
+ order: 'asc' | 'desc';
96
+ };
97
+ type QueryFilterOperator = '=' | '>=' | '>' | '<=' | '<' | 'like' | 'ilike' | 'is null' | (string & {});
98
+ type QueryResult = {
99
+ schema: SchemaName;
100
+ table: TableName;
101
+ fetchedAt: number;
102
+ duration: number;
103
+ rows: Record<ColumnName, QueryResultColumn>[];
104
+ count: number;
105
+ };
106
+ type QueryResultColumn = {
107
+ column: ColumnName;
108
+ value: unknown;
109
+ dataType?: IntrospectDataType;
110
+ uiType?: IntrospectUiType;
111
+ };
112
+ type MutateInput = {};
113
+ type MutateResult = {};
114
+ type AlterInput = {};
115
+ type AlterResult = {};
116
+ type RawQueryInput = {};
117
+ type RawQueryResult = {};
118
+
119
+ declare class AdapterMock implements Adapter {
120
+ introspect(): Promise<Either<Error, InstrospectResult>>;
121
+ query(input: QueryInput): Promise<Either<Error, QueryResult>>;
122
+ mutate(inputs: MutateInput[]): Promise<Either<Error, MutateResult>>;
123
+ alter(inputs: AlterInput[]): Promise<Either<Error, AlterResult>>;
124
+ rawQuery(input: RawQueryInput): Promise<Either<Error, RawQueryResult>>;
125
+ }
126
+
127
+ export { type Adapter, AdapterMock };
@@ -0,0 +1 @@
1
+ var a=class{async introspect(){return[null,{schemas:{public:{tables:{users:{schema:"public",name:"users",columns:{id:{schema:"public",table:"users",name:"id",dataType:{name:"integer",args:[]},uiType:{kind:"number",isList:!1,max:1e4,min:0},defaults:null,nullable:!1,partOfPk:!0,reference:null},name:{schema:"public",table:"users",name:"name",dataType:{name:"varchar",args:[255]},uiType:{kind:"string",isList:!1,max:255,min:0},defaults:null,nullable:!1,partOfPk:!1,reference:null},role:{schema:"public",table:"users",name:"role",dataType:{name:"enum",args:[]},uiType:{kind:"enum",isList:!1,name:"UserRole",values:["admin","user","guest"]},defaults:"user",nullable:!1,partOfPk:!1,reference:null}}},posts:{schema:"public",name:"posts",columns:{id:{schema:"public",table:"posts",name:"id",dataType:{name:"integer",args:[]},uiType:{kind:"number",isList:!1,max:1e4,min:0},defaults:null,nullable:!1,partOfPk:!0,reference:null},title:{schema:"public",table:"posts",name:"title",dataType:{name:"varchar",args:[255]},uiType:{kind:"string",isList:!1,max:255,min:0},defaults:null,nullable:!1,partOfPk:!1,reference:null},content:{schema:"public",table:"posts",name:"content",dataType:{name:"text",args:[]},uiType:{kind:"string",isList:!1,max:1e4,min:0},defaults:null,nullable:!0,partOfPk:!1,reference:null},userId:{schema:"public",table:"posts",name:"userId",dataType:{name:"integer",args:[]},uiType:{kind:"number",isList:!1,max:1e4,min:0},defaults:null,nullable:!1,partOfPk:!1,reference:{schema:"public",name:"users",columns:{}}}}}},enums:{UserRole:{name:"UserRole",values:["admin","user","guest"]}}}},filters:{"=":!0,">=":!0,">":!0,"<=":!0,"<":!0,like:!0,ilike:!1,"is null":!0}}]}async query(e){return[null,{schema:"public",table:"users",fetchedAt:Date.now(),duration:35,count:2,rows:[{id:{column:"id",value:1,dataType:{name:"integer",args:[]},uiType:{kind:"number",isList:!1,max:1e4,min:0}},name:{column:"name",value:"Alice",dataType:{name:"varchar",args:[255]},uiType:{kind:"string",isList:!1,max:255,min:0}},role:{column:"role",value:"admin",dataType:{name:"enum",args:[]},uiType:{kind:"enum",isList:!1,name:"UserRole",values:["admin","user","guest"]}}},{id:{column:"id",value:2,dataType:{name:"integer",args:[]},uiType:{kind:"number",isList:!1,max:1e4,min:0}},name:{column:"name",value:"Bob",dataType:{name:"varchar",args:[255]},uiType:{kind:"string",isList:!1,max:255,min:0}},role:{column:"role",value:"user",dataType:{name:"enum",args:[]},uiType:{kind:"enum",isList:!1,name:"UserRole",values:["admin","user","guest"]}}}]}]}async mutate(e){throw new Error("Method not implemented.")}async alter(e){throw new Error("Method not implemented.")}async rawQuery(e){throw new Error("Method not implemented.")}};export{a as AdapterMock};
@@ -0,0 +1,3 @@
1
+ declare function HelloWorld(): void;
2
+
3
+ export { HelloWorld as default };
@@ -0,0 +1 @@
1
+ function l(){console.log("Hello World")}export{l as default};
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@prisma/studio-core",
3
+ "version": "0.0.0-dev.202503182320",
4
+ "description": "Modular Prisma Studio components",
5
+ "sideEffects": false,
6
+ "main": "./dist/data/index.js",
7
+ "types": "./dist/data/index.d.ts",
8
+ "type": "module",
9
+ "exports": {
10
+ "./data": {
11
+ "types": "./dist/data/index.d.ts",
12
+ "import": "./dist/data/index.js",
13
+ "default": "./dist/data/index.js"
14
+ },
15
+ "./ui": {
16
+ "types": "./dist/ui/index.d.ts",
17
+ "import": "./dist/ui/index.js",
18
+ "default": "./dist/ui/index.js"
19
+ }
20
+ },
21
+ "keywords": [],
22
+ "author": "",
23
+ "license": "ISC",
24
+ "dependencies": {
25
+ "tsup": "8.0.2",
26
+ "tsx": "4.17.0",
27
+ "typescript": "5.5.4"
28
+ },
29
+ "peerDependencies": {
30
+ "@types/react": "18.3.3",
31
+ "react": "18.3.0-canary-a870b2d54-20240314"
32
+ },
33
+ "scripts": {
34
+ "build": "tsup",
35
+ "typecheck": "tsc --noEmit",
36
+ "lint": "eslint --fix .",
37
+ "test": ""
38
+ }
39
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "lib": ["DOM", "DOM.Iterable", "ES2022"]
5
+ }
6
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ cjsInterop: true,
5
+ clean: true,
6
+ dts: true,
7
+ entry: ["./data/index.ts", "./ui/index.tsx"],
8
+ format: ["esm"],
9
+ minify: true,
10
+ outDir: "dist",
11
+ });
package/ui/index.tsx ADDED
@@ -0,0 +1,3 @@
1
+ export default function HelloWorld() {
2
+ console.log("Hello World");
3
+ }