palgres 0.0.0-stage → 0.2.0
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/LICENSE +27 -0
- package/README.md +2 -2
- package/dist/chunks/JJVO5DTA.js +2 -0
- package/dist/chunks/JZLQMXDV.js +2 -0
- package/dist/chunks/XZNL22V6.js +5 -0
- package/dist/dsl.js +2 -0
- package/dist/index.js +372 -0
- package/dist/testing.js +2 -0
- package/package.json +32 -4
- package/types/internal/src/data.d.ts +15 -0
- package/types/palgres/src/adopt.d.ts +17 -0
- package/types/palgres/src/connect.d.ts +37 -0
- package/types/palgres/src/dsl/columns.d.ts +388 -0
- package/types/palgres/src/dsl/foreign-key.d.ts +33 -0
- package/types/palgres/src/dsl/index.d.ts +11 -0
- package/types/palgres/src/dsl/policy.d.ts +181 -0
- package/types/palgres/src/dsl/raw.d.ts +43 -0
- package/types/palgres/src/dsl/schema.d.ts +288 -0
- package/types/palgres/src/dsl/to-model.d.ts +6 -0
- package/types/palgres/src/forget.d.ts +12 -0
- package/types/palgres/src/index.d.ts +15 -0
- package/types/palgres/src/introspect.d.ts +17 -0
- package/types/palgres/src/migrate.d.ts +189 -0
- package/types/palgres/src/model.d.ts +181 -0
- package/types/palgres/src/plan.d.ts +107 -0
- package/types/palgres/src/pull.d.ts +13 -0
- package/types/palgres/src/query/admission.d.ts +80 -0
- package/types/palgres/src/query/catalog.d.ts +50 -0
- package/types/palgres/src/query/client.d.ts +154 -0
- package/types/palgres/src/query/data-mark.d.ts +7 -0
- package/types/palgres/src/query/diagnostics.d.ts +76 -0
- package/types/palgres/src/query/driver.d.ts +299 -0
- package/types/palgres/src/query/env-gen.d.ts +14 -0
- package/types/palgres/src/query/errors.d.ts +168 -0
- package/types/palgres/src/query/guards.d.ts +62 -0
- package/types/palgres/src/query/index.d.ts +76 -0
- package/types/palgres/src/query/options.d.ts +75 -0
- package/types/palgres/src/query/relations.d.ts +15 -0
- package/types/palgres/src/query/repository.d.ts +42 -0
- package/types/palgres/src/query/request.d.ts +54 -0
- package/types/palgres/src/query/search.d.ts +55 -0
- package/types/palgres/src/query/surface.d.ts +9 -0
- package/types/palgres/src/query/tx-plan.d.ts +229 -0
- package/types/palgres/src/query/typed.d.ts +537 -0
- package/types/palgres/src/query/unique.d.ts +16 -0
- package/types/palgres/src/search-worker.d.ts +36 -0
- package/types/palgres/src/search.d.ts +107 -0
- package/types/palgres/src/testing/fake.d.ts +22 -0
- package/types/palgres/src/testing/index.d.ts +2 -0
- package/types/palgres/src/units.d.ts +24 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type Search, type SearchMetric } from './model.js';
|
|
2
|
+
import type { Roles } from './plan.js';
|
|
3
|
+
export declare const SEARCH_SCHEMA = "palgres_search";
|
|
4
|
+
/** A generation of a table's vectors, as palgres_search.generations says it. */
|
|
5
|
+
export interface SearchGeneration {
|
|
6
|
+
gen: number;
|
|
7
|
+
model: string;
|
|
8
|
+
dimensions: number;
|
|
9
|
+
metric: SearchMetric;
|
|
10
|
+
from: string[];
|
|
11
|
+
status: 'filling' | 'active' | 'retired';
|
|
12
|
+
}
|
|
13
|
+
/** What a generation's vectors are made with: a declaration that says the same needs no other. */
|
|
14
|
+
export declare const sameVectors: (a: Pick<Search, 'model' | 'dimensions' | 'metric' | 'from'>, b: Pick<Search, 'model' | 'dimensions' | 'metric' | 'from'>) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The table a generation's vectors are in: <schema>__<table>__g<gen>, its
|
|
17
|
+
* name cut and told apart by a hash where 63 bytes would not hold it.
|
|
18
|
+
* palgres_search.vectors() says the same in SQL.
|
|
19
|
+
*/
|
|
20
|
+
export declare function vectorTable(tableKey: string, gen: number): string;
|
|
21
|
+
/** A generation's triggers on its table. */
|
|
22
|
+
export declare const searchTriggers: (gen: number) => {
|
|
23
|
+
insert: string;
|
|
24
|
+
update: string;
|
|
25
|
+
};
|
|
26
|
+
/** The index the keyword leg reads: one per list of columns, so a new list's is built beside the old one's. */
|
|
27
|
+
export declare function keywordIndex(t: {
|
|
28
|
+
schema: string;
|
|
29
|
+
name: string;
|
|
30
|
+
}, from: readonly string[]): string;
|
|
31
|
+
/**
|
|
32
|
+
* A row's text as it is embedded and as the keyword leg reads it: its `from`
|
|
33
|
+
* columns in their order, a space between them, NULL as nothing. One
|
|
34
|
+
* expression for the index, the query and the worker — an index is used only
|
|
35
|
+
* by the expression it was built on.
|
|
36
|
+
*/
|
|
37
|
+
export declare function sourceText(from: readonly string[], alias?: string): string;
|
|
38
|
+
/** The keyword leg's document: 'simple' — no language's stemming, the words as they are written. */
|
|
39
|
+
export declare const keywordDocument: (from: readonly string[], alias?: string) => string;
|
|
40
|
+
/** How pgvector keeps and compares a generation's vectors: half precision past what a full one can be indexed at. */
|
|
41
|
+
export declare function vectorKind(dimensions: number, metric: SearchMetric): {
|
|
42
|
+
type: 'vector' | 'halfvec';
|
|
43
|
+
opclass: string;
|
|
44
|
+
operator: string;
|
|
45
|
+
};
|
|
46
|
+
/** A table's key ("schema.table") as the relation it names. */
|
|
47
|
+
export declare function relationOf(tableKey: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* What a generation makes, in one transaction: its row, its vectors' table
|
|
50
|
+
* (read by the app's roles through the parent's own policies, written by the
|
|
51
|
+
* service role), the function its triggers run and the triggers. `types`
|
|
52
|
+
* says where pgvector's types are (the extension's schema).
|
|
53
|
+
*/
|
|
54
|
+
export declare function generationSql(o: {
|
|
55
|
+
table: {
|
|
56
|
+
schema: string;
|
|
57
|
+
name: string;
|
|
58
|
+
};
|
|
59
|
+
gen: number;
|
|
60
|
+
search: Search;
|
|
61
|
+
status: 'filling' | 'active';
|
|
62
|
+
pk: {
|
|
63
|
+
name: string;
|
|
64
|
+
type: string;
|
|
65
|
+
};
|
|
66
|
+
roles: Roles;
|
|
67
|
+
types: string;
|
|
68
|
+
}): string[];
|
|
69
|
+
/** A generation's triggers on its table: every new row, and every row whose text changes. `replace`: over the ones there, with another staleness. */
|
|
70
|
+
export declare function generationTriggers(o: {
|
|
71
|
+
table: {
|
|
72
|
+
schema: string;
|
|
73
|
+
name: string;
|
|
74
|
+
};
|
|
75
|
+
gen: number;
|
|
76
|
+
from: readonly string[];
|
|
77
|
+
staleness: Search['staleness'];
|
|
78
|
+
}, replace: boolean): string[];
|
|
79
|
+
/** Every row of a table into a generation's queue: one statement, and run again it adds nothing. */
|
|
80
|
+
export declare function enqueueAllSql(table: {
|
|
81
|
+
schema: string;
|
|
82
|
+
name: string;
|
|
83
|
+
}, gen: number, pk: string): string;
|
|
84
|
+
/** What takes a generation away, whatever of it is there: its triggers, its vectors, its function, its queue, its row. */
|
|
85
|
+
export declare function dropGenerationSql(table: {
|
|
86
|
+
schema: string;
|
|
87
|
+
name: string;
|
|
88
|
+
}, gen: number): string[];
|
|
89
|
+
/**
|
|
90
|
+
* What the search schema says of itself (its comment) once searchLedgerSql
|
|
91
|
+
* made it: this text, for these roles. A migrator that reads it there makes
|
|
92
|
+
* nothing again; any change to what searchLedgerSql makes changes the number.
|
|
93
|
+
*/
|
|
94
|
+
export declare const searchLedgerMark: (roles: Roles) => string;
|
|
95
|
+
/**
|
|
96
|
+
* Palgres' search schema, made with its ledger in every database it migrates
|
|
97
|
+
* (migrate.ts' ensure): the generations, the queue, and promote() — how a
|
|
98
|
+
* filled generation takes over. Each statement leaves what is there as it
|
|
99
|
+
* is; the last says it is done (searchLedgerMark).
|
|
100
|
+
*/
|
|
101
|
+
export declare function searchLedgerSql(roles: Roles): string[];
|
|
102
|
+
/** Told when a write to a table with search commits in this process: a worker here need not wait for its next look. */
|
|
103
|
+
export declare const searchWrites: {
|
|
104
|
+
/** `wake` on every such commit; the return ends it. */
|
|
105
|
+
listen(wake: () => void): () => void;
|
|
106
|
+
committed(): void;
|
|
107
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { DBClient } from '../query/client.js';
|
|
2
|
+
type Row = Record<string, unknown>;
|
|
3
|
+
/** One raw SQL call, as it was made. */
|
|
4
|
+
export interface RecordedQuery {
|
|
5
|
+
sql: string;
|
|
6
|
+
params: unknown[];
|
|
7
|
+
}
|
|
8
|
+
export interface FakeClient extends DBClient {
|
|
9
|
+
/** Rows written into a table since it was made: inserts and the inserts of put, claim and plans. */
|
|
10
|
+
inserted(table: string): Row[];
|
|
11
|
+
/** Rows as each update left them: update, updateMany, put on a row that was there, plans. */
|
|
12
|
+
updated(table: string): Row[];
|
|
13
|
+
/** The ids of the rows deleted from a table. */
|
|
14
|
+
deleted(table: string): string[];
|
|
15
|
+
/** The table's rows, from now on: the given ones, copied. */
|
|
16
|
+
seed(table: string, rows: Row[]): void;
|
|
17
|
+
/** Every raw SQL call, through any handle — the request's, $asService(), a savepoint's. */
|
|
18
|
+
readonly queries: readonly RecordedQuery[];
|
|
19
|
+
}
|
|
20
|
+
/** A DBClient in memory: see the top of this file. */
|
|
21
|
+
export declare function createFakeClient(): FakeClient;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface SchemaUnit {
|
|
2
|
+
/** The Postgres schema it is in: the schema file that carries it. */
|
|
3
|
+
schema: string;
|
|
4
|
+
/** What it is and its name, as Introspected.objects keys it. */
|
|
5
|
+
key: string;
|
|
6
|
+
/** How Introspected.unmanaged begins its line for it: what a file carrying it no longer lists as left. */
|
|
7
|
+
listed: string;
|
|
8
|
+
kind: 'domain' | 'type' | 'sequence' | 'function' | 'view' | 'materialized view' | 'index' | 'trigger';
|
|
9
|
+
/** A name for it as a schema file's raw unit: letters, digits and _, unique in the schema. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Made before the schema's tables: a column's type or default may need it. */
|
|
12
|
+
before: boolean;
|
|
13
|
+
/** Makes it, and leaves one already there as it is. */
|
|
14
|
+
create: string;
|
|
15
|
+
drop: string;
|
|
16
|
+
}
|
|
17
|
+
type Query = <T>(text: string) => Promise<T[]>;
|
|
18
|
+
/**
|
|
19
|
+
* The units of `schemas`, in an order they can be made in. `managed`: the
|
|
20
|
+
* relations the model carries ("schema.name"); `objects` receives each unit's
|
|
21
|
+
* text, the key it is compared by.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readUnits(q: Query, inSchemas: string, managed: ReadonlySet<string>, objects: Map<string, string>): Promise<SchemaUnit[]>;
|
|
24
|
+
export {};
|