@quanthea/plugin-kit 0.1.0 → 0.3.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/README.md CHANGED
@@ -17,7 +17,7 @@ kit to the plugin when it loads it, so the bundle carries none of the kit's code
17
17
  ## Write a plugin
18
18
 
19
19
  The plugin is one bundled ES module. It exports the kit version it is built for and, as default, a
20
- function that receives the kit and returns its kinds:
20
+ function that receives the kit and returns what the plugin adds, its connector kinds:
21
21
 
22
22
  ```ts
23
23
  import type { ConnectorKit } from '@quanthea/plugin-kit';
@@ -25,7 +25,9 @@ import type { ConnectorKit } from '@quanthea/plugin-kit';
25
25
  export const kitVersion = 0;
26
26
 
27
27
  export default function plugin(kit: ConnectorKit) {
28
- return [kit.defineConnector({ kind: 'example', configSchema: kit.z.object({ … }), … })];
28
+ return {
29
+ connectors: [kit.defineConnector({ kind: 'example', configSchema: kit.z.object({ … }), … })],
30
+ };
29
31
  }
30
32
  ```
31
33
 
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- // packages/plugin-kit/src/kit.ts
2
+ // src/kit.ts
3
3
  var kitVersion2 = 0;
4
4
 
5
5
  export { kitVersion2 };
