@lunora/d1 1.0.0-alpha.9 → 1.0.0-alpha.91

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.md CHANGED
@@ -103,3 +103,9 @@ Unless required by applicable law or agreed to in writing, software distributed
103
103
  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
104
  CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
105
  specific language governing permissions and limitations under the License.
106
+
107
+ <!-- DEPENDENCIES -->
108
+ <!-- /DEPENDENCIES -->
109
+
110
+ <!-- TYPE_DEPENDENCIES -->
111
+ <!-- /TYPE_DEPENDENCIES -->
@@ -1,39 +1,51 @@
1
1
  /**
2
- * The Lunora **D1 dialect** the single source of truth for how `.global()`
3
- * tables are physically shaped in D1.
4
- *
5
- * Both the runtime (`runD1GlobalTableMigrations` in `d1-ctx-db.ts`, which
6
- * auto-provisions tables) and the `lunora migrate generate` SQL emitter
7
- * (`@lunora/cli`'s `migration-diff.ts`) derive their DDL from these helpers, so
8
- * the table a migration writes is byte-identical to the one the runtime creates.
9
- * Previously each encoded the dialect independently and a comment begged them to
10
- * stay "in lockstep"; this module makes the lockstep structural.
11
- *
12
- * Exposed as the `@lunora/d1/dialect` subpath. Pure no runtime dependencies
13
- * so the CLI can import it without pulling the D1 runtime.
14
- */
2
+ * Canonical SQL identifier quoter shared by `@lunora/d1` and `@lunora/do`.
3
+ *
4
+ * Double-quotes a SQL identifier and escapes any embedded double quotes by
5
+ * doubling them (`"` `""`) — the ANSI/SQLite/Postgres rule. This is a
6
+ * security-relevant primitive (it is the sole defense against identifier
7
+ * injection wherever a table/column name is spliced into raw SQL), so it must
8
+ * have exactly ONE definition rather than byte-identical copies that can drift.
9
+ *
10
+ * Like `shared/stable-key.ts`, it is deliberately **not** a package: `@lunora/d1`
11
+ * and `@lunora/do` sit on the same tier with no lower-level package to host it,
12
+ * so each imports this file by relative path and the bundler (packem/rollup)
13
+ * inlines it no runtime dependency edge, duplicated only in emitted output.
14
+ * Keep it genuinely zero-dependency (relative/built-in imports only) or inlining
15
+ * breaks. Consumers must drop `outDir`/`rootDir` from their `tsconfig.json` (a
16
+ * set `rootDir` raises TS6059 for this out-of-package file under `tsc --noEmit`).
17
+ */
18
+ declare const quoteIdentifier: (name: string) => string;
15
19
  /** SQLite column type affinities Lunora emits. */
16
20
  type SqlAffinity = "BLOB" | "INTEGER" | "REAL" | "TEXT";
17
- /** Double-quote (and escape) a SQL identifier. */
18
- declare const quoteIdentifier: (name: string) => string;
19
21
  /**
20
- * SQLite affinity for a column by its validator `kind`, chosen so the value the
21
- * D1 layer serializes round-trips intact:
22
- * - `boolean` → INTEGER (stored as 1/0)
23
- * - `number`/`timestamp`/`date` → REAL (numeric, never coerced to text)
24
- * - `bytes` → BLOB
25
- * - everything else → TEXT — string/id/literal, `bigint` (serialized as a
26
- * decimal string), and object/array/record/union/any (JSON). A numeric affinity
27
- * would coerce a numeric-looking string and corrupt the decode.
28
- */
22
+ * SQLite affinity for a column by its validator `kind`, chosen so the value the
23
+ * D1 layer serializes round-trips intact:
24
+ * - `boolean` → INTEGER (stored as 1/0)
25
+ * - `number`/`timestamp`/`date` → REAL (numeric, never coerced to text)
26
+ * - `bytes` → BLOB
27
+ * - everything else → TEXT — string/id/literal, `bigint` (serialized as a
28
+ * decimal string), and object/array/record/union/any (JSON). A numeric affinity
29
+ * would coerce a numeric-looking string and corrupt the decode.
30
+ */
29
31
  declare const sqlAffinityForKind: (kind: string | undefined) => SqlAffinity;
32
+ /**
33
+ * Most columns one D1 table may carry, framework columns included.
34
+ *
35
+ * D1 runs Workerd's SQLite build, which sets `SQLITE_LIMIT_COLUMN` to 100 where
36
+ * stock SQLite allows 2,000. Exported so the two producers of global-table DDL
37
+ * — the runtime auto-provisioner in `@lunora/sql-store` and the
38
+ * `lunora migrate generate` emitter — check the same number rather than each
39
+ * carrying its own copy.
40
+ */
41
+ declare const MAX_D1_TABLE_COLUMNS = 100;
30
42
  /** Framework columns every global table carries: the physical `id` (exposed as `_id`) and `_creationTime`. */
