@prisma/studio-core 0.0.0-dev.202503201507 → 0.0.0-dev.202503201515

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/ui/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var H=(o,l)=>{for(var d in l)n(o,d,{get:l[d],enumerable:!0})},W=(o,l,d,r)=>{if(l&&typeof l=="object"||typeof l=="function")for(let e of f(l))!u.call(o,e)&&e!==d&&n(o,e,{get:()=>l[e],enumerable:!(r=c(l,e))||r.enumerable});return o};var a=o=>W(n({},"__esModule",{value:!0}),o);var g={};H(g,{default:()=>t});module.exports=a(g);function t(){console.log("Hello World")}
1
+ "use strict";var i=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var h=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},u=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of d(e))!s.call(t,o)&&o!==r&&i(t,o,{get:()=>e[o],enumerable:!(a=c(e,o))||a.enumerable});return t};var k=t=>u(i({},"__esModule",{value:!0}),t);var b={};h(b,{default:()=>n});module.exports=k(b);var l=require("react/jsx-runtime");function n(){return(0,l.jsx)("h1",{className:"tw-preflight ps:p-10",children:"Hello, world!"})}
@@ -0,0 +1,2 @@
1
+ @layer theme,base,components,utilities;@layer theme{:root,:host{--ps-spacing: .25rem}}@layer utilities{.ps\:p-10{padding:calc(var(--ps-spacing) * 10)}}body{background-color:var(--background)}:root{--radius: .625rem;--background: oklch(1 0 0);--foreground: oklch(.141 .005 285.823);--card: oklch(1 0 0);--card-foreground: oklch(.141 .005 285.823);--popover: oklch(1 0 0);--popover-foreground: oklch(.141 .005 285.823);--primary: oklch(.21 .006 285.885);--primary-foreground: oklch(.985 0 0);--secondary: oklch(.967 .001 286.375);--secondary-foreground: oklch(.21 .006 285.885);--muted: oklch(.967 .001 286.375);--muted-foreground: oklch(.552 .016 285.938);--accent: oklch(.967 .001 286.375);--accent-foreground: oklch(.21 .006 285.885);--destructive: oklch(.577 .245 27.325);--border: oklch(.92 .004 286.32);--input: oklch(.92 .004 286.32);--ring: oklch(.705 .015 286.067);--chart-1: oklch(.646 .222 41.116);--chart-2: oklch(.6 .118 184.704);--chart-3: oklch(.398 .07 227.392);--chart-4: oklch(.828 .189 84.429);--chart-5: oklch(.769 .188 70.08);--sidebar: oklch(.985 0 0);--sidebar-foreground: oklch(.141 .005 285.823);--sidebar-primary: oklch(.21 .006 285.885);--sidebar-primary-foreground: oklch(.985 0 0);--sidebar-accent: oklch(.967 .001 286.375);--sidebar-accent-foreground: oklch(.21 .006 285.885);--sidebar-border: oklch(.92 .004 286.32);--sidebar-ring: oklch(.705 .015 286.067);--studio-cell-spacing: 16px}.dark{--background: oklch(.141 .005 285.823);--foreground: oklch(.985 0 0);--card: oklch(.21 .006 285.885);--card-foreground: oklch(.985 0 0);--popover: oklch(.21 .006 285.885);--popover-foreground: oklch(.985 0 0);--primary: oklch(.92 .004 286.32);--primary-foreground: oklch(.21 .006 285.885);--secondary: oklch(.274 .006 286.033);--secondary-foreground: oklch(.985 0 0);--muted: oklch(.274 .006 286.033);--muted-foreground: oklch(.705 .015 286.067);--accent: oklch(.274 .006 286.033);--accent-foreground: oklch(.985 0 0);--destructive: oklch(.704 .191 22.216);--border: oklch(1 0 0 / 10%);--input: oklch(1 0 0 / 15%);--ring: oklch(.552 .016 285.938);--chart-1: oklch(.488 .243 264.376);--chart-2: oklch(.696 .17 162.48);--chart-3: oklch(.769 .188 70.08);--chart-4: oklch(.627 .265 303.9);--chart-5: oklch(.645 .246 16.439);--sidebar: oklch(.21 .006 285.885);--sidebar-foreground: oklch(.985 0 0);--sidebar-primary: oklch(.488 .243 264.376);--sidebar-primary-foreground: oklch(.985 0 0);--sidebar-accent: oklch(.274 .006 286.033);--sidebar-accent-foreground: oklch(.985 0 0);--sidebar-border: oklch(1 0 0 / 10%);--sidebar-ring: oklch(.552 .016 285.938)}@layer base{.tw-preflight{*,:after,:before,::backdrop,::file-selector-button{box-sizing:border-box;margin:0;padding:0;border:0 solid}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;tab-size:4;font-family:var( --default-font-family, ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji" );font-feature-settings:var(--default-font-feature-settings, normal);font-variation-settings:var(--default-font-variation-settings, normal);-webkit-tap-highlight-color:transparent}body{line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var( --default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace );font-feature-settings:var(--default-mono-font-feature-settings, normal);font-variation-settings:var(--default-mono-font-variation-settings, normal);font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea,::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;border-radius:0;background-color:transparent;opacity:1}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1;color:color-mix(in oklab,currentColor 50%,transparent)}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit,::-webkit-datetime-edit-year-field,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute-field,::-webkit-datetime-edit-second-field,::-webkit-datetime-edit-millisecond-field,::-webkit-datetime-edit-meridiem-field{padding-block:0}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]),::file-selector-button{appearance:button}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}*{border-color:var(--border);outline-color:color-mix(in oklab,var(--ring) 50%,transparent)}body{background-color:var(--background);color:var(--foreground)}}@keyframes enter{0%{opacity:var(--tw-enter-opacity, 1);transform:translate3d(var(--tw-enter-translate-x, 0),var(--tw-enter-translate-y, 0),0) scale3d(var(--tw-enter-scale, 1),var(--tw-enter-scale, 1),var(--tw-enter-scale, 1)) rotate(var(--tw-enter-rotate, 0))}}@keyframes exit{to{opacity:var(--tw-exit-opacity, 1);transform:translate3d(var(--tw-exit-translate-x, 0),var(--tw-exit-translate-y, 0),0) scale3d(var(--tw-exit-scale, 1),var(--tw-exit-scale, 1),var(--tw-exit-scale, 1)) rotate(var(--tw-exit-rotate, 0))}}
2
+ /*! tailwindcss v4.0.14 | MIT License | https://tailwindcss.com */
@@ -1,3 +1,5 @@
1
- declare function HelloWorld(): void;
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ declare function HelloWorld(): react_jsx_runtime.JSX.Element;
2
4
 
3
5
  export = HelloWorld;
@@ -1,3 +1,5 @@
1
- declare function HelloWorld(): void;
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ declare function HelloWorld(): react_jsx_runtime.JSX.Element;
2
4
 
3
5
  export { HelloWorld as default };
package/dist/ui/index.js CHANGED
@@ -1 +1 @@
1
- function l(){console.log("Hello World")}export{l as default};
1
+ import{jsx as t}from"react/jsx-runtime";function e(){return t("h1",{className:"tw-preflight ps:p-10",children:"Hello, world!"})}export{e as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/studio-core",
3
- "version": "0.0.0-dev.202503201507",
3
+ "version": "0.0.0-dev.202503201515",
4
4
  "description": "Modular Prisma Studio components",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -39,15 +39,21 @@
39
39
  "keywords": [],
40
40
  "author": "",
41
41
  "license": "ISC",
42
- "dependencies": {
42
+ "devDependencies": {
43
+ "@tailwindcss/postcss": "4.0.14",
44
+ "postcss": "8.4.41",
45
+ "tailwind-merge": "2.5.2",
46
+ "tailwindcss": "4.0.14",
47
+ "tailwindcss-animate": "1.0.7",
43
48
  "tsup": "8.0.2",
44
49
  "tsx": "4.17.0",
45
- "typescript": "5.5.4"
46
- },
47
- "devDependencies": {
50
+ "typescript": "5.5.4",
48
51
  "@arethetypeswrong/cli": "0.17.4",
49
52
  "kysely": "0.27.4"
50
53
  },
54
+ "files": [
55
+ "dist"
56
+ ],
51
57
  "peerDependencies": {
52
58
  "@types/react": "18.3.3",
53
59
  "react": "18.3.0-canary-a870b2d54-20240314"
@@ -1,151 +0,0 @@
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
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
139
- export type MutateInput = {};
140
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
141
- export type MutateResult = {};
142
-
143
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
144
- export type AlterInput = {};
145
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
146
- export type AlterResult = {};
147
-
148
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
149
- export type RawQueryInput = {};
150
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
151
- export type RawQueryResult = {};
@@ -1,221 +0,0 @@
1
- import {
2
- Adapter,
3
- AlterInput,
4
- AlterResult,
5
- Either,
6
- InstrospectResult,
7
- MutateInput,
8
- MutateResult,
9
- QueryInput,
10
- QueryResult,
11
- RawQueryInput,
12
- RawQueryResult,
13
- } from "./Adapter";
14
-
15
- export class AdapterMock implements Adapter {
16
- // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
17
- async introspect(): Promise<Either<Error, InstrospectResult>> {
18
- return [
19
- null,
20
- {
21
- schemas: {
22
- public: {
23
- tables: {
24
- users: {
25
- schema: "public",
26
- name: "users",
27
- columns: {
28
- id: {
29
- schema: "public",
30
- table: "users",
31
- name: "id",
32
- dataType: { name: "integer", args: [] },
33
- uiType: { kind: "number", isList: false, max: 10000, min: 0 },
34
- defaults: null,
35
- nullable: false,
36
- partOfPk: true,
37
- reference: null,
38
- },
39
- name: {
40
- schema: "public",
41
- table: "users",
42
- name: "name",
43
- dataType: { name: "varchar", args: [255] },
44
- uiType: { kind: "string", isList: false, max: 255, min: 0 },
45
- defaults: null,
46
- nullable: false,
47
- partOfPk: false,
48
- reference: null,
49
- },
50
- role: {
51
- schema: "public",
52
- table: "users",
53
- name: "role",
54
- dataType: { name: "enum", args: [] },
55
- uiType: {
56
- kind: "enum",
57
- isList: false,
58
- name: "UserRole",
59
- values: ["admin", "user", "guest"],
60
- },
61
- defaults: "user",
62
- nullable: false,
63
- partOfPk: false,
64
- reference: null,
65
- },
66
- },
67
- },
68
- posts: {
69
- schema: "public",
70
- name: "posts",
71
- columns: {
72
- id: {
73
- schema: "public",
74
- table: "posts",
75
- name: "id",
76
- dataType: { name: "integer", args: [] },
77
- uiType: { kind: "number", isList: false, max: 10000, min: 0 },
78
- defaults: null,
79
- nullable: false,
80
- partOfPk: true,
81
- reference: null,
82
- },
83
- title: {
84
- schema: "public",
85
- table: "posts",
86
- name: "title",
87
- dataType: { name: "varchar", args: [255] },
88
- uiType: { kind: "string", isList: false, max: 255, min: 0 },
89
- defaults: null,
90
- nullable: false,
91
- partOfPk: false,
92
- reference: null,
93
- },
94
- content: {
95
- schema: "public",
96
- table: "posts",
97
- name: "content",
98
- dataType: { name: "text", args: [] },
99
- uiType: { kind: "string", isList: false, max: 10000, min: 0 },
100
- defaults: null,
101
- nullable: true,
102
- partOfPk: false,
103
- reference: null,
104
- },
105
- userId: {
106
- schema: "public",
107
- table: "posts",
108
- name: "userId",
109
- dataType: { name: "integer", args: [] },
110
- uiType: { kind: "number", isList: false, max: 10000, min: 0 },
111
- defaults: null,
112
- nullable: false,
113
- partOfPk: false,
114
- reference: {
115
- schema: "public",
116
- name: "users",
117
- columns: {}, // This can be expanded if needed.
118
- },
119
- },
120
- },
121
- },
122
- },
123
- enums: {
124
- UserRole: {
125
- name: "UserRole",
126
- values: ["admin", "user", "guest"],
127
- },
128
- },
129
- },
130
- },
131
- filters: {
132
- "=": true,
133
- ">=": true,
134
- ">": true,
135
- "<=": true,
136
- "<": true,
137
- like: true,
138
- ilike: false,
139
- "is null": true,
140
- },
141
- },
142
- ];
143
- }
144
- // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
145
- async query(input: QueryInput): Promise<Either<Error, QueryResult>> {
146
- return [
147
- null,
148
- {
149
- schema: "public",
150
- table: "users",
151
- fetchedAt: Date.now(),
152
- duration: 35,
153
- count: 2,
154
- rows: [
155
- {
156
- id: {
157
- column: "id",
158
- value: 1,
159
- dataType: { name: "integer", args: [] },
160
- uiType: { kind: "number", isList: false, max: 10000, min: 0 },
161
- },
162
- name: {
163
- column: "name",
164
- value: "Alice",
165
- dataType: { name: "varchar", args: [255] },
166
- uiType: { kind: "string", isList: false, max: 255, min: 0 },
167
- },
168
- role: {
169
- column: "role",
170
- value: "admin",
171
- dataType: { name: "enum", args: [] },
172
- uiType: {
173
- kind: "enum",
174
- isList: false,
175
- name: "UserRole",
176
- values: ["admin", "user", "guest"],
177
- },
178
- },
179
- },
180
- {
181
- id: {
182
- column: "id",
183
- value: 2,
184
- dataType: { name: "integer", args: [] },
185
- uiType: { kind: "number", isList: false, max: 10000, min: 0 },
186
- },
187
- name: {
188
- column: "name",
189
- value: "Bob",
190
- dataType: { name: "varchar", args: [255] },
191
- uiType: { kind: "string", isList: false, max: 255, min: 0 },
192
- },
193
- role: {
194
- column: "role",
195
- value: "user",
196
- dataType: { name: "enum", args: [] },
197
- uiType: {
198
- kind: "enum",
199
- isList: false,
200
- name: "UserRole",
201
- values: ["admin", "user", "guest"],
202
- },
203
- },
204
- },
205
- ],
206
- },
207
- ];
208
- }
209
- // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
210
- async mutate(inputs: MutateInput[]): Promise<Either<Error, MutateResult>> {
211
- throw new Error("Method not implemented.");
212
- }
213
- // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
214
- async alter(inputs: AlterInput[]): Promise<Either<Error, AlterResult>> {
215
- throw new Error("Method not implemented.");
216
- }
217
- // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
218
- async rawQuery(input: RawQueryInput): Promise<Either<Error, RawQueryResult>> {
219
- throw new Error("Method not implemented.");
220
- }
221
- }
package/data/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export { type Adapter } from "./adapter/Adapter";
2
- export { AdapterMock } from "./adapter/AdapterMock";
@@ -1 +0,0 @@
1
- export * from "./introspection";
@@ -1,98 +0,0 @@
1
- import { type Kysely, PostgresAdapter, PostgresQueryCompiler, type SelectQueryBuilder } from "kysely";
2
- import { jsonArrayFrom } from "kysely/helpers/postgres";
3
-
4
- import { type BuilderRequirements, compile, getBuilder, QueryResult } from "../query";
5
-
6
- const REGULAR_TABLE_KIND = "r";
7
- const VIEW_TABLE_KIND = "v";
8
- const TABLE_KINDS = [REGULAR_TABLE_KIND, VIEW_TABLE_KIND] as const;
9
- type TableKind = (typeof TABLE_KINDS)[number];
10
-
11
- interface Database {
12
- /** columns */
13
- "pg_catalog.pg_attribute": {
14
- /** column order number in its table */
15
- attnum: number;
16
- /** table/view identifier */
17
- attrelid: string;
18
- /** column name */
19
- attname: string;
20
- /** was the column dropped. dropped columns might not be 100% removed immediately. */
21
- attisdropped: boolean;
22
- };
23
- /** resources, e.g. tables, sequences, etc. */
24
- "pg_catalog.pg_class": {
25
- /** resource id */
26
- oid: number;
27
- /** resource name */
28
- relname: string;
29
- /** schema id */
30
- relnamespace: number;
31
- /** resource kind: regular table, view */
32
- relkind: TableKind;
33
- };
34
- /** schemas */
35
- "pg_catalog.pg_namespace": {
36
- /** schema name */
37
- nspname: string;
38
- /** schema id */
39
- oid: number;
40
- };
41
- }
42
-
43
- export function getTablesQuery(requirements?: Omit<BuilderRequirements, "Adapter" | "Compiler">) {
44
- return compile(
45
- getPostgreSQLBuilder(requirements)
46
- .selectFrom("pg_catalog.pg_class as cls")
47
- .innerJoin("pg_catalog.pg_namespace as ns", "cls.relnamespace", "ns.oid")
48
- .$call(excludeSystemTables)
49
- // regular tables or views
50
- .where("cls.relkind", "in", TABLE_KINDS)
51
- .select((eb) => [
52
- "ns.nspname as schema",
53
- "cls.relname as name",
54
- jsonArrayFrom(
55
- eb
56
- .selectFrom("pg_catalog.pg_attribute as att")
57
- // column belongs to current table
58
- .whereRef("att.attrelid", "=", "cls.oid")
59
- // exclude system columns
60
- .where("att.attnum", ">=", 0)
61
- // exclude dropped columns
62
- .where("att.attisdropped", "!=", true)
63
- .select("att.attname as name"),
64
- ).as("columns"),
65
- ]),
66
- );
67
- }
68
-
69
- /**
70
- * For testing purposes.
71
- */
72
- export function mockTablesQuery(): QueryResult<typeof getTablesQuery> {
73
- return [
74
- {
75
- schema: "public",
76
- name: "users",
77
- columns: [{ name: "id" }, { name: "name" }, { name: "role" }, { name: "created_at" }],
78
- },
79
- ];
80
- }
81
-
82
- /**
83
- * We don't want PostgreSQL internals in introspection results. To be used in `$call`.
84
- */
85
- function excludeSystemTables<
86
- T extends SelectQueryBuilder<
87
- Database & { ns: Database["pg_catalog.pg_namespace"]; cls: Database["pg_catalog.pg_class"] },
88
- "ns" | "cls",
89
- any
90
- >,
91
- >(qb: T): T {
92
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
93
- return qb.where(`ns.nspname`, `!~`, `^pg_`).where(`ns.nspname`, `!=`, `information_schema`) as any;
94
- }
95
-
96
- function getPostgreSQLBuilder(requirements?: Omit<BuilderRequirements, "Adapter" | "QueryCompiler">): Kysely<Database> {
97
- return getBuilder({ ...requirements, Adapter: PostgresAdapter, QueryCompiler: PostgresQueryCompiler });
98
- }
package/data/query.ts DELETED
@@ -1,75 +0,0 @@
1
- import {
2
- type Compilable,
3
- type DialectAdapter,
4
- DummyDriver,
5
- Kysely,
6
- type KyselyPlugin,
7
- OperationNodeTransformer,
8
- type PluginTransformQueryArgs,
9
- type PluginTransformResultArgs,
10
- type QueryCompiler,
11
- type QueryResult as KyselyQueryResult,
12
- type RootOperationNode,
13
- type UnknownRow,
14
- type ValueNode,
15
- } from "kysely";
16
-
17
- export interface BuilderRequirements {
18
- Adapter: { new (): DialectAdapter };
19
- noParameters?: boolean;
20
- QueryCompiler: { new (): QueryCompiler };
21
- }
22
-
23
- export function getBuilder<DB>(requirements: BuilderRequirements): Kysely<DB> {
24
- return new Kysely({
25
- dialect: {
26
- createAdapter: () => new requirements.Adapter(),
27
- createDriver: () => new DummyDriver(),
28
- // @ts-expect-error - we don't need built-in introspection in this case
29
- createIntrospector: () => null,
30
- createQueryCompiler: () => new requirements.QueryCompiler(),
31
- },
32
- plugins: [...(requirements.noParameters ? [new ImmediateValuePlugin()] : [])],
33
- });
34
- }
35
-
36
- /**
37
- * A plugin that transforms all values to immediate values. This means their injected into the SQL string instead of populating the parameters array.
38
- * In some situations, a database driver might not support parameters, and this plugin can be used to work around that.
39
- */
40
- class ImmediateValuePlugin implements KyselyPlugin {
41
- readonly #transformer = new ImmediateValueTransformer();
42
-
43
- transformQuery(args: PluginTransformQueryArgs): RootOperationNode {
44
- return this.#transformer.transformNode(args.node);
45
- }
46
-
47
- transformResult(args: PluginTransformResultArgs): Promise<KyselyQueryResult<UnknownRow>> {
48
- return Promise.resolve(args.result);
49
- }
50
- }
51
-
52
- class ImmediateValueTransformer extends OperationNodeTransformer {
53
- override transformValue(node: ValueNode): ValueNode {
54
- return { ...super.transformValue(node), immediate: true };
55
- }
56
- }
57
-
58
- declare const queryType: unique symbol;
59
- export interface Query<T> {
60
- [queryType]?: T;
61
- parameters: readonly unknown[];
62
- sql: string;
63
- }
64
-
65
- export type QueryResult<T> =
66
- T extends Query<infer R> ? R[] : T extends (...args: any[]) => Query<infer R> ? R[] : never;
67
-
68
- export function compile<T>(compileable: Compilable<T>): Query<T> {
69
- const compiledQuery = compileable.compile();
70
-
71
- return {
72
- parameters: compiledQuery.parameters,
73
- sql: compiledQuery.sql,
74
- };
75
- }
package/eslintconfig.mjs DELETED
@@ -1,3 +0,0 @@
1
- import baseConfig from "../../eslint.config.base.mjs";
2
-
3
- export default baseConfig({ metaUrl: import.meta.url });
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "lib": ["DOM", "DOM.Iterable", "ES2022"],
5
- "noEmit": true
6
- }
7
- }
package/tsup.config.ts DELETED
@@ -1,15 +0,0 @@
1
- import { defineConfig } from "tsup";
2
-
3
- export default defineConfig({
4
- cjsInterop: true,
5
- clean: true,
6
- dts: true,
7
- entry: ["./data/index.ts", "./data/postgres-core/index.ts", "./ui/index.tsx"],
8
- format: ["cjs", "esm"],
9
- minify: true,
10
- noExternal: [
11
- // we want to hide the fact that we are using kysely, i guess.
12
- "kysely",
13
- ],
14
- outDir: "dist",
15
- });
package/ui/index.tsx DELETED
@@ -1,3 +0,0 @@
1
- export default function HelloWorld() {
2
- console.log("Hello World");
3
- }