@lines-db/studio 0.16.2 → 0.16.4

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
@@ -1,5 +1,23 @@
1
1
  # @lines-db/studio
2
2
 
3
+ ## 0.16.4
4
+
5
+ ### Patch Changes
6
+
7
+ - aa9725e: `lines-db studio` now lists a table whose JSONL file has no rows, and a table with a primary key can have its first row added in the studio. The studio reads the columns of such a table from the types of its schema file, so the table is listed when the schema declares its input type through `~standard.types` (zod and valibot do; a hand-written Standard Schema has to declare `types`). Without types, the table stays out of the list as before. `DatabaseConfig` has a new `schemaOfEmptyTable` option to give the columns of a table with no rows. `lines-db validate` no longer says a table has "validation errors" when it only skips the foreign keys that point at an empty table; it says the table has no rows to read its columns from.
8
+ - Updated dependencies [8deddc8]
9
+ - Updated dependencies [aa9725e]
10
+ - Updated dependencies [376a141]
11
+ - Updated dependencies [8deddc8]
12
+ - Updated dependencies [8deddc8]
13
+ - lines-db@0.19.0
14
+
15
+ ## 0.16.3
16
+
17
+ ### Patch Changes
18
+
19
+ - 7943f11: Update the bundled Studio UI to matching React and React DOM 19.3.1 versions.
20
+
3
21
  ## 0.16.2
4
22
 
5
23
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { WriteFilledValues } from "lines-db";
2
- //#region src/server.d.ts
3
2
  interface StudioServerOptions {
4
3
  dataDir: string | string[];
5
4
  schemaDir?: string;
@@ -17,6 +16,5 @@ interface StudioServer {
17
16
  close(): Promise<void>;
18
17
  }
19
18
  export declare function startStudioServer(options: StudioServerOptions): Promise<StudioServer>;
20
- //#endregion
21
19
  export type { StudioServer, StudioServerOptions };
22
20
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/server.ts"],"mappings":";;UA8BiB;EACf;EACA;;EAEA;;EAEA,oBAAoB;EACpB;EACA;;UAGe;EACf;;EAEA;EACA,SAAS;;wBAwBW,kBAAkB,SAAS,sBAAsB,QAAQ"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/server.ts"],"mappings":";UA8BiB;EACf;EACA;;EAEA;;EAEA,oBAAoB;EACpB;EACA;;UAGe;EACf;;EAEA;EACA,SAAS;;wBAwBW,kBAAkB,SAAS,sBAAsB,QAAQ"}
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import { basename, dirname, extname, join, relative, resolve, win32 } from "node
7
7
  import { fileURLToPath, pathToFileURL } from "node:url";
8
8
  import { DirectoryScanner, ErrorFormatter, JsonlReader, LinesDB, findSchemaFile, unwrap } from "lines-db";
9
9
  import { hashJsonlContent, replaceFile } from "lines-db/internal";
10
- //#region src/declared-columns.ts
10
+ // src/declared-columns.ts
11
11
  const CORSA_NULL = 8;
12
12
  const CORSA_UNION = 134217728;
13
13
  const CORSA_OPTIONAL = 16777216;
@@ -190,8 +190,60 @@ async function readDeclaredColumns(schemaPath, searchFrom) {
190
190
  return;
191
191
  }
192
192
  }
