@rljson/io 0.0.6 → 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.
- package/README.contributors.md +32 -28
- package/dist/README.contributors.md +32 -28
- package/dist/index.d.ts +1 -0
- package/dist/io.js +162 -0
- package/package.json +4 -4
package/README.contributors.md
CHANGED
|
@@ -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
|
|
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="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
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,6 +139,29 @@ 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
|
|
@@ -166,7 +171,7 @@ Commit your changes
|
|
|
166
171
|
If you only have one thing, execute
|
|
167
172
|
|
|
168
173
|
```bash
|
|
169
|
-
git commit -
|
|
174
|
+
git add . && git commit -m "$MESSAGE"
|
|
170
175
|
```
|
|
171
176
|
|
|
172
177
|
### Update dependencies
|
|
@@ -175,7 +180,7 @@ We aim to work with the latest versions of our dependencies.
|
|
|
175
180
|
|
|
176
181
|
```bash
|
|
177
182
|
pnpm update --latest &&\
|
|
178
|
-
git commit -
|
|
183
|
+
git commit -m"Update dependencies"
|
|
179
184
|
```
|
|
180
185
|
|
|
181
186
|
### Increase version
|
|
@@ -190,8 +195,7 @@ git commit -am"Increase version"
|
|
|
190
195
|
```bash
|
|
191
196
|
git push -u origin $BRANCH && \
|
|
192
197
|
gh pr create --base main --title "$MESSAGE" --body "" && \
|
|
193
|
-
gh pr merge --auto --squash
|
|
194
|
-
|
|
198
|
+
gh pr merge --auto --squash
|
|
195
199
|
```
|
|
196
200
|
|
|
197
201
|
### Wait until PR is merged
|
|
@@ -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
|
|
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="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
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,6 +139,29 @@ 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
|
|
@@ -166,7 +171,7 @@ Commit your changes
|
|
|
166
171
|
If you only have one thing, execute
|
|
167
172
|
|
|
168
173
|
```bash
|
|
169
|
-
git commit -
|
|
174
|
+
git add . && git commit -m "$MESSAGE"
|
|
170
175
|
```
|
|
171
176
|
|
|
172
177
|
### Update dependencies
|
|
@@ -175,7 +180,7 @@ We aim to work with the latest versions of our dependencies.
|
|
|
175
180
|
|
|
176
181
|
```bash
|
|
177
182
|
pnpm update --latest &&\
|
|
178
|
-
git commit -
|
|
183
|
+
git commit -m"Update dependencies"
|
|
179
184
|
```
|
|
180
185
|
|
|
181
186
|
### Increase version
|
|
@@ -190,8 +195,7 @@ git commit -am"Increase version"
|
|
|
190
195
|
```bash
|
|
191
196
|
git push -u origin $BRANCH && \
|
|
192
197
|
gh pr create --base main --title "$MESSAGE" --body "" && \
|
|
193
|
-
gh pr merge --auto --squash
|
|
194
|
-
|
|
198
|
+
gh pr merge --auto --squash
|
|
195
199
|
```
|
|
196
200
|
|
|
197
201
|
### Wait until PR is merged
|
package/dist/index.d.ts
CHANGED
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
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rljson/io",
|
|
3
|
-
"version": "0.0.
|
|
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.
|
|
61
|
-
"@rljson/rljson": "^0.0.
|
|
62
|
-
"@rljson/validate": "^0.0.
|
|
60
|
+
"@rljson/json": "^0.0.9",
|
|
61
|
+
"@rljson/rljson": "^0.0.9",
|
|
62
|
+
"@rljson/validate": "^0.0.6"
|
|
63
63
|
}
|
|
64
64
|
}
|