@rljson/rljson 0.0.84 → 0.0.85

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.public.md CHANGED
@@ -37,6 +37,7 @@ Core types, validation, and sync protocol for the RLJSON data format.
37
37
  - [SyncEventNames](#synceventnames)
38
38
  - [ClientId](#clientid)
39
39
  - [Utilities](#utilities)
40
+ - [Tables](#tables)
40
41
  - [Row, ref and rowOf](#row-ref-and-rowof)
41
42
  - [TimeId](#timeid)
42
43
  - [RemoveDuplicates](#removeduplicates)
@@ -389,6 +390,27 @@ const onConflict: ConflictCallback = (conflict: Conflict) => {
389
390
 
390
391
  ## Utilities
391
392
 
393
+ ### Tables
394
+
395
+ `Tables` is a read-only view on the tables of an Rljson dump. By default it
396
+ hides insert history tables and tables whose key starts with `_`.
397
+
398
+ ```ts
399
+ import { Tables } from '@rljson/rljson';
400
+
401
+ const tables = new Tables(rljson);
402
+ tables.ls(); // ['cars', 'tableCfgs'] — sorted table keys
403
+ tables.ls({ internal: true }); // also insert history and `_` tables
404
+ tables.ls({ long: true }); // aligned lines: 'cars components 2'
405
+ tables.all; // the visible tables in ls() order
406
+ tables.count; // number of visible tables
407
+ tables.get('cars'); // the table or undefined
408
+ tables.has('carsInsertHistory'); // true, also for internal tables
409
+ tables.ofType('components'); // sorted keys of that type, internal included
410
+ tables.cfg('cars'); // the latest TableCfg of the table
411
+ tables.rowCount('cars'); // 2
412
+ ```
413
+
392
414
  ### Row, ref and rowOf
393
415
 
394
416
  A `Row` is a row of an Rljson table: a JSON object whose `_hash` is written by
@@ -37,6 +37,7 @@ Core types, validation, and sync protocol for the RLJSON data format.
37
37
  - [SyncEventNames](#synceventnames)
38
38
  - [ClientId](#clientid)
39
39
  - [Utilities](#utilities)
40
+ - [Tables](#tables)
40
41
  - [Row, ref and rowOf](#row-ref-and-rowof)
41
42
  - [TimeId](#timeid)
42
43
  - [RemoveDuplicates](#removeduplicates)
@@ -389,6 +390,27 @@ const onConflict: ConflictCallback = (conflict: Conflict) => {
389
390
 
390
391
  ## Utilities
391
392
 
393
+ ### Tables
394
+
395
+ `Tables` is a read-only view on the tables of an Rljson dump. By default it
396
+ hides insert history tables and tables whose key starts with `_`.
397
+
398
+ ```ts
399
+ import { Tables } from '@rljson/rljson';
400
+
401
+ const tables = new Tables(rljson);
402
+ tables.ls(); // ['cars', 'tableCfgs'] — sorted table keys
403
+ tables.ls({ internal: true }); // also insert history and `_` tables
404
+ tables.ls({ long: true }); // aligned lines: 'cars components 2'
405
+ tables.all; // the visible tables in ls() order
406
+ tables.count; // number of visible tables
407
+ tables.get('cars'); // the table or undefined
408
+ tables.has('carsInsertHistory'); // true, also for internal tables
409
+ tables.ofType('components'); // sorted keys of that type, internal included
410
+ tables.cfg('cars'); // the latest TableCfg of the table
411
+ tables.rowCount('cars'); // 2
412
+ ```
413
+
392
414
  ### Row, ref and rowOf
393
415
 
394
416
  A `Row` is a row of an Rljson table: a JSON object whose `_hash` is written by
package/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ export * from './sync/connector-payload.ts';
23
23
  export * from './sync/gap-fill.ts';
24
24
  export * from './sync/sync-config.ts';
25
25
  export * from './sync/sync-events.ts';
26
+ export * from './tables/tables.ts';
26
27
  export * from './tools/ref.ts';
27
28
  export * from './tools/resolve-slice-ids.ts';
28
29
  export * from './tools/remove-duplicates.ts';
package/dist/rljson.js CHANGED
@@ -2046,6 +2046,91 @@ var syncEvents = (route) => ({
2046
2046
  bootstrap: `${route}:bootstrap`
2047
2047
  });
2048
2048
  //#endregion
2049
+ //#region src/tables/tables.ts
2050
+ // @license
2051
+ /**
2052
+ * Read only view on the tables of an Rljson dump.
2053
+ *
2054
+ * By default insert history tables and tables whose key starts with `_`
2055
+ * are hidden. Pass `internal: true` to ls() to include them.
2056
+ */
2057
+ var Tables = class Tables {
2058
+ /**
2059
+ * Creates a view on the tables of the Rljson
2060
+ * @param rljson - the Rljson dump to wrap
2061
+ */
2062
+ constructor(rljson) {
2063
+ this._rljson = rljson;
2064
+ }
2065
+ _rljson;
2066
+ /** The wrapped Rljson */
2067
+ get rljson() {
2068
+ return this._rljson;
2069
+ }
2070
+ /**
2071
+ * The sorted table keys.
2072
+ * @param options - see TablesLsOptions
2073
+ * @returns table keys, or aligned lines `name type rowCount` with `long`
2074
+ */
2075
+ ls(options = {}) {
2076
+ const keys = this._keys(options.internal === true);
2077
+ if (!options.long) return keys;
2078
+ const nameWidth = Math.max(0, ...keys.map((k) => k.length));
2079
+ const typeWidth = Math.max(0, ...keys.map((k) => this.get(k)._type.length));
2080
+ return keys.map((k) => `${k.padEnd(nameWidth)} ${this.get(k)._type.padEnd(typeWidth)} ${this.rowCount(k)}`);
2081
+ }
2082
+ /** The visible tables in ls() order */
2083
+ get all() {
2084
+ return this.ls().map((k) => this.get(k));
2085
+ }
2086
+ /** The number of visible tables */
2087
+ get count() {
2088
+ return this.ls().length;
2089
+ }
2090
+ /**
2091
+ * The table with the given key or undefined
2092
+ * @param key - the table key
2093
+ */
2094
+ get(key) {
2095
+ const table = this._rljson[key];
2096
+ return Tables._isTable(table) ? table : void 0;
2097
+ }
2098
+ /**
2099
+ * True if a table with the key exists, including internal tables
2100
+ * @param key - the table key
2101
+ */
2102
+ has(key) {
2103
+ return this.get(key) !== void 0;
2104
+ }
2105
+ /**
2106
+ * The sorted keys of all tables with the given type, including internal
2107
+ * @param type - the content type
2108
+ */
2109
+ ofType(type) {
2110
+ return this._keys(true).filter((k) => this.get(k)._type === type);
2111
+ }
2112
+ /**
2113
+ * The latest table config for the key, or undefined
2114
+ * @param key - the table key
2115
+ */
2116
+ cfg(key) {
2117
+ return (this.get("tableCfgs")?._data ?? []).filter((c) => c.key === key).pop();
2118
+ }
2119
+ /**
2120
+ * The number of rows of the table, 0 if it does not exist
2121
+ * @param key - the table key
2122
+ */
2123
+ rowCount(key) {
2124
+ return this.get(key)?._data.length ?? 0;
2125
+ }
2126
+ _keys(internal) {
2127
+ return Object.keys(this._rljson).filter((k) => this.has(k)).filter((k) => internal || !k.startsWith("_") && this.get(k)._type !== "insertHistory").sort();
2128
+ }
2129
+ static _isTable(value) {
2130
+ return typeof value === "object" && value !== null && typeof value._type === "string" && Array.isArray(value._data);
2131
+ }
2132
+ };
2133
+ //#endregion
2049
2134
  //#region src/tools/ref.ts
2050
2135
  // @license
2051
2136
  /**
@@ -2932,4 +3017,4 @@ var Validate = class {
2932
3017
  //#region src/index.ts
2933
3018
  // @license
2934
3019
  //#endregion
2935
- export { BaseValidator, Example, InsertValidator, Route, Validate, ackPayloadExample, ackPayloadPartialExample, addColumnsToTableCfg, bakeryExample, clientId, clientIdExample, connectorPayloadExample, connectorPayloadFullExample, contentTypes, createCakeTableCfg, createEditHistoryTableCfg, createEditTableCfg, createInsertHistoryTableCfg, createLayerTableCfg, createMultiEditTableCfg, createSliceIdsTableCfg, createTreesTableCfg, exampleBuffetsTable, exampleCakesTable, exampleComponentsTable, exampleInsert, exampleInsertHistoryTable, exampleLayersTable, exampleRevision, exampleRljson, exampleSliceIdsTable, exampleTableCfg, exampleTableCfgTable, exampleTreesTable, exampleTypedefs, gapFillRequestExample, gapFillResponseExample, getTimeIdTimestamp, getTimeIdUniquePart, isClientId, isTimeId, isValidFieldName, iterateTables, iterateTablesSync, mergeSliceIds, ref, removeDuplicates, reservedFieldNames, reservedTableKeys, resolveSliceIds, routeRefSeperator, routeSliceIdIndicators, routeSliceIdSeperator, rowOf, syncConfigCausalOnlyExample, syncConfigDefault, syncConfigFullExample, syncEvents, throwOnInvalidTableCfg, timeId, treeFromObject, validateInsert, validateRljsonAgainstTableCfg };
3020
+ export { BaseValidator, Example, InsertValidator, Route, Tables, Validate, ackPayloadExample, ackPayloadPartialExample, addColumnsToTableCfg, bakeryExample, clientId, clientIdExample, connectorPayloadExample, connectorPayloadFullExample, contentTypes, createCakeTableCfg, createEditHistoryTableCfg, createEditTableCfg, createInsertHistoryTableCfg, createLayerTableCfg, createMultiEditTableCfg, createSliceIdsTableCfg, createTreesTableCfg, exampleBuffetsTable, exampleCakesTable, exampleComponentsTable, exampleInsert, exampleInsertHistoryTable, exampleLayersTable, exampleRevision, exampleRljson, exampleSliceIdsTable, exampleTableCfg, exampleTableCfgTable, exampleTreesTable, exampleTypedefs, gapFillRequestExample, gapFillResponseExample, getTimeIdTimestamp, getTimeIdUniquePart, isClientId, isTimeId, isValidFieldName, iterateTables, iterateTablesSync, mergeSliceIds, ref, removeDuplicates, reservedFieldNames, reservedTableKeys, resolveSliceIds, routeRefSeperator, routeSliceIdIndicators, routeSliceIdSeperator, rowOf, syncConfigCausalOnlyExample, syncConfigDefault, syncConfigFullExample, syncEvents, throwOnInvalidTableCfg, timeId, treeFromObject, validateInsert, validateRljsonAgainstTableCfg };
@@ -1,2 +1,2 @@
1
1
  /** The version of the `@rljson/rljson` package. */
2
- export declare const rljsonVersion = "0.0.84";
2
+ export declare const rljsonVersion = "0.0.85";
@@ -0,0 +1,63 @@
1
+ import { TableCfg } from '../content/table-cfg.ts';
2
+ import { Rljson, TableType } from '../rljson.ts';
3
+ import { ContentType, TableKey } from '../typedefs.ts';
4
+ /** Options for Tables.ls */
5
+ export interface TablesLsOptions {
6
+ /** Return aligned lines `name type rowCount` instead of names */
7
+ long?: boolean;
8
+ /** Include insert history tables and tables starting with `_` */
9
+ internal?: boolean;
10
+ }
11
+ /**
12
+ * Read only view on the tables of an Rljson dump.
13
+ *
14
+ * By default insert history tables and tables whose key starts with `_`
15
+ * are hidden. Pass `internal: true` to ls() to include them.
16
+ */
17
+ export declare class Tables {
18
+ /**
19
+ * Creates a view on the tables of the Rljson
20
+ * @param rljson - the Rljson dump to wrap
21
+ */
22
+ constructor(rljson: Rljson);
23
+ private readonly _rljson;
24
+ /** The wrapped Rljson */
25
+ get rljson(): Rljson;
26
+ /**
27
+ * The sorted table keys.
28
+ * @param options - see TablesLsOptions
29
+ * @returns table keys, or aligned lines `name type rowCount` with `long`
30
+ */
31
+ ls(options?: TablesLsOptions): string[];
32
+ /** The visible tables in ls() order */
33
+ get all(): TableType[];
34
+ /** The number of visible tables */
35
+ get count(): number;
36
+ /**
37
+ * The table with the given key or undefined
38
+ * @param key - the table key
39
+ */
40
+ get(key: TableKey): TableType | undefined;
41
+ /**
42
+ * True if a table with the key exists, including internal tables
43
+ * @param key - the table key
44
+ */
45
+ has(key: TableKey): boolean;
46
+ /**
47
+ * The sorted keys of all tables with the given type, including internal
48
+ * @param type - the content type
49
+ */
50
+ ofType(type: ContentType): TableKey[];
51
+ /**
52
+ * The latest table config for the key, or undefined
53
+ * @param key - the table key
54
+ */
55
+ cfg(key: TableKey): TableCfg | undefined;
56
+ /**
57
+ * The number of rows of the table, 0 if it does not exist
58
+ * @param key - the table key
59
+ */
60
+ rowCount(key: TableKey): number;
61
+ private _keys;
62
+ private static _isTable;
63
+ }
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/rljson",
3
- "version": "0.0.84",
4
- "packageManager": "pnpm@11.10.0+sha512.0b7f8b98060031904c017e3a41eb187a16d40eeb829b95c4f8cb03681761fc4ab53dd219115b9b447f4dce1a05a214764461e7d3703392a9f32f9511ce8c86c8",
3
+ "version": "0.0.85",
5
4
  "description": "The RLJSON data format specification",
6
5
  "homepage": "https://github.com/rljson/rljson",
7
6
  "bugs": "https://github.com/rljson/rljson/issues",
@@ -20,37 +19,36 @@
20
19
  "dist"
21
20
  ],
22
21
  "type": "module",
23
- "scripts": {
24
- "build": "pnpm test && vite build && tsc && cp README* dist && mkdir dist/src && cp src/example.ts dist/src",
25
- "test": "vitest run --coverage && npm run lint",
26
- "prepublishOnly": "npm run build",
27
- "lint": "eslint",
28
- "updateGoldens": "cross-env UPDATE_GOLDENS=true npm test"
29
- },
30
22
  "devDependencies": {
31
- "@types/node": "^26.6.3",
32
- "@typescript-eslint/eslint-plugin": "^8.70.1",
33
- "@typescript-eslint/parser": "^8.70.1",
34
- "@vitest/coverage-v8": "^5.0.2",
23
+ "@types/node": "^26.6.4",
24
+ "@typescript-eslint/eslint-plugin": "^8.71.1",
25
+ "@typescript-eslint/parser": "^8.71.1",
26
+ "@vitest/coverage-v8": "^5.0.3",
35
27
  "cross-env": "^10.1.0",
36
- "eslint": "^10.11.0",
37
- "eslint-plugin-jsdoc": "^64.5.4",
38
- "eslint-plugin-tsdoc": "^0.5.3",
39
- "globals": "^17.12.0",
28
+ "eslint": "^10.12.0",
29
+ "eslint-plugin-jsdoc": "^65.2.0",
30
+ "eslint-plugin-tsdoc": "^0.5.4",
31
+ "globals": "^17.13.0",
40
32
  "jsdoc": "^4.0.5",
41
33
  "read-pkg": "^10.1.0",
42
34
  "typescript": "~6.0.3",
43
- "typescript-eslint": "^8.70.1",
44
- "vite": "^8.3.1",
35
+ "typescript-eslint": "^8.71.1",
36
+ "vite": "^8.3.4",
45
37
  "vite-node": "^6.0.0",
46
- "vite-plugin-dts": "^5.1.1",
38
+ "vite-plugin-dts": "^5.1.2",
47
39
  "vite-tsconfig-paths": "^6.1.1",
48
- "vitest": "^5.0.2",
40
+ "vitest": "^5.0.3",
49
41
  "vitest-dom": "^0.1.1"
50
42
  },
51
43
  "dependencies": {
52
44
  "@rljson/hash": "0.0.19",
53
45
  "@rljson/json": "0.0.23",
54
- "nanoid": "^6.0.1"
46
+ "nanoid": "^6.0.2"
47
+ },
48
+ "scripts": {
49
+ "build": "pnpm test && vite build && tsc && cp README* dist && mkdir dist/src && cp src/example.ts dist/src",
50
+ "test": "vitest run --coverage && npm run lint",
51
+ "lint": "eslint",
52
+ "updateGoldens": "cross-env UPDATE_GOLDENS=true npm test"
55
53
  }
56
- }
54
+ }