@rljson/io 0.0.6 → 0.0.8

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.
@@ -1,240 +1,32 @@
1
1
  <!--
2
- // @license
3
- // Copyright (c) 2025 Rljson
4
- //
5
- // Use of this source code is governed by terms that can be
6
- // found in the LICENSE file in the root of this package.
2
+ @license
3
+ Copyright (c) 2025 Rljson
4
+
5
+ Use of this source code is governed by terms that can be
6
+ found in the LICENSE file in the root of this package.
7
7
  -->
8
8
 
9
9
  # Contributors Guide
10
10
 
11
- - [Install](#install)
12
- - [Check out](#check-out)
13
- - [Install pnpm](#install-pnpm)
14
- - [Install dependencies](#install-dependencies)
15
- - [Install Vscode extensions](#install-vscode-extensions)
16
- - [Uninstall Jest and Jasmine](#uninstall-jest-and-jasmine)
17
- - [Install GitHub CLI](#install-github-cli)
11
+ - [Prepare](#prepare)
18
12
  - [Develop](#develop)
19
- - [Read architecture doc](#read-architecture-doc)
20
- - [Checkout main](#checkout-main)
21
- - [Create a branch](#create-a-branch)
22
- - [Debug](#debug)
23
- - [Update goldens](#update-goldens)
24
- - [Test and Build](#test-and-build)
25
- - [Commit](#commit)
26
- - [Update dependencies](#update-dependencies)
27
- - [Increase version](#increase-version)
28
- - [Create a pull request](#create-a-pull-request)
29
- - [Wait until PR is merged](#wait-until-pr-is-merged)
30
- - [Delete feature branch](#delete-feature-branch)
31
- - [Publish to NPM](#publish-to-npm)
32
- - [Troubleshooting](#troubleshooting)
33
- - [Checkout README.trouble.md](#checkout-readmetroublemd)
34
- - [File issues on GitHub](#file-issues-on-github)
35
-
36
- <!-- ........................................................................-->
37
-
38
- ## Install
39
-
40
- ### Check out
41
-
42
- ```bash
43
- mkdir rljson
44
- cd rljson
45
- git clone https://github.com/rljson/io.git
46
- cd io
47
- ```
48
-
49
- ### Install pnpm
50
-
51
- Windows:
52
-
53
- ```bash
54
- corepack enable pnpm
55
- ```
56
-
57
- Mac:
58
-
59
- ```bash
60
- sudo corepack enable pnpm
61
- ```
62
-
63
- ### Install dependencies
64
-
65
- ```bash
66
- pnpm install
67
- ```
68
-
69
- ### Install Vscode extensions
70
-
71
- Open this project in `vscode`.
72
-
73
- Press `Cmd+Shift+P`.
74
-
75
- Type `Extensions: Show Recommended Extensions` and press `Enter`.
13
+ - [Tools](#tools)
14
+ - [Superheros](#superheros)
76
15
 
77
- The recommended extensions will be shown.
16
+ ## Prepare
78
17
 
79
- Make sure, all recommended extensions are shown.
80
-
81
- ### Uninstall Jest and Jasmine
82
-
83
- Jest or Jasmine extensions conflict with the `Vitest` extension used for this
84
- project.
85
-
86
- Uninstall them, if you have installed them.
87
-
88
- ### Install GitHub CLI
89
-
90
- Install GitHub CLI on Mac
91
-
92
- ```bash
93
- brew install gh
94
- ```
95
-
96
- Login
97
-
98
- ```bash
99
- gh auth login
100
- ```
18
+ Read [prepare.md](doc/workflows/prepare.md)
101
19
 
102
20
  <!-- ........................................................................-->
103
21
 
104
22
  ## Develop
105
23
 
106
- ### Read architecture doc
107
-
108
- Read [README.architecture.md](./README.architecture.md) to get an overview
109
- of the package's architecture.
110
-
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="Add IoMem and dump table" && \
126
- export BRANCH=`echo "$MESSAGE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]/_/g'` &&\
127
- git checkout -b $BRANCH
128
- ```
129
-
130
- ### Debug
131
-
132
- In Vscode: At the `left side bar` click on the `Test tube` icon to open the `Test explorer`.
133
-
134
- At the `top`, click on the `refresh` icon to show update the tests.
135
-
136
- Open a test file (`*.spec.ts`)
137
-
138
- Set a breakpoint.
139
-
140
- Press `alt` and click on the play button left beside the test.
141
-
142
- Execution should stop at the breakpoint.
143
-
144
- ### Update goldens
145
-
146
- In various tests we are creating golden files, that are reference files that
147
- are compared against the files created in the tests.
148
-
149
- ```bash
150
- pnpm updateGoldens
151
- ```
152
-
153
- ### Test and Build
154
-
155
- ```bash
156
- pnpm test &&\
157
- pnpm build
158
- ```
159
-
160
- ### Commit
161
-
162
- Develop your feature
163
-
164
- Commit your changes
165
-
166
- If you only have one thing, execute
167
-
168
- ```bash
169
- git commit -am"$MESSAGE"
170
- ```
171
-
172
- ### Update dependencies
173
-
174
- We aim to work with the latest versions of our dependencies.
175
-
176
- ```bash
177
- pnpm update --latest &&\
178
- git commit -am"Update dependencies"
179
- ```
180
-
181
- ### Increase version
182
-
183
- ```bash
184
- pnpm version patch --no-git-tag-version && \
185
- git commit -am"Increase version"
186
- ```
187
-
188
- ### Create a pull request
189
-
190
- ```bash
191
- git push -u origin $BRANCH && \
192
- gh pr create --base main --title "$MESSAGE" --body "" && \
193
- gh pr merge --auto --squash && \
194
-
195
- ```
196
-
197
- ### Wait until PR is merged
198
-
199
- Get the PR URL with the following command
200
-
201
- ```bash
202
- echo -e "\033[34m$(gh pr view --json url | jq -r '.url')\033[0m"
203
- echo "Wait until PR is closed ..." && \
204
- until gh pr view --json closed | jq -e '.closed == true' >/dev/null; do
205
- sleep 2 >/dev/null;
206
- done;
207
- ```
208
-
209
- ### Delete feature branch
210
-
211
- ```bash
212
- git fetch && git checkout main && \
213
- git reset --soft origin/main && \
214
- git stash -m"PR Aftermath" && \
215
- git pull && \
216
- git branch -d $BRANCH
217
- ```
218
-
219
- ### Publish to NPM
220
-
221
- ```bash
222
- npm publish --access public && \
223
- git tag $(npm pkg get version | tr -d '\\"')
224
- ```
225
-
226
- <!-- ........................................................................-->
227
-
228
- ## Troubleshooting
229
-
230
- ### Checkout README.trouble.md
231
-
232
- Checkout [./README.trouble.md](./README.trouble.md)
24
+ Read [develop.md](doc/workflows/develop.md)
233
25
 
234
- ### File issues on GitHub
26
+ ## Tools
235
27
 
236
- Visit <https://github.com/rljson/io/issues>
28
+ Read [tools.md](doc/workflows/tools.md)
237
29
 
238
- Check if there is already an issue for your problem.
30
+ ## Superheros
239
31
 
240
- If no, report the issue.
32
+ Read [super-hero.md](doc/workflows/super-hero.md)
@@ -1,240 +1,32 @@
1
1
  <!--
2
- // @license
3
- // Copyright (c) 2025 Rljson
4
- //
5
- // Use of this source code is governed by terms that can be
6
- // found in the LICENSE file in the root of this package.
2
+ @license
3
+ Copyright (c) 2025 Rljson
4
+
5
+ Use of this source code is governed by terms that can be
6
+ found in the LICENSE file in the root of this package.
7
7
  -->
8
8
 
9
9
  # Contributors Guide
10
10
 
11
- - [Install](#install)
12
- - [Check out](#check-out)
13
- - [Install pnpm](#install-pnpm)
14
- - [Install dependencies](#install-dependencies)
15
- - [Install Vscode extensions](#install-vscode-extensions)
16
- - [Uninstall Jest and Jasmine](#uninstall-jest-and-jasmine)
17
- - [Install GitHub CLI](#install-github-cli)
11
+ - [Prepare](#prepare)
18
12
  - [Develop](#develop)
19
- - [Read architecture doc](#read-architecture-doc)
20
- - [Checkout main](#checkout-main)
21
- - [Create a branch](#create-a-branch)
22
- - [Debug](#debug)
23
- - [Update goldens](#update-goldens)
24
- - [Test and Build](#test-and-build)
25
- - [Commit](#commit)
26
- - [Update dependencies](#update-dependencies)
27
- - [Increase version](#increase-version)
28
- - [Create a pull request](#create-a-pull-request)
29
- - [Wait until PR is merged](#wait-until-pr-is-merged)
30
- - [Delete feature branch](#delete-feature-branch)
31
- - [Publish to NPM](#publish-to-npm)
32
- - [Troubleshooting](#troubleshooting)
33
- - [Checkout README.trouble.md](#checkout-readmetroublemd)
34
- - [File issues on GitHub](#file-issues-on-github)
35
-
36
- <!-- ........................................................................-->
37
-
38
- ## Install
39
-
40
- ### Check out
41
-
42
- ```bash
43
- mkdir rljson
44
- cd rljson
45
- git clone https://github.com/rljson/io.git
46
- cd io
47
- ```
48
-
49
- ### Install pnpm
50
-
51
- Windows:
52
-
53
- ```bash
54
- corepack enable pnpm
55
- ```
56
-
57
- Mac:
58
-
59
- ```bash
60
- sudo corepack enable pnpm
61
- ```
62
-
63
- ### Install dependencies
64
-
65
- ```bash
66
- pnpm install
67
- ```
68
-
69
- ### Install Vscode extensions
70
-
71
- Open this project in `vscode`.
72
-
73
- Press `Cmd+Shift+P`.
74
-
75
- Type `Extensions: Show Recommended Extensions` and press `Enter`.
13
+ - [Tools](#tools)
14
+ - [Superheros](#superheros)
76
15
 
77
- The recommended extensions will be shown.
16
+ ## Prepare
78
17
 
79
- Make sure, all recommended extensions are shown.
80
-
81
- ### Uninstall Jest and Jasmine
82
-
83
- Jest or Jasmine extensions conflict with the `Vitest` extension used for this
84
- project.
85
-
86
- Uninstall them, if you have installed them.
87
-
88
- ### Install GitHub CLI
89
-
90
- Install GitHub CLI on Mac
91
-
92
- ```bash
93
- brew install gh
94
- ```
95
-
96
- Login
97
-
98
- ```bash
99
- gh auth login
100
- ```
18
+ Read [prepare.md](doc/workflows/prepare.md)
101
19
 
102
20
  <!-- ........................................................................-->
103
21
 
104
22
  ## Develop
105
23
 
106
- ### Read architecture doc
107
-
108
- Read [README.architecture.md](./README.architecture.md) to get an overview
109
- of the package's architecture.
110
-
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="Add IoMem and dump table" && \
126
- export BRANCH=`echo "$MESSAGE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]/_/g'` &&\
127
- git checkout -b $BRANCH
128
- ```
129
-
130
- ### Debug
131
-
132
- In Vscode: At the `left side bar` click on the `Test tube` icon to open the `Test explorer`.
133
-
134
- At the `top`, click on the `refresh` icon to show update the tests.
135
-
136
- Open a test file (`*.spec.ts`)
137
-
138
- Set a breakpoint.
139
-
140
- Press `alt` and click on the play button left beside the test.
141
-
142
- Execution should stop at the breakpoint.
143
-
144
- ### Update goldens
145
-
146
- In various tests we are creating golden files, that are reference files that
147
- are compared against the files created in the tests.
148
-
149
- ```bash
150
- pnpm updateGoldens
151
- ```
152
-
153
- ### Test and Build
154
-
155
- ```bash
156
- pnpm test &&\
157
- pnpm build
158
- ```
159
-
160
- ### Commit
161
-
162
- Develop your feature
163
-
164
- Commit your changes
165
-
166
- If you only have one thing, execute
167
-
168
- ```bash
169
- git commit -am"$MESSAGE"
170
- ```
171
-
172
- ### Update dependencies
173
-
174
- We aim to work with the latest versions of our dependencies.
175
-
176
- ```bash
177
- pnpm update --latest &&\
178
- git commit -am"Update dependencies"
179
- ```
180
-
181
- ### Increase version
182
-
183
- ```bash
184
- pnpm version patch --no-git-tag-version && \
185
- git commit -am"Increase version"
186
- ```
187
-
188
- ### Create a pull request
189
-
190
- ```bash
191
- git push -u origin $BRANCH && \
192
- gh pr create --base main --title "$MESSAGE" --body "" && \
193
- gh pr merge --auto --squash && \
194
-
195
- ```
196
-
197
- ### Wait until PR is merged
198
-
199
- Get the PR URL with the following command
200
-
201
- ```bash
202
- echo -e "\033[34m$(gh pr view --json url | jq -r '.url')\033[0m"
203
- echo "Wait until PR is closed ..." && \
204
- until gh pr view --json closed | jq -e '.closed == true' >/dev/null; do
205
- sleep 2 >/dev/null;
206
- done;
207
- ```
208
-
209
- ### Delete feature branch
210
-
211
- ```bash
212
- git fetch && git checkout main && \
213
- git reset --soft origin/main && \
214
- git stash -m"PR Aftermath" && \
215
- git pull && \
216
- git branch -d $BRANCH
217
- ```
218
-
219
- ### Publish to NPM
220
-
221
- ```bash
222
- npm publish --access public && \
223
- git tag $(npm pkg get version | tr -d '\\"')
224
- ```
225
-
226
- <!-- ........................................................................-->
227
-
228
- ## Troubleshooting
229
-
230
- ### Checkout README.trouble.md
231
-
232
- Checkout [./README.trouble.md](./README.trouble.md)
24
+ Read [develop.md](doc/workflows/develop.md)
233
25
 
234
- ### File issues on GitHub
26
+ ## Tools
235
27
 
236
- Visit <https://github.com/rljson/io/issues>
28
+ Read [tools.md](doc/workflows/tools.md)
237
29
 
238
- Check if there is already an issue for your problem.
30
+ ## Superheros
239
31
 
240
- If no, report the issue.
32
+ Read [super-hero.md](doc/workflows/super-hero.md)
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
+ export * from './io-mem.ts';
1
2
  export * from './io.ts';
package/dist/io.js CHANGED
@@ -1,5 +1,168 @@
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
+ const table = hip({
63
+ _data: [],
64
+ _type: type
65
+ });
66
+ (_a = this._mem)[name] ?? (_a[name] = table);
67
+ }
68
+ }
69
+ // ...........................................................................
70
+ async _readRow(request) {
71
+ const table = this._mem[request.table];
72
+ if (!table) {
73
+ throw new Error(`Table ${request.table} not found`);
74
+ }
75
+ const row = table._data.find((row2) => row2._hash === request.rowHash);
76
+ if (!row) {
77
+ throw new Error(
78
+ `Row "${request.rowHash}" not found in table ${request.table}`
79
+ );
80
+ }
81
+ const result = {
82
+ [request.table]: {
83
+ _data: [row]
84
+ }
85
+ };
86
+ return result;
87
+ }
88
+ // ...........................................................................
89
+ async _dump() {
90
+ return copy(this._mem);
91
+ }
92
+ // ...........................................................................
93
+ async _dumpTable(request) {
94
+ const table = this._mem[request.name];
95
+ if (!table) {
96
+ throw new Error(`Table ${request.name} not found`);
97
+ }
98
+ return {
99
+ [request.name]: copy(table)
100
+ };
101
+ }
102
+ // ...........................................................................
103
+ async _write(request) {
104
+ const addedData = hsh(request.data);
105
+ const tables = Object.keys(addedData);
106
+ for (const table of tables) {
107
+ if (table.startsWith("_")) {
108
+ continue;
109
+ } else {
110
+ if (!this._mem[table]) {
111
+ throw new Error(`Table ${table} does not exist`);
112
+ }
113
+ }
114
+ const oldTable = this._mem[table];
115
+ const newTable = addedData[table];
116
+ if (oldTable._type !== newTable._type) {
117
+ throw new Error(
118
+ `Table ${table} has different types: "${oldTable._type}" vs "${newTable._type}"`
119
+ );
120
+ }
121
+ for (const item of newTable._data) {
122
+ const hash = item._hash;
123
+ const exists = oldTable._data.find((i) => i._hash === hash);
124
+ if (!exists) {
125
+ oldTable._data.push(item);
126
+ }
127
+ }
128
+ }
129
+ this._mem._hash = "";
130
+ const updateExistingHashes = false;
131
+ const throwIfOnWrongHashes = false;
132
+ hip(this._mem, updateExistingHashes, throwIfOnWrongHashes);
133
+ }
134
+ // ...........................................................................
135
+ async _readRows(request) {
136
+ const table = this._mem[request.table];
137
+ if (!table) {
138
+ throw new Error(`Table ${request.table} not found`);
139
+ }
140
+ const result = {
141
+ [request.table]: {
142
+ _data: table._data.filter((row) => {
143
+ for (const column in request.where) {
144
+ const a = row[column];
145
+ const b = request.where[column];
146
+ if (!equals(a, b)) {
147
+ return false;
148
+ }
149
+ }
150
+ return true;
151
+ })
152
+ }
153
+ };
154
+ return result;
155
+ }
156
+ };
157
+ // ...........................................................................
158
+ // Constructor & example
159
+ __publicField(_IoMem, "example", () => {
160
+ return new _IoMem();
161
+ });
162
+ let IoMem = _IoMem;
1
163
  // @license
2
164
  const exampleIo = "Checkout @rljson/io-mem for an example implementation";
3
165
  export {
166
+ IoMem,
4
167
  exampleIo
5
168
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/io",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
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",
@@ -29,24 +29,24 @@
29
29
  "updateGoldens": "cross-env UPDATE_GOLDENS=true npm test"
30
30
  },
31
31
  "devDependencies": {
32
- "@types/node": "^22.13.10",
33
- "@typescript-eslint/eslint-plugin": "^8.26.1",
34
- "@typescript-eslint/parser": "^8.26.1",
35
- "@vitest/coverage-v8": "^3.0.8",
32
+ "@types/node": "^22.13.11",
33
+ "@typescript-eslint/eslint-plugin": "^8.27.0",
34
+ "@typescript-eslint/parser": "^8.27.0",
35
+ "@vitest/coverage-v8": "^3.0.9",
36
36
  "cross-env": "^7.0.3",
37
37
  "eslint": "^9.22.0",
38
- "eslint-plugin-jsdoc": "^50.6.6",
38
+ "eslint-plugin-jsdoc": "^50.6.8",
39
39
  "eslint-plugin-tsdoc": "^0.4.0",
40
40
  "globals": "^16.0.0",
41
41
  "jsdoc": "^4.0.4",
42
42
  "read-pkg": "^9.0.1",
43
43
  "typescript": "~5.8.2",
44
- "typescript-eslint": "^8.26.1",
45
- "vite": "^6.2.1",
46
- "vite-node": "^3.0.8",
44
+ "typescript-eslint": "^8.27.0",
45
+ "vite": "^6.2.2",
46
+ "vite-node": "^3.0.9",
47
47
  "vite-plugin-dts": "^4.5.3",
48
48
  "vite-tsconfig-paths": "^5.1.4",
49
- "vitest": "^3.0.8",
49
+ "vitest": "^3.0.9",
50
50
  "vitest-dom": "^0.1.1"
51
51
  },
52
52
  "pnpm": {
@@ -56,9 +56,9 @@
56
56
  "overrides": {}
57
57
  },
58
58
  "dependencies": {
59
- "@rljson/hash": "^0.0.10",
60
- "@rljson/json": "^0.0.8",
61
- "@rljson/rljson": "^0.0.7",
62
- "@rljson/validate": "^0.0.5"
59
+ "@rljson/hash": "^0.0.12",
60
+ "@rljson/json": "^0.0.18",
61
+ "@rljson/rljson": "^0.0.19",
62
+ "@rljson/validate": "^0.0.8"
63
63
  }
64
64
  }