31
43
  declare const frameworkColumnDdl: () => ReadonlyArray<string>;
32
44
  /**
33
- * Resolve a schema field to its physical D1 column: `_id`/`id` both map to the
34
- * physical `id` column, `_creationTime` to its own, every other field to itself.
35
- */
45
+ * Resolve a schema field to its physical D1 column: `_id`/`id` both map to the
46
+ * physical `id` column, `_creationTime` to its own, every other field to itself.
47
+ */
36
48
  declare const columnRef: (field: string) => string;
37
- /** Physical index identifier — `&lt;table>_&lt;name>`, so two tables' like-named indexes don't collide in SQLite's flat index namespace. */
49
+ /** Physical index identifier — `<table>_<name>`, so two tables' like-named indexes don't collide in SQLite's flat index namespace. */
38
50
  declare const physicalIndexName: (tableName: string, indexName: string) => string;
39
- export { SqlAffinity, columnRef, frameworkColumnDdl, physicalIndexName, quoteIdentifier, sqlAffinityForKind };
51
+ export { MAX_D1_TABLE_COLUMNS, SqlAffinity, columnRef, frameworkColumnDdl, physicalIndexName, quoteIdentifier, sqlAffinityForKind };
package/dist/dialect.d.ts CHANGED
@@ -1,39 +1,51 @@
1
1
  /**
2
- * The Lunora **D1 dialect** the single source of truth for how `.global()`
3
- * tables are physically shaped in D1.
4
- *
5
- * Both the runtime (`runD1GlobalTableMigrations` in `d1-ctx-db.ts`, which
6
- * auto-provisions tables) and the `lunora migrate generate` SQL emitter
7
- * (`@lunora/cli`'s `migration-diff.ts`) derive their DDL from these helpers, so
8
- * the table a migration writes is byte-identical to the one the runtime creates.
9
- * Previously each encoded the dialect independently and a comment begged them to
10
- * stay "in lockstep"; this module makes the lockstep structural.
11
- *
12
- * Exposed as the `@lunora/d1/dialect` subpath. Pure no runtime dependencies
13
- * so the CLI can import it without pulling the D1 runtime.
14
- */
2
+ * Canonical SQL identifier quoter shared by `@lunora/d1` and `@lunora/do`.
3
+ *
4
+ * Double-quotes a SQL identifier and escapes any embedded double quotes by
5
+ * doubling them (`"` `""`) — the ANSI/SQLite/Postgres rule. This is a
6
+ * security-relevant primitive (it is the sole defense against identifier
7
+ * injection wherever a table/column name is spliced into raw SQL), so it must
8
+ * have exactly ONE definition rather than byte-identical copies that can drift.
9
+ *
10
+ * Like `shared/stable-key.ts`, it is deliberately **not** a package: `@lunora/d1`
11
+ * and `@lunora/do` sit on the same tier with no lower-level package to host it,
12
+ * so each imports this file by relative path and the bundler (packem/rollup)
13
+ * inlines it no runtime dependency edge, duplicated only in emitted output.
14
+ * Keep it genuinely zero-dependency (relative/built-in imports only) or inlining
15
+ * breaks. Consumers must drop `outDir`/`rootDir` from their `tsconfig.json` (a
16
+ * set `rootDir` raises TS6059 for this out-of-package file under `tsc --noEmit`).
17
+ */
18
+ declare const quoteIdentifier: (name: string) => string;
15
19
  /** SQLite column type affinities Lunora emits. */
16
20
  type SqlAffinity = "BLOB" | "INTEGER" | "REAL" | "TEXT";
17
- /** Double-quote (and escape) a SQL identifier. */
18
- declare const quoteIdentifier: (name: string) => string;
19
21
  /**
20
- * SQLite affinity for a column by its validator `kind`, chosen so the value the
21
- * D1 layer serializes round-trips intact:
22
- * - `boolean` → INTEGER (stored as 1/0)
23
- * - `number`/`timestamp`/`date` → REAL (numeric, never coerced to text)
24
- * - `bytes` → BLOB
25
- * - everything else → TEXT — string/id/literal, `bigint` (serialized as a
26
- * decimal string), and object/array/record/union/any (JSON). A numeric affinity
27
- * would coerce a numeric-looking string and corrupt the decode.
28
- */
22
+ * SQLite affinity for a column by its validator `kind`, chosen so the value the
23
+ * D1 layer serializes round-trips intact:
24
+ * - `boolean` → INTEGER (stored as 1/0)
25
+ * - `number`/`timestamp`/`date` → REAL (numeric, never coerced to text)
26
+ * - `bytes` → BLOB
27
+ * - everything else → TEXT — string/id/literal, `bigint` (serialized as a
28
+ * decimal string), and object/array/record/union/any (JSON). A numeric affinity
29
+ * would coerce a numeric-looking string and corrupt the decode.
30
+ */
29
31
  declare const sqlAffinityForKind: (kind: string | undefined) => SqlAffinity;
32
+ /**
33
+ * Most columns one D1 table may carry, framework columns included.
34
+ *
35
+ * D1 runs Workerd's SQLite build, which sets `SQLITE_LIMIT_COLUMN` to 100 where
36
+ * stock SQLite allows 2,000. Exported so the two producers of global-table DDL
37
+ * — the runtime auto-provisioner in `@lunora/sql-store` and the
38
+ * `lunora migrate generate` emitter — check the same number rather than each
39
+ * carrying its own copy.
40
+ */
41
+ declare const MAX_D1_TABLE_COLUMNS = 100;
30
42
  /** Framework columns every global table carries: the physical `id` (exposed as `_id`) and `_creationTime`. */
31
43
  declare const frameworkColumnDdl: () => ReadonlyArray<string>;
32
44
  /**
33
- * Resolve a schema field to its physical D1 column: `_id`/`id` both map to the
34
- * physical `id` column, `_creationTime` to its own, every other field to itself.
35
- */
45
+ * Resolve a schema field to its physical D1 column: `_id`/`id` both map to the
46
+ * physical `id` column, `_creationTime` to its own, every other field to itself.
47
+ */
36
48
  declare const columnRef: (field: string) => string;
37
- /** Physical index identifier — `&lt;table>_&lt;name>`, so two tables' like-named indexes don't collide in SQLite's flat index namespace. */
49
+ /** Physical index identifier — `<table>_<name>`, so two tables' like-named indexes don't collide in SQLite's flat index namespace. */
38
50
  declare const physicalIndexName: (tableName: string, indexName: string) => string;
39
- export { SqlAffinity, columnRef, frameworkColumnDdl, physicalIndexName, quoteIdentifier, sqlAffinityForKind };
51
+ export { MAX_D1_TABLE_COLUMNS, SqlAffinity, columnRef, frameworkColumnDdl, physicalIndexName, quoteIdentifier, sqlAffinityForKind };
package/dist/dialect.mjs CHANGED
@@ -1,35 +1 @@
1
- const quoteIdentifier = (name) => `"${name.replaceAll('"', '""')}"`;
2
- const sqlAffinityForKind = (kind) => {
3
- switch (kind) {
4
- case "boolean": {
5
- return "INTEGER";
6
- }
7
- case "bytes": {
8
- return "BLOB";
9
- }
10
- case "date":
11
- case "number":
12
- case "timestamp": {
13
- return "REAL";
14
- }
15
- default: {
16
- return "TEXT";
17
- }
18
- }
19
- };
20
- const frameworkColumnDdl = () => [
21
- `${quoteIdentifier("id")} TEXT PRIMARY KEY`,
22
- `${quoteIdentifier("_creationTime")} REAL NOT NULL`
23
- ];
24
- const columnRef = (field) => {
25
- if (field === "_id" || field === "id") {
26
- return quoteIdentifier("id");
27
- }
28
- if (field === "_creationTime") {
29
- return quoteIdentifier("_creationTime");
30
- }
31
- return quoteIdentifier(field);
32
- };
33
- const physicalIndexName = (tableName, indexName) => quoteIdentifier(`${tableName}_${indexName}`);
34
-
35
- export { columnRef, frameworkColumnDdl, physicalIndexName, quoteIdentifier, sqlAffinityForKind };
1
+ import{quoteIdentifier as t}from"./packem_shared/quoteIdentifier-CObIFRhb.mjs";const i=e=>{switch(e){case"boolean":return"INTEGER";case"bytes":return"BLOB";case"date":case"number":case"timestamp":return"REAL";default:return"TEXT"}},o=100,c=()=>[`${t("id")} TEXT PRIMARY KEY`,`${t("_creationTime")} REAL NOT NULL`],a=e=>e==="_id"||e==="id"?t("id"):e==="_creationTime"?t("_creationTime"):t(e),s=(e,r)=>t(`${e}_${r}`);export{o as MAX_D1_TABLE_COLUMNS,a as columnRef,c as frameworkColumnDdl,s as physicalIndexName,t as quoteIdentifier,i as sqlAffinityForKind};