193
- //#endregion
194
- //#region src/file-rows.ts
193
+ /**
194
+ * The table the columns a schema file declares make, for a table with no rows to infer them from. The types
195
+ * are written as the compiler prints them, so a number cannot be told an integer from a real one and is stored
196
+ * as REAL, which gives an integer back as one.
197
+ */
198
+ function tableSchemaOf(tableName, columns) {
199
+ return {
200
+ name: tableName,
201
+ columns: columns.map((column) => ({
202
+ name: column.name,
203
+ type: sqlTypeOf(column.type),
204
+ notNull: !column.optional && !column.nullable,
205
+ ...isBoolean(column.type) ? { valueType: "boolean" } : {}
206
+ }))
207
+ };
208
+ }
209
+ function kindOf(member) {
210
+ if (member === "string" || /^(".*"|'.*')$/.test(member)) return "text";
211
+ if (member === "number" || /^-?\d+(\.\d+)?$/.test(member)) return "number";
212
+ if (member === "boolean" || member === "true" || member === "false") return "boolean";
213
+ return "other";
214
+ }
215
+ function sqlTypeOf(type) {
216
+ const kinds = new Set(unionMembers(type).map(kindOf));
217
+ if (kinds.size !== 1) return "JSON";
218
+ const [kind] = kinds;
219
+ return kind === "text" ? "TEXT" : kind === "number" ? "REAL" : kind === "boolean" ? "INTEGER" : "JSON";
220
+ }
221
+ function isBoolean(type) {
222
+ return unionMembers(type).every((member) => kindOf(member) === "boolean");
223
+ }
224
+ /** The members of a union as the compiler prints it, split only where ` | ` is outside quotes and brackets */
225
+ function unionMembers(type) {
226
+ const members = [];
227
+ let depth = 0;
228
+ let quote;
229
+ let start = 0;
230
+ for (let index = 0; index < type.length; index++) {
231
+ const char = type[index];
232
+ if (quote) {
233
+ if (char === "\\") index++;
234
+ else if (char === quote) quote = void 0;
235
+ } else if (char === "\"" || char === "'") quote = char;
236
+ else if ("{[(<".includes(char)) depth++;
237
+ else if ("}])>".includes(char)) depth--;
238
+ else if (depth === 0 && type.startsWith(" | ", index)) {
239
+ members.push(type.slice(start, index));
240
+ start = index + 3;
241
+ }
242
+ }
243
+ members.push(type.slice(start));
244
+ return members;
245
+ }
246
+ // src/file-rows.ts
195
247
  /**
196
248
  * The content with the rows at the given indexes - counting the lines that hold a row, as reading
197
249
  * the file does - written over their lines, and every other line left as it was
@@ -207,8 +259,7 @@ function replaceRows(content, replaced) {
207
259
  return row ? `${JSON.stringify(row)}${carriage}` : raw;
208
260
  }).join("\n");
209
261
  }
210
- //#endregion
211
- //#region src/server.ts
262
+ // src/server.ts
212
263
  async function startStudioServer(options) {
213
264
  const dataDirs = [];
214
265
  const seen = /* @__PURE__ */ new Set();
@@ -716,6 +767,7 @@ async function startStudioServer(options) {
716
767
  }
717
768
  };
718
769
  }
770
+ leeway.get(snapshot)?.delete(tableName);
719
771
  return {
720
772
  status: write.kind === "insert" ? 201 : 200,
721
773
  body: { ok: true },
@@ -759,7 +811,11 @@ async function loadSnapshot(dataDir, schemaDir, writeFilledValues) {
759
811
  dataDir,
760
812
  schemaDir,
761
813
  writeFilledValues,
762
- writeDataSets: true
814
+ writeDataSets: true,
815
+ schemaOfEmptyTable: async ({ tableName, schemaPath }) => {
816
+ const declared = schemaPath && await readDeclaredColumns(schemaPath, schemaDir ?? dirname(schemaPath));
817
+ return declared ? tableSchemaOf(tableName, declared) : void 0;
818
+ }
763
819
  });
764
820
  const baseDir = [dataDir].flat()[0];
765
821
  const loaded = await db.initialize({ detailedValidate: true });
@@ -1203,7 +1259,6 @@ function parseJson(text, message) {
1203
1259
  function errorMessage(error) {
1204
1260
  return error instanceof Error ? error.message : String(error);
1205
1261
  }
1206
- //#endregion
1207
1262
  export { startStudioServer };
1208
1263
 
1209
1264
  //# sourceMappingURL=index.mjs.map