@rljson/io 0.0.5 → 0.0.7

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.
@@ -17,11 +17,12 @@
17
17
  - [Install GitHub CLI](#install-github-cli)
18
18
  - [Develop](#develop)
19
19
  - [Read architecture doc](#read-architecture-doc)
20
- - [Checkout main](#checkout-main)
21
- - [Create a branch](#create-a-branch)
22
20
  - [Debug](#debug)
23
21
  - [Update goldens](#update-goldens)
24
22
  - [Test and Build](#test-and-build)
23
+ - [Workflow](#workflow)
24
+ - [Checkout main](#checkout-main)
25
+ - [Create a branch](#create-a-branch)
25
26
  - [Commit](#commit)
26
27
  - [Update dependencies](#update-dependencies)
27
28
  - [Increase version](#increase-version)
@@ -40,10 +41,10 @@
40
41
  ### Check out
41
42
 
42
43
  ```bash
43
- mkdir rljson
44
- cd rljson
45
- git clone https://github.com/rljson/io.git
44
+ mkdir io
46
45
  cd io
46
+ git clone https://github.com/rljson/io.git
47
+ cd db
47
48
  ```
48
49
 
49
50
  ### Install pnpm
@@ -108,25 +109,6 @@ gh auth login
108
109
  Read [README.architecture.md](./README.architecture.md) to get an overview
109
110
  of the package's architecture.
110
111
 
111
- ### Checkout main
112
-
113
- ```bash
114
- git checkout main && \
115
- git fetch && \
116
- git pull
117
- ```
118
-
119
- ### Create a branch
120
-
121
- Please replace `Commit Message` in the next command by your commit message.
122
- It will also used for branch name and pull request
123
-
124
- ```bash
125
- export MESSAGE="Take over code from old rljson-js lib" && \
126
- export BRANCH=`echo "$MESSAGE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]/_/g'` &&\
127
- git checkout -b $BRANCH
128
- ```
129
-
130
112
  ### Debug
131
113
 
132
114
  In Vscode: At the `left side bar` click on the `Test tube` icon to open the `Test explorer`.
@@ -157,14 +139,39 @@ pnpm test &&\
157
139
  pnpm build
158
140
  ```
159
141
 
142
+ <!-- ........................................................................-->
143
+
144
+ ## Workflow
145
+
146
+ ### Checkout main
147
+
148
+ ```bash
149
+ git checkout main && \
150
+ git fetch && \
151
+ git pull
152
+ ```
153
+
154
+ ### Create a branch
155
+
156
+ Please replace `Commit Message` in the next command by your commit message.
157
+ It will also used for branch name and pull request
158
+
159
+ ```bash
160
+ export MESSAGE="Update README.contributors.m" && \
161
+ export BRANCH=`echo "$MESSAGE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]/_/g'` &&\
162
+ git checkout -b $BRANCH
163
+ ```
164
+
160
165
  ### Commit
161
166
 
162
167
  Develop your feature
163
168
 
164
169
  Commit your changes
165
170
 
171
+ If you only have one thing, execute
172
+
166
173
  ```bash
167
- git commit -am"$MESSAGE"
174
+ git add . && git commit -m "$MESSAGE"
168
175
  ```
169
176
 
170
177
  ### Update dependencies
@@ -173,7 +180,7 @@ We aim to work with the latest versions of our dependencies.
173
180
 
174
181
  ```bash
175
182
  pnpm update --latest &&\
176
- git commit -am"Update dependencies"
183
+ git commit -m"Update dependencies"
177
184
  ```
178
185
 
179
186
  ### Increase version
@@ -196,11 +203,13 @@ gh pr merge --auto --squash
196
203
  Get the PR URL with the following command
197
204
 
198
205
  ```bash
199
- gh pr view --json url -q .url
206
+ echo -e "\033[34m$(gh pr view --json url | jq -r '.url')\033[0m"
207
+ echo "Wait until PR is closed ..." && \
208
+ until gh pr view --json closed | jq -e '.closed == true' >/dev/null; do
209
+ sleep 2 >/dev/null;
210
+ done;
200
211
  ```
201
212
 
202
- Visit it
203
-
204
213
  ### Delete feature branch
205
214
 
206
215
  ```bash
@@ -17,11 +17,12 @@
17
17
  - [Install GitHub CLI](#install-github-cli)
18
18
  - [Develop](#develop)
19
19
  - [Read architecture doc](#read-architecture-doc)
20
- - [Checkout main](#checkout-main)
21
- - [Create a branch](#create-a-branch)
22
20
  - [Debug](#debug)
23
21
  - [Update goldens](#update-goldens)
24
22
  - [Test and Build](#test-and-build)
23
+ - [Workflow](#workflow)
24
+ - [Checkout main](#checkout-main)
25
+ - [Create a branch](#create-a-branch)
25
26
  - [Commit](#commit)
26
27
  - [Update dependencies](#update-dependencies)
27
28
  - [Increase version](#increase-version)
@@ -40,10 +41,10 @@
40
41
  ### Check out
41
42
 
42
43
  ```bash
43
- mkdir rljson
44
- cd rljson
45
- git clone https://github.com/rljson/io.git
44
+ mkdir io
46
45
  cd io
46
+ git clone https://github.com/rljson/io.git
47
+ cd db
47
48
  ```
48
49
 
49
50
  ### Install pnpm
@@ -108,25 +109,6 @@ gh auth login
108
109
  Read [README.architecture.md](./README.architecture.md) to get an overview
109
110
  of the package's architecture.
110
111
 
111
- ### Checkout main
112
-
113
- ```bash
114
- git checkout main && \
115
- git fetch && \
116
- git pull
117
- ```
118
-
119
- ### Create a branch
120
-
121
- Please replace `Commit Message` in the next command by your commit message.
122
- It will also used for branch name and pull request
123
-
124
- ```bash
125
- export MESSAGE="Take over code from old rljson-js lib" && \
126
- export BRANCH=`echo "$MESSAGE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]/_/g'` &&\
127
- git checkout -b $BRANCH
128
- ```
129
-
130
112
  ### Debug
131
113
 
132
114
  In Vscode: At the `left side bar` click on the `Test tube` icon to open the `Test explorer`.
@@ -157,14 +139,39 @@ pnpm test &&\
157
139
  pnpm build
158
140
  ```
159
141
 
142
+ <!-- ........................................................................-->
143
+
144
+ ## Workflow
145
+
146
+ ### Checkout main
147
+
148
+ ```bash
149
+ git checkout main && \
150
+ git fetch && \
151
+ git pull
152
+ ```
153
+
154
+ ### Create a branch
155
+
156
+ Please replace `Commit Message` in the next command by your commit message.
157
+ It will also used for branch name and pull request
158
+
159
+ ```bash
160
+ export MESSAGE="Update README.contributors.m" && \
161
+ export BRANCH=`echo "$MESSAGE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]/_/g'` &&\
162
+ git checkout -b $BRANCH
163
+ ```
164
+
160
165
  ### Commit
161
166
 
162
167
  Develop your feature
163
168
 
164
169
  Commit your changes
165
170
 
171
+ If you only have one thing, execute
172
+
166
173
  ```bash
167
- git commit -am"$MESSAGE"
174
+ git add . && git commit -m "$MESSAGE"
168
175
  ```
169
176
 
170
177
  ### Update dependencies
@@ -173,7 +180,7 @@ We aim to work with the latest versions of our dependencies.
173
180
 
174
181
  ```bash
175
182
  pnpm update --latest &&\
176
- git commit -am"Update dependencies"
183
+ git commit -m"Update dependencies"
177
184
  ```
178
185
 
179
186
  ### Increase version
@@ -196,11 +203,13 @@ gh pr merge --auto --squash
196
203
  Get the PR URL with the following command
197
204
 
198
205
  ```bash
199
- gh pr view --json url -q .url
206
+ echo -e "\033[34m$(gh pr view --json url | jq -r '.url')\033[0m"
207
+ echo "Wait until PR is closed ..." && \
208
+ until gh pr view --json closed | jq -e '.closed == true' >/dev/null; do
209
+ sleep 2 >/dev/null;
210
+ done;
200
211
  ```
201
212
 
202
- Visit it
203
-
204
213
  ### Delete feature branch
205
214
 
206
215
  ```bash
package/dist/example.d.ts CHANGED
@@ -1,4 +1 @@
1
- /**
2
- * The example function demonstrates how the package works
3
- */
4
- export declare const example: () => void;
1
+ export declare const example: () => Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
+ export * from './io-mem.ts';
1
2
  export * from './io.ts';
@@ -0,0 +1,39 @@
1
+ import { JsonValue } from '@rljson/json';
2
+ import { ContentType, Rljson } from '@rljson/rljson';
3
+ import { Io } from './io.ts';
4
+ /**
5
+ * In-Memory implementation of the Rljson Io interface.
6
+ */
7
+ export declare class IoMem implements Io {
8
+ static example: () => IoMem;
9
+ isReady(): Promise<void>;
10
+ dump(): Promise<Rljson>;
11
+ dumpTable(request: {
12
+ name: string;
13
+ }): Promise<Rljson>;
14
+ readRow(request: {
15
+ table: string;
16
+ rowHash: string;
17
+ }): Promise<Rljson>;
18
+ readRows(request: {
19
+ table: string;
20
+ where: {
21
+ [column: string]: JsonValue;
22
+ };
23
+ }): Promise<Rljson>;
24
+ write(request: {
25
+ data: Rljson;
26
+ }): Promise<void>;
27
+ createTable(request: {
28
+ name: string;
29
+ type: ContentType;
30
+ }): Promise<void>;
31
+ tables(): Promise<string[]>;
32
+ private _mem;
33
+ private _createTable;
34
+ private _readRow;
35
+ private _dump;
36
+ private _dumpTable;
37
+ private _write;
38
+ private _readRows;
39
+ }
package/dist/io.d.ts CHANGED
@@ -5,6 +5,10 @@ export interface Io {
5
5
  isReady(): Promise<void>;
6
6
  /** Returns the complete db content as Rljson */
7
7
  dump(): Promise<Rljson>;
8
+ /** Returns the dump of a complete table */
9
+ dumpTable(request: {
10
+ name: string;
11
+ }): Promise<Rljson>;
8
12
  /** Creates a table with a given type */
9
13
  createTable(request: {
10
14
  name: string;
package/dist/io.js CHANGED
@@ -1,5 +1,167 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { hip, hsh } from "@rljson/hash";
5
+ import { copy, equals } from "@rljson/json";
6
+ // @license
7
+ const _IoMem = class _IoMem {
8
+ constructor() {
9
+ // ######################
10
+ // Private
11
+ // ######################
12
+ __publicField(this, "_mem", hip({}));
13
+ }
14
+ // ...........................................................................
15
+ // General
16
+ isReady() {
17
+ return Promise.resolve();
18
+ }
19
+ // ...........................................................................
20
+ // Dump
21
+ dump() {
22
+ return this._dump();
23
+ }
24
+ async dumpTable(request) {
25
+ return this._dumpTable(request);
26
+ }
27
+ // ...........................................................................
28
+ // Rows
29
+ readRow(request) {
30
+ return this._readRow(request);
31
+ }
32
+ readRows(request) {
33
+ return this._readRows(request);
34
+ }
35
+ // ...........................................................................
36
+ // Write
37
+ write(request) {
38
+ return this._write(request);
39
+ }
40
+ // ...........................................................................
41
+ // Table management
42
+ createTable(request) {
43
+ return this._createTable(request);
44
+ }
45
+ async tables() {
46
+ const keys = Object.keys(this._mem);
47
+ const tables = keys.filter((key) => !key.startsWith("_"));
48
+ return tables;
49
+ }
50
+ // ...........................................................................
51
+ async _createTable(request) {
52
+ var _a;
53
+ const { name, type } = request;
54
+ const existing = this._mem[name];
55
+ if (existing) {
56
+ if (existing._type !== type) {
57
+ throw new Error(
58
+ `Table ${name} already exists with different type: "${existing._type}" vs "${request.type}"`
59
+ );
60
+ }
61
+ } else {
62
+ (_a = this._mem)[name] ?? (_a[name] = {
63
+ _data: [],
64
+ _type: type
65
+ });
66
+ }
67
+ }
68
+ // ...........................................................................
69
+ async _readRow(request) {
70
+ const table = this._mem[request.table];
71
+ if (!table) {
72
+ throw new Error(`Table ${request.table} not found`);
73
+ }
74
+ const row = table._data.find((row2) => row2._hash === request.rowHash);
75
+ if (!row) {
76
+ throw new Error(
77
+ `Row "${request.rowHash}" not found in table ${request.table}`
78
+ );
79
+ }
80
+ const result = {
81
+ [request.table]: {
82
+ _data: [row]
83
+ }
84
+ };
85
+ return result;
86
+ }
87
+ // ...........................................................................
88
+ async _dump() {
89
+ return copy(this._mem);
90
+ }
91
+ // ...........................................................................
92
+ async _dumpTable(request) {
93
+ const table = this._mem[request.name];
94
+ if (!table) {
95
+ throw new Error(`Table ${request.name} not found`);
96
+ }
97
+ return {
98
+ [request.name]: copy(table)
99
+ };
100
+ }
101
+ // ...........................................................................
102
+ async _write(request) {
103
+ const addedData = hsh(request.data);
104
+ const tables = Object.keys(addedData);
105
+ for (const table of tables) {
106
+ if (table.startsWith("_")) {
107
+ continue;
108
+ } else {
109
+ if (!this._mem[table]) {
110
+ throw new Error(`Table ${table} does not exist`);
111
+ }
112
+ }
113
+ const oldTable = this._mem[table];
114
+ const newTable = addedData[table];
115
+ if (oldTable._type !== newTable._type) {
116
+ throw new Error(
117
+ `Table ${table} has different types: "${oldTable._type}" vs "${newTable._type}"`
118
+ );
119
+ }
120
+ for (const item of newTable._data) {
121
+ const hash = item._hash;
122
+ const exists = oldTable._data.find((i) => i._hash === hash);
123
+ if (!exists) {
124
+ oldTable._data.push(item);
125
+ }
126
+ }
127
+ }
128
+ this._mem._hash = "";
129
+ const updateExistingHashes = false;
130
+ const throwIfOnWrongHashes = false;
131
+ hip(this._mem, updateExistingHashes, throwIfOnWrongHashes);
132
+ }
133
+ // ...........................................................................
134
+ async _readRows(request) {
135
+ const table = this._mem[request.table];
136
+ if (!table) {
137
+ throw new Error(`Table ${request.table} not found`);
138
+ }
139
+ const result = {
140
+ [request.table]: {
141
+ _data: table._data.filter((row) => {
142
+ for (const column in request.where) {
143
+ const a = row[column];
144
+ const b = request.where[column];
145
+ if (!equals(a, b)) {
146
+ return false;
147
+ }
148
+ }
149
+ return true;
150
+ })
151
+ }
152
+ };
153
+ return result;
154
+ }
155
+ };
156
+ // ...........................................................................
157
+ // Constructor & example
158
+ __publicField(_IoMem, "example", () => {
159
+ return new _IoMem();
160
+ });
161
+ let IoMem = _IoMem;
1
162
  // @license
2
163
  const exampleIo = "Checkout @rljson/io-mem for an example implementation";
3
164
  export {
165
+ IoMem,
4
166
  exampleIo
5
167
  };
@@ -4,9 +4,39 @@
4
4
  // Use of this source code is governed by terms that can be
5
5
  // found in the LICENSE file in the root of this package.
6
6
 
7
- /**
8
- * The example function demonstrates how the package works
9
- */
10
- export const example = () => {
11
- console.log('exampleIo');
7
+ import { hsh } from '@rljson/hash';
8
+ import { Rljson } from '@rljson/rljson';
9
+
10
+ import { IoMem } from './io-mem.ts';
11
+
12
+ // Run »pnpm updateGoldens« when you change this file
13
+ export const example = async () => {
14
+ const ioMem = new IoMem();
15
+
16
+ const row = { keyA2: 'a2' };
17
+ const rowWithHash = hsh(row);
18
+
19
+ // Create a table first
20
+ await ioMem.createTable({ name: 'tableA', type: 'properties' });
21
+
22
+ // Write data into the table
23
+ await ioMem.write({
24
+ data: {
25
+ tableA: {
26
+ _type: 'properties',
27
+ _data: [row],
28
+ },
29
+ },
30
+ });
31
+
32
+ // Read data from the table
33
+ const data: Rljson = await ioMem.readRow({
34
+ table: 'tableA',
35
+ rowHash: rowWithHash._hash,
36
+ });
37
+
38
+ // Print the return rljson data
39
+ console.log(JSON.stringify(data, null, 2));
12
40
  };
41
+
42
+ // example();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/io",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "packageManager": "pnpm@10.6.2",
5
5
  "description": "Low level interface for reading and writing RLJSON data",
6
6
  "homepage": "https://github.com/rljson/io",
@@ -57,8 +57,8 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@rljson/hash": "^0.0.10",
60
- "@rljson/json": "^0.0.8",
61
- "@rljson/rljson": "^0.0.7",
62
- "@rljson/validate": "^0.0.5"
60
+ "@rljson/json": "^0.0.9",
61
+ "@rljson/rljson": "^0.0.9",
62
+ "@rljson/validate": "^0.0.6"
63
63
  }
64
64
  }