@typesql/core 0.1.0 → 0.1.1
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/CHANGELOG.md
CHANGED
|
@@ -187,7 +187,7 @@ type GetRel<DB, Ref extends TableRef> = IsTop<Ref["schema"]> extends true ? Ref[
|
|
|
187
187
|
type SchemaExists<DB, S> = IsTop<S> extends true ? true : S extends string ? IsSchemaKey<DB, S> : false;
|
|
188
188
|
type NoSchema<S> = SqlError<`schema "${S & string}" does not exist`, null>;
|
|
189
189
|
/** A new top-level relation would overwrite a schema (schemas and public relations share `DB`'s keys). */
|
|
190
|
-
type SchemaClash<DB, Ref extends TableRef> = IsTop<Ref["schema"]> extends true ? Ref["name"] extends keyof DB ? SqlError<`cannot create relation "${Ref["name"]}": a schema with that name exists (
|
|
190
|
+
type SchemaClash<DB, Ref extends TableRef> = IsTop<Ref["schema"]> extends true ? Ref["name"] extends keyof DB ? SqlError<`cannot create relation "${Ref["name"]}": a schema with that name exists (TypeSQL keeps schemas and public relations in one object)`, null> : null : null;
|
|
191
191
|
/** Checks before adding a relation at `Ref`: `null` when it can be added. */
|
|
192
192
|
type CanCreate<DB, Ref extends TableRef> = SchemaExists<DB, Ref["schema"]> extends false ? NoSchema<Ref["schema"]> : SchemaClash<DB, Ref>;
|
|
193
193
|
type PutRel<DB, Ref extends TableRef, V> = IsTop<Ref["schema"]> extends true ? SetKey<DB, Ref["name"], V> : Ref["schema"] extends keyof DB ? SetKey<DB, Ref["schema"] & string, SetKey<DB[Ref["schema"]], Ref["name"], V>> : NoSchema<Ref["schema"]>;
|
|
@@ -281,7 +281,7 @@ type NameCols<C extends Cols, Names, Acc extends Cols, TooMany extends string> =
|
|
|
281
281
|
} ? NameCols<R, NR, [...Acc, {
|
|
282
282
|
readonly n: N;
|
|
283
283
|
readonly t: I;
|
|
284
|
-
}], TooMany> : SqlError<"a column name list cannot rename the columns of a * projection (
|
|
284
|
+
}], TooMany> : SqlError<"a column name list cannot rename the columns of a * projection (TypeSQL limitation): list the columns explicitly", null> : SqlError<TooMany, null> : [...Acc, ...C];
|
|
285
285
|
/** First duplicate output name, or null. */
|
|
286
286
|
type DupCol<C extends Cols, Seen> = C extends readonly [infer H, ...infer R extends Cols] ? H extends {
|
|
287
287
|
readonly star: infer M;
|
|
@@ -438,7 +438,7 @@ type DropTypeNs<NS, N extends string> = Rebuild<{
|
|
|
438
438
|
type StripCols<Tbl, N extends string> = Rebuild<{
|
|
439
439
|
[K in keyof Tbl as ColUses<Tbl[K], N> extends true ? never : K]: Tbl[K];
|
|
440
440
|
}>;
|
|
441
|
-
type ApplyCreateSchema<DB, Ine, Name extends string> = Name extends "public" ? (Ine extends true ? DB : SqlError<`schema "public" already exists`, null>) : Name extends keyof DB ? IsSchemaKey<DB, Name> extends true ? (Ine extends true ? DB : SqlError<`schema "${Name}" already exists`, null>) : SqlError<`cannot create schema "${Name}": a relation with that name exists (
|
|
441
|
+
type ApplyCreateSchema<DB, Ine, Name extends string> = Name extends "public" ? (Ine extends true ? DB : SqlError<`schema "public" already exists`, null>) : Name extends keyof DB ? IsSchemaKey<DB, Name> extends true ? (Ine extends true ? DB : SqlError<`schema "${Name}" already exists`, null>) : SqlError<`cannot create schema "${Name}": a relation with that name exists (TypeSQL keeps schemas and public relations in one object)`, null> : SetKey<DB, Name, {}>;
|
|
442
442
|
type ApplyDropSchemas<DB, Names, Ife, Casc> = Names extends readonly [infer N extends string, ...infer Rest] ? N extends "public" ? SqlError<"DROP SCHEMA public is not supported", null> : IsSchemaKey<DB, N> extends true ? [keyof DB[N & keyof DB]] extends [never] ? ApplyDropSchemas<DelKey<DB, N>, Rest, Ife, Casc> : Casc extends true ? ApplyDropSchemas<DelKey<DB, N>, Rest, Ife, Casc> : SqlError<`cannot drop schema ${N} because other objects depend on it`, null> : Ife extends true ? ApplyDropSchemas<DB, Rest, Ife, Casc> : SqlError<`schema "${N}" does not exist`, null> : DB;
|
|
443
443
|
type ApplyRenameSchema<DB, F extends string, To extends string> = IsSchemaKey<DB, F> extends true ? To extends keyof DB | "public" ? SqlError<`schema "${To}" already exists`, null> : RenameKey<DB, F, To> : SqlError<`schema "${F}" does not exist`, null>;
|
|
444
444
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Col, Nullable, View } from "./column.js";
|
|
2
2
|
/**
|
|
3
3
|
* Relations of `pg_catalog` in the {@link PgCatalog} slice. Catalog tables are declared as
|
|
4
|
-
* views too:
|
|
4
|
+
* views too: TypeSQL treats the whole slice as read-only.
|
|
5
5
|
*/
|
|
6
6
|
export interface PgCatalogNamespace {
|
|
7
7
|
/** Table `pg_catalog.pg_am`: Access methods. */
|
package/package.json
CHANGED
package/src/engine/ddl/apply.ts
CHANGED
|
@@ -177,7 +177,7 @@ type NoSchema<S> = SqlError<`schema "${S & string}" does not exist`, null>;
|
|
|
177
177
|
/** A new top-level relation would overwrite a schema (schemas and public relations share `DB`'s keys). */
|
|
178
178
|
type SchemaClash<DB, Ref extends TableRef> =
|
|
179
179
|
IsTop<Ref["schema"]> extends true
|
|
180
|
-
? Ref["name"] extends keyof DB ? SqlError<`cannot create relation "${Ref["name"]}": a schema with that name exists (
|
|
180
|
+
? Ref["name"] extends keyof DB ? SqlError<`cannot create relation "${Ref["name"]}": a schema with that name exists (TypeSQL keeps schemas and public relations in one object)`, null> : null
|
|
181
181
|
: null;
|
|
182
182
|
/** Checks before adding a relation at `Ref`: `null` when it can be added. */
|
|
183
183
|
type CanCreate<DB, Ref extends TableRef> =
|
|
@@ -326,7 +326,7 @@ type NameCols<C extends Cols, Names, Acc extends Cols, TooMany extends string> =
|
|
|
326
326
|
Names extends readonly [infer N extends string, ...infer NR]
|
|
327
327
|
? C extends readonly [infer H, ...infer R extends Cols]
|
|
328
328
|
? H extends { readonly n: string; readonly t: infer I extends ColInfo } ? NameCols<R, NR, [...Acc, { readonly n: N; readonly t: I }], TooMany>
|
|
329
|
-
: SqlError<"a column name list cannot rename the columns of a * projection (
|
|
329
|
+
: SqlError<"a column name list cannot rename the columns of a * projection (TypeSQL limitation): list the columns explicitly", null>
|
|
330
330
|
: SqlError<TooMany, null>
|
|
331
331
|
: [...Acc, ...C];
|
|
332
332
|
|
|
@@ -585,7 +585,7 @@ type ApplyCreateSchema<DB, Ine, Name extends string> =
|
|
|
585
585
|
Name extends "public" ? (Ine extends true ? DB : SqlError<`schema "public" already exists`, null>)
|
|
586
586
|
: Name extends keyof DB
|
|
587
587
|
? IsSchemaKey<DB, Name> extends true ? (Ine extends true ? DB : SqlError<`schema "${Name}" already exists`, null>)
|
|
588
|
-
: SqlError<`cannot create schema "${Name}": a relation with that name exists (
|
|
588
|
+
: SqlError<`cannot create schema "${Name}": a relation with that name exists (TypeSQL keeps schemas and public relations in one object)`, null>
|
|
589
589
|
: SetKey<DB, Name, {}>;
|
|
590
590
|
|
|
591
591
|
type ApplyDropSchemas<DB, Names, Ife, Casc> =
|
package/src/schema/pg-catalog.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Col, Nullable, View } from "./column.js";
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Relations of `pg_catalog` in the {@link PgCatalog} slice. Catalog tables are declared as
|
|
6
|
-
* views too:
|
|
6
|
+
* views too: TypeSQL treats the whole slice as read-only.
|
|
7
7
|
*/
|
|
8
8
|
export interface PgCatalogNamespace {
|
|
9
9
|
/** Table `pg_catalog.pg_am`: Access methods. */
|