@rljson/rljson 0.0.11 → 0.0.14

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,15 +1,15 @@
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
11
  - [Install](#install)
12
- - [Check out](#check-out)
12
+ - [Checkout](#checkout)
13
13
  - [Install pnpm](#install-pnpm)
14
14
  - [Install dependencies](#install-dependencies)
15
15
  - [Install Vscode extensions](#install-vscode-extensions)
@@ -20,13 +20,16 @@
20
20
  - [Debug](#debug)
21
21
  - [Update goldens](#update-goldens)
22
22
  - [Test and Build](#test-and-build)
23
+ - [Rename classes](#rename-classes)
23
24
  - [Workflow](#workflow)
25
+ - [Set a PR title](#set-a-pr-title)
24
26
  - [Checkout main](#checkout-main)
25
- - [Create a branch](#create-a-branch)
26
- - [Commit](#commit)
27
+ - [Create a feature branch](#create-a-feature-branch)
27
28
  - [Update dependencies](#update-dependencies)
29
+ - [Debug and develop](#debug-and-develop)
30
+ - [Commit](#commit)
28
31
  - [Increase version](#increase-version)
29
- - [Push the branch](#push-the-branch)
32
+ - [Build](#build)
30
33
  - [Create a pull request](#create-a-pull-request)
31
34
  - [Wait until PR is merged](#wait-until-pr-is-merged)
32
35
  - [Delete feature branch](#delete-feature-branch)
@@ -39,13 +42,13 @@
39
42
 
40
43
  ## Install
41
44
 
42
- ### Check out
45
+ ### Checkout
43
46
 
44
47
  ```bash
45
48
  mkdir rljson
46
49
  cd rljson
47
50
  git clone https://github.com/rljson/rljson.git
48
- cd io
51
+ cd rljson
49
52
  ```
50
53
 
51
54
  ### Install pnpm
@@ -136,102 +139,156 @@ pnpm updateGoldens
136
139
  ### Test and Build
137
140
 
138
141
  ```bash
139
- pnpm test &&\
142
+ pnpm test
140
143
  pnpm build
141
144
  ```
142
145
 
146
+ ### Rename classes
147
+
148
+ Replace `ClassA` by `ClassB` in the following script and run it:
149
+
150
+ ```bash
151
+ export CLASS_A="ColumnSelection"
152
+ export CLASS_B="ColumnsConfig"
153
+
154
+ to_snake_case() {
155
+ echo "$1" | sed -E 's/([a-z0-9])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]'
156
+ }
157
+
158
+ to_lower_first() {
159
+ first_char=$(echo "$1" | cut -c1 | tr '[:upper:]' '[:lower:]')
160
+ rest_chars=$(echo "$1" | cut -c2-)
161
+ echo "$first_char$rest_chars"
162
+ }
163
+
164
+ export LOWER_CLASS_A=$(to_lower_first "$CLASS_A")
165
+ export LOWER_CLASS_B=$(to_lower_first "$CLASS_B")
166
+ export SNAKE_CLASS_A=$(to_snake_case "$CLASS_A")
167
+ export SNAKE_CLASS_B=$(to_snake_case "$CLASS_B")
168
+
169
+ find . -type f \( -name "*.ts" -o -name "*.md" -o -name "package.json" \) -not -path "./node_modules/*" \
170
+ -exec sed -i '' "s/$CLASS_A/$CLASS_B/g" {} +
171
+
172
+ find . -type f \( -name "*.ts" -o -name "*.md" -o -name "package.json" \) -not -path "./node_modules/*" \
173
+ -exec sed -i '' "s/$LOWER_CLASS_A/$LOWER_CLASS_B/g" {} +
174
+
175
+ find . -type f \( -name "*.ts" -o -name "*.md" -o -name "package.json" \) -not -path "./node_modules/*" \
176
+ -exec sed -i '' "s/$SNAKE_CLASS_A/$SNAKE_CLASS_B/g" {} +
177
+
178
+ find . -type f -not -path "*/node_modules/*" -not -path "*/.*" -name "*$SNAKE_CLASS_A*" \
179
+ -exec bash -c 'mv "$1" "${1//'"$SNAKE_CLASS_A"'/'"$SNAKE_CLASS_B"'}"' _ {} \;
180
+
181
+ rm -rf test/goldens
182
+ pnpm updateGoldens
183
+ ```
184
+
185
+ Review the changes.
186
+
187
+ Commit
188
+
189
+ ```bash
190
+ git stage .
191
+ git commit -am"Rename $CLASS_A to $CLASS_B"
192
+ ```
193
+
143
194
  <!-- ........................................................................-->
144
195
 
145
196
  ## Workflow
146
197
 
198
+ ### Set a PR title
199
+
200
+ ```bash
201
+ export PR_TITLE="PR Title"
202
+ ```
203
+
147
204
  ### Checkout main
148
205
 
149
206
  ```bash
150
- git checkout main && \
151
- git fetch && \
207
+ git checkout main
208
+ git fetch
152
209
  git pull
153
210
  ```
154
211
 
155
- ### Create a branch
156
-
157
- Please replace `Commit Message` in the next command by your commit message.
158
- It will also used for branch name and pull request
212
+ ### Create a feature branch
159
213
 
160
214
  ```bash
161
- export MESSAGE="Add simple example" && \
162
- export BRANCH=`echo "$MESSAGE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]/_/g'` &&\
215
+ export BRANCH=`echo "$PR_TITLE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]/_/g'`
163
216
  git checkout -b $BRANCH
164
217
  ```
165
218
 
166
- ### Commit
167
-
168
- Develop your feature
169
-
170
- Commit your changes
171
-
172
- If you only have one thing, execute
219
+ ### Update dependencies
173
220
 
174
221
  ```bash
175
- git add . && git commit -m "$MESSAGE"
222
+ pnpm update --latest
223
+ git commit -am"Update dependencies"
176
224
  ```
177
225
 
178
- ### Update dependencies
226
+ ### Debug and develop
227
+
228
+ Debug and develop
229
+
230
+ ### Commit
179
231
 
180
- We aim to work with the latest versions of our dependencies
232
+ If you only have one thing changed, execute
181
233
 
182
234
  ```bash
183
- pnpm update --latest &&\
184
- git commit -m"Update dependencies"
235
+ git add . && git commit -m "$PR_TITLE"
185
236
  ```
186
237
 
187
238
  ### Increase version
188
239
 
189
240
  ```bash
190
- pnpm version patch --no-git-tag-version && \
241
+ pnpm version patch --no-git-tag-version
191
242
  git commit -am"Increase version"
192
243
  ```
193
244
 
194
- ### Push the branch
195
-
196
- Use your ID or this git command to push the branch
245
+ ### Build
197
246
 
198
247
  ```bash
199
- git push -u origin $BRANCH
248
+ npm run build
200
249
  ```
201
250
 
202
251
  ### Create a pull request
203
252
 
204
253
  ```bash
205
- gh pr create --base main --title "$MESSAGE" --body "" && \
254
+ git push -u origin $BRANCH
255
+ gh pr create --base main --title "$PR_TITLE" --body ""
206
256
  gh pr merge --auto --squash
207
257
  ```
208
258
 
209
259
  ### Wait until PR is merged
210
260
 
211
- Get the PR URL with the following command
212
-
213
261
  ```bash
214
262
  echo -e "\033[34m$(gh pr view --json url | jq -r '.url')\033[0m"
215
- echo "Wait until PR is closed ..." && \
216
- until gh pr view --json closed | jq -e '.closed == true' >/dev/null; do
217
- sleep 2 >/dev/null;
218
- done;
263
+ echo -e "\033[33mWait until PR is closed or merged ...\033[0m"
264
+
265
+ while true; do
266
+ STATUS=$(gh pr view --json state | jq -r '.state')
267
+ if [ "$STATUS" = "CLOSED" ] || [ "$STATUS" = "MERGED" ]; then
268
+ echo -e "\033[32mPR has been merged or closed.\033[0m"
269
+ break
270
+ elif [ "$STATUS" = "FAILED" ]; then
271
+ echo -e "\033[31mError: PR has failed.\033[0m"
272
+ break
273
+ fi
274
+ sleep 2
275
+ done
219
276
  ```
220
277
 
221
278
  ### Delete feature branch
222
279
 
223
280
  ```bash
224
- git fetch && git checkout main && \
225
- git reset --soft origin/main && \
226
- git stash -m"PR Aftermath" && \
227
- git pull && \
281
+ git fetch && git checkout main
282
+ git reset --soft origin/main
283
+ git stash -m"PR Aftermath"
284
+ git pull
228
285
  git branch -d $BRANCH
229
286
  ```
230
287
 
231
288
  ### Publish to NPM
232
289
 
233
290
  ```bash
234
- npm publish --access public && \
291
+ npm publish --access public
235
292
  git tag $(npm pkg get version | tr -d '\\"')
236
293
  ```
237
294
 
@@ -1,15 +1,15 @@
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
11
  - [Install](#install)
12
- - [Check out](#check-out)
12
+ - [Checkout](#checkout)
13
13
  - [Install pnpm](#install-pnpm)
14
14
  - [Install dependencies](#install-dependencies)
15
15
  - [Install Vscode extensions](#install-vscode-extensions)
@@ -20,13 +20,16 @@
20
20
  - [Debug](#debug)
21
21
  - [Update goldens](#update-goldens)
22
22
  - [Test and Build](#test-and-build)
23
+ - [Rename classes](#rename-classes)
23
24
  - [Workflow](#workflow)
25
+ - [Set a PR title](#set-a-pr-title)
24
26
  - [Checkout main](#checkout-main)
25
- - [Create a branch](#create-a-branch)
26
- - [Commit](#commit)
27
+ - [Create a feature branch](#create-a-feature-branch)
27
28
  - [Update dependencies](#update-dependencies)
29
+ - [Debug and develop](#debug-and-develop)
30
+ - [Commit](#commit)
28
31
  - [Increase version](#increase-version)
29
- - [Push the branch](#push-the-branch)
32
+ - [Build](#build)
30
33
  - [Create a pull request](#create-a-pull-request)
31
34
  - [Wait until PR is merged](#wait-until-pr-is-merged)
32
35
  - [Delete feature branch](#delete-feature-branch)
@@ -39,13 +42,13 @@
39
42
 
40
43
  ## Install
41
44
 
42
- ### Check out
45
+ ### Checkout
43
46
 
44
47
  ```bash
45
48
  mkdir rljson
46
49
  cd rljson
47
50
  git clone https://github.com/rljson/rljson.git
48
- cd io
51
+ cd rljson
49
52
  ```
50
53
 
51
54
  ### Install pnpm
@@ -136,102 +139,156 @@ pnpm updateGoldens
136
139
  ### Test and Build
137
140
 
138
141
  ```bash
139
- pnpm test &&\
142
+ pnpm test
140
143
  pnpm build
141
144
  ```
142
145
 
146
+ ### Rename classes
147
+
148
+ Replace `ClassA` by `ClassB` in the following script and run it:
149
+
150
+ ```bash
151
+ export CLASS_A="ColumnSelection"
152
+ export CLASS_B="ColumnsConfig"
153
+
154
+ to_snake_case() {
155
+ echo "$1" | sed -E 's/([a-z0-9])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]'
156
+ }
157
+
158
+ to_lower_first() {
159
+ first_char=$(echo "$1" | cut -c1 | tr '[:upper:]' '[:lower:]')
160
+ rest_chars=$(echo "$1" | cut -c2-)
161
+ echo "$first_char$rest_chars"
162
+ }
163
+
164
+ export LOWER_CLASS_A=$(to_lower_first "$CLASS_A")
165
+ export LOWER_CLASS_B=$(to_lower_first "$CLASS_B")
166
+ export SNAKE_CLASS_A=$(to_snake_case "$CLASS_A")
167
+ export SNAKE_CLASS_B=$(to_snake_case "$CLASS_B")
168
+
169
+ find . -type f \( -name "*.ts" -o -name "*.md" -o -name "package.json" \) -not -path "./node_modules/*" \
170
+ -exec sed -i '' "s/$CLASS_A/$CLASS_B/g" {} +
171
+
172
+ find . -type f \( -name "*.ts" -o -name "*.md" -o -name "package.json" \) -not -path "./node_modules/*" \
173
+ -exec sed -i '' "s/$LOWER_CLASS_A/$LOWER_CLASS_B/g" {} +
174
+
175
+ find . -type f \( -name "*.ts" -o -name "*.md" -o -name "package.json" \) -not -path "./node_modules/*" \
176
+ -exec sed -i '' "s/$SNAKE_CLASS_A/$SNAKE_CLASS_B/g" {} +
177
+
178
+ find . -type f -not -path "*/node_modules/*" -not -path "*/.*" -name "*$SNAKE_CLASS_A*" \
179
+ -exec bash -c 'mv "$1" "${1//'"$SNAKE_CLASS_A"'/'"$SNAKE_CLASS_B"'}"' _ {} \;
180
+
181
+ rm -rf test/goldens
182
+ pnpm updateGoldens
183
+ ```
184
+
185
+ Review the changes.
186
+
187
+ Commit
188
+
189
+ ```bash
190
+ git stage .
191
+ git commit -am"Rename $CLASS_A to $CLASS_B"
192
+ ```
193
+
143
194
  <!-- ........................................................................-->
144
195
 
145
196
  ## Workflow
146
197
 
198
+ ### Set a PR title
199
+
200
+ ```bash
201
+ export PR_TITLE="PR Title"
202
+ ```
203
+
147
204
  ### Checkout main
148
205
 
149
206
  ```bash
150
- git checkout main && \
151
- git fetch && \
207
+ git checkout main
208
+ git fetch
152
209
  git pull
153
210
  ```
154
211
 
155
- ### Create a branch
156
-
157
- Please replace `Commit Message` in the next command by your commit message.
158
- It will also used for branch name and pull request
212
+ ### Create a feature branch
159
213
 
160
214
  ```bash
161
- export MESSAGE="Add simple example" && \
162
- export BRANCH=`echo "$MESSAGE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]/_/g'` &&\
215
+ export BRANCH=`echo "$PR_TITLE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]/_/g'`
163
216
  git checkout -b $BRANCH
164
217
  ```
165
218
 
166
- ### Commit
167
-
168
- Develop your feature
169
-
170
- Commit your changes
171
-
172
- If you only have one thing, execute
219
+ ### Update dependencies
173
220
 
174
221
  ```bash
175
- git add . && git commit -m "$MESSAGE"
222
+ pnpm update --latest
223
+ git commit -am"Update dependencies"
176
224
  ```
177
225
 
178
- ### Update dependencies
226
+ ### Debug and develop
227
+
228
+ Debug and develop
229
+
230
+ ### Commit
179
231
 
180
- We aim to work with the latest versions of our dependencies
232
+ If you only have one thing changed, execute
181
233
 
182
234
  ```bash
183
- pnpm update --latest &&\
184
- git commit -m"Update dependencies"
235
+ git add . && git commit -m "$PR_TITLE"
185
236
  ```
186
237
 
187
238
  ### Increase version
188
239
 
189
240
  ```bash
190
- pnpm version patch --no-git-tag-version && \
241
+ pnpm version patch --no-git-tag-version
191
242
  git commit -am"Increase version"
192
243
  ```
193
244
 
194
- ### Push the branch
195
-
196
- Use your ID or this git command to push the branch
245
+ ### Build
197
246
 
198
247
  ```bash
199
- git push -u origin $BRANCH
248
+ npm run build
200
249
  ```
201
250
 
202
251
  ### Create a pull request
203
252
 
204
253
  ```bash
205
- gh pr create --base main --title "$MESSAGE" --body "" && \
254
+ git push -u origin $BRANCH
255
+ gh pr create --base main --title "$PR_TITLE" --body ""
206
256
  gh pr merge --auto --squash
207
257
  ```
208
258
 
209
259
  ### Wait until PR is merged
210
260
 
211
- Get the PR URL with the following command
212
-
213
261
  ```bash
214
262
  echo -e "\033[34m$(gh pr view --json url | jq -r '.url')\033[0m"
215
- echo "Wait until PR is closed ..." && \
216
- until gh pr view --json closed | jq -e '.closed == true' >/dev/null; do
217
- sleep 2 >/dev/null;
218
- done;
263
+ echo -e "\033[33mWait until PR is closed or merged ...\033[0m"
264
+
265
+ while true; do
266
+ STATUS=$(gh pr view --json state | jq -r '.state')
267
+ if [ "$STATUS" = "CLOSED" ] || [ "$STATUS" = "MERGED" ]; then
268
+ echo -e "\033[32mPR has been merged or closed.\033[0m"
269
+ break
270
+ elif [ "$STATUS" = "FAILED" ]; then
271
+ echo -e "\033[31mError: PR has failed.\033[0m"
272
+ break
273
+ fi
274
+ sleep 2
275
+ done
219
276
  ```
220
277
 
221
278
  ### Delete feature branch
222
279
 
223
280
  ```bash
224
- git fetch && git checkout main && \
225
- git reset --soft origin/main && \
226
- git stash -m"PR Aftermath" && \
227
- git pull && \
281
+ git fetch && git checkout main
282
+ git reset --soft origin/main
283
+ git stash -m"PR Aftermath"
284
+ git pull
228
285
  git branch -d $BRANCH
229
286
  ```
230
287
 
231
288
  ### Publish to NPM
232
289
 
233
290
  ```bash
234
- npm publish --access public && \
291
+ npm publish --access public
235
292
  git tag $(npm pkg get version | tr -d '\\"')
236
293
  ```
237
294
 
package/dist/example.d.ts CHANGED
@@ -1,4 +1,39 @@
1
- /**
2
- * The example function demonstrates how the package works
3
- */
4
- export declare const example: () => void;
1
+ import { Rljson } from './rljson.ts';
2
+ export declare class Example {
3
+ static readonly ok: {
4
+ bakery: () => Rljson;
5
+ empty: () => Rljson;
6
+ binary: () => Rljson;
7
+ singleRow: () => Rljson;
8
+ multipleRows: () => Rljson;
9
+ singleRef: () => Rljson;
10
+ complete: () => Rljson;
11
+ };
12
+ static readonly broken: {
13
+ brokenTableName: () => {
14
+ brok$en: {
15
+ _type: string;
16
+ _data: never[];
17
+ };
18
+ };
19
+ missingData: () => Rljson;
20
+ dataNotBeingAnArray: () => Rljson;
21
+ missingRef: () => Rljson;
22
+ missingReferencedTable: () => Rljson;
23
+ collections: {
24
+ missingBase: () => Rljson;
25
+ missingIdSet: () => Rljson;
26
+ missingAssignedPropertyTable: () => Rljson;
27
+ missingAssignedProperty: () => Rljson;
28
+ };
29
+ cakes: {
30
+ missingIdSet: () => Rljson;
31
+ missingCollectionsTable: () => Rljson;
32
+ missingLayerCollection: () => Rljson;
33
+ };
34
+ buffets: {
35
+ missingTable: () => Rljson;
36
+ missingItems: () => Rljson;
37
+ };
38
+ };
39
+ }
package/dist/index.d.ts CHANGED
@@ -1 +1,9 @@
1
+ export * from './content/buffet.ts';
2
+ export * from './content/cake.ts';
3
+ export * from './content/collection.ts';
4
+ export * from './content/id-set.ts';
5
+ export * from './content/properties.ts';
6
+ export * from './example.ts';
7
+ export * from './rljson-indexed.ts';
1
8
  export * from './rljson.ts';
9
+ export * from './typedefs.ts';
@@ -0,0 +1,19 @@
1
+ import { Json } from '@rljson/json';
2
+ import { Rljson } from './rljson.ts';
3
+ /**
4
+ * An Rljson object where all tables' rows are indexed by their hash.
5
+ */
6
+ export interface RljsonIndexed {
7
+ [tableName: string]: {
8
+ _data: {
9
+ [rowHash: string]: Json;
10
+ };
11
+ };
12
+ [key: `_${string}`]: any;
13
+ }
14
+ /**
15
+ * Returns an rljson where all tables' rows are indexed by their hash.
16
+ * @param rljson - The Rljson object to index
17
+ * @returns The indexed Rljson object
18
+ */
19
+ export declare const rljsonIndexed: (rljson: Rljson) => RljsonIndexed;