package/dialects.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /** The SQL dialects the core binds, and the styles an `ansi` source picks. */
2
+ /**
3
+ * The SQL dialects the core knows how to bind: how each writes its literals and its placeholders.
4
+ * A SQL connector kind declares one of them. `ansi` is standard SQL, for the sources the others do
5
+ * not fit; its kind also picks a placeholder style and a row-limit style.
6
+ */
7
+ export declare const sqlDialects: readonly ["postgres", "mysql", "clickhouse", "trino", "influxdb", "ansi"];
8
+ /** A SQL dialect name. */
9
+ export type SqlDialect = (typeof sqlDialects)[number];
10
+ /**
11
+ * How an `ansi` source writes a placeholder: `?` (JDBC, ODBC, SQLite, Snowflake), `$1` (numbered,
12
+ * as PostgreSQL), `:1` (numbered, as Oracle) or `@p1` (named, as SQL Server drivers).
13
+ */
14
+ export declare const sqlPlaceholderStyles: readonly ["?", "$1", ":1", "@p1"];
15
+ /** A placeholder style. */
16
+ export type SqlPlaceholderStyle = (typeof sqlPlaceholderStyles)[number];
17
+ /** How an `ansi` source limits rows: `FETCH FIRST n ROWS ONLY`, the standard, or `LIMIT n`. */
18
+ export declare const sqlRowLimits: readonly ["fetch", "limit"];
19
+ /** A row-limit style. */
20
+ export type SqlRowLimit = (typeof sqlRowLimits)[number];
package/host.d.ts CHANGED
@@ -6,6 +6,7 @@ export { type AnyConnectorKind, type ConnectorIcon, type ConnectorInstance, type
6
6
  export { ConnectorError, type ConnectorErrorCode } from './errors.js';
7
7
  export { createFrameBuilder } from './frame-builder.js';
8
8
  export { createHttpClient, type HttpClient, type HttpResponse } from './http.js';
9
+ export { isMetadataAddress } from './http-address.js';
9
10
  export { kitVersion } from './kit.js';
10
11
  export { type BoundQuery, type ExecutionContext, type HttpField, type HttpQuery, type LogqlQuery, type MongodbQuery, type PromqlQuery, type QueryLanguage, type RedisQuery, type SearchQuery, type SqlDialect, type SqlParameter, type SqlPlaceholderStyle, type SqlQuery, type SqlRowLimit, sqlDialects, type TimeRange, } from './queries.js';
11
12
  export type { FieldReference, HealthReport, SampleResult, SchemaEntity, SchemaField, SchemaSnapshot, } from './schema.js';
package/index.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * import type { ConnectorKit } from '@quanthea/plugin-kit';
7
7
  * export const kitVersion = 0;
8
8
  * export default function plugin(kit: ConnectorKit) {
9
- * return [kit.defineConnector({ kind: 'example', … })];
9
+ * return { connectors: [kit.defineConnector({ kind: 'example', … })] };
10
10
  * }
11
11
  * ```
12
12
  */
@@ -15,7 +15,7 @@ export type { ConnectorError, ConnectorErrorCode } from './errors.js';
15
15
  export type { FrameBuilder, FrameBuilderOptions } from './frame-builder.js';
16
16
  export type { Field, FieldType, Frame } from './frames.js';
17
17
  export type { HttpClient, HttpClientOptions, HttpRequest, HttpResponse } from './http.js';
18
- export { type ConnectorKit, type ConnectorPlugin, kitVersion } from './kit.js';
18
+ export { type ConnectorKit, kitVersion, type Plugin, type PluginContributions } from './kit.js';
19
19
  export type { BoundQuery, ExecutionContext, HttpField, HttpQuery, LogqlQuery, MongodbQuery, PromqlQuery, QueryLanguage, RedisQuery, SearchQuery, SqlDialect, SqlParameter, SqlPlaceholderStyle, SqlQuery, SqlRowLimit, TimeRange, } from './queries.js';
20
20
  export type { FieldReference, HealthReport, SampleResult, SchemaEntity, SchemaField, SchemaSnapshot, } from './schema.js';
21
21
  export type { SeriesData } from './series-frames.js';
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  kitVersion2
4
- } from "./chunk-3ayrhcmg.js";
4
+ } from "./chunk-9jgedrqw.js";
5
5
  export {
6
6
  kitVersion2 as kitVersion
7
7
  };
package/kit.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The kit quanthea hands a plugin when it loads it, and the shape of a plugin. The kit is the live
2
+ * The kit quanthea hands a plugin when it loads it, and the shape of a plugin and what it adds. The kit is the live
3
3
  * one: its Zod, its error class and its helpers are the server's own, so a plugin's schemas and
4
4
  * errors are the ones the core checks.
5
5
  */
@@ -29,9 +29,17 @@ export interface ConnectorKit {
29
29
  readonly seriesFrames: typeof seriesFrames;
30
30
  }
31
31
  /**
32
- * A plugin's default export: given the kit, the connector kinds it adds.
32
+ * What a plugin adds to quanthea, by kind of contribution. Connector kinds are the one kind today;
33
+ * others will be added beside them, so a plugin written now keeps loading.
34
+ */
35
+ export interface PluginContributions {
36
+ /** The connector kinds the plugin adds. */
37
+ readonly connectors: readonly ConnectorKind[];
38
+ }
39
+ /**
40
+ * A plugin's default export: given the kit, what the plugin adds.
33
41
  *
34
42
  * @param kit - The kit.
35
- * @returns The kinds.
43
+ * @returns The contributions.
36
44
  */
37
- export type ConnectorPlugin = (kit: ConnectorKit) => readonly ConnectorKind[];
45
+ export type Plugin = (kit: ConnectorKit) => PluginContributions;
package/naming.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /** How plugins and connector kinds are named, as the loader and the static checks read them. */
2
+ /** A plugin's npm package name: `quanthea-plugin-<name>` or `@scope/quanthea-plugin-<name>`. */
3
+ export declare const pluginNamePattern: RegExp;
4
+ /** A connector kind identifier: lowercase letters, digits and dashes, up to 40 characters. */
5
+ export declare const kindPattern: RegExp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quanthea/plugin-kit",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "The connector kit: the types a quanthea connector plugin is written against, a test kit and the conformance suite.",
5
5
  "keywords": [
6
6
  "quanthea",
package/queries.d.ts CHANGED
@@ -1,25 +1,7 @@
1
1
  /** The queries a connector executes: already bound, never a template with raw variables. */
2
2
  import type { QueryLanguage } from './languages.js';
3
+ export { type SqlDialect, type SqlPlaceholderStyle, type SqlRowLimit, sqlDialects, sqlPlaceholderStyles, sqlRowLimits, } from './dialects.js';
3
4
  export type { QueryLanguage };
4
- /**
5
- * The SQL dialects the core knows how to bind: how each writes its literals and its placeholders.
6
- * A SQL connector kind declares one of them. `ansi` is standard SQL, for the sources the others do
7
- * not fit; its kind also picks a placeholder style and a row-limit style.
8
- */
9
- export declare const sqlDialects: readonly ["postgres", "mysql", "clickhouse", "trino", "influxdb", "ansi"];
10
- /** A SQL dialect name. */
11
- export type SqlDialect = (typeof sqlDialects)[number];
12
- /**
13
- * How an `ansi` source writes a placeholder: `?` (JDBC, ODBC, SQLite, Snowflake), `$1` (numbered,
14
- * as PostgreSQL), `:1` (numbered, as Oracle) or `@p1` (named, as SQL Server drivers).
15
- */
16
- export declare const sqlPlaceholderStyles: readonly ["?", "$1", ":1", "@p1"];
17
- /** A placeholder style. */
18
- export type SqlPlaceholderStyle = (typeof sqlPlaceholderStyles)[number];
19
- /** How an `ansi` source limits rows: `FETCH FIRST n ROWS ONLY`, the standard, or `LIMIT n`. */
20
- export declare const sqlRowLimits: readonly ["fetch", "limit"];
21
- /** A row-limit style. */
22
- export type SqlRowLimit = (typeof sqlRowLimits)[number];
23
5
  /** A value bound to a SQL placeholder. */
24
6
  export type SqlParameter = string | number | boolean | Date | null;
25
7
  /**
package/testing.js CHANGED
@@ -1,15 +1,27 @@
1
1
  // @bun
2
2
  import {
3
3
  kitVersion2
4
- } from "./chunk-3ayrhcmg.js";
4
+ } from "./chunk-9jgedrqw.js";
5
5
 
6
- // packages/plugin-kit/src/testing.ts
6
+ // src/testing.ts
7
7
  import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8
8
 
9
- // packages/plugin-kit/src/checks.ts
9
+ // src/checks.ts
10
10
  import { z as z2 } from "zod";
11
11
 
12
- // packages/plugin-kit/src/languages.ts
12
+ // src/dialects.ts
13
+ var sqlDialects = [
14
+ "postgres",
15
+ "mysql",
16
+ "clickhouse",
17
+ "trino",
18
+ "influxdb",
19
+ "ansi"
20
+ ];
21
+ var sqlPlaceholderStyles = ["?", "$1", ":1", "@p1"];
22
+ var sqlRowLimits = ["fetch", "limit"];
23
+
24
+ // src/languages.ts
13
25
  import { z } from "zod";
14
26
  var queryLanguages = [
15
27
  "sql",
@@ -22,20 +34,10 @@ var queryLanguages = [
22
34
  ];
23
35
  var queryLanguageSchema = z.enum(queryLanguages);
24
36
 
25
- // packages/plugin-kit/src/queries.ts
26
- var sqlDialects = [
27
- "postgres",
28
- "mysql",
29
- "clickhouse",
30
- "trino",
31
- "influxdb",
32
- "ansi"
33
- ];
34
- var sqlPlaceholderStyles = ["?", "$1", ":1", "@p1"];
35
- var sqlRowLimits = ["fetch", "limit"];
36
-
37
- // packages/plugin-kit/src/checks.ts
37
+ // src/naming.ts
38
38
  var kindPattern = /^[a-z][a-z0-9-]{0,39}$/;
39
+
40
+ // src/checks.ts
39
41
  var pathPattern = /^[MmZzLlHhVvCcSsQqTtAa0-9eE.,\s+-]+$/;
40
42
  var colorPattern = /^#[0-9a-fA-F]{6}$/;
41
43
  var maxGuideLength = 8192;
@@ -133,7 +135,7 @@ function kindProblems(kind) {
133
135
  return [...failed, ...schemaProblems(candidate)];
134
136
  }
135
137
 
136
- // packages/plugin-kit/src/errors.ts
138
+ // src/errors.ts
137
139
  var connectorErrorCodes = [
138
140
  "unreachable",
139
141
  "authentication",
@@ -165,7 +167,7 @@ class ConnectorError extends Error {
165
167
  }
166
168
  Object.defineProperty(ConnectorError.prototype, brand, { value: true });
167
169
 
168
- // packages/plugin-kit/src/frames.ts
170
+ // src/frames.ts
169
171
  import { z as z3 } from "zod";
170
172
  var fieldTypes = ["time", "number", "string", "boolean"];
171
173
  var fieldSchema = z3.object({
@@ -213,11 +215,9 @@ function frameProblems(frame) {
213
215
  });
214
216
  }
215
217
 
216
- // packages/plugin-kit/src/host.ts
218
+ // src/host.ts
217
219
  import { z as z4 } from "zod";
218
-
219
- // packages/plugin-kit/src/connector-kind.ts
220
- var kindPattern2 = /^[a-z][a-z0-9-]*$/;
220
+ // src/connector-kind.ts
221
221
  var pathPattern2 = /^[MmZzLlHhVvCcSsQqTtAa0-9eE.,\s+-]+$/;
222
222
  var colorPattern2 = /^#[0-9a-fA-F]{6}$/;
223
223
  function checkIcon(kind, icon) {
@@ -236,8 +236,8 @@ function checkAnsiStyles(definition) {
236
236
  throw new Error(`Connector kind "${kind}" has rowLimit "${rowLimit}": use fetch or limit.`);
237
237
  }
238
238
  function defineConnector(definition) {
239
- if (!kindPattern2.test(definition.kind)) {
240
- throw new Error(`Connector kind "${definition.kind}" must be lowercase letters, digits and dashes.`);
239
+ if (!kindPattern.test(definition.kind)) {
240
+ throw new Error(`Connector kind "${definition.kind}" must be lowercase letters, digits and dashes, up to 40.`);
241
241
  }
242
242
  if (definition.language === "sql" && definition.dialect === undefined)
243
243
  throw new Error(`Connector kind "${definition.kind}" runs SQL and must declare its dialect.`);
@@ -246,7 +246,7 @@ function defineConnector(definition) {
246
246
  return definition;
247
247
  }
248
248
 
249
- // packages/plugin-kit/src/frame-builder.ts
249
+ // src/frame-builder.ts
250
250
  function createFrameBuilder(options) {
251
251
  const columns = options.fields.map(() => []);
252
252
  let rowCount = 0;
@@ -275,7 +275,7 @@ function createFrameBuilder(options) {
275
275
  };
276
276
  }
277
277
 
278
- // packages/plugin-kit/src/http-address.ts
278
+ // src/http-address.ts
279
279
  var metadataIpv4 = [/^169\.254\./, /^100\.100\.100\.200$/];
280
280
  var metadataIpv6 = [/^fe[89ab][0-9a-f]:/, /^fd00:ec2::254$/];
281
281
  var dottedIpv4 = /^\d{1,3}(?:\.\d{1,3}){3}$/;
@@ -311,7 +311,7 @@ async function checkDestination(url, sourceName) {
311
311
  throw refused;
312
312
  }
313
313
 
314
- // packages/plugin-kit/src/http.ts
314
+ // src/http.ts
315
315
  var maxRedirects = 5;
316
316
  function transportError(error, signal, sourceName) {
317
317
  if (error instanceof ConnectorError)
@@ -458,7 +458,7 @@ function createHttpClient(options) {
458
458
  };
459
459
  }
460
460
 
461
- // packages/plugin-kit/src/series-frames.ts
461
+ // src/series-frames.ts
462
462
  var maxSeries = 1000;
463
463
  function sampleValue(value) {
464
464
  const number = Number(value);
@@ -532,7 +532,7 @@ function seriesFrames(data, context, durationMs) {
532
532
  return [builder.build(durationMs)];
533
533
  }
534
534
 
535
- // packages/plugin-kit/src/host.ts
535
+ // src/host.ts
536
536
  var hostKit = Object.freeze({
537
537
  version: kitVersion2,
538
538
  z: z4,
@@ -543,7 +543,7 @@ var hostKit = Object.freeze({
543
543
  seriesFrames
544
544
  });
545
545
 
546
- // packages/plugin-kit/src/testing.ts
546
+ // src/testing.ts
547
547
  function createTestKit() {
548
548
  return hostKit;
549
549
  }