@yuneta/gobj-js 7.25.9 → 7.26.1
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.md +86 -24
- package/dist/gobj-js.cjs.js +199 -94
- package/dist/gobj-js.cjs.js.map +1 -1
- package/dist/gobj-js.cjs.min.js +934 -878
- package/dist/gobj-js.cjs.min.js.map +1 -1
- package/dist/gobj-js.es.js +199 -94
- package/dist/gobj-js.es.js.map +1 -1
- package/dist/gobj-js.es.min.js +1053 -997
- package/dist/gobj-js.es.min.js.map +1 -1
- package/dist/gobj-js.iife.js +199 -94
- package/dist/gobj-js.iife.js.map +1 -1
- package/dist/gobj-js.iife.min.js +941 -885
- package/dist/gobj-js.iife.min.js.map +1 -1
- package/dist/gobj-js.umd.js +199 -94
- package/dist/gobj-js.umd.js.map +1 -1
- package/dist/gobj-js.umd.min.js +941 -885
- package/dist/gobj-js.umd.min.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -159,8 +159,10 @@ To publish a new version of `@yuneta/gobj-js` to [npmjs.com](https://www.npmjs.c
|
|
|
159
159
|
# 1. Configure your npm token (only once)
|
|
160
160
|
echo "//registry.npmjs.org/:_authToken=<your-token>" > ~/.npmrc
|
|
161
161
|
|
|
162
|
-
# 2. Update the version in package.json
|
|
163
|
-
|
|
162
|
+
# 2. Update the version in package.json. The first two numbers are those
|
|
163
|
+
# of the SDK (YUNETA_VERSION) the package belongs to; only the third
|
|
164
|
+
# moves between SDK releases.
|
|
165
|
+
npm version patch
|
|
164
166
|
|
|
165
167
|
# 3. Publish (build runs automatically via prepublishOnly)
|
|
166
168
|
npm publish --access public
|
|
@@ -372,7 +374,7 @@ gclass_create(name, event_types, states, gmt, lmt, attrs_table,
|
|
|
372
374
|
private_data, authz_table, command_table,
|
|
373
375
|
s_user_trace_level, gclass_flag)
|
|
374
376
|
|
|
375
|
-
gclass_find_by_name(name)
|
|
377
|
+
gclass_find_by_name(name, verbose) // → GClass or null
|
|
376
378
|
gclass_check_fsm(gclass) // validate FSM (returns error count)
|
|
377
379
|
gclass_add_event_type(gclass, event_name, flag)
|
|
378
380
|
gclass_add_state(gclass, state_name)
|
|
@@ -479,9 +481,9 @@ gobj_name(gobj)
|
|
|
479
481
|
gobj_short_name(gobj)
|
|
480
482
|
gobj_full_name(gobj)
|
|
481
483
|
gobj_gclass_name(gobj)
|
|
482
|
-
gobj_yuno_name(
|
|
483
|
-
gobj_yuno_role(
|
|
484
|
-
gobj_yuno_id(
|
|
484
|
+
gobj_yuno_name() // no argument: there is one yuno
|
|
485
|
+
gobj_yuno_role()
|
|
486
|
+
gobj_yuno_id()
|
|
485
487
|
|
|
486
488
|
gobj_find_child(gobj, kw_filter)
|
|
487
489
|
gobj_find_service(name, verbose)
|
|
@@ -605,6 +607,13 @@ kw_select (gobj, kw, jn_filter, match_fn) // filter list
|
|
|
605
607
|
kw_collect(gobj, kw, jn_filter, match_fn) // extract subset
|
|
606
608
|
kw_clone_by_keys (gobj, kw, keys, verbose)
|
|
607
609
|
kw_clone_by_not_keys(gobj, kw, keys, verbose)
|
|
610
|
+
// A filter value is compared as a value: {online: false}, {channel: 0}
|
|
611
|
+
// and {name: ""} match (up to 7.25.9 a false value never did):
|
|
612
|
+
// kw_select(null, [{id: "a", online: false}], {online: false}) → [{id: "a", ...}]
|
|
613
|
+
// A key is read only when the kw OWNS it ("toString" or "constructor" on
|
|
614
|
+
// a plain {} are not there) and written as its own key, "__proto__"
|
|
615
|
+
// included, as in C: never into a prototype. The helpers that copy
|
|
616
|
+
// (json_object_update(), kw_clone_by_*(), flat_apply()...) do the same.
|
|
608
617
|
|
|
609
618
|
// Flags: KW_REQUIRED, KW_CREATE, KW_EXTRACT, KW_RECURSIVE, KW_WILD_NUMBER
|
|
610
619
|
|
|
@@ -623,8 +632,8 @@ str_in_list(list, str, ci) // case-insensitive optional
|
|
|
623
632
|
index_in_list(list, value)
|
|
624
633
|
delete_from_list(list, value)
|
|
625
634
|
jwtDecode(token) // → header/payload/signature
|
|
626
|
-
jwt2json(token)
|
|
627
|
-
debounce(fn,
|
|
635
|
+
jwt2json(token, what) // → payload JSON (what: optional part)
|
|
636
|
+
debounce(fn, wait, immediate)
|
|
628
637
|
timeTracker()
|
|
629
638
|
|
|
630
639
|
// Inter-event message stack
|
|
@@ -636,11 +645,53 @@ msg_iev_write_key(kw, key, value) // no gobj
|
|
|
636
645
|
msg_iev_read_key (kw, key) // no gobj
|
|
637
646
|
```
|
|
638
647
|
|
|
648
|
+
### A json as a table: `json2flat` / `flat2json`
|
|
649
|
+
|
|
650
|
+
The same grammar as the C kernel (`kwid.h`): one row per leaf, the id being
|
|
651
|
+
the path joined by `` ` ``, an array index written `[N]`, an empty container
|
|
652
|
+
a leaf of its own.
|
|
653
|
+
|
|
654
|
+
```javascript
|
|
655
|
+
json2flat({a: {b: 1, c: [true]}, d: {}})
|
|
656
|
+
// → {"a`b": 1, "a`c`[0]": true, "d": {}}
|
|
657
|
+
flat2json({"a`b": 1, "a`c`[0]": true, "d": {}})
|
|
658
|
+
// → {a: {b: 1, c: [true]}, d: {}}
|
|
659
|
+
|
|
660
|
+
flat_diff({a: 1, b: 2}, {a: 1, b: 3, c: 4})
|
|
661
|
+
// → {added: {c: 4}, removed: {}, changed: {b: {from: 2, to: 3}}}
|
|
662
|
+
flat_apply(flat, diff) // → flat with that diff applied
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
`flat2json()` throws on the first id that does not fit (a leaf and a
|
|
666
|
+
container at once) instead of guessing.
|
|
667
|
+
|
|
668
|
+
### Secrets in traces and logs
|
|
669
|
+
|
|
670
|
+
```javascript
|
|
671
|
+
is_secret_name("password") // → true ("token", "jwt", "apikey"...)
|
|
672
|
+
is_secret_name("token_endpoint") // → false (names something ABOUT one)
|
|
673
|
+
mask_secrets_inline("login user=a passw=x") // → "login user=a passw=********"
|
|
674
|
+
json_mask_secrets({user: "a", password: "x"}) // → {user: "a", password: "********"}
|
|
675
|
+
trace_json_masked(kw, "sent") // trace_json() of the masked copy
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
As the C kernel's: linear and bounded (a text over 4 MB is not shown at all).
|
|
679
|
+
|
|
639
680
|
### Logging
|
|
640
681
|
|
|
641
|
-
All log functions take a
|
|
642
|
-
substitution (`%s`, `%d`, `%i`, `%f`, `%o`/`%O`)
|
|
643
|
-
|
|
682
|
+
All log functions take a `format` and its arguments, with `printf`-style
|
|
683
|
+
substitution (`%s`, `%d`, `%i`, `%f`, `%o`/`%O`); arguments left over are
|
|
684
|
+
appended. A message with no arguments (a template literal, the usual case)
|
|
685
|
+
is printed as it is, so a `%s` in its data is not touched. There is no
|
|
686
|
+
`gobj` or error-code argument (that's the C API — the JS runtime is simpler).
|
|
687
|
+
|
|
688
|
+
```javascript
|
|
689
|
+
log_error("Command not found: %s", command); // → "Command not found: open"
|
|
690
|
+
log_error(`Command not found: ${command}`); // the same line
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
(Up to 7.25.9 the arguments were dropped: the first line printed
|
|
694
|
+
`Command not found: undefined`.)
|
|
644
695
|
|
|
645
696
|
```javascript
|
|
646
697
|
log_error(format, ...args) // red, prefixed "ERROR"
|
|
@@ -904,7 +955,8 @@ import {
|
|
|
904
955
|
SDATA, SDATA_END,
|
|
905
956
|
data_type_t, sdata_flag_t,
|
|
906
957
|
gclass_create,
|
|
907
|
-
gobj_subscribe_event, gobj_yuno,
|
|
958
|
+
gobj_subscribe_event, gobj_yuno, gobj_parent,
|
|
959
|
+
gobj_read_pointer_attr,
|
|
908
960
|
trace_msg,
|
|
909
961
|
} from "@yuneta/gobj-js";
|
|
910
962
|
|
|
@@ -912,8 +964,9 @@ const GCLASS_NAME = "C_MY_CLASS";
|
|
|
912
964
|
|
|
913
965
|
// 1. Attribute schema
|
|
914
966
|
const attrs_table = [
|
|
915
|
-
SDATA(data_type_t.DTP_STRING, "url",
|
|
916
|
-
SDATA(data_type_t.DTP_INTEGER, "retries",
|
|
967
|
+
SDATA(data_type_t.DTP_STRING, "url", sdata_flag_t.SDF_RD, "", "Remote URL"),
|
|
968
|
+
SDATA(data_type_t.DTP_INTEGER, "retries", sdata_flag_t.SDF_RD, 3, "Max retries"),
|
|
969
|
+
SDATA(data_type_t.DTP_POINTER, "subscriber", 0, null, "Subscriber of the output events"),
|
|
917
970
|
SDATA_END()
|
|
918
971
|
];
|
|
919
972
|
|
|
@@ -924,10 +977,20 @@ const PRIVATE_DATA = {
|
|
|
924
977
|
|
|
925
978
|
// 3. Lifecycle methods
|
|
926
979
|
function mt_create(gobj) {
|
|
927
|
-
//
|
|
980
|
+
// The attrs already hold their values: defaults + the kw of the create.
|
|
981
|
+
|
|
982
|
+
/*
|
|
983
|
+
* CHILD subscription model (a SERVICE uses the other one, see the
|
|
984
|
+
* skeletons of yuno-skeleton)
|
|
985
|
+
*/
|
|
986
|
+
let subscriber = gobj_read_pointer_attr(gobj, "subscriber");
|
|
987
|
+
if(!subscriber) {
|
|
988
|
+
subscriber = gobj_parent(gobj);
|
|
989
|
+
}
|
|
990
|
+
gobj_subscribe_event(gobj, null, {}, subscriber);
|
|
928
991
|
}
|
|
929
992
|
function mt_start(gobj) {
|
|
930
|
-
// subscribe to events
|
|
993
|
+
// subscribe to events OF OTHER gobjs here
|
|
931
994
|
gobj_subscribe_event(gobj_yuno(), "EV_TIMEOUT_PERIODIC", {}, gobj);
|
|
932
995
|
}
|
|
933
996
|
function mt_stop(gobj) { }
|
|
@@ -984,16 +1047,15 @@ kernel/js/gobj-js/
|
|
|
984
1047
|
├── package.json
|
|
985
1048
|
├── vite.config.js
|
|
986
1049
|
├── dist/ ← compiled outputs (ES, CJS, UMD, IIFE)
|
|
987
|
-
├── tests/
|
|
988
|
-
│ └── kw_delete.test.js
|
|
1050
|
+
├── tests/ ← vitest suite, one file per contract (npm test)
|
|
989
1051
|
└── src/
|
|
990
1052
|
├── index.js ← public API entry point (barrel export)
|
|
991
|
-
├── gobj.js ← GObject/FSM runtime (~
|
|
992
|
-
├── helpers.js ← utilities, JSON, logging (~
|
|
993
|
-
├── c_ievent_cli.js ← remote service proxy (~1
|
|
994
|
-
├── lib_treedb.js ← TreeDB helpers (~
|
|
995
|
-
├── c_timer.js ← Timer GClass (~
|
|
996
|
-
├── c_yuno.js ← Yuno GClass (~
|
|
1053
|
+
├── gobj.js ← GObject/FSM runtime (~5 600 LOC)
|
|
1054
|
+
├── helpers.js ← utilities, JSON, logging (~4 700 LOC)
|
|
1055
|
+
├── c_ievent_cli.js ← remote service proxy (~1 600 LOC)
|
|
1056
|
+
├── lib_treedb.js ← TreeDB helpers (~ 580 LOC)
|
|
1057
|
+
├── c_timer.js ← Timer GClass (~ 390 LOC)
|
|
1058
|
+
├── c_yuno.js ← Yuno GClass (~ 530 LOC)
|
|
997
1059
|
├── dbsimple.js ← localStorage persistence (~ 140 LOC)
|
|
998
1060
|
├── sprintf.js ← printf-style formatting (~ 210 LOC)
|
|
999
1061
|
├── command_parser.js ← command parsing
|