@fougere/adapter-duckdb 0.17.3-alpha.0 → 0.18.0-alpha.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/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +9 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { type Entity } from '@fougere/schema';
|
|
2
2
|
/** The engines DuckDB can attach — and the reason the list is short. */
|
|
3
3
|
export type Attachable = 'sqlite' | 'postgres' | 'mysql';
|
|
4
4
|
export interface SourceDeclaration {
|
|
@@ -21,19 +21,18 @@ export interface ConnectOptions {
|
|
|
21
21
|
/** The other places, exactly as `fougere.config.ts` states them. */
|
|
22
22
|
sources?: Record<string, SourceDeclaration>;
|
|
23
23
|
/** What this scope may read — and therefore what gets attached at all. */
|
|
24
|
-
reads: readonly
|
|
24
|
+
reads: readonly Entity[];
|
|
25
25
|
/** Same resolver the storage uses, when an app renames tables. */
|
|
26
26
|
tableName?: (name: string) => string;
|
|
27
27
|
}
|
|
28
28
|
/** A query's answer: the rows, projected onto the shape that was named. */
|
|
29
29
|
export interface Reads {
|
|
30
30
|
/** Name the shape the answer takes, then write the query. */
|
|
31
|
-
read<E extends
|
|
31
|
+
read<E extends Entity>(shape: E): (sql: TemplateStringsArray, ...refs: unknown[]) => Promise<InstanceType<E>[]>;
|
|
32
32
|
/** The attached sources, by alias — what the scope actually opened. */
|
|
33
33
|
attached: ReadonlyMap<string, string>;
|
|
34
34
|
close(): Promise<void>;
|
|
35
35
|
}
|
|
36
36
|
/** Open a read-only view of the app's sources. */
|
|
37
37
|
export declare function connectSources(options: ConnectOptions): Promise<Reads>;
|
|
38
|
-
export {};
|
|
39
38
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,KAAK,MAAM,EAAmB,MAAM,iBAAiB,CAAC;AAI3E,wEAAwE;AACxE,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAEzD,MAAM,WAAW,iBAAiB;IAChC,0BAA0B;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,EAAE,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE,CAAC;IAC1D,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC5C,0EAA0E;IAC1E,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,kEAAkE;IAClE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACtC;AAED,2EAA2E;AAC3E,MAAM,WAAW,KAAK;IACpB,6DAA6D;IAC7D,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,oBAAoB,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAChH,uEAAuE;IACvE,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AA+BD,kDAAkD;AAClD,wBAAsB,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,CA4D5E"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAgC,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAqCnF,MAAM,SAAS,GAA+B;IAC5C,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,MAAM,WAAW,GAA+B;IAC9C,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,kFAAkF;AAClF,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B,yFAAyF;AAEzF,SAAS,QAAQ,CAAC,WAA+C,EAAE,KAAa;IAC9E,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC;IACtD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,WAAW,KAAK,oEAAoE;YACpF,oEAAoE,CACrE,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,kDAAkD;AAClD,MAA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AI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpD,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;IACjD,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fougere/adapter-duckdb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0-alpha.0",
|
|
4
4
|
"description": "Read across an app's sources — one SQL query over what DuckDB can attach.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fougere",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"src"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@fougere/schema": "0.
|
|
33
|
-
"@fougere/adapter-sql": "0.
|
|
32
|
+
"@fougere/schema": "0.18.0-alpha.0",
|
|
33
|
+
"@fougere/adapter-sql": "0.18.0-alpha.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@duckdb/node-api": ">=1.4.0-0"
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/** Read across an app's sources — one SQL query over what can be attached. */
|
|
2
2
|
import { DuckDBInstance } from '@duckdb/node-api';
|
|
3
|
-
import { lowerFirst, type SchemaView } from '@fougere/schema';
|
|
3
|
+
import { lowerFirst, type Entity, type SchemaView } from '@fougere/schema';
|
|
4
4
|
import { toTable, toTableName, toSnakeCase, codecsOf } from '@fougere/adapter-sql';
|
|
5
5
|
|
|
6
|
-
type ShapeClass = abstract new (...args: any[]) => any;
|
|
7
6
|
|
|
8
7
|
/** The engines DuckDB can attach — and the reason the list is short. */
|
|
9
8
|
export type Attachable = 'sqlite' | 'postgres' | 'mysql';
|
|
@@ -25,7 +24,7 @@ export interface ConnectOptions {
|
|
|
25
24
|
/** The other places, exactly as `fougere.config.ts` states them. */
|
|
26
25
|
sources?: Record<string, SourceDeclaration>;
|
|
27
26
|
/** What this scope may read — and therefore what gets attached at all. */
|
|
28
|
-
reads: readonly
|
|
27
|
+
reads: readonly Entity[];
|
|
29
28
|
/** Same resolver the storage uses, when an app renames tables. */
|
|
30
29
|
tableName?: (name: string) => string;
|
|
31
30
|
}
|
|
@@ -33,7 +32,7 @@ export interface ConnectOptions {
|
|
|
33
32
|
/** A query's answer: the rows, projected onto the shape that was named. */
|
|
34
33
|
export interface Reads {
|
|
35
34
|
/** Name the shape the answer takes, then write the query. */
|
|
36
|
-
read<E extends
|
|
35
|
+
read<E extends Entity>(shape: E): (sql: TemplateStringsArray, ...refs: unknown[]) => Promise<InstanceType<E>[]>;
|
|
37
36
|
/** The attached sources, by alias — what the scope actually opened. */
|
|
38
37
|
attached: ReadonlyMap<string, string>;
|
|
39
38
|
close(): Promise<void>;
|
|
@@ -80,7 +79,7 @@ export async function connectSources(options: ConnectOptions): Promise<Reads> {
|
|
|
80
79
|
|
|
81
80
|
// Only what this scope reads is attached — the declaration IS the environment.
|
|
82
81
|
const wanted = new Set<string>();
|
|
83
|
-
const placed = new Map<
|
|
82
|
+
const placed = new Map<Entity, { alias: string; table: string }>();
|
|
84
83
|
for (const shape of options.reads) {
|
|
85
84
|
const name = lowerFirst((shape as { name?: string }).name ?? '');
|
|
86
85
|
const alias = home.get(name) ?? DEFAULT_ALIAS;
|
|
@@ -114,8 +113,8 @@ export async function connectSources(options: ConnectOptions): Promise<Reads> {
|
|
|
114
113
|
return {
|
|
115
114
|
attached,
|
|
116
115
|
close: async () => { db.closeSync(); },
|
|
117
|
-
read<E extends
|
|
118
|
-
const schema = shape
|
|
116
|
+
read<E extends Entity>(shape: E) {
|
|
117
|
+
const schema: SchemaView = shape;
|
|
119
118
|
const fields = schema.getFields();
|
|
120
119
|
const codecs = codecsOf(toTable('x', schema).columns);
|
|
121
120
|
const names = Object.keys(fields);
|
|
@@ -132,8 +131,8 @@ export async function connectSources(options: ConnectOptions): Promise<Reads> {
|
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
/** `${Book}` becomes `archive.books` — the alias AND the table, from one declaration. */
|
|
135
|
-
function qualify(ref: unknown, placed: Map<
|
|
136
|
-
const found = placed.get(ref as
|
|
134
|
+
function qualify(ref: unknown, placed: Map<Entity, { alias: string; table: string }>): string {
|
|
135
|
+
const found = placed.get(ref as Entity);
|
|
137
136
|
if (found) return `${quote(found.alias)}.${quote(found.table)}`;
|
|
138
137
|
const name = (ref as { name?: string } | undefined)?.name;
|
|
139
138
|
if (name) {
|
|
@@ -153,7 +152,7 @@ function qualify(ref: unknown, placed: Map<ShapeClass, { alias: string; table: s
|
|
|
153
152
|
const quote = (identifier: string): string => `"${identifier.replace(/"/g, '""')}"`;
|
|
154
153
|
|
|
155
154
|
/** The column set, checked ONCE against the shape. */
|
|
156
|
-
function refuseMismatch(shape:
|
|
155
|
+
function refuseMismatch(shape: Entity, names: string[], row: Record<string, unknown>, sql: string): void {
|
|
157
156
|
const missing = names.filter((name) => !(toSnakeCase(name) in row) && !(name in row));
|
|
158
157
|
if (missing.length === 0) return;
|
|
159
158
|
throw new Error